page=str_replace(':', "",$page); if($subdir) { $subdir = trim($subdir,':\\\/'); $subdir = str_replace(':','/',$subdir); $this->subdir ="/$subdir"; chdir($subdir); } if($exact == 'on') $this->exact_page_match = true; if($tm) { list($this->timestamp,$this->t_when) = explode(':',$tm); $this->dtype = $dtype; } if($search) { $this->search = $search; } else if($fuzzy) { $this->fuzzy = $this->get_regex($fuzzy); } if($search || $fuzzy) { if($ltype) $this->ltype = $ltype; } ob_start(); $this->recurse('.'); if(!$this->match){ echo "No match for $subdir/$page" ."
\n"; } $contents = ob_get_contents(); ob_end_clean(); $contents = str_replace("\n","",$contents); echo $contents; } function recurse($dir) { $dh = opendir($dir); if (!$dh) return; while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') continue; if (is_dir("$dir/$file")) $this->recurse("$dir/$file"); if (preg_match("/\.meta$/", $file)) { if($this->page && !preg_match("/" . $this->page ."/",$file)) continue; if($this->exact_page_match) { if(!preg_match("/^" . $this->page ."\.meta$/",$file)) continue; } $store_name = preg_replace('/^\./', $this->subdir, "$dir/$file"); $id_name = PAGES . preg_replace("/\.meta$/","",$store_name) . '.txt'; if(!file_exists($id_name)) continue; $success = $this->get_data("$dir/$file","$id_name",$store_name); if($success) { $this->match = true; echo "\n
"; } } } closedir($dh); } /* @param string $file, the meta file @param string $id_path, path to dokuwiki page */ function get_data($file,$id_path,$store_name="") { global $current; $description = ""; $data = file_get_contents($file); $data_array = @unserialize(file_get_contents($file)); $creator =""; $creator_id=""; $contributors = array(); if ($data_array === false || !is_array($data_array)) return; if (!isset($data_array['current'])) return false; $current = $data_array['current']; if($this->t_when) { $tmstmp = $this->getcurrent('date', $this->dtype); if($this->t_when == 'b' && $tmstmp > $this->timestamp) { return false; } else if($this->t_when == 'a' && $tmstmp < $this->timestamp) { return false; } } $search = ""; $regex = ""; if($this->fuzzy) { $search = $this->fuzzy; $regex = '/(' . $search . ')/im'; } else if($this->search) { $search = $this->search; $regex = '/(' . $search . ')/m'; } if($regex) { if($this->ltype == 'descr') { $description = $this->getcurrent('description','abstract'); if(!preg_match($regex,$description)){ return false; } $description = preg_replace($regex,"$1",$description); } else if($this->ltype == 'media') { $media = $this->check_listtypes('media',$regex); if(!$media) return false; } else if($this->ltype == 'links') { $references = $this->check_listtypes('references',$regex); if(!$references) return false; } else if($this->ltype == 'contrib') { $contribs = $this->getcurrent('contributor', null); if(!$contribs) return false; if(!array_key_exists($search,$contribs)) return; $val = $contribs[$search]; unset($contribs[$search]); $search = "$search"; $contribs[$search] = $val; $contributors = $contribs; } else if($this->ltype == 'creator') { $creator = $this->getcurrent('creator', null); $creator_id = $this->getcurrent('user', null); if(!$creator && !$creator_id) return false; if(!preg_match($regex,$creator) && !preg_match($regex,$creator_id)) return; $creator=preg_replace($regex,"$1",$creator); $creator_id=preg_replace($regex,"$1",$creator_id); } } $this->match = true; echo $store_name ."\n"; echo "\n" . '' ."\n"; echo "\n"; $keys = array('title','date','creator','last_change','relation', 'description','contributor'); foreach ($keys AS $header) { switch($header) { case 'title': $title = $this->getcurrent($header, null); echo "\n"; break; case 'date': $this->process_dates($this->getcurrent('date', 'created'),$this->getcurrent('date', 'modified')); break; case 'user': if($creator || $creator_id) break; case 'creator': /* creator: string, full name of the user who created the page user: string, the login name of the user who created the page */ if(!$creator) { $creator = $this->getcurrent('creator', null); } if(!$creator_id) { $creator_id = $this->getcurrent('user', null); } $this->process_users($creator,$creator_id); break; case 'last_change': $last_change = $this->getSimpleKeyValue($this->getcurrent($header, null),"last_change"); if($last_change) { echo "\n"; echo "\n"; } break; case 'contributor': if(empty($contributors)) { $contributors = $this->getcurrent($header, null); } if(!$contributors) break; echo "\n"; echo ''; break; case 'relation': $isreferencedby = $this->getcurrent($header,'isreferencedby'); if(!$references) { $references = $this->getcurrent($header,'references'); } if(!$media) { $media = $this->getcurrent($header,'media'); } $firstimage = $this->getcurrent($header,'firstimage'); $haspart = $this->getcurrent($header,'haspart'); $subject = $this->getcurrent($header,'subject'); $this->process_relation($isreferencedby,$references,$media,$firstimage,$haspart,$subject); break; case 'description': echo "\n"; if(!$description) { $description = htmlentities($this->getcurrent($header,'abstract')); } $description = preg_replace("/[\n]+/",'
', $description); echo "\n"; break; default: break; } } echo "\n
$id_path
Title: $title
Last Change$last_change
Contributors
'; foreach($contributors as $userid=>$name) { $this->process_users($name,$userid, ''); } echo '
Description
$description
\n"; return true; $current = array(); } /* * @param array $ar metadata field * @param string $which which field */ function getSimpleKeyValue($ar,$which="") { $retv = ""; $types = array('C'=>'Create','E'=>'Edit','e' =>'minor edit','D'=>'Delete', 'R'=>'Revert'); if(!is_array($ar)) return false; foreach ($ar As $key=>$val) { if(!empty($val)) { if($which == 'last_change') { if($key == 'date') { $val = date("r", $val); } if($key == 'type') { $val = $types[$val]; } } $retv .= "$key:$val\n"; } } return $retv; } function process_users($creator,$user, $label = 'Created by') { if(empty($creator)) { echo "\n"; return; } if ($label) { $label .= ':'; echo "$label $creator (userid: $user)\n"; } else echo " $creator (userid: $user)\n"; } function process_dates($created, $modified) { $retv = ""; if ($created) { $rfc_cr = date("r", $created); echo "Date created:".$rfc_cr. "$created\n"; } if ($modified) { $rfc_mod = date("r", $modified); echo "Last modified:" . $rfc_mod . "$modified\n"; } } function insertListInTable($list,$type) { if($list) echo "$type$list\n"; } function process_relation($isreferencedby,$references,$media,$firstimage,$haspart,$subject) { echo "Relation\n"; if(!empty($isreferencedby)) { $list = $this->create_list(array_keys($isreferencedby)); $this->insertListInTable($list,'Backlinks'); } if(!empty($references)) { $list = $this->create_list(array_keys($references)); $this->insertListInTable($list,'Links'); } if(!empty($media)) { $list = $this->create_list(array_keys($media)); $this->insertListInTable($list,'Media'); } if(!empty($firstimage)) { echo "First Image$firstimage"; } if(!empty($haspart)) { $list = $this->create_list(array_keys($haspart)); $this->insertListInTable($list,'haspart'); } if(!empty($subject)) { $list = create_list(array_keys($subject)); $this->insertListInTable($list,'Subject'); } } function create_list($ar) { $list = "\n
    \n"; for($i=0; $i\n"; } $list .= "
