1<?php 2/** 3 * Plugin metadisplay" 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Myron Turner <turnermm02@shaw.ca 7 */ 8if(!defined('DOKU_INC')) die(); 9use splitbrain\phpcli\Options; 10 11class cli_plugin_metadisplay extends DokuWiki_CLI_Plugin { 12private $helper; 13protected function setup(Options $options) { 14 $options->setHelp('Displays metadata for specified namespace or page' . "\n". 15 "USAGE (from Command Line):\n" . "php plugin.php metadisplay " . 16 "[-h] [--no-colors] [--loglevel ] \n [[-n --namespace|.] [[-p -page] [-e --exact ]][-c --cmdL]][[-b --before|-a --after] timestamp -d -dtype [modified|created]] [[-s --search|-f --fuzzy] [search-term] [-l --ltype contrib|creator]] -c --cmdL. " 17 . "\n" . '<br /><b>timestamp</b> can be timestamp or numerical date of the form: <br /><b>Year-Month-Day</b>' 18 ); 19 $options->registerOption('version', 'print version and exit', 'v'); 20 $options->registerOption('namespace', 21 'metadata namespace; the -n option with dot [.] defaults to the top level. This option cannot be left blank if it is not followed by a page name','n'); 22 $options->registerOption('page', 'page name without namespace or extension, e.g. start', 'p'); 23 $options->registerOption('exact', 'set to "on" for exact <b><u>page</u></b> match', 'e'); 24 $options->registerOption('cmdL', 'set automatically to "html" when accessing from admin.php', 'c'); 25 $options->registerOption('before', 'before timestamp', 'b'); 26 $options->registerOption('after', 'after timestamp', 'a'); 27 $options->registerOption('dtype', 'sets whether file\'s timestamp is read from "created" or "modified" field', 'd'); 28 $options->registerOption('search', 'set to search term, exact match', 's'); 29 $options->registerOption('fuzzy', 'set to search term, fuzzy match', 'f'); 30 $options->registerOption('ltype', 'set to search type: link, media, creator, contrib (contrib = contributor)', 'l'); 31} 32 33// implement your code 34protected function main(Options $options) { 35 if ($options->getOpt('namespace')) { 36 $opts = $options->getArgs(); 37 38 $clopts = $this->get_commandLineOptions($opts); 39 40 if($clopts['cl'] == 'html') { 41 $helper = plugin_load('helper','metadisplay_html'); 42 } else { 43 $helper = plugin_load('helper','metadisplay_plaintext'); 44 } 45 46 $helper->init($clopts); 47 48 } 49 else if ($options->getOpt('version')) { 50 $info = $this->getInfo(); 51 $this->success($info['date']); 52 } else { 53 echo $options->help(); 54 } 55} 56 57function get_commandLineOptions($opts) { 58 if(function_exists('is_countable') &&!is_countable($opts)) return; 59 60 $page=""; $exact=""; $cl=""; $search=""; $fuzzy=""; $tm=""; $dtype=""; $ltype=""; 61 $namespace = array_shift($opts); 62 for($i=0; $i<count($opts); $i++) { 63 $cl_switch = trim($opts[$i],'-'); 64 switch ($cl_switch) { 65 case 'p': 66 case 'page': 67 $page = $opts[$i+1]; 68 break; 69 case 'e': 70 case 'exact': 71 $exact = $opts[$i+1]; 72 break; 73 case 's': 74 case 'search': 75 $search = $opts[$i+1]; 76 break; 77 case 'f': 78 case 'fuzzy': 79 $fuzzy = $opts[$i+1]; 80 break; 81 case 'c': 82 case 'cmdL': 83 $cl = $opts[$i+1]; 84 break; 85 case 'b': 86 case 'before': 87 $tm = $this->get_timestamp( $opts[$i+1]) . ':b'; 88 break; 89 case 'a': 90 case 'after': 91 $tm = $this->get_timestamp( $opts[$i+1]) . ':a'; 92 break; 93 case 'd': 94 case 'dtype': 95 $dtype = $opts[$i+1]; 96 break; 97 case 'l': 98 case 'ltype': 99 $ltype = $opts[$i+1]; 100 break; 101 } 102 } 103 104 $ret = array('namespace'=>$namespace,'page'=>$page,'exact'=>$exact,'search'=>$search,'fuzzy'=>$fuzzy, 105 'cl'=>$cl,'tm'=>$tm,'dtype'=>$dtype, 'ltype'=>$ltype); 106 return $ret; 107} 108 109function get_timestamp($date_str){ 110 list($year,$month,$day) = explode('-',$date_str); 111 $hour = '0'; $min = '01'; $second = '0'; 112 return mktime($hour, $min, $second,$month,$day,$year); 113} 114public function write_debug($msg) { 115return; 116 $dfile = $metafile = metaFN("dbg:debug",'.dbg'); 117 $date_time = date('Y-m-d h:i:s'); 118 io_saveFile($dfile , "$date_time\n$msg\n",true); 119} 120} //end class definition 121 122 123 124