Browse Source

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

tags/3.3-RC
Michael Vogel 5 years ago
parent
commit
a333036f00
3 changed files with 42 additions and 6 deletions
  1. 2
    2
      .htaccess
  2. 11
    3
      boot.php
  3. 29
    1
      include/api.php

+ 2
- 2
.htaccess View File

@@ -12,7 +12,7 @@ Deny from all
12 12
   # Protect repository directory from browsing
13 13
   RewriteRule "(^|/)\.git" - [F]
14 14
 
15
-  # Rewrite current-style URLs of the form 'index.php?q=x'.
15
+  # Rewrite current-style URLs of the form 'index.php?pagename=x'.
16 16
   # Also place auth information into REMOTE_USER for sites running
17 17
   # in CGI mode.
18 18
 
@@ -28,7 +28,7 @@ Deny from all
28 28
 
29 29
   RewriteCond %{REQUEST_FILENAME} !-f
30 30
   RewriteCond %{REQUEST_FILENAME} !-d
31
-  RewriteRule ^(.*)$ index.php?q=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
31
+  RewriteRule ^(.*)$ index.php?pagename=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
32 32
 
33 33
 </IfModule>
34 34
 

+ 11
- 3
boot.php View File

@@ -507,13 +507,20 @@ if(! class_exists('App')) {
507 507
 
508 508
 			set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
509 509
 
510
-			if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
510
+			if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") {
511
+				$this->query_string = substr($_SERVER['QUERY_STRING'],9);
512
+				// removing trailing / - maybe a nginx problem
513
+				if (substr($this->query_string, 0, 1) == "/")
514
+					$this->query_string = substr($this->query_string, 1);
515
+			} elseif((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
511 516
 				$this->query_string = substr($_SERVER['QUERY_STRING'],2);
512 517
 				// removing trailing / - maybe a nginx problem
513 518
 				if (substr($this->query_string, 0, 1) == "/")
514 519
 					$this->query_string = substr($this->query_string, 1);
515 520
 			}
516
-			if(x($_GET,'q'))
521
+			if (x($_GET,'pagename'))
522
+				$this->cmd = trim($_GET['pagename'],'/\\');
523
+			elseif (x($_GET,'q'))
517 524
 				$this->cmd = trim($_GET['q'],'/\\');
518 525
 
519 526
 			// unix style "homedir"
@@ -1019,7 +1026,8 @@ if(! function_exists('update_db')) {
1019 1026
 
1020 1027
 					$t = get_config('database','dbupdate_'.DB_UPDATE_VERSION);
1021 1028
 					if($t !== false)
1022
-						break;
1029
+						return;
1030
+
1023 1031
 					set_config('database','dbupdate_'.DB_UPDATE_VERSION, time());
1024 1032
 
1025 1033
 					require_once("include/dbstructure.php");

+ 29
- 1
include/api.php View File

@@ -122,7 +122,6 @@
122 122
 
123 123
 		// preset
124 124
 		$type="json";
125
-
126 125
 		foreach ($API as $p=>$info){
127 126
 			if (strpos($a->query_string, $p)===0){
128 127
 				$called_api= explode("/",$p);
@@ -936,6 +935,35 @@
936 935
 	}
937 936
 	api_register_func('api/users/show','api_users_show');
938 937
 
938
+
939
+	function api_users_search(&$a, $type) {
940
+		$page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
941
+
942
+		$userlist = array();
943
+
944
+		if (isset($_GET["q"])) {
945
+			$r = q("SELECT id FROM unique_contacts WHERE name='%s'", dbesc($_GET["q"]));
946
+			if (!count($r))
947
+				$r = q("SELECT id FROM unique_contacts WHERE nick='%s'", dbesc($_GET["q"]));
948
+
949
+			if (count($r)) {
950
+				foreach ($r AS $user) {
951
+					$user_info = api_get_user($a, $user["id"]);
952
+					//echo print_r($user_info, true)."\n";
953
+					$userdata = api_apply_template("user", $type, array('user' => $user_info));
954
+					$userlist[] = $userdata["user"];
955
+				}
956
+				$userlist = array("users" => $userlist);
957
+			} else
958
+				die(api_error($a, $type, t("User not found.")));
959
+		} else
960
+			die(api_error($a, $type, t("User not found.")));
961
+
962
+		return ($userlist);
963
+	}
964
+
965
+	api_register_func('api/users/search','api_users_search');
966
+
939 967
 	/**
940 968
 	 *
941 969
 	 * http://developer.twitter.com/doc/get/statuses/home_timeline

Loading…
Cancel
Save