From 945a09cfc3f830fd4aa70668ecc95bc1116fe305 Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Fri, 1 Aug 2014 16:40:20 +0200 Subject: [PATCH] issue #117: Replacing Template service with Twig and implementing Twig in all modules/utils --- composer.json | 3 +- composer.lock | 59 +++- docs/credits.rst | 33 +- src/bootstrap.php | 5 +- src/includes/psmconfig.inc.php | 6 + src/lang/bg_BG.lang.php | 2 +- src/lang/da_DK.lang.php | 2 +- src/lang/de_DE.lang.php | 2 +- src/lang/en_US.lang.php | 2 +- src/lang/es_ES.lang.php | 2 +- src/lang/fr_FR.lang.php | 2 +- src/lang/it_IT.lang.php | 2 +- src/lang/ko_KR.lang.php | 2 +- src/lang/nl_NL.lang.php | 2 +- src/lang/pt_BR.lang.php | 2 +- src/lang/ru_RU.lang.php | 2 +- src/lang/zh_CN.lang.php | 2 +- src/psm/Module/AbstractController.class.php | 138 +++----- .../Controller/ConfigController.class.php | 148 ++++----- src/psm/Module/ControllerInterface.class.php | 3 +- .../Controller/ErrorController.class.php | 10 +- .../Controller/InstallController.class.php | 59 +--- .../AbstractServerController.class.php | 5 +- .../Server/Controller/LogController.class.php | 72 ++-- .../Controller/ServerController.class.php | 172 ++++------ .../Controller/StatusController.class.php | 65 ++-- .../Controller/UpdateController.class.php | 5 +- .../User/Controller/LoginController.class.php | 21 +- .../Controller/ProfileController.class.php | 49 +-- .../User/Controller/UserController.class.php | 106 +++--- src/psm/Router.class.php | 9 +- src/psm/Service/Template.class.php | 307 ------------------ src/psm/Util/Module/Modal.class.php | 66 ++-- src/psm/Util/Module/ModalInterface.class.php | 2 +- src/psm/Util/Module/Sidebar.class.php | 51 +-- .../Util/Module/SidebarInterface.class.php | 2 +- src/psm/Util/Server/HistoryGraph.class.php | 34 +- src/templates/default/main/body.tpl.html | 79 +++++ src/templates/default/main/menu.tpl.html | 22 ++ .../module}/config/config.tpl.html | 153 +++++---- .../default/module/error/401.tpl.html | 2 + .../module/install/config_new.tpl.html | 61 ++++ .../module/install/config_new_user.tpl.html | 44 +++ .../module/install/config_upgrade.tpl.html | 9 + .../default/module/install/index.tpl.html | 15 + .../default/module/install/main.tpl.html | 5 + .../default/module/install/results.tpl.html | 10 + .../default/module/install/success.tpl.html | 20 ++ .../module}/server/history.tpl.html | 41 +-- .../default/module/server/log.tpl.html | 60 ++++ .../module/server/server/list.tpl.html | 66 ++++ .../module/server/server/update.tpl.html | 106 ++++++ .../module/server/server/view.tpl.html | 91 ++++++ .../module/server/status/header.tpl.html | 4 + .../module/server/status/index.tpl.html | 60 ++++ .../default/module/user/login/forgot.tpl.html | 8 + .../default/module/user/login/login.tpl.html | 13 + .../default/module/user/login/reset.tpl.html | 10 + .../default/module/user/profile.tpl.html | 72 ++++ .../default/module/user/user/list.tpl.html | 66 ++++ .../default/module/user/user/update.tpl.html | 83 +++++ .../default/util/module/modal.tpl.html | 14 + .../default/util/module/sidebar.tpl.html | 26 ++ src/templates/error/error.tpl.html | 4 - src/templates/install/install.tpl.html | 160 --------- src/templates/main.tpl.html | 110 ------- src/templates/main_modal.tpl.html | 14 - src/templates/main_sidebar.tpl.html | 37 --- src/templates/server/log.tpl.html | 75 ----- src/templates/server/server.tpl.html | 180 ---------- src/templates/server/status.tpl.html | 73 ----- src/templates/server/view.tpl.html | 96 ------ src/templates/user/login.tpl.html | 39 --- src/templates/user/profile.tpl.html | 74 ----- src/templates/user/user.tpl.html | 151 --------- 75 files changed, 1538 insertions(+), 2069 deletions(-) delete mode 100644 src/psm/Service/Template.class.php create mode 100644 src/templates/default/main/body.tpl.html create mode 100644 src/templates/default/main/menu.tpl.html rename src/templates/{ => default/module}/config/config.tpl.html (50%) create mode 100644 src/templates/default/module/error/401.tpl.html create mode 100644 src/templates/default/module/install/config_new.tpl.html create mode 100644 src/templates/default/module/install/config_new_user.tpl.html create mode 100644 src/templates/default/module/install/config_upgrade.tpl.html create mode 100644 src/templates/default/module/install/index.tpl.html create mode 100644 src/templates/default/module/install/main.tpl.html create mode 100644 src/templates/default/module/install/results.tpl.html create mode 100644 src/templates/default/module/install/success.tpl.html rename src/templates/{ => default/module}/server/history.tpl.html (56%) create mode 100644 src/templates/default/module/server/log.tpl.html create mode 100644 src/templates/default/module/server/server/list.tpl.html create mode 100644 src/templates/default/module/server/server/update.tpl.html create mode 100644 src/templates/default/module/server/server/view.tpl.html create mode 100644 src/templates/default/module/server/status/header.tpl.html create mode 100644 src/templates/default/module/server/status/index.tpl.html create mode 100644 src/templates/default/module/user/login/forgot.tpl.html create mode 100644 src/templates/default/module/user/login/login.tpl.html create mode 100644 src/templates/default/module/user/login/reset.tpl.html create mode 100644 src/templates/default/module/user/profile.tpl.html create mode 100644 src/templates/default/module/user/user/list.tpl.html create mode 100644 src/templates/default/module/user/user/update.tpl.html create mode 100644 src/templates/default/util/module/modal.tpl.html create mode 100644 src/templates/default/util/module/sidebar.tpl.html delete mode 100644 src/templates/error/error.tpl.html delete mode 100644 src/templates/install/install.tpl.html delete mode 100644 src/templates/main.tpl.html delete mode 100644 src/templates/main_modal.tpl.html delete mode 100644 src/templates/main_sidebar.tpl.html delete mode 100644 src/templates/server/log.tpl.html delete mode 100644 src/templates/server/server.tpl.html delete mode 100644 src/templates/server/status.tpl.html delete mode 100644 src/templates/server/view.tpl.html delete mode 100644 src/templates/user/login.tpl.html delete mode 100644 src/templates/user/profile.tpl.html delete mode 100644 src/templates/user/user.tpl.html diff --git a/composer.json b/composer.json index 52a883a2..b3331228 100755 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "php": ">=5.3.7", "phpmailer/phpmailer": "5.2.6", "symfony/http-foundation": "2.4.*", - "php-pushover/php-pushover": "dev-master" + "php-pushover/php-pushover": "dev-master", + "twig/twig": "1.*" } } diff --git a/composer.lock b/composer.lock index ea19d7aa..48e948b7 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "6a941e5369d421e16d869151569bc5c7", + "hash": "1d763e23381a086e18f83644bd89f16c", "packages": [ { "name": "php-pushover/php-pushover", @@ -138,6 +138,63 @@ "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", "time": "2014-07-15 14:07:10" + }, + { + "name": "twig/twig", + "version": "v1.16.0", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Twig.git", + "reference": "8ce37115802e257a984a82d38254884085060024" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Twig/zipball/8ce37115802e257a984a82d38254884085060024", + "reference": "8ce37115802e257a984a82d38254884085060024", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.16-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "https://github.com/fabpot/Twig/graphs/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2014-07-05 12:19:05" } ], "packages-dev": [ diff --git a/docs/credits.rst b/docs/credits.rst index 672fee5d..0b3d4cc2 100644 --- a/docs/credits.rst +++ b/docs/credits.rst @@ -9,32 +9,32 @@ Credits The following people have contributed to the development of PHP Server Monitor: -* Pepijn Over +* Pepijn Over - https://github.com/dopeh * Creator and project maintainer -* Jérôme Cabanis +* Jérôme Cabanis - https://github.com/Abawell * History graphs * Date localization * Mobile compatibility * Various fixes and improvements -* Perri Vardy-Mason +* Perri Vardy-Mason - https://github.com/VeoPVM * Textmarketer SMS gateway * Various fixes and improvements -* Luiz Alberto S. Ribeiro +* Luiz Alberto S. Ribeiro - https://github.com/madeinnordeste * Bootstrap implementation * Portuguese Brazilian translation -* Michael Greenhill +* Michael Greenhill - https://github.com/doctorjbeam * Status page -* Andreas Ek +* Andreas Ek - https://github.com/EkAndreas * Mosms SMS gateway @@ -42,23 +42,23 @@ The following people have contributed to the development of PHP Server Monitor: * Website pattern / regular expression search -* nerdalertdk +* nerdalertdk - https://github.com/nerdalertdk * Smsit SMS gateway -* Victor Macko +* Victor Macko - https://github.com/victormacko * SMSGlobal SMS gateway -* Julien Lebouteiller +* Julien Lebouteiller - https://github.com/Halvra * Custom time-out per server -* Mathias Lange +* Mathias Lange - https://github.com/remmedia * Pushover.net support -* Alexander Moore +* Alexander Moore - http://www.famfamfam.com * Icon @@ -69,11 +69,11 @@ The following people have contributed to the translation of PHP Server Monitor: * Chinese - * manhere + * manhere - https://github.com/manhere * Bulgarian - * Plamen Vasilev + * Plamen Vasilev - https://github.com/PVasileff * Danish @@ -102,11 +102,11 @@ The following people have contributed to the translation of PHP Server Monitor: * Spanish - * Klemens Häckel + * Klemens Häckel - http://clickdimension.wordpress.com * Russian - * Roman Beylin + * Roman Beylin - https://github.com/roman-beylin Vendors @@ -118,4 +118,5 @@ The following libraries are being used by PHP Server Monitor: * Twitter Bootstrap - http://getbootstrap.com * Bootstrap Multiselect - https://github.com/davidstutz/bootstrap-multiselect * PHP Mailer - https://github.com/PHPMailer/PHPMailer -* php-pushover - https://github.com/kryap/php-pushover \ No newline at end of file +* php-pushover - https://github.com/kryap/php-pushover +* Twig - http://twig.sensiolabs.org \ No newline at end of file diff --git a/src/bootstrap.php b/src/bootstrap.php index ee81a02f..bde32179 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -47,7 +47,10 @@ if(file_exists($path_conf)) { include_once $path_conf; } // check for a debug var -if(defined('PSM_DEBUG') && PSM_DEBUG) { +if(!defined('PSM_DEBUG')) { + define('PSM_DEBUG', false); +} +if(PSM_DEBUG) { error_reporting(E_ALL); ini_set('display_erors', 1); } else { diff --git a/src/includes/psmconfig.inc.php b/src/includes/psmconfig.inc.php index 588cf21f..58c309b6 100644 --- a/src/includes/psmconfig.inc.php +++ b/src/includes/psmconfig.inc.php @@ -101,3 +101,9 @@ define('PSM_CRON_TIMEOUT', 600); * Default timeout in seconds for curl requests (can be overwritten per-server). */ define('PSM_CURL_TIMEOUT', 10); + + +/** + * Name of the default theme. + */ +define('PSM_THEME', 'default'); \ No newline at end of file diff --git a/src/lang/bg_BG.lang.php b/src/lang/bg_BG.lang.php index ca5ba0d3..1cb8b533 100644 --- a/src/lang/bg_BG.lang.php +++ b/src/lang/bg_BG.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Изберете кога желаете да получавате известия
', + 'alert_type' => 'Изберете кога желаете да получавате известия', 'alert_type_description' => 'Промяна на сатуса:
'. 'Ще получавате известие когато има промяна със връзката на даден някой от описаните сървър или сайт. От Онлайн -> Офлайн и от Офлайн -> Онлайн.
'. '
Офлайн
'. diff --git a/src/lang/da_DK.lang.php b/src/lang/da_DK.lang.php index b7fc3357..d78b5d46 100644 --- a/src/lang/da_DK.lang.php +++ b/src/lang/da_DK.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Vælg hvornår du vil modtage besked.
', + 'alert_type' => 'Vælg hvornår du vil modtage besked', 'alert_type_description' => 'Status ændring: '. 'Du vil modtage en notifcation når en server har en ændring i status. Fra online -> offline eller offline -> online.
'. '
Offline: '. diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index d1d0f54b..7f39008d 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Wann möchten Sie benachrichtig werden?
', + 'alert_type' => 'Wann möchten Sie benachrichtig werden?', 'alert_type_description' => 'Status geändert: '. '... wenn sich der Status ändert
'. 'z.B. online -> offline oder offline -> online.
'. diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 1019013a..b3a0218d 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Select when you\'d like to be notified.
', + 'alert_type' => 'Select when you\'d like to be notified.', 'alert_type_description' => 'Status change: '. 'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.
'. '
Offline: '. diff --git a/src/lang/es_ES.lang.php b/src/lang/es_ES.lang.php index 45833263..3d271739 100644 --- a/src/lang/es_ES.lang.php +++ b/src/lang/es_ES.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Cuando desea recibir notificaciones ?
', + 'alert_type' => 'Cuando desea recibir notificaciones ?', 'alert_type_description' => '... Al cambiar el estado: '. 'p.ej. online -> offline o offline -> online.
'. '
Offline: '. diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php index fbf0cdf4..f8e76f08 100644 --- a/src/lang/fr_FR.lang.php +++ b/src/lang/fr_FR.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Choisissez quand vous souhaitez être notifié.
', + 'alert_type' => 'Choisissez quand vous souhaitez être notifié', 'alert_type_description' => 'Changement d\'état : '. 'Vous recevez une notification chaque fois que le serveur change d\'état. C\'est-à-dire passe de l\'état OK à HORS SERVICE ou de HORS SERVICE à OK.
'. '
Hors service : '. diff --git a/src/lang/it_IT.lang.php b/src/lang/it_IT.lang.php index 0d311573..b5c231bf 100644 --- a/src/lang/it_IT.lang.php +++ b/src/lang/it_IT.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Seleziona quando vuoi essere notificato.
', + 'alert_type' => 'Seleziona quando vuoi essere notificato', 'alert_type_description' => 'Cambio di Stato: '. 'Riceverai una notifica solo quando un server cambierà stato. Quindi da online -> offline oppure da offline -> online.
'. '
Offline: '. diff --git a/src/lang/ko_KR.lang.php b/src/lang/ko_KR.lang.php index 1fb127db..85337917 100644 --- a/src/lang/ko_KR.lang.php +++ b/src/lang/ko_KR.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => '알림을 원하면 다음과 같이 변경하십시오..
', + 'alert_type' => '알림을 원하면 다음과 같이 변경하십시오.', 'alert_type_description' => '상태 변경:
'. '서버 상태가 변경이되면 알림을 받습니다. online -> offline -> online.
'. '
오프라인:
'. diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index ba0035ba..a3d78e43 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is een dienst die het gemakkelijk maakt om real-time notificaties te ontvangen. Zie hun website voor meer informatie.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Voordat je Pushover kunt gebruiken moet je een App registreren via hun website, en daarvan de App API Token hier invullen.', - 'alert_type' => 'Selecteer wanneer je een notificatie wilt.
', + 'alert_type' => 'Selecteer wanneer je een notificatie wilt', 'alert_type_description' => 'Status change: '. 'Je ontvangt alleen bericht wanneer een server van status verandert. Dus van online -> offline of offline -> online.
'. '
Offline: '. diff --git a/src/lang/pt_BR.lang.php b/src/lang/pt_BR.lang.php index d4c7a23b..bd89fa54 100644 --- a/src/lang/pt_BR.lang.php +++ b/src/lang/pt_BR.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => 'Selecione como você gostaria de ser notificado.
', + 'alert_type' => 'Selecione como você gostaria de ser notificado.', 'alert_type_description' => 'Mudança de Status: '. 'Você receberá uma notificação quando o seridor tive uma mudança de status. De online -> offline ou offline -> online.
'. '
Offline: '. diff --git a/src/lang/ru_RU.lang.php b/src/lang/ru_RU.lang.php index 02021d81..5ec93971 100644 --- a/src/lang/ru_RU.lang.php +++ b/src/lang/ru_RU.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover - это сервис, который позволяет легко получать уведомления в режиме реального времени. Больше информации на их веб-сайте.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Прежде чем вы сможете начать пользоваться Pushover, вам необходимо зарегестрировать "App" на их веб-сайте и ввести "App API Token" сюда.', - 'alert_type' => 'Выбeрите, какие вы хотите получать уведомления
', + 'alert_type' => 'Выбeрите, какие вы хотите получать уведомления', 'alert_type_description' => 'Изменение статуса : '. 'Вы получите уведомление об изменение статуса. Для онлайн -> оффлайн или офлайн -> онлайн.
'. '
Оффлайн: '. diff --git a/src/lang/zh_CN.lang.php b/src/lang/zh_CN.lang.php index 1884fad0..eed73d86 100644 --- a/src/lang/zh_CN.lang.php +++ b/src/lang/zh_CN.lang.php @@ -200,7 +200,7 @@ $sm_lang = array( 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', - 'alert_type' => '如果想要收到提醒请选中此项.
', + 'alert_type' => '如果想要收到提醒请选中此项.', 'alert_type_description' => '状态变化: '. '服务器 online -> offline 或 offline -> online 的状态变化将会收到提醒.
'. '
离线状态: '. diff --git a/src/psm/Module/AbstractController.class.php b/src/psm/Module/AbstractController.class.php index e99f1933..d976e25b 100644 --- a/src/psm/Module/AbstractController.class.php +++ b/src/psm/Module/AbstractController.class.php @@ -27,7 +27,6 @@ namespace psm\Module; use psm\Service\Database; -use psm\Service\Template; use Symfony\Component\HttpFoundation\Response; abstract class AbstractController implements ControllerInterface { @@ -99,17 +98,10 @@ abstract class AbstractController implements ControllerInterface { protected $db; /** - * Template object - * @var \psm\Service\Template $tpl + * Twig object + * @var \Twig_Environment $twig */ - protected $tpl; - - /** - * Template Id that should be added to the main template - * @var string - * @see setTemplateId() getTemplateId() - */ - protected $tpl_id; + protected $twig; /** * User service @@ -144,9 +136,9 @@ abstract class AbstractController implements ControllerInterface { */ protected $xhr = false; - function __construct(Database $db, Template $tpl) { + function __construct(Database $db, \Twig_Environment $twig) { $this->db = $db; - $this->tpl = $tpl; + $this->twig = $twig; } /** @@ -170,7 +162,7 @@ abstract class AbstractController implements ControllerInterface { } // no response returned from execute, create regular HTML - return $this->createHTML(); + return $this->createHTML($result); } /** @@ -202,29 +194,23 @@ abstract class AbstractController implements ControllerInterface { /** * Create the HTML code for the module. * - * First the createHTMLLabels() will be called to add all labels to the template, - * Then the tpl_id set in $this->getTemplateId() will be added to the main template automatically. * If XHR is on, no main template will be added. * + * @param string $html HTML code to add to the main body * @return \Symfony\Component\HttpFoundation\Response */ - protected function createHTML() { - $tpl_id_content = $this->getTemplateId(); - $html = ''; - - if($this->xhr) { + protected function createHTML($html = null) { + if(!$this->xhr) { // in XHR mode, we will not add the main template - if($tpl_id_content) { - $this->createHTMLLabels(); - $html = $this->tpl->display($tpl_id_content); - } - } else { - // regular request, add main frame - $tpl_data = array(); + $tpl_data = array( + 'title' => strtoupper(psm_get_lang('system', 'title')), + 'label_back_to_top' => psm_get_lang('system', 'back_to_top'), + 'add_footer' => $this->add_footer, + 'version' => 'v' . PSM_VERSION, + 'messages' => $this->getMessages(), + 'html_content' => $html, + ); - if(!empty($this->messages)) { - $this->tpl->addTemplateDataRepeat('main', 'messages', $this->messages); - } // add menu to page? if($this->add_menu) { $tpl_data['html_menu'] = $this->createHTMLMenu(); @@ -245,16 +231,6 @@ abstract class AbstractController implements ControllerInterface { if($this->sidebar !== null) { $tpl_data['html_sidebar'] = $this->sidebar->createHTML(); } - // add footer to page? - if($this->add_footer) { - $this->tpl->newTemplate('main_footer', 'main.tpl.html'); - $tpl_data['html_footer'] = $this->tpl->getTemplate('main_footer'); - $tpl_data['version'] = 'v' . PSM_VERSION; - } - - if($tpl_id_content) { - $tpl_data['content'] = $this->tpl->getTemplate($tpl_id_content); - } if(psm_update_available()) { $tpl_data['update_available'] = str_replace('{version}', 'v'.psm_get_conf('version_update_check'), psm_get_lang('system', 'update_available')); @@ -263,12 +239,7 @@ abstract class AbstractController implements ControllerInterface { if($this->black_background) { $tpl_data['body_class'] = 'black_background'; } - - // add the module's custom template to the main template to get some content - $this->setTemplateId('main'); - $this->tpl->addTemplatedata($this->getTemplateId(), $tpl_data); - $this->createHTMLLabels(); - $html = $this->tpl->display($this->getTemplateId()); + $html = $this->twig->render('main/body.tpl.html', $tpl_data); } $response = new Response($html); @@ -283,9 +254,6 @@ abstract class AbstractController implements ControllerInterface { protected function createHTMLMenu() { $ulvl = ($this->user) ? $this->user->getUserLevel() : PSM_USER_ANONYMOUS; - $tpl_id = 'main_menu'; - $this->tpl->newTemplate($tpl_id, 'main.tpl.html'); - $tpl_data = array( 'label_help' => psm_get_lang('menu', 'help'), 'label_profile' => psm_get_lang('users', 'profile'), @@ -305,17 +273,14 @@ abstract class AbstractController implements ControllerInterface { $items = array(); break; } - $menu = array(); + $tpl_data['menu'] = array(); foreach($items as $key) { - $menu[] = array( + $tpl_data['menu'][] = array( 'active' => ($key == psm_GET('mod')) ? 'active' : '', 'url' => psm_build_url(array('mod' => $key)), 'label' => psm_get_lang('menu', $key), ); } - if(!empty($menu)) { - $this->tpl->addTemplateDataRepeat($tpl_id, 'menu', $menu); - } if($ulvl != PSM_USER_ANONYMOUS) { $user = $this->user->getUser(); @@ -325,51 +290,7 @@ abstract class AbstractController implements ControllerInterface { psm_get_lang('login', 'welcome_usermenu') ); } - $this->tpl->addTemplateData($tpl_id, $tpl_data); - - return $this->tpl->getTemplate($tpl_id); - } - - /** - * Use this to add language specific labels to template - * - * @see createHTML() - */ - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - 'main', - array( - 'title' => strtoupper(psm_get_lang('system', 'title')), - 'label_back_to_top' => psm_get_lang('system', 'back_to_top'), - ) - ); - } - - /** - * Set a template id that will be added to the main template automatically - * once you call the parent::createHTML() - * - * @param string $tpl_id - * @param string $tpl_file if given, the tpl_id will be created automatically from this file - * @see getTemplateId() createHTML() - */ - public function setTemplateId($tpl_id, $tpl_file = null) { - $this->tpl_id = $tpl_id; - - if($tpl_file != null) { - // tpl_file given, try to load the template.. - $this->tpl->newTemplate($tpl_id, $tpl_file); - } - } - - /** - * Get the mpalte id that will be added to the main template - * - * @return string - * @see setTemplateId() - */ - public function getTemplateId() { - return $this->tpl_id; + return $this->twig->render('main/menu.tpl.html', $tpl_data); } /** @@ -424,7 +345,8 @@ abstract class AbstractController implements ControllerInterface { * Add one or multiple message to the stack to be displayed to the user * @param string|array $msg * @param string $shortcode info/success/warning/error - * @return \psm\Module\AbstractModule + * @return \psm\Module\ControllerInterface + * @see getMessages() */ public function addMessage($msg, $shortcode = 'info') { if(!is_array($msg)) { @@ -455,6 +377,20 @@ abstract class AbstractController implements ControllerInterface { return $this; } + /** + * Get all messages (and optionally clear them) + * @param boolean $clear + * @return array + * @see addMessage() + */ + public function getMessages($clear = true) { + $msgs = $this->messages; + if($clear) { + $this->messages = array(); + } + return $msgs; + } + /** * Set user service * @param \psm\Service\User $user diff --git a/src/psm/Module/Config/Controller/ConfigController.class.php b/src/psm/Module/Config/Controller/ConfigController.class.php index bb954b8f..e518525d 100644 --- a/src/psm/Module/Config/Controller/ConfigController.class.php +++ b/src/psm/Module/Config/Controller/ConfigController.class.php @@ -28,7 +28,6 @@ namespace psm\Module\Config\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class ConfigController extends AbstractController { @@ -67,8 +66,8 @@ class ConfigController extends AbstractController { private $default_tab = 'general'; - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setMinUserLevelRequired(PSM_USER_ADMIN); @@ -79,9 +78,12 @@ class ConfigController extends AbstractController { /** * Populate all the config fields with values from the database + * + * @return string */ protected function executeIndex() { - $this->setTemplateId('config', 'config/config.tpl.html'); + $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'config')); + $tpl_data = $this->getLabels(); $config_db = $this->db->select( PSM_DB_PREFIX . 'config', @@ -96,21 +98,20 @@ class ConfigController extends AbstractController { // generate language array $lang_keys = psm_get_langs(); - $languages = array(); + $tpl_data['language_current'] = (isset($config['language'])) + ? $config['language'] + : 'en_US'; + $tpl_data['languages'] = array(); foreach($lang_keys as $key => $label) { - $languages[] = array( + $tpl_data['languages'][] = array( 'value' => $key, 'label' => $label, - 'selected' => ($key == $config['language']) ? 'selected="selected"' : '', ); } - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'languages', $languages); - $tpl_data = array( - 'sms_selected_' . $config['sms_gateway'] => 'selected="selected"', - 'alert_type_selected_' . $config['alert_type'] => 'selected="selected"', - 'auto_refresh_servers' => (isset($config['auto_refresh_servers'])) ? $config['auto_refresh_servers'] : '0', - ); + $tpl_data['sms_selected_' . $config['sms_gateway']] = 'selected="selected"'; + $tpl_data['alert_type_selected_' . $config['alert_type']] = 'selected="selected"'; + $tpl_data['auto_refresh_servers'] = (isset($config['auto_refresh_servers'])) ? $config['auto_refresh_servers'] : '0'; foreach($this->checkboxes as $input_key) { $tpl_data[$input_key . '_checked'] = @@ -126,14 +127,14 @@ class ConfigController extends AbstractController { $testmodals = array('email', 'sms', 'pushover'); foreach($testmodals as $modal_id) { - $modal = new \psm\Util\Module\Modal($this->tpl, 'test' . ucfirst($modal_id), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL); + $modal = new \psm\Util\Module\Modal($this->twig, 'test' . ucfirst($modal_id), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL); $this->addModal($modal); $modal->setTitle(psm_get_lang('servers', 'send_' . $modal_id)); $modal->setMessage(psm_get_lang('config', 'test_' . $modal_id)); $modal->setOKButtonLabel(psm_get_lang('config', 'send')); } - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/config/config.tpl.html', $tpl_data); } /** @@ -186,7 +187,7 @@ class ConfigController extends AbstractController { $this->default_tab = 'pushover'; } } - $this->initializeAction('index'); + return $this->initializeAction('index'); } /** @@ -270,67 +271,60 @@ class ConfigController extends AbstractController { } } - // override parent::createHTMLLabels() - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('menu', 'config'), - 'label_tab_email' => psm_get_lang('config', 'tab_email'), - 'label_tab_sms' => psm_get_lang('config', 'tab_sms'), - 'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'), - 'label_settings_email' => psm_get_lang('config', 'settings_email'), - 'label_settings_sms' => psm_get_lang('config', 'settings_sms'), - 'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'), - 'label_settings_notification' => psm_get_lang('config', 'settings_notification'), - 'label_settings_log' => psm_get_lang('config', 'settings_log'), - 'label_general' => psm_get_lang('config', 'general'), - 'label_language' => psm_get_lang('config', 'language'), - 'label_show_update' => psm_get_lang('config', 'show_update'), - 'label_email_status' => psm_get_lang('config', 'email_status'), - 'label_email_from_email' => psm_get_lang('config', 'email_from_email'), - 'label_email_from_name' => psm_get_lang('config', 'email_from_name'), - 'label_email_smtp' => psm_get_lang('config', 'email_smtp'), - 'label_email_smtp_host' => psm_get_lang('config', 'email_smtp_host'), - 'label_email_smtp_port' => psm_get_lang('config', 'email_smtp_port'), - 'label_email_smtp_username' => psm_get_lang('config', 'email_smtp_username'), - 'label_email_smtp_password' => psm_get_lang('config', 'email_smtp_password'), - 'label_email_smtp_noauth' => psm_get_lang('config', 'email_smtp_noauth'), - 'label_sms_status' => psm_get_lang('config', 'sms_status'), - 'label_sms_gateway' => psm_get_lang('config', 'sms_gateway'), - 'label_sms_gateway_mosms' => psm_get_lang('config', 'sms_gateway_mosms'), - 'label_sms_gateway_mollie' => psm_get_lang('config', 'sms_gateway_mollie'), - 'label_sms_gateway_spryng' => psm_get_lang('config', 'sms_gateway_spryng'), - 'label_sms_gateway_inetworx' => psm_get_lang('config', 'sms_gateway_inetworx'), - 'label_sms_gateway_clickatell' => psm_get_lang('config', 'sms_gateway_clickatell'), - 'label_sms_gateway_textmarketer' => psm_get_lang('config', 'sms_gateway_textmarketer'), - 'label_sms_gateway_smsit' => psm_get_lang('config', 'sms_gateway_smsit'), - 'label_sms_gateway_smsglobal' => psm_get_lang('config', 'sms_gateway_smsglobal'), - 'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'), - 'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'), - 'label_sms_from' => psm_get_lang('config', 'sms_from'), - 'label_pushover_description' => psm_get_lang('config', 'pushover_description'), - 'label_pushover_status' => psm_get_lang('config', 'pushover_status'), - 'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'), - 'label_pushover_api_token_description' => psm_get_lang('config', 'pushover_api_token_description'), - 'label_alert_type' => psm_get_lang('config', 'alert_type'), - 'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'), - 'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'), - 'label_alert_type_offline' => psm_get_lang('config', 'alert_type_offline'), - 'label_alert_type_always' => psm_get_lang('config', 'alert_type_always'), - 'label_log_status' => psm_get_lang('config', 'log_status'), - 'label_log_status_description' => psm_get_lang('config', 'log_status_description'), - 'label_log_email' => psm_get_lang('config', 'log_email'), - 'label_log_sms' => psm_get_lang('config', 'log_sms'), - 'label_log_pushover' => psm_get_lang('config', 'log_pushover'), - 'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'), - 'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'), - 'label_seconds' => psm_get_lang('config', 'seconds'), - 'label_save' => psm_get_lang('system', 'save'), - 'label_test' => psm_get_lang('config', 'test'), - ) + protected function getLabels() { + return array( + 'label_tab_email' => psm_get_lang('config', 'tab_email'), + 'label_tab_sms' => psm_get_lang('config', 'tab_sms'), + 'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'), + 'label_settings_email' => psm_get_lang('config', 'settings_email'), + 'label_settings_sms' => psm_get_lang('config', 'settings_sms'), + 'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'), + 'label_settings_notification' => psm_get_lang('config', 'settings_notification'), + 'label_settings_log' => psm_get_lang('config', 'settings_log'), + 'label_general' => psm_get_lang('config', 'general'), + 'label_language' => psm_get_lang('config', 'language'), + 'label_show_update' => psm_get_lang('config', 'show_update'), + 'label_email_status' => psm_get_lang('config', 'email_status'), + 'label_email_from_email' => psm_get_lang('config', 'email_from_email'), + 'label_email_from_name' => psm_get_lang('config', 'email_from_name'), + 'label_email_smtp' => psm_get_lang('config', 'email_smtp'), + 'label_email_smtp_host' => psm_get_lang('config', 'email_smtp_host'), + 'label_email_smtp_port' => psm_get_lang('config', 'email_smtp_port'), + 'label_email_smtp_username' => psm_get_lang('config', 'email_smtp_username'), + 'label_email_smtp_password' => psm_get_lang('config', 'email_smtp_password'), + 'label_email_smtp_noauth' => psm_get_lang('config', 'email_smtp_noauth'), + 'label_sms_status' => psm_get_lang('config', 'sms_status'), + 'label_sms_gateway' => psm_get_lang('config', 'sms_gateway'), + 'label_sms_gateway_mosms' => psm_get_lang('config', 'sms_gateway_mosms'), + 'label_sms_gateway_mollie' => psm_get_lang('config', 'sms_gateway_mollie'), + 'label_sms_gateway_spryng' => psm_get_lang('config', 'sms_gateway_spryng'), + 'label_sms_gateway_inetworx' => psm_get_lang('config', 'sms_gateway_inetworx'), + 'label_sms_gateway_clickatell' => psm_get_lang('config', 'sms_gateway_clickatell'), + 'label_sms_gateway_textmarketer' => psm_get_lang('config', 'sms_gateway_textmarketer'), + 'label_sms_gateway_smsit' => psm_get_lang('config', 'sms_gateway_smsit'), + 'label_sms_gateway_smsglobal' => psm_get_lang('config', 'sms_gateway_smsglobal'), + 'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'), + 'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'), + 'label_sms_from' => psm_get_lang('config', 'sms_from'), + 'label_pushover_description' => psm_get_lang('config', 'pushover_description'), + 'label_pushover_status' => psm_get_lang('config', 'pushover_status'), + 'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'), + 'label_pushover_api_token_description' => psm_get_lang('config', 'pushover_api_token_description'), + 'label_alert_type' => psm_get_lang('config', 'alert_type'), + 'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'), + 'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'), + 'label_alert_type_offline' => psm_get_lang('config', 'alert_type_offline'), + 'label_alert_type_always' => psm_get_lang('config', 'alert_type_always'), + 'label_log_status' => psm_get_lang('config', 'log_status'), + 'label_log_status_description' => psm_get_lang('config', 'log_status_description'), + 'label_log_email' => psm_get_lang('config', 'log_email'), + 'label_log_sms' => psm_get_lang('config', 'log_sms'), + 'label_log_pushover' => psm_get_lang('config', 'log_pushover'), + 'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'), + 'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'), + 'label_seconds' => psm_get_lang('config', 'seconds'), + 'label_save' => psm_get_lang('system', 'save'), + 'label_test' => psm_get_lang('config', 'test'), ); - - return parent::createHTMLLabels(); } } diff --git a/src/psm/Module/ControllerInterface.class.php b/src/psm/Module/ControllerInterface.class.php index 14a63abf..8889d55c 100644 --- a/src/psm/Module/ControllerInterface.class.php +++ b/src/psm/Module/ControllerInterface.class.php @@ -28,11 +28,10 @@ namespace psm\Module; use psm\Service\Database; -use psm\Service\Template; interface ControllerInterface { - public function __construct(Database $db, Template $tpl); + public function __construct(Database $db, \Twig_Environment $twig); /** * Initialize the module diff --git a/src/psm/Module/Error/Controller/ErrorController.class.php b/src/psm/Module/Error/Controller/ErrorController.class.php index d4009d2b..f4c2c061 100644 --- a/src/psm/Module/Error/Controller/ErrorController.class.php +++ b/src/psm/Module/Error/Controller/ErrorController.class.php @@ -29,12 +29,11 @@ namespace psm\Module\Error\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class ErrorController extends AbstractController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setMinUserLevelRequired(PSM_USER_ANONYMOUS); @@ -45,10 +44,11 @@ class ErrorController extends AbstractController { /** * 401 error page + * + * @return string */ protected function execute401() { - $this->setTemplateId('error', 'error/error.tpl.html'); - $this->tpl->addTemplateData('error', array( + return $this->twig->render('module/error/401.tpl.html', array( 'label_title' => psm_get_lang('error', '401_unauthorized'), 'label_description' => psm_get_lang('error', '401_unauthorized_description'), )); diff --git a/src/psm/Module/Install/Controller/InstallController.class.php b/src/psm/Module/Install/Controller/InstallController.class.php index 6bd5fef9..be04e0c8 100644 --- a/src/psm/Module/Install/Controller/InstallController.class.php +++ b/src/psm/Module/Install/Controller/InstallController.class.php @@ -29,7 +29,6 @@ namespace psm\Module\Install\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class InstallController extends AbstractController { @@ -45,8 +44,8 @@ class InstallController extends AbstractController { */ protected $path_config_old; - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setMinUserLevelRequired(PSM_USER_ANONYMOUS); $this->addMenu(false); @@ -57,33 +56,14 @@ class InstallController extends AbstractController { $this->setActions(array( 'index', 'config', 'install' ), 'index'); - } - protected function createHTML() { - $html_results = ''; - if(!empty($this->messages)) { - $this->tpl->newTemplate('install_results', 'install/install.tpl.html'); - $this->tpl->addTemplateDataRepeat('install_results', 'resultmsgs', $this->messages); - $html_results = $this->tpl->getTemplate('install_results'); - $this->messages = array(); - } - $tpl_id = $this->getTemplateId(); - $this->setTemplateId('install', 'install/install.tpl.html'); - - $this->tpl->addTemplateData($this->getTemplateId(), array( - 'html_install' => $this->tpl->getTemplate($tpl_id), - 'html_results' => $html_results, - )); - - return parent::createHTML(); + $this->twig->addGlobal('subtitle', psm_get_lang('system,', 'install')); } /** * Say hi to our new user */ protected function executeIndex() { - $this->setTemplateId('install_index', 'install/install.tpl.html'); - // build prerequisites $errors = 0; @@ -110,13 +90,17 @@ class InstallController extends AbstractController { if($errors > 0) { $this->addMessage($errors . ' error(s) have been encountered. Please fix them and refresh this page.', 'error'); } + + return $this->twig->render('module/install/index.tpl.html', array( + 'messages' => $this->getMessages() + )); } /** * Help the user create a new config file */ protected function executeConfig() { - $this->setTemplateId('install_config_new', 'install/install.tpl.html'); + $tpl_name = 'module/install/config_new.tpl.html'; $tpl_data = array(); if(!defined('PSM_DB_PREFIX')) { @@ -168,8 +152,7 @@ class InstallController extends AbstractController { $this->addMessage('Configuration file written successfully.', 'success'); } else { $this->addMessage('Config file is not writable, we cannot save it for you.', 'error'); - $this->tpl->newTemplate('install_config_new_copy', 'install/install.tpl.html'); - $tpl_data['html_config_copy'] = $this->tpl->getTemplate('install_config_new_copy'); + $tpl_data['include_config_new_copy'] = true; $tpl_data['php_config'] = $config_php; } } else { @@ -185,14 +168,14 @@ class InstallController extends AbstractController { if(version_compare($this->getPreviousVersion(), '3.0.0', '<')) { // upgrade from before 3.0, does not have passwords yet.. create new user first $this->addMessage('Your current version does not have an authentication system, but since v3.0 access to the monitor is restricted by user accounts. Please set up a new account to be able to login after the upgrade, and which you can use to change the passwords for your other accounts.', 'info'); - $this->setTemplateId('install_config_new_user', 'install/install.tpl.html'); + $tpl_name = 'module/install/config_new_user.tpl.html'; } else { - $this->setTemplateId('install_config_upgrade', 'install/install.tpl.html'); + $tpl_name = 'module/install/config_upgrade.tpl.html'; $tpl_data['version'] = PSM_VERSION; } } else { // fresh install ahead - $this->setTemplateId('install_config_new_user', 'install/install.tpl.html'); + $tpl_name = 'module/install/config_new_user.tpl.html'; $tpl_data['username'] = (isset($_POST['username'])) ? $_POST['username'] : ''; $tpl_data['email'] = (isset($_POST['email'])) ? $_POST['email'] : ''; @@ -201,7 +184,8 @@ class InstallController extends AbstractController { $this->addMessage('Configuration file found, but unable to connect to MySQL. Please check your information.', 'error'); } } - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + $tpl_data['messages'] = $this->getMessages(); + return $this->twig->render($tpl_name, $tpl_data); } /** @@ -280,7 +264,9 @@ class InstallController extends AbstractController { } } - $this->setTemplateId('install_success', 'install/install.tpl.html'); + return $this->twig->render('module/install/success.tpl.html', array( + 'messages' => $this->getMessages() + )); } /** @@ -363,15 +349,4 @@ class InstallController extends AbstractController { return $version_from; } } - - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('system', 'install'), - ) - ); - - return parent::createHTMLLabels(); - } } diff --git a/src/psm/Module/Server/Controller/AbstractServerController.class.php b/src/psm/Module/Server/Controller/AbstractServerController.class.php index 8d75fb37..d5c773b2 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.class.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.class.php @@ -29,12 +29,11 @@ namespace psm\Module\Server\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; abstract class AbstractServerController extends AbstractController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); } /** diff --git a/src/psm/Module/Server/Controller/LogController.class.php b/src/psm/Module/Server/Controller/LogController.class.php index 82eaead6..2b6e465f 100644 --- a/src/psm/Module/Server/Controller/LogController.class.php +++ b/src/psm/Module/Server/Controller/LogController.class.php @@ -27,15 +27,14 @@ namespace psm\Module\Server\Controller; use psm\Service\Database; -use psm\Service\Template; /** * Log module. Create the page to view previous log messages */ class LogController extends AbstractServerController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setActions('index', 'index'); } @@ -44,7 +43,21 @@ class LogController extends AbstractServerController { * Prepare the template with a list of all log entries */ protected function executeIndex() { - $this->setTemplateId('server_log_list', 'server/log.tpl.html'); + $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server_log')); + $tpl_data = array( + 'label_status' => psm_get_lang('log', 'status'), + 'label_email' => psm_get_lang('log', 'email'), + 'label_sms' => psm_get_lang('log', 'sms'), + 'label_pushover' => psm_get_lang('log', 'pushover'), + 'label_title' => psm_get_lang('log', 'title'), + 'label_server' => psm_get_lang('servers', 'server'), + 'label_type' => psm_get_lang('log', 'type'), + 'label_message' => psm_get_lang('system', 'message'), + 'label_date' => psm_get_lang('system', 'date'), + 'label_users' => ucfirst(psm_get_lang('menu', 'user')), + 'label_no_logs' => psm_get_lang('log', 'no_logs'), + 'tabs' => array(), + ); $log_types = array('status', 'email', 'sms', 'pushover'); // get users @@ -59,6 +72,13 @@ class LogController extends AbstractServerController { $records = $this->getEntries($key); $log_count = count($records); + $tab_data = array( + 'id' => $key, + 'has_users' => ($key == 'status') ? false : true, + 'no_logs' => ($log_count == 0) ? true : false, + 'tab_active' => ($key == 'status') ? 'active' : '', + ); + for ($x = 0; $x < $log_count; $x++) { $record = &$records[$x]; $record['class'] = ($x & 1) ? 'odd' : 'even'; @@ -88,25 +108,10 @@ class LogController extends AbstractServerController { $record['user_list'] = implode(' • ', $names); } } - - // add entries to template - $this->tpl->newTemplate('server_log_entries', 'server/log.tpl.html'); - $this->tpl->addTemplateDataRepeat('server_log_entries', 'entries', $records); - $this->tpl->addTemplateData( - 'server_log_entries', - array( - 'logtitle' => $key, - '?has_users' => ($key == 'status') ? false : true, - '?no_logs' => ($log_count == 0) ? true : false, - ) - ); - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'content_' . $key => $this->tpl->getTemplate('server_log_entries'), - ) - ); + $tab_data['entries'] = $records; + $tpl_data['tabs'][] = $tab_data; } + return $this->twig->render('module/server/log.tpl.html', $tpl_data); } /** @@ -143,27 +148,4 @@ class LogController extends AbstractServerController { ); return $entries; } - - // override parent::createHTMLLabels() - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('menu', 'server_log'), - 'label_status' => psm_get_lang('log', 'status'), - 'label_email' => psm_get_lang('log', 'email'), - 'label_sms' => psm_get_lang('log', 'sms'), - 'label_pushover' => psm_get_lang('log', 'pushover'), - 'label_title' => psm_get_lang('log', 'title'), - 'label_server' => psm_get_lang('servers', 'server'), - 'label_type' => psm_get_lang('log', 'type'), - 'label_message' => psm_get_lang('system', 'message'), - 'label_date' => psm_get_lang('system', 'date'), - 'label_users' => ucfirst(psm_get_lang('menu', 'user')), - 'label_no_logs' => psm_get_lang('log', 'no_logs'), - ) - ); - - return parent::createHTMLLabels(); - } } diff --git a/src/psm/Module/Server/Controller/ServerController.class.php b/src/psm/Module/Server/Controller/ServerController.class.php index 0d144537..7d635c47 100644 --- a/src/psm/Module/Server/Controller/ServerController.class.php +++ b/src/psm/Module/Server/Controller/ServerController.class.php @@ -27,7 +27,6 @@ namespace psm\Module\Server\Controller; use psm\Service\Database; -use psm\Service\Template; /** * Server module. Add/edit/delete servers, show a list of all servers etc. @@ -40,8 +39,8 @@ class ServerController extends AbstractServerController { */ protected $server_id; - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->server_id = isset($_GET['id']) ? intval($_GET['id']) : 0; @@ -53,19 +52,21 @@ class ServerController extends AbstractServerController { $this->setMinUserLevelRequiredForAction(PSM_USER_ADMIN, array( 'delete', 'edit', 'save' )); + $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server')); } /** * Prepare the template to show a list of all servers */ protected function executeIndex() { - $this->setTemplateId('server_list', 'server/server.tpl.html'); - $sidebar = new \psm\Util\Module\Sidebar($this->tpl); + $tpl_data = $this->getLabels(); + $tpl_data['user_level'] = $this->user->getUserLevel(); + $sidebar = new \psm\Util\Module\Sidebar($this->twig); $this->setSidebar($sidebar); // check if user is admin, in that case we add the buttons if($this->user->getUserLevel() == PSM_USER_ADMIN) { - $modal = new \psm\Util\Module\Modal($this->tpl, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); + $modal = new \psm\Util\Module\Modal($this->twig, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); $this->addModal($modal); $modal->setTitle(psm_get_lang('servers', 'delete_title')); $modal->setMessage(psm_get_lang('servers', 'delete_message')); @@ -77,11 +78,6 @@ class ServerController extends AbstractServerController { psm_build_url(array('mod' => 'server', 'action' => 'edit')), 'plus icon-white', 'success' ); - // get the action buttons per server - $this->tpl->newTemplate('server_list_admin_actions', 'server/server.tpl.html'); - $html_actions = $this->tpl->getTemplate('server_list_admin_actions'); - } else { - $html_actions = ''; } $sidebar->addButton( @@ -91,8 +87,6 @@ class ServerController extends AbstractServerController { 'refresh' ); - // we need an array for our template magic (see below): - $html_actions = array('html_actions' => $html_actions); $icons = array( 'email' => 'icon-envelope', 'sms' => 'icon-mobile', @@ -103,10 +97,6 @@ class ServerController extends AbstractServerController { $server_count = count($servers); for ($x = 0; $x < $server_count; $x++) { - // template magic: push the actions html to the front of the server array - // so the template handler will add it first. that way the other server vars - // will also be replaced in the html_actions template itself - $servers[$x] = $html_actions + $servers[$x]; $servers[$x]['class'] = ($x & 1) ? 'odd' : 'even'; if($servers[$x]['type'] == 'website') { @@ -138,27 +128,24 @@ class ServerController extends AbstractServerController { $servers[$x] = $this->formatServer($servers[$x]); } - // add servers to template - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers', $servers); + $tpl_data['servers'] = $servers; + return $this->twig->render('module/server/server/list.tpl.html', $tpl_data); } /** * Prepare the template to show the update screen for a single server */ protected function executeEdit() { - $this->setTemplateId('server_update', 'server/server.tpl.html'); $back_to = isset($_GET['back_to']) ? $_GET['back_to'] : ''; - $tpl_data = array( - 'edit_server_id' => $this->server_id, - // form url: - 'url_save' => psm_build_url(array( - 'mod' => 'server', - 'action' => 'save', - 'id' => $this->server_id, - 'back_to' => $back_to, - )), - ); + $tpl_data = $this->getLabels(); + $tpl_data['edit_server_id'] = $this->server_id; + $tpl_data['url_save'] = psm_build_url(array( + 'mod' => 'server', + 'action' => 'save', + 'id' => $this->server_id, + 'back_to' => $back_to, + )); // depending on where the user came from, add the go back url: if($back_to == 'view' && $this->server_id > 0) { @@ -167,7 +154,7 @@ class ServerController extends AbstractServerController { $tpl_data['url_go_back'] = psm_build_url(array('mod' => 'server')); } - $users = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id', 'name'), '', 'name'); + $tpl_data['users'] = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id', 'name'), '', 'name'); switch($this->server_id) { case 0: @@ -188,7 +175,7 @@ class ServerController extends AbstractServerController { $tpl_data['titlemode'] = psm_get_lang('system', 'edit') . ' ' . $edit_server['label']; $user_idc_selected = $this->getServerUsers($this->server_id); - foreach($users as &$user) { + foreach($tpl_data['users'] as &$user) { if(in_array($user['user_id'], $user_idc_selected)) { $user['edit_selected'] = 'selected="selected"'; } @@ -196,7 +183,6 @@ class ServerController extends AbstractServerController { break; } - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'users', $users); if(!empty($edit_server)) { // attempt to prefill previously posted fields @@ -221,19 +207,19 @@ class ServerController extends AbstractServerController { } $notifications = array('email', 'sms', 'pushover'); - $this->tpl->newTemplate('server_update_warning', 'server/server.tpl.html'); foreach($notifications as $notification) { if(psm_get_conf($notification . '_status') == 0) { + $tpl_data['warning_' . $notification] = true; $tpl_data['control_class_' . $notification] = 'warning'; - $tpl_data['warning_' . $notification] = $this->tpl->addTemplateData( - $this->tpl->getTemplate('server_update_warning'), - array('label_warning' => psm_get_lang('servers', 'warning_notifications_disabled_' . $notification)), - true + $tpl_data['label_warning_' . $notification] = psm_get_lang( + 'servers', 'warning_notifications_disabled_' . $notification ); + } else { + $tpl_data['warning_' . $notification] = false; } } - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/server/server/update.tpl.html', $tpl_data); } /** @@ -312,9 +298,9 @@ class ServerController extends AbstractServerController { $back_to = isset($_GET['back_to']) ? $_GET['back_to'] : 'index'; if($back_to == 'view') { - $this->initializeAction('view'); + return $this->initializeAction('view'); } else { - $this->initializeAction('index'); + return $this->initializeAction('index'); } } @@ -335,7 +321,7 @@ class ServerController extends AbstractServerController { } $this->addMessage(psm_get_lang('servers', 'deleted'), 'success'); } - $this->initializeAction('index'); + return $this->initializeAction('index'); } /** @@ -351,27 +337,19 @@ class ServerController extends AbstractServerController { return $this->initializeAction('index'); } - $this->setTemplateId('server_view', 'server/view.tpl.html'); - - $tpl_data = $this->formatServer($server); + $tpl_data = $this->getLabels(); + $tpl_data = array_merge($tpl_data, $this->formatServer($server)); // create history HTML - $history = new \psm\Util\Server\HistoryGraph($this->db, $this->tpl); + $history = new \psm\Util\Server\HistoryGraph($this->db, $this->twig); $tpl_data['html_history'] = $history->createHTML($this->server_id); // add edit/delete buttons for admins if($this->user->getUserLevel() == PSM_USER_ADMIN) { - $tpl_id_actions = 'server_view_admin_actions'; - $this->tpl->newTemplate($tpl_id_actions, 'server/view.tpl.html'); - // template magic: push the actions html to the front of the server array - // so the template handler will add it first. that way the other server vars - // will also be replaced in the html_actions template itself - $tpl_data = array('html_actions' => $this->tpl->getTemplate($tpl_id_actions)) + $tpl_data; - + $tpl_data['has_admin_actions'] = true; $tpl_data['url_edit'] = psm_build_url(array('mod' => 'server', 'action' => 'edit', 'id' => $this->server_id, 'back_to' => 'view')); - $tpl_data['server_name'] = $server['label']; - $modal = new \psm\Util\Module\Modal($this->tpl, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); + $modal = new \psm\Util\Module\Modal($this->twig, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); $this->addModal($modal); $modal->setTitle(psm_get_lang('servers', 'delete_title')); $modal->setMessage(psm_get_lang('servers', 'delete_message')); @@ -380,17 +358,16 @@ class ServerController extends AbstractServerController { // add all available servers to the menu $servers = $this->getServers(); - $options = array(); + $tpl_data['options'] = array(); foreach($servers as $i => $server_available) { - $options[] = array( + $tpl_data['options'][] = array( 'class_active' => ($server_available['server_id'] == $this->server_id) ? 'active' : '', 'url' => psm_build_url(array('mod' => 'server', 'action' => 'view', 'id' => $server_available['server_id'])), 'label' => $server_available['label'], ); } - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'options', $options); - $sidebar = new \psm\Util\Module\Sidebar($this->tpl); + $sidebar = new \psm\Util\Module\Sidebar($this->twig); $this->setSidebar($sidebar); // check which module the user came from, and add a link accordingly @@ -402,51 +379,44 @@ class ServerController extends AbstractServerController { 'th-list' ); - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/server/server/view.tpl.html', $tpl_data); } - // override parent::createHTMLLabels() - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('menu', 'server'), - 'label_label' => psm_get_lang('servers', 'label'), - 'label_status' => psm_get_lang('servers', 'status'), - 'label_domain' => psm_get_lang('servers', 'domain'), - 'label_timeout' => psm_get_lang('servers', 'timeout'), - 'label_timeout_description' => psm_get_lang('servers', 'timeout_description'), - 'label_port' => psm_get_lang('servers', 'port'), - 'label_type' => psm_get_lang('servers', 'type'), - 'label_website' => psm_get_lang('servers', 'type_website'), - 'label_service' => psm_get_lang('servers', 'type_service'), - 'label_type' => psm_get_lang('servers', 'type'), - 'label_pattern' => psm_get_lang('servers', 'pattern'), - 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), - 'label_last_check' => psm_get_lang('servers', 'last_check'), - 'label_rtime' => psm_get_lang('servers', 'latency'), - 'label_last_online' => psm_get_lang('servers', 'last_online'), - 'label_monitoring' => psm_get_lang('servers', 'monitoring'), - 'label_email' => psm_get_lang('servers', 'email'), - 'label_send_email' => psm_get_lang('servers', 'send_email'), - 'label_sms' => psm_get_lang('servers', 'sms'), - 'label_send_sms' => psm_get_lang('servers', 'send_sms'), - 'label_pushover' => psm_get_lang('servers', 'pushover'), - 'label_users' => psm_get_lang('servers', 'users'), - 'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'), - 'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'), - 'label_action' => psm_get_lang('system', 'action'), - 'label_save' => psm_get_lang('system', 'save'), - 'label_go_back' => psm_get_lang('system', 'go_back'), - 'label_edit' => psm_get_lang('system', 'edit'), - 'label_delete' => psm_get_lang('system', 'delete'), - 'label_yes' => psm_get_lang('system', 'yes'), - 'label_no' => psm_get_lang('system', 'no'), - 'label_add_new' => psm_get_lang('system', 'add_new'), - ) + protected function getLabels() { + return array( + 'label_label' => psm_get_lang('servers', 'label'), + 'label_status' => psm_get_lang('servers', 'status'), + 'label_domain' => psm_get_lang('servers', 'domain'), + 'label_timeout' => psm_get_lang('servers', 'timeout'), + 'label_timeout_description' => psm_get_lang('servers', 'timeout_description'), + 'label_port' => psm_get_lang('servers', 'port'), + 'label_type' => psm_get_lang('servers', 'type'), + 'label_website' => psm_get_lang('servers', 'type_website'), + 'label_service' => psm_get_lang('servers', 'type_service'), + 'label_type' => psm_get_lang('servers', 'type'), + 'label_pattern' => psm_get_lang('servers', 'pattern'), + 'label_pattern_description' => psm_get_lang('servers', 'pattern_description'), + 'label_last_check' => psm_get_lang('servers', 'last_check'), + 'label_rtime' => psm_get_lang('servers', 'latency'), + 'label_last_online' => psm_get_lang('servers', 'last_online'), + 'label_monitoring' => psm_get_lang('servers', 'monitoring'), + 'label_email' => psm_get_lang('servers', 'email'), + 'label_send_email' => psm_get_lang('servers', 'send_email'), + 'label_sms' => psm_get_lang('servers', 'sms'), + 'label_send_sms' => psm_get_lang('servers', 'send_sms'), + 'label_pushover' => psm_get_lang('servers', 'pushover'), + 'label_users' => psm_get_lang('servers', 'users'), + 'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'), + 'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'), + 'label_action' => psm_get_lang('system', 'action'), + 'label_save' => psm_get_lang('system', 'save'), + 'label_go_back' => psm_get_lang('system', 'go_back'), + 'label_edit' => psm_get_lang('system', 'edit'), + 'label_delete' => psm_get_lang('system', 'delete'), + 'label_yes' => psm_get_lang('system', 'yes'), + 'label_no' => psm_get_lang('system', 'no'), + 'label_add_new' => psm_get_lang('system', 'add_new'), ); - - return parent::createHTMLLabels(); } /** diff --git a/src/psm/Module/Server/Controller/StatusController.class.php b/src/psm/Module/Server/Controller/StatusController.class.php index fe42a311..a98aef23 100644 --- a/src/psm/Module/Server/Controller/StatusController.class.php +++ b/src/psm/Module/Server/Controller/StatusController.class.php @@ -28,15 +28,14 @@ namespace psm\Module\Server\Controller; use psm\Service\Database; -use psm\Service\Template; /** * Status module */ class StatusController extends AbstractServerController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setActions(array('index', 'saveLayout'), 'index'); } @@ -48,28 +47,26 @@ class StatusController extends AbstractServerController { protected function executeIndex() { // set background color to black $this->black_background = true; - + $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server_status')); + // add header accessories $layout = $this->user->getUserPref('status_layout', 0); $layout_data = array( + 'label_last_check' => psm_get_lang('servers', 'last_check'), + 'label_last_online' => psm_get_lang('servers', 'last_online'), + 'label_rtime' => psm_get_lang('servers', 'latency'), 'block_layout_active' => ($layout == 0) ? 'active' : '', 'list_layout_active' => ($layout != 0) ? 'active' : '', ); - $this->tpl->newTemplate('status_layout_selector', 'server/status.tpl.html'); - $this->tpl->addTemplateData('status_layout_selector', $layout_data); - $html_accessories = $this->tpl->getTemplate('status_layout_selector'); - $this->setHeaderAccessories($html_accessories); - - $this->setTemplateId('server_status', 'server/status.tpl.html'); + $this->setHeaderAccessories($this->twig->render('module/server/status/header.tpl.html', $layout_data)); + $this->addFooter(false); - $this->tpl->addTemplateData($this->getTemplateId(), $layout_data); - // get the active servers from database $servers = $this->getServers(); - $offline = array(); - $online = array(); + $layout_data['servers_offline'] = array(); + $layout_data['servers_online'] = array(); foreach ($servers as $server) { if($server['active'] == 'no') { @@ -80,36 +77,28 @@ class StatusController extends AbstractServerController { $server['url_view'] = psm_build_url(array('mod' => 'server', 'action' => 'view', 'id' => $server['server_id'], 'back_to' => 'server_status')); if ($server['status'] == "off") { - $offline[$server['server_id']] = $server; + $layout_data['servers_offline'][] = $server; } elseif($server['warning_threshold_counter'] > 0) { $server['class_warning'] = 'warning'; - $offline[$server['server_id']] = $server; + $layout_data['servers_offline'][] = $server; } else { - $online[$server['server_id']] = $server; + $layout_data['servers_online'][] = $server; } } - // add servers to template - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_offline', $offline); - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_online', $online); - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_offline2', $offline); - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers_online2', $online); - - // check if we need to add the auto refresh - $auto_refresh = psm_get_conf('auto_refresh_servers'); - if(intval($auto_refresh) > 0) { - // add it - $this->tpl->newTemplate('main_auto_refresh', 'main.tpl.html'); - $this->tpl->addTemplateData('main_auto_refresh', array('seconds' => $auto_refresh)); - $this->tpl->addTemplateData('main', array('auto_refresh' => $this->tpl->getTemplate('main_auto_refresh'))); + $auto_refresh_seconds = psm_get_conf('auto_refresh_servers'); + if(intval($auto_refresh_seconds) > 0) { + $this->twig->addGlobal('auto_refresh', true); + $this->twig->addGlobal('auto_refresh_seconds', $auto_refresh_seconds); } + return $this->twig->render('module/server/status/index.tpl.html', $layout_data); } protected function executeSaveLayout() { if($this->isXHR()) { $layout = psm_POST('layout', 0); $this->user->setUserPref('status_layout', $layout); - + $response = new \Symfony\Component\HttpFoundation\JsonResponse(); $response->setData(array( 'layout' => $layout, @@ -117,18 +106,4 @@ class StatusController extends AbstractServerController { return $response; } } - - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('menu', 'server_status'), - 'label_last_check' => psm_get_lang('servers', 'last_check'), - 'label_last_online' => psm_get_lang('servers', 'last_online'), - 'label_rtime' => psm_get_lang('servers', 'latency'), - ) - ); - - return parent::createHTMLLabels(); - } } diff --git a/src/psm/Module/Server/Controller/UpdateController.class.php b/src/psm/Module/Server/Controller/UpdateController.class.php index f6f241ff..c6aab3a0 100644 --- a/src/psm/Module/Server/Controller/UpdateController.class.php +++ b/src/psm/Module/Server/Controller/UpdateController.class.php @@ -30,12 +30,11 @@ namespace psm\Module\Server\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class UpdateController extends AbstractController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setActions('index', 'index'); } diff --git a/src/psm/Module/User/Controller/LoginController.class.php b/src/psm/Module/User/Controller/LoginController.class.php index ef57e3af..5f9a165f 100644 --- a/src/psm/Module/User/Controller/LoginController.class.php +++ b/src/psm/Module/User/Controller/LoginController.class.php @@ -29,12 +29,11 @@ namespace psm\Module\User\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class LoginController extends AbstractController { - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setMinUserLevelRequired(PSM_USER_ANONYMOUS); @@ -46,8 +45,6 @@ class LoginController extends AbstractController { } protected function executeLogin() { - $this->setTemplateId('user_login', 'user/login.tpl.html'); - if(isset($_POST['user_name']) && isset($_POST['user_password'])) { $rememberme = (isset($_POST['user_rememberme'])) ? true : false; $result = $this->user->loginWithPostData( @@ -76,15 +73,15 @@ class LoginController extends AbstractController { 'value_rememberme' => (isset($rememberme) && $rememberme) ? 'checked="checked"' : '', ); - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/user/login/login.tpl.html', $tpl_data); } /** * Show/process the password forgot form (before the mail) + * + * @return string */ protected function executeForgot() { - $this->setTemplateId('user_login_forgot', 'user/login.tpl.html'); - if(isset($_POST['user_name'])) { $user = $this->user->getUserByUsername($_POST['user_name']); @@ -110,16 +107,13 @@ class LoginController extends AbstractController { 'label_submit' => psm_get_lang('login', 'submit'), 'label_go_back' => psm_get_lang('system', 'go_back'), ); - - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/user/login/forgot.tpl.html', $tpl_data); } /** * Show/process the password reset form (after the mail) */ protected function executeReset() { - $this->setTemplateId('user_login_reset', 'user/login.tpl.html'); - $user_id = (isset($_GET['user_id'])) ? intval($_GET['user_id']) : 0; $token = (isset($_GET['token'])) ? $_GET['token'] : ''; @@ -153,8 +147,7 @@ class LoginController extends AbstractController { 'label_go_back' => psm_get_lang('system', 'go_back'), 'value_user_name' => $user->user_name, ); - - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/user/login/reset.tpl.html', $tpl_data); } /** diff --git a/src/psm/Module/User/Controller/ProfileController.class.php b/src/psm/Module/User/Controller/ProfileController.class.php index f6a261a8..a51ca031 100644 --- a/src/psm/Module/User/Controller/ProfileController.class.php +++ b/src/psm/Module/User/Controller/ProfileController.class.php @@ -28,7 +28,6 @@ namespace psm\Module\User\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; class ProfileController extends AbstractController { @@ -38,8 +37,8 @@ class ProfileController extends AbstractController { */ protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setActions(array( 'index', 'save', @@ -48,13 +47,26 @@ class ProfileController extends AbstractController { /** * Show the profile page + * @return string */ protected function executeIndex() { - $this->setTemplateId('user_profile', 'user/profile.tpl.html'); - + $this->twig->addGlobal('subtitle', psm_get_lang('users', 'profile')); $user = $this->user->getUser(null, true); $tpl_data = array( + 'label_name' => psm_get_lang('users', 'name'), + 'label_user_name' => psm_get_lang('users', 'user_name'), + 'label_password' => psm_get_lang('users', 'password'), + 'label_password_repeat' => psm_get_lang('users', 'password_repeat'), + 'label_level' => psm_get_lang('users', 'level'), + 'label_mobile' => psm_get_lang('users', 'mobile'), + 'label_pushover' => psm_get_lang('users', 'pushover'), + 'label_pushover_description' => psm_get_lang('users', 'pushover_description'), + 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), + 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), + 'label_pushover_device_description' => psm_get_lang('users', 'pushover_device_description'), + 'label_email' => psm_get_lang('users', 'email'), + 'label_save' => psm_get_lang('system', 'save'), 'form_action' => psm_build_url(array( 'mod' => 'user_profile', 'action' => 'save', @@ -65,7 +77,7 @@ class ProfileController extends AbstractController { foreach($this->profile_fields as $field) { $tpl_data[$field] = (isset($user->$field)) ? $user->$field : ''; } - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + return $this->twig->render('module/user/profile.tpl.html', $tpl_data); } /** @@ -119,29 +131,4 @@ class ProfileController extends AbstractController { return $this->executeIndex(); } - - // override parent::createHTMLLabels() - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('users', 'profile'), - 'label_name' => psm_get_lang('users', 'name'), - 'label_user_name' => psm_get_lang('users', 'user_name'), - 'label_password' => psm_get_lang('users', 'password'), - 'label_password_repeat' => psm_get_lang('users', 'password_repeat'), - 'label_level' => psm_get_lang('users', 'level'), - 'label_mobile' => psm_get_lang('users', 'mobile'), - 'label_pushover' => psm_get_lang('users', 'pushover'), - 'label_pushover_description' => psm_get_lang('users', 'pushover_description'), - 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), - 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), - 'label_pushover_device_description' => psm_get_lang('users', 'pushover_device_description'), - 'label_email' => psm_get_lang('users', 'email'), - 'label_save' => psm_get_lang('system', 'save'), - ) - ); - - return parent::createHTMLLabels(); - } } \ No newline at end of file diff --git a/src/psm/Module/User/Controller/UserController.class.php b/src/psm/Module/User/Controller/UserController.class.php index 0552d6d6..f29fa6c9 100644 --- a/src/psm/Module/User/Controller/UserController.class.php +++ b/src/psm/Module/User/Controller/UserController.class.php @@ -28,7 +28,6 @@ namespace psm\Module\User\Controller; use psm\Module\AbstractController; use psm\Service\Database; -use psm\Service\Template; /** * User module. Add, edit and delete users, or assign @@ -43,14 +42,15 @@ class UserController extends AbstractController { */ protected $user_validator; - function __construct(Database $db, Template $tpl) { - parent::__construct($db, $tpl); + function __construct(Database $db, \Twig_Environment $twig) { + parent::__construct($db, $twig); $this->setMinUserLevelRequired(PSM_USER_ADMIN); $this->setActions(array( 'index', 'edit', 'delete', 'save', ), 'index'); + $this->twig->addGlobal('subtitle', psm_get_lang('menu', 'user')); } public function initialize() { @@ -65,11 +65,12 @@ class UserController extends AbstractController { } /** - * Prepare the template to show a list of all users + * Create HTML to show a list of all users + * + * @return string */ protected function executeIndex() { - $this->setTemplateId('user_list', 'user/user.tpl.html'); - $sidebar = new \psm\Util\Module\Sidebar($this->tpl); + $sidebar = new \psm\Util\Module\Sidebar($this->twig); $this->setSidebar($sidebar); $sidebar->addButton( @@ -79,7 +80,7 @@ class UserController extends AbstractController { 'plus icon-white', 'success' ); - $modal = new \psm\Util\Module\Modal($this->tpl, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); + $modal = new \psm\Util\Module\Modal($this->twig, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER); $this->addModal($modal); $modal->setTitle(psm_get_lang('users', 'delete_title')); $modal->setMessage(psm_get_lang('users', 'delete_message')); @@ -102,15 +103,17 @@ class UserController extends AbstractController { foreach($users as $x => &$user) { $user_servers = $this->getUserServers($user['user_id']); $user['class'] = ($x & 1) ? 'odd' : 'even'; + $user['level_text'] = psm_get_lang('users', 'level_' . $user['level']); - $user['emp_servers'] = ''; + $user['emp_servers'] = array(); // fix server list foreach($user_servers as $server_id) { if (!isset($servers_labels[$server_id])) continue; - $user['emp_servers'] .= $servers_labels[$server_id] . '
'; + $user['emp_servers'][] = array( + 'label' => $servers_labels[$server_id] + ); } - $user['emp_servers'] = substr($user['emp_servers'], 0, -5); $user['url_delete'] = psm_build_url(array( 'mod' => 'user', @@ -123,14 +126,18 @@ class UserController extends AbstractController { 'id' => $user['user_id'], )); } - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'users', $users); + $tpl_data = $this->getLabels(); + $tpl_data['users'] = $users; + + return $this->twig->render('module/user/user/list.tpl.html', $tpl_data); } /** - * Prepare the template to show the update screen for a user + * Crate HTML for the update screen for a user + * + * @return string */ protected function executeEdit() { - $this->setTemplateId('user_update', 'user/user.tpl.html'); $user_id = isset($_GET['id']) ? intval($_GET['id']) : 0; $fields_prefill = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); @@ -182,6 +189,8 @@ class UserController extends AbstractController { 'action' => 'save', 'id' => $user_id, )), + 'servers' => $this->servers, + 'user_level' => $lvl_selected, ); foreach($fields_prefill as $field) { if(isset($edit_user->$field)) { @@ -189,17 +198,17 @@ class UserController extends AbstractController { } } - $ulvls_tpl = array(); + $tpl_data['levels'] = array(); foreach($this->user_validator->getUserLevels() as $lvl) { - $ulvls_tpl[] = array( + $tpl_data['levels'][] = array( 'value' => $lvl, 'label' => psm_get_lang('users', 'level_' . $lvl), - 'selected' => ($lvl == $lvl_selected) ? 'selected="selected"' : '', ); } - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'levels', $ulvls_tpl); - $this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'servers', $this->servers); - $this->tpl->addTemplateData($this->getTemplateId(), $tpl_data); + + $tpl_data = array_merge($this->getLabels(), $tpl_data); + + return $this->twig->render('module/user/user/update.tpl.html', $tpl_data); } /** @@ -299,42 +308,31 @@ class UserController extends AbstractController { return $this->executeIndex(); } - // override parent::createHTMLLabels() - protected function createHTMLLabels() { - $this->tpl->addTemplateData( - $this->getTemplateId(), - array( - 'subtitle' => psm_get_lang('menu', 'user'), - 'label_users' => psm_get_lang('menu', 'users'), - 'label_user' => psm_get_lang('users', 'user'), - 'label_name' => psm_get_lang('users', 'name'), - 'label_user_name' => psm_get_lang('users', 'user_name'), - 'label_password' => psm_get_lang('users', 'password'), - 'label_password_repeat' => psm_get_lang('users', 'password_repeat'), - 'label_level' => psm_get_lang('users', 'level'), - 'label_level_10' => psm_get_lang('users', 'level_10'), - 'label_level_20' => psm_get_lang('users', 'level_20'), - 'label_level_description' => psm_get_lang('users', 'level_description'), - 'label_mobile' => psm_get_lang('users', 'mobile'), - 'label_pushover' => psm_get_lang('users', 'pushover'), - 'label_pushover_description' => psm_get_lang('users', 'pushover_description'), - 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), - 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), - 'label_pushover_device_description' => psm_get_lang('users', 'pushover_device_description'), - 'label_email' => psm_get_lang('users', 'email'), - 'label_servers' => psm_get_lang('menu', 'server'), - 'label_action' => psm_get_lang('system', 'action'), - 'label_save' => psm_get_lang('system', 'save'), - 'label_go_back' => psm_get_lang('system', 'go_back'), - 'label_edit' => psm_get_lang('system', 'edit'), - 'label_delete' => psm_get_lang('system', 'delete'), - 'label_add_new' => psm_get_lang('system', 'add_new'), - 'icon_level_10' => 'icon-admin', - 'icon_level_20' => 'icon-user', - ) + protected function getLabels() { + return array( + 'label_users' => psm_get_lang('menu', 'users'), + 'label_user' => psm_get_lang('users', 'user'), + 'label_name' => psm_get_lang('users', 'name'), + 'label_user_name' => psm_get_lang('users', 'user_name'), + 'label_password' => psm_get_lang('users', 'password'), + 'label_password_repeat' => psm_get_lang('users', 'password_repeat'), + 'label_level' => psm_get_lang('users', 'level'), + 'label_level_description' => psm_get_lang('users', 'level_description'), + 'label_mobile' => psm_get_lang('users', 'mobile'), + 'label_pushover' => psm_get_lang('users', 'pushover'), + 'label_pushover_description' => psm_get_lang('users', 'pushover_description'), + 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), + 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), + 'label_pushover_device_description' => psm_get_lang('users', 'pushover_device_description'), + 'label_email' => psm_get_lang('users', 'email'), + 'label_servers' => psm_get_lang('menu', 'server'), + 'label_action' => psm_get_lang('system', 'action'), + 'label_save' => psm_get_lang('system', 'save'), + 'label_go_back' => psm_get_lang('system', 'go_back'), + 'label_edit' => psm_get_lang('system', 'edit'), + 'label_delete' => psm_get_lang('system', 'delete'), + 'label_add_new' => psm_get_lang('system', 'add_new'), ); - - return parent::createHTMLLabels(); } /** diff --git a/src/psm/Router.class.php b/src/psm/Router.class.php index 43a53936..125b690e 100644 --- a/src/psm/Router.class.php +++ b/src/psm/Router.class.php @@ -64,9 +64,14 @@ class Router { public function __construct() { global $db; $this->services['db'] = $db; - $this->services['tpl'] = new \psm\Service\Template(); $this->services['user'] = new \psm\Service\User($db); + $loader = new \Twig_Loader_Filesystem(PSM_PATH_TPL . PSM_THEME); + $this->services['twig'] = new \Twig_Environment($loader); + if(PSM_DEBUG) { + $this->services['twig']->enableDebug(); + } + $modules = $this->getModules(); foreach($modules as $id => $module) { @@ -156,7 +161,7 @@ class Router { if($controller === false) { throw new \InvalidArgumentException('Controller is not registered'); } - $controller = new $controller($this->services['db'], $this->services['tpl']); + $controller = new $controller($this->services['db'], $this->services['twig']); if(!$controller instanceof \psm\Module\ControllerInterface) { throw new \Exception('Controller does not use ControllerInterface'); diff --git a/src/psm/Service/Template.class.php b/src/psm/Service/Template.class.php deleted file mode 100644 index e5d433de..00000000 --- a/src/psm/Service/Template.class.php +++ /dev/null @@ -1,307 +0,0 @@ -. - * - * @package phpservermon - * @author Pepijn Over - * @copyright Copyright (c) 2008-2014 Pepijn Over - * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 - * @version Release: @package_version@ - * @link http://www.phpservermonitor.org/ - **/ - -namespace psm\Service; - -class Template { - - /** - * Loaded templates - * @var array $templates - */ - protected $templates = array(); - - /** - * Cache of parsed files - * @var array $files_parsed - * @see parseFile() - */ - protected $files_parsed = array(); - - function __construct() { - // add the main template - $this->newTemplate('main', 'main.tpl.html'); - } - - /** - * Add template - * - * @param string $id template id used in the tpl file (html) - * @param string $filename path to template file, or if file is located in the default template dir just the filename - * @return mixed false if template cannot be found, html code on success - */ - public function newTemplate($id, $filename) { - if (file_exists($filename)) { - $this->templates[$id] = $this->parseFile($filename); - } elseif (file_exists(PSM_PATH_TPL.$filename)) { - $this->templates[$id] = $this->parseFile(PSM_PATH_TPL.$filename); - } else { - // file does not exist - trigger_error('Template not found with id: '.$id.' and filename: '.$filename); - return false; - } - $use_tpl = null; - - // only get data from the file that's between the tpl id tags with this id - // find "tpl_{$row_id}" in the current template - //preg_match_all('{(.*?)}is', $this->templates[$id], $matches); - preg_match_all("{(.*?)}is", $this->templates[$id], $matches); - - // no repeat tpl found? skip to next one - if (empty($matches)) return false; - - // check if the row_id is in one of the matches (aka whether the supplied row id actually has a template in this file) - if (isset($matches[1][0])) { - $use_tpl = $matches[1][0]; - } - - // no template with the given id found.. - if ($use_tpl === null) return false; - - // remove tpl code tags from original template so it won't be in the source - $this->templates[$id] = preg_replace("{(.*?)}is", "", $use_tpl); - - return $this->templates[$id]; - } - - /** - * Add data to the template - * - * @param string $tpl_id template_id used by add_template() - * @param array $data - * @param boolean $use_html if true, $tpl_id is considered to be HTML code and used rather than a template - * @return string new template - */ - public function addTemplateData($tpl_id, $data, $use_html = false) { - if($use_html) { - // no template - $source = $tpl_id; - } else { - // does the template exist? - if (!isset($this->templates[$tpl_id])) { - // file does not exist - trigger_error("Template '{$tpl_id}' could not be found", E_USER_WARNING); - return false; - } - $source =& $this->templates[$tpl_id]; - } - - foreach($data as $key => $value) { - if(is_array($value)) { - $subdata = array(); - foreach($value as $k => $v) { - $subdata[$key.'_'.$k] = $v; - } - $source = $this->addTemplateData($source, $subdata, true); - } else { - if(substr($key, 0, 1) == '?') { - $key = substr($key, 1); - // replace if statements - $if_replacement = empty($value) ? '' : '$1'; - $source = preg_replace('{(.*?)}is', $if_replacement, $source); - } - - $source = str_replace('{'.$key.'}', $value, $source); - } - } - return $source; - } - - /** - * Add repeat rows to template. - * It's possible to create a nested repeat tpl. All you need to do is to create a subarray - * For example: - * $data = array( - * 0 => array( - * 'name' => 'Test', - * 'subdata' => array( - * 0 => array( - * 'name' => 'Subtest 1', - * ), - * 1 => array(...) - * ), - * ), - * ); - * In your template you would literally put the nested repeat inside the first repeat. - * If you have more than 1 nested array, the first subtemplate will be used for all others. - * - * @param string $id template id used by add_template() or html code in case of repeat-repeat tpl - * @param string $repeat_id ID used in template file for the repeat template: html - * @param array $data - * @param boolean $use_html can only be used from within this function for recursive repeat templating. in this case the $id is the html code - * @param int $level starts off with 0. if level=2, current repeat template will be used again for subs, so you can go all the way - * @param int $level_reuse_prev from what level should we start repeating the current template for more subrecords, so we can go all the way? - * @return mixed false if repeat template cannot be found, html code on success - */ - public function addTemplateDataRepeat($tpl_id, $repeat_id, $data, $use_html = false, $level = 0, $level_reuse_prev = 2) { - if($use_html) { - $source = $tpl_id; - } else { - // does the template exist? - if (!isset($this->templates[$tpl_id])) { - // file does not exist - trigger_error("Template '{$tpl_id}' could not be found", E_USER_WARNING); - return false; - } - $source =& $this->templates[$tpl_id]; - } - - if($level < $level_reuse_prev) { - // find "tpl_repeat_{$repeat_id}_" in the current template - preg_match_all("{(.*?)}is", $source, $matches); - - // check if the repeat_id is in one of the matches - if (isset($matches[1][0])) { - $use_tpl = $matches[1][0]; - } else { - // if we didn't find a repeat template for the repeat_id supplied, skip the rest.. - return false; - } - - // remove repeat tpl code from original template so it won't be in the source - $source = preg_replace("{(.*?)}is", "", $source); - } else { - $use_tpl = $source; - } - // now lets go through all the records supplied and put them in the HTML repeat code we just found - $result = ''; - - foreach($data as $record) { - $tmp_string = $use_tpl; - - if(!is_array($record)) { - $record = array( - 'value' => $record, - ); - } - - // multi dim array - foreach($record as $k => $v) { - if(is_array($v)) { - // nested repeat - if(isset($v[0]) && is_array($v[0])) { - // repeat template in a repeat template - $repeat_html = $this->addTemplateDataRepeat($use_tpl, $k, $v, true, ($level + 1), $level_reuse_prev); - $tmp_string = str_replace('{'.$k.'}', $repeat_html, $tmp_string); - } else { - foreach($v as $vk => $vv) { - if(substr($vk, 0, 1) == '?') { - $vk = substr($vk, 1); - // replace if statements - $if_replacement = empty($vv) ? '' : '$1'; - $tmp_string = preg_replace('{(.*?)}is', $if_replacement, $tmp_string); - } - - $tmp_string = str_replace('{'.$k.'_'.$vk.'}', $vv, $tmp_string); - } - } - } else { - if(substr($k, 0, 1) == '?') { - $k = substr($k, 1); - // replace if statements - $if_replacement = empty($v) ? '' : '$1'; - $tmp_string = preg_replace('{(.*?)}is', $if_replacement, $tmp_string); - } - - $tmp_string = str_replace('{'.$k.'}', $v, $tmp_string); - } - } - - $result .= $tmp_string.PHP_EOL; - } - - if($use_html === false) { - // add to main template.. - return $this->addTemplateData($tpl_id, array($repeat_id => $result)); - } else { - return $result; - } - } - - public function display($id) { - // check if there are any unused tpl_repeat templates, and if there are remove them - $result = preg_replace('{(.*?)}is', '', $this->templates[$id]); - - // check if there are any unused if, and if there are remove them - $result = preg_replace('{(.*?)}is', '', $result); - - // check for tpl variables that have not been replaced. ie: {name}. ignore literal stuff, though. ie: {{name}} is {name} and should not be removed - preg_match_all('~{?{(\w+?)}}?~', $result, $matches); - - foreach($matches[0] as $match) { - if (substr($match, 0, 2) == '{{') { - // literal! remove only first and last bracket! - $result = str_replace($match, substr($match, 1, -1), $result); - } else { - // unused variable, remove completely - $result = str_replace($match, '', $result); - } - } - return $result; - } - - /** - * Get html code for a template, or if no template id given get all templates - * - * @param string $template_id - * @return mixed string when ID given, else array - */ - public function getTemplate($template_id = null) { - if ($template_id === null) { - return $this->templates; - } elseif (isset($this->templates[$template_id])) { - return $this->templates[$template_id]; - } else { - return false; - } - } - - /** - * - * Get file content - * - * @param string $filename filename - * @return string file contents - */ - protected function parseFile($filename) { - if (!file_exists($filename)) return false; - - if(isset($this->files_parsed[$filename])) { - return $this->files_parsed[$filename]; - } - - ob_start(); - include($filename); - $file_content = ob_get_contents(); - ob_end_clean(); - - $this->files_parsed[$filename] = $file_content; - - return $file_content; - } -} - diff --git a/src/psm/Util/Module/Modal.class.php b/src/psm/Util/Module/Modal.class.php index 18b911be..00857afd 100644 --- a/src/psm/Util/Module/Modal.class.php +++ b/src/psm/Util/Module/Modal.class.php @@ -27,52 +27,51 @@ **/ namespace psm\Util\Module; -use psm\Service\Template; class Modal implements ModalInterface { - + const MODAL_TYPE_OK = 0; const MODAL_TYPE_OKCANCEL = 1; const MODAL_TYPE_DANGER = 2; - /** - * Template service - * @var \psm\Service\Template $tpl - */ - protected $tpl; - /** * prefix used for modal dialog box elements - * @var string $modal_id + * @var string $modal_id */ protected $modal_id; - + /** - * @var int $type Type of modal dialog + * @var int $type Type of modal dialog */ protected $type; - + /** * Modal dialog title * @var string $title */ protected $title; - + /** * Modal dialog message * @var string $body */ protected $message; - + /** * label of the OK button * @var string $ok_label */ protected $ok_label; - public function __construct(Template $tpl, $modal_id = 'main', $type = self::MODAL_TYPE_OK ) { + /** + * Twig environment + * @var \Twig_Environment $twig + */ + protected $twig; + + public function __construct(\Twig_Environment $twig, $modal_id = 'main', $type = self::MODAL_TYPE_OK ) { $this->modal_id = $modal_id; - $this->tpl = $tpl; + $this->twig = $twig; $this->type = $type; } @@ -83,7 +82,7 @@ class Modal implements ModalInterface { public function getModalID() { return $this->modal_id; } - + /** * Set the modal dialog type * @param int $type @@ -95,7 +94,7 @@ class Modal implements ModalInterface { } return $this; } - + /** * Set the modal dialog title * @param string $title @@ -105,7 +104,7 @@ class Modal implements ModalInterface { $this->title = $title; return $this; } - + /** * Set the modal dialog message * @param string $message @@ -115,41 +114,36 @@ class Modal implements ModalInterface { $this->message = $message; return $this; } - + public function setOKButtonLabel($label) { $this->ok_label = $label; return $this; } - - public function createHTML() { - $tpl_id = 'main_modal_container'; - $this->tpl->newTemplate($tpl_id, 'main_modal.tpl.html'); + public function createHTML() { $has_cancel = ($this->type == self::MODAL_TYPE_OK) ? false : true; $button_type = ($this->type == self::MODAL_TYPE_DANGER) ? 'danger' : 'primary'; $button_label = empty($this->ok_label) ? psm_get_lang('system', 'ok') : $this->ok_label; - $message = !empty($this->message) ? $this->message : ''; + $matches = array(); if(preg_match_all('/%(\d)/', $message, $matches, PREG_SET_ORDER)) { foreach($matches as $match) { $message = str_replace($match[0], '', $message); } } - - $this->tpl->addTemplateData($tpl_id, array( - 'modal_id' => $this->modal_id, - 'modal_title' => !empty($this->title) ? $this->title : psm_get_lang('system', 'title'), - 'modal_body' => $message, - '?has_cancel' => $has_cancel, - 'label_cancel' => psm_get_lang('system', 'cancel'), + + $tpl = $this->twig->loadTemplate('util/module/modal.tpl.html'); + $html = $tpl->render(array( + 'modal_id' => $this->modal_id, + 'modal_title' => !empty($this->title) ? $this->title : psm_get_lang('system', 'title'), + 'modal_body' => $message, + 'has_cancel' => $has_cancel, + 'label_cancel' => psm_get_lang('system', 'cancel'), 'modal_button_type' => $button_type, 'modal_button_label'=> $button_label, )); - - - $html = $this->tpl->getTemplate($tpl_id); return $html; - } + } } diff --git a/src/psm/Util/Module/ModalInterface.class.php b/src/psm/Util/Module/ModalInterface.class.php index b5fe1e5c..3f204823 100644 --- a/src/psm/Util/Module/ModalInterface.class.php +++ b/src/psm/Util/Module/ModalInterface.class.php @@ -30,7 +30,7 @@ namespace psm\Util\Module; interface ModalInterface { - public function __construct(\psm\Service\Template $tpl); + public function __construct(\Twig_Environment $twig); public function getModalID(); public function createHTML(); diff --git a/src/psm/Util/Module/Sidebar.class.php b/src/psm/Util/Module/Sidebar.class.php index 051e762d..7a52bac2 100644 --- a/src/psm/Util/Module/Sidebar.class.php +++ b/src/psm/Util/Module/Sidebar.class.php @@ -26,7 +26,6 @@ **/ namespace psm\Util\Module; -use psm\Service\Template; class Sidebar implements SidebarInterface { @@ -51,13 +50,13 @@ class Sidebar implements SidebarInterface { protected $subtitle; /** - * Template service - * @var \psm\Service\Template $tpl + * Twig environment + * @var \Twig_Environment $twig */ - protected $tpl; + protected $twig; - public function __construct(Template $tpl) { - $this->tpl = $tpl; + public function __construct(\Twig_Environment $twig) { + $this->twig = $twig; } /** @@ -73,7 +72,7 @@ class Sidebar implements SidebarInterface { /** * Set a custom subtitle (default is module subitle) * @param string $title - * @return \psm\Util\Moduke\Sidebar + * @return \psm\Util\Module\Sidebar */ public function setSubtitle($title) { $this->subtitle = $title; @@ -154,11 +153,11 @@ class Sidebar implements SidebarInterface { } public function createHTML() { - $tpl_id = 'main_sidebar_container'; - $this->tpl->newTemplate($tpl_id, 'main_sidebar.tpl.html'); - + $tpl_data = array( + 'subtitle' => $this->subtitle, + ); $types = array('dropdown', 'button', 'link'); - $items = array(); + $tpl_data['items'] = array(); // loop through all types and build their html foreach($types as $type) { @@ -166,37 +165,17 @@ class Sidebar implements SidebarInterface { // no items for this type continue; } - // retrieve template for this type once so we can use it in the loop - $tpl_id_type = 'main_sidebar_types_' . $type; - $this->tpl->newTemplate($tpl_id_type, 'main_sidebar.tpl.html'); - $html_type = $this->tpl->getTemplate($tpl_id_type); // build html for each individual item foreach($this->items[$type] as $id => $item) { - $html_item = $html_type; - - if(isset($item['options'])) { - $item['options'] = $this->tpl->addTemplateDataRepeat($html_item, 'options', $item['options'], true); - - } - $html_item = $this->tpl->addTemplateData($html_type, $item, true); - - $items[] = array( - 'html_item' => $html_item, - 'class_active' => ($id === $this->active_id) ? 'active' : '', - ); + $item['type'] = $type; + $item['class_active'] = ($id === $this->active_id) ? 'active' : ''; + $tpl_data['items'][] = $item; } } - if(!empty($items)) { - $this->tpl->addTemplateDataRepeat($tpl_id, 'items', $items); - } - if($this->subtitle !== null) { - $this->tpl->addTemplateData($tpl_id, array( - 'subtitle' => $this->subtitle, - )); - } - $html = $this->tpl->getTemplate($tpl_id); + $tpl = $this->twig->loadTemplate('util/module/sidebar.tpl.html'); + $html = $tpl->render($tpl_data); return $html; } diff --git a/src/psm/Util/Module/SidebarInterface.class.php b/src/psm/Util/Module/SidebarInterface.class.php index 24f791ea..e388eae0 100644 --- a/src/psm/Util/Module/SidebarInterface.class.php +++ b/src/psm/Util/Module/SidebarInterface.class.php @@ -29,7 +29,7 @@ namespace psm\Util\Module; interface SidebarInterface { - public function __construct(\psm\Service\Template $tpl); + public function __construct(\Twig_Environment $twig); public function createHTML(); diff --git a/src/psm/Util/Server/HistoryGraph.class.php b/src/psm/Util/Server/HistoryGraph.class.php index 2ee728ad..195cffdf 100644 --- a/src/psm/Util/Server/HistoryGraph.class.php +++ b/src/psm/Util/Server/HistoryGraph.class.php @@ -28,7 +28,6 @@ namespace psm\Util\Server; use psm\Service\Database; -use psm\Service\Template; /** * History util, create HTML for server graphs @@ -42,14 +41,14 @@ class HistoryGraph { protected $db; /** - * Template service - * @var \psm\Service\Template $tpl + * Twig environment + * @var \Twig_Environment $twig */ - protected $tpl; + protected $twig; - function __construct(Database $db, Template $tpl) { + function __construct(Database $db, \Twig_Environment $twig) { $this->db = $db; - $this->tpl = $tpl; + $this->twig = $twig; } /** @@ -57,9 +56,6 @@ class HistoryGraph { * @return string */ public function createHTML($server_id) { - $tpl_id = 'server_history'; - $this->tpl->newTemplate($tpl_id, 'server/history.tpl.html'); - $graphs = array( 0 => $this->generateGraphUptime($server_id), 1 => $this->generateGraphHistory($server_id), @@ -84,20 +80,16 @@ class HistoryGraph { } } - $this->tpl->addTemplateDataRepeat($tpl_id, 'graphs', $graphs); - - $this->tpl->addTemplateData( - $tpl_id, - array( - 'label_server' => psm_get_lang('servers', 'server'), - 'day_format' => psm_get_lang('servers', 'chart_day_format'), - 'long_date_format' => psm_get_lang('servers', 'chart_long_date_format'), - 'short_date_format' => psm_get_lang('servers', 'chart_short_date_format'), - 'short_time_format' => psm_get_lang('servers', 'chart_short_time_format'), - ) + $tpl_data = array( + 'graphs' => $graphs, + 'label_server' => psm_get_lang('servers', 'server'), + 'day_format' => psm_get_lang('servers', 'chart_day_format'), + 'long_date_format' => psm_get_lang('servers', 'chart_long_date_format'), + 'short_date_format' => psm_get_lang('servers', 'chart_short_date_format'), + 'short_time_format' => psm_get_lang('servers', 'chart_short_time_format'), ); - return $this->tpl->getTemplate($tpl_id); + return $this->twig->render('module/server/history.tpl.html', $tpl_data); } /** diff --git a/src/templates/default/main/body.tpl.html b/src/templates/default/main/body.tpl.html new file mode 100644 index 00000000..95a14490 --- /dev/null +++ b/src/templates/default/main/body.tpl.html @@ -0,0 +1,79 @@ +{% block header %} + + + + + {{ title }} + + + + + + {% if auto_refresh %} + + {% endif %} + + + + + + + + + + + + +{% endblock %} + + + + + + {{ html_modal|raw }} + +
+ +
+ {{ html_sidebar|raw }} +
+
+ {% for msg in messages %} +
+

+

{{ msg.message }}

+
+ {% endfor %} +
+ {{ html_content|raw }} +
+
+ {% if add_footer %} + {% block footer %} + + {% endblock %} + {% endif %} +
+ + + \ No newline at end of file diff --git a/src/templates/default/main/menu.tpl.html b/src/templates/default/main/menu.tpl.html new file mode 100644 index 00000000..7ffeba0c --- /dev/null +++ b/src/templates/default/main/menu.tpl.html @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/src/templates/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html similarity index 50% rename from src/templates/config/config.tpl.html rename to src/templates/default/module/config/config.tpl.html index d9f3b1d5..35d84325 100644 --- a/src/templates/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -1,215 +1,212 @@ - -
+
-
+
- {label_general} + {{ label_general }}
- +
- +
- +
-  {label_seconds} -

{label_auto_refresh_servers}

+  {{ label_seconds }} +

{{ label_auto_refresh_servers|raw }}

- {label_settings_notification} + {{ label_settings_notification }}
- +
-

{label_alert_type_description}

+

{{ label_alert_type_description|raw }}

- {label_settings_log} + {{ label_settings_log }}
- -

{label_log_status_description}

+ +

{{ label_log_status_description|raw }}

- +
-
+ -
+
- {label_settings_sms} + {{ label_settings_sms }}
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
-
+
- {label_settings_pushover} + {{ label_settings_pushover }}
- -

{label_pushover_description}

+ +

{{ label_pushover_description|raw }}

- +
- +
- -

{label_pushover_api_token_description}

+ +

{{ label_pushover_api_token_description|raw }}

- +
- +
- - \ No newline at end of file + \ No newline at end of file diff --git a/src/templates/default/module/error/401.tpl.html b/src/templates/default/module/error/401.tpl.html new file mode 100644 index 00000000..0733878d --- /dev/null +++ b/src/templates/default/module/error/401.tpl.html @@ -0,0 +1,2 @@ +

{{ label_title }}

+

{{ label_description }}

\ No newline at end of file diff --git a/src/templates/default/module/install/config_new.tpl.html b/src/templates/default/module/install/config_new.tpl.html new file mode 100644 index 00000000..f7bc1712 --- /dev/null +++ b/src/templates/default/module/install/config_new.tpl.html @@ -0,0 +1,61 @@ +{% extends "module/install/main.tpl.html" %} +{% use "module/install/results.tpl.html" %} + +{% block install %} +
+
{{ block('results') }}
+
+
+
+
+

Please enter your database info:

+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+ {% if include_config_new_copy %} +
+

Your config file:

+
Unable to save your configuration.
+

Your database information is valid, however we are unable to create the configuration file automatically. + Please create a new file in the project directory called "config.php" and copy the information below.

+

After you have copied the configuration, press the button to continue.

+

+

+
+ {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/src/templates/default/module/install/config_new_user.tpl.html b/src/templates/default/module/install/config_new_user.tpl.html new file mode 100644 index 00000000..28bddbb1 --- /dev/null +++ b/src/templates/default/module/install/config_new_user.tpl.html @@ -0,0 +1,44 @@ +{% extends "module/install/main.tpl.html" %} +{% use "module/install/results.tpl.html" %} + +{% block install %} +

Sweet, your database connection is up and running!

+

Next, please set up a new account to access your monitor:

+{{ block('results') }} +

 

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/src/templates/default/module/install/config_upgrade.tpl.html b/src/templates/default/module/install/config_upgrade.tpl.html new file mode 100644 index 00000000..d233b515 --- /dev/null +++ b/src/templates/default/module/install/config_upgrade.tpl.html @@ -0,0 +1,9 @@ +{% extends "module/install/main.tpl.html" %} + +{% block install %} +

We have discovered a previous version.

+

In the next step we will upgrade your database to the latest version.

+{{ block('results') }} +

 

+

Upgrade to {{ version }}

+{% endblock %} \ No newline at end of file diff --git a/src/templates/default/module/install/index.tpl.html b/src/templates/default/module/install/index.tpl.html new file mode 100644 index 00000000..a3edb8e4 --- /dev/null +++ b/src/templates/default/module/install/index.tpl.html @@ -0,0 +1,15 @@ +{% extends "module/install/main.tpl.html" %} +{% use "module/install/results.tpl.html" %} + +{% block install %} +

Welcome to the installation of PHP Server Monitor. This page will guide you through the steps to install or upgrade your monitor.

+

Before we start, we need to verify your system meets the requirements. + If you see any errors in the list below, you may still continue, but PHP Server Monitor may not work correctly. + It is recommended you fix any errors before continuing. +

+{{ block('results') }} +

 

+

+ Let's go +

+{% endblock %} \ No newline at end of file diff --git a/src/templates/default/module/install/main.tpl.html b/src/templates/default/module/install/main.tpl.html new file mode 100644 index 00000000..f899b94e --- /dev/null +++ b/src/templates/default/module/install/main.tpl.html @@ -0,0 +1,5 @@ +
+

 PHP Server Monitor

+

 

+ {% block install %} {% endblock %} +
\ No newline at end of file diff --git a/src/templates/default/module/install/results.tpl.html b/src/templates/default/module/install/results.tpl.html new file mode 100644 index 00000000..6a4085b9 --- /dev/null +++ b/src/templates/default/module/install/results.tpl.html @@ -0,0 +1,10 @@ +{% block results %} +{% if messages %} + {% for msg in messages %} +
+

{{ msg.shortcode }}

+

{{ msg.message }}

+
+ {% endfor %} +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/src/templates/default/module/install/success.tpl.html b/src/templates/default/module/install/success.tpl.html new file mode 100644 index 00000000..0df73c09 --- /dev/null +++ b/src/templates/default/module/install/success.tpl.html @@ -0,0 +1,20 @@ +{% extends "module/install/main.tpl.html" %} +{% use "module/install/results.tpl.html" %} + +{% block install %} +
+
{{ block('results') }}
+
+
+
+

 

+

The installation is complete. Please check above if errors have occurred.
+If no errors have occurred, you are good to go.

+

+ Go to your monitor + PHP Server Monitor + Documentation +

+
+
+{% endblock %} \ No newline at end of file diff --git a/src/templates/server/history.tpl.html b/src/templates/default/module/server/history.tpl.html similarity index 56% rename from src/templates/server/history.tpl.html rename to src/templates/default/module/server/history.tpl.html index 47923532..7a2aeaab 100644 --- a/src/templates/server/history.tpl.html +++ b/src/templates/default/module/server/history.tpl.html @@ -1,4 +1,3 @@ - @@ -9,46 +8,48 @@
- +{% for graph in graphs %}
-
+
- -
  • {label}: {value}
  • - - +
    -
      {info}
    +
      + {% for record in graph.info %} +
    • {{ record.label }}: {{ record.value }}
    • + {% endfor %} +
    - - - - {buttons} + {% for button in graph.buttons %} + + {% endfor %}
     
    - -{graphs} -
    - \ No newline at end of file +{% endfor %} +
    \ No newline at end of file diff --git a/src/templates/default/module/server/log.tpl.html b/src/templates/default/module/server/log.tpl.html new file mode 100644 index 00000000..5ee80bb8 --- /dev/null +++ b/src/templates/default/module/server/log.tpl.html @@ -0,0 +1,60 @@ +
    + +
    + {% for tab in tabs %} +
    + + + + + + + {% if tab.has_users %} {% endif %} + + + + {% for entry in tab.entries %} + + + + + {% if tab.has_users %}{% endif %} + + {% endfor %} + {% if tab.no_logs %} + + + + {% endif %} + +
    {{ label_server }}{{ label_message }}{{ label_date }}{{ label_users }}
    +
    +
    +
    +  {{ entry.datetime_format }} +
    + {{ entry.server }} {{ entry.ip }} +
    +
    +
    +
    +
    +
    {{ entry.message|raw }}
    +
    +
    + {% if tab.has_users %}
    +
    +
    +
    {{ label_users }}: {{ entry.user_list|raw }}
    +
    +
    {% endif %} +
    {{ entry.message|raw }}{{ entry.datetime_format }}{{ entry.users|raw }}
    {{ label_no_logs }}
    +
    + {% endfor %} +
    +
    \ No newline at end of file diff --git a/src/templates/default/module/server/server/list.tpl.html b/src/templates/default/module/server/server/list.tpl.html new file mode 100644 index 00000000..9427ad9f --- /dev/null +++ b/src/templates/default/module/server/server/list.tpl.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + {% for server in servers %} + + + + + + + + + + + + + + {% endfor %} + +
     {{ label_label }}{{ label_domain }}{{ label_port }}{{ label_type }}{{ label_rtime }}{{ label_last_online }}{{ label_monitoring }}{{ label_action }}
    {{ server.ip_short|raw }}
    {{ server.ip|raw }}
    {{ server.port }}
    {{ server.type }}
    {{ server.rtime }} s
    {{ server.last_online }}
    +
    + + {% if user_level == 10 %} + + + {% endif %} +
    +
    +
    + +
    +   + {% if user_level == 10 %} + + + {% endif %} +
    +
    +
    +
    +
    {{ server.ip_short|raw }}
    +
    + +
    +
    +
    +
    +
    {{ label_rtime }}:  
    {{ server.rtime }} s
    +
    {{ label_last_online }}:  
    {{ server.last_online }}
    +
    +
    \ No newline at end of file diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html new file mode 100644 index 00000000..5dcd46d6 --- /dev/null +++ b/src/templates/default/module/server/server/update.tpl.html @@ -0,0 +1,106 @@ +
    +
    + {{ titlemode }} +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + s +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + + {{ label_go_back }} +
    +
    +
    \ No newline at end of file diff --git a/src/templates/default/module/server/server/view.tpl.html b/src/templates/default/module/server/server/view.tpl.html new file mode 100644 index 00000000..8b95c7f5 --- /dev/null +++ b/src/templates/default/module/server/server/view.tpl.html @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% if has_admin_actions %} + + + + + {% endif %} + +
    +
    + + +
    +
    {{ label_status }}: + + {{ status }} +  {{ error }} +
    {{ label_type }}:{{ type }}
    {{ label_domain }}:{{ ip|raw }}
    {{ label_port }}:{{ port }}
    {{ label_last_check }}:{{ last_check }}
    {{ label_last_online }}:{{ last_online }}
    {{ label_rtime }}:{{ rtime }} s
    {{ label_monitoring }}:{{ active }}
    {{ label_email }}:{{ email }}
    {{ label_sms }}:{{ sms }}
    {{ label_pushover }}:{{ pushover }}
    {{ label_timeout }}:{{ timeout }} s
      + +  {{ label_edit }} + + +  {{ label_delete }} + +
    +{{ html_history|raw }} \ No newline at end of file diff --git a/src/templates/default/module/server/status/header.tpl.html b/src/templates/default/module/server/status/header.tpl.html new file mode 100644 index 00000000..d6455f4a --- /dev/null +++ b/src/templates/default/module/server/status/header.tpl.html @@ -0,0 +1,4 @@ +
    + + +
    \ No newline at end of file diff --git a/src/templates/default/module/server/status/index.tpl.html b/src/templates/default/module/server/status/index.tpl.html new file mode 100644 index 00000000..4f579206 --- /dev/null +++ b/src/templates/default/module/server/status/index.tpl.html @@ -0,0 +1,60 @@ +
    +
    +
    + {% for server in servers_offline %} +
    +
    +

    {{ server.label }}

    +

    {{ label_last_online }}: {{ server.last_online_nice }}

    +

    {{ label_last_check }}: {{ server.last_checked_nice }}

    +
    +
    + {% endfor %} + {% for server in servers_online %} +
    +
    +

    {{ server.label }}

    +

    {{ label_last_online }}: {{ server.last_online_nice }}

    +

    {{ label_rtime }}: {{ server.rtime }}s

    +
    +
    + {% endfor %} +
    +
    +
    +
    + + + {% for server in servers_offline %} + + + + + + {% endfor %} + {% for server in servers_online %} + + + + + + {% endfor %} + +
    {{ server.label }}
    +
    +
    +
    {{ label_last_online }}:  
    {{ server.last_online_nice }}
    +
    {{ label_last_check }}:  
    {{ server.last_checked_nice }}
    +
    +
    +
    {{ label_last_online }}: {{ server.last_online_nice }}{{ label_last_check }}: {{ server.last_checked_nice }}
    {{ server.label }}
    +
    +
    +
    {{ label_last_online }}:  
    {{ server.last_online_nice }}
    +
    {{ label_rtime }}:  
    {{ server.rtime }}
    +
    +
    +
    {{ label_last_online }}: {{ server.last_online_nice }}{{ label_rtime }}: {{ server.rtime }}s
    +
    +
    +
    \ No newline at end of file diff --git a/src/templates/default/module/user/login/forgot.tpl.html b/src/templates/default/module/user/login/forgot.tpl.html new file mode 100644 index 00000000..5d669239 --- /dev/null +++ b/src/templates/default/module/user/login/forgot.tpl.html @@ -0,0 +1,8 @@ +
    + +
    \ No newline at end of file diff --git a/src/templates/default/module/user/login/login.tpl.html b/src/templates/default/module/user/login/login.tpl.html new file mode 100644 index 00000000..0bf89cd7 --- /dev/null +++ b/src/templates/default/module/user/login/login.tpl.html @@ -0,0 +1,13 @@ +
    + +
    \ No newline at end of file diff --git a/src/templates/default/module/user/login/reset.tpl.html b/src/templates/default/module/user/login/reset.tpl.html new file mode 100644 index 00000000..24151e6e --- /dev/null +++ b/src/templates/default/module/user/login/reset.tpl.html @@ -0,0 +1,10 @@ +
    + +
    \ No newline at end of file diff --git a/src/templates/default/module/user/profile.tpl.html b/src/templates/default/module/user/profile.tpl.html new file mode 100644 index 00000000..a848cfc8 --- /dev/null +++ b/src/templates/default/module/user/profile.tpl.html @@ -0,0 +1,72 @@ +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    + +
    {{ label_pushover_description|raw }}
    +
    +
    + +
    + +
    +
    +
    + +
    + +

    {{ label_pushover_device_description }}

    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    \ No newline at end of file diff --git a/src/templates/default/module/user/user/list.tpl.html b/src/templates/default/module/user/user/list.tpl.html new file mode 100644 index 00000000..7043b358 --- /dev/null +++ b/src/templates/default/module/user/user/list.tpl.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + {% for user in users %} + + + + + + + + + + {% endfor %} + +
    {{ label_user }}{{ label_name }}{{ label_level }}{{ label_email }}{{ label_mobile }}{{ label_servers }}{{ label_action }}
    +
    +
    + + + {% if user.level == '10' %} +   + {% elseif user.level == '20' %} +   + {% endif %} + + {{ user.user_name }} + + ({{ user.name }}) +
    +
    + +
    +
    +
    +
    +
    {{ label_email }}: 
    {{ user.email }}
    +
    {{ label_mobile }}: 
    {{ user.mobile }}
    +
    {{ label_servers }}: 
    {% for server in user.emp_servers %} {{ server.label }}
    {% endfor %}
    +
    +
    +
    {{ user.name }}
    {{ user.level_text }}
    {{ user.email }}
    {{ user.mobile }}
    {% for server in user.emp_servers %} {{ server.label }}
    {% endfor %}
    + + + + + + +
    \ No newline at end of file diff --git a/src/templates/default/module/user/user/update.tpl.html b/src/templates/default/module/user/user/update.tpl.html new file mode 100644 index 00000000..0164d988 --- /dev/null +++ b/src/templates/default/module/user/user/update.tpl.html @@ -0,0 +1,83 @@ +
    +
    + {{ titlemode }} +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +

    {{ label_level_description|raw }}

    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    {{ label_pushover_description|raw }}
    +
    +
    + +
    + +
    +
    +
    + +
    + +

    {{ label_pushover_device_description }}

    +
    +
    +
    + +
    + +
    +
    +
    + + +
    +
    +
    \ No newline at end of file diff --git a/src/templates/default/util/module/modal.tpl.html b/src/templates/default/util/module/modal.tpl.html new file mode 100644 index 00000000..56ee6eed --- /dev/null +++ b/src/templates/default/util/module/modal.tpl.html @@ -0,0 +1,14 @@ + diff --git a/src/templates/default/util/module/sidebar.tpl.html b/src/templates/default/util/module/sidebar.tpl.html new file mode 100644 index 00000000..0588d8c8 --- /dev/null +++ b/src/templates/default/util/module/sidebar.tpl.html @@ -0,0 +1,26 @@ + \ No newline at end of file diff --git a/src/templates/error/error.tpl.html b/src/templates/error/error.tpl.html deleted file mode 100644 index 2037f765..00000000 --- a/src/templates/error/error.tpl.html +++ /dev/null @@ -1,4 +0,0 @@ - -

    {label_title}

    -

    {label_description}

    - diff --git a/src/templates/install/install.tpl.html b/src/templates/install/install.tpl.html deleted file mode 100644 index c57e973b..00000000 --- a/src/templates/install/install.tpl.html +++ /dev/null @@ -1,160 +0,0 @@ - -
    -

     PHP Server Monitor

    -

     

    - {html_install} -
    - - - -

    Welcome to the installation of PHP Server Monitor. This page will guide you through the steps to install or upgrade your monitor.

    -

    Before we start, we need to verify your system meets the requirements. - If you see any errors in the list below, you may still continue, but PHP Server Monitor may not work correctly. - It is recommended you fix any errors before continuing. -

    -{html_results} -

     

    -

    - Let's go -

    - - - -

    We have discovered a previous version.

    -

    In the next step we will upgrade your database to the latest version.

    -{html_results} -

     

    -

    Upgrade to {version}

    - - - -

    Sweet, your database connection is up and running!

    -

    Next, please set up a new account to access your monitor:

    -{html_results} -

     

    -
    -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    -
    - -
    -
    -
    -
    -{html_config_copy} -
    - - - -
    -
    {html_results}
    -
    -
    -
    -
    -

    Please enter your database info:

    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    -
    - -
    -
    -
    -
    -{html_config_copy} -
    - - - -
    -

    Your config file:

    -
    Unable to save your configuration.
    -

    Your database information is valid, however we are unable to create the configuration file automatically. - Please create a new file in the project directory called "config.php" and copy the information below.

    -

    After you have copied the configuration, press the button to continue.

    -

    -

    -
    - - - -
    -
    {html_results}
    -
    -
    -
    -

     

    -

    The installation is complete. Please check above if errors have occurred.
    -If no errors have occurred, you are good to go.

    -

    - Go to your monitor - PHP Server Monitor - Twitter Bootstrap -

    -
    -
    - - - - -
    -

    {shortcode}

    -

    {message}

    -
    - -{resultmsgs} - \ No newline at end of file diff --git a/src/templates/main.tpl.html b/src/templates/main.tpl.html deleted file mode 100644 index 15924793..00000000 --- a/src/templates/main.tpl.html +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - {title} - - - - - - {auto_refresh} - - - - - - - - - - - - - - - - - - {html_modal} - -
    - -
    - {html_sidebar} -
    -
    - -
    -

    -

    {message}

    -
    - - {messages} -
    - {content} -
    -
    - {html_footer} -
    - - - - - - - - - - - - - - - - diff --git a/src/templates/main_modal.tpl.html b/src/templates/main_modal.tpl.html deleted file mode 100644 index 09251429..00000000 --- a/src/templates/main_modal.tpl.html +++ /dev/null @@ -1,14 +0,0 @@ - - - diff --git a/src/templates/main_sidebar.tpl.html b/src/templates/main_sidebar.tpl.html deleted file mode 100644 index db5b8f07..00000000 --- a/src/templates/main_sidebar.tpl.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - {label} - - - - - - -
    - - -
    - \ No newline at end of file diff --git a/src/templates/server/log.tpl.html b/src/templates/server/log.tpl.html deleted file mode 100644 index 3ae62bf1..00000000 --- a/src/templates/server/log.tpl.html +++ /dev/null @@ -1,75 +0,0 @@ - -
    - -
    -
    - {content_status} -
    -
    - {content_email} -
    -
    - {content_sms} -
    -
    - {content_pushover} -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - {entries} - - - - - - -
    {label_server}{label_message}{label_date}{label_users}
    -
    -
    -
    -  {datetime_format} -
    - {server} {ip} -
    -
    -
    -
    -
    -
    {message}
    -
    -
    -
    -
    -
    -
    {label_users}: {user_list}
    -
    -
    -
    {message}{datetime_format}{users}
    {label_no_logs}
    - \ No newline at end of file diff --git a/src/templates/server/server.tpl.html b/src/templates/server/server.tpl.html deleted file mode 100644 index 7a1b89cf..00000000 --- a/src/templates/server/server.tpl.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {servers} - -
     {label_label}{label_domain}{label_port}{label_type}{label_rtime}{label_last_online}{label_monitoring}{label_action}
    {ip_short}
    {ip}
    {port}
    {type}
    {rtime} s
    {last_online}
    -
    - - {html_actions} -
    -
    -
    - -
    -   - {html_actions} -
    -
    -
    -
    -
    {ip_short}
    -
    - -
    -
    -
    -
    -
    {label_rtime}:  
    {rtime} s
    -
    {label_last_online}:  
    {last_online}
    -
    -
    - - - - - - - - - - - - -
    -
    - {titlemode} -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - s -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - - {label_go_back} -
    -
    -
    - - - -

    - \ No newline at end of file diff --git a/src/templates/server/status.tpl.html b/src/templates/server/status.tpl.html deleted file mode 100644 index 14e92f01..00000000 --- a/src/templates/server/status.tpl.html +++ /dev/null @@ -1,73 +0,0 @@ - -
    -
    -
    - -
    -
    -

    {label}

    -

    {label_last_online}: {last_online_nice}

    -

    {label_last_check}: {last_checked_nice}

    -
    -
    - - {servers_offline} - -
    -
    -

    {label}

    -

    {label_last_online}: {last_online_nice}

    -

    {label_rtime}: {rtime}s

    -
    -
    - - {servers_online} -
    -
    -
    -
    - - - - - - - - - - {servers_offline2} - - - - - - - - {servers_online2} - -
    {label}
    -
    -
    -
    {label_last_online}:  
    {last_online_nice}
    -
    {label_last_check}:  
    {last_checked_nice}
    -
    -
    -
    {label_last_online}: {last_online_nice}{label_last_check}: {last_checked_nice}
    {label}
    -
    -
    -
    {label_last_online}:  
    {last_online_nice}
    -
    {label_rtime}:  
    {rtime}
    -
    -
    -
    {label_last_online}: {last_online_nice}{label_rtime}: {rtime}s
    -
    -
    -
    - - - -
    - - -
    - diff --git a/src/templates/server/view.tpl.html b/src/templates/server/view.tpl.html deleted file mode 100644 index 970dcf46..00000000 --- a/src/templates/server/view.tpl.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {html_actions} - -
    -
    - - -
    -
    {label_status}: - - {status} -  {error} -
    {label_type}:{type}
    {label_domain}:{ip}
    {label_port}:{port}
    {label_last_check}:{last_check}
    {label_last_online}:{last_online}
    {label_rtime}:{rtime} s
    {label_monitoring}:{active}
    {label_email}:{email}
    {label_sms}:{sms}
    {label_pushover}:{pushover}
    {label_timeout}:{timeout} s
    -{html_history} - - - - -   - - -  {label_edit} - - -  {label_delete} - - - - diff --git a/src/templates/user/login.tpl.html b/src/templates/user/login.tpl.html deleted file mode 100644 index d43ee9e3..00000000 --- a/src/templates/user/login.tpl.html +++ /dev/null @@ -1,39 +0,0 @@ - -
    - -
    - - - -
    - -
    - - - -
    - -
    - \ No newline at end of file diff --git a/src/templates/user/profile.tpl.html b/src/templates/user/profile.tpl.html deleted file mode 100644 index f504e4c0..00000000 --- a/src/templates/user/profile.tpl.html +++ /dev/null @@ -1,74 +0,0 @@ - -
    -
    -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    -
    -
    - -
    {label_pushover_description}
    -
    -
    - -
    - -
    -
    -
    - -
    - -

    {label_pushover_device_description}

    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    - \ No newline at end of file diff --git a/src/templates/user/user.tpl.html b/src/templates/user/user.tpl.html deleted file mode 100644 index 956c933d..00000000 --- a/src/templates/user/user.tpl.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - {users} - -
    {label_user}{label_name}{label_level}{label_email}{label_mobile}{label_servers}{label_action}
    -
    -
    - -   - {user_name} - - ({name}) -
    -
    - -
    -
    -
    -
    -
    {label_email}: 
    {email}
    -
    {label_mobile}: 
    {mobile}
    -
    {label_servers}: 
    {emp_servers}
    -
    -
    -
    {name}
    {label_level_{level}}
    {email}
    {mobile}
    {emp_servers}
    - - - - - - -
    - - - -
    -
    - {titlemode} -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -

    {label_level_description}

    -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    {label_pushover_description}
    -
    -
    - -
    - -
    -
    -
    - -
    - -

    {label_pushover_device_description}

    -
    -
    -
    - -
    - -
    -
    -
    - - -
    -
    -
    - \ No newline at end of file