aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-07-25 16:00:04 -0700
committerfriendica <info@friendica.com>2013-07-25 16:00:04 -0700
commit3d95fcb7cd37c6bff03f76e20b0d2eeb785616da (patch)
tree823126978a388cc01c033a9a6743df5bdbfef6a8 /include
parente45beccd5b7f5f56f3bda9f09e77e4c0f9669fcd (diff)
downloadvolse-hubzilla-3d95fcb7cd37c6bff03f76e20b0d2eeb785616da.tar.gz
volse-hubzilla-3d95fcb7cd37c6bff03f76e20b0d2eeb785616da.tar.bz2
volse-hubzilla-3d95fcb7cd37c6bff03f76e20b0d2eeb785616da.zip
more work on clone sync
Diffstat (limited to 'include')
-rw-r--r--include/settings.php100
-rw-r--r--include/zot.php101
2 files changed, 101 insertions, 100 deletions
diff --git a/include/settings.php b/include/settings.php
deleted file mode 100644
index f7bb98d93..000000000
--- a/include/settings.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php /** @file */
-
-/**
- * Send a zot packet to all hubs where this channel is duplicated, refreshing
- * such things as personal settings, channel permissions, address book updates, etc.
- */
-
-require_once('include/zot.php');
-
-function build_sync_packet($uid = 0, $packet = null) {
- $a = get_app();
-
- if(! $uid)
- $uid = local_user();
-
- if(! $uid)
- return;
-
- $channel = $a->get_channel();
-
- $h = q("select * from hubloc where hubloc_hash = '%s'",
- dbesc($channel['channel_hash'])
- );
-
- if(! $h)
- return;
-
- $synchubs = array();
-
- foreach($h as $x) {
- if($x['hubloc_host'] == $a->get_hostname())
- continue;
- $synchubs[] = $x;
- }
-
- if(! $synchubs)
- return;
-
- $r = q("select xchan_guid, xchan_guid_sig from xchan where xchan_hash = '%s' limit 1",
- dbesc($channel['channel_hash'])
- );
- if(! $r)
- return;
-
- $env_recips = array();
- $env_recips[] = array('guid' => $r[0]['xchan_guid'],'guid_sig' => $r[0]['xchan_guid_sig']);
-
- $info = (($packet) ? $packet : array());
- $info['type'] = 'channel_sync';
-
- if(array_key_exists($uid,$a->config) && array_key_exists('transient',$a->config[$uid])) {
- $settings = $a->config[$uid]['transient'];
- if($settings) {
- $info['config'] = $settings;
- }
- }
-
- if($channel) {
- $info['channel'] = array();
- foreach($channel as $k => $v) {
- if(strpos('channel_',$k) !== 0)
- continue;
-
- // don't pass these elements, they should not be synchronised
-
- $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey');
-
- if(in_array($k,$disallowed))
- continue;
-
- $info['channel'][$k] = $v;
- }
- }
-
- $interval = ((get_config('system','delivery_interval') !== false)
- ? intval(get_config('system','delivery_interval')) : 2 );
-
-
- foreach($synchubs as $hub) {
- $hash = random_string();
- $n = zot_build_packet($channel,'notify',$env_recips,$hub['hubloc_sitekey'],$hash);
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
- dbesc($hash),
- intval($channel['channel_account']),
- intval($channel['channel_id']),
- dbesc($hub['hubloc_callback']),
- intval(1),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($n),
- dbesc(json_encode($info))
- );
-
- proc_run('php','include/deliver.php',$hash);
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
- }
-
-
-}
diff --git a/include/zot.php b/include/zot.php
index 609107936..277e38c7a 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -1492,3 +1492,104 @@ function import_site($arr,$pubkey) {
+/**
+ * Send a zot packet to all hubs where this channel is duplicated, refreshing
+ * such things as personal settings, channel permissions, address book updates, etc.
+ */
+
+function build_sync_packet($uid = 0, $packet = null) {
+
+ $a = get_app();
+
+ logger('build_sync_packet');
+ if(! $uid)
+ $uid = local_user();
+
+ if(! $uid)
+ return;
+
+ $channel = $a->get_channel();
+
+ $h = q("select * from hubloc where hubloc_hash = '%s'",
+ dbesc($channel['channel_hash'])
+ );
+
+ if(! $h)
+ return;
+
+ $synchubs = array();
+
+ foreach($h as $x) {
+ if($x['hubloc_host'] == $a->get_hostname())
+ continue;
+ $synchubs[] = $x;
+ }
+
+ if(! $synchubs)
+ return;
+
+ $r = q("select xchan_guid, xchan_guid_sig from xchan where xchan_hash = '%s' limit 1",
+ dbesc($channel['channel_hash'])
+ );
+ if(! $r)
+ return;
+
+ $env_recips = array();
+ $env_recips[] = array('guid' => $r[0]['xchan_guid'],'guid_sig' => $r[0]['xchan_guid_sig']);
+
+ $info = (($packet) ? $packet : array());
+ $info['type'] = 'channel_sync';
+
+ if(array_key_exists($uid,$a->config) && array_key_exists('transient',$a->config[$uid])) {
+ $settings = $a->config[$uid]['transient'];
+ if($settings) {
+ $info['config'] = $settings;
+ }
+ }
+
+ if($channel) {
+ $info['channel'] = array();
+ foreach($channel as $k => $v) {
+
+ // filter out any joined tables like xchan
+
+ if(strpos($k,'channel_') !== 0)
+ continue;
+
+ // don't pass these elements, they should not be synchronised
+
+ $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey');
+
+ if(in_array($k,$disallowed))
+ continue;
+
+ $info['channel'][$k] = $v;
+ }
+ }
+
+ $interval = ((get_config('system','delivery_interval') !== false)
+ ? intval(get_config('system','delivery_interval')) : 2 );
+
+
+ foreach($synchubs as $hub) {
+ $hash = random_string();
+ $n = zot_build_packet($channel,'notify',$env_recips,$hub['hubloc_sitekey'],$hash);
+ q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
+ dbesc($hash),
+ intval($channel['channel_account']),
+ intval($channel['channel_id']),
+ dbesc($hub['hubloc_callback']),
+ intval(1),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($n),
+ dbesc(json_encode($info))
+ );
+
+ proc_run('php','include/deliver.php',$hash);
+ if($interval)
+ @time_sleep_until(microtime(true) + (float) $interval);
+ }
+
+
+}