@@ -27,24 +27,24 @@ |
||
| 27 | 27 | |
| 28 | 28 | class MailVerifyPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getContent(): string { |
|
| 31 | - $template = new DwooTemplate("pages/verifymail"); |
|
| 32 | - |
|
| 33 | - if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
| 34 | - $template->assign("no_token", false); |
|
| 35 | - |
|
| 36 | - //check token |
|
| 37 | - if (!Mail_Verification::checkToken($_REQUEST['token'])) { |
|
| 38 | - $template->assign("invalide_token", true); |
|
| 39 | - } else { |
|
| 40 | - $template->assign("invalide_token", false); |
|
| 41 | - } |
|
| 42 | - } else { |
|
| 43 | - $template->assign("no_token", true); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $template->getCode(); |
|
| 47 | - } |
|
| 30 | + public function getContent(): string { |
|
| 31 | + $template = new DwooTemplate("pages/verifymail"); |
|
| 32 | + |
|
| 33 | + if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
| 34 | + $template->assign("no_token", false); |
|
| 35 | + |
|
| 36 | + //check token |
|
| 37 | + if (!Mail_Verification::checkToken($_REQUEST['token'])) { |
|
| 38 | + $template->assign("invalide_token", true); |
|
| 39 | + } else { |
|
| 40 | + $template->assign("invalide_token", false); |
|
| 41 | + } |
|
| 42 | + } else { |
|
| 43 | + $template->assign("no_token", true); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $template->getCode(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -33,16 +33,16 @@ |
||
| 33 | 33 | |
| 34 | 34 | class PluginPLang extends Plugin implements ICompilable { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param Compiler $compiler |
|
| 38 | - * @param mixed $value |
|
| 39 | - * @param mixed $var |
|
| 40 | - * |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public static function compile(Compiler $compiler, $msg1, $msg2, $n, $domain = "") { |
|
| 44 | - return 'Translator::n_translate(' . $msg1 . ', ' . $msg2 . ', ' . $n . ', ' . $domain . ')'; |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * @param Compiler $compiler |
|
| 38 | + * @param mixed $value |
|
| 39 | + * @param mixed $var |
|
| 40 | + * |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public static function compile(Compiler $compiler, $msg1, $msg2, $n, $domain = "") { |
|
| 44 | + return 'Translator::n_translate(' . $msg1 . ', ' . $msg2 . ', ' . $n . ', ' . $domain . ')'; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
@@ -27,41 +27,41 @@ |
||
| 27 | 27 | |
| 28 | 28 | interface Translator_Backend { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * initialize translator backend |
|
| 32 | - * |
|
| 33 | - * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 34 | - */ |
|
| 35 | - public function init (string $lang_token); |
|
| 30 | + /** |
|
| 31 | + * initialize translator backend |
|
| 32 | + * |
|
| 33 | + * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 34 | + */ |
|
| 35 | + public function init (string $lang_token); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * translate a string |
|
| 39 | - * |
|
| 40 | - * @param string $key message to translate |
|
| 41 | - * @param string $domain domain where to search key (optional) |
|
| 42 | - * @param array $params array with params to replace in translated message |
|
| 43 | - * |
|
| 44 | - * @return string translated message |
|
| 45 | - */ |
|
| 46 | - public function translate (string $key, string $domain = "", $params = null) : string; |
|
| 37 | + /** |
|
| 38 | + * translate a string |
|
| 39 | + * |
|
| 40 | + * @param string $key message to translate |
|
| 41 | + * @param string $domain domain where to search key (optional) |
|
| 42 | + * @param array $params array with params to replace in translated message |
|
| 43 | + * |
|
| 44 | + * @return string translated message |
|
| 45 | + */ |
|
| 46 | + public function translate (string $key, string $domain = "", $params = null) : string; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * translate a string, plural version of translate() |
|
| 50 | - * |
|
| 51 | - * @see Translator_Backend::translate() |
|
| 52 | - * @since 0.1.0 |
|
| 53 | - * |
|
| 54 | - * @param string $key message to translate |
|
| 55 | - * @param string $domain domain where to search key (optional) |
|
| 56 | - * @param array $params array with params to replace in translated message |
|
| 57 | - * |
|
| 58 | - * @return string translated message |
|
| 59 | - */ |
|
| 60 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 48 | + /** |
|
| 49 | + * translate a string, plural version of translate() |
|
| 50 | + * |
|
| 51 | + * @see Translator_Backend::translate() |
|
| 52 | + * @since 0.1.0 |
|
| 53 | + * |
|
| 54 | + * @param string $key message to translate |
|
| 55 | + * @param string $domain domain where to search key (optional) |
|
| 56 | + * @param array $params array with params to replace in translated message |
|
| 57 | + * |
|
| 58 | + * @return string translated message |
|
| 59 | + */ |
|
| 60 | + public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 61 | 61 | |
| 62 | - public function bindLangPack (string $domain, string $path); |
|
| 62 | + public function bindLangPack (string $domain, string $path); |
|
| 63 | 63 | |
| 64 | - public function setDefaultDomain (string $domain); |
|
| 64 | + public function setDefaultDomain (string $domain); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param $lang_token $lang_token contains language & country, e.q. de_DE |
| 34 | 34 | */ |
| 35 | - public function init (string $lang_token); |
|
| 35 | + public function init(string $lang_token); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * translate a string |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string translated message |
| 45 | 45 | */ |
| 46 | - public function translate (string $key, string $domain = "", $params = null) : string; |
|
| 46 | + public function translate(string $key, string $domain = "", $params = null) : string; |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * translate a string, plural version of translate() |
@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return string translated message |
| 59 | 59 | */ |
| 60 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 60 | + public function n_translate(string $key, string $plural_key, int $n, string $domain = "", $params = null) : string; |
|
| 61 | 61 | |
| 62 | - public function bindLangPack (string $domain, string $path); |
|
| 62 | + public function bindLangPack(string $domain, string $path); |
|
| 63 | 63 | |
| 64 | - public function setDefaultDomain (string $domain); |
|
| 64 | + public function setDefaultDomain(string $domain); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -27,73 +27,73 @@ |
||
| 27 | 27 | |
| 28 | 28 | class GetTextBackend implements Translator_Backend { |
| 29 | 29 | |
| 30 | - //current language token |
|
| 31 | - protected $lang_token = ""; |
|
| 32 | - |
|
| 33 | - //current domain |
|
| 34 | - protected $domain = ""; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * initialize translator backend |
|
| 38 | - * |
|
| 39 | - * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 40 | - */ |
|
| 41 | - public function init(string $lang_token) { |
|
| 42 | - //check, if gettext is available |
|
| 43 | - if (!PHPUtils::isGettextAvailable()) { |
|
| 44 | - throw new IllegalStateException("PHP extension 'gettext' is not available."); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - putenv("LANG=" . $lang_token); |
|
| 48 | - setlocale(LC_ALL, $lang_token); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function translate(string $key, string $domain = "", $params = null): string { |
|
| 52 | - $text = ""; |
|
| 53 | - |
|
| 54 | - if (empty($domain)) { |
|
| 55 | - $text = gettext($key); |
|
| 56 | - } else { |
|
| 57 | - $text = dgettext($domain, $key); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if ($params != null && !empty($params)) { |
|
| 61 | - foreach ($params as $key=>$value) { |
|
| 62 | - //replace variables |
|
| 63 | - $text = str_replace("{" . $key . "}", $value, $text); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $text; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 71 | - $text = ""; |
|
| 72 | - |
|
| 73 | - if (empty($domain)) { |
|
| 74 | - $text = ngettext($key, $plural_key, $n); |
|
| 75 | - } else { |
|
| 76 | - $text = dngettext($domain, $key, $plural_key, $n); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($params != null && !empty($params)) { |
|
| 80 | - foreach ($params as $key=>$value) { |
|
| 81 | - //replace variables |
|
| 82 | - $text = str_replace("{" . $key . "}", $value, $text); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $text; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function bindLangPack(string $domain, string $path) { |
|
| 90 | - bindtextdomain($domain, $path); |
|
| 91 | - bind_textdomain_codeset($domain, 'UTF-8'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function setDefaultDomain(string $domain) { |
|
| 95 | - textdomain($domain); |
|
| 96 | - } |
|
| 30 | + //current language token |
|
| 31 | + protected $lang_token = ""; |
|
| 32 | + |
|
| 33 | + //current domain |
|
| 34 | + protected $domain = ""; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * initialize translator backend |
|
| 38 | + * |
|
| 39 | + * @param $lang_token $lang_token contains language & country, e.q. de_DE |
|
| 40 | + */ |
|
| 41 | + public function init(string $lang_token) { |
|
| 42 | + //check, if gettext is available |
|
| 43 | + if (!PHPUtils::isGettextAvailable()) { |
|
| 44 | + throw new IllegalStateException("PHP extension 'gettext' is not available."); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + putenv("LANG=" . $lang_token); |
|
| 48 | + setlocale(LC_ALL, $lang_token); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function translate(string $key, string $domain = "", $params = null): string { |
|
| 52 | + $text = ""; |
|
| 53 | + |
|
| 54 | + if (empty($domain)) { |
|
| 55 | + $text = gettext($key); |
|
| 56 | + } else { |
|
| 57 | + $text = dgettext($domain, $key); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if ($params != null && !empty($params)) { |
|
| 61 | + foreach ($params as $key=>$value) { |
|
| 62 | + //replace variables |
|
| 63 | + $text = str_replace("{" . $key . "}", $value, $text); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $text; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 71 | + $text = ""; |
|
| 72 | + |
|
| 73 | + if (empty($domain)) { |
|
| 74 | + $text = ngettext($key, $plural_key, $n); |
|
| 75 | + } else { |
|
| 76 | + $text = dngettext($domain, $key, $plural_key, $n); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($params != null && !empty($params)) { |
|
| 80 | + foreach ($params as $key=>$value) { |
|
| 81 | + //replace variables |
|
| 82 | + $text = str_replace("{" . $key . "}", $value, $text); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $text; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function bindLangPack(string $domain, string $path) { |
|
| 90 | + bindtextdomain($domain, $path); |
|
| 91 | + bind_textdomain_codeset($domain, 'UTF-8'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function setDefaultDomain(string $domain) { |
|
| 95 | + textdomain($domain); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | ?> |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | return $text; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 70 | + public function n_translate(string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 71 | 71 | $text = ""; |
| 72 | 72 | |
| 73 | 73 | if (empty($domain)) { |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class PHPInfoPage extends PageType { |
| 29 | 29 | |
| 30 | - public function getContent(): string { |
|
| 31 | - if (isset($_REQUEST['no_design'])) { |
|
| 32 | - phpinfo(); |
|
| 33 | - exit; |
|
| 34 | - } else { |
|
| 35 | - /*$content = ""; |
|
| 30 | + public function getContent(): string { |
|
| 31 | + if (isset($_REQUEST['no_design'])) { |
|
| 32 | + phpinfo(); |
|
| 33 | + exit; |
|
| 34 | + } else { |
|
| 35 | + /*$content = ""; |
|
| 36 | 36 | |
| 37 | 37 | ob_start(); |
| 38 | 38 | phpinfo(); |
@@ -41,25 +41,25 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | return $content;*/ |
| 43 | 43 | |
| 44 | - //https://github.com/Froxlor/Froxlor/blob/5437fcdc898cb505348b89c5a3d09a16e29f67d2/admin_settings.php |
|
| 44 | + //https://github.com/Froxlor/Froxlor/blob/5437fcdc898cb505348b89c5a3d09a16e29f67d2/admin_settings.php |
|
| 45 | 45 | |
| 46 | - //show iframe |
|
| 47 | - return $this->generateNormalPage(" <iframe src=\"" . DomainUtils::generateURL("admin/phpinfo") . "?no_design=true\" style=\"width: 100%; min-height: 800px; \"></iframe> "); |
|
| 48 | - } |
|
| 49 | - } |
|
| 46 | + //show iframe |
|
| 47 | + return $this->generateNormalPage(" <iframe src=\"" . DomainUtils::generateURL("admin/phpinfo") . "?no_design=true\" style=\"width: 100%; min-height: 800px; \"></iframe> "); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function setCustomHeader() { |
|
| 52 | - //allow iframe |
|
| 53 | - header('X-Frame-Options: SAMEORIGIN'); |
|
| 54 | - } |
|
| 51 | + public function setCustomHeader() { |
|
| 52 | + //allow iframe |
|
| 53 | + header('X-Frame-Options: SAMEORIGIN'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function showDesign() { |
|
| 57 | - return !isset($_REQUEST['no_design']); |
|
| 58 | - } |
|
| 56 | + public function showDesign() { |
|
| 57 | + return !isset($_REQUEST['no_design']); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function listRequiredPermissions(): array { |
|
| 61 | - return array("can_see_phpinfo"); |
|
| 62 | - } |
|
| 60 | + public function listRequiredPermissions(): array { |
|
| 61 | + return array("can_see_phpinfo"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -27,96 +27,96 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Translator { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - protected static $backend = null; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * translate a string |
|
| 37 | - * |
|
| 38 | - * @param string $key message to translate |
|
| 39 | - * @param string $domain domain where to search key (optional) |
|
| 40 | - * @param array $params array with params to replace in translated message |
|
| 41 | - * |
|
| 42 | - * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 43 | - * @see Translator_Backend::translate() |
|
| 44 | - * @since 0.1.0 |
|
| 45 | - * |
|
| 46 | - * @return string translated message |
|
| 47 | - */ |
|
| 48 | - public static function translate (string $key, string $domain = "", $params = null) : string { |
|
| 49 | - return self::getBackend()->translate($key, $domain, $params); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * translate a string, plural version of translate() |
|
| 54 | - * |
|
| 55 | - * @param string $key message to translate |
|
| 56 | - * @param string $domain domain where to search key (optional) |
|
| 57 | - * @param array $params array with params to replace in translated message |
|
| 58 | - * |
|
| 59 | - * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 60 | - * @see Translator_Backend::n_translate() |
|
| 61 | - * @since 0.1.0 |
|
| 62 | - * |
|
| 63 | - * @return string translated message |
|
| 64 | - */ |
|
| 65 | - public static function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 66 | - return self::getBackend()->n_translate($key, $plural_key, $n, $domain, $params); |
|
| 67 | - } |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + protected static $backend = null; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * translate a string |
|
| 37 | + * |
|
| 38 | + * @param string $key message to translate |
|
| 39 | + * @param string $domain domain where to search key (optional) |
|
| 40 | + * @param array $params array with params to replace in translated message |
|
| 41 | + * |
|
| 42 | + * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 43 | + * @see Translator_Backend::translate() |
|
| 44 | + * @since 0.1.0 |
|
| 45 | + * |
|
| 46 | + * @return string translated message |
|
| 47 | + */ |
|
| 48 | + public static function translate (string $key, string $domain = "", $params = null) : string { |
|
| 49 | + return self::getBackend()->translate($key, $domain, $params); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * translate a string, plural version of translate() |
|
| 54 | + * |
|
| 55 | + * @param string $key message to translate |
|
| 56 | + * @param string $domain domain where to search key (optional) |
|
| 57 | + * @param array $params array with params to replace in translated message |
|
| 58 | + * |
|
| 59 | + * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 60 | + * @see Translator_Backend::n_translate() |
|
| 61 | + * @since 0.1.0 |
|
| 62 | + * |
|
| 63 | + * @return string translated message |
|
| 64 | + */ |
|
| 65 | + public static function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 66 | + return self::getBackend()->n_translate($key, $plural_key, $n, $domain, $params); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public static function translateTitle (string $token) { |
|
| 70 | - //translate title |
|
| 71 | - if (strpos($token, "lang_") !== FALSE) { |
|
| 72 | - $array1 = explode("_", $token); |
|
| 73 | - |
|
| 74 | - if (count($array1) == 2) { |
|
| 75 | - //translate |
|
| 76 | - $token = Translator::translate($array1[1]); |
|
| 77 | - } else if (count($array1) == 3) { |
|
| 78 | - //translate with domain |
|
| 79 | - $token = Translator::translate($array1[2], $array1[1]); |
|
| 80 | - } else if (count($array1) > 3) { |
|
| 81 | - $token_parts = array(); |
|
| 82 | - |
|
| 83 | - for ($i = 2; $i < count($array1); $i++) { |
|
| 84 | - $token_parts[] = $array1[$i]; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - //generate final token |
|
| 88 | - $token = implode("_", $token_parts); |
|
| 89 | - |
|
| 90 | - //translate with domain |
|
| 91 | - $token = Translator::translate($token, $array1[1]); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $token; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * get current instance of translator backend |
|
| 100 | - * |
|
| 101 | - * @see GetTextBackend |
|
| 102 | - * |
|
| 103 | - * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 104 | - * |
|
| 105 | - * @return Translator_Backend instance of translator backend |
|
| 106 | - */ |
|
| 107 | - public static function &getBackend () : Translator_Backend { |
|
| 108 | - if (self::$backend == null) { |
|
| 109 | - //get translator backend |
|
| 110 | - $class_name = Settings::get("translator_class_name", "GetTextBackend"); |
|
| 111 | - |
|
| 112 | - self::$backend = new $class_name(); |
|
| 113 | - |
|
| 114 | - //initialize backend with current language |
|
| 115 | - self::$backend->init(Registry::singleton()->getSetting("lang_token")); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return self::$backend; |
|
| 119 | - } |
|
| 69 | + public static function translateTitle (string $token) { |
|
| 70 | + //translate title |
|
| 71 | + if (strpos($token, "lang_") !== FALSE) { |
|
| 72 | + $array1 = explode("_", $token); |
|
| 73 | + |
|
| 74 | + if (count($array1) == 2) { |
|
| 75 | + //translate |
|
| 76 | + $token = Translator::translate($array1[1]); |
|
| 77 | + } else if (count($array1) == 3) { |
|
| 78 | + //translate with domain |
|
| 79 | + $token = Translator::translate($array1[2], $array1[1]); |
|
| 80 | + } else if (count($array1) > 3) { |
|
| 81 | + $token_parts = array(); |
|
| 82 | + |
|
| 83 | + for ($i = 2; $i < count($array1); $i++) { |
|
| 84 | + $token_parts[] = $array1[$i]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //generate final token |
|
| 88 | + $token = implode("_", $token_parts); |
|
| 89 | + |
|
| 90 | + //translate with domain |
|
| 91 | + $token = Translator::translate($token, $array1[1]); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $token; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * get current instance of translator backend |
|
| 100 | + * |
|
| 101 | + * @see GetTextBackend |
|
| 102 | + * |
|
| 103 | + * @throws IllegalStateException if settings key "translator_class_name" is not set |
|
| 104 | + * |
|
| 105 | + * @return Translator_Backend instance of translator backend |
|
| 106 | + */ |
|
| 107 | + public static function &getBackend () : Translator_Backend { |
|
| 108 | + if (self::$backend == null) { |
|
| 109 | + //get translator backend |
|
| 110 | + $class_name = Settings::get("translator_class_name", "GetTextBackend"); |
|
| 111 | + |
|
| 112 | + self::$backend = new $class_name(); |
|
| 113 | + |
|
| 114 | + //initialize backend with current language |
|
| 115 | + self::$backend->init(Registry::singleton()->getSetting("lang_token")); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return self::$backend; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string translated message |
| 47 | 47 | */ |
| 48 | - public static function translate (string $key, string $domain = "", $params = null) : string { |
|
| 48 | + public static function translate(string $key, string $domain = "", $params = null) : string { |
|
| 49 | 49 | return self::getBackend()->translate($key, $domain, $params); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return string translated message |
| 64 | 64 | */ |
| 65 | - public static function n_translate (string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 65 | + public static function n_translate(string $key, string $plural_key, int $n, string $domain = "", $params = null) : string { |
|
| 66 | 66 | return self::getBackend()->n_translate($key, $plural_key, $n, $domain, $params); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public static function translateTitle (string $token) { |
|
| 69 | + public static function translateTitle(string $token) { |
|
| 70 | 70 | //translate title |
| 71 | 71 | if (strpos($token, "lang_") !== FALSE) { |
| 72 | 72 | $array1 = explode("_", $token); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return Translator_Backend instance of translator backend |
| 106 | 106 | */ |
| 107 | - public static function &getBackend () : Translator_Backend { |
|
| 107 | + public static function &getBackend() : Translator_Backend { |
|
| 108 | 108 | if (self::$backend == null) { |
| 109 | 109 | //get translator backend |
| 110 | 110 | $class_name = Settings::get("translator_class_name", "GetTextBackend"); |
@@ -32,64 +32,64 @@ |
||
| 32 | 32 | |
| 33 | 33 | class PluginLang extends Plugin implements ICompilableBlock { |
| 34 | 34 | |
| 35 | - protected static $domain = ""; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param Compiler $compiler |
|
| 39 | - * @param mixed $value |
|
| 40 | - * @param mixed $var |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - /*public static function compile(Compiler $compiler, $value, $domain = "") { |
|
| 35 | + protected static $domain = ""; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param Compiler $compiler |
|
| 39 | + * @param mixed $value |
|
| 40 | + * @param mixed $var |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + /*public static function compile(Compiler $compiler, $value, $domain = "") { |
|
| 45 | 45 | return 'Translator::translate(' . $value . ', ' . $domain . ')'; |
| 46 | 46 | }*/ |
| 47 | 47 | |
| 48 | - // parameters go here if you need any settings |
|
| 49 | - public function init() { |
|
| 50 | - // |
|
| 51 | - } |
|
| 48 | + // parameters go here if you need any settings |
|
| 49 | + public function init() { |
|
| 50 | + // |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // this can be ommitted, it's called once when the block ends, don't implement if you don't need it |
|
| 54 | - public function end() { |
|
| 55 | - // |
|
| 56 | - } |
|
| 53 | + // this can be ommitted, it's called once when the block ends, don't implement if you don't need it |
|
| 54 | + public function end() { |
|
| 55 | + // |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - // this is called when the block is required to output it's data, it should read $this->buffer, process it and return it |
|
| 59 | - /*public function process(){ |
|
| 58 | + // this is called when the block is required to output it's data, it should read $this->buffer, process it and return it |
|
| 59 | + /*public function process(){ |
|
| 60 | 60 | var_dump($this->buffer); |
| 61 | 61 | |
| 62 | 62 | return strtoupper($this->buffer); |
| 63 | 63 | }*/ |
| 64 | 64 | |
| 65 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { |
|
| 66 | - $domain = ""; |
|
| 65 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { |
|
| 66 | + $domain = ""; |
|
| 67 | 67 | |
| 68 | - /*if (isset($params[1])) { |
|
| 68 | + /*if (isset($params[1])) { |
|
| 69 | 69 | $domain = $params[1][1]; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return Compiler::PHP_OPEN . $prepend . " echo Translator::translate(\"" . $params[0][1] . "\", \"" . $domain . "\"); " . $append . Compiler::PHP_CLOSE;*/ |
| 73 | 73 | |
| 74 | - if (isset($params[0])) { |
|
| 75 | - $domain = $params[0][1]; |
|
| 76 | - } |
|
| 74 | + if (isset($params[0])) { |
|
| 75 | + $domain = $params[0][1]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - self::$domain = $domain; |
|
| 78 | + self::$domain = $domain; |
|
| 79 | 79 | |
| 80 | - return Compiler::PHP_OPEN . "echo Translator::translate(\""; |
|
| 81 | - } |
|
| 80 | + return Compiler::PHP_OPEN . "echo Translator::translate(\""; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { |
|
| 84 | - /** |
|
| 85 | - * the block is responsible for outputting it's entire content (passed as $content), |
|
| 86 | - * so you can transform it and then return it, but in this case we don't because |
|
| 87 | - * we want the content to be uppercased at runtime and not at compile time |
|
| 88 | - */ |
|
| 89 | - //return $content . Compiler::PHP_OPEN . $prepend . ' ' . $append . Compiler::PHP_CLOSE; |
|
| 83 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { |
|
| 84 | + /** |
|
| 85 | + * the block is responsible for outputting it's entire content (passed as $content), |
|
| 86 | + * so you can transform it and then return it, but in this case we don't because |
|
| 87 | + * we want the content to be uppercased at runtime and not at compile time |
|
| 88 | + */ |
|
| 89 | + //return $content . Compiler::PHP_OPEN . $prepend . ' ' . $append . Compiler::PHP_CLOSE; |
|
| 90 | 90 | |
| 91 | - return $content . "\", \"" . self::$domain . "\"); " . Compiler::PHP_CLOSE; |
|
| 92 | - } |
|
| 91 | + return $content . "\", \"" . self::$domain . "\"); " . Compiler::PHP_CLOSE; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | |
@@ -27,155 +27,155 @@ |
||
| 27 | 27 | |
| 28 | 28 | class DwooTemplate extends Template { |
| 29 | 29 | |
| 30 | - protected static $core = null; |
|
| 30 | + protected static $core = null; |
|
| 31 | 31 | |
| 32 | - protected static $files = array(); |
|
| 32 | + protected static $files = array(); |
|
| 33 | 33 | |
| 34 | - protected static $benchmark = array(); |
|
| 34 | + protected static $benchmark = array(); |
|
| 35 | 35 | |
| 36 | - //variables |
|
| 37 | - //protected $vars = array(); |
|
| 38 | - protected $data = null; |
|
| 36 | + //variables |
|
| 37 | + //protected $vars = array(); |
|
| 38 | + protected $data = null; |
|
| 39 | 39 | |
| 40 | - protected $file = ""; |
|
| 41 | - protected $template = null; |
|
| 40 | + protected $file = ""; |
|
| 41 | + protected $template = null; |
|
| 42 | 42 | |
| 43 | - public function __construct($file, Registry $registry = null) { |
|
| 44 | - if ($registry == null) { |
|
| 45 | - $registry = Registry::singleton(); |
|
| 46 | - } |
|
| 43 | + public function __construct($file, Registry $registry = null) { |
|
| 44 | + if ($registry == null) { |
|
| 45 | + $registry = Registry::singleton(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - //initialize core if neccessary |
|
| 49 | - self::initCoreIfAbsent(); |
|
| 48 | + //initialize core if neccessary |
|
| 49 | + self::initCoreIfAbsent(); |
|
| 50 | 50 | |
| 51 | - $start_time = microtime(true); |
|
| 51 | + $start_time = microtime(true); |
|
| 52 | 52 | |
| 53 | - //find file |
|
| 54 | - $this->file = Template::findTemplate($file, $registry); |
|
| 53 | + //find file |
|
| 54 | + $this->file = Template::findTemplate($file, $registry); |
|
| 55 | 55 | |
| 56 | - //load a template file, this is reusable if you want to render multiple times the same template with different data |
|
| 57 | - if (isset(self::$files[$file])) { |
|
| 58 | - $this->template = self::$files[$this->file]; |
|
| 59 | - } else { |
|
| 60 | - $this->template = new Dwoo\Template\File($this->file); |
|
| 61 | - self::$files[$file] = $this->template; |
|
| 62 | - } |
|
| 56 | + //load a template file, this is reusable if you want to render multiple times the same template with different data |
|
| 57 | + if (isset(self::$files[$file])) { |
|
| 58 | + $this->template = self::$files[$this->file]; |
|
| 59 | + } else { |
|
| 60 | + $this->template = new Dwoo\Template\File($this->file); |
|
| 61 | + self::$files[$file] = $this->template; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //create a data set, this data set can be reused to render multiple templates if it contains enough data to fill them all |
|
| 65 | - $this->data = new Dwoo\Data(); |
|
| 64 | + //create a data set, this data set can be reused to render multiple templates if it contains enough data to fill them all |
|
| 65 | + $this->data = new Dwoo\Data(); |
|
| 66 | 66 | |
| 67 | - //set default values |
|
| 68 | - $this->assign("REGISTRY", $registry->listSettings()); |
|
| 67 | + //set default values |
|
| 68 | + $this->assign("REGISTRY", $registry->listSettings()); |
|
| 69 | 69 | |
| 70 | - //set CSRF token |
|
| 71 | - $this->assign("CSRF_TOKEN", Security::getCSRFToken()); |
|
| 70 | + //set CSRF token |
|
| 71 | + $this->assign("CSRF_TOKEN", Security::getCSRFToken()); |
|
| 72 | 72 | |
| 73 | - //set domain, current page and so on |
|
| 74 | - $this->assign("DOMAIN", DomainUtils::getCurrentDomain()); |
|
| 75 | - $this->assign("BASE_URL", DomainUtils::getBaseURL()); |
|
| 76 | - $this->assign("CURRENT_URL", DomainUtils::getURL()); |
|
| 77 | - $this->assign("FOLDER", $registry->getSetting("folder")); |
|
| 73 | + //set domain, current page and so on |
|
| 74 | + $this->assign("DOMAIN", DomainUtils::getCurrentDomain()); |
|
| 75 | + $this->assign("BASE_URL", DomainUtils::getBaseURL()); |
|
| 76 | + $this->assign("CURRENT_URL", DomainUtils::getURL()); |
|
| 77 | + $this->assign("FOLDER", $registry->getSetting("folder")); |
|
| 78 | 78 | |
| 79 | - //set language settings |
|
| 80 | - $this->assign("PREF_LANG", $registry->getSetting("pref_lang")); |
|
| 81 | - $this->assign("LANG_TOKEN", $registry->getSetting("lang_token")); |
|
| 79 | + //set language settings |
|
| 80 | + $this->assign("PREF_LANG", $registry->getSetting("pref_lang")); |
|
| 81 | + $this->assign("LANG_TOKEN", $registry->getSetting("lang_token")); |
|
| 82 | 82 | |
| 83 | - $domain = $registry->getObject("domain"); |
|
| 84 | - $this->assign("HOME_PAGE", $domain->getHomePage()); |
|
| 85 | - $this->assign("LOGIN_PAGE", Settings::get("login_page", "login")); |
|
| 86 | - $this->assign("LOGIN_URL", $registry->getSetting("login_url")); |
|
| 87 | - $this->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout")); |
|
| 88 | - $this->assign("LOGOUT_URL", $registry->getSetting("logout_url")); |
|
| 83 | + $domain = $registry->getObject("domain"); |
|
| 84 | + $this->assign("HOME_PAGE", $domain->getHomePage()); |
|
| 85 | + $this->assign("LOGIN_PAGE", Settings::get("login_page", "login")); |
|
| 86 | + $this->assign("LOGIN_URL", $registry->getSetting("login_url")); |
|
| 87 | + $this->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout")); |
|
| 88 | + $this->assign("LOGOUT_URL", $registry->getSetting("logout_url")); |
|
| 89 | 89 | |
| 90 | - //set user variables |
|
| 91 | - $this->assign("USERID", User::current()->getID()); |
|
| 92 | - $this->assign("USERNAME", User::current()->getUsername()); |
|
| 90 | + //set user variables |
|
| 91 | + $this->assign("USERID", User::current()->getID()); |
|
| 92 | + $this->assign("USERNAME", User::current()->getUsername()); |
|
| 93 | 93 | |
| 94 | - $style_name = $registry->getSetting("current_style_name"); |
|
| 95 | - $this->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
| 94 | + $style_name = $registry->getSetting("current_style_name"); |
|
| 95 | + $this->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
| 96 | 96 | |
| 97 | - $end_time = microtime(true); |
|
| 98 | - $exec_time = $end_time - $start_time; |
|
| 97 | + $end_time = microtime(true); |
|
| 98 | + $exec_time = $end_time - $start_time; |
|
| 99 | 99 | |
| 100 | - //store benchmark |
|
| 101 | - self::$benchmark[$this->file] = $exec_time; |
|
| 102 | - } |
|
| 100 | + //store benchmark |
|
| 101 | + self::$benchmark[$this->file] = $exec_time; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function assign ($var, $value) { |
|
| 105 | - //$this->vars[$var] = $value; |
|
| 106 | - $this->data->assign($var, $value); |
|
| 107 | - } |
|
| 104 | + public function assign ($var, $value) { |
|
| 105 | + //$this->vars[$var] = $value; |
|
| 106 | + $this->data->assign($var, $value); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public function parse ($name = "main") { |
|
| 110 | - throw new Exception("Method DwooTemplate::parse() is not supported from Dwoo template engine."); |
|
| 111 | - } |
|
| 109 | + public function parse ($name = "main") { |
|
| 110 | + throw new Exception("Method DwooTemplate::parse() is not supported from Dwoo template engine."); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public function getCode ($name = "main") { |
|
| 114 | - $start_time = microtime(true); |
|
| 113 | + public function getCode ($name = "main") { |
|
| 114 | + $start_time = microtime(true); |
|
| 115 | 115 | |
| 116 | - // Output the result |
|
| 117 | - $html = self::$core->get($this->template, $this->data); |
|
| 116 | + // Output the result |
|
| 117 | + $html = self::$core->get($this->template, $this->data); |
|
| 118 | 118 | |
| 119 | - $end_time = microtime(true); |
|
| 120 | - $exec_time = $end_time - $start_time; |
|
| 119 | + $end_time = microtime(true); |
|
| 120 | + $exec_time = $end_time - $start_time; |
|
| 121 | 121 | |
| 122 | - //store benchmark |
|
| 123 | - if (isset(self::$benchmark[$this->file])) { |
|
| 124 | - self::$benchmark[$this->file] = self::$benchmark[$this->file] + $exec_time; |
|
| 125 | - } else { |
|
| 126 | - self::$benchmark[$this->file] = $exec_time; |
|
| 127 | - } |
|
| 122 | + //store benchmark |
|
| 123 | + if (isset(self::$benchmark[$this->file])) { |
|
| 124 | + self::$benchmark[$this->file] = self::$benchmark[$this->file] + $exec_time; |
|
| 125 | + } else { |
|
| 126 | + self::$benchmark[$this->file] = $exec_time; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return $html; |
|
| 130 | - } |
|
| 129 | + return $html; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - protected static function initCoreIfAbsent () { |
|
| 133 | - if (self::$core == null) { |
|
| 134 | - self::$core = new Dwoo\Core(); |
|
| 132 | + protected static function initCoreIfAbsent () { |
|
| 133 | + if (self::$core == null) { |
|
| 134 | + self::$core = new Dwoo\Core(); |
|
| 135 | 135 | |
| 136 | - $cache_dir = CACHE_PATH . "dwoo/"; |
|
| 137 | - $compile_dir = CACHE_PATH . "dwoo-compile/"; |
|
| 136 | + $cache_dir = CACHE_PATH . "dwoo/"; |
|
| 137 | + $compile_dir = CACHE_PATH . "dwoo-compile/"; |
|
| 138 | 138 | |
| 139 | - //check, if cache dir exists |
|
| 140 | - if (!file_exists($cache_dir)) { |
|
| 141 | - mkdir($cache_dir); |
|
| 142 | - } |
|
| 139 | + //check, if cache dir exists |
|
| 140 | + if (!file_exists($cache_dir)) { |
|
| 141 | + mkdir($cache_dir); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - //check, if compile dir exists |
|
| 145 | - if (!file_exists($compile_dir)) { |
|
| 146 | - mkdir($compile_dir); |
|
| 147 | - } |
|
| 144 | + //check, if compile dir exists |
|
| 145 | + if (!file_exists($compile_dir)) { |
|
| 146 | + mkdir($compile_dir); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - //set cache dir |
|
| 150 | - self::$core->setCacheDir($cache_dir); |
|
| 151 | - self::$core->setCompileDir($compile_dir); |
|
| 149 | + //set cache dir |
|
| 150 | + self::$core->setCacheDir($cache_dir); |
|
| 151 | + self::$core->setCompileDir($compile_dir); |
|
| 152 | 152 | |
| 153 | - //allow some php functions |
|
| 154 | - //self::$core->setSecurityPolicy(new \Dwoo\Security\Policy()); |
|
| 155 | - //self::$core->getSecurityPolicy()->allowPhpFunction("count"); |
|
| 156 | - //self::$core->getSecurityPolicy()->allowPhpFunction("sizeof"); |
|
| 157 | - |
|
| 158 | - //add plugins |
|
| 159 | - //self::$core->addPlugin("if"); |
|
| 153 | + //allow some php functions |
|
| 154 | + //self::$core->setSecurityPolicy(new \Dwoo\Security\Policy()); |
|
| 155 | + //self::$core->getSecurityPolicy()->allowPhpFunction("count"); |
|
| 156 | + //self::$core->getSecurityPolicy()->allowPhpFunction("sizeof"); |
|
| 157 | + |
|
| 158 | + //add plugins |
|
| 159 | + //self::$core->addPlugin("if"); |
|
| 160 | 160 | |
| 161 | - //self::$core->addPlugin("lang", new \Dwoo\Plugins\Functions\PluginLang(self::$core)); |
|
| 161 | + //self::$core->addPlugin("lang", new \Dwoo\Plugins\Functions\PluginLang(self::$core)); |
|
| 162 | 162 | |
| 163 | - // add custom plugin |
|
| 164 | - /*self::$core->addPlugin('lang', function (Dwoo\Core $core, $str, $str1 = "") { |
|
| 163 | + // add custom plugin |
|
| 164 | + /*self::$core->addPlugin('lang', function (Dwoo\Core $core, $str, $str1 = "") { |
|
| 165 | 165 | return "test_" . $str; |
| 166 | 166 | });*/ |
| 167 | 167 | |
| 168 | - Events::throwEvent("init_dwoo", array( |
|
| 169 | - 'core' => &self::$core, |
|
| 170 | - 'cache_path' => CACHE_PATH, |
|
| 171 | - 'cache_dir' => $cache_dir |
|
| 172 | - )); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public static function listFileBenchmark () { |
|
| 177 | - return self::$benchmark; |
|
| 178 | - } |
|
| 168 | + Events::throwEvent("init_dwoo", array( |
|
| 169 | + 'core' => &self::$core, |
|
| 170 | + 'cache_path' => CACHE_PATH, |
|
| 171 | + 'cache_dir' => $cache_dir |
|
| 172 | + )); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public static function listFileBenchmark () { |
|
| 177 | + return self::$benchmark; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } |
| 181 | 181 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $this->assign("USERNAME", User::current()->getUsername()); |
| 93 | 93 | |
| 94 | 94 | $style_name = $registry->getSetting("current_style_name"); |
| 95 | - $this->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
| 95 | + $this->assign("STYLE_PATH", DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
| 96 | 96 | |
| 97 | 97 | $end_time = microtime(true); |
| 98 | 98 | $exec_time = $end_time - $start_time; |
@@ -101,16 +101,16 @@ discard block |
||
| 101 | 101 | self::$benchmark[$this->file] = $exec_time; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function assign ($var, $value) { |
|
| 104 | + public function assign($var, $value) { |
|
| 105 | 105 | //$this->vars[$var] = $value; |
| 106 | 106 | $this->data->assign($var, $value); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function parse ($name = "main") { |
|
| 109 | + public function parse($name = "main") { |
|
| 110 | 110 | throw new Exception("Method DwooTemplate::parse() is not supported from Dwoo template engine."); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public function getCode ($name = "main") { |
|
| 113 | + public function getCode($name = "main") { |
|
| 114 | 114 | $start_time = microtime(true); |
| 115 | 115 | |
| 116 | 116 | // Output the result |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return $html; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - protected static function initCoreIfAbsent () { |
|
| 132 | + protected static function initCoreIfAbsent() { |
|
| 133 | 133 | if (self::$core == null) { |
| 134 | 134 | self::$core = new Dwoo\Core(); |
| 135 | 135 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public static function listFileBenchmark () { |
|
| 176 | + public static function listFileBenchmark() { |
|
| 177 | 177 | return self::$benchmark; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class Plugins { |
| 29 | 29 | |
| 30 | - public static function listAvailablePluginNames () : array { |
|
| 30 | + public static function listAvailablePluginNames() : array { |
|
| 31 | 31 | $names = array(); |
| 32 | 32 | |
| 33 | 33 | //use directory iterator |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | return $names; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function listInstalledPluginNames () : array { |
|
| 45 | + public static function listInstalledPluginNames() : array { |
|
| 46 | 46 | if (Cache::contains("plugins", "installed_plugin_names")) { |
| 47 | 47 | return Cache::get("plugins", "installed_plugin_names"); |
| 48 | 48 | } else { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public static function listInstalledPlugins () : array { |
|
| 64 | + public static function listInstalledPlugins() : array { |
|
| 65 | 65 | if (Cache::contains("plugins", "installed_plugins")) { |
| 66 | 66 | return Cache::get("plugins", "installed_plugins"); |
| 67 | 67 | } else { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public static function listUninstalledPlugins () : array { |
|
| 90 | + public static function listUninstalledPlugins() : array { |
|
| 91 | 91 | $installed_plugin_names = self::listInstalledPluginNames(); |
| 92 | 92 | |
| 93 | 93 | //create new empty list |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | return $list; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public static function clearCache () { |
|
| 128 | + public static function clearCache() { |
|
| 129 | 129 | Cache::clear("plugins"); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -27,107 +27,107 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Plugins { |
| 29 | 29 | |
| 30 | - public static function listAvailablePluginNames () : array { |
|
| 31 | - $names = array(); |
|
| 30 | + public static function listAvailablePluginNames () : array { |
|
| 31 | + $names = array(); |
|
| 32 | 32 | |
| 33 | - //use directory iterator |
|
| 34 | - $dir = new DirectoryIterator(PLUGIN_PATH); |
|
| 33 | + //use directory iterator |
|
| 34 | + $dir = new DirectoryIterator(PLUGIN_PATH); |
|
| 35 | 35 | |
| 36 | - foreach ($dir as $fileinfo) { |
|
| 37 | - if ($fileinfo->isDir() && !$fileinfo->isDot()) { |
|
| 38 | - $names[] = $fileinfo->getFilename(); |
|
| 39 | - } |
|
| 40 | - } |
|
| 36 | + foreach ($dir as $fileinfo) { |
|
| 37 | + if ($fileinfo->isDir() && !$fileinfo->isDot()) { |
|
| 38 | + $names[] = $fileinfo->getFilename(); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $names; |
|
| 43 | - } |
|
| 42 | + return $names; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public static function listInstalledPluginNames () : array { |
|
| 46 | - if (Cache::contains("plugins", "installed_plugin_names")) { |
|
| 47 | - return Cache::get("plugins", "installed_plugin_names"); |
|
| 48 | - } else { |
|
| 49 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
| 45 | + public static function listInstalledPluginNames () : array { |
|
| 46 | + if (Cache::contains("plugins", "installed_plugin_names")) { |
|
| 47 | + return Cache::get("plugins", "installed_plugin_names"); |
|
| 48 | + } else { |
|
| 49 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
| 50 | 50 | |
| 51 | - $array = array(); |
|
| 51 | + $array = array(); |
|
| 52 | 52 | |
| 53 | - foreach ($rows as $row) { |
|
| 54 | - $array[] = $row['name']; |
|
| 55 | - } |
|
| 53 | + foreach ($rows as $row) { |
|
| 54 | + $array[] = $row['name']; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - //cache rows |
|
| 58 | - Cache::put("plugins", "installed_plugin_names", $array); |
|
| 57 | + //cache rows |
|
| 58 | + Cache::put("plugins", "installed_plugin_names", $array); |
|
| 59 | 59 | |
| 60 | - return $array; |
|
| 61 | - } |
|
| 62 | - } |
|
| 60 | + return $array; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public static function listInstalledPlugins () : array { |
|
| 65 | - if (Cache::contains("plugins", "installed_plugins")) { |
|
| 66 | - return Cache::get("plugins", "installed_plugins"); |
|
| 67 | - } else { |
|
| 68 | - //read installed plugins from database |
|
| 69 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
| 64 | + public static function listInstalledPlugins () : array { |
|
| 65 | + if (Cache::contains("plugins", "installed_plugins")) { |
|
| 66 | + return Cache::get("plugins", "installed_plugins"); |
|
| 67 | + } else { |
|
| 68 | + //read installed plugins from database |
|
| 69 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
| 70 | 70 | |
| 71 | - $plugins = array(); |
|
| 71 | + $plugins = array(); |
|
| 72 | 72 | |
| 73 | - foreach ($rows as $row) { |
|
| 74 | - //create new plugin instance |
|
| 75 | - $plugin = new Plugin($row['name'], $row); |
|
| 73 | + foreach ($rows as $row) { |
|
| 74 | + //create new plugin instance |
|
| 75 | + $plugin = new Plugin($row['name'], $row); |
|
| 76 | 76 | |
| 77 | - //load plugin |
|
| 78 | - $plugin->load(); |
|
| 77 | + //load plugin |
|
| 78 | + $plugin->load(); |
|
| 79 | 79 | |
| 80 | - $plugins[$plugin->getName()] = $plugin; |
|
| 81 | - } |
|
| 80 | + $plugins[$plugin->getName()] = $plugin; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - //cache plugins |
|
| 84 | - Cache::put("plugins", "installed_plugins", $plugins); |
|
| 83 | + //cache plugins |
|
| 84 | + Cache::put("plugins", "installed_plugins", $plugins); |
|
| 85 | 85 | |
| 86 | - return $plugins; |
|
| 87 | - } |
|
| 88 | - } |
|
| 86 | + return $plugins; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public static function listUninstalledPlugins () : array { |
|
| 91 | - $installed_plugin_names = self::listInstalledPluginNames(); |
|
| 90 | + public static function listUninstalledPlugins () : array { |
|
| 91 | + $installed_plugin_names = self::listInstalledPluginNames(); |
|
| 92 | 92 | |
| 93 | - //create new empty list |
|
| 94 | - $list = array(); |
|
| 93 | + //create new empty list |
|
| 94 | + $list = array(); |
|
| 95 | 95 | |
| 96 | - $dir = new DirectoryIterator(PLUGIN_PATH); |
|
| 96 | + $dir = new DirectoryIterator(PLUGIN_PATH); |
|
| 97 | 97 | |
| 98 | - foreach ($dir as $fileInfo) { |
|
| 99 | - if ($fileInfo->isDot()) { |
|
| 100 | - //dont parse directory "." |
|
| 101 | - continue; |
|
| 102 | - } |
|
| 98 | + foreach ($dir as $fileInfo) { |
|
| 99 | + if ($fileInfo->isDot()) { |
|
| 100 | + //dont parse directory "." |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - if (!$fileInfo->isDir()) { |
|
| 105 | - //we only search for directories |
|
| 106 | - continue; |
|
| 107 | - } |
|
| 104 | + if (!$fileInfo->isDir()) { |
|
| 105 | + //we only search for directories |
|
| 106 | + continue; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - //get directory name |
|
| 110 | - $name = $fileInfo->getFilename(); |
|
| 109 | + //get directory name |
|
| 110 | + $name = $fileInfo->getFilename(); |
|
| 111 | 111 | |
| 112 | - //check, if plugin is already installed |
|
| 113 | - if (in_array($name, $installed_plugin_names)) { |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 112 | + //check, if plugin is already installed |
|
| 113 | + if (in_array($name, $installed_plugin_names)) { |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - //create and load new plugin |
|
| 118 | - $plugin = new Plugin($name); |
|
| 119 | - $plugin->load(); |
|
| 117 | + //create and load new plugin |
|
| 118 | + $plugin = new Plugin($name); |
|
| 119 | + $plugin->load(); |
|
| 120 | 120 | |
| 121 | - //add plugin to list |
|
| 122 | - $list[] = $plugin; |
|
| 123 | - } |
|
| 121 | + //add plugin to list |
|
| 122 | + $list[] = $plugin; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return $list; |
|
| 126 | - } |
|
| 125 | + return $list; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - public static function clearCache () { |
|
| 129 | - Cache::clear("plugins"); |
|
| 130 | - } |
|
| 128 | + public static function clearCache () { |
|
| 129 | + Cache::clear("plugins"); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |