Compare commits
3 Commits
master
...
feature/do
| Author | SHA1 | Date | |
|---|---|---|---|
| 795aff3683 | |||
| 5e43ac0d32 | |||
| 508439e8cf |
@@ -17,7 +17,8 @@ class Plugin extends PluginBase {
|
||||
public function registerComponents() {
|
||||
return [
|
||||
'NicoSt\GCalendar\Components\Upcoming' => 'upcoming',
|
||||
'NicoSt\GCalendar\Components\EmbeddedCalendar' => 'embeddedCalendar'
|
||||
'NicoSt\GCalendar\Components\EmbeddedCalendar' => 'embeddedCalendar',
|
||||
'NicoSt\GCalendar\Components\Download' => 'download'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
95
components/Download.php
Normal file
95
components/Download.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php namespace NicoSt\GCalendar\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use NicoSt\GCalendar\Classes\GoogleCalendarService;
|
||||
|
||||
class Download extends ComponentBase {
|
||||
private $calPropSeparator = '§§';
|
||||
private $googleIcalUrl = 'https://calendar.google.com/calendar/ical/%s/public/basic.ics';
|
||||
|
||||
/**
|
||||
* Returns information about this component, including name and description.
|
||||
*/
|
||||
public function componentDetails() {
|
||||
return [
|
||||
'name' => 'nicost.gcalendar::lang.component.download.name',
|
||||
'description' => 'nicost.gcalendar::lang.component.download.description'
|
||||
];
|
||||
}
|
||||
|
||||
public function defineProperties() {
|
||||
|
||||
$calendars = $this->calendarProperties();
|
||||
$customProperties = [];
|
||||
|
||||
$result = array_merge($customProperties, $calendars);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCalendarDownloads() {
|
||||
|
||||
// Calenders from config
|
||||
$calendarList = $this->getCalendarsFromProperties();
|
||||
|
||||
$data = [];
|
||||
foreach($calendarList as $calendarData) {
|
||||
$calendar = [];
|
||||
$calendar['link'] = sprintf($this->googleIcalUrl, $calendarData['id']);
|
||||
$calendar['title'] = $calendarData['title'];
|
||||
|
||||
array_push($data, $calendar);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getCalendarsFromProperties() {
|
||||
$calendars = [];
|
||||
foreach($this->properties as $key => $value){
|
||||
$exp_key = explode($this->calPropSeparator, $key);
|
||||
if($exp_key[0] == 'cal' && $this->property($key) == true){
|
||||
$calendar = [];
|
||||
$calendar['id'] = $exp_key[1];
|
||||
$calendar['title'] = $exp_key[2];
|
||||
array_push($calendars, $calendar);
|
||||
}
|
||||
}
|
||||
|
||||
return $calendars;
|
||||
}
|
||||
|
||||
private function calendarProperties() {
|
||||
$service = new GoogleCalendarService();
|
||||
$calendars = $service->calendarList();
|
||||
|
||||
if (isset($calendars['error'])) {
|
||||
$calendars = '';
|
||||
}
|
||||
|
||||
$calendarProperties = [];
|
||||
if (!empty($calendars)) {
|
||||
foreach ($calendars as &$calendar) {
|
||||
$calendarData = [];
|
||||
$calendarData['id'] = $calendar->id;
|
||||
$calendarData['title'] = $calendar->summary;
|
||||
|
||||
$property = $this->createProperty($calendarData);
|
||||
$calendarProperties = array_merge($calendarProperties, $property);
|
||||
}
|
||||
}
|
||||
return $calendarProperties;
|
||||
}
|
||||
|
||||
private function createProperty(array $calendarData) {
|
||||
return [
|
||||
'cal'.$this->calPropSeparator.$calendarData['id'].$this->calPropSeparator.$calendarData['title'] => [
|
||||
'title' => $calendarData['title'],
|
||||
'type' => 'checkbox',
|
||||
'group' => 'nicost.gcalendar::lang.component.download.groups.calendars',
|
||||
// Default to setting from config
|
||||
'default' => 0,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -176,6 +176,7 @@ class EmbeddedCalendar extends ComponentBase {
|
||||
$data += ['wkst' => 2];
|
||||
}
|
||||
|
||||
// Calenders from config
|
||||
$calendarList = $this->getCalendarsFromProperties();
|
||||
$dataParams = http_build_query($data);
|
||||
|
||||
@@ -220,9 +221,9 @@ class EmbeddedCalendar extends ComponentBase {
|
||||
$exp_key = explode($this->calPropSeparator, $key);
|
||||
if($exp_key[0] == 'cal' && $this->property($key) == true){
|
||||
$calendar = [];
|
||||
$calendar['src'] = $exp_key[2];
|
||||
$calendar['color'] = $exp_key[1];
|
||||
$calendars[] = $calendar;
|
||||
$calendar['src'] = $exp_key[2];
|
||||
array_push($calendars, $calendar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +231,6 @@ class EmbeddedCalendar extends ComponentBase {
|
||||
}
|
||||
|
||||
private function calendarProperties() {
|
||||
// ToDo: Add cache => https://octobercms.com/docs/services/cache
|
||||
$service = new GoogleCalendarService();
|
||||
$calendars = $service->calendarList();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class Upcoming extends ComponentBase {
|
||||
];
|
||||
}
|
||||
|
||||
public function events() {
|
||||
public function getEvents() {
|
||||
$connector = new GoogleCalendarService();
|
||||
$maxEvents = $this->property('maxEvents');
|
||||
$calendarEvents = $connector->allEventList($maxEvents);
|
||||
|
||||
5
components/download/default.htm
Normal file
5
components/download/default.htm
Normal file
@@ -0,0 +1,5 @@
|
||||
<h3>Click on a calendar to download it and import it to you're device.</h3>
|
||||
{% set calendars = __SELF__.calendarDownloads %}
|
||||
{% for calendar in calendars %}
|
||||
<a href="{{ calendar.link }}" target="_blank">{{ calendar.title }}</a><br />
|
||||
{% endfor %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% set events = upcoming.events %}
|
||||
{% set events = __SELF__.events %}
|
||||
|
||||
{% if not events.error and events is not empty %}
|
||||
<table>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "nicost/oc-gcalendar-plugin",
|
||||
"name": "nicost/gcalendar-plugin",
|
||||
"type": "october-plugin",
|
||||
"description": "OctoberCMS calendar plugin which uses the Google Calendar API to provide event data.",
|
||||
"keywords": ["october", "cms", "google", "calendar", "events", "schedule", "kalender"],
|
||||
@@ -11,6 +11,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"composer/installers": "~1.0",
|
||||
"google/apiclient": "^2.0",
|
||||
"mobiledetect/mobiledetectlib": "^2.8"
|
||||
}
|
||||
|
||||
34
composer.lock
generated
34
composer.lock
generated
@@ -136,16 +136,16 @@
|
||||
},
|
||||
{
|
||||
"name": "google/apiclient-services",
|
||||
"version": "v0.228.0",
|
||||
"version": "v0.232.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/googleapis/google-api-php-client-services.git",
|
||||
"reference": "ec64bbf1d6af9475bee7b1ce4fc0ed8a0a8d8889"
|
||||
"reference": "e671adddfd3d2b36a415e7bf22189b1626bc13f8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/ec64bbf1d6af9475bee7b1ce4fc0ed8a0a8d8889",
|
||||
"reference": "ec64bbf1d6af9475bee7b1ce4fc0ed8a0a8d8889",
|
||||
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/e671adddfd3d2b36a415e7bf22189b1626bc13f8",
|
||||
"reference": "e671adddfd3d2b36a415e7bf22189b1626bc13f8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -174,9 +174,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/googleapis/google-api-php-client-services/issues",
|
||||
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.228.0"
|
||||
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.232.0"
|
||||
},
|
||||
"time": "2021-12-21T12:26:12+00:00"
|
||||
"time": "2022-01-28T12:22:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "google/auth",
|
||||
@@ -720,16 +720,16 @@
|
||||
},
|
||||
{
|
||||
"name": "paragonie/constant_time_encoding",
|
||||
"version": "v2.4.0",
|
||||
"version": "v2.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/paragonie/constant_time_encoding.git",
|
||||
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c"
|
||||
"reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
|
||||
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
|
||||
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/9229e15f2e6ba772f0c55dd6986c563b937170a8",
|
||||
"reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -783,7 +783,7 @@
|
||||
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
|
||||
"source": "https://github.com/paragonie/constant_time_encoding"
|
||||
},
|
||||
"time": "2020-12-06T15:14:20+00:00"
|
||||
"time": "2022-01-17T05:32:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "paragonie/random_compat",
|
||||
@@ -837,16 +837,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpseclib/phpseclib",
|
||||
"version": "3.0.12",
|
||||
"version": "3.0.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpseclib/phpseclib.git",
|
||||
"reference": "89bfb45bd8b1abc3b37e910d57f5dbd3174f40fb"
|
||||
"reference": "1443ab79364eea48665fa8c09ac67f37d1025f7e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/89bfb45bd8b1abc3b37e910d57f5dbd3174f40fb",
|
||||
"reference": "89bfb45bd8b1abc3b37e910d57f5dbd3174f40fb",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/1443ab79364eea48665fa8c09ac67f37d1025f7e",
|
||||
"reference": "1443ab79364eea48665fa8c09ac67f37d1025f7e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -928,7 +928,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpseclib/phpseclib/issues",
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.12"
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.13"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -944,7 +944,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-11-28T23:46:03+00:00"
|
||||
"time": "2022-01-30T08:50:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
|
||||
@@ -74,8 +74,14 @@
|
||||
],
|
||||
'showCalendarList' => [
|
||||
'title' => 'Kalender Liste Anzeigen'
|
||||
],
|
||||
|
||||
]
|
||||
]
|
||||
],
|
||||
'download' => [
|
||||
'name' => 'Download Kalender',
|
||||
'description' => 'Kalender als "ICS-Datei" downloaden.',
|
||||
'groups' => [
|
||||
'calendars' => 'Kalender'
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
@@ -74,8 +74,14 @@
|
||||
],
|
||||
'showCalendarList' => [
|
||||
'title' => 'Show Calendar List'
|
||||
],
|
||||
|
||||
]
|
||||
]
|
||||
],
|
||||
'download' => [
|
||||
'name' => 'Download Calendar',
|
||||
'description' => 'Download calendar as "ICS-File".',
|
||||
'groups' => [
|
||||
'calendars' => 'Calendars'
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
1.0.0:
|
||||
- Initialize plugin.
|
||||
- Prepare for October marketplace.
|
||||
- Prepare for October marketplace.
|
||||
1.1.0:
|
||||
- Add new "Download" component to display a list of calendars to be downloaded as ics-file.
|
||||
- Update dependencies
|
||||
- Fix some minor bugs
|
||||
1.1.1:
|
||||
- Compatibility with October CMS 2
|
||||
Reference in New Issue
Block a user