]> git.mxchange.org Git - friendica.git/commitdiff
API: rework share as retweet
authorfabrixxm <fabrix.xm@gmail.com>
Wed, 13 Jul 2016 20:11:10 +0000 (22:11 +0200)
committerfabrixxm <fabrix.xm@gmail.com>
Wed, 13 Jul 2016 20:29:07 +0000 (22:29 +0200)
new shared status xml template.
<retweeted_status> element in xml.
parent status keeps his body and author, 'retweeted_status'
get body, author and plink from share bbcode.

include/api.php
view/templates/api_single_status_xml.tpl [new file with mode: 0644]
view/templates/api_status_xml.tpl
view/templates/api_timeline_xml.tpl

index 38555706b51eb86d19daaca54f61621c62e6e43f..3f71ecf9c4a408024c202f636821fd8e092f3047 100644 (file)
        }
 
        function api_convert_item($item) {
-
                $body = $item['body'];
                $attachments = api_get_attachments($body);
 
                        $statushtml = "<h4>".bbcode($item['title'])."</h4>\n".$statushtml;
 
                $entities = api_get_entitities($statustext, $body);
-
-               return(array("text" => $statustext, "html" => $statushtml, "attachments" => $attachments, "entities" => $entities));
+               
+               return array(
+                       "text" => $statustext,
+                       "html" => $statushtml,
+                       "attachments" => $attachments,
+                       "entities" => $entities
+               );
        }
 
        function api_get_attachments(&$body) {
                                $offset = $start + 1;
                        }
                }
