2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
4 require_once('include/Contact.php');
6 function dirfind_init(&$a) {
8 if(! x($a->page,'aside'))
9 $a->page['aside'] = '';
11 $a->page['aside'] .= follow_widget();
13 $a->page['aside'] .= findpeople_widget();
18 function dirfind_content(&$a, $prefix = "") {
22 $local = get_config('system','poco_local_search');
24 $search = $prefix.notags(trim($_REQUEST['search']));
26 if(strpos($search,'@') === 0)
27 $search = substr($search,1);
29 if(strpos($search,'!') === 0) {
30 $search = substr($search,1);
36 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
37 '$title' => sprintf( t('People Search - %s'), $search)
45 $extra_sql = " AND `community`";
50 $startrec = (($a->pager['page']) * $perpage) - $perpage;
52 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
53 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
54 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
55 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)));
59 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
61 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
62 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
63 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
64 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
65 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
66 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
67 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
68 GROUP BY `gcontact`.`nurl`
69 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
70 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
71 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
72 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
73 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
74 intval($startrec), intval($perpage));
76 $j->total = $count[0]["total"];
77 $j->items_page = $perpage;
78 $j->page = $a->pager['page'];
79 foreach ($results AS $result) {
80 if (poco_alternate_ostatus_url($result["url"]))
83 if ($result["name"] == "") {
84 $urlparts = parse_url($result["url"]);
85 $result["name"] = end(explode("/", $urlparts["path"]));
88 $objresult = new stdClass();
89 $objresult->cid = $result["cid"];
90 $objresult->name = $result["name"];
91 $objresult->url = $result["url"];
92 $objresult->photo = $result["photo"];
93 $objresult->tags = $result["keywords"];
95 $j->results[] = $objresult;
98 // Add found profiles from the global directory to the local directory
99 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
102 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
104 if(strlen(get_config('system','directory')))
105 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
107 $j = json_decode($x);
111 $a->set_pager_total($j->total);
112 $a->set_pager_itemspage($j->items_page);
115 if(count($j->results)) {
119 $tpl = get_markup_template('match.tpl');
120 foreach($j->results as $jj) {
122 // If We already know this contact then don't show the "connect" button
126 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
129 $photo_menu = contact_photo_menu($contact[0]);
131 $photo_menu = array();
133 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
134 $conntxt = t('Connect');
135 $photo_menu = array(array(t("Connect/Follow"), $connlnk));
138 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
140 $o .= replace_macros($tpl,array(
141 '$url' => zrl($jj->url),
142 '$name' => $jj->name,
143 '$photo' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
144 '$tags' => $jj->tags,
145 '$conntxt' => $conntxt,
146 '$connlnk' => $connlnk,
147 '$photo_menu' => $photo_menu,
153 info( t('No matches') . EOL);
158 $o .= '<div class="clear"></div>';