예제 #1
0
 /**
  * Sets up additional custom rules
  *
  * @return  void
  */
 public function setup()
 {
     $this->addRule('old_url', function ($data) {
         $row = Link::blank();
         if (isset($data['id'])) {
             $row->whereEquals('old_url', $data['old_url'])->where('id', '!=', $data['id'])->row();
         }
         return !$row->id ? false : Lang::txt('COM_REDIRECT_ERROR_DUPLICATE_OLD_URL');
     });
 }
예제 #2
0
 /**
  * Sets up additional custom rules
  *
  * @return  void
  */
 public function setup()
 {
     $this->addRule('old_url', function ($data) {
         $entries = Link::blank()->whereEquals('old_url', substr($data['old_url'], 0, 255));
         if (isset($data['id'])) {
             $entries->where('id', '!=', $data['id']);
         }
         $row = $entries->row();
         return !$row->get('id') ? false : Lang::txt('COM_REDIRECT_ERROR_DUPLICATE_OLD_URL');
     });
 }
예제 #3
0
 /**
  * Remove one or more entries
  *
  * @return  void
  */
 public function removeTask()
 {
     // Access check.
     if (!User::authorise('core.delete', $this->_option)) {
         Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
         return $this->cancelTask();
     }
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     $ids = Request::getVar('id', array(), '', 'array');
     if (empty($ids)) {
         Notify::error(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED'));
     }
     $i = 0;
     foreach ($ids as $id) {
         $entry = Link::oneOrFail(intval($id));
         if (!$entry->destroy()) {
             Notify::error($entry->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txts('COM_REDIRECT_N_ITEMS_DELETED', $i));
     }
     $this->cancelTask();
 }
예제 #4
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);
 }
예제 #5
0
 /**
  * Method to publish a list of items
  *
  * @return  void
  */
 public function publishTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Get items to publish from the request.
     $ids = Request::getVar('id', array(), '', 'array');
     $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
     $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int');
     if (empty($ids)) {
         Notify::error(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED'));
     }
     $updated = 0;
     // Loop through all the IDs
     foreach ($ids as $id) {
         $entry = Link::oneOrFail(intval($id));
         $entry->set('published', $value);
         // Remove the items.
         if (!$entry->save()) {
             Notify::error($entry->getError());
             continue;
         }
         $updated++;
     }
     if ($value == 1) {
         $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED';
     } elseif ($value == 0) {
         $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED';
     } elseif ($value == 2) {
         $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED';
     } else {
         $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED';
     }
     Notify::success(Lang::txts($ntext, $updated));
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }
예제 #6
0
 /**
  * Method to publish a list of items
  *
  * @return  void
  */
 public function publishTask()
 {
     // Check for request forgeries
     Request::checkToken() or die(Lang::txt('JINVALID_TOKEN'));
     // Get items to publish from the request.
     $cid = Request::getVar('cid', array(), '', 'array');
     $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
     $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int');
     if (empty($cid)) {
         throw new Exception(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED'), 500);
     } else {
         // Get the model.
         $model = new Record();
         // Make sure the item ids are integers
         \Hubzero\Utility\Arr::toInteger($cid);
         // Publish the items.
         if (!$model->publish($cid, $value)) {
             throw new Exception($model->getError(), 500);
         } else {
             if ($value == 1) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED';
             } elseif ($value == 0) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED';
             } elseif ($value == 2) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED';
             } else {
                 $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED';
             }
             Notify::success(Lang::txts($ntext, count($cid)));
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }