Source for file redirect.php
Documentation is available at redirect.php
* @subpackage System.redirect
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Plugin class for redirect handling.
* @subpackage System.redirect
* @param object The object to observe -- event dispatcher.
* @param object The configuration object for the plugin.
// Set the error handler for E_ERROR to be the class handleError method.
// Get the application object.
// Make sure the error is a 404 and we are not in the administrator.
if (!$app->isAdmin() and ($error->getCode() ==
404))
// Get the full current URI.
$current =
$uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'));
// Attempt to ignore idiots.
if ((strpos($current, 'mosConfig_') !==
false) ||
(strpos($current, '=http://') !==
false))
// Render the error page.
// See if the current url exists in the database as a redirect.
$query =
$db->getQuery(true)
->select($db->quoteName('new_url'))
->select($db->quoteName('published'))
->from($db->quoteName('#__redirect_links'))
->where($db->quoteName('old_url') .
' = ' .
$db->quote($current));
$db->setQuery($query, 0, 1);
$link =
$db->loadObject();
// If a redirect exists and is published, permanently redirect.
if ($link and ($link->published ==
1))
$app->redirect($link->new_url, true);
$referer =
empty($_SERVER['HTTP_REFERER']) ?
'' :
$_SERVER['HTTP_REFERER'];
$db->setQuery('SELECT id FROM ' .
$db->quoteName('#__redirect_links') .
' WHERE old_url= ' .
$db->quote($current));
$res =
$db->loadResult();
// If not, add the new url to the database.
$db->quoteName('old_url'),
$db->quoteName('new_url'),
$db->quoteName('referer'),
$db->quoteName('comment'),
$db->quoteName('published'),
$db->quoteName('created_date')
->insert($db->quoteName('#__redirect_links'), false)
$db->quote($current) .
', ' .
$db->quote('') .
' ,' .
$db->quote($referer) .
', ' .
$db->quote('') .
',1,0, ' .
// Existing error url, increase hit counter
->update($db->quoteName('#__redirect_links'))
->set($db->quoteName('hits') .
' = ' .
$db->quote('hits') .
' + 1')
->where('id = ' . (int)
$res);
// Render the error page.
// Render the error page.
Documentation generated on Tue, 19 Nov 2013 15:11:38 +0100 by phpDocumentor 1.4.3