diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:38:16 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:38:16 +0200 |
commit | 529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105 (patch) | |
tree | 8a50c30271b9b328cde0d907b1441f2dabdc341b /Neutron-trunk/widgets | |
parent | 15e4724761c50b30803df1811a525c85058f70bf (diff) | |
download | electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.tar.gz electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.tar.bz2 electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.zip |
Update
Diffstat (limited to 'Neutron-trunk/widgets')
-rw-r--r-- | Neutron-trunk/widgets/.htaccess | 4 | ||||
-rw-r--r-- | Neutron-trunk/widgets/calendar/feature.json | 15 | ||||
-rw-r--r-- | Neutron-trunk/widgets/calendar/source.php | 124 | ||||
-rw-r--r-- | Neutron-trunk/widgets/clock/feature.json | 15 | ||||
-rw-r--r-- | Neutron-trunk/widgets/clock/source.php | 96 | ||||
-rw-r--r-- | Neutron-trunk/widgets/views/feature.json | 15 | ||||
-rw-r--r-- | Neutron-trunk/widgets/views/source.php | 25 |
7 files changed, 294 insertions, 0 deletions
diff --git a/Neutron-trunk/widgets/.htaccess b/Neutron-trunk/widgets/.htaccess new file mode 100644 index 0000000..bc839cb --- /dev/null +++ b/Neutron-trunk/widgets/.htaccess @@ -0,0 +1,4 @@ +ErrorDocument 401 /cms-special/error/?id=401&description=Accès%20refusé +ErrorDocument 403 /cms-special/error/?id=403&description=Accès%20interdit +ErrorDocument 404 /cms-special/error/?id=404&description=Ressource%20introuvable +ErrorDocument 500 /cms-special/error/?id=500&description=Erreur%20interne
\ No newline at end of file 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>"); + } + } +} diff --git a/Neutron-trunk/widgets/clock/feature.json b/Neutron-trunk/widgets/clock/feature.json new file mode 100644 index 0000000..70db617 --- /dev/null +++ b/Neutron-trunk/widgets/clock/feature.json @@ -0,0 +1,15 @@ +{ + "name": { + "en": "Clock", + "fr": "Horloge" + }, + "description": { + "en": "Shows the current time in a widget", + "fr": "Affiche un widget contenant l'heure" + }, + + "config": null, + "class": null, + + "cache": true +}
\ No newline at end of file diff --git a/Neutron-trunk/widgets/clock/source.php b/Neutron-trunk/widgets/clock/source.php new file mode 100644 index 0000000..04c3939 --- /dev/null +++ b/Neutron-trunk/widgets/clock/source.php @@ -0,0 +1,96 @@ +<div id="widget-space"> + <div style="text-align: center;"><h3 id="widget-clock-time">00:00:00</h3><span id="widget-clock-date">????? ??? ??????? ????</span></div> +</div> +<script> + +setInterval(() => { + time = new Date() + hours = time.getHours() + minutes = time.getMinutes() + seconds = time.getSeconds() + day = time.getDate() + month = time.getMonth() + 1 + year = time.getFullYear() + dow = time.getDay() + 1 + if (hours < 10) { + hours_str = "0" + hours + } else { + hours_str = hours + } + if (minutes < 10) { + minutes_str = "0" + minutes + } else { + minutes_str = minutes + } + if (seconds < 10) { + seconds_str = "0" + seconds + } else { + seconds_str = seconds + } + if (day == 1) { + day_str = "<?= $lang["widgets"]["clock"]["ordinal"] ?>" + } else { + day_str = day + } + if (dow == 2) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][0] ?>" + } + if (dow == 3) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][1] ?>" + } + if (dow == 4) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][2] ?>" + } + if (dow == 5) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][3] ?>" + } + if (dow == 6) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][4] ?>" + } + if (dow == 7) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][5] ?>" + } + if (dow == 1) { + dow_str = "<?= $lang["widgets"]["clock"]["days"][6] ?>" + } + if (month == 1) { + month_str = "<?= $lang["widgets"]["clock"]["months"][0] ?>" + } + if (month == 2) { + month_str = "<?= $lang["widgets"]["clock"]["months"][1] ?>" + } + if (month == 3) { + month_str = "<?= $lang["widgets"]["clock"]["months"][2] ?>" + } + if (month == 4) { + month_str = "<?= $lang["widgets"]["clock"]["months"][3] ?>" + } + if (month == 5) { + month_str = "<?= $lang["widgets"]["clock"]["months"][4] ?>" + } + if (month == 6) { + month_str = "<?= $lang["widgets"]["clock"]["months"][5] ?>" + } + if (month == 7) { + month_str = "<?= $lang["widgets"]["clock"]["months"][6] ?>" + } + if (month == 8) { + month_str = "<?= $lang["widgets"]["clock"]["months"][7] ?>" + } + if (month == 9) { + month_str = "<?= $lang["widgets"]["clock"]["months"][8] ?>" + } + if (month == 10) { + month_str = "<?= $lang["widgets"]["clock"]["months"][9] ?>" + } + if (month == 11) { + month_str = "<?= $lang["widgets"]["clock"]["months"][10] ?>" + } + if (month == 12) { + month_str = "<?= $lang["widgets"]["clock"]["months"][11] ?>" + } + document.getElementById('widget-clock-time').innerHTML = hours_str + ":" + minutes_str + ":" + seconds_str + document.getElementById('widget-clock-date').innerHTML = dow_str + " " + day_str + " " + month_str + " " + year +}, 100) + +</script>
\ No newline at end of file diff --git a/Neutron-trunk/widgets/views/feature.json b/Neutron-trunk/widgets/views/feature.json new file mode 100644 index 0000000..a7b3cb7 --- /dev/null +++ b/Neutron-trunk/widgets/views/feature.json @@ -0,0 +1,15 @@ +{ + "name": { + "en": "Views Count", + "fr": "Compteur de visites" + }, + "description": { + "en": "Shows the number of today's site visits in a widget", + "fr": "Affiche un widget avec le nombre de vues du jour" + }, + + "config": null, + "class": null, + + "cache": false +}
\ No newline at end of file diff --git a/Neutron-trunk/widgets/views/source.php b/Neutron-trunk/widgets/views/source.php new file mode 100644 index 0000000..399e616 --- /dev/null +++ b/Neutron-trunk/widgets/views/source.php @@ -0,0 +1,25 @@ +<div id="widget-space" style="text-align: center;"> + <?= $lang["widgets"]["views"]["intro"] ?> <h2 style="margin:0;"><?php + + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/newstats/" . date('Y') . "/" . date('m') . "/" . date('d'))) { + $file = trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/newstats/" . date("Y") . "/" . date("m") . "/" . date('d'))); + $count = count(explode("\n", $file)); + if ($count < 4) { + if ($count < 3) { + if ($count < 2) { + echo($count . $lang["widgets"]["views"]["ordinals"]["1"]); + } else { + echo($count . $lang["widgets"]["views"]["ordinals"]["2"]); + } + } else { + echo($count . $lang["widgets"]["views"]["ordinals"]["3"]); + } + } else { + echo($count . $lang["widgets"]["views"]["ordinals"]["4"]); + } + } else { + echo("({$lang["widgets"]["views"]["error"]})"); + } + + ?></h2> <?= $lang["widgets"]["views"]["outro"] ?> +</div>
\ No newline at end of file |