]> git.mxchange.org Git - friendica.git/commitdiff
API: The command "users/search" is now supported.
authorMichael Vogel <icarus@dabo.de>
Sun, 7 Sep 2014 05:32:09 +0000 (07:32 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 7 Sep 2014 05:32:09 +0000 (07:32 +0200)
.htaccess
boot.php
include/api.php

index 83d67e8f890b2d6315857481bac4587d50660092..1b63f9ad6fb2b81060f5da54cdc82277ceb7f310 100644 (file)
--- 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]
 
 </IfModule>
 
index 5ef24f4944b7060ad5483211e468a3233f4a187f..3ea08477d07b66418458bc814e78ac3b8a0b1a95 100644 (file)
--- 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");
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