aboutsummaryrefslogtreecommitdiffstats
path: root/include/hubloc.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-10-13 15:27:03 -0700
committerfriendica <info@friendica.com>2014-10-13 15:27:56 -0700
commit1b0390af0659e0c5534acbee97db1ef3c1e65288 (patch)
tree8b1bab439ad02518c8d3b5a4782ad80c5442cba6 /include/hubloc.php
parenta512d1a4aab35ac874ccbff89d84fdd6d5b3343f (diff)
downloadvolse-hubzilla-1b0390af0659e0c5534acbee97db1ef3c1e65288.tar.gz
volse-hubzilla-1b0390af0659e0c5534acbee97db1ef3c1e65288.tar.bz2
volse-hubzilla-1b0390af0659e0c5534acbee97db1ef3c1e65288.zip
new function hubloc_change_primary()
Diffstat (limited to 'include/hubloc.php')
-rw-r--r--include/hubloc.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/hubloc.php b/include/hubloc.php
index fded434d2..89ec6231d 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -113,4 +113,46 @@ function remove_obsolete_hublocs() {
}
+function hubloc_change_primary($hubloc) {
+
+ if(! is_array($hubloc))
+ return false;
+ if(! $hubloc['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)
+ return false;
+
+ // See if there's a local channel
+
+ $r = q("select channel_id, channel_primary from channel where channel_hash = '%s' limit 1",
+ dbesc($hubloc['hubloc_hash'])
+ );
+ if(($r) && (! $r[0]['channel_primary'])) {
+ q("update channel set channel_primary = 1 where channel_id = %d limit 1",
+ intval($r[0]['channel_id'])
+ );
+ }
+
+ // do we even have an xchan for this hubloc and if so is it already set as primary?
+
+ $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($hubloc['hubloc_hash'])
+ );
+ if(! $r)
+ return false;
+ if($r[0]['xchan_addr'] === $hubloc['hubloc_addr'])
+ return false;
+
+ $url = $hubloc['hubloc_url'];
+ $lwebbie = substr($hubloc['hubloc_addr'],0,strpos($hubloc['hubloc_addr'],'@'));
+
+ $r = q("update xchan set xchan_addr, xchan_url = '%s', xchan_follow = '%s', xchan_connurl = '%s', where xchan_hash = '%s' limit 1",
+ dbesc($hubloc['hubloc_addr']),
+ dbesc($url . '/channel/' . $lwebbie),
+ dbesc($url . '/follow?f=&url=%s'),
+ dbesc($url . '/poco/' . $lwebbie),
+ dbesc($hubloc['hubloc_hash'])
+ );
+
+ return true;
+
+}
\ No newline at end of file