]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #2045 from annando/1511-dirfind-addr
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Sun, 8 Nov 2015 14:19:11 +0000 (15:19 +0100)
committerTobias Diekershoff <tobias.diekershoff@gmx.net>
Sun, 8 Nov 2015 14:19:11 +0000 (15:19 +0100)
You can now discover previously unknown users via the dirsearch

include/text.php
mod/dirfind.php

index e6af5f3db7c3ff07608162cca6a08977496a09bb..b5010864e68853b82c2f93b1e0c6f7b7941d5262 100644 (file)
@@ -1020,8 +1020,9 @@ if(! function_exists('valid_email')) {
  */
 function valid_email($x){
 
-       if(get_config('system','disable_email_validation'))
-               return true;
+       // Removed because Fabio told me so.
+       //if(get_config('system','disable_email_validation'))
+       //      return true;
 
        if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
                return true;
index 3df27e5fb7840da113614a6cabf8715f24f6e271..6a4c7f1ced21a542c33225f400b2f0913e39ea27 100644 (file)
@@ -25,13 +25,20 @@ function dirfind_init(&$a) {
 function dirfind_content(&$a, $prefix = "") {
 
        $community = false;
+       $discover_user = false;
 
        $local = get_config('system','poco_local_search');
 
        $search = $prefix.notags(trim($_REQUEST['search']));
 
-       if(strpos($search,'@') === 0)
+       if(strpos($search,'@') === 0) {
                $search = substr($search,1);
+               if ((valid_email($search) AND validate_email($search)) OR
+                       (substr(normalise_link($search), 0, 7) == "http://")) {
+                       $user_data = probe_url($search);
+                       $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
+               }
+       }
 
        if(strpos($search,'!') === 0) {
                $search = substr($search,1);
@@ -42,7 +49,32 @@ function dirfind_content(&$a, $prefix = "") {
 
        if($search) {
 
-               if ($local) {
+               if ($discover_user) {
+                       $j = new stdClass();
+                       $j->total = 1;
+                       $j->items_page = 1;
+                       $j->page = $a->pager['page'];
+
+                       $objresult = new stdClass();
+                       $objresult->cid = 0;
+                       $objresult->name = $user_data["name"];
+                       $objresult->addr = $user_data["addr"];
+                       $objresult->url = $user_data["url"];
+                       $objresult->photo = $user_data["photo"];
+                       $objresult->tags = "";
+                       $objresult->network = $user_data["network"];
+
+                       $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
+                                       dbesc(normalise_link($user_data["url"])), intval(local_user()));
+                       if ($contact)
+                               $objresult->cid = $contact[0]["id"];
+
+
+                       $j->results[] = $objresult;
+
+                       poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
+                               "", "", "", "", "", datetime_convert(), 0);
+               } elseif ($local) {
 
                        if ($community)
                                $extra_sql = " AND `community`";