Example #1
0
File: kb.php Project: Hildy/cerb5
 function writeResponse(DevblocksHttpResponse $response)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(dirname(__FILE__))) . '/templates/';
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     $stack = $response->path;
     array_shift($stack);
     // kb
     // KB Roots
     $sKbRoots = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_KB_ROOTS, '');
     $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
     $kb_roots_str = '0';
     if (!empty($kb_roots)) {
         $kb_roots_str = implode(',', array_keys($kb_roots));
     }
     switch (array_shift($stack)) {
         case 'search':
             @($q = DevblocksPlatform::importGPC($_REQUEST['q'], 'string', ''));
             $tpl->assign('q', $q);
             if (null == ($view = UmScAbstractViewLoader::getView('', UmSc_KbArticleView::DEFAULT_ID))) {
                 $view = new UmSc_KbArticleView();
             }
             $view->name = "";
             $view->params = array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, DevblocksSearchCriteria::OPER_FULLTEXT, $q), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, DevblocksSearchCriteria::OPER_FULLTEXT, $q)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots)));
             UmScAbstractViewLoader::setView($view->id, $view);
             $tpl->assign('view', $view);
             $tpl->display("devblocks:cerberusweb.kb:support_center/kb/search_results.tpl:portal_" . UmPortalHelper::getCode());
             break;
         case 'article':
             if (empty($kb_roots)) {
                 return;
             }
             $id = intval(array_shift($stack));
             list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::ID, '=', $id), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
             if (!isset($articles[$id])) {
                 break;
             }
             $article = DAO_KbArticle::get($id);
             $tpl->assign('article', $article);
             @($article_list = $umsession->getProperty(self::SESSION_ARTICLE_LIST, array()));
             if (!empty($article) && !isset($article_list[$id])) {
                 DAO_KbArticle::update($article->id, array(DAO_KbArticle::VIEWS => ++$article->views));
                 $article_list[$id] = $id;
                 $umsession->setProperty(self::SESSION_ARTICLE_LIST, $article_list);
             }
             $categories = DAO_KbCategory::getWhere();
             $tpl->assign('categories', $categories);
             $cats = DAO_KbArticle::getCategoriesByArticleId($id);
             $breadcrumbs = array();
             foreach ($cats as $cat_id) {
                 if (!isset($breadcrumbs[$cat_id])) {
                     $breadcrumbs[$cat_id] = array();
                 }
                 $pid = $cat_id;
                 while ($pid) {
                     $breadcrumbs[$cat_id][] = $pid;
                     $pid = $categories[$pid]->parent_id;
                 }
                 $breadcrumbs[$cat_id] = array_reverse($breadcrumbs[$cat_id]);
                 // Remove any breadcrumbs not in this SC profile
                 $pid = reset($breadcrumbs[$cat_id]);
                 if (!isset($kb_roots[$pid])) {
                     unset($breadcrumbs[$cat_id]);
                 }
             }
             $tpl->assign('breadcrumbs', $breadcrumbs);
             $tpl->display("devblocks:cerberusweb.kb:support_center/kb/article.tpl:portal_" . UmPortalHelper::getCode());
             break;
         default:
         case 'browse':
             @($root = intval(array_shift($stack)));
             $tpl->assign('root_id', $root);
             $categories = DAO_KbCategory::getWhere();
             $tpl->assign('categories', $categories);
             $tree_map = DAO_KbCategory::getTreeMap(0);
             // Remove other top-level categories
             if (is_array($tree_map[0])) {
                 foreach ($tree_map[0] as $child_id => $count) {
                     if (!isset($kb_roots[$child_id])) {
                         unset($tree_map[0][$child_id]);
                     }
                 }
             }
             // Remove empty categories
             if (is_array($tree_map[0])) {
                 foreach ($tree_map as $node_id => $children) {
                     foreach ($children as $child_id => $count) {
                         if (empty($count)) {
                             @($pid = $categories[$child_id]->parent_id);
                             unset($tree_map[$pid][$child_id]);
                             unset($tree_map[$child_id]);
                         }
                     }
                 }
             }
             $tpl->assign('tree', $tree_map);
             // Breadcrumb // [TODO] API-ize inside Model_KbTree ?
             $breadcrumb = array();
             $pid = $root;
             while (0 != $pid) {
                 $breadcrumb[] = $pid;
                 $pid = $categories[$pid]->parent_id;
             }
             $tpl->assign('breadcrumb', array_reverse($breadcrumb));
             $tpl->assign('mid', @intval(ceil(count($tree_map[$root]) / 2)));
             // Articles
             if (null == ($view = UmScAbstractViewLoader::getView('', UmSc_KbArticleView::DEFAULT_ID))) {
                 $view = new UmSc_KbArticleView();
             }
             if (!empty($root)) {
                 $view->params = array(new DevblocksSearchCriteria(SearchFields_KbArticle::CATEGORY_ID, '=', $root), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots)));
             } else {
                 // Most Popular Articles
                 $view->params = array(new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots)));
             }
             $view->name = "";
             $view->renderSortBy = SearchFields_KbArticle::VIEWS;
             $view->renderSortAsc = false;
             $view->renderPage = 0;
             $view->renderLimit = 10;
             UmScAbstractViewLoader::setView($view->id, $view);
             $tpl->assign('view', $view);
             $tpl->display("devblocks:cerberusweb.kb:support_center/kb/index.tpl:portal_" . UmPortalHelper::getCode());
             break;
     }
 }
Example #2
0
 function writeResponse(DevblocksHttpResponse $response)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $theme = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_THEME, UmScApp::DEFAULT_THEME);
     if (!is_dir($tpl_path . 'portal/sc/themes/' . $theme)) {
         $theme = UmScApp::DEFAULT_THEME;
     }
     $umsession = $this->getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     $stack = $response->path;
     @($module = array_shift($stack));
     switch ($module) {
         default:
         case 'home':
             $sHomeRss = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_HOME_RSS, '');
             $aHomeRss = !empty($sHomeRss) ? unserialize($sHomeRss) : array();
             $feeds = array();
             // [TODO] Implement a feed cache so we aren't bombing out
             foreach ($aHomeRss as $title => $url) {
                 $feed = null;
                 try {
                     $feed = Zend_Feed::import($url);
                 } catch (Exception $e) {
                 }
                 if (!empty($feed) && $feed->count()) {
                     $feeds[] = array('name' => $title, 'feed' => $feed);
                 }
             }
             $tpl->assign('feeds', $feeds);
             $tpl->display("file:{$tpl_path}portal/sc/internal/home/index.tpl");
             break;
         case 'account':
             if (!$this->allow_logins || empty($active_user)) {
                 break;
             }
             $address = DAO_Address::get($active_user->id);
             $tpl->assign('address', $address);
             $tpl->display("file:{$tpl_path}portal/sc/internal/account/index.tpl");
             break;
         case 'kb':
             // KB Roots
             $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, '');
             $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
             $kb_roots_str = '0';
             if (!empty($kb_roots)) {
                 $kb_roots_str = implode(',', array_keys($kb_roots));
             }
             switch (array_shift($stack)) {
                 case 'article':
                     if (empty($kb_roots)) {
                         return;
                     }
                     $id = intval(array_shift($stack));
                     list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::ID, '=', $id), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
                     if (!isset($articles[$id])) {
                         break;
                     }
                     $article = DAO_KbArticle::get($id);
                     $tpl->assign('article', $article);
                     @($article_list = $umsession->getProperty(UmScApp::SESSION_ARTICLE_LIST, array()));
                     if (!empty($article) && !isset($article_list[$id])) {
                         DAO_KbArticle::update($article->id, array(DAO_KbArticle::VIEWS => ++$article->views));
                         $article_list[$id] = $id;
                         $umsession->setProperty(UmScApp::SESSION_ARTICLE_LIST, $article_list);
                     }
                     $categories = DAO_KbCategory::getWhere();
                     $tpl->assign('categories', $categories);
                     $cats = DAO_KbArticle::getCategoriesByArticleId($id);
                     $breadcrumbs = array();
                     foreach ($cats as $cat_id) {
                         if (!isset($breadcrumbs[$cat_id])) {
                             $breadcrumbs[$cat_id] = array();
                         }
                         $pid = $cat_id;
                         while ($pid) {
                             $breadcrumbs[$cat_id][] = $pid;
                             $pid = $categories[$pid]->parent_id;
                         }
                         $breadcrumbs[$cat_id] = array_reverse($breadcrumbs[$cat_id]);
                         // Remove any breadcrumbs not in this SC profile
                         $pid = reset($breadcrumbs[$cat_id]);
                         if (!isset($kb_roots[$pid])) {
                             unset($breadcrumbs[$cat_id]);
                         }
                     }
                     $tpl->assign('breadcrumbs', $breadcrumbs);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/kb/article.tpl");
                     break;
                 default:
                 case 'browse':
                     @($root = intval(array_shift($stack)));
                     $tpl->assign('root_id', $root);
                     $categories = DAO_KbCategory::getWhere();
                     $tpl->assign('categories', $categories);
                     $tree_map = DAO_KbCategory::getTreeMap(0);
                     // Remove other top-level categories
                     if (is_array($tree_map[0])) {
                         foreach ($tree_map[0] as $child_id => $count) {
                             if (!isset($kb_roots[$child_id])) {
                                 unset($tree_map[0][$child_id]);
                             }
                         }
                     }
                     // Remove empty categories
                     if (is_array($tree_map[0])) {
                         foreach ($tree_map as $node_id => $children) {
                             foreach ($children as $child_id => $count) {
                                 if (empty($count)) {
                                     @($pid = $categories[$child_id]->parent_id);
                                     unset($tree_map[$pid][$child_id]);
                                     unset($tree_map[$child_id]);
                                 }
                             }
                         }
                     }
                     $tpl->assign('tree', $tree_map);
                     // Breadcrumb // [TODO] API-ize inside Model_KbTree ?
                     $breadcrumb = array();
                     $pid = $root;
                     while (0 != $pid) {
                         $breadcrumb[] = $pid;
                         $pid = $categories[$pid]->parent_id;
                     }
                     $tpl->assign('breadcrumb', array_reverse($breadcrumb));
                     $tpl->assign('mid', @intval(ceil(count($tree_map[$root]) / 2)));
                     // Articles
                     if (!empty($root)) {
                         list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::CATEGORY_ID, '=', $root), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
                     }
                     $tpl->assign('articles', $articles);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/kb/index.tpl");
                     break;
             }
             break;
         case 'answers':
             $query = rawurldecode(array_shift($stack));
             $tpl->assign('query', $query);
             $sFnrSources = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_FNR_SOURCES, '');
             $aFnrSources = !empty($sFnrSources) ? unserialize($sFnrSources) : array();
             if (!empty($query)) {
                 // [JAS]: If we've been customized with specific sources, use them
                 $where = !empty($aFnrSources) ? sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, implode(',', array_keys($aFnrSources))) : sprintf("%s IN (-1)", DAO_FnrExternalResource::ID);
                 $resources = DAO_FnrExternalResource::getWhere($where);
                 $feeds = Model_FnrExternalResource::searchResources($resources, $query);
                 $tpl->assign('feeds', $feeds);
                 $fields = array(DAO_FnrQuery::QUERY => $query, DAO_FnrQuery::CREATED => time(), DAO_FnrQuery::SOURCE => $this->getPortal(), DAO_FnrQuery::NO_MATCH => empty($feeds) ? 1 : 0);
                 DAO_FnrQuery::create($fields);
             }
             // KB
             $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, '');
             $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
             list($articles, $count) = DAO_KbArticle::search(array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, 'fulltext', $query), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, 'fulltext', $query)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 100, 0, null, null, true);
             $tpl->assign('articles', $articles);
             $tpl->display("file:{$tpl_path}portal/sc/internal/answers/index.tpl");
             break;
         case 'contact':
             $response = array_shift($stack);
             $settings = CerberusSettings::getInstance();
             $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
             $tpl->assign('default_from', $default_from);
             switch ($response) {
                 case 'confirm':
                     $tpl->assign('last_opened', $umsession->getProperty('support.write.last_opened', ''));
                     $tpl->display("file:{$tpl_path}portal/sc/internal/contact/confirm.tpl");
                     break;
                 default:
                 case 'step1':
                     $umsession->setProperty('support.write.last_error', null);
                 case 'step2':
                     $sFrom = $umsession->getProperty('support.write.last_from', '');
                     $sSubject = $umsession->getProperty('support.write.last_subject', '');
                     $sNature = $umsession->getProperty('support.write.last_nature', '');
                     $sContent = $umsession->getProperty('support.write.last_content', '');
                     //		    			$aLastFollowupQ = $umsession->getProperty('support.write.last_followup_q','');
                     $aLastFollowupA = $umsession->getProperty('support.write.last_followup_a', '');
                     $sError = $umsession->getProperty('support.write.last_error', '');
                     $tpl->assign('last_from', $sFrom);
                     $tpl->assign('last_subject', $sSubject);
                     $tpl->assign('last_nature', $sNature);
                     $tpl->assign('last_content', $sContent);
                     //						$tpl->assign('last_followup_q', $aLastFollowupQ);
                     $tpl->assign('last_followup_a', $aLastFollowupA);
                     $tpl->assign('last_error', $sError);
                     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_DISPATCH, '');
                     //		    			$dispatch = !empty($sDispatch) ? (is_array($sDispatch) ? unserialize($sDispatch): array($sDispatch)) : array();
                     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
                     $tpl->assign('dispatch', $dispatch);
                     switch ($response) {
                         default:
                             // If there's only one situation, skip to step2
                             if (1 == count($dispatch)) {
                                 @($sNature = md5(key($dispatch)));
                                 $umsession->setProperty('support.write.last_nature', $sNature);
                                 reset($dispatch);
                             } else {
                                 $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step1.tpl");
                                 break;
                             }
                         case 'step2':
                             // Cache along with answers?
                             if (is_array($dispatch)) {
                                 foreach ($dispatch as $k => $v) {
                                     if (md5($k) == $sNature) {
                                         $umsession->setProperty('support.write.last_nature_string', $k);
                                         $tpl->assign('situation', $k);
                                         $tpl->assign('situation_params', $v);
                                         break;
                                     }
                                 }
                             }
                             $ticket_fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
                             $tpl->assign('ticket_fields', $ticket_fields);
                             $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step2.tpl");
                             break;
                     }
                     break;
             }
             break;
             //				$tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl");
             //				break;
         //				$tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl");
         //				break;
         case 'history':
             if (!$this->allow_logins || empty($active_user)) {
                 break;
             }
             $mask = array_shift($stack);
             if (empty($mask)) {
                 list($open_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 0)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false);
                 $tpl->assign('open_tickets', $open_tickets);
                 list($closed_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 1)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false);
                 $tpl->assign('closed_tickets', $closed_tickets);
                 $tpl->display("file:{$tpl_path}portal/sc/internal/history/index.tpl");
             } else {
                 // Secure retrieval (address + mask)
                 list($tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MASK, '=', $mask), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id)), 1, 0, null, null, false);
                 $ticket = array_shift($tickets);
                 // Security check (mask compare)
                 if (0 == strcasecmp($ticket[SearchFields_Ticket::TICKET_MASK], $mask)) {
                     $messages = DAO_Ticket::getMessagesByTicket($ticket[SearchFields_Ticket::TICKET_ID]);
                     $messages = array_reverse($messages, true);
                     $tpl->assign('ticket', $ticket);
                     $tpl->assign('messages', $messages);
                     $tpl->display("file:{$tpl_path}portal/sc/internal/history/display.tpl");
                 }
             }
             break;
         case 'register':
             if (!$this->allow_logins) {
                 break;
             }
             @($step = array_shift($stack));
             switch ($step) {
                 case 'forgot':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot.tpl");
                     break;
                 case 'forgot2':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot_confirm.tpl");
                     break;
                 case 'confirm':
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/confirm.tpl");
                     break;
                 default:
                     $tpl->display("file:{$tpl_path}portal/sc/internal/register/index.tpl");
                     break;
             }
             break;
     }
     //		print_r($response);
 }
