From beaca70126d45b472c3d610081d66584f2feca43 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 12 Jan 2015 00:14:51 +0100 Subject: [PATCH 1/2] OStatus: Replies now arrive their target. --- boot.php | 2 +- include/bbcode.php | 2 +- include/notifier.php | 127 +++++++++++++++++-------------- include/ostatus_conversation.php | 40 +++++----- mod/item.php | 25 +++++- 5 files changed, 114 insertions(+), 82 deletions(-) diff --git a/boot.php b/boot.php index a8a6bf40c..72cb8a341 100644 --- a/boot.php +++ b/boot.php @@ -2074,7 +2074,7 @@ if(! function_exists('load_contact_links')) { if(! $uid || x($a->contacts,'empty')) return; - $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ", + $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `thumb` != ''", intval($uid) ); if(count($r)) { diff --git a/include/bbcode.php b/include/bbcode.php index 1f635e051..639d90cf4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -697,7 +697,7 @@ function bb_RemovePictureLinks($match) { } function bb_expand_links($match) { - if (stristr($match[2], $match[3]) OR ($match[2] == $match[3])) + if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3])) return ($match[1]."[url]".$match[2]."[/url]"); else return ($match[1].$match[3]." [url]".$match[2]."[/url]"); diff --git a/include/notifier.php b/include/notifier.php index 79de67470..cfd85593f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -90,7 +90,7 @@ function notifier_run(&$argv, &$argc){ $expire = false; $mail = false; $fsuggest = false; - $relocate = false; + $relocate = false; $top_level = false; $recipients = array(); $url_recipients = array(); @@ -110,11 +110,10 @@ function notifier_run(&$argv, &$argc){ $recipients[] = $message[0]['contact-id']; $item = $message[0]; - } - elseif($cmd === 'expire') { + } elseif($cmd === 'expire') { $normal_mode = false; $expire = true; - $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 + $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE", intval($item_id) ); @@ -122,8 +121,7 @@ function notifier_run(&$argv, &$argc){ $item_id = 0; if(! count($items)) return; - } - elseif($cmd === 'suggest') { + } elseif($cmd === 'suggest') { $normal_mode = false; $fsuggest = true; @@ -135,8 +133,7 @@ function notifier_run(&$argv, &$argc){ $uid = $suggest[0]['uid']; $recipients[] = $suggest[0]['cid']; $item = $suggest[0]; - } - elseif($cmd === 'removeme') { + } elseif($cmd === 'removeme') { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id)); if (! $r) return; @@ -156,13 +153,11 @@ function notifier_run(&$argv, &$argc){ terminate_friendship($user, $self, $contact); } return; - } - elseif($cmd === 'relocate') { - $normal_mode = false; + } elseif($cmd === 'relocate') { + $normal_mode = false; $relocate = true; - $uid = $item_id; - } - else { + $uid = $item_id; + } else { // find ancestors $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1", intval($item_id) @@ -181,7 +176,7 @@ function notifier_run(&$argv, &$argc){ if(! $parent_id) return; - $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` + $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC", intval($parent_id) ); @@ -204,10 +199,10 @@ function notifier_run(&$argv, &$argc){ } - $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, + $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, + `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`, `user`.`prvnets` - FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` + FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); @@ -306,9 +301,9 @@ function notifier_run(&$argv, &$argc){ return; } - if((strlen($parent['allow_cid'])) - || (strlen($parent['allow_gid'])) - || (strlen($parent['deny_cid'])) + if((strlen($parent['allow_cid'])) + || (strlen($parent['allow_gid'])) + || (strlen($parent['deny_cid'])) || (strlen($parent['deny_gid']))) { $public_message = false; // private recipients, not public } @@ -410,8 +405,7 @@ function notifier_run(&$argv, &$argc){ '$content' => xmlify($body), '$parent_id' => xmlify($item['parent-uri']) )); - } - elseif($fsuggest) { + } elseif($fsuggest) { $public_message = false; // suggestions are not public $sugg_template = get_markup_template('atom_suggest.tpl'); @@ -430,9 +424,8 @@ function notifier_run(&$argv, &$argc){ intval($item['id']) ); - } - elseif($relocate) { - $public_message = false; // suggestions are not public + } elseif($relocate) { + $public_message = false; // suggestions are not public $sugg_template = get_markup_template('atom_relocate.tpl'); @@ -444,8 +437,8 @@ function notifier_run(&$argv, &$argc){ set_config('system','site_pubkey', $res['pubkey']); } - $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` - WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid); + $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` + WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid); $photos = array(); $ext = Photo::supportedTypes(); foreach($rp as $p){ @@ -453,24 +446,23 @@ function notifier_run(&$argv, &$argc){ } unset($rp, $ext); - $atom .= replace_macros($sugg_template, array( - '$name' => xmlify($owner['name']), - '$photo' => xmlify($photos[4]), - '$thumb' => xmlify($photos[5]), - '$micro' => xmlify($photos[6]), - '$url' => xmlify($owner['url']), - '$request' => xmlify($owner['request']), - '$confirm' => xmlify($owner['confirm']), - '$notify' => xmlify($owner['notify']), - '$poll' => xmlify($owner['poll']), - '$sitepubkey' => xmlify(get_config('system','site_pubkey')), - //'$pubkey' => xmlify($owner['pubkey']), - //'$prvkey' => xmlify($owner['prvkey']), - )); - $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN); + $atom .= replace_macros($sugg_template, array( + '$name' => xmlify($owner['name']), + '$photo' => xmlify($photos[4]), + '$thumb' => xmlify($photos[5]), + '$micro' => xmlify($photos[6]), + '$url' => xmlify($owner['url']), + '$request' => xmlify($owner['request']), + '$confirm' => xmlify($owner['confirm']), + '$notify' => xmlify($owner['notify']), + '$poll' => xmlify($owner['poll']), + '$sitepubkey' => xmlify(get_config('system','site_pubkey')), + //'$pubkey' => xmlify($owner['pubkey']), + //'$prvkey' => xmlify($owner['prvkey']), + )); + $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN); unset($photos); - } - else { + } else { if($followup) { foreach($items as $item) { // there is only one item if(! $item['parent']) @@ -481,8 +473,7 @@ function notifier_run(&$argv, &$argc){ $atom .= atom_entry($item,'text',null,$owner,false); } } - } - else { + } else { foreach($items as $item) { if(! $item['parent']) @@ -510,7 +501,7 @@ function notifier_run(&$argv, &$argc){ else $atom .= atom_entry($item,'text',null,$owner,true); - if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) + if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) $slaps[] = atom_entry($item,'html',null,$owner,true); } } @@ -545,12 +536,12 @@ function notifier_run(&$argv, &$argc){ else $recip_str = implode(', ', $recipients); - if ($relocate) - $r = $recipients_relocate; - else - $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ", - dbesc($recip_str) - ); + if ($relocate) + $r = $recipients_relocate; + else + $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ", + dbesc($recip_str) + ); require_once('include/salmon.php'); @@ -700,13 +691,33 @@ function notifier_run(&$argv, &$argc){ if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only')) break; - if($followup && $contact['notify']) { - logger('notifier: slapdelivery: ' . $contact['name']); - $deliver_status = slapper($owner,$contact['notify'],$slap); + $ostatus_contact = $contact; + + // If the contact doesn't fit with the contact, then fetch the correct contact + // This is more a test than a good solution. The whole OStatus stuff needs a rework. + if ($followup) { + $thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"])); + if (count($thrparent) AND (normalise_link($contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { + require_once("include/Scrape.php"); + $probed_contact = probe_url($thrparent[0]["author-link"]); + if ($probed_contact["network"] != NETWORK_FEED) { + $ostatus_contact = $probed_contact; + $ostatus_contact["nurl"] = normalise_link($probed_contact["url"]); + $ostatus_contact["thumb"] = $probed_contact["photo"]; + $ostatus_contact["micro"] = $probed_contact["photo"]; + } + logger('scrape data for slapper: '.print_r($ostatus_contact, true)); + } + } + + if($followup && $ostatus_contact['notify']) { + + logger('notifier: slapdelivery: ' . $ostatus_contact['name']); + $deliver_status = slapper($owner,$ostatus_contact['notify'],$slap); if($deliver_status == (-1)) { // queue message for redelivery - add_to_queue($contact['id'],NETWORK_OSTATUS,$slap); + add_to_queue($ostatus_contact['id'],NETWORK_OSTATUS,$slap); } } else { diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index 2fa7d7a54..403f95f4b 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -20,12 +20,12 @@ function check_conversations() { if($last) { $next = $last + ($poll_interval * 60); if($next > time()) { - logger('complete_conversation: poll interval not reached'); + logger('poll interval not reached'); return; } } - logger('complete_conversation: cron_start'); + logger('cron_start'); $start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60)); $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", @@ -36,7 +36,7 @@ function check_conversations() { complete_conversation($id, $url); } - logger('complete_conversation: cron_end'); + logger(' cron_end'); set_config('system','ostatus_last_poll', time()); } @@ -52,8 +52,6 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $a->last_ostatus_conversation_url = $conversation_url; - //logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid); - $messages = q("SELECT `uid`, `parent`, `created` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) return; @@ -90,8 +88,6 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio do { $conv_as = fetch_url($conv."?page=".$pageno); - //$conv_as = fetch_url($conv."?page=".$pageno, false, 0, 10); - //$conv_as = file_get_contents($conv."?page=".$pageno); $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); @@ -110,7 +106,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $items = array_reverse($items); foreach ($items as $single_conv) { - // identi.ca just changed the format of the activity streams. This is a quick fix. + // status.net changed the format of the activity streams. This is a quick fix. if (@is_string($single_conv->object->id)) $single_conv->id = $single_conv->object->id; @@ -127,7 +123,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio intval($message["uid"]), dbesc($first_id)); if ($new_parents) { $parent = $new_parents[0]; - logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid); + logger('adopting new parent '.$parent["id"].' for '.$itemid); } else { $parent["id"] = 0; $parent["uri"] = $first_id; @@ -144,6 +140,8 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio if ($message_exists) { if ($parent["id"] != 0) { $existing_message = $message_exists[0]; + + // This is partly bad, since the entry in the thread table isn't updated $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d", intval($parent["id"]), dbesc($parent["uri"]), @@ -153,12 +151,23 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio continue; } + $contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", + $message["uid"], normalise_link($single_conv->actor->id), NETWORK_STATUSNET); + + if (count($contact)) { + logger("Found contact for url ".$single_conv->actor->id, LOGGER_DEBUG); + $contact_id = $contact[0]["id"]; + } else { + logger("No contact found for url ".$single_conv->actor->id, LOGGER_DEBUG); + $contact_id = $parent["contact-id"]; + } + $arr = array(); $arr["network"] = NETWORK_OSTATUS; $arr["uri"] = $single_conv->id; $arr["plink"] = $single_conv->id; $arr["uid"] = $message["uid"]; - $arr["contact-id"] = $parent["contact-id"]; // To-Do + $arr["contact-id"] = $contact_id; if ($parent["id"] != 0) $arr["parent"] = $parent["id"]; $arr["parent-uri"] = $parent["uri"]; @@ -201,20 +210,13 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio // If the newly created item is the top item then change the parent settings of the thread if ($newitem AND ($arr["uri"] == $first_id)) { - logger('complete_conversation: setting new parent to id '.$newitem); + logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($message["uid"]), intval($newitem)); if ($new_parents) { $parent = $new_parents[0]; - logger('complete_conversation: done changing parents to parent '.$newitem); + logger('done changing parents to parent '.$newitem); } - - /*logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]); - $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d", - intval($newitem), - dbesc($arr["uri"]), - intval($parent["id"])); - logger('complete_conversation: done changing parents to parent '.$newitem.' '.print_r($r, true));*/ } } } diff --git a/mod/item.php b/mod/item.php index 0f4e3db0c..a66535d7d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -90,14 +90,14 @@ function item_post(&$a) { $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($parent) ); - } - elseif($parent_uri && local_user()) { + } elseif($parent_uri && local_user()) { // This is coming from an API source, and we are logged in $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent_uri), intval(local_user()) ); } + // if this isn't the real parent of the conversation, find it if($r !== false && count($r)) { $parid = $r[0]['parent']; @@ -127,8 +127,27 @@ function item_post(&$a) { intval($parent_item['contact-id']), intval($uid) ); - if(count($r)) + if(count($r)) { $parent_contact = $r[0]; + + // If the contact id doesn't fit with the contact, then set the contact to null + $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); + if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS) + AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { + $parent_contact = null; + + require_once("include/Scrape.php"); + $probed_contact = probe_url($thrparent[0]["author-link"]); + if ($probed_contact["network"] != NETWORK_FEED) { + $parent_contact = $probed_contact; + $parent_contact["nurl"] = normalise_link($probed_contact["url"]); + $parent_contact["thumb"] = $probed_contact["photo"]; + $parent_contact["micro"] = $probed_contact["photo"]; + } + logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG); + } else + logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG); + } } } From 184dcf75a75f50f02dd9efa1267ee446b4708a80 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 20 Jan 2015 22:54:25 +0100 Subject: [PATCH 2/2] Caching for scrape, keywords for remote_self, notifications for addresses that aren't in your contact list. --- include/Scrape.php | 11 +++++ include/follow.php | 23 +++++---- include/html2bbcode.php | 3 +- include/items.php | 43 ++++++++++++++-- include/notifier.php | 107 ++++++++++++++++++++-------------------- mod/contacts.php | 14 +++--- mod/salmon.php | 14 ++---- 7 files changed, 130 insertions(+), 85 deletions(-) diff --git a/include/Scrape.php b/include/Scrape.php index 629f7a063..fa2d7944a 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -343,6 +343,12 @@ function probe_url($url, $mode = PROBE_NORMAL) { if(! $url) return $result; + $result = Cache::get("probe_url:".$mode.":".$url); + if (!is_null($result)) { + $result = unserialize($result); + return $result; + } + $network = null; $diaspora = false; $diaspora_base = ''; @@ -401,6 +407,9 @@ function probe_url($url, $mode = PROBE_NORMAL) { $pubkey = $diaspora_key; $diaspora = true; } + if($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe') { + $diaspora = false; + } } // Status.Net can have more than one profile URL. We need to match the profile URL @@ -759,5 +768,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $result = $result2; } + Cache::set("probe_url:".$mode.":".$url,serialize($result)); + return $result; } diff --git a/include/follow.php b/include/follow.php index 285f864b9..ba036cd48 100644 --- a/include/follow.php +++ b/include/follow.php @@ -37,7 +37,7 @@ function new_contact($uid,$url,$interactive = false) { call_hooks('follow', $arr); - if(x($arr['contact'],'name')) + if(x($arr['contact'],'name')) $ret = $arr['contact']; else $ret = probe_url($url); @@ -73,7 +73,7 @@ function new_contact($uid,$url,$interactive = false) { // do we have enough information? - + if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) { $result['message'] .= t('The profile address specified does not provide adequate information.') . EOL; if(! x($ret,'poll')) @@ -120,12 +120,12 @@ function new_contact($uid,$url,$interactive = false) { // the poll url is more reliable than the profile url, as we may have // indirect links or webfinger links - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' AND `network` = '%s' LIMIT 1", intval($uid), - dbesc($ret['poll']) + dbesc($ret['poll']), + dbesc($ret['network']) ); - if(count($r)) { // update contact if($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) { @@ -169,10 +169,10 @@ function new_contact($uid,$url,$interactive = false) { if($ret['network'] === NETWORK_DIASPORA) $new_relation = CONTACT_IS_FOLLOWER; - // create contact record - $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, + // create contact record + $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `network`, `pubkey`, `rel`, `priority`, `writable`, `hidden`, `blocked`, `readonly`, `pending`, `subhub` ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, 0, 0, 0, %d ) ", + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, 0, 0, 0, %d ) ", intval($uid), dbesc(datetime_convert()), dbesc($ret['url']), @@ -185,7 +185,6 @@ function new_contact($uid,$url,$interactive = false) { dbesc($ret['poco']), dbesc($ret['name']), dbesc($ret['nick']), - dbesc($ret['photo']), dbesc($ret['network']), dbesc($ret['pubkey']), intval($new_relation), @@ -196,8 +195,9 @@ function new_contact($uid,$url,$interactive = false) { ); } - $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", dbesc($ret['url']), + dbesc($ret['network']), intval($uid) ); @@ -228,8 +228,7 @@ function new_contact($uid,$url,$interactive = false) { `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' - WHERE `id` = %d - ", + WHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 1b940d949..650bbdcae 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -76,13 +76,14 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) return($replace); } +if(!function_exists('deletenode')) { function deletenode(&$doc, $node) { $xpath = new DomXPath($doc); $list = $xpath->query("//".$node); foreach ($list as $child) $child->parentNode->removeChild($child); -} +}} function html2bbcode($message) { diff --git a/include/items.php b/include/items.php index dc4b231f2..77337fe0d 100644 --- a/include/items.php +++ b/include/items.php @@ -882,6 +882,7 @@ function get_atom_elements($feed, $item, $contact = array()) { $preview = $attachment->link; $res["body"] = $res["title"].add_page_info($res['plink'], false, $preview, ($contact['fetch_further_information'] == 2), $contact['ffi_keyword_blacklist']); + $res["tag"] = add_page_keywords($res['plink'], false, $preview, ($contact['fetch_further_information'] == 2), $contact['ffi_keyword_blacklist']); $res["title"] = ""; $res["object-type"] = ACTIVITY_OBJ_BOOKMARK; unset($res["attach"]); @@ -946,7 +947,7 @@ function add_page_info_data($data) { return("\n[class=type-".$data["type"]."]".$text."[/class]".$hashtags); } -function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") { +function query_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") { require_once("mod/parse_url.php"); $data = Cache::get("parse_url:".$url); @@ -959,7 +960,7 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, if ($photo != "") $data["images"][0]["src"] = $photo; - logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG); + logger('fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG); if (!$keywords AND isset($data["keywords"])) unset($data["keywords"]); @@ -974,6 +975,32 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, } } + return($data); +} + +function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") { + $data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist); + + $tags = ""; + if (isset($data["keywords"]) AND count($data["keywords"])) { + $a = get_app(); + foreach ($data["keywords"] AS $keyword) { + $hashtag = str_replace(array(" ", "+", "/", ".", "#", "'"), + array("","", "", "", "", ""), $keyword); + + if ($tags != "") + $tags .= ","; + + $tags .= "#[url=".$a->get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url]"; + } + } + + return($tags); +} + +function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") { + $data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist); + $text = add_page_info_data($data); return($text); @@ -4071,6 +4098,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { else $body = $item['body']; + $o = "\r\n\r\n\r\n"; if(is_array($author)) @@ -4085,13 +4113,22 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $o .= '' . "\r\n"; } + $htmlbody = $body; + + if ($item['title'] != "") + $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; + + $htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7); + $o .= '' . xmlify($item['uri']) . '' . "\r\n"; $o .= '' . xmlify($item['title']) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; $o .= '' . base64url_encode($body, true) . '' . "\r\n"; - $o .= '' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '' . "\r\n"; + $o .= '' . xmlify((($type === 'html') ? $htmlbody : $body)) . '' . "\r\n"; $o .= '' . "\r\n"; + + if($comment) $o .= '' . intval($item['last-child']) . '' . "\r\n"; diff --git a/include/notifier.php b/include/notifier.php index cfd85593f..067251b42 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -55,7 +55,7 @@ function notifier_run(&$argv, &$argc){ @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); } require_once("include/session.php"); @@ -110,10 +110,11 @@ function notifier_run(&$argv, &$argc){ $recipients[] = $message[0]['contact-id']; $item = $message[0]; - } elseif($cmd === 'expire') { + } + elseif($cmd === 'expire') { $normal_mode = false; $expire = true; - $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 + $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE", intval($item_id) ); @@ -121,7 +122,8 @@ function notifier_run(&$argv, &$argc){ $item_id = 0; if(! count($items)) return; - } elseif($cmd === 'suggest') { + } + elseif($cmd === 'suggest') { $normal_mode = false; $fsuggest = true; @@ -176,7 +178,7 @@ function notifier_run(&$argv, &$argc){ if(! $parent_id) return; - $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` + $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC", intval($parent_id) ); @@ -290,8 +292,28 @@ function notifier_run(&$argv, &$argc){ $followup = true; $public_message = false; // not public $conversant_str = dbesc($parent['contact-id']); - } - else { + $recipients = array($parent['contact-id']); + + if ($parent['network'] == NETWORK_OSTATUS) { + + // Check if the recipient isn't in your contact list + $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']); + if (count($r)) { + $url_recipients = array(); + + $thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"])); + if (count($thrparent) AND (normalise_link($r[0]["url"]) != normalise_link($thrparent[0]["author-link"]))) { + require_once("include/Scrape.php"); + $probed_contact = probe_url($thrparent[0]["author-link"]); + if ($probed_contact["notify"] != "") { + logger('scrape data for slapper: '.print_r($probed_contact, true)); + $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; + } + } + } + logger("url_recipients".print_r($url_recipients,true)); + } + } else { $followup = false; // don't send deletions onward for other people's stuff @@ -437,8 +459,8 @@ function notifier_run(&$argv, &$argc){ set_config('system','site_pubkey', $res['pubkey']); } - $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` - WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid); + $rp = q("SELECT `resource-id` , `scale`, type FROM `photo` + WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid); $photos = array(); $ext = Photo::supportedTypes(); foreach($rp as $p){ @@ -446,19 +468,19 @@ function notifier_run(&$argv, &$argc){ } unset($rp, $ext); - $atom .= replace_macros($sugg_template, array( - '$name' => xmlify($owner['name']), - '$photo' => xmlify($photos[4]), - '$thumb' => xmlify($photos[5]), - '$micro' => xmlify($photos[6]), - '$url' => xmlify($owner['url']), - '$request' => xmlify($owner['request']), - '$confirm' => xmlify($owner['confirm']), - '$notify' => xmlify($owner['notify']), - '$poll' => xmlify($owner['poll']), - '$sitepubkey' => xmlify(get_config('system','site_pubkey')), - //'$pubkey' => xmlify($owner['pubkey']), - //'$prvkey' => xmlify($owner['prvkey']), + $atom .= replace_macros($sugg_template, array( + '$name' => xmlify($owner['name']), + '$photo' => xmlify($photos[4]), + '$thumb' => xmlify($photos[5]), + '$micro' => xmlify($photos[6]), + '$url' => xmlify($owner['url']), + '$request' => xmlify($owner['request']), + '$confirm' => xmlify($owner['confirm']), + '$notify' => xmlify($owner['notify']), + '$poll' => xmlify($owner['poll']), + '$sitepubkey' => xmlify(get_config('system','site_pubkey')), + //'$pubkey' => xmlify($owner['pubkey']), + //'$prvkey' => xmlify($owner['prvkey']), )); $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN); unset($photos); @@ -497,8 +519,7 @@ function notifier_run(&$argv, &$argc){ if($item_id == $item['id'] || $item['id'] == $item['parent']) $atom .= atom_entry($item,'text',null,$owner,true); - } - else + } else $atom .= atom_entry($item,'text',null,$owner,true); if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) @@ -517,8 +538,8 @@ function notifier_run(&$argv, &$argc){ $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); if(! $mail_disabled) { - if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) - && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid'])) + if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) + && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid'])) && (intval($target_item['pubmail']))) { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'", intval($uid), @@ -541,7 +562,7 @@ function notifier_run(&$argv, &$argc){ else $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ", dbesc($recip_str) - ); + ); require_once('include/salmon.php'); @@ -691,33 +712,13 @@ function notifier_run(&$argv, &$argc){ if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only')) break; - $ostatus_contact = $contact; - - // If the contact doesn't fit with the contact, then fetch the correct contact - // This is more a test than a good solution. The whole OStatus stuff needs a rework. - if ($followup) { - $thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"])); - if (count($thrparent) AND (normalise_link($contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { - require_once("include/Scrape.php"); - $probed_contact = probe_url($thrparent[0]["author-link"]); - if ($probed_contact["network"] != NETWORK_FEED) { - $ostatus_contact = $probed_contact; - $ostatus_contact["nurl"] = normalise_link($probed_contact["url"]); - $ostatus_contact["thumb"] = $probed_contact["photo"]; - $ostatus_contact["micro"] = $probed_contact["photo"]; - } - logger('scrape data for slapper: '.print_r($ostatus_contact, true)); - } - } - - if($followup && $ostatus_contact['notify']) { - - logger('notifier: slapdelivery: ' . $ostatus_contact['name']); - $deliver_status = slapper($owner,$ostatus_contact['notify'],$slap); + if($followup && $contact['notify']) { + logger('notifier: slapdelivery: ' . $contact['name']); + $deliver_status = slapper($owner,$contact['notify'],$slap); if($deliver_status == (-1)) { // queue message for redelivery - add_to_queue($ostatus_contact['id'],NETWORK_OSTATUS,$slap); + add_to_queue($contact['id'],NETWORK_OSTATUS,$slap); } } else { @@ -1012,6 +1013,6 @@ function notifier_run(&$argv, &$argc){ if (array_search(__file__,get_included_files())===0){ - notifier_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); + notifier_run($_SERVER["argv"],$_SERVER["argc"]); + killme(); } diff --git a/mod/contacts.php b/mod/contacts.php index fbab84f56..047dc1ea9 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -407,19 +407,19 @@ function contacts_content(&$a) { $url = "redir/{$contact['id']}"; $sparkle = ' class="sparkle" '; } - else { + else { $url = $contact['url']; $sparkle = ''; } $insecure = t('Private communications are not available for this contact.'); - $last_update = (($contact['last-update'] == '0000-00-00 00:00:00') - ? t('Never') + $last_update = (($contact['last-update'] == '0000-00-00 00:00:00') + ? t('Never') : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A')); if($contact['last-update'] !== '0000-00-00 00:00:00') - $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29")); + $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29")); $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : ''); @@ -430,7 +430,7 @@ function contacts_content(&$a) { $common = count_common_friends(local_user(),$contact['id']); $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : ''); - $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : ''); + $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : ''); $x = count_all_friends(local_user(), $contact['id']); $all_friends = (($x) ? t('View all contacts') : ''); @@ -668,7 +668,7 @@ function contacts_content(&$a) { $url = "redir/{$rr['id']}"; $sparkle = ' class="sparkle" '; } - else { + else { $url = $rr['url']; $sparkle = ''; } @@ -681,7 +681,7 @@ function contacts_content(&$a) { 'id' => $rr['id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, - 'thumb' => $rr['thumb'], + 'thumb' => $rr['thumb'], 'name' => $rr['name'], 'username' => $rr['name'], 'sparkle' => $sparkle, diff --git a/mod/salmon.php b/mod/salmon.php index 5df1e1c9e..11e42d943 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -15,7 +15,7 @@ function salmon_return($val) { if($val >= 200 && $val < 300) $err = 'OK'; - logger('mod-salmon returns ' . $val); + logger('mod-salmon returns ' . $val); header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); killme(); @@ -50,7 +50,7 @@ function salmon_post(&$a) { $base = $dom->env; elseif($dom->data) $base = $dom; - + if(! $base) { logger('mod-salmon: unable to locate salmon data in xml '); http_status_exit(400); @@ -92,7 +92,7 @@ function salmon_post(&$a) { // Create a fake feed wrapper so simplepie doesn't choke $tpl = get_markup_template('fake_feed.tpl'); - + $base = substr($data,strpos($data,''; @@ -100,7 +100,7 @@ function salmon_post(&$a) { logger('mod-salmon: Processed feed: ' . $feedxml); // Now parse it like a normal atom feed to scrape out the author URI - + $feed = new SimplePie(); $feed->set_raw_data($feedxml); $feed->enable_order_by_date(false); @@ -192,7 +192,7 @@ function salmon_post(&$a) { ); } } - } + } // is this a follower? Or have we ignored the person? // If so we can not accept this post. @@ -223,7 +223,3 @@ function salmon_post(&$a) { http_status_exit(200); } - - - -