2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
4 require_once('include/Contact.php');
5 require_once('include/contact_selectors.php');
6 require_once('mod/contacts.php');
8 function dirfind_init(&$a) {
11 notice( t('Permission denied.') . EOL );
15 if(! x($a->page,'aside'))
16 $a->page['aside'] = '';
18 $a->page['aside'] .= findpeople_widget();
20 $a->page['aside'] .= follow_widget();
25 function dirfind_content(&$a, $prefix = "") {
28 $discover_user = false;
30 $local = get_config('system','poco_local_search');
32 $search = $prefix.notags(trim($_REQUEST['search']));
34 if(strpos($search,'@') === 0) {
35 $search = substr($search,1);
36 if (valid_email($search)) {
37 $user_data = probe_url($search);
38 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
42 if(strpos($search,'!') === 0) {
43 $search = substr($search,1);
53 $j->total = $count[0]["total"];
55 $j->page = $a->pager['page'];
57 $objresult = new stdClass();
59 $objresult->name = $user_data["name"];
60 $objresult->addr = $user_data["addr"];
61 $objresult->url = $user_data["url"];
62 $objresult->photo = $user_data["photo"];
63 $objresult->tags = "";
64 $objresult->network = $user_data["network"];
66 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
67 dbesc(normalise_link($user_data["url"])), intval(local_user()));
69 $objresult->cid = $contact[0]["id"];
72 $j->results[] = $objresult;
74 poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
75 "", "", "", "", "", datetime_convert(), 0);
79 $extra_sql = " AND `community`";
84 $startrec = (($a->pager['page']) * $perpage) - $perpage;
86 if (get_config('system','diaspora_enabled'))
87 $diaspora = NETWORK_DIASPORA;
89 $diaspora = NETWORK_DFRN;
91 if (!get_config('system','ostatus_disabled'))
92 $ostatus = NETWORK_OSTATUS;
94 $ostatus = NETWORK_DFRN;
96 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
97 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
98 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
99 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
100 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
101 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
103 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
105 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
106 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
107 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
108 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
109 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
110 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
111 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
112 GROUP BY `gcontact`.`nurl`
113 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
114 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
115 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
116 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
117 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
118 intval($startrec), intval($perpage));
120 $j->total = $count[0]["total"];
121 $j->items_page = $perpage;
122 $j->page = $a->pager['page'];
123 foreach ($results AS $result) {
124 if (poco_alternate_ostatus_url($result["url"]))
127 if ($result["name"] == "") {
128 $urlparts = parse_url($result["url"]);
129 $result["name"] = end(explode("/", $urlparts["path"]));
132 $objresult = new stdClass();
133 $objresult->cid = $result["cid"];
134 $objresult->name = $result["name"];
135 $objresult->addr = $result["addr"];
136 $objresult->url = $result["url"];
137 $objresult->photo = $result["photo"];
138 $objresult->tags = $result["keywords"];
139 $objresult->network = $result["network"];
141 $j->results[] = $objresult;
144 // Add found profiles from the global directory to the local directory
145 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
148 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
150 if(strlen(get_config('system','directory')))
151 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
153 $j = json_decode($x);
157 $a->set_pager_total($j->total);
158 $a->set_pager_itemspage($j->items_page);
161 if(count($j->results)) {
165 foreach($j->results as $jj) {
169 $contact_details = get_contact_details_by_url($jj->url, local_user());
171 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
173 // If We already know this contact then don't show the "connect" button
177 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
180 $photo_menu = contact_photo_menu($contact[0]);
181 $details = _contact_detail_for_template($contact[0]);
182 $alt_text = $details['alt_text'];
184 $photo_menu = array();
186 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
187 $conntxt = t('Connect');
188 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
189 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
192 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
195 'alt_text' => $alt_text,
196 'url' => zrl($jj->url),
197 'itemurl' => $itemurl,
198 'name' => htmlentities($jj->name),
199 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
200 'img_hover' => $jj->tags,
201 'conntxt' => $conntxt,
202 'connlnk' => $connlnk,
203 'photo_menu' => $photo_menu,
204 'details' => $contact_details['location'],
205 'tags' => $contact_details['keywords'],
206 'about' => $contact_details['about'],
207 'network' => network_to_name($jj->network, $jj->url),
213 $tpl = get_markup_template('viewcontact_template.tpl');
215 $o .= replace_macros($tpl,array(
216 'title' => sprintf( t('People Search - %s'), $search),
217 '$contacts' => $entries,
218 '$paginate' => paginate($a),
223 info( t('No matches') . EOL);