]> git.mxchange.org Git - friendica.git/blob - mod/dirfind.php
Don't show the alternate url syntax in searches
[friendica.git] / mod / dirfind.php
1 <?php
2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
4
5 function dirfind_init(&$a) {
6
7         if(! x($a->page,'aside'))
8                 $a->page['aside'] = '';
9
10         $a->page['aside'] .= follow_widget();
11
12         $a->page['aside'] .= findpeople_widget();
13 }
14
15
16
17 function dirfind_content(&$a, $prefix = "") {
18
19         $community = false;
20
21         $local = get_config('system','poco_local_search');
22
23         $search = $prefix.notags(trim($_REQUEST['search']));
24
25         if(strpos($search,'@') === 0)
26                 $search = substr($search,1);
27
28         if(strpos($search,'!') === 0) {
29                 $search = substr($search,1);
30                 $community = true;
31         }
32
33         $o = '';
34
35         $o .= replace_macros(get_markup_template("section_title.tpl"),array(
36                 '$title' => sprintf( t('People Search - %s'), $search)
37         ));
38
39         if($search) {
40
41                 if ($local) {
42
43                         if ($community)
44                                 $extra_sql = " AND `community`";
45                         else
46                                 $extra_sql = "";
47
48                         $perpage = 80;
49                         $startrec = (($a->pager['page']) * $perpage) - $perpage;
50
51                         $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
52                                         (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
53                                                 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
54                                         dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
55                                         dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
56                                         dbesc(escape_tags($search)), dbesc(escape_tags($search)));
57
58                         $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
59                                         FROM `gcontact`
60                                         LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
61                                                 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
62                                                 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
63                                         WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
64                                         ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
65                                         (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
66                                                 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
67                                                 GROUP BY `gcontact`.`nurl`
68                                                 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
69                                         intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
70                                         dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
71                                         dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
72                                         dbesc(escape_tags($search)), dbesc(escape_tags($search)),
73                                         intval($startrec), intval($perpage));
74                         $j = new stdClass();
75                         $j->total = $count[0]["total"];
76                         $j->items_page = $perpage;
77                         $j->page = $a->pager['page'];
78                         foreach ($results AS $result) {
79                                 if (poco_alternate_ostatus_url($result["url"]))
80                                          continue;
81
82                                 if ($result["name"] == "") {
83                                         $urlparts = parse_url($result["url"]);
84                                         $result["name"] = end(explode("/", $urlparts["path"]));
85                                 }
86
87                                 $objresult = new stdClass();
88                                 $objresult->cid = $result["cid"];
89                                 $objresult->name = $result["name"];
90                                 $objresult->url = $result["url"];
91                                 $objresult->photo = $result["photo"];
92                                 $objresult->tags = $result["keywords"];
93
94                                 $j->results[] = $objresult;
95                         }
96
97                         // Add found profiles from the global directory to the local directory
98                         proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
99                 } else {
100
101                         $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
102
103                         if(strlen(get_config('system','directory_submit_url')))
104                                 $x = fetch_url(get_server().'/lsearch?f=' . $p .  '&search=' . urlencode($search));
105
106                         $j = json_decode($x);
107                 }
108
109                 if($j->total) {
110                         $a->set_pager_total($j->total);
111                         $a->set_pager_itemspage($j->items_page);
112                 }
113
114                 if(count($j->results)) {
115
116                         $tpl = get_markup_template('match.tpl');
117                         foreach($j->results as $jj) {
118
119                                 // If We already know this contact then don't show the "connect" button
120                                 if ($jj->cid > 0) {
121                                         $connlnk = "";
122                                         $conntxt = "";
123                                 } else {
124                                         $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
125                                         $conntxt = t('Connect');
126                                 }
127
128                                 $o .= replace_macros($tpl,array(
129                                         '$url' => zrl($jj->url),
130                                         '$name' => $jj->name,
131                                         '$photo' => proxy_url($jj->photo),
132                                         '$tags' => $jj->tags,
133                                         '$conntxt' => $conntxt,
134                                         '$connlnk' => $connlnk,
135                                 ));
136                         }
137                 }
138                 else {
139                         info( t('No matches') . EOL);
140                 }
141
142         }
143
144         $o .= '<div class="clear"></div>';
145         $o .= paginate($a);
146         return $o;
147 }