aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Extend/Hook.php8
-rw-r--r--Zotlabs/Lib/Config.php166
-rw-r--r--Zotlabs/Module/Admin.php2
3 files changed, 171 insertions, 5 deletions
diff --git a/Zotlabs/Extend/Hook.php b/Zotlabs/Extend/Hook.php
index 713165faf..fc1e95367 100644
--- a/Zotlabs/Extend/Hook.php
+++ b/Zotlabs/Extend/Hook.php
@@ -10,7 +10,7 @@ class Hook {
$function = serialize($function);
}
- $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' and priority = %d and hook_version = %d LIMIT 1",
+ $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `fn` = '%s' and priority = %d and hook_version = %d LIMIT 1",
dbesc($hook),
dbesc($file),
dbesc($function),
@@ -23,13 +23,13 @@ class Hook {
// To aid in upgrade and transition, remove old settings for any registered hooks that match in all respects except
// for priority or hook_version
- $r = q("DELETE FROM `hook` where `hook` = '%s' and `file` = '%s' and `function` = '%s'",
+ $r = q("DELETE FROM `hook` where `hook` = '%s' and `file` = '%s' and `fn` = '%s'",
dbesc($hook),
dbesc($file),
dbesc($function)
);
- $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`, `hook_version`) VALUES ( '%s', '%s', '%s', %d, %d )",
+ $r = q("INSERT INTO `hook` (`hook`, `file`, `fn`, `priority`, `hook_version`) VALUES ( '%s', '%s', '%s', %d, %d )",
dbesc($hook),
dbesc($file),
dbesc($function),
@@ -44,7 +44,7 @@ class Hook {
if(is_array($function)) {
$function = serialize($function);
}
- $r = q("DELETE FROM hook WHERE hook = '%s' AND `file` = '%s' AND `function` = '%s' and priority = %d and hook_version = %d",
+ $r = q("DELETE FROM hook WHERE hook = '%s' AND `file` = '%s' AND `fn` = '%s' and priority = %d and hook_version = %d",
dbesc($hook),
dbesc($file),
dbesc($function),
diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php
new file mode 100644
index 000000000..d4ee1aeda
--- /dev/null
+++ b/Zotlabs/Lib/Config.php
@@ -0,0 +1,166 @@
+<?php /** @file */
+
+namespace Zotlabs\Lib;
+
+
+class Config {
+
+ /**
+ * @brief Loads the hub's configuration from database to a cached storage.
+ *
+ * Retrieve a category ($family) of config variables from database to a cached
+ * storage in the global App::$config[$family].
+ *
+ * @param string $family
+ * The category of the configuration value
+ */
+
+ static public function Load($family) {
+ if(! array_key_exists($family, \App::$config))
+ \App::$config[$family] = array();
+
+ if(! array_key_exists('config_loaded', \App::$config[$family])) {
+ $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
+ if($r !== false) {
+ if($r) {
+ foreach($r as $rr) {
+ $k = $rr['k'];
+ \App::$config[$family][$k] = $rr['v'];
+ }
+ }
+ \App::$config[$family]['config_loaded'] = true;
+ }
+ }
+ }
+
+ /**
+ * @brief Sets a configuration value for the hub.
+ *
+ * Stores a config value ($value) in the category ($family) under the key ($key).
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to set
+ * @param mixed $value
+ * The value to store in the configuration
+ * @return mixed
+ * Return the set value, or false if the database update failed
+ */
+
+ static public function Set($family,$key,$value) {
+ // manage array value
+ $dbvalue = ((is_array($value)) ? serialize($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+
+ if(get_config($family, $key) === false || (! self::get_from_storage($family, $key))) {
+ $ret = q("INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ if($ret) {
+ \App::$config[$family][$key] = $value;
+ $ret = $value;
+ }
+ return $ret;
+ }
+
+ $ret = q("UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
+ dbesc($dbvalue),
+ dbesc($family),
+ dbesc($key)
+ );
+
+ if($ret) {
+ \App::$config[$family][$key] = $value;
+ $ret = $value;
+ }
+ return $ret;
+
+ }
+
+ /**
+ * @brief Get a particular config variable given the category name ($family)
+ * and a key.
+ *
+ * Get a particular config variable from the given category ($family) and the
+ * $key from a cached storage in App::$config[$family]. If a key is found in the
+ * DB but does not exist in local config cache, pull it into the cache so we
+ * do not have to hit the DB again for this item.
+ *
+ * Returns false if not set.
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @return mixed Return value or false on error or if not set
+ */
+
+ static public function Get($family,$key) {
+ if((! array_key_exists($family, \App::$config)) || (! array_key_exists('config_loaded', \App::$config[$family])))
+ self::Load($family);
+
+ if(array_key_exists('config_loaded', \App::$config[$family])) {
+ if(! array_key_exists($key, \App::$config[$family])) {
+ return false;
+ }
+ return ((! is_array(\App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$family][$key]))
+ ? unserialize(\App::$config[$family][$key])
+ : \App::$config[$family][$key]
+ );
+ }
+
+ return false;
+ }
+
+ /**
+ * @brief Deletes the given key from the hub's configuration database.
+ *
+ * Removes the configured value from the stored cache in App::$config[$family]
+ * and removes it from the database.
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to delete
+ * @return mixed
+ */
+
+ static public function Delete($family,$key) {
+
+ $ret = false;
+
+ if(array_key_exists($family, \App::$config) && array_key_exists($key, \App::$config[$family]))
+ unset(\App::$config[$family][$key]);
+ $ret = q("DELETE FROM config WHERE cat = '%s' AND k = '%s'",
+ dbesc($family),
+ dbesc($key)
+ );
+ return $ret;
+ }
+
+
+ /**
+ * @brief Returns a value directly from the database configuration storage.
+ *
+ * This function queries directly the database and bypasses the chached storage
+ * from get_config($family, $key).
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @return mixed
+ */
+
+ static private function get_from_storage($family,$key) {
+ $ret = q("SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
+ dbesc($family),
+ dbesc($key)
+ );
+ return $ret;
+ }
+
+}
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index 8f15035d1..4cabd78ca 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -1291,7 +1291,7 @@ class Admin extends \Zotlabs\Web\Controller {
$admin_form = '';
- $r = q("select * from addon where plugin_admin = 1 and name = '%s' limit 1",
+ $r = q("select * from addon where plugin_admin = 1 and aname = '%s' limit 1",
dbesc($plugin)
);