diff options
Diffstat (limited to 'Neutron-trunk/widgets/calendar')
-rw-r--r-- | Neutron-trunk/widgets/calendar/feature.json | 15 | ||||
-rw-r--r-- | Neutron-trunk/widgets/calendar/source.php | 124 |
2 files changed, 139 insertions, 0 deletions
diff --git a/Neutron-trunk/widgets/calendar/feature.json b/Neutron-trunk/widgets/calendar/feature.json new file mode 100644 index 0000000..efe8702 --- /dev/null +++ b/Neutron-trunk/widgets/calendar/feature.json @@ -0,0 +1,15 @@ +{ + "name": { + "en": "Upcoming Events", + "fr": "Prochains événements" + }, + "description": { + "en": "Shows the upcoming calendar events in a widget", + "fr": "Affiche les prochains événements du calendrier dans un widget" + }, + + "config": "/cms-special/admin/calendar", + "class": "MpcmsFeatureCalendar", + + "cache": true +}
\ No newline at end of file diff --git a/Neutron-trunk/widgets/calendar/source.php b/Neutron-trunk/widgets/calendar/source.php new file mode 100644 index 0000000..dd644a9 --- /dev/null +++ b/Neutron-trunk/widgets/calendar/source.php @@ -0,0 +1,124 @@ +<?php + +class MpcmsFeatureCalendar { + private function isJson($string) { + json_decode($string); + return (json_last_error() == JSON_ERROR_NONE); + } + + public function __construct() { + if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang")) { + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang", "fr"); +} + +$langsel = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/lang"); +$lang = []; + +if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel)) { + $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/"); + foreach ($langprops as $langprop) { + if ($langprop != "." && $langprop != "..") { + $langpieces = explode("/", implode("/", explode("\\", $langprop))); + $langitemsel = explode(".", $langpieces[count($langpieces) - 1]); + $langitem = $langitemsel[count($langitemsel) - 1]; + if ($langitemsel[count($langitemsel) - 1] != "json") { + require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON."); + } else { + json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop), true); + if (json_last_error() == JSON_ERROR_NONE) { + $lang[$langitemsel[count($langitemsel) - 2]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/" . $langsel . "/" . $langprop), true); + } else { + require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry."); + } + } + } + } +} else { + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr")) { + echo("Unable to load language files: unable to find selected language files, loading fallback files"); + $langprops = scandir($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/"); + foreach ($langprops as $langprop) { + if ($langprop != "." && $langprop != "..") { + $langpieces = explode("/", implode("/", explode("\\", $langprop))); + $langitemsel = explode(".", $langpieces[count($langpieces) - 1]); + $langitem = $langitemsel[count($langitemsel) - 1]; + if ($langitemsel[count($langitemsel) - 1] != "json") { + require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " is not in a valid format. Language files must be JSON."); + } else { + json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop), true); + if (json_last_error() == JSON_ERROR_NONE) { + $lang[$langitemsel[count($langitemsel) - 2]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/resources/i18n/fr/" . $langprop), true); + } else { + require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language file: " . implode(".", $langitemsel) . " isn't a valid JSON file. Please check for syntax errors and retry."); + } + } + } + } + } else { + require $_SERVER['DOCUMENT_ROOT'] . "/api/electrode/quit.php";quit("Unable to load language files: unable to find selected language files, and unable to find fallback language files"); + } +} + + global $GLOBALS; + global $_RENDERER; + + echo('<div id="widget-space"><ul>'); + $jsonraw = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/caldb.json"); + if ($this::isJson($jsonraw)) { + $json = json_decode($jsonraw); + $eventlist = []; + foreach ($json->events as $event) { + if (isset($event->timestamp)) { + array_push($eventlist, $event->timestamp); + } + } + sort($eventlist); + $pos = 1; + $shown = 0; + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/calendar_events")) { + $calevn = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/calendar_events"); + } else { + $calevn = "3"; + } + foreach ($eventlist as $event) { + if ($pos == ($calevn + 1)) {} else { + foreach ($json->events as $el) { + if (isset($el->timestamp)) { + if ($el->timestamp == $event) { + (int)$currentDate = date("Ymd"); + if ($currentDate < $el->timestamp) { + $shown = $shown + 1; + if (isset($el->link)) { + if ($el->link != "" && $el->link != "http://") { + echo("<li><b><a target=\"_blank\" class=\"sblink\" href=\"" . $el->link . "\">" . $el->datestr . "</b> : " . $el->name . "</a></li>"); + } else { + echo("<li><b>" . $el->datestr . "</b> : " . $el->name . "</li>"); + } + } else { + echo("<li><b>" . $el->datestr . "</b> : " . $el->name . "</li>"); + } + $pos = $pos + 1; + } + if ($currentDate == $el->timestamp) { + $shown = $shown + 1; + echo("<li><b>{$lang["widgets"]["calendar"]["today"]}</b> : " . $el->name . "</li>"); + $pos = $pos + 1; + } + } + } + } + } + } + if ($shown == "0") { + echo("</ul><div style=\"text-align: center;\"><i>{$lang["widgets"]["calendar"]["nothing"]}</i></div>"); + } + } else { + echo("<b>{$lang["widgets"]["calendar"]["corrupt"]}</b>"); + } + if ($_RENDERER === "Neutron Titanium") { + echo("</ul><small><a href=\"/cms-special/calendar\">{$lang["widgets"]["calendar"]["more"]}</a></small></div>"); + } else { + echo("</ul><small><a href=\"{$GLOBALS["SYSTEM_ROOT"]}/cms-special/calendar\">{$lang["widgets"]["calendar"]["more"]}</a></small></div>"); + } + } +} |