4 use Friendica\Core\System;
6 require_once('include/contact_widgets.php');
7 require_once('include/redir.php');
9 function profile_init(App $a) {
11 if(! x($a->page,'aside'))
12 $a->page['aside'] = '';
15 $which = htmlspecialchars($a->argv[1]);
17 $r = q("select nickname from user where blocked = 0 and account_expired = 0 and account_removed = 0 and verified = 1 order by rand() limit 1");
18 if (dbm::is_result($r)) {
19 goaway(System::baseUrl() . '/profile/' . $r[0]['nickname']);
22 logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG);
23 notice( t('Requested profile is not available.') . EOL );
30 if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
31 $which = $a->user['nickname'];
32 $profile = htmlspecialchars($a->argv[1]);
35 auto_redir($a, $which);
38 profile_load($a,$which,$profile);
40 $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
41 $userblock = (($a->profile['hidewall'] && (! local_user()) && (! remote_user())) ? true : false);
43 if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
44 $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
46 if (x($a->profile,'openidserver')) {
47 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
49 if (x($a->profile,'openid')) {
50 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'https://' . $a->profile['openid']);
51 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
54 if ((! $blocked) && (! $userblock)) {
55 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
56 $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
58 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
61 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
62 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
63 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
64 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
65 header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
67 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
68 foreach ($dfrn_pages as $dfrn) {
69 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".System::baseUrl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
71 $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".System::baseUrl()."/poco/{$which}\" />\r\n";
76 function profile_content(App $a, $update = 0) {
78 $category = $datequery = $datequery2 = '';
81 for ($x = 2; $x < $a->argc; $x ++) {
82 if (is_a_date_arg($a->argv[$x])) {
84 $datequery2 = escape_tags($a->argv[$x]);
86 $datequery = escape_tags($a->argv[$x]);
89 $category = $a->argv[$x];
95 $category = ((x($_GET,'category')) ? $_GET['category'] : '');
98 if (get_config('system','block_public') && (! local_user()) && (! remote_user())) {
102 require_once("include/bbcode.php");
103 require_once('include/security.php');
104 require_once('include/conversation.php');
105 require_once('include/acl_selectors.php');
106 require_once('include/items.php');
114 // Ensure we've got a profile owner if updating.
115 $a->profile['profile_uid'] = $update;
116 } elseif ($a->profile['profile_uid'] == local_user()) {
117 nav_set_selected('home');
121 $remote_contact = false;
125 if (is_array($_SESSION['remote'])) {
126 foreach ($_SESSION['remote'] as $v) {
127 if ($v['uid'] == $a->profile['profile_uid']) {
128 $contact_id = $v['cid'];
135 $groups = init_groups_visitor($contact_id);
136 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
138 intval($a->profile['profile_uid'])
140 if (dbm::is_result($r)) {
142 $remote_contact = true;
146 if (! $remote_contact) {
148 $contact_id = $_SESSION['cid'];
149 $contact = $a->contact;
153 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
154 $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user();
156 if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
157 notice( t('Access to this profile has been restricted.') . EOL);
162 if (x($_GET,'tab')) {
163 $tab = notags(trim($_GET['tab']));
166 $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
168 if ($tab === 'profile') {
169 $o .= advanced_profile($a);
170 call_hooks('profile_advanced',$o);
174 $o .= common_friends_visitor_widget($a->profile['profile_uid']);
176 if (x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner) {
177 $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
180 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
181 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
183 $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'],$a->profile['profile_uid'],true);
184 $a->page['aside'] .= categories_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
186 if (can_write_wall($a,$a->profile['profile_uid'])) {
189 'is_owner' => $is_owner,
190 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
191 'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
192 'nickname' => $a->profile['nickname'],
193 'lockstate' => (((is_array($a->user) && ((strlen($a->user['allow_cid'])) ||
194 (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) ||
195 (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
196 'acl' => (($is_owner) ? populate_acl($a->user, true) : ''),
198 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
199 'profile_uid' => $a->profile['profile_uid'],
200 'acl_data' => ( $is_owner ? construct_acl_data($a, $a->user) : '' ), // For non-Javascript ACL selector
203 $o .= status_editor($a,$x);
209 * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
211 $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
215 $last_updated = (x($_SESSION['last_updated'], $last_updated_key) ? $_SESSION['last_updated'][$last_updated_key] : 0);
217 // If the page user is the owner of the page we should query for unseen
218 // items. Otherwise use a timestamp of the last succesful update request.
219 if ($is_owner || !$last_updated) {
220 $sql_extra4 = " AND `item`.`unseen`";
222 $gmupdate = gmdate("Y-m-d H:i:s", $last_updated);
223 $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
226 $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, `item`.`created`
227 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
228 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
229 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
230 (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."'
231 OR item.verb = '" . ACTIVITY_DISLIKE . "' OR item.verb = '" . ACTIVITY_ATTEND . "'
232 OR item.verb = '" . ACTIVITY_ATTENDNO . "' OR item.verb = '" . ACTIVITY_ATTENDMAYBE . "')
233 AND `item`.`moderated` = 0
234 AND `item`.`wall` = 1
237 ORDER BY `item`.`created` DESC",
238 intval($a->profile['profile_uid'])
241 if (!dbm::is_result($r)) {
246 $sql_post_table = "";
249 $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
250 dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
251 //$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
255 $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
258 $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
261 // Belongs the profile page to a forum?
262 // If not then we can improve the performance with an additional condition
263 $r = q("SELECT `uid` FROM `user` WHERE `uid` = %d AND `page-flags` IN (%d, %d)",
264 intval($a->profile['profile_uid']),
265 intval(PAGE_COMMUNITY),
266 intval(PAGE_PRVGROUP));
268 if (!dbm::is_result($r)) {
269 $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
272 // check if we serve a mobile device and get the user settings
275 $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network');
276 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 10);
278 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
279 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
281 // now that we have the user settings, see if the theme forces
282 // a maximum item number which is lower then the user choice
283 if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
284 $itemspage_network = $a->force_max_items;
286 $a->set_pager_itemspage($itemspage_network);
288 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
290 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`
292 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
294 STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
295 AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
296 WHERE `thread`.`uid` = %d AND `thread`.`visible`
297 AND NOT `thread`.`deleted`
298 AND NOT `thread`.`moderated`
300 $sql_extra3 $sql_extra $sql_extra2
301 ORDER BY `thread`.`created` DESC $pager_sql",
302 intval($a->profile['profile_uid'])
307 $parents_arr = array();
310 // Set a time stamp for this page. We will make use of it when we
311 // search for new items (update routine)
312 $_SESSION['last_updated'][$last_updated_key] = time();
314 if (dbm::is_result($r)) {
316 $parents_arr[] = $rr['item_id'];
317 $parents_str = implode(', ', $parents_arr);
319 $items = q(item_query()." AND `item`.`uid` = %d
320 AND `item`.`parent` IN (%s)
322 intval($a->profile['profile_uid']),
326 $items = conv_sort($items,'created');
331 if($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) {
332 $o .= get_birthdays();
338 $unseen = dba::exists('item', array('wall' => true, 'unseen' => true, 'uid' => local_user()));
340 $r = dba::update('item', array('unseen' => false),
341 array('wall' => true, 'unseen' => true, 'uid' => local_user()));
345 $o .= conversation($a, $items, 'profile', $update);
348 $o .= alt_pager($a, count($items));