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 feed_import($xml, $importer, &$contact, &$hub) { $a = get_app(); logger("Import Atom/RSS feed", LOGGER_DEBUG); if ($xml == "") { return; } $doc = new DOMDocument(); @$doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); $xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/"); $xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/"); $xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); $xpath->registerNamespace('rss', "http://purl.org/rss/1.0/"); $xpath->registerNamespace('media', "http://search.yahoo.com/mrss/"); $author = array(); // Is it RDF? if ($xpath->query('/rdf:RDF/rss:channel')->length > 0) { //$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:title/text()')->item(0)->nodeValue; if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:description/text()')->item(0)->nodeValue; } $entries = $xpath->query('/rdf:RDF/rss:item'); } // Is it Atom? if ($xpath->query('/atom:feed/atom:entry')->length > 0) { //$self = $xpath->query("/atom:feed/atom:link[@rel='self']")->item(0)->attributes; //if (is_object($self)) // foreach($self AS $attributes) // if ($attributes->name == "href") // $author["author-link"] = $attributes->textContent; //if ($author["author-link"] == "") { // $alternate = $xpath->query("/atom:feed/atom:link[@rel='alternate']")->item(0)->attributes; // if (is_object($alternate)) // foreach($alternate AS $attributes) // if ($attributes->name == "href") // $author["author-link"] = $attributes->textContent; //} $author["author-name"] = $xpath->evaluate('/atom:feed/atom:title/text()')->item(0)->nodeValue; if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/atom:feed/atom:subtitle/text()')->item(0)->nodeValue; } if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue; } //$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue; $author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue; $author["app"] = $xpath->evaluate('/atom:feed/atom:generator/text()')->item(0)->nodeValue; $entries = $xpath->query('/atom:feed/atom:entry'); } // Is it RSS? if ($xpath->query('/rss/channel')->length > 0) { //$author["author-link"] = $xpath->evaluate('/rss/channel/link/text()')->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('/rss/channel/title/text()')->item(0)->nodeValue; //$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue; if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rss/channel/copyright/text()')->item(0)->nodeValue; } if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rss/channel/description/text()')->item(0)->nodeValue; } $author["edited"] = $author["created"] = $xpath->query('/rss/channel/pubDate/text()')->item(0)->nodeValue; $author["app"] = $xpath->evaluate('/rss/channel/generator/text()')->item(0)->nodeValue; $entries = $xpath->query('/rss/channel/item'); } //if ($author["author-link"] == "") $author["author-link"] = $contact["url"]; if ($author["author-name"] == "") { $author["author-name"] = $contact["name"]; } //if ($author["author-avatar"] == "") $author["author-avatar"] = $contact["thumb"]; $author["owner-link"] = $contact["url"]; $author["owner-name"] = $contact["name"]; $author["owner-avatar"] = $contact["thumb"]; $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_FEED; $header["type"] = "remote"; $header["wall"] = 0; $header["origin"] = 0; $header["gravity"] = GRAVITY_PARENT; $header["private"] = 2; $header["verb"] = ACTIVITY_POST; $header["object-type"] = ACTIVITY_OBJ_NOTE; $header["contact-id"] = $contact["id"]; if (!strlen($contact["notify"])) { // one way feed - no remote comment ability $header["last-child"] = 0; } if (!is_object($entries)) { return; } $entrylist = array(); foreach ($entries as $entry) { $entrylist[] = $entry; } foreach (array_reverse($entrylist) as $entry) { $item = array_merge($header, $author); $item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue; if ($item["title"] == "") { $item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue; } if ($item["title"] == "") { $item["title"] = $xpath->evaluate('rss:title/text()', $entry)->item(0)->nodeValue; } $alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes; if (!is_object($alternate)) { $alternate = $xpath->query("atom:link", $entry)->item(0)->attributes; } if (is_object($alternate)) { foreach ($alternate as $attributes) { if ($attributes->name == "href") { $item["plink"] = $attributes->textContent; } } } if ($item["plink"] == "") { $item["plink"] = $xpath->evaluate('link/text()', $entry)->item(0)->nodeValue; } if ($item["plink"] == "") { $item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue; } $item["plink"] = original_url($item["plink"]); $item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue; if ($item["uri"] == "") { $item["uri"] = $xpath->evaluate('guid/text()', $entry)->item(0)->nodeValue; } if ($item["uri"] == "") { $item["uri"] = $item["plink"]; } $item["parent-uri"] = $item["uri"]; $published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; if ($published == "") { $published = $xpath->query('pubDate/text()', $entry)->item(0)->nodeValue; } if ($published == "") { $published = $xpath->query('dc:date/text()', $entry)->item(0)->nodeValue; } $updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; if ($updated == "") { $updated = $published; } if ($published != "") { $item["created"] = $published; } if ($updated != "") { $item["edited"] = $updated; } $creator = $xpath->query('author/text()', $entry)->item(0)->nodeValue; if ($creator == "") { $creator = $xpath->query('atom:author/atom:name/text()', $entry)->item(0)->nodeValue; } if ($creator == "") { $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue; } if ($creator != "") { $item["author-name"] = $creator; } if ($pubDate != "") { $item["edited"] = $item["created"] = $pubDate; } $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue; if ($creator != "") { $item["author-name"] = $creator; } //$item["object"] = $xml; $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')", intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN)); if ($r) { logger("Item with uri " . $item["uri"] . " for user " . $importer["uid"] . " already existed under id " . $r[0]["id"], LOGGER_DEBUG); continue; } // To-Do? // <category>Ausland</category> // <media:thumbnail width="152" height="76" url="http://www.taz.de/picture/667875/192/14388767.jpg"/> $attachments = array(); $enclosures = $xpath->query("enclosure", $entry); foreach ($enclosures as $enclosure) { $href = ""; $length = ""; $type = ""; $title = ""; foreach ($enclosure->attributes as $attributes) { if ($attributes->name == "url") { $href = $attributes->textContent; } elseif ($attributes->name == "length") { $length = $attributes->textContent; } elseif ($attributes->name == "type") { $type = $attributes->textContent; } } if (strlen($item["attach"])) { $item["attach"] .= ','; } $attachments[] = array("link" => $href, "type" => $type, "length" => $length); $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '"[/attach]'; } if ($contact["fetch_further_information"]) { $preview = ""; // Handle enclosures and treat them as preview picture foreach ($attachments as $attachment) { if ($attachment["type"] == "image/jpeg") { $preview = $attachment["link"]; } } $item["body"] = $item["title"] . add_page_info($item["plink"], false, $preview, $contact["fetch_further_information"] == 2, $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], false, $preview, $contact["fetch_further_information"] == 2, $contact["ffi_keyword_blacklist"]); $item["title"] = ""; $item["object-type"] = ACTIVITY_OBJ_BOOKMARK; unset($item["attach"]); } else { $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue); if ($body == "") { $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue); } if ($body == "") { $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue); } if ($body == "") { $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue); } // remove the content of the title if it is identically to the body // This helps with auto generated titles e.g. from tumblr if (title_is_body($item["title"], $body)) { $item["title"] = ""; } $item["body"] = html2bbcode($body); } logger("Stored feed: " . print_r($item, true), LOGGER_DEBUG); $notify = item_is_remote_self($contact, $item); $id = item_store($item, false, $notify); //print_r($item); logger("Feed for contact " . $contact["url"] . " stored under id " . $id); } }