/** * 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('calias')) { $category = Category::oneOrNew($this->get('category')); $this->set('calias', $category->get('path')); } $link .= '§ion=' . $this->get('calias'); $link .= $this->get('alias') ? '&alias=' . $this->get('alias') : '&alias=' . $this->get('id'); // If it doesn't exist or isn't published switch (strtolower($type)) { case 'component': case 'base': return $this->_base; break; case 'vote': $link = $this->_base . '&task=vote&category=article&id=' . $this->get('id'); break; case 'edit': $link .= '&task=edit'; break; case 'delete': $link .= '&task=delete'; break; case 'comments': $link .= '#comments'; break; case 'report': $link = 'index.php?option=com_support&task=reportabuse&category=kb&id=' . $this->get('id'); break; case 'feed': $link .= '/comments.rss'; $feed = Route::url($link); if (substr($feed, 0, 4) != 'http') { $live_site = rtrim(Request::base(), '/'); $feed = $live_site . '/' . ltrim($feed, '/'); } $link = str_replace('https://', 'http://', $feed); break; case 'permalink': default: break; } return $link; }
/** * 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')); }
/** * Show a form for editing an entry * * @param mixed $row * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); if (!is_object($row)) { // Incoming $id = Request::getVar('id', array(0)); if (is_array($id) && !empty($id)) { $id = $id[0]; } // Load category $row = Article::oneOrNew($id); } $this->view->row = $row; // Fail if checked out not by 'me' if ($this->view->row->get('checked_out') && $this->view->row->get('checked_out') != User::get('id')) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_KB_CHECKED_OUT'), 'warning'); return; } if ($this->view->row->isNew()) { $this->view->row->set('created_by', User::get('id')); $this->view->row->set('created', Date::toSql()); } $this->view->params = new Parameter($this->view->row->get('params'), dirname(dirname(__DIR__)) . DS . 'kb.xml'); // Get the sections $this->view->categories = Category::all()->ordered(); /* $m = new KbModelAdminArticle(); $this->view->form = $m->getForm(); */ // Output the HTML $this->view->setLayout('edit')->display(); }
/** * 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; }
/** * Show a form for editing an entry * * @param mixed $row * @return void */ public function editTask($row = null) { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } Request::setVar('hidemainmenu', 1); if (!is_object($row)) { // Incoming $id = Request::getVar('id', array(0)); if (is_array($id) && !empty($id)) { $id = $id[0]; } // Load category $row = Article::oneOrNew($id); } // Fail if checked out not by 'me' if ($row->get('checked_out') && $row->get('checked_out') != User::get('id')) { Notify::warning(Lang::txt('COM_KB_CHECKED_OUT')); return $this->cancelTask(); } if ($row->isNew()) { $row->set('created_by', User::get('id')); $row->set('created', Date::toSql()); } $params = new Parameter($row->get('params'), dirname(dirname(__DIR__)) . DS . 'kb.xml'); // Get the sections $categories = Category::all()->ordered()->rows(); /* $m = new KbModelAdminArticle(); $form = $m->getForm(); */ // Output the HTML $this->view->set('row', $row)->set('params', $params)->set('categories', $categories)->setLayout('edit')->display(); }
/** * Parse the segments of a URL. * * @param array &$segments The segments of the URL to parse. * @return array The URL attributes to be used by the application. */ public function parse(&$segments) { $vars = array(); $vars['task'] = 'categories'; if (empty($segments[0])) { return $vars; } $count = count($segments); // section/ switch ($count) { case 1: $vars['task'] = 'category'; $vars['alias'] = urldecode($segments[0]); $vars['alias'] = str_replace(':', '-', $vars['alias']); break; case 2: $title1 = urldecode($segments[0]); $title1 = str_replace(':', '-', $title1); $title2 = urldecode($segments[1]); $title2 = str_replace(':', '-', $title2); include_once dirname(__DIR__) . DS . 'models' . DS . 'archive.php'; $category = Category::all()->whereEquals('path', $title1 . '/' . $title2)->row(); //$db = \App::get('db'); //$category = Category::oneByAlias($title2); if ($category->get('id')) { // section/category $vars['task'] = 'category'; $vars['id'] = $category->get('id'); //$vars['alias'] = $title2; return $vars; } /*else { $category->loadAlias($title1); }*/ if (!$category->get('id')) { $vars['alias'] = $title2; $vars['task'] = 'article'; $vars['category'] = $title1; return $vars; } /*$article = Article::oneByAliasAndCategory($title2, $category->get('id')); if ($article->get('id')) { // section/article $vars['id'] = $article->get('id'); $vars['task'] = 'article'; //$vars['alias'] = $title2; //urldecode($segments[1]); }*/ break; case 3: // section/category/article // section/article/comments.rss if ($segments[2] == 'comments.rss') { $vars['task'] = 'comments'; $vars['alias'] = urldecode($segments[1]); $vars['alias'] = str_replace(':', '-', $vars['alias']); $vars['category'] = $segments[0]; } else { $vars['task'] = 'article'; if (isset($vars['alias']) && $vars['alias']) { $vars['category'] = $vars['alias']; } else { $vars['category'] = $segments[0]; } $vars['alias'] = urldecode($segments[2]); $vars['alias'] = str_replace(':', '-', $vars['alias']); } break; case 4: // task/category/id/vote // section/category/article/comments.rss if ($segments[3] == 'comments.rss') { $vars['task'] = 'comments'; $vars['alias'] = urldecode($segments[2]); $vars['alias'] = str_replace(':', '-', $vars['alias']); $vars['category'] = $segments[1]; } else { $vars['task'] = $segments[0]; $vars['type'] = $segments[1]; $vars['id'] = $segments[2]; $vars['vote'] = $segments[3]; } break; } return $vars; }