From 95b7de631321a7b61b7e1524abe0a42980435d5f Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 13 Jul 2016 18:35:55 +0200 Subject: [PATCH 1/9] API: Fix `api_array_to_xml()` --- include/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index c86a3cbe4b..9b245a73ee 100644 --- a/include/api.php +++ b/include/api.php @@ -688,8 +688,9 @@ function api_array_to_xml($data, $ename="") { $attrs=""; $childs=""; - if (count($data)==1 && !is_array($data[0])) { + if (count($data)==1 && !is_array($data[array_keys($data)[0]])) { $ename = array_keys($data)[0]; + $ename = trim($ename,'$'); $v = $data[$ename]; return "<$ename>$v"; } From 3cd2ed54ebb868dbdc54b7fde6b7774b2f493305 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 13 Jul 2016 19:47:15 +0200 Subject: [PATCH 2/9] api: item owner and activities details 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 | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/include/api.php b/include/api.php index 9b245a73ee..38555706b5 100644 --- a/include/api.php +++ b/include/api.php @@ -664,18 +664,20 @@ // 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)); } @@ -2278,6 +2280,24 @@ return $text; } + + /** + * @brief return name 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 * @@ -2286,7 +2306,7 @@ * likes => int count * dislikes => int count */ - function api_format_items_likes(&$item) { + function api_format_items_activities(&$item) { $activities = array( 'like' => array(), 'dislike' => array(), @@ -2301,13 +2321,13 @@ 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; } @@ -2327,7 +2347,7 @@ 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"])) @@ -2388,10 +2408,11 @@ '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) From d98ab84d76891ef7739f5a5daf414467a1096689 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 13 Jul 2016 20:11:18 +0200 Subject: [PATCH 3/9] API: update template for friendica:owner data api_user_xml.tpl lost his root element. Includer templates must provide it. This allow to use same data structure under different root tag. --- view/templates/api_friends_xml.tpl | 6 ++---- view/templates/api_timeline_xml.tpl | 4 +++- view/templates/api_user_xml.tpl | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/view/templates/api_friends_xml.tpl b/view/templates/api_friends_xml.tpl index 6520415a77..4c9f7e6287 100644 --- a/view/templates/api_friends_xml.tpl +++ b/view/templates/api_friends_xml.tpl @@ -1,8 +1,6 @@ - - - +{{* used in include/api.php 'api_statuses_friends' and 'api_statuses_followers' *}} {{foreach $users as $u}} - {{include file="api_user_xml.tpl" user=$u}} + {{include file="api_user_xml.tpl" user=$u}} {{/foreach}} diff --git a/view/templates/api_timeline_xml.tpl b/view/templates/api_timeline_xml.tpl index e22c1e2ee5..2579331495 100644 --- a/view/templates/api_timeline_xml.tpl +++ b/view/templates/api_timeline_xml.tpl @@ -13,7 +13,9 @@ {{$status.in_reply_to_screen_name}} {{$status.geo}} {{$status.favorited}} -{{include file="api_user_xml.tpl" user=$status.user}} {{$status.statusnet_html}} + {{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}} diff --git a/view/templates/api_user_xml.tpl b/view/templates/api_user_xml.tpl index 7e0ec6ed63..698c5436dd 100644 --- a/view/templates/api_user_xml.tpl +++ b/view/templates/api_user_xml.tpl @@ -1,5 +1,5 @@ +{{* includer template MUST provide root element *}} - {{$user.id}} {{$user.name}} {{$user.screen_name}} @@ -44,4 +44,4 @@ {{$user.status.place}} {{$user.status.contributors}} {{/if}} - + From ce2f765d28ea857bee8bec5cdebde7d1ed99d956 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 13 Jul 2016 22:11:10 +0200 Subject: [PATCH 4/9] 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 38555706b5..3f71ecf9c4 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 0000000000..88c56f935b
--- /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 c3b702baab..a382810ff4 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 2579331495..01b71c0bcc 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}}
+

From 18bd7f5eb7153726d616297981e04816798b5463 Mon Sep 17 00:00:00 2001
From: fabrixxm 
Date: Thu, 14 Jul 2016 13:32:31 +0200
Subject: [PATCH 5/9] API: use regex instead of SimpleXMLElement

