]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Bugfix: Feeds weren't imported if a post with the same URI existed.
[friendica.git] / include / items.php
index fa370c82a8ef2d1c06647496d0019376430e2918..1506e737bae4346a28ca9a103d8a4335bc1fa363 100644 (file)
@@ -9,13 +9,16 @@ require_once('include/tags.php');
 require_once('include/files.php');
 require_once('include/text.php');
 require_once('include/email.php');
-//require_once('include/ostatus_conversation.php');
 require_once('include/threads.php');
 require_once('include/socgraph.php');
 require_once('include/plaintext.php');
 require_once('include/ostatus.php');
+require_once('include/feed.php');
 require_once('mod/share.php');
 
+require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
+
+
 function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, $forpubsub = false) {
 
 
@@ -39,7 +42,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0,
 
        // default permissions - anonymous user
 
-       $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid`  = '' AND `deny_gid`  = '' ";
+       $sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' ";
 
        $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`
                FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
@@ -119,9 +122,10 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0,
 
        // Include answers to status.net posts in pubsub feeds
        if($forpubsub) {
-               $sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` ";
-               $visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND `thread`.`network`='%s')",
-                                       dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS));
+               $sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
+                               LEFT JOIN `item` AS `thritem` ON `thritem`.`uri`=`item`.`thr-parent` AND `thritem`.`uid`=`item`.`uid`";
+               $visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND ((`thread`.`network`='%s') OR (`thritem`.`network` = '%s')))",
+                                       dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS));
                $date_field = "`received`";
                $sql_order = "`item`.`received` DESC";
        } else {
@@ -481,7 +485,6 @@ function get_atom_elements($feed, $item, $contact = array()) {
        // 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.
 
-       // Search for ostatus conversation url
        $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) {
@@ -886,23 +889,6 @@ function get_atom_elements($feed, $item, $contact = array()) {
                }
        }
 
-//     // Search for ostatus conversation url
-//     $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"];
-//
-//     if (is_array($links)) {
-//             foreach ($links as $link) {
-//                     $conversation = array_shift($link["attribs"]);
-//
-//                     if ($conversation["rel"] == "ostatus:conversation") {
-//                             $res["ostatus_conversation"] = ostatus_convert_href($conversation["href"]);
-//                             logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]);
-//                     //} elseif ($conversation["rel"] == "alternate") {
-//                     //      $res["plink"] = $conversation["href"];
-//                     //      logger('get_atom_elements: found plink '.$res["plink"]);
-//                     }
-//             };
-//     }
-
        if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) {
                $preview = "";
 
@@ -984,7 +970,7 @@ function query_page_info($url, $no_photos = false, $photo = "", $keywords = fals
        $data = Cache::get("parse_url:".$url);
        if (is_null($data)){
                $data = parseurl_getsiteinfo($url, true);
-               Cache::set("parse_url:".$url,serialize($data));
+               Cache::set("parse_url:".$url,serialize($data), CACHE_DAY);
        } else
                $data = unserialize($data);
 
@@ -1111,6 +1097,48 @@ function add_guid($item) {
                dbesc($item["uri"]), dbesc($item["network"]));
 }
 
+// Adds a "lang" specification in a "postopts" element of given $arr,
+// if possible and not already present.
+// Expects "body" element to exist in $arr.
+// TODO: add a parameter to request forcing override
+function item_add_language_opt(&$arr) {
+
+       if (version_compare(PHP_VERSION, '5.3.0', '<')) return; // LanguageDetect.php not available ?
+
+       if ( x($arr, 'postopts') )
+       {
+               if ( strstr($arr['postopts'], 'lang=') )
+               {
+                       // do not override
+                       // TODO: add parameter to request overriding
+                       return;
+               }
+               $postopts = $arr['postopts'];
+       }
+       else
+       {
+               $postopts = "";
+       }
+
+       require_once('library/langdet/Text/LanguageDetect.php');
+       $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
+       $l = new Text_LanguageDetect;
+       //$lng = $l->detectConfidence($naked_body);
+       //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+       $lng = $l->detect($naked_body, 3);
+
+       if (sizeof($lng) > 0) {
+               if ($postopts != "") $postopts .= '&'; // arbitrary separator, to be reviewed
+               $postopts .= 'lang=';
+               $sep = "";
+               foreach ($lng as $language => $score) {
+                       $postopts .= $sep . $language.";".$score;
+                       $sep = ':';
+               }
+               $arr['postopts'] = $postopts;
+       }
+}
+
 function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) {
 
        // If it is a posting where users should get notifications, then define it as wall posting
@@ -1139,15 +1167,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                        $arr['plink'] = ostatus_convert_href($arr['uri']);
        }
 
-//     // if an OStatus conversation url was passed in, it is stored and then
-//     // removed from the array.
-//     $ostatus_conversation = null;
-
-//     if (isset($arr["ostatus_conversation"])) {
-//             $ostatus_conversation = $arr["ostatus_conversation"];
-//             unset($arr["ostatus_conversation"]);
-//     }
-
        if(x($arr, 'gravity'))
                $arr['gravity'] = intval($arr['gravity']);
        elseif($arr['parent-uri'] === $arr['uri'])
@@ -1192,12 +1211,15 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        // If there is no guid then take the same guid that was taken before for the same plink
        if ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "") AND (trim($arr['network']) != "")) {
                logger('item_store: checking for an existing guid for plink '.$arr['plink'], LOGGER_DEBUG);
-               $r = q("SELECT `guid` FROM `guid` WHERE `plink` = '%s' AND `network` = '%s' LIMIT 1",
+               $r = q("SELECT `guid`, `uri` FROM `guid` WHERE `plink` = '%s' AND `network` = '%s' LIMIT 1",
                        dbesc(trim($arr['plink'])), dbesc(trim($arr['network'])));
 
                if(count($r)) {
                        $arr['guid'] = $r[0]["guid"];
                        logger('item_store: found guid '.$arr['guid'].' for plink '.$arr['plink'], LOGGER_DEBUG);
+
+                       if ($r[0]["uri"] != $arr['uri'])
+                       logger('Different uri for same guid: '.$arr['uri'].' and '.$r[0]["uri"].' - this shouldnt happen!', LOGGER_DEBUG);
                }
        }
 
@@ -1206,32 +1228,16 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
        //      $arr['body'] = strip_tags($arr['body']);
 
+       item_add_language_opt($arr);
 
-       if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
-               require_once('library/langdet/Text/LanguageDetect.php');
-               $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
-               $l = new Text_LanguageDetect;
-               //$lng = $l->detectConfidence($naked_body);
-               //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
-               $lng = $l->detect($naked_body, 3);
-
-               if (sizeof($lng) > 0) {
-                       $postopts = "";
-
-                       foreach ($lng as $language => $score) {
-                               if ($postopts == "")
-                                       $postopts = "lang=";
-                               else
-                                       $postopts .= ":";
-
-                               $postopts .= $language.";".$score;
-                       }
-                       $arr['postopts'] = $postopts;
-               }
-       }
+       if ($notify)
+               $guid_prefix = "";
+       else
+               $guid_prefix = $arr['network'];
 
        $arr['wall']          = ((x($arr,'wall'))          ? intval($arr['wall'])                : 0);
-       $arr['uri']           = ((x($arr,'uri'))           ? notags(trim($arr['uri']))           : random_string());
+       $arr['guid']          = ((x($arr,'guid'))          ? notags(trim($arr['guid']))          : get_guid(32, $guid_prefix));
+       $arr['uri']           = ((x($arr,'uri'))           ? notags(trim($arr['uri']))           : $arr['guid']);
        $arr['extid']         = ((x($arr,'extid'))         ? notags(trim($arr['extid']))         : '');
        $arr['author-name']   = ((x($arr,'author-name'))   ? notags(trim($arr['author-name']))   : '');
        $arr['author-link']   = ((x($arr,'author-link'))   ? notags(trim($arr['author-link']))   : '');
@@ -1269,7 +1275,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        $arr['app']           = ((x($arr,'app'))           ? notags(trim($arr['app']))           : '');
        $arr['origin']        = ((x($arr,'origin'))        ? intval($arr['origin'])              : 0 );
        $arr['network']       = ((x($arr,'network'))       ? trim($arr['network'])               : '');
-       $arr['guid']          = ((x($arr,'guid'))          ? notags(trim($arr['guid']))          : get_guid(32, $arr['network']));
        $arr['postopts']      = ((x($arr,'postopts'))      ? trim($arr['postopts'])              : '');
        $arr['resource-id']   = ((x($arr,'resource-id'))   ? trim($arr['resource-id'])           : '');
        $arr['event-id']      = ((x($arr,'event-id'))      ? intval($arr['event-id'])            : 0 );
@@ -1282,11 +1287,24 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        }
 
        if ($arr['network'] == "") {
-               $r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                       intval($arr['contact-id']),
+               $r = q("SELECT `network` FROM `contact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' AND `uid` = %d LIMIT 1",
+                       dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
+                       dbesc(normalise_link($arr['author-link'])),
                        intval($arr['uid'])
                );
 
+               if(!count($r))
+                       $r = q("SELECT `network` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' LIMIT 1",
+                               dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
+                               dbesc(normalise_link($arr['author-link']))
+                       );
+
+               if(!count($r))
+                       $r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+                               intval($arr['contact-id']),
+                               intval($arr['uid'])
+                       );
+
                if(count($r))
                        $arr['network'] = $r[0]["network"];
 
