4 use Friendica\Core\System;
6 require_once 'include/contact_widgets.php';
7 require_once 'include/probe.php';
8 require_once 'include/socgraph.php';
9 require_once 'include/Contact.php';
10 require_once 'include/contact_selectors.php';
11 require_once 'mod/contacts.php';
13 function dirfind_init(App $a) {
16 notice( t('Permission denied.') . EOL );
20 if (! x($a->page,'aside')) {
21 $a->page['aside'] = '';
24 $a->page['aside'] .= findpeople_widget();
26 $a->page['aside'] .= follow_widget();
29 function dirfind_content(App $a, $prefix = "") {
32 $discover_user = false;
34 $local = get_config('system','poco_local_search');
36 $search = $prefix.notags(trim($_REQUEST['search']));
38 if (strpos($search,'@') === 0) {
39 $search = substr($search,1);
40 $header = sprintf( t('People Search - %s'), $search);
41 if ((valid_email($search) && validate_email($search)) ||
42 (substr(normalise_link($search), 0, 7) == "http://")) {
43 $user_data = probe_url($search);
44 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
48 if (strpos($search,'!') === 0) {
49 $search = substr($search,1);
51 $header = sprintf( t('Forum Search - %s'), $search);
62 $j->page = $a->pager['page'];
64 $objresult = new stdClass();
66 $objresult->name = $user_data["name"];
67 $objresult->addr = $user_data["addr"];
68 $objresult->url = $user_data["url"];
69 $objresult->photo = $user_data["photo"];
70 $objresult->tags = "";
71 $objresult->network = $user_data["network"];
73 $contact = get_contact_details_by_url($user_data["url"], local_user());
74 $objresult->cid = $contact["cid"];
76 $j->results[] = $objresult;
78 // Add the contact to the global contacts if it isn't already in our system
79 if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
80 update_gcontact($user_data);
85 $extra_sql = " AND `community`";
90 $startrec = (($a->pager['page']) * $perpage) - $perpage;
92 if (get_config('system','diaspora_enabled')) {
93 $diaspora = NETWORK_DIASPORA;
95 $diaspora = NETWORK_DFRN;
98 if (!get_config('system','ostatus_disabled')) {
99 $ostatus = NETWORK_OSTATUS;
101 $ostatus = NETWORK_DFRN;
104 $search2 = "%".$search."%";
106 /// @TODO These 2 SELECTs are not checked on validity with dbm::is_result()
107 $count = q("SELECT count(*) AS `total` FROM `gcontact`
108 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
109 AND `contact`.`network` = `gcontact`.`network`
110 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
111 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
112 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
113 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
114 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
115 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
116 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
117 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
118 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
119 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
121 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
123 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
124 AND `contact`.`network` = `gcontact`.`network`
125 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
126 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
127 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
128 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
129 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
130 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
131 GROUP BY `gcontact`.`nurl`
132 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
133 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
134 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
135 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
136 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
137 intval($startrec), intval($perpage));
139 $j->total = $count[0]["total"];
140 $j->items_page = $perpage;
141 $j->page = $a->pager['page'];
142 foreach ($results AS $result) {
143 if (poco_alternate_ostatus_url($result["url"])) {
147 $result = get_contact_details_by_url($result["url"], local_user(), $result);
149 if ($result["name"] == "") {
150 $urlparts = parse_url($result["url"]);
151 $result["name"] = end(explode("/", $urlparts["path"]));
154 $objresult = new stdClass();
155 $objresult->cid = $result["cid"];
156 $objresult->name = $result["name"];
157 $objresult->addr = $result["addr"];
158 $objresult->url = $result["url"];
159 $objresult->photo = $result["photo"];
160 $objresult->tags = $result["keywords"];
161 $objresult->network = $result["network"];
163 $j->results[] = $objresult;
166 // Add found profiles from the global directory to the local directory
167 proc_run(PRIORITY_LOW, 'include/discover_poco.php', "dirsearch", urlencode($search));
170 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
172 if(strlen(get_config('system','directory')))
173 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
175 $j = json_decode($x);
179 $a->set_pager_total($j->total);
180 $a->set_pager_itemspage($j->items_page);
183 if (count($j->results)) {
187 foreach ($j->results as $jj) {
191 $contact_details = get_contact_details_by_url($jj->url, local_user());
193 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
195 // If We already know this contact then don't show the "connect" button
199 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
202 $photo_menu = contact_photo_menu($contact[0]);
203 $details = _contact_detail_for_template($contact[0]);
204 $alt_text = $details['alt_text'];
206 $photo_menu = array();
209 $connlnk = System::baseUrl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
210 $conntxt = t('Connect');
212 'profile' => array(t("View Profile"), zrl($jj->url)),
213 'follow' => array(t("Connect/Follow"), $connlnk)
217 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
220 'alt_text' => $alt_text,
221 'url' => zrl($jj->url),
222 'itemurl' => $itemurl,
223 'name' => htmlentities($jj->name),
224 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
225 'img_hover' => $jj->tags,
226 'conntxt' => $conntxt,
227 'connlnk' => $connlnk,
228 'photo_menu' => $photo_menu,
229 'details' => $contact_details['location'],
230 'tags' => $contact_details['keywords'],
231 'about' => $contact_details['about'],
232 'account_type' => account_type($contact_details),
233 'network' => network_to_name($jj->network, $jj->url),
239 $tpl = get_markup_template('viewcontact_template.tpl');
241 $o .= replace_macros($tpl,array(
243 '$contacts' => $entries,
244 '$paginate' => paginate($a),
248 info( t('No matches') . EOL);