From ce2f765d28ea857bee8bec5cdebde7d1ed99d956 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 13 Jul 2016 22:11:10 +0200 Subject: [PATCH] API: rework share as retweet new shared status xml template. element in xml. parent status keeps his body and author, 'retweeted_status' get body, author and plink from share bbcode. --- include/api.php | 50 ++++++++++++++------- view/templates/api_single_status_xml.tpl | 25 +++++++++++ view/templates/api_status_xml.tpl | 55 ++++-------------------- view/templates/api_timeline_xml.tpl | 28 +++--------- 4 files changed, 72 insertions(+), 86 deletions(-) create mode 100644 view/templates/api_single_status_xml.tpl diff --git a/include/api.php b/include/api.php index 38555706b..3f71ecf9c 100644 --- a/include/api.php +++ b/include/api.php @@ -2047,7 +2047,6 @@ } function api_convert_item($item) { - $body = $item['body']; $attachments = api_get_attachments($body); @@ -2084,8 +2083,13 @@ $statushtml = "

".bbcode($item['title'])."

\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) { @@ -2266,7 +2270,7 @@ $offset = $start + 1; } } - + return($entities); } function api_format_items_embeded_images(&$item, $text){ @@ -2429,15 +2433,29 @@ // 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 "
"; var_dump($status); killme();
 			}
 
 			// "uid" and "self" are only needed for some internal stuff, so remove it from here
@@ -3055,12 +3073,12 @@
 		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
index 000000000..88c56f935
--- /dev/null
+++ b/view/templates/api_single_status_xml.tpl
@@ -0,0 +1,25 @@
+{{* shared structure for statuses. includers must define root element *}}
+  {{$status.text}}
+  {{$status.truncated}}
+  {{$status.created_at}}
+  {{$status.in_reply_to_status_id}}
+  {{$status.source}}
+  {{$status.id}}
+  {{$status.in_reply_to_user_id}}
+  {{$status.in_reply_to_screen_name}}
+  {{$status.geo}}
+  {{$status.favorited}}
+	{{include file="api_user_xml.tpl" user=$status.user}}
+	{{include file="api_user_xml.tpl" user=$status.friendica_owner}}
+  {{$status.statusnet_html}}
+  {{$status.statusnet_conversation_id}}
+  {{$status.url}}
+  {{$status.coordinates}}
+  {{$status.place}}
+  {{$status.contributors}}
+  {{if $status.retweeted_status}}{{include file="api_single_status_xml.tpl" status=$status.retweeted_status}}{{/if}}
+  
+    {{foreach $status.friendica_activities as $k=>$v}}
+    {{$v|count}}
+    {{/foreach}}
+  
\ No newline at end of file
diff --git a/view/templates/api_status_xml.tpl b/view/templates/api_status_xml.tpl
index c3b702baa..a382810ff 100644
--- a/view/templates/api_status_xml.tpl
+++ b/view/templates/api_status_xml.tpl
@@ -1,47 +1,8 @@
-
-{{if $status}}
-    {{$status.created_at}}
-    {{$status.id}}
-    {{$status.text}}
-    {{$status.source}}
-    {{$status.truncated}}
-    {{$status.in_reply_to_status_id}}
-    {{$status.in_reply_to_user_id}}
-    {{$status.favorited}}
-    {{$status.in_reply_to_screen_name}}
-    {{$status.geo}}
-    {{$status.coordinates}}
-    {{$status.place}}
-    {{$status.contributors}}
-	
-	  {{$status.user.id}}
-	  {{$status.user.name}}
-	  {{$status.user.screen_name}}
-	  {{$status.user.location}}
-	  {{$status.user.description}}
-	  {{$status.user.profile_image_url}}
-	  {{$status.user.url}}
-	  {{$status.user.protected}}
-	  {{$status.user.followers}}
-	  {{$status.user.profile_background_color}}
-  	  {{$status.user.profile_text_color}}
-  	  {{$status.user.profile_link_color}}
-  	  {{$status.user.profile_sidebar_fill_color}}
-  	  {{$status.user.profile_sidebar_border_color}}
-  	  {{$status.user.friends_count}}
-  	  {{$status.user.created_at}}
-  	  {{$status.user.favourites_count}}
-  	  {{$status.user.utc_offset}}
-  	  {{$status.user.time_zone}}
-  	  {{$status.user.profile_background_image_url}}
-  	  {{$status.user.profile_background_tile}}
-  	  {{$status.user.profile_use_background_image}}
-  	  
-  	  {{$status.user.geo_enabled}}
-  	  {{$status.user.verified}}
-  	  
-  	  {{$status.user.statuses_count}}
-  	  {{$status.user.lang}}
-  	  {{$status.user.contributors_enabled}}
-	  
-{{/if}}
+{{* used in api.php to return a single status *}}
+
+	{{if $status}}
+	{{include file="api_single_status_xml.tpl" status=$status}}
+	{{/if}}
+
diff --git a/view/templates/api_timeline_xml.tpl b/view/templates/api_timeline_xml.tpl
index 257933149..01b71c0bc 100644
--- a/view/templates/api_timeline_xml.tpl
+++ b/view/templates/api_timeline_xml.tpl
@@ -2,27 +2,9 @@
 
-{{foreach $statuses as $status}} 
-  {{$status.text}}
-  {{$status.truncated}}
-  {{$status.created_at}}
-  {{$status.in_reply_to_status_id}}
-  {{$status.source}}
-  {{$status.id}}
-  {{$status.in_reply_to_user_id}}
-  {{$status.in_reply_to_screen_name}}
-  {{$status.geo}}
-  {{$status.favorited}}
-	{{include file="api_user_xml.tpl" user=$status.user}}
-	{{include file="api_user_xml.tpl" user=$status.friendica_owner}}
-  {{$status.statusnet_html}}
-  {{$status.statusnet_conversation_id}}
-  {{$status.url}}
-  {{$status.coordinates}}
-  {{$status.place}}
-  {{$status.contributors}}
-  {{foreach $status.friendica_activities as $k=>$v}}
-    {{$v}}
-  {{/foreach}}
+{{foreach $statuses as $status}}
+ 
+	{{include file="api_single_status_xml.tpl" status=$status}}
  
-{{/foreach}}
+{{/foreach}}
+