| @@ -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,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 | - | |
| 49 | + | |
| 57 | 50 | /** |
| 58 | 51 | * put your comment there... |
| 59 | - * | |
| 52 | + * | |
| 60 | 53 | * @var mixed |
| 61 | 54 | */ |
| 62 | 55 | protected $loadMethod; |
| 63 | - | |
| 56 | + | |
| 64 | 57 | /** |
| 65 | 58 | * put your comment there... |
| 66 | - * | |
| 59 | + * | |
| 67 | 60 | * @var mixed |
| 68 | 61 | */ |
| 69 | 62 | protected $onautoload = array('parameters' => array('file', 'class')); |
| 70 | - | |
| 63 | + | |
| 71 | 64 | /** |
| 72 | 65 | * put your comment there... |
| 73 | - * | |
| 66 | + * | |
| 74 | 67 | * @var mixed |
| 75 | 68 | */ |
| 76 | 69 | protected $onbindevent = array('parameters' => array('event', 'callback')); |
| 77 | - | |
| 70 | + | |
| 78 | 71 | /** |
| 79 | 72 | * put your comment there... |
| 80 | - * | |
| 73 | + * | |
| 81 | 74 | * @var mixed |
| 82 | 75 | */ |
| 83 | 76 | protected $ondetectextension = array('parameters' => array('extension')); |
| 84 | - | |
| 77 | + | |
| 85 | 78 | /** |
| 86 | 79 | * put your comment there... |
| 87 | - * | |
| 80 | + * | |
| 88 | 81 | * @var mixed |
| 89 | 82 | */ |
| 90 | 83 | protected $ongetactiveplugins = array('parameters' => array('plugins')); |
| 91 | - | |
| 84 | + | |
| 92 | 85 | /** |
| 93 | 86 | * put your comment there... |
| 94 | - * | |
| 87 | + * | |
| 95 | 88 | * @var mixed |
| 96 | 89 | */ |
| 97 | 90 | protected $onload = array('parameters' => array('params')); |
| 98 | - | |
| 91 | + | |
| 99 | 92 | /** |
| 100 | 93 | * put your comment there... |
| 101 | - * | |
| 94 | + * | |
| 102 | 95 | * @var mixed |
| 103 | 96 | */ |
| 104 | 97 | protected $onloadcallback = array('parameters' => array('callback')); |
| 105 | - | |
| 98 | + | |
| 106 | 99 | /** |
| 107 | 100 | * put your comment there... |
| 108 | - * | |
| 101 | + * | |
| 109 | 102 | * @var mixed |
| 110 | 103 | */ |
| 111 | 104 | protected $onloaddefinition = array('parameters' => array('definition')); |
| 112 | - | |
| 105 | + | |
| 113 | 106 | /*** |
| 114 | 107 | * put your comment there... |
| 115 | - * | |
| 108 | + * | |
| 116 | 109 | * @var mixed |
| 117 | 110 | */ |
| 118 | 111 | protected $ontregisterautoload = array('parameters' => array('callback')); |
| 119 | - | |
| 112 | + | |
| 120 | 113 | /** |
| 121 | 114 | * put your comment there... |
| 122 | - * | |
| 115 | + * | |
| 123 | 116 | * @var mixed |
| 124 | 117 | */ |
| 125 | 118 | protected $onreloadcacheparameters = array('parameters' => array('params')); |
| 126 | - | |
| 119 | + | |
| 127 | 120 | /** |
| 128 | 121 | * put your comment there... |
| 129 | - * | |
| 122 | + * | |
| 130 | 123 | * @var mixed |
| 131 | 124 | */ |
| 132 | 125 | protected $onloaded = array( |
| 133 | 126 | 'hookType' => CJTWordpressEvents::HOOK_ACTION, |
| @@ -132,22 +125,22 @@ | ||
| 132 | 125 | protected $onloaded = array( |
| 133 | 126 | 'hookType' => CJTWordpressEvents::HOOK_ACTION, |
| 134 | 127 | 'parameters' => array('class', 'extension', 'definition', 'result') |
| 135 | 128 | ); |
| 136 | - | |
| 129 | + | |
| 137 | 130 | /** |
| 138 | 131 | * put your comment there... |
| 139 | - * | |
| 132 | + * | |
| 140 | 133 | * @var mixed |
| 141 | 134 | */ |
| 142 | 135 | protected $prefix; |
| 143 | - | |
| 136 | + | |
| 144 | 137 | /** |
| 145 | 138 | * put your comment there... |
| 146 | - * | |
| 139 | + * | |
| 147 | 140 | * @param mixed $className |
| 148 | 141 | */ |
| 149 | - public function _autoload($className) { | |
| 142 | + public function __autoload($className) { | |
| 150 | 143 | // Load only classed defined on the list! |
| 151 | 144 | if (isset($this->extensions[$className])) { |
| 152 | 145 | $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className); |
| 153 | 146 | // Import class file! |
| @@ -153,35 +146,35 @@ | ||
| 153 | 146 | // Import class file! |
| 154 | 147 | require_once $classFile; |
| 155 | 148 | } |
| 156 | 149 | } |
| 157 | - | |
| 150 | + | |
| 158 | 151 | /** |
| 159 | 152 | * put your comment there... |
| 160 | - * | |
| 153 | + * | |
| 161 | 154 | * @param mixed $prefix |
| 162 | 155 | * @param mixed $loadMethod |
| 163 | 156 | * @return CJTExtensions |
| 164 | 157 | */ |
| 165 | - public function __construct($prefix = self::PREFIXS, $loadMethod = self::LOAD_METHOD) { | |
| 158 | + public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) { | |
| 166 | 159 | // Hookable! |
| 167 | 160 | parent::__construct(); |
| 168 | 161 | // Initializing! |
| 169 | - $this->prefix = explode( ',', $prefix ); | |
| 162 | + $this->prefix = $prefix; | |
| 170 | 163 | $this->loadMethod = $loadMethod; |
| 171 | 164 | } |
| 172 | - | |
| 165 | + | |
| 173 | 166 | /** |
| 174 | 167 | * put your comment there... |
| 175 | - * | |
| 168 | + * | |
| 176 | 169 | */ |
| 177 | 170 | public function __destruct() { |
| 178 | - spl_autoload_unregister(array($this, '_autoload')); | |
| 171 | + spl_autoload_unregister(array($this, '__autoload')); | |
| 179 | 172 | } |
| 180 | - | |
| 173 | + | |
| 181 | 174 | /** |
| 182 | 175 | * put your comment there... |
| 183 | - * | |
| 176 | + * | |
| 184 | 177 | * @param mixed $reload |
| 185 | 178 | * @return CJTExtensions |
| 186 | 179 | */ |
| 187 | 180 | public function & getExtensions($reload = false) { |
| @@ -190,27 +183,21 @@ | ||
| 190 | 183 | if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) { |
| 191 | 184 | //Resting! |
| 192 | 185 | $this->file2Classmap = array(); |
| 193 | 186 | $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 | - } | |
| 187 | + $edition = CJTPlugin::Edition; | |
| 200 | 188 | // filter all installed Plugins to fetch all out Extensions! |
| 201 | - $activePlugins = $this->ongetactiveplugins($activePlugins); | |
| 189 | + $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins()); | |
| 202 | 190 | foreach ($activePlugins as $file) { |
| 203 | 191 | $pluginDir = dirname($file); |
| 204 | 192 | $pluginName = basename($pluginDir); |
| 205 | 193 | // Any plugin with our prefix is a CJT extension! |
| 206 | - if ( ( strpos( $pluginName, $this->prefix[0] ) === 0 ) || | |
| 207 | - ( strpos( $pluginName, $this->prefix[1] ) === 0 ) ) { | |
| 194 | + if (strpos($pluginName, $this->prefix) === 0) { | |
| 208 | 195 | // CJT Extsnsion must has the definition XML file! |
| 209 | 196 | // First try for Edition-Specific file |
| 210 | 197 | // if not exists try the generic one. |
| 211 | - $xmlFile = "{$pluginDir}/{$pluginName}.xml"; | |
| 212 | - if (file_exists($xmlFile)) { | |
| 198 | + $xmlFile = "{$pluginDir}/{$pluginName}-{$edition}.xml"; | |
| 199 | + if (file_exists($xmlFile) || file_exists($xmlFile = "{$pluginDir}/{$pluginName}.xml")) { | |
| 213 | 200 | // Get Plugin primary data! |
| 214 | 201 | $extension = array(); |
| 215 | 202 | $extension['pluginFile'] = $file; |
| 216 | 203 | $extension['file'] = basename($file); |
| @@ -215,9 +202,9 @@ | ||
| 215 | 202 | $extension['pluginFile'] = $file; |
| 216 | 203 | $extension['file'] = basename($file); |
| 217 | 204 | $extension['defFile'] = basename($pluginDir) . DIRECTORY_SEPARATOR . basename($xmlFile); |
| 218 | 205 | // Its useful to use ABS path only at runtime as it might changed as host might get moved. |
| 219 | - $extension['dir'] = basename($pluginDir); | |
| 206 | + $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ; | |
| 220 | 207 | $extension['name'] = $pluginName; |
| 221 | 208 | // Cache XML file. |
| 222 | 209 | $extension['definition']['raw'] = file_get_contents($xmlFile); |
| 223 | 210 | // Filer! |
| @@ -235,23 +222,25 @@ | ||
| 235 | 222 | $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className; |
| 236 | 223 | } |
| 237 | 224 | } |
| 238 | 225 | } |
| 226 | + // Update the cache Cache! | |
| 227 | + // ----update_option(self::CACHE_OPTION_NAME, $extensions); | |
| 239 | 228 | } |
| 240 | 229 | $this->extensions = $this->onload($extensions); |
| 241 | 230 | // Chaining |
| 242 | 231 | return $this->extensions; |
| 243 | 232 | } |
| 244 | - | |
| 233 | + | |
| 245 | 234 | /** |
| 246 | 235 | * put your comment there... |
| 247 | - * | |
| 236 | + * | |
| 248 | 237 | */ |
| 249 | 238 | public function load() { |
| 250 | 239 | // Initialize. |
| 251 | 240 | $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version); |
| 252 | 241 | // Auto load CJT extensions files when requested. |
| 253 | - spl_autoload_register($this->ontregisterautoload(array($this, '_autoload'))); | |
| 242 | + spl_autoload_register($this->ontregisterautoload(array($this, '__autoload'))); | |
| 254 | 243 | // Load all CJT extensions! |
| 255 | 244 | foreach ($this->getExtensions() as $class => $extension) { |
| 256 | 245 | // Filters! |
| 257 | 246 | extract($this->onload($extension, compact('class', 'extension'))); |
| @@ -308,9 +297,9 @@ | ||
| 308 | 297 | CJTPlugin::on((string) $event->attributes()->type, $callback); |
| 309 | 298 | } |
| 310 | 299 | } |
| 311 | 300 | } |
| 312 | - else { // If manual load specified just | |
| 301 | + else { // If manual load specified just | |
| 313 | 302 | if (class_exists($class)) { // Make sure the class is loaded! |
| 314 | 303 | $this->onloaded($class, $extension, $definitionXML, call_user_func($callback)); |
| 315 | 304 | } |
| 316 | 305 | } |
| @@ -319,43 +308,20 @@ | ||
| 319 | 308 | // Hook for processing incomaptible extensions. |
| 320 | 309 | add_action('admin_notices', array(& $this, 'processIncompatibles')); |
| 321 | 310 | } |
| 322 | 311 | } |
| 323 | - | |
| 312 | + | |
| 324 | 313 | /** |
| 325 | 314 | * put your comment there... |
| 326 | - * | |
| 327 | - * @param mixed $pluginName | |
| 315 | + * | |
| 328 | 316 | */ |
| 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 | 317 | public function & getFiles2ClassesMap() { |
| 352 | - return $this->file2Classmap; | |
| 318 | + return $this->file2Classmap; | |
| 353 | 319 | } |
| 354 | - | |
| 320 | + | |
| 355 | 321 | /** |
| 356 | 322 | * put your comment there... |
| 357 | - * | |
| 323 | + * | |
| 358 | 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!!! |
| 359 | 325 | */ |
| 360 | 326 | public function processIncompatibles() { |
| 361 | 327 | // Proces only if in CJT page. |
| @@ -365,9 +331,9 @@ | ||
| 365 | 331 | // INitialize. |
| 366 | 332 | $message = cssJSToolbox::getText('CJT detects incompatible installed extensions, listed below with status message for every extension:'); |
| 367 | 333 | $list = ''; |
| 368 | 334 | // For every compatible extension add |
| 369 | - // an list item with details | |
| 335 | + // an list item with details | |
| 370 | 336 | // if there is an update available or provide |
| 371 | 337 | // a direct link to CJT website if no upgrade is available. |
| 372 | 338 | // Upgrade wont be available in case no license key is activated! |
| 373 | 339 | foreach ($this->incompatibilies as $class => $extension) { |