It's easier with exotic chars.
And the editor replaced all leading spaces with tabs.
---
 include/api.php | 71 ++++++++++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 31 deletions(-)

diff --git a/include/api.php b/include/api.php
index 3f71ecf9c4..4a3d609693 100644
--- a/include/api.php
+++ b/include/api.php
@@ -250,7 +250,7 @@
 	 */
 	function api_call(&$a){
 		GLOBAL $API, $called_api;
-		
+
 		$type="json";
 		if (strpos($a->query_string, ".xml")>0) $type="xml";
 		if (strpos($a->query_string, ".json")>0) $type="json";
@@ -667,7 +667,7 @@
 		#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
@@ -675,8 +675,8 @@
 						($item["deny_gid"] != "") OR
 						$item["private"]);
 
-		$owner_user = api_get_user($a,$item["owner-link"]);						
-						
+		$owner_user = api_get_user($a,$item["owner-link"]);
+
 		return (array($status_user, $owner_user));
 	}
 
@@ -723,7 +723,7 @@
 			case "xml":
 				$data = array_xmlify($data);
 				if ($templatename==="") {
-					$ret = api_array_to_xml($data); 
+					$ret = api_array_to_xml($data);
 				} else {
 					$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
 					if(! $tpl) {
@@ -2083,7 +2083,7 @@
 			$statushtml = "

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

\n".$statushtml; $entities = api_get_entitities($statustext, $body); - + return array( "text" => $statustext, "html" => $statushtml, @@ -2270,7 +2270,7 @@ $offset = $start + 1; } } - + return($entities); } function api_format_items_embeded_images(&$item, $text){ @@ -2284,7 +2284,7 @@ return $text; } - + /** * @brief return name as array * @@ -2292,16 +2292,25 @@ * @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() - ); + $match = array(); + $r = preg_match_all('|([^<]*)|', $txt, $match); + if ($r && count($match)==3) { + $res = array( + 'name' => $match[2], + 'url' => $match[1] + ); + } else { + $res = array( + 'name' => $text, + 'url' => "" + ); + } + return $res; } - - + + /** * @brief return likes, dislikes and attend status for item * @@ -2325,13 +2334,13 @@ foreach ($items as $i){ builtin_activity_puller($i, $activities); } - + $res = array(); $uri = $item['uri']."-l"; foreach($activities as $k => $v) { $res[$k] = ( x($v,$uri) ? array_map("api_contactlink_to_array", $v[$uri]) : array() ); } - + return $res; } @@ -2436,8 +2445,8 @@ #$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; try { @@ -2454,7 +2463,7 @@ $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();
 			}
 
@@ -3482,16 +3491,16 @@
 		if (api_user()===false) throw new ForbiddenException();
 		if ($a->argc!==3) throw new BadRequestException("Invalid argument count");
 		$nm = new NotificationsManager();
-		
+
 		$notes = $nm->getAll(array(), "+seen -date", 50);
 		return api_apply_template("", $type, array('$notes' => $notes));
 	}
