diff --git a/actions/avatarbynickname.php b/actions/avatarbynickname.php
index 9bbdecefac..ca58c96537 100644
--- a/actions/avatarbynickname.php
+++ b/actions/avatarbynickname.php
@@ -90,9 +90,9 @@ class AvatarbynicknameAction extends Action
$url = $avatar->url;
} else {
if ($size == 'original') {
- $url = common_default_avatar(AVATAR_PROFILE_SIZE);
+ $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
} else {
- $url = common_default_avatar($size+0);
+ $url = Avatar::defaultImage($size+0);
}
}
common_redirect($url, 302);
diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php
index 3f50ca24cd..a0be5d8f88 100644
--- a/actions/avatarsettings.php
+++ b/actions/avatarsettings.php
@@ -200,7 +200,7 @@ class AvatarsettingsAction extends AccountSettingsAction
'class' => 'avatar_view'));
$this->element('h2', null, _("Original"));
$this->elementStart('div', array('id'=>'avatar_original_view'));
- $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+ $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
'width' => $this->filedata['width'],
'height' => $this->filedata['height'],
'alt' => $user->nickname));
@@ -212,7 +212,7 @@ class AvatarsettingsAction extends AccountSettingsAction
'class' => 'avatar_view'));
$this->element('h2', null, _("Preview"));
$this->elementStart('div', array('id'=>'avatar_preview_view'));
- $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+ $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
'alt' => $user->nickname));
@@ -281,12 +281,12 @@ class AvatarsettingsAction extends AccountSettingsAction
$cur = common_current_user();
- $filename = common_avatar_filename($cur->id,
+ $filename = Avatar::filename($cur->id,
image_type_to_extension($imagefile->type),
null,
'tmp'.common_timestamp());
- $filepath = common_avatar_path($filename);
+ $filepath = Avatar::path($filename);
move_uploaded_file($imagefile->filepath, $filepath);
diff --git a/actions/grouplogo.php b/actions/grouplogo.php
index 7cf198dc73..650c952556 100644
--- a/actions/grouplogo.php
+++ b/actions/grouplogo.php
@@ -263,7 +263,7 @@ class GrouplogoAction extends Action
'class' => 'avatar_view'));
$this->element('h2', null, _("Original"));
$this->elementStart('div', array('id'=>'avatar_original_view'));
- $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+ $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
'width' => $this->filedata['width'],
'height' => $this->filedata['height'],
'alt' => $this->group->nickname));
@@ -275,7 +275,7 @@ class GrouplogoAction extends Action
'class' => 'avatar_view'));
$this->element('h2', null, _("Preview"));
$this->elementStart('div', array('id'=>'avatar_preview_view'));
- $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+ $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
'alt' => $this->group->nickname));
@@ -343,12 +343,12 @@ class GrouplogoAction extends Action
return;
}
- $filename = common_avatar_filename($this->group->id,
+ $filename = Avatar::filename($this->group->id,
image_type_to_extension($imagefile->type),
null,
'group-temp-'.common_timestamp());
- $filepath = common_avatar_path($filename);
+ $filepath = Avatar::path($filename);
move_uploaded_file($imagefile->filepath, $filepath);
diff --git a/actions/noticesearch.php b/actions/noticesearch.php
index c0c2381209..a5f01350c4 100644
--- a/actions/noticesearch.php
+++ b/actions/noticesearch.php
@@ -166,7 +166,7 @@ class NoticesearchAction extends SearchAction
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
$this->elementStart('a', array('href' => $profile->profileurl,
'class' => 'url'));
- $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
+ $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
'class' => 'avatar photo',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
diff --git a/actions/showstream.php b/actions/showstream.php
index 224bbce9fb..28bb8453f8 100644
--- a/actions/showstream.php
+++ b/actions/showstream.php
@@ -242,7 +242,7 @@ class ShowstreamAction extends Action
$this->elementStart('dl', 'entity_depiction');
$this->element('dt', null, _('Photo'));
$this->elementStart('dd');
- $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
+ $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
'class' => 'photo avatar',
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
diff --git a/actions/tagother.php b/actions/tagother.php
index cbace5b6b5..3e8a12fd69 100644
--- a/actions/tagother.php
+++ b/actions/tagother.php
@@ -80,7 +80,7 @@ class TagotherAction extends Action
$this->elementStart('dl', 'entity_depiction');
$this->element('dt', null, _('Photo'));
$this->elementStart('dd');
- $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
+ $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
'class' => 'photo avatar',
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
diff --git a/actions/twittersettings.php b/actions/twittersettings.php
index b3bf67dc3f..2d41469bba 100644
--- a/actions/twittersettings.php
+++ b/actions/twittersettings.php
@@ -250,8 +250,8 @@ class TwittersettingsAction extends ConnectSettingsAction
$avatar = $other->getAvatar(AVATAR_MINI_SIZE);
$avatar_url = ($avatar) ?
- common_avatar_display_url($avatar) :
- common_default_avatar(AVATAR_MINI_SIZE);
+ $avatar->displayUrl() :
+ Avatar::defaultImage(AVATAR_MINI_SIZE);
$this->element('img', array('src' => $avatar_url,
'width' => AVATAR_MINI_SIZE,
diff --git a/classes/Avatar.php b/classes/Avatar.php
index 6a9ea76865..6248a84d3b 100644
--- a/classes/Avatar.php
+++ b/classes/Avatar.php
@@ -4,18 +4,18 @@
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-class Avatar extends Memcached_DataObject
+class Avatar extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'avatar'; // table name
public $profile_id; // int(4) primary_key not_null
- public $original; // tinyint(1)
+ public $original; // tinyint(1)
public $width; // int(4) primary_key not_null
public $height; // int(4) primary_key not_null
public $mediatype; // varchar(32) not_null
- public $filename; // varchar(255)
+ public $filename; // varchar(255)
public $url; // varchar(255) unique_key
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
@@ -33,13 +33,51 @@ class Avatar extends Memcached_DataObject
{
$filename = $this->filename;
if (parent::delete()) {
- @unlink(common_avatar_path($filename));
+ @unlink(Avatar::path($filename));
}
}
-
- function &pkeyGet($kv)
+
+ function &pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Avatar', $kv);
}
+ // where should the avatar go for this user?
+
+ static function filename($id, $extension, $size=null, $extra=null)
+ {
+ if ($size) {
+ return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
+ } else {
+ return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
+ }
+ }
+
+ static function path($filename)
+ {
+ return INSTALLDIR . '/avatar/' . $filename;
+ }
+
+ static function url($filename)
+ {
+ return common_path('avatar/'.$filename);
+ }
+
+ function displayUrl()
+ {
+ $server = common_config('avatar', 'server');
+ if ($server) {
+ return 'http://'.$server.'/'.$this->filename;
+ } else {
+ return $this->url;
+ }
+ }
+
+ static function defaultAvatar($size)
+ {
+ static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
+ AVATAR_STREAM_SIZE => 'stream',
+ AVATAR_MINI_SIZE => 'mini');
+ return theme_path('default-avatar-'.$sizenames[$size].'.png');
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 5be632f87c..f3bfe299cf 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -71,7 +71,7 @@ class Profile extends Memcached_DataObject
function setOriginal($filename)
{
- $imagefile = new ImageFile($this->id, common_avatar_path($filename));
+ $imagefile = new ImageFile($this->id, Avatar::path($filename));
$avatar = new Avatar();
$avatar->profile_id = $this->id;
@@ -80,22 +80,22 @@ class Profile extends Memcached_DataObject
$avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename;
$avatar->original = true;
- $avatar->url = common_avatar_url($filename);
+ $avatar->url = Avatar::url($filename);
$avatar->created = DB_DataObject_Cast::dateTime(); # current time
# XXX: start a transaction here
if (!$this->delete_avatars() || !$avatar->insert()) {
- @unlink(common_avatar_path($filename));
+ @unlink(Avatar::path($filename));
return null;
}
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
# We don't do a scaled one if original is our scaled size
if (!($avatar->width == $size && $avatar->height == $size)) {
-
+
$scaled_filename = $imagefile->resize($size);
-
+
//$scaled = DB_DataObject::factory('avatar');
$scaled = new Avatar();
$scaled->profile_id = $this->id;
@@ -104,7 +104,7 @@ class Profile extends Memcached_DataObject
$scaled->original = false;
$scaled->mediatype = image_type_to_mime_type($imagefile->type);
$scaled->filename = $scaled_filename;
- $scaled->url = common_avatar_url($scaled_filename);
+ $scaled->url = Avatar::url($scaled_filename);
$scaled->created = DB_DataObject_Cast::dateTime(); # current time
if (!$scaled->insert()) {
@@ -194,4 +194,13 @@ class Profile extends Memcached_DataObject
}
}
+ function avatarUrl($size=AVATAR_PROFILE_SIZE)
+ {
+ $avatar = $this->getAvatar($size);
+ if ($avatar) {
+ return $avatar->displayUrl();
+ } else {
+ return Avatar::defaultImage($size);
+ }
+ }
}
diff --git a/classes/User_group.php b/classes/User_group.php
index 340d7f67a7..d152f9d567 100755
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -90,13 +90,13 @@ class User_group extends Memcached_DataObject
function setOriginal($filename)
{
- $imagefile = new ImageFile($this->id, common_avatar_path($filename));
+ $imagefile = new ImageFile($this->id, Avatar::path($filename));
$orig = clone($this);
- $this->original_logo = common_avatar_url($filename);
- $this->homepage_logo = common_avatar_url($imagefile->resize(AVATAR_PROFILE_SIZE));
- $this->stream_logo = common_avatar_url($imagefile->resize(AVATAR_STREAM_SIZE));
- $this->mini_logo = common_avatar_url($imagefile->resize(AVATAR_MINI_SIZE));
+ $this->original_logo = Avatar::url($filename);
+ $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
+ $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
+ $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
common_debug(common_log_objstring($this));
return $this->update($orig);
}
diff --git a/lib/imagefile.php b/lib/imagefile.php
index fa0581dd05..db344db8f8 100644
--- a/lib/imagefile.php
+++ b/lib/imagefile.php
@@ -153,12 +153,12 @@ class ImageFile
imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h);
- $outname = common_avatar_filename($this->id,
+ $outname = Avatar::filename($this->id,
image_type_to_extension($this->type),
$size,
common_timestamp());
- $outpath = common_avatar_path($outname);
+ $outpath = Avatar::path($outname);
switch ($this->type) {
case IMAGETYPE_GIF:
diff --git a/lib/jabber.php b/lib/jabber.php
index f1be577681..f41d984d62 100644
--- a/lib/jabber.php
+++ b/lib/jabber.php
@@ -178,7 +178,7 @@ function jabber_format_entry($profile, $notice)
$entry .= "\n";
$entry .= "\n";
$entry .= "