Overview

Packages

  • None
  • Wicked

Classes

  • Text_Wiki_Parse_Heading2
  • Text_Wiki_Parse_Toc2
  • Text_Wiki_Render_Latex_Heading2
  • Text_Wiki_Render_Latex_Toc2
  • Text_Wiki_Render_Plain_Heading2
  • Text_Wiki_Render_Plain_Toc2
  • Text_Wiki_Render_Rst
  • Text_Wiki_Render_Rst_Blockquote
  • Text_Wiki_Render_Rst_Bold
  • Text_Wiki_Render_Rst_Code
  • Text_Wiki_Render_Rst_Deflist
  • Text_Wiki_Render_Rst_Emphasis
  • Text_Wiki_Render_Rst_Freelink
  • Text_Wiki_Render_Rst_Heading2
  • Text_Wiki_Render_Rst_Links
  • Text_Wiki_Render_Rst_List
  • Text_Wiki_Render_Rst_Newline
  • Text_Wiki_Render_Rst_Paragraph
  • Text_Wiki_Render_Rst_Raw
  • Text_Wiki_Render_Rst_Toc2
  • Text_Wiki_Render_Rst_Tt
  • Text_Wiki_Render_Rst_Url
  • Text_Wiki_Render_Xhtml_Attribute
  • Text_Wiki_Render_Xhtml_Code2
  • Text_Wiki_Render_Xhtml_Freelink2
  • Text_Wiki_Render_Xhtml_Heading2
  • Text_Wiki_Render_Xhtml_Image2
  • Text_Wiki_Render_Xhtml_Interwiki
  • Text_Wiki_Render_Xhtml_Registrylink
  • Text_Wiki_Render_Xhtml_Toc2
  • Text_Wiki_Render_Xhtml_Url
  • Text_Wiki_Render_Xhtml_Wickedblock
  • Text_Wiki_Render_Xhtml_Wikilink2
  • Wicked
  • Wicked_Api
  • Wicked_Driver
  • Wicked_Driver_Sql
  • Wicked_Exception
  • Wicked_Factory_Driver
  • Wicked_Page
  • Wicked_Page_AddPage
  • Wicked_Page_AllPages
  • Wicked_Page_AttachedFiles
  • Wicked_Page_BackLinks
  • Wicked_Page_DeletePage
  • Wicked_Page_EditPage
  • Wicked_Page_LeastPopular
  • Wicked_Page_LikePages
  • Wicked_Page_MergeOrRename
  • Wicked_Page_MostPopular
  • Wicked_Page_NewPage
  • Wicked_Page_RecentChanges
  • Wicked_Page_RevertPage
  • Wicked_Page_Search
  • Wicked_Page_StandardHistoryPage
  • Wicked_Page_StandardPage
  • Wicked_Page_SyncDiff
  • Wicked_Page_SyncPages
  • Wicked_Sync
  • Wicked_Sync_Wicked
  • Wicked_Test
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Wicked SearchAll class.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author Ben Chavet <ben@horde.org>
 11:  * @package Wicked
 12:  */
 13: class Wicked_Page_Search extends Wicked_Page {
 14: 
 15:     /**
 16:      * Display modes supported by this page.
 17:      * @var array
 18:      */
 19:     public $supportedModes = array(
 20:         Wicked::MODE_CONTENT => true,
 21:         Wicked::MODE_DISPLAY => true);
 22: 
 23:     /**
 24:      * Cached search results.
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_results = array();
 29: 
 30:     /**
 31:      * Renders this page in content mode.
 32:      *
 33:      * @param string $searchtext  The title to search for.
 34:      *
 35:      * @return string  The page content.
 36:      */
 37:     public function content($searchtext = '')
 38:     {
 39:         if (empty($searchtext)) {
 40:             return array();
 41:         }
 42:         return array(
 43:             'titles' => $GLOBALS['wicked']->searchTitles($searchtext),
 44:             'pages' => $GLOBALS['wicked']->searchText($searchtext, false));
 45:     }
 46: 
 47:     /**
 48:      * Perform any pre-display checks for permissions, searches,
 49:      * etc. Called before any output is sent so the page can do
 50:      * redirects. If the page wants to take control of flow from here,
 51:      * it can, and is entirely responsible for handling the user
 52:      * (should call exit after redirecting, for example).
 53:      *
 54:      * $param integer $mode    The page render mode.
 55:      * $param array   $params  Any page parameters.
 56:      */
 57:     public function preDisplay($mode, $params)
 58:     {
 59:         $this->_results = $this->content($params);
 60:     }
 61: 
 62:     /**
 63:      * Renders this page in display mode.
 64:      *
 65:      * @param string $searchtext  The title to search for.
 66:      *
 67:      * @throws Wicked_Exception
 68:      */
 69:     public function display($searchtext)
 70:     {
 71:         global $notification;
 72: 
 73:         if (!$searchtext) {
 74:             require WICKED_TEMPLATES . '/pagelist/search.inc';
 75:             require WICKED_TEMPLATES . '/pagelist/footer.inc';
 76:             return true;
 77:         }
 78: 
 79:         Horde::addScriptFile('tables.js', 'horde', true);
 80: 
 81:         $template = $GLOBALS['injector']->createInstance('Horde_Template');
 82: 
 83:         /* Prepare exact match section */
 84:         $exact = array();
 85:         $page = new Wicked_Page_StandardPage($searchtext);
 86:         if ($GLOBALS['wicked']->pageExists($searchtext)) {
 87:             $exact[] = array('author' => htmlspecialchars($page->author()),
 88:                              'created' => $page->formatVersionCreated(),
 89:                              'name' => htmlspecialchars($page->pageName()),
 90:                              'context' => false,
 91:                              'url' => $page->pageUrl(),
 92:                              'version' => $page->version(),
 93:                              'class' => '');
 94:         } else {
 95:             $exact[] = array('author' => '',
 96:                              'created' => '',
 97:                              'name' => htmlspecialchars($searchtext),
 98:                              'context' => sprintf(_("%s does not exist. You can create it now."), '<strong>' . htmlspecialchars($searchtext) . '</strong>'),
 99:                              'url' => Wicked::url($searchtext, false),
100:                              'version' => '',
101:                              'class' => 'newpage');
102:         }
103: 
104:         /* Prepare page title matches */
105:         $titles = array();
106:         foreach ($this->_results['titles'] as $page) {
107:             if (!empty($page['page_history'])) {
108:                 $page = new Wicked_Page_StandardHistoryPage($page);
109:             } else {
110:                 $page = new Wicked_Page_StandardPage($page);
111:             }
112: 
113:             $titles[] = array('author' => $page->author(),
114:                               'created' => $page->formatVersionCreated(),
115:                               'name' => $page->pageName(),
116:                               'context' => false,
117:                               'url' => $page->pageUrl(),
118:                               'version' => $page->version(),
119:                               'class' => '');
120:         }
121: 
122:         /* Prepare page text matches */
123:         $pages = array();
124:         foreach ($this->_results['pages'] as $page) {
125:             if (!empty($page['page_history'])) {
126:                 $page = new Wicked_Page_StandardHistoryPage($page);
127:             } else {
128:                 $page = new Wicked_Page_StandardPage($page);
129:             }
130: 
131:             $pages[] = array('author' => $page->author(),
132:                              'created' => $page->formatVersionCreated(),
133:                              'name' => $page->pageName(),
134:                              'context' => $this->getContext($page, $searchtext),
135:                              'url' => $page->pageUrl(),
136:                              'version' => $page->version(),
137:                              'class' => '');
138:         }
139: 
140:         $template->set('hits', false, true);
141: 
142:         $template->set('th_page', _("Page"), true);
143:         $template->set('th_version', _("Current Version"), true);
144:         $template->set('th_author', _("Last Author"), true);
145:         $template->set('th_updated', _("Last Update"), true);
146: 
147:         // Show search form and page header.
148:         require WICKED_TEMPLATES . '/pagelist/search.inc';
149: 
150:         // Show exact match.
151:         $template->set('title', _("Exact Match"), true);
152:         $template->set('pages', $exact, true);
153:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/results_header.html');
154:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/pagelist.html');
155:         require WICKED_TEMPLATES . '/pagelist/results_footer.inc';
156: 
157:         // Show page title matches.
158:         $template->set('title', _("Page Title Matches"), true);
159:         $template->set('pages', $titles, true);
160:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/results_header.html');
161:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/pagelist.html');
162:         require WICKED_TEMPLATES . '/pagelist/results_footer.inc';
163: 
164:         // Show page text matches.
165:         $template->set('title', _("Page Text Matches"), true);
166:         $template->set('pages', $pages, true);
167:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/results_header.html');
168:         echo $template->fetch(WICKED_TEMPLATES . '/pagelist/pagelist.html');
169:         require WICKED_TEMPLATES . '/pagelist/results_footer.inc';
170:         echo '</div>';
171: 
172:         return true;
173:     }
174: 
175:     public function getContext($page, $searchtext)
176:     {
177:         try {
178:             $text = strip_tags($page->displayContents(false));
179:         } catch (Wicked_Exception $e) {
180:             $text = $page->getText();
181:         }
182:         if (preg_match('/.{0,100}' . preg_quote($searchtext, '/') . '.{0,100}/i', $text, $context)) {
183:             return preg_replace('/' . preg_quote($searchtext, '/') . '/i', '<span class="match">' . htmlspecialchars($searchtext) . '</span>', htmlspecialchars($context[0]));
184:         }
185:         return '';
186:     }
187: 
188:     public function pageName()
189:     {
190:         return 'Search';
191:     }
192: 
193:     public function pageTitle()
194:     {
195:         return _("Search");
196:     }
197: 
198: }
199: 
API documentation generated by ApiGen