\n"; return $list; } function getcurrent($which, $other) { global $current; if (!isset($current)) return ""; if ($other) { if (isset($current[$which][$other])) { return $current[$which][$other]; } } if (isset($current[$which]) && $other === null) { return $current[$which]; } return ""; } function get_regex($str) { $str = preg_replace('{([aeiou])\1+}','$1',$str); $a = str_split($str); for($i = 0; $i < count($a); $i++) { if(preg_match("/[aeiou]/",$a[$i])) { $a[$i] = '[aeiou]+'; } } return implode("",$a); } function check_listtypes($which,$regex) { if($which == 'references' || $which == 'media') { $ar = $this->getcurrent('relation',$which); // cli_plugin_metadisplay::write_debug($ar ."\n" . print_r($ar,1)); if(is_array($ar)) { $references = array_keys($ar); // references here refers to either images or links } else $references = $ar; if(!empty($references)) { $str = implode('|',$references); if(preg_match($regex,$str)) { $str = preg_replace($regex,"$1",$str); if($str) { $arr = explode('|', $str); $vals = array_values($ar); $val_str = implode('|',$vals); $val_str = preg_replace($regex,"$1",$val_str); $vals = explode('|',$val_str); return array_combine($arr,$vals); } } return false; } return false; } return $ar; } }