This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from joomlatools/feature/346-404redirect-plugin
Create 404 re-direct plugin
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
install/mysql/migrations/v2.0.0/20180301063731_install_plg_system404.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class InstallPlgSystem404 extends AbstractMigration | ||
{ | ||
public function up() | ||
{ | ||
$sql = <<<EOL | ||
INSERT INTO `extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) | ||
VALUES | ||
(450, 'plg_system_404', 'plugin', '404', 'system', 0, 1, 1, 0, '{}', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0); | ||
EOL; | ||
|
||
$this->execute($sql); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->execute("DELETE FROM `extensions` WHERE `extensions`.`name` = 'plg_system_404'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* @package System - 404 | ||
* @copyright Copyright (C) 2018 Timble CVBA. (http://www.timble.net) | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
* @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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<extension version="3.1" type="plugin" group="system" method="upgrade"> | ||
<name>plg_system_404</name> | ||
<author>Joomlatools</author> | ||
<creationDate>March 2018</creationDate> | ||
<copyright>Copyright (C) 2018 Timble CVBA (http://www.timble.net)</copyright> | ||
<license>GNU GPLv3 - http://www.gnu.org/licenses/gpl.html</license> | ||
<authorEmail>support@joomlatools.com</authorEmail> | ||
<authorUrl>www.joomlatools.com</authorUrl> | ||
<version>1.0.0</version> | ||
<description>PLG_SYSTEM_404_DESCRIPTION</description> | ||
<files> | ||
<filename plugin="404">404.php</filename> | ||
</files> | ||
<languages> | ||
<language tag="en-GB">en-GB.plg_system_404.ini</language> | ||
<language tag="en-GB">en-GB.plg_system_404.sys.ini</language> | ||
</languages> | ||
</extension> |
6 changes: 6 additions & 0 deletions
6
lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; Copyright © 2018 Timble CVBA. (http://www.timble.net) | ||
; GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
; 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." |
6 changes: 6 additions & 0 deletions
6
lib/plugins/system/404/language/en-GB/en-GB.plg_system_404.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
; Copyright © 2018 Timble CVBA. (http://www.timble.net) | ||
; GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
; 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." |