aboutsummaryrefslogtreecommitdiffstats
path: root/include/zot.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/zot.php')
-rw-r--r--include/zot.php140
1 files changed, 95 insertions, 45 deletions
diff --git a/include/zot.php b/include/zot.php
index 9e69aea96..4f42ea2b4 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -314,11 +314,8 @@ function zot_refresh($them,$channel = null, $force = false) {
if(! $x['success'])
return false;
- $xchan_hash = $x['hash'];
-
$their_perms = 0;
-
if($channel) {
$global_perms = get_perms();
if($j['permissions']['data']) {
@@ -355,14 +352,29 @@ function zot_refresh($them,$channel = null, $force = false) {
intval(ABOOK_FLAG_SELF)
);
+ if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) {
+ $next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']);
+ }
+ else {
+ $next_birthday = '0000-00-00 00:00:00';
+ }
+
if($r) {
+ // if the dob is the same as what we have stored (disregarding the year), keep the one
+ // we have as we may have updated the year after sending a notification; and resetting
+ // to the one we just received would cause us to create duplicated events.
+
+ if(substr($r[0]['abook_dob'],5) == substr($next_birthday,5))
+ $next_birthday = $r[0]['abook_dob'];
+
$current_abook_connected = (($r[0]['abook_flags'] & ABOOK_FLAG_UNCONNECTED) ? 0 : 1);
- $y = q("update abook set abook_their_perms = %d
+ $y = q("update abook set abook_their_perms = %d, abook_dob = '%s'
where abook_xchan = '%s' and abook_channel = %d
and not (abook_flags & %d) limit 1",
intval($their_perms),
+ dbesc($next_birthday),
dbesc($x['hash']),
intval($channel['channel_id']),
intval(ABOOK_FLAG_SELF)
@@ -402,7 +414,10 @@ function zot_refresh($them,$channel = null, $force = false) {
if($z)
$default_perms = intval($z[0]['abook_my_perms']);
- $y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_flags ) values ( %d, %d, '%s', %d, %d, '%s', '%s', %d )",
+ // Keep original perms to check if we need to notify them
+ $previous_perms = get_all_perms($channel['channel_id'],$x['hash']);
+
+ $y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_dob, abook_flags ) values ( %d, %d, '%s', %d, %d, '%s', '%s', '%s', %d )",
intval($channel['channel_account_id']),
intval($channel['channel_id']),
dbesc($x['hash']),
@@ -410,13 +425,15 @@ function zot_refresh($them,$channel = null, $force = false) {
intval($default_perms),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
+ dbesc($next_birthday),
intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING)
);
if($y) {
logger("New introduction received for {$channel['channel_name']}");
- if($default_perms) {
- // send back a permissions update for auto-friend/auto-permissions
+ $new_perms = get_all_perms($channel['channel_id'],$x['hash']);
+ if($new_perms != $previous_perms) {
+ // Send back a permissions update if permissions have changed
$z = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) limit 1",
dbesc($x['hash']),
intval($channel['channel_id']),
@@ -429,7 +446,7 @@ function zot_refresh($them,$channel = null, $force = false) {
intval($channel['channel_id']),
dbesc($x['hash'])
);
- if(($new_connection) && (! $default_perms)) {
+ if($new_connection) {
require_once('include/enotify.php');
notification(array(
'type' => NOTIFY_INTRO,
@@ -439,8 +456,11 @@ function zot_refresh($them,$channel = null, $force = false) {
));
}
- if($new_connection && (! ($new_connection[0]['abook_flags'] & ABOOK_FLAG_PENDING)) && ($their_perms & PERMS_R_STREAM))
+ if($new_connection && ($their_perms & PERMS_R_STREAM)) {
+ if(($channel['channel_w_stream'] & PERMS_PENDING)
+ || (! ($new_connection[0]['abook_flags'] & ABOOK_FLAG_PENDING)) )
proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']);
+ }
}
}
@@ -840,6 +860,24 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED) {
intval($r[0]['hubloc_id'])
);
}
+ if($r[0]['hubloc_status'] & HUBLOC_OFFLINE) {
+ q("update hubloc set hubloc_status = (hubloc_status ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_OFFLINE),
+ intval($r[0]['hubloc_id'])
+ );
+ if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) {
+ q("update hubloc set hubloc_flags = (hubloc_flags ^ %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_FLAGS_ORPHANCHECK),
+ intval($r[0]['hubloc_id'])
+ );
+ }
+ q("update xchan set xchan_flags = (xchan_flags ^ %d) where (xchan_flags & %d) and xchan_hash = '%s' limit 1",
+ intval(XCHAN_FLAGS_ORPHAN),
+ intval(XCHAN_FLAGS_ORPHAN),
+ dbesc($xchan_hash)
+ );
+
+ }
// Remove pure duplicates
if(count($r) > 1) {
@@ -1101,7 +1139,7 @@ function zot_import($arr, $sender_url) {
if(array_key_exists('iv',$data)) {
$data = json_decode(crypto_unencapsulate($data,get_config('system','prvkey')),true);
- }
+ }
$incoming = $data['pickup'];
@@ -1113,7 +1151,7 @@ function zot_import($arr, $sender_url) {
if(array_key_exists('iv',$i['notify'])) {
$i['notify'] = json_decode(crypto_unencapsulate($i['notify'],get_config('system','prvkey')),true);
- }
+ }
logger('zot_import: notify: ' . print_r($i['notify'],true), LOGGER_DATA);
@@ -1295,7 +1333,7 @@ function public_recips($msg) {
if(! $r)
$r = array();
- $x = q("select channel_hash as hash from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and not ( channel_pageflags & " . PAGE_REMOVED . " ) and (( " . $col . " & " . PERMS_SPECIFIC . " ) and ( abook_my_perms & " . $field . " )) OR ( " . $col . " & " . PERMS_CONTACTS . " ) ",
+ $x = q("select channel_hash as hash from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and not ( channel_pageflags & " . PAGE_REMOVED . " ) and (( " . $col . " & " . PERMS_SPECIFIC . " ) and ( abook_my_perms & " . $field . " )) OR ( " . $col . " & " . PERMS_PENDING . " ) OR (( " . $col . " & " . PERMS_CONTACTS . " ) and not ( abook_flags & " . ABOOK_FLAG_PENDING . " )) ",
dbesc($msg['notify']['sender']['hash'])
);
@@ -1452,37 +1490,6 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) {
continue;
}
- // for events, extract the event info and create an event linked to an item
-
- if((x($arr,'obj_type')) && (activity_match($arr['obj_type'],ACTIVITY_OBJ_EVENT))) {
- require_once('include/event.php');
- $ev = bbtoevent($arr['body']);
- if(x($ev,'description') && x($ev,'start')) {
- $ev['event_xchan'] = $arr['author_xchan'];
- $ev['uid'] = $channel['channel_id'];
- $ev['account'] = $channel['channel_account_id'];
- $ev['edited'] = $arr['edited'];
- $ev['mid'] = $arr['mid'];
- $ev['private'] = $arr['item_private'];
-
- // is this an edit?
-
- $r = q("SELECT resource_id FROM item where mid = '%s' and uid = %d and resource_type = 'event' limit 1",
- dbesc($arr['mid']),
- intval($channel['channel_id'])
- );
- if($r) {
- $ev['event_hash'] = $r[0]['resource_id'];
- }
-
- $xyz = event_store($ev);
- add_source_route($xyz,$sender['hash']);
-
- $result = array($d['hash'],'event processed',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
- continue;
- }
- }
-
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']),
intval($channel['channel_id'])
@@ -1501,6 +1508,9 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) {
$arr['uid'] = $channel['channel_id'];
$item_result = item_store($arr);
$item_id = $item_result['item_id'];
+ $parr = array('item_id' => $item_id,'item' => $arr,'sender' => $sender,'channel' => $channel);
+ call_hooks('activity_received',$parr);
+
add_source_route($item_id,$sender['hash']);
$result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
@@ -2038,12 +2048,12 @@ function build_sync_packet($uid = 0, $packet = null) {
if(! $uid)
return;
- $r = q("select * from channel where channel_id = %d limit 1",
+ $r = q("select * from channel where channel_id = %d limit 1",
intval($uid)
);
if(! $r)
return;
-
+
$channel = $r[0];
$h = q("select * from hubloc where hubloc_hash = '%s'",
@@ -2248,6 +2258,46 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) {
}
}
}
+
+ if(array_key_exists('profile',$arr) && is_array($arr['profile']) && count($arr['profile'])) {
+
+ $disallowed = array('id','aid','uid');
+
+ foreach($arr['profile'] as $profile) {
+ $x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
+ dbesc($profile['profile_guid']),
+ intval($channel['channel_id'])
+ );
+ if(! $x) {
+ q("insert into profile ( profile_guid, aid, uid ) values ('%s', %d, %d)",
+ dbesc($profile['profile_guid']),
+ intval($channel['channel_account_id']),
+ intval($channel['channel_id'])
+ );
+ $x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
+ dbesc($profile['profile_guid']),
+ intval($channel['channel_id'])
+ );
+ if(! $x)
+ continue;
+ }
+ $clean = array();
+ foreach($profile as $k => $v) {
+ if(in_array($k,$disallowed))
+ continue;
+ $clean[$k] = $v;
+ // TODO - check if these are allowed, otherwise we'll error
+ // We also need to import local photos if a custom photo is selected
+ }
+ if(count($clean)) {
+ foreach($clean as $k => $v) {
+ $r = dbq("UPDATE profile set " . dbesc($k) . " = '" . dbesc($v)
+ . "' where profile_guid = '" . dbesc($profile['profile_guid']) . "' and uid = " . intval($channel['channel_id'])
+ . " limit 1");
+ }
+ }
+ }
+ }
$result[] = array($d['hash'],'channel sync updated',$channel['channel_name'],'');