3 * Table Definition for avatar
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Avatar extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'avatar'; // table name
13 public $profile_id; // int(4) primary_key not_null
14 public $original; // tinyint(1)
15 public $width; // int(4) primary_key not_null
16 public $height; // int(4) primary_key not_null
17 public $mediatype; // varchar(32) not_null
18 public $filename; // varchar(255)
19 public $url; // varchar(255) unique_key
20 public $created; // datetime() not_null
21 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
24 function staticGet($k,$v=null)
25 { return Memcached_DataObject::staticGet('Avatar',$k,$v); }
27 /* the code above is auto generated do not remove the tag below */
30 // We clean up the file, too
34 $filename = $this->filename;
35 if (parent::delete()) {
36 @unlink(Avatar::path($filename));
42 return Memcached_DataObject::pkeyGet('Avatar', $kv);
46 * Where should the avatar go for this user?
48 static function filename($id, $extension, $size=null, $extra=null)
51 return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
53 return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
57 static function path($filename)
59 $dir = common_config('avatar', 'dir');
61 if ($dir[strlen($dir)-1] != '/') {
65 return $dir . $filename;
68 static function url($filename)
70 $path = common_config('avatar', 'path');
72 if ($path[strlen($path)-1] != '/') {
76 if ($path[0] != '/') {
80 $server = common_config('avatar', 'server');
83 $server = common_config('site', 'server');
86 $ssl = common_config('avatar', 'ssl');
88 if (is_null($ssl)) { // null -> guess
89 if (common_config('site', 'ssl') == 'always' &&
90 !common_config('avatar', 'server')) {
97 $protocol = ($ssl) ? 'https' : 'http';
99 return $protocol.'://'.$server.$path.$filename;
102 function displayUrl()
104 $server = common_config('avatar', 'server');
106 return Avatar::url($this->filename);
112 static function defaultImage($size)
114 static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
115 AVATAR_STREAM_SIZE => 'stream',
116 AVATAR_MINI_SIZE => 'mini');
117 return Theme::path('default-avatar-'.$sizenames[$size].'.png');