3 * @file include/identity.php
6 require_once('include/forums.php');
11 * Function : profile_load
13 * @parameter string $nickname
14 * @parameter int $profile
16 * Summary: Loads a profile into the page sidebar.
17 * The function requires a writeable copy of the main App structure, and the nickname
18 * of a registered local account.
20 * If the viewer is an authenticated remote viewer, the profile displayed is the
21 * one that has been configured for his/her viewing in the Contact manager.
22 * Passing a non-zero profile ID can also allow a preview of a selected profile
25 * Profile information is placed in the App structure for later retrieval.
26 * Honours the owner's chosen theme for display.
28 * IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
29 * the theme is chosen before the _init() function of a theme is run, which will usually
30 * load a lot of theme-specific content
34 if(! function_exists('profile_load')) {
35 function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
37 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
41 if(!$user && count($user) && !count($profiledata)) {
42 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
43 notice( t('Requested account is not available.') . EOL );
48 if(remote_user() && count($_SESSION['remote'])) {
49 foreach($_SESSION['remote'] as $visitor) {
50 if($visitor['uid'] == $user[0]['uid']) {
51 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
52 intval($visitor['cid'])
55 $profile = $r[0]['profile-id'];
64 $profile_int = intval($profile);
65 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
66 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
67 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d AND `contact`.`self` = 1 LIMIT 1",
72 if((!$r) && (!count($r))) {
73 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
74 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
75 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 AND `contact`.`self` = 1 LIMIT 1",
80 if(($r === false) || (!count($r)) && !count($profiledata)) {
81 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
82 notice( t('Requested profile is not available.') . EOL );
87 // fetch user tags if this isn't the default profile
89 if(!$r[0]['is-default']) {
90 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
91 intval($r[0]['profile_uid'])
94 $r[0]['pub_keywords'] = $x[0]['pub_keywords'];
98 $a->profile_uid = $r[0]['profile_uid'];
100 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
101 $a->profile['network'] = NETWORK_DFRN;
103 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
105 // if (!$profiledata)
106 // $_SESSION['theme'] = $a->profile['theme'];
108 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
111 * load/reload current theme info
114 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
116 $theme_info_file = "view/theme/".current_theme()."/theme.php";
117 if (file_exists($theme_info_file)){
118 require_once($theme_info_file);
121 if(! (x($a->page,'aside')))
122 $a->page['aside'] = '';
124 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
125 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
126 '$editprofile' => t('Edit profile'),
127 '$profid' => $a->profile['id']
131 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
134 // By now, the contact block isn't shown, when a different profile is given
135 // But: When this profile was on the same server, then we could display the contacts
137 $a->page['aside'] .= profile_sidebar($profiledata, true);
139 $a->page['aside'] .= profile_sidebar($a->profile, $block);
143 $a->page['aside'] .= contact_block();*/
152 * Function: profile_sidebar
154 * Formats a profile for display in the sidebar.
155 * It is very difficult to templatise the HTML completely
156 * because of all the conditional logic.
158 * @parameter: array $profile
160 * Returns HTML string stuitable for sidebar inclusion
161 * Exceptions: Returns empty string if passed $profile is wrong type or not populated
166 if(! function_exists('profile_sidebar')) {
167 function profile_sidebar($profile, $block = 0) {
175 if((! is_array($profile)) && (! count($profile)))
178 $profile['picdate'] = urlencode($profile['picdate']);
180 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
181 require_once('include/contact_selectors.php');
182 if ($profile['url'] != "")
183 $profile['network_name'] = '<a href="'.$profile['url'].'">'.network_to_name($profile['network'], $profile['url'])."</a>";
185 $profile['network_name'] = network_to_name($profile['network']);
187 $profile['network_name'] = "";
189 call_hooks('profile_sidebar_enter', $profile);
192 // don't show connect link to yourself
193 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
195 // don't show connect link to authenticated visitors either
196 if(remote_user() && count($_SESSION['remote'])) {
197 foreach($_SESSION['remote'] as $visitor) {
198 if($visitor['uid'] == $profile['uid']) {
205 // Is the local user already connected to that user?
206 if ($connect AND local_user()) {
207 if (isset($profile["url"]))
208 $profile_url = normalise_link($profile["url"]);
210 $profile_url = normalise_link($a->get_baseurl()."/profile/".$profile["nickname"]);
212 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
213 local_user(), $profile_url);
218 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
221 if (isset($profile['remoteconnect']))
222 $remoteconnect = $profile['remoteconnect'];
224 if( get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()) )
225 $wallmessage = t('Message');
227 $wallmessage = false;
229 // show edit profile to yourself
230 if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
231 $profile['edit'] = array($a->get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
232 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
235 $profile['menu'] = array(
236 'chg_photo' => t('Change profile photo'),
237 'cr_new' => t('Create New Profile'),
238 'entries' => array(),
244 $profile['menu']['entries'][] = array(
245 'photo' => $rr['thumb'],
247 'alt' => t('Profile Image'),
248 'profile_name' => $rr['profile-name'],
249 'isdefault' => $rr['is-default'],
250 'visibile_to_everybody' => t('visible to everybody'),
251 'edit_visibility' => t('Edit visibility'),
259 if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
260 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
261 $profile['menu'] = array(
262 'chg_photo' => t('Change profile photo'),
264 'entries' => array(),
268 if((x($profile,'address') == 1)
269 || (x($profile,'locality') == 1)
270 || (x($profile,'region') == 1)
271 || (x($profile,'postal-code') == 1)
272 || (x($profile,'country-name') == 1))
273 $location = t('Location:');
275 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
278 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
280 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
282 $about = ((x($profile,'about') == 1) ? t('About:') : False);
284 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
285 $location = $pdesc = $gender = $marital = $homepage = $about = False;
288 $firstname = ((strpos($profile['name'],' '))
289 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
290 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
293 'guid' => $profile['guid'],
294 'podloc' => $a->get_baseurl(),
295 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
296 'nickname' => $profile['nickname'],
297 'fullname' => $profile['name'],
298 'firstname' => $firstname,
299 'lastname' => $lastname,
300 'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
301 'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
302 'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'),
306 $contact_block = contact_block();
308 if(is_array($a->profile) AND !$a->profile['hide-friends']) {
309 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
310 intval($a->profile['uid']));
312 $updated = date("c", strtotime($r[0]['updated']));
314 $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
315 AND `network` IN ('%s', '%s', '%s', '')",
316 intval($profile['uid']),
318 dbesc(NETWORK_DIASPORA),
319 dbesc(NETWORK_OSTATUS)
322 $contacts = intval($r[0]['total']);
327 foreach($profile as $k => $v) {
328 $k = str_replace('-','_',$k);
332 if($a->theme['template_engine'] === 'internal')
333 $location = template_escape($location);
335 $tpl = get_markup_template('profile_vcard.tpl');
336 $o .= replace_macros($tpl, array(
338 '$connect' => $connect,
339 '$remoteconnect' => $remoteconnect,
340 '$wallmessage' => $wallmessage,
341 '$location' => $location,
342 '$gender' => $gender,
344 '$marital' => $marital,
345 '$homepage' => $homepage,
347 '$network' => t('Network:'),
348 '$contacts' => $contacts,
349 '$updated' => $updated,
350 '$diaspora' => $diaspora,
351 '$contact_block' => $contact_block,
355 $arr = array('profile' => &$profile, 'entry' => &$o);
357 call_hooks('profile_sidebar', $arr);
364 if(! function_exists('get_birthdays')) {
365 function get_birthdays() {
370 if(! local_user() || $a->is_mobile || $a->is_tablet)
373 // $mobile_detect = new Mobile_Detect();
374 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
379 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
380 $bd_short = t('F d');
382 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
383 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
384 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
385 ORDER BY `start` ASC ",
386 intval(local_user()),
387 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
388 dbesc(datetime_convert('UTC','UTC','now'))
391 if($r && count($r)) {
393 $now = strtotime('now');
398 if(strlen($rr['name']))
400 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
403 $classtoday = $istoday ? ' birthday-today ' : '';
405 foreach($r as &$rr) {
406 if(! strlen($rr['name']))
411 if(in_array($rr['cid'],$cids))
413 $cids[] = $rr['cid'];
415 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
418 if($rr['network'] === NETWORK_DFRN) {
419 $sparkle = " sparkle";
420 $url = $a->get_baseurl() . '/redir/' . $rr['cid'];
424 $rr['title'] = $rr['name'];
425 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
426 $rr['startime'] = Null;
427 $rr['today'] = $today;
432 $tpl = get_markup_template("birthdays_reminder.tpl");
433 return replace_macros($tpl, array(
434 '$baseurl' => $a->get_baseurl(),
435 '$classtoday' => $classtoday,
437 '$event_reminders' => t('Birthday Reminders'),
438 '$event_title' => t('Birthdays this week:'),
440 '$lbr' => '{', // raw brackets mess up if/endif macro processing
448 if(! function_exists('get_events')) {
449 function get_events() {
451 require_once('include/bbcode.php');
455 if(! local_user() || $a->is_mobile || $a->is_tablet)
459 // $mobile_detect = new Mobile_Detect();
460 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
465 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
466 $bd_short = t('F d');
468 $r = q("SELECT `event`.* FROM `event`
469 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
470 ORDER BY `start` ASC ",
471 intval(local_user()),
472 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
473 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
476 if($r && count($r)) {
477 $now = strtotime('now');
480 if(strlen($rr['name']))
483 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
484 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
487 $classtoday = (($istoday) ? 'event-today' : '');
491 foreach($r as &$rr) {
492 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
494 if(strlen($title) > 35)
495 $title = substr($title,0,32) . '... ';
497 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
499 $description = t('[No description]');
501 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
503 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
508 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
510 $rr['title'] = $title;
511 $rr['description'] = $desciption;
512 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
513 $rr['startime'] = $strt;
514 $rr['today'] = $today;
518 $tpl = get_markup_template("events_reminder.tpl");
519 return replace_macros($tpl, array(
520 '$baseurl' => $a->get_baseurl(),
521 '$classtoday' => $classtoday,
522 '$count' => count($r) - $skip,
523 '$event_reminders' => t('Event Reminders'),
524 '$event_title' => t('Events this week:'),
530 function advanced_profile(&$a) {
533 $uid = $a->profile['uid'];
535 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
536 '$title' => t('Profile')
539 if($a->profile['name']) {
541 $tpl = get_markup_template('profile_advanced.tpl');
545 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
547 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
550 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
552 $year_bd_format = t('j F, Y');
553 $short_bd_format = t('j F');
556 $val = ((intval($a->profile['dob']))
557 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
558 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
560 $profile['birthday'] = array( t('Birthday:'), $val);
564 if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
567 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
570 if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
572 if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
573 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
576 if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
578 if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
580 if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
582 if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
584 if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
586 if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
588 if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
590 if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
592 if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
594 if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
597 if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
599 if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
601 if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
603 if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
605 if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
607 if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
609 if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
611 if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
613 //show subcribed forum if it is enabled in the usersettings
614 if (feature_enabled($uid,'forumlist_profile')) {
615 $profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid));
618 if ($a->profile['uid'] == local_user())
619 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
621 return replace_macros($tpl, array(
622 '$title' => t('Profile'),
623 '$profile' => $profile
630 if(! function_exists('profile_tabs')){
631 function profile_tabs($a, $is_owner=False, $nickname=Null){
632 //echo "<pre>"; var_dump($a->user); killme();
634 if (is_null($nickname))
635 $nickname = $a->user['nickname'];
638 $tab = notags(trim($_GET['tab']));
640 $url = $a->get_baseurl() . '/profile/' . $nickname;
644 'label'=>t('Status'),
646 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
647 'title' => t('Status Messages and Posts'),
648 'id' => 'status-tab',
652 'label' => t('Profile'),
653 'url' => $url.'/?tab=profile',
654 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
655 'title' => t('Profile Details'),
656 'id' => 'profile-tab',
660 'label' => t('Photos'),
661 'url' => $a->get_baseurl() . '/photos/' . $nickname,
662 'sel' => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
663 'title' => t('Photo Albums'),
668 'label' => t('Videos'),
669 'url' => $a->get_baseurl() . '/videos/' . $nickname,
670 'sel' => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
671 'title' => t('Videos'),
678 if ($a->theme_events_in_profile)
680 'label' => t('Events'),
681 'url' => $a->get_baseurl() . '/events',
682 'sel' =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
683 'title' => t('Events and Calendar'),
684 'id' => 'events-tab',
688 'label' => t('Personal Notes'),
689 'url' => $a->get_baseurl() . '/notes',
690 'sel' =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
691 'title' => t('Only You Can See This'),
698 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
699 call_hooks('profile_tabs', $arr);
701 $tpl = get_markup_template('common_tabs.tpl');
703 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
707 function get_my_url() {
708 if(x($_SESSION,'my_url'))
709 return $_SESSION['my_url'];
713 function zrl_init(&$a) {
714 $tmp_str = get_my_url();
715 if(validate_url($tmp_str)) {
717 // Is it a DDoS attempt?
718 // The check fetches the cached value from gprobe to reduce the load for this system
719 $urlparts = parse_url($tmp_str);
721 $result = Cache::get("gprobe:".$urlparts["host"]);
722 if (!is_null($result)) {
723 $result = unserialize($result);
724 if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
725 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
730 proc_run('php','include/gprobe.php',bin2hex($tmp_str));
731 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
732 call_hooks('zrl_init',$arr);
736 function zrl($s,$force = false) {
739 if((! strpos($s,'/profile/')) && (! $force))
741 if($force && substr($s,-1,1) !== '/')
743 $achar = strpos($s,'?') ? '&' : '?';
744 $mine = get_my_url();
745 if($mine and ! link_compare($mine,$s))
746 return $s . $achar . 'zrl=' . urlencode($mine);
750 // Used from within PCSS themes to set theme parameters. If there's a
751 // puid request variable, that is the "page owner" and normally their theme
752 // settings take precedence; unless a local user sets the "always_my_theme"
753 // system pconfig, which means they don't want to see anybody else's theme
754 // settings except their own while on this site.
756 function get_theme_uid() {
757 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
759 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))