Example #3
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('tpl_path', dirname(__FILE__) . '/templates/');
     $umsession = $this->getSession();
     $stack = $response->path;
     $logo_url = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_LOGO_URL, '');
     $tpl->assign('logo_url', $logo_url);
     $page_title = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_PAGE_TITLE, 'Knowledgebase');
     $tpl->assign('page_title', $page_title);
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_CAPTCHA_ENABLED, 1);
     $tpl->assign('captcha_enabled', $captcha_enabled);
     // KB Roots
     $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_KB_ROOTS, '');
     $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array();
     $kb_roots_str = '0';
     if (!empty($kb_roots)) {
         $kb_roots_str = implode(',', array_keys($kb_roots));
     }
     // Usermeet Session
     if (null == ($fingerprint = parent::getFingerprint())) {
         die("A problem occurred.");
     }
     $tpl->assign('fingerprint', $fingerprint);
     switch (array_shift($stack)) {
         case 'rss':
             header("Content-type: application/rss+xml");
             switch (array_shift($stack)) {
                 case 'recent_changes':
                     list($results, $null) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 25, 0, SearchFields_KbArticle::UPDATED, false, false);
                     if (is_array($results) && !empty($results)) {
                         $full_articles = DAO_KbArticle::getWhere(sprintf("%s IN (%s)", DAO_KbArticle::ID, implode(',', array_keys($results))));
                     }
                     $order = array_keys($results);
                     $articles = array();
                     foreach ($order as $id) {
                         $articles[$id] =& $full_articles[$id];
                     }
                     $this->_writeArticlesAsRss($articles, $page_title);
                     break;
                 case 'most_popular':
                     list($results, $null) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 25, 0, SearchFields_KbArticle::VIEWS, false, false);
                     if (is_array($results) && !empty($results)) {
                         $full_articles = DAO_KbArticle::getWhere(sprintf("%s IN (%s)", DAO_KbArticle::ID, implode(',', array_keys($results))));
                     }
                     $order = array_keys($results);
                     $articles = array();
                     foreach ($order as $id) {
                         $articles[$id] =& $full_articles[$id];
                     }
                     $this->_writeArticlesAsRss($articles, $page_title);
                     break;
                 case 'search':
                     $query = rawurldecode(array_shift($stack));
                     list($articles, $count) = DAO_KbArticle::search(array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, 'fulltext', $query), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, 'fulltext', $query)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 50, 0, null, null, true);
                     if (!empty($articles)) {
                         $articles = DAO_KbArticle::getWhere(sprintf("%s IN (%s)", DAO_KbArticle::ID, implode(',', array_keys($articles))));
                     }
                     $this->_writeArticlesAsRss($articles, $page_title);
                     break;
                     //					case 'article':
                     //						$id = intval(array_shift($stack));
                     //
                     //						// [TODO] Convert to KB categories
                     //						$articles = DAO_KbArticle::getWhere(sprintf("%s = %d AND %s = '%s'",
                     //							DAO_KbArticle::ID,
                     //							$id,
                     //							DAO_KbArticle::TITLE,
                     //							$this->getPortal()
                     //						));
                     //
                     //						$this->_writeArticlesAsRss($articles, $page_title);
                     //
                     //						break;
             }
             break;
         case 'search':
             @($query = urldecode(array_shift($stack)));
             $session = $this->getSession();
             if (!empty($query)) {
                 $session->setProperty('last_query', $query);
             } else {
                 $query = $session->getProperty('last_query', '');
             }
             list($articles, $count) = DAO_KbArticle::search(array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, 'fulltext', $query), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, 'fulltext', $query)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 100, 0, null, null, true);
             $tpl->assign('query', $query);
             $tpl->assign('articles', $articles);
             $tpl->assign('count', $count);
             $tpl->display('file:' . dirname(__FILE__) . '/templates/portal/kb/search.tpl');
             break;
             //			case 'import':
             //				if(empty($editor))
             //					break;
             //
             //				$tpl->display('file:' . dirname(__FILE__) . '/templates/portal/kb/public_config/import.tpl');
             //				break;
         //			case 'import':
         //				if(empty($editor))
         //					break;
         //
         //				$tpl->display('file:' . dirname(__FILE__) . '/templates/portal/kb/public_config/import.tpl');
         //				break;
         case 'article':
             // If no roots are enabled, no articles are visible
             if (empty($kb_roots)) {
                 return;
             }
             $id = intval(array_shift($stack));
             list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::ID, '=', $id), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
             if (!isset($articles[$id])) {
                 break;
             }
             $article = DAO_KbArticle::get($id);
             $tpl->assign('article', $article);
             @($article_list = $umsession->getProperty(self::SESSION_ARTICLE_LIST, array()));
             if (!empty($article) && !isset($article_list[$id])) {
                 DAO_KbArticle::update($article->id, array(DAO_KbArticle::VIEWS => ++$article->views));
                 $article_list[$id] = $id;
                 $umsession->setProperty(self::SESSION_ARTICLE_LIST, $article_list);
             }
             $categories = DAO_KbCategory::getWhere();
             $tpl->assign('categories', $categories);
             $cats = DAO_KbArticle::getCategoriesByArticleId($id);
             $breadcrumbs = array();
             foreach ($cats as $cat_id) {
                 if (!isset($breadcrumbs[$cat_id])) {
                     $breadcrumbs[$cat_id] = array();
                 }
                 $pid = $cat_id;
                 while ($pid) {
                     $breadcrumbs[$cat_id][] = $pid;
                     $pid = $categories[$pid]->parent_id;
                 }
                 $breadcrumbs[$cat_id] = array_reverse($breadcrumbs[$cat_id]);
                 // Remove any breadcrumbs not in this SC profile
                 $pid = reset($breadcrumbs[$cat_id]);
                 if (!isset($kb_roots[$pid])) {
                     unset($breadcrumbs[$cat_id]);
                 }
             }
             $tpl->assign('breadcrumbs', $breadcrumbs);
             $tpl->display('file:' . dirname(__FILE__) . '/templates/portal/kb/article.tpl');
             break;
         case 'browse':
         default:
             // [TODO] Root
             @($root = intval(array_shift($stack)));
             $tpl->assign('root_id', $root);
             $categories = DAO_KbCategory::getWhere();
             $tpl->assign('categories', $categories);
             $tree_map = DAO_KbCategory::getTreeMap(0);
             // Remove other top-level categories
             if (is_array($tree_map[0])) {
                 foreach ($tree_map[0] as $child_id => $count) {
                     if (!isset($kb_roots[$child_id])) {
                         unset($tree_map[0][$child_id]);
                     }
                 }
             }
             // Remove empty categories
             if (is_array($tree_map[0])) {
                 foreach ($tree_map as $node_id => $children) {
                     foreach ($children as $child_id => $count) {
                         if (empty($count)) {
                             @($pid = $categories[$child_id]->parent_id);
                             unset($tree_map[$pid][$child_id]);
                             unset($tree_map[$child_id]);
                         }
                     }
                 }
             }
             $tpl->assign('tree', $tree_map);
             // Breadcrumb // [TODO] API-ize inside Model_KbTree ?
             $breadcrumb = array();
             $pid = $root;
             while (0 != $pid) {
                 $breadcrumb[] = $pid;
                 $pid = $categories[$pid]->parent_id;
             }
             $tpl->assign('breadcrumb', array_reverse($breadcrumb));
             $tpl->assign('mid', @intval(ceil(count($tree_map[$root]) / 2)));
             // Articles
             $articles = array();
             if (!empty($root)) {
                 list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::CATEGORY_ID, '=', $root), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false);
                 $tpl->assign('articles', $articles);
             }
             $tpl->display('file:' . dirname(__FILE__) . '/templates/portal/kb/index.tpl');
             break;
     }
 }
