Exemplo n.º 1
0
 static function handleError(&$error)
 {
     // Get the application object.
     $app = JFactory::getApplication();
     // 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.
         $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.
             JError::customErrorPage($error);
         }
         // See if the current url exists in the database as a redirect.
         $db = JFactory::getDBO();
         $db->setQuery('SELECT `new_url`, `published`' . ' FROM `#__redirect_links`' . ' WHERE `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, false);
         } else {
             $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
             // If not, add the new url to the database.
             $db->setQuery('INSERT IGNORE INTO `#__redirect_links` (`old_url`, `referer`, `published`, `created_date`)' . ' VALUES (' . $db->Quote($current) . ', ' . $db->Quote($referer) . ', 0, ' . $db->Quote(JFactory::getDate()->toMySQL()) . ')');
             $db->query();
             // Render the error page.
             JError::customErrorPage($error);
         }
     } else {
         // Render the error page.
         JError::customErrorPage($error);
     }
 }
Exemplo n.º 2
0
 static function handleError(&$error)
 {
     // Get the application object.
     $app = JFactory::getApplication();
     // 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.
         $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.
             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 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(JFactory::getDate()->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.
             JError::customErrorPage($error);
         }
     } else {
         // Render the error page.
         JError::customErrorPage($error);
     }
 }
Exemplo n.º 3
0
 static function handleError(&$error)
 {
     // Get the application object.
     $app = JFactory::getApplication();
     // 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', JText::_('PLG_SYSTEM_LOGOUT_REDIRECT'), null, true, false);
     } else {
         // Render the error page.
         JError::customErrorPage($error);
     }
 }
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  $error  The Exception object to be handled.
  *
  * @return  void
  *
  * @since   1.6
  */
 public static function handleError($error)
 {
     // Get the application object.
     $app = JFactory::getApplication();
     // Make sure the error is a 403 and we are in the frontend.
     if ($error->getCode() == 403 && $app->isSite()) {
         // Load language file.
         parent::loadLanguage();
         // Redirect to the home page.
         $app->enqueueMessage(JText::_('PLG_SYSTEM_LOGOUT_REDIRECT'), 'message');
         $app->redirect(JRoute::_('index.php'));
     } else {
         // Render the custom error page.
         JError::customErrorPage($error);
     }
 }
Exemplo n.º 5
0
 /**
  * Custom JError callback
  *
  * Push the exception call stack in the JException returned through the call back
  * adn then rener the custom error page
  *
  * @param object A JException object
  * @return void
  */
 public function errorHandler($error)
 {
     if ($error instanceof Exception) {
         $exception = $error;
         $this->_exception = $exception;
         //store the exception for later use
         //Make sure we have a valid status code
         JError::raiseError(KHttpResponse::isError($exception->getCode()) ? $exception->getCode() : 500, $exception->getMessage());
         return;
     }
     $error->setProperties(array('backtrace' => $this->_exception->getTrace(), 'file' => $this->_exception->getFile(), 'line' => $this->_exception->getLine()));
     $debug = version_compare(JVERSION, '3.0', 'ge') ? JFactory::getConfig()->get('debug') : JFactory::getConfig()->getValue('config.debug');
     if ($debug) {
         $error->set('message', (string) $this->_exception);
     } else {
         $error->set('message', KHttpResponse::getMessage($error->get('code')));
     }
     //Make sure the buffers are cleared
     while (@ob_get_clean()) {
     }
     JError::customErrorPage($error);
 }
Exemplo n.º 6
0
	/**
	 * Custom JError callback
	 *
	 * Push the exception call stack in the JException returned through the call back
	 * adn then rener the custom error page
	 *
	 * @param object A JException object
	 * @return void
	 */
	public function errorHandler($error)
	{
		$error->setProperties(array(
			'backtrace'	=> $this->_exception->getTrace(),
			'file'		=> $this->_exception->getFile(),
			'line'		=> $this->_exception->getLine()
		));
		
		if(KFactory::get('joomla:config')->getValue('config.debug')) {
			$error->set('message', (string) $this->_exception);
		} else {
			$error->set('message', KHttpResponse::getMessage($error->code));
		}
		
		//Make sure the buffers are cleared
		while(@ob_get_clean());
		JError::customErrorPage($error);
	}
Exemplo n.º 7
0
 /**
  * @param stdClass $error
  */
 public function redirectNotAllowed($error)
 {
     if ($error->code == 403) {
         $app = JFactory::getApplication();
         $app->redirect(JURI::base() . 'index.php?option=com_acctexp&task=NotAllowed');
     } else {
         JError::customErrorPage($error);
     }
 }
