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 +101 -12 6.07.2 View file →
@@ -44,8 +44,15 @@
44 44 * put your comment there...
45 45 *
46 46 * @var mixed
47 47 */
48 + protected $incompatibilies;
49 +
50 + /**
51 + * put your comment there...
52 + *
53 + * @var mixed
54 + */
48 55 protected $loadMethod;
49 56
50 57 /**
51 58 * put your comment there...
@@ -176,8 +183,9 @@
176 183 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
177 184 //Resting!
178 185 $this->file2Classmap = array();
179 186 $extensions = array();
187 + $edition = CJTPlugin::Edition;
180 188 // filter all installed Plugins to fetch all out Extensions!
181 189 $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
182 190 foreach ($activePlugins as $file) {
183 191 $pluginDir = dirname($file);
@@ -184,13 +192,17 @@
184 192 $pluginName = basename($pluginDir);
185 193 // Any plugin with our prefix is a CJT extension!
186 194 if (strpos($pluginName, $this->prefix) === 0) {
187 195 // CJT Extsnsion must has the definition XML file!
188 - $xmlFile = "{$pluginDir}/{$pluginName}.xml";
189 - if (file_exists($xmlFile)) {
196 + // First try for Edition-Specific file
197 + // if not exists try the generic one.
198 + $xmlFile = "{$pluginDir}/{$pluginName}-{$edition}.xml";
199 + if (file_exists($xmlFile) || file_exists($xmlFile = "{$pluginDir}/{$pluginName}.xml")) {
190 200 // Get Plugin primary data!
191 201 $extension = array();
202 + $extension['pluginFile'] = $file;
192 203 $extension['file'] = basename($file);
204 + $extension['defFile'] = basename($pluginDir) . DIRECTORY_SEPARATOR . basename($xmlFile);
193 205 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
194 206 $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ;
195 207 $extension['name'] = $pluginName;
196 208 // Cache XML file.
@@ -199,8 +211,9 @@
199 211 $extension = $this->ondetectextension($extension);
200 212 // Read Basic XML Definition!
201 213 $definitionXML = $this->onloaddefinition(new SimpleXMLElement($extension['definition']['raw']));
202 214 $attrs = $definitionXML->attributes();
215 + $extension['defDoc'] = $definitionXML;
203 216 $extension['definition']['primary']['loadMethod'] = (string) $attrs->loadMethod;
204 217 $extension['definition']['primary']['requiredLicense'] = (string) $definitionXML->license;
205 218 $className = ((string) $attrs->class);
206 219 // Add to list!
@@ -206,9 +219,8 @@
206 219 // Add to list!
207 220 $extensions[$className] = $extension;
208 221 // Map Plugin FILE-2-CLASS name!
209 222 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
210 - $definitionXML = null;
211 223 }
212 224 }
213 225 }
214 226 // Update the cache Cache!
@@ -223,28 +235,69 @@
223 235 * put your comment there...
224 236 *
225 237 */
226 238 public function load() {
239 + // Initialize.
240 + $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version);
227 241 // Auto load CJT extensions files when requested.
228 242 spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
229 243 // Load all CJT extensions!
230 244 foreach ($this->getExtensions() as $class => $extension) {
245 + // Filters!
231 246 extract($this->onload($extension, compact('class', 'extension')));
232 - // Initialize common vars!
233 - $callback = $this->onloadcallback(array($class, $this->loadMethod));
247 + // Build Extension plugin path
234 248 $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
235 249 // Set runtime variables.
236 250 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
251 + // Load definition.
252 + $definitionXML = $extension['defDoc'];
253 + // Extensions below version 1.0 use static classes
254 + // while version 1.0 and up use objects
255 + if (((string) $definitionXML->attributes()->version) == '1.0') {
256 + // Instantiate extension object
257 + $extensionObject = new $class($extension);
258 + // Hold extension object
259 + $extension['exObject'] = $extensionObject;
260 + // Obejct callback
261 + $callback = array($extensionObject, $this->loadMethod);
262 + }
263 + else {
264 + # Static callback
265 + $callback = array($class, $this->loadMethod);
266 + }
267 + // Callback filter
268 + $callback = $this->onloadcallback($callback);
237 269 // If auto load is speicifd then import class file and bind events.
238 270 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);
271 + // If frameworkVersion is not provided assume its 0 (Older version)
272 + // before frameworkversion chech even supported.
273 + // otherwise compare it with current frameworkversion
274 + // If the version MAJOR is different current
275 + // then its incompatible.
276 + $extensionVer = new CJT_Framework_Version_Version((int) ((string) $definitionXML->attributes()->requireFrameworkVersion));
277 + if ($frameworkVersion->getMajor() < $extensionVer->getMajor()) {
278 + // Detects which requird updates CJT or the Extension itself.
279 + $extension['incompatibleMessage']['msg'] = cssJSToolbox::getText('Extension is required CJT Framework Version higher than currently installed, CJT need to get updated!!!');
280 + $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Aborted');
281 + // Add to incomaptibility list.
282 + $this->incompatibilies[$pluginPath] = $extension;
246 283 }
284 + else {
285 + # Detect extensions required old Framework
286 + if ($frameworkVersion->getMajor() > $extensionVer->getMajor()) {
287 + $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!!!');
288 + $extension['incompatibleMessage']['flag'] = cssJSToolbox::getText('Ignored');
289 + // Add to incomaptibility list.
290 + $this->incompatibilies[$pluginPath] = $extension;
291 + }
292 + // Bind events for compatible extensions.
293 + foreach ($definitionXML->getInvolved->event as $event) {
294 + // filter!
295 + extract($this->onbindevent(compact('event', 'callback')));
296 + // Bind!
297 + CJTPlugin::on((string) $event->attributes()->type, $callback);
298 + }
299 + }
247 300 }
248 301 else { // If manual load specified just
249 302 if (class_exists($class)) { // Make sure the class is loaded!
250 303 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
@@ -250,8 +303,12 @@
250 303 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
251 304 }
252 305 }
253 306 }
307 + if (!empty($this->incompatibilies)) {
308 + // Hook for processing incomaptible extensions.
309 + add_action('admin_notices', array(& $this, 'processIncompatibles'));
310 + }
254 311 }
255 312
256 313 /**
257 314 * put your comment there...
@@ -260,9 +317,41 @@
260 317 public function & getFiles2ClassesMap() {
261 318 return $this->file2Classmap;
262 319 }
263 320
321 + /**
322 + * put your comment there...
323 + *
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!!!
325 + */
326 + public function processIncompatibles() {
327 + // Proces only if in CJT page.
328 + if (!preg_match('/\/plugins\.php|page\=cjtoolbox/', $_SERVER['REQUEST_URI'])) {
329 + return;
330 + }
331 + // INitialize.
332 + $message = cssJSToolbox::getText('CJT detects incompatible installed extensions, listed below with status message for every extension:');
333 + $list = '';
334 + // For every compatible extension add
335 + // an list item with details
336 + // if there is an update available or provide
337 + // a direct link to CJT website if no upgrade is available.
338 + // Upgrade wont be available in case no license key is activated!
339 + foreach ($this->incompatibilies as $class => $extension) {
340 + // Show details.
341 + $pluginInfo = get_plugin_data($extension['pluginFile']);
342 + // List item Markup
343 + $list .= "<li><a target='_blank' href='{$pluginInfo['PluginURI']}'>{$pluginInfo['Name']}</a> (Status: {$extension['incompatibleMessage']['flag']}, Message: {$extension['incompatibleMessage']['msg']})</li>\n";
344 + }
345 + // Output full message.
346 + // TODO: BAD PRACTICE1!!!!! NEVER MIX HTML WITH PHP, JUST TEMPORARY1!!!
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>";
351 + }
352 +
264 353 } // End class.
265 354
266 355
267 356 // Hookable!
268 357 CJTExtensions::define('CJTExtensions', array('hookType' => CJTWordpressEvents::HOOK_FILTER));