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) AND validate_email($search)) OR
37 (substr(normalise_link($search), 0, 7) == "http://")) {
38 $user_data = probe_url($search);
39 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
43 if(strpos($search,'!') === 0) {
44 $search = substr($search,1);
56 $j->page = $a->pager['page'];
58 $objresult = new stdClass();
60 $objresult->name = $user_data["name"];
61 $objresult->addr = $user_data["addr"];
62 $objresult->url = $user_data["url"];
63 $objresult->photo = $user_data["photo"];
64 $objresult->tags = "";
65 $objresult->network = $user_data["network"];
67 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
68 dbesc(normalise_link($user_data["url"])), intval(local_user()));
70 $objresult->cid = $contact[0]["id"];
73 $j->results[] = $objresult;
75 poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"],
76 "", "", "", "", "", datetime_convert(), 0);
80 $extra_sql = " AND `community`";
85 $startrec = (($a->pager['page']) * $perpage) - $perpage;
87 if (get_config('system','diaspora_enabled'))
88 $diaspora = NETWORK_DIASPORA;
90 $diaspora = NETWORK_DFRN;
92 if (!get_config('system','ostatus_disabled'))
93 $ostatus = NETWORK_OSTATUS;
95 $ostatus = NETWORK_DFRN;
97 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
98 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
99 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
100 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
101 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
102 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
104 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
106 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
107 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
108 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
109 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
110 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
111 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
112 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
113 GROUP BY `gcontact`.`nurl`
114 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
115 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
116 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
117 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
118 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
119 intval($startrec), intval($perpage));
121 $j->total = $count[0]["total"];
122 $j->items_page = $perpage;
123 $j->page = $a->pager['page'];
124 foreach ($results AS $result) {
125 if (poco_alternate_ostatus_url($result["url"]))
128 if ($result["name"] == "") {
129 $urlparts = parse_url($result["url"]);
130 $result["name"] = end(explode("/", $urlparts["path"]));
133 $objresult = new stdClass();
134 $objresult->cid = $result["cid"];
135 $objresult->name = $result["name"];
136 $objresult->addr = $result["addr"];
137 $objresult->url = $result["url"];
138 $objresult->photo = $result["photo"];
139 $objresult->tags = $result["keywords"];
140 $objresult->network = $result["network"];
142 $j->results[] = $objresult;
145 // Add found profiles from the global directory to the local directory
146 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
149 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
151 if(strlen(get_config('system','directory')))
152 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
154 $j = json_decode($x);
158 $a->set_pager_total($j->total);
159 $a->set_pager_itemspage($j->items_page);
162 if(count($j->results)) {
166 foreach($j->results as $jj) {
170 $contact_details = get_contact_details_by_url($jj->url, local_user());
172 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
174 // If We already know this contact then don't show the "connect" button
178 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
181 $photo_menu = contact_photo_menu($contact[0]);
182 $details = _contact_detail_for_template($contact[0]);
183 $alt_text = $details['alt_text'];
185 $photo_menu = array();
187 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
188 $conntxt = t('Connect');
189 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
190 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
193 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
196 'alt_text' => $alt_text,
197 'url' => zrl($jj->url),
198 'itemurl' => $itemurl,
199 'name' => htmlentities($jj->name),
200 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
201 'img_hover' => $jj->tags,
202 'conntxt' => $conntxt,
203 'connlnk' => $connlnk,
204 'photo_menu' => $photo_menu,
205 'details' => $contact_details['location'],
206 'tags' => $contact_details['keywords'],
207 'about' => $contact_details['about'],
208 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
209 'network' => network_to_name($jj->network, $jj->url),
215 $tpl = get_markup_template('viewcontact_template.tpl');
217 $o .= replace_macros($tpl,array(
218 'title' => sprintf( t('People Search - %s'), $search),
219 '$contacts' => $entries,
220 '$paginate' => paginate($a),
225 info( t('No matches') . EOL);