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-54-g00ecf 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-54-g00ecf