*/ class helper_plugin_searchns extends Plugin { public const SEARCHNS_HEADING = 'SEARCHNS_HEADING'; /** * @var array */ protected $ns; /** * Constructor */ public function __construct() { $this->ns = $this->getNsFromConfig(); } /** * Converts config string to array * * @return array */ public function getNsFromConfig() { if (!is_null($this->ns)) { return $this->ns; } $ns = []; $config = $this->getConf('namespaces'); if (empty($config)) return $ns; $lines = array_filter(explode("\n", $config)); foreach ($lines as $line) { $n = sexplode(' ', $line, 2); if (strpos($n[0], ':', -1) === false) { msg('Search namespaces are not configured correctly!', -1); return $ns; } $ns[trim($n[1])] = rtrim(trim($n[0], ':')); } if ($this->getConf('first all')) { $ns = array_merge([$this->getLang('all label') => ''], $ns); } else { $ns[$this->getLang('all label')] = ''; } return $ns; } /** * array_filter callback to remove namespaces that the current user can't read * * @param string $ns * @return bool */ public function filterByACL($ns) { if ($ns === '') return true; // all is always allowed return auth_quickaclcheck($ns . ':*') >= AUTH_READ; } /** * Returns HTML list of search results. * Based on core quicksearch * @see \dokuwiki\Ajax::callQsearch() * * @return string */ public function qSearch() { global $INPUT; $maxnumbersuggestions = 50; // search parameters as posted via AJAX $query = $INPUT->str('q'); $ns = $INPUT->str('ns'); if (empty($query)) return ''; $query = urldecode($query) . ($ns ? " @$ns" : ''); $data = ft_pageLookup($query, true, useHeading('navigation')); if ($data === []) return ''; $ret = '