Exemplo n.º 8
0
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  &$error  The Exception object to be handled.
  *
  * @return  void
  *
  * @since   1.6
  */
 public static function handleError(&$error)
 {
     // Get the application object.
     $app = JFactory::getApplication();
     // 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.
         $uri = JUri::getInstance();
         $current = rawurldecode($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.
             JError::customErrorPage($error);
         }
         // See if the current url exists in the database as a redirect.
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->select($db->quoteName(array('new_url', 'header')))->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 no published redirect was found try with the server-relative URL
         if (!$link or $link->published != 1) {
             $currRel = rawurldecode($uri->toString(array('path', 'query', 'fragment')));
             $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($currRel));
             $db->setQuery($query, 0, 1);
             $link = $db->loadObject();
         }
         // If a redirect exists and is published, permanently redirect.
         if ($link and $link->published == 1) {
             // If no header is set use a 301 permanent redirect
             if (!$link->header || JComponentHelper::getParams('com_redirect')->get('mode', 0) == false) {
                 $link->header = 301;
             }
             // If we have a redirect in the 300 range use JApplicationWeb::redirect().
             if ($link->header < 400 && $link->header >= 300) {
                 $new_link = JUri::isInternal($link->new_url) ? JRoute::_($link->new_url) : $link->new_url;
                 $app->redirect($new_link, intval($link->header));
             } else {
                 // Else rethrow the exeception with the new header and return
                 try {
                     throw new RuntimeException($error->getMessage(), $link->header, $error);
                 } catch (Exception $e) {
                     $newError = $e;
                 }
                 JError::customErrorPage($newError);
             }
         } else {
             $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
             $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__redirect_links'))->where($db->quoteName('old_url') . ' = ' . $db->quote($current));
             $db->setQuery($query);
             $res = $db->loadResult();
             if (!$res) {
                 // If not, add the new url to the database but only if option is enabled
                 $params = new Registry(JPluginHelper::getPlugin('system', 'redirect')->params);
                 $collect_urls = $params->get('collect_urls', 1);
                 if ($collect_urls == true) {
                     $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->clear()->insert($db->quoteName('#__redirect_links'), false)->columns($columns)->values($db->quote($current) . ', ' . $db->quote('') . ' ,' . $db->quote($referer) . ', ' . $db->quote('') . ',1,0, ' . $db->quote(JFactory::getDate()->toSql()));
                     $db->setQuery($query);
                     $db->execute();
                 }
             } else {
                 // Existing error url, increase hit counter.
                 $query->clear()->update($db->quoteName('#__redirect_links'))->set($db->quoteName('hits') . ' = ' . $db->quoteName('hits') . ' + 1')->where('id = ' . (int) $res);
                 $db->setQuery($query);
                 $db->execute();
             }
             // Render the error page.
             JError::customErrorPage($error);
         }
     } else {
         // Render the error page.
         JError::customErrorPage($error);
     }
 }
Exemplo n.º 9
0
 /**
  * Callback to handle both JError and Exception
  * 
  * @param KCommandContext $context Command chain context
  * caller => KObject, data => mixed
  * 
  * @return KException
  */
 protected function _actionException($context)
 {
     $error = $context->data;
     if ($context->response->getHeader('Location')) {
         $context->response->send();
         exit(0);
     }
     JError::customErrorPage($error);
     exit(0);
 }
Exemplo n.º 10
0
 /**
  * Custom JError callback
  *
  * Push the exception call stack in the JException returned through the call back
  * adn then rener the custom error page
  *
  * @param object A JException object
  * @return void
  */
 public function errorHandler($error)
 {
     $error->setProperties(array('backtrace' => $this->_exception->getTrace(), 'file' => $this->_exception->getFile(), 'line' => $this->_exception->getLine()));
     if (JFactory::getConfig()->getValue('config.debug')) {
         $error->set('message', (string) $this->_exception);
     } else {
         $error->set('message', KHttpResponse::getMessage($error->get('code')));
     }
     if ($this->_exception->getCode() == KHttpResponse::UNAUTHORIZED) {
         header('WWW-Authenticate: Basic Realm="' . KRequest::base() . '"');
     }
     //Make sure the buffers are cleared
     while (@ob_get_clean()) {
     }
     JError::customErrorPage($error);
 }