-	
+
 	/**
 	 * @brief Set notification as seen and returns associated item (if possible)
 	 *
 	 * POST request with 'id' param as notification id
-	 * 
+	 *
 	 * @param App $a
 	 * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
 	 * @return string
@@ -3499,13 +3508,13 @@
 	function api_friendica_notification_seen(&$a, $type){
 		if (api_user()===false) throw new ForbiddenException();
 		if ($a->argc!==4) throw new BadRequestException("Invalid argument count");
-		
+
 		$id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0);
-		
-		$nm = new NotificationsManager();		
+
+		$nm = new NotificationsManager();
 		$note = $nm->getByID($id);
 		if (is_null($note)) throw new BadRequestException("Invalid argument");
-		
+
 		$nm->setSeen($note);
 		if ($note['otype']=='item') {
 			// would be really better with an ItemsManager and $im->getByID() :-P
@@ -3521,13 +3530,13 @@
 				return api_apply_template("timeline", $type, $data);
 			}
 			// the item can't be found, but we set the note as seen, so we count this as a success
-		} 
+		}
 		return api_apply_template('', $type, array('status' => "success"));
 	}
-	
+
 	api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
 	api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
-	
+
 
 /*
 To.Do:

From c7876d0c38cdea4982b19fc1324534ac927b5814 Mon Sep 17 00:00:00 2001
From: fabrixxm 
Date: Thu, 14 Jul 2016 13:35:36 +0200
Subject: [PATCH 6/9] API: add docs to `api_item_get_user()`

and remove commented out lines
---
 include/api.php | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/api.php b/include/api.php
index 4a3d609693..1d4f5d5874 100644
--- a/include/api.php
+++ b/include/api.php
@@ -653,6 +653,13 @@
 
 	}
 
+	/**
+	 * @brief return api-formatted array for item's author and owner
+	 *
+	 * @param App $a
+	 * @param array $item : item from db
+	 * @return array(array:author, array:owner)
+	 */
 	function api_item_get_user(&$a, $item) {
 
 		// Make sure that there is an entry in the global contacts for author and owner
@@ -662,12 +669,6 @@
 		get_gcontact_id(array("url" => $item['owner-link'], "network" => $item['network'],
 					"photo" => $item['owner-avatar'], "name" => $item['owner-name']));
 
-		// 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"]);
 		$status_user["protected"] = (($item["allow_cid"] != "") OR
 						($item["allow_gid"] != "") OR

From 66199c9861d113a874cd7b6a6e486cafec6f96a3 Mon Sep 17 00:00:00 2001
From: fabrixxm 
Date: Thu, 14 Jul 2016 16:39:40 +0200
Subject: [PATCH 7/9] API: rework retweeted_status

`api_share_as_retweet()` now returns a copy of the item with
fields updated to shared content, instead of modify the item itself.
The new item array is used to build 'retweeted_status'.
---
 include/api.php | 93 +++++++++++++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 33 deletions(-)

diff --git a/include/api.php b/include/api.php
index 1d4f5d5874..e51942ca63 100644
--- a/include/api.php
+++ b/include/api.php
@@ -2358,7 +2358,6 @@
 		$ret = Array();
 
 		foreach($r as $item) {
-			api_share_as_retweet($item);
 
 			localize_item($item);
 			list($status_user, $owner_user) = api_item_get_user($a,$item);
@@ -2448,24 +2447,26 @@
 			#	$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;
-				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();
+			if ($item["id"] == $item["parent"]) {
+				$retweeted_item = api_share_as_retweet($item);
+				if ($retweeted_item !== false) {
+					$retweeted_status = $status;
+					try {
+						$retweeted_status["user"] = api_get_user($a,$retweeted_item["author-link"]);
+					} catch( BadRequestException $e ) {
+						// user not found. should be found?
+						// TODO: check if the user should be found...
+						$retweeted_status["user"] = array();
+					}
+
+					$rt_converted = api_convert_item($retweeted_item);
+
+					$retweeted_status['text'] = $rt_converted["text"];
+					$retweeted_status['statusnet_html'] = $rt_converted["html"];
+					$retweeted_status['friendica_activities'] = api_format_items_activities($retweeted_item);
+					$retweeted_status['created_at'] =  api_date($retweeted_item['created']);
+					$status['retweeted_status'] = $retweeted_status;
 				}
-
-				$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
@@ -3024,23 +3025,36 @@
 	}
 	api_register_func('api/friendica/remoteauth', 'api_friendica_remoteauth', true);
 
-
+	/**
+	 * @brief Return the item shared, if the item contains only the [share] tag
+	 *
+	 * @param array $item Sharer item
+	 * @return array Shared item or false if not a reshare
+	 */
 	function api_share_as_retweet(&$item) {
 		$body = trim($item["body"]);
 
 		// Skip if it isn't a pure repeated messages
 		// Does it start with a share?
 		if (strpos($body, "[share") > 0)
-			return(false);
+			return false;
 
 		// Does it end with a share?
 		if (strlen($body) > (strrpos($body, "[/share]") + 8))
-			return(false);
+			return false;
 
 		$attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
-		// Skip if there is no shared message in there
-		if ($body == $attributes)
-			return(false);
+ 		// Skip if there is no shared message in there
+ 		if ($body == $attributes)
+			return false;
+
+		// NOTE: we could check te guid="" attribute and then  try to load original post
+		//            from database given the guid: we can see the original post via web under
+		//			/display/, but all the logic to fetch an item from db based on guid
+		//			looks like is in display_init() and would need a big refractor to be usable here.
+		//			so, we build the original item starting from the reshare.
+
+		$reshared_item = $item;
 
 		$author = "";
 		preg_match("/author='(.*?)'/ism", $attributes, $matches);
@@ -3078,18 +3092,31 @@
 		if ($matches[1] != "")
 			$link = $matches[1];
 
+		$posted = "";
+		preg_match("/posted='(.*?)'/ism", $attributes, $matches);
+		if ($matches[1] != "")
+			$posted= $matches[1];
+
+		preg_match('/posted="(.*?)"/ism', $attributes, $matches);
+		if ($matches[1] != "")
+			$posted = $matches[1];
+
 		$shared_body = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$2",$body);
 
-		if (($shared_body == "") OR ($profile == "") OR ($author == "") OR ($avatar == ""))
-			return(false);
+		if (($shared_body == "") || ($profile == "") || ($author == "") || ($avatar == "") || ($posted == ""))
+			return false;
 
-		$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);
+
+
+		$reshared_item["body"] = $shared_body;
+		$reshared_item["author-name"] = $author;
+		$reshared_item["author-link"] = $profile;
+		$reshared_item["author-avatar"] = $avatar;
+		$reshared_item["plink"] = $link;
+		$reshared_item["created"] = $posted;
+		$reshared_item["edited"] = $posted;
+
+		return $reshared_item;
 
 	}
 

From 43699646d6a3d366a655be434655fc45ffa2e6c4 Mon Sep 17 00:00:00 2001
From: fabrixxm 
Date: Fri, 15 Jul 2016 11:46:19 +0200
Subject: [PATCH 8/9] API: use doxygen todo style

---
 include/api.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/api.php b/include/api.php
index e51942ca63..5a3e92bb88 100644
--- a/include/api.php
+++ b/include/api.php
@@ -2455,7 +2455,7 @@
 						$retweeted_status["user"] = api_get_user($a,$retweeted_item["author-link"]);
 					} catch( BadRequestException $e ) {
 						// user not found. should be found?
-						// TODO: check if the user should be found...
+						/// @todo check if the user should be always found
 						$retweeted_status["user"] = array();
 					}
 

From d68c09e428d5da9b4109be48ccd65f113bb56b6f Mon Sep 17 00:00:00 2001
From: fabrixxm 
Date: Fri, 15 Jul 2016 12:22:35 +0200
Subject: [PATCH 9/9] API: use `diaspora::is_reshare()`

---
 include/api.php | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/include/api.php b/include/api.php
index 5a3e92bb88..832240f716 100644
--- a/include/api.php
+++ b/include/api.php
@@ -3034,26 +3034,19 @@
 	function api_share_as_retweet(&$item) {
 		$body = trim($item["body"]);
 
-		// Skip if it isn't a pure repeated messages
-		// Does it start with a share?
-		if (strpos($body, "[share") > 0)
-			return false;
-
-		// Does it end with a share?
-		if (strlen($body) > (strrpos($body, "[/share]") + 8))
+		if (diaspora::is_reshare($body, false)===false) {
 			return false;
+		}
 
 		$attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
  		// Skip if there is no shared message in there
+ 		// we already checked this in diaspora::is_reshare()
+ 		// but better one more than one less...
  		if ($body == $attributes)
 			return false;
 
-		// NOTE: we could check te guid="" attribute and then  try to load original post
-		//            from database given the guid: we can see the original post via web under
-		//			/display/, but all the logic to fetch an item from db based on guid
-		//			looks like is in display_init() and would need a big refractor to be usable here.
-		//			so, we build the original item starting from the reshare.
 
+		// build the fake reshared item
 		$reshared_item = $item;
 
 		$author = "";