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(App $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();
24 function dirfind_content(App $a, $prefix = "") {
27 $discover_user = false;
29 $local = get_config('system','poco_local_search');
31 $search = $prefix.notags(trim($_REQUEST['search']));
33 if (strpos($search,'@') === 0) {
34 $search = substr($search,1);
35 $header = sprintf( t('People Search - %s'), $search);
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);
46 $header = sprintf( t('Forum Search - %s'), $search);
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 = get_contact_details_by_url($user_data["url"], local_user());
69 $objresult->cid = $contact["cid"];
71 $j->results[] = $objresult;
73 // Add the contact to the global contacts if it isn't already in our system
74 if (($contact["cid"] == 0) AND ($contact["zid"] == 0) AND ($contact["gid"] == 0)) {
75 update_gcontact($user_data);
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;
93 if (!get_config('system','ostatus_disabled')) {
94 $ostatus = NETWORK_OSTATUS;
96 $ostatus = NETWORK_DFRN;
99 $search2 = "%".$search."%";
101 /// @TODO These 2 SELECTs are not checked on validity with dbm::is_result()
102 $count = q("SELECT count(*) AS `total` FROM `gcontact`
103 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
104 AND `contact`.`network` = `gcontact`.`network`
105 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
106 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
107 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
108 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
109 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
110 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
111 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
112 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
113 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
114 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
116 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
118 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
119 AND `contact`.`network` = `gcontact`.`network`
120 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
121 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
122 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
123 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
124 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
125 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
126 GROUP BY `gcontact`.`nurl`
127 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
128 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
129 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
130 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
131 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
132 intval($startrec), intval($perpage));
134 $j->total = $count[0]["total"];
135 $j->items_page = $perpage;
136 $j->page = $a->pager['page'];
137 foreach ($results AS $result) {
138 if (poco_alternate_ostatus_url($result["url"])) {
142 $result = get_contact_details_by_url($result["url"], local_user(), $result);
144 if ($result["name"] == "") {
145 $urlparts = parse_url($result["url"]);
146 $result["name"] = end(explode("/", $urlparts["path"]));
149 $objresult = new stdClass();
150 $objresult->cid = $result["cid"];
151 $objresult->name = $result["name"];
152 $objresult->addr = $result["addr"];
153 $objresult->url = $result["url"];
154 $objresult->photo = $result["photo"];
155 $objresult->tags = $result["keywords"];
156 $objresult->network = $result["network"];
158 $j->results[] = $objresult;
161 // Add found profiles from the global directory to the local directory
162 proc_run(PRIORITY_LOW, 'include/discover_poco.php', "dirsearch", urlencode($search));
165 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
167 if(strlen(get_config('system','directory')))
168 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
170 $j = json_decode($x);
174 $a->set_pager_total($j->total);
175 $a->set_pager_itemspage($j->items_page);
178 if (count($j->results)) {
182 foreach ($j->results as $jj) {
186 $contact_details = get_contact_details_by_url($jj->url, local_user());
188 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
190 // If We already know this contact then don't show the "connect" button
194 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
197 $photo_menu = contact_photo_menu($contact[0]);
198 $details = _contact_detail_for_template($contact[0]);
199 $alt_text = $details['alt_text'];
201 $photo_menu = array();
204 $connlnk = App::get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
205 $conntxt = t('Connect');
207 'profile' => array(t("View Profile"), zrl($jj->url)),
208 'follow' => array(t("Connect/Follow"), $connlnk)
212 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
215 'alt_text' => $alt_text,
216 'url' => zrl($jj->url),
217 'itemurl' => $itemurl,
218 'name' => htmlentities($jj->name),
219 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
220 'img_hover' => $jj->tags,
221 'conntxt' => $conntxt,
222 'connlnk' => $connlnk,
223 'photo_menu' => $photo_menu,
224 'details' => $contact_details['location'],
225 'tags' => $contact_details['keywords'],
226 'about' => $contact_details['about'],
227 'account_type' => account_type($contact_details),
228 'network' => network_to_name($jj->network, $jj->url),
234 $tpl = get_markup_template('viewcontact_template.tpl');
236 $o .= replace_macros($tpl,array(
238 '$contacts' => $entries,
239 '$paginate' => paginate($a),
243 info( t('No matches') . EOL);