Skip to content

Commit

Permalink
Merge branch '5.1-dev' into 5.1-customfields1
Browse files Browse the repository at this point in the history
  • Loading branch information
bembelimen committed Feb 28, 2024
2 parents 7a367e7 + 96618f6 commit 29380dc
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_CACHE_SETTINGS');
$this->description = '';
$this->fieldsname = 'cache';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_COOKIE_SETTINGS');
$this->description = '';
$this->fieldsname = 'cookie';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_DATABASE_SETTINGS');
$this->description = '';
$this->fieldsname = 'database';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_DEBUG_SETTINGS');
$this->description = '';
$this->fieldsname = 'debug';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_TEXT_FILTER_SETTINGS');
$this->description = '';
$this->fieldsname = 'filters';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_LOCATION_SETTINGS');
$this->description = '';
$this->fieldsname = 'locale';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_LOGGING_SETTINGS');
$this->description = '';
$this->fieldsname = 'logging';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_LOGGING_CUSTOM_SETTINGS');
$this->description = '';
$this->fieldsname = 'logging_custom';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$ajaxUri = Route::_('index.php?option=com_config&task=application.sendtestmail&format=json');

$this->name = Text::_('COM_CONFIG_MAIL_SETTINGS');
$this->description = '';
$this->fieldsname = 'mail';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_METADATA_SETTINGS');
$this->description = '';
$this->fieldsname = 'metadata';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_PROXY_SETTINGS');
$this->description = '';
$this->fieldsname = 'proxy';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_SEO_SETTINGS');
$this->description = Text::_('COM_CONFIG_SEO_SETTINGS_DESC');
$this->fieldsname = 'seo';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_SERVER_SETTINGS');
$this->description = '';
$this->fieldsname = 'server';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_SESSION_SETTINGS');
$this->description = '';
$this->fieldsname = 'session';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_SITE_SETTINGS');
$this->description = '';
$this->fieldsname = 'site';
$this->formclass = 'options-form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
defined('_JEXEC') or die;

$this->name = Text::_('COM_CONFIG_WEBSERVICES_SETTINGS');
$this->description = '';
$this->fieldsname = 'webservices';
$this->formclass = 'options-form';

Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ COM_CONFIG_SENDMAIL_METHOD_SMTP="SMTP"
COM_CONFIG_SENDMAIL_SUBJECT="Test mail from {SITENAME}"
COM_CONFIG_SENDMAIL_SUCCESS="The email was sent to <strong>%s</strong> using <strong>%s</strong>. You should check that you've received the test email."
COM_CONFIG_SENDMAIL_SUCCESS_FALLBACK="The email was sent to <strong>%s</strong> but using <strong>%s</strong> as fallback. You should check that you've received the test email."
COM_CONFIG_SEO_SETTINGS_DESC="Additional settings can be found in the \"System - SEF\" plugin."
COM_CONFIG_SEO_SETTINGS="SEO"
COM_CONFIG_SERVER="Server"
COM_CONFIG_SERVER_SETTINGS="Server"
Expand Down
5 changes: 5 additions & 0 deletions administrator/language/en-GB/plg_system_sef.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@

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. <br><strong>Note:</strong> https://example.com and https://www.example.com are different domains."
PLG_SEF_DOMAIN_LABEL="Site Domain"
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"
PLG_SEF_TRAILINGSLASH_OPTION_NO_SLASH="Enforce URLs without trailing slash"
PLG_SEF_TRAILINGSLASH_OPTION_SLASH="Enforce URLs with trailing slash"
PLG_SEF_XML_DESCRIPTION="Adds SEF support to links in the document. It operates directly on the HTML and does not require a special tag."
PLG_SYSTEM_SEF="System - SEF"
6 changes: 5 additions & 1 deletion layouts/joomla/content/options_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Language\Text;

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
Expand All @@ -21,7 +22,10 @@
<fieldset class="<?php echo !empty($displayData->formclass) ? $displayData->formclass : ''; ?>">
<legend><?php echo $displayData->name; ?></legend>
<?php if (!empty($displayData->description)) : ?>
<p><?php echo $displayData->description; ?></p>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo $displayData->description; ?>
</div>
<?php endif; ?>
<?php $fieldsnames = explode(',', $displayData->fieldsname); ?>
<div class="form-grid">
Expand Down
13 changes: 13 additions & 0 deletions plugins/system/sef/sef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
filter="url"
validate="url"
/>

