Ejemplo n.º 1
0
 function render($mode, Doku_Renderer $renderer, $opt)
 {
     if (!PHP_MAJOR_VERSION >= 5 && !PHP_MINOR_VERSION >= 3) {
         $renderer->doc .= "You must have PHP 5.3 or greater to use this pagequery plugin.  Please upgrade PHP or use an older version of the plugin";
         return false;
     }
     $incl_ns = array();
     $excl_ns = array();
     $sort_opts = array();
     $group_opts = array();
     $message = '';
     $lang = array('jump_section' => $this->getLang('jump_section'), 'link_to_top' => $this->getLang('link_to_top'), 'no_results' => $this->getLang('no_results'));
     $pq = new PageQuery($lang);
     $query = $opt['query'];
     if ($mode == 'xhtml') {
         // first get a raw list of matching results
         if ($opt['fulltext']) {
             // full text searching (Dokuwiki style)
             $results = $pq->page_search($query);
         } else {
             // page id searching (i.e. namespace and name, faster)
             // fullregex option considers entire query to be a regex
             // over the whole page id, incl. namespace
             if (!$opt['fullregex']) {
                 list($query, $incl_ns, $excl_ns) = $pq->parse_ns_query($query);
             }
             // Allow for a lazy man's option!
             if ($query == '*') {
                 $query = '.*';
             }
             // search by page name or path only
             $results = $pq->page_lookup($query, $opt['fullregex'], $incl_ns, $excl_ns);
         }
         $results = $pq->validate_pages($results, $opt['hidestart'], $opt['maxns']);
         $no_result = false;
         if ($results === false) {
             $no_result = true;
             $message = $this->getLang('regex_error');
         } elseif (!empty($results)) {
             // prepare the necessary sorting arrays, as per users options
             list($sort_array, $sort_opts, $group_opts) = $pq->build_sorting_array($results, $opt);
             // meta data filtering of the list is next
             $sort_array = $pq->filter_meta($sort_array, $opt['filter']);
             if (empty($sort_array)) {
                 $no_result = true;
                 $message = $this->getLang("empty_filter");
             }
         } else {
             $no_result = true;
         }
         // successful search...
         if (!$no_result) {
             // now do the sorting
             $pq->msort($sort_array, $sort_opts);
             // limit the result list length if required; this can only be done after sorting!
             if ($opt['limit'] > 0) {
                 $sort_array = array_slice($sort_array, 0, $opt['limit']);
             }
             // do a link count BEFORE grouping (don't want to count headers...)
             $count = count($sort_array);
             // and finally the grouping
             $keys = array('name', 'id', 'title', 'abstract', 'display');
             if (!$opt['group']) {
                 $group_opts = array();
             }
             $sorted_results = $pq->mgroup($sort_array, $keys, $group_opts);
             // and out to the page
             $renderer->doc .= $pq->render_as_html($opt['layout'], $sorted_results, $opt, $count);
             // no results...
         } else {
             if (!$opt['hidemsg']) {
                 $renderer->doc .= $pq->render_as_empty($query, $message);
             }
         }
         return true;
     } else {
         if ($mode == 'metadata') {
             // this is a pagequery page needing PARSER_CACHE_USE event trigger;
             $renderer->meta['pagequery'] = TRUE;
             unset($renderer->persistent['pagequery']);
             return true;
         } else {
             return false;
         }
     }
 }