]> source.dussan.org Git - nextcloud-server.git/commitdiff
Load avatar in header via PHP
authorkondou <kondou@ts.unde.re>
Sat, 15 Mar 2014 14:27:48 +0000 (15:27 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 23 Oct 2014 21:17:18 +0000 (23:17 +0200)
* fix #7484
* use UID, css, and div instead of span

core/css/header.css
core/js/avatar.js
core/templates/layout.user.php
lib/private/helper.php
lib/private/templatelayout.php

index f83ef451ce60a52b5411c4003c4656c4284f4661..33eb7e25cc60d444a1705b01822c275b7f454a35 100644 (file)
        display: inline-block;
        margin-right: 5px;
        cursor: pointer;
+       height: 32px;
+       width: 32px;
 }
 #header .avatardiv img {
        opacity: 1;
index 6835f6ef0acac6ef799ffe50ac1c9fbe1c845577..8ff136d67ca9d4624492703857932e3053344281 100644 (file)
@@ -1,15 +1,5 @@
 $(document).ready(function(){
        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
                $('#avatar .avatardiv').avatar(OC.currentUser, 128);
        }
index 9445175efcfda6f9a6f3425cbd5dbb67f8de4e44..09630435b77c226b4ff55cd7be92ee7fc6661702 100644 (file)
                        </a>
                        <div id="logo-claim" style="display:none;"><?php p($theme->getLogoClaim()); ?></div>
                        <div id="settings" class="svg">
-                               <span id="expand" tabindex="0" role="link">
+                               <div id="expand" tabindex="0" role="link">
                                        <?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; ?>
                                        <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')); ?>" />
-                               </span>
+                               </div>
                                <div id="expanddiv">
                                <ul>
                                <?php foreach($_['settingsnavigation'] as $entry):?>
index 823e82ceeb1aef586fb3b44bec40d44f5d6269b7..628af14fa08efaee148d188fb402ce10d253c700 100644 (file)
@@ -279,6 +279,21 @@ class OC_Helper {
                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
         * @param int $bytes file size in bytes
index f5f079c8b2a3950ef3825fe70fd11a7a026cfe94..cbaadd5768fb8fc0d2da2217c74460f2bf4749b0 100644 (file)
@@ -76,6 +76,7 @@ class OC_TemplateLayout extends OC_Template {
                        $this->assign( 'user_uid', OC_User::getUser() );
                        $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('userAvatarSet', \OC_Helper::userAvatarSet(OC_User::getUser()));
                } else if ($renderAs == 'error') {
                        parent::__construct('core', 'layout.guest', '', false);
                        $this->assign('bodyid', 'body-login');
@@ -89,7 +90,7 @@ class OC_TemplateLayout extends OC_Template {
                if(empty(self::$versionHash)) {
                        self::$versionHash = md5(implode(',', OC_App::getAppVersions()));
                }
-               
+
                $useAssetPipeline = self::isAssetPipelineEnabled();
                if ($useAssetPipeline) {
                        $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash)));