6 * Function : profile_load
8 * @parameter string $nickname
9 * @parameter int $profile
11 * Summary: Loads a profile into the page sidebar.
12 * The function requires a writeable copy of the main App structure, and the nickname
13 * of a registered local account.
15 * If the viewer is an authenticated remote viewer, the profile displayed is the
16 * one that has been configured for his/her viewing in the Contact manager.
17 * Passing a non-zero profile ID can also allow a preview of a selected profile
20 * Profile information is placed in the App structure for later retrieval.
21 * Honours the owner's chosen theme for display.
23 * IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
24 * the theme is chosen before the _init() function of a theme is run, which will usually
25 * load a lot of theme-specific content
29 if(! function_exists('profile_load')) {
30 function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
32 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
36 if(!$user && count($user) && !count($profiledata)) {
37 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
38 notice( t('Requested account is not available.') . EOL );
43 if(remote_user() && count($_SESSION['remote'])) {
44 foreach($_SESSION['remote'] as $visitor) {
45 if($visitor['uid'] == $user[0]['uid']) {
46 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
47 intval($visitor['cid'])
50 $profile = $r[0]['profile-id'];
59 $profile_int = intval($profile);
60 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
61 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
62 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d and `contact`.`self` = 1 LIMIT 1",
67 if((!$r) && (!count($r))) {
68 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
69 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
70 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
75 if(($r === false) || (!count($r)) && !count($profiledata)) {
76 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
77 notice( t('Requested profile is not available.') . EOL );
82 // fetch user tags if this isn't the default profile
84 if(!$r[0]['is-default']) {
85 $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1",
86 intval($r[0]['profile_uid'])
89 $r[0]['pub_keywords'] = $x[0]['pub_keywords'];
93 $a->profile_uid = $r[0]['profile_uid'];
95 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
96 $a->profile['network'] = NETWORK_DFRN;
98 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
100 // if (!$profiledata)
101 // $_SESSION['theme'] = $a->profile['theme'];
103 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
106 * load/reload current theme info
109 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
111 $theme_info_file = "view/theme/".current_theme()."/theme.php";
112 if (file_exists($theme_info_file)){
113 require_once($theme_info_file);
116 if(! (x($a->page,'aside')))
117 $a->page['aside'] = '';
119 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
120 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
121 '$editprofile' => t('Edit profile'),
122 '$profid' => $a->profile['id']
126 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
129 // By now, the contact block isn't shown, when a different profile is given
130 // But: When this profile was on the same server, then we could display the contacts
132 $a->page['aside'] .= profile_sidebar($profiledata, true);
134 $a->page['aside'] .= profile_sidebar($a->profile, $block);
138 $a->page['aside'] .= contact_block();*/
147 * Function: profile_sidebar
149 * Formats a profile for display in the sidebar.
150 * It is very difficult to templatise the HTML completely
151 * because of all the conditional logic.
153 * @parameter: array $profile
155 * Returns HTML string stuitable for sidebar inclusion
156 * Exceptions: Returns empty string if passed $profile is wrong type or not populated
161 if(! function_exists('profile_sidebar')) {
162 function profile_sidebar($profile, $block = 0) {
170 if((! is_array($profile)) && (! count($profile)))
173 $profile['picdate'] = urlencode($profile['picdate']);
175 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
176 require_once('include/contact_selectors.php');
177 if ($profile['url'] != "")
178 $profile['network_name'] = '<a href="'.$profile['url'].'">'.network_to_name($profile['network'], $profile['url'])."</a>";
180 $profile['network_name'] = network_to_name($profile['network']);
182 $profile['network_name'] = "";
184 call_hooks('profile_sidebar_enter', $profile);
187 // don't show connect link to yourself
188 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
190 // don't show connect link to authenticated visitors either
191 if(remote_user() && count($_SESSION['remote'])) {
192 foreach($_SESSION['remote'] as $visitor) {
193 if($visitor['uid'] == $profile['uid']) {
200 // Is the local user already connected to that user?
201 if ($connect AND local_user()) {
202 if (isset($profile["url"]))
203 $profile_url = normalise_link($profile["url"]);
205 $profile_url = normalise_link($a->get_baseurl()."/profile/".$profile["nickname"]);
207 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
208 local_user(), $profile_url);
213 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
216 if (isset($profile['remoteconnect']))
217 $remoteconnect = $profile['remoteconnect'];
219 if( get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()) )
220 $wallmessage = t('Message');
222 $wallmessage = false;
224 // show edit profile to yourself
225 if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
226 $profile['edit'] = array($a->get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
227 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
230 $profile['menu'] = array(
231 'chg_photo' => t('Change profile photo'),
232 'cr_new' => t('Create New Profile'),
233 'entries' => array(),
239 $profile['menu']['entries'][] = array(
240 'photo' => $rr['thumb'],
242 'alt' => t('Profile Image'),
243 'profile_name' => $rr['profile-name'],
244 'isdefault' => $rr['is-default'],
245 'visibile_to_everybody' => t('visible to everybody'),
246 'edit_visibility' => t('Edit visibility'),
254 if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
255 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
256 $profile['menu'] = array(
257 'chg_photo' => t('Change profile photo'),
259 'entries' => array(),
263 if((x($profile,'address') == 1)
264 || (x($profile,'locality') == 1)
265 || (x($profile,'region') == 1)
266 || (x($profile,'postal-code') == 1)
267 || (x($profile,'country-name') == 1))
268 $location = t('Location:');
270 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
273 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
275 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
277 $about = ((x($profile,'about') == 1) ? t('About:') : False);
279 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
280 $location = $pdesc = $gender = $marital = $homepage = $about = False;
283 $firstname = ((strpos($profile['name'],' '))
284 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
285 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
288 'podloc' => $a->get_baseurl(),
289 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
290 'nickname' => $profile['nickname'],
291 'fullname' => $profile['name'],
292 'firstname' => $firstname,
293 'lastname' => $lastname,
294 'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
295 'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
296 'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'),
300 $contact_block = contact_block();
302 if(is_array($a->profile) AND !$a->profile['hide-friends']) {
303 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
304 intval($a->profile['uid']));
306 $updated = date("c", strtotime($r[0]['updated']));
308 $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
309 AND `network` IN ('%s', '%s', '%s', '')",
310 intval($profile['uid']),
312 dbesc(NETWORK_DIASPORA),
313 dbesc(NETWORK_OSTATUS)
316 $contacts = intval($r[0]['total']);
321 foreach($profile as $k => $v) {
322 $k = str_replace('-','_',$k);
326 if($a->theme['template_engine'] === 'internal')
327 $location = template_escape($location);
329 $tpl = get_markup_template('profile_vcard.tpl');
330 $o .= replace_macros($tpl, array(
332 '$connect' => $connect,
333 '$remoteconnect' => $remoteconnect,
334 '$wallmessage' => $wallmessage,
335 '$location' => $location,
336 '$gender' => $gender,
338 '$marital' => $marital,
339 '$homepage' => $homepage,
341 '$network' => t('Network:'),
342 '$contacts' => $contacts,
343 '$updated' => $updated,
344 '$diaspora' => $diaspora,
345 '$contact_block' => $contact_block,
349 $arr = array('profile' => &$profile, 'entry' => &$o);
351 call_hooks('profile_sidebar', $arr);
358 if(! function_exists('get_birthdays')) {
359 function get_birthdays() {
364 if(! local_user() || $a->is_mobile || $a->is_tablet)
367 // $mobile_detect = new Mobile_Detect();
368 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
373 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
374 $bd_short = t('F d');
376 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
377 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
378 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
379 ORDER BY `start` ASC ",
380 intval(local_user()),
381 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
382 dbesc(datetime_convert('UTC','UTC','now'))
385 if($r && count($r)) {
387 $now = strtotime('now');
392 if(strlen($rr['name']))
394 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
397 $classtoday = $istoday ? ' birthday-today ' : '';
399 foreach($r as &$rr) {
400 if(! strlen($rr['name']))
405 if(in_array($rr['cid'],$cids))
407 $cids[] = $rr['cid'];
409 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
412 if($rr['network'] === NETWORK_DFRN) {
413 $sparkle = " sparkle";
414 $url = $a->get_baseurl() . '/redir/' . $rr['cid'];
418 $rr['title'] = $rr['name'];
419 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
420 $rr['startime'] = Null;
421 $rr['today'] = $today;
426 $tpl = get_markup_template("birthdays_reminder.tpl");
427 return replace_macros($tpl, array(
428 '$baseurl' => $a->get_baseurl(),
429 '$classtoday' => $classtoday,
431 '$event_reminders' => t('Birthday Reminders'),
432 '$event_title' => t('Birthdays this week:'),
434 '$lbr' => '{', // raw brackets mess up if/endif macro processing
442 if(! function_exists('get_events')) {
443 function get_events() {
445 require_once('include/bbcode.php');
449 if(! local_user() || $a->is_mobile || $a->is_tablet)
453 // $mobile_detect = new Mobile_Detect();
454 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
459 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
460 $bd_short = t('F d');
462 $r = q("SELECT `event`.* FROM `event`
463 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
464 ORDER BY `start` ASC ",
465 intval(local_user()),
466 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
467 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
470 if($r && count($r)) {
471 $now = strtotime('now');
474 if(strlen($rr['name']))
477 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
478 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
481 $classtoday = (($istoday) ? 'event-today' : '');
485 foreach($r as &$rr) {
486 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
488 if(strlen($title) > 35)
489 $title = substr($title,0,32) . '... ';
491 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
493 $description = t('[No description]');
495 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
497 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
502 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
504 $rr['title'] = $title;
505 $rr['description'] = $desciption;
506 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
507 $rr['startime'] = $strt;
508 $rr['today'] = $today;
512 $tpl = get_markup_template("events_reminder.tpl");
513 return replace_macros($tpl, array(
514 '$baseurl' => $a->get_baseurl(),
515 '$classtoday' => $classtoday,
516 '$count' => count($r) - $skip,
517 '$event_reminders' => t('Event Reminders'),
518 '$event_title' => t('Events this week:'),
524 function advanced_profile(&$a) {
528 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
529 '$title' => t('Profile')
532 if($a->profile['name']) {
534 $tpl = get_markup_template('profile_advanced.tpl');
538 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
540 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
543 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
545 $year_bd_format = t('j F, Y');
546 $short_bd_format = t('j F');
549 $val = ((intval($a->profile['dob']))
550 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
551 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
553 $profile['birthday'] = array( t('Birthday:'), $val);
557 if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
560 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
563 if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
565 if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
566 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
569 if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
571 if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
573 if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
575 if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
577 if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
579 if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
581 if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
583 if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
585 if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
587 if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
590 if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
592 if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
594 if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
596 if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
598 if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
600 if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
602 if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
604 if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
606 if ($a->profile['uid'] == local_user())
607 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
609 return replace_macros($tpl, array(
610 '$title' => t('Profile'),
611 '$profile' => $profile
618 if(! function_exists('profile_tabs')){
619 function profile_tabs($a, $is_owner=False, $nickname=Null){
620 //echo "<pre>"; var_dump($a->user); killme();
622 if (is_null($nickname))
623 $nickname = $a->user['nickname'];
626 $tab = notags(trim($_GET['tab']));
628 $url = $a->get_baseurl() . '/profile/' . $nickname;
632 'label'=>t('Status'),
634 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
635 'title' => t('Status Messages and Posts'),
636 'id' => 'status-tab',
640 'label' => t('Profile'),
641 'url' => $url.'/?tab=profile',
642 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
643 'title' => t('Profile Details'),
644 'id' => 'profile-tab',
648 'label' => t('Photos'),
649 'url' => $a->get_baseurl() . '/photos/' . $nickname,
650 'sel' => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
651 'title' => t('Photo Albums'),
656 'label' => t('Videos'),
657 'url' => $a->get_baseurl() . '/videos/' . $nickname,
658 'sel' => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
659 'title' => t('Videos'),
667 'label' => t('Events'),
668 'url' => $a->get_baseurl() . '/events',
669 'sel' =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
670 'title' => t('Events and Calendar'),
671 'id' => 'events-tab',
675 'label' => t('Personal Notes'),
676 'url' => $a->get_baseurl() . '/notes',
677 'sel' =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
678 'title' => t('Only You Can See This'),
685 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
686 call_hooks('profile_tabs', $arr);
688 $tpl = get_markup_template('common_tabs.tpl');
690 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
694 function get_my_url() {
695 if(x($_SESSION,'my_url'))
696 return $_SESSION['my_url'];
700 function zrl_init(&$a) {
701 $tmp_str = get_my_url();
702 if(validate_url($tmp_str)) {
704 // Is it a DDoS attempt?
705 // The check fetches the cached value from gprobe to reduce the load for this system
706 $urlparts = parse_url($tmp_str);
708 $result = Cache::get("gprobe:".$urlparts["host"]);
709 if (!is_null($result)) {
710 $result = unserialize($result);
711 if ($result["network"] == NETWORK_FEED) {
712 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
717 proc_run('php','include/gprobe.php',bin2hex($tmp_str));
718 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
719 call_hooks('zrl_init',$arr);
723 function zrl($s,$force = false) {
726 if((! strpos($s,'/profile/')) && (! $force))
728 if($force && substr($s,-1,1) !== '/')
730 $achar = strpos($s,'?') ? '&' : '?';
731 $mine = get_my_url();
732 if($mine and ! link_compare($mine,$s))
733 return $s . $achar . 'zrl=' . urlencode($mine);
737 // Used from within PCSS themes to set theme parameters. If there's a
738 // puid request variable, that is the "page owner" and normally their theme
739 // settings take precedence; unless a local user sets the "always_my_theme"
740 // system pconfig, which means they don't want to see anybody else's theme
741 // settings except their own while on this site.
743 function get_theme_uid() {
744 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
746 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))