Skip to content
Snippets Groups Projects
Commit 9f22b14a authored by David Siegfried's avatar David Siegfried
Browse files

replace FTP againts HTTPs and cleanup, closes #2

parent a5f215c1
No related branches found
No related tags found
No related merge requests found
...@@ -34,12 +34,12 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -34,12 +34,12 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
/** /**
* Add several information to object * 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) { if (!self::$injected) {
$this->addStylesheet('assets/mensa-widget.less'); $this->addStylesheet('assets/mensa-widget.scss');
PageLayout::addScript($this->getPluginURL() . '/assets/mensa-widget.js'); PageLayout::addScript($this->getPluginURL() . '/assets/mensa-widget.js');
PageLayout::addHeadElement('meta', [ PageLayout::addHeadElement('meta', [
'name' => 'mensa-widget-url', 'name' => 'mensa-widget-url',
...@@ -59,9 +59,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -59,9 +59,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* as the request was not issued via AJAX). * as the request was not issued via AJAX).
* *
* @param String $template Name of the template file * @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; static $factory = null;
if ($factory === null) { if ($factory === null) {
...@@ -76,10 +77,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -76,10 +77,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* Displays the menu for a certain a specific date. * Displays the menu for a certain a specific date.
* *
* @param mixed $date Date to display; optional, defaults to today * @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('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 30 * 60));
header('Pragma: cache'); header('Pragma: cache');
...@@ -95,7 +97,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -95,7 +97,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* *
* @return String containing the localized plugin name. * @return String containing the localized plugin name.
*/ */
public function getPluginName() public function getPluginName(): string
{ {
return _('Mensaplan'); return _('Mensaplan');
} }
...@@ -106,7 +108,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -106,7 +108,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* @param int $date Date to display the title for * @param int $date Date to display the title for
* @return String containing the widget title for the given date. * @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); return $this->getPluginName() . ' - ' . strftime('%A %x', $date);
} }
...@@ -116,8 +118,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -116,8 +118,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* *
* @param int $date Date to display * @param int $date Date to display
* @return String containing the html output for the menu * @return String containing the html output for the menu
* @throws Flexi_TemplateNotFoundException
*/ */
private function renderMenu($date) private function renderMenu(int $date): string
{ {
try { try {
$template = $this->getTemplate('menu.php'); $template = $this->getTemplate('menu.php');
...@@ -140,9 +143,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -140,9 +143,10 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* *
* @param int $date Date to display * @param int $date Date to display
* @return String containing the html output for the widget * @return String containing the html output for the widget
* @throws Flexi_TemplateNotFoundException
* @see MensaWidget::renderMenu * @see MensaWidget::renderMenu
*/ */
private function renderWidget($date) private function renderWidget(int $date): string
{ {
$template = $this->getTemplate('widget.php'); $template = $this->getTemplate('widget.php');
$template->menu = $this->renderMenu($date); $template->menu = $this->renderMenu($date);
...@@ -153,6 +157,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -153,6 +157,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
* Renders the portal widget. * Renders the portal widget.
* *
* @return FlexiTemplate object * @return FlexiTemplate object
* @throws Flexi_TemplateNotFoundException
*/ */
public function getPortalTemplate() public function getPortalTemplate()
{ {
...@@ -161,7 +166,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -161,7 +166,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
if (isset($options['date'])) { if (isset($options['date'])) {
$date = $options['date']; $date = $options['date'];
} elseif (date('G') >= 15) { } elseif (date('G') >= 15) {
$date = $this->timeshift(time(), 'next'); $date = $this->timeShift(time());
} else { } else {
$date = strtotime('today midnight'); $date = strtotime('today midnight');
} }
...@@ -174,10 +179,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -174,10 +179,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
$nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'], $nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'],
['mensa-widget' => ['date' => strtotime('yesterday', $date)]])); ['mensa-widget' => ['date' => strtotime('yesterday', $date)]]));
$nav->setImage( $nav->setImage(
Icon::create( Icon::create('arr_1left'),
'arr_1left',
ICON::ROLE_CLICKABLE
),
tooltip2(_('Einen Tag zurück')) + ['class' => 'mensa-widget-back'] tooltip2(_('Einen Tag zurück')) + ['class' => 'mensa-widget-back']
); );
$navigation[] = $nav; $navigation[] = $nav;
...@@ -186,10 +188,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -186,10 +188,7 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
$nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'], $nav->setURL(URLHelper::getURL($GLOBALS['ABSOLUTE_URI_STUDIP'],
['mensa-widget' => ['date' => strtotime('tomorrow', $date)]])); ['mensa-widget' => ['date' => strtotime('tomorrow', $date)]]));
$nav->setImage( $nav->setImage(
Icon::create( Icon::create('arr_1right'),
'arr_1right',
ICON::ROLE_CLICKABLE
),
tooltip2(_('Einen Tag weiter')) + ['class' => 'mensa-widget-forward'] tooltip2(_('Einen Tag weiter')) + ['class' => 'mensa-widget-forward']
); );
$navigation[] = $nav; $navigation[] = $nav;
...@@ -204,9 +203,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -204,9 +203,9 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
/** /**
* Get the diet for a specific date * Get the diet for a specific date
* @param null $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'); $timestamp = $date ?: strtotime('today midnight');
return MensaHelper::getMenu($timestamp); return MensaHelper::getMenu($timestamp);
...@@ -214,11 +213,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin ...@@ -214,11 +213,11 @@ class MensaPlugin extends StudIPPlugin implements PortalPlugin
/** /**
* Calculate the prev / next date * Calculate the prev / next date
* @param $date * @param string $date
* @param string $direction * @param string $direction
* @return int * @return int
*/ */
protected function timeshift($date, $direction = 'next') protected function timeShift(string $date, string $direction = 'next'): int
{ {
if ($direction === 'next') { if ($direction === 'next') {
do { do {
......
...@@ -32,7 +32,6 @@ a.mensa-widget-back, a.mensa-widget-forward { ...@@ -32,7 +32,6 @@ a.mensa-widget-back, a.mensa-widget-forward {
.mensa-increases { .mensa-increases {
input[type=text] { input[type=text] {
.box-sizing(border-box);
width: 100%; width: 100%;
} }
.new-entry:not(:only-child) { .new-entry:not(:only-child) {
...@@ -46,7 +45,7 @@ a.mensa-widget-back, a.mensa-widget-forward { ...@@ -46,7 +45,7 @@ a.mensa-widget-back, a.mensa-widget-forward {
.js .mensa-increases table.collapsable { .js .mensa-increases table.collapsable {
.collapsable-toggle { .collapsable-toggle {
display: block; display: block;
.icon('before', 'arr_1down', 'clickable', 24); @include icon('before', 'arr_1down', 'clickable', 24);
} }
&:not(.uncollapsed) { &:not(.uncollapsed) {
th.hidden-when-collapsed { th.hidden-when-collapsed {
...@@ -56,7 +55,7 @@ a.mensa-widget-back, a.mensa-widget-forward { ...@@ -56,7 +55,7 @@ a.mensa-widget-back, a.mensa-widget-forward {
display: none; display: none;
} }
.collapsable-toggle { .collapsable-toggle {
.icon('before', 'arr_1right', 'clickable', 24); @include icon('before', 'arr_1right', 'clickable', 24);
} }
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author David Siegfried <david.siegfried@uni-vechta.de> * @author David Siegfried <david.siegfried@uni-vechta.de>
* @license GPL2 or any later version * @license GPL2 or any later version
*/ */
class MensaCronjob extends CronJob final class MensaCronjob extends CronJob
{ {
private static $curl_timeout = 50; private static $curl_timeout = 50;
...@@ -15,7 +15,7 @@ class MensaCronjob extends CronJob ...@@ -15,7 +15,7 @@ class MensaCronjob extends CronJob
public static function getDescription() 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() public function setUp()
...@@ -25,12 +25,10 @@ class MensaCronjob extends CronJob ...@@ -25,12 +25,10 @@ class MensaCronjob extends CronJob
public function execute($last_result, $parameters = []) public function execute($last_result, $parameters = [])
{ {
$sourceFile = 'ftp://' . Config::get()->MENSA_FTP_SERVER . '/' . Config::get()->MENSA_FTP_FILE; $shareServer = Config::get()->MENSA_SHARE_SERVER;
$filename = MensaHelper::getFilename(); $fileName = MensaHelper::getFilename();
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $shareServer);
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_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, self::$curl_timeout); curl_setopt($curl, CURLOPT_TIMEOUT, self::$curl_timeout);
...@@ -45,12 +43,12 @@ class MensaCronjob extends CronJob ...@@ -45,12 +43,12 @@ class MensaCronjob extends CronJob
curl_close($curl); curl_close($curl);
if ($result !== false) { if ($result !== false) {
file_put_contents($filename, $result); file_put_contents($fileName, $result);
} }
if (!isset($_SERVER)) { if (!isset($_SERVER)) {
chown($filename, 'www-data'); chown($fileName, 'www-data');
chgrp($filename, 'www-data'); chgrp($fileName, 'www-data');
} }
} }
} }
\ No newline at end of file
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
class MensaHelper 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(); $file = self::getFilename();
...@@ -54,9 +58,9 @@ class MensaHelper ...@@ -54,9 +58,9 @@ class MensaHelper
return $data[$timestamp]; 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) public static function replace($string)
...@@ -66,4 +70,4 @@ class MensaHelper ...@@ -66,4 +70,4 @@ class MensaHelper
return preg_replace($patterns, $replacements, htmlReady($string)); return preg_replace($patterns, $replacements, htmlReady($string));
} }
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license GPL2 or any later version * @license GPL2 or any later version
*/ */
class AddCronjob extends Migration final class AddCronjob extends Migration
{ {
public function description() public function description()
{ {
...@@ -31,4 +31,4 @@ class AddCronjob extends Migration ...@@ -31,4 +31,4 @@ class AddCronjob extends Migration
} }
} }
} }
\ No newline at end of file
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
* @license GPL2 or any later version * @license GPL2 or any later version
*/ */
class AddConfig extends Migration final class AddConfig extends Migration
{ {
public function description() public function description()
{ {
return 'Lagert die FTP-Daten in die globale Konfiguration aus'; return 'Lagert die FTP-Daten in die globale Konfiguration aus';
} }
public function up() public function up()
{ {
if (!Config::get()->MENSA_FTP_SERVER) { if (!Config::get()->MENSA_FTP_SERVER) {
...@@ -24,7 +24,7 @@ class AddConfig extends Migration ...@@ -24,7 +24,7 @@ class AddConfig extends Migration
'description' => _('Adresse des FTP-Servers'), 'description' => _('Adresse des FTP-Servers'),
]); ]);
} }
if (!Config::get()->MENSA_FTP_USER) { if (!Config::get()->MENSA_FTP_USER) {
Config::get()->create('MENSA_FTP_USER', [ Config::get()->create('MENSA_FTP_USER', [
'value' => "", 'value' => "",
...@@ -35,7 +35,7 @@ class AddConfig extends Migration ...@@ -35,7 +35,7 @@ class AddConfig extends Migration
'description' => _('Benutzer'), 'description' => _('Benutzer'),
]); ]);
} }
if (!Config::get()->MENSA_FTP_PASS) { if (!Config::get()->MENSA_FTP_PASS) {
Config::get()->create('MENSA_FTP_PASS', [ Config::get()->create('MENSA_FTP_PASS', [
'value' => "", 'value' => "",
...@@ -46,7 +46,7 @@ class AddConfig extends Migration ...@@ -46,7 +46,7 @@ class AddConfig extends Migration
'description' => _('Passwort'), 'description' => _('Passwort'),
]); ]);
} }
if (!Config::get()->MENSA_FTP_FILE) { if (!Config::get()->MENSA_FTP_FILE) {
Config::get()->create('MENSA_FTP_FILE', [ Config::get()->create('MENSA_FTP_FILE', [
'value' => "SPEISEPLAN-Export-4.txt", 'value' => "SPEISEPLAN-Export-4.txt",
...@@ -58,7 +58,7 @@ class AddConfig extends Migration ...@@ -58,7 +58,7 @@ class AddConfig extends Migration
]); ]);
} }
} }
public function down() public function down()
{ {
Config::get()->delete('MENSA_FTP_SERVER'); Config::get()->delete('MENSA_FTP_SERVER');
...@@ -66,5 +66,5 @@ class AddConfig extends Migration ...@@ -66,5 +66,5 @@ class AddConfig extends Migration
Config::get()->delete('MENSA_FTP_PASS'); Config::get()->delete('MENSA_FTP_PASS');
Config::get()->delete('MENSA_FTP_FILE'); Config::get()->delete('MENSA_FTP_FILE');
} }
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license GPL2 or any later version * @license GPL2 or any later version
*/ */
class AddConfigLocation extends Migration final class AddConfigLocation extends Migration
{ {
public function description() public function description()
{ {
...@@ -31,4 +31,4 @@ class AddConfigLocation extends Migration ...@@ -31,4 +31,4 @@ class AddConfigLocation extends Migration
Config::get()->delete('MENSA_LOCATION'); Config::get()->delete('MENSA_LOCATION');
} }
} }
\ No newline at end of file
<?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'),
]);
}
}
}
{
"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"
}
}
pluginclassname=MensaPlugin pluginclassname=MensaPlugin
pluginname=Mensa pluginname=Mensa
origin=Vec origin=Vec
version=2.2 version=2.2.1
studipMinVersion=4.0 studipMinVersion=4.0
studipMaxVersion=5.9.99 studipMaxVersion=5.9.99
description=Zeigt den Mensaplan als Widget aber auch als Gesamtübersicht an description=Zeigt den Mensaplan als Widget aber auch als Gesamtübersicht an
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment