From 7d5d905fcf03a67f606154feee6173581640708f Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Thu, 20 Jul 2017 01:14:28 +0200 Subject: [PATCH 1/3] Moved $themes array to config --- config/config.default.php | 11 ++++++++++- includes/pages/user_settings.php | 3 ++- includes/sys_template.php | 11 ----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config/config.default.php b/config/config.default.php index e816fe9c..ffa030db 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -29,9 +29,18 @@ return [ // From address of all emails 'no_reply_email' => 'noreply@engelsystem.de', - // Default theme of the start page, 1=style1.css + // Default theme, 1=style1.css 'theme' => 1, + // Available themes + 'available_themes' => [ + '4' => 'Engelsystem 33c3 (2016)', + '3' => 'Engelsystem 32c3 (2015)', + '2' => 'Engelsystem cccamp15', + '0' => 'Engelsystem light', + '1' => 'Engelsystem dark' + ], + // Number of News shown on one site 'display_news' => 6, diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 69e5a7fb..667e73d9 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -198,8 +198,9 @@ function user_settings_locale($user_source, $locales) */ function user_settings() { - global $themes, $user; + global $user; $request = request(); + $themes = config('available_themes'); $enable_tshirt_size = config('enable_tshirt_size'); $tshirt_sizes = config('tshirt_sizes'); diff --git a/includes/sys_template.php b/includes/sys_template.php index 1d3943b7..bcf462d7 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -1,16 +1,5 @@ 'Engelsystem 33c3 (2016)', - '3' => 'Engelsystem 32c3 (2015)', - '2' => 'Engelsystem cccamp15', - '0' => 'Engelsystem light', - '1' => 'Engelsystem dark' -]; - /** * Display muted (grey) text. * From d4ad70804be9d310787b98fcdce51b3697967d22 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Thu, 20 Jul 2017 02:10:53 +0200 Subject: [PATCH 2/3] Removed overwhelmed page --- includes/pages/guest_login.php | 3 +- public/overwhelmed.html | 77 ---------------------------------- 2 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 public/overwhelmed.html diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 858ced80..106db33a 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -488,6 +488,5 @@ function get_register_hint() ]); } - //@TODO: FIXME: return error(_('Registration is disabled.'), true); - return error('Registration is disabled.', true); + return error(_('Registration is disabled.'), true); } diff --git a/public/overwhelmed.html b/public/overwhelmed.html deleted file mode 100644 index cae0d1b5..00000000 --- a/public/overwhelmed.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - Engelsystem - - - - - - - - - - -
-
-
-
-
-

Dear Angels,

-

- The great interest in becoming an angel and participating at 33C3 is is something we are - grateful for every time. There is a record number of angels and helping volunteers this year. -

-

- We did anticipate a great number but we are overwhelmed by this endless wave of support. We do - want to enable each and every one of you to be an angel at the congress, but sadly our resources - and capacities at Heaven are limited. The amount of angels at this point is beyond our - planing and to ensure we can support the angels already checked in. We did make a choice never - thought possible on a chaos event: -

-

- We closed the registration in the Engelsystem and at Heaven Desk at 19:00 27. Dec. 2016. -

-

- Everyone of us works for you to support you in being an angel, but the Heaven Desk and the - Kitchen among others are limited and so we decided to focus our effort to support those of you - already arrived to the best of our abilities. -

-

- For the Heaven Team
- Agnes, Jen, LLF and Knuth -

-
-
-
-
- -
- - - From e1762e7764d4ee4f37757ecd2630f62a440dbf0e Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Thu, 20 Jul 2017 02:22:18 +0200 Subject: [PATCH 3/3] replaced template_render with dynamic renderer class --- includes/engelsystem_provider.php | 12 ++++- includes/pages/guest_credits.php | 2 +- includes/pages/user_shifts.php | 2 +- includes/sys_template.php | 22 --------- public/index.php | 2 +- src/Renderer/EngineInterface.php | 21 +++++++++ src/Renderer/HtmlEngine.php | 34 ++++++++++++++ src/Renderer/Renderer.php | 62 ++++++++++++++++++++++++++ src/helpers.php | 17 +++++++ {public => templates}/maintenance.html | 0 10 files changed, 148 insertions(+), 26 deletions(-) create mode 100644 src/Renderer/EngineInterface.php create mode 100644 src/Renderer/HtmlEngine.php create mode 100644 src/Renderer/Renderer.php rename {public => templates}/maintenance.html (100%) diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index edfae705..ff682871 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -4,6 +4,8 @@ use Engelsystem\Config\Config; use Engelsystem\Database\Db; use Engelsystem\Exceptions\Handler as ExceptionHandler; use Engelsystem\Http\Request; +use Engelsystem\Renderer\HtmlEngine; +use Engelsystem\Renderer\Renderer; /** * This file includes all needed functions, connects to the db etc. @@ -43,11 +45,19 @@ $request::setInstance($request); * Check for maintenance */ if ($config->get('maintenance')) { - echo file_get_contents(__DIR__ . '/../public/maintenance.html'); + echo file_get_contents(__DIR__ . '/../templates/maintenance.html'); die(); } +/** + * Initialize renderer + */ +$renderer = new Renderer(); +$renderer->addRenderer(new HtmlEngine()); +Renderer::setInstance($renderer); + + /** * Register error handler */ diff --git a/includes/pages/guest_credits.php b/includes/pages/guest_credits.php index d9224cbb..db86132d 100644 --- a/includes/pages/guest_credits.php +++ b/includes/pages/guest_credits.php @@ -13,5 +13,5 @@ function credits_title() */ function guest_credits() { - return template_render(__DIR__ . '/../../templates/guest_credits.html', []); + return view(__DIR__ . '/../../templates/guest_credits.html'); } diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 4dabdfb5..813cb9b3 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -206,7 +206,7 @@ function view_user_shifts() return page([ div('col-md-12', [ msg(), - template_render(__DIR__ . '/../../templates/user_shifts.html', [ + view(__DIR__ . '/../../templates/user_shifts.html', [ 'title' => shifts_title(), 'room_select' => make_select($rooms, $shiftsFilter->getRooms(), 'rooms', _('Rooms')), 'start_select' => html_select_key('start_day', 'start_day', array_combine($days, $days), $start_day), diff --git a/includes/sys_template.php b/includes/sys_template.php index bcf462d7..a659a7f3 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -321,28 +321,6 @@ function table_buttons($buttons = []) return '
' . join(' ', $buttons) . '
'; } -/** - * Load and render template - * - * @param string $file - * @param string[] $data - * @return string - */ -function template_render($file, $data = []) -{ - if (file_exists($file)) { - $template = file_get_contents($file); - if (is_array($data)) { - foreach ($data as $name => $content) { - $template = str_replace('%' . $name . '%', $content, $template); - } - } - return $template; - } - engelsystem_error('Cannot find template file «' . $file . '».'); - return ''; -} - /** * @param string $str * @param int $length diff --git a/public/index.php b/public/index.php index 52f32438..f22721c8 100644 --- a/public/index.php +++ b/public/index.php @@ -166,7 +166,7 @@ if ( $event_config = EventConfig(); -echo template_render(__DIR__ . '/../templates/layout.html', [ +echo view(__DIR__ . '/../templates/layout.html', [ 'theme' => isset($user) ? $user['color'] : config('theme'), 'title' => $title, 'atom_link' => ($page == 'news' || $page == 'user_meetings') diff --git a/src/Renderer/EngineInterface.php b/src/Renderer/EngineInterface.php new file mode 100644 index 00000000..ca468db5 --- /dev/null +++ b/src/Renderer/EngineInterface.php @@ -0,0 +1,21 @@ + $content) { + $template = str_replace('%' . $name . '%', $content, $template); + } + } + + return $template; + } + + /** + * @param string $path + * @return bool + */ + public function canRender($path) + { + return strpos($path, '.html') && file_exists($path); + } +} diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php new file mode 100644 index 00000000..bf3d5609 --- /dev/null +++ b/src/Renderer/Renderer.php @@ -0,0 +1,62 @@ +renderer as $renderer) { + if (!$renderer->canRender($template)) { + continue; + } + + return $renderer->get($template, $data); + } + + engelsystem_error('Unable to find a renderer for template file «' . $template . '».'); + return ''; + } + + /** + * Add a new renderer engine + * + * @param EngineInterface $renderer + */ + public function addRenderer(EngineInterface $renderer) + { + $this->renderer[] = $renderer; + } + + /** + * @return self + * @throws ErrorException + */ + public static function getInstance() + { + return self::$instance; + } + + /** + * @param self $instance + */ + public static function setInstance($instance) + { + self::$instance = $instance; + } +} diff --git a/src/helpers.php b/src/helpers.php index a410b27e..d44d1d21 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -3,6 +3,7 @@ use Engelsystem\Config\Config; use Engelsystem\Http\Request; +use Engelsystem\Renderer\Renderer; /** * Get or set config values @@ -39,3 +40,19 @@ function request($key = null, $default = null) return $request->input($key, $default); } + +/** + * @param string $template + * @param mixed[] $data + * @return Renderer|string + */ +function view($template = null, $data = null) +{ + $renderer = Renderer::getInstance(); + + if (is_null($template)) { + return $renderer; + } + + return $renderer->render($template, $data); +} diff --git a/public/maintenance.html b/templates/maintenance.html similarity index 100% rename from public/maintenance.html rename to templates/maintenance.html