This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrism_Detached.php
211 lines (160 loc) · 4.49 KB
/
Prism_Detached.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
<?php
/*
Plugin Name: Prism Syntax Highlighter (detached)
Plugin URI: https://github.com/apfelbox/Prism-Detached
Description: Includes the prism syntax highlighter in WordPress by using Custom Fields.
Version: 1.5
Author: Jannik Zschiesche
Update: JC John Sese Cuneta
Author URI: http://apfelbox.net
Update URI: http://jcsesecuneta.com
License: GPL2
*/
// Start script
$prism = new Prism_Detached();
$prism->init();
/**
* Main Controller for the prism plugin
*/
class Prism_Detached
{
/**
* The used prism version
*
* @var string
*/
const PRISM_VERSION = '07c0f4f6b2';
/**
* The plugin version
*
* @var string
*/
const PLUGIN_VERSION = '1.5';
/**
* The prism settings
*
* @var Prism_Detached_Settings
*/
private $settings;
/**
* The extension loader
*
* @var Prism_Detached_Extension_Loader
*/
private $extensionLoader;
/**
* The admin handler
*
* @var Prism_Detached_Admin
*/
private $admin;
/**
* Constructs a new prism detached plugin handler
*/
public function __construct ()
{
// register autoloader
$this->registerAutoloader();
// create settings
$this->settings = new Prism_Detached_Settings();
// create extension loader
$extensionDir = __DIR__ . '/vendor/extensions';
$extensionUrl = plugins_url('', __FILE__) . '/vendor/extensions';
$this->extensionLoader = new Prism_Detached_Extension_Loader($extensionDir, $extensionUrl, $this->settings);
// add the extension loader to the settings
$this->settings->setExtensionLoader($this->extensionLoader);
// create admin handler
$this->admin = new Prism_Detached_Admin($this->extensionLoader, $this->settings);
}
/**
* Registers the autoloader for the plugin
*/
private function registerAutoloader ()
{
$baseDir = __DIR__ . "/lib/";
spl_autoload_register(
function ($className) use ($baseDir)
{
if (substr($className, 0, 14) !== "Prism_Detached")
{
return;
}
$filePath = $baseDir . str_replace('_', '/', trim($className, '/')) . '.php';
if (is_file($filePath))
{
require_once $filePath;
}
}
);
}
/**
* Initializes the prism plugin
*/
public function init ()
{
// Register the [prism] short code
Prism_Detached_Shortcode_Handler::register();
// register the necessary hooks
$this->registerHooks();
}
/**
* Registers the used hooks
*/
private function registerHooks ()
{
register_deactivation_hook(__FILE__, array($this, 'onDeactivation'));
add_action('wp_enqueue_scripts', array($this, 'registerNeededAssets'));
add_action('admin_menu', array($this, 'registerAdminPage'));
add_action('admin_init', array($this, 'onAdminInit'));
// register to custom actions
add_action("prism-detached-settings-updated", array($this, 'onSettingsUpdated'));
}
/**
* Registers the needed assets in WordPress
*/
public function registerNeededAssets ()
{
$this->getAssetLoader()->registerAssets();
}
/**
* Returns the asset loader to use
*
* @return Prism_Detached_AssetsLoader_Base
*/
private function getAssetLoader ()
{
$cachedLoader = new Prism_Detached_AssetsLoader_Cached($this->extensionLoader, $this->settings, __FILE__);
return $cachedLoader->isAvailable()
? $cachedLoader
: new Prism_Detached_AssetsLoader_Default($this->extensionLoader);
}
/**
* Callback, when settings are updated
*/
public function onSettingsUpdated ()
{
$cachedLoader = new Prism_Detached_AssetsLoader_Cached($this->extensionLoader, $this->settings, __FILE__);
$cachedLoader->regenerate();
}
/**
* On deactivation callback
*/
public function onDeactivation ()
{
$this->settings->unregisterSettings();
}
/**
* Registers the admin page
*/
public function registerAdminPage ()
{
$this->admin->registerPage();
}
/**
* Handles the admin_init action
*/
public function onAdminInit ()
{
$this->settings->registerSettings();
}
}