]> git.mxchange.org Git - friendica.git/commitdiff
Some more improvements to xml.php, code cleanup
authorMichael Vogel <icarus@dabo.de>
Sun, 17 Jul 2016 21:59:35 +0000 (23:59 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 17 Jul 2016 21:59:35 +0000 (23:59 +0200)
include/api.php
include/xml.php
view/templates/api_timeline_atom.tpl [deleted file]

index ddc5813d50e714d4eaca037d967f9f07e6291bdd..4796228f9d77c6188d5e976de3e9b69ad192db72 100644 (file)
                                        switch($type){
                                                case "xml":
                                                        header ("Content-Type: text/xml");
-
-                                                       if (substr($r, 0, 5) == "<?xml")
-                                                               return $r;
-
-                                                       $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
-                                                       return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+                                                       return $r;
                                                        break;
                                                case "json":
                                                        header ("Content-Type: application/json");
        function api_error(&$a, $type, $e) {
                $error = ($e->getMessage()!==""?$e->getMessage():$e->httpdesc);
                # TODO:  https://dev.twitter.com/overview/api/response-codes
-               $xmlstr = "<status><error>{$error}</error><code>{$e->httpcode} {$e->httpdesc}</code><request>{$a->query_string}</request></status>";
+
+               $error = array("error" => $error,
+                               "code" => $e->httpcode." ".$e->httpdesc,
+                               "request" => $a->query_string);
+
+               $ret = api_format_data('status', $type, array('status' => $error));
+
                switch($type){
                        case "xml":
                                header ("Content-Type: text/xml");
-                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$xmlstr;
+                               return $ret;
                                break;
                        case "json":
                                header ("Content-Type: application/json");
-                               return json_encode(array(
-                                       'error' => $error,
-                                       'request' => $a->query_string,
-                                       'code' => $e->httpcode." ".$e->httpdesc
-                               ));
+                               return json_encode($ret);
                                break;
                        case "rss":
                                header ("Content-Type: application/rss+xml");
-                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$xmlstr;
+                               return $ret;
                                break;
                        case "atom":
                                header ("Content-Type: application/atom+xml");
-                               return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$xmlstr;
+                               return $ret;
                                break;
                }
        }
                return (array($status_user, $owner_user));
        }
 
-
-       /**
-        * @brief transform $data array in xml without a template
-        *
-        * @param array $data
-        * @return string xml string
-        */
-       function api_array_to_xml($data, $ename="") {
-               $attrs="";
-               $childs="";
-               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</$ename>";
-               }
-               foreach($data as $k=>$v) {
-                       $k=trim($k,'$');
-                       if (!is_array($v)) {
-                               $attrs .= sprintf('%s="%s" ', $k, $v);
-                       } else {
-                               if (is_numeric($k)) $k=trim($ename,'s');
-                               $childs.=api_array_to_xml($v, $k);
-                       }
-               }
-               $res = $childs;
-               if ($ename!="") $res = "<$ename $attrs>$res</$ename>";
-               return $res;
-       }
-
-
        /**
         * @brief walks recursively through an array with the possibility to change value and key
         *
                        $key = "statusnet:".substr($key, 10);
                elseif (substr($key, 0, 10) == "friendica_")
                        $key = "friendica:".substr($key, 10);
-               elseif (in_array($key, array("like", "dislike", "attendyes", "attendno", "attendmaybe")))
-                       $key = "friendica:".$key;
+               //else
+               //      $key = "default:".$key;
 
-               return (!in_array($key, array("attachments", "friendica:activities", "coordinates")));
+               return true;
        }
 
        /**
         * @brief Creates the XML from a JSON style array
         *
         * @param array $data JSON style array
-        * @param string $template Name of the root element
+        * @param string $root_element Name of the root element
         *
-        * @return boolean string The XML data
+        * @return string The XML data
         */
        function api_create_xml($data, $root_element) {
-
                $childname = key($data);
                $data2 = array_pop($data);
                $key = key($data2);
 
-               $namespaces = array("statusnet" => "http://status.net/schema/api/1/",
-                                       "friendica" => "http://friendi.ca/schema/api/1/");
+               $namespaces = array("" => "http://api.twitter.com",
+                                       "statusnet" => "http://status.net/schema/api/1/",
+                                       "friendica" => "http://friendi.ca/schema/api/1/",
+                                       "georss" => "http://www.georss.org/georss");
 
                /// @todo Auto detection of needed namespaces
                if (in_array($root_element, array("ok", "hash", "config", "version", "ids", "notes", "photos")))
        }
 
        /**
-        *  load api $templatename for $type and replace $data array
+        * @brief Formats the data according to the data type
+        *
+        * @param string $root_element Name of the root element
+        * @param string $type Return type (atom, rss, xml, json)
+        * @param array $data JSON style array
+        *
+        * @return (string|object) XML data or JSON data
         */
