forked from LeedRSS/Leed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.class.php
executable file
·276 lines (212 loc) · 7.21 KB
/
Plugin.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
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
<?php
/*
@nom: Plugin
@auteur: Idleman ([email protected])
@description: Classe de gestion des plugins au travers de l'application
*/
class Plugin{
const FOLDER = '/plugins';
protected $name,$author,$mail,$link,$licence,$path,$description,$version,$state;
function __construct(){
}
public static function includeAll(){
$pluginFiles = Plugin::getFiles(true);
if(is_array($pluginFiles)) {
foreach($pluginFiles as $pluginFile) {
//Inclusion du coeur de plugin
include $pluginFile;
//Gestion des css du plugin en fonction du thème actif
$cssTheme = glob(dirname($pluginFile).'/*/'.DEFAULT_THEME.'.css');
$cssDefault = glob(dirname($pluginFile).'/*/default.css');
if(isset($cssTheme[0])){
$GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssTheme[0]));
}else if(isset($cssDefault[0])){
$GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssDefault[0]));
}
}
}
}
public static function getAll(){
$pluginFiles = Plugin::getFiles();
$plugins = array();
if(is_array($pluginFiles)) {
foreach($pluginFiles as $pluginFile) {
$plugin = new Plugin();
$fileLines = file_get_contents($pluginFile);
//Author
if(preg_match("#@author\s(.+)\s\<#", $fileLines, $match))
$plugin->setAuthor(trim($match[1]));
if(preg_match("#@author\s(.+)\s\<([a-z\@\.A-Z\s\-]+)\>#", $fileLines, $match))
$plugin->setMail(strtolower($match[2]));
if(preg_match("#@name\s(.+)[\r\n]#", $fileLines, $match))
$plugin->setName($match[1]);
if(preg_match("#@licence\s(.+)[\r\n]#", $fileLines, $match))
$plugin->setLicence($match[1]);
if(preg_match("#@version\s(.+)[\r\n]#", $fileLines, $match))
$plugin->setVersion($match[1]);
if(preg_match("#@link\s(.+)[\r\n]#", $fileLines, $match))
$plugin->setLink(trim($match[1]));
if(preg_match("#@description\s(.+)[\r\n]#", $fileLines, $match))
$plugin->setDescription(trim($match[1]));
if(strpos($pluginFile,'.plugin.enabled.php')!==false){
$plugin->setState(1);
}else{
$plugin->setState(0);
}
$plugin->setPath($pluginFile);
$plugins[]=$plugin;
}
}
usort($plugins, "Plugin::sortPlugin");
return $plugins;
}
public static function addHook($hookName, $functionName) {
$GLOBALS['hooks'][$hookName][] = $functionName;
}
public static function addCss($css) {
$bt = debug_backtrace();
$path = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']).$css));
$GLOBALS['hooks']['css_files'][] = $path;
}
public static function callCss(){
$return='';
if(isset($GLOBALS['hooks']['css_files'])) {
foreach($GLOBALS['hooks']['css_files'] as $css_file) {
$return .='<link rel="stylesheet" href="'.$css_file.'">'."\n";
}
}
return $return;
}
public static function addLink($rel, $link) {
$GLOBALS['hooks']['head_link'][] = array("rel"=>$rel, "link"=>$link);
}
public static function callLink(){
$return='';
if(isset($GLOBALS['hooks']['head_link'])) {
foreach($GLOBALS['hooks']['head_link'] as $head_link) {
$return .='<link rel="'.$head_link['rel'].'" href="'.$head_link['link'].'" />'."\n";
}
}
return $return;
}
public static function path(){
$bt = debug_backtrace();
return Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']))).'/';
}
public static function addJs($js) {
$bt = debug_backtrace();
$path = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']).$js));
$GLOBALS['hooks']['js_files'][] = $path;
}
public static function callJs(){
$return='';
if(isset($GLOBALS['hooks']['js_files'])) {
foreach($GLOBALS['hooks']['js_files'] as $js_file) {
$return .='<script type="text/javascript" src="'.$js_file.'"></script>'."\n";
}
}
return $return;
}
public static function callHook($hookName, $hookArguments) {
//echo '<div style="display:inline;background-color:#CC47CB;padding:3px;border:5px solid #9F1A9E;border-radius:5px;color:#ffffff;font-size:15px;">'.$hookName.'</div>';
if(isset($GLOBALS['hooks'][$hookName])) {
foreach($GLOBALS['hooks'][$hookName] as $functionName) {
call_user_func_array($functionName, $hookArguments);
}
}
}
public static function getFiles($onlyActivated=false){
$files = glob(dirname(__FILE__) . Plugin::FOLDER .'/*/*.plugin.enabled.php');
$filesDisabled = glob(dirname(__FILE__) . Plugin::FOLDER .'/*/*.plugin.disabled.php');
if (!is_array($files)) $files = array();
if (!is_array($filesDisabled)) $filesDisabled = array();
if(!$onlyActivated)$files = array_merge($files,$filesDisabled);
return $files;
}
function getName(){
return $this->name;
}
function setName($name){
$this->name = $name;
}
function setAuthor($author){
$this->author = $author;
}
function getAuthor(){
return $this->author;
}
function getMail(){
return $this->mail;
}
function setMail($mail){
$this->mail = $mail;
}
function getLicence(){
return $this->licence;
}
function setLicence($licence){
$this->licence = $licence;
}
function getPath(){
return $this->path;
}
function setPath($path){
$this->path = $path;
}
function getDescription(){
return $this->description;
}
function setDescription($description){
$this->description = $description;
}
function getLink(){
return $this->link;
}
function setLink($link){
$this->link = $link;
}
function getVersion(){
return $this->version;
}
function setVersion($version){
$this->version = $version;
}
function getState(){
return $this->state;
}
function setState($state){
$this->state = $state;
}
function getUid(){
$pathInfo = explode('/',$this->getPath());
$count = count($pathInfo);
$name = $pathInfo[$count-1];
return $pathInfo[$count -2].'-'.substr($name,0,strpos($name,'.'));
}
public static function enabled($pluginUid){
$plugins = Plugin::getAll();
foreach($plugins as $plugin){
if($plugin->getUid()==$pluginUid){
rename($plugin->getPath(),str_replace('.plugin.disabled.php', '.plugin.enabled.php', $plugin->getPath()));
$install = dirname($plugin->getPath()).'/install.php';
if(file_exists($install))require_once($install);
}
}
}
public static function disabled($pluginUid){
$plugins = Plugin::getAll();
foreach($plugins as $plugin){
if($plugin->getUid()==$pluginUid){
rename($plugin->getPath(),str_replace('.plugin.enabled.php', '.plugin.disabled.php', $plugin->getPath()));
$uninstall = dirname($plugin->getPath()).'/uninstall.php';
if(file_exists($uninstall))require_once($uninstall);
}
}
}
static function sortPlugin($a, $b){
if ($a->getName() == $b->getName())
return 0;
return ($a->getName() < $b->getName()) ? -1 : 1;
}
}
?>