summaryrefslogtreecommitdiff
path: root/inc/search.php
diff options
context:
space:
mode:
authorGerrit Uitslag <klapinklapin@gmail.com>2013-11-19 21:26:50 +0100
committerGerrit Uitslag <klapinklapin@gmail.com>2013-11-19 21:26:50 +0100
commit703aeaef1a43b07dc5497dba72c98151466396cc (patch)
tree1e18a6b3fc3c28156c2e56f8a3d515b8dd6a9cf9 /inc/search.php
parent33c3b3817b00aa9384760813643fac0e33daaaff (diff)
parent14b3007921f7b66fc9e3621b861a3c83e7e9093c (diff)
downloadrpg-703aeaef1a43b07dc5497dba72c98151466396cc.tar.gz
rpg-703aeaef1a43b07dc5497dba72c98151466396cc.tar.bz2
Merge remote-tracking branch 'origin/master' into diff_navigation
Diffstat (limited to 'inc/search.php')
-rw-r--r--inc/search.php89
1 files changed, 30 insertions, 59 deletions
diff --git a/inc/search.php b/inc/search.php
index 6927fff5f..c2d31b959 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -9,14 +9,15 @@
if(!defined('DOKU_INC')) die('meh.');
/**
- * recurse direcory
+ * Recurse directory
*
* This function recurses into a given base directory
* and calls the supplied function for each file and directory
*
- * @param array ref $data The results of the search are stored here
+ * @param array &$data The results of the search are stored here
* @param string $base Where to start the search
* @param callback $func Callback (function name or array with object,method)
+ * @param array $opts option array will be given to the Callback
* @param string $dir Current directory beyond $base
* @param int $lvl Recursion Level
* @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting.
@@ -68,12 +69,12 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){
* decide if this directory should be traversed (true) or not (false)
* The function has to accept the following parameters:
*
- * &$data - Reference to the result data structure
- * $base - Base usually $conf['datadir']
- * $file - current file or directory relative to $base
- * $type - Type either 'd' for directory or 'f' for file
- * $lvl - Current recursion depht
- * $opts - option array as given to search()
+ * array &$data - Reference to the result data structure
+ * string $base - Base usually $conf['datadir']
+ * string $file - current file or directory relative to $base
+ * string $type - Type either 'd' for directory or 'f' for file
+ * int $lvl - Current recursion depht
+ * array $opts - option array as given to search()
*
* return values for files are ignored
*
@@ -110,7 +111,7 @@ function search_index(&$data,$base,$file,$type,$lvl,$opts){
$opts = array(
'pagesonly' => true,
'listdirs' => true,
- 'listfiles' => !$opts['nofiles'],
+ 'listfiles' => empty($opts['nofiles']),
'sneakyacl' => $conf['sneaky_index'],
// Hacky, should rather use recmatch
'depth' => preg_match('#^'.preg_quote($file, '#').'(/|$)#','/'.$opts['ns']) ? 0 : -1
@@ -273,45 +274,6 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
return true;
}
-/**
- * Reference search
- * This fuction searches for existing references to a given media file
- * and returns an array with the found pages. It doesn't pay any
- * attention to ACL permissions to find every reference. The caller
- * must check if the user has the appropriate rights to see the found
- * page and eventually have to prevent the result from displaying.
- *
- * @param array $data Reference to the result data structure
- * @param string $base Base usually $conf['datadir']
- * @param string $file current file or directory relative to $base
- * @param char $type Type either 'd' for directory or 'f' for file
- * @param int $lvl Current recursion depht
- * @param mixed $opts option array as given to search()
- *
- * $opts['query'] is the demanded media file name
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
-function search_reference(&$data,$base,$file,$type,$lvl,$opts){
- global $conf;
-
- //we do nothing with directories
- if($type == 'd') return true;
-
- //only search txt files
- if(substr($file,-4) != '.txt') return true;
-
- //we finish after 'cnt' references found. The return value
- //'false' will skip subdirectories to speed search up.
- $cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
- if(count($data) >= $cnt) return false;
-
- $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
- search_regex($data,$base,$file,$reg,array($opts['query']));
- return true;
-}
-
/* ------------- helper functions below -------------- */
/**
@@ -373,6 +335,15 @@ function pathID($path,$keeptxt=false){
* showhidden bool show hidden files too
* firsthead bool return first heading for pages
*
+ * @param array &$data - Reference to the result data structure
+ * @param string $base - Base usually $conf['datadir']
+ * @param string $file - current file or directory relative to $base
+ * @param string $type - Type either 'd' for directory or 'f' for file
+ * @param int $lvl - Current recursion depht
+ * @param array $opts - option array as given to search()
+ * @return bool if this directory should be traversed (true) or not (false)
+ * return value is ignored for files
+ *
* @author Andreas Gohr <gohr@cosmocode.de>
*/
function search_universal(&$data,$base,$file,$type,$lvl,$opts){
@@ -406,7 +377,7 @@ function search_universal(&$data,$base,$file,$type,$lvl,$opts){
}
// check ACL
- if(!$opts['skipacl']){
+ if(empty($opts['skipacl'])){
if($type == 'd'){
$item['perm'] = auth_quickaclcheck($item['id'].':*');
}else{
@@ -418,17 +389,17 @@ function search_universal(&$data,$base,$file,$type,$lvl,$opts){
// are we done here maybe?
if($type == 'd'){
- if(!$opts['listdirs']) return $return;
- if(!$opts['skipacl'] && $opts['sneakyacl'] && $item['perm'] < AUTH_READ) return false; //neither list nor recurse
- if($opts['dirmatch'] && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return;
- if($opts['nsmatch'] && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return;
+ if(empty($opts['listdirs'])) return $return;
+ if(empty($opts['skipacl']) && !empty($opts['sneakyacl']) && $item['perm'] < AUTH_READ) return false; //neither list nor recurse
+ if(!empty($opts['dirmatch']) && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return;
+ if(!empty($opts['nsmatch']) && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return;
}else{
- if(!$opts['listfiles']) return $return;
- if(!$opts['skipacl'] && $item['perm'] < AUTH_READ) return $return;
- if($opts['pagesonly'] && (substr($file,-4) != '.txt')) return $return;
- if(!$opts['showhidden'] && isHiddenPage($item['id'])) return $return;
- if($opts['filematch'] && !preg_match('/'.$opts['filematch'].'/',$file)) return $return;
- if($opts['idmatch'] && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return;
+ if(empty($opts['listfiles'])) return $return;
+ if(empty($opts['skipacl']) && $item['perm'] < AUTH_READ) return $return;
+ if(!empty($opts['pagesonly']) && (substr($file,-4) != '.txt')) return $return;
+ if(empty($opts['showhidden']) && isHiddenPage($item['id'])) return $return;
+ if(!empty($opts['filematch']) && !preg_match('/'.$opts['filematch'].'/',$file)) return $return;
+ if(!empty($opts['idmatch']) && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return;
}
// still here? prepare the item