page=str_replace(':', "",$page); if($subdir) { $subdir = trim($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){ if($page) $page = ":$page"; if($subdir) $subdir = "for $subdir"; echo "No match $subdir$page" ."\n"; } $contents = ob_get_contents(); ob_end_clean(); 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 "\n----------------\n$store_name"; echo "\n$id_path\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[Title: $title]"; 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 "[Last Change] \n$last_change\n"; } break; case 'contributor': if(empty($contributors)) { $contributors = $this->getcurrent($header, null); } if(!$contributors) break; echo "Contributors\n"; echo ''; foreach($contributors as $userid=>$name) { $this->process_users($name,$userid, ''); } 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 "[Description]\n"; if(!$description) { $description = htmlentities($this->getcurrent($header,'abstract')); } $description = preg_replace("/[\n]+/","\n", $description); echo "$description\n"; break; default: break; } } echo "\n\n"; $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 "\n$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 "\nDate 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) { 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] \n$firstimage\n"; } 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"; for($i=0; $igetcurrent('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; } }