/
css-js-toolbox.class.php
250 lines (216 loc) · 5.61 KB
/
css-js-toolbox.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
*
*/
// Disallow direct access.
defined('ABSPATH') or die("Access denied");
/** Change active profile to development state */
define('CJTOOLBOX_PROFILE_DEVELOPMENT', 'development');
/** Change active profile to production state */
define('CJTOOLBOX_PROFILE_PRODUCTION', 'production');
/** Set development state */
define('CJTOOLBOX_ACTIVE_PROFILE', CJTOOLBOX_PROFILE_DEVELOPMENT);
/** MVC library framework */
define('CJTOOLBOX_MVC_FRAMEWOK', CJTOOLBOX_INCLUDE_PATH . '/mvc');
/** Models dir path */
define('CJTOOLBOX_MODELS_PATH', CJTOOLBOX_PATH . '/models');
/** Tables dir path */
define('CJTOOLBOX_TABLES_PATH', CJTOOLBOX_PATH . '/tables');
/** Models views path */
define('CJTOOLBOX_VIEWS_PATH', CJTOOLBOX_PATH . '/views');
/** Views controllers path */
define('CJTOOLBOX_CONTROLLERS_PATH', CJTOOLBOX_PATH . '/controllers');
/** URI to CJT Plugin dir */
define('CJTOOLBOX_URL', WP_PLUGIN_URL . '/' . CJTOOLBOX_NAME );
/** URI to CJT Views directory */
define('CJTOOLBOX_VIEWS_URL', CJTOOLBOX_URL . '/views');
/** HTML Components URI */
define('CJTOOLBOX_HTML_CONPONENTS_URL', CJTOOLBOX_URL . '/framework/html/components');
/**
* CJT Core class.
*
* @package CJT
* @author Original Developer
* @version 0.3
*/
class cssJSToolbox extends CJTHookableClass {
/**
*
*/
const CJT_WEB_SITE_DOMAIN = 'css-javascript-toolbox.com';
/**
* put your comment there...
*
* @todo remove this and use configuration instead
*
* @var mixed
*/
public static $config = null;
/**
* put your comment there...
*
* @var mixed
*/
private $dbDriver;
/**
* Reference of CJT Plugin object.
*
* @var cssJSToolbox
*/
public static $instance = null;
/**
* put your comment there...
*
* @var mixed
*/
protected static $ongettext = array('parameters' => array('text'));
/**
* put your comment there...
*
* @var mixed
*/
protected static $onimport = array('parameters' => array('vpaths'));
/**
* put your comment there...
*
* @var mixed
*/
protected static $oninstantiate = array('parameters' => array('instance'));
/**
* put your comment there...
*
* @var mixed
*/
protected $onloadconfiguration = array('parameters' => array('configuration'));
/**
* put your comment there...
*
* @var mixed
*/
protected $onloaddbdriver = array('parameters' => array('dbdriver'));
/**
* put your comment there...
*
* @var mixed
*/
protected static $onresolvepath = array('parameters' => array('path', 'vpath'));
/**
* Initialize Plugin.
*
* @return void
*/
protected function __construct() {
// Initialize hookable!
parent::__construct();
// Load configuration.
self::$config = $this->onloadconfiguration(require(self::resolvePath('configuration.inc.php')));
// Initialize vars!
self::import('framework:db:mysql:queue-driver.inc.php');
$this->dbDriver = $this->onloaddbdriver(new CJTMYSQLQueueDriver($GLOBALS['wpdb']));
}
/**
* put your comment there...
*
*/
public static function getCJTWebSiteURL($path = null) {
$domain = self::CJT_WEB_SITE_DOMAIN;
return "http://{$domain}/{$path}";
}
/**
* put your comment there...
*
*/
public function & getDBDriver() {
return $this->dbDriver;
}
/**
* Get CJT Plugin object.
*
* @return cssJSToolbox
*/
public static function & getInstance() {
if (!self::$instance) {
self::$instance = self::trigger('cssJSToolbox.instantiate', (new cssJSToolbox()));
}
return self::$instance;
}
/**
* put your comment there...
*
*/
public static function getSecurityToken() {
return wp_create_nonce(CJTController::NONCE_ACTION);
}
/**
* put your comment there...
*
* @param mixed $text
*/
public static function getText($text) {
// Make sure to don't use $this while calling!
// $this might be an object other than CssJSToolbox!
return self::__callStatic('cssJSToolbox.ongettext', array(__($text, CJTOOLBOX_TEXT_DOMAIN)));
}
/**
* put your comment there...
*
* @param mixed $path
*/
public static function getURI($vPath, $uriBase = null) {
// PHP wrapper however its not imlpemented as wrapper yet
// because this is not the point right now!
if (strpos($vPath, 'extension://') === 0) {
// Expression for getting plugin/extension name!
$exp = '/^extension\:\/\/([^\/]+)/';
preg_match($exp, $vPath, $extensionPath);
// Get base URI + removing extension:// wrapper!
$uriBase = plugins_url($extensionPath[1]);
$uri = self::getURI(preg_replace($exp, '', $vPath), $uriBase);
}
else {
// Translate Virtual path to real path.
$path = str_replace(':', '/', $vPath);
// Get full URI.
if (!isset($uriBase)) {
$uriBase = plugin_dir_url(__FILE__);
}
$uri = "{$uriBase}{$path}";
}
return $uri;
}
/**
* put your comment there...
*
*/
public static function import() {
// Initialize!
$params = func_get_args();
// Allow vriables list parameters.
$vPaths = self::trigger('cssJSToolbox.import', $params);
foreach ($vPaths as $vPath) {
// Import file.
require_once self::resolvePath($vPath);
}
}
/**
* put your comment there...
*
* @param mixed $vPath
* @param mixed $base
*/
public static function resolvePath($vPath, $base = CJTOOLBOX_PATH) {
// Resolve CJT extensions path
if (strpos($vPath, 'extension://') === 0) {
// Remove extension wrapper
$vPath = str_replace('extension://', '', $vPath);
// Point to plugin directory
$base = WP_PLUGIN_DIR;
}
// Replace all :'s with /'s.
$path = str_replace(':', '/', $vPath);
$path = "{$base}/{$path}";
return self::trigger('cssJSToolbox.resolvepath', $path, $vPath);
}
}// End Class
// Hookable!
cssJSToolbox::define('cssJSToolbox', array('hookType' => CJTWordpressEvents::HOOK_FILTER));