-       function api_apply_template($templatename, $type, $data){
+       function api_format_data($root_element, $type, $data){
 
                $a = get_app();
 
                        case "atom":
                        case "rss":
                        case "xml":
-                               $ret = api_create_xml($data, $templatename);
-                               break;
-
-                               $data = array_xmlify($data);
-                               if ($templatename==="<auto>") {
-                                       $ret = api_array_to_xml($data);
-                               } else {
-                                       $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
-                                       if(! $tpl) {
-                                               header ("Content-Type: text/xml");
-                                               echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
-                                               killme();
-                                       }
-                                       $ret = replace_macros($tpl, $data);
-                               }
+                               $ret = api_create_xml($data, $root_element);
                                break;
                        case "json":
                                $ret = $data;
                unset($user_info["uid"]);
                unset($user_info["self"]);
 
-               return api_apply_template("user", $type, array('user' => $user_info));
+               return api_format_data("user", $type, array('user' => $user_info));
 
        }
        api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
 
                        $converted = api_convert_item($lastwall);
 
+                       if ($type == "xml")
+                               $geo = "georss:point";
+                       else
+                               $geo = "geo";
+
                        $status_info = array(
                                'created_at' => api_date($lastwall['created']),
                                'id' => intval($lastwall['id']),
                                'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
                                'user' => $user_info,
-                               'geo' => NULL,
+                               $geo => NULL,
                                'coordinates' => "",
                                'place' => "",
                                'contributors' => "",
                if ($type == "raw")
                        return($status_info);
 
-               return  api_apply_template("statuses", $type, array('status' => $status_info));
+               return  api_format_data("statuses", $type, array('status' => $status_info));
 
        }
 
 
                        $converted = api_convert_item($lastwall);
 
+                       if ($type == "xml")
+                               $geo = "georss:point";
+                       else
+                               $geo = "geo";
+
                        $user_info['status'] = array(
                                'text' => $converted["text"],
                                'truncated' => false,
                                'in_reply_to_user_id' => $in_reply_to_user_id,
                                'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
-                               'geo' => NULL,
+                               $geo => NULL,
                                'favorited' => $lastwall['starred'] ? true : false,
                                'statusnet_html'                => $converted["html"],
                                'statusnet_conversation_id'     => $lastwall['parent'],
                unset($user_info["uid"]);
                unset($user_info["self"]);
 
-               return  api_apply_template("user", $type, array('user' => $user_info));
+               return  api_format_data("user", $type, array('user' => $user_info));
 
        }
        api_register_func('api/users/show','api_users_show');
                                $r = q("SELECT `id` FROM `gcontact` WHERE `nick`='%s'", dbesc($_GET["q"]));
 
                        if (count($r)) {
+                               $k = 0;
                                foreach ($r AS $user) {
-                                       $user_info = api_get_user($a, $user["id"]);
-                                       //echo print_r($user_info, true)."\n";
-                                       $userdata = api_apply_template("user", $type, array('users' => $user_info));
-                                       $userlist[] = $userdata["user"];
+                                       $user_info = api_get_user($a, $user["id"], "json");
+
+                                       if ($type == "xml")
+                                               $userlist[$k++.":user"] = $user_info;
+                                       else
+                                               $userlist[] = $user_info;
                                }
                                $userlist = array("users" => $userlist);
                        } else {
                } else {
                        throw new BadRequestException("User not found.");
                }
-               return ($userlist);
+               return api_format_data("users", $type, $userlist);
        }
 
        api_register_func('api/users/search','api_users_search');
                        intval($start), intval($count)
                );
 
