PluginProbe
CSS & JavaScript Toolbox / 6.0
CSS & JavaScript Toolbox v6.0
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / extensions / extensions.class.php

extensions.class.php in CSS & JavaScript Toolbox 6.0, at framework/extensions/extensions.class.php

268 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 /**
10 *
11 */
12 class CJTExtensions extends CJTHookableClass {
13
14 /**
15 *
16 */
17 const CACHE_OPTION_NAME = 'cjt_extensions';
18
19 /**
20 *
21 */
22 const LOAD_METHOD = 'getInvolved';
23
24 /**
25 *
26 */
27 const PREFIX = 'cjte-';
28
29 /**
30 * put your comment there...
31 *
32 * @var mixed
33 */
34 protected $extensions;
35
36 /**
37 * put your comment there...
38 *
39 * @var mixed
40 */
41 protected $file2Classmap;
42
43 /**
44 * put your comment there...
45 *
46 * @var mixed
47 */
48 protected $loadMethod;
49
50 /**
51 * put your comment there...
52 *
53 * @var mixed
54 */
55 protected $onautoload = array('parameters' => array('file', 'class'));
56
57 /**
58 * put your comment there...
59 *
60 * @var mixed
61 */
62 protected $onbindevent = array('parameters' => array('event', 'callback'));
63
64 /**
65 * put your comment there...
66 *
67 * @var mixed
68 */
69 protected $ondetectextension = array('parameters' => array('extension'));
70
71 /**
72 * put your comment there...
73 *
74 * @var mixed
75 */
76 protected $ongetactiveplugins = array('parameters' => array('plugins'));
77
78 /**
79 * put your comment there...
80 *
81 * @var mixed
82 */
83 protected $onload = array('parameters' => array('params'));
84
85 /**
86 * put your comment there...
87 *
88 * @var mixed
89 */
90 protected $onloadcallback = array('parameters' => array('callback'));
91
92 /**
93 * put your comment there...
94 *
95 * @var mixed
96 */
97 protected $onloaddefinition = array('parameters' => array('definition'));
98
99 /***
100 * put your comment there...
101 *
102 * @var mixed
103 */
104 protected $ontregisterautoload = array('parameters' => array('callback'));
105
106 /**
107 * put your comment there...
108 *
109 * @var mixed
110 */
111 protected $onreloadcacheparameters = array('parameters' => array('params'));
112
113 /**
114 * put your comment there...
115 *
116 * @var mixed
117 */
118 protected $onloaded = array(
119 'hookType' => CJTWordpressEvents::HOOK_ACTION,
120 'parameters' => array('class', 'extension', 'definition', 'result')
121 );
122
123 /**
124 * put your comment there...
125 *
126 * @var mixed
127 */
128 protected $prefix;
129
130 /**
131 * put your comment there...
132 *
133 * @param mixed $className
134 */
135 public function __autoload($className) {
136 // Load only classed defined on the list!
137 if (isset($this->extensions[$className])) {
138 $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className);
139 // Import class file!
140 require_once $classFile;
141 }
142 }
143
144 /**
145 * put your comment there...
146 *
147 * @param mixed $prefix
148 * @param mixed $loadMethod
149 * @return CJTExtensions
150 */
151 public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) {
152 // Hookable!
153 parent::__construct();
154 // Initializing!
155 $this->prefix = $prefix;
156 $this->loadMethod = $loadMethod;
157 }
158
159 /**
160 * put your comment there...
161 *
162 */
163 public function __destruct() {
164 spl_autoload_unregister(array($this, '__autoload'));
165 }
166
167 /**
168 * put your comment there...
169 *
170 * @param mixed $reload
171 * @return CJTExtensions
172 */
173 public function & getExtensions($reload = false) {
174 // Get cached extensions or cache then if not yest cached!
175 extract($this->onreloadcacheparameters(compact('reload')));
176 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
177 //Resting!
178 $this->file2Classmap = array();
179 $extensions = array();
180 // filter all installed Plugins to fetch all out Extensions!
181 $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
182 foreach ($activePlugins as $file) {
183 $pluginDir = dirname($file);
184 $pluginName = basename($pluginDir);
185 // Any plugin with our prefix is a CJT extension!
186 if (strpos($pluginName, $this->prefix) === 0) {
187 // CJT Extsnsion must has the definition XML file!
188 $xmlFile = "{$pluginDir}/{$pluginName}.xml";
189 if (file_exists($xmlFile)) {
190 // Get Plugin primary data!
191 $extension = array();
192 $extension['file'] = basename($file);
193 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
194 $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ;
195 $extension['name'] = $pluginName;
196 // Cache XML file.
197 $extension['definition']['raw'] = file_get_contents($xmlFile);
198 // Filer!
199 $extension = $this->ondetectextension($extension);
200 // Read Basic XML Definition!
201 $definitionXML = $this->onloaddefinition(new SimpleXMLElement($extension['definition']['raw']));
202 $attrs = $definitionXML->attributes();
203 $extension['definition']['primary']['loadMethod'] = (string) $attrs->loadMethod;
204 $extension['definition']['primary']['requiredLicense'] = (string) $definitionXML->license;
205 $className = ((string) $attrs->class);
206 // Add to list!
207 $extensions[$className] = $extension;
208 // Map Plugin FILE-2-CLASS name!
209 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
210 $definitionXML = null;
211 }
212 }
213 }
214 // Update the cache Cache!
215 // ----update_option(self::CACHE_OPTION_NAME, $extensions);
216 }
217 $this->extensions = $this->onload($extensions);
218 // Chaining
219 return $this->extensions;
220 }
221
222 /**
223 * put your comment there...
224 *
225 */
226 public function load() {
227 // Auto load CJT extensions files when requested.
228 spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
229 // Load all CJT extensions!
230 foreach ($this->getExtensions() as $class => $extension) {
231 extract($this->onload($extension, compact('class', 'extension')));
232 // Initialize common vars!
233 $callback = $this->onloadcallback(array($class, $this->loadMethod));
234 $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
235 // Set runtime variables.
236 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
237 // If auto load is speicifd then import class file and bind events.
238 if ($extension['definition']['primary']['loadMethod'] == 'auto') {
239 // Bind events!
240 $definitionXML = new SimpleXMLElement($extension['definition']['raw']);
241 foreach ($definitionXML->getInvolved->event as $event) {
242 // filter!
243 extract($this->onbindevent(compact('event', 'callback')));
244 // Bind!
245 CJTPlugin::on((string) $event->attributes()->type, $callback);
246 }
247 }
248 else { // If manual load specified just
249 if (class_exists($class)) { // Make sure the class is loaded!
250 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
251 }
252 }
253 }
254 }
255
256 /**
257 * put your comment there...
258 *
259 */
260 public function & getFiles2ClassesMap() {
261 return $this->file2Classmap;
262 }
263
264 } // End class.
265
266
267 // Hookable!
268 CJTExtensions::define('CJTExtensions', array('hookType' => CJTWordpressEvents::HOOK_FILTER));