예제 #1
0
파일: UmScApp.php 프로젝트: joegeck/cerb4
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $umsession = $this->getSession();
     $stack = $response->path;
     $modules = $this->_getModules();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('tpl_path', $tpl_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, 'Support Center');
     $tpl->assign('page_title', $page_title);
     $footer_html = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_FOOTER_HTML, '');
     $tpl->assign('footer_html', $footer_html);
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_CAPTCHA_ENABLED, 1);
     $tpl->assign('captcha_enabled', $captcha_enabled);
     $allow_logins = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_ALLOW_LOGINS, 0);
     $tpl->assign('allow_logins', $allow_logins);
     $allow_subjects = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_ALLOW_SUBJECTS, 0);
     $tpl->assign('allow_subjects', $allow_subjects);
     $sFnrSources = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_FNR_SOURCES, '');
     $fnr_sources = !empty($sFnrSources) ? unserialize($sFnrSources) : array();
     $iKbEnabled = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_KB_ENABLED, 0);
     $tpl->assign('show_search', !empty($fnr_sources) || $iKbEnabled ? true : false);
     $theme = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_THEME, self::DEFAULT_THEME);
     if (!is_dir($tpl_path . 'portal/sc/themes/' . $theme)) {
         $theme = self::DEFAULT_THEME;
     }
     $tpl->assign('theme', $theme);
     @($active_user = $umsession->getProperty('sc_login', null));
     $tpl->assign('active_user', $active_user);
     // Usermeet Session
     if (null == ($fingerprint = parent::getFingerprint())) {
         die("A problem occurred.");
     }
     $tpl->assign('fingerprint', $fingerprint);
     $module_uri = array_shift($stack);
     if (isset($modules[$module_uri])) {
         $mf = DevblocksPlatform::getExtension($modules[$module_uri]['extension_id'], false, true);
     } else {
         $mf = DevblocksPlatform::getExtension($this->default_controller, false, true);
     }
     $menu_modules = array();
     if (is_array($modules)) {
         foreach ($modules as $idx => $item) {
             // Must be menu renderable
             if (!empty($item['menu_title']) && !empty($item['uri'])) {
                 // Must not require login, or we must be logged in
                 // [TODO] Check if the module wants to render (KB not empty, etc.)
                 if (!isset($item['requires_login']) || isset($item['requires_login']) && !empty($active_user)) {
                     // Skip KB in menu if no topics are set
                     // [TODO] Hack (shouldn't be hardcoded in menu logic)
                     if (0 == strcasecmp($item['uri'], 'kb') && !$iKbEnabled) {
                         continue;
                     }
                     $menu_modules[$idx] = $item;
                 }
             }
         }
     }
     $tpl->assign('menu', $menu_modules);
     array_unshift($stack, $module_uri);
     $controller = $mf->createInstance();
     $controller->setPortal($this->getPortal());
     $tpl->assign('module', $controller);
     $tpl->assign('module_response', new DevblocksHttpResponse($stack));
     switch ($module_uri) {
         case 'captcha':
             header('Cache-control: max-age=0', true);
             // 1 wk // , must-revalidate
             header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 604800) . ' GMT');
             // 1 wk
             header('Content-type: image/jpeg');
             //header('Content-length: '. count($jpg));
             //		        // Get CAPTCHA secret passphrase
             $phrase = CerberusApplication::generatePassword(4);
             $umsession->setProperty(UmScApp::SESSION_CAPTCHA, $phrase);
             $im = @imagecreate(150, 70) or die("Cannot Initialize new GD image stream");
             $background_color = imagecolorallocate($im, 240, 240, 240);
             $text_color = imagecolorallocate($im, 40, 40, 40);
             //233, 14, 91
             $font = DEVBLOCKS_PATH . 'resources/font/ryanlerch_-_Tuffy_Bold(2).ttf';
             imagettftext($im, 24, mt_rand(0, 20), 5, 60 + 6, $text_color, $font, $phrase);
             //				$im = imagerotate($im, mt_rand(-20,20), $background_color);
             imagejpeg($im, null, 85);
             imagedestroy($im);
             exit;
             break;
         default:
             // Look up the current module
             $tpl->display('file:' . $tpl_path . 'portal/sc/themes/' . $theme . '/index.tpl');
             break;
     }
 }
예제 #2
0
파일: UmScApp.php 프로젝트: Hildy/cerb5
 function __construct($manifest)
 {
     parent::__construct($manifest);
 }
예제 #3
0
파일: classes.php 프로젝트: joegeck/cerb4
 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;
     }
 }