3 * Table Definition for avatar
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Avatar extends Managed_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
23 /* the code above is auto generated do not remove the tag below */
26 public static function schemaDef()
30 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
31 'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'uploaded by user or generated?'),
32 'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
33 'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
34 'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
35 'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'local filename, if local'),
36 'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'avatar location'),
37 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
38 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
40 'primary key' => array('profile_id', 'width', 'height'),
41 'unique keys' => array(
42 'avatar_url_key' => array('url'),
44 'foreign keys' => array(
45 'avatar_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
48 'avatar_profile_id_idx' => array('profile_id'),
52 // We clean up the file, too
56 $filename = $this->filename;
57 if (parent::delete()) {
58 @unlink(Avatar::path($filename));
63 * Where should the avatar go for this user?
65 static function filename($id, $extension, $size=null, $extra=null)
68 return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
70 return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
74 static function path($filename)
76 $dir = common_config('avatar', 'dir');
78 if ($dir[strlen($dir)-1] != '/') {
82 return $dir . $filename;
85 static function url($filename)
87 $path = common_config('avatar', 'path');
89 if ($path[strlen($path)-1] != '/') {
93 if ($path[0] != '/') {
97 $server = common_config('avatar', 'server');
100 $server = common_config('site', 'server');
103 $ssl = common_config('avatar', 'ssl');
105 if (is_null($ssl)) { // null -> guess
106 if (common_config('site', 'ssl') == 'always' &&
107 !common_config('avatar', 'server')) {
114 $protocol = ($ssl) ? 'https' : 'http';
116 return $protocol.'://'.$server.$path.$filename;
119 function displayUrl()
121 $server = common_config('avatar', 'server');
122 if ($server && !empty($this->filename)) {
123 return Avatar::url($this->filename);
129 static function defaultImage($size)
131 static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
132 AVATAR_STREAM_SIZE => 'stream',
133 AVATAR_MINI_SIZE => 'mini');
134 return Theme::path('default-avatar-'.$sizenames[$size].'.png');