Пример #1
0
 /**
  * Display
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', '*'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created_date'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'desc'));
     $entries = Link::all();
     if ($filters['state'] != '*') {
         $entries->whereEquals('published', (int) $filters['state']);
     }
     if ($filters['search']) {
         $filters['search'] = strtolower((string) $filters['search']);
         $entries->whereLike('old_url', $filters['search'], 1)->orWhereLike('new_url', $filters['search'], 1)->orWhereLike('comment', $filters['search'], 1)->orWhereLike('referer', $filters['search'], 1)->resetDepth();
     }
     // Get records
     $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated();
     $this->view->set('rows', $rows)->set('filters', $filters)->set('enabled', Helper::isEnabled())->display();
 }
Пример #2
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);
 }