-
+               
                return($entities);
        }
        function api_format_items_embeded_images(&$item, $text){
 
                        // Retweets are only valid for top postings
                        // It doesn't work reliable with the link if its a feed
-                       $IsRetweet = ($item['owner-link'] != $item['author-link']);
-                       if ($IsRetweet)
-                               $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar']));
-
-                       if ($IsRetweet AND ($item["id"] == $item["parent"])) {
+                       #$IsRetweet = ($item['owner-link'] != $item['author-link']);
+                       #if ($IsRetweet)
+                       #       $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar']));
+                       
+                                               
+                       if ($item['is_retweet'] AND ($item["id"] == $item["parent"])) {
                                $retweeted_status = $status;
-                               $retweeted_status["user"] = api_get_user($a,$item["author-link"]);
+                               try {
+                                       $retweeted_status["user"] = api_get_user($a,$item["retweet-author-link"]);
+                               } catch( BadRequestException $e ) {
+                                       // user not found. should be found?
+                                       // TODO: check if the user should be found...
+                                       $retweeted_status["user"] = array();
+                               }
 
                                $status["retweeted_status"] = $retweeted_status;
+                               $status["retweeted_status"]["body"] = $item["retweet-body"];
+                               $status["retweeted_status"]["author-name"] = $item["retweet-author-name"];
+                               $status["retweeted_status"]["author-link"] = $item["retweet-author-link"];
+                               $status["retweeted_status"]["author-avatar"] = $item["retweet-author-avatar"];
+                               $status["retweeted_status"]["plink"] = $item["retweet-plink"];
+                               
+                               //echo "<pre>"; var_dump($status); killme();
                        }
 
                        // "uid" and "self" are only needed for some internal stuff, so remove it from here
                if (($shared_body == "") OR ($profile == "") OR ($author == "") OR ($avatar == ""))
                        return(false);
 
-               $item["body"] = $shared_body;
-               $item["author-name"] = $author;
-               $item["author-link"] = $profile;
-               $item["author-avatar"] = $avatar;
-               $item["plink"] = $link;
-
+               $item["retweet-body"] = $shared_body;
+               $item["retweet-author-name"] = $author;
+               $item["retweet-author-link"] = $profile;
+               $item["retweet-author-avatar"] = $avatar;
+               $item["retweet-plink"] = $link;
+               $item["is_retweet"] = true;
                return(true);
 
        }
diff --git a/view/templates/api_single_status_xml.tpl b/view/templates/api_single_status_xml.tpl
new file mode 100644 (file)
index 0000000..88c56f9
--- /dev/null
@@ -0,0 +1,25 @@
+{{* shared structure for statuses. includers must define root element *}}
+  <text>{{$status.text}}</text>
+  <truncated>{{$status.truncated}}</truncated>
+  <created_at>{{$status.created_at}}</created_at>
+  <in_reply_to_status_id>{{$status.in_reply_to_status_id}}</in_reply_to_status_id>
+  <source>{{$status.source}}</source>
+  <id>{{$status.id}}</id>
+  <in_reply_to_user_id>{{$status.in_reply_to_user_id}}</in_reply_to_user_id>
+  <in_reply_to_screen_name>{{$status.in_reply_to_screen_name}}</in_reply_to_screen_name>
+  <geo>{{$status.geo}}</geo>
+  <favorited>{{$status.favorited}}</favorited>
+       <user>{{include file="api_user_xml.tpl" user=$status.user}}</user>
+       <friendica:owner>{{include file="api_user_xml.tpl" user=$status.friendica_owner}}</friendica:owner>
+  <statusnet:html>{{$status.statusnet_html}}</statusnet:html>
+  <statusnet:conversation_id>{{$status.statusnet_conversation_id}}</statusnet:conversation_id>
+  <url>{{$status.url}}</url>
+  <coordinates>{{$status.coordinates}}</coordinates>
+  <place>{{$status.place}}</place>
+  <contributors>{{$status.contributors}}</contributors>
+  {{if $status.retweeted_status}}<retweeted_status>{{include file="api_single_status_xml.tpl" status=$status.retweeted_status}}</retweeted_status>{{/if}}
+  <friendica:activities>
+    {{foreach $status.friendica_activities as $k=>$v}}
+    <friendica:{{$k}}>{{$v|count}}</friendica:{{$k}}>
+    {{/foreach}}
+  </friendica:activities>
\ No newline at end of file
index c3b702baab0af62ce4e0812ff2e534f0de0ec75c..a382810ff455526f0b253a1ff143c5792c3ad300 100644 (file)
@@ -1,47 +1,8 @@
-
-<status>{{if $status}}
-    <created_at>{{$status.created_at}}</created_at>
-    <id>{{$status.id}}</id>
-    <text>{{$status.text}}</text>
-    <source>{{$status.source}}</source>
-    <truncated>{{$status.truncated}}</truncated>
-    <in_reply_to_status_id>{{$status.in_reply_to_status_id}}</in_reply_to_status_id>
-    <in_reply_to_user_id>{{$status.in_reply_to_user_id}}</in_reply_to_user_id>
-    <favorited>{{$status.favorited}}</favorited>
-    <in_reply_to_screen_name>{{$status.in_reply_to_screen_name}}</in_reply_to_screen_name>
-    <geo>{{$status.geo}}</geo>
-    <coordinates>{{$status.coordinates}}</coordinates>
-    <place>{{$status.place}}</place>
-    <contributors>{{$status.contributors}}</contributors>
-       <user>
-         <id>{{$status.user.id}}</id>
-         <name>{{$status.user.name}}</name>
-         <screen_name>{{$status.user.screen_name}}</screen_name>
-         <location>{{$status.user.location}}</location>
-         <description>{{$status.user.description}}</description>
-         <profile_image_url>{{$status.user.profile_image_url}}</profile_image_url>
-         <url>{{$status.user.url}}</url>
-         <protected>{{$status.user.protected}}</protected>
-         <followers_count>{{$status.user.followers}}</followers_count>
-         <profile_background_color>{{$status.user.profile_background_color}}</profile_background_color>
-         <profile_text_color>{{$status.user.profile_text_color}}</profile_text_color>
-         <profile_link_color>{{$status.user.profile_link_color}}</profile_link_color>
-         <profile_sidebar_fill_color>{{$status.user.profile_sidebar_fill_color}}</profile_sidebar_fill_color>
-         <profile_sidebar_border_color>{{$status.user.profile_sidebar_border_color}}</profile_sidebar_border_color>
-         <friends_count>{{$status.user.friends_count}}</friends_count>
-         <created_at>{{$status.user.created_at}}</created_at>
-         <favourites_count>{{$status.user.favourites_count}}</favourites_count>
-         <utc_offset>{{$status.user.utc_offset}}</utc_offset>
-         <time_zone>{{$status.user.time_zone}}</time_zone>
-         <profile_background_image_url>{{$status.user.profile_background_image_url}}</profile_background_image_url>
-         <profile_background_tile>{{$status.user.profile_background_tile}}</profile_background_tile>
-         <profile_use_background_image>{{$status.user.profile_use_background_image}}</profile_use_background_image>
-         <notifications></notifications>
-         <geo_enabled>{{$status.user.geo_enabled}}</geo_enabled>
-         <verified>{{$status.user.verified}}</verified>
-         <following></following>
-         <statuses_count>{{$status.user.statuses_count}}</statuses_count>
-         <lang>{{$status.user.lang}}</lang>
-         <contributors_enabled>{{$status.user.contributors_enabled}}</contributors_enabled>
-         </user>
-{{/if}}</status>
+{{* used in api.php to return a single status *}}
+<status
+       xmlns:statusnet="http://status.net/schema/api/1/"
+       xmlns:friendica="http://friendi.ca/schema/api/1/">
+       {{if $status}}
+       {{include file="api_single_status_xml.tpl" status=$status}}
+       {{/if}}
+</status>
index 2579331495fd5f7611adec8ae7f91d5d1bb34ea3..01b71c0bcc856e55e7f8d20f096ba5ba3b2fc223 100644 (file)
@@ -2,27 +2,9 @@
 <statuses type="array"
        xmlns:statusnet="http://status.net/schema/api/1/"
        xmlns:friendica="http://friendi.ca/schema/api/1/">
-{{foreach $statuses as $status}} <status>
-  <text>{{$status.text}}</text>
-  <truncated>{{$status.truncated}}</truncated>
-  <created_at>{{$status.created_at}}</created_at>
-  <in_reply_to_status_id>{{$status.in_reply_to_status_id}}</in_reply_to_status_id>
-  <source>{{$status.source}}</source>
-  <id>{{$status.id}}</id>
-  <in_reply_to_user_id>{{$status.in_reply_to_user_id}}</in_reply_to_user_id>
-  <in_reply_to_screen_name>{{$status.in_reply_to_screen_name}}</in_reply_to_screen_name>
-  <geo>{{$status.geo}}</geo>
-  <favorited>{{$status.favorited}}</favorited>
-       <user>{{include file="api_user_xml.tpl" user=$status.user}}</user>
-       <friendica:owner>{{include file="api_user_xml.tpl" user=$status.friendica_owner}}</friendica:owner>
-  <statusnet:html>{{$status.statusnet_html}}</statusnet:html>
-  <statusnet:conversation_id>{{$status.statusnet_conversation_id}}</statusnet:conversation_id>
-  <url>{{$status.url}}</url>
-  <coordinates>{{$status.coordinates}}</coordinates>
-  <place>{{$status.place}}</place>
-  <contributors>{{$status.contributors}}</contributors>
-  <friendica:activities>{{foreach $status.friendica_activities as $k=>$v}}
-    <friendica:{{$k}}>{{$v}}</friendica:{{$k}}>
-  {{/foreach}}</friendica:activities>
+{{foreach $statuses as $status}}
+ <status>
+       {{include file="api_single_status_xml.tpl" status=$status}}
  </status>
-{{/foreach}}</statuses>
+{{/foreach}}
+</statuses>