]> git.mxchange.org Git - friendica.git/blob - include/plugin.php
show experimental and unsupported theme status on theme admin page\18
[friendica.git] / include / plugin.php
1 <?php
2
3
4 // install and uninstall plugin
5 if (! function_exists('uninstall_plugin')){
6 function uninstall_plugin($plugin){
7         logger("Addons: uninstalling " . $plugin);
8         q("DELETE FROM `addon` WHERE `name` = '%s' LIMIT 1",
9                 dbesc($plugin)
10         );
11
12         @include_once('addon/' . $plugin . '/' . $plugin . '.php');
13         if(function_exists($plugin . '_uninstall')) {
14                 $func = $plugin . '_uninstall';
15                 $func();
16         }
17 }}
18
19 if (! function_exists('install_plugin')){
20 function install_plugin($plugin){
21         logger("Addons: installing " . $plugin);
22         $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
23         @include_once('addon/' . $plugin . '/' . $plugin . '.php');
24         if(function_exists($plugin . '_install')) {
25                 $func = $plugin . '_install';
26                 $func();
27                 
28                 $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
29                 
30                 $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
31                         dbesc($plugin),
32                         intval($t),
33                         $plugin_admin
34                 );
35         }
36         else {
37                 logger("Addons: FAILED installing " . $plugin);
38         }
39
40 }}
41
42 // reload all updated plugins
43
44 if(! function_exists('reload_plugins')) {
45 function reload_plugins() {
46         $plugins = get_config('system','addon');
47         if(strlen($plugins)) {
48
49                 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
50                 if(count($r))
51                         $installed = $r;
52                 else
53                         $installed = array();
54
55                 $parr = explode(',',$plugins);
56                 if(count($parr)) {
57                         foreach($parr as $pl) {
58                                 $pl = trim($pl);
59
60                                 $fname = 'addon/' . $pl . '/' . $pl . '.php';
61                                 
62                                 if(file_exists($fname)) {
63                                         $t = @filemtime($fname);
64                                         foreach($installed as $i) {
65                                                 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {    
66                                                         logger('Reloading plugin: ' . $i['name']);
67                                                         @include_once($fname);
68
69                                                         if(function_exists($pl . '_uninstall')) {
70                                                                 $func = $pl . '_uninstall';
71                                                                 $func();
72                                                         }
73                                                         if(function_exists($pl . '_install')) {
74                                                                 $func = $pl . '_install';
75                                                                 $func();
76                                                         }
77                                                         q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
78                                                                 intval($t),
79                                                                 intval($i['id'])
80                                                         );
81                                                 }
82                                         }
83                                 }
84                         }
85                 }
86         }
87 }}
88                                 
89
90
91
92
93 if(! function_exists('register_hook')) {
94 function register_hook($hook,$file,$function) {
95
96         $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
97                 dbesc($hook),
98                 dbesc($file),
99                 dbesc($function)
100         );
101         if(count($r))
102                 return true;
103
104         $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
105                 dbesc($hook),
106                 dbesc($file),
107                 dbesc($function)
108         );
109         return $r;
110 }}
111
112 if(! function_exists('unregister_hook')) {
113 function unregister_hook($hook,$file,$function) {
114
115         $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
116                 dbesc($hook),
117                 dbesc($file),
118                 dbesc($function)
119         );
120         return $r;
121 }}
122
123
124 if(! function_exists('load_hooks')) {
125 function load_hooks() {
126         $a = get_app();
127         $a->hooks = array();
128         $r = q("SELECT * FROM `hook` WHERE 1");
129         if(count($r)) {
130                 foreach($r as $rr) {
131                         $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
132                 }
133         }
134 }}
135
136
137 if(! function_exists('call_hooks')) {
138 function call_hooks($name, &$data = null) {
139         $a = get_app();
140
141         if(count($a->hooks)) {
142                 foreach($a->hooks as $hook) {
143                         if($hook[HOOK_HOOK] === $name) {
144                                 @include_once($hook[HOOK_FILE]);
145                                 if(function_exists($hook[HOOK_FUNCTION])) {
146                                         $func = $hook[HOOK_FUNCTION];
147                                         $func($a,$data);
148                                 }
149                         }
150                 }
151         }
152 }}
153
154
155 /*
156  * parse plugin comment in search of plugin infos.
157  * like
158  *      
159  *       * Name: Plugin
160  *   * Description: A plugin which plugs in
161  *       * Version: 1.2.3
162  *   * Author: John <profile url>
163  *   * Author: Jane <email>
164  *   *
165  */
166
167 if (! function_exists('get_plugin_info')){
168 function get_plugin_info($plugin){
169         $info=Array(
170                 'name' => $plugin,
171                 'description' => "",
172                 'author' => array(),
173                 'version' => ""
174         );
175         
176         if (!is_file("addon/$plugin/$plugin.php")) return $info;
177         
178         $f = file_get_contents("addon/$plugin/$plugin.php");
179         $r = preg_match("|/\*.*\*/|msU", $f, $m);
180         
181         if ($r){
182                 $ll = explode("\n", $m[0]);
183                 foreach( $ll as $l ) {
184                         $l = trim($l,"\t\n\r */");
185                         if ($l!=""){
186                                 list($k,$v) = array_map("trim", explode(":",$l,2));
187                                 $k= strtolower($k);
188                                 if ($k=="author"){
189                                         $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
190                                         if ($r) {
191                                                 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
192                                         } else {
193                                                 $info['author'][] = array('name'=>$v);
194                                         }
195                                 } else {
196                                         if (array_key_exists($k,$info)){
197                                                 $info[$k]=$v;
198                                         }
199                                 }
200                                 
201                         }
202                 }
203                 
204         }
205         return $info;
206 }}
207
208
209 /*
210  * parse theme comment in search of theme infos.
211  * like
212  *      
213  *       * Name: My Theme
214  *   * Description: My Cool Theme
215  *       * Version: 1.2.3
216  *   * Author: John <profile url>
217  *   * Maintainer: Jane <profile url>
218  *   *
219  */
220
221 if (! function_exists('get_theme_info')){
222 function get_theme_info($theme){
223         $info=Array(
224                 'name' => $theme,
225                 'description' => "",
226                 'author' => array(),
227                 'maintainer' => array(),
228                 'version' => "",
229                 'experimental' => false,
230                 'unsupported' => false
231         );
232
233         if(file_exists("view/theme/$theme/experimental"))
234                 $info['experimental'] = true;
235         if(file_exists("view/theme/$theme/unsupported"))
236                 $info['unsupported'] = true;
237
238         if (!is_file("view/theme/$theme/theme.php")) return $info;
239         
240         $f = file_get_contents("view/theme/$theme/theme.php");
241         $r = preg_match("|/\*.*\*/|msU", $f, $m);
242         
243         
244         if ($r){
245                 $ll = explode("\n", $m[0]);
246                 foreach( $ll as $l ) {
247                         $l = trim($l,"\t\n\r */");
248                         if ($l!=""){
249                                 list($k,$v) = array_map("trim", explode(":",$l,2));
250                                 $k= strtolower($k);
251                                 if ($k=="author"){
252                                         $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
253                                         if ($r) {
254                                                 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
255                                         } else {
256                                                 $info['author'][] = array('name'=>$v);
257                                         }
258                                 }
259                                 elseif ($k=="maintainer"){
260                                         $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
261                                         if ($r) {
262                                                 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
263                                         } else {
264                                                 $info['maintainer'][] = array('name'=>$v);
265                                         }
266                                 } else {
267                                         if (array_key_exists($k,$info)){
268                                                 $info[$k]=$v;
269                                         }
270                                 }
271                                 
272                         }
273                 }
274                 
275         }
276         return $info;
277 }}
278