4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6 use Friendica\Core\Worker;
7 use Friendica\Network\Probe;
9 require_once 'include/contact_widgets.php';
10 require_once 'include/probe.php';
11 require_once 'include/socgraph.php';
12 require_once 'include/Contact.php';
13 require_once 'include/contact_selectors.php';
14 require_once 'mod/contacts.php';
16 function dirfind_init(App $a) {
19 notice( t('Permission denied.') . EOL );
23 if (! x($a->page,'aside')) {
24 $a->page['aside'] = '';
27 $a->page['aside'] .= findpeople_widget();
29 $a->page['aside'] .= follow_widget();
32 function dirfind_content(App $a, $prefix = "") {
35 $discover_user = false;
37 $local = Config::get('system','poco_local_search');
39 $search = $prefix.notags(trim($_REQUEST['search']));
41 if (strpos($search,'@') === 0) {
42 $search = substr($search,1);
43 $header = sprintf( t('People Search - %s'), $search);
44 if ((valid_email($search) && validate_email($search)) ||
45 (substr(normalise_link($search), 0, 7) == "http://")) {
46 $user_data = Probe::uri($search);
47 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
51 if (strpos($search,'!') === 0) {
52 $search = substr($search,1);
54 $header = sprintf( t('Forum Search - %s'), $search);
65 $j->page = $a->pager['page'];
67 $objresult = new stdClass();
69 $objresult->name = $user_data["name"];
70 $objresult->addr = $user_data["addr"];
71 $objresult->url = $user_data["url"];
72 $objresult->photo = $user_data["photo"];
73 $objresult->tags = "";
74 $objresult->network = $user_data["network"];
76 $contact = get_contact_details_by_url($user_data["url"], local_user());
77 $objresult->cid = $contact["cid"];
79 $j->results[] = $objresult;
81 // Add the contact to the global contacts if it isn't already in our system
82 if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
83 update_gcontact($user_data);
88 $extra_sql = " AND `community`";
93 $startrec = (($a->pager['page']) * $perpage) - $perpage;
95 if (Config::get('system','diaspora_enabled')) {
96 $diaspora = NETWORK_DIASPORA;
98 $diaspora = NETWORK_DFRN;
101 if (!Config::get('system','ostatus_disabled')) {
102 $ostatus = NETWORK_OSTATUS;
104 $ostatus = NETWORK_DFRN;
107 $search2 = "%".$search."%";
109 /// @TODO These 2 SELECTs are not checked on validity with dbm::is_result()
110 $count = q("SELECT count(*) AS `total` FROM `gcontact`
111 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
112 AND `contact`.`network` = `gcontact`.`network`
113 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
114 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
115 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
116 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
117 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
118 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
119 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
120 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
121 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
122 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
124 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
126 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
127 AND `contact`.`network` = `gcontact`.`network`
128 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
129 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
130 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
131 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
132 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
133 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
134 GROUP BY `gcontact`.`nurl`
135 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
136 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
137 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
138 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
139 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
140 intval($startrec), intval($perpage));
142 $j->total = $count[0]["total"];
143 $j->items_page = $perpage;
144 $j->page = $a->pager['page'];
145 foreach ($results AS $result) {
146 if (poco_alternate_ostatus_url($result["url"])) {
150 $result = get_contact_details_by_url($result["url"], local_user(), $result);
152 if ($result["name"] == "") {
153 $urlparts = parse_url($result["url"]);
154 $result["name"] = end(explode("/", $urlparts["path"]));
157 $objresult = new stdClass();
158 $objresult->cid = $result["cid"];
159 $objresult->name = $result["name"];
160 $objresult->addr = $result["addr"];
161 $objresult->url = $result["url"];
162 $objresult->photo = $result["photo"];
163 $objresult->tags = $result["keywords"];
164 $objresult->network = $result["network"];
166 $j->results[] = $objresult;
169 // Add found profiles from the global directory to the local directory
170 Worker::add(PRIORITY_LOW, 'discover_poco', "dirsearch", urlencode($search));
173 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
175 if(strlen(Config::get('system','directory')))
176 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
178 $j = json_decode($x);
182 $a->set_pager_total($j->total);
183 $a->set_pager_itemspage($j->items_page);
186 if (count($j->results)) {
190 foreach ($j->results as $jj) {
194 $contact_details = get_contact_details_by_url($jj->url, local_user());
196 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
198 // If We already know this contact then don't show the "connect" button
202 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
205 $photo_menu = contact_photo_menu($contact[0]);
206 $details = _contact_detail_for_template($contact[0]);
207 $alt_text = $details['alt_text'];
209 $photo_menu = array();
212 $connlnk = System::baseUrl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
213 $conntxt = t('Connect');
215 'profile' => array(t("View Profile"), zrl($jj->url)),
216 'follow' => array(t("Connect/Follow"), $connlnk)
220 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
223 'alt_text' => $alt_text,
224 'url' => zrl($jj->url),
225 'itemurl' => $itemurl,
226 'name' => htmlentities($jj->name),
227 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
228 'img_hover' => $jj->tags,
229 'conntxt' => $conntxt,
230 'connlnk' => $connlnk,
231 'photo_menu' => $photo_menu,
232 'details' => $contact_details['location'],
233 'tags' => $contact_details['keywords'],
234 'about' => $contact_details['about'],
235 'account_type' => account_type($contact_details),
236 'network' => network_to_name($jj->network, $jj->url),
242 $tpl = get_markup_template('viewcontact_template.tpl');
244 $o .= replace_macros($tpl,array(
246 '$contacts' => $entries,
247 '$paginate' => paginate($a),
251 info( t('No matches') . EOL);