isAdmin() || ((int) $error->getCode() !== 404)) { // Proxy to the previous exception handler if available, otherwise just render the error page if (self::$previousExceptionHandler) { call_user_func_array(self::$previousExceptionHandler, array($error)); } else { JErrorPage::render($error); } } $uri = JUri::getInstance(); $url = rawurldecode($uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'))); $urlRel = rawurldecode($uri->toString(array('path', 'query', 'fragment'))); $urlWithoutQuery = rawurldecode($uri->toString(array('scheme', 'host', 'port', 'path', 'fragment'))); $urlRelWithoutQuery = rawurldecode($uri->toString(array('path', 'fragment'))); // Why is this (still) here? if ((strpos($url, 'mosConfig_') !== false) || (strpos($url, '=http://') !== false)) { JErrorPage::render($error); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from($db->quoteName('#__redirect_links')) ->where( '(' . $db->quoteName('old_url') . ' = ' . $db->quote($url) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlRel) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlWithoutQuery) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlRelWithoutQuery) . ')' ); $db->setQuery($query); $redirect = null; try { $redirects = $db->loadAssocList(); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } $possibleMatches = array_unique( array($url, $urlRel, $urlWithoutQuery, $urlRelWithoutQuery) ); foreach ($possibleMatches as $match) { if (($index = array_search($match, array_column($redirects, 'old_url'))) !== false) { $redirect = (object) $redirects[$index]; if ((int) $redirect->published === 1) { break; } } } // A redirect object was found and, if published, will be used if (!is_null($redirect) && ((int) $redirect->published === 1)) { if (!$redirect->header || (bool) JComponentHelper::getParams('com_redirect')->get('mode', false) === false) { $redirect->header = 301; } if ($redirect->header < 400 && $redirect->header >= 300) { $urlQuery = $uri->getQuery(); $oldUrlParts = parse_url($redirect->old_url); if (empty($oldUrlParts['query']) && $urlQuery !== '') { $redirect->new_url .= '?' . $urlQuery; } $destination = JUri::isInternal($redirect->new_url) ? JRoute::_($redirect->new_url) : $redirect->new_url; $app->redirect($destination, (int) $redirect->header); } JErrorPage::render(new RuntimeException($error->getMessage(), $redirect->header, $error)); } // No redirect object was found so we create an entry in the redirect table elseif (is_null($redirect)) { $params = new Registry(JPluginHelper::getPlugin('system', 'redirect')->params); if ((bool) $params->get('collect_urls', true)) { $data = (object) array( 'id' => 0, 'old_url' => $url, 'referer' => $app->input->server->getString('HTTP_REFERER', ''), 'hits' => 1, 'published' => 0, 'created_date' => JFactory::getDate()->toSql() ); try { $db->insertObject('#__redirect_links', $data, 'id'); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } } } // We have an unpublished redirect object, increment the hit counter else { $redirect->hits += 1; try { $db->updateObject('#__redirect_links', $redirect, 'id'); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } } JErrorPage::render($error); } }