]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #2853 from annando/1610-bugfix-config
[friendica.git] / include / items.php
index 203b7d0eee6755d0699d8261e3d2da2dedae7d46..5f0187ad97df61be53ec7a73e07e38f3f3a111c7 100644 (file)
@@ -584,6 +584,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                                                 "photo" => $arr['author-avatar'], "name" => $arr['author-name']));
        }
 
+       if ($arr["author-id"] == 0)
+               $arr["author-id"] = get_contact($arr["author-link"], 0);
+
+       if ($arr["owner-id"] == 0)
+               $arr["owner-id"] = get_contact($arr["owner-link"], 0);
+
        if ($arr['guid'] != "") {
                // Checking if there is already an item with the same guid
                logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG);
@@ -663,7 +669,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
 
                        // If its a post from myself then tag the thread as "mention"
                        logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG);
-                       $u = q("select * from user where uid = %d limit 1", intval($arr['uid']));
+                       $u = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($arr['uid']));
                        if(count($u)) {
                                $a = get_app();
                                $self = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
@@ -673,8 +679,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                        logger("item_store: tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG);
                                }
                        }
-               }
-               else {
+               } else {
 
                        // Allow one to see reply tweets from status.net even when
                        // we don't have or can't see the original post.
@@ -729,6 +734,19 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                $arr["global"] = (count($isglobal) > 0);
        }
 
+       // ACL settings
+       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+               $private = 1;
+       else
+               $private = $arr['private'];
+
+       $arr["allow_cid"] = $allow_cid;
+       $arr["allow_gid"] = $allow_gid;
+       $arr["deny_cid"] = $deny_cid;
+       $arr["deny_gid"] = $deny_gid;
+       $arr["private"] = $private;
+       $arr["deleted"] = $parent_deleted;
+
        // Fill the cache field
        put_item_in_cache($arr);
 
@@ -801,41 +819,38 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                                dbesc($arr['received']),
                                intval($arr['contact-id'])
                        );
+
+               // Now do the same for the system wide contacts with uid=0
+               if (!$arr['private']) {
+                       q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+                               dbesc($arr['received']),
+                               dbesc($arr['received']),
+                               intval($arr['owner-id'])
+                       );
+
+                       if ($arr['owner-id'] != $arr['author-id'])
+                               q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+                                       dbesc($arr['received']),
+                                       dbesc($arr['received']),
+                                       intval($arr['author-id'])
+                               );
+               }
        } else {
                logger('item_store: could not locate created item');
                return 0;
        }
 
-       if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
+       if(!$parent_id || ($arr['parent-uri'] === $arr['uri']))
                $parent_id = $current_post;
 
-       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
-               $private = 1;
-       else
-               $private = $arr['private'];
-
-       // Set parent id - and also make sure to inherit the parent's ACLs.
-
-       $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
-               `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d",
+       // Set parent id
+       $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d",
                intval($parent_id),
-               dbesc($allow_cid),
-               dbesc($allow_gid),
-               dbesc($deny_cid),
-               dbesc($deny_gid),
-               intval($private),
-               intval($parent_deleted),
                intval($current_post)
        );
 
        $arr['id'] = $current_post;
        $arr['parent'] = $parent_id;
-       $arr['allow_cid'] = $allow_cid;
-       $arr['allow_gid'] = $allow_gid;
-       $arr['deny_cid'] = $deny_cid;
-       $arr['deny_gid'] = $deny_gid;
-       $arr['private'] = $private;
-       $arr['deleted'] = $parent_deleted;
 
        // update the commented timestamp on the parent
        // Only update "commented" if it is really a comment
@@ -911,7 +926,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        check_item_notification($current_post, $uid);
 
        if ($notify)
-               proc_run('php', "include/notifier.php", $notify_type, $current_post);
+               proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $current_post);
 
        return $current_post;
 }
@@ -1150,7 +1165,7 @@ function tag_deliver($uid,$item_id) {
        );
        update_thread($item_id);
 
-       proc_run('php','include/notifier.php','tgroup',$item_id);
+       proc_run(PRIORITY_HIGH,'include/notifier.php', 'tgroup', $item_id);
 
 }
 
@@ -1398,16 +1413,8 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
                                dbesc($url)
                );
                if(count($r)) {
-                               $contact_record = $r[0];
-
-                               $photos = import_profile_photo($photo,$importer["uid"],$contact_record["id"]);
-
-                               q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d",
-                                       dbesc($photos[0]),
-                                       dbesc($photos[1]),
-                                       dbesc($photos[2]),
-                                       intval($contact_record["id"])
-                               );
+                       $contact_record = $r[0];
+                       update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true);
                }
 
 
@@ -1714,7 +1721,7 @@ function item_expire($uid, $days, $network = "", $force = false) {
        } else
                $range = "AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
 
-       $r = q("SELECT * FROM `item`
+       $r = q("SELECT `file`, `resource-id`, `starred`, `type`, `id` FROM `item`
                WHERE `uid` = %d $range
                AND `id` = `parent`
                $sql_extra
@@ -1765,7 +1772,7 @@ function item_expire($uid, $days, $network = "", $force = false) {
                drop_item($item['id'],false);
        }
 
-       proc_run('php',"include/notifier.php","expire","$uid");
+       proc_run(PRIORITY_HIGH,"include/notifier.php", "expire", $uid);
 
 }
 
@@ -1787,7 +1794,7 @@ function drop_items($items) {
        // multiple threads may have been deleted, send an expire notification
 
        if($uid)
-               proc_run('php',"include/notifier.php","expire","$uid");
+               proc_run(PRIORITY_HIGH,"include/notifier.php", "expire", $uid);
 }
 
 
@@ -2000,7 +2007,7 @@ function drop_item($id,$interactive = true) {
 
                // send the notification upstream/downstream as the case may be
 
-               proc_run('php',"include/notifier.php","drop","$drop_id");
+               proc_run(PRIORITY_HIGH,"include/notifier.php", "drop", $drop_id);
 
                if(! $interactive)
                        return $owner;