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/socgraph.php';
11 require_once 'include/Contact.php';
12 require_once 'include/contact_selectors.php';
13 require_once 'mod/contacts.php';
15 function dirfind_init(App $a) {
18 notice( t('Permission denied.') . EOL );
22 if (! x($a->page,'aside')) {
23 $a->page['aside'] = '';
26 $a->page['aside'] .= findpeople_widget();
28 $a->page['aside'] .= follow_widget();
31 function dirfind_content(App $a, $prefix = "") {
34 $discover_user = false;
36 $local = Config::get('system','poco_local_search');
38 $search = $prefix.notags(trim($_REQUEST['search']));
40 if (strpos($search,'@') === 0) {
41 $search = substr($search,1);
42 $header = sprintf( t('People Search - %s'), $search);
43 if ((valid_email($search) && validate_email($search)) ||
44 (substr(normalise_link($search), 0, 7) == "http://")) {
45 $user_data = Probe::uri($search);
46 $discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
50 if (strpos($search,'!') === 0) {
51 $search = substr($search,1);
53 $header = sprintf( t('Forum Search - %s'), $search);
64 $j->page = $a->pager['page'];
66 $objresult = new stdClass();
68 $objresult->name = $user_data["name"];
69 $objresult->addr = $user_data["addr"];
70 $objresult->url = $user_data["url"];
71 $objresult->photo = $user_data["photo"];
72 $objresult->tags = "";
73 $objresult->network = $user_data["network"];
75 $contact = get_contact_details_by_url($user_data["url"], local_user());
76 $objresult->cid = $contact["cid"];
78 $j->results[] = $objresult;
80 // Add the contact to the global contacts if it isn't already in our system
81 if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
82 update_gcontact($user_data);
87 $extra_sql = " AND `community`";
92 $startrec = (($a->pager['page']) * $perpage) - $perpage;
94 if (Config::get('system','diaspora_enabled')) {
95 $diaspora = NETWORK_DIASPORA;
97 $diaspora = NETWORK_DFRN;
100 if (!Config::get('system','ostatus_disabled')) {
101 $ostatus = NETWORK_OSTATUS;
103 $ostatus = NETWORK_DFRN;
106 $search2 = "%".$search."%";
108 /// @TODO These 2 SELECTs are not checked on validity with DBM::is_result()
109 $count = q("SELECT count(*) AS `total` FROM `gcontact`
110 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
111 AND `contact`.`network` = `gcontact`.`network`
112 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
113 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
114 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
115 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
116 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
117 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
118 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
119 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
120 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
121 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
123 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
125 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
126 AND `contact`.`network` = `gcontact`.`network`
127 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
128 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
129 WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
130 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
131 (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
132 `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
133 GROUP BY `gcontact`.`nurl`
134 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
135 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
136 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
137 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
138 dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
139 intval($startrec), intval($perpage));
141 $j->total = $count[0]["total"];
142 $j->items_page = $perpage;
143 $j->page = $a->pager['page'];
144 foreach ($results AS $result) {
145 if (poco_alternate_ostatus_url($result["url"])) {
149 $result = get_contact_details_by_url($result["url"], local_user(), $result);
151 if ($result["name"] == "") {
152 $urlparts = parse_url($result["url"]);
153 $result["name"] = end(explode("/", $urlparts["path"]));
156 $objresult = new stdClass();
157 $objresult->cid = $result["cid"];
158 $objresult->name = $result["name"];
159 $objresult->addr = $result["addr"];
160 $objresult->url = $result["url"];
161 $objresult->photo = $result["photo"];
162 $objresult->tags = $result["keywords"];
163 $objresult->network = $result["network"];
165 $j->results[] = $objresult;
168 // Add found profiles from the global directory to the local directory
169 Worker::add(PRIORITY_LOW, 'discover_poco', "dirsearch", urlencode($search));
172 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
174 if(strlen(Config::get('system','directory')))
175 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
177 $j = json_decode($x);
181 $a->set_pager_total($j->total);
182 $a->set_pager_itemspage($j->items_page);
185 if (count($j->results)) {
189 foreach ($j->results as $jj) {
193 $contact_details = get_contact_details_by_url($jj->url, local_user());
195 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
197 // If We already know this contact then don't show the "connect" button
201 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
204 $photo_menu = contact_photo_menu($contact[0]);
205 $details = _contact_detail_for_template($contact[0]);
206 $alt_text = $details['alt_text'];
208 $photo_menu = array();
211 $connlnk = System::baseUrl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
212 $conntxt = t('Connect');
214 'profile' => array(t("View Profile"), zrl($jj->url)),
215 'follow' => array(t("Connect/Follow"), $connlnk)
219 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
222 'alt_text' => $alt_text,
223 'url' => zrl($jj->url),
224 'itemurl' => $itemurl,
225 'name' => htmlentities($jj->name),
226 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
227 'img_hover' => $jj->tags,
228 'conntxt' => $conntxt,
229 'connlnk' => $connlnk,
230 'photo_menu' => $photo_menu,
231 'details' => $contact_details['location'],
232 'tags' => $contact_details['keywords'],
233 'about' => $contact_details['about'],
234 'account_type' => account_type($contact_details),
235 'network' => network_to_name($jj->network, $jj->url),
241 $tpl = get_markup_template('viewcontact_template.tpl');
243 $o .= replace_macros($tpl,array(
245 '$contacts' => $entries,
246 '$paginate' => paginate($a),
250 info( t('No matches') . EOL);