Load avatar in header via PHP

* fix #7484
* use UID, css, and div instead of span
This commit is contained in:
kondou 2014-03-15 15:27:48 +01:00 committed by Morris Jobke
parent e26a16afea
commit 729dffed5e
5 changed files with 26 additions and 14 deletions

View file

@ -239,6 +239,8 @@
display: inline-block; display: inline-block;
margin-right: 5px; margin-right: 5px;
cursor: pointer; cursor: pointer;
height: 32px;
width: 32px;
} }
#header .avatardiv img { #header .avatardiv img {
opacity: 1; opacity: 1;

View file

@ -1,15 +1,5 @@
$(document).ready(function(){ $(document).ready(function(){
if (OC.currentUser) { if (OC.currentUser) {
var callback = function() {
// do not show display name on mobile when profile picture is present
if($('#header .avatardiv').children().length > 0) {
$('#header .avatardiv').addClass('avatardiv-shown');
}
};
$('#header .avatardiv').avatar(
OC.currentUser, 32, undefined, true, callback
);
// Personal settings // Personal settings
$('#avatar .avatardiv').avatar(OC.currentUser, 128); $('#avatar .avatardiv').avatar(OC.currentUser, 128);
} }

View file

@ -65,13 +65,17 @@
</a> </a>
<div id="logo-claim" style="display:none;"><?php p($theme->getLogoClaim()); ?></div> <div id="logo-claim" style="display:none;"><?php p($theme->getLogoClaim()); ?></div>
<div id="settings" class="svg"> <div id="settings" class="svg">
<span id="expand" tabindex="0" role="link"> <div id="expand" tabindex="0" role="link">
<?php if ($_['enableAvatars']): ?> <?php if ($_['enableAvatars']): ?>
<div class="avatardiv"></div> <div class="avatardiv"<?php if (!$_['userAvatarSet']) { print_unescaped(' style="display: none"'); } ?>>
<?php if ($_['userAvatarSet']): ?>
<img src="<?php p(link_to('', 'index.php').'/avatar/'.$_['user_uid'].'/32?requesttoken='.$_['requesttoken']); ?>">
<?php endif; ?>
</div>
<?php endif; ?> <?php endif; ?>
<span id="expandDisplayName"><?php p(trim($_['user_displayname']) != '' ? $_['user_displayname'] : $_['user_uid']) ?></span> <span id="expandDisplayName"><?php p(trim($_['user_displayname']) != '' ? $_['user_displayname'] : $_['user_uid']) ?></span>
<img class="svg" alt="" src="<?php print_unescaped(image_path('', 'actions/caret.svg')); ?>" /> <img class="svg" alt="" src="<?php print_unescaped(image_path('', 'actions/caret.svg')); ?>" />
</span> </div>
<div id="expanddiv"> <div id="expanddiv">
<ul> <ul>
<?php foreach($_['settingsnavigation'] as $entry):?> <?php foreach($_['settingsnavigation'] as $entry):?>

View file

@ -279,6 +279,21 @@ class OC_Helper {
return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => $path, 't' => $token)); return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => $path, 't' => $token));
} }
/**
* shows whether the user has an avatar
* @param string $user username
* @return bool avatar set or not
**/
public static function userAvatarSet($user) {
$avatar = new \OC_Avatar($user);
$image = $avatar->get(1);
if ($image instanceof \OC_Image) {
return true;
} else {
return false;
}
}
/** /**
* Make a human file size * Make a human file size
* @param int $bytes file size in bytes * @param int $bytes file size in bytes

View file

@ -76,6 +76,7 @@ class OC_TemplateLayout extends OC_Template {
$this->assign( 'user_uid', OC_User::getUser() ); $this->assign( 'user_uid', OC_User::getUser() );
$this->assign( 'appsmanagement_active', strpos(OC_Request::requestUri(), OC_Helper::linkToRoute('settings_apps')) === 0 ); $this->assign( 'appsmanagement_active', strpos(OC_Request::requestUri(), OC_Helper::linkToRoute('settings_apps')) === 0 );
$this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true)); $this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true));
$this->assign('userAvatarSet', \OC_Helper::userAvatarSet(OC_User::getUser()));
} else if ($renderAs == 'error') { } else if ($renderAs == 'error') {
parent::__construct('core', 'layout.guest', '', false); parent::__construct('core', 'layout.guest', '', false);
$this->assign('bodyid', 'body-login'); $this->assign('bodyid', 'body-login');
@ -89,7 +90,7 @@ class OC_TemplateLayout extends OC_Template {
if(empty(self::$versionHash)) { if(empty(self::$versionHash)) {
self::$versionHash = md5(implode(',', OC_App::getAppVersions())); self::$versionHash = md5(implode(',', OC_App::getAppVersions()));
} }
$useAssetPipeline = self::isAssetPipelineEnabled(); $useAssetPipeline = self::isAssetPipelineEnabled();
if ($useAssetPipeline) { if ($useAssetPipeline) {
$this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash))); $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash)));