aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-06-02 22:32:50 -0400
committerAndrew Manning <tamanning@zoho.com>2016-06-02 22:32:50 -0400
commitb93e398674b375a3b14718fc6dd2a815aad9b387 (patch)
tree7c2a8097e1c90a87cc8207b5fe08a064f4fa3ae8 /Zotlabs/Lib
parentb70c6809648bb3c78e5e26f9293727b3a7aa4025 (diff)
parentf9075e2a2feca0f37fdf568be6e6e53460aa9034 (diff)
downloadvolse-hubzilla-b93e398674b375a3b14718fc6dd2a815aad9b387.tar.gz
volse-hubzilla-b93e398674b375a3b14718fc6dd2a815aad9b387.tar.bz2
volse-hubzilla-b93e398674b375a3b14718fc6dd2a815aad9b387.zip
Merge remote-tracking branch 'upstream/dev' into wiki
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Apps.php60
-rw-r--r--Zotlabs/Lib/Config.php166
-rw-r--r--Zotlabs/Lib/Enotify.php16
3 files changed, 227 insertions, 15 deletions
diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php
index 07a50766e..ed06943a1 100644
--- a/Zotlabs/Lib/Apps.php
+++ b/Zotlabs/Lib/Apps.php
@@ -13,6 +13,8 @@ require_once('include/channel.php');
class Apps {
+ static public $installed_system_apps = null;
+
static public function get_system_apps($translate = true) {
$ret = array();
@@ -49,22 +51,62 @@ class Apps {
static public function import_system_apps() {
if(! local_channel())
return;
+ $apps = self::get_system_apps(false);
- // Eventually we want to look at modification dates and update system apps.
- $installed = get_pconfig(local_channel(),'system','apps_installed');
- if($installed)
- return;
- $apps = self::get_system_apps(false);
+ self::$installed_system_apps = q("select * from app where app_system = 1 and app_channel = %d",
+ intval(local_channel())
+ );
+
if($apps) {
foreach($apps as $app) {
+ $id = self::check_install_system_app($app);
+ // $id will be boolean true or false to install an app, or an integer id to update an existing app
+ if($id === false)
+ continue;
+ if($id !== true) {
+ // if we already installed this app, but it changed, preserve any categories we created
+ $s = '';
+ $r = q("select * from term where otype = %d and oid = d",
+ intval(TERM_OBJ_APP),
+ intval($id)
+ );
+ if($r) {
+ foreach($r as $t) {
+ if($s)
+ $s .= ',';
+ $s .= $t['term'];
+ }
+ $app['categories'] = $s;
+ }
+ }
$app['uid'] = local_channel();
$app['guid'] = hash('whirlpool',$app['name']);
$app['system'] = 1;
- self::app_install(local_channel(),$app);
+ self::app_install(local_channel(),$app);
}
}
- set_pconfig(local_channel(),'system','apps_installed',1);
+ }
+
+ /**
+ * Install the system app if no system apps have been installed, or if a new system app
+ * is discovered, or if the version of a system app changes.
+ */
+
+ static public function check_install_system_app($app) {
+ if((! is_array(self::$installed_system_apps)) || (! count(self::$installed_system_apps))) {
+ return true;
+ }
+ $notfound = true;
+ foreach(self::$installed_system_apps as $iapp) {
+ if($iapp['app_id'] == hash('whirlpool',$app['name'])) {
+ $notfound = false;
+ if($iapp['app_version'] != $app['version']) {
+ return intval($iapp['app_id']);
+ }
+ }
+ }
+ return $notfound;
}
@@ -111,6 +153,10 @@ class Apps {
if(array_key_exists('target',$ret))
$ret['target'] = str_replace(array('\'','"'),array('&#39;','&dquot;'),$ret['target']);
+ if(array_key_exists('version',$ret))
+ $ret['version'] = str_replace(array('\'','"'),array('&#39;','&dquot;'),$ret['version']);
+
+
if(array_key_exists('requires',$ret)) {
$requires = explode(',',$ret['requires']);
foreach($requires as $require) {
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/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php
index ccb538ef5..56c717468 100644
--- a/Zotlabs/Lib/Enotify.php
+++ b/Zotlabs/Lib/Enotify.php
@@ -348,7 +348,7 @@ class Enotify {
$hash = random_string();
$r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
dbesc($hash));
- if (count($r))
+ if ($r)
$dups = true;
} while ($dups === true);
@@ -356,16 +356,16 @@ class Enotify {
$datarray = array();
$datarray['hash'] = $hash;
$datarray['sender_hash'] = $sender['xchan_hash'];
- $datarray['name'] = $sender['xchan_name'];
+ $datarray['xname'] = $sender['xchan_name'];
$datarray['url'] = $sender['xchan_url'];
$datarray['photo'] = $sender['xchan_photo_s'];
- $datarray['date'] = datetime_convert();
+ $datarray['created'] = datetime_convert();
$datarray['aid'] = $recip['channel_account_id'];
$datarray['uid'] = $recip['channel_id'];
$datarray['link'] = $itemlink;
$datarray['parent'] = $parent_mid;
$datarray['parent_item'] = $parent_item;
- $datarray['type'] = $params['type'];
+ $datarray['ntype'] = $params['type'];
$datarray['verb'] = $params['verb'];
$datarray['otype'] = $params['otype'];
$datarray['abort'] = false;
@@ -394,19 +394,19 @@ class Enotify {
}
}
- $r = q("insert into notify (hash,name,url,photo,date,aid,uid,link,parent,seen,type,verb,otype)
+ $r = q("insert into notify (hash,xname,url,photo,created,aid,uid,link,parent,seen,ntype,verb,otype)
values('%s','%s','%s','%s','%s',%d,%d,'%s','%s',%d,%d,'%s','%s')",
dbesc($datarray['hash']),
- dbesc($datarray['name']),
+ dbesc($datarray['xname']),
dbesc($datarray['url']),
dbesc($datarray['photo']),
- dbesc($datarray['date']),
+ dbesc($datarray['created']),
intval($datarray['aid']),
intval($datarray['uid']),
dbesc($datarray['link']),
dbesc($datarray['parent']),
intval($seen),
- intval($datarray['type']),
+ intval($datarray['ntype']),
dbesc($datarray['verb']),
dbesc($datarray['otype'])
);