4 * @file src/Model/Profile.php
7 namespace Friendica\Model;
10 use Friendica\Content\Feature;
11 use Friendica\Content\ForumManager;
12 use Friendica\Core\Cache;
13 use Friendica\Core\Config;
14 use Friendica\Core\PConfig;
15 use Friendica\Core\System;
16 use Friendica\Core\Worker;
17 use Friendica\Database\DBM;
18 use Friendica\Model\Contact;
19 use Friendica\Protocol\Diaspora;
21 require_once 'include/bbcode.php';
22 require_once 'mod/proxy.php';
27 * @brief Returns a formatted location string from the given profile array
29 * @param array $profile Profile array (Generated from the "profile" table)
31 * @return string Location string
33 public static function formatLocation(array $profile)
37 if ($profile['locality']) {
38 $location .= $profile['locality'];
41 if ($profile['region'] && ($profile['locality'] != $profile['region'])) {
46 $location .= $profile['region'];
49 if ($profile['country-name']) {
54 $location .= $profile['country-name'];
62 * @brief Loads a profile into the page sidebar.
64 * The function requires a writeable copy of the main App structure, and the nickname
65 * of a registered local account.
67 * If the viewer is an authenticated remote viewer, the profile displayed is the
68 * one that has been configured for his/her viewing in the Contact manager.
69 * Passing a non-zero profile ID can also allow a preview of a selected profile
72 * Profile information is placed in the App structure for later retrieval.
73 * Honours the owner's chosen theme for display.
75 * @attention Should only be run in the _init() functions of a module. That ensures that
76 * the theme is chosen before the _init() function of a theme is run, which will usually
77 * load a lot of theme-specific content
79 * @param object $a App
80 * @param string $nickname string
81 * @param int $profile int
82 * @param array $profiledata array
83 * @param boolean $show_connect Show connect link
85 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array(), $show_connect = true)
88 "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
92 if (!$user && !count($user) && !count($profiledata)) {
93 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
94 notice(t('Requested account is not available.') . EOL);
99 if (!x($a->page, 'aside')) {
100 $a->page['aside'] = '';
104 $a->page['aside'] .= profile_sidebar($profiledata, true, $show_connect);
106 if (!DBM::is_result($user)) {
111 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
113 if (empty($pdata) && empty($profiledata)) {
114 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
115 notice(t('Requested profile is not available.') . EOL);
120 // fetch user tags if this isn't the default profile
122 if (!$pdata['is-default']) {
124 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
125 intval($pdata['profile_uid'])
127 if ($x && count($x)) {
128 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
132 $a->profile = $pdata;
133 $a->profile_uid = $pdata['profile_uid'];
135 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
136 $a->profile['network'] = NETWORK_DFRN;
138 $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename'];
140 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
141 $_SESSION['theme'] = $a->profile['theme'];
144 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
147 * load/reload current theme info
150 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
152 $theme_info_file = 'view/theme/' . current_theme() . '/theme.php';
153 if (file_exists($theme_info_file)) {
154 require_once $theme_info_file;
157 if (!x($a->page, 'aside')) {
158 $a->page['aside'] = '';
161 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
162 $a->page['aside'] .= replace_macros(
163 get_markup_template('profile_edlink.tpl'),
165 '$editprofile' => t('Edit profile'),
166 '$profid' => $a->profile['id']
171 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
175 * By now, the contact block isn't shown, when a different profile is given
176 * But: When this profile was on the same server, then we could display the contacts
179 $a->page['aside'] .= profile_sidebar($a->profile, $block, $show_connect);
186 * @brief Get all profil data of a local user
188 * If the viewer is an authenticated remote viewer, the profile displayed is the
189 * one that has been configured for his/her viewing in the Contact manager.
190 * Passing a non-zero profile ID can also allow a preview of a selected profile
193 * Includes all available profile data
195 * @param string $nickname nick
196 * @param int $uid uid
197 * @param int $profile_id ID of the profile
200 function get_profiledata_by_nick($nickname, $uid = 0, $profile_id = 0)
202 if (remote_user() && count($_SESSION['remote'])) {
203 foreach ($_SESSION['remote'] as $visitor) {
204 if ($visitor['uid'] == $uid) {
205 $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
206 if (DBM::is_result($contact)) {
207 $profile_id = $contact['profile-id'];
217 $profile = dba::fetch_first(
218 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
219 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
220 `profile`.`uid` AS `profile_uid`, `profile`.*,
221 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
223 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
224 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
225 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
230 if (!DBM::is_result($profile)) {
231 $profile = dba::fetch_first(
232 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
233 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
234 `profile`.`uid` AS `profile_uid`, `profile`.*,
235 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
237 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
238 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
239 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
248 * @brief Formats a profile for display in the sidebar.
250 * It is very difficult to templatise the HTML completely
251 * because of all the conditional logic.
253 * @param array $profile
255 * @param boolean $show_connect Show connect link
257 * @return HTML string suitable for sidebar inclusion
259 * @note Returns empty string if passed $profile is wrong type or not populated
261 * @hooks 'profile_sidebar_enter'
262 * array $profile - profile data
263 * @hooks 'profile_sidebar'
266 function profile_sidebar($profile, $block = 0, $show_connect = true)
273 // This function can also use contact information in $profile
274 $is_contact = x($profile, 'cid');
276 if (!is_array($profile) && !count($profile)) {
280 $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
282 if (($profile['network'] != '') && ($profile['network'] != NETWORK_DFRN)) {
283 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
285 $profile['network_name'] = '';
288 call_hooks('profile_sidebar_enter', $profile);
291 // don't show connect link to yourself
292 $connect = $profile['uid'] != local_user() ? t('Connect') : false;
294 // don't show connect link to authenticated visitors either
295 if (remote_user() && count($_SESSION['remote'])) {
296 foreach ($_SESSION['remote'] as $visitor) {
297 if ($visitor['uid'] == $profile['uid']) {
304 if (!$show_connect) {
308 // Is the local user already connected to that user?
309 if ($connect && local_user()) {
310 if (isset($profile['url'])) {
311 $profile_url = normalise_link($profile['url']);
313 $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']);
316 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
321 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect'])) {
325 $remoteconnect = null;
326 if (isset($profile['remoteconnect'])) {
327 $remoteconnect = $profile['remoteconnect'];
330 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect)) {
331 $subscribe_feed = t('Atom feed');
333 $subscribe_feed = false;
336 if (remote_user() || (get_my_url() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
337 $wallmessage = t('Message');
338 $wallmessage_link = 'wallmessage/' . $profile['nickname'];
342 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
343 intval($profile['uid']),
344 intval(remote_user()),
345 intval(CONTACT_IS_FRIEND)
349 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
350 intval($profile['uid']),
351 dbesc(normalise_link(get_my_url())),
352 intval(CONTACT_IS_FRIEND)
356 $remote_url = $r[0]['url'];
357 $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url);
358 $wallmessage_link = $message_path . base64_encode($profile['addr']);
361 $wallmessage = false;
362 $wallmessage_link = false;
365 // show edit profile to yourself
366 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
367 $profile['edit'] = array(System::baseUrl() . '/profiles', t('Profiles'), '', t('Manage/edit profiles'));
369 "SELECT * FROM `profile` WHERE `uid` = %d",
373 $profile['menu'] = array(
374 'chg_photo' => t('Change profile photo'),
375 'cr_new' => t('Create New Profile'),
376 'entries' => array(),
379 if (DBM::is_result($r)) {
380 foreach ($r as $rr) {
381 $profile['menu']['entries'][] = array(
382 'photo' => $rr['thumb'],
384 'alt' => t('Profile Image'),
385 'profile_name' => $rr['profile-name'],
386 'isdefault' => $rr['is-default'],
387 'visibile_to_everybody' => t('visible to everybody'),
388 'edit_visibility' => t('Edit visibility'),
393 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
394 $profile['edit'] = array(System::baseUrl() . '/profiles/' . $profile['id'], t('Edit profile'), '', t('Edit profile'));
395 $profile['menu'] = array(
396 'chg_photo' => t('Change profile photo'),
398 'entries' => array(),
402 // Fetch the account type
403 $account_type = Contact::getAccountType($profile);
405 if (x($profile, 'address')
406 || x($profile, 'location')
407 || x($profile, 'locality')
408 || x($profile, 'region')
409 || x($profile, 'postal-code')
410 || x($profile, 'country-name')
412 $location = t('Location:');
415 $gender = x($profile, 'gender') ? t('Gender:') : false;
416 $marital = x($profile, 'marital') ? t('Status:') : false;
417 $homepage = x($profile, 'homepage') ? t('Homepage:') : false;
418 $about = x($profile, 'about') ? t('About:') : false;
419 $xmpp = x($profile, 'xmpp') ? t('XMPP:') : false;
421 if ((x($profile, 'hidewall') || $block) && !local_user() && !remote_user()) {
422 $location = $gender = $marital = $homepage = $about = false;
425 $split_name = Diaspora::splitName($profile['name']);
426 $firstname = $split_name['first'];
427 $lastname = $split_name['last'];
429 if (x($profile, 'guid')) {
431 'guid' => $profile['guid'],
432 'podloc' => System::baseUrl(),
433 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
434 'nickname' => $profile['nickname'],
435 'fullname' => $profile['name'],
436 'firstname' => $firstname,
437 'lastname' => $lastname,
438 'photo300' => $profile['contact_photo'],
439 'photo100' => $profile['contact_thumb'],
440 'photo50' => $profile['contact_micro'],
450 $contact_block = contact_block();
452 if (is_array($a->profile) && !$a->profile['hide-friends']) {
454 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
455 intval($a->profile['uid'])
457 if (DBM::is_result($r)) {
458 $updated = date('c', strtotime($r[0]['updated']));
462 "SELECT COUNT(*) AS `total` FROM `contact`
464 AND NOT `self` AND NOT `blocked` AND NOT `pending`
465 AND NOT `hidden` AND NOT `archive`
466 AND `network` IN ('%s', '%s', '%s', '')",
467 intval($profile['uid']),
469 dbesc(NETWORK_DIASPORA),
470 dbesc(NETWORK_OSTATUS)
472 if (DBM::is_result($r)) {
473 $contacts = intval($r[0]['total']);
479 foreach ($profile as $k => $v) {
480 $k = str_replace('-', '_', $k);
484 if (isset($p['about'])) {
485 $p['about'] = bbcode($p['about']);
488 if (isset($p['address'])) {
489 $p['address'] = bbcode($p['address']);
491 $p['address'] = bbcode($p['location']);
494 if (isset($p['photo'])) {
495 $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
498 $tpl = get_markup_template('profile_vcard.tpl');
499 $o .= replace_macros($tpl, array(
502 '$connect' => $connect,
503 '$remoteconnect' => $remoteconnect,
504 '$subscribe_feed' => $subscribe_feed,
505 '$wallmessage' => $wallmessage,
506 '$wallmessage_link' => $wallmessage_link,
507 '$account_type' => $account_type,
508 '$location' => $location,
509 '$gender' => $gender,
510 '$marital' => $marital,
511 '$homepage' => $homepage,
513 '$network' => t('Network:'),
514 '$contacts' => $contacts,
515 '$updated' => $updated,
516 '$diaspora' => $diaspora,
517 '$contact_block' => $contact_block,
520 $arr = array('profile' => &$profile, 'entry' => &$o);
522 call_hooks('profile_sidebar', $arr);
527 function get_birthdays()
532 if (!local_user() || $a->is_mobile || $a->is_tablet) {
537 * $mobile_detect = new Mobile_Detect();
538 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
543 $bd_format = t('g A l F d'); // 8 AM Friday January 18
544 $bd_short = t('F d');
546 $cachekey = 'get_birthdays:' . local_user();
547 $r = Cache::get($cachekey);
550 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
551 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
552 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
553 ORDER BY `start` ASC ",
555 datetime_convert('UTC', 'UTC', 'now + 6 days'),
556 datetime_convert('UTC', 'UTC', 'now')
558 if (DBM::is_result($s)) {
559 $r = dba::inArray($s);
560 Cache::set($cachekey, $r, CACHE_HOUR);
563 if (DBM::is_result($r)) {
565 $now = strtotime('now');
569 foreach ($r as $rr) {
570 if (strlen($rr['name'])) {
573 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
577 $classtoday = $istoday ? ' birthday-today ' : '';
579 foreach ($r as &$rr) {
580 if (!strlen($rr['name'])) {
586 if (in_array($rr['cid'], $cids)) {
589 $cids[] = $rr['cid'];
591 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
593 if ($rr['network'] === NETWORK_DFRN) {
594 $url = System::baseUrl() . '/redir/' . $rr['cid'];
598 $rr['title'] = $rr['name'];
599 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
600 $rr['startime'] = null;
601 $rr['today'] = $today;
605 $tpl = get_markup_template('birthdays_reminder.tpl');
606 return replace_macros($tpl, array(
607 '$baseurl' => System::baseUrl(),
608 '$classtoday' => $classtoday,
610 '$event_reminders' => t('Birthday Reminders'),
611 '$event_title' => t('Birthdays this week:'),
613 '$lbr' => '{', // raw brackets mess up if/endif macro processing
618 function get_events()
620 require_once 'include/bbcode.php';
624 if (!local_user() || $a->is_mobile || $a->is_tablet) {
629 * $mobile_detect = new Mobile_Detect();
630 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
635 $bd_format = t('g A l F d'); // 8 AM Friday January 18
639 "SELECT `event`.* FROM `event`
640 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
641 ORDER BY `start` ASC ",
643 datetime_convert('UTC', 'UTC', 'now + 7 days'),
644 datetime_convert('UTC', 'UTC', 'now - 1 days')
649 if (DBM::is_result($s)) {
652 while ($rr = dba::fetch($s)) {
653 if (strlen($rr['name'])) {
657 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
658 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
662 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
664 if (strlen($title) > 35) {
665 $title = substr($title, 0, 32) . '... ';
668 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
670 $description = t('[No description]');
673 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
675 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
679 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
681 $rr['title'] = $title;
682 $rr['description'] = $description;
683 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
684 $rr['startime'] = $strt;
685 $rr['today'] = $today;
690 $classtoday = (($istoday) ? 'event-today' : '');
692 $tpl = get_markup_template('events_reminder.tpl');
693 return replace_macros($tpl, array(
694 '$baseurl' => System::baseUrl(),
695 '$classtoday' => $classtoday,
696 '$count' => count($r),
697 '$event_reminders' => t('Event Reminders'),
698 '$event_title' => t('Events this week:'),
703 function advanced_profile(App $a)
706 $uid = $a->profile['uid'];
708 $o .= replace_macros(
709 get_markup_template('section_title.tpl'),
710 array('$title' => t('Profile'))
713 if ($a->profile['name']) {
714 $tpl = get_markup_template('profile_advanced.tpl');
718 $profile['fullname'] = array(t('Full Name:'), $a->profile['name']);
720 if ($a->profile['gender']) {
721 $profile['gender'] = array(t('Gender:'), $a->profile['gender']);
724 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
725 $year_bd_format = t('j F, Y');
726 $short_bd_format = t('j F');
728 $val = intval($a->profile['dob']) ?
729 day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
730 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format));
732 $profile['birthday'] = array(t('Birthday:'), $val);
735 if (!empty($a->profile['dob'])
736 && $a->profile['dob'] > '0001-01-01'
737 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
739 $profile['age'] = array(t('Age:'), $age);
742 if ($a->profile['marital']) {
743 $profile['marital'] = array(t('Status:'), $a->profile['marital']);
746 /// @TODO Maybe use x() here, plus below?
747 if ($a->profile['with']) {
748 $profile['marital']['with'] = $a->profile['with'];
751 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
752 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
755 if ($a->profile['sexual']) {
756 $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']);
759 if ($a->profile['homepage']) {
760 $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage']));
763 if ($a->profile['hometown']) {
764 $profile['hometown'] = array(t('Hometown:'), linkify($a->profile['hometown']));
767 if ($a->profile['pub_keywords']) {
768 $profile['pub_keywords'] = array(t('Tags:'), $a->profile['pub_keywords']);
771 if ($a->profile['politic']) {
772 $profile['politic'] = array(t('Political Views:'), $a->profile['politic']);
775 if ($a->profile['religion']) {
776 $profile['religion'] = array(t('Religion:'), $a->profile['religion']);
779 if ($txt = prepare_text($a->profile['about'])) {
780 $profile['about'] = array(t('About:'), $txt);
783 if ($txt = prepare_text($a->profile['interest'])) {
784 $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
787 if ($txt = prepare_text($a->profile['likes'])) {
788 $profile['likes'] = array(t('Likes:'), $txt);
791 if ($txt = prepare_text($a->profile['dislikes'])) {
792 $profile['dislikes'] = array(t('Dislikes:'), $txt);
795 if ($txt = prepare_text($a->profile['contact'])) {
796 $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
799 if ($txt = prepare_text($a->profile['music'])) {
800 $profile['music'] = array(t('Musical interests:'), $txt);
803 if ($txt = prepare_text($a->profile['book'])) {
804 $profile['book'] = array(t('Books, literature:'), $txt);
807 if ($txt = prepare_text($a->profile['tv'])) {
808 $profile['tv'] = array(t('Television:'), $txt);
811 if ($txt = prepare_text($a->profile['film'])) {
812 $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
815 if ($txt = prepare_text($a->profile['romance'])) {
816 $profile['romance'] = array(t('Love/Romance:'), $txt);
819 if ($txt = prepare_text($a->profile['work'])) {
820 $profile['work'] = array(t('Work/employment:'), $txt);
823 if ($txt = prepare_text($a->profile['education'])) {
824 $profile['education'] = array(t('School/education:'), $txt);
827 //show subcribed forum if it is enabled in the usersettings
828 if (Feature::isEnabled($uid, 'forumlist_profile')) {
829 $profile['forumlist'] = array(t('Forums:'), ForumManager::profileAdvanced($uid));
832 if ($a->profile['uid'] == local_user()) {
833 $profile['edit'] = array(System::baseUrl() . '/profiles/' . $a->profile['id'], t('Edit profile'), '', t('Edit profile'));
836 return replace_macros($tpl, array(
837 '$title' => t('Profile'),
838 '$basic' => t('Basic'),
839 '$advanced' => t('Advanced'),
840 '$profile' => $profile
847 function profile_tabs($a, $is_owner = false, $nickname = null)
849 if (is_null($nickname)) {
850 $nickname = $a->user['nickname'];
854 if (x($_GET, 'tab')) {
855 $tab = notags(trim($_GET['tab']));
858 $url = System::baseUrl() . '/profile/' . $nickname;
862 'label' => t('Status'),
864 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
865 'title' => t('Status Messages and Posts'),
866 'id' => 'status-tab',
870 'label' => t('Profile'),
871 'url' => $url . '/?tab=profile',
872 'sel' => $tab == 'profile' ? 'active' : '',
873 'title' => t('Profile Details'),
874 'id' => 'profile-tab',
878 'label' => t('Photos'),
879 'url' => System::baseUrl() . '/photos/' . $nickname,
880 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
881 'title' => t('Photo Albums'),
886 'label' => t('Videos'),
887 'url' => System::baseUrl() . '/videos/' . $nickname,
888 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
889 'title' => t('Videos'),
895 // the calendar link for the full featured events calendar
896 if ($is_owner && $a->theme_events_in_profile) {
898 'label' => t('Events'),
899 'url' => System::baseUrl() . '/events',
900 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
901 'title' => t('Events and Calendar'),
902 'id' => 'events-tab',
905 // if the user is not the owner of the calendar we only show a calendar
906 // with the public events of the calendar owner
907 } elseif (!$is_owner) {
909 'label' => t('Events'),
910 'url' => System::baseUrl() . '/cal/' . $nickname,
911 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
912 'title' => t('Events and Calendar'),
913 'id' => 'events-tab',
920 'label' => t('Personal Notes'),
921 'url' => System::baseUrl() . '/notes',
922 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
923 'title' => t('Only You Can See This'),
929 if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
931 'label' => t('Contacts'),
932 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
933 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
934 'title' => t('Contacts'),
935 'id' => 'viewcontacts-tab',
940 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs);
941 call_hooks('profile_tabs', $arr);
943 $tpl = get_markup_template('common_tabs.tpl');
945 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
949 * Retrieves the my_url session variable
953 function get_my_url()
955 if (x($_SESSION, 'my_url')) {
956 return $_SESSION['my_url'];
961 function zrl_init(App $a)
963 $my_url = get_my_url();
964 $my_url = validate_url($my_url);
966 // Is it a DDoS attempt?
967 // The check fetches the cached value from gprobe to reduce the load for this system
968 $urlparts = parse_url($my_url);
970 $result = Cache::get('gprobe:' . $urlparts['host']);
971 if ((!is_null($result)) && (in_array($result['network'], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
972 logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
976 Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
977 $arr = array('zrl' => $my_url, 'url' => $a->cmd);
978 call_hooks('zrl_init', $arr);
982 function zrl($s, $force = false)
987 if ((!strpos($s, '/profile/')) && (!$force)) {
990 if ($force && substr($s, -1, 1) !== '/') {
993 $achar = strpos($s, '?') ? '&' : '?';
994 $mine = get_my_url();
995 if ($mine && !link_compare($mine, $s)) {
996 return $s . $achar . 'zrl=' . urlencode($mine);
1002 * @brief Get the user ID of the page owner
1004 * Used from within PCSS themes to set theme parameters. If there's a
1005 * puid request variable, that is the "page owner" and normally their theme
1006 * settings take precedence; unless a local user sets the "always_my_theme"
1007 * system pconfig, which means they don't want to see anybody else's theme
1008 * settings except their own while on this site.
1010 * @return int user ID
1012 * @note Returns local_user instead of user ID if "always_my_theme"
1015 function get_theme_uid()
1017 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
1018 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
1019 return local_user();