PluginProbe
CSS & JavaScript Toolbox / 7.1
CSS & JavaScript Toolbox v7.1
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
css-javascript-toolbox / framework / extensions / extensions.class.php

extensions.class.php in CSS & JavaScript Toolbox 7.1, at framework/extensions/extensions.class.php

333 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 /**
10 *
11 */
12 class CJTExtensions extends CJTHookableClass {
13
14 /**
15 *
16 */
17 const CACHE_OPTION_NAME = 'cjt_extensions';
18
19 /**
20 *
21 */
22 const LOAD_METHOD = 'getInvolved';
23
24 /**
25 *
26 */
27 const PREFIX = 'cjte-';
28
29 /**
30 * put your comment there...
31 *
32 * @var mixed
33 */
34 protected $extensions;
35
36 /**
37 * put your comment there...
38 *
39 * @var mixed
40 */
41 protected $file2Classmap;
42
43 /**
44 * put your comment there...
45 *
46 * @var mixed
47 */
48 protected $incompatibilies;
49
50 /**
51 * put your comment there...
52 *
53 * @var mixed
54 */
55 protected $loadMethod;
56
57 /**
58 * put your comment there...
59 *
60 * @var mixed
61 */
62 protected $onautoload = array('parameters' => array('file', 'class'));
63
64 /**
65 * put your comment there...
66 *
67 * @var mixed
68 */
69 protected $onbindevent = array('parameters' => array('event', 'callback'));
70
71 /**
72 * put your comment there...
73 *
74 * @var mixed
75 */
76 protected $ondetectextension = array('parameters' => array('extension'));
77
78 /**
79 * put your comment there...
80 *
81 * @var mixed
82 */
83 protected $ongetactiveplugins = array('parameters' => array('plugins'));
84
85 /**
86 * put your comment there...
87 *
88 * @var mixed
89 */
90 protected $onload = array('parameters' => array('params'));
91
92 /**
93 * put your comment there...
94 *
95 * @var mixed
96 */
97 protected $onloadcallback = array('parameters' => array('callback'));
98
99 /**
100 * put your comment there...
101 *
102 * @var mixed
103 */
104 protected $onloaddefinition = array('parameters' => array('definition'));
105
106 /***
107 * put your comment there...
108 *
109 * @var mixed
110 */
111 protected $ontregisterautoload = array('parameters' => array('callback'));
112
113 /**
114 * put your comment there...
115 *
116 * @var mixed
117 */
118 protected $onreloadcacheparameters = array('parameters' => array('params'));
119
120 /**
121 * put your comment there...
122 *
123 * @var mixed
124 */
125 protected $onloaded = array(
126 'hookType' => CJTWordpressEvents::HOOK_ACTION,
127 'parameters' => array('class', 'extension', 'definition', 'result')
128 );
129
130 /**
131 * put your comment there...
132 *
133 * @var mixed
134 */
135 protected $prefix;
136
137 /**
138 * put your comment there...
139 *
140 * @param mixed $className
141 */
142 public function __autoload($className) {
143 // Load only classed defined on the list!
144 if (isset($this->extensions[$className])) {
145 $classFile = $this->onautoload($this->extensions[$className]['runtime']['classFile'], $className);
146 // Import class file!
147 require_once $classFile;
148 }
149 }
150
151 /**
152 * put your comment there...
153 *
154 * @param mixed $prefix
155 * @param mixed $loadMethod
156 * @return CJTExtensions
157 */
158 public function __construct($prefix = self::PREFIX, $loadMethod = self::LOAD_METHOD) {
159 // Hookable!
160 parent::__construct();
161 // Initializing!
162 $this->prefix = $prefix;
163 $this->loadMethod = $loadMethod;
164 }
165
166 /**
167 * put your comment there...
168 *
169 */
170 public function __destruct() {
171 spl_autoload_unregister(array($this, '__autoload'));
172 }
173
174 /**
175 * put your comment there...
176 *
177 * @param mixed $reload
178 * @return CJTExtensions
179 */
180 public function & getExtensions($reload = false) {
181 // Get cached extensions or cache then if not yest cached!
182 extract($this->onreloadcacheparameters(compact('reload')));
183 if ($reload || (!($extensions = $this->extensions) && !($extensions = get_option(self::CACHE_OPTION_NAME, array())))) {
184 //Resting!
185 $this->file2Classmap = array();
186 $extensions = array();
187 $edition = CJTPlugin::Edition;
188 // filter all installed Plugins to fetch all out Extensions!
189 $activePlugins = $this->ongetactiveplugins(wp_get_active_and_valid_plugins());
190 foreach ($activePlugins as $file) {
191 $pluginDir = dirname($file);
192 $pluginName = basename($pluginDir);
193 // Any plugin with our prefix is a CJT extension!
194 if (strpos($pluginName, $this->prefix) === 0) {
195 // CJT Extsnsion must has the definition XML file!
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")) {
200 // Get Plugin primary data!
201 $extension = array();
202 $extension['pluginFile'] = $file;
203 $extension['file'] = basename($file);
204 // Its useful to use ABS path only at runtime as it might changed as host might get moved.
205 $extension['dir'] = str_replace((ABSPATH . PLUGINDIR . '/'), '', $pluginDir) ;
206 $extension['name'] = $pluginName;
207 // Cache XML file.
208 $extension['definition']['raw'] = file_get_contents($xmlFile);
209 // Filer!
210 $extension = $this->ondetectextension($extension);
211 // Read Basic XML Definition!
212 $definitionXML = $this->onloaddefinition(new SimpleXMLElement($extension['definition']['raw']));
213 $attrs = $definitionXML->attributes();
214 $extension['definition']['primary']['loadMethod'] = (string) $attrs->loadMethod;
215 $extension['definition']['primary']['requiredLicense'] = (string) $definitionXML->license;
216 $className = ((string) $attrs->class);
217 // Add to list!
218 $extensions[$className] = $extension;
219 // Map Plugin FILE-2-CLASS name!
220 $this->file2Classmap["{$extension['dir']}/{$extension['file']}"] = $className;
221 $definitionXML = null;
222 }
223 }
224 }
225 // Update the cache Cache!
226 // ----update_option(self::CACHE_OPTION_NAME, $extensions);
227 }
228 $this->extensions = $this->onload($extensions);
229 // Chaining
230 return $this->extensions;
231 }
232
233 /**
234 * put your comment there...
235 *
236 */
237 public function load() {
238 // Initialize.
239 $frameworkVersion = new CJT_Framework_Version_Version(CJTPlugin::FW_Version);
240 // Auto load CJT extensions files when requested.
241 spl_autoload_register($this->ontregisterautoload(array($this, '__autoload')));
242 // Load all CJT extensions!
243 foreach ($this->getExtensions() as $class => $extension) {
244 extract($this->onload($extension, compact('class', 'extension')));
245 // Initialize common vars!
246 $callback = $this->onloadcallback(array($class, $this->loadMethod));
247 $pluginPath = ABSPATH . PLUGINDIR . "/{$extension['name']}";
248 // Set runtime variables.
249 $this->extensions[$class]['runtime']['classFile'] = "{$pluginPath}/{$extension['name']}.class.php";
250 // If auto load is speicifd then import class file and bind events.
251 if ($extension['definition']['primary']['loadMethod'] == 'auto') {
252 // Load definition.
253 $definitionXML = new SimpleXMLElement($extension['definition']['raw']);
254 // If frameworkVersion is not provided assume its 0 (Older version)
255 // before frameworkversion chech even supported.
256 // otherwise compare it with current frameworkversion
257 // If the version MAJOR is different current
258 // then its incompatible.
259 $extensionVer = new CJT_Framework_Version_Version((int) ((string) $definitionXML->attributes()->requireFrameworkVersion));
260 if ($frameworkVersion->getMajor() != $extensionVer->getMajor()) {
261 // Add to incomaptibility list.
262 $this->incompatibilies[$pluginPath] = $extension;
263 }
264 else {
265 // Bind events for compatible extensions.
266 foreach ($definitionXML->getInvolved->event as $event) {
267 // filter!
268 extract($this->onbindevent(compact('event', 'callback')));
269 // Bind!
270 CJTPlugin::on((string) $event->attributes()->type, $callback);
271 }
272 }
273 }
274 else { // If manual load specified just
275 if (class_exists($class)) { // Make sure the class is loaded!
276 $this->onloaded($class, $extension, $definitionXML, call_user_func($callback));
277 }
278 }
279 }
280 if (!empty($this->incompatibilies)) {
281 // Hook for processing incomaptible extensions.
282 add_action('admin_notices', array(& $this, 'processIncompatibles'));
283 }
284 }
285
286 /**
287 * put your comment there...
288 *
289 */
290 public function & getFiles2ClassesMap() {
291 return $this->file2Classmap;
292 }
293
294 /**
295 * put your comment there...
296 *
297 * @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!!!
298 */
299 public function processIncompatibles() {
300 // Proces only if in CJT page.
301 if (!isset($_GET['page']) || ($_GET['page'] != 'cjtoolbox')) {
302 return;
303 }
304 // INitialize.
305 $message = cssJSToolbox::getText('CJT detects incompatible installed extensions and must be updated. Extensions are listed below.
306 Please upgrade those extensions from Wordpress Plugins or update page.
307 Those extensions are now stopped until the upgrade is done.
308 If you\'ve any problem upgrading them please visit CJT website by clicking extension links below.');
309 $list = '';
310 // For every compatible extension add
311 // an list item with details
312 // if there is an update available or provide
313 // a direct link to CJT website if no upgrade is available.
314 // Upgrade wont be available in case no license key is activated!
315 foreach ($this->incompatibilies as $class => $extension) {
316 // Show details.
317 $pluginInfo = get_plugin_data($extension['pluginFile']);
318 // List item Markup
319 $list .= "<li><a target='_blank' href='{$pluginInfo['PluginURI']}'>{$pluginInfo['Name']}</a></li>\n";
320 }
321 // Output full message.
322 // TODO: BAD PRACTICE1!!!!! NEVER MIX HTML WITH PHP, JUST TEMPORARY1!!!
323 echo "<div class='cjt-incomaptible-extensions-notice updated' style='font-size:14px;font-weight:bold;padding-top:11px'>
324 <span>{$message}</span>
325 <ul style='list-style-type: circle;padding-left: 27px;font-size: 12px;'>{$list}</ul>
326 </div>";
327 }
328
329 } // End class.
330
331
332 // Hookable!
333 CJTExtensions::define('CJTExtensions', array('hookType' => CJTWordpressEvents::HOOK_FILTER));