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); // resources // F&R Topics $sFnrTopics = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_FNR_TOPICS, ''); $fnr_topics = !empty($sFnrTopics) ? unserialize($sFnrTopics) : array(); switch (array_shift($stack)) { default: case 'search': @($q = DevblocksPlatform::importGPC($_REQUEST['q'], 'string', '')); $tpl->assign('q', $q); if (!empty($q)) { $feeds = array(); $where = null; if (!empty($fnr_topics)) { $where = sprintf("%s IN (%s)", DAO_FnrExternalResource::TOPIC_ID, implode(',', array_keys($fnr_topics))); } $resources = DAO_FnrExternalResource::getWhere($where); $feeds = Model_FnrExternalResource::searchResources($resources, $q); $tpl->assign('feeds', $feeds); $tpl->assign('sources', $sources); } $tpl->display("devblocks:cerberusweb.fnr:support_center/fnr/search_results.tpl:portal_" . UmPortalHelper::getCode()); break; } }
function doFnrAction() { $q = DevblocksPlatform::importGPC(@$_POST['q'], 'string', ''); $sources = DevblocksPlatform::importGPC(@$_POST['sources'], 'array', array()); @($sources = array_flip($sources)); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $feeds = array(); $where = null; if (!empty($sources)) { $where = sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, implode(',', array_keys($sources))); } $resources = DAO_FnrExternalResource::getWhere($where); $feeds = Model_FnrExternalResource::searchResources($resources, $q); $tpl->assign('terms', $q); $tpl->assign('feeds', $feeds); $tpl->assign('sources', $sources); $tpl->display('file:' . $this->_TPL_PATH . 'results.tpl'); }
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); }
private function _getSearchAction($path) { @($p_query = DevblocksPlatform::importGPC($_REQUEST['query'], 'string', '')); @($p_resources = DevblocksPlatform::importGPC($_REQUEST['resources'], 'string', '')); $resource_where = null; // Specific topics only? if (!empty($p_resources)) { $db = DevblocksPlatform::getDatabaseService(); $resource_ids = DevblocksPlatform::parseCsvString($p_resources); if (!empty($resource_ids)) { $resource_where = sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, $db->qstr(implode(',', $resource_ids))); } } $resources = DAO_FnrExternalResource::getWhere($resource_where); $feeds = Model_FnrExternalResource::searchResources($resources, $p_query); $xml_out = new SimpleXMLElement("<resources></resources>"); foreach ($feeds as $matches) { $eMatch = $xml_out->addChild("resource"); $eMatch->addChild('name', $matches['name']); $eMatch->addChild('topic', $matches['topic_name']); $eMatch->addChild('link', $matches['feed']->link); $eResults = $eMatch->addChild("results"); foreach ($matches['feed'] as $item) { $eResult = $eResults->addChild("result"); if ($item instanceof Zend_Feed_Entry_Rss) { $eResult->addChild('title', (string) $item->title()); $eResult->addChild('link', (string) $item->link()); $eResult->addChild('date', (string) $item->pubDate()); $eResult->addChild('description', (string) $item->description()); } elseif ($item instanceof Zend_Feed_Atom) { $eResult->addChild('title', (string) $item->title()); $eResult->addChild('link', (string) $item->link['href']); $eResult->addChild('date', (string) $item->published()); $eResult->addChild('description', (string) $item->summary()); } } } $this->_render($xml_out->asXML()); }