]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
template proc: avoid a notice and allow template name to include to be passed with...
[friendica.git] / include / items.php
old mode 100644 (file)
new mode 100755 (executable)
index 9becb9f..250d023
@@ -118,7 +118,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
-               WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`parent` != 0 
+               WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0 
                AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
                $sql_extra
@@ -295,6 +295,11 @@ function get_atom_elements($feed,$item) {
        $res['body'] = unxmlify($item->get_content());
        $res['plink'] = unxmlify($item->get_link(0));
 
+       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
 
@@ -303,7 +308,7 @@ function get_atom_elements($feed,$item) {
        if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
                $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
                foreach($base as $link) {
-                       if(! $res['author-avatar']) {
+                       if(!x($res, 'author-avatar') || !$res['author-avatar']) {
                                if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
                                        $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
                        }
@@ -318,7 +323,7 @@ function get_atom_elements($feed,$item) {
                        foreach($base as $link) {
                                if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
                                        $res['author-link'] = unxmlify($link['attribs']['']['href']);
-                               if(! $res['author-avatar']) {
+                               if(!x($res, 'author-avatar') || !$res['author-avatar']) {
                                        if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
                                                $res['author-avatar'] = unxmlify($link['attribs']['']['href']);
                                }
@@ -414,6 +419,8 @@ function get_atom_elements($feed,$item) {
 
        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']);
@@ -496,7 +503,7 @@ function get_atom_elements($feed,$item) {
                $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
 
                foreach($base as $link) {
-                       if(! $res['owner-avatar']) {
+                       if(!x($res, 'owner-avatar') || !$res['owner-avatar']) {
                                if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')                 
                                        $res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
                        }
@@ -807,6 +814,11 @@ function item_store($arr,$force_parent = false) {
 
        call_hooks('post_remote',$arr);
 
+       if(x($arr,'cancel')) {
+               logger('item_store: post cancelled by plugin.');
+               return 0;
+       }
+
        dbesc_array($arr);
 
        logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
@@ -893,7 +905,7 @@ function item_store($arr,$force_parent = false) {
                );
        }
 
-       tgroup_deliver($arr['uid'],$current_post);
+       tag_deliver($arr['uid'],$current_post);
 
        return $current_post;
 }
@@ -911,22 +923,22 @@ function get_item_contact($item,$contacts) {
 }
 
 
-function tgroup_deliver($uid,$item_id) {
-
+function tag_deliver($uid,$item_id) {
 
-       // setup a second delivery chain for forum/community posts if appropriate
+       // look for mention tags and setup a second delivery chain for forum/community posts if appropriate
 
        $a = get_app();
 
-       $deliver_to_tgroup = false;
+       $mention = false;
 
-       $u = q("select * from user where uid = %d and `page-flags` = %d limit 1",
-               intval($uid),
-               intval(PAGE_COMMUNITY)
+       $u = q("select uid, nickname, language, username, email, `page-flags`, `notify-flags` from user where uid = %d limit 1",
+               intval($uid)
        );
        if(! count($u))
                return;
 
+       $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
+
        $i = q("select * from item where id = %d and uid = %d limit 1",
                intval($item_id),
                intval($uid)
@@ -936,32 +948,68 @@ function tgroup_deliver($uid,$item_id) {
 
        $item = $i[0];
 
-       // prevent delivery looping - only proceed
-       // if the message originated elsewhere and is a top-level post
-
-       if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent']))
-               return;
+       $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
 
+       // Diaspora uses their own hardwired link URL in @-tags
+       // instead of the one we supply with webfinger
 
-       $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
+       $dlink = normalise_link($a->get_baseurl() . '/u/' . $u[0]['nickname']);
 
-       $cnt = preg_match_all('/\@\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER);
+       $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER);
        if($cnt) {
                foreach($matches as $mtch) {
-                       if(link_compare($link,$mtch[1])) {
-                               $deliver_to_tgroup = true;
-                               logger('tgroup_deliver: local group mention found: ' . $mtch[2]);
+                       if(link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) {
+                               $mention = true;
+                               logger('tag_deliver: mention found: ' . $mtch[2]);
                        }
                }
        }
 
-       if(! $deliver_to_tgroup)
+       if(! $mention)
+               return;
+
+       // send a notification
+
+       require_once('include/enotify.php');
+       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'          => $u[0]['uid'],
+               'item'         => $item,
+               'link'         => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'],
+               'source_name'  => $item['author-name'],
+               'source_link'  => $item['author-link'],
+               'source_photo' => $item['author-avatar'],
+               'verb'         => ACTIVITY_TAG,
+               'otype'        => 'item'
+       ));
+
+       if(! $community_page)
+               return;
+
+       // tgroup delivery - setup a second delivery chain
+       // prevent delivery looping - only proceed
+       // if the message originated elsewhere and is a top-level post
+
+       if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent']))
                return;
 
        // now change this copy of the post to a forum head message and deliver to all the tgroup members
 
 
-       q("update item set wall = 1, origin = 1, forum_mode = 1 where id = %d limit 1",
+       $c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1",
+               intval($u[0]['uid'])
+       );
+       if(! count($c))
+               return;
+
+       q("update item set wall = 1, origin = 1, forum_mode = 1, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s'  where id = %d limit 1",
+               dbesc($c[0]['name']),
+               dbesc($c[0]['url']),
+               dbesc($c[0]['thumb']),
                intval($item_id)
        );
 
@@ -978,8 +1026,8 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 
        $a = get_app();
 
-       if((! strlen($contact['issued-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
-               return 3;
+//     if((! strlen($contact['issued-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
+//             return 3;
 
        $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
 
@@ -1030,7 +1078,9 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        $final_dfrn_id = '';
 
 
-       if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+       if(($contact['duplex'] && strlen($contact['pubkey'])) 
+               || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
+               || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) {
                openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
                openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
        }
@@ -1073,7 +1123,10 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 
 
                if($dfrn_version >= 2.1) {      
-                       if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+                       if(($contact['duplex'] && strlen($contact['pubkey'])) 
+                               || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
+                               || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) {
+
                                openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
                        }
                        else {
@@ -1255,12 +1308,28 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
        }
 
        if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) {
-               q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
+               $r = q("select * from contact where uid = %d and id = %d limit 1",
+                       intval($contact['uid']),
+                       intval($contact['id'])
+               );
+
+               $x = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
                        dbesc(notags(trim($new_name))),
                        dbesc(datetime_convert()),
                        intval($contact['uid']),
                        intval($contact['id'])
                );
+
+               // do our best to update the name on content items
+
+               if(count($r)) {
+                       q("update item set `author-name` = '%s' where `author-name` = '%s' and `author-link` = '%s' and uid = %d",
+                               dbesc(notags(trim($new_name))),
+                               dbesc($r[0]['name']),
+                               dbesc($r[0]['url']),
+                               intval($contact['uid'])
+                       );
+               }
        }
 
        if(strlen($birthday)) {
@@ -1402,7 +1471,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                                                intval($item['uid'])
                                                        );
                                                        // who is the last child now? 
-                                                       $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d 
+                                                       $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `moderated` = 0 AND `uid` = %d 
                                                                ORDER BY `created` DESC LIMIT 1",
                                                                        dbesc($item['parent-uri']),
                                                                        intval($importer['uid'])
@@ -1452,13 +1521,18 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                $item_id  = $item->get_id();
                                $datarray = get_atom_elements($feed,$item);
 
-                               if(! x($datarray,'author-name'))
+
+                               if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
                                        $datarray['author-name'] = $contact['name'];
-                               if(! x($datarray,'author-link'))
+                               if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN))
                                        $datarray['author-link'] = $contact['url'];
-                               if(! x($datarray,'author-avatar'))
+                               if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN))
                                        $datarray['author-avatar'] = $contact['thumb'];
 
+                               if((! x($datarray,'author-name')) || (! x($datarray,'author-link'))) {
+                                       logger('consume_feed: no author information! ' . print_r($datarray,true));
+                                       continue;
+                               }
 
                                $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($item_id),
@@ -1469,7 +1543,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 
                                if(count($r)) {
                                        if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
-                                               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                               $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                                       dbesc($datarray['title']),
                                                        dbesc($datarray['body']),
                                                        dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
                                                        dbesc($item_id),
@@ -1497,8 +1572,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                }
 
                                $force_parent = false;
-                               if($contact['network'] === NETWORK_OSTATUS) {
-                                       $force_parent = true;
+                               if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
+                                       if($contact['network'] === NETWORK_OSTATUS)
+                                               $force_parent = true;
                                        if(strlen($datarray['title']))
                                                unset($datarray['title']);
                                        $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
@@ -1559,14 +1635,19 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                $datarray = get_atom_elements($feed,$item);
 
                                if(is_array($contact)) {
-                                       if(! x($datarray,'author-name'))
+                                       if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
                                                $datarray['author-name'] = $contact['name'];
-                                       if(! x($datarray,'author-link'))
+                                       if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN))
                                                $datarray['author-link'] = $contact['url'];
-                                       if(! x($datarray,'author-avatar'))
+                                       if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN))
                                                $datarray['author-avatar'] = $contact['thumb'];
                                }
 
+                               if((! x($datarray,'author-name')) || (! x($datarray,'author-link'))) {
+                                       logger('consume_feed: no author information! ' . print_r($datarray,true));
+                                       continue;
+                               }
+
                                // special handling for events
 
                                if((x($datarray,'object-type')) && ($datarray['object-type'] === ACTIVITY_OBJ_EVENT)) {
@@ -1599,7 +1680,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 
                                if(count($r)) {
                                        if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
-                                               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                               $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                                       dbesc($datarray['title']),
                                                        dbesc($datarray['body']),
                                                        dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
                                                        dbesc($item_id),
@@ -1645,7 +1727,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                if(! is_array($contact))
                                        return;
 
-                               if($contact['network'] === NETWORK_OSTATUS || stristr($permalink,'twitter.com')) {
+                               if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
                                        if(strlen($datarray['title']))
                                                unset($datarray['title']);
                                        $datarray['last-child'] = 1;
@@ -1788,7 +1870,21 @@ function local_delivery($importer,$data) {
                        intval(0)
                );
 
-               // TODO - send email notify (which may require a new notification preference)
+               notification(array(
+                       'type'         => NOTIFY_SUGGEST,
+                       'notify_flags' => $importer['notify-flags'],
+                       'language'     => $importer['language'],
+                       'to_name'      => $importer['username'],
+                       'to_email'     => $importer['email'],
+                       'uid'          => $importer['importer_uid'],
+                       'item'         => $fsugg,
+                       'link'         => $a->get_baseurl() . '/notifications/intros',
+                       'source_name'  => $importer['name'],
+                       'source_link'  => $importer['url'],
+                       'source_photo' => $importer['photo'],
+                       'verb'         => ACTIVITY_REQ_FRIEND,
+                       'otype'        => 'intro'
+               ));
 
                return 0;
        }
@@ -1832,10 +1928,13 @@ function local_delivery($importer,$data) {
                        'language' => $importer['language'],
                        'to_name' => $importer['username'],
                        'to_email' => $importer['email'],
+                       'uid' => $importer['importer_uid'],
                        'item' => $msg,
                        'source_name' => $msg['from-name'],
                        'source_link' => $importer['url'],
                        'source_photo' => $importer['thumb'],
+                       'verb' => ACTIVITY_POST,
+                       'otype' => 'mail'
                );
                        
                notification($notif_params);
@@ -1968,13 +2067,12 @@ function local_delivery($importer,$data) {
                }
 
                if($is_reply) {
-
                        $community = false;
 
                        if($importer['page-flags'] == PAGE_COMMUNITY) {
                                $sql_extra = '';
                                $community = true;
-                               logger('local_delivery: community reply');
+                               logger('local_delivery: possible community reply');
                        }
                        else
                                $sql_extra = " and contact.self = 1 and item.wall = 1 ";
@@ -1982,7 +2080,9 @@ function local_delivery($importer,$data) {
                        // was the top-level post for this reply written by somebody on this site? 
                        // Specifically, the recipient? 
 
-                       $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, 
+                       $is_a_remote_comment = false;
+
+                       $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`, 
                                `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` 
                                LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` 
                                WHERE `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s'
@@ -1993,16 +2093,29 @@ function local_delivery($importer,$data) {
                                dbesc($parent_uri),
                                intval($importer['importer_uid'])
                        );
+                       if($r && count($r))
+                               $is_a_remote_comment = true;                    
+
+                       // Does this have the characteristics of a community comment?
+                       // If it's a reply to a wall post on a community page it's a 
+                       // valid community comment. Also forum_mode makes it valid for sure. 
+                       // If neither, it's not.
+
+                       if($is_a_remote_comment && $community) {
+                               if((! $r[0]['forum_mode']) && (! $r[0]['wall'])) {
+                                       $is_a_remote_comment = false;
+                                       logger('local_delivery: not a community reply');
+                               }
+                       }
 
-                       if($r && count($r)) {   
-
+                       if($is_a_remote_comment) {
                                logger('local_delivery: received remote comment');
                                $is_like = false;
                                // remote reply to our post. Import and then notify everybody else.
                                $datarray = get_atom_elements($feed,$item);
 
 
-               // TODO: make this next part work against both delivery threads of a community post
+                               // TODO: make this next part work against both delivery threads of a community post
 
 //                             if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) {
 //                                     logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] ); 
@@ -2102,16 +2215,22 @@ function local_delivery($importer,$data) {
                                                                'language'     => $importer['language'],
                                                                'to_name'      => $importer['username'],
                                                                'to_email'     => $importer['email'],
+                                                               'uid'          => $importer['importer_uid'],
                                                                'item'         => $datarray,
                                                                'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
                                                                'source_name'  => stripslashes($datarray['author-name']),
                                                                'source_link'  => $datarray['author-link'],
                                                                'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) 
-                                                                       ? $importer['thumb'] : $datarray['author-avatar'])
+                                                                       ? $importer['thumb'] : $datarray['author-avatar']),
+                                                               'verb'         => ACTIVITY_POST,
+                                                               'otype'        => 'item',
+                                                               'parent'       => $parent,
+
                                                        ));
 
                                                }
                                        }
+
                                        return 0;
                                        // NOTREACHED
                                }
@@ -2132,7 +2251,8 @@ function local_delivery($importer,$data) {
 
                                if(count($r)) {
                                        if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
-                                               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                               $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                                       dbesc($datarray['title']),
                                                        dbesc($datarray['body']),
                                                        dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
                                                        dbesc($item_id),
@@ -2198,7 +2318,7 @@ function local_delivery($importer,$data) {
                        
                                if($datarray['type'] != 'activity') {
 
-                                       $myconv = q("SELECT `author-link`, `author-avatar` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
+                                       $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
                                                dbesc($parent_uri),
                                                intval($importer['importer_uid'])
                                        );
@@ -2211,6 +2331,8 @@ function local_delivery($importer,$data) {
                                                                continue;
 
                                                        require_once('include/enotify.php');
+                                                       
+                                                       $conv_parent = $conv['parent'];
 
                                                        notification(array(
                                                                'type'         => NOTIFY_COMMENT,
@@ -2218,12 +2340,17 @@ function local_delivery($importer,$data) {
                                                                'language'     => $importer['language'],
                                                                'to_name'      => $importer['username'],
                                                                'to_email'     => $importer['email'],
+                                                               'uid'          => $importer['importer_uid'],
                                                                'item'         => $datarray,
                                                                'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
                                                                'source_name'  => stripslashes($datarray['author-name']),
                                                                'source_link'  => $datarray['author-link'],
                                                                'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) 
-                                                                       ? $importer['thumb'] : $datarray['author-avatar'])
+                                                                       ? $importer['thumb'] : $datarray['author-avatar']),
+                                                               'verb'         => ACTIVITY_POST,
+                                                               'otype'        => 'item',
+                                                               'parent'       => $conv_parent,
+
                                                        ));
 
                                                        break;
@@ -2271,7 +2398,8 @@ function local_delivery($importer,$data) {
 
                        if(count($r)) {
                                if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
-                                       $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                       $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                               dbesc($datarray['title']),
                                                dbesc($datarray['body']),
                                                dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
                                                dbesc($item_id),
@@ -2296,7 +2424,7 @@ function local_delivery($importer,$data) {
                        // This is my contact on another system, but it's really me.
                        // Turn this into a wall post.
 
-                       if($contact['remote_self'])
+                       if($importer['remote_self'])
                                $datarray['wall'] = 1;
 
                        $datarray['parent-uri'] = $item_id;
@@ -2722,6 +2850,9 @@ function item_expire($uid,$days) {
 function drop_items($items) {
        $uid = 0;
 
+       if((! local_user()) && (! $remote_user()))
+               return;
+
        if(count($items)) {
                foreach($items as $item) {
                        $owner = drop_item($item,false);
@@ -2764,7 +2895,7 @@ function drop_item($id,$interactive = true) {
 
                // delete the item
 
-               $r = q("UPDATE `item` SET `deleted` = 1, `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+               $r = q("UPDATE `item` SET `deleted` = 1, `title` = '', `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
                        dbesc(datetime_convert()),
                        dbesc(datetime_convert()),
                        intval($item['id'])
@@ -2797,7 +2928,7 @@ function drop_item($id,$interactive = true) {
                // If it's the parent of a comment thread, kill all the kids
 
                if($item['uri'] == $item['parent-uri']) {
-                       $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' 
+                       $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = ''
                                WHERE `parent-uri` = '%s' AND `uid` = %d ",
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),