| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 defined('JPATH_BASE') or die; 8 9 /** 10 * Plugin class for redirect handling. 11 * 12 * @package Joomla.Plugin 13 * @subpackage System.redirect 14 */ 15 class plgSystemRedirect extends JPlugin 16 { 17 /** 18 * Object Constructor. 19 * 20 * @access public 21 * @param object The object to observe -- event dispatcher. 22 * @param object The configuration object for the plugin. 23 * @return void 24 * @since 1.0 25 */ 26 function __construct(&$subject, $config) 27 { 28 parent::__construct($subject, $config); 29 30 // Set the error handler for E_ERROR to be the class handleError method. 31 JError::setErrorHandling(E_ERROR, 'callback', array('plgSystemRedirect', 'handleError')); 32 } 33 34 static function handleError(&$error) 35 { 36 // Get the application object. 37 $app = JFactory::getApplication(); 38 39 // Make sure the error is a 404 and we are not in the administrator. 40 if (!$app->isAdmin() and ($error->getCode() == 404)) 41 { 42 // Get the full current URI. 43 $uri = JURI::getInstance(); 44 $current = $uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment')); 45 46 // Attempt to ignore idiots. 47 if ((strpos($current, 'mosConfig_') !== false) || (strpos($current, '=http://') !== false)) { 48 // Render the error page. 49 JError::customErrorPage($error); 50 } 51 52 // See if the current url exists in the database as a redirect. 53 $db = JFactory::getDBO(); 54 $db->setQuery( 55 'SELECT '.$db->quoteName('new_url').', '.$db->quoteName('published'). 56 ' FROM '.$db->quoteName('#__redirect_links') . 57 ' WHERE '.$db->quoteName('old_url').' = '.$db->quote($current), 58 0, 1 59 ); 60 $link = $db->loadObject(); 61 62 // If a redirect exists and is published, permanently redirect. 63 if ($link and ($link->published == 1)) { 64 $app->redirect($link->new_url, null, null, true, true); 65 } 66 else 67 { 68 $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; 69 70 $db->setQuery('SELECT id FROM ' . $db->quoteName('#__redirect_links') . ' WHERE old_url= ' . $db->quote($current)); 71 $res = $db->loadResult(); 72 if(!$res) { 73 74 // If not, add the new url to the database. 75 $query = $db->getQuery(true); 76 $query->insert($db->quoteName('#__redirect_links'), false); 77 $columns = array( $db->quoteName('old_url'), 78 $db->quoteName('new_url'), 79 $db->quoteName('referer'), 80 $db->quoteName('comment'), 81 $db->quoteName('published'), 82 $db->quoteName('created_date') 83 ); 84 $query->columns($columns); 85 $query->values($db->Quote($current). ', '. $db->Quote(''). 86 ' ,'.$db->Quote($referer).', '.$db->Quote('').',0, '. 87 $db->Quote(JFactory::getDate()->toSql()) 88 ); 89 90 $db->setQuery($query); 91 $db->query(); 92 93 } 94 // Render the error page. 95 JError::customErrorPage($error); 96 } 97 } 98 else { 99 // Render the error page. 100 JError::customErrorPage($error); 101 } 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |