xref: /dokuwiki/inc/search.php (revision 506fa8936561993b7f70aa507d0c39a44a6ebab9)
1ed7b5f09Sandi<?php
215fae107Sandi/**
315fae107Sandi * DokuWiki search functions
415fae107Sandi *
515fae107Sandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
615fae107Sandi * @author     Andreas Gohr <andi@splitbrain.org>
715fae107Sandi */
8f3f0262cSandi
9ed7b5f09Sandi  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10ed7b5f09Sandi  require_once(DOKU_INC.'inc/common.php');
11f3f0262cSandi
12f3f0262cSandi/**
1315fae107Sandi * recurse direcory
1415fae107Sandi *
15f3f0262cSandi * This function recurses into a given base directory
16f3f0262cSandi * and calls the supplied function for each file and directory
1715fae107Sandi *
1815fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
19f3f0262cSandi */
20f3f0262cSandifunction search(&$data,$base,$func,$opts,$dir='',$lvl=1){
21f3f0262cSandi  $dirs   = array();
22f3f0262cSandi  $files  = array();
23f3f0262cSandi
24f3f0262cSandi  //read in directories and files
25f3f0262cSandi  $dh = @opendir($base.'/'.$dir);
26f3f0262cSandi  if(!$dh) return;
27f3f0262cSandi  while(($file = readdir($dh)) !== false){
28de3dfc91Sandi    if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
29f3f0262cSandi    if(is_dir($base.'/'.$dir.'/'.$file)){
30f3f0262cSandi      $dirs[] = $dir.'/'.$file;
31f3f0262cSandi      continue;
3264f50cdbSandi    }elseif(substr($file,-5) == '.lock'){
3364f50cdbSandi      //skip lockfiles
3464f50cdbSandi      continue;
35f3f0262cSandi    }
36f3f0262cSandi    $files[] = $dir.'/'.$file;
37f3f0262cSandi  }
38f3f0262cSandi  closedir($dh);
39f3f0262cSandi  sort($files);
40f3f0262cSandi  sort($dirs);
41f3f0262cSandi
42f3f0262cSandi  //give directories to userfunction then recurse
43f3f0262cSandi  foreach($dirs as $dir){
44f3f0262cSandi    if ($func($data,$base,$dir,'d',$lvl,$opts)){
45f3f0262cSandi      search($data,$base,$func,$opts,$dir,$lvl+1);
46f3f0262cSandi    }
47f3f0262cSandi  }
48f3f0262cSandi  //now handle the files
49f3f0262cSandi  foreach($files as $file){
50f3f0262cSandi    $func($data,$base,$file,'f',$lvl,$opts);
51f3f0262cSandi  }
52f3f0262cSandi}
53f3f0262cSandi
54f3f0262cSandi/**
55f3f0262cSandi * The following functions are userfunctions to use with the search
56f3f0262cSandi * function above. This function is called for every found file or
57f3f0262cSandi * directory. When a directory is given to the function it has to
58f3f0262cSandi * decide if this directory should be traversed (true) or not (false)
59f3f0262cSandi * The function has to accept the following parameters:
60f3f0262cSandi *
61f3f0262cSandi * &$data - Reference to the result data structure
62f3f0262cSandi * $base  - Base usually $conf['datadir']
63f3f0262cSandi * $file  - current file or directory relative to $base
64f3f0262cSandi * $type  - Type either 'd' for directory or 'f' for file
65f3f0262cSandi * $lvl   - Current recursion depht
66f3f0262cSandi * $opts  - option array as given to search()
67f3f0262cSandi *
68f3f0262cSandi * return values for files are ignored
69f3f0262cSandi *
70f3f0262cSandi * All functions should check the ACL for document READ rights
71f3f0262cSandi * namespaces (directories) are NOT checked as this would break
72f3f0262cSandi * the recursion (You can have an nonreadable dir over a readable
73f3f0262cSandi * one deeper nested)
74f3f0262cSandi */
75f3f0262cSandi
76f3f0262cSandi/**
7763f2400bSandi * Searches for pages beginning with the given query
7863f2400bSandi *
7963f2400bSandi * @author Andreas Gohr <andi@splitbrain.org>
8063f2400bSandi */
8163f2400bSandifunction search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
8263f2400bSandi  $item = array();
8363f2400bSandi
8463f2400bSandi  if($type == 'd'){
8563f2400bSandi    return false; //no handling yet
8663f2400bSandi  }
8763f2400bSandi
8863f2400bSandi  //get id
8963f2400bSandi  $id = pathID($file);
9063f2400bSandi
9163f2400bSandi  //check if it matches the query
9263f2400bSandi  if(!preg_match('/^'.preg_quote($opts['query'],'/').'/u',$id)){
9363f2400bSandi    return false;
9463f2400bSandi  }
9563f2400bSandi
9663f2400bSandi  //check ACL
9763f2400bSandi  if(auth_quickaclcheck($id) < AUTH_READ){
9863f2400bSandi    return false;
9963f2400bSandi  }
10063f2400bSandi
10163f2400bSandi  $data[]=array( 'id'    => $id,
10263f2400bSandi                 'type'  => $type,
10363f2400bSandi                 'level' => 1,
10463f2400bSandi                 'open'  => true);
10563f2400bSandi  return true;
10663f2400bSandi}
10763f2400bSandi
10863f2400bSandi/**
10915fae107Sandi * Build the browsable index of pages
110f3f0262cSandi *
111f3f0262cSandi * $opts['ns'] is the current namespace
11215fae107Sandi *
11315fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
114f3f0262cSandi */
115f3f0262cSandifunction search_index(&$data,$base,$file,$type,$lvl,$opts){
116f3f0262cSandi  $return = true;
117f3f0262cSandi
118cb70c441Sandi  $item = array();
119cb70c441Sandi
120f3f0262cSandi  if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
121f3f0262cSandi    //add but don't recurse
122f3f0262cSandi    $return = false;
123f3f0262cSandi  }elseif($type == 'f' && !preg_match('#\.txt$#',$file)){
124f3f0262cSandi    //don't add
125f3f0262cSandi    return false;
126f3f0262cSandi  }
127f3f0262cSandi
128f3f0262cSandi  //check ACL
129f3f0262cSandi  $id = pathID($file);
130f3f0262cSandi  if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
131f3f0262cSandi    return false;
132f3f0262cSandi  }
133f3f0262cSandi
134f3f0262cSandi  $data[]=array( 'id'    => $id,
135f3f0262cSandi                 'type'  => $type,
136cb70c441Sandi                 'level' => $lvl,
137cb70c441Sandi                 'open'  => $return );
138f3f0262cSandi  return $return;
139f3f0262cSandi}
140f3f0262cSandi
141f3f0262cSandi/**
14215fae107Sandi * List all namespaces
14315fae107Sandi *
14415fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
145f3f0262cSandi */
146f3f0262cSandifunction search_namespaces(&$data,$base,$file,$type,$lvl,$opts){
147f3f0262cSandi  if($type == 'f') return true; //nothing to do on files
148f3f0262cSandi
149f3f0262cSandi  $id = pathID($file);
150f3f0262cSandi  $data[]=array( 'id'    => $id,
151f3f0262cSandi                 'type'  => $type,
152f3f0262cSandi                 'level' => $lvl );
153f3f0262cSandi  return true;
154f3f0262cSandi}
155f3f0262cSandi
156f3f0262cSandi/**
15715fae107Sandi * List all mediafiles in a namespace
15815fae107Sandi *
15915fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
160f3f0262cSandi */
161f3f0262cSandifunction search_media(&$data,$base,$file,$type,$lvl,$opts){
162f3f0262cSandi  //we do nothing with directories
163f3f0262cSandi  if($type == 'd') return false;
164f3f0262cSandi
165f3f0262cSandi  $info         = array();
166156a608cSandi  $info['id']   = pathID($file,true);
167f3f0262cSandi
168f3f0262cSandi  //check ACL for namespace (we have no ACL for mediafiles)
169f3f0262cSandi  if(auth_quickaclcheck(getNS($info['id']).':*') < AUTH_READ){
170f3f0262cSandi    return false;
171f3f0262cSandi  }
172f3f0262cSandi
173f3f0262cSandi  $info['file'] = basename($file);
174f3f0262cSandi  $info['size'] = filesize($base.'/'.$file);
175f3f0262cSandi  if(preg_match("/\.(jpe?g|gif|png)$/",$file)){
176f3f0262cSandi    $info['isimg'] = true;
17723a34783SAndreas Gohr    require_once(DOKU_INC.'inc/JpegMeta.php');
17823a34783SAndreas Gohr    $info['meta']  = new JpegMeta($base.'/'.$file);
179f3f0262cSandi  }else{
180f3f0262cSandi    $info['isimg'] = false;
181f3f0262cSandi  }
182f3f0262cSandi  $data[] = $info;
183f3f0262cSandi
184f3f0262cSandi  return false;
185f3f0262cSandi}
186f3f0262cSandi
187f3f0262cSandi/**
188f3f0262cSandi * This function just lists documents (for RSS namespace export)
18915fae107Sandi *
19015fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
191f3f0262cSandi */
192f3f0262cSandifunction search_list(&$data,$base,$file,$type,$lvl,$opts){
193f3f0262cSandi  //we do nothing with directories
194f3f0262cSandi  if($type == 'd') return false;
195f3f0262cSandi  if(preg_match('#\.txt$#',$file)){
196f3f0262cSandi    //check ACL
197f3f0262cSandi    $id = pathID($file);
198f3f0262cSandi    if(auth_quickaclcheck($id) < AUTH_READ){
199f3f0262cSandi      return false;
200f3f0262cSandi    }
201f3f0262cSandi    $data[]['id'] = $id;;
202f3f0262cSandi  }
203f3f0262cSandi  return false;
204f3f0262cSandi}
205f3f0262cSandi
206f3f0262cSandi/**
207f3f0262cSandi * Quicksearch for searching matching pagenames
208f3f0262cSandi *
209f3f0262cSandi * $opts['query'] is the search query
21015fae107Sandi *
21115fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
212f3f0262cSandi */
213f3f0262cSandifunction search_pagename(&$data,$base,$file,$type,$lvl,$opts){
214f3f0262cSandi  //we do nothing with directories
215f3f0262cSandi  if($type == 'd') return true;
216f3f0262cSandi  //only search txt files
217f3f0262cSandi  if(!preg_match('#\.txt$#',$file)) return true;
218f3f0262cSandi
219f3f0262cSandi  //simple stringmatching
220396b7edbSmatthiasgrimm  if (!empty($opts['query'])){
221f3f0262cSandi    if(strpos($file,$opts['query']) !== false){
222f3f0262cSandi      //check ACL
223f3f0262cSandi      $id = pathID($file);
224f3f0262cSandi      if(auth_quickaclcheck($id) < AUTH_READ){
225f3f0262cSandi        return false;
226f3f0262cSandi      }
227f3f0262cSandi      $data[]['id'] = $id;
228f3f0262cSandi    }
229396b7edbSmatthiasgrimm  }
230f3f0262cSandi  return true;
231f3f0262cSandi}
232f3f0262cSandi
233f3f0262cSandi/**
234f3f0262cSandi * Search for backlinks to a given page
235f3f0262cSandi *
236f3f0262cSandi * $opts['ns']    namespace of the page
237f3f0262cSandi * $opts['name']  name of the page without namespace
23815fae107Sandi *
23915fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
240f3f0262cSandi */
241f3f0262cSandifunction search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
242f3f0262cSandi  //we do nothing with directories
243f3f0262cSandi  if($type == 'd') return true;;
244f3f0262cSandi  //only search txt files
245f3f0262cSandi  if(!preg_match('#\.txt$#',$file)) return true;;
246f3f0262cSandi
247f3f0262cSandi  //absolute search id
248f3f0262cSandi  $sid = cleanID($opts['ns'].':'.$opts['name']);
249f3f0262cSandi
25037e34a5eSandi  //current id and namespace
251f3f0262cSandi  $cid = pathID($file);
252f3f0262cSandi  $cns = getNS($cid);
253f3f0262cSandi
254f3f0262cSandi  //check ACL
255f3f0262cSandi  if(auth_quickaclcheck($cid) < AUTH_READ){
256f3f0262cSandi    return false;
257f3f0262cSandi  }
258f3f0262cSandi
25937e34a5eSandi  //fetch instructions
26037e34a5eSandi  require_once(DOKU_INC.'inc/parserutils.php');
26137e34a5eSandi  $instructions = p_cached_instructions($base.$file,true);
26237e34a5eSandi  if(is_null($instructions)) return false;
263f3f0262cSandi
26437e34a5eSandi  //check all links for match
26537e34a5eSandi  foreach($instructions as $ins){
26637e34a5eSandi    if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
26737e34a5eSandi      $mid = $ins[1][0];
26837e34a5eSandi      resolve_pageid($cns,$mid,$exists); //exists is not used
269f3f0262cSandi      if($mid == $sid){
27037e34a5eSandi        //we have a match - finish
271f3f0262cSandi        $data[]['id'] = $cid;
272f3f0262cSandi        break;
273f3f0262cSandi      }
274f3f0262cSandi    }
275f3f0262cSandi  }
276f3f0262cSandi
27737e34a5eSandi  return false;
27837e34a5eSandi}
27937e34a5eSandi
280f3f0262cSandi/**
281f3f0262cSandi * Fulltextsearch
282f3f0262cSandi *
283f3f0262cSandi * $opts['query'] is the search query
28415fae107Sandi *
28515fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
286*506fa893SAndreas Gohr * @deprecated - fulltext indexer is used instead
287f3f0262cSandi */
288f3f0262cSandifunction search_fulltext(&$data,$base,$file,$type,$lvl,$opts){
289f3f0262cSandi  //we do nothing with directories
290f3f0262cSandi  if($type == 'd') return true;;
291f3f0262cSandi  //only search txt files
292f3f0262cSandi  if(!preg_match('#\.txt$#',$file)) return true;;
293f3f0262cSandi
294f3f0262cSandi  //check ACL
295f3f0262cSandi  $id = pathID($file);
296f3f0262cSandi  if(auth_quickaclcheck($id) < AUTH_READ){
297f3f0262cSandi    return false;
298f3f0262cSandi  }
299f3f0262cSandi
300f3f0262cSandi  //create regexp from queries
3015ef370d2Smatthiasgrimm  $poswords = array();
3025ef370d2Smatthiasgrimm  $negwords = array();
3035ef370d2Smatthiasgrimm  $qpreg = preg_split('/\s+/',$opts['query']);
3045ef370d2Smatthiasgrimm
3055ef370d2Smatthiasgrimm  foreach($qpreg as $word){
3065ef370d2Smatthiasgrimm    switch(substr($word,0,1)){
3075ef370d2Smatthiasgrimm      case '-':
308396b7edbSmatthiasgrimm        if(strlen($word) > 1){  // catch single '-'
3095ef370d2Smatthiasgrimm          array_push($negwords,preg_quote(substr($word,1),'#'));
310396b7edbSmatthiasgrimm        }
3115ef370d2Smatthiasgrimm        break;
3125ef370d2Smatthiasgrimm      case '+':
313396b7edbSmatthiasgrimm        if(strlen($word) > 1){  // catch single '+'
3145ef370d2Smatthiasgrimm          array_push($poswords,preg_quote(substr($word,1),'#'));
315396b7edbSmatthiasgrimm        }
3165ef370d2Smatthiasgrimm        break;
3175ef370d2Smatthiasgrimm      default:
3185ef370d2Smatthiasgrimm        array_push($poswords,preg_quote($word,'#'));
3195ef370d2Smatthiasgrimm        break;
3205ef370d2Smatthiasgrimm    }
3215ef370d2Smatthiasgrimm  }
322248a7321Smatthiasgrimm
323248a7321Smatthiasgrimm  // a search without any posword is useless
324248a7321Smatthiasgrimm  if (!count($poswords)) return true;
3255ef370d2Smatthiasgrimm
3265a5d942dSmatthiasgrimm  $reg  = '^(?=.*?'.join(')(?=.*?',$poswords).')';
3275ef370d2Smatthiasgrimm  $reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
328b59a406bSmatthiasgrimm  search_regex($data,$base,$file,$reg,$poswords);
329b59a406bSmatthiasgrimm  return true;
330b59a406bSmatthiasgrimm}
331b59a406bSmatthiasgrimm
332b59a406bSmatthiasgrimm/**
333b59a406bSmatthiasgrimm * Reference search
334b59a406bSmatthiasgrimm * This fuction searches for existing references to a given media file
335b59a406bSmatthiasgrimm * and returns an array with the found pages. It doesn't pay any
336b59a406bSmatthiasgrimm * attention to ACL permissions to find every reference. The caller
337b59a406bSmatthiasgrimm * must check if the user has the appropriate rights to see the found
338b59a406bSmatthiasgrimm * page and eventually have to prevent the result from displaying.
339b59a406bSmatthiasgrimm *
340b59a406bSmatthiasgrimm * @param array  $data Reference to the result data structure
341b59a406bSmatthiasgrimm * @param string $base Base usually $conf['datadir']
342b59a406bSmatthiasgrimm * @param string $file current file or directory relative to $base
343b59a406bSmatthiasgrimm * @param char   $type Type either 'd' for directory or 'f' for file
344b59a406bSmatthiasgrimm * @param int    $lvl  Current recursion depht
345b59a406bSmatthiasgrimm * @param mixed  $opts option array as given to search()
346b59a406bSmatthiasgrimm *
347b59a406bSmatthiasgrimm * $opts['query'] is the demanded media file name
348b59a406bSmatthiasgrimm *
349b59a406bSmatthiasgrimm * @author  Andreas Gohr <andi@splitbrain.org>
350b59a406bSmatthiasgrimm * @author  Matthias Grimm <matthiasgrimm@users.sourceforge.net>
351b59a406bSmatthiasgrimm */
352b59a406bSmatthiasgrimmfunction search_reference(&$data,$base,$file,$type,$lvl,$opts){
353b59a406bSmatthiasgrimm  global $conf;
354b59a406bSmatthiasgrimm
355b59a406bSmatthiasgrimm  //we do nothing with directories
356b59a406bSmatthiasgrimm  if($type == 'd') return true;
357b59a406bSmatthiasgrimm
358b59a406bSmatthiasgrimm  //only search txt files
359b59a406bSmatthiasgrimm  if(!preg_match('#\.txt$#',$file)) return true;
360b59a406bSmatthiasgrimm
361e28299ccSmatthiasgrimm  //we finish after 'cnt' references found. The return value
362b59a406bSmatthiasgrimm  //'false' will skip subdirectories to speed search up.
363e28299ccSmatthiasgrimm  $cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
364e28299ccSmatthiasgrimm  if(count($data) >= $cnt) return false;
365b59a406bSmatthiasgrimm
366d67ca2c0Smatthiasgrimm  $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
367b59a406bSmatthiasgrimm  search_regex($data,$base,$file,$reg,array($opts['query']));
368b59a406bSmatthiasgrimm  return true;
369b59a406bSmatthiasgrimm}
370b59a406bSmatthiasgrimm
371b59a406bSmatthiasgrimm/* ------------- helper functions below -------------- */
372b59a406bSmatthiasgrimm
373b59a406bSmatthiasgrimm/**
374b59a406bSmatthiasgrimm * fulltext search helper
375b59a406bSmatthiasgrimm * searches a text file with a given regular expression
376b59a406bSmatthiasgrimm * no ACL checks are performed. This have to be done by
377b59a406bSmatthiasgrimm * the caller if necessary.
378b59a406bSmatthiasgrimm *
379b59a406bSmatthiasgrimm * @param array  $data  reference to array for results
380b59a406bSmatthiasgrimm * @param string $base  base directory
381b59a406bSmatthiasgrimm * @param string $file  file name to search in
382b59a406bSmatthiasgrimm * @param string $reg   regular expression to search for
383b59a406bSmatthiasgrimm * @param array  $words words that should be marked in the results
384b59a406bSmatthiasgrimm *
385b59a406bSmatthiasgrimm * @author  Andreas Gohr <andi@splitbrain.org>
386b59a406bSmatthiasgrimm * @author  Matthias Grimm <matthiasgrimm@users.sourceforge.net>
387*506fa893SAndreas Gohr *
388*506fa893SAndreas Gohr * @deprecated - fulltext indexer is used instead
389b59a406bSmatthiasgrimm */
390b59a406bSmatthiasgrimmfunction search_regex(&$data,$base,$file,$reg,$words){
391b59a406bSmatthiasgrimm
392b59a406bSmatthiasgrimm  //get text
393b59a406bSmatthiasgrimm  $text = io_readfile($base.'/'.$file);
394b59a406bSmatthiasgrimm  //lowercase text (u modifier does not help with case)
395b59a406bSmatthiasgrimm  $lctext = utf8_strtolower($text);
396f3f0262cSandi
397f3f0262cSandi  //do the fulltext search
398f3f0262cSandi  $matches = array();
3995ef370d2Smatthiasgrimm  if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
400f3f0262cSandi    //this is not the best way for snippet generation but the fastest I could find
401b59a406bSmatthiasgrimm    $q = $words[0];  //use first word for snippet creation
402d5a2a500Sandi    $p = utf8_strpos($lctext,$q);
403f3f0262cSandi    $f = $p - 100;
404d5a2a500Sandi    $l = utf8_strlen($q) + 200;
405f3f0262cSandi    if($f < 0) $f = 0;
406f3f0262cSandi    $snippet = '<span class="search_sep"> ... </span>'.
407d5a2a500Sandi               htmlspecialchars(utf8_substr($text,$f,$l)).
408f3f0262cSandi               '<span class="search_sep"> ... </span>';
409b59a406bSmatthiasgrimm    $mark    = '('.join('|', $words).')';
4105ef370d2Smatthiasgrimm    $snippet = preg_replace('#'.$mark.'#si','<span class="search_hit">\\1</span>',$snippet);
411f3f0262cSandi
412f3f0262cSandi    $data[] = array(
413b59a406bSmatthiasgrimm      'id'       => pathID($file),
4145ef370d2Smatthiasgrimm      'count'    => preg_match_all('#'.$mark.'#usi',$lctext,$matches),
415b59a406bSmatthiasgrimm      'poswords' => join(' ',$words),
416f3f0262cSandi      'snippet'  => $snippet,
417f3f0262cSandi    );
418f3f0262cSandi  }
419f3f0262cSandi
420f3f0262cSandi  return true;
421f3f0262cSandi}
422f3f0262cSandi
423b59a406bSmatthiasgrimm
424f3f0262cSandi/**
42515fae107Sandi * fulltext sort
42615fae107Sandi *
427f3f0262cSandi * Callback sort function for use with usort to sort the data
428f3f0262cSandi * structure created by search_fulltext. Sorts descending by count
42915fae107Sandi *
43015fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
431f3f0262cSandi */
432f3f0262cSandifunction sort_search_fulltext($a,$b){
433f3f0262cSandi  if($a['count'] > $b['count']){
434f3f0262cSandi    return -1;
435f3f0262cSandi  }elseif($a['count'] < $b['count']){
436f3f0262cSandi    return 1;
437f3f0262cSandi  }else{
438f3f0262cSandi    return strcmp($a['id'],$b['id']);
439f3f0262cSandi  }
440f3f0262cSandi}
441f3f0262cSandi
442f3f0262cSandi/**
443f3f0262cSandi * translates a document path to an ID
44415fae107Sandi *
44515fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
44637e34a5eSandi * @todo    move to pageutils
447f3f0262cSandi */
448156a608cSandifunction pathID($path,$keeptxt=false){
44949c713a3Sandi  $id = utf8_decodeFN($path);
45049c713a3Sandi  $id = str_replace('/',':',$id);
451156a608cSandi  if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
452f3f0262cSandi  $id = preg_replace('#^:+#','',$id);
453f3f0262cSandi  $id = preg_replace('#:+$#','',$id);
454f3f0262cSandi  return $id;
455f3f0262cSandi}
456f3f0262cSandi
457340756e4Sandi
458340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
459