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 = get_contact_details_by_url($user_data["url"], local_user());
70 $objresult->cid = $contact["cid"];
72 $j->results[] = $objresult;
74 // Add the contact to the global contacts if it isn't already in our system
75 if (($contact["cid"] == 0) AND ($contact["zid"] == 0) AND ($contact["gid"] == 0))
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 $search2 = "%".$search."%";
100 $count = q("SELECT count(*) AS `total` FROM `gcontact`
101 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
102 AND `contact`.`network` = `gcontact`.`network`
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`.`network` = `gcontact`.`network`
118 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
119 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
120 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
121 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
122 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
123 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
124 GROUP BY `gcontact`.`nurl`
125 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
126 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
127 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
128 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
129 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
130 intval($startrec), intval($perpage));
132 $j->total = $count[0]["total"];
133 $j->items_page = $perpage;
134 $j->page = $a->pager['page'];
135 foreach ($results AS $result) {
136 if (poco_alternate_ostatus_url($result["url"]))
139 $result = get_contact_details_by_url($result["url"], local_user(), $result);
141 if ($result["name"] == "") {
142 $urlparts = parse_url($result["url"]);
143 $result["name"] = end(explode("/", $urlparts["path"]));
146 $objresult = new stdClass();
147 $objresult->cid = $result["cid"];
148 $objresult->name = $result["name"];
149 $objresult->addr = $result["addr"];
150 $objresult->url = $result["url"];
151 $objresult->photo = $result["photo"];
152 $objresult->tags = $result["keywords"];
153 $objresult->network = $result["network"];
155 $j->results[] = $objresult;
158 // Add found profiles from the global directory to the local directory
159 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
162 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
164 if(strlen(get_config('system','directory')))
165 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
167 $j = json_decode($x);
171 $a->set_pager_total($j->total);
172 $a->set_pager_itemspage($j->items_page);
175 if(count($j->results)) {
179 foreach($j->results as $jj) {
183 $contact_details = get_contact_details_by_url($jj->url, local_user());
185 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
187 // If We already know this contact then don't show the "connect" button
191 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
194 $photo_menu = contact_photo_menu($contact[0]);
195 $details = _contact_detail_for_template($contact[0]);
196 $alt_text = $details['alt_text'];
198 $photo_menu = array();
200 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
201 $conntxt = t('Connect');
203 'profile' => array(t("View Profile"), zrl($jj->url)),
204 'follow' => array(t("Connect/Follow"), $connlnk)
208 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
211 'alt_text' => $alt_text,
212 'url' => zrl($jj->url),
213 'itemurl' => $itemurl,
214 'name' => htmlentities($jj->name),
215 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
216 'img_hover' => $jj->tags,
217 'conntxt' => $conntxt,
218 'connlnk' => $connlnk,
219 'photo_menu' => $photo_menu,
220 'details' => $contact_details['location'],
221 'tags' => $contact_details['keywords'],
222 'about' => $contact_details['about'],
223 'account_type' => (($contact_details['community']) ? t('Forum') : ''),
224 'network' => network_to_name($jj->network, $jj->url),
230 $tpl = get_markup_template('viewcontact_template.tpl');
232 $o .= replace_macros($tpl,array(
234 '$contacts' => $entries,
235 '$paginate' => paginate($a),
240 info( t('No matches') . EOL);