3 function dirfind_init(&$a) {
5 require_once('include/contact_widgets.php');
7 if(! x($a->page,'aside'))
8 $a->page['aside'] = '';
10 $a->page['aside'] .= follow_widget();
12 $a->page['aside'] .= findpeople_widget();
17 function dirfind_content(&$a) {
19 $local = get_config('system','poco_local_search');
21 $search = notags(trim($_REQUEST['search']));
23 if(strpos($search,'@') === 0)
24 $search = substr($search,1);
28 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
29 '$title' => sprintf( t('People Search - %s'), $search)
37 $startrec = (($a->pager['page']) * $perpage) - $perpage;
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)));
46 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
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));
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"]));
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"];
76 $j->results[] = $objresult;
79 // Add found profiles from the global directory to the local directory
80 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
83 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
85 if(strlen(get_config('system','directory_submit_url')))
86 $x = fetch_url('http://dir.friendica.com/lsearch?f=' . $p . '&search=' . urlencode($search));
92 $a->set_pager_total($j->total);
93 $a->set_pager_itemspage($j->items_page);
96 if(count($j->results)) {
98 $tpl = get_markup_template('match.tpl');
99 foreach($j->results as $jj) {
101 // If We already know this contact then don't show the "connect" button
106 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
107 $conntxt = t('Connect');
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,
121 info( t('No matches') . EOL);
126 $o .= '<div class="clear"></div>';