0dfa57948f
Replace deprecated functions with new syntax.
940 lines
27 KiB
PHP
940 lines
27 KiB
PHP
<?php
|
|
/**
|
|
* @file include/identity.php
|
|
*/
|
|
|
|
use Friendica\App;
|
|
use Friendica\Core\Config;
|
|
use Friendica\Core\PConfig;
|
|
use Friendica\Core\System;
|
|
use Friendica\Core\Worker;
|
|
|
|
require_once 'include/ForumManager.php';
|
|
require_once 'include/bbcode.php';
|
|
require_once 'mod/proxy.php';
|
|
require_once 'include/cache.php';
|
|
|
|
/**
|
|
*
|
|
* @brief Loads a profile into the page sidebar.
|
|
*
|
|
* The function requires a writeable copy of the main App structure, and the nickname
|
|
* of a registered local account.
|
|
*
|
|
* 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.
|
|
*
|
|
* Profile information is placed in the App structure for later retrieval.
|
|
* Honours the owner's chosen theme for display.
|
|
*
|
|
* @attention Should only be run in the _init() functions of a module. That ensures that
|
|
* the theme is chosen before the _init() function of a theme is run, which will usually
|
|
* load a lot of theme-specific content
|
|
*
|
|
* @param App $a
|
|
* @param string $nickname
|
|
* @param int $profile
|
|
* @param array $profiledata
|
|
*/
|
|
function profile_load(App $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;
|
|
}
|
|
|
|
$pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
|
|
|
|
if (empty($pdata) && empty($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 (!$pdata['is-default']) {
|
|
$x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
|
|
intval($pdata['profile_uid'])
|
|
);
|
|
if ($x && count($x))
|
|
$pdata['pub_keywords'] = $x[0]['pub_keywords'];
|
|
}
|
|
|
|
$a->profile = $pdata;
|
|
$a->profile_uid = $pdata['profile_uid'];
|
|
|
|
$a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
|
|
$a->profile['network'] = NETWORK_DFRN;
|
|
|
|
$a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
|
|
|
|
if (!$profiledata && !PConfig::get(local_user(),'system','always_my_theme'))
|
|
$_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 = (((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
|
|
|
|
/**
|
|
* @todo
|
|
* 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();*/
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
/**
|
|
* @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 = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
|
|
if (dbm::is_result($r)) {
|
|
$profile = $r['profile-id'];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$r = null;
|
|
|
|
if ($profile) {
|
|
$profile_int = intval($profile);
|
|
$r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
|
|
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
|
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
|
`contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
|
|
FROM `profile`
|
|
INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
|
|
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
|
WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
|
|
$nickname,
|
|
$profile_int
|
|
);
|
|
}
|
|
if (!dbm::is_result($r)) {
|
|
$r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
|
|
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
|
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
|
`contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
|
|
FROM `profile`
|
|
INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
|
|
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
|
WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
|
|
$nickname
|
|
);
|
|
}
|
|
|
|
return $r;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Formats a profile for display in the sidebar.
|
|
*
|
|
* It is very difficult to templatise the HTML completely
|
|
* because of all the conditional logic.
|
|
*
|
|
* @param array $profile
|
|
* @param int $block
|
|
*
|
|
* @return HTML string stuitable for sidebar inclusion
|
|
*
|
|
* @note Returns empty string if passed $profile is wrong type or not populated
|
|
*
|
|
* @hooks 'profile_sidebar_enter'
|
|
* array $profile - profile data
|
|
* @hooks 'profile_sidebar'
|
|
* array $arr
|
|
*/
|
|
function profile_sidebar($profile, $block = 0) {
|
|
$a = get_app();
|
|
|
|
$o = '';
|
|
$location = false;
|
|
$address = false;
|
|
// $pdesc = true;
|
|
|
|
// This function can also use contact information in $profile
|
|
$is_contact = x($profile, 'cid');
|
|
|
|
if ((! is_array($profile)) && (! count($profile))) {
|
|
return $o;
|
|
}
|
|
|
|
$profile['picdate'] = urlencode($profile['picdate']);
|
|
|
|
if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
|
|
$profile['network_name'] = format_network_name($profile['network'], $profile['url']);
|
|
} else {
|
|
$profile['network_name'] = "";
|
|
}
|
|
|
|
call_hooks('profile_sidebar_enter', $profile);
|
|
|
|
|
|
// don't show connect link to yourself
|
|
$connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
|
|
|
|
// don't show connect link to authenticated visitors either
|
|
if (remote_user() && count($_SESSION['remote'])) {
|
|
foreach ($_SESSION['remote'] as $visitor) {
|
|
if ($visitor['uid'] == $profile['uid']) {
|
|
$connect = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Is the local user already connected to that user?
|
|
if ($connect && local_user()) {
|
|
if (isset($profile["url"])) {
|
|
$profile_url = normalise_link($profile["url"]);
|
|
} else {
|
|
$profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
|
|
}
|
|
|
|
if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
|
|
$connect = false;
|
|
}
|
|
}
|
|
|
|
if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
|
|
$connect = false;
|
|
|
|
$remoteconnect = NULL;
|
|
if (isset($profile['remoteconnect']))
|
|
$remoteconnect = $profile['remoteconnect'];
|
|
|
|
if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
|
|
$subscribe_feed = t("Atom feed");
|
|
else
|
|
$subscribe_feed = false;
|
|
|
|
if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
|
|
$wallmessage = t('Message');
|
|
$wallmessage_link = "wallmessage/".$profile["nickname"];
|
|
|
|
if (remote_user()) {
|
|
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
|
|
intval($profile['uid']),
|
|
intval(remote_user()),
|
|
intval(CONTACT_IS_FRIEND));
|
|
} else {
|
|
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
|
|
intval($profile['uid']),
|
|
dbesc(normalise_link(get_my_url())),
|
|
intval(CONTACT_IS_FRIEND));
|
|
}
|
|
if ($r) {
|
|
$remote_url = $r[0]["url"];
|
|
$message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
|
|
$wallmessage_link = $message_path.base64_encode($profile["addr"]);
|
|
}
|
|
} else {
|
|
$wallmessage = false;
|
|
$wallmessage_link = false;
|
|
}
|
|
|
|
// show edit profile to yourself
|
|
if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
|
|
$profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
|
|
$r = q("SELECT * FROM `profile` WHERE `uid` = %d",
|
|
local_user());
|
|
|
|
$profile['menu'] = array(
|
|
'chg_photo' => t('Change profile photo'),
|
|
'cr_new' => t('Create New Profile'),
|
|
'entries' => array(),
|
|
);
|
|
|
|
if (dbm::is_result($r)) {
|
|
|
|
foreach ($r as $rr) {
|
|
$profile['menu']['entries'][] = array(
|
|
'photo' => $rr['thumb'],
|
|
'id' => $rr['id'],
|
|
'alt' => t('Profile Image'),
|
|
'profile_name' => $rr['profile-name'],
|
|
'isdefault' => $rr['is-default'],
|
|
'visibile_to_everybody' => t('visible to everybody'),
|
|
'edit_visibility' => t('Edit visibility'),
|
|
|
|
);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
|
|
$profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
|
|
$profile['menu'] = array(
|
|
'chg_photo' => t('Change profile photo'),
|
|
'cr_new' => null,
|
|
'entries' => array(),
|
|
);
|
|