3 * @file include/identity.php
6 require_once('include/ForumManager.php');
7 require_once('include/bbcode.php');
8 require_once("mod/proxy.php");
9 require_once('include/cache.php');
13 * @brief Loads a profile into the page sidebar.
15 * The function requires a writeable copy of the main App structure, and the nickname
16 * of a registered local account.
18 * If the viewer is an authenticated remote viewer, the profile displayed is the
19 * one that has been configured for his/her viewing in the Contact manager.
20 * Passing a non-zero profile ID can also allow a preview of a selected profile
23 * Profile information is placed in the App structure for later retrieval.
24 * Honours the owner's chosen theme for display.
26 * @attention Should only be run in the _init() functions of a module. That ensures that
27 * the theme is chosen before the _init() function of a theme is run, which will usually
28 * load a lot of theme-specific content
31 * @param string $nickname
33 * @param array $profiledata
35 function profile_load(App $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 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
50 if(($pdata === false) || (!count($pdata)) && !count($profiledata)) {
51 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
52 notice( t('Requested profile is not available.') . EOL );
57 // fetch user tags if this isn't the default profile
59 if(!$pdata['is-default']) {
60 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
61 intval($pdata['profile_uid'])
64 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
68 $a->profile_uid = $pdata['profile_uid'];
70 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
71 $a->profile['network'] = NETWORK_DFRN;
73 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
75 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
76 $_SESSION['theme'] = $a->profile['theme'];
78 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
81 * load/reload current theme info
84 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
86 $theme_info_file = "view/theme/".current_theme()."/theme.php";
87 if (file_exists($theme_info_file)){
88 require_once($theme_info_file);
91 if(! (x($a->page,'aside')))
92 $a->page['aside'] = '';
94 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
95 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
96 '$editprofile' => t('Edit profile'),
97 '$profid' => $a->profile['id']
101 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
105 * By now, the contact block isn't shown, when a different profile is given
106 * But: When this profile was on the same server, then we could display the contacts
109 $a->page['aside'] .= profile_sidebar($profiledata, true);
111 $a->page['aside'] .= profile_sidebar($a->profile, $block);
114 $a->page['aside'] .= contact_block();*/
121 * @brief Get all profil data of a local user
123 * If the viewer is an authenticated remote viewer, the profile displayed is the
124 * one that has been configured for his/her viewing in the Contact manager.
125 * Passing a non-zero profile ID can also allow a preview of a selected profile
128 * @param string $nickname
130 * @param int $profile
133 * Includes all available profile data
135 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
136 if(remote_user() && count($_SESSION['remote'])) {
137 foreach($_SESSION['remote'] as $visitor) {
138 if($visitor['uid'] == $uid) {
139 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
140 intval($visitor['cid'])
142 if (dbm::is_result($r))
143 $profile = $r[0]['profile-id'];
152 $profile_int = intval($profile);
153 $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
154 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
156 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
157 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
158 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
163 if (!dbm::is_result($r)) {
164 $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
165 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
167 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
168 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
169 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` LIMIT 1",
180 * @brief Formats a profile for display in the sidebar.
182 * It is very difficult to templatise the HTML completely
183 * because of all the conditional logic.
185 * @param array $profile
188 * @return HTML string stuitable for sidebar inclusion
190 * @note Returns empty string if passed $profile is wrong type or not populated
192 * @hooks 'profile_sidebar_enter'
193 * array $profile - profile data
194 * @hooks 'profile_sidebar'
197 function profile_sidebar($profile, $block = 0) {
205 if((! is_array($profile)) && (! count($profile)))
208 $profile['picdate'] = urlencode($profile['picdate']);
210 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
211 $profile['network_name'] = format_network_name($profile['network'],$profile['url']);
213 $profile['network_name'] = "";
215 call_hooks('profile_sidebar_enter', $profile);
218 // don't show connect link to yourself
219 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
221 // don't show connect link to authenticated visitors either
222 if(remote_user() && count($_SESSION['remote'])) {
223 foreach($_SESSION['remote'] as $visitor) {
224 if($visitor['uid'] == $profile['uid']) {
231 // Is the local user already connected to that user?
232 if ($connect AND local_user()) {
233 if (isset($profile["url"])) {
234 $profile_url = normalise_link($profile["url"]);
236 $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
239 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
240 local_user(), $profile_url);
242 if (dbm::is_result($r))
246 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
249 $remoteconnect = NULL;
250 if (isset($profile['remoteconnect']))
251 $remoteconnect = $profile['remoteconnect'];
253 if ($connect AND ($profile['network'] == NETWORK_DFRN) AND !isset($remoteconnect))
254 $subscribe_feed = t("Atom feed");
256 $subscribe_feed = false;
258 if (remote_user() OR (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
259 $wallmessage = t('Message');
260 $wallmessage_link = "wallmessage/".$profile["nickname"];
263 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
264 intval($profile['uid']),
265 intval(remote_user()),
266 intval(CONTACT_IS_FRIEND));
268 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
269 intval($profile['uid']),
270 dbesc(normalise_link(get_my_url())),
271 intval(CONTACT_IS_FRIEND));
274 $remote_url = $r[0]["url"];
275 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
276 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
279 $wallmessage = false;
280 $wallmessage_link = false;
283 // show edit profile to yourself
284 if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
285 $profile['edit'] = array(App::get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
286 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
289 $profile['menu'] = array(
290 'chg_photo' => t('Change profile photo'),
291 'cr_new' => t('Create New Profile'),
292 'entries' => array(),
295 if (dbm::is_result($r)) {
297 foreach ($r as $rr) {
298 $profile['menu']['entries'][] = array(
299 'photo' => $rr['thumb'],
301 'alt' => t('Profile Image'),
302 'profile_name' => $rr['profile-name'],
303 'isdefault' => $rr['is-default'],
304 'visibile_to_everybody' => t('visible to everybody'),
305 'edit_visibility' => t('Edit visibility'),
313 if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
314 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
315 $profile['menu'] = array(
316 'chg_photo' => t('Change profile photo'),
318 'entries' => array(),
322 // Fetch the account type
323 $account_type = account_type($profile);
325 if((x($profile,'address') == 1)
326 || (x($profile,'location') == 1)
327 || (x($profile,'locality') == 1)
328 || (x($profile,'region') == 1)
329 || (x($profile,'postal-code') == 1)
330 || (x($profile,'country-name') == 1))
331 $location = t('Location:');
333 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
336 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
338 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
340 $about = ((x($profile,'about') == 1) ? t('About:') : False);
342 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
344 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
345 $location = $pdesc = $gender = $marital = $homepage = $about = False;
348 $firstname = ((strpos($profile['name'],' '))
349 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
350 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
352 if ($profile['guid'] != "")
354 'guid' => $profile['guid'],
355 'podloc' => App::get_baseurl(),
356 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
357 'nickname' => $profile['nickname'],
358 'fullname' => $profile['name'],
359 'firstname' => $firstname,
360 'lastname' => $lastname,
361 'photo300' => App::get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
362 'photo100' => App::get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
363 'photo50' => App::get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
369 $contact_block = contact_block();
371 if(is_array($a->profile) AND !$a->profile['hide-friends']) {
372 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
373 intval($a->profile['uid']));
374 if (dbm::is_result($r))
375 $updated = date("c", strtotime($r[0]['updated']));
377 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
379 AND NOT `self` AND NOT `blocked` AND NOT `pending`
380 AND NOT `hidden` AND NOT `archive`
381 AND `network` IN ('%s', '%s', '%s', '')",
382 intval($profile['uid']),
384 dbesc(NETWORK_DIASPORA),
385 dbesc(NETWORK_OSTATUS)
387 if (dbm::is_result($r))
388 $contacts = intval($r[0]['total']);
393 foreach($profile as $k => $v) {
394 $k = str_replace('-','_',$k);
398 if (isset($p["about"]))
399 $p["about"] = bbcode($p["about"]);
401 if (isset($p["address"]))
402 $p["address"] = bbcode($p["address"]);
404 $p["address"] = bbcode($p["location"]);
406 if (isset($p["photo"]))
407 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
409 if($a->theme['template_engine'] === 'internal')
410 $location = template_escape($location);
412 $tpl = get_markup_template('profile_vcard.tpl');
413 $o .= replace_macros($tpl, array(
416 '$connect' => $connect,
417 '$remoteconnect' => $remoteconnect,
418 '$subscribe_feed' => $subscribe_feed,
419 '$wallmessage' => $wallmessage,
420 '$wallmessage_link' => $wallmessage_link,
421 '$account_type' => $account_type,
422 '$location' => $location,
423 '$gender' => $gender,
424 // '$pdesc' => $pdesc,
425 '$marital' => $marital,
426 '$homepage' => $homepage,
428 '$network' => t('Network:'),
429 '$contacts' => $contacts,
430 '$updated' => $updated,
431 '$diaspora' => $diaspora,
432 '$contact_block' => $contact_block,
435 $arr = array('profile' => &$profile, 'entry' => &$o);
437 call_hooks('profile_sidebar', $arr);
443 function get_birthdays() {
448 if(! local_user() || $a->is_mobile || $a->is_tablet)
451 // $mobile_detect = new Mobile_Detect();
452 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
457 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
458 $bd_short = t('F d');
460 $cachekey = "get_birthdays:".local_user();
461 $r = Cache::get($cachekey);
463 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
464 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
465 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
466 ORDER BY `start` ASC ",
467 intval(local_user()),
468 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
469 dbesc(datetime_convert('UTC','UTC','now'))
471 if (dbm::is_result($r)) {
472 Cache::set($cachekey, $r, CACHE_HOUR);
475 if (dbm::is_result($r)) {
477 $now = strtotime('now');
481 foreach ($r as $rr) {
482 if(strlen($rr['name']))
484 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
487 $classtoday = $istoday ? ' birthday-today ' : '';
489 foreach($r as &$rr) {
490 if(! strlen($rr['name']))
495 if(in_array($rr['cid'],$cids))
497 $cids[] = $rr['cid'];
499 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
502 if($rr['network'] === NETWORK_DFRN) {
503 $sparkle = " sparkle";
504 $url = App::get_baseurl() . '/redir/' . $rr['cid'];
508 $rr['title'] = $rr['name'];
509 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
510 $rr['startime'] = Null;
511 $rr['today'] = $today;
516 $tpl = get_markup_template("birthdays_reminder.tpl");
517 return replace_macros($tpl, array(
518 '$baseurl' => App::get_baseurl(),
519 '$classtoday' => $classtoday,
521 '$event_reminders' => t('Birthday Reminders'),
522 '$event_title' => t('Birthdays this week:'),
524 '$lbr' => '{', // raw brackets mess up if/endif macro processing
531 function get_events() {
533 require_once('include/bbcode.php');
537 if(! local_user() || $a->is_mobile || $a->is_tablet)
541 // $mobile_detect = new Mobile_Detect();
542 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
547 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
548 $bd_short = t('F d');
550 $r = q("SELECT `event`.* FROM `event`
551 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
552 ORDER BY `start` ASC ",
553 intval(local_user()),
554 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
555 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
558 if (dbm::is_result($r)) {
559 $now = strtotime('now');
561 foreach ($r as $rr) {
562 if(strlen($rr['name']))
565 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
566 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
569 $classtoday = (($istoday) ? 'event-today' : '');
573 foreach($r as &$rr) {
574 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
576 if(strlen($title) > 35)
577 $title = substr($title,0,32) . '... ';
579 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
581 $description = t('[No description]');
583 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
585 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
590 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
592 $rr['title'] = $title;
593 $rr['description'] = $desciption;
594 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
595 $rr['startime'] = $strt;
596 $rr['today'] = $today;
600 $tpl = get_markup_template("events_reminder.tpl");
601 return replace_macros($tpl, array(
602 '$baseurl' => App::get_baseurl(),
603 '$classtoday' => $classtoday,
604 '$count' => count($r) - $skip,
605 '$event_reminders' => t('Event Reminders'),
606 '$event_title' => t('Events this week:'),
611 function advanced_profile(App $a) {
614 $uid = $a->profile['uid'];
616 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
617 '$title' => t('Profile')
620 if($a->profile['name']) {
622 $tpl = get_markup_template('profile_advanced.tpl');
626 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
628 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
631 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
633 $year_bd_format = t('j F, Y');
634 $short_bd_format = t('j F');
637 $val = ((intval($a->profile['dob']))
638 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
639 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
641 $profile['birthday'] = array( t('Birthday:'), $val);
645 if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
648 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
650 /// @TODO Maybe use x() here, plus below?
651 if ($a->profile['with']) {
652 $profile['marital']['with'] = $a->profile['with'];
655 if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
656 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
659 if ($a->profile['sexual']) {
660 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
663 if ($a->profile['homepage']) {
664 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
667 if ($a->profile['hometown']) {
668 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
671 if ($a->profile['pub_keywords']) {
672 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
675 if ($a->profile['politic']) {
676 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
679 if ($a->profile['religion']) {
680 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
683 if ($txt = prepare_text($a->profile['about'])) {
684 $profile['about'] = array( t('About:'), $txt );
687 if ($txt = prepare_text($a->profile['interest'])) {
688 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
691 if ($txt = prepare_text($a->profile['likes'])) {
692 $profile['likes'] = array( t('Likes:'), $txt);
695 if ($txt = prepare_text($a->profile['dislikes'])) {
696 $profile['dislikes'] = array( t('Dislikes:'), $txt);
699 if ($txt = prepare_text($a->profile['contact'])) {
700 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
703 if ($txt = prepare_text($a->profile['music'])) {
704 $profile['music'] = array( t('Musical interests:'), $txt);
707 if ($txt = prepare_text($a->profile['book'])) {
708 $profile['book'] = array( t('Books, literature:'), $txt);
711 if ($txt = prepare_text($a->profile['tv'])) {
712 $profile['tv'] = array( t('Television:'), $txt);
715 if ($txt = prepare_text($a->profile['film'])) {
716 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
719 if ($txt = prepare_text($a->profile['romance'])) {
720 $profile['romance'] = array( t('Love/Romance:'), $txt);
723 if ($txt = prepare_text($a->profile['work'])) {
724 $profile['work'] = array( t('Work/employment:'), $txt);
727 if ($txt = prepare_text($a->profile['education'])) {
728 $profile['education'] = array( t('School/education:'), $txt );
731 //show subcribed forum if it is enabled in the usersettings
732 if (feature_enabled($uid,'forumlist_profile')) {
733 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
736 if ($a->profile['uid'] == local_user()) {
737 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
740 return replace_macros($tpl, array(
741 '$title' => t('Profile'),
742 '$basic' => t('Basic'),
743 '$advanced' => t('Advanced'),
744 '$profile' => $profile
751 function profile_tabs($a, $is_owner=False, $nickname=Null){
752 //echo "<pre>"; var_dump($a->user); killme();
754 if (is_null($nickname)) {
755 $nickname = $a->user['nickname'];
758 if (x($_GET,'tab')) {
759 $tab = notags(trim($_GET['tab']));
762 $url = App::get_baseurl() . '/profile/' . $nickname;
766 'label'=>t('Status'),
768 'sel' => ((!isset($tab) && $a->argv[0]=='profile')?'active':''),
769 'title' => t('Status Messages and Posts'),
770 'id' => 'status-tab',
774 'label' => t('Profile'),
775 'url' => $url.'/?tab=profile',
776 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
777 'title' => t('Profile Details'),
778 'id' => 'profile-tab',
782 'label' => t('Photos'),
783 'url' => App::get_baseurl() . '/photos/' . $nickname,
784 'sel' => ((!isset($tab) && $a->argv[0]=='photos')?'active':''),
785 'title' => t('Photo Albums'),
790 'label' => t('Videos'),
791 'url' => App::get_baseurl() . '/videos/' . $nickname,
792 'sel' => ((!isset($tab) && $a->argv[0]=='videos')?'active':''),
793 'title' => t('Videos'),
799 // the calendar link for the full featured events calendar
800 if ($is_owner && $a->theme_events_in_profile) {
802 'label' => t('Events'),
803 'url' => App::get_baseurl() . '/events',
804 'sel' =>((!isset($tab) && $a->argv[0]=='events')?'active':''),
805 'title' => t('Events and Calendar'),
806 'id' => 'events-tab',
809 // if the user is not the owner of the calendar we only show a calendar
810 // with the public events of the calendar owner
811 } elseif (! $is_owner) {
813 'label' => t('Events'),
814 'url' => App::get_baseurl() . '/cal/' . $nickname,
815 'sel' =>((!isset($tab) && $a->argv[0]=='cal')?'active':''),
816 'title' => t('Events and Calendar'),
817 'id' => 'events-tab',
824 'label' => t('Personal Notes'),
825 'url' => App::get_baseurl() . '/notes',
826 'sel' =>((!isset($tab) && $a->argv[0]=='notes')?'active':''),
827 'title' => t('Only You Can See This'),
833 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
835 'label' => t('Contacts'),
836 'url' => App::get_baseurl() . '/viewcontacts/' . $nickname,
837 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts')?'active':''),
838 'title' => t('Contacts'),
839 'id' => 'viewcontacts-tab',
844 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
845 call_hooks('profile_tabs', $arr);
847 $tpl = get_markup_template('common_tabs.tpl');
849 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
852 function get_my_url() {
853 if(x($_SESSION,'my_url'))
854 return $_SESSION['my_url'];
858 function zrl_init(App $a) {
859 $tmp_str = get_my_url();
860 if(validate_url($tmp_str)) {
862 // Is it a DDoS attempt?
863 // The check fetches the cached value from gprobe to reduce the load for this system
864 $urlparts = parse_url($tmp_str);
866 $result = Cache::get("gprobe:".$urlparts["host"]);
867 if (!is_null($result)) {
868 if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
869 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
874 proc_run(PRIORITY_LOW, 'include/gprobe.php',bin2hex($tmp_str));
875 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
876 call_hooks('zrl_init',$arr);
880 function zrl($s,$force = false) {
883 if((! strpos($s,'/profile/')) && (! $force))
885 if($force && substr($s,-1,1) !== '/')
887 $achar = strpos($s,'?') ? '&' : '?';
888 $mine = get_my_url();
889 if($mine and ! link_compare($mine,$s))
890 return $s . $achar . 'zrl=' . urlencode($mine);
895 * @brief Get the user ID of the page owner
897 * Used from within PCSS themes to set theme parameters. If there's a
898 * puid request variable, that is the "page owner" and normally their theme
899 * settings take precedence; unless a local user sets the "always_my_theme"
900 * system pconfig, which means they don't want to see anybody else's theme
901 * settings except their own while on this site.
903 * @return int user ID
905 * @note Returns local_user instead of user ID if "always_my_theme"
908 function get_theme_uid() {
909 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
911 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))