-if(! function_exists('profile_load')) {
- function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
-
- $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
- dbesc($nickname)
- );
-
- if(!$user && count($user) && !count($profiledata)) {
- logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
- notice( t('Requested account is not available.') . EOL );
- $a->error = 404;
- return;
- }
-
- if(remote_user() && count($_SESSION['remote'])) {
- foreach($_SESSION['remote'] as $visitor) {
- if($visitor['uid'] == $user[0]['uid']) {
- $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
- intval($visitor['cid'])
- );
- if(count($r))
- $profile = $r[0]['profile-id'];
- break;
- }
- }
- }
-
- $r = null;
-
- if($profile) {
- $profile_int = intval($profile);
- $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
- INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
- WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d and `contact`.`self` = 1 LIMIT 1",
- dbesc($nickname),
- intval($profile_int)
- );
- }
- if((!$r) && (!count($r))) {
- $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
- INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
- WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
- dbesc($nickname)
- );
- }
-
- if(($r === false) || (!count($r)) && !count($profiledata)) {
- logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
- notice( t('Requested profile is not available.') . EOL );
- $a->error = 404;
- return;
- }
-
- // fetch user tags if this isn't the default profile
-
- if(!$r[0]['is-default']) {
- $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1",
- intval($r[0]['profile_uid'])
- );
- if($x && count($x))
- $r[0]['pub_keywords'] = $x[0]['pub_keywords'];
- }
-
- $a->profile = $r[0];
-
- $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
- $a->profile['network'] = NETWORK_DFRN;
-
- $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
-
- if (!$profiledata)
- $_SESSION['theme'] = $a->profile['theme'];
-
- $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
-
- /**
- * load/reload current theme info
- */
-
- $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
-
- $theme_info_file = "view/theme/".current_theme()."/theme.php";
- if (file_exists($theme_info_file)){
- require_once($theme_info_file);
- }
-
- if(! (x($a->page,'aside')))
- $a->page['aside'] = '';
-
- if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
- $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
- '$editprofile' => t('Edit profile'),
- '$profid' => $a->profile['id']
- ));
- }
-
- $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
-
- // To-Do:
- // By now, the contact block isn't shown, when a different profile is given
- // But: When this profile was on the same server, then we could display the contacts
- if ($profiledata)
- $a->page['aside'] .= profile_sidebar($profiledata, true);
- else
- $a->page['aside'] .= profile_sidebar($a->profile, $block);
-
-
- /*if(! $block)
- $a->page['aside'] .= contact_block();*/
-