4 * @file HelpHandler.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
12 * @brief Handle requests for viewing help pages.
15 // $Id: HelpHandler.inc.php,v 1.5 2009/05/12 20:12:44 asmecher Exp $
18 define('HELP_DEFAULT_TOPIC', 'index/topic/000000');
19 define('HELP_DEFAULT_TOC', 'index/toc/000000');
21 import('help.HelpToc');
22 import('help.HelpTocDAO');
23 import('help.HelpTopic');
24 import('help.HelpTopicDAO');
25 import('help.HelpTopicSection');
26 import('handler.Handler');
29 class HelpHandler
extends Handler
{
30 function HelpHandler() {
35 * Display help table of contents.
38 $this->view(array('index', 'topic', '000000'));
43 $this->setupTemplate();
45 $templateMgr =& TemplateManager
::getManager();
46 $help =& Help
::getHelp();
47 $templateMgr->assign_by_ref('helpToc', $help->getTableOfContents());
48 $templateMgr->display('help/helpToc.tpl');
52 * Display the selected help topic.
53 * @param $args array first parameter is the ID of the topic to display
55 function view($args) {
57 $this->setupTemplate();
59 $topicId = implode('/',$args);
60 $keyword = trim(String::regexp_replace('/[^\w\s\.\-]/', '', strip_tags(Request
::getUserVar('keyword'))));
61 $result = (int) Request
::getUserVar('result');
63 $topicDao =& DAORegistry
::getDAO('HelpTopicDAO');
64 $topic = $topicDao->getTopic($topicId);
66 if ($topic === false) {
67 // Invalid topic, use default instead
68 $topicId = HELP_DEFAULT_TOPIC
;
69 $topic = $topicDao->getTopic($topicId);
72 $tocDao =& DAORegistry
::getDAO('HelpTocDAO');
73 $toc = $tocDao->getToc($topic->getTocId());
76 // Invalid toc, use default instead
77 $toc = $tocDao->getToc(HELP_DEFAULT_TOC
);
80 if ($topic->getSubTocId() != null) {
81 $subToc = $tocDao->getToc($topic->getSubTocId());
86 $relatedTopics = $topic->getRelatedTopics();
88 $topics = $toc->getTopics();
90 $templateMgr =& TemplateManager
::getManager();
91 $templateMgr->assign('currentTopicId', $topic->getId());
92 $templateMgr->assign_by_ref('topic', $topic);
93 $templateMgr->assign('toc', $toc);
94 $templateMgr->assign('subToc', $subToc);
95 $templateMgr->assign('relatedTopics', $relatedTopics);
96 $templateMgr->assign('locale', Locale
::getLocale());
97 $templateMgr->assign('breadcrumbs', $toc->getBreadcrumbs());
98 if (!empty($keyword)) {
99 $templateMgr->assign('helpSearchKeyword', $keyword);
101 if (!empty($result)) {
102 $templateMgr->assign('helpSearchResult', $result);
104 $templateMgr->display('help/view.tpl');
108 * Display search results for a topic search by keyword.
112 $this->setupTemplate();
114 $searchResults = array();
116 $keyword = trim(String::regexp_replace('/[^\w\s\.\-]/', '', strip_tags(Request
::getUserVar('keyword'))));
118 if (!empty($keyword)) {
119 $topicDao =& DAORegistry
::getDAO('HelpTopicDAO');
120 $topics = $topicDao->getTopicsByKeyword($keyword);
122 $tocDao =& DAORegistry
::getDAO('HelpTocDAO');
123 foreach ($topics as $topic) {
124 $searchResults[] = array('topic' => $topic, 'toc' => $tocDao->getToc($topic->getTocId()));
128 $templateMgr =& TemplateManager
::getManager();
129 $templateMgr->assign('showSearch', true);
130 $templateMgr->assign('pageTitle', Locale
::translate('help.searchResults'));
131 $templateMgr->assign('helpSearchKeyword', $keyword);
132 $templateMgr->assign('searchResults', $searchResults);
133 $templateMgr->display('help/searchResults.tpl');
137 * Initialize the template
139 function setupTemplate() {
140 $templateMgr =& TemplateManager
::getManager();
141 $templateMgr->setCacheability(CACHEABILITY_PUBLIC
);