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