PluginProbe
CSS & JavaScript Toolbox / 12
CSS & JavaScript Toolbox v12
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 / css-js-toolbox.php

css-js-toolbox.php in CSS & JavaScript Toolbox 12, at css-js-toolbox.php

418 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: CSS & JavaScript Toolbox
4 Plugin URI: https://css-javascript-toolbox.com/
5 Description: Easily add CSS, JavaScript, HTML and PHP code to unique CJT code blocks and assign them anywhere on your website.
6 Version: 12.0
7 Author: Wipeout Media
8 Stable tag: 12.0
9 Author URI: https://css-javascript-toolbox.com
10 License:
11
12 The Software is package as a WordPress¨ plugin. The PHP code associated with the Software is licensed under the GPL version 2.0 license (as found at http://www.gnu.org/licenses/gpl-2.0.txt GNU/GPLv2 or "GPLv2"). You may redistribute, repackage, and modify the PHP code as you see fit and as consistent with GPLv2.
13
14 The remaining portions of the Software ("Proprietary Portion"), which includes all images, cascading style sheets, and JavaScript are NOT licensed under GPLv2 and are considered proprietary to Licensor and are solely licensed under the remaining terms of this Agreement. The Proprietary Portion may not be redistributed, repackaged, or otherwise modified.
15 */
16
17 // Disallow direct access.
18 defined( 'ABSPATH' ) or die( 'Access denied' );
19
20
21 /** * */
22 define( 'CJTOOLBOX_PLUGIN_BASE', basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
23
24 /** * */
25 define( 'CJTOOLBOX_PLUGIN_FILE', __FILE__ );
26
27 /** CJT Name */
28 define( 'CJTOOLBOX_NAME', plugin_basename( dirname( __FILE__ ) ) );
29
30 /** CJT Text Domain used for localize texts */
31 define( 'CJTOOLBOX_TEXT_DOMAIN', CJTOOLBOX_NAME );
32
33 /** */
34 define( 'CJTOOLBOX_LANGUAGES', CJTOOLBOX_NAME . '/locals/languages/' );
35
36 /** CJT Absoulte path */
37 define( 'CJTOOLBOX_PATH', dirname( __FILE__ ) );
38
39 /** Dont use!! @deprecated */
40 define( 'CJTOOLBOX_INCLUDE_PATH', CJTOOLBOX_PATH . '/framework' );
41
42 /** Access Points path */
43 define( 'CJTOOLBOX_ACCESS_POINTS', CJTOOLBOX_PATH . '/access.points' );
44
45 /** Frmaework path */
46 define('CJTOOLBOX_FRAMEWORK', CJTOOLBOX_INCLUDE_PATH); // Alias to include path!
47
48 // Class Autoload Added @since 6.2.
49 require 'autoload.inc.php';
50
51 // Import dependencies
52 require_once CJTOOLBOX_FRAMEWORK . '/php/includes.class.php';
53 require_once CJTOOLBOX_FRAMEWORK . '/events/definition.class.php';
54 require_once CJTOOLBOX_FRAMEWORK . '/events/events.class.php';
55 require_once CJTOOLBOX_FRAMEWORK . '/events/wordpress.class.php';
56 require_once CJTOOLBOX_FRAMEWORK . '/events/hookable.interface.php';
57 require_once CJTOOLBOX_FRAMEWORK . '/events/hookable.class.php';
58
59 // Initialize events engine/system!
60 CJTWordpressEvents::_init( array( 'hookType' => CJTWordpressEvents::HOOK_ACTION ) );
61 CJTWordpressEvents::$paths[ 'subjects' ][ 'core' ] = CJTOOLBOX_FRAMEWORK . '/events/subjects';
62 CJTWordpressEvents::$paths[ 'observers' ][ 'core' ] = CJTOOLBOX_FRAMEWORK . '/events/observers';
63
64 /**
65 * CJT Plugin interface.
66 *
67 * The CJT Plugin is maximum deferred.
68 * All functionality here is just to detect if the request should be processed!
69 *
70 * The main class is located css-js-toolbox.class.php cssJSToolbox class
71 * The plugin is fully developed using Model-View-Controller design pattern.
72 *
73 * access.points directory has all the entry points that processed by the Plugin.
74 *
75 * @package CJT
76 * @author Ahmed Said
77 * @version 6
78 */
79 class CJTPlugin extends CJTHookableClass
80 {
81
82 /**
83 *
84 */
85 const DB_VERSION = '1.7';
86
87 /**
88 * put your comment there...
89 *
90 * @var mixed
91 */
92 CONST ENV_PHP_MIN_VERSION = '5.3';
93
94 /**
95 *
96 */
97 const FW_Version = '5.0';
98
99 /**
100 *
101 */
102 const VERSION = '11';
103
104 /**
105 *
106 */
107 const DB_VERSION_OPTION_NAME = 'cjtoolbox_db_version';
108
109 /**
110 *
111 */
112 const PLUGIN_REQUEST_ID = 'cjtoolbox';
113
114 /**
115 * put your comment there...
116 *
117 * @var mixed
118 */
119 protected $accessPoints;
120
121 /**
122 * put your comment there...
123 *
124 * @var mixed
125 */
126 protected $extensions;
127
128 /**
129 * put your comment there...
130 *
131 * @var mixed
132 */
133 protected $installed;
134
135 /**
136 * put your comment there...
137 *
138 * @var CJTPlugin
139 */
140 protected static $instance;
141
142 /**
143 * put your comment there...
144 *
145 * @var mixed
146 */
147 protected $mainAC;
148
149 /**
150 * put your comment there...
151 *
152 * @var mixed
153 */
154 protected $onloaddbversion = array( 'parameters' => array( 'dbVersion' ) );
155
156 /**
157 * put your comment there...
158 *
159 * @var mixed
160 */
161 protected $onimportcontroller = array( 'parameters' => array( 'file' ) );
162
163 /**
164 * put your comment there...
165 *
166 * @var mixed
167 */
168 protected $onimportmodel = array( 'parameters' => array( 'file' ) );
169
170 /**
171 * put your comment there...
172 *
173 * @var mixed
174 */
175 protected $onload = array( 'parameters' => array( 'instance' ) );
176
177 /**
178 * put your comment there...
179 *
180 */
181 protected function __construct()
182 {
183 // Hookable!
184 parent::__construct();
185
186 // Allow access points to utilize from CJTPlugin functionality
187 // even if the call is recursive inside getInstance/construct methods!!!
188 self::$instance = $this;
189
190 // Installation version
191 $dbVersion = $this->onloaddbversion( get_option( self::DB_VERSION_OPTION_NAME ) );
192 $this->installed = ( ( $dbVersion ) == self::DB_VERSION );
193
194 // Load plugin and all installed extensions!.
195 $this->load();
196 $this->loadExtensions();
197
198 // Run MAIN access point!
199 $this->main();
200 }
201
202 /**
203 * put your comment there...
204 *
205 */
206 public function & extensions()
207 {
208 return $this->extensions;
209 }
210
211 /**
212 * put your comment there...
213 *
214 */
215 public function getAccessPoint( $name )
216 {
217 return $this->accessPoints[ $name ];
218 }
219
220 /**
221 * put your comment there...
222 *
223 */
224 public static function getInstance()
225 {
226
227 if ( ! self::$instance )
228 {
229 self::$instance = new CJTPlugin();
230 }
231
232 return self::$instance;
233 }
234
235 /**
236 * put your comment there...
237 *
238 */
239 public static function isCompatibleEnvironment()
240 {
241
242 if ( version_compare( PHP_VERSION, self::ENV_PHP_MIN_VERSION, '<' ) )
243 {
244
245 $importHTMLFileCode = 'require "includes" . DIRECTORY_SEPARATOR . "html" . DIRECTORY_SEPARATOR . "incompatible_environment_message.html.php";';
246
247 add_action( 'admin_notices', create_function( '', $importHTMLFileCode ) );
248
249 return false;
250 }
251
252 return true;
253 }
254 /**
255 * put your comment there...
256 *
257 */
258 public function isInstalled()
259 {
260 return $this->installed;
261 }
262
263 /**
264 * put your comment there...
265 *
266 */
267 public function listen()
268 {
269 // For now we've only admin access points! Future versions might has something changed!
270 if ( is_admin() )
271 {
272
273 // Import access points core classes.
274 require_once 'framework/access-points/page.class.php';
275 require_once 'framework/access-points/directory-spider.class.php';
276
277 // Get access points!
278 $accessPoints = CJTAccessPointsDirectorySpider::getInstance( 'CJT', CJTOOLBOX_ACCESS_POINTS );
279
280 // For every access point create instance and LISTEN to the request!
281 foreach ( $accessPoints as $name => $info )
282 {
283 /**
284 * @var CJTAccessPoint
285 */
286 $this->accessPoints[ $name ] = $point = $accessPoints->point()->listen();
287
288 // We need to do some work with there is a connected access point.
289 $point->onconnected = array( & $this, 'onconnected' );
290
291 }
292
293 }
294
295 return $this;
296 }
297
298 /**
299 * put your comment there...
300 *
301 */
302 protected function load()
303 {
304 // Bootstrap the Plugin!
305 cssJSToolbox::getInstance();
306
307 // Load MVC framework core!
308 require_once $this->onimportmodel( CJTOOLBOX_MVC_FRAMEWOK . '/model.inc.php' );
309 require_once $this->onimportcontroller( CJTOOLBOX_MVC_FRAMEWOK . '/controller.inc.php' );
310
311 return $this;
312 }
313
314 /**
315 * put your comment there...
316 *
317 */
318 protected function loadExtensions()
319 {
320 // Load extensions lib!
321 require_once 'framework/extensions/extensions.class.php';
322
323 $this->extensions = new CJTExtensions();
324 $this->extensions->load();
325
326 return $this;
327 }
328
329 /**
330 * Run MAIN access point!
331 *
332 * @return $this
333 */
334 protected function main()
335 {
336 // Fire laod event
337 $this->onload( $this );
338
339 // Access point base class is a dependency!
340 require_once 'framework/access-points/access-point.class.php';
341
342 // Run Main Acces Point!
343 include_once 'access.points/main.accesspoint.php';
344
345 $this->mainAC = new CJTMainAccessPoint();
346 $this->mainAC->listen();
347 }
348
349 /**
350 * Called When any In-Listen-State (ILS) Access point is
351 * connected (called by Wordpress hooking system).
352 *
353 * @return boolean TRUE.
354 */
355 public function onconnected( $observer, $state )
356 {
357
358 // In all cases that we'll process the request load the localization file.
359 load_plugin_textdomain( CJTOOLBOX_TEXT_DOMAIN, false, CJTOOLBOX_LANGUAGES );
360
361 do_action( CJTPluggableHelper::ACTION_CJT_TEXT_DOMAIN_LOADED );
362
363 // Always connet the access point!
364 return $state;
365
366 }
367
368 }// End Class
369
370 // Dont run if environment (e.g PHP version) is incomaptible
371 if ( ! CJTPlugin::isCompatibleEnvironment() )
372 {
373 return;
374 }
375
376 // Initialize events!
377 CJTPlugin::define( 'CJTPlugin', array( 'hookType' => CJTWordpressEvents::HOOK_FILTER ) );
378
379 // Let's Go!
380 function deprecatedPHPCheck()
381 { ?>
382 <div class="notice notice-error">
383 <p><strong>CJT</strong>: CSS & JavaScript Toolbox need PHP version 7.3 or greater to operate properly. Please ask your hosting provider to update the PHP version.<br>
384 Current PHP Version: <strong><?php echo phpversion(); ?></strong>
385 </p>
386 </div>
387 <?php }
388
389 if ( version_compare( phpversion(), 7, '>=' ) ) {
390 CJTPlugin::getInstance();
391 } else {
392 add_action( 'admin_notices', 'deprecatedPHPCheck' );
393 }
394
395 add_action( 'upgrader_process_complete', 'upgradeCheck',10, 2 );
396
397 function upgradeCheck( $upgrader_object, $options ) {
398 $CJTPluginPath = plugin_basename( __FILE__ );
399
400 global $wpdb;
401 $table_name = $wpdb->base_prefix.'cjtoolbox_blocks';
402 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
403 $preCheck = get_option( '__existing_cjt_user' );
404
405 if ( $options['action'] == 'update' && $options['type'] == 'plugin' ) {
406 foreach( $options['plugins'] as $each_plugin ) {
407 if ( $each_plugin == $CJTPluginPath ) {
408 $preCheck = get_option( '__existing_cjt_user' );
409
410 // Only create it once.
411 if ( empty( $preCheck ) ) {
412 update_option( '__existing_cjt_user', $wpdb->get_var( $query ) === $table_name ? 'true' : 'false' );
413 }
414 }
415 }
416 }
417 }
418