]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
API: The command "users/search" is now supported.
[friendica.git] / include / api.php
index 7cc72948d184d0e7c96734fdccd8c94868ce1b64..69dc51bac99ac4770db06136b6e67467397a29ac 100644 (file)
 
                // preset
                $type="json";
-
                foreach ($API as $p=>$info){
                        if (strpos($a->query_string, $p)===0){
                                $called_api= explode("/",$p);
        }
        api_register_func('api/users/show','api_users_show');
 
+
+       function api_users_search(&$a, $type) {
+               $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
+
+               $userlist = array();
+
+               if (isset($_GET["q"])) {
+                       $r = q("SELECT id FROM unique_contacts WHERE name='%s'", dbesc($_GET["q"]));
+                       if (!count($r))
+                               $r = q("SELECT id FROM unique_contacts WHERE nick='%s'", dbesc($_GET["q"]));
+
+                       if (count($r)) {
+                               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('user' => $user_info));
+                                       $userlist[] = $userdata["user"];
+                               }
+                               $userlist = array("users" => $userlist);
+                       } else
+                               die(api_error($a, $type, t("User not found.")));
+               } else
+                       die(api_error($a, $type, t("User not found.")));
+
+               return ($userlist);
+       }
+
+       api_register_func('api/users/search','api_users_search');
+
        /**
         *
         * http://developer.twitter.com/doc/get/statuses/home_timeline
 
                $a = get_app();
 
-               $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'privacy_image_cache' AND `installed`");
-               $image_cache = (count($result) > 0);
-
                $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
 
                if ($include_entities != "true") {
-                       if ($image_cache) {
-                               require_once("addon/privacy_image_cache/privacy_image_cache.php");
+                       require_once("mod/proxy.php");
 
-                               preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
+                       preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
 
-                               foreach ($images[1] AS $image) {
-                                       $replace = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($image);
-                                       $text = str_replace($image, $replace, $text);
-                               }
+                       foreach ($images[1] AS $image) {
+                               $replace = proxy_url($image);
+                               $text = str_replace($image, $replace, $text);
                        }
                        return array();
                }
                                require_once("include/Photo.php");
                                $image = get_photo_info($url);
                                if ($image) {
-                                       // If privacy_image_cache is activated, then use the following sizes:
+                                       // If image cache is activated, then use the following sizes:
                                        // thumb  (150), small (340), medium (600) and large (1024)
-                                       if ($image_cache) {
-                                               require_once("addon/privacy_image_cache/privacy_image_cache.php");
-                                               $media_url = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($url);
+                                       if (!get_config("system", "proxy_disabled")) {
+                                               require_once("mod/proxy.php");
+                                               $media_url = proxy_url($url);
 
                                                $sizes = array();
                                                $scale = scale_image($image[0], $image[1], 150);
        api_register_func('api/oauth/request_token', 'api_oauth_request_token', false);
        api_register_func('api/oauth/access_token', 'api_oauth_access_token', false);
 
+
+       function api_fr_photos_list(&$a,$type) {
+               if (api_user()===false) return false;
+               $r = q("select distinct `resource-id` from photo where uid = %d and album != 'Contact Photos' ",
+                       intval(local_user())
+               );
+               if($r) {
+                       $ret = array();
+                       foreach($r as $rr)
+                               $ret[] = $rr['resource-id'];
+                       header("Content-type: application/json");
+                       echo json_encode($ret);
+               }
+               killme();
+       }
+
+       function api_fr_photo_detail(&$a,$type) {
+               if (api_user()===false) return false;
+               if(! $_REQUEST['photo_id']) return false;
+               $scale = ((array_key_exists('scale',$_REQUEST)) ? intval($_REQUEST['scale']) : 0);
+               $r = q("select * from photo where uid = %d and `resource-id` = '%s' and scale = %d limit 1",
+                       intval(local_user()),
+                       dbesc($_REQUEST['photo_id']),
+                       intval($scale)
+               );
+               if($r) {
+                       header("Content-type: application/json");
+                       $r[0]['data'] = base64_encode($r[0]['data']);
+                       echo json_encode($r[0]);
+               }
+
+               killme();       
+       }
+
+       api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
+       api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
+
+
+
+
+
+
 function api_share_as_retweet($a, $uid, &$item) {
        $body = trim($item["body"]);