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