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();
26 function dirfind_content(App $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;
92 $diaspora = NETWORK_DFRN;
95 if (!get_config('system','ostatus_disabled')) {
96 $ostatus = NETWORK_OSTATUS;
98 $ostatus = NETWORK_DFRN;
101 $search2 = "%".$search."%";
103 /// @TODO These 2 SELECTs are not checked on validity with dbm::is_result()
104 $count = q("SELECT count(*) AS `total` FROM `gcontact`
105 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
106 AND `contact`.`network` = `gcontact`.`network`
107 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
108 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
109 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
110 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
111 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
112 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
113 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
114 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
115 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
116 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
118 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
120 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
121 AND `contact`.`network` = `gcontact`.`network`
122 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
123 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
124 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
125 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
126 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
127 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
128 GROUP BY `gcontact`.`nurl`
129 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
130 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
131 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
132 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
133 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
134 intval($startrec), intval($perpage));
136 $j->total = $count[0]["total"];
137 $j->items_page = $perpage;
138 $j->page = $a->pager['page'];
139 foreach ($results AS $result) {
140 if (poco_alternate_ostatus_url($result["url"])) {
144 $result = get_contact_details_by_url($result["url"], local_user(), $result);
146 if ($result["name"] == "") {
147 $urlparts = parse_url($result["url"]);
148 $result["name"] = end(explode("/", $urlparts["path"]));
151 $objresult = new stdClass();
152 $objresult->cid = $result["cid"];
153 $objresult->name = $result["name"];
154 $objresult->addr = $result["addr"];
155 $objresult->url = $result["url"];
156 $objresult->photo = $result["photo"];
157 $objresult->tags = $result["keywords"];
158 $objresult->network = $result["network"];
160 $j->results[] = $objresult;
163 // Add found profiles from the global directory to the local directory
164 proc_run(PRIORITY_LOW, 'include/discover_poco.php', "dirsearch", urlencode($search));
167 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
169 if(strlen(get_config('system','directory')))
170 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
172 $j = json_decode($x);
176 $a->set_pager_total($j->total);
177 $a->set_pager_itemspage($j->items_page);
180 if (count($j->results)) {
184 foreach ($j->results as $jj) {
188 $contact_details = get_contact_details_by_url($jj->url, local_user());
190 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
192 // If We already know this contact then don't show the "connect" button
196 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
199 $photo_menu = contact_photo_menu($contact[0]);
200 $details = _contact_detail_for_template($contact[0]);
201 $alt_text = $details['alt_text'];
203 $photo_menu = array();
206 $connlnk = App::get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
207 $conntxt = t('Connect');
209 'profile' => array(t("View Profile"), zrl($jj->url)),
210 'follow' => array(t("Connect/Follow"), $connlnk)
214 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
217 'alt_text' => $alt_text,
218 'url' => zrl($jj->url),
219 'itemurl' => $itemurl,
220 'name' => htmlentities($jj->name),
221 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
222 'img_hover' => $jj->tags,
223 'conntxt' => $conntxt,
224 'connlnk' => $connlnk,
225 'photo_menu' => $photo_menu,
226 'details' => $contact_details['location'],
227 'tags' => $contact_details['keywords'],
228 'about' => $contact_details['about'],
229 'account_type' => account_type($contact_details),
230 'network' => network_to_name($jj->network, $jj->url),
236 $tpl = get_markup_template('viewcontact_template.tpl');
238 $o .= replace_macros($tpl,array(
240 '$contacts' => $entries,
241 '$paginate' => paginate($a),
245 info( t('No matches') . EOL);