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'] = '';
19 $a->page['aside'] .= findpeople_widget();
21 $a->page['aside'] .= follow_widget();
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 $header = sprintf( t('People Search - %s'), $search);
38 if ((valid_email($search) AND validate_email($search)) OR
39 (substr(normalise_link($search), 0, 7) == "http://")) {
40 $user_data = probe_url($search);
41 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
45 if (strpos($search,'!') === 0) {
46 $search = substr($search,1);
48 $header = sprintf( t('Forum Search - %s'), $search);
59 $j->page = $a->pager['page'];
61 $objresult = new stdClass();
63 $objresult->name = $user_data["name"];
64 $objresult->addr = $user_data["addr"];
65 $objresult->url = $user_data["url"];
66 $objresult->photo = $user_data["photo"];
67 $objresult->tags = "";
68 $objresult->network = $user_data["network"];
70 $contact = get_contact_details_by_url($user_data["url"], local_user());
71 $objresult->cid = $contact["cid"];
73 $j->results[] = $objresult;
75 // Add the contact to the global contacts if it isn't already in our system
76 if (($contact["cid"] == 0) AND ($contact["zid"] == 0) AND ($contact["gid"] == 0))
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;
93 $diaspora = NETWORK_DFRN;
96 if (!get_config('system','ostatus_disabled')) {
97 $ostatus = NETWORK_OSTATUS;
100 $ostatus = NETWORK_DFRN;
103 $search2 = "%".$search."%";
105 $count = q("SELECT count(*) AS `total` FROM `gcontact`
106 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
107 AND `contact`.`network` = `gcontact`.`network`
108 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
109 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
110 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
111 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
112 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
113 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
114 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
115 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
116 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
117 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
119 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
121 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
122 AND `contact`.`network` = `gcontact`.`network`
123 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
124 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
125 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
126 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
127 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
128 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
129 GROUP BY `gcontact`.`nurl`
130 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
131 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
132 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
133 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
134 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
135 intval($startrec), intval($perpage));
137 $j->total = $count[0]["total"];
138 $j->items_page = $perpage;
139 $j->page = $a->pager['page'];
140 foreach ($results AS $result) {
141 if (poco_alternate_ostatus_url($result["url"])) {
145 $result = get_contact_details_by_url($result["url"], local_user(), $result);
147 if ($result["name"] == "") {
148 $urlparts = parse_url($result["url"]);
149 $result["name"] = end(explode("/", $urlparts["path"]));
152 $objresult = new stdClass();
153 $objresult->cid = $result["cid"];
154 $objresult->name = $result["name"];
155 $objresult->addr = $result["addr"];
156 $objresult->url = $result["url"];
157 $objresult->photo = $result["photo"];
158 $objresult->tags = $result["keywords"];
159 $objresult->network = $result["network"];
161 $j->results[] = $objresult;
164 // Add found profiles from the global directory to the local directory
165 proc_run(PRIORITY_LOW, 'include/discover_poco.php', "dirsearch", urlencode($search));
168 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
170 if(strlen(get_config('system','directory')))
171 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
173 $j = json_decode($x);
177 $a->set_pager_total($j->total);
178 $a->set_pager_itemspage($j->items_page);
181 if (count($j->results)) {
185 foreach ($j->results as $jj) {
189 $contact_details = get_contact_details_by_url($jj->url, local_user());
191 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
193 // If We already know this contact then don't show the "connect" button
197 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
200 $photo_menu = contact_photo_menu($contact[0]);
201 $details = _contact_detail_for_template($contact[0]);
202 $alt_text = $details['alt_text'];
205 $photo_menu = array();
208 $connlnk = App::get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
209 $conntxt = t('Connect');
211 'profile' => array(t("View Profile"), zrl($jj->url)),
212 'follow' => array(t("Connect/Follow"), $connlnk)
216 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
219 'alt_text' => $alt_text,
220 'url' => zrl($jj->url),
221 'itemurl' => $itemurl,
222 'name' => htmlentities($jj->name),
223 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
224 'img_hover' => $jj->tags,
225 'conntxt' => $conntxt,
226 'connlnk' => $connlnk,
227 'photo_menu' => $photo_menu,
228 'details' => $contact_details['location'],
229 'tags' => $contact_details['keywords'],
230 'about' => $contact_details['about'],
231 'account_type' => account_type($contact_details),
232 'network' => network_to_name($jj->network, $jj->url),
238 $tpl = get_markup_template('viewcontact_template.tpl');
240 $o .= replace_macros($tpl,array(
242 '$contacts' => $entries,
243 '$paginate' => paginate($a),
248 info( t('No matches') . EOL);