diff --git a/install/mysql/migrations/v2.0.0/20180301063731_install_plg_system404.php b/install/mysql/migrations/v2.0.0/20180301063731_install_plg_system404.php new file mode 100644 index 0000000000..d198ca0bba --- /dev/null +++ b/install/mysql/migrations/v2.0.0/20180301063731_install_plg_system404.php @@ -0,0 +1,22 @@ +execute($sql); + } + + public function down() + { + $this->execute("DELETE FROM `extensions` WHERE `extensions`.`name` = 'plg_system_404'"); + } +} diff --git a/lib/plugins/system/404/404.php b/lib/plugins/system/404/404.php new file mode 100644 index 0000000000..96c78b9ffc --- /dev/null +++ b/lib/plugins/system/404/404.php @@ -0,0 +1,44 @@ + + * @link http://www.joomlatools.com + */ + +defined('_JEXEC') or die; + +class PlgSystem404 extends JPlugin +{ + public function __construct(&$subject, $config) + { + parent::__construct($subject, $config); + + if (JFactory::getApplication()->isSite()) + { + // Set the JError handler for E_ERROR to be the class' handleError method. + JError::setErrorHandling(E_ERROR, 'callback', array('PlgSystem404', 'handleError')); + } + } + + public static function handleError(JException $error) + { + $app = JFactory::getApplication(); + + if ($app->get('sef') && (int) $error->getCode() == 404) + { + $regex = '/\/[\d]+\-/'; + $current = JUri::current(); + + // Match url having "/xxx-" format, where xxx is a number. + if (preg_match($regex, $current)) + { + // Redirect with-id to no-id url + $redirect = preg_replace($regex, '/', $current); + $app->redirect($redirect); + } + } + + JErrorPage::render($error); + } +} diff --git a/lib/plugins/system/404/404.xml b/lib/plugins/system/404/404.xml new file mode 100644 index 0000000000..32c540df2a --- /dev/null +++ b/lib/plugins/system/404/404.xml @@ -0,0 +1,19 @@ + + + plg_system_404 + Joomlatools + March 2018 + Copyright (C) 2018 Timble CVBA (http://www.timble.net) + GNU GPLv3 - http://www.gnu.org/licenses/gpl.html + support@joomlatools.com + www.joomlatools.com + 1.0.0 + PLG_SYSTEM_404_DESCRIPTION + + 404.php + + + en-GB.plg_system_404.ini + en-GB.plg_system_404.sys.ini + + diff --git a/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.ini b/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.ini new file mode 100644 index 0000000000..75b68dc8fe --- /dev/null +++ b/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.ini @@ -0,0 +1,6 @@ +; Copyright © 2018 Timble CVBA. (http://www.timble.net) +; GNU GPLv3 +; Note : All ini files need to be saved as UTF-8 + +PLG_SYSTEM_404="System - 404" +PLG_SYSTEM_404_DESCRIPTION="This will redirect with-id to no-id url." diff --git a/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.sys.ini b/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.sys.ini new file mode 100644 index 0000000000..75b68dc8fe --- /dev/null +++ b/lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.sys.ini @@ -0,0 +1,6 @@ +; Copyright © 2018 Timble CVBA. (http://www.timble.net) +; GNU GPLv3 +; Note : All ini files need to be saved as UTF-8 + +PLG_SYSTEM_404="System - 404" +PLG_SYSTEM_404_DESCRIPTION="This will redirect with-id to no-id url."