API: The command "users/search" is now supported.

This commit is contained in:
Michael Vogel 2014-09-07 07:32:09 +02:00
parent 0e9c8f6f1a
commit a333036f00
3 changed files with 42 additions and 6 deletions

View File

@ -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]
</IfModule>

View File

@ -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");

View File

@ -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