116a367d4SAndreas Gohr<?php 216a367d4SAndreas Gohr 316a367d4SAndreas Gohrnamespace dokuwiki; 416a367d4SAndreas Gohr 524870174SAndreas Gohruse dokuwiki\Extension\Event; 624870174SAndreas Gohruse dokuwiki\Ui\MediaDiff; 724870174SAndreas Gohruse dokuwiki\Ui\Index; 89c8632b4SSatoshi Saharause dokuwiki\Ui; 92d85e841SAndreas Gohruse dokuwiki\Utf8\Sort; 109c8632b4SSatoshi Sahara 1116a367d4SAndreas Gohr/** 1216a367d4SAndreas Gohr * Manage all builtin AJAX calls 1316a367d4SAndreas Gohr * 1416a367d4SAndreas Gohr * @todo The calls should be refactored out to their own proper classes 1516a367d4SAndreas Gohr * @package dokuwiki 1616a367d4SAndreas Gohr */ 178c7c53b0SAndreas Gohrclass Ajax 188c7c53b0SAndreas Gohr{ 1916a367d4SAndreas Gohr 2016a367d4SAndreas Gohr /** 2116a367d4SAndreas Gohr * Execute the given call 2216a367d4SAndreas Gohr * 2316a367d4SAndreas Gohr * @param string $call name of the ajax call 2416a367d4SAndreas Gohr */ 25*d868eb89SAndreas Gohr public function __construct($call) 26*d868eb89SAndreas Gohr { 272ed72d06SAndreas Gohr $callfn = 'call' . ucfirst($call); 2816a367d4SAndreas Gohr if(method_exists($this, $callfn)) { 2916a367d4SAndreas Gohr $this->$callfn(); 3016a367d4SAndreas Gohr } else { 3124870174SAndreas Gohr $evt = new Event('AJAX_CALL_UNKNOWN', $call); 3216a367d4SAndreas Gohr if($evt->advise_before()) { 3316a367d4SAndreas Gohr print "AJAX call '" . hsc($call) . "' unknown!\n"; 3416a367d4SAndreas Gohr } else { 3516a367d4SAndreas Gohr $evt->advise_after(); 3616a367d4SAndreas Gohr unset($evt); 3716a367d4SAndreas Gohr } 3816a367d4SAndreas Gohr } 3916a367d4SAndreas Gohr } 4016a367d4SAndreas Gohr 4116a367d4SAndreas Gohr /** 4216a367d4SAndreas Gohr * Searches for matching pagenames 4316a367d4SAndreas Gohr * 4416a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4516a367d4SAndreas Gohr */ 46*d868eb89SAndreas Gohr protected function callQsearch() 47*d868eb89SAndreas Gohr { 4816a367d4SAndreas Gohr global $lang; 4916a367d4SAndreas Gohr global $INPUT; 5016a367d4SAndreas Gohr 5116a367d4SAndreas Gohr $maxnumbersuggestions = 50; 5216a367d4SAndreas Gohr 5316a367d4SAndreas Gohr $query = $INPUT->post->str('q'); 5416a367d4SAndreas Gohr if(empty($query)) $query = $INPUT->get->str('q'); 5516a367d4SAndreas Gohr if(empty($query)) return; 5616a367d4SAndreas Gohr 5716a367d4SAndreas Gohr $query = urldecode($query); 5816a367d4SAndreas Gohr 5916a367d4SAndreas Gohr $data = ft_pageLookup($query, true, useHeading('navigation')); 6016a367d4SAndreas Gohr 6124870174SAndreas Gohr if($data === []) return; 6216a367d4SAndreas Gohr 6316a367d4SAndreas Gohr print '<strong>' . $lang['quickhits'] . '</strong>'; 6416a367d4SAndreas Gohr print '<ul>'; 6516a367d4SAndreas Gohr $counter = 0; 6616a367d4SAndreas Gohr foreach($data as $id => $title) { 6716a367d4SAndreas Gohr if(useHeading('navigation')) { 6816a367d4SAndreas Gohr $name = $title; 6916a367d4SAndreas Gohr } else { 7016a367d4SAndreas Gohr $ns = getNS($id); 7116a367d4SAndreas Gohr if($ns) { 7216a367d4SAndreas Gohr $name = noNS($id) . ' (' . $ns . ')'; 7316a367d4SAndreas Gohr } else { 7416a367d4SAndreas Gohr $name = $id; 7516a367d4SAndreas Gohr } 7616a367d4SAndreas Gohr } 7716a367d4SAndreas Gohr echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; 7816a367d4SAndreas Gohr 7916a367d4SAndreas Gohr $counter++; 8016a367d4SAndreas Gohr if($counter > $maxnumbersuggestions) { 8116a367d4SAndreas Gohr echo '<li>...</li>'; 8216a367d4SAndreas Gohr break; 8316a367d4SAndreas Gohr } 8416a367d4SAndreas Gohr } 8516a367d4SAndreas Gohr print '</ul>'; 8616a367d4SAndreas Gohr } 8716a367d4SAndreas Gohr 8816a367d4SAndreas Gohr /** 8916a367d4SAndreas Gohr * Support OpenSearch suggestions 9016a367d4SAndreas Gohr * 9116a367d4SAndreas Gohr * @link http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0 9216a367d4SAndreas Gohr * @author Mike Frysinger <vapier@gentoo.org> 9316a367d4SAndreas Gohr */ 94*d868eb89SAndreas Gohr protected function callSuggestions() 95*d868eb89SAndreas Gohr { 9616a367d4SAndreas Gohr global $INPUT; 9716a367d4SAndreas Gohr 9816a367d4SAndreas Gohr $query = cleanID($INPUT->post->str('q')); 9916a367d4SAndreas Gohr if(empty($query)) $query = cleanID($INPUT->get->str('q')); 10016a367d4SAndreas Gohr if(empty($query)) return; 10116a367d4SAndreas Gohr 10216a367d4SAndreas Gohr $data = ft_pageLookup($query); 10324870174SAndreas Gohr if($data === []) return; 10416a367d4SAndreas Gohr $data = array_keys($data); 10516a367d4SAndreas Gohr 10616a367d4SAndreas Gohr // limit results to 15 hits 10716a367d4SAndreas Gohr $data = array_slice($data, 0, 15); 10816a367d4SAndreas Gohr $data = array_map('trim', $data); 10916a367d4SAndreas Gohr $data = array_map('noNS', $data); 11016a367d4SAndreas Gohr $data = array_unique($data); 1112d85e841SAndreas Gohr Sort::sort($data); 11216a367d4SAndreas Gohr 11316a367d4SAndreas Gohr /* now construct a json */ 11424870174SAndreas Gohr $suggestions = [ 11516a367d4SAndreas Gohr $query, // the original query 11616a367d4SAndreas Gohr $data, // some suggestions 11724870174SAndreas Gohr [], // no description 11824870174SAndreas Gohr [], // no urls 11924870174SAndreas Gohr ]; 12016a367d4SAndreas Gohr 12116a367d4SAndreas Gohr header('Content-Type: application/x-suggestions+json'); 12224870174SAndreas Gohr print json_encode($suggestions, JSON_THROW_ON_ERROR); 12316a367d4SAndreas Gohr } 12416a367d4SAndreas Gohr 12516a367d4SAndreas Gohr /** 12616a367d4SAndreas Gohr * Refresh a page lock and save draft 12716a367d4SAndreas Gohr * 12816a367d4SAndreas Gohr * Andreas Gohr <andi@splitbrain.org> 12916a367d4SAndreas Gohr */ 130*d868eb89SAndreas Gohr protected function callLock() 131*d868eb89SAndreas Gohr { 13216a367d4SAndreas Gohr global $ID; 13316a367d4SAndreas Gohr global $INFO; 13416a367d4SAndreas Gohr global $INPUT; 13516a367d4SAndreas Gohr 13616a367d4SAndreas Gohr $ID = cleanID($INPUT->post->str('id')); 13716a367d4SAndreas Gohr if(empty($ID)) return; 13816a367d4SAndreas Gohr 13916a367d4SAndreas Gohr $INFO = pageinfo(); 14016a367d4SAndreas Gohr 141b16fbc3fSMichael Große $response = [ 142b16fbc3fSMichael Große 'errors' => [], 143b16fbc3fSMichael Große 'lock' => '0', 144b16fbc3fSMichael Große 'draft' => '', 145b16fbc3fSMichael Große ]; 14616a367d4SAndreas Gohr if(!$INFO['writable']) { 147b16fbc3fSMichael Große $response['errors'][] = 'Permission to write this page has been denied.'; 148b16fbc3fSMichael Große echo json_encode($response); 14916a367d4SAndreas Gohr return; 15016a367d4SAndreas Gohr } 15116a367d4SAndreas Gohr 15216a367d4SAndreas Gohr if(!checklock($ID)) { 15316a367d4SAndreas Gohr lock($ID); 154b16fbc3fSMichael Große $response['lock'] = '1'; 15516a367d4SAndreas Gohr } 15616a367d4SAndreas Gohr 1570aabe6f8SMichael Große $draft = new Draft($ID, $INFO['client']); 1580aabe6f8SMichael Große if ($draft->saveDraft()) { 159b16fbc3fSMichael Große $response['draft'] = $draft->getDraftMessage(); 160b16fbc3fSMichael Große } else { 161b16fbc3fSMichael Große $response['errors'] = array_merge($response['errors'], $draft->getErrors()); 16216a367d4SAndreas Gohr } 16324870174SAndreas Gohr echo json_encode($response, JSON_THROW_ON_ERROR); 16416a367d4SAndreas Gohr } 16516a367d4SAndreas Gohr 16616a367d4SAndreas Gohr /** 16716a367d4SAndreas Gohr * Delete a draft 16816a367d4SAndreas Gohr * 16916a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 17016a367d4SAndreas Gohr */ 171*d868eb89SAndreas Gohr protected function callDraftdel() 172*d868eb89SAndreas Gohr { 17316a367d4SAndreas Gohr global $INPUT; 17416a367d4SAndreas Gohr $id = cleanID($INPUT->str('id')); 17516a367d4SAndreas Gohr if(empty($id)) return; 17616a367d4SAndreas Gohr 1772b9be456SAndreas Gohr $client = $INPUT->server->str('REMOTE_USER'); 17816a367d4SAndreas Gohr if(!$client) $client = clientIP(true); 17916a367d4SAndreas Gohr 18024201594SAndreas Gohr $draft = new Draft($id, $client); 18124201594SAndreas Gohr if ($draft->isDraftAvailable() && checkSecurityToken()) { 18224201594SAndreas Gohr $draft->deleteDraft(); 18324201594SAndreas Gohr } 18416a367d4SAndreas Gohr } 18516a367d4SAndreas Gohr 18616a367d4SAndreas Gohr /** 18716a367d4SAndreas Gohr * Return subnamespaces for the Mediamanager 18816a367d4SAndreas Gohr * 18916a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 19016a367d4SAndreas Gohr */ 191*d868eb89SAndreas Gohr protected function callMedians() 192*d868eb89SAndreas Gohr { 19316a367d4SAndreas Gohr global $conf; 19416a367d4SAndreas Gohr global $INPUT; 19516a367d4SAndreas Gohr 19616a367d4SAndreas Gohr // wanted namespace 19716a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('ns')); 19816a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 19916a367d4SAndreas Gohr 20016a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 20116a367d4SAndreas Gohr 20224870174SAndreas Gohr $data = []; 20324870174SAndreas Gohr search($data, $conf['mediadir'], 'search_index', ['nofiles' => true], $dir); 20416a367d4SAndreas Gohr foreach(array_keys($data) as $item) { 20516a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 20616a367d4SAndreas Gohr } 20716a367d4SAndreas Gohr echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li'); 20816a367d4SAndreas Gohr } 20916a367d4SAndreas Gohr 21016a367d4SAndreas Gohr /** 21116a367d4SAndreas Gohr * Return list of files for the Mediamanager 21216a367d4SAndreas Gohr * 21316a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 21416a367d4SAndreas Gohr */ 215*d868eb89SAndreas Gohr protected function callMedialist() 216*d868eb89SAndreas Gohr { 21716a367d4SAndreas Gohr global $NS; 21816a367d4SAndreas Gohr global $INPUT; 21916a367d4SAndreas Gohr 22016a367d4SAndreas Gohr $NS = cleanID($INPUT->post->str('ns')); 22116a367d4SAndreas Gohr $sort = $INPUT->post->bool('recent') ? 'date' : 'natural'; 22216a367d4SAndreas Gohr if($INPUT->post->str('do') == 'media') { 22316a367d4SAndreas Gohr tpl_mediaFileList(); 22416a367d4SAndreas Gohr } else { 22516a367d4SAndreas Gohr tpl_mediaContent(true, $sort); 22616a367d4SAndreas Gohr } 22716a367d4SAndreas Gohr } 22816a367d4SAndreas Gohr 22916a367d4SAndreas Gohr /** 23016a367d4SAndreas Gohr * Return the content of the right column 23116a367d4SAndreas Gohr * (image details) for the Mediamanager 23216a367d4SAndreas Gohr * 23316a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 23416a367d4SAndreas Gohr */ 235*d868eb89SAndreas Gohr protected function callMediadetails() 236*d868eb89SAndreas Gohr { 23716a367d4SAndreas Gohr global $IMG, $JUMPTO, $REV, $fullscreen, $INPUT; 23816a367d4SAndreas Gohr $fullscreen = true; 23916a367d4SAndreas Gohr require_once(DOKU_INC . 'lib/exe/mediamanager.php'); 24016a367d4SAndreas Gohr 24116a367d4SAndreas Gohr $image = ''; 24216a367d4SAndreas Gohr if($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 24316a367d4SAndreas Gohr if(isset($IMG)) $image = $IMG; 24416a367d4SAndreas Gohr if(isset($JUMPTO)) $image = $JUMPTO; 24516a367d4SAndreas Gohr $rev = false; 24616a367d4SAndreas Gohr if(isset($REV) && !$JUMPTO) $rev = $REV; 24716a367d4SAndreas Gohr 24816a367d4SAndreas Gohr html_msgarea(); 24916a367d4SAndreas Gohr tpl_mediaFileDetails($image, $rev); 25016a367d4SAndreas Gohr } 25116a367d4SAndreas Gohr 25216a367d4SAndreas Gohr /** 25316a367d4SAndreas Gohr * Returns image diff representation for mediamanager 25416a367d4SAndreas Gohr * 25516a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 25616a367d4SAndreas Gohr */ 257*d868eb89SAndreas Gohr protected function callMediadiff() 258*d868eb89SAndreas Gohr { 25916a367d4SAndreas Gohr global $INPUT; 26016a367d4SAndreas Gohr 26116a367d4SAndreas Gohr $image = ''; 26216a367d4SAndreas Gohr if($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 26324870174SAndreas Gohr (new MediaDiff($image))->preference('fromAjax', true)->show(); 26416a367d4SAndreas Gohr } 26516a367d4SAndreas Gohr 26616a367d4SAndreas Gohr /** 26716a367d4SAndreas Gohr * Manages file uploads 26816a367d4SAndreas Gohr * 26916a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 27016a367d4SAndreas Gohr */ 271*d868eb89SAndreas Gohr protected function callMediaupload() 272*d868eb89SAndreas Gohr { 27316a367d4SAndreas Gohr global $NS, $MSG, $INPUT; 27416a367d4SAndreas Gohr 27516a367d4SAndreas Gohr $id = ''; 276aac83cd4SPhy if(isset($_FILES['qqfile']['tmp_name'])) { 27716a367d4SAndreas Gohr $id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']); 27816a367d4SAndreas Gohr } elseif($INPUT->get->has('qqfile')) { 27916a367d4SAndreas Gohr $id = $INPUT->get->str('qqfile'); 28016a367d4SAndreas Gohr } 28116a367d4SAndreas Gohr 28216a367d4SAndreas Gohr $id = cleanID($id); 28316a367d4SAndreas Gohr 28416a367d4SAndreas Gohr $NS = $INPUT->str('ns'); 28516a367d4SAndreas Gohr $ns = $NS . ':' . getNS($id); 28616a367d4SAndreas Gohr 28716a367d4SAndreas Gohr $AUTH = auth_quickaclcheck("$ns:*"); 28816a367d4SAndreas Gohr if($AUTH >= AUTH_UPLOAD) { 28916a367d4SAndreas Gohr io_createNamespace("$ns:xxx", 'media'); 29016a367d4SAndreas Gohr } 29116a367d4SAndreas Gohr 292aac83cd4SPhy if(isset($_FILES['qqfile']['error']) && $_FILES['qqfile']['error']) unset($_FILES['qqfile']); 29316a367d4SAndreas Gohr 29416a367d4SAndreas Gohr $res = false; 29568491db9SPhy if(isset($_FILES['qqfile']['tmp_name'])) $res = media_upload($NS, $AUTH, $_FILES['qqfile']); 29616a367d4SAndreas Gohr if($INPUT->get->has('qqfile')) $res = media_upload_xhr($NS, $AUTH); 29716a367d4SAndreas Gohr 29816a367d4SAndreas Gohr if($res) { 29924870174SAndreas Gohr $result = [ 30016a367d4SAndreas Gohr 'success' => true, 30124870174SAndreas Gohr 'link' => media_managerURL(['ns' => $ns, 'image' => $NS . ':' . $id], '&'), 30216a367d4SAndreas Gohr 'id' => $NS . ':' . $id, 30316a367d4SAndreas Gohr 'ns' => $NS 30424870174SAndreas Gohr ]; 30516a367d4SAndreas Gohr } else { 30616a367d4SAndreas Gohr $error = ''; 30716a367d4SAndreas Gohr if(isset($MSG)) { 30816a367d4SAndreas Gohr foreach($MSG as $msg) { 30916a367d4SAndreas Gohr $error .= $msg['msg']; 31016a367d4SAndreas Gohr } 31116a367d4SAndreas Gohr } 31224870174SAndreas Gohr $result = ['error' => $error, 'ns' => $NS]; 31316a367d4SAndreas Gohr } 314d443762bSAndreas Gohr 31516a367d4SAndreas Gohr header('Content-Type: application/json'); 31624870174SAndreas Gohr echo json_encode($result, JSON_THROW_ON_ERROR); 31716a367d4SAndreas Gohr } 31816a367d4SAndreas Gohr 31916a367d4SAndreas Gohr /** 32016a367d4SAndreas Gohr * Return sub index for index view 32116a367d4SAndreas Gohr * 32216a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 32316a367d4SAndreas Gohr */ 324*d868eb89SAndreas Gohr protected function callIndex() 325*d868eb89SAndreas Gohr { 32616a367d4SAndreas Gohr global $conf; 32716a367d4SAndreas Gohr global $INPUT; 32816a367d4SAndreas Gohr 32916a367d4SAndreas Gohr // wanted namespace 33016a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('idx')); 33116a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 33216a367d4SAndreas Gohr 33316a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 33416a367d4SAndreas Gohr 33524870174SAndreas Gohr $data = []; 33624870174SAndreas Gohr search($data, $conf['datadir'], 'search_index', ['ns' => $ns], $dir); 33716a367d4SAndreas Gohr foreach (array_keys($data) as $item) { 33816a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 33916a367d4SAndreas Gohr } 34024870174SAndreas Gohr $idx = new Index; 341d11e205cSSatoshi Sahara echo html_buildlist($data, 'idx', [$idx,'formatListItem'], [$idx,'tagListItem']); 34216a367d4SAndreas Gohr } 34316a367d4SAndreas Gohr 34416a367d4SAndreas Gohr /** 34516a367d4SAndreas Gohr * List matching namespaces and pages for the link wizard 34616a367d4SAndreas Gohr * 34716a367d4SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 34816a367d4SAndreas Gohr */ 349*d868eb89SAndreas Gohr protected function callLinkwiz() 350*d868eb89SAndreas Gohr { 35116a367d4SAndreas Gohr global $conf; 35216a367d4SAndreas Gohr global $lang; 35316a367d4SAndreas Gohr global $INPUT; 35416a367d4SAndreas Gohr 35516a367d4SAndreas Gohr $q = ltrim(trim($INPUT->post->str('q')), ':'); 35616a367d4SAndreas Gohr $id = noNS($q); 35716a367d4SAndreas Gohr $ns = getNS($q); 35816a367d4SAndreas Gohr 35916a367d4SAndreas Gohr $ns = cleanID($ns); 36024870174SAndreas Gohr 36116a367d4SAndreas Gohr $id = cleanID($id); 36216a367d4SAndreas Gohr 36316a367d4SAndreas Gohr $nsd = utf8_encodeFN(str_replace(':', '/', $ns)); 36416a367d4SAndreas Gohr 36524870174SAndreas Gohr $data = []; 3665d27cd14SPhy if($q !== '' && $ns === '') { 36716a367d4SAndreas Gohr 36816a367d4SAndreas Gohr // use index to lookup matching pages 36916a367d4SAndreas Gohr $pages = ft_pageLookup($id, true); 37016a367d4SAndreas Gohr 3712aa917afSalexdraconian // If 'useheading' option is 'always' or 'content', 3722aa917afSalexdraconian // search page titles with original query as well. 373fd260edfSalexdraconian if ($conf['useheading'] == '1' || $conf['useheading'] == 'content') { 3742aa917afSalexdraconian $pages = array_merge($pages, ft_pageLookup($q, true, true)); 3752aa917afSalexdraconian asort($pages, SORT_STRING); 3764668fa19Salexdraconian } 37716a367d4SAndreas Gohr 37816a367d4SAndreas Gohr // result contains matches in pages and namespaces 37916a367d4SAndreas Gohr // we now extract the matching namespaces to show 38016a367d4SAndreas Gohr // them seperately 38124870174SAndreas Gohr $dirs = []; 38216a367d4SAndreas Gohr 38316a367d4SAndreas Gohr foreach($pages as $pid => $title) { 3843c4b22e8Salexdraconian if(strpos(getNS($pid), $id) !== false) { 38516a367d4SAndreas Gohr // match was in the namespace 38616a367d4SAndreas Gohr $dirs[getNS($pid)] = 1; // assoc array avoids dupes 38716a367d4SAndreas Gohr } else { 38816a367d4SAndreas Gohr // it is a matching page, add it to the result 38924870174SAndreas Gohr $data[] = ['id' => $pid, 'title' => $title, 'type' => 'f']; 39016a367d4SAndreas Gohr } 39116a367d4SAndreas Gohr unset($pages[$pid]); 39216a367d4SAndreas Gohr } 39324870174SAndreas Gohr foreach(array_keys($dirs) as $dir) { 39424870174SAndreas Gohr $data[] = ['id' => $dir, 'type' => 'd']; 39516a367d4SAndreas Gohr } 39616a367d4SAndreas Gohr 39716a367d4SAndreas Gohr } else { 39816a367d4SAndreas Gohr 39924870174SAndreas Gohr $opts = [ 40016a367d4SAndreas Gohr 'depth' => 1, 40116a367d4SAndreas Gohr 'listfiles' => true, 40216a367d4SAndreas Gohr 'listdirs' => true, 40316a367d4SAndreas Gohr 'pagesonly' => true, 40416a367d4SAndreas Gohr 'firsthead' => true, 40524870174SAndreas Gohr 'sneakyacl' => $conf['sneaky_index'] 40624870174SAndreas Gohr ]; 40716a367d4SAndreas Gohr if($id) $opts['filematch'] = '^.*\/' . $id; 40816a367d4SAndreas Gohr if($id) $opts['dirmatch'] = '^.*\/' . $id; 40916a367d4SAndreas Gohr search($data, $conf['datadir'], 'search_universal', $opts, $nsd); 41016a367d4SAndreas Gohr 41116a367d4SAndreas Gohr // add back to upper 41216a367d4SAndreas Gohr if($ns) { 41316a367d4SAndreas Gohr array_unshift( 41424870174SAndreas Gohr $data, ['id' => getNS($ns), 'type' => 'u'] 41516a367d4SAndreas Gohr ); 41616a367d4SAndreas Gohr } 41716a367d4SAndreas Gohr } 41816a367d4SAndreas Gohr 41916a367d4SAndreas Gohr // fixme sort results in a useful way ? 42016a367d4SAndreas Gohr 42116a367d4SAndreas Gohr if(!count($data)) { 42216a367d4SAndreas Gohr echo $lang['nothingfound']; 42316a367d4SAndreas Gohr exit; 42416a367d4SAndreas Gohr } 42516a367d4SAndreas Gohr 42616a367d4SAndreas Gohr // output the found data 42716a367d4SAndreas Gohr $even = 1; 42816a367d4SAndreas Gohr foreach($data as $item) { 42916a367d4SAndreas Gohr $even *= -1; //zebra 43016a367d4SAndreas Gohr 43173f05217SPhy if(($item['type'] == 'd' || $item['type'] == 'u') && $item['id'] !== '') $item['id'] .= ':'; 43216a367d4SAndreas Gohr $link = wl($item['id']); 43316a367d4SAndreas Gohr 43416a367d4SAndreas Gohr echo '<div class="' . (($even > 0) ? 'even' : 'odd') . ' type_' . $item['type'] . '">'; 43516a367d4SAndreas Gohr 43616a367d4SAndreas Gohr if($item['type'] == 'u') { 43716a367d4SAndreas Gohr $name = $lang['upperns']; 43816a367d4SAndreas Gohr } else { 43916a367d4SAndreas Gohr $name = hsc($item['id']); 44016a367d4SAndreas Gohr } 44116a367d4SAndreas Gohr 44216a367d4SAndreas Gohr echo '<a href="' . $link . '" title="' . hsc($item['id']) . '" class="wikilink1">' . $name . '</a>'; 44316a367d4SAndreas Gohr 44416a367d4SAndreas Gohr if(!blank($item['title'])) { 44516a367d4SAndreas Gohr echo '<span>' . hsc($item['title']) . '</span>'; 44616a367d4SAndreas Gohr } 44716a367d4SAndreas Gohr echo '</div>'; 44816a367d4SAndreas Gohr } 44916a367d4SAndreas Gohr 45016a367d4SAndreas Gohr } 45116a367d4SAndreas Gohr} 452