Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
6.3 KiB

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