-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcuisine.php
309 lines (230 loc) · 6.65 KB
/
cuisine.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/**
* Plugin Name: Cuisine
* Plugin URI: http://chefduweb.nl/cuisine
* Description: A framework for WordPress developers.
* Version: 3.0.0
* Author: Luc Princen
* Author URI: http://www.chefduweb.nl/
* License: GPLv3
* Bitbucket Plugin URI: https://bitbucket.org/chefduweb/cuisine
* Bitbucket Branch: master
*
* @package Cuisine
* @category Core
* @author Chef du Web
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// The directory separator.
defined('DS') ? DS : define('DS', DIRECTORY_SEPARATOR);
/**
* Main class that bootstraps the framework.
*/
if (!class_exists('Cuisine')) {
class Cuisine {
/**
* Framework bootstrap instance.
*
* @var \Cuisine
*/
private static $instance = null;
/**
* Plugin directory name.
*
* @var string
*/
private static $dirName = '';
/**
* All registered routes
*
* @var array
*/
public $routes = array();
/**
* All registered templates
*
* @var array
*/
public $templates = array();
/**
* All registered scripts
*
* @var array
*/
public $scripts = array();
/**
* All registered JS vars
*
* @var array
*/
public $jsVars = array();
/**
* All registered JS Shims
*
* @var array
*/
public $shims = array();
/**
* All registered Nav Items
*
* @var array
*/
public $navItems = array();
private function __construct(){
static::$dirName = static::setDirName(__DIR__);
// Load plugin.
$this->load();
}
/**
* Load the framework classes.
*
* @return void
*/
private function load(){
//auto-loads all .php files in these directories.
$includes = array(
'Classes/Wrappers',
'Classes/Utilities',
'Classes/Database/Contracts',
'Classes/Database/Grammars',
'Classes/Database',
'Classes/Database/Migrations',
'Classes/Models',
'Classes/Cron',
'Classes/Admin',
'Classes/Front',
'Classes/Builders',
'Classes/Fields',
'Classes/View'
);
if ( defined('WP_CLI') && WP_CLI )
$includes[] = 'Classes/Cli';
$includes = apply_filters( 'cuisine_autoload_dirs', $includes );
foreach( $includes as $inc ){
$root = static::getPluginPath();
$files = glob( $root.$inc.'/*.php' );
foreach ( $files as $file ){
require_once( $file );
}
}
// Set the framework paths and starts the framework.
add_action('after_setup_theme', array($this, 'bootstrap'));
//cuisine is fully loaded
do_action( 'cuisine_loaded' );
//include the css
add_action( 'admin_init', function(){
wp_enqueue_style( 'cuisine', plugins_url( 'Assets/css/admin.css', __FILE__ ) );
});
}
/**
* Define paths and bootstrap the framework.
*
* @return void
*/
public function bootstrap(){
/**
* Define all framework paths
* These are real paths, not URLs to the framework files.
* These paths are extensible with the help of WordPress
* filters.
*/
// Framework paths.
$paths = apply_filters('cuisine_framework_paths', array());
// Plugin base path.
$paths['plugin'] = static::getPluginPath();
// Register globally the paths
foreach ($paths as $name => $path){
if ( !isset( $GLOBALS['cuisine_paths'][$name] ) ){
$GLOBALS['cuisine_paths'][$name] = realpath($path).DS;
}
}
do_action( 'cuisine_bootstrapped' );
}
/*=============================================================*/
/** Getters & Setters */
/*=============================================================*/
/**
* Init the framework classes
*
* @return \Cuisine
*/
public static function getInstance(){
if ( is_null( static::$instance ) ){
static::$instance = new static();
}
return static::$instance;
}
/**
* Set the plugin directory property. This property
* is used as 'key' in order to retrieve the plugins
* informations.
*
* @param string
* @return string
*/
private static function setDirName($path) {
$parent = static::getParentDirectoryName(dirname($path));
$dirName = explode($parent, $path);
$dirName = substr($dirName[1], 1);
return $dirName;
}
/**
* Check if the plugin is inside the 'mu-plugins'
* or 'plugin' directory.
*
* @param string $path
* @return string
*/
private static function getParentDirectoryName($path) {
// Check if in the 'mu-plugins' directory.
if (WPMU_PLUGIN_DIR === $path) {
return 'mu-plugins';
}
// Install as a classic plugin.
return 'plugins';
}
public static function getPluginPath(){
return __DIR__.DS;
}
/**
* Returns the directory name.
*
* @return string
*/
public static function getDirName(){
return static::$dirName;
}
}
}
/**
* Load the main class.
*
*/
add_action('plugins_loaded', function(){
$GLOBALS['Cuisine'] = Cuisine::getInstance();
});
/**
* Registration & deactivation:
*/
register_activation_hook( __FILE__, function(){
update_option( 'cuisine_activated', 'cuisine' );
});
/**
* Print_R in a <pre> tag
*/
if( !function_exists( 'cuisine_dump' ) ){
function cuisine_dump( $arr ){
echo '<pre>';
print_r( $arr );
echo '</pre>';
}
}
/**
* Print_R in a <pre> tag and die
*/
if( !function_exists( 'dd' ) ){
function dd( $arr ){
cuisine_dump( $arr );
die();
}
}