PluginProbe
CSS & JavaScript Toolbox / 8.0
CSS & JavaScript Toolbox v8.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 8.0, at framework/extensions/extensions.class.php

384 lines 11.3 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 $defDocs;
35
36 /**
37 * put your comment there...
38 *
39 * @var mixed
40 */
41 protected $extensions;
42
43 /**
44 * put your comment there...
45 *
46 * @var mixed
47 */
48 protected $file2Classmap;
49
50 /**
51 * put your comment there...
52 *
53 * @var mixed
54 */
55 protected $incompatibilies;
56
57 /**
58 * put your comment there...
59 *
60 * @var mixed
61 */
62 protected $loadMethod;
63
64 /**
65 * put your comment there...
66 *
67 * @var mixed
68 */
69 protected $onautoload = array('parameters' => array('file', 'class'));
70
71 /**
72 * put your comment there...
73 *
74 * @var mixed
75 */
76 protected $onbindevent = array('parameters' => array('event', 'callback'));
77
78 /**
79 * put your comment there...
80 *
81 * @var mixed
82 */
83 protected $ondetectextension = array('parameters' => array('extension'));
84
85 /**
86 * put your comment there...
87 *
88 * @var mixed
89 */
90 protected $ongetactiveplugins = array('parameters' => array('plugins'));
91
92 /**
93 * put your comment there...
94 *
95 * @var mixed
96 */
97 protected $onload = array('parameters' => array('params'));
98
99 /**
100 * put your comment there...
101 *
102 * @var mixed
103 */
104 protected $onloadcallback = array('parameters' => array('callback'));
105
106 /**
107 * put your comment there...
108 *
109 * @var mixed
110 */
111 protected $onloaddefinition = array('parameters' => array('definition'));
112
113 /***
114 * put your comment there...
115 *
116 * @var mixed
117 */
118 protected $ontregisterautoload = array('parameters' => array('callback'));
119
120 /**
121 * put your comment there...
122 *
123 * @var mixed
124 */
125 protected $onreloadcacheparameters = array('parameters' => array('params'));
126
127 /**
128 * put your comment there...
129 *
130 * @var mixed
131 */
132 protected $onloaded = array(
133 'hookType' => CJTWordpressEvents::HOOK_ACTION,
134 'parameters' => array('class', 'extension', 'definition', 'result')
135 );
136
137 /**
138 * put your comment there...
139 *
140 * @var mixed
141 */
142 protected $prefix;
143
144 /**
145 * put your comment there...
146 *
147 * @param mixed $className
148 */
149 public function __autoload($className) {
150 // Load only classed defined on the list!
151 if (isset($this->extensions[$className])) {
152 $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className);
153 // Import class file!
154 require_once $classFile;
155 }
156 }
157
158 /**
159 * put your comment there...
160 *
161 * @param mixed $prefix
162 * @param mixed $loadMethod
163 * @return CJTExtensions
164 */
165 public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) {
166 // Hookable!
167 parent::__construct();
168 // Initializing!
169 $this->prefix = $prefix;
170 $this->loadMethod = $loadMethod;
171 }
172
173 /**
174 * put your comment there...
175 *
176 */
177 public function __destruct() {
178 spl_autoload_unregister(array($this, '__autoload'));
179 }
180
181 /**
182 * put your comment there...
183 *
184 * @param mixed $reload
185 * @return CJTExtensions
186 */
187 public function & getExtensions($reload = false) {
188 // Get cached extensions or cache then if not yest cached!
189 extract($this->onreloadcacheparameters(compact('reload')));
190 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
191 //Resting!
192 $this->file2Classmap = array();
193 $extensions = array();
194 // filter all installed Plugins to fetch all out Extensions!
195 $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
196 foreach ($activePlugins as $file) {
197 $pluginDir = dirname($file);
198 $pluginName = basename($pluginDir);
199 // Any plugin with our prefix is a CJT extension!
200 if (strpos($pluginName, $this->prefix) === 0) {
201 // CJT Extsnsion must has the definition XML file!
202 // First try for Edition-Specific file
203 // if not exists try the generic one.
204 $xmlFile = "{$pluginDir}/{$pluginName}.xml";
205 if (file_exists($xmlFile)) {
206 // Get Plugin primary data!
207 $extension = array();
208 $extension['pluginFile'] = $file;
209 $extension['file'] = basename($file);
210 $extension['defFile'] = basename($pluginDir) . DIRECTORY_SEPARATOR . basename($xmlFile);
211 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
212 $extension['dir'] = basename($pluginDir);
213 $extension['name'] = $pluginName;
214 // Cache XML file.
215 $extension['definition']['raw'] = file_get_contents($xmlFile);
216 // Filer!
217 $extension = $this->ondetectextension($extension);
218 // Read Basic XML Definition!
219 $definitionXML = $this->onloaddefinition(new SimpleXMLElement($extension['definition']['raw']));
220 $attrs = $definitionXML->attributes();
221 $extension['defDoc'] = $definitionXML;
222 $extension['definition']['primary']['loadMethod'] = (string) $attrs->loadMethod;
223 $extension['definition']['primary']['requiredLicense'] = (string) $definitionXML->license;
224 $className = ((string) $attrs->class);
225 // Add to list!
226 $extensions[$className] = $extension;
227 // Map Plugin FILE-2-CLASS name!
228 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
229 }
230 }
231 }
232 }
233 $this->extensions = $this->onload($extensions);
234 // Chaining
235 return $this->extensions;
236 }
237
238 /**
239 * put your comment there...
240 *
241 */
242 public function load() {
243 // Initialize.
244 $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version);
245 // Auto load CJT extensions files when requested.
246 spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
247 // Load all CJT extensions!
248 foreach ($this->getExtensions() as $class => $extension) {
249 // Filters!
250 extract($this->onload($extension, compact('class', 'extension')));
251 // Build Extension plugin path
252 $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
253 // Set runtime variables.
254 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
255 // Load definition.
256 $definitionXML = $extension['defDoc'];
257 // Extensions below version 1.0 use static classes
258 // while version 1.0 and up use objects
259 if (((string) $definitionXML->attributes()->version) == '1.0') {
260 // Instantiate extension object
261 $extensionObject = new $class($extension);
262 // Hold extension object
263 $extension['exObject'] = $extensionObject;
264 // Obejct callback
265 $callback = array($extensionObject, $this->loadMethod);
266 }
267 else {
268 # Static callback
269 $callback = array($class, $this->loadMethod);
270 }
271 // Callback filter
272 $callback = $this->onloadcallback($callback);
273 // If auto load is speicifd then import class file and bind events.
274 if ($extension['definition']['primary']['loadMethod'] == 'auto') {
275 // If frameworkVersion is not provided assume its 0 (Older version)
276 // before frameworkversion chech even supported.
277 // otherwise compare it with current frameworkversion
278 // If the version MAJOR is different current
279 // then its incompatible.
280 $extensionVer = new CJT_Framework_Version_Version((int) ((string) $definitionXML->attributes()->requireFrameworkVersion));
281 if ($frameworkVersion->getMajor() < $extensionVer->getMajor()) {
282 // Detects which requird updates CJT or the Extension itself.
283 $extension['incompatibleMessage']['msg'] = cssJSToolbox::getText('Extension is required CJT Framework Version higher than currently installed, CJT need to get updated!!!');
284 $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Aborted');
285 // Add to incomaptibility list.
286 $this->incompatibilies[$pluginPath] = $extension;
287 }
288 else {
289 # Detect extensions required old Framework
290 if ($frameworkVersion->getMajor() > $extensionVer->getMajor()) {
291 $extension['incompatibleMessage']['msg'] = cssJSToolbox::getText('Extension is required old CJT Framework Version than the installed. This extension might need to get update. Please check if this extension is currently behaving correctly!!!');
292 $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Ignored');
293 // Add to incomaptibility list.
294 $this->incompatibilies[$pluginPath] = $extension;
295 }
296 // Bind events for compatible extensions.
297 foreach ($definitionXML->getInvolved->event as $event) {
298 // filter!
299 extract($this->onbindevent(compact('event', 'callback')));
300 // Bind!
301 CJTPlugin::on((string) $event->attributes()->type, $callback);
302 }
303 }
304 }
305 else { // If manual load specified just
306 if (class_exists($class)) { // Make sure the class is loaded!
307 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
308 }
309 }
310 }
311 if (!empty($this->incompatibilies)) {
312 // Hook for processing incomaptible extensions.
313 add_action('admin_notices', array(& $this, 'processIncompatibles'));
314 }
315 }
316
317 /**
318 * put your comment there...
319 *
320 * @param mixed $pluginName
321 */
322 public function & getDefDoc($pluginName) {
323 # Find if cached or create it
324 if (!isset($this->defDocs[$pluginName])) {
325 // Add CJT Def doc to def docs list
326 $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $pluginName . DIRECTORY_SEPARATOR . "{$pluginName}.xml";
327 // Extension might removed while its license key still in the database
328 // Make sure the extension still exists
329 if (file_exists($pluginXMLFile)) {
330 $this->defDocs[$pluginName] = new SimpleXMLElement(file_get_contents($pluginXMLFile));
331 }
332 else {
333 # Return null when extension is absent!
334 $this->defDocs[$pluginName] = null;
335 }
336 }
337 return $this->defDocs[$pluginName];
338 }
339
340 /**
341 * put your comment there...
342 *
343 */
344 public function & getFiles2ClassesMap() {
345 return $this->file2Classmap;
346 }
347
348 /**
349 * put your comment there...
350 *
351 * @TODO: REMOVE HTML-MARKUP. CJT PLUGIN NEVER WRITE MARKUP IMIXED WITH HTML. ITS VERY BAD PROGRAMMING PRACTICE. THIS WILL BE REMOVED NEXT TIME AS WE IN RUSH!!!
352 */
353 public function processIncompatibles() {
354 // Proces only if in CJT page.
355 if (!preg_match('/\/plugins\.php|page\=cjtoolbox/', $_SERVER['REQUEST_URI'])) {
356 return;
357 }
358 // INitialize.
359 $message = cssJSToolbox::getText('CJT detects incompatible installed extensions, listed below with status message for every extension:');
360 $list = '';
361 // For every compatible extension add
362 // an list item with details
363 // if there is an update available or provide
364 // a direct link to CJT website if no upgrade is available.
365 // Upgrade wont be available in case no license key is activated!
366 foreach ($this->incompatibilies as $class => $extension) {
367 // Show details.
368 $pluginInfo = get_plugin_data($extension['pluginFile']);
369 // List item Markup
370 $list .= "<li><a target='_blank' href='{$pluginInfo['PluginURI']}'>{$pluginInfo['Name']}</a> (Status: {$extension['incompatibleMessage']['flag']}, Message: {$extension['incompatibleMessage']['msg']})</li>\n";
371 }
372 // Output full message.
373 // TODO: BAD PRACTICE1!!!!! NEVER MIX HTML WITH PHP, JUST TEMPORARY1!!!
374 echo "<div class='cjt-incomaptible-extensions-notice updated' style='font-size:14px;font-weight:bold;padding-top:11px'>
375 <span>{$message}</span>
376 <ul style='list-style-type: circle;padding-left: 27px;font-size: 12px;'>{$list}</ul>
377 </div>";
378 }
379
380 } // End class.
381
382
383 // Hookable!
384 CJTExtensions::define('CJTExtensions', array('hookType' => CJTWordpressEvents::HOOK_FILTER));