Пример #1
0
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  &$error  The Exception object to be handled.
  * @return  void
  */
 public static function handleError(&$error)
 {
     $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template')->template, App::get('config')->get('debug'));
     // Make sure the error is a 404 and we are not in the administrator.
     if (!App::isAdmin() and $error->getCode() == 404) {
         // Render the error page.
         $renderer->render($error);
     }
     // Get the full current URI.
     $uri = JURI::getInstance();
     $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.
         $renderer->render($error);
     }
     // See if the current url exists in the database as a redirect.
     $db = App::get('db');
     $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 no published redirect was found try with the server-relative URL
     if (!$link or $link->published != 1) {
         $currRel = $uri->toString(array('path', 'query', 'fragment'));
         $db->setQuery('SELECT ' . $db->quoteName('new_url') . ', ' . $db->quoteName('published') . ' FROM ' . $db->quoteName('#__redirect_links') . ' WHERE ' . $db->quoteName('old_url') . ' = ' . $db->quote($currRel), 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, false);
     } else {
         $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 (!$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('hits'), $db->quoteName('published'), $db->quoteName('created_date'));
             $query->columns($columns);
             $query->values($db->Quote($current) . ', ' . $db->Quote('') . ' ,' . $db->Quote($referer) . ', ' . $db->Quote('') . ',1,0, ' . $db->Quote(Date::toSql()));
             $db->setQuery($query);
             $db->query();
         } else {
             // Existing error url, increase hit counter
             $query = $db->getQuery(true);
             $query->update($db->quoteName('#__redirect_links'));
             $query->set($db->quoteName('hits') . ' = ' . $db->quoteName('hits') . ' + 1');
             $query->where('id = ' . (int) $res);
             $db->setQuery((string) $query);
             $db->query();
         }
         // Render the error page.
         $renderer->render($error);
     }
 }
Пример #2
0
 /**
  * Handle an error
  *
  * @param   object  $error
  * @return  void
  */
 public static function handleError(&$error)
 {
     // Make sure the error is a 403 and we are in the frontend.
     if ($error->getCode() == 403 and App::isSite()) {
         // Redirect to the home page
         App::redirect('index.php', Lang::txt('PLG_SYSTEM_LOGOUT_REDIRECT'), null, true, false);
     } else {
         // Render the error page.
         $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template')->template, App::get('config')->get('debug'));
         $renderer->render($error);
     }
 }
Пример #3
0
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  &$error  The Exception object to be handled.
  * @return  void
  */
 public static function handleError(&$error)
 {
     $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template.loader'), App::get('config')->get('debug'));
     // Make sure the error is a 404 and we are not in the administrator.
     if (!App::isSite() || $error->getCode() != 404) {
         // Render the error page.
         return $renderer->render($error);
     }
     // Get the full current URI.
     $uri = Hubzero\Utility\Uri::getInstance();
     $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.
         return $renderer->render($error);
     }
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_redirect' . DS . 'models' . DS . 'link.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_redirect' . DS . 'models' . DS . 'link.php';
         // See if the current url exists in the database as a redirect.
         $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $current)->row();
         // If no published redirect was found try with the server-relative URL
         if (!$link->get('id') || $link->get('published') != 1) {
             $currRel = $uri->toString(array('path', 'query', 'fragment'));
             $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $currRel)->row();
         }
         // If a redirect exists and is published, permanently redirect.
         if ($link->get('id') && $link->get('published') == 1) {
             App::redirect($link->new_url, null, null, true, false);
         }
         $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
         $row = \Components\Redirect\Models\Link::all()->whereEquals('old_url', substr($current, 0, 255))->row();
         if (!$row->get('id')) {
             $row->set(['old_url' => $current, 'new_url' => '', 'referer' => $referer, 'comment' => '', 'hits' => 1, 'published' => 0, 'created_date' => Date::toSql()]);
         } else {
             $row->set('hits', intval($row->get('hits', 0)) + 1);
         }
         try {
             $row->save();
         } catch (Exception $e) {
             // Do nothing for now.
             // @TODO  Log this?
         }
     }
     // Render the error page.
     $renderer->render($error);
 }