]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
API: The command "users/search" is now supported.
[friendica.git] / include / api.php
index ade783662bd5d15e08dea74bc80bbadf302c8cc4..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