Example #4
0
 function showArticleEditPanelAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.kb.articles.modify')) {
         return;
     }
     @($id = DevblocksPlatform::importGPC($_REQUEST['id']));
     @($root_id = DevblocksPlatform::importGPC($_REQUEST['root_id']));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('root_id', $root_id);
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     $tpl->assign('view_id', $view_id);
     if (!empty($id)) {
         $article = DAO_KbArticle::get($id);
         $tpl->assign('article', $article);
         $article_categories = DAO_KbArticle::getCategoriesByArticleId($id);
         $tpl->assign('article_categories', $article_categories);
     }
     $categories = DAO_KbCategory::getWhere();
     $tpl->assign('categories', $categories);
     $levels = DAO_KbCategory::getTree(0);
     //$root_id
     $tpl->assign('levels', $levels);
     $tpl->display('file:' . $this->_TPL_PATH . 'ajax/article_edit_panel.tpl');
 }
Example #5
0
 function showArticleEditPanelAction()
 {
     @($id = DevblocksPlatform::importGPC($_REQUEST['id']));
     @($root_id = DevblocksPlatform::importGPC($_REQUEST['root_id']));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('root_id', $root_id);
     if (!empty($id)) {
         $article = DAO_KbArticle::get($id);
         $tpl->assign('article', $article);
         $article_categories = DAO_KbArticle::getCategoriesByArticleId($id);
         $tpl->assign('article_categories', $article_categories);
     }
     $categories = DAO_KbCategory::getWhere();
     $tpl->assign('categories', $categories);
     $levels = DAO_KbCategory::getTree(0);
     //$root_id
     $tpl->assign('levels', $levels);
     $tpl->display('file:' . $this->_TPL_PATH . 'ajax/article_edit_panel.tpl');
 }