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 if(! function_exists('dirfind_init')) {
9 function dirfind_init(&$a) {
12 notice( t('Permission denied.') . EOL );
16 if(! x($a->page,'aside'))
17 $a->page['aside'] = '';
19 $a->page['aside'] .= findpeople_widget();
21 $a->page['aside'] .= follow_widget();
25 if(! function_exists('dirfind_content')) {
26 function dirfind_content(&$a, $prefix = "") {
29 $discover_user = false;
31 $local = get_config('system','poco_local_search');
33 $search = $prefix.notags(trim($_REQUEST['search']));
35 if(strpos($search,'@') === 0) {
36 $search = substr($search,1);
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);
57 $j->page = $a->pager['page'];
59 $objresult = new stdClass();
61 $objresult->name = $user_data["name"];
62 $objresult->addr = $user_data["addr"];
63 $objresult->url = $user_data["url"];
64 $objresult->photo = $user_data["photo"];
65 $objresult->tags = "";
66 $objresult->network = $user_data["network"];
68 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
69 dbesc(normalise_link($user_data["url"])), intval(local_user()));
71 $objresult->cid = $contact[0]["id"];
74 $j->results[] = $objresult;
76 poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
77 "", "", "", "", "", datetime_convert(), 0);
81 $extra_sql = " AND `community`";
86 $startrec = (($a->pager['page']) * $perpage) - $perpage;
88 if (get_config('system','diaspora_enabled'))
89 $diaspora = NETWORK_DIASPORA;
91 $diaspora = NETWORK_DFRN;
93 if (!get_config('system','ostatus_disabled'))
94 $ostatus = NETWORK_OSTATUS;
96 $ostatus = NETWORK_DFRN;
98 $count = q("SELECT count(*) AS `total` FROM `gcontact`
99 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
100 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
101 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
102 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
103 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
104 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
105 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql",
106 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
107 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
108 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
109 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
111 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
113 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
114 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
115 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
116 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
117 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
118 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
119 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
120 GROUP BY `gcontact`.`nurl`
121 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
122 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
123 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
124 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
125 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
126 intval($startrec), intval($perpage));
128 $j->total = $count[0]["total"];
129 $j->items_page = $perpage;
130 $j->page = $a->pager['page'];
131 foreach ($results AS $result) {
132 if (poco_alternate_ostatus_url($result["url"]))
135 if ($result["name"] == "") {
136 $urlparts = parse_url($result["url"]);
137 $result["name"] = end(explode("/", $urlparts["path"]));
140 $objresult = new stdClass();
141 $objresult->cid = $result["cid"];
142 $objresult->name = $result["name"];
143 $objresult->addr = $result["addr"];
144 $objresult->url = $result["url"];
145 $objresult->photo = $result["photo"];
146 $objresult->tags = $result["keywords"];
147 $objresult->network = $result["network"];
149 $j->results[] = $objresult;
152 // Add found profiles from the global directory to the local directory
153 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
156 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
158 if(strlen(get_config('system','directory')))
159 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
161 $j = json_decode($x);
165 $a->set_pager_total($j->total);
166 $a->set_pager_itemspage($j->items_page);
169 if(count($j->results)) {
173 foreach($j->results as $jj) {
177 $contact_details = get_contact_details_by_url($jj->url, local_user());
179 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
181 // If We already know this contact then don't show the "connect" button
185 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
188 $photo_menu = contact_photo_menu($contact[0]);
189 $details = _contact_detail_for_template($contact[0]);
190 $alt_text = $details['alt_text'];
192 $photo_menu = array();
194 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
195 $conntxt = t('Connect');
196 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
197 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
200 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
203 'alt_text' => $alt_text,
204 'url' => zrl($jj->url),
205 'itemurl' => $itemurl,
206 'name' => htmlentities($jj->name),
207 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
208 'img_hover' => $jj->tags,
209 'conntxt' => $conntxt,
210 'connlnk' => $connlnk,
211 'photo_menu' => $photo_menu,
212 'details' => $contact_details['location'],
213 'tags' => $contact_details['keywords'],
214 'about' => $contact_details['about'],
215 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
216 'network' => network_to_name($jj->network, $jj->url),
222 $tpl = get_markup_template('viewcontact_template.tpl');
224 $o .= replace_macros($tpl,array(
225 'title' => sprintf( t('People Search - %s'), $search),
226 '$contacts' => $entries,
227 '$paginate' => paginate($a),
232 info( t('No matches') . EOL);