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
/**
* 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 {
......
......@@ -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);
}
}
}
......@@ -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');
}
}
}
......@@ -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)
......
......@@ -5,7 +5,7 @@
* @license GPL2 or any later version
*/
class AddCronjob extends Migration
final class AddCronjob extends Migration
{
public function description()
{
......
......@@ -5,7 +5,7 @@
* @license GPL2 or any later version
*/
class AddConfig extends Migration
final class AddConfig extends Migration
{
public function description()
{
......
......@@ -5,7 +5,7 @@
* @license GPL2 or any later version
*/
class AddConfigLocation extends Migration
final class AddConfigLocation extends Migration
{
public function description()
{
......
<?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
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment