From a333036f005e749269eeeadfb78ef0ad8badbde5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 7 Sep 2014 07:32:09 +0200 Subject: [PATCH] API: The command "users/search" is now supported. --- .htaccess | 4 ++-- boot.php | 14 +++++++++++--- include/api.php | 30 +++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.htaccess b/.htaccess index 83d67e8f89..1b63f9ad6f 100644 --- a/.htaccess +++ b/.htaccess @@ -12,7 +12,7 @@ Deny from all # Protect repository directory from browsing RewriteRule "(^|/)\.git" - [F] - # Rewrite current-style URLs of the form 'index.php?q=x'. + # Rewrite current-style URLs of the form 'index.php?pagename=x'. # Also place auth information into REMOTE_USER for sites running # in CGI mode. @@ -28,7 +28,7 @@ Deny from all RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.*)$ index.php?q=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA] + RewriteRule ^(.*)$ index.php?pagename=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA] diff --git a/boot.php b/boot.php index 5ef24f4944..3ea08477d0 100644 --- a/boot.php +++ b/boot.php @@ -507,13 +507,20 @@ if(! class_exists('App')) { set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path()); - if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { + if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { + $this->query_string = substr($_SERVER['QUERY_STRING'],9); + // removing trailing / - maybe a nginx problem + if (substr($this->query_string, 0, 1) == "/") + $this->query_string = substr($this->query_string, 1); + } elseif((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { $this->query_string = substr($_SERVER['QUERY_STRING'],2); // removing trailing / - maybe a nginx problem if (substr($this->query_string, 0, 1) == "/") $this->query_string = substr($this->query_string, 1); } - if(x($_GET,'q')) + if (x($_GET,'pagename')) + $this->cmd = trim($_GET['pagename'],'/\\'); + elseif (x($_GET,'q')) $this->cmd = trim($_GET['q'],'/\\'); // unix style "homedir" @@ -1019,7 +1026,8 @@ if(! function_exists('update_db')) { $t = get_config('database','dbupdate_'.DB_UPDATE_VERSION); if($t !== false) - break; + return; + set_config('database','dbupdate_'.DB_UPDATE_VERSION, time()); require_once("include/dbstructure.php"); diff --git a/include/api.php b/include/api.php index ade783662b..69dc51bac9 100644 --- a/include/api.php +++ b/include/api.php @@ -122,7 +122,6 @@ // preset $type="json"; - foreach ($API as $p=>$info){ if (strpos($a->query_string, $p)===0){ $called_api= explode("/",$p); @@ -936,6 +935,35 @@ } 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 -- 2.39.5