diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/controller/shifts_controller.php | 4 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 6 | ||||
-rw-r--r-- | includes/engelsystem_provider.php | 82 | ||||
-rw-r--r-- | includes/helper/internationalization_helper.php | 12 | ||||
-rw-r--r-- | includes/model/User_model.php | 7 | ||||
-rw-r--r-- | includes/pages/admin_active.php | 5 | ||||
-rw-r--r-- | includes/pages/admin_user.php | 9 | ||||
-rw-r--r-- | includes/pages/guest_login.php | 14 | ||||
-rw-r--r-- | includes/pages/guest_stats.php | 4 | ||||
-rw-r--r-- | includes/pages/user_atom.php | 4 | ||||
-rw-r--r-- | includes/pages/user_myshifts.php | 6 | ||||
-rw-r--r-- | includes/pages/user_news.php | 6 | ||||
-rw-r--r-- | includes/pages/user_settings.php | 16 | ||||
-rw-r--r-- | includes/sys_auth.php | 5 | ||||
-rw-r--r-- | includes/view/AngelTypes_view.php | 4 | ||||
-rw-r--r-- | includes/view/User_view.php | 34 |
16 files changed, 127 insertions, 91 deletions
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 @@ <?php +use Engelsystem\Config\Config; use Engelsystem\Database\Db; use Engelsystem\Exceptions\Handler as ExceptionHandler; @@ -12,6 +13,60 @@ if (!is_readable(__DIR__ . '/../vendor/autoload.php')) { } require __DIR__ . '/../vendor/autoload.php'; + +/** + * Load configuration + */ +$config = new Config(); +Config::setInstance($config); +$config->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 @@ <?php -$locales = [ - 'de_DE.UTF-8' => '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 = '<div class="col-md-12"><h1>' . meetings_title() . '</h1>' . 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 = '<div class="col-md-12"><h1>' . news_title() . '</h1>' . 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') ]), '<p>' . _('Here is the list of teams and their tasks. If you have questions, read the FAQ.') . '</p>', '<hr />' 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,25 +1,6 @@ <?php /** - * Available T-Shirt sizes - */ -$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' -]; - -/** * Renders user settings page * * @param array $user_source The user @@ -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 = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>'; 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!'); } |