Clean up and prepare a bit for custom default avatars

This commit is contained in:
kondou 2013-08-18 16:41:00 +02:00
parent cd2f7bdaef
commit 4a9c89fb33
2 changed files with 7 additions and 12 deletions

View File

@ -1,9 +1,5 @@
<?php <?php
/**
* * @todo work on hashing userstrings, so one can't guess usernames
*/
require_once 'lib/base.php'; require_once 'lib/base.php';
if (!\OC_User::isLoggedIn()) { if (!\OC_User::isLoggedIn()) {
@ -40,6 +36,6 @@ if ($image instanceof \OC_Image) {
} elseif (is_string($image)) { // Gravatar alike services } elseif (is_string($image)) { // Gravatar alike services
header("Location: ".$image); header("Location: ".$image);
} else { } else {
$image = \OC_Avatar::getDefaultAvatar($size); $image = \OC_Avatar::getDefaultAvatar($user, $size);
$image->show(); $image->show();
} }

View File

@ -8,7 +8,7 @@
/** /**
* This class gets and sets users avatars. * This class gets and sets users avatars.
* Avalaible backends are local (saved in users root at avatar.[png|jpg]) and gravatar. * Available backends are local (saved in users root at avatar.[png|jpg]), gravatar TODO and custom backends.
* However the get function is easy to extend with further backends. * However the get function is easy to extend with further backends.
*/ */
@ -84,9 +84,8 @@ class OC_Avatar {
/** /**
* @brief get the users gravatar * @brief get the users gravatar
* @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');
@ -98,7 +97,7 @@ class OC_Avatar {
return $url; return $url;
} }
} }
return self::getDefaultAvatar($size); return self::getDefaultAvatar($user, $size);
} }
/** /**
@ -115,7 +114,7 @@ class OC_Avatar {
} elseif ($view->file_exists('avatar.png')) { } elseif ($view->file_exists('avatar.png')) {
$ext = 'png'; $ext = 'png';
} else { } else {
return self::getDefaultAvatar($size); return self::getDefaultAvatar($user, $size);
} }
$avatar = new OC_Image($view->file_get_contents('avatar.'.$ext)); $avatar = new OC_Image($view->file_get_contents('avatar.'.$ext));
@ -132,12 +131,12 @@ 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 * @brief $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 * @todo use custom default images, when they arive
*/ */
public static function getDefaultAvatar ($size = 64) { public static function getDefaultAvatar ($user, $size = 64) {
$default = new OC_Image(OC::$SERVERROOT."/core/img/defaultavatar.png"); $default = new OC_Image(OC::$SERVERROOT."/core/img/defaultavatar.png");
$default->resize($size); $default->resize($size);
return $default; return $default;