]> git.mxchange.org Git - friendica.git/blobdiff - include/plugin.php
Bugfix for pictures that weren't stored / reworked database calls
[friendica.git] / include / plugin.php
index c75441bf9e6da6ff65d80afdc71c39afb6ca98f4..d5bceafdea82406e6b9ff770e647d325bfcbd50e 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 /**
  * @file include/plugin.php
- * 
+ *
  * @brief Some functions to handle addons and themes.
  */
 
+use Friendica\App;
+use Friendica\Core\System;
 
 /**
  * @brief uninstalls an addon.
@@ -45,22 +47,17 @@ function install_plugin($plugin) {
                $func = $plugin . '_install';
                $func();
 
-               $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
+               $plugin_admin = (function_exists($plugin."_plugin_admin") ? 1 : 0);
 
-               $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
-                       dbesc($plugin),
-                       intval($t),
-                       $plugin_admin
-               );
+               dba::insert('addon', array('name' => $plugin, 'installed' => true,
+                                       'timestamp' => $t, 'plugin_admin' => $plugin_admin));
 
                // we can add the following with the previous SQL
                // once most site tables have been updated.
                // This way the system won't fall over dead during the update.
 
                if (file_exists('addon/' . $plugin . '/.hidden')) {
-                       q("UPDATE `addon` SET `hidden` = 1 WHERE `name` = '%s'",
-                               dbesc($plugin)
-                       );
+                       dba::update('addon', array('hidden' => true), array('name' => $plugin));
                }
                return true;
        }
@@ -87,7 +84,7 @@ function reload_plugins() {
                $parr = explode(',',$plugins);
 
                if (count($parr)) {
-                       foreach($parr as $pl) {
+                       foreach ($parr as $pl) {
 
                                $pl = trim($pl);
 
@@ -95,7 +92,7 @@ function reload_plugins() {
 
                                if (file_exists($fname)) {
                                        $t = @filemtime($fname);
-                                       foreach($installed as $i) {
+                                       foreach ($installed as $i) {
                                                if (($i['name'] == $pl) && ($i['timestamp'] != $t)) {
                                                        logger('Reloading plugin: ' . $i['name']);
                                                        @include_once($fname);
@@ -108,10 +105,7 @@ function reload_plugins() {
                                                                $func = $pl . '_install';
                                                                $func();
                                                        }
-                                                       q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d",
-                                                               intval($t),
-                                                               intval($i['id'])
-                                                       );
+                                                       dba::update('addon', array('timestamp' => $t), array('id' => $i['id']));
                                                }
                                        }
                                }
@@ -128,8 +122,7 @@ function reload_plugins() {
  * @return boolean
  */
 function plugin_enabled($plugin) {
-       $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
-       return ((dbm::is_result($r)) && (count($r) > 0));
+       return dba::exists('addon', array('installed' => true, 'name' => $plugin));
 }
 
 
@@ -153,18 +146,14 @@ function register_hook($hook,$file,$function,$priority=0) {
        if (dbm::is_result($r))
                return true;
 
-       $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
-               dbesc($hook),
-               dbesc($file),
-               dbesc($function),
-               dbesc($priority)
-       );
+       $r = dba::insert('hook', array('hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority));
+
        return $r;
 }}
 
 /**
  * @brief unregisters a hook.
- * 
+ *
  * @param string $hook the name of the hook
  * @param string $file the name of the file that hooks into
  * @param string $function the name of the function that the hook called
@@ -182,20 +171,19 @@ function unregister_hook($hook,$file,$function) {
 }}
 
 
-if (! function_exists('load_hooks')) {
 function load_hooks() {
        $a = get_app();
        $a->hooks = array();
-       $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC, `file`");
+       $r = dba::select('hook', array('hook', 'file', 'function'), array(), array('order' => array('priority' => 'desc', 'file')));
 
-       if (dbm::is_result($r)) {
-               foreach ($r as $rr) {
-                       if (! array_key_exists($rr['hook'],$a->hooks))
-                               $a->hooks[$rr['hook']] = array();
-                       $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
+       while ($rr = dba::fetch($r)) {
+               if (! array_key_exists($rr['hook'],$a->hooks)) {
+                       $a->hooks[$rr['hook']] = array();
                }
+               $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
        }
-}}
+       dba::close($r);
+}
 
 /**
  * @brief Calls a hook.
@@ -249,7 +237,7 @@ function plugin_is_app($name) {
        $a = get_app();
 
        if (is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) {
-               foreach($a->hooks['app_menu'] as $hook) {
+               foreach ($a->hooks['app_menu'] as $hook) {
                        if ($hook[0] == 'addon/'.$name.'/'.$name.'.php')
                                return true;
                }
@@ -297,7 +285,7 @@ function get_plugin_info($plugin){
 
        if ($r){
                $ll = explode("\n", $m[0]);
-               foreach( $ll as $l ) {
+               foreach ( $ll as $l ) {
                        $l = trim($l,"\t\n\r */");
                        if ($l!=""){
                                list($k,$v) = array_map("trim", explode(":",$l,2));
@@ -325,7 +313,7 @@ function get_plugin_info($plugin){
 
 /**
  * @brief Parse theme comment in search of theme infos.
- * 
+ *
  * like
  * \code
  * ..* Name: My Theme
@@ -368,7 +356,7 @@ function get_theme_info($theme){
 
        if ($r){
                $ll = explode("\n", $m[0]);
-               foreach( $ll as $l ) {
+               foreach ( $ll as $l ) {
                        $l = trim($l,"\t\n\r */");
                        if ($l!=""){
                                list($k,$v) = array_map("trim", explode(":",$l,2));
@@ -412,12 +400,12 @@ function get_theme_info($theme){
  */
 function get_theme_screenshot($theme) {
        $exts = array('.png','.jpg');
-       foreach($exts as $ext) {
+       foreach ($exts as $ext) {
                if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
-                       return(App::get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
+                       return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);
                }
        }
-       return(App::get_baseurl() . '/images/blank.png');
+       return(System::baseUrl() . '/images/blank.png');
 }
 
 // install and uninstall theme
@@ -547,22 +535,24 @@ function upgrade_bool_message($bbcode = false) {
 
 /**
  * @brief Get the full path to relevant theme files by filename
- * 
+ *
  * This function search in the theme directory (and if not present in global theme directory)
  * if there is a directory with the file extension and  for a file with the given
- * filename. 
- * 
+ * filename.
+ *
  * @param string $file Filename
  * @param string $root Full root path
  * @return string Path to the file or empty string if the file isn't found
  */
 function theme_include($file, $root = '') {
+       $file = basename($file);
+
        // Make sure $root ends with a slash / if it's not blank
        if ($root !== '' && $root[strlen($root)-1] !== '/') {
                $root = $root . '/';
        }
-       $theme_info = $a->theme_info;
-       if (is_array($theme_info) AND array_key_exists('extends',$theme_info)) {
+       $theme_info = get_app()->theme_info;
+       if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
                $parent = $theme_info['extends'];
        } else {
                $parent = 'NOPATH';
@@ -575,7 +565,7 @@ function theme_include($file, $root = '') {
                "{$root}view/theme/$parent/$ext/$file",
                "{$root}view/$ext/$file",
        );
-       foreach($paths as $p) {
+       foreach ($paths as $p) {
                // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
                if (strpos($p,'NOPATH') !== false) {
                        continue;