1<?php 2 3 4// must be run within Dokuwiki 5if(!defined('DOKU_INC')) die(); 6if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 7 8 9 10class SI_MatchEntry implements IteratorAggregate { 11 12 public $all = array(); 13 public $first = array(); 14 15 private $matchers = array(); 16 17 18 function __construct() { 19 $default = null; 20 $types = array(); 21 $files = glob(SUBJ_IDX_PLUGINS . 'Entry*.php'); 22 foreach ($files as $file) { 23 $matched = preg_match('/Entry(.+?)\.php/', $file, $match); 24 if ($matched) { 25 require_once($file); 26 $class = 'SI_Entry' . $match[1]; 27 $matcher = new $class(); 28 $this->matchers[$matcher->order] = $matcher; 29 $types[$matcher->section] = $matcher->type; 30 if ($matcher->type == 'default') $default = $matcher; 31 } 32 } 33 $default->types = $types; 34 ksort($this->matchers); 35 } 36 37 38 function match($text) { 39 $matches = array(); 40 $matched = false; 41 foreach ($this->matchers as $matcher) { 42 if ($matcher->match($text) === true) { 43 $matches = array_merge($matches, $matcher->items); 44 $matched = true; 45 } 46 } 47 $this->all= $matches; 48 $this->first = $matches[0]; 49 return $matched; 50 } 51 52 53 function getIterator() { 54 return new ArrayIterator($this->matchers); 55 } 56} 57 58 59 60/** 61 * Base class for all Matchers 62 */ 63class SI_Entry { 64 65 public $order = 0; // order in which to use this matcher 66 public $items = array(); // the different elements of the match: section, display, entry, type 67 public $type = 'default'; // type of entry matched 68 public $section = 0; // section this entry will be added to 69 public $regex = ''; 70 71 function match() { 72 } 73}