diff --git a/MensaPlugin.class.php b/MensaPlugin.class.php index a6f635f8bad6b411d80b94e1926554e15112cf71..11c104b8392eaef6e1b9500bb81a29aaf1b9a96b 100755 --- a/MensaPlugin.class.php +++ b/MensaPlugin.class.php @@ -34,12 +34,12 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin /** * Add several information to object - * @param Integer $date current date + * @param int|null $date current date */ - public function injectAssets($date = null) + public function injectAssets(int $date = null) { if (!self::$injected) { - $this->addStylesheet('assets/mensa-widget.less'); + $this->addStylesheet('assets/mensa-widget.scss'); PageLayout::addScript($this->getPluginURL() . '/assets/mensa-widget.js'); PageLayout::addHeadElement('meta', [ 'name' => 'mensa-widget-url', @@ -59,9 +59,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * as the request was not issued via AJAX). * * @param String $template Name of the template file - * @return FlexiTemplate object + * @return Mixed object + * @throws Flexi_TemplateNotFoundException */ - private function getTemplate($template) + private function getTemplate(string $template) { static $factory = null; if ($factory === null) { @@ -76,10 +77,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * Displays the menu for a certain a specific date. * * @param mixed $date Date to display; optional, defaults to today + * @throws Flexi_TemplateNotFoundException */ - public function menu_action($date = null, $direction = null) + public function menu_action(string $date = null, string $direction = null): void { - $date = $this->timeshift($date ?: time(), $direction); + $date = $this->timeShift($date ?: time(), $direction); header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 30 * 60)); header('Pragma: cache'); @@ -95,7 +97,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * * @return String containing the localized plugin name. */ - public function getPluginName() + public function getPluginName(): string { return _('Mensaplan'); } @@ -106,7 +108,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * @param int $date Date to display the title for * @return String containing the widget title for the given date. */ - private function getTitle($date) + private function getTitle(int $date): string { return $this->getPluginName() . ' - ' . strftime('%A %x', $date); } @@ -116,8 +118,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * * @param int $date Date to display * @return String containing the html output for the menu + * @throws Flexi_TemplateNotFoundException */ - private function renderMenu($date) + private function renderMenu(int $date): string { try { $template = $this->getTemplate('menu.php'); @@ -140,9 +143,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * * @param int $date Date to display * @return String containing the html output for the widget + * @throws Flexi_TemplateNotFoundException * @see MensaWidget::renderMenu */ - private function renderWidget($date) + private function renderWidget(int $date): string { $template = $this->getTemplate('widget.php'); $template->menu = $this->renderMenu($date); @@ -153,6 +157,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin * Renders the portal widget. * * @return FlexiTemplate object + * @throws Flexi_TemplateNotFoundException */ public function getPortalTemplate() { @@ -161,7 +166,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin if (isset($options['date'])) { $date = $options['date']; } elseif (date('G') >= 15) { - $date = $this->timeshift(time(), 'next'); + $date = $this->timeShift(time()); } else { $date = strtotime('today midnight'); } @@ -174,10 +179,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin $nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'], ['mensa-widget' => ['date' => strtotime('yesterday', $date)]])); $nav->setImage( - Icon::create( - 'arr_1left', - ICON::ROLE_CLICKABLE - ), + Icon::create('arr_1left'), tooltip2(_('Einen Tag zurück')) + ['class' => 'mensa-widget-back'] ); $navigation[] = $nav; @@ -186,10 +188,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin $nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'], ['mensa-widget' => ['date' => strtotime('tomorrow', $date)]])); $nav->setImage( - Icon::create( - 'arr_1right', - ICON::ROLE_CLICKABLE - ), + Icon::create('arr_1right'), tooltip2(_('Einen Tag weiter')) + ['class' => 'mensa-widget-forward'] ); $navigation[] = $nav; @@ -204,9 +203,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin /** * Get the diet for a specific date * @param null $date - * @return mixed[] $data Mensa diet + * @return array $data Mensa diet */ - private function getMenu($date = null) + private function getMenu($date = null): array { $timestamp = $date ?: strtotime('today midnight'); return MensaHelper::getMenu($timestamp); @@ -214,11 +213,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin /** * Calculate the prev / next date - * @param $date + * @param string $date * @param string $direction * @return int */ - protected function timeshift($date, $direction = 'next') + protected function timeShift(string $date, string $direction = 'next'): int { if ($direction === 'next') { do { diff --git a/assets/mensa-widget.less b/assets/mensa-widget.scss similarity index 86% rename from assets/mensa-widget.less rename to assets/mensa-widget.scss index f121a631693f9bfad8098275bc9b06bee1b06537..760b8e9a058b19bb3b2854d52e26d4c2343aa797 100755 --- a/assets/mensa-widget.less +++ b/assets/mensa-widget.scss @@ -32,7 +32,6 @@ a.mensa-widget-back, a.mensa-widget-forward { .mensa-increases { input[type=text] { - .box-sizing(border-box); width: 100%; } .new-entry:not(:only-child) { @@ -46,7 +45,7 @@ a.mensa-widget-back, a.mensa-widget-forward { .js .mensa-increases table.collapsable { .collapsable-toggle { display: block; - .icon('before', 'arr_1down', 'clickable', 24); + @include icon('before', 'arr_1down', 'clickable', 24); } &:not(.uncollapsed) { th.hidden-when-collapsed { @@ -56,7 +55,7 @@ a.mensa-widget-back, a.mensa-widget-forward { display: none; } .collapsable-toggle { - .icon('before', 'arr_1right', 'clickable', 24); + @include icon('before', 'arr_1right', 'clickable', 24); } } -} \ No newline at end of file +} diff --git a/classes/MensaCronjob.class.php b/classes/MensaCronjob.class.php index 4006b8b616452735adfea14cf5b89cf84c80212e..62abe3d7575e7654ec568664fd8f32534e9a96b1 100755 --- a/classes/MensaCronjob.class.php +++ b/classes/MensaCronjob.class.php @@ -4,7 +4,7 @@ * @author David Siegfried <david.siegfried@uni-vechta.de> * @license GPL2 or any later version */ -class MensaCronjob extends CronJob +final class MensaCronjob extends CronJob { private static $curl_timeout = 50; @@ -15,7 +15,7 @@ class MensaCronjob extends CronJob public static function getDescription() { - return _('Lädt die Speisepläne für das Studentenwerk Osnabrück herunter'); + return _('Mensa: Lädt die Speisepläne für das Studentenwerk Osnabrück herunter'); } public function setUp() @@ -25,12 +25,10 @@ class MensaCronjob extends CronJob public function execute($last_result, $parameters = []) { - $sourceFile = 'ftp://' . Config::get()->MENSA_FTP_SERVER . '/' . Config::get()->MENSA_FTP_FILE; - $filename = MensaHelper::getFilename(); + $shareServer = Config::get()->MENSA_SHARE_SERVER; + $fileName = MensaHelper::getFilename(); $curl = curl_init(); - - curl_setopt($curl, CURLOPT_URL, $sourceFile); - curl_setopt($curl, CURLOPT_USERPWD, Config::get()->MENSA_FTP_USER . ':' . Config::get()->MENSA_FTP_PASS); + curl_setopt($curl, CURLOPT_URL, $shareServer); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, self::$curl_timeout); @@ -45,12 +43,12 @@ class MensaCronjob extends CronJob curl_close($curl); if ($result !== false) { - file_put_contents($filename, $result); + file_put_contents($fileName, $result); } if (!isset($_SERVER)) { - chown($filename, 'www-data'); - chgrp($filename, 'www-data'); + chown($fileName, 'www-data'); + chgrp($fileName, 'www-data'); } } -} \ No newline at end of file +} diff --git a/classes/MensaHelper.class.php b/classes/MensaHelper.class.php index 6db6fe89db60ac05864bda36ce64ba0fe8fc590f..5a1e8ea33b38206e13c13208a298e2df3608441c 100755 --- a/classes/MensaHelper.class.php +++ b/classes/MensaHelper.class.php @@ -7,7 +7,11 @@ class MensaHelper { - public static function getMenu($timestamp = null) + /** + * @param int|null $timestamp + * @return array + */ + public static function getMenu(int $timestamp = null): array { $file = self::getFilename(); @@ -54,9 +58,9 @@ class MensaHelper return $data[$timestamp]; } - public static function getFilename() + public static function getFilename(): string { - return $GLOBALS['TMP_PATH'] . '/mensa.txt'; + return $GLOBALS['TMP_PATH'] . '/mensa.csv'; } public static function replace($string) @@ -66,4 +70,4 @@ class MensaHelper return preg_replace($patterns, $replacements, htmlReady($string)); } -} \ No newline at end of file +} diff --git a/migrations/01_add_cronjob.php b/migrations/01_add_cronjob.php index d10836ecfcfc96fe27df508e8a85a03013f9e700..b73973b30778cd066bcc613561aaf444e9269c20 100755 --- a/migrations/01_add_cronjob.php +++ b/migrations/01_add_cronjob.php @@ -5,7 +5,7 @@ * @license GPL2 or any later version */ -class AddCronjob extends Migration +final class AddCronjob extends Migration { public function description() { @@ -31,4 +31,4 @@ class AddCronjob extends Migration } } -} \ No newline at end of file +} diff --git a/migrations/02_add_config.php b/migrations/02_add_config.php index addb68893a05cd04d59319527fa414e8bafeca7d..5c88997ec6cd3c97f50413db46827898aa548f4f 100755 --- a/migrations/02_add_config.php +++ b/migrations/02_add_config.php @@ -5,13 +5,13 @@ * @license GPL2 or any later version */ -class AddConfig extends Migration +final class AddConfig extends Migration { public function description() { return 'Lagert die FTP-Daten in die globale Konfiguration aus'; } - + public function up() { if (!Config::get()->MENSA_FTP_SERVER) { @@ -24,7 +24,7 @@ class AddConfig extends Migration 'description' => _('Adresse des FTP-Servers'), ]); } - + if (!Config::get()->MENSA_FTP_USER) { Config::get()->create('MENSA_FTP_USER', [ 'value' => "", @@ -35,7 +35,7 @@ class AddConfig extends Migration 'description' => _('Benutzer'), ]); } - + if (!Config::get()->MENSA_FTP_PASS) { Config::get()->create('MENSA_FTP_PASS', [ 'value' => "", @@ -46,7 +46,7 @@ class AddConfig extends Migration 'description' => _('Passwort'), ]); } - + if (!Config::get()->MENSA_FTP_FILE) { Config::get()->create('MENSA_FTP_FILE', [ 'value' => "SPEISEPLAN-Export-4.txt", @@ -58,7 +58,7 @@ class AddConfig extends Migration ]); } } - + public function down() { Config::get()->delete('MENSA_FTP_SERVER'); @@ -66,5 +66,5 @@ class AddConfig extends Migration Config::get()->delete('MENSA_FTP_PASS'); Config::get()->delete('MENSA_FTP_FILE'); } - -} \ No newline at end of file + +} diff --git a/migrations/03_add_config_location.php b/migrations/03_add_config_location.php index 179e02057444c7b22d96687d7d6f0f67065bb363..e69b582d885a8c71a6bd298f7b8ecf4a9ddf160e 100755 --- a/migrations/03_add_config_location.php +++ b/migrations/03_add_config_location.php @@ -5,7 +5,7 @@ * @license GPL2 or any later version */ -class AddConfigLocation extends Migration +final class AddConfigLocation extends Migration { public function description() { @@ -31,4 +31,4 @@ class AddConfigLocation extends Migration Config::get()->delete('MENSA_LOCATION'); } -} \ No newline at end of file +} diff --git a/migrations/04_refine_config.php b/migrations/04_refine_config.php new file mode 100644 index 0000000000000000000000000000000000000000..d7fe7dc511bc521bb4cf9fb897e93cae6b2d3b58 --- /dev/null +++ b/migrations/04_refine_config.php @@ -0,0 +1,72 @@ +<?php + +final class RefineConfig extends Migration +{ + public function up() + { + // Delete old configuration + Config::get()->delete('MENSA_FTP_SERVER'); + Config::get()->delete('MENSA_FTP_USER'); + Config::get()->delete('MENSA_FTP_PASS'); + Config::get()->delete('MENSA_FTP_FILE'); + + if (!Config::get()->MENSA_SHARE_SERVER) { + Config::get()->create('MENSA_SHARE_SERVER', [ + 'value' => 'https://share.sw-os.de/uni-vechta', + 'is_default' => 0, + 'type' => 'string', + 'range' => 'global', + 'section' => 'MENSA_Plugin', + 'description' => _('Shareserver für den Speiseplan'), + ]); + } + } + + + public function down() + { + if (!Config::get()->MENSA_FTP_SERVER) { + Config::get()->create('MENSA_FTP_SERVER', [ + 'value' => "131.173.252.37", + 'is_default' => 0, + 'type' => 'string', + 'range' => 'global', + 'section' => 'MENSA_Plugin', + 'description' => _('Adresse des FTP-Servers'), + ]); + } + + if (!Config::get()->MENSA_FTP_USER) { + Config::get()->create('MENSA_FTP_USER', [ + 'value' => "", + 'is_default' => 0, + 'type' => 'string', + 'range' => 'global', + 'section' => 'MENSA_Plugin', + 'description' => _('Benutzer'), + ]); + } + + if (!Config::get()->MENSA_FTP_PASS) { + Config::get()->create('MENSA_FTP_PASS', [ + 'value' => "", + 'is_default' => 0, + 'type' => 'string', + 'range' => 'global', + 'section' => 'MENSA_Plugin', + 'description' => _('Passwort'), + ]); + } + + if (!Config::get()->MENSA_FTP_FILE) { + Config::get()->create('MENSA_FTP_FILE', [ + 'value' => "SPEISEPLAN-Export-4.txt", + 'is_default' => 0, + 'type' => 'string', + 'range' => 'global', + 'section' => 'MENSA_Plugin', + 'description' => _('Dateiname'), + ]); + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..1c5f67611fcd463a44f16ce40abb79c8938f85d0 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "mensa-plugin", + "version": "2.2.1", + "description": "", + "scripts": { + "dev": "webpack --watch --mode=\"development\"", + "prod": "webpack --mode=\"production\"", + "zip": "zip -r MensaPlugin-V$npm_package_version.zip assets classes migrations templates MensaPlugin.class.php plugin.manifest" + } +} diff --git a/plugin.manifest b/plugin.manifest index 0b7c3385dac204b174fbe1119601ebfc71b1410e..4c32ce61871e22db60d80ec1cfbd11be62080a60 100755 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginclassname=MensaPlugin pluginname=Mensa origin=Vec -version=2.2 +version=2.2.1 studipMinVersion=4.0 studipMaxVersion=5.9.99 description=Zeigt den Mensaplan als Widget aber auch als Gesamtübersicht an