From 5ccb1a80ac63a3bf05387be354a01f51f86955f3 Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Sun, 24 Nov 2024 22:45:12 +0100 Subject: [PATCH] YCom-spezifische Artikel ignorieren --- lib/speed_up.php | 72 ++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/lib/speed_up.php b/lib/speed_up.php index 93d29ad..aedbe7f 100644 --- a/lib/speed_up.php +++ b/lib/speed_up.php @@ -26,7 +26,7 @@ public function __construct($profile = 'auto') } $mount_id = rex_yrewrite::getCurrentDomain()->getMountId(); $category_mount_children = []; - + if (rex_category::get($mount_id)) { $category_mount_children = rex_category::get($mount_id)->getChildren(true); } @@ -35,20 +35,21 @@ public function __construct($profile = 'auto') $category_neighbours = []; - if (null != $category_parent && $category_current->getId() != $mount_id) { + if ($category_parent != null && $category_current->getId() != $mount_id) { // Nur wenn wir uns nicht in Root befinden oder überhalb eines Mount-Points - andere YRewrite-Domains möchten wir nicht prefetchen. $category_neighbours = $category_parent->getChildren(true); } // Manuelle Einstellungen - $article_prefetch_config = explode(',', self::getConfig('prefetch_articles') ?? ''); + $article_prefetch_config = explode(",", speed_up::getConfig('prefetch_articles') ?? ""); + + if (self::getConfig('profile') === 'auto') { - if ('auto' === self::getConfig('profile')) { // Mount-Point = oberste Navigationsebene (Startseite könnte auch in einer Unterkategorie sein) foreach ($category_mount_children as $category) { $urls[$category->getId()] = $category->getUrl(); } - + // Nur das erste Kind-Element foreach ($category_children as $category) { $urls[$category->getId()] = $category->getUrl(); @@ -63,9 +64,9 @@ public function __construct($profile = 'auto') } $urls[$category->getId()] = $category->getUrl(); // Nach 2 gefundenen Nachbarn aussteigen - if (2 == ++$neighbours) { + if (++$neighbours == 2) { break; - } + }; } $neighbours = 0; @@ -75,21 +76,22 @@ public function __construct($profile = 'auto') continue; } $urls[$article->getId()] = $article->getUrl(); - if (2 == ++$neighbours) { + if (++$neighbours == 2) { break; - } + }; } if ($category_current && $category_current->getId() != $start_id) { // Startseite hinzufügen $urls[$start_id] = rex_article::get($start_id)->getUrl(); } - } elseif ('aggressive' === self::getConfig('profile')) { + } elseif (self::getConfig('profile') === 'aggressive') { + // Mount-Point = oberste Navigationsebene (Startseite könnte auch in einer Unterkategorie sein) foreach ($category_mount_children as $category) { $urls[$category->getId()] = $category->getUrl(); } - + foreach ($category_children as $category) { $urls[$category->getId()] = $category->getUrl(); } @@ -97,10 +99,13 @@ public function __construct($profile = 'auto') foreach ($category_articles as $article) { $urls[$article->getId()] = $article->getUrl(); } + + foreach ($category_neighbours as $category) { $urls[$category->getId()] = $category->getUrl(); } + if ($category_current && $category_current->getId() != $start_id) { // Startseite hinzufügen @@ -118,7 +123,7 @@ public function __construct($profile = 'auto') $urls = rex_extension::registerPoint(new rex_extension_point( 'PREFETCH_URLS', - $urls, + $urls )); /* @@ -128,52 +133,59 @@ public function __construct($profile = 'auto') } */ if (rex_addon::get('ycom')->isAvailable()) { - // YCom-spezifische Seiten wie Logout sollten keinesfalls geladen werden. - unset($urls[rex_config::get('ycom', 'article_id_jump_ok')]); - unset($urls[rex_config::get('ycom', 'article_id_jump_not_ok')]); - unset($urls[rex_config::get('ycom', 'article_id_jump_logout')]); + // YCom-spezifische Seiten wie Logout sollten keinesfalls eigenständig aufgerufen werden. */ unset($urls[rex_config::get('ycom', 'article_id_jump_denied')]); + unset($urls[rex_config::get('ycom', 'article_id_jump_logout')]); + unset($urls[rex_config::get('ycom', 'article_id_jump_not_ok')]); + unset($urls[rex_config::get('ycom', 'article_id_jump_ok')]); unset($urls[rex_config::get('ycom', 'article_id_jump_password')]); unset($urls[rex_config::get('ycom', 'article_id_jump_termsofuse')]); + unset($urls[rex_config::get('ycom', 'article_id_login')]); + unset($urls[rex_config::get('ycom', 'article_id_logout')]); + unset($urls[rex_config::get('ycom', 'article_id_register')]); + unset($urls[rex_config::get('ycom', 'article_id_password')]); + unset($urls[rex_config::get('ycom', 'otp_article_id')]); - // Reicht das? Wie verhält sich das prefetching zwischen einem ein- und ausgeloggten Nutzer? } unset($urls[rex_yrewrite::getCurrentDomain()->getNotfoundId()]); - + $this->urls = $urls; return $this; } + public function showOutput() { echo $this->getOutput(); + return; } - + public function show() /* Alias, BC */ { return $this->showOutput(); } + public function getOutput() { - if ('disabled' === self::getConfig('profile')) { + if (self::getConfig('profile') === 'disabled') { return; } - $output = PHP_EOL; - $output .= self::getConfig('preload') . PHP_EOL; - $output .= self::getConfig('prefetch') . PHP_EOL; - - $preload_media_config = explode(',', self::getConfig('preload_media') ?? ''); - + $output = PHP_EOL; + $output .= self::getConfig('preload').PHP_EOL; + $output .= self::getConfig('prefetch').PHP_EOL; + + $preload_media_config = explode(",", speed_up::getConfig('preload_media') ?? ""); + foreach ($preload_media_config as $file) { if ($media = rex_media::get($file)) { - $output .= '' . PHP_EOL; + $output .= ''.PHP_EOL; } } - - if ('custom' === self::getConfig('profile')) { + + if (self::getConfig('profile') === "custom") { return; } @@ -182,7 +194,7 @@ public function getOutput() if (isset($parsedUrl['scheme']) && !in_array($parsedUrl['scheme'], ['http', 'https'])) { continue; } - $output .= '' . PHP_EOL; + $output .= ''.PHP_EOL; } return $output; }