-               $ret = api_format_items($r,$user_info);
+               $ret = api_format_items($r,$user_info, false, $type);
 
                // Set all posts from the query above to seen
                $idarray = array();
                                break;
                }
 
-               return  api_apply_template("statuses", $type, $data);
+               return  api_format_data("statuses", $type, $data);
        }
        api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
        api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
                        intval($start),
                        intval($count));
 
-               $ret = api_format_items($r,$user_info);
+               $ret = api_format_items($r,$user_info, false, $type);
 
 
                $data = array('status' => $ret);
                                break;
                }
 
-               return  api_apply_template("statuses", $type, $data);
+               return  api_format_data("statuses", $type, $data);
        }
        api_register_func('api/statuses/public_timeline','api_statuses_public_timeline', true);
 
                        throw new BadRequestException("There is no status with this id.");
                }
 
-               $ret = api_format_items($r,$user_info);
+               $ret = api_format_items($r,$user_info, false, $type);
 
                if ($conversation) {
                        $data = array('status' => $ret);
-                       return api_apply_template("statuses", $type, $data);
+                       return api_format_data("statuses", $type, $data);
                } else {
                        $data = array('status' => $ret[0]);
-                       return  api_apply_template("status", $type, $data);
+                       return  api_format_data("status", $type, $data);
                }
        }
        api_register_func('api/statuses/show','api_statuses_show', true);
                if (!$r)
                        throw new BadRequestException("There is no conversation with this id.");
 
-               $ret = api_format_items($r,$user_info);
+               $ret = api_format_items($r,$user_info, false, $type);
 
                $data = array('status' => $ret);
-               return api_apply_template("statuses", $type, $data);
+               return api_format_data("statuses", $type, $data);
        }
        api_register_func('api/conversation/show','api_conversation_show', true);
        api_register_func('api/statusnet/conversation','api_conversation_show', true);
                        intval($start), intval($count)
                );
 
-               $ret = api_format_items($r,$user_info);
+               $ret = api_format_items($r,$user_info, false, $type);
 
 
                $data = array('status' => $ret);
                                break;
                }
 
-               return  api_apply_template("statuses", $type, $data);
+               return  api_format_data("statuses", $type, $data);
        }
        api_register_func('api/statuses/mentions','api_statuses_mentions', true);
        api_register_func('api/statuses/replies','api_statuses_mentions', true);
                        intval($start), intval($count)
                );
 
-               $ret = api_format_items($r,$user_info, true);
+               $ret = api_format_items($r,$user_info, true, $type);
 
                $data = array('status' => $ret);
                switch($type){
                                $data = api_rss_extra($a, $data, $user_info);
                }
 
-               return  api_apply_template("statuses", $type, $data);
+               return  api_format_data("statuses", $type, $data);
        }
        api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
 
 
 
                $user_info = api_get_user($a);
-               $rets = api_format_items($item,$user_info);
+               $rets = api_format_items($item,$user_info, false, $type);
                $ret = $rets[0];
 
                $data = array('status' => $ret);
                                $data = api_rss_extra($a, $data, $user_info);
                }
 
-               return api_apply_template("status", $type, $data);
+               return api_format_data("status", $type, $data);
        }
        api_register_func('api/favorites/create', 'api_favorites_create_destroy', true, API_METHOD_POST);
        api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true, API_METHOD_DELETE);
                                intval($start), intval($count)
                        );
 
-                       $ret = api_format_items($r,$user_info);
+                       $ret = api_format_items($r,$user_info, false, $type);
 
                }
 
                                $data = api_rss_extra($a, $data, $user_info);
                }
 
-               return  api_apply_template("statuses", $type, $data);
+               return  api_format_data("statuses", $type, $data);
        }
        api_register_func('api/favorites','api_favorites', true);
 
         *                      likes => int count
         *                      dislikes => int count
         */
