From a0f6f2e849d0884259693e7c1df1bc9de6585eb2 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Tue, 22 Sep 2020 21:30:49 +0200 Subject: Require STE using composer and add autoloading --- ratatoeskr/libs/INFO | 24 +++----- ratatoeskr/main.php | 1 + ratatoeskr/setup/setup.php | 1 + ratatoeskr/sys/GlobalSte.php | 135 +++++++++++++++++++++++++++++++++++++++++++ ratatoeskr/sys/init_ste.php | 45 +++------------ 5 files changed, 153 insertions(+), 53 deletions(-) create mode 100644 ratatoeskr/sys/GlobalSte.php (limited to 'ratatoeskr') diff --git a/ratatoeskr/libs/INFO b/ratatoeskr/libs/INFO index 1ce4244..80a47e3 100644 --- a/ratatoeskr/libs/INFO +++ b/ratatoeskr/libs/INFO @@ -1,25 +1,19 @@ This directory will hold some libraries Ratatöskr needs. -1. STE Template Engine (STE) - - Place the STE files into the subdirectory "ste" (create it, if it doesn't exist). At least "ste.php" and the "src" directory of STE are needed! - - STE can be found here: - -2. PHP Markdown - +1. PHP Markdown + Place "markdown.php" from the archive directly into this directory. - + PHP Markdown can be found here: -3. kses - +2. kses + Place "kses.php" from the archive directly into this directory. - + kses can be found at -4. jQuery - +3. jQuery + Place jquery.min.js into this folder. - + jQuery can be found at \ No newline at end of file diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php index 9bbe504..6353050 100644 --- a/ratatoeskr/main.php +++ b/ratatoeskr/main.php @@ -16,6 +16,7 @@ if (!defined("CONFIG_FILLED_OUT") || !CONFIG_FILLED_OUT) { die("Config file not filled out!"); } +require_once(dirname(__FILE__) . "/vendor/autoload.php"); require_once(dirname(__FILE__) . "/sys/db.php"); require_once(dirname(__FILE__) . "/sys/models.php"); require_once(dirname(__FILE__) . "/sys/init_ste.php"); diff --git a/ratatoeskr/setup/setup.php b/ratatoeskr/setup/setup.php index 749315a..f1c6dee 100644 --- a/ratatoeskr/setup/setup.php +++ b/ratatoeskr/setup/setup.php @@ -2,6 +2,7 @@ define("SETUP", true); +require_once(dirname(__FILE__) . "/../vendor/autoload.php"); require_once(dirname(__FILE__) . "/../sys/init_ste.php"); require_once(dirname(__FILE__) . "/../sys/translation.php"); require_once(dirname(__FILE__) . "/../sys/db.php"); diff --git a/ratatoeskr/sys/GlobalSte.php b/ratatoeskr/sys/GlobalSte.php new file mode 100644 index 0000000..3a5c8e6 --- /dev/null +++ b/ratatoeskr/sys/GlobalSte.php @@ -0,0 +1,135 @@ +ste = new STECore(new FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc")); + if (defined("__DEBUG__") && __DEBUG__) { + $this->ste->mute_runtime_errors = false; + } + + $this->ste->register_tag("l10n_replace", [self::class, "tag_l10n_replace"]); + $this->ste->register_tag("capitalize", [self::class, "tag_capitalize"]); + $this->ste->register_tag("loremipsum", [self::class, "tag_loremipsum"]); + } + + public static function tag_l10n_replace($ste, $params, $sub) + { + $content = $sub($ste); + foreach ($params as $name => $replace) { + $content = str_replace("[[$name]]", $replace, $content); + } + return $content; + } + + public static function tag_capitalize($ste, $params, $sub) + { + return ucwords($sub($ste)); + } + + public static function tag_loremipsum($ste, $params, $sub) + { + $repeats = empty($params["repeat"]) ? 1 : $params["repeat"] + 0; + return implode( + "\n\n", + array_repeat( + "

Lorem ipsum dolor sit amet, consectetur adipisici elit, " + . "sed eiusmod tempor incidunt ut labore et dolore magna " + . "aliqua. Ut enim ad minim veniam, quis nostrud exercitation " + . "ullamco laboris nisi ut aliquid ex ea commodi consequat. " + . "Quis aute iure reprehenderit in voluptate velit esse cillum " + . "dolore eu fugiat nulla pariatur. Excepteur sint obcaecat " + . "cupiditat non proident, sunt in culpa qui officia deserunt " + . "mollit anim id est laborum.

\n\n

Duis autem vel eum " + . "iriure dolor in hendrerit in vulputate velit esse molestie " + . "consequat, vel illum dolore eu feugiat nulla facilisis at " + . "vero eros et accumsan et iusto odio dignissim qui blandit " + . "praesent luptatum zzril delenit augue duis dolore te " + . "feugait nulla facilisi. Lorem ipsum dolor sit amet, " + . "consectetuer adipiscing elit, sed diam nonummy nibh euismod " + . "tincidunt ut laoreet dolore magna aliquam erat volutpat." + . "

\n\n

Ut wisi enim ad minim veniam, quis nostrud " + . "exerci tation ullamcorper suscipit lobortis nisl ut aliquip " + . "ex ea commodo consequat. Duis autem vel eum iriure dolor in " + . "hendrerit in vulputate velit esse molestie consequat, vel " + . "illum dolore eu feugiat nulla facilisis at vero eros et " + . "accumsan et iusto odio dignissim qui blandit praesent " + . "luptatum zzril delenit augue duis dolore te feugait nulla " + . "facilisi.

\n\n

Nam liber tempor cum soluta nobis " + . "eleifend option congue nihil imperdiet doming id quod mazim " + . "placerat facer possim assum. Lorem ipsum dolor sit amet, " + . "consectetuer adipiscing elit, sed diam nonummy nibh euismod " + . "tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut " + . "wisi enim ad minim veniam, quis nostrud exerci tation " + . "ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo " + . "consequat.

\n\n

Duis autem vel eum iriure dolor in " + . "hendrerit in vulputate velit esse molestie consequat, vel " + . "illum dolore eu feugiat nulla facilisis.

\n\n

At vero " + . "eos et accusam et justo duo dolores et ea rebum. Stet clita " + . "kasd gubergren, no sea takimata sanctus est Lorem ipsum " + . "dolor sit amet. Lorem ipsum dolor sit amet, consetetur " + . "sadipscing elitr, sed diam nonumy eirmod tempor invidunt " + . "ut labore et dolore magna aliquyam erat, sed diam voluptua. " + . "At vero eos et accusam et justo duo dolores et ea rebum. " + . "Stet clita kasd gubergren, no sea takimata sanctus est " + . "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, " + . "consetetur sadipscing elitr, At accusam aliquyam diam diam " + . "dolore dolores duo eirmod eos erat, et nonumy sed tempor et " + . "et invidunt justo labore Stet clita ea et gubergren, kasd " + . "magna no rebum. sanctus sea sed takimata ut vero voluptua. " + . "est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, " + . "consetetur sadipscing elitr, sed diam nonumy eirmod tempor " + . "invidunt ut labore et dolore magna aliquyam erat.

\n\n" + . "

Consetetur sadipscing elitr, sed diam nonumy eirmod " + . "tempor invidunt ut labore et dolore magna aliquyam erat, " + . "sed diam voluptua. At vero eos et accusam et justo duo " + . "dolores et ea rebum. Stet clita kasd gubergren, no sea " + . "takimata sanctus est Lorem ipsum dolor sit amet. Lorem " + . "ipsum dolor sit amet, consetetur sadipscing elitr, sed " + . "diam nonumy eirmod tempor invidunt ut labore et dolore " + . "magna aliquyam erat, sed diam voluptua. At vero eos et " + . "accusam et justo duo dolores et ea rebum. Stet clita kasd " + . "gubergren, no sea takimata sanctus est Lorem ipsum dolor " + . "sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing " + . "elitr, sed diam nonumy eirmod tempor invidunt ut labore et " + . "dolore magna aliquyam erat, sed diam voluptua. At vero eos " + . "et accusam et justo duo dolores et ea rebum. Stet clita " + . "kasd gubergren, no sea takimata sanctus est Lorem ipsum " + . "dolor sit amet.

", + $repeats + ) + ); + } + + private static function getInstance(): self + { + self::$instance = self::$instance ?? new self(); + return self::$instance; + } + + /** + * Get (and initialize, if necessary) the global STE instance. + * @return STECore + */ + public static function getGlobalSte(): STECore + { + return self::getInstance()->ste; + } +} diff --git a/ratatoeskr/sys/init_ste.php b/ratatoeskr/sys/init_ste.php index b422046..07e8976 100644 --- a/ratatoeskr/sys/init_ste.php +++ b/ratatoeskr/sys/init_ste.php @@ -11,42 +11,11 @@ * See "ratatoeskr/licenses/ratatoeskr" for more information. */ -require_once(dirname(__FILE__) . "/../libs/ste/ste.php"); +use r7r\cms\sys\GlobalSte; +use r7r\ste\STECore; -$tpl_basedir = dirname(__FILE__) . "/../templates"; - -if (!isset($ste)) { - /* - * Variable: $ste - * - * The global STECore instance. - */ - $ste = new \ste\STECore(new \ste\FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc")); - if (defined("__DEBUG__") && __DEBUG__) { - $ste->mute_runtime_errors = false; - } -} - -$ste->register_tag( - "l10n_replace", - function ($ste, $params, $sub) { - $content = $sub($ste); - foreach ($params as $name => $replace) { - $content = str_replace("[[$name]]", $replace, $content); - } - return $content; - } -); -$ste->register_tag( - "capitalize", - function ($ste, $params, $sub) { - return ucwords($sub($ste)); - } -); -$ste->register_tag( - "loremipsum", - function ($ste, $params, $sub) { - $repeats = empty($params["repeat"]) ? 1 : $params["repeat"] + 0; - return implode("\n\n", array_repeat("

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\n\n

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

\n\n

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

\n\n

Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

\n\n

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.

\n\n

At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.

\n\n

Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

", $repeats)); - } -); +/** + * @var STECore The global STECore instance. + * @deprecated Use {@see GlobalSte} directly now. + */ +$ste = GlobalSte::getGlobalSte(); -- cgit v1.2.3-70-g09d2