]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge remote branch 'upstream/master'
[friendica.git] / include / items.php
index 347826042e66cc79a53a321567e6f4e778c028c1..a1254e165ac9cbc162e4da590cb61eb04339ed9d 100755 (executable)
@@ -308,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']);
                        }
@@ -323,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']);
                                }
@@ -503,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']);
                        }
@@ -1308,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)) {
@@ -1505,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),
@@ -1614,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)) {
@@ -2197,7 +2223,8 @@ function local_delivery($importer,$data) {
                                                                'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) 
                                                                        ? $importer['thumb'] : $datarray['author-avatar']),
                                                                'verb'         => ACTIVITY_POST,
-                                                               'otype'        => 'item'
+                                                               'otype'        => 'item',
+                                                               'parent'       => $parent,
 
                                                        ));
 
@@ -2291,39 +2318,51 @@ 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'])
                                        );
 
                                        if(count($myconv)) {
                                                $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
-                                               foreach($myconv as $conv) {
 
-                                                       if(! link_compare($conv['author-link'],$importer_url))
-                                                               continue;
+                                               // first make sure this isn't our own post coming back to us from a wall-to-wall event
+                                               if(! link_compare($datarray['author-link'],$importer_url)) {
 
-                                                       require_once('include/enotify.php');
+                                                       
+                                                       foreach($myconv as $conv) {
 
-                                                       notification(array(
-                                                               'type'         => NOTIFY_COMMENT,
-                                                               'notify_flags' => $importer['notify-flags'],
-                                                               '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']),
-                                                               'verb'         => ACTIVITY_POST,
-                                                               'otype'        => 'item'
-
-                                                       ));
+                                                               // now if we find a match, it means we're in this conversation
+       
+                                                               if(! link_compare($conv['author-link'],$importer_url))
+                                                                       continue;
 
-                                                       break;
+                                                               require_once('include/enotify.php');
+                                                               
+                                                               $conv_parent = $conv['parent'];
+
+                                                               notification(array(
+                                                                       'type'         => NOTIFY_COMMENT,
+                                                                       'notify_flags' => $importer['notify-flags'],
+                                                                       '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']),
+                                                                       'verb'         => ACTIVITY_POST,
+                                                                       'otype'        => 'item',
+                                                                       'parent'       => $conv_parent,
+
+                                                               ));
+
+                                                               // only send one notification
+                                                               break;
+                                                       }
                                                }
                                        }
                                }
@@ -2394,7 +2433,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;