-       function api_format_items_activities(&$item) {
+       function api_format_items_activities(&$item, $type = "json") {
                $activities = array(
                        'like' => array(),
                        'dislike' => array(),
                        builtin_activity_puller($i, $activities);
                }
 
+               if ($type == "xml") {
+                       $xml_activities = array();
+                       foreach ($activities as $k => $v)
+                               $xml_activities["friendica:".$k] = $v;
+
+                       $activities = $xml_activities;
+               }
+
                $res = array();
                $uri = $item['uri']."-l";
                foreach($activities as $k => $v) {
         * @param array $user_info
         * @param bool $filter_user filter items by $user_info
         */
-       function api_format_items($r,$user_info, $filter_user = false) {
+       function api_format_items($r,$user_info, $filter_user = false, $type = "json") {
 
                $a = get_app();
                $ret = Array();
 
                        $converted = api_convert_item($item);
 
+                       if ($type == "xml")
+                               $geo = "georss:point";
+                       else
+                               $geo = "geo";
+
                        $status = array(
                                'text'          => $converted["text"],
                                'truncated' => False,
                                'in_reply_to_user_id' => $in_reply_to_user_id,
                                'in_reply_to_user_id_str' => $in_reply_to_user_id_str,
                                'in_reply_to_screen_name' => $in_reply_to_screen_name,
-                               'geo' => NULL,
+                               $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_activities($item),
+                               'friendica_activities' => api_format_items_activities($item, $type),
                        );
 
                        if (count($converted["attachments"]) > 0)
 
                                        $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['friendica_activities'] = api_format_items_activities($retweeted_item, $type);
                                        $retweeted_status['created_at'] =  api_date($retweeted_item['created']);
                                        $status['retweeted_status'] = $retweeted_status;
                                }
                        if ($item["coord"] != "") {
                                $coords = explode(' ',$item["coord"]);
                                if (count($coords) == 2) {
-                                       $status["geo"] = array('type' => 'Point',
-                                                       'coordinates' => array((float) $coords[0],
-                                                                               (float) $coords[1]));
+                                       if ($type == "json")
+                                               $status["geo"] = array('type' => 'Point',
+                                                               'coordinates' => array((float) $coords[0],
+                                                                                       (float) $coords[1]));
+                                       else // Not sure if this is the official format - if someone founds a documentation we can check
+                                               $status["georss:point"] = $item["coord"];
                                }
                        }
-
                        $ret[] = $status;
                };
                return $ret;
 
        function api_account_rate_limit_status(&$a,$type) {
 
-               if ($type == "json")
-                       $hash = array(
-                                       'reset_time_in_seconds' => strtotime('now + 1 hour'),
-                                       'remaining_hits' => (string) 150,
-                                       'hourly_limit' => (string) 150,
-                                       'reset_time' => api_date(datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME)),
-                               );
-               else
+               if ($type == "xml")
                        $hash = array(
                                        'remaining-hits' => (string) 150,
                                        '@attributes' => array("type" => "integer"),
                                        'reset_time_in_seconds' => strtotime('now + 1 hour'),
                                        '@attributes4' => array("type" => "integer"),
                                );
+               else
+                       $hash = array(
+                                       'reset_time_in_seconds' => strtotime('now + 1 hour'),
+                                       'remaining_hits' => (string) 150,
+                                       'hourly_limit' => (string) 150,
+                                       'reset_time' => api_date(datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME)),
+                               );
 
-               return api_apply_template('hash', $type, array('hash' => $hash));
+               return api_format_data('hash', $type, array('hash' => $hash));
        }
        api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
 
                else
                        $ok = "ok";
 
-               return api_apply_template('ok', $type, array("ok" => $ok));
+               return api_format_data('ok', $type, array("ok" => $ok));
        }
        api_register_func('api/help/test','api_help_test',false);
 
        function api_lists(&$a,$type) {
                $ret = array();
-               return api_apply_template('lists', $type, array("lists_list" => $ret));
+               return api_format_data('lists', $type, array("lists_list" => $ret));
        }
        api_register_func('api/lists','api_lists',true);
 
        function api_lists_list(&$a,$type) {
                $ret = array();
-               return api_apply_template('lists', $type, array("lists_list" => $ret));
+               return api_format_data('lists', $type, array("lists_list" => $ret));
        }
        api_register_func('api/lists/list','api_lists_list',true);
 
        function api_statuses_friends(&$a, $type){
                $data =  api_statuses_f($a,$type,"friends");
                if ($data===false) return false;
-               return  api_apply_template("users", $type, $data);
+               return  api_format_data("users", $type, $data);
        }
        function api_statuses_followers(&$a, $type){
                $data = api_statuses_f($a,$type,"followers");
                if ($data===false) return false;
-               return  api_apply_template("users", $type, $data);
+               return  api_format_data("users", $type, $data);
        }
        api_register_func('api/statuses/friends','api_statuses_friends',true);
        api_register_func('api/statuses/followers','api_statuses_followers',true);
                        ),
                );
 
