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
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 static function pivotGet($keyCol, $keyVals, $otherCols)
32 return Memcached_DataObject::pivotGet('Avatar', $keyCol, $keyVals, $otherCols);
35 public static function schemaDef()
39 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
40 'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'uploaded by user or generated?'),
41 'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
42 'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
43 'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
44 'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'local filename, if local'),
45 'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'avatar location'),
46 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
47 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
49 'primary key' => array('profile_id', 'width', 'height'),
50 'unique keys' => array(
51 'avatar_url_key' => array('url'),
53 'foreign keys' => array(
54 'avatar_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
57 'avatar_profile_id_idx' => array('profile_id'),
61 // We clean up the file, too
65 $filename = $this->filename;
66 if (parent::delete()) {
67 @unlink(Avatar::path($filename));
73 return Memcached_DataObject::pkeyGet('Avatar', $kv);
77 * Where should the avatar go for this user?
79 static function filename($id, $extension, $size=null, $extra=null)
82 return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
84 return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
88 static function path($filename)
90 $dir = common_config('avatar', 'dir');
92 if ($dir[strlen($dir)-1] != '/') {
96 return $dir . $filename;
99 static function url($filename)
101 $path = common_config('avatar', 'path');
103 if ($path[strlen($path)-1] != '/') {
107 if ($path[0] != '/') {
111 $server = common_config('avatar', 'server');
113 if (empty($server)) {
114 $server = common_config('site', 'server');
117 $ssl = common_config('avatar', 'ssl');
119 if (is_null($ssl)) { // null -> guess
120 if (common_config('site', 'ssl') == 'always' &&
121 !common_config('avatar', 'server')) {
128 $protocol = ($ssl) ? 'https' : 'http';
130 return $protocol.'://'.$server.$path.$filename;
133 function displayUrl()
135 $server = common_config('avatar', 'server');
136 if ($server && !empty($this->filename)) {
137 return Avatar::url($this->filename);
143 static function defaultImage($size)
145 static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
146 AVATAR_STREAM_SIZE => 'stream',
147 AVATAR_MINI_SIZE => 'mini');
148 return Theme::path('default-avatar-'.$sizenames[$size].'.png');