]> git.mxchange.org Git - friendica.git/commitdiff
api: item owner and activities details
authorfabrixxm <fabrix.xm@gmail.com>
Wed, 13 Jul 2016 17:47:15 +0000 (19:47 +0200)
committerfabrixxm <fabrix.xm@gmail.com>
Wed, 13 Jul 2016 17:58:38 +0000 (19:58 +0200)
return new fileld for items 'friendica_owner'.
'user' is always the author of the item.
Items activitites now returns array of contacts details: {'name','url'}

include/api.php

index 9b245a73ee96c05232cdd0b2056fbc90005fed66..38555706b51eb86d19daaca54f61621c62e6e43f 100644 (file)
 
                // Comments in threads may appear as wall-to-wall postings.
                // So only take the owner at the top posting.
-               if ($item["id"] == $item["parent"])
-                       $status_user = api_get_user($a,$item["owner-link"]);
-               else
-                       $status_user = api_get_user($a,$item["author-link"]);
-
+               #if ($item["id"] == $item["parent"])
+               #       $status_user = api_get_user($a,$item["owner-link"]);
+               #else
+               
+               $status_user = api_get_user($a,$item["author-link"]);
                $status_user["protected"] = (($item["allow_cid"] != "") OR
                                                ($item["allow_gid"] != "") OR
                                                ($item["deny_cid"] != "") OR
                                                ($item["deny_gid"] != "") OR
                                                $item["private"]);
 
-               return ($status_user);
+               $owner_user = api_get_user($a,$item["owner-link"]);                                             
+                                               
+               return (array($status_user, $owner_user));
        }
 
 
                return $text;
        }
 
+       
+       /**
+        * @brief return <a href='url'>name</a> as array
+        *
+        * @param string $txt
+        * @return array
+        *                      name => 'name'
+        *                      'url => 'url'
+        */             
+       function api_contactlink_to_array($txt) {
+               $elm = new SimpleXMLElement($txt);
+               return array(
+                       'name' => $elm->__toString(),
+                       'url' => $elm->attributes()['href']->__toString()
+               );
+       }
+       
+       
        /**
         * @brief return likes, dislikes and attend status for item
         *
         *                      likes => int count
         *                      dislikes => int count
         */
-       function api_format_items_likes(&$item) {
+       function api_format_items_activities(&$item) {
                $activities = array(
                        'like' => array(),
                        'dislike' => array(),
                foreach ($items as $i){
                        builtin_activity_puller($i, $activities);
                }
-
+               
                $res = array();
-               $uri = $item['uri'];
+               $uri = $item['uri']."-l";
                foreach($activities as $k => $v) {
-                       $res[$k] = (x($v,$uri)?$v[$uri]:0);
+                       $res[$k] = ( x($v,$uri) ? array_map("api_contactlink_to_array", $v[$uri]) : array() );
                }
-
+       
                return $res;
        }
 
                        api_share_as_retweet($item);
 
                        localize_item($item);
-                       $status_user = api_item_get_user($a,$item);
+                       list($status_user, $owner_user) = api_item_get_user($a,$item);
 
                        // Look if the posts are matching if they should be filtered by user id
                        if ($filter_user AND ($status_user["id"] != $user_info["id"]))
                                'geo' => NULL,
                                'favorited' => $item['starred'] ? true : false,
                                'user' =>  $status_user ,
+                               'friendica_owner' => $owner_user,
                                //'entities' => NULL,
                                'statusnet_html'                => $converted["html"],
                                'statusnet_conversation_id'     => $item['parent'],
-                               'friendica_activities' => api_format_items_likes($item),
+                               'friendica_activities' => api_format_items_activities($item),
                        );
 
                        if (count($converted["attachments"]) > 0)