-               return api_apply_template('config', $type, array('config' => $config));
+               return api_format_data('config', $type, array('config' => $config));
 
        }
        api_register_func('api/statusnet/config','api_statusnet_config',false);
                // liar
                $fake_statusnet_version = "0.9.7";
 
-               return api_apply_template('version', $type, array('version' => $fake_statusnet_version));
+               return api_format_data('version', $type, array('version' => $fake_statusnet_version));
        }
        api_register_func('api/statusnet/version','api_statusnet_version',false);
 
        /**
-        * @todo use api_apply_template() to return data
+        * @todo use api_format_data() to return data
         */
        function api_ff_ids(&$a,$type,$qtype) {
                if(! api_user()) throw new ForbiddenException();
                        else
                                $ids[] = intval($rr['id']);
 
-               return api_apply_template("ids", $type, array('id' => $ids));
+               return api_format_data("ids", $type, array('id' => $ids));
        }
 
        function api_friends_ids(&$a,$type) {
                                $data = api_rss_extra($a, $data, $user_info);
                }
 
-               return  api_apply_template("direct-messages", $type, $data);
+               return  api_format_data("direct-messages", $type, $data);
 
        }
        api_register_func('api/direct_messages/new','api_direct_messages_new',true, API_METHOD_POST);
                                $data = api_rss_extra($a, $data, $user_info);
                }
 
-               return  api_apply_template("direct-messages", $type, $data);
+               return  api_format_data("direct-messages", $type, $data);
 
        }
 
                                $photo['type'] = $rr['type'];
                                $thumb = $a->get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
 
-                               if ($type == "json") {
+                               if ($type == "xml")
+                                       $data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
+                               else {
                                        $photo['thumb'] = $thumb;
                                        $data['photo'][] = $photo;
-                               } else {
-                                       $data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
                                }
                        }
                }
