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