· 7 years ago · Jan 21, 2019, 09:44 PM
1<?php
2
3
4
5/**
6
7 * Plugin Name: Timetable and Event Schedule
8
9 * Plugin URI: https://motopress.com
10
11 * Description: Smart time-management tool with a clean minimalist design for featuring your timetables and upcoming events.
12
13 * Version: 2.2.1
14
15 * Author: MotoPress
16
17 * Author URI: https://motopress.com
18
19 * License: GPLv2 or later
20
21 * Text Domain: mp-timetable
22
23 * Domain Path: /languages
24
25 */
26
27
28
29/*
30
31 * This plugin contains hooks that allow you to edit, add and move content without needing to edit template files. This method protects against upgrade issues.
32
33 * Alternatively, you can copy template files from '/mp-timetable/templates/' folder to '/your-theme/mp-timetable/' to override them.
34
35 */
36
37
38
39use mp_timetable\plugin_core\classes\Core;
40
41
42
43define( "MP_TT_PLUGIN_NAME", 'mp-timetable' );
44
45define( 'MP_TT_DEBUG', false );
46
47
48
49register_activation_hook( __FILE__, array( Mp_Time_Table::init(), 'on_activation' ) );
50
51register_deactivation_hook( __FILE__, array( 'Mp_Time_Table', 'on_deactivation' ) );
52
53register_uninstall_hook( __FILE__, array( 'Mp_Time_Table', 'on_uninstall' ) );
54
55
56
57add_action( 'plugins_loaded', array( 'Mp_Time_Table', 'init' ) );
58
59add_action( 'wpmu_new_blog', array( 'Mp_Time_Table', 'on_create_blog' ), 10, 6 );
60
61add_filter( 'wpmu_drop_tables', array( 'Mp_Time_Table', 'on_delete_blog' ) );
62
63
64
65/**
66
67 * Class Mp_Time_Table
68
69 */
70
71class Mp_Time_Table {
72
73
74
75 protected static $instance;
76
77
78
79 /**
80
81 * Mp_Time_Table constructor.
82
83 */
84
85 public function __construct() {
86
87 $this->include_all();
88
89 Core::get_instance()->init_plugin( 'mp_timetable' );
90
91 }
92
93
94
95 /**
96
97 * Include all files
98
99 */
100
101 public function include_all() {
102
103 /**
104
105 * Include Gump
106
107 */
108
109 require_once self::get_plugin_path() . 'classes/libs/class-gump.php';
110
111 /**
112
113 * Install Fire bug
114
115 */
116
117 require_once self::get_plugin_path() . 'classes/libs/FirePHPCore/fb.php';
118
119 /**
120
121 * Install Parsers
122
123 */
124
125 require_once self::get_plugin_path() . 'classes/libs/parsers.php';
126
127 /**
128
129 * Include Permalinks
130
131 */
132
133 require_once self::get_plugin_path() . 'classes/class-permalinks.php';
134
135 /**
136
137 * Include Core
138
139 */
140
141 require_once self::get_plugin_path() . 'classes/class-core.php';
142
143 /**
144
145 * Include module
146
147 */
148
149 require_once self::get_plugin_path() . 'classes/class-module.php';
150
151 /**
152
153 * Include Model
154
155 */
156
157 require_once self::get_plugin_path() . 'classes/class-model.php';
158
159
160
161 /**
162
163 * Include Controller
164
165 */
166
167 require_once self::get_plugin_path() . 'classes/class-controller.php';
168
169 /**
170
171 * Include State factory
172
173 */
174
175 require_once self::get_plugin_path() . 'classes/class-state-factory.php';
176
177
178
179 /**
180
181 * Include Preprocessor
182
183 */
184
185 require_once self::get_plugin_path() . 'classes/class-preprocessor.php';
186
187
188
189 /**
190
191 * include shortcodes
192
193 */
194
195 require_once( self::get_plugin_path() . 'classes/class-shortcode.php' );
196
197 /**
198
199 * include Widgets
200
201 */
202
203 require_once self::get_plugin_path() . 'classes/widgets/class-mp-timetable-widget.php';
204
205 /**
206
207 * Include view
208
209 */
210
211 require_once self::get_plugin_path() . 'classes/class-view.php';
212
213 /**
214
215 * Include hooks
216
217 */
218
219 require_once self::get_plugin_path() . 'classes/class-hooks.php';
220
221 }
222
223
224
225 /**
226
227 * Get plugin path
228
229 */
230
231 public static function get_plugin_path() {
232
233 return plugin_dir_path( __FILE__ );
234
235 }
236
237
238
239 /**
240
241 * @return Mp_Time_Table
242
243 */
244
245 public static function init() {
246
247 if ( null === self::$instance ) {
248
249 self::$instance = new self();
250
251 }
252
253
254
255 return self::$instance;
256
257 }
258
259
260
261 /**
262
263 * Retrieve relative to theme root path to templates.
264
265 *
266
267 * @return string
268
269 */
270
271 public static function get_template_path() {
272
273 return apply_filters( 'mptt_template_path', 'mp-timetable/' );
274
275 }
276
277
278
279 /**
280
281 * Retrieve relative to plugin root path to templates.
282
283 *
284
285 * @return string
286
287 */
288
289 public static function get_templates_path() {
290
291 return self::get_plugin_path() . 'templates/';
292
293 }
294
295
296
297 /**
298
299 * Get plugin part path
300
301 *
302
303 * @param string $part
304
305 *
306
307 * @return string
308
309 */
310
311 public static function get_plugin_part_path( $part = '' ) {
312
313 return self::get_plugin_path() . $part;
314
315 }
316
317
318
319 /**
320
321 * On activation
322
323 */
324
325 public static function on_activation() {
326
327 // Register post type
328
329 Core::get_instance()->register_all_post_type();
330
331
332
333 // Register taxonomy all
334
335 Core::get_instance()->register_all_taxonomies();
336
337
338
339 flush_rewrite_rules();
340
341
342
343 //Create table in not exists
344
345 Core::get_instance()->create_table();
346
347 }
348
349
350
351 /**
352
353 * On deactivation
354
355 */
356
357 public static function on_deactivation() {
358
359 flush_rewrite_rules();
360
361 }
362
363
364
365 /**
366
367 * On uninstall
368
369 */
370
371 public static function on_uninstall() {
372
373 do_action( 'mptt_on_uninstall' );
374
375 }
376
377
378
379 /**
380
381 * On create blog
382
383 *
384
385 * @param $blog_id
386
387 * @param $user_id
388
389 * @param $domain
390
391 * @param $path
392
393 * @param $site_id
394
395 * @param $meta
396
397 */
398
399 public static function on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
400
401 if ( is_plugin_active_for_network( self::get_plugin_name() . '/' . self::get_plugin_name() . '.php' ) ) {
402
403 switch_to_blog( $blog_id );
404
405 //Create table in not exists
406
407 Core::get_instance()->create_table();
408
409 restore_current_blog();
410
411 }
412
413 }
414
415
416
417 /**
418
419 * Get plugin name
420
421 *
422
423 * @return string
424
425 */
426
427 public static function get_plugin_name() {
428
429 return dirname( plugin_basename( __FILE__ ) );
430
431 }
432
433
434
435 /**
436
437 * On blog creation
438
439 */
440
441 public static function on_delete_blog( $tables ) {
442
443
444
445 $tables[] = self::get_datatable();
446
447
448
449 return $tables;
450
451 }
452
453
454
455 /**
456
457 * Get data table name
458
459 *
460
461 * @return string
462
463 */
464
465 public static function get_datatable() {
466
467 global $wpdb;
468
469
470
471 return $wpdb->prefix . "mp_timetable_data";
472
473 }
474
475
476
477 /**
478
479 * Get plugin url
480
481 *
482
483 * @param bool|false $path
484
485 * @param string $pluginName
486
487 * @param string $sync
488
489 *
490
491 * @return string
492
493 */
494
495 static function get_plugin_url( $path = false, $pluginName = 'mp-timetable', $sync = '' ) {
496
497 return plugins_url() . '/' . $pluginName . '/' . $path . $sync;
498
499 }
500
501}