1 | <?php |
---|
2 | require_once('LLReader/Util.php'); |
---|
3 | //require_once('LLReader/Constant.php'); |
---|
4 | |
---|
5 | class LLReader { |
---|
6 | private $config; |
---|
7 | private $plugins; |
---|
8 | private $feeds; |
---|
9 | private $update_feeds; |
---|
10 | |
---|
11 | public function __construct($config){ |
---|
12 | $this->config = $config; |
---|
13 | $this->plugins = array(); |
---|
14 | $this->feeds = array(); |
---|
15 | $this->update_feeds = array(); |
---|
16 | } |
---|
17 | |
---|
18 | public function run () { |
---|
19 | $this->load_plugins(); |
---|
20 | |
---|
21 | $phases = array( |
---|
22 | 'Subscription', |
---|
23 | 'Filter', |
---|
24 | 'Publish' |
---|
25 | ); |
---|
26 | |
---|
27 | foreach ( $phases as $phase ) { |
---|
28 | $plugins = $this->get_plugins($phase); |
---|
29 | |
---|
30 | foreach ( $plugins as $plugin ) { |
---|
31 | $plugin->execute($this); |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | private function load_plugins () { |
---|
37 | foreach ($this->config['plugins'] as $name => $config) { |
---|
38 | $class = 'LLReader_Plugin_' . $name; |
---|
39 | $include = preg_replace('/_/', '/', $class) . '.php'; |
---|
40 | $ret = include_once($include); |
---|
41 | |
---|
42 | $err = 0; |
---|
43 | |
---|
44 | if ($ret) { |
---|
45 | if ( preg_match("/^(.+?)_/", $name, $matches) ) { |
---|
46 | $phase = $matches[1]; |
---|
47 | $this->plugins[$phase][] = new $class($this, $config); |
---|
48 | $this->log('[OK] ' . $class . ' loaded'); |
---|
49 | } |
---|
50 | else { |
---|
51 | $this->log('[ERR] ' . 'class name is invalid: ' . $class); |
---|
52 | $err++; |
---|
53 | } |
---|
54 | } |
---|
55 | else { |
---|
56 | $this->log('[ERR] ' . $class . ' not found'); |
---|
57 | $err++; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | if ($err) { |
---|
62 | $this->_die('function load_plugins()'); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | public function log ($msg) { |
---|
67 | LLReader_Util::log($msg); |
---|
68 | } |
---|
69 | |
---|
70 | public function p ($var) { |
---|
71 | LLReader_Util::p($var); |
---|
72 | } |
---|
73 | |
---|
74 | public function _die ($msg) { |
---|
75 | $this->log('[DIE] ' . $msg); |
---|
76 | exit(); |
---|
77 | } |
---|
78 | |
---|
79 | private function get_plugins ($phase) { |
---|
80 | if ( empty($this->plugins[$phase]) ) { |
---|
81 | return array(); |
---|
82 | } |
---|
83 | return $this->plugins[$phase]; |
---|
84 | } |
---|
85 | |
---|
86 | public function get_feeds () { |
---|
87 | if ( count($this->update_feeds) > 0 ) { |
---|
88 | return $this->update_feeds; |
---|
89 | } |
---|
90 | return $this->feeds; |
---|
91 | } |
---|
92 | |
---|
93 | public function add_feed ($feed) { |
---|
94 | $this->feeds[] = $feed; |
---|
95 | } |
---|
96 | } |
---|
97 | ?> |
---|