aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-09-06 12:22:41 +0200
committerMario Vavti <mario@mariovavti.com>2018-09-06 12:22:41 +0200
commitf3ce5e73feec540b550b3c99b96e3f48ae569e0a (patch)
treef8fef3725491597bdd163a2531c4ec45bfed707d
parentc53d3a4b3aec46921ce3b903aa5b0cce6b169c68 (diff)
parentc5bc4fe24519079664b8f63a5e9082f0a7ffc945 (diff)
downloadvolse-hubzilla-f3ce5e73feec540b550b3c99b96e3f48ae569e0a.tar.gz
volse-hubzilla-f3ce5e73feec540b550b3c99b96e3f48ae569e0a.tar.bz2
volse-hubzilla-f3ce5e73feec540b550b3c99b96e3f48ae569e0a.zip
Merge remote-tracking branch 'mike/master' into dev
-rwxr-xr-xinclude/plugin.php56
1 files changed, 40 insertions, 16 deletions
diff --git a/include/plugin.php b/include/plugin.php
index ea3c67c2f..9757be356 100755
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -109,11 +109,16 @@ function install_plugin($plugin) {
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
- q("INSERT INTO addon (aname, installed, tstamp, plugin_admin) VALUES ( '%s', 1, %d , %d ) ",
- dbesc($plugin),
- intval($t),
- $plugin_admin
+ $d = q("select * from addon where aname = '%s' limit 1",
+ dbesc($plugin)
);
+ if(! $d) {
+ q("INSERT INTO addon (aname, installed, tstamp, plugin_admin) VALUES ( '%s', 1, %d , %d ) ",
+ dbesc($plugin),
+ intval($t),
+ $plugin_admin
+ );
+ }
load_plugin($plugin);
}
@@ -366,28 +371,47 @@ function unregister_hook($hook, $file, $function) {
return $r;
}
-
-//
-// It might not be obvious but themes can manually add hooks to the App::$hooks
-// array in their theme_init() and use this to customise the app behaviour.
-// UPDATE: use insert_hook($hookname,$function_name) to do this
-//
+/**
+ * @brief loads all active hooks into memory
+ * alters: App::$hooks
+ * Called during initialisation
+ * Duplicated hooks are removed and the duplicates ignored
+ *
+ * It might not be obvious but themes can manually add hooks to the App::$hooks
+ * array in their theme_init() and use this to customise the app behaviour.
+ * use insert_hook($hookname,$function_name) to do this.
+ */
function load_hooks() {
- App::$hooks = array();
+ App::$hooks = [];
$r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC");
if($r) {
- foreach($r as $rr) {
- if(! array_key_exists($rr['hook'],App::$hooks))
- App::$hooks[$rr['hook']] = array();
- App::$hooks[$rr['hook']][] = array($rr['file'],$rr['fn'],$rr['priority'],$rr['hook_version']);
+ foreach($r as $rv) {
+ $duplicated = false;
+ if(! array_key_exists($rv['hook'],App::$hooks)) {
+ App::$hooks[$rv['hook']] = [];
+ }
+ else {
+ foreach(App::$hooks[$rv['hook']] as $h) {
+ if($h[0] === $rv['file'] && $h[1] === $rv['fn']) {
+ $duplicated = true;
+ q("delete from hook where id = %d",
+ intval($rv['id'])
+ );
+ logger('duplicate hook ' . $h[1] . ' removed');
+ }
+ }
+ }
+ if(! $duplicated) {
+ App::$hooks[$rv['hook']][] = [ $rv['file'], $rv['fn'], $rv['priority'], $rv['hook_version']];
+ }
}
}
- //logger('hooks: ' . print_r(App::$hooks,true));
+ // logger('hooks: ' . print_r(App::$hooks,true));
}
/**