Merge pull request #2682 from annando/1607-api-generic-xml

API: XML is now generated without templates
This commit is contained in:
Tobias Diekershoff 2016-08-01 07:25:24 +02:00 committed by GitHub
commit 75be187216
21 changed files with 516 additions and 713 deletions

View File

@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1199 );
define ( 'DB_UPDATE_VERSION', 1200 );
/**
* @brief Constant with a HTML line break.

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 3.5-dev (Asparagus)
-- DB_UPDATE_VERSION 1199
-- DB_UPDATE_VERSION 1200
-- ------------------------------------------
@ -522,6 +522,7 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_title` (`uid`,`title`),
INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`),
INDEX `authorid_created` (`author-id`,`created`),
@ -532,7 +533,7 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_wall_created` (`uid`,`wall`,`created`),
INDEX `resource-id` (`resource-id`),
INDEX `uid_type` (`uid`,`type`),
INDEX `uid_starred` (`uid`,`starred`),
INDEX `uid_starred_id` (`uid`,`starred`,`id`),
INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)),
INDEX `uid_wall_parent_created` (`uid`,`wall`,`parent`,`created`),
INDEX `uid_type_changed` (`uid`,`type`,`changed`),

View File

@ -631,11 +631,11 @@ function posts_from_contact($a, $contact_id) {
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `item` FORCE INDEX (`uid_contactid_created`)
FROM `item` FORCE INDEX (`uid_contactid_id`)
WHERE `item`.`uid` = %d AND `contact-id` = %d
AND `author-link` IN ('%s', '%s')
AND NOT `deleted` AND NOT `moderated` AND `visible`
ORDER BY `item`.`created` DESC LIMIT %d, %d",
ORDER BY `item`.`id` DESC LIMIT %d, %d",
intval(local_user()),
intval($contact_id),
dbesc(str_replace("https://", "http://", $contact["url"])),

File diff suppressed because it is too large Load Diff

View File

@ -858,6 +858,7 @@ function db_definition() {
"uid_title" => array("uid","title"),
"uid_thrparent" => array("uid","thr-parent"),
"uid_parenturi" => array("uid","parent-uri"),
"uid_contactid_id" => array("uid","contact-id","id"),
"uid_contactid_created" => array("uid","contact-id","created"),
"gcontactid_uid_created" => array("gcontact-id","uid","created"),
"authorid_created" => array("author-id","created"),
@ -868,7 +869,7 @@ function db_definition() {
"uid_wall_created" => array("uid","wall","created"),
"resource-id" => array("resource-id"),
"uid_type" => array("uid","type"),
"uid_starred" => array("uid","starred"),
"uid_starred_id" => array("uid","starred", "id"),
"contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"),
"uid_wall_parent_created" => array("uid","wall","parent","created"),
"uid_type_changed" => array("uid","type","changed"),

View File

@ -1971,7 +1971,7 @@ class ostatus {
OR (`item`.`network` = '%s' AND ((`thread`.`network` IN ('%s', '%s')) OR (`thritem`.`network` IN ('%s', '%s')))) AND `thread`.`mention`)
AND ((`item`.`owner-link` IN ('%s', '%s') AND (`item`.`parent` = `item`.`id`))
OR (`item`.`author-link` IN ('%s', '%s')))
ORDER BY `item`.`received` DESC
ORDER BY `item`.`id` DESC
LIMIT 0, 300",
intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN),
//dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),

View File

@ -27,8 +27,11 @@ class xml {
foreach ($namespaces AS $nskey => $nsvalue)
$key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
$root = new SimpleXMLElement("<".$key."/>");
self::from_array($value, $root, $remove_header, $namespaces, false);
if (is_array($value)) {
$root = new SimpleXMLElement("<".$key."/>");
self::from_array($value, $root, $remove_header, $namespaces, false);
} else
$root = new SimpleXMLElement("<".$key.">".xmlify($value)."</".$key.">");
$dom = dom_import_simplexml($root)->ownerDocument;
$dom->formatOutput = true;
@ -44,6 +47,15 @@ class xml {
}
foreach($array as $key => $value) {
if (!isset($element) AND isset($xml))
$element = $xml;
if (is_integer($key)) {
if (isset($element))
$element[0] = $value;
continue;
}
if (substr($key, 0, 11) == "@attributes") {
if (!isset($element) OR !is_array($value))
continue;
@ -55,7 +67,7 @@ class xml {
else
$namespace = NULL;
$element->addAttribute ($attr_key, $attr_value, $namespace);
$element->addAttribute($attr_key, $attr_value, $namespace);
}
continue;
@ -64,6 +76,8 @@ class xml {
$element_parts = explode(":", $key);
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
$namespace = $namespaces[$element_parts[0]];
elseif (isset($namespaces[""]))
$namespace = $namespaces[""];
else
$namespace = NULL;

View File

@ -224,7 +224,7 @@ function content_content(&$a, $update = 0) {
$simple_update
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ",
ORDER BY `item`.`id` DESC $pager_sql ",
intval($_SESSION['uid'])
);

View File

@ -1,6 +1,6 @@
<?php
define('UPDATE_VERSION' , 1199);
define('UPDATE_VERSION' , 1200);
/**
*

View File

@ -1,67 +0,0 @@
<config>
<site>
<name>{{$config.site.name}}</name>
<server>{{$config.site.server}}</server>
<theme>default</theme>
<path></path>
<logo>{{$config.site.logo}}</logo>
<fancy>true</fancy>
<language>en</language>
<email>{{$config.site.email}}</email>
<broughtby></broughtby>
<broughtbyurl></broughtbyurl>
<timezone>UTC</timezone>
<closed>{{$config.site.closed}}</closed>
<inviteonly>false</inviteonly>
<private>{{$config.site.private}}</private>
<textlimit>{{$config.site.textlimit}}</textlimit>
<ssl>{{$config.site.ssl}}</ssl>
<sslserver>{{$config.site.sslserver}}</sslserver>
<shorturllength>30</shorturllength>
</site>
<license>
<type>cc</type>
<owner></owner>
<url>http://creativecommons.org/licenses/by/3.0/</url>
<title>Creative Commons Attribution 3.0</title>
<image>http://i.creativecommons.org/l/by/3.0/80x15.png</image>
</license>
<nickname>
<featured></featured>
</nickname>
<profile>
<biolimit></biolimit>
</profile>
<group>
<desclimit></desclimit>
</group>
<notice>
<contentlimit></contentlimit>
</notice>
<throttle>
<enabled>false</enabled>
<count>20</count>
<timespan>600</timespan>
</throttle>
<xmpp>
<enabled>false</enabled>
<server>INVALID SERVER</server>
<port>5222</port>
<user>update</user>
</xmpp>
<integration>
<source>StatusNet</source>
</integration>
<attachments>
<uploads>false</uploads>
<file_quota>0</file_quota>
</attachments>
</config>

View File

@ -1,6 +0,0 @@
{{* used in include/api.php 'api_statuses_friends' and 'api_statuses_followers' *}}
<users type="array">
{{foreach $users as $u}}
<user>{{include file="api_user_xml.tpl" user=$u}}</user>
{{/foreach}}
</users>

View File

@ -1,21 +0,0 @@
<photo>
<id>{{$photo.id}}</id>
<created>{{$photo.created}}</created>
<edited>{{$photo.edited}}</edited>
<title>{{$photo.title}}</title>
<desc>{{$photo.desc}}</desc>
<album>{{$photo.album}}</album>
<filename>{{$photo.filename}}</filename>
<type>{{$photo.type}}</type>
<height>{{$photo.height}}</height>
<width>{{$photo.width}}</width>
<datasize>{{$photo.datasize}}</datasize>
<profile>1</profile>
<links type="array">{{foreach $photo.link as $scale => $url}}
<link type="{{$photo.type}}" scale="{{$scale}}" href="{{$url}}" />
{{/foreach}}</links>
{{if $photo.data}}
<data encode="base64">{{$photo.data}}</data>
{{/if}}
</photo>

View File

@ -1,5 +0,0 @@
<photos type="array">
{{foreach $photos as $photo}}
<photo id="{{$photo.id}}" album="{{$photo.album}}" filename="{{$photo.filename}}" type="{{$photo.type}}">{{$photo.thumb}}</photo>
{{/foreach}}</photos>

View File

@ -1,7 +0,0 @@
<hash>
<remaining-hits type="integer">{{$hash.remaining_hits}}</remaining-hits>
<hourly-limit type="integer">{{$hash.hourly_limit}}</hourly-limit>
<reset-time type="datetime">{{$hash.reset_time}}</reset-time>
<reset_time_in_seconds type="integer">{{$hash.resettime_in_seconds}}</reset_time_in_seconds>
</hash>

View File

@ -1,25 +0,0 @@
{{* 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>

View File

@ -1,8 +0,0 @@
{{* 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>

View File

@ -1,2 +0,0 @@
<ok>{{$ok}}</ok>

View File

@ -1,91 +0,0 @@
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
<generator uri="http://status.net" version="0.9.7">StatusNet</generator>
<id>{{$rss.self}}</id>
<title>Friendica</title>
<subtitle>Friendica API feed</subtitle>
<logo>{{$rss.logo}}</logo>
<updated>{{$rss.atom_updated}}</updated>
<link type="text/html" rel="alternate" href="{{$rss.alternate}}"/>
<link type="application/atom+xml" rel="self" href="{{$rss.self}}"/>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>{{$user.url}}</uri>
<name>{{$user.name}}</name>
<link rel="alternate" type="text/html" href="{{$user.url}}"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="{{$user.profile_image_url}}"/>
<georss:point></georss:point>
<poco:preferredUsername>{{$user.screen_name}}</poco:preferredUsername>
<poco:displayName>{{$user.name}}</poco:displayName>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>{{$user.url}}</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<statusnet:profile_info local_id="{{$user.id}}"></statusnet:profile_info>
</author>
<!--Deprecation warning: activity:subject is present only for backward compatibility. It will be removed in the next version of StatusNet.-->
<activity:subject>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<id>{{$user.contact_url}}</id>
<title>{{$user.name}}</title>
<link rel="alternate" type="text/html" href="{{$user.url}}"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="{{$user.profile_image_url}}"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="{{$user.profile_image_url}}"/>
<poco:preferredUsername>{{$user.screen_name}}</poco:preferredUsername>
<poco:displayName>{{$user.name}}</poco:displayName>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>{{$user.url}}</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<statusnet:profile_info local_id="{{$user.id}}"></statusnet:profile_info>
</activity:subject>
{{foreach $statuses as $status}}
<entry>
<activity:object-type>{{$status.objecttype}}</activity:object-type>
<id>{{$status.message_id}}</id>
<title>{{$status.text}}</title>
<content type="html">{{$status.statusnet_html}}</content>
<link rel="alternate" type="text/html" href="{{$status.url}}"/>
<activity:verb>{{$status.verb}}</activity:verb>
<published>{{$status.published}}</published>
<updated>{{$status.updated}}</updated>
<link rel="self" type="application/atom+xml" href="{{$status.self}}"/>
<link rel="edit" type="application/atom+xml" href="{{$status.edit}}"/>
<statusnet:notice_info local_id="{{$status.id}}" source="{{$status.source}}" >
</statusnet:notice_info>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>{{$status.user.url}}</uri>
<name>{{$status.user.name}}</name>
<link rel="alternate" type="text/html" href="{{$status.user.url}}"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="{{$status.user.profile_image_url}}"/>
<georss:point/>
<poco:preferredUsername>{{$status.user.screen_name}}</poco:preferredUsername>
<poco:displayName>{{$status.user.name}}</poco:displayName>
<poco:address/>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>{{$status.user.url}}</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
</author>
<link rel="ostatus:conversation" type="text/html" href="{{$status.url}}"/>
</entry>
{{/foreach}}
</feed>

View File

@ -1,27 +0,0 @@
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:georss="http://www.georss.org/georss" xmlns:twitter="http://api.twitter.com">
<channel>
<title>Friendica</title>
<link>{{$rss.alternate}}</link>
<atom:link type="application/rss+xml" rel="self" href="{{$rss.self}}"/>
<description>Friendica timeline</description>
<language>{{$rss.language}}</language>
<ttl>40</ttl>
<image>
<link>{{$user.link}}</link>
<title>{{$user.name}}'s items</title>
<url>{{$user.profile_image_url}}</url>
</image>
{{foreach $statuses as $status}}
<item>
<title>{{$status.user.name}}: {{$status.text}}</title>
<description>{{$status.text}}</description>
<pubDate>{{$status.created_at}}</pubDate>
<guid>{{$status.url}}</guid>
<link>{{$status.url}}</link>
<twitter:source>{{$status.source}}</twitter:source>
</item>
{{/foreach}}
</channel>
</rss>

View File

@ -1,10 +0,0 @@
<statuses type="array"
xmlns:statusnet="http://status.net/schema/api/1/"
xmlns:friendica="http://friendi.ca/schema/api/1/">
{{foreach $statuses as $status}}
<status>
{{include file="api_single_status_xml.tpl" status=$status}}
</status>
{{/foreach}}
</statuses>

View File

@ -1,47 +0,0 @@
{{* includer template MUST provide root element *}}
<id>{{$user.id}}</id>
<name>{{$user.name}}</name>
<screen_name>{{$user.screen_name}}</screen_name>
<location>{{$user.location}}</location>
<description>{{$user.description}}</description>
<profile_image_url>{{$user.profile_image_url}}</profile_image_url>
<url>{{$user.url}}</url>
<protected>{{$user.protected}}</protected>
<followers_count>{{$user.followers_count}}</followers_count>
<friends_count>{{$user.friends_count}}</friends_count>
<created_at>{{$user.created_at}}</created_at>
<favourites_count>{{$user.favourites_count}}</favourites_count>
<utc_offset>{{$user.utc_offset}}</utc_offset>
<time_zone>{{$user.time_zone}}</time_zone>
<statuses_count>{{$user.statuses_count}}</statuses_count>
<following>{{$user.following}}</following>
<profile_background_color>{{$user.profile_background_color}}</profile_background_color>
<profile_text_color>{{$user.profile_text_color}}</profile_text_color>
<profile_link_color>{{$user.profile_link_color}}</profile_link_color>
<profile_sidebar_fill_color>{{$user.profile_sidebar_fill_color}}</profile_sidebar_fill_color>
<profile_sidebar_border_color>{{$user.profile_sidebar_border_color}}</profile_sidebar_border_color>
<profile_background_image_url>{{$user.profile_background_image_url}}</profile_background_image_url>
<profile_background_tile>{{$user.profile_background_tile}}</profile_background_tile>
<profile_use_background_image>{{$user.profile_use_background_image}}</profile_use_background_image>
<notifications>{{$user.notifications}}</notifications>
<geo_enabled>{{$user.geo_enabled}}</geo_enabled>
<verified>{{$user.verified}}</verified>
<lang>{{$user.lang}}</lang>
<contributors_enabled>{{$user.contributors_enabled}}</contributors_enabled>
<status>{{if $user.status}}
<created_at>{{$user.status.created_at}}</created_at>
<id>{{$user.status.id}}</id>
<text>{{$user.status.text}}</text>
<source>{{$user.status.source}}</source>
<truncated>{{$user.status.truncated}}</truncated>
<in_reply_to_status_id>{{$user.status.in_reply_to_status_id}}</in_reply_to_status_id>
<in_reply_to_user_id>{{$user.status.in_reply_to_user_id}}</in_reply_to_user_id>
<favorited>{{$user.status.favorited}}</favorited>
<in_reply_to_screen_name>{{$user.status.in_reply_to_screen_name}}</in_reply_to_screen_name>
<geo>{{$user.status.geo}}</geo>
<coordinates>{{$user.status.coordinates}}</coordinates>
<place>{{$user.status.place}}</place>
<contributors>{{$user.status.contributors}}</contributors>
{{/if}}</status>