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, $prefix = "") {
21 $local = get_config('system','poco_local_search');
23 $search = $prefix.notags(trim($_REQUEST['search']));
25 if(strpos($search,'@') === 0)
26 $search = substr($search,1);
28 if(strpos($search,'!') === 0) {
29 $search = substr($search,1);
35 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
36 '$title' => sprintf( t('People Search - %s'), $search)
44 $extra_sql = " AND `community`";
49 $startrec = (($a->pager['page']) * $perpage) - $perpage;
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)));
58 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
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));
75 $j->total = $count[0]["total"];
76 $j->items_page = $perpage;
77 $j->page = $a->pager['page'];
78 foreach ($results AS $result) {
79 if ($result["name"] == "") {
80 $urlparts = parse_url($result["url"]);
81 $result["name"] = end(explode("/", $urlparts["path"]));
84 $objresult = new stdClass();
85 $objresult->cid = $result["cid"];
86 $objresult->name = $result["name"];
87 $objresult->url = $result["url"];
88 $objresult->photo = $result["photo"];
89 $objresult->tags = $result["keywords"];
91 $j->results[] = $objresult;
94 // Add found profiles from the global directory to the local directory
95 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
98 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
100 if(strlen(get_config('system','directory_submit_url')))
101 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
103 $j = json_decode($x);
107 $a->set_pager_total($j->total);
108 $a->set_pager_itemspage($j->items_page);
111 if(count($j->results)) {
113 $tpl = get_markup_template('match.tpl');
114 foreach($j->results as $jj) {
116 // If We already know this contact then don't show the "connect" button
121 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
122 $conntxt = t('Connect');
125 $o .= replace_macros($tpl,array(
126 '$url' => zrl($jj->url),
127 '$name' => $jj->name,
128 '$photo' => proxy_url($jj->photo),
129 '$tags' => $jj->tags,
130 '$conntxt' => $conntxt,
131 '$connlnk' => $connlnk,
136 info( t('No matches') . EOL);
141 $o .= '<div class="clear"></div>';