API: rework share as retweet
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.
This commit is contained in:
parent
d98ab84d76
commit
ce2f765d28
|
@ -2047,7 +2047,6 @@
|
|||
}
|
||||
|
||||
function api_convert_item($item) {
|
||||
|
||||
$body = $item['body'];
|
||||
$attachments = api_get_attachments($body);
|
||||
|
||||
|
@ -2084,8 +2083,13 @@
|
|||
$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) {
|
||||
|
@ -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 "<pre>"; 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);
|
||||
|
||||
}
|
||||
|
|
25
view/templates/api_single_status_xml.tpl
Normal file
25
view/templates/api_single_status_xml.tpl
Normal file
|
@ -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>
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue