diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/api.php | 46 | ||||
-rw-r--r-- | include/attach.php | 4 | ||||
-rw-r--r-- | include/bb2diaspora.php | 12 | ||||
-rw-r--r-- | include/deliver.php | 110 | ||||
-rw-r--r-- | include/directory.php | 26 | ||||
-rwxr-xr-x | include/items.php | 10 | ||||
-rw-r--r-- | include/notifier.php | 235 | ||||
-rw-r--r-- | include/photos.php | 49 | ||||
-rw-r--r-- | include/queue.php | 57 | ||||
-rw-r--r-- | include/queue_fn.php | 139 | ||||
-rw-r--r-- | include/ratenotif.php | 20 | ||||
-rw-r--r-- | include/text.php | 24 | ||||
-rw-r--r-- | include/zot.php | 70 |
13 files changed, 354 insertions, 448 deletions
diff --git a/include/api.php b/include/api.php index f37e0669f..5053977c5 100644 --- a/include/api.php +++ b/include/api.php @@ -251,6 +251,7 @@ require_once('include/api_auth.php'); if (count($uinfo)==0) { return False; } + $following = false; if(intval($uinfo[0]['abook_self'])) { $usr = q("select * from channel where channel_id = %d limit 1", @@ -266,18 +267,22 @@ require_once('include/api_auth.php'); $r = q("SELECT COUNT(`id`) as `count` FROM `item` WHERE `uid` = %d AND item_wall = 1 $item_normal - AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", + AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' + AND item_private = 0 ", intval($usr[0]['channel_id']) ); $countitms = $r[0]['count']; + $following = true; } else { $r = q("SELECT COUNT(`id`) as `count` FROM `item` WHERE author_xchan = '%s' - AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", + AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' + AND item_private = 0 ", intval($uinfo[0]['xchan_hash']) ); $countitms = $r[0]['count']; + $following = (($uinfo[0]['abook_myperms'] & PERMS_R_STREAM) ? true : false ); } @@ -313,7 +318,6 @@ require_once('include/api_auth.php'); 'location' => ($usr) ? $usr[0]['channel_location'] : '', 'profile_image_url' => $uinfo[0]['xchan_photo_l'], 'url' => $uinfo[0]['xchan_url'], -//FIXME 'contact_url' => $a->get_baseurl() . "/connections/".$uinfo[0]['abook_id'], 'protected' => false, 'friends_count' => intval($countfriends), @@ -337,7 +341,7 @@ require_once('include/api_auth.php'); 'profile_background_tile' => false, 'profile_use_background_image' => false, 'notifications' => false, - 'following' => '', // #XXX: fix me + 'following' => $following, 'verified' => true // #XXX: fix me ); @@ -417,7 +421,7 @@ require_once('include/api_auth.php'); 'utc_offset' => 0, // #XXX: fix me 'time_zone' => '', //$uinfo[0]['timezone'], 'statuses_count' => 0, - 'following' => 1, + 'following' => false, 'statusnet_blocking' => false, 'notifications' => false, 'uid' => 0, @@ -855,15 +859,29 @@ require_once('include/api_auth.php'); $_REQUEST['type'] = 'wall'; if(x($_FILES,'media')) { - $num_uploads = count($_FILES['media']['name']); - for($x = 0; $x < $num_uploads; $x ++) { - $_FILES['userfile'] = array(); - $_FILES['userfile']['name'] = $_FILES['media']['name'][$x]; - $_FILES['userfile']['type'] = $_FILES['media']['type'][$x]; - $_FILES['userfile']['tmp_name'] = $_FILES['media']['tmp_name'][$x]; - $_FILES['userfile']['error'] = $_FILES['media']['error'][$x]; - $_FILES['userfile']['size'] = $_FILES['media']['size'][$x]; - + if(is_array($_FILES['media']['name'])) { + $num_uploads = count($_FILES['media']['name']); + for($x = 0; $x < $num_uploads; $x ++) { + $_FILES['userfile'] = array(); + $_FILES['userfile']['name'] = $_FILES['media']['name'][$x]; + $_FILES['userfile']['type'] = $_FILES['media']['type'][$x]; + $_FILES['userfile']['tmp_name'] = $_FILES['media']['tmp_name'][$x]; + $_FILES['userfile']['error'] = $_FILES['media']['error'][$x]; + $_FILES['userfile']['size'] = $_FILES['media']['size'][$x]; + + // upload each image if we have any + $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo + require_once('mod/wall_attach.php'); + $a->data['api_info'] = $user_info; + $media = wall_attach_post($a); + + if(strlen($media)>0) + $_REQUEST['body'] .= "\n\n" . $media; + } + } + else { + // AndStatus doesn't present media as an array + $_FILES['userfile'] = $_FILES['media']; // upload each image if we have any $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo require_once('mod/wall_attach.php'); diff --git a/include/attach.php b/include/attach.php index 20e8b7444..8595d5d86 100644 --- a/include/attach.php +++ b/include/attach.php @@ -503,6 +503,10 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { } } + // AndStatus sends jpegs with a non-standard mimetype + if($type === 'image/jpg') + $type = 'image/jpeg'; + $existing_size = 0; if($options === 'replace') { diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 1be7caa19..81b95b30b 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -305,15 +305,6 @@ function bb2diaspora_itembody($item, $force_update = false) { $matches = array(); - //if we have a photo item just prepend the photo bbcode to item['body'] - $is_photo = (($item['obj_type'] == ACTIVITY_OBJ_PHOTO) ? true : false); - if($is_photo) { - $object = json_decode($item['object'],true); - if($object['bbcode']) { - $item['body'] = (($item['body']) ? $object['bbcode'] . "\r\n" . $item['body'] : $object['bbcode']); - } - } - if(($item['diaspora_meta']) && (! $force_update)) { $diaspora_meta = json_decode($item['diaspora_meta'],true); if($diaspora_meta) { @@ -333,6 +324,8 @@ function bb2diaspora_itembody($item, $force_update = false) { } } + create_export_photo_body($item); + $newitem = $item; if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { @@ -346,6 +339,7 @@ function bb2diaspora_itembody($item, $force_update = false) { } } + bb2diaspora_itemwallwall($newitem); $title = $newitem['title']; diff --git a/include/deliver.php b/include/deliver.php index de93e316e..60d935d02 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -2,6 +2,7 @@ require_once('include/cli_startup.php'); require_once('include/zot.php'); +require_once('include/queue_fn.php'); function deliver_run($argv, $argc) { @@ -15,7 +16,6 @@ function deliver_run($argv, $argc) { logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA); - for($x = 1; $x < $argc; $x ++) { $dresult = null; @@ -24,87 +24,6 @@ function deliver_run($argv, $argc) { ); if($r) { - /** - * Check to see if we have any recent communications with this hub (in the last month). - * If not, reduce the outq_priority. - */ - - $base = ''; - - $h = parse_url($r[0]['outq_posturl']); - if($h) { - $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); - if($base !== z_root()) { - $y = q("select site_update, site_dead from site where site_url = '%s' ", - dbesc($base) - ); - if($y) { - if(intval($y[0]['site_dead'])) { - q("delete from outq where outq_posturl = '%s'", - dbesc($r[0]['outq_posturl']) - ); - logger('dead site ignored ' . $base); - continue; - } - if($y[0]['site_update'] < datetime_convert('UTC','UTC','now - 1 month')) { - q("update outq set outq_priority = %d where outq_hash = '%s'", - intval($r[0]['outq_priority'] + 10), - dbesc($r[0]['outq_hash']) - ); - logger('immediate delivery deferred for site ' . $base); - continue; - } - } - else { - - // zot sites should all have a site record, unless they've been dead for as long as - // your site has existed. Since we don't know for sure what these sites are, - // call them unknown - - q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", - dbesc($base), - dbesc(datetime_convert()), - intval(($r[0]['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN) - ); - } - } - } - - // "post" queue driver - used for diaspora and friendica-over-diaspora communications. - - if($r[0]['outq_driver'] === 'post') { - - - $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); - if($result['success'] && $result['return_code'] < 300) { - logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - if($base) { - q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", - dbesc(datetime_convert()), - dbesc($base) - ); - } - q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", - dbesc('accepted for delivery'), - dbesc(datetime_convert()), - dbesc($argv[$x]) - ); - - $y = q("delete from outq where outq_hash = '%s'", - dbesc($argv[$x]) - ); - - } - else { - logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", - dbesc(datetime_convert()), - dbesc($argv[$x]) - ); - } - continue; - } - $notify = json_decode($r[0]['outq_notify'],true); // Messages without an outq_msg will need to go via the web, even if it's a @@ -127,9 +46,9 @@ function deliver_run($argv, $argc) { $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m))))); $dresult = zot_import($msg,z_root()); } - $r = q("delete from outq where outq_hash = '%s'", - dbesc($argv[$x]) - ); + + remove_queue_item($r[0]['outq_hash']); + if($dresult && is_array($dresult)) { foreach($dresult as $xx) { if(is_array($xx) && array_key_exists('message_id',$xx)) { @@ -152,22 +71,11 @@ function deliver_run($argv, $argc) { ); } } - else { - logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - $result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']); - if($result['success']) { - logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']); - zot_process_response($r[0]['outq_posturl'],$result, $r[0]); - } - else { - logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']); - logger('deliver: remote zot delivery fail data: ' . print_r($result,true), LOGGER_DATA); - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", - dbesc(datetime_convert()), - dbesc($argv[$x]) - ); - } - } + + // otherwise it's a remote delivery - call queue_deliver(); + + queue_deliver($r[0],true); + } } } diff --git a/include/directory.php b/include/directory.php index 9ab1d805b..8792a15e1 100644 --- a/include/directory.php +++ b/include/directory.php @@ -8,6 +8,7 @@ require_once('boot.php'); require_once('include/zot.php'); require_once('include/cli_startup.php'); require_once('include/dir_fns.php'); +require_once('include/queue_fn.php'); /** * @brief @@ -83,20 +84,17 @@ function directory_run($argv, $argc){ */ $hash = random_string(); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) - values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($channel['channel_account_id']), - intval($channel['channel_id']), - dbesc('zot'), - dbesc($url), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($packet), - dbesc('') - ); - } else { + + queue_insert(array( + 'hash' => $hash, + 'account_id' => $channel['channel_account_id'], + 'channel_id' => $channel['channel_id'], + 'posturl' => $url, + 'notify' => $packet, + )); + + } + else { q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']) diff --git a/include/items.php b/include/items.php index 8c2e7deb2..44f9633a9 100755 --- a/include/items.php +++ b/include/items.php @@ -3335,7 +3335,6 @@ function start_delivery_chain($channel, $item, $item_id, $parent) { if((! $private) && $new_public_policy) $private = 1; - $item_wall = 1; $item_origin = 1; $item_uplink = 0; @@ -3386,8 +3385,13 @@ function start_delivery_chain($channel, $item, $item_id, $parent) { if($r) proc_run('php','include/notifier.php','tgroup',$item_id); - else + else { logger('start_delivery_chain: failed to update item'); + // reset the source xchan to prevent loops + $r = q("update item set source_xchan = '' where id = %d", + intval($item_id) + ); + } } /** @@ -3950,6 +3954,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { return '<at:deleted-entry ref="' . xmlify($item['mid']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n"; + create_export_photo_body($item); + if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); else diff --git a/include/notifier.php b/include/notifier.php index 66b6160e4..50981df9d 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -44,7 +44,6 @@ require_once('include/html2plain.php'); * expire (in items.php) * like (in like.php, poke.php) * mail (in message.php) - * suggest (in fsuggest.php) * tag (in photos.php, poke.php, tagger.php) * tgroup (in items.php) * wall-new (in photos.php, item.php) @@ -52,6 +51,7 @@ require_once('include/html2plain.php'); * and ITEM_ID is the id of the item in the database that needs to be sent to others. * * ZOT + * permission_create abook_id * permission_update abook_id * refresh_all channel_id * purge_all channel_id @@ -68,6 +68,12 @@ require_once('include/html2plain.php'); require_once('include/cli_startup.php'); require_once('include/zot.php'); require_once('include/queue_fn.php'); +require_once('include/session.php'); +require_once('include/datetime.php'); +require_once('include/items.php'); +require_once('include/bbcode.php'); +require_once('include/identity.php'); +require_once('include/Contact.php'); function notifier_run($argv, $argc){ @@ -75,15 +81,10 @@ function notifier_run($argv, $argc){ $a = get_app(); - require_once("session.php"); - require_once("datetime.php"); - require_once('include/items.php'); - require_once('include/bbcode.php'); if($argc < 3) return; - logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG); $cmd = $argv[1]; @@ -95,7 +96,6 @@ function notifier_run($argv, $argc){ if(! $item_id) return; - require_once('include/identity.php'); $sys = get_sys_channel(); $deliveries = array(); @@ -110,87 +110,8 @@ function notifier_run($argv, $argc){ } - if($cmd == 'permission_update' || $cmd == 'permission_create') { - // Get the recipient - $r = q("select abook.*, hubloc.* from abook - left join hubloc on hubloc_hash = abook_xchan - where abook_id = %d and abook_self = 0 - and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0 limit 1", - intval($item_id), - intval(HUBLOC_FLAGS_DELETED), - intval(HUBLOC_OFFLINE) - ); - - if($r) { - // Get the sender - $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", - intval($r[0]['abook_channel']) - ); - if($s) { - $perm_update = array('sender' => $s[0], 'recipient' => $r[0], 'success' => false, 'deliveries' => ''); - - if($cmd == 'permission_create') - call_hooks('permissions_create',$perm_update); - else - call_hooks('permissions_update',$perm_update); - - if($perm_update['success'] && $perm_update['deliveries']) - $deliveries[] = $perm_update['deliveries']; - - if(! $perm_update['success']) { - // send a refresh message to each hub they have registered here - $h = q("select * from hubloc where hubloc_hash = '%s' - and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", - dbesc($r[0]['hubloc_hash']), - intval(HUBLOC_FLAGS_DELETED), - intval(HUBLOC_OFFLINE) - ); - if($h) { - foreach($h as $hh) { - if(in_array($hh['hubloc_url'],$dead_hubs)) { - logger('skipping dead hub: ' . $hh['hubloc_url'], LOGGER_DEBUG); - continue; - } - - $data = zot_build_packet($s[0],'refresh',array(array( - 'guid' => $hh['hubloc_guid'], - 'guid_sig' => $hh['hubloc_guid_sig'], - 'url' => $hh['hubloc_url']) - )); - if($data) { - $hash = random_string(); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) - values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($s[0]['channel_account_id']), - intval($s[0]['channel_id']), - dbesc('zot'), - dbesc($hh['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($data), - dbesc('') - ); - $deliveries[] = $hash; - } - } - - } - } - - if($deliveries) - do_delivery($deliveries); - } - } - return; - } - - - $expire = false; $request = false; $mail = false; - $fsuggest = false; $top_level = false; $location = false; $recipients = array(); @@ -239,51 +160,42 @@ function notifier_run($argv, $argc){ $packet_type = 'request'; $normal_mode = false; } - elseif($cmd === 'expire') { - - // FIXME - // This will require a special zot packet containing a list of item message_id's to be expired. - // This packet will be public, since we cannot selectively deliver here. - // We need the handling on this end to create the array, and the handling on the remote end - // to verify permissions (for each item) and process it. Until this is complete, the expire feature will be disabled. - - return; - - $normal_mode = false; - $expire = true; - $items = q("SELECT * FROM item WHERE uid = %d AND item_wall = 1 - AND item_deleted = 1 AND `changed` > %s - INTERVAL %s", - intval($item_id), - db_utcnow(), db_quoteinterval('10 MINUTE') + elseif($cmd == 'permission_update' || $cmd == 'permission_create') { + // Get the (single) recipient + $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_self = 0", + intval($item_id) ); - $uid = $item_id; - $item_id = 0; - if(! $items) - return; + if($r) { + $uid = $r[0]['abook_channel']; + // Get the sender + $channel = channelx_by_n($uid); + if($channel) { + $perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => ''); - } - elseif($cmd === 'suggest') { - $normal_mode = false; - $fsuggest = true; + if($cmd == 'permission_create') + call_hooks('permissions_create',$perm_update); + else + call_hooks('permissions_update',$perm_update); - $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1", - intval($item_id) - ); - if(! count($suggest)) - return; - $uid = $suggest[0]['uid']; - $recipients[] = $suggest[0]['cid']; - $item = $suggest[0]; + if($perm_update['success']) { + if($perm_update['deliveries']) { + $deliveries[] = $perm_update['deliveries']; + do_delivery($deliveries); + } + return; + } + else { + $recipients[] = $r[0]['abook_xchan']; + $private = false; + $packet_type = 'refresh'; + } + } + } } elseif($cmd === 'refresh_all') { logger('notifier: refresh_all: ' . $item_id); - $s = q("select * from channel where channel_id = %d limit 1", - intval($item_id) - ); - if($s) - $channel = $s[0]; $uid = $item_id; - $recipients = array(); + $channel = channelx_by_n($item_id); $r = q("select abook_xchan from abook where abook_channel = %d", intval($item_id) ); @@ -466,9 +378,12 @@ function notifier_run($argv, $argc){ // if our parent is a tag_delivery recipient, uplink to the original author causing // a delivery fork. - if(intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) { - logger('notifier: uplinking this item'); - proc_run('php','include/notifier.php','uplink',$item_id); + if(($parent_item) && intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) { + // don't uplink a relayed post to the relay owner + if($parent_item['source_xchan'] !== $parent_item['owner_xchan']) { + logger('notifier: uplinking this item'); + proc_run('php','include/notifier.php','uplink',$item_id); + } } $private = false; @@ -607,10 +522,8 @@ function notifier_run($argv, $argc){ 'relay_to_owner' => $relay_to_owner, 'uplink' => $uplink, 'cmd' => $cmd, - 'expire' => $expire, 'mail' => $mail, 'location' => $location, - 'fsuggest' => $fsuggest, 'request' => $request, 'normal_mode' => $normal_mode, 'packet_type' => $packet_type, @@ -630,52 +543,38 @@ function notifier_run($argv, $argc){ // default: zot protocol - $hash = random_string(); + $packet = null; + if($packet_type === 'refresh' || $packet_type === 'purge') { - $n = zot_build_packet($channel,$packet_type); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($channel['channel_account_id']), - intval($channel['channel_id']), - dbesc('zot'), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc('') - ); + $packet = zot_build_packet($channel,$packet_type); } elseif($packet_type === 'request') { - $n = zot_build_packet($channel,'request',$env_recips,$hub['hubloc_sitekey'],$hash,array('message_id' => $request_message_id)); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($channel['channel_account_id']), - intval($channel['channel_id']), - dbesc('zot'), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc('') + $packet = zot_build_packet($channel,$packet_type,$env_recips,$hub['hubloc_sitekey'],$hash, + array('message_id' => $request_message_id) ); } + + if($packet) { + queue_insert(array( + 'hash' => $hash, + 'account_id' => $channel['channel_account_id'], + 'channel_id' => $channel['channel_id'], + 'posturl' => $hub['hubloc_callback'], + 'notify' => $packet + )); + } else { - $n = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($target_item['aid']), - intval($target_item['uid']), - dbesc('zot'), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc(json_encode($encoded_item)) - ); + $packet = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash); + queue_insert(array( + 'hash' => $hash, + 'account_id' => $target_item['aid'], + 'channel_id' => $target_item['uid'], + 'posturl' => $hub['hubloc_callback'], + 'notify' => $packet, + 'msg' => json_encode($encoded_item) + )); + // only create delivery reports for normal undeleted items if(is_array($target_item) && array_key_exists('postopts',$target_item) && (! $target_item['item_deleted'])) { q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s','%s','%s','%s','%s','%s','%s' ) ", diff --git a/include/photos.php b/include/photos.php index 15aa8ee17..93511d2c0 100644 --- a/include/photos.php +++ b/include/photos.php @@ -292,17 +292,35 @@ function photo_upload($channel, $observer, $args) { $tag = (($r2) ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]'); } - $body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' + $author_link = '[zrl=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $channel['channel_name'] . '[/zrl]'; + + $photo_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . t('a new photo') . '[/zrl]'; + + $album_link = '[zrl=' . z_root() . '/photos/album/' . bin2hex($album) . ']' . $album . '[/zrl]'; + + $activity_format = sprintf(t('%1$s posted %2$s to %3$s','photo_upload'), $author_link, $photo_link, $album_link); + + $summary = $activity_format . "\n\n" . (($args['body']) ? $args['body'] . "\n\n" : ''); + + $obj_body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]' . '[/zrl]'; // Create item object $object = array( - 'type' => ACTIVITY_OBJ_PHOTO, - 'title' => $title, - 'id' => rawurlencode(z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash), - 'link' => $link, - 'bbcode' => $body + 'type' => ACTIVITY_OBJ_PHOTO, + 'title' => $title, + 'created' => $p['created'], + 'edited' => $p['edited'], + 'id' => rawurlencode(z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash), + 'link' => $link, + 'body' => $obj_body + ); + + $target = array( + 'type' => ACTIVITY_OBJ_ALBUM, + 'title' => (($album) ? $album : '/'), + 'id' => rawurlencode(z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album)) ); // Create item container @@ -314,9 +332,12 @@ function photo_upload($channel, $observer, $args) { if($item['mid'] === $item['parent_mid']) { - $item['body'] = (($object) ? $args['body'] : $body . "\r\n" . $args['body']); - $item['obj_type'] = (($object) ? ACTIVITY_OBJ_PHOTO : ''); - $item['object'] = (($object) ? json_encode($object) : ''); + $item['body'] = $args['body']; + $item['obj_type'] = ACTIVITY_OBJ_PHOTO; + $item['object'] = json_encode($object); + + $item['tgt_type'] = ACTIVITY_OBJ_ALBUM; + $item['target'] = json_encode($target); if($item['author_xchan'] === $channel['channel_hash']) { $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey'])); @@ -370,14 +391,16 @@ function photo_upload($channel, $observer, $args) { $arr['deny_cid'] = $ac['deny_cid']; $arr['deny_gid'] = $ac['deny_gid']; $arr['verb'] = ACTIVITY_POST; - $arr['obj_type'] = (($object) ? ACTIVITY_OBJ_PHOTO : ''); - $arr['object'] = (($object) ? json_encode($object) : ''); + $arr['obj_type'] = ACTIVITY_OBJ_PHOTO; + $arr['object'] = json_encode($object); + $arr['tgt_type'] = ACTIVITY_OBJ_ALBUM; + $arr['target'] = json_encode($target); $arr['item_wall'] = 1; $arr['item_origin'] = 1; $arr['item_thread_top'] = 1; $arr['item_private'] = intval($acl->is_private()); $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - $arr['body'] = (($object) ? $args['body'] : $body . "\r\n" . $args['body']); + $arr['body'] = $summary; // this one is tricky because the item and the photo have the same permissions, those of the photo. @@ -402,7 +425,7 @@ function photo_upload($channel, $observer, $args) { $ret['success'] = true; $ret['item'] = $arr; - $ret['body'] = $body; + $ret['body'] = $obj_body; $ret['resource_id'] = $photo_hash; $ret['photoitem_id'] = $item_id; diff --git a/include/queue.php b/include/queue.php index 71ac50c83..8a3b2aa58 100644 --- a/include/queue.php +++ b/include/queue.php @@ -18,11 +18,8 @@ function queue_run($argv, $argc){ else $queue_id = 0; - $deadguys = array(); - logger('queue: start'); - // delete all queue items more than 3 days old // but first mark these sites dead if we haven't heard from them in a month @@ -88,59 +85,7 @@ function queue_run($argv, $argc){ return; foreach($r as $rr) { - - $dresult = null; - - if(in_array($rr['outq_posturl'],$deadguys)) - continue; - - $base = ''; - $h = parse_url($rr['outq_posturl']); - if($h) - $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); - - if($rr['outq_driver'] === 'post') { - $result = z_post_url($rr['outq_posturl'],$rr['outq_msg']); - if($result['success'] && $result['return_code'] < 300) { - logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); - if($base) { - q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", - dbesc(datetime_convert()), - dbesc($base) - ); - } - q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", - dbesc('accepted for delivery'), - dbesc(datetime_convert()), - dbesc($rr['outq_hash']) - ); - $y = q("delete from outq where outq_hash = '%s'", - dbesc($rr['outq_hash']) - ); - } - else { - logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s', outq_priority = outq_priority + 10 where outq_hash = '%s'", - dbesc(datetime_convert()), - dbesc($rr['outq_hash']) - ); - $deadguys[] = $rr['outq_posturl']; - } - continue; - } - $result = zot_zot($rr['outq_posturl'],$rr['outq_notify']); - if($result['success']) { - logger('queue: deliver zot success to ' . $rr['outq_posturl'], LOGGER_DEBUG); - zot_process_response($rr['outq_posturl'],$result, $rr); - } - else { - $deadguys[] = $rr['outq_posturl']; - logger('queue: deliver zot returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s', outq_priority = outq_priority + 10 where outq_hash = '%s'", - dbesc(datetime_convert()), - dbesc($rr['outq_hash']) - ); - } + queue_deliver($rr); } } diff --git a/include/queue_fn.php b/include/queue_fn.php index 22580bc48..1e53d7488 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -1,18 +1,145 @@ <?php /** @file */ -function update_queue_time($id) { - logger('queue: requeue item ' . $id); - q("UPDATE outq SET outq_updated = '%s' WHERE outq_hash = '%s'", +function update_queue_item($id, $add_priority = 0) { + logger('queue: requeue item ' . $id,LOGGER_DEBUG); + q("UPDATE outq SET outq_updated = '%s', outq_priority = outq_priority + %d WHERE outq_hash = '%s'", dbesc(datetime_convert()), + intval($add_priority), dbesc($id) ); } -function remove_queue_item($id) { - logger('queue: remove queue item ' . $id); - q("DELETE FROM outq WHERE hash = '%s'", +function remove_queue_item($id,$channel_id = 0) { + logger('queue: remove queue item ' . $id,LOGGER_DEBUG); + $sql_extra = (($channel_id) ? " and outq_channel = " . intval($channel_id) . " " : ''); + + q("DELETE FROM outq WHERE outq_hash = '%s' $sql_extra", dbesc($id) ); } +function remove_queue_by_posturl($posturl) { + logger('queue: remove queue posturl ' . $posturl,LOGGER_DEBUG); + + q("DELETE FROM outq WHERE outq_posturl = '%s' ", + dbesc($posturl) + ); +} + + + +function queue_set_delivered($id,$channel = 0) { + logger('queue: set delivered ' . $id,LOGGER_DEBUG); + $sql_extra = (($channel_id) ? " and outq_channel = " . intval($channel_id) . " " : ''); + + q("update outq set outq_delivered = 1, outq_updated = '%s' where outq_hash = '%s' $sql_extra ", + dbesc(datetime_convert()), + dbesc($id) + ); +} + + + +function queue_insert($arr) { + + $x = q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority, + outq_created, outq_updated, outq_notify, outq_msg ) + values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' )", + dbesc($arr['hash']), + intval($arr['account_id']), + intval($arr['channel_id']), + dbesc(($arr['driver']) ? $arr['driver'] : 'zot'), + dbesc($arr['posturl']), + intval(1), + intval(($arr['priority']) ? $arr['priority'] : 0), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($arr['notify']), + dbesc(($arr['msg']) ? $arr['msg'] : '') + ); + return $x; + +} + + + +function queue_deliver($outq, $immediate = false) { + + $base = null; + $h = parse_url($outq['outq_posturl']); + if($h) + $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); + + if(($base) && ($base !== z_root()) && ($immediate)) { + $y = q("select site_update, site_dead from site where site_url = '%s' ", + dbesc($base) + ); + if($y) { + if(intval($y[0]['site_dead'])) { + remove_queue_by_posturl($outq['outq_posturl']); + logger('dead site ignored ' . $base); + return; + } + if($y[0]['site_update'] < datetime_convert('UTC','UTC','now - 1 month')) { + update_queue_item($outq['outq_hash'],10); + logger('immediate delivery deferred for site ' . $base); + return; + } + } + else { + // zot sites should all have a site record, unless they've been dead for as long as + // your site has existed. Since we don't know for sure what these sites are, + // call them unknown + + q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", + dbesc($base), + dbesc(datetime_convert()), + intval(($outq['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN) + ); + } + } + + // "post" queue driver - used for diaspora and friendica-over-diaspora communications. + + if($outq['outq_driver'] === 'post') { + $result = z_post_url($outq['outq_posturl'],$outq['outq_msg']); + if($result['success'] && $result['return_code'] < 300) { + logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG); + if($base) { + q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", + dbesc(datetime_convert()), + dbesc($base) + ); + } + q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", + dbesc('accepted for delivery'), + dbesc(datetime_convert()), + dbesc($outq['outq_hash']) + ); + remove_queue_item($outq['outq_hash']); + } + else { + logger('deliver: queue post returned ' . $result['return_code'] + . ' from ' . $outq['outq_posturl'],LOGGER_DEBUG); + update_queue_item($argv[$x]); + } + return; + } + + // normal zot delivery + + logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG); + $result = zot_zot($outq['outq_posturl'],$outq['outq_notify']); + if($result['success']) { + logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']); + zot_process_response($outq['outq_posturl'],$result, $outq); + } + else { + logger('deliver: remote zot delivery failed to ' . $outq['outq_posturl']); + logger('deliver: remote zot delivery fail data: ' . print_r($result,true), LOGGER_DATA); + update_queue_item($outq['outq_hash'],10); + } + return; +} + diff --git a/include/ratenotif.php b/include/ratenotif.php index 63fd7c2ee..e94f30247 100644 --- a/include/ratenotif.php +++ b/include/ratenotif.php @@ -82,18 +82,14 @@ function ratenotif_run($argv, $argc){ $hash = random_string(); $n = zot_build_packet($channel,'notify',null,null,$hash); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($channel['channel_account_id']), - intval($channel['channel_id']), - dbesc('zot'), - dbesc($h . '/post'), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc(json_encode($encoded_item)) - ); + queue_insert(array( + 'hash' => $hash, + 'account_id' => $channel['channel_account_id'], + 'channel_id' => $channel['channel_id'], + 'posturl' => $h . '/post', + 'notify' => $n, + 'msg' => json_encode($encoded_item) + )); $deliver[] = $hash; diff --git a/include/text.php b/include/text.php index 4777e7a61..dd52b16b6 100644 --- a/include/text.php +++ b/include/text.php @@ -1416,20 +1416,14 @@ function format_event($jobject) { function prepare_body(&$item,$attach = false) { require_once('include/identity.php'); -// if($item['html']) { -// $s = bb_observer($item['html']); -// } -// else { - call_hooks('prepare_body_init', $item); -// unobscure($item); - $s = prepare_text($item['body'],$item['mimetype'], false); -// } + call_hooks('prepare_body_init', $item); $photo = ''; - $is_photo = (($item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); + $is_photo = ((($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) ? true : false); if($is_photo) { + $object = json_decode($item['object'],true); // if original photo width is <= 640px prepend it to item body @@ -1444,6 +1438,8 @@ function prepare_body(&$item,$attach = false) { } } + $s = prepare_text($item['body'],$item['mimetype'], false); + $event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event($item['object']) : false); $prep_arr = array( @@ -1602,6 +1598,16 @@ function prepare_text($text, $content_type = 'text/bbcode', $cache = false) { } +function create_export_photo_body(&$item) { + if(($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) { + $j = json_decode($item['object'],true); + if($j) { + $item['body'] .= "\n\n" . (($j['body']) ? $j['body'] : $j['bbcode']); + $item['sig'] = ''; + } + } +} + /** * zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links * These will typically be generated by a bbcode '[zrl]' tag. This is done inside prepare_text() rather than bbcode() diff --git a/include/zot.php b/include/zot.php index 390407e4e..ce3bef783 100644 --- a/include/zot.php +++ b/include/zot.php @@ -12,6 +12,7 @@ require_once('include/crypto.php'); require_once('include/items.php'); require_once('include/hubloc.php'); require_once('include/DReport.php'); +require_once('include/queue_fn.php'); /** @@ -997,6 +998,8 @@ function zot_process_response($hub, $arr, $outq) { } } + // we have a more descriptive delivery report, so discard the per hub 'queued' report. + q("delete from dreport where dreport_queue = '%s' limit 1", dbesc($outq['outq_hash']) ); @@ -1011,18 +1014,8 @@ function zot_process_response($hub, $arr, $outq) { // synchronous message types are handled immediately // async messages remain in the queue until processed. - if (intval($outq['outq_async'])) { - q("update outq set outq_delivered = 1, outq_updated = '%s' where outq_hash = '%s' and outq_channel = %d", - dbesc(datetime_convert()), - dbesc($outq['outq_hash']), - intval($outq['outq_channel']) - ); - } else { - q("delete from outq where outq_hash = '%s' and outq_channel = %d", - dbesc($outq['outq_hash']), - intval($outq['outq_channel']) - ); - } + if(intval($outq['outq_async'])) + queue_set_delivered($outq['outq_hash'],$outq['outq_channel']); logger('zot_process_response: ' . print_r($x,true), LOGGER_DEBUG); } @@ -2974,24 +2967,19 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $interval = ((get_config('system','delivery_interval') !== false) ? intval(get_config('system','delivery_interval')) : 2 ); - logger('build_sync_packet: packet: ' . print_r($info,true), LOGGER_DATA); 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_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($channel['channel_account']), - intval($channel['channel_id']), - dbesc('zot'), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc(json_encode($info)) - ); + queue_insert(array( + 'hash' => $hash, + 'account_id' => $channel['channel_account_id'], + 'channel_id' => $channel['channel_id'], + 'posturl' => $hub['hubloc_callback'], + 'notify' => $n, + 'msg' => json_encode($info) + )); proc_run('php', 'include/deliver.php', $hash); if($interval) @@ -3530,7 +3518,7 @@ function zot_reply_message_request($data) { if ($messages) { $env_recips = null; - $r = q("select * from hubloc where hubloc_hash = '%s' and not hubloc_error and not hubloc_deleted + $r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0 and hubloc_deleted = 0 group by hubloc_sitekey", dbesc($sender_hash) ); @@ -3554,20 +3542,15 @@ function zot_reply_message_request($data) { */ $n = zot_build_packet($c[0],'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash,array('message_id' => $data['message_id'])); - q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, - outq_created, outq_updated, outq_notify, outq_msg ) - values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", - dbesc($hash), - intval($c[0]['channel_account_id']), - intval($c[0]['channel_id']), - dbesc('zot'), - dbesc($hub['hubloc_callback']), - intval(1), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($n), - dbesc($data_packet) - ); + + queue_insert(array( + 'hash' => $hash, + 'account_id' => $c[0]['channel_account_id'], + 'channel_id' => $c[0]['channel_id'], + 'posturl' => $hub['hubloc_callback'], + 'notify' => $n, + 'msg' => $data_packet + )); /* * invoke delivery to send out the notify packet @@ -4162,16 +4145,15 @@ function zot_reply_pickup($data) { if(! $x) continue; - if(array_key_exists('message_list',$x)) { + if(is_array($x) && array_key_exists('message_list',$x)) { foreach($x['message_list'] as $xx) { $ret['pickup'][] = array('notify' => json_decode($rr['outq_notify'],true),'message' => $xx); } } else $ret['pickup'][] = array('notify' => json_decode($rr['outq_notify'],true),'message' => $x); - $x = q("delete from outq where outq_hash = '%s'", - dbesc($rr['outq_hash']) - ); + + remove_queue_item($rr['outq_hash']); } } } |