Several improvements

- Don't use gravatars default avatars
- Use "profile image" instead of "avatar"
- Use <p> instead of tables
- Ease updateAvatar()
- Actually return something in \OCP\Avatar
This commit is contained in:
kondou 2013-08-17 11:01:47 +02:00
parent d7e6c77e20
commit 9c12da6a94
7 changed files with 49 additions and 48 deletions

View File

@ -1,5 +1,9 @@
<?php <?php
/**
* * @todo work on hashing userstrings, so one can't guess usernames
*/
require_once 'lib/base.php'; require_once 'lib/base.php';
$mode = \OC_Avatar::getMode(); $mode = \OC_Avatar::getMode();

View File

@ -86,17 +86,20 @@ class OC_Avatar {
* @param $user string which user to get the gravatar for * @param $user string which user to get the gravatar for
* @param size integer size in px of the avatar, defaults to 64 * @param size integer size in px of the avatar, defaults to 64
* @return string link to the gravatar, or \OC_Image with the default avatar * @return string link to the gravatar, or \OC_Image with the default avatar
* @todo work on hashing userstrings, so one can't guess usernames
*/ */
public static function getGravatar ($user, $size = 64) { public static function getGravatar ($user, $size = 64) {
$email = \OC_Preferences::getValue($user, 'settings', 'email'); $email = \OC_Preferences::getValue($user, 'settings', 'email');
if ($email !== null) { if ($email !== null) {
$emailhash = md5(strtolower(trim($email))); $emailhash = md5(strtolower(trim($email)));
$url = "http://www.gravatar.com/avatar/".$emailhash."?s=".$size; $url = "http://secure.gravatar.com/avatar/".$emailhash."?d=404&s=".$size;
$headers = get_headers($url, 1);
if (strpos($headers[0], "404 Not Found") === false) {
return $url; return $url;
} else {
return self::getDefaultAvatar($size);
} }
} }
return self::getDefaultAvatar($size);
}
/** /**
* @brief get the local avatar * @brief get the local avatar
@ -121,7 +124,7 @@ class OC_Avatar {
} }
/** /**
* * @todo todo
*/ */
public static function getCustomAvatar($user, $size) { public static function getCustomAvatar($user, $size) {
// TODO // TODO
@ -129,8 +132,10 @@ class OC_Avatar {
/** /**
* @brief gets the default avatar * @brief gets the default avatar
* @todo when custom default images arive @param $user string which user to get the avatar for
* @param $size integer size of the avatar in px, defaults to 64 * @param $size integer size of the avatar in px, defaults to 64
* @return \OC_Image containing the default avatar * @return \OC_Image containing the default avatar
* @todo use custom default images, when they arive
*/ */
public static function getDefaultAvatar ($size = 64) { public static function getDefaultAvatar ($size = 64) {
$default = new OC_Image(OC::$SERVERROOT."/core/img/defaultavatar.png"); $default = new OC_Image(OC::$SERVERROOT."/core/img/defaultavatar.png");

View File

@ -10,10 +10,10 @@ namespace OCP;
class Avatar { class Avatar {
public static function get ($user, $size = 64) { public static function get ($user, $size = 64) {
\OC_Avatar::get($user, $size); return \OC_Avatar::get($user, $size);
} }
public static function getMode () { public static function getMode () {
\OC_Avatar::getMode(); return \OC_Avatar::getMode();
} }
} }

View File

@ -55,7 +55,7 @@ function selectAvatar (path) {
} }
function updateAvatar () { function updateAvatar () {
$('#avatar img').attr('src', OC.filePath('', '', 'avatar.php?user='+OC.currentUser+'&size=128')); $('#avatar img').attr('src', $('#avatar img').attr('src') + '#');
} }
$(document).ready(function(){ $(document).ready(function(){

View File

@ -117,38 +117,30 @@ if (!$_['internetconnectionworking']) {
</fieldset> </fieldset>
<fieldset class="personalblock" id="avatar"> <fieldset class="personalblock" id="avatar">
<legend><strong><?php p($l->t('Avatars')); ?></strong></legend> <legend><strong><?php p($l->t('Profile images')); ?></strong></legend>
<table class="nostyle"> <p>
<tr>
<td>
<input type="radio" name="avatarmode" value="gravatar" id="avatar_gravatar" <input type="radio" name="avatarmode" value="gravatar" id="avatar_gravatar"
<?php if ($_['avatar'] === "gravatar") { p('checked'); } ?> <?php if ($_['avatar'] === "gravatar") { p('checked'); } ?>
<?php if (!$_['internetconnectionworking']) { p('disabled'); } ?>> <?php if (!$_['internetconnectionworking']) { p('disabled'); } ?>>
<label for="avatar_gravatar">Gravatar</label><br> <label for="avatar_gravatar">Gravatar</label><br>
<em><?php print_unescaped($l->t('Use <a href="http://gravatar.com/">gravatar</a> for avatars')); ?></em><br> <em><?php print_unescaped($l->t('Use <a href="http://gravatar.com/">gravatar</a> for profile images')); ?></em><br>
<em><?php p($l->t('This sends data to gravatar')); ?></em> <em><?php p($l->t('This sends data to gravatar and may slow down loading')); ?></em>
<?php if (!$_['internetconnectionworking']): ?> <?php if (!$_['internetconnectionworking']): ?>
<br><em><?php p($l->t('Gravatar needs an internet connection!')); ?></em> <br><em><?php p($l->t('Gravatar needs an internet connection!')); ?></em>
<?php endif; ?> <?php endif; ?>
</td> </p>
</tr> <p>
<tr>
<td>
<input type="radio" name="avatarmode" value="local" id="avatar_local" <input type="radio" name="avatarmode" value="local" id="avatar_local"
<?php if ($_['avatar'] === "local") { p('checked'); } ?>> <?php if ($_['avatar'] === "local") { p('checked'); } ?>>
<label for="avatar_local"><?php p($l->t('Local avatars')); ?></label><br> <label for="avatar_local"><?php p($l->t('Local avatars')); ?></label><br>
<em><?php p($l->t('Use local avatars, which each user has to upload themselves')); ?></em> <em><?php p($l->t('Use local avatars, which each user has to upload themselves')); ?></em>
</td> </p>
</tr> <p>
<tr>
<td>
<input type="radio" name="avatarmode" value="none" id="avatar_none" <input type="radio" name="avatarmode" value="none" id="avatar_none"
<?php if ($_['avatar'] === "none") { p('checked'); } ?>> <?php if ($_['avatar'] === "none") { p('checked'); } ?>>
<label for="avatar_none"><?php p($l->t('No avatars')); ?></label><br> <label for="avatar_none"><?php p($l->t('No avatars')); ?></label><br>
<em><?php p($l->t('Do not provide avatars')); ?></em> <em><?php p($l->t('Do not provide avatars')); ?></em>
</td> </p>
</tr>
</table>
</fieldset> </fieldset>
<fieldset class="personalblock" id="shareAPI"> <fieldset class="personalblock" id="shareAPI">

View File

@ -86,18 +86,18 @@ if($_['passwordChangeSupported']) {
<?php if ($_['avatar'] !== "none"): ?> <?php if ($_['avatar'] !== "none"): ?>
<form id="avatar" method="post" action="<?php p(\OC_Helper::linkToRoute('settings_ajax_newavatar')); ?>"> <form id="avatar" method="post" action="<?php p(\OC_Helper::linkToRoute('settings_ajax_newavatar')); ?>">
<fieldset class="personalblock"> <fieldset class="personalblock">
<legend><strong><?php p($l->t('Avatar')); ?></strong></legend> <legend><strong><?php p($l->t('Profile Image')); ?></strong></legend>
<img src="<?php print_unescaped(link_to('', 'avatar.php').'?user='.OC_User::getUser().'&size=128'); ?>"><br> <img src="<?php print_unescaped(link_to('', 'avatar.php').'?user='.OC_User::getUser().'&size=128'); ?>"><br>
<?php if ($_['avatar'] === "local"): ?> <?php if ($_['avatar'] === "local"): ?>
<em><?php p($l->t('Your avatar has to be a square and either a PNG or JPG image')); ?></em><br> <em><?php p($l->t('Your profile image has to be a square and either a PNG or JPG image')); ?></em><br>
<div class="inlineblock button" id="uploadavatarbutton"><?php p($l->t('Upload a new avatar')); ?></div> <div class="inlineblock button" id="uploadavatarbutton"><?php p($l->t('Upload a new image')); ?></div>
<input type="file" class="hidden" name="files[]" id="uploadavatar"> <input type="file" class="hidden" name="files[]" id="uploadavatar">
<div class="inlineblock button" id="selectavatar"><?php p($l->t('Select a new avatar from your files')); ?></div> <div class="inlineblock button" id="selectavatar"><?php p($l->t('Select a new image from your files')); ?></div>
<div class="inlineblock button" id="removeavatar"><?php p($l->t('Remove my avatar')); ?></div> <div class="inlineblock button" id="removeavatar"><?php p($l->t('Remove my image')); ?></div>
<?php elseif ($_['avatar'] === "gravatar"): ?> <?php elseif ($_['avatar'] === "gravatar"): ?>
<em><?php p($l->t('Your avatar is provided by gravatar, which is based on your Email.')); ?></em> <em><?php p($l->t('Your profile image is provided by gravatar, which is based on your Email.')); ?></em>
<?php else: ?> <?php else: ?>
<em><?php p($l->t('Your avatar is provided by a custom service, ask your administrator, on how to change your avatar.')); ?></em> <em><?php p($l->t('Your profile image is provided by a custom service, ask your administrator, on how to change your image.')); ?></em>
<?php endif; ?> <?php endif; ?>
</fieldset> </fieldset>
</form> </form>

View File

@ -82,7 +82,7 @@ $_['subadmingroups'] = array_flip($items);
<thead> <thead>
<tr> <tr>
<?php if(\OC_Avatar::getMode() !== "none"): ?> <?php if(\OC_Avatar::getMode() !== "none"): ?>
<th id='headerAvatar'><?php p($l->t('Avatar')); ?></th> <th id='headerAvatar'></th>
<?php endif; ?> <?php endif; ?>
<th id='headerName'><?php p($l->t('Username'))?></th> <th id='headerName'><?php p($l->t('Username'))?></th>
<th id="headerDisplayName"><?php p($l->t( 'Display Name' )); ?></th> <th id="headerDisplayName"><?php p($l->t( 'Display Name' )); ?></th>