Esempio n. 1
0
 /**
  * Generate and return various links to the entry
  * Link will vary depending upon action desired, such as edit, delete, etc.
  *
  * @param      string $type The type of link to return
  * @return     string
  */
 public function link($type = '')
 {
     $link = $this->_base;
     if (!$this->get('section')) {
         $article = Article::oneOrFail($this->get('entry_id'));
         $this->set('category', $article->category()->get('alias'));
         $this->set('article', $article->get('alias'));
     }
     $link .= '&section=' . $this->get('section');
     $link .= '&alias=' . $this->get('article');
     // If it doesn't exist or isn't published
     switch (strtolower($type)) {
         case 'component':
         case 'base':
             return $this->_base;
             break;
         case 'article':
             // Return as is
             break;
         case 'edit':
             $link .= '&action=edit&comment=' . $this->get('id');
             break;
         case 'delete':
             $link .= '&action=delete&comment=' . $this->get('id');
             break;
         case 'reply':
             $link .= '&reply=' . $this->get('id') . '#c' . $this->get('id');
             break;
         case 'vote':
             $link = $this->_base . '&task=vote&category=comment&id=' . $this->get('id');
             break;
         case 'report':
             $link = 'index.php?option=com_support&task=reportabuse&category=kb&id=' . $this->get('id') . '&parent=' . $this->get('entry_id');
             break;
         case 'permalink':
         default:
             $link .= '#c' . $this->get('id');
             break;
     }
     return $link;
 }
Esempio n. 2
0
 /**
  * Displays an RSS feed of comments for a given article
  *
  * @return  void
  */
 public function commentsTask()
 {
     if (!$this->config->get('feeds_enabled')) {
         throw new Exception(Lang::txt('COM_KB_ERROR_ARTICLE_NOT_FOUND'), 404);
     }
     // Incoming
     $alias = Request::getVar('alias', '');
     $id = Request::getInt('id', 0);
     // Load the article
     $category = Category::oneByAlias(Request::getVar('category'));
     $article = $alias ? Article::oneByAlias($alias) : Article::oneOrFail($id);
     if (!$article->get('id')) {
         throw new Exception(Lang::txt('COM_KB_ERROR_ARTICLE_NOT_FOUND'), 404);
     }
     // Set the mime encoding for the document
     Document::setType('feed');
     // Start a new feed object
     Document::setLink(Route::url($article->link()));
     // Build some basic RSS document information
     $title = Config::get('sitename') . ' - ' . Lang::txt(strtoupper($this->_option));
     $title .= $article->get('title') ? ': ' . stripslashes($article->get('title')) : '';
     $title .= ': ' . Lang::txt('COM_KB_COMMENTS');
     Document::setTitle($title);
     Document::instance()->description = Lang::txt('COM_KB_COMMENTS_RSS_DESCRIPTION', Config::get('sitename'), stripslashes($article->get('title')));
     Document::instance()->copyright = Lang::txt('COM_KB_COMMENTS_RSS_COPYRIGHT', gmdate("Y"), Config::get('sitename'));
     // Start outputing results if any found
     $this->_feedItem($article->comments('list'));
 }
Esempio n. 3
0
 /**
  * Create an item entry
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once PATH_CORE . DS . 'components' . DS . 'com_kb' . DS . 'models' . DS . 'article.php';
     $article = null;
     if (!$id) {
         $category = Category::all()->whereEquals('alias', Request::getVar('category'))->limit(1)->row();
         if (!$category->get('id')) {
             return true;
         }
         $article = Article::all()->whereEquals('alias', Request::getVar('alias', ''))->whereEquals('category', $category->get('id'))->limit(1)->row();
         $id = $article->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$article) {
         $article = Article::oneOrNew($id);
     }
     if ($article->isNew()) {
         $this->setError(Lang::txt('Knowledge base article not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $article->get('id'))->set('created', $article->get('created'))->set('created_by', $article->get('created_by'))->set('title', $article->get('title'))->set('description', \Hubzero\Utility\String::truncate($article->fulltxt(), 200))->set('url', Route::url($article->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Reset the vote count on an entry
  *
  * @return  void
  */
 public function resetvotesTask()
 {
     // Incoming
     $cid = Request::getInt('cid', 0);
     $id = Request::getInt('id', 0);
     // Make sure we have an ID to work with
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_KB_NO_ID'), 'error');
     }
     // Load and reset the article's ratings
     $article = Article::oneOrFail($id);
     $article->set('helpful', 0);
     $article->set('nothelpful', 0);
     if (!$article->save()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $article->getError(), 'error');
         return;
     }
     // Delete all the entries associated with this article
     foreach ($article->votes() as $vote) {
         $vote->destroy();
     }
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
 }
Esempio n. 5
0
 /**
  * Reset the vote count on an entry
  *
  * @return  void
  */
 public function resetvotesTask()
 {
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $cid = Request::getInt('cid', 0);
     $id = Request::getInt('id', 0);
     // Make sure we have an ID to work with
     if (!$id) {
         Notify::warning(Lang::txt('COM_KB_NO_ID'));
         return $this->cancelTask();
     }
     // Load and reset the article's ratings
     $article = Article::oneOrFail($id);
     $article->set('helpful', 0);
     $article->set('nothelpful', 0);
     if (!$article->save()) {
         Notify::error($article->getError());
         return $this->cancelTask();
     }
     // Delete all the entries associated with this article
     foreach ($article->votes()->rows() as $vote) {
         $vote->destroy();
     }
     // Set the redirect
     $this->cancelTask();
 }