@@ -1444,7 +1462,10 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        // Fill the cache field
        put_item_in_cache($arr);
 
-       call_hooks('post_remote',$arr);
+       if ($notify)
+               call_hooks('post_local',$arr);
+       else
+               call_hooks('post_remote',$arr);
 
        if(x($arr,'cancel')) {
                logger('item_store: post cancelled by plugin.');
@@ -1468,9 +1489,10 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        $arr = $unescaped;
 
        // find the item we just created
-       $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ",
+       $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s' ORDER BY `id` ASC ",
                dbesc($arr['uri']),
-               intval($arr['uid'])
+               intval($arr['uid']),
+               dbesc($arr['network'])
        );
 
        if(count($r)) {
@@ -1537,10 +1559,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                intval($current_post)
        );
 
-       // Complete ostatus threads
-       //if ($ostatus_conversation)
-       //      complete_conversation($current_post, $ostatus_conversation);
-
        $arr['id'] = $current_post;
        $arr['parent'] = $parent_id;
        $arr['allow_cid'] = $allow_cid;
@@ -1594,7 +1612,10 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
 
                $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
                if (count($r) == 1) {
-                       call_hooks('post_remote_end', $r[0]);
+                       if ($notify)
+                               call_hooks('post_local_end', $r[0]);
+                       else
+                               call_hooks('post_remote_end', $r[0]);
                } else
                        logger('item_store: new item not found in DB, id ' . $current_post);
        }
