Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Attempt to ignore idiots.
- if ((strpos($current, 'mosConfig_') !== false) || (strpos($current, '=http://') !== false)) {
- // Render the error page.
- JError::customErrorPage($error);
- }
- // See if the current url exists in the database as a redirect.
- $db = JFactory::getDBO();
- $db->setQuery(
- 'SELECT '.$db->quoteName('new_url').', '.$db->quoteName('published').
- ' FROM '.$db->quoteName('#__redirect_links') .
- ' WHERE '.$db->quoteName('old_url').' = '.$db->quote($current),
- 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, null, null, true, true);
- }
- else
- {
- $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
- $db->setQuery('select id from '.$db->quoteName('#__redirect_links')." where old_url='".$current."'");
- $res = $db->loadResult();
- if(!$res) {
- // If not, add the new url to the database.
- $query = $db->getQuery(true);
- $query->insert($db->quoteName('#__redirect_links'), false);
- $columns = array( $db->quoteName('old_url'),
- $db->quoteName('new_url'),
- $db->quoteName('referer'),
- $db->quoteName('comment'),
- $db->quoteName('published'),
- $db->quoteName('created_date')
- );
- $query->columns($columns);
- $query->values($db->Quote($current). ', '. $db->Quote('').
- ' ,'.$db->Quote($referer).', '.$db->Quote('').',0, '.
- $db->Quote(JFactory::getDate()->toSql())
- );
- $db->setQuery($query);
- $db->query();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement