2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
5 function dirfind_init(&$a) {
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 (poco_alternate_ostatus_url($result["url"]))
82 if ($result["name"] == "") {
83 $urlparts = parse_url($result["url"]);
84 $result["name"] = end(explode("/", $urlparts["path"]));
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"];
94 $j->results[] = $objresult;
97 // Add found profiles from the global directory to the local directory
98 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
101 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
103 if(strlen(get_config('system','directory')))
104 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
106 $j = json_decode($x);
110 $a->set_pager_total($j->total);
111 $a->set_pager_itemspage($j->items_page);
114 if(count($j->results)) {
116 $tpl = get_markup_template('match.tpl');
117 foreach($j->results as $jj) {
119 // If We already know this contact then don't show the "connect" button
124 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
125 $conntxt = t('Connect');
128 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
130 $o .= replace_macros($tpl,array(
131 '$url' => zrl($jj->url),
132 '$name' => $jj->name,
133 '$photo' => proxy_url($jj->photo),
134 '$tags' => $jj->tags,
135 '$conntxt' => $conntxt,
136 '$connlnk' => $connlnk,
141 info( t('No matches') . EOL);
146 $o .= '<div class="clear"></div>';