function diaspora_fetch_message($guid, $server, $level = 0) { if ($level > 5) { return false; } $a = get_app(); // This will not work if the server is not a Diaspora server $source_url = $server . '/p/' . $guid . '.xml'; $x = fetch_url($source_url); if (!$x) { return false; } $x = str_replace(array('<activity_streams-photo>', '</activity_streams-photo>'), array('<asphoto>', '</asphoto>'), $x); $source_xml = parse_xml_string($x, false); $item = array(); $item["app"] = 'Diaspora'; $item["guid"] = $guid; $body = ""; if ($source_xml->post->status_message->created_at) { $item["created"] = unxmlify($source_xml->post->status_message->created_at); } if ($source_xml->post->status_message->provider_display_name) { $item["app"] = unxmlify($source_xml->post->status_message->provider_display_name); } if ($source_xml->post->status_message->diaspora_handle) { $item["author"] = unxmlify($source_xml->post->status_message->diaspora_handle); } if ($source_xml->post->status_message->guid) { $item["guid"] = unxmlify($source_xml->post->status_message->guid); } $item["private"] = unxmlify($source_xml->post->status_message->public) == 'false'; $item["object"] = json_encode($source_xml->post); if (strlen($source_xml->post->asphoto->objectId) && $source_xml->post->asphoto->objectId != 0 && $source_xml->post->asphoto->image_url) { $item["object-type"] = ACTIVITY_OBJ_PHOTO; $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n"; $body = scale_external_images($body, false); } elseif ($source_xml->post->asphoto->image_url) { $item["object-type"] = ACTIVITY_OBJ_PHOTO; $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n"; $body = scale_external_images($body); } elseif ($source_xml->post->status_message) { $body = diaspora2bb($source_xml->post->status_message->raw_message); // Checking for embedded pictures if ($source_xml->post->status_message->photo->remote_photo_path and $source_xml->post->status_message->photo->remote_photo_name) { $item["object-type"] = ACTIVITY_OBJ_PHOTO; $remote_photo_path = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_path)); $remote_photo_name = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_name)); $body = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n" . $body; logger('embedded picture link found: ' . $body, LOGGER_DEBUG); } else { $item["object-type"] = ACTIVITY_OBJ_NOTE; } $body = scale_external_images($body); // Add OEmbed and other information to the body // To-Do: It could be a repeated redmatrix item // Then we shouldn't add further data to it if ($item["object-type"] == ACTIVITY_OBJ_NOTE) { $body = add_page_info_to_body($body, false, true); } } elseif ($source_xml->post->reshare) { // Reshare of a reshare return diaspora_fetch_message($source_xml->post->reshare->root_guid, $server, ++$level); } else { // Maybe it is a reshare of a photo that will be delivered at a later time (testing) logger('no content found: ' . print_r($source_xml, true)); return false; } if (trim($body) == "") { return false; } $item["tag"] = ''; $item["body"] = $body; return $item; }
function get_atom_elements($feed, $item, $contact = array()) { require_once 'library/HTMLPurifier.auto.php'; require_once 'include/html2bbcode.php'; $best_photo = array(); $res = array(); $author = $item->get_author(); if ($author) { $res['author-name'] = unxmlify($author->get_name()); $res['author-link'] = unxmlify($author->get_link()); } else { $res['author-name'] = unxmlify($feed->get_title()); $res['author-link'] = unxmlify($feed->get_permalink()); } $res['uri'] = unxmlify($item->get_id()); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); if (isset($contact["network"]) and $contact["network"] == NETWORK_FEED and strstr($res['plink'], ".app.net/")) { logger("get_atom_elements: detected app.net posting: " . print_r($res, true), LOGGER_DEBUG); $res['title'] = ""; $res['body'] = nl2br($res['body']); } // removing the content of the title if its identically to the body // This helps with auto generated titles e.g. from tumblr if (title_is_body($res["title"], $res["body"])) { $res['title'] = ""; } if ($res['plink']) { $base_url = implode('/', array_slice(explode('/', $res['plink']), 0, 3)); } else { $base_url = ''; } // look for a photo. We should check media size and find the best one, // but for now let's just find any author photo // Additionally we look for an alternate author link. On OStatus this one is the one we want. $authorlinks = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; if (is_array($authorlinks)) { foreach ($authorlinks as $link) { $linkdata = array_shift($link["attribs"]); if ($linkdata["rel"] == "alternate") { $res["author-link"] = $linkdata["href"]; } } } $rawauthor = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach ($base as $link) { if ($link['attribs']['']['rel'] === 'alternate') { $res['author-link'] = unxmlify($link['attribs']['']['href']); } if (!x($res, 'author-avatar') || !$res['author-avatar']) { if ($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') { $res['author-avatar'] = unxmlify($link['attribs']['']['href']); } } } } $rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor'); if ($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'], ACTIVITY_OBJ_PERSON)) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; if ($base && count($base)) { foreach ($base as $link) { if ($link['attribs']['']['rel'] === 'alternate' && !$res['author-link']) { $res['author-link'] = unxmlify($link['attribs']['']['href']); } if (!x($res, 'author-avatar') || !$res['author-avatar']) { if ($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') { $res['author-avatar'] = unxmlify($link['attribs']['']['href']); } } } } } // No photo/profile-link on the item - look at the feed level if (!x($res, 'author-link') || !x($res, 'author-avatar')) { $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach ($base as $link) { if ($link['attribs']['']['rel'] === 'alternate' && !$res['author-link']) { $res['author-link'] = unxmlify($link['attribs']['']['href']); } if (!$res['author-avatar']) { if ($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') { $res['author-avatar'] = unxmlify($link['attribs']['']['href']); } } } } $rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject'); if ($rawactor && activity_match($rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'], ACTIVITY_OBJ_PERSON)) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; if ($base && count($base)) { foreach ($base as $link) { if ($link['attribs']['']['rel'] === 'alternate' && !$res['author-link']) { $res['author-link'] = unxmlify($link['attribs']['']['href']); } if (!x($res, 'author-avatar')) { if ($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') { $res['author-avatar'] = unxmlify($link['attribs']['']['href']); } } } } } } $apps = $item->get_item_tags(NAMESPACE_STATUSNET, 'notice_info'); if ($apps && $apps[0]['attribs']['']['source']) { $res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source'])); if ($res['app'] === 'web') { $res['app'] = 'OStatus'; } } // base64 encoded json structure representing Diaspora signature $dsig = $item->get_item_tags(NAMESPACE_DFRN, 'diaspora_signature'); if ($dsig) { $res['dsprsig'] = unxmlify($dsig[0]['data']); } $dguid = $item->get_item_tags(NAMESPACE_DFRN, 'diaspora_guid'); if ($dguid) { $res['guid'] = unxmlify($dguid[0]['data']); } $bm = $item->get_item_tags(NAMESPACE_DFRN, 'bookmark'); if ($bm) { $res['bookmark'] = unxmlify($bm[0]['data']) === 'true' ? 1 : 0; } /** * If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it. */ $have_real_body = false; $rawenv = $item->get_item_tags(NAMESPACE_DFRN, 'env'); if ($rawenv) { $have_real_body = true; $res['body'] = $rawenv[0]['data']; $res['body'] = str_replace(array(' ', "\t", "\r", "\n"), array('', '', '', ''), $res['body']); // make sure nobody is trying to sneak some html tags by us $res['body'] = notags(base64url_decode($res['body'])); } $res['body'] = limit_body_size($res['body']); // It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust // the content type. Our own network only emits text normally, though it might have been converted to // html if we used a pubsubhubbub transport. But if we see even one html tag in our text, we will // have to assume it is all html and needs to be purified. // It doesn't matter all that much security wise - because before this content is used anywhere, we are // going to escape any tags we find regardless, but this lets us import a limited subset of html from // the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining // html. if (strpos($res['body'], '<') !== false && strpos($res['body'], '>') !== false) { $res['body'] = reltoabs($res['body'], $base_url); $res['body'] = html2bb_video($res['body']); $res['body'] = oembed_html2bbcode($res['body']); $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); // we shouldn't need a whitelist, because the bbcode converter // will strip out any unsupported tags. $purifier = new HTMLPurifier($config); $res['body'] = $purifier->purify($res['body']); $res['body'] = @html2bbcode($res['body']); } elseif (!$have_real_body) { // it's not one of our messages and it has no tags // so it's probably just text. We'll escape it just to be safe. $res['body'] = escape_tags($res['body']); } // this tag is obsolete but we keep it for really old sites $allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow'); if ($allow && $allow[0]['data'] == 1) { $res['last-child'] = 1; } else { $res['last-child'] = 0; } $private = $item->get_item_tags(NAMESPACE_DFRN, 'private'); if ($private && intval($private[0]['data']) > 0) { $res['private'] = intval($private[0]['data']); } else { $res['private'] = 0; } $extid = $item->get_item_tags(NAMESPACE_DFRN, 'extid'); if ($extid && $extid[0]['data']) { $res['extid'] = $extid[0]['data']; } $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location'); if ($rawlocation) { $res['location'] = unxmlify($rawlocation[0]['data']); } $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); if ($rawcreated) { $res['created'] = unxmlify($rawcreated[0]['data']); } $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'); if ($rawedited) { $res['edited'] = unxmlify($rawedited[0]['data']); } if (x($res, 'edited') && !x($res, 'created')) { $res['created'] = $res['edited']; } if (!$res['created']) { $res['created'] = $item->get_date('c'); } if (!$res['edited']) { $res['edited'] = $item->get_date('c'); } // Disallow time travelling posts $d1 = strtotime($res['created']); $d2 = strtotime($res['edited']); $d3 = strtotime('now'); if ($d1 > $d3) { $res['created'] = datetime_convert(); } if ($d2 > $d3) { $res['edited'] = datetime_convert(); } $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner'); if ($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']) { $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); } elseif ($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']) { $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']); } if ($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']) { $res['owner-link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); } elseif ($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']) { $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']); } if ($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach ($base as $link) { if (!x($res, 'owner-avatar') || !$res['owner-avatar']) { if ($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') { $res['owner-avatar'] = unxmlify($link['attribs']['']['href']); } } } } $rawgeo = $item->get_item_tags(NAMESPACE_GEORSS, 'point'); if ($rawgeo) { $res['coord'] = unxmlify($rawgeo[0]['data']); } if ($contact["network"] == NETWORK_FEED) { $res['verb'] = ACTIVITY_POST; $res['object-type'] = ACTIVITY_OBJ_NOTE; } $rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb'); // select between supported verbs if ($rawverb) { $res['verb'] = unxmlify($rawverb[0]['data']); } // translate OStatus unfollow to activity streams if it happened to get selected if (x($res, 'verb') && $res['verb'] === 'http://ostatus.org/schema/1.0/unfollow') { $res['verb'] = ACTIVITY_UNFOLLOW; } $cats = $item->get_categories(); if ($cats) { $tag_arr = array(); foreach ($cats as $cat) { $term = $cat->get_term(); if (!$term) { $term = $cat->get_label(); } $scheme = $cat->get_scheme(); if ($scheme && $term && stristr($scheme, 'X-DFRN:')) { $tag_arr[] = substr($scheme, 7, 1) . '[url=' . unxmlify(substr($scheme, 9)) . ']' . unxmlify($term) . '[/url]'; } elseif ($term) { $tag_arr[] = notags(trim($term)); } } $res['tag'] = implode(',', $tag_arr); } $attach = $item->get_enclosures(); if ($attach) { $att_arr = array(); foreach ($attach as $att) { $len = intval($att->get_length()); $link = str_replace(array(',', '"'), array('%2D', '%22'), notags(trim(unxmlify($att->get_link())))); $title = str_replace(array(',', '"'), array('%2D', '%22'), notags(trim(unxmlify($att->get_title())))); $type = str_replace(array(',', '"'), array('%2D', '%22'), notags(trim(unxmlify($att->get_type())))); if (strpos($type, ';')) { $type = substr($type, 0, strpos($type, ';')); } if (!$link || strpos($link, 'http') !== 0) { continue; } if (!$title) { $title = ' '; } if (!$type) { $type = 'application/octet-stream'; } $att_arr[] = '[attach]href="' . $link . '" length="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; } $res['attach'] = implode(',', $att_arr); } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); if ($rawobj) { $res['object'] = '<object>' . "\n"; $child = $rawobj[0]['child']; if ($child[NAMESPACE_ACTIVITY]['object-type'][0]['data']) { $res['object-type'] = $child[NAMESPACE_ACTIVITY]['object-type'][0]['data']; $res['object'] .= '<type>' . $child[NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) { $res['object'] .= '<id>' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $res['object'] .= '<link>' . encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'title') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) { $res['object'] .= '<title>' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'content') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; if (!$body) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; } // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n"; if (strpos($body, '<') !== false || strpos($body, '>') !== false) { $body = html2bb_video($body); $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $body = $purifier->purify($body); $body = html2bbcode($body); } $res['object'] .= '<content>' . $body . '</content>' . "\n"; } $res['object'] .= '</object>' . "\n"; } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target'); if ($rawobj) { $res['target'] = '<target>' . "\n"; $child = $rawobj[0]['child']; if ($child[NAMESPACE_ACTIVITY]['object-type'][0]['data']) { $res['target'] .= '<type>' . $child[NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '</type>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) { $res['target'] .= '<id>' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '</id>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $res['target'] .= '<link>' . encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '</link>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'data') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) { $res['target'] .= '<title>' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '</title>' . "\n"; } if (x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'data') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; if (!$body) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; } // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events $res['target'] .= '<orig>' . xmlify($body) . '</orig>' . "\n"; if (strpos($body, '<') !== false || strpos($body, '>') !== false) { $body = html2bb_video($body); $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $body = $purifier->purify($body); $body = html2bbcode($body); } $res['target'] .= '<content>' . $body . '</content>' . "\n"; } $res['target'] .= '</target>' . "\n"; } // This is some experimental stuff. By now retweets are shown with "RT:" // But: There is data so that the message could be shown similar to native retweets // There is some better way to parse this array - but it didn't worked for me. $child = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://activitystrea.ms/spec/1.0/"][object][0]["child"]; if (is_array($child)) { logger('get_atom_elements: Looking for status.net repeated message'); $message = $child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["content"][0]["data"]; $orig_id = ostatus_convert_href($child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["id"][0]["data"]); $author = $child[SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]; $uri = $author["uri"][0]["data"]; $name = $author["name"][0]["data"]; $avatar = @array_shift($author["link"][2]["attribs"]); $avatar = $avatar["href"]; if ($name != "" and $uri != "" and $avatar != "" and $message != "") { logger('get_atom_elements: fixing sender of repeated message. ' . $orig_id, LOGGER_DEBUG); if (!intval(get_config('system', 'wall-to-wall_share'))) { $prefix = share_header($name, $uri, $avatar, "", "", $orig_link); $res["body"] = $prefix . html2bbcode($message) . "[/share]"; } else { $res["owner-name"] = $res["author-name"]; $res["owner-link"] = $res["author-link"]; $res["owner-avatar"] = $res["author-avatar"]; $res["author-name"] = $name; $res["author-link"] = $uri; $res["author-avatar"] = $avatar; $res["body"] = html2bbcode($message); } } } if (isset($contact["network"]) and $contact["network"] == NETWORK_FEED and $contact['fetch_further_information']) { $preview = ""; // Handle enclosures and treat them as preview picture if (isset($attach)) { foreach ($attach as $attachment) { if ($attachment->type == "image/jpeg") { $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"]); } elseif (isset($contact["network"]) and $contact["network"] == NETWORK_OSTATUS) { $res["body"] = add_page_info_to_body($res["body"]); } elseif (isset($contact["network"]) and $contact["network"] == NETWORK_FEED and strstr($res['plink'], ".app.net/")) { $res["body"] = add_page_info_to_body($res["body"]); } $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); call_hooks('parse_atom', $arr); return $res; }
function ostatus_completion($conversation_url, $uid, $item = array()) { $a = get_app(); $item_stored = -1; $conversation_url = ostatus_convert_href($conversation_url); // If the thread shouldn't be completed then store the item and go away if (intval(get_config('system', 'ostatus_poll_interval')) == -2 and count($item) > 0) { //$arr["app"] .= " (OStatus-NoCompletion)"; $item_stored = item_store($item, true); return $item_stored; } // Get the parent $parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN\n\t\t\t(SELECT `parent` FROM `item` WHERE `id` IN\n\t\t\t\t(SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); if ($parents) { $parent = $parents[0]; } elseif (count($item) > 0) { $parent = $item; $parent["type"] = "remote"; $parent["verb"] = ACTIVITY_POST; $parent["visible"] = 1; } else { // Preset the parent $r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid); if (!$r) { return -2; } $parent = array(); $parent["id"] = 0; $parent["parent"] = 0; $parent["uri"] = ""; $parent["contact-id"] = $r[0]["id"]; $parent["type"] = "remote"; $parent["verb"] = ACTIVITY_POST; $parent["visible"] = 1; } $conv = str_replace("/conversation/", "/api/statusnet/conversation/", $conversation_url) . ".as"; $pageno = 1; $items = array(); logger('fetching conversation url ' . $conv . ' for user ' . $uid); do { $conv_arr = z_fetch_url($conv . "?page=" . $pageno); // If it is a non-ssl site and there is an error, then try ssl or vice versa if (!$conv_arr["success"] and substr($conv, 0, 7) == "http://") { $conv = str_replace("http://", "https://", $conv); $conv_as = fetch_url($conv . "?page=" . $pageno); } elseif (!$conv_arr["success"] and substr($conv, 0, 8) == "https://") { $conv = str_replace("https://", "http://", $conv); $conv_as = fetch_url($conv . "?page=" . $pageno); } else { $conv_as = $conv_arr["body"]; } $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); if (@is_array($conv_as->items)) { $items = array_merge($items, $conv_as->items); } else { break; } $pageno++; } while (true); logger('fetching conversation done. Found ' . count($items) . ' items'); if (!sizeof($items)) { if (count($item) > 0) { //$arr["app"] .= " (OStatus-NoConvFetched)"; $item_stored = item_store($item, true); if ($item_stored) { logger("Conversation " . $conversation_url . " couldn't be fetched. Item uri " . $item["uri"] . " stored: " . $item_stored, LOGGER_DEBUG); ostatus_store_conversation($item_id, $conversation_url); } return $item_stored; } else { return -3; } } $items = array_reverse($items); $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); $importer = $r[0]; foreach ($items as $single_conv) { // Test - remove before flight //$tempfile = tempnam(get_temppath(), "conversation"); //file_put_contents($tempfile, json_encode($single_conv)); $mention = false; if (isset($single_conv->object->id)) { $single_conv->id = $single_conv->object->id; } $plink = ostatus_convert_href($single_conv->id); if (isset($single_conv->object->url)) { $plink = ostatus_convert_href($single_conv->object->url); } if (@(!$single_conv->id)) { continue; } logger("Got id " . $single_conv->id, LOGGER_DEBUG); if ($first_id == "") { $first_id = $single_conv->id; // The first post of the conversation isn't our first post. There are three options: // 1. Our conversation hasn't the "real" thread starter // 2. This first post is a post inside our thread // 3. This first post is a post inside another thread if ($first_id != $parent["uri"] and $parent["uri"] != "") { $new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN\n\t\t\t\t\t\t\t(SELECT `parent` FROM `item`\n\t\t\t\t\t\t\t\tWHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1", intval($uid), dbesc($first_id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($new_parents) { if ($new_parents[0]["parent"] == $parent["parent"]) { // Option 2: This post is already present inside our thread - but not as thread starter logger("Option 2: uri present in our thread: " . $first_id, LOGGER_DEBUG); $first_id = $parent["uri"]; } else { // Option 3: Not so good. We have mixed parents. We have to see how to clean this up. // For now just take the new parent. $parent = $new_parents[0]; $first_id = $parent["uri"]; logger("Option 3: mixed parents for uri " . $first_id, LOGGER_DEBUG); } } else { // Option 1: We hadn't got the real thread starter // We have to clean up our existing messages. $parent["id"] = 0; $parent["uri"] = $first_id; logger("Option 1: we have a new parent: " . $first_id, LOGGER_DEBUG); } } elseif ($parent["uri"] == "") { $parent["id"] = 0; $parent["uri"] = $first_id; } } $parent_uri = $parent["uri"]; // "context" only seems to exist on older servers if (isset($single_conv->context->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->context->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($parent_exists) { $parent_uri = $single_conv->context->inReplyTo->id; } } // This is the current way if (isset($single_conv->object->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->object->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($parent_exists) { $parent_uri = $single_conv->object->inReplyTo->id; } } $message_exists = q("SELECT `id`, `parent`, `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($message_exists) { logger("Message " . $single_conv->id . " already existed on the system", LOGGER_DEBUG); if ($parent["id"] != 0) { $existing_message = $message_exists[0]; // We improved the way we fetch OStatus messages, this shouldn't happen very often now // To-Do: we have to change the shadow copies as well. This way here is really ugly. if ($existing_message["parent"] != $parent["id"]) { logger('updating id ' . $existing_message["id"] . ' with parent ' . $existing_message["parent"] . ' to parent ' . $parent["id"] . ' uri ' . $parent["uri"] . ' thread ' . $parent_uri, LOGGER_DEBUG); // Update the parent id of the selected item $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `id` = %d", intval($parent["id"]), dbesc($parent["uri"]), intval($existing_message["id"])); // Update the parent uri in the thread - but only if it points to itself $r = q("UPDATE `item` SET `thr-parent` = '%s' WHERE `id` = %d AND `uri` = `thr-parent`", dbesc($parent_uri), intval($existing_message["id"])); // try to change all items of the same parent $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d", intval($parent["id"]), dbesc($parent["uri"]), intval($existing_message["parent"])); // Update the parent uri in the thread - but only if it points to itself $r = q("UPDATE `item` SET `thr-parent` = '%s' WHERE (`parent` = %d) AND (`uri` = `thr-parent`)", dbesc($parent["uri"]), intval($existing_message["parent"])); // Now delete the thread delete_thread($existing_message["parent"]); } } // The item we are having on the system is the one that we wanted to store via the item array if (isset($item["uri"]) and $item["uri"] == $existing_message["uri"]) { $item = array(); $item_stored = 0; } continue; } if (is_array($single_conv->to)) { foreach ($single_conv->to as $to) { if ($importer["nurl"] == normalise_link($to->id)) { $mention = true; } } } $actor = $single_conv->actor->id; if (isset($single_conv->actor->url)) { $actor = $single_conv->actor->url; } $contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", $uid, normalise_link($actor), NETWORK_STATUSNET); if (count($contact)) { logger("Found contact for url " . $actor, LOGGER_DEBUG); $contact_id = $contact[0]["id"]; } else { logger("No contact found for url " . $actor, LOGGER_DEBUG); // Adding a global contact // To-Do: Use this data for the post $global_contact_id = get_contact($actor, 0); logger("Global contact " . $global_contact_id . " found for url " . $actor, LOGGER_DEBUG); $contact_id = $parent["contact-id"]; } $arr = array(); $arr["network"] = NETWORK_OSTATUS; $arr["uri"] = $single_conv->id; $arr["plink"] = $plink; $arr["uid"] = $uid; $arr["contact-id"] = $contact_id; $arr["parent-uri"] = $parent_uri; $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->contact->displayName; } if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName; } $arr["owner-link"] = $actor; $arr["owner-avatar"] = $single_conv->actor->image->url; $arr["author-name"] = $arr["owner-name"]; $arr["author-link"] = $actor; $arr["author-avatar"] = $single_conv->actor->image->url; $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content)); if (isset($single_conv->status_net->notice_info->source)) { $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); } elseif (isset($single_conv->statusnet->notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet->notice_info->source); } elseif (isset($single_conv->statusnet_notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet_notice_info->source); } elseif (isset($single_conv->provider->displayName)) { $arr["app"] = $single_conv->provider->displayName; } else { $arr["app"] = "OStatus"; } //$arr["app"] .= " (Conversation)"; $arr["object"] = json_encode($single_conv); $arr["verb"] = $parent["verb"]; $arr["visible"] = $parent["visible"]; $arr["location"] = $single_conv->location->displayName; $arr["coord"] = trim($single_conv->location->lat . " " . $single_conv->location->lon); // Is it a reshared item? if (isset($single_conv->verb) and $single_conv->verb == "share" and isset($single_conv->object)) { if (is_array($single_conv->object)) { $single_conv->object = $single_conv->object[0]; } logger("Found reshared item " . $single_conv->object->id); // $single_conv->object->context->conversation; if (isset($single_conv->object->object->id)) { $arr["uri"] = $single_conv->object->object->id; } else { $arr["uri"] = $single_conv->object->id; } if (isset($single_conv->object->object->url)) { $plink = ostatus_convert_href($single_conv->object->object->url); } else { $plink = ostatus_convert_href($single_conv->object->url); } if (isset($single_conv->object->object->content)) { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->object->content)); } else { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->content)); } $arr["plink"] = $plink; $arr["created"] = $single_conv->object->published; $arr["edited"] = $single_conv->object->published; $arr["author-name"] = $single_conv->object->actor->displayName; if ($arr["owner-name"] == '') { $arr["author-name"] = $single_conv->object->actor->contact->displayName; } $arr["author-link"] = $single_conv->object->actor->url; $arr["author-avatar"] = $single_conv->object->actor->image->url; $arr["app"] = $single_conv->object->provider->displayName . "#"; //$arr["verb"] = $single_conv->object->verb; $arr["location"] = $single_conv->object->location->displayName; $arr["coord"] = trim($single_conv->object->location->lat . " " . $single_conv->object->location->lon); } if ($arr["location"] == "") { unset($arr["location"]); } if ($arr["coord"] == "") { unset($arr["coord"]); } // Copy fields from given item array if (isset($item["uri"]) and ($item["uri"] == $arr["uri"] or $item["uri"] == $single_conv->id)) { $copy_fields = array("owner-name", "owner-link", "owner-avatar", "author-name", "author-link", "author-avatar", "gravity", "body", "object-type", "object", "verb", "created", "edited", "coord", "tag", "title", "attach", "app", "type", "location", "contact-id", "uri"); foreach ($copy_fields as $field) { if (isset($item[$field])) { $arr[$field] = $item[$field]; } } //$arr["app"] .= " (OStatus)"; } $newitem = item_store($arr); if (!$newitem) { logger("Item wasn't stored " . print_r($arr, true), LOGGER_DEBUG); continue; } if (isset($item["uri"]) and $item["uri"] == $arr["uri"]) { $item = array(); $item_stored = $newitem; } logger('Stored new item ' . $plink . ' for parent ' . $arr["parent-uri"] . ' under id ' . $newitem, LOGGER_DEBUG); // Add the conversation entry (but don't fetch the whole conversation) ostatus_store_conversation($newitem, $conversation_url); if ($mention) { $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($uid)); $r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($newitem)); notification(array('type' => NOTIFY_TAGSELF, 'notify_flags' => $u[0]["notify-flags"], 'language' => $u[0]["language"], 'to_name' => $u[0]["username"], 'to_email' => $u[0]["email"], 'uid' => $uid, 'item' => $arr, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($newitem)), 'source_name' => $arr["author-name"], 'source_link' => $arr["author-link"], 'source_photo' => $arr["author-avatar"], 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $r[0]["parent"])); } // If the newly created item is the top item then change the parent settings of the thread // This shouldn't happen anymore. This is supposed to be absolote. if ($arr["uri"] == $first_id) { 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($uid), intval($newitem)); if ($new_parents) { $parent = $new_parents[0]; } } } if ($item_stored < 0 and count($item) > 0) { //$arr["app"] .= " (OStatus-NoConvFound)"; $item_stored = item_store($item, true); if ($item_stored) { logger("Uri " . $item["uri"] . " wasn't found in conversation " . $conversation_url, LOGGER_DEBUG); ostatus_store_conversation($item_stored, $conversation_url); } } return $item_stored; }
function twitter_expand_entities($a, $body, $item, $no_tags = false, $picture) { require_once "include/oembed.php"; require_once "include/network.php"; $tags = ""; if (isset($item->entities->urls)) { $type = ""; $footerurl = ""; $footerlink = ""; $footer = ""; foreach ($item->entities->urls as $url) { if ($url->url and $url->expanded_url and $url->display_url) { $expanded_url = original_url($url->expanded_url); $oembed_data = oembed_fetch_url($expanded_url); // Quickfix: Workaround for URL with "[" and "]" in it if (strpos($expanded_url, "[") or strpos($expanded_url, "]")) { $expanded_url = $url->url; } if ($type == "") { $type = $oembed_data->type; } if ($oembed_data->type == "video") { //$body = str_replace($url->url, // "[video]".$expanded_url."[/video]", $body); //$dontincludemedia = true; $type = $oembed_data->type; $footerurl = $expanded_url; $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]"; $body = str_replace($url->url, $footerlink, $body); //} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) { } elseif ($oembed_data->type == "photo" and isset($oembed_data->url)) { $body = str_replace($url->url, "[url=" . $expanded_url . "][img]" . $oembed_data->url . "[/img][/url]", $body); //$dontincludemedia = true; } elseif ($oembed_data->type != "link") { $body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); } else { $img_str = fetch_url($expanded_url, true, $redirects, 4); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); $mime = image_type_to_mime_type(exif_imagetype($tempfile)); unlink($tempfile); if (substr($mime, 0, 6) == "image/") { $type = "photo"; $body = str_replace($url->url, "[img]" . $expanded_url . "[/img]", $body); //$dontincludemedia = true; } else { $type = $oembed_data->type; $footerurl = $expanded_url; $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]"; $body = str_replace($url->url, $footerlink, $body); } } } } if ($footerurl != "") { $footer = add_page_info($footerurl, false, $picture); } if ($footerlink != "" and trim($footer) != "") { $removedlink = trim(str_replace($footerlink, "", $body)); if ($removedlink == "" or strstr($body, $removedlink)) { $body = $removedlink; } $body .= $footer; } if ($footer == "" and $picture != "") { $body .= "\n\n[img]" . $picture . "[/img]\n"; } elseif ($footer == "" and $picture == "") { $body = add_page_info_to_body($body); } if ($no_tags) { return array("body" => $body, "tags" => ""); } $tags_arr = array(); foreach ($item->entities->hashtags as $hashtag) { $url = "#[url=" . $a->get_baseurl() . "/search?tag=" . rawurlencode($hashtag->text) . "]" . $hashtag->text . "[/url]"; $tags_arr["#" . $hashtag->text] = $url; $body = str_replace("#" . $hashtag->text, $url, $body); } foreach ($item->entities->user_mentions as $mention) { $url = "@[url=https://twitter.com/" . rawurlencode($mention->screen_name) . "]" . $mention->screen_name . "[/url]"; $tags_arr["@" . $mention->screen_name] = $url; $body = str_replace("@" . $mention->screen_name, $url, $body); } // it seems as if the entities aren't always covering all mentions. So the rest will be checked here $tags = get_tags($body); if (count($tags)) { foreach ($tags as $tag) { if (strstr(trim($tag), " ")) { continue; } if (strpos($tag, '#') === 0) { if (strpos($tag, '[url=')) { continue; } // don't link tags that are already embedded in links if (preg_match('/\\[(.*?)' . preg_quote($tag, '/') . '(.*?)\\]/', $body)) { continue; } if (preg_match('/\\[(.*?)\\]\\((.*?)' . preg_quote($tag, '/') . '(.*?)\\)/', $body)) { continue; } $basetag = str_replace('_', ' ', substr($tag, 1)); $url = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; $body = str_replace($tag, $url, $body); $tags_arr["#" . $basetag] = $url; continue; } elseif (strpos($tag, '@') === 0) { if (strpos($tag, '[url=')) { continue; } $basetag = substr($tag, 1); $url = '@[url=https://twitter.com/' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; $body = str_replace($tag, $url, $body); $tags_arr["@" . $basetag] = $url; } } } $tags = implode($tags_arr, ","); } return array("body" => $body, "tags" => $tags); }
function statusnet_fetchtimeline($a, $uid) { $ckey = get_pconfig($uid, 'statusnet', 'consumerkey'); $csecret = get_pconfig($uid, 'statusnet', 'consumersecret'); $api = get_pconfig($uid, 'statusnet', 'baseapi'); $otoken = get_pconfig($uid, 'statusnet', 'oauthtoken'); $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret'); $lastid = get_pconfig($uid, 'statusnet', 'lastid'); require_once 'mod/item.php'; require_once 'include/items.php'; // get the application name for the SN app // 1st try personal config, then system config and fallback to the // hostname of the node if neither one is set. $application_name = get_pconfig($uid, 'statusnet', 'application_name'); if ($application_name == "") { $application_name = get_config('statusnet', 'application_name'); } if ($application_name == "") { $application_name = $a->get_hostname(); } $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); $parameters = array("exclude_replies" => true, "trim_user" => true, "contributor_details" => false, "include_rts" => false); $first_time = $lastid == ""; if ($lastid != "") { $parameters["since_id"] = $lastid; } $items = $connection->get('statuses/user_timeline', $parameters); if (!is_array($items)) { return; } $posts = array_reverse($items); if (count($posts)) { foreach ($posts as $post) { if ($post->id > $lastid) { $lastid = $post->id; } if ($first_time) { continue; } if ($post->source == "activity") { continue; } if (is_object($post->retweeted_status)) { continue; } if ($post->in_reply_to_status_id != "") { continue; } if (!stristr($post->source, $application_name)) { $_SESSION["authenticated"] = true; $_SESSION["uid"] = $uid; unset($_REQUEST); $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; //$_REQUEST["source"] = "StatusNet"; $_REQUEST["source"] = $post->source; $_REQUEST["extid"] = NETWORK_STATUSNET; //$_REQUEST["date"] = $post->created_at; $_REQUEST["title"] = ""; $_REQUEST["body"] = add_page_info_to_body($post->text, true); if (is_string($post->place->name)) { $_REQUEST["location"] = $post->place->name; } if (is_string($post->place->full_name)) { $_REQUEST["location"] = $post->place->full_name; } if (is_array($post->geo->coordinates)) { $_REQUEST["coord"] = $post->geo->coordinates[0] . " " . $post->geo->coordinates[1]; } if (is_array($post->coordinates->coordinates)) { $_REQUEST["coord"] = $post->coordinates->coordinates[1] . " " . $post->coordinates->coordinates[0]; } //print_r($_REQUEST); if ($_REQUEST["body"] != "") { logger('statusnet: posting for user ' . $uid); item_post($a); } } } } set_pconfig($uid, 'statusnet', 'lastid', $lastid); }
function diaspora_reshare($importer, $xml, $msg) { logger('diaspora_reshare: init: ' . print_r($xml, true)); $a = get_app(); $guid = notags(unxmlify($xml->guid)); $diaspora_handle = notags(unxmlify($xml->diaspora_handle)); if ($diaspora_handle != $msg['author']) { logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.'); return 202; } $contact = diaspora_get_contact_by_handle($importer['uid'], $diaspora_handle); if (!$contact) { return; } if (!diaspora_post_allow($importer, $contact)) { logger('diaspora_reshare: Ignoring this author: ' . $diaspora_handle . ' ' . print_r($xml, true)); return 202; } $message_id = $diaspora_handle . ':' . $guid; $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", intval($importer['uid']), dbesc($message_id), dbesc($guid)); if (count($r)) { logger('diaspora_reshare: message exists: ' . $guid); return; } $orig_author = notags(unxmlify($xml->root_diaspora_id)); $orig_guid = notags(unxmlify($xml->root_guid)); $source_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/p/' . $orig_guid . '.xml'; $orig_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/posts/' . $orig_guid; $x = fetch_url($source_url); if (!$x) { $x = fetch_url(str_replace('https://', 'http://', $source_url)); } if (!$x) { logger('diaspora_reshare: unable to fetch source url ' . $source_url); return; } logger('diaspora_reshare: source: ' . $x); $x = str_replace(array('<activity_streams-photo>', '</activity_streams-photo>'), array('<asphoto>', '</asphoto>'), $x); $source_xml = parse_xml_string($x, false); if (strlen($source_xml->post->asphoto->objectId) && $source_xml->post->asphoto->objectId != 0 && $source_xml->post->asphoto->image_url) { $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n"; $body = scale_external_images($body, false); } elseif ($source_xml->post->asphoto->image_url) { $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n"; $body = scale_external_images($body); } elseif ($source_xml->post->status_message) { $body = diaspora2bb($source_xml->post->status_message->raw_message); // Checking for embedded pictures if ($source_xml->post->status_message->photo->remote_photo_path and $source_xml->post->status_message->photo->remote_photo_name) { $remote_photo_path = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_path)); $remote_photo_name = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_name)); $body = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n" . $body; logger('diaspora_reshare: embedded picture link found: ' . $body, LOGGER_DEBUG); } $body = scale_external_images($body); // Add OEmbed and other information to the body $body = add_page_info_to_body($body, false, true); } else { // Maybe it is a reshare of a photo that will be delivered at a later time (testing) logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml, true)); $body = ""; //return; } //if(! $body) { // logger('diaspora_reshare: empty body: source= ' . $x); // return; //} $person = find_diaspora_person_by_handle($orig_author); /*if(is_array($person) && x($person,'name') && x($person,'url')) $details = '[url=' . $person['url'] . ']' . $person['name'] . '[/url]'; else $details = $orig_author; $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n";*/ // allocate a guid on our system - we aren't fixing any collisions. // we're ignoring them $g = q("select * from guid where guid = '%s' limit 1", dbesc($guid)); if (!count($g)) { q("insert into guid ( guid ) values ( '%s' )", dbesc($guid)); } $created = unxmlify($xml->created_at); $private = unxmlify($xml->public) == 'false' ? 1 : 0; $datarray = array(); $str_tags = ''; $tags = get_tags($body); if (count($tags)) { foreach ($tags as $tag) { if (strpos($tag, '#') === 0) { if (strpos($tag, '[url=')) { continue; } // don't link tags that are already embedded in links if (preg_match('/\\[(.*?)' . preg_quote($tag, '/') . '(.*?)\\]/', $body)) { continue; } if (preg_match('/\\[(.*?)\\]\\((.*?)' . preg_quote($tag, '/') . '(.*?)\\)/', $body)) { continue; } $basetag = str_replace('_', ' ', substr($tag, 1)); $body = str_replace($tag, '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]', $body); if (strlen($str_tags)) { $str_tags .= ','; } $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; continue; } } } $plink = 'https://' . substr($diaspora_handle, strpos($diaspora_handle, '@') + 1) . '/posts/' . $guid; $datarray['uid'] = $importer['uid']; $datarray['contact-id'] = $contact['id']; $datarray['wall'] = 0; $datarray['network'] = NETWORK_DIASPORA; $datarray['guid'] = $guid; $datarray['uri'] = $datarray['parent-uri'] = $message_id; $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC', 'UTC', $created); $datarray['private'] = $private; $datarray['parent'] = 0; $datarray['plink'] = $plink; $datarray['owner-name'] = $contact['name']; $datarray['owner-link'] = $contact['url']; $datarray['owner-avatar'] = x($contact, 'thumb') ? $contact['thumb'] : $contact['photo']; if (!intval(get_config('system', 'wall-to-wall_share'))) { $prefix = "[share author='" . str_replace(array("'", "[", "]"), array("'", "[", "]"), $person['name']) . "' profile='" . $person['url'] . "' avatar='" . (x($person, 'thumb') ? $person['thumb'] : $person['photo']) . "' link='" . str_replace(array("'", "[", "]"), array("'", "[", "]"), $orig_url) . "']"; $datarray['author-name'] = $contact['name']; $datarray['author-link'] = $contact['url']; $datarray['author-avatar'] = $contact['thumb']; $datarray['body'] = $prefix . $body . "[/share]"; } else { // Let reshared messages look like wall-to-wall posts $datarray['author-name'] = $person['name']; $datarray['author-link'] = $person['url']; $datarray['author-avatar'] = x($person, 'thumb') ? $person['thumb'] : $person['photo']; $datarray['body'] = $body; } $datarray['tag'] = $str_tags; $datarray['app'] = 'Diaspora'; // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible. (testing) $datarray['visible'] = strlen($body) ? 1 : 0; $message_id = item_store($datarray); //if($message_id) { // q("update item set plink = '%s' where id = %d", // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), // intval($message_id) // ); //} return; }