1<?php 2 3/** 4 * DokuWiki Plugin struct (Helper Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 8 */ 9 10class helper_plugin_struct_config extends DokuWiki_Plugin 11{ 12 /** 13 * @param string $val 14 * 15 * @return array 16 */ 17 public function parseSort($val) 18 { 19 if (substr($val, 0, 1) == '^') { 20 return array(substr($val, 1), false); 21 } 22 return array($val, true); 23 } 24 25 /** 26 * @param $logic 27 * @param $val 28 * 29 * @return array|bool 30 */ 31 public function parseFilterLine($logic, $val) 32 { 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 52 $comps = dokuwiki\plugin\struct\meta\Search::$COMPARATORS; 53 $comps[] = '*~'; 54 array_unshift($comps, '<>'); 55 $comps = array_map('preg_quote_cb', $comps); 56 $comps = join('|', $comps); 57 58 if (!preg_match('/^(.*?)(' . $comps . ')(.*)$/', $val, $match)) { 59 throw new dokuwiki\plugin\struct\meta\StructException('Invalid search filter %s', hsc($val)); 60 } 61 array_shift($match); // we don't need the zeroth match 62 $match[0] = trim($match[0]); 63 $match[2] = trim($match[2]); 64 return $match; 65 } 66} 67 68// vim:ts=4:sw=4:et: 69