1<?php 2/** 3 * DokuWiki Plugin struct (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class helper_plugin_struct_config extends DokuWiki_Plugin { 13 14 /** 15 * @param string $val 16 * 17 * @return array 18 */ 19 public function parseSort($val) { 20 if(substr($val, 0, 1) == '^') { 21 return array(substr($val, 1), false); 22 } 23 return array($val, true); 24 } 25 26 /** 27 * @param $logic 28 * @param $val 29 * 30 * @return array|bool 31 */ 32 public function parseFilterLine($logic, $val) { 33 $flt = $this->parseFilter($val); 34 if($flt) { 35 $flt[] = $logic; 36 return $flt; 37 } 38 return false; 39 } 40 41 /** 42 * Parse a filter 43 * 44 * @param string $val 45 * 46 * @return array ($col, $comp, $value) 47 * @throws dokuwiki\plugin\struct\meta\StructException 48 */ 49 protected function parseFilter($val) { 50 51 $comps = dokuwiki\plugin\struct\meta\Search::$COMPARATORS; 52 $comps[] = '*~'; 53 array_unshift($comps, '<>'); 54 $comps = array_map('preg_quote_cb', $comps); 55 $comps = join('|', $comps); 56 57 if(!preg_match('/^(.*?)('.$comps.')(.*)$/', $val, $match)) { 58 throw new dokuwiki\plugin\struct\meta\StructException('Invalid search filter %s', hsc($val)); 59 } 60 array_shift($match); // we don't need the zeroth match 61 $match[0] = trim($match[0]); 62 $match[2] = trim($match[2]); 63 return $match; 64 } 65} 66 67// vim:ts=4:sw=4:et: 68