@@ -2011,12 +2032,13 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if($contact['duplex'] && $contact['issued-id'])
                $idtosend = '1:' . $orig_id;
 
-       $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
 
-       $rino_enable = get_config('system','rino_encrypt');
+       $rino = get_config('system','rino_encrypt');
+       $rino = intval($rino);
+       // use RINO1 if mcrypt isn't installed and RINO2 was selected
+       if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1;
 
-       if(! $rino_enable)
-               $rino = 0;
+       logger("Local rino version: ". $rino, LOGGER_DEBUG);
 
        $ssl_val = intval(get_config('system','ssl_policy'));
        $ssl_policy = '';
@@ -2034,7 +2056,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
                        break;
        }
 
-       $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
+       $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino='.$rino : '');
 
        logger('dfrn_deliver: ' . $url);
 
@@ -2065,9 +2087,11 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        $challenge    = hex2bin((string) $res->challenge);
        $perm         = (($res->perm) ? $res->perm : null);
        $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
-       $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
+       $rino_remote_version = intval($res->rino);
        $page         = (($owner['page-flags'] == PAGE_COMMUNITY) ? 1 : 0);
 
+       logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG);
+
        if($owner['page-flags'] == PAGE_PRVGROUP)
                $page = 2;
 
@@ -2126,11 +2150,46 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if($page)
                $postvars['page'] = $page;
 
