diff --git a/include/identity.php b/include/identity.php index 1cd2e6f73..2230d98a4 100644 --- a/include/identity.php +++ b/include/identity.php @@ -45,39 +45,9 @@ if(! function_exists('profile_load')) { 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; - } - } - } + $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile); - $r = null; - - if($profile) { - $profile_int = intval($profile); - $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `contact`.`addr` AS faddr, `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, `contact`.`addr` AS faddr, `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)) { + if(($pdata === false) || (!count($pdata)) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -86,16 +56,16 @@ if(! function_exists('profile_load')) { // fetch user tags if this isn't the default profile - if(!$r[0]['is-default']) { + if(!$pdata['is-default']) { $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", - intval($r[0]['profile_uid']) + intval($pdata['profile_uid']) ); if($x && count($x)) - $r[0]['pub_keywords'] = $x[0]['pub_keywords']; + $pdata['pub_keywords'] = $x[0]['pub_keywords']; } - $a->profile = $r[0]; - $a->profile_uid = $r[0]['profile_uid']; + $a->profile = $pdata; + $a->profile_uid = $pdata['profile_uid']; $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme'); $a->profile['network'] = NETWORK_DFRN; @@ -147,6 +117,58 @@ if(! function_exists('profile_load')) { } +/** + * @brief Get all profil data of a local user + * If the viewer is an authenticated remote viewer, the profile displayed is the + * one that has been configured for his/her viewing in the Contact manager. + * Passing a non-zero profile ID can also allow a preview of a selected profile + * by the owner + * + * @param string $nickname + * @param int $uid + * @param int $profile + * ID of the profile + * @returns array + * Includes all available profile data + */ +function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) { + if(remote_user() && count($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $visitor) { + if($visitor['uid'] == $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, `contact`.`addr`, `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, `contact`.`addr`, `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) + ); + } + + return $r[0]; + +} + + /** * * Function: profile_sidebar @@ -161,8 +183,6 @@ if(! function_exists('profile_load')) { * Exceptions: Returns empty string if passed $profile is wrong type or not populated * */ - - if(! function_exists('profile_sidebar')) { function profile_sidebar($profile, $block = 0) { $a = get_app(); @@ -170,7 +190,7 @@ if(! function_exists('profile_sidebar')) { $o = ''; $location = false; $address = false; - $pdesc = true; +// $pdesc = true; if((! is_array($profile)) && (! count($profile))) return $o; @@ -178,12 +198,8 @@ if(! function_exists('profile_sidebar')) { $profile['picdate'] = urlencode($profile['picdate']); if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) { - require_once('include/contact_selectors.php'); - if ($profile['url'] != "") - $profile['network_name'] = ''.network_to_name($profile['network'], $profile['url']).""; - else - $profile['network_name'] = network_to_name($profile['network']); - } else + $profile['network_name'] = format_network_name($profile['network'],$profile['url']); + } else $profile['network_name'] = ""; call_hooks('profile_sidebar_enter', $profile); @@ -270,6 +286,16 @@ if(! function_exists('profile_sidebar')) { ); } + // check if profile is a forum + if((x($profile['page-flags']) == 2) + || (x($profile['page-flags']) == 5) + || (x($profile['forum'])) + || (x($profile['prv'])) + || (x($profile['community']))) + $account_type = t('Forum'); + else + $account_type = ""; + if((x($profile,'address') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) @@ -344,9 +370,10 @@ if(! function_exists('profile_sidebar')) { '$remoteconnect' => $remoteconnect, '$subscribe_feed' => $subscribe_feed, '$wallmessage' => $wallmessage, + '$account_type' => $account_type, '$location' => $location, '$gender' => $gender, - '$pdesc' => $pdesc, +// '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, '$about' => $about, diff --git a/include/text.php b/include/text.php index 253489180..1b03c39d2 100644 --- a/include/text.php +++ b/include/text.php @@ -2289,32 +2289,23 @@ function formatBytes($bytes, $precision = 2) { } /** - * @brief Translate the PAGE type flags in human readable string + * @brief translate and format the networkname of a contact * - * @param int $page_type - * @return string $trans_type + * @param string $network + * Networkname of the contact (e.g. dfrn, rss and so on) + * @param sting $url + * The contact url + * @return string */ -function page_type_translate($page_type) { +function format_network_name($network, $url = 0) { + if ($network != "") { + require_once('include/contact_selectors.php'); + if ($url != "") + $network_name = ''.network_to_name($network, $url).""; + else + $network_name = network_to_name($network); - // ToDo: we need a good interpretable translation for PAGE_SOAPBOX - // and PAGE_PRVGROUP - switch ($page_type) { - case PAGE_NORMAL: - $trans_type = t('Normal Account'); - break; - case PAGE_SOAPBOX: - $trans_type = t('Fan Page'); - break; - case PAGE_COMMUNITY: - $trans_type = t('Community Forum'); - break; - case PAGE_FREELOVE: - $trans_type = t('Open Forum'); - break; - case PAGE_PRVGROUP: - $trans_type = t('Private Forum'); - break; + return $network_name; } - return $trans_type; } diff --git a/mod/contacts.php b/mod/contacts.php index 992f8ed6b..f1829a183 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -35,10 +35,20 @@ function contacts_init(&$a) { if($contact_id) { $a->data['contact'] = $r[0]; + + if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) { + $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']); + } else + $networkname = ''; + $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array( '$name' => htmlentities($a->data['contact']['name']), '$photo' => $a->data['contact']['photo'], - '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? z_root()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url'] + '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? z_root()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url'], + '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), + '$network_name' => $networkname, + '$network' => t('Network:'), + 'account_type' => (($a->data['contact']['forum'] || $a->data['contact']['prv']) ? t('Forum') : '') )); $finpeople_widget = ''; $follow_widget = ''; @@ -570,16 +580,8 @@ function contacts_content(&$a) { $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]); - $header = $contact["name"]; - - if ($contact["addr"] != "") - $header .= " <".$contact["addr"].">"; - - $header .= " (".network_to_name($contact['network'], $contact['url']).")"; - $o .= replace_macros($tpl, array( //'$header' => t('Contact Editor'), - '$header' => htmlentities($header), '$tab_str' => $tab_str, '$submit' => t('Submit'), '$lbl_vis1' => t('Profile Visibility'), @@ -905,18 +907,6 @@ function contact_posts($a, $contact_id) { $tab_str = contact_tabs($a, $contact_id, 1); - $header = $contact["name"]; - - if ($contact["addr"] != "") - $header .= " <".$contact["addr"].">"; - - $header .= " (".network_to_name($contact['network'], $contact['url']).")"; - - $tpl = get_markup_template("section_title.tpl"); - $o = replace_macros($tpl,array( - '$title' => htmlentities($header) - )); - $o .= $tab_str; $o .= conversation($a,$r,'community',false); diff --git a/mod/crepair.php b/mod/crepair.php index d16adf8c7..98202ae0b 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -24,11 +24,22 @@ function crepair_init(&$a) { if($contact_id) { $a->data['contact'] = $r[0]; - $tpl = get_markup_template("vcard-widget.tpl"); - $vcard_widget .= replace_macros($tpl, array( - '$name' => htmlentities($a->data['contact']['name']), - '$photo' => $a->data['contact']['photo'] - )); + + if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) { + $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']); + } else + $networkname = ''; + + $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array( + '$name' => htmlentities($a->data['contact']['name']), + '$photo' => $a->data['contact']['photo'], + '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? z_root()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url'], + '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), + '$network_name' => $networkname, + '$network' => t('Network:'), + 'account_type' => (($a->data['contact']['forum'] || $a->data['contact']['prv']) ? t('Forum') : '') + )); + $a->page['aside'] .= $vcard_widget; } @@ -161,17 +172,10 @@ function crepair_content(&$a) { $tab_str = contact_tabs($a, $contact['id'], 3); - $header = $contact["name"]; - - if ($contact["addr"] != "") - $header .= " <".$contact["addr"].">"; - - $header .= " (".network_to_name($contact['network'], $contact['url']).")"; $tpl = get_markup_template('crepair.tpl'); $o .= replace_macros($tpl, array( //'$title' => t('Repair Contact Settings'), - '$title' => htmlentities($header), '$tab_str' => $tab_str, '$warning' => $warning, '$info' => $info, diff --git a/mod/directory.php b/mod/directory.php index bedc71907..cb233db89 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -86,7 +86,7 @@ function directory_content(&$a) { $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']); $r = $db->q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, - `contact`.`addr` AS faddr, `contact`.`url` AS profile_url FROM `profile` + `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit); @@ -102,7 +102,7 @@ function directory_content(&$a) { $community = ''; $itemurl= ''; - $itemurl = (($rr['faddr'] != "") ? $rr['faddr'] : $rr['profile_url']); + $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']); $profile_link = z_root() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); diff --git a/mod/photos.php b/mod/photos.php index 5ca973d16..6b97d7d4f 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -24,24 +24,32 @@ function photos_init(&$a) { if($a->argc > 1) { $nick = $a->argv[1]; - $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", + $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if(! count($r)) + if(! count($user)) return; - $a->data['user'] = $r[0]; - $a->profile_uid = $r[0]['uid']; + $a->data['user'] = $user[0]; + $a->profile_uid = $user[0]['uid']; $is_owner = (local_user() && (local_user() == $a->profile_uid)); - $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg'); + $profile = get_profiledata_by_nick($nick, $a->profile_uid); + + if((x($profile['page-flags']) == 2) || (x($profile['page-flags']) == 5)) + $account_type = t('Forum'); + else + $account_type = ""; $tpl = get_markup_template("vcard-widget.tpl"); $vcard_widget .= replace_macros($tpl, array( - '$name' => $a->data['user']['username'], - '$photo' => $profilephoto + '$name' => $profile['name'], + '$photo' => $profile['photo'], + '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""), + '$account_type' => $account_type, + '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""), )); @@ -89,7 +97,7 @@ function photos_init(&$a) { $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array( '$nick' => $a->data['user']['nickname'], '$title' => t('Photo Albums'), - 'recent' => t('Recent Photos'), + '$recent' => t('Recent Photos'), '$albums' => $albums['albums'], '$baseurl' => z_root(), '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'), diff --git a/mod/videos.php b/mod/videos.php index 04c40b236..7ea09d6a9 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -21,23 +21,31 @@ function videos_init(&$a) { if($a->argc > 1) { $nick = $a->argv[1]; - $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", + $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if(! count($r)) + if(! count($user)) return; - $a->data['user'] = $r[0]; - $a->profile_uid = $r[0]['uid']; + $a->data['user'] = $user[0]; + $a->profile_uid = $user[0]['uid']; - $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg'); + $profile = get_profiledata_by_nick($nick, $a->profile_uid); + + if((x($profile['page-flags']) == 2) || (x($profile['page-flags']) == 5)) + $account_type = t('Forum'); + else + $account_type = ""; $tpl = get_markup_template("vcard-widget.tpl"); - $vcard_widget = replace_macros($tpl, array( - '$name' => $a->data['user']['username'], - '$photo' => $profilephoto + $vcard_widget .= replace_macros($tpl, array( + '$name' => $profile['name'], + '$photo' => $profile['photo'], + '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""), + '$account_type' => $account_type, + '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""), )); diff --git a/view/templates/profile_vcard.tpl b/view/templates/profile_vcard.tpl index fa209bf46..0a3a13f9d 100644 --- a/view/templates/profile_vcard.tpl +++ b/view/templates/profile_vcard.tpl @@ -3,15 +3,16 @@