PluginProbe
CSS & JavaScript Toolbox / 6.0.9
CSS & JavaScript Toolbox v6.0.9
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
← All changes | framework/extensions/extensions.class.php +72 -268 11.46.0.9 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 -*
3 +*
4 4 */
5 5
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
@@ -6,136 +6,114 @@
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
8 8
9 9 /**
10 -*
10 +*
11 11 */
12 12 class CJTExtensions extends CJTHookableClass {
13 -
13 +
14 14 /**
15 - *
15 + *
16 16 */
17 17 const CACHE_OPTION_NAME = 'cjt_extensions';
18 -
18 +
19 19 /**
20 - *
20 + *
21 21 */
22 22 const LOAD_METHOD = 'getInvolved';
23 -
23 +
24 24 /**
25 - *
25 + *
26 26 */
27 - const PREFIXS = 'cjte-,css-javascript-toolbox-';
28 -
27 + const PREFIX = 'cjte-';
28 +
29 29 /**
30 30 * put your comment there...
31 - *
31 + *
32 32 * @var mixed
33 33 */
34 - protected $defDocs;
35 -
36 - /**
37 - * put your comment there...
38 - *
39 - * @var mixed
40 - */
41 34 protected $extensions;
42 -
35 +
43 36 /**
44 37 * put your comment there...
45 - *
38 + *
46 39 * @var mixed
47 40 */
48 41 protected $file2Classmap;
49 -
42 +
50 43 /**
51 44 * put your comment there...
52 - *
45 + *
53 46 * @var mixed
54 47 */
55 - protected $incompatibilies;
56 -
57 - /**
58 - * put your comment there...
59 - *
60 - * @var mixed
61 - */
62 - protected $incompatibleAddons = array();
63 -
64 -
65 - /**
66 - * put your comment there...
67 - *
68 - * @var mixed
69 - */
70 48 protected $loadMethod;
71 -
49 +
72 50 /**
73 51 * put your comment there...
74 - *
52 + *
75 53 * @var mixed
76 54 */
77 55 protected $onautoload = array('parameters' => array('file', 'class'));
78 -
56 +
79 57 /**
80 58 * put your comment there...
81 - *
59 + *
82 60 * @var mixed
83 61 */
84 62 protected $onbindevent = array('parameters' => array('event', 'callback'));
85 -
63 +
86 64 /**
87 65 * put your comment there...
88 - *
66 + *
89 67 * @var mixed
90 68 */
91 69 protected $ondetectextension = array('parameters' => array('extension'));
92 -
70 +
93 71 /**
94 72 * put your comment there...
95 - *
73 + *
96 74 * @var mixed
97 75 */
98 76 protected $ongetactiveplugins = array('parameters' => array('plugins'));
99 -
77 +
100 78 /**
101 79 * put your comment there...
102 - *
80 + *
103 81 * @var mixed
104 82 */
105 83 protected $onload = array('parameters' => array('params'));
106 -
84 +
107 85 /**
108 86 * put your comment there...
109 - *
87 + *
110 88 * @var mixed
111 89 */
112 90 protected $onloadcallback = array('parameters' => array('callback'));
113 -
91 +
114 92 /**
115 93 * put your comment there...
116 - *
94 + *
117 95 * @var mixed
118 96 */
119 97 protected $onloaddefinition = array('parameters' => array('definition'));
120 -
98 +
121 99 /***
122 100 * put your comment there...
123 - *
101 + *
124 102 * @var mixed
125 103 */
126 104 protected $ontregisterautoload = array('parameters' => array('callback'));
127 -
105 +
128 106 /**
129 107 * put your comment there...
130 - *
108 + *
131 109 * @var mixed
132 110 */
133 111 protected $onreloadcacheparameters = array('parameters' => array('params'));
134 -
112 +
135 113 /**
136 114 * put your comment there...
137 - *
115 + *
138 116 * @var mixed
139 117 */
140 118 protected $onloaded = array(
141 119 'hookType' => CJTWordpressEvents::HOOK_ACTION,
@@ -140,23 +118,22 @@
140 118 protected $onloaded = array(
141 119 'hookType' => CJTWordpressEvents::HOOK_ACTION,
142 120 'parameters' => array('class', 'extension', 'definition', 'result')
143 121 );
144 -
122 +
145 123 /**
146 124 * put your comment there...
147 - *
125 + *
148 126 * @var mixed
149 127 */
150 128 protected $prefix;
151 -
129 +
152 130 /**
153 131 * put your comment there...
154 - *
132 + *
155 133 * @param mixed $className
156 134 */
157 - public function _autoload($className) {
158 -
135 + public function __autoload($className) {
159 136 // Load only classed defined on the list!
160 137 if (isset($this->extensions[$className])) {
161 138 $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className);
162 139 // Import class file!
@@ -162,61 +139,35 @@
162 139 // Import class file!
163 140 require_once $classFile;
164 141 }
165 142 }
166 -
143 +
167 144 /**
168 145 * put your comment there...
169 - *
146 + *
170 147 * @param mixed $prefix
171 148 * @param mixed $loadMethod
172 149 * @return CJTExtensions
173 150 */
174 - public function __construct($prefix = self::PREFIXS, $loadMethod = self::LOAD_METHOD) {
151 + public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) {
175 152 // Hookable!
176 153 parent::__construct();
177 -
178 - // Initialize incomapiblt addons meta data
179 - $this->incompatibleAddons = array(
180 -
181 - 'css-javascript-toolbox-plus' => array(
182 - '9.4',
183 - '<',
184 - 'Aborted',
185 -
186 - function() {
187 -
188 - ob_start();
189 -
190 - require CJTOOLBOX_PATH . DIRECTORY_SEPARATOR . 'includes' .
191 - DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR .
192 - 'incompatible_cjtplus_version.html.php';
193 -
194 - $content = ob_get_clean();
195 -
196 - return $content;
197 - }
198 -
199 - ),
200 -
201 - );
202 -
203 154 // Initializing!
204 - $this->prefix = explode( ',', $prefix );
155 + $this->prefix = $prefix;
205 156 $this->loadMethod = $loadMethod;
206 157 }
207 -
158 +
208 159 /**
209 160 * put your comment there...
210 - *
161 + *
211 162 */
212 163 public function __destruct() {
213 - spl_autoload_unregister(array($this, '_autoload'));
164 + spl_autoload_unregister(array($this, '__autoload'));
214 165 }
215 -
166 +
216 167 /**
217 168 * put your comment there...
218 - *
169 + *
219 170 * @param mixed $reload
220 171 * @return CJTExtensions
221 172 */
222 173 public function & getExtensions($reload = false) {
@@ -225,34 +176,23 @@
225 176 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
226 177 //Resting!
227 178 $this->file2Classmap = array();
228 179 $extensions = array();
229 - # Get all active plugins
230 - $activePlugins = wp_get_active_and_valid_plugins();
231 - # Get Network plugins
232 - if (is_multisite()) {
233 - $activePlugins = array_merge(wp_get_active_network_plugins(), $activePlugins);
234 - }
235 180 // filter all installed Plugins to fetch all out Extensions!
236 - $activePlugins = $this->ongetactiveplugins($activePlugins);
181 + $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
237 182 foreach ($activePlugins as $file) {
238 183 $pluginDir = dirname($file);
239 184 $pluginName = basename($pluginDir);
240 185 // Any plugin with our prefix is a CJT extension!
241 - if ( ( strpos( $pluginName, $this->prefix[0] ) === 0 ) ||
242 - ( strpos( $pluginName, $this->prefix[1] ) === 0 ) ) {
186 + if (strpos($pluginName, $this->prefix) === 0) {
243 187 // CJT Extsnsion must has the definition XML file!
244 - // First try for Edition-Specific file
245 - // if not exists try the generic one.
246 188 $xmlFile = "{$pluginDir}/{$pluginName}.xml";
247 189 if (file_exists($xmlFile)) {
248 190 // Get Plugin primary data!
249 191 $extension = array();
250 - $extension['pluginFile'] = $file;
251 192 $extension['file'] = basename($file);
252 - $extension['defFile'] = basename($pluginDir) . DIRECTORY_SEPARATOR . basename($xmlFile);
253 193 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
254 - $extension['dir'] = basename($pluginDir);
194 + $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ;
255 195 $extension['name'] = $pluginName;
256 196 // Cache XML file.
257 197 $extension['definition']['raw'] = file_get_contents($xmlFile);
258 198 // Filer!
@@ -259,9 +199,8 @@
259 199 $extension = $this->ondetectextension($extension);
260 200 // Read Basic XML Definition!
261 201 $definitionXML = $this->onloaddefinition(new SimpleXMLElement($extension['definition']['raw']));
262 202 $attrs = $definitionXML->attributes();
263 - $extension['defDoc'] = $definitionXML;
264 203 $extension['definition']['primary']['loadMethod'] = (string) $attrs->loadMethod;
265 204 $extension['definition']['primary']['requiredLicense'] = (string) $definitionXML->license;
266 205 $className = ((string) $attrs->class);
267 206 // Add to list!
@@ -267,198 +206,63 @@
267 206 // Add to list!
268 207 $extensions[$className] = $extension;
269 208 // Map Plugin FILE-2-CLASS name!
270 209 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
210 + $definitionXML = null;
271 211 }
272 212 }
273 213 }
214 + // Update the cache Cache!
215 + // ----update_option(self::CACHE_OPTION_NAME, $extensions);
274 216 }
275 217 $this->extensions = $this->onload($extensions);
276 218 // Chaining
277 219 return $this->extensions;
278 220 }
279 -
221 +
280 222 /**
281 223 * put your comment there...
282 - *
224 + *
283 225 */
284 226 public function load() {
285 -
286 - // Initialize.
287 - $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version);
288 -
289 227 // Auto load CJT extensions files when requested.
290 - spl_autoload_register($this->ontregisterautoload(array($this, '_autoload')));
291 -
228 + spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
292 229 // Load all CJT extensions!
293 230 foreach ($this->getExtensions() as $class => $extension) {
294 - // Filters!
295 231 extract($this->onload($extension, compact('class', 'extension')));
296 - // Build Extension plugin path
232 + // Initialize common vars!
233 + $callback = $this->onloadcallback(array($class, $this->loadMethod));
297 234 $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
298 235 // Set runtime variables.
299 236 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
300 - // Load definition.
301 - $definitionXML = $extension['defDoc'];
302 - // Extensions below version 1.0 use static classes
303 - // while version 1.0 and up use objects
304 - if (((string) $definitionXML->attributes()->version) == '1.0') {
305 - // Instantiate extension object
306 - $extensionObject = new $class($extension);
307 - // Hold extension object
308 - $extension['exObject'] = $extensionObject;
309 - // Obejct callback
310 - $callback = array($extensionObject, $this->loadMethod);
311 - }
312 - else {
313 - # Static callback
314 - $callback = array($class, $this->loadMethod);
315 - }
316 - // Callback filter
317 - $callback = $this->onloadcallback($callback);
318 237 // If auto load is speicifd then import class file and bind events.
319 238 if ($extension['definition']['primary']['loadMethod'] == 'auto') {
320 -
321 - // Don't load Incompatible extensions/addons
322 - if (isset($this->incompatibleAddons[$extension['name']])) {
323 -
324 - require_once ABSPATH . DIRECTORY_SEPARATOR . 'wp-admin' .
325 - DIRECTORY_SEPARATOR . 'includes' .
326 - DIRECTORY_SEPARATOR . 'plugin.php';
327 -
328 - $incomapatibleAddon = $this->incompatibleAddons[$extension['name']];
329 - $addonVersion = get_plugin_data($extension['pluginFile'], false, false)['Version'];
330 - $currentVersion = get_plugin_data( CJTOOLBOX_PLUGIN_FILE )['Version'];
331 -
332 - // Only show notice if addon version is less than 11.
333 - if ( $addonVersion < 11) {
334 -
335 - $extension['incompatibleMessage']['flag'] = $incomapatibleAddon[2];
336 - $extension['incompatibleMessage']['msg'] = $incomapatibleAddon[3];
337 -
338 - $this->incompatibilies[$pluginPath] = $extension;
339 -
340 - continue;
341 - }
342 -
343 - }
344 -
345 - // If frameworkVersion is not provided assume its 0 (Older version)
346 - // before frameworkversion chech even supported.
347 - // otherwise compare it with current frameworkversion
348 - // If the version MAJOR is different current
349 - // then its incompatible.
350 - $extensionVer = new CJT_Framework_Version_Version((int) ((string) $definitionXML->attributes()->requireFrameworkVersion));
351 - if ($frameworkVersion->getMajor() < $extensionVer->getMajor()) {
352 - // Detects which requird updates CJT or the Extension itself.
353 - $extension['incompatibleMessage']['msg'] = cssJSToolbox::getText('Extension is required CJT Framework Version higher than currently installed, CJT need to get updated!!!');
354 - $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Aborted');
355 - // Add to incomaptibility list.
356 - $this->incompatibilies[$pluginPath] = $extension;
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);
357 246 }
358 - else {
359 - # Detect extensions required old Framework
360 - if ($frameworkVersion->getMajor() > $extensionVer->getMajor()) {
361 - $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!!!');
362 - $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Ignored');
363 - // Add to incomaptibility list.
364 - $this->incompatibilies[$pluginPath] = $extension;
365 - }
366 - // Bind events for compatible extensions.
367 - foreach ($definitionXML->getInvolved->event as $event) {
368 - // filter!
369 - extract($this->onbindevent(compact('event', 'callback')));
370 - // Bind!
371 - CJTPlugin::on((string) $event->attributes()->type, $callback);
372 - }
373 - }
374 247 }
375 - else { // If manual load specified just
248 + else { // If manual load specified just
376 249 if (class_exists($class)) { // Make sure the class is loaded!
377 250 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
378 251 }
379 252 }
380 253 }
381 - if (!empty($this->incompatibilies)) {
382 - // Hook for processing incomaptible extensions.
383 - add_action('admin_notices', array(& $this, 'processIncompatibles'));
384 - }
385 254 }
386 -
255 +
387 256 /**
388 257 * put your comment there...
389 - *
390 - * @param mixed $pluginName
258 + *
391 259 */
392 - public function & getDefDoc($pluginName) {
393 - # Find if cached or create it
394 - if (!isset($this->defDocs[$pluginName])) {
395 - // Add CJT Def doc to def docs list
396 - $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $pluginName . DIRECTORY_SEPARATOR . "{$pluginName}.xml";
397 - // Extension might removed while its license key still in the database
398 - // Make sure the extension still exists
399 - if (file_exists($pluginXMLFile)) {
400 - $this->defDocs[$pluginName] = new SimpleXMLElement(file_get_contents($pluginXMLFile));
401 - }
402 - else {
403 - # Return null when extension is absent!
404 - $this->defDocs[$pluginName] = null;
405 - }
406 - }
407 - return $this->defDocs[$pluginName];
408 - }
409 -
410 - /**
411 - * put your comment there...
412 - *
413 - */
414 260 public function & getFiles2ClassesMap() {
415 - return $this->file2Classmap;
261 + return $this->file2Classmap;
416 262 }
417 -
418 - /**
419 - * put your comment there...
420 - *
421 - * @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!!!
422 - */
423 - public function processIncompatibles() {
424 - global $current_screen;
425 -
426 - // Proces only if in CJT page.
427 - if (!preg_match('/\/plugins\.php|page\=cjtoolbox/', $_SERVER['REQUEST_URI'])) {
428 - return;
429 - }
430 - // INitialize.
431 - $message = cssJSToolbox::getText('CJT detects incompatible installed extensions, listed below with status message for every extension:');
432 - $list = '';
433 - // For every compatible extension add
434 - // an list item with details
435 - // if there is an update available or provide
436 - // a direct link to CJT website if no upgrade is available.
437 - // Upgrade wont be available in case no license key is activated!
438 - foreach ($this->incompatibilies as $class => $extension) {
439 - // Show details.
440 - $pluginInfo = get_plugin_data($extension['pluginFile']);
441 - // List item Markup
442 - $list .= is_callable($extension['incompatibleMessage']['msg']) ?
443 - "<li style='list-style-type:none'>{$extension['incompatibleMessage']['msg']()}</li>" :
444 - "<li><a target='_blank' href='{$pluginInfo['PluginURI']}'>{$pluginInfo['Name']}</a> (Status: {$extension['incompatibleMessage']['flag']}, Message: {$extension['incompatibleMessage']['msg']})</li>\n";
445 - }
446 -
447 - $noticeClasses = 'cjt-incomaptible-extensions-notice notice notice-error';
448 -
449 - if ( $current_screen->id !== 'toplevel_page_cjtoolbox' ) {
450 - $noticeClasses .= ' is-dismissible';
451 - }
452 -
453 - // Output full message.
454 - // TODO: BAD PRACTICE1!!!!! NEVER MIX HTML WITH PHP, JUST TEMPORARY1!!!
455 - echo "<div class='$noticeClasses' style='font-size:14px;font-weight:bold;margin-top: 20px;'>
456 - <ul style='list-style-type: circle;font-size: 12px;'>{$list}</ul>
457 - </div>";
458 - }
459 -
263 +
460 264 } // End class.
461 265
462 266
463 267 // Hookable!
464 268 CJTExtensions::define('CJTExtensions', array('hookType' => CJTWordpressEvents::HOOK_FILTER));