From f7c09cb7ff84db1004a4fa83a70735475702023f Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 20 Jan 2017 21:12:19 +0100 Subject: Added exception handler --- src/Exceptions/Handler.php | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/Exceptions/Handler.php (limited to 'src/Exceptions/Handler.php') diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php new file mode 100644 index 00000000..a81900b6 --- /dev/null +++ b/src/Exceptions/Handler.php @@ -0,0 +1,97 @@ +environment = $environment; + + set_error_handler([$this, 'errorHandler']); + set_exception_handler([$this, 'exceptionHandler']); + } + + /** + * @param int $number + * @param string $string + * @param string $file + * @param int $line + * @param array $context + */ + public function errorHandler($number, $string, $file, $line, $context) + { + $this->handle('error', $number, $string, $file, $line, $context); + } + + /** + * @param Exception $e + */ + public function exceptionHandler(Exception $e) + { + $this->handle( + 'exception', + $e->getCode(), + get_class($e) . ': ' . $e->getMessage(), + $e->getFile(), + $e->getLine() + ); + } + + /** + * @param string $type + * @param int $number + * @param string $string + * @param string $file + * @param int $line + * @param array $context + */ + protected function handle($type, $number, $string, $file, $line, $context = []) + { + error_log(sprintf('%s: Number: %s, String: %s, File: %s:%u, Context: %s', + $type, + $number, + $string, + $file, + $line, + json_encode($context) + )); + + if ($this->environment == self::ENV_DEVELOPMENT || $this->environment == self::ENV_DEBUGGING) { + echo '
';
+            echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number);
+            var_export([
+                'string'  => $string,
+                'file'    => $file . ':' . $line,
+                'context' => ($this->environment == self::ENV_DEBUGGING ? $context : null),
+            ]);
+            echo '
'; + die(); + } + + echo 'An unexpected error occurred, a team of untrained monkeys has been dispatched to deal with it.'; + die(); + } + + /** + * @param string $environment + */ + public function setEnvironment($environment) + { + $this->environment = $environment; + } +} -- cgit v1.2.3-70-g09d2 From 8506d6d27e3b926521007064abcdcc2f69c6aa06 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 21 Jan 2017 23:07:20 +0100 Subject: Refactoring: Config cleanup / moved to class --- composer.json | 5 +- config/config.default.php | 170 ++++++++++++++---------- includes/controller/shifts_controller.php | 4 +- includes/controller/users_controller.php | 6 +- includes/engelsystem_provider.php | 82 ++++++++---- includes/helper/internationalization_helper.php | 12 +- includes/model/User_model.php | 7 +- includes/pages/admin_active.php | 5 +- includes/pages/admin_user.php | 9 +- includes/pages/guest_login.php | 14 +- includes/pages/guest_stats.php | 4 +- includes/pages/user_atom.php | 4 +- includes/pages/user_myshifts.php | 6 +- includes/pages/user_news.php | 6 +- includes/pages/user_settings.php | 16 ++- includes/sys_auth.php | 5 +- includes/view/AngelTypes_view.php | 4 +- includes/view/User_view.php | 34 ++--- public/index.php | 6 +- src/Config/Config.php | 128 ++++++++++++++++++ src/Exceptions/Handler.php | 8 +- src/helpers.php | 24 ++++ 22 files changed, 393 insertions(+), 166 deletions(-) create mode 100644 src/Config/Config.php create mode 100644 src/helpers.php (limited to 'src/Exceptions/Handler.php') diff --git a/composer.json b/composer.json index bb21de23..7655275c 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,9 @@ "autoload": { "psr-4": { "Engelsystem\\": "src/" - } + }, + "files": [ + "src/helpers.php" + ] } } diff --git a/config/config.default.php b/config/config.default.php index bcfcc89c..437399e3 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -1,70 +1,106 @@ 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < 6) - OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < 6) - OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= 6) - ))*(`Shifts`.`end` - `Shifts`.`start`)*(1 - 3 * `ShiftEntry`.`freeloaded`) -)'; - -// voucher calculation -$voucher_settings = [ - 'initial_vouchers' => 2, - 'shifts_per_voucher' => 1 -]; - -// weigh every shift the same -// $shift_sum_formula = 'SUM(`end` - `start`)'; - -// For accessing stats -$api_key = ''; - -// MySQL-Connection Settings -$config = [ - 'host' => 'localhost', - 'user' => 'root', - 'pw' => '', - 'db' => 'engelsystem' +// To change settings create a config.php + +return [ + // MySQL-Connection Settings + 'database' => [ + 'host' => 'localhost', + 'user' => 'root', + 'pw' => '', + 'db' => 'engelsystem', + ], + + // For accessing stats + 'api_key' => '', + + // Enable maintenance mode (show a static page) + 'maintenance' => false, + + // Set to development to enable debugging messages + 'environment' => 'production', + + // URL to the angel faq and job description + 'faq_url' => 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers', + + // Contact email address, linked on every page + 'contact_email' => 'mailto:ticket@c3heaven.de', + + // Default theme of the start page, 1=style1.css + 'default_theme' => 1, + + // Number of News shown on one site + 'display_news' => 6, + + // Anzahl Stunden bis zum Austragen eigener Schichten + 'last_unsubscribe' => 3, + + // Setzt den zu verwendenden Crypto-Algorismus (entsprechend der Dokumentation von crypt()). + // Falls ein Benutzerpasswort in einem anderen Format gespeichert ist, + // wird es bei der ersten Benutzung des Klartext-Passworts in das neue Format + // konvertiert. + // MD5 '$1' + // Blowfish '$2y$13' + // SHA-256 '$5$rounds=5000' + // SHA-512 '$6$rounds=5000' + 'crypt_alg' => '$6$rounds=5000', // SHA-512 + + 'min_password_length' => 8, + + // Wenn Engel beim Registrieren oder in ihrem Profil eine T-Shirt Größe angeben sollen, auf true setzen: + 'enable_tshirt_size' => true, + + // Number of shifts to freeload until angel is locked for shift signup. + 'max_freeloadable_shifts' => 2, + + // local timezone + 'timezone' => 'Europe/Berlin', + + // multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2 + 'shift_sum_formula' => ' + SUM( + (1 + + ( + (HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < 6) + OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < 6) + OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= 6) + ) + ) + * (`Shifts`.`end` - `Shifts`.`start`) + * (1 - 3 * `ShiftEntry`.`freeloaded`) + ) + ', + // weigh every shift the same + //'shift_sum_formula' => 'SUM(`end` - `start`)', + + // voucher calculation + 'voucher_settings' => [ + 'initial_vouchers' => 2, + 'shifts_per_voucher' => 1, + ], + + // Available locales in /locale/ + 'locales' => [ + 'de_DE.UTF-8' => 'Deutsch', + 'en_US.UTF-8' => 'English', + ], + + 'default_locale' => 'en_US.UTF-8', + + // Available T-Shirt sizes, set value to null if not available + 'tshirt_sizes' => [ + '' => _('Please select...'), + 'S' => 'S', + 'M' => 'M', + 'L' => 'L', + 'XL' => 'XL', + '2XL' => '2XL', + '3XL' => '3XL', + '4XL' => '4XL', + '5XL' => '5XL', + 'S-G' => 'S Girl', + 'M-G' => 'M Girl', + 'L-G' => 'L Girl', + 'XL-G' => 'XL Girl', + ], ]; diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 71459a10..a1801de6 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -329,9 +329,9 @@ function shift_next_controller() */ function shifts_json_export_all_controller() { - global $api_key; + $api_key = config('api_key'); - if ($api_key == '') { + if (empty($api_key)) { engelsystem_error('Config contains empty apikey.'); } diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index b80fdb4d..84b6bbda 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -282,7 +282,6 @@ function users_list_controller() */ function user_password_recovery_set_new_controller() { - global $min_password_length; $user_source = User_by_password_recovery_token($_REQUEST['token']); if ($user_source == null) { error(_('Token is not correct.')); @@ -292,7 +291,10 @@ function user_password_recovery_set_new_controller() if (isset($_REQUEST['submit'])) { $valid = true; - if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) { + if ( + isset($_REQUEST['password']) + && strlen($_REQUEST['password']) >= config('min_password_length') + ) { if ($_REQUEST['password'] != $_REQUEST['password2']) { $valid = false; error(_('Your passwords don\'t match.')); diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 3537f100..8a5723ef 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -1,5 +1,6 @@ set(require __DIR__ . '/../config/config.default.php'); + +if (file_exists(__DIR__ . '/../config/config.php')) { + $config->set(array_replace_recursive( + $config->get(null), + require __DIR__ . '/../config/config.php' + )); +} + +date_default_timezone_set($config->get('timezone')); + + +/** + * Check for maintenance + */ +if ($config->get('maintenance')) { + echo file_get_contents(__DIR__ . '/../public/maintenance.html'); + die(); +} + + +/** + * Register error handler + */ +$errorHandler = new ExceptionHandler(); +if (config('environment') == 'development') { + $errorHandler->setEnvironment(ExceptionHandler::ENV_DEVELOPMENT); + ini_set('display_errors', true); + error_reporting(E_ALL); +} else { + ini_set('display_errors', false); +} + + +/** + * Connect to database + */ +Db::connect( + 'mysql:host=' . config('database')['host'] . ';dbname=' . config('database')['db'] . ';charset=utf8', + config('database')['user'], + config('database')['pw'] +) || die('Error: Unable to connect to database'); +Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + +/** + * Include legacy code + */ require_once realpath(__DIR__ . '/../includes/sys_auth.php'); require_once realpath(__DIR__ . '/../includes/sys_form.php'); require_once realpath(__DIR__ . '/../includes/sys_log.php'); @@ -71,17 +126,6 @@ require_once realpath(__DIR__ . '/../includes/helper/email_helper.php'); require_once realpath(__DIR__ . '/../includes/mailer/shifts_mailer.php'); require_once realpath(__DIR__ . '/../includes/mailer/users_mailer.php'); -$config = []; -require_once realpath(__DIR__ . '/../config/config.default.php'); -if (file_exists(realpath(__DIR__ . '/../config/config.php'))) { - require_once realpath(__DIR__ . '/../config/config.php'); -} - -if ($maintenance_mode) { - echo file_get_contents(__DIR__ . '/../public/maintenance.html'); - die(); -} - require_once realpath(__DIR__ . '/../includes/pages/admin_active.php'); require_once realpath(__DIR__ . '/../includes/pages/admin_arrive.php'); require_once realpath(__DIR__ . '/../includes/pages/admin_free.php'); @@ -100,20 +144,10 @@ require_once realpath(__DIR__ . '/../includes/pages/user_questions.php'); require_once realpath(__DIR__ . '/../includes/pages/user_settings.php'); require_once realpath(__DIR__ . '/../includes/pages/user_shifts.php'); -$errorHandler = new ExceptionHandler( - ($environment == 'development' - ? ExceptionHandler::ENV_DEVELOPMENT - : ExceptionHandler::ENV_PRODUCTION - ) -); - -Db::connect( - 'mysql:host=' . $config['host'] . ';dbname=' . $config['db'] . ';charset=utf8', - $config['user'], - $config['pw'] -) || die('Error: Unable to connect to database'); -Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +/** + * Init application + */ session_start(); gettext_init(); diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php index 7c04ebbd..ed16de15 100644 --- a/includes/helper/internationalization_helper.php +++ b/includes/helper/internationalization_helper.php @@ -1,10 +1,4 @@ 'Deutsch', - 'en_US.UTF-8' => 'English' -]; - -$default_locale = 'en_US.UTF-8'; /** * Return currently active locale @@ -31,7 +25,8 @@ function locale_short() */ function gettext_init() { - global $locales, $default_locale; + $locales = config('locales'); + $default_locale = config('default_locale'); if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) { $_SESSION['locale'] = $_REQUEST['set_locale']; @@ -67,11 +62,10 @@ function gettext_locale($locale = null) */ function make_langselect() { - global $locales; $url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale='; $items = []; - foreach ($locales as $locale => $name) { + foreach (config('locales') as $locale => $name) { $items[] = toolbar_item_link( htmlspecialchars($url) . $locale, '', diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 097e8faf..53b4ce1e 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -215,9 +215,9 @@ function Users($order_by = 'Nick') */ function User_is_freeloader($user) { - global $max_freeloadable_shifts, $user; + global $user; - return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts; + return count(ShiftEntries_freeloaded_by_user($user)) >= config('max_freeloadable_shifts'); } /** @@ -542,8 +542,7 @@ function User_generate_password_recovery_token(&$user) */ function User_get_eligable_voucher_count(&$user) { - global $voucher_settings; - + $voucher_settings = config('voucher_settings'); $shifts_done = count(ShiftEntries_finished_by_user($user)); $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 275f50ba..8cb66e6e 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -15,7 +15,8 @@ function admin_active_title() */ function admin_active() { - global $tshirt_sizes, $shift_sum_formula; + $tshirt_sizes = config('tshirt_sizes'); + $shift_sum_formula = config('shift_sum_formula'); $msg = ''; $search = ''; @@ -208,7 +209,7 @@ function admin_active() $shirt_statistics = []; foreach (array_keys($tshirt_sizes) as $size) { - if ($size != '') { + if (!empty($size)) { $sc = DB::select( 'SELECT count(*) FROM `User` WHERE `Size`=? AND `Gekommen`=1', [$size] diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 192becb0..2ab40cca 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -15,7 +15,14 @@ function admin_user_title() */ function admin_user() { - global $user, $tshirt_sizes, $privileges; + global $user, $privileges; + $tshirt_sizes = config('tshirt_sizes'); + + foreach ($tshirt_sizes as $key => $size) { + if (empty($size)) { + unset($tshirt_sizes[$key]); + } + } $html = ''; diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 66a06116..2ffa4b98 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -33,8 +33,10 @@ function logout_title() */ function guest_register() { - global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length; - + global $user; + $tshirt_sizes = config('tshirt_sizes'); + $enable_tshirt_size = config('enable_tshirt_size'); + $min_password_length = config('min_password_length'); $event_config = EventConfig(); $msg = ''; @@ -65,6 +67,12 @@ function guest_register() } } + foreach ($tshirt_sizes as $key => $size) { + if (empty($size)) { + unset($tshirt_sizes[$key]); + } + } + if (isset($_REQUEST['submit'])) { $valid = true; @@ -201,7 +209,7 @@ function guest_register() VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, NULL, ?) ', [ - $default_theme, + config('default_theme'), $nick, $preName, $lastName, diff --git a/includes/pages/guest_stats.php b/includes/pages/guest_stats.php index 4add3e97..6b6f0572 100644 --- a/includes/pages/guest_stats.php +++ b/includes/pages/guest_stats.php @@ -4,10 +4,10 @@ use Engelsystem\Database\DB; function guest_stats() { - global $api_key; + $apiKey = config('api_key'); if (isset($_REQUEST['api_key'])) { - if ($_REQUEST['api_key'] == $api_key) { + if ($_REQUEST['api_key'] == $apiKey && !empty($apiKey)) { $stats = []; list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`'); diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index 3c4b631d..5574e8eb 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -7,7 +7,7 @@ use Engelsystem\Database\DB; */ function user_atom() { - global $user, $display_news; + global $user; if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) { engelsystem_error('Missing key.'); @@ -27,7 +27,7 @@ function user_atom() FROM `News` ' . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . ' ORDER BY `ID` - DESC LIMIT ' . (int)$display_news + DESC LIMIT ' . (int)config('display_news') ); $output = make_atom_entries_from_news($news); diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index acb78875..62d87d27 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -17,7 +17,6 @@ function myshifts_title() */ function user_myshifts() { - global $last_unsubscribe; global $user, $privileges; if ( @@ -144,7 +143,10 @@ function user_myshifts() ); if (count($shift) > 0) { $shift = array_shift($shift); - if (($shift['start'] > time() + $last_unsubscribe * 3600) || in_array('user_shifts_admin', $privileges)) { + if ( + ($shift['start'] > time() + config('last_unsubscribe') * 3600) + || in_array('user_shifts_admin', $privileges) + ) { $result = ShiftEntry_delete($user_id); if ($result === false) { engelsystem_error('Unable to delete shift entry.'); diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index 69d20e69..b1e337b6 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -31,8 +31,7 @@ function meetings_title() */ function user_meetings() { - global $display_news; - + $display_news = config('display_news'); $html = '

' . meetings_title() . '

' . msg(); if (isset($_REQUEST['page']) && preg_match('/^\d{1,}$/', $_REQUEST['page'])) { @@ -178,7 +177,8 @@ function user_news_comments() */ function user_news() { - global $display_news, $privileges, $user; + global $privileges, $user; + $display_news = config('display_news'); $html = '

' . news_title() . '

' . msg(); diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 5d4ba368..a2a486f4 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -97,13 +97,12 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) */ function user_settings_password($user_source) { - global $min_password_length; if ( !isset($_REQUEST['password']) || !verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID']) ) { error(_('-> not OK. Please try again.')); - } elseif (strlen($_REQUEST['new_password']) < $min_password_length) { + } elseif (strlen($_REQUEST['new_password']) < config('min_password_length')) { error(_('Your password is to short (please use at least 6 characters).')); } elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) { error(_('Your passwords don\'t match.')); @@ -195,8 +194,11 @@ function user_settings_locale($user_source, $locales) */ function user_settings() { - global $enable_tshirt_size, $tshirt_sizes, $themes, $locales; - global $user; + global $themes, $user; + + $enable_tshirt_size = config('enable_tshirt_size'); + $tshirt_sizes = config('tshirt_sizes'); + $locales = config('locales'); $buildup_start_date = null; $teardown_end_date = null; @@ -210,6 +212,12 @@ function user_settings() } } + foreach ($tshirt_sizes as $key => $size) { + if (empty($size)) { + unset($tshirt_sizes[$key]); + } + } + $user_source = $user; if (isset($_REQUEST['submit'])) { diff --git a/includes/sys_auth.php b/includes/sys_auth.php index 083c1b8d..856ed4ab 100644 --- a/includes/sys_auth.php +++ b/includes/sys_auth.php @@ -59,7 +59,6 @@ function generate_salt($length = 16) */ function set_password($uid, $password) { - global $crypt_alg; $result = DB::update(' UPDATE `User` SET `Passwort` = ?, @@ -68,7 +67,7 @@ function set_password($uid, $password) LIMIT 1 ', [ - crypt($password, $crypt_alg . '$' . generate_salt(16) . '$'), + crypt($password, config('crypt_alg') . '$' . generate_salt(16) . '$'), $uid ] ); @@ -89,7 +88,7 @@ function set_password($uid, $password) */ function verify_password($password, $salt, $uid = null) { - global $crypt_alg; + $crypt_alg = config('crypt_alg'); $correct = false; if (substr($salt, 0, 1) == '$') { // new-style crypt() $correct = crypt($password, $salt) == $salt; diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index be866c9b..bd258d3a 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -443,14 +443,12 @@ function AngelTypes_about_view_angeltype($angeltype) */ function AngelTypes_about_view($angeltypes, $user_logged_in) { - global $faq_url; - $content = [ buttons([ !$user_logged_in ? button(page_link_to('register'), register_title()) : '', !$user_logged_in ? button(page_link_to('login'), login_title()) : '', $user_logged_in ? button(page_link_to('angeltypes'), angeltypes_title(), 'back') : '', - button($faq_url, _('FAQ'), 'btn-primary') + button(config('faq_url'), _('FAQ'), 'btn-primary') ]), '

' . _('Here is the list of teams and their tasks. If you have questions, read the FAQ.') . '

', '
' diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 50c54f5a..932614a7 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -1,24 +1,5 @@ _('Please select...'), - 'S' => 'S', - 'M' => 'M', - 'L' => 'L', - 'XL' => 'XL', - '2XL' => '2XL', - '3XL' => '3XL', - '4XL' => '4XL', - '5XL' => '5XL', - 'S-G' => 'S Girl', - 'M-G' => 'M Girl', - 'L-G' => 'L Girl', - 'XL-G' => 'XL Girl' -]; - /** * Renders user settings page * @@ -335,7 +316,7 @@ function User_view_shiftentries($needed_angel_type) */ function User_view_myshift($shift, $user_source, $its_me) { - global $last_unsubscribe, $privileges; + global $privileges; $shift_info = '' . $shift['name'] . ''; if ($shift['title']) { @@ -371,7 +352,10 @@ function User_view_myshift($shift, $user_source, $its_me) 'btn-xs' ); } - if (($shift['start'] > time() + $last_unsubscribe * 3600) || in_array('user_shifts_admin', $privileges)) { + if ( + ($shift['start'] > time() + config('last_unsubscribe') * 3600) + || in_array('user_shifts_admin', $privileges) + ) { $myshift['actions'][] = button( page_link_to('user_myshifts') . ((!$its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'], glyph('trash') . _('sign off'), @@ -646,12 +630,12 @@ function render_user_departure_date_hint() */ function render_user_freeloader_hint() { - global $user, $max_freeloadable_shifts; + global $user; if (User_is_freeloader($user)) { return sprintf( _('You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again.'), - $max_freeloadable_shifts + config('max_freeloadable_shifts') ); } @@ -679,9 +663,9 @@ function render_user_arrived_hint() */ function render_user_tshirt_hint() { - global $enable_tshirt_size, $user; + global $user; - if ($enable_tshirt_size && $user['Size'] == '') { + if (config('enable_tshirt_size') && $user['Size'] == '') { return _('You need to specify a tshirt size in your settings!'); } diff --git a/public/index.php b/public/index.php index 12d6f744..4e5dab03 100644 --- a/public/index.php +++ b/public/index.php @@ -169,7 +169,7 @@ if ( $event_config = EventConfig(); echo template_render(__DIR__ . '/../templates/layout.html', [ - 'theme' => isset($user) ? $user['color'] : $default_theme, + 'theme' => isset($user) ? $user['color'] : config('default_theme'), 'title' => $title, 'atom_link' => ($page == 'news' || $page == 'user_meetings') ? ' '; echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number); var_export([ 'string' => $string, 'file' => $file . ':' . $line, - 'context' => ($this->environment == self::ENV_DEBUGGING ? $context : null), + 'context' => ($this->environment == self::ENV_DEVELOPMENT ? $context : null), ]); echo ''; die(); diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 00000000..aeb256e9 --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,24 @@ +set($key); + } + + return Config::getInstance()->get($key, $default); +} -- cgit v1.2.3-70-g09d2 From 144b453bc6b594ea16838a006eb20b04e5b5ec19 Mon Sep 17 00:00:00 2001 From: msquare Date: Sun, 23 Jul 2017 12:18:32 +0200 Subject: fix unreadable exception --- src/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Exceptions/Handler.php') diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 0532a7d8..942e11d6 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -72,7 +72,7 @@ class Handler )); if ($this->environment == self::ENV_DEVELOPMENT) { - echo '
';
+            echo '
';
             echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number);
             var_export([
                 'string'  => $string,
-- 
cgit v1.2.3-70-g09d2


From 440ed74cd7a0bde035a93fde36b08b9a5aca557d Mon Sep 17 00:00:00 2001
From: msquare 
Date: Fri, 28 Jul 2017 19:28:00 +0200
Subject: exception handler should handle throwables instead of exceptions

---
 src/Exceptions/Handler.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'src/Exceptions/Handler.php')

diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php
index 942e11d6..e52549e7 100644
--- a/src/Exceptions/Handler.php
+++ b/src/Exceptions/Handler.php
@@ -2,7 +2,7 @@
 
 namespace Engelsystem\Exceptions;
 
-use Exception;
+use Throwable;
 
 class Handler
 {
@@ -38,9 +38,9 @@ class Handler
     }
 
     /**
-     * @param Exception $e
+     * @param Throwable $e
      */
-    public function exceptionHandler(Exception $e)
+    public function exceptionHandler(Throwable $e)
     {
         $this->handle(
             'exception',
-- 
cgit v1.2.3-70-g09d2


From cc01c906ba63b3797bf2b9ef92a6854fe2ddbefb Mon Sep 17 00:00:00 2001
From: Igor Scheller 
Date: Tue, 29 Aug 2017 16:21:25 +0200
Subject: #336: Integration of symfony/http-foundation request

---
 composer.json                                    |   5 +-
 config/config.default.php                        |   5 +-
 includes/controller/angeltypes_controller.php    |   2 +-
 includes/controller/shift_entries_controller.php |   2 +-
 includes/controller/shifts_controller.php        |  25 ++--
 includes/controller/users_controller.php         |  12 +-
 includes/engelsystem_provider.php                |   5 +-
 includes/helper/internationalization_helper.php  |  14 ++-
 includes/pages/admin_groups.php                  |   5 +-
 includes/pages/admin_news.php                    |   7 +-
 includes/pages/admin_rooms.php                   |  13 ++-
 includes/pages/admin_shifts.php                  |  10 +-
 includes/pages/admin_user.php                    |  40 +++----
 includes/pages/guest_login.php                   |   8 +-
 includes/pages/user_atom.php                     |  17 +--
 includes/pages/user_news.php                     |  10 +-
 includes/pages/user_settings.php                 |   8 +-
 includes/pages/user_shifts.php                   |   4 +-
 includes/sys_form.php                            |   9 +-
 includes/sys_menu.php                            |  18 +--
 includes/sys_page.php                            |  14 ++-
 phpunit.xml                                      |  15 +--
 public/index.php                                 |   8 +-
 src/Exceptions/Handler.php                       |  56 ++++++++-
 src/Http/Request.php                             | 138 ++---------------------
 src/Routing/UrlGenerator.php                     |  27 +++++
 src/helpers.php                                  |  11 ++
 27 files changed, 230 insertions(+), 258 deletions(-)
 create mode 100644 src/Routing/UrlGenerator.php

(limited to 'src/Exceptions/Handler.php')

diff --git a/composer.json b/composer.json
index d2e0108b..e6d20108 100644
--- a/composer.json
+++ b/composer.json
@@ -16,10 +16,11 @@
     "require": {
         "php": ">=5.6.4",
         "erusev/parsedown": "1.6.*",
-        "twbs/bootstrap": "^3.3"
+        "twbs/bootstrap": "^3.3",
+        "symfony/http-foundation": "^3.3"
     },
     "require-dev": {
-        "phpunit/phpunit": "^6.2"
+        "phpunit/phpunit": "^6.3"
     },
     "autoload": {
         "psr-4": {
diff --git a/config/config.default.php b/config/config.default.php
index c3a939cd..a0303b15 100644
--- a/config/config.default.php
+++ b/config/config.default.php
@@ -20,9 +20,6 @@ return [
     // Set to development to enable debugging messages
     'environment'      => 'production',
 
-    // Site URL, used to generate links on page (https://example.com/[sub-dir/])
-    'url'              => null,
-
     // URL to the angel faq and job description
     'faq_url'          => 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers',
 
@@ -58,7 +55,7 @@ return [
     //  Blowfish    '$2y$13'
     //  SHA-256     '$5$rounds=5000'
     //  SHA-512     '$6$rounds=5000'
-    'crypt_alg'        => '$6$rounds=5000', // SHA-512
+    'crypt_alg'        => '$6$rounds=5000',
 
     'min_password_length'     => 8,
 
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index d60b6fc7..8c1cbe5d 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -127,7 +127,7 @@ function angeltype_edit_controller()
 
         if (!$supporter_mode) {
             if ($request->has('name')) {
-                $result = AngelType_validate_name($request->get('name'), $angeltype);
+                $result = AngelType_validate_name($request->postData('name'), $angeltype);
                 $angeltype['name'] = $result->getValue();
                 if (!$result->isValid()) {
                     $valid = false;
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index 38aad5bb..3890241d 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -27,10 +27,10 @@ function shift_entry_add_controller()
     }
 
     $shift = Shift($shift_id);
-    $shift['Name'] = $room_array[$shift['RID']];
     if ($shift == null) {
         redirect(page_link_to('user_shifts'));
     }
+    $shift['Name'] = $room_array[$shift['RID']];
 
     $type_id = 0;
     if ($request->has('type_id') && preg_match('/^\d*$/', $request->input('type_id'))) {
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index f4f3f119..f68f64fe 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -62,7 +62,7 @@ function shift_edit_controller()
     $angeltypes = select_array(AngelTypes(), 'id', 'name');
     $shifttypes = select_array(ShiftTypes(), 'id', 'name');
 
-    $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
+    $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'angel_type_id', 'count');
     foreach (array_keys($angeltypes) as $angeltype_id) {
         if (!isset($needed_angel_types[$angeltype_id])) {
             $needed_angel_types[$angeltype_id] = 0;
@@ -117,15 +117,20 @@ function shift_edit_controller()
             $msg .= error(_('The ending time has to be after the starting time.'), true);
         }
 
-        foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
-            if ($request->has('type_' . $needed_angeltype_id) && test_request_int('type_' . $needed_angeltype_id)) {
-                $needed_angel_types[$needed_angeltype_id] = trim($request->input('type_' . $needed_angeltype_id));
-            } else {
-                $valid = false;
-                $msg .= error(sprintf(
-                    _('Please check your input for needed angels of type %s.'),
-                    $needed_angeltype_name
-                ), true);
+        foreach ($needed_angel_types as $needed_angeltype_id => $count) {
+            $needed_angel_types[$needed_angeltype_id] = 0;
+
+            $queryKey = 'type_' . $needed_angeltype_id;
+            if ($request->has($queryKey)) {
+                if (test_request_int($queryKey)) {
+                    $needed_angel_types[$needed_angeltype_id] = trim($request->input($queryKey));
+                } else {
+                    $valid = false;
+                    $msg .= error(sprintf(
+                        _('Please check your input for needed angels of type %s.'),
+                        $angeltypes[$needed_angeltype_id]
+                    ), true);
+                }
             }
         }
 
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index 6dc74d68..b8a1fdbd 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -47,7 +47,7 @@ function user_delete_controller()
     $request = request();
 
     if ($request->has('user_id')) {
-        $user_source = User($request->get('user_id'));
+        $user_source = User($request->query->get('user_id'));
     } else {
         $user_source = $user;
     }
@@ -68,7 +68,7 @@ function user_delete_controller()
         if (
         !(
             $request->has('password')
-            && verify_password($request->post('password'), $user['Passwort'], $user['UID'])
+            && verify_password($request->postData('password'), $user['Passwort'], $user['UID'])
         )
         ) {
             $valid = false;
@@ -307,9 +307,9 @@ function user_password_recovery_set_new_controller()
 
         if (
             $request->has('password')
-            && strlen($request->post('password')) >= config('min_password_length')
+            && strlen($request->postData('password')) >= config('min_password_length')
         ) {
-            if ($request->post('password') != $request->post('password2')) {
+            if ($request->postData('password') != $request->postData('password2')) {
                 $valid = false;
                 error(_('Your passwords don\'t match.'));
             }
@@ -319,7 +319,7 @@ function user_password_recovery_set_new_controller()
         }
 
         if ($valid) {
-            set_password($user_source['UID'], $request->post('password'));
+            set_password($user_source['UID'], $request->postData('password'));
             success(_('Password saved.'));
             redirect(page_link_to('login'));
         }
@@ -363,7 +363,7 @@ function user_password_recovery_start_controller()
                 _('Password recovery'),
                 sprintf(
                     _('Please visit %s to recover your password.'),
-                    page_link_to_absolute('user_password_recovery', ['token' => $token])
+                    page_link_to('user_password_recovery', ['token' => $token])
                 )
             );
             success(_('We sent an email containing your password recovery link.'));
diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php
index c065d332..e6b457d9 100644
--- a/includes/engelsystem_provider.php
+++ b/includes/engelsystem_provider.php
@@ -32,9 +32,10 @@ date_default_timezone_set($config->get('timezone'));
 
 /**
  * Initialize Request
+ *
+ * @var Request $request
  */
-$request = new Request();
-$request->create($_GET, $_POST, $_SERVER, config('url'));
+$request = Request::createFromGlobals();
 $request::setInstance($request);
 
 /**
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
index d2dbcdbd..83faabb0 100644
--- a/includes/helper/internationalization_helper.php
+++ b/includes/helper/internationalization_helper.php
@@ -1,5 +1,7 @@
  0 ? '&' : '?') . 'set_locale=';
+    $request = Request::getInstance();
 
     $items = [];
     foreach (config('locales') as $locale => $name) {
+        $url = url($request->getPathInfo(), ['set_locale' => $locale]);
+
         $items[] = toolbar_item_link(
-            htmlspecialchars($url) . $locale,
+            htmlspecialchars($url),
             '',
-            '' . $name . ' ' . $name
+            sprintf(
+                '%s %2$s',
+                url('pic/flag/' . $locale . '.png'),
+                $name
+            )
         );
     }
     return $items;
diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php
index d64afe76..1de8bfb7 100644
--- a/includes/pages/admin_groups.php
+++ b/includes/pages/admin_groups.php
@@ -81,7 +81,8 @@ function admin_groups()
                             'privileges[]',
                             $privilege['desc'] . ' (' . $privilege['name'] . ')',
                             $privilege['group_id'] != '',
-                            $privilege['id']
+                            $privilege['id'],
+                            'privilege-' . $privilege['name']
                         );
                         $privileges_html .= sprintf(
                             ' %s %s',
@@ -112,7 +113,7 @@ function admin_groups()
                 }
 
                 $group = DB::select('SELECT * FROM `Groups` WHERE `UID`=? LIMIT 1', [$group_id]);
-                $privileges = $request->get('privileges');
+                $privileges = $request->postData('privileges');
                 if (!is_array($privileges)) {
                     $privileges = [];
                 }
diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php
index a5354da7..64a54f4b 100644
--- a/includes/pages/admin_news.php
+++ b/includes/pages/admin_news.php
@@ -62,14 +62,15 @@ function admin_news()
                 ',
                 [
                     time(),
-                    $request->post('eBetreff'),
-                    $request->post('eText'),
+                    $request->postData('eBetreff'),
+                    $request->postData('eText'),
                     $user['UID'],
                     $request->has('eTreffen') ? 1 : 0,
                     $news_id
                 ]
             );
-            engelsystem_log('News updated: ' . $request->post('eBetreff'));
+
+            engelsystem_log('News updated: ' . $request->postData('eBetreff'));
             success(_('News entry updated.'));
             redirect(page_link_to('news'));
             break;
diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php
index 8a7720d8..457114a0 100644
--- a/includes/pages/admin_rooms.php
+++ b/includes/pages/admin_rooms.php
@@ -110,11 +110,14 @@ function admin_rooms()
                 }
 
                 foreach ($angeltypes as $angeltype_id => $angeltype) {
-                    if (
-                        $request->has('angeltype_count_' . $angeltype_id)
-                        && preg_match('/^\d{1,4}$/', $request->input('angeltype_count_' . $angeltype_id))
-                    ) {
-                        $angeltypes_count[$angeltype_id] = $request->input('angeltype_count_' . $angeltype_id);
+                    $angeltypes_count[$angeltype_id] = 0;
+                    $queryKey = 'angeltype_count_' . $angeltype_id;
+                    if (!$request->has($queryKey)) {
+                        continue;
+                    }
+
+                    if (preg_match('/^\d{1,4}$/', $request->input($queryKey))) {
+                        $angeltypes_count[$angeltype_id] = $request->input($queryKey);
                     } else {
                         $valid = false;
                         $msg .= error(sprintf(_('Please enter needed angels for type %s.'), $angeltype), true);
diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php
index 5b53f9cd..d36635f7 100644
--- a/includes/pages/admin_shifts.php
+++ b/includes/pages/admin_shifts.php
@@ -135,16 +135,14 @@ function admin_shifts()
             } elseif ($request->input('angelmode') == 'manually') {
                 $angelmode = 'manually';
                 foreach ($types as $type) {
-                    if (
-                        $request->has('type_' . $type['id'])
-                        && preg_match('/^\d+$/', trim($request->input('type_' . $type['id'])))
-                    ) {
-                        $needed_angel_types[$type['id']] = trim($request->input('type_' . $type['id']));
+                    if (preg_match('/^\d+$/', trim($request->input('type_' . $type['id'], 0)))) {
+                        $needed_angel_types[$type['id']] = trim($request->input('type_' . $type['id'], 0));
                     } else {
                         $valid = false;
                         error(sprintf(_('Please check the needed angels for team %s.'), $type['name']));
                     }
                 }
+
                 if (array_sum($needed_angel_types) == 0) {
                     $valid = false;
                     error(_('There are 0 angels needed. Please enter the amounts of needed angels.'));
@@ -306,7 +304,7 @@ function admin_shifts()
         }
     } elseif ($request->has('submit')) {
         if (
-            !$request->has('admin_shifts_shifts')
+            !isset($_SESSION['admin_shifts_shifts'])
             || !isset($_SESSION['admin_shifts_types'])
             || !is_array($_SESSION['admin_shifts_shifts'])
             || !is_array($_SESSION['admin_shifts_types'])
diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php
index 00113507..aea68f52 100644
--- a/includes/pages/admin_user.php
+++ b/includes/pages/admin_user.php
@@ -261,7 +261,7 @@ function admin_user()
                       `Handy` = ?,
                       `Alter` =?,
                       `DECT` = ?,
-                      ' . ($user_source['email_by_human_allowed'] ? '`email` = ' . DB::getPdo()->quote($request->post('eemail')) . ',' : '') . '
+                      ' . ($user_source['email_by_human_allowed'] ? '`email` = ' . DB::getPdo()->quote($request->postData('eemail')) . ',' : '') . '
                       `jabber` = ?,
                       `Size` = ?,
                       `Gekommen`= ?,
@@ -272,34 +272,34 @@ function admin_user()
                       WHERE `UID` = ?
                       LIMIT 1';
                 DB::update($sql, [
-                    $request->post('eNick'),
-                    $request->post('eName'),
-                    $request->post('eVorname'),
-                    $request->post('eTelefon'),
-                    $request->post('eHandy'),
-                    $request->post('eAlter'),
-                    $request->post('eDECT'),
-                    $request->post('ejabber'),
-                    $request->post('eSize'),
-                    $request->post('eGekommen'),
-                    $request->post('eAktiv'),
+                    $request->postData('eNick'),
+                    $request->postData('eName'),
+                    $request->postData('eVorname'),
+                    $request->postData('eTelefon'),
+                    $request->postData('eHandy'),
+                    $request->postData('eAlter'),
+                    $request->postData('eDECT'),
+                    $request->postData('ejabber'),
+                    $request->postData('eSize'),
+                    $request->postData('eGekommen'),
+                    $request->postData('eAktiv'),
                     $force_active,
-                    $request->post('eTshirt'),
-                    $request->post('Hometown'),
+                    $request->postData('eTshirt'),
+                    $request->postData('Hometown'),
                     $user_id,
                 ]);
                 engelsystem_log(
-                    'Updated user: ' . $request->post('eNick') . ', ' . $request->post('eSize')
-                    . ', arrived: ' . $request->post('eVorname')
-                    . ', active: ' . $request->post('eAktiv')
-                    . ', tshirt: ' . $request->post('eTshirt')
+                    'Updated user: ' . $request->postData('eNick') . ', ' . $request->postData('eSize')
+                    . ', arrived: ' . $request->postData('eVorname')
+                    . ', active: ' . $request->postData('eAktiv')
+                    . ', tshirt: ' . $request->postData('eTshirt')
                 );
                 $html .= success('Änderung wurde gespeichert...' . "\n", true);
                 break;
 
             case 'change_pw':
-                if ($request->post('new_pw') != '' && $request->post('new_pw') == $request->post('new_pw2')) {
-                    set_password($user_id, $request->post('new_pw'));
+                if ($request->postData('new_pw') != '' && $request->postData('new_pw') == $request->postData('new_pw2')) {
+                    set_password($user_id, $request->postData('new_pw'));
                     $user_source = User($user_id);
                     engelsystem_log('Set new password for ' . User_Nick_render($user_source));
                     $html .= success('Passwort neu gesetzt.', true);
diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php
index b83b8382..3966b55c 100644
--- a/includes/pages/guest_login.php
+++ b/includes/pages/guest_login.php
@@ -127,8 +127,8 @@ function guest_register()
             }
         }
 
-        if ($request->has('password') && strlen($request->post('password')) >= $min_password_length) {
-            if ($request->post('password') != $request->post('password2')) {
+        if ($request->has('password') && strlen($request->postData('password')) >= $min_password_length) {
+            if ($request->postData('password') != $request->postData('password2')) {
                 $valid = false;
                 $msg .= error(_('Your passwords don\'t match.'), true);
             }
@@ -234,7 +234,7 @@ function guest_register()
             // Assign user-group and set password
             $user_id = DB::getPdo()->lastInsertId();
             DB::insert('INSERT INTO `UserGroups` (`uid`, `group_id`) VALUES (?, -2)', [$user_id]);
-            set_password($user_id, $request->post('password'));
+            set_password($user_id, $request->postData('password'));
 
             // Assign angel-types
             $user_angel_types_info = [];
@@ -403,7 +403,7 @@ function guest_login()
             if (count($login_user) > 0) {
                 $login_user = $login_user[0];
                 if ($request->has('password')) {
-                    if (!verify_password($request->post('password'), $login_user['Passwort'], $login_user['UID'])) {
+                    if (!verify_password($request->postData('password'), $login_user['Passwort'], $login_user['UID'])) {
                         $valid = false;
                         error(_('Your password is incorrect.  Please try it again.'));
                     }
diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php
index 98ace9cc..2991bdbf 100644
--- a/includes/pages/user_atom.php
+++ b/includes/pages/user_atom.php
@@ -1,6 +1,7 @@
 
   
   Engelsystem
-  ' . $_SERVER['HTTP_HOST']
+  ' . $request->getHttpHost()
         . htmlspecialchars(preg_replace(
             '#[&?]key=[a-f\d]{32}#',
             '',
-            $_SERVER['REQUEST_URI']
+            $request->getRequestUri()
         ))
         . '
   ' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . '' . "\n";
@@ -64,11 +66,12 @@ function make_atom_entries_from_news($news_entries)
 
 function make_atom_entry_from_news($news_entry)
 {
-    return '  
+    return '
+  
     ' . htmlspecialchars($news_entry['Betreff']) . '
-    
-      ' . preg_replace('#^https?://#', '', page_link_to_absolute('news')) . '-' . $news_entry['ID'] . '
-      ' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '
+    
+    ' . preg_replace('#^https?://#', '', page_link_to('news_comments', ['nid' => $news_entry['ID']])) . '
+    ' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . '
     ' . htmlspecialchars($news_entry['Text']) . '
-    ' . "\n";
+  ' . "\n";
 }
diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php
index 2dd141ec..bdbb0645 100644
--- a/includes/pages/user_news.php
+++ b/includes/pages/user_news.php
@@ -186,9 +186,9 @@ function user_news()
 
     $html = '

' . news_title() . '

' . msg(); - $isMeeting = $request->post('treffen'); + $isMeeting = $request->postData('treffen'); if ($request->has('text') && $request->has('betreff') && in_array('admin_news', $privileges)) { - if (!$request->has('treffen') || !in_array('admin_news', $privileges)) { + if (!$request->has('treffen')) { $isMeeting = 0; } DB::insert(' @@ -197,13 +197,13 @@ function user_news() ', [ time(), - $request->post('betreff'), - $request->post('text'), + $request->postData('betreff'), + $request->postData('text'), $user['UID'], $isMeeting, ] ); - engelsystem_log('Created news: ' . $_POST['betreff'] . ', treffen: ' . $isMeeting); + engelsystem_log('Created news: ' . $request->postData('betreff') . ', treffen: ' . $isMeeting); success(_('Entry saved.')); redirect(page_link_to('news')); } diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 667e73d9..9a43f5ce 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -101,14 +101,14 @@ function user_settings_password($user_source) $request = request(); if ( !$request->has('password') - || !verify_password($request->post('password'), $user_source['Passwort'], $user_source['UID']) + || !verify_password($request->postData('password'), $user_source['Passwort'], $user_source['UID']) ) { error(_('-> not OK. Please try again.')); - } elseif (strlen($request->post('new_password')) < config('min_password_length')) { + } elseif (strlen($request->postData('new_password')) < config('min_password_length')) { error(_('Your password is to short (please use at least 6 characters).')); - } elseif ($request->post('new_password') != $request->post('new_password2')) { + } elseif ($request->postData('new_password') != $request->postData('new_password2')) { error(_('Your passwords don\'t match.')); - } elseif (set_password($user_source['UID'], $request->post('new_password'))) { + } elseif (set_password($user_source['UID'], $request->postData('new_password'))) { success(_('Password saved.')); } else { error(_('Failed setting password.')); diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index cd18a037..db0bb193 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -229,8 +229,8 @@ function view_user_shifts() 'shifts_table' => msg() . $shiftCalendarRenderer->render(), 'ical_text' => '

' . _('iCal export') . '

' . sprintf( _('Export of shown shifts. iCal format or JSON format available (please keep secret, otherwise reset the api key).'), - page_link_to_absolute('ical', ['key' => $user['api_key']]), - page_link_to_absolute('shifts_json_export', ['key' => $user['api_key']]), + page_link_to('ical', ['key' => $user['api_key']]), + page_link_to('shifts_json_export', ['key' => $user['api_key']]), page_link_to('user_myshifts', ['reset' => 1]) ) . '

', 'filter' => _('Filter') diff --git a/includes/sys_form.php b/includes/sys_form.php index 936e3203..78e97792 100644 --- a/includes/sys_form.php +++ b/includes/sys_form.php @@ -144,10 +144,15 @@ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = [] * @param string $label * @param string $selected * @param string $value + * @param string $id * @return string */ -function form_checkbox($name, $label, $selected, $value = 'checked') +function form_checkbox($name, $label, $selected, $value = 'checked', $id = null) { + if (is_null($id)) { + $id = $name; + } + return '