JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.1] SEF: Implementing index.php behavior #464

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 8 months ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/42704 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/language/en-GB/plg_system_sef.ini b/administrator/language/en-GB/plg_system_sef.ini index d4be5f41bca6..654019797899 100644 --- a/administrator/language/en-GB/plg_system_sef.ini +++ b/administrator/language/en-GB/plg_system_sef.ini @@ -5,6 +5,8 @@ PLG_SEF_DOMAIN_DESCRIPTION="If your site can be accessed through more than one domain enter the preferred (sometimes referred to as canonical) domain here.
Note: https://example.com and https://www.example.com are different domains." PLG_SEF_DOMAIN_LABEL="Site Domain" +PLG_SEF_INDEXPHP_DESCRIPTION="This option enables a stricter handling of 'index.php' in URLs when 'Use URL Rewriting' is enabled in Global Configuration. It will remove 'index.php' if a URL still contains it and redirect incoming requests with 'index.php' to the version without the 'index.php'." +PLG_SEF_INDEXPHP_LABEL="Strict handling of index.php" PLG_SEF_TRAILINGSLASH_DESCRIPTION="Force Joomla to only use URLs with or without trailing slash. When set, this will force the right URL with redirects and is only applied when 'Add suffix to URL' is disabled." PLG_SEF_TRAILINGSLASH_LABEL="Trailing slash for URLs" PLG_SEF_TRAILINGSLASH_OPTION_NONE="No change" diff --git a/plugins/system/sef/sef.xml b/plugins/system/sef/sef.xml index 39b87d9b4204..a0012238b554 100644 --- a/plugins/system/sef/sef.xml +++ b/plugins/system/sef/sef.xml @@ -31,6 +31,19 @@ validate="url" /> + + + + + getRouter(), SiteRouter::class) - || !$this->app->get('sef') - || $this->app->get('sef_suffix') - || !$this->params->get('trailingslash') + is_a($event->getRouter(), SiteRouter::class) + && $this->app->get('sef_rewrite') + && $this->params->get('indexphp') ) { - return; + // Enforce removing index.php with a redirect + $event->getRouter()->attachParseRule([$this, 'removeIndexphp'], SiteRouter::PROCESS_BEFORE); } - if ($this->params->get('trailingslash') == 1) { - // Remove trailingslash - $event->getRouter()->attachBuildRule([$this, 'removeTrailingSlash'], SiteRouter::PROCESS_AFTER); - } elseif ($this->params->get('trailingslash') == 2) { - // Add trailingslash - $event->getRouter()->attachBuildRule([$this, 'addTrailingSlash'], SiteRouter::PROCESS_AFTER); - } + if ( + is_a($event->getRouter(), SiteRouter::class) + && $this->app->get('sef') + && !$this->app->get('sef_suffix') + && $this->params->get('trailingslash') + ) { + if ($this->params->get('trailingslash') == 1) { + // Remove trailingslash + $event->getRouter()->attachBuildRule([$this, 'removeTrailingSlash'], SiteRouter::PROCESS_AFTER); + } elseif ($this->params->get('trailingslash') == 2) { + // Add trailingslash + $event->getRouter()->attachBuildRule([$this, 'addTrailingSlash'], SiteRouter::PROCESS_AFTER); + } - $event->getRouter()->attachParseRule([$this, 'enforceTrailingSlash'], SiteRouter::PROCESS_BEFORE); + $event->getRouter()->attachParseRule([$this, 'enforceTrailingSlash'], SiteRouter::PROCESS_BEFORE); + } } /** @@ -250,6 +257,38 @@ function ($match) use ($base, $protocols) { $this->getApplication()->setBody($buffer); } + /** + * Enforce removal of index.php with a redirect + * + * @param Router &$router Router object. + * @param Uri &$uri Uri object. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function removeIndexphp(&$router, &$uri) + { + // We only want to redirect on GET requests + if ($this->app->getInput()->getMethod() !== 'GET') { + return; + } + + $origUri = Uri::getInstance(); + + if (substr($origUri->getPath(), -9) === 'index.php') { + // Remove trailing index.php + $origUri->setPath(substr($origUri->getPath(), 0, -9)); + $this->app->redirect($origUri->toString(), 301); + } + + if (substr($origUri->getPath(), \strlen(Uri::base(true)), 11) === '/index.php/') { + // Remove leading index.php + $origUri->setPath(Uri::base(true) . substr($origUri->getPath(), \strlen(Uri::base(true)) + 10)); + $this->app->redirect($origUri->toString(), 301); + } + } + /** * Remove any trailing slash from URLs built in Joomla * ```
zwiastunsw commented 7 months ago

rozwiązane w 5.0.3