-       if($rino && $rino_allowed && (! $dissolve)) {
-               $key = substr(random_string(),0,16);
-               $data = bin2hex(aes_encrypt($postvars['data'],$key));
-               $postvars['data'] = $data;
-               logger('rino: sent key = ' . $key, LOGGER_DEBUG);
+
+       if($rino>0 && $rino_remote_version>0 && (! $dissolve)) {
+               logger('rino version: '. $rino_remote_version);
+
+               switch($rino_remote_version) {
+                       case 1:
+                               // Deprecated rino version!
+                               $key = substr(random_string(),0,16);
+                               $data = aes_encrypt($postvars['data'],$key);
+                               break;
+                       case 2:
+                               // RINO 2 based on php-encryption
+                               try {
+                                       $key = Crypto::createNewRandomKey();
+                               } catch (CryptoTestFailed $ex) {
+                                       logger('Cannot safely create a key');
+                                       return -1;
+                               } catch (CannotPerformOperation $ex) {
+                                       logger('Cannot safely create a key');
+                                       return -1;
+                               }
+                               try {
+                                       $data = Crypto::encrypt($postvars['data'], $key);
+                               } catch (CryptoTestFailed $ex) {
+                                       logger('Cannot safely perform encryption');
+                                       return -1;
+                               } catch (CannotPerformOperation $ex) {
+                                       logger('Cannot safely perform encryption');
+                                       return -1;
+                               }
+                               break;
+                       default:
+                               logger("rino: invalid requested verision '$rino_remote_version'");
+                               return -1;
+               }
+
+               $postvars['rino'] = $rino_remote_version;
+               $postvars['data'] = bin2hex($data);
+
+               #logger('rino: sent key = ' . $key, LOGGER_DEBUG);
 
 
                if($dfrn_version >= 2.1) {
@@ -2158,6 +2217,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
                $postvars['key'] = bin2hex($postvars['key']);
        }
 
+
        logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
 
        $xml = post_url($contact['notify'],$postvars);
@@ -2239,16 +2299,20 @@ function edited_timestamp_is_newer($existing, $update) {
 function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) {
        if ($contact['network'] === NETWORK_OSTATUS) {
                if ($pass < 2) {
-                       // Test - remove before flight
-                       //$tempfile = tempnam(get_temppath(), "ostatus");
-                       //file_put_contents($tempfile, $xml);
-
                        logger("Consume OStatus messages ", LOGGER_DEBUG);
                        ostatus_import($xml,$importer,$contact, $hub);
                }
                return;
        }
 
+       if ($contact['network'] === NETWORK_FEED) {
+               if ($pass < 2) {
+                       logger("Consume feeds", LOGGER_DEBUG);
+                       feed_import($xml,$importer,$contact, $hub);
+               }
+               return;
+       }
+
        require_once('library/simplepie/simplepie.inc');
        require_once('include/contact_selectors.php');
 
@@ -2957,7 +3021,7 @@ function item_is_remote_self($contact, &$datarray) {
                if ($contact['network'] != NETWORK_FEED) {
                        $datarray["guid"] = get_guid(32);
                        unset($datarray["plink"]);
-                       $datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid']);
+                       $datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid'], $datarray["guid"]);
                        $datarray["parent-uri"] = $datarray["uri"];
                        $datarray["extid"] = $contact['network'];
                        $urlpart = parse_url($datarray2['author-link']);
@@ -2966,9 +3030,6 @@ function item_is_remote_self($contact, &$datarray) {
                        $datarray['private'] = 0;
        }
 
-       //if (!isset($datarray["app"]) OR ($datarray["app"] == ""))
-       //      $datarray["app"] = network_to_name($contact['network']);
-
        if ($contact['network'] != NETWORK_FEED) {
                // Store the original post
                $r = item_store($datarray2, false, false);
@@ -4148,9 +4209,12 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
        $name = notags(trim($datarray['author-name']));
        $photo = notags(trim($datarray['author-avatar']));
 
-       $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
-       if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'])
-               $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
+       if (is_object($item)) {
+               $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
+               if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'])
+                       $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
+       } else
+               $nick = $item;
 
        if(is_array($contact)) {
                if(($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
@@ -4288,7 +4352,7 @@ function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') {
 
        logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: '  . $push_url . ' with verifier ' . $verify_token);
 
-       if(! strlen($contact['hub-verify'])) {
+       if(!strlen($contact['hub-verify']) OR ($contact['hub-verify'] != $verify_token)) {
                $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d",
                        dbesc($verify_token),
                        intval($contact['id'])
@@ -4392,8 +4456,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
                $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
 
        if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
+               $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
                $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
-               $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' .  xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n";
+               $o .= '<thr:in-reply-to ref="'.xmlify($parent_item).'" type="text/html" href="'.xmlify($a->get_baseurl().'/display/'.$parent[0]['guid']).'" />'."\r\n";
        }
 
        $htmlbody = $body;
@@ -4401,7 +4466,6 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
        if ($item['title'] != "")
                $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
 
-       //$htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7);
        $htmlbody = bbcode($htmlbody, false, false, 7);
 
        $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
@@ -4410,8 +4474,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
        $o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
        $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
        $o .= '<content type="' . $type . '" >' . xmlify((($type === 'html') ? $htmlbody : $body)) . '</content>' . "\r\n";
-       $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
-
+       $o .= '<link rel="alternate" type="text/html" href="'.xmlify($a->get_baseurl().'/display/'.$item['guid']).'" />'."\r\n";
 
        $o .= '<status_net notice_id="'.$item['id'].'"></status_net>'."\r\n";