<field
name="trailingslash"
type="list"
label="PLG_SEF_TRAILINGSLASH_LABEL"
description="PLG_SEF_TRAILINGSLASH_DESCRIPTION"
default="0"
filter="option"
>
<option value="0">PLG_SEF_TRAILINGSLASH_OPTION_NONE</option>
<option value="1">PLG_SEF_TRAILINGSLASH_OPTION_NO_SLASH</option>
<option value="2">PLG_SEF_TRAILINGSLASH_OPTION_SLASH</option>
</field>
</fieldset>
</fields>
</config>
Expand Down
132 changes: 131 additions & 1 deletion plugins/system/sef/src/Extension/Sef.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

namespace Joomla\Plugin\System\Sef\Extension;

use Joomla\CMS\Event\Router\AfterInitialiseRouterEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\Router;
use Joomla\CMS\Router\SiteRouter;
use Joomla\CMS\Uri\Uri;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -23,8 +27,66 @@
*
* @since 1.5
*/
final class Sef extends CMSPlugin
final class Sef extends CMSPlugin implements SubscriberInterface
{
/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Returns an array of CMS events this plugin will listen to and the respective handlers.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
/**
* Note that onAfterInitialise must be the first handlers to run for this
* plugin to operate as expected. These handlers load compatibility code which
* might be needed by other plugins
*/
return [
'onAfterInitialiseRouter' => 'onAfterInitialiseRouter',
'onAfterDispatch' => 'onAfterDispatch',
'onAfterRender' => 'onAfterRender',
];
}

/**
* After initialise router.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onAfterInitialiseRouter(AfterInitialiseRouterEvent $event)
{
if (
!is_a($event->getRouter(), SiteRouter::class)
|| !$this->app->get('sef')
|| $this->app->get('sef_suffix')
|| !$this->params->get('trailingslash')
) {
return;
}

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);
}

/**
* Add the canonical uri to the head.
*
Expand Down Expand Up @@ -188,6 +250,74 @@ function ($match) use ($base, $protocols) {
$this->getApplication()->setBody($buffer);
}

/**
* Remove any trailing slash from URLs built in Joomla
*
* @param Router &$router Router object.
* @param Uri &$uri Uri object.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function removeTrailingSlash(&$router, &$uri)
{
$path = $uri->getPath();

if (substr($path, -1) == '/') {
$uri->setPath(substr($path, 0, -1));
}
}

/**
* Add trailing slash to URLs built in Joomla
*
* @param Router &$router Router object.
* @param Uri &$uri Uri object.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function addTrailingSlash(&$router, &$uri)
{
$path = $uri->getPath();

if (substr($path, -1) !== '/') {
$uri->setPath($path . '/');
}
}

/**
* Redirect to a URL with or without trailing slash
*
* @param Router &$router Router object.
* @param Uri &$uri Uri object.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function enforceTrailingSlash(&$router, &$uri)
{
// We only want to redirect on GET requests
if ($this->app->getInput()->getMethod() != 'GET') {
return;
}

$originalUri = Uri::getInstance();

if ($this->params->get('trailingslash') == 1 && substr($originalUri->getPath(), -1) == '/' && $originalUri->toString() != Uri::root()) {
// Remove trailingslash
$originalUri->setPath(substr($originalUri->getPath(), 0, -1));
$this->app->redirect($originalUri->toString(), 301);
} elseif ($this->params->get('trailingslash') == 2 && substr($originalUri->getPath(), -1) != '/') {
// Add trailingslash
$originalUri->setPath($originalUri->getPath() . '/');
$this->app->redirect($originalUri->toString(), 301);
}
}

/**
* Check the buffer.
*
Expand Down

0 comments on commit 29380dc

Please sign in to comment.