-               return  api_apply_template("photos", $type, $data);
+               return  api_format_data("photos", $type, $data);
        }
 
        function api_fr_photo_detail(&$a,$type) {
 
                if ($r) {
                        $data = array('photo' => $r[0]);
+                       $data['photo']['id'] = $data['photo']['resource-id'];
                        if ($scale !== false) {
                                $data['photo']['data'] = base64_encode($data['photo']['data']);
                        } else {
                                unset($data['photo']['datasize']); //needed only with scale param
                        }
-                       $data['photo']['link'] = array();
-                       for($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++) {
-                               $data['photo']['link'][$k] = $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
+                       if ($type == "xml") {
+                               $data['photo']['links'] = array();
+                               for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++)
+                                       $data['photo']['links'][$k.":link"]["@attributes"] = array("type" => $data['photo']['type'],
+                                                                                       "scale" => $k,
+                                                                                       "href" => $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
+                       } else {
+                               $data['photo']['link'] = array();
+                               for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++) {
+                                       $data['photo']['link'][$k] = $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
+                               }
                        }
-                       $data['photo']['id'] = $data['photo']['resource-id'];
                        unset($data['photo']['resource-id']);
                        unset($data['photo']['minscale']);
                        unset($data['photo']['maxscale']);
                        throw new NotFoundException();
                }
 
-               return api_apply_template("photo_detail", $type, $data);
+               return api_format_data("photo_detail", $type, $data);
        }
 
        api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
                foreach ($r as $rr) {
                        $members = group_get_members($rr['id']);
                        $users = array();
-                       foreach ($members as $member) {
-                               $user = api_get_user($a, $member['nurl']);
-                               $users[] = $user;
+
+                       if ($type == "xml") {
+                               $user_element = "users";
+                               $k = 0;
+                               foreach ($members as $member) {
+                                       $user = api_get_user($a, $member['nurl']);
+                                       $users[$k++.":user"] = $user;
+                               }
+                       } else {
+                               $user_element = "user";
+                               foreach ($members as $member) {
+                                       $user = api_get_user($a, $member['nurl']);
+                                       $users[] = $user;
+                               }
                        }
-                       $grps[] = array('name' => $rr['name'], 'gid' => $rr['id'], 'user' => $users);
+                       $grps[] = array('name' => $rr['name'], 'gid' => $rr['id'], $user_element => $users);
                }
-               return api_apply_template("group_show", $type, array('groups' => $grps));
+               return api_format_data("groups", $type, array('group' => $grps));
        }
        api_register_func('api/friendica/group_show', 'api_friendica_group_show', true);
 
                if ($ret) {
                        // return success
                        $success = array('success' => $ret, 'gid' => $gid, 'name' => $name, 'status' => 'deleted', 'wrong users' => array());
-                       return api_apply_template("group_delete", $type, array('result' => $success));
+                       return api_format_data("group_delete", $type, array('result' => $success));
                }
                else
                        throw new BadRequestException('other API error');
                // return success message incl. missing users in array
                $status = ($erroraddinguser ? "missing user" : ($reactivate_group ? "reactivated" : "ok"));
                $success = array('success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers);
-               return api_apply_template("group_create", $type, array('result' => $success));
+               return api_format_data("group_create", $type, array('result' => $success));
        }
        api_register_func('api/friendica/group_create', 'api_friendica_group_create', true, API_METHOD_POST);
 
                // return success message incl. missing users in array
                $status = ($erroraddinguser ? "missing user" : "ok");
                $success = array('success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers);
-               return api_apply_template("group_update", $type, array('result' => $success));
+               return api_format_data("group_update", $type, array('result' => $success));
        }
        api_register_func('api/friendica/group_update', 'api_friendica_group_update', true, API_METHOD_POST);
 
                $res = do_like($id, $verb);
 
                if ($res) {
-                       if ($type == 'xml')
+                       if ($type == "xml")
                                $ok = "true";
                        else
                                $ok = "ok";
-                       return api_apply_template('test', $type, array('ok' => $ok));
+                       return api_format_data('ok', $type, array('ok' => $ok));
                } else {
                        throw new BadRequestException('Error adding activity');
                }
                        $notes = $xmlnotes;
                }
 
-               return api_apply_template("notes", $type, array('note' => $notes));
+               return api_format_data("notes", $type, array('note' => $notes));
        }
 
        /**
                        if ($r!==false) {
                                // we found the item, return it to the user
                                $user_info = api_get_user($a);
-                               $ret = api_format_items($r,$user_info);
-                               $data = array('statuses' => $ret);
-                               return api_apply_template("timeline", $type, $data);
+                               $ret = api_format_items($r,$user_info, false, $type);
+                               $data = array('status' => $ret);
+                               return api_format_data("status", $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('<auto>', $type, array('status' => "success"));
+               return api_format_data('result', $type, array('result' => "success"));
        }
 
        api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
index 133c2b319a2b80978a5de885d1ea2c3d75436364..d2a0f7655bf2af66d7fc2e86297868e0df3aad8d 100644 (file)
@@ -64,6 +64,8 @@ class xml {
                                        $element_parts = explode(":", $attr_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;
 
@@ -76,6 +78,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;
 
diff --git a/view/templates/api_timeline_atom.tpl b/view/templates/api_timeline_atom.tpl
deleted file mode 100644 (file)
index d11b4a3..0000000
+++ /dev/null
@@ -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>