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 $header = sprintf( t('People Search - %s'), $search);
37 if ((valid_email($search) AND validate_email($search)) OR
38 (substr(normalise_link($search), 0, 7) == "http://")) {
39 $user_data = probe_url($search);
40 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
44 if(strpos($search,'!') === 0) {
45 $search = substr($search,1);
47 $header = sprintf( t('Forum Search - %s'), $search);
58 $j->page = $a->pager['page'];
60 $objresult = new stdClass();
62 $objresult->name = $user_data["name"];
63 $objresult->addr = $user_data["addr"];
64 $objresult->url = $user_data["url"];
65 $objresult->photo = $user_data["photo"];
66 $objresult->tags = "";
67 $objresult->network = $user_data["network"];
69 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
70 dbesc(normalise_link($user_data["url"])), intval(local_user()));
72 $objresult->cid = $contact[0]["id"];
75 $j->results[] = $objresult;
77 poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
78 "", "", "", "", "", datetime_convert(), 0);
82 $extra_sql = " AND `community`";
87 $startrec = (($a->pager['page']) * $perpage) - $perpage;
89 if (get_config('system','diaspora_enabled'))
90 $diaspora = NETWORK_DIASPORA;
92 $diaspora = NETWORK_DFRN;
94 if (!get_config('system','ostatus_disabled'))
95 $ostatus = NETWORK_OSTATUS;
97 $ostatus = NETWORK_DFRN;
99 $search2 = "%".$search."%";
101 $count = q("SELECT count(*) AS `total` FROM `gcontact`
102 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
103 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
104 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
105 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
106 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
107 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
108 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
109 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
110 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
111 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
112 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
114 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
116 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
117 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
118 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
119 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
120 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
121 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
122 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
123 GROUP BY `gcontact`.`nurl`
124 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
125 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
126 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
127 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
128 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
129 intval($startrec), intval($perpage));
131 $j->total = $count[0]["total"];
132 $j->items_page = $perpage;
133 $j->page = $a->pager['page'];
134 foreach ($results AS $result) {
135 if (poco_alternate_ostatus_url($result["url"]))
138 $result = get_contact_details_by_url($result["url"], local_user(), $result);
140 if ($result["name"] == "") {
141 $urlparts = parse_url($result["url"]);
142 $result["name"] = end(explode("/", $urlparts["path"]));
145 $objresult = new stdClass();
146 $objresult->cid = $result["cid"];
147 $objresult->name = $result["name"];
148 $objresult->addr = $result["addr"];
149 $objresult->url = $result["url"];
150 $objresult->photo = $result["photo"];
151 $objresult->tags = $result["keywords"];
152 $objresult->network = $result["network"];
154 $j->results[] = $objresult;
157 // Add found profiles from the global directory to the local directory
158 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
161 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
163 if(strlen(get_config('system','directory')))
164 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
166 $j = json_decode($x);
170 $a->set_pager_total($j->total);
171 $a->set_pager_itemspage($j->items_page);
174 if(count($j->results)) {
178 foreach($j->results as $jj) {
182 $contact_details = get_contact_details_by_url($jj->url, local_user());
184 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
186 // If We already know this contact then don't show the "connect" button
190 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
193 $photo_menu = contact_photo_menu($contact[0]);
194 $details = _contact_detail_for_template($contact[0]);
195 $alt_text = $details['alt_text'];
197 $photo_menu = array();
199 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
200 $conntxt = t('Connect');
202 'profile' => array(t("View Profile"), zrl($jj->url)),
203 'follow' => array(t("Connect/Follow"), $connlnk)
207 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
210 'alt_text' => $alt_text,
211 'url' => zrl($jj->url),
212 'itemurl' => $itemurl,
213 'name' => htmlentities($jj->name),
214 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
215 'img_hover' => $jj->tags,
216 'conntxt' => $conntxt,
217 'connlnk' => $connlnk,
218 'photo_menu' => $photo_menu,
219 'details' => $contact_details['location'],
220 'tags' => $contact_details['keywords'],
221 'about' => $contact_details['about'],
222 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
223 'network' => network_to_name($jj->network, $jj->url),
229 $tpl = get_markup_template('viewcontact_template.tpl');
231 $o .= replace_macros($tpl,array(
233 '$contacts' => $entries,
234 '$paginate' => paginate($a),
239 info( t('No matches') . EOL);