PluginProbe
CSS & JavaScript Toolbox / 7.2
CSS & JavaScript Toolbox v7.2
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 +75 -182 127.2 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,121 @@
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 48 protected $incompatibilies;
56 -
57 - /**
58 - * put your comment there...
59 - *
60 - * @var mixed
61 - */
62 - protected $incompatibleAddons = array();
63 -
64 -
49 +
65 50 /**
66 51 * put your comment there...
67 - *
52 + *
68 53 * @var mixed
69 54 */
70 55 protected $loadMethod;
71 -
56 +
72 57 /**
73 58 * put your comment there...
74 - *
59 + *
75 60 * @var mixed
76 61 */
77 62 protected $onautoload = array('parameters' => array('file', 'class'));
78 -
63 +
79 64 /**
80 65 * put your comment there...
81 - *
66 + *
82 67 * @var mixed
83 68 */
84 69 protected $onbindevent = array('parameters' => array('event', 'callback'));
85 -
70 +
86 71 /**
87 72 * put your comment there...
88 - *
73 + *
89 74 * @var mixed
90 75 */
91 76 protected $ondetectextension = array('parameters' => array('extension'));
92 -
77 +
93 78 /**
94 79 * put your comment there...
95 - *
80 + *
96 81 * @var mixed
97 82 */
98 83 protected $ongetactiveplugins = array('parameters' => array('plugins'));
99 -
84 +
100 85 /**
101 86 * put your comment there...
102 - *
87 + *
103 88 * @var mixed
104 89 */
105 90 protected $onload = array('parameters' => array('params'));
106 -
91 +
107 92 /**
108 93 * put your comment there...
109 - *
94 + *
110 95 * @var mixed
111 96 */
112 97 protected $onloadcallback = array('parameters' => array('callback'));
113 -
98 +
114 99 /**
115 100 * put your comment there...
116 - *
101 + *
117 102 * @var mixed
118 103 */
119 104 protected $onloaddefinition = array('parameters' => array('definition'));
120 -
105 +
121 106 /***
122 107 * put your comment there...
123 - *
108 + *
124 109 * @var mixed
125 110 */
126 111 protected $ontregisterautoload = array('parameters' => array('callback'));
127 -
112 +
128 113 /**
129 114 * put your comment there...
130 - *
115 + *
131 116 * @var mixed
132 117 */
133 118 protected $onreloadcacheparameters = array('parameters' => array('params'));
134 -
119 +
135 120 /**
136 121 * put your comment there...
137 - *
122 + *
138 123 * @var mixed
139 124 */
140 125 protected $onloaded = array(
141 126 'hookType' => CJTWordpressEvents::HOOK_ACTION,
@@ -140,23 +125,22 @@
140 125 protected $onloaded = array(
141 126 'hookType' => CJTWordpressEvents::HOOK_ACTION,
142 127 'parameters' => array('class', 'extension', 'definition', 'result')
143 128 );
144 -
129 +
145 130 /**
146 131 * put your comment there...
147 - *
132 + *
148 133 * @var mixed
149 134 */
150 135 protected $prefix;
151 -
136 +
152 137 /**
153 138 * put your comment there...
154 - *
139 + *
155 140 * @param mixed $className
156 141 */
157 - public function _autoload($className) {
158 -
142 + public function __autoload($className) {
159 143 // Load only classed defined on the list!
160 144 if (isset($this->extensions[$className])) {
161 145 $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className);
162 146 // Import class file!
@@ -162,61 +146,35 @@
162 146 // Import class file!
163 147 require_once $classFile;
164 148 }
165 149 }
166 -
150 +
167 151 /**
168 152 * put your comment there...
169 - *
153 + *
170 154 * @param mixed $prefix
171 155 * @param mixed $loadMethod
172 156 * @return CJTExtensions
173 157 */
174 - public function __construct($prefix = self::PREFIXS, $loadMethod = self::LOAD_METHOD) {
158 + public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) {
175 159 // Hookable!
176 160 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 161 // Initializing!
204 - $this->prefix = explode( ',', $prefix );
162 + $this->prefix = $prefix;
205 163 $this->loadMethod = $loadMethod;
206 164 }
207 -
165 +
208 166 /**
209 167 * put your comment there...
210 - *
168 + *
211 169 */
212 170 public function __destruct() {
213 - spl_autoload_unregister(array($this, '_autoload'));
171 + spl_autoload_unregister(array($this, '__autoload'));
214 172 }
215 -
173 +
216 174 /**
217 175 * put your comment there...
218 - *
176 + *
219 177 * @param mixed $reload
220 178 * @return CJTExtensions
221 179 */
222 180 public function & getExtensions($reload = false) {
@@ -225,27 +183,21 @@
225 183 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
226 184 //Resting!
227 185 $this->file2Classmap = array();
228 186 $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 - }
187 + $edition = CJTPlugin::Edition;
235 188 // filter all installed Plugins to fetch all out Extensions!
236 - $activePlugins = $this->ongetactiveplugins($activePlugins);
189 + $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
237 190 foreach ($activePlugins as $file) {
238 191 $pluginDir = dirname($file);
239 192 $pluginName = basename($pluginDir);
240 193 // Any plugin with our prefix is a CJT extension!
241 - if ( ( strpos( $pluginName, $this->prefix[0] ) === 0 ) ||
242 - ( strpos( $pluginName, $this->prefix[1] ) === 0 ) ) {
194 + if (strpos($pluginName, $this->prefix) === 0) {
243 195 // CJT Extsnsion must has the definition XML file!
244 196 // First try for Edition-Specific file
245 197 // if not exists try the generic one.
246 - $xmlFile = "{$pluginDir}/{$pluginName}.xml";
247 - if (file_exists($xmlFile)) {
198 + $xmlFile = "{$pluginDir}/{$pluginName}-{$edition}.xml";
199 + if (file_exists($xmlFile) || file_exists($xmlFile = "{$pluginDir}/{$pluginName}.xml")) {
248 200 // Get Plugin primary data!
249 201 $extension = array();
250 202 $extension['pluginFile'] = $file;
251 203 $extension['file'] = basename($file);
@@ -250,9 +202,9 @@
250 202 $extension['pluginFile'] = $file;
251 203 $extension['file'] = basename($file);
252 204 $extension['defFile'] = basename($pluginDir) . DIRECTORY_SEPARATOR . basename($xmlFile);
253 205 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
254 - $extension['dir'] = basename($pluginDir);
206 + $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ;
255 207 $extension['name'] = $pluginName;
256 208 // Cache XML file.
257 209 $extension['definition']['raw'] = file_get_contents($xmlFile);
258 210 // Filer!
@@ -270,32 +222,31 @@
270 222 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
271 223 }
272 224 }
273 225 }
226 + // Update the cache Cache!
227 + // ----update_option(self::CACHE_OPTION_NAME, $extensions);
274 228 }
275 229 $this->extensions = $this->onload($extensions);
276 230 // Chaining
277 231 return $this->extensions;
278 232 }
279 -
233 +
280 234 /**
281 235 * put your comment there...
282 - *
236 + *
283 237 */
284 238 public function load() {
285 -
286 239 // Initialize.
287 240 $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version);
288 -
289 241 // Auto load CJT extensions files when requested.
290 - spl_autoload_register($this->ontregisterautoload(array($this, '_autoload')));
291 -
242 + spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
292 243 // Load all CJT extensions!
293 244 foreach ($this->getExtensions() as $class => $extension) {
294 245 // Filters!
295 246 extract($this->onload($extension, compact('class', 'extension')));
296 247 // Build Extension plugin path
297 - $pluginPath = WP_PLUGIN_DIR . "/{$extension['name']}";
248 + $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
298 249 // Set runtime variables.
299 250 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
300 251 // Load definition.
301 252 $definitionXML = $extension['defDoc'];
@@ -316,33 +267,8 @@
316 267 // Callback filter
317 268 $callback = $this->onloadcallback($callback);
318 269 // If auto load is speicifd then import class file and bind events.
319 270 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 271 // If frameworkVersion is not provided assume its 0 (Older version)
346 272 // before frameworkversion chech even supported.
347 273 // otherwise compare it with current frameworkversion
348 274 // If the version MAJOR is different current
@@ -371,9 +297,9 @@
371 297 CJTPlugin::on((string) $event->attributes()->type, $callback);
372 298 }
373 299 }
374 300 }
375 - else { // If manual load specified just
301 + else { // If manual load specified just
376 302 if (class_exists($class)) { // Make sure the class is loaded!
377 303 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
378 304 }
379 305 }
@@ -382,48 +308,23 @@
382 308 // Hook for processing incomaptible extensions.
383 309 add_action('admin_notices', array(& $this, 'processIncompatibles'));
384 310 }
385 311 }
386 -
312 +
387 313 /**
388 314 * put your comment there...
389 - *
390 - * @param mixed $pluginName
315 + *
391 316 */
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 317 public function & getFiles2ClassesMap() {
415 - return $this->file2Classmap;
318 + return $this->file2Classmap;
416 319 }
417 -
320 +
418 321 /**
419 322 * put your comment there...
420 - *
323 + *
421 324 * @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 325 */
423 326 public function processIncompatibles() {
424 - global $current_screen;
425 -
426 327 // Proces only if in CJT page.
427 328 if (!preg_match('/\/plugins\.php|page\=cjtoolbox/', $_SERVER['REQUEST_URI'])) {
428 329 return;
429 330 }
@@ -430,9 +331,9 @@
430 331 // INitialize.
431 332 $message = cssJSToolbox::getText('CJT detects incompatible installed extensions, listed below with status message for every extension:');
432 333 $list = '';
433 334 // For every compatible extension add
434 - // an list item with details
335 + // an list item with details
435 336 // if there is an update available or provide
436 337 // a direct link to CJT website if no upgrade is available.
437 338 // Upgrade wont be available in case no license key is activated!
438 339 foreach ($this->incompatibilies as $class => $extension) {
@@ -438,24 +339,16 @@
438 339 foreach ($this->incompatibilies as $class => $extension) {
439 340 // Show details.
440 341 $pluginInfo = get_plugin_data($extension['pluginFile']);
441 342 // 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";
343 + $list .= "<li><a target='_blank' href='{$pluginInfo['PluginURI']}'>{$pluginInfo['Name']}</a> (Status: {$extension['incompatibleMessage']['flag']}, Message: {$extension['incompatibleMessage']['msg']})</li>\n";
445 344 }
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 345 // Output full message.
454 346 // 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>";
347 + echo "<div class='cjt-incomaptible-extensions-notice updated' style='font-size:14px;font-weight:bold;padding-top:11px'>
348 + <span>{$message}</span>
349 + <ul style='list-style-type: circle;padding-left: 27px;font-size: 12px;'>{$list}</ul>
350 + </div>";
458 351 }
459 352
460 353 } // End class.
461 354