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 static function pivotGet($keyCol, $keyVals, $otherCols)
28 return Memcached_DataObject::pivotGet('Avatar', $keyCol, $keyVals, $otherCols);
31 public static function schemaDef()
35 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
36 'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'uploaded by user or generated?'),
37 'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
38 'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
39 'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
40 'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'local filename, if local'),
41 'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'avatar location'),
42 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
43 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
45 'primary key' => array('profile_id', 'width', 'height'),
46 'unique keys' => array(
47 'avatar_url_key' => array('url'),
49 'foreign keys' => array(
50 'avatar_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
53 'avatar_profile_id_idx' => array('profile_id'),
57 // We clean up the file, too
61 $filename = $this->filename;
62 if (parent::delete()) {
63 @unlink(Avatar::path($filename));
69 return Memcached_DataObject::pkeyGet('Avatar', $kv);
73 * Where should the avatar go for this user?
75 static function filename($id, $extension, $size=null, $extra=null)
78 return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
80 return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
84 static function path($filename)
86 $dir = common_config('avatar', 'dir');
88 if ($dir[strlen($dir)-1] != '/') {
92 return $dir . $filename;
95 static function url($filename)
97 $path = common_config('avatar', 'path');
99 if ($path[strlen($path)-1] != '/') {
103 if ($path[0] != '/') {
107 $server = common_config('avatar', 'server');
109 if (empty($server)) {
110 $server = common_config('site', 'server');
113 $ssl = common_config('avatar', 'ssl');
115 if (is_null($ssl)) { // null -> guess
116 if (common_config('site', 'ssl') == 'always' &&
117 !common_config('avatar', 'server')) {
124 $protocol = ($ssl) ? 'https' : 'http';
126 return $protocol.'://'.$server.$path.$filename;
129 function displayUrl()
131 $server = common_config('avatar', 'server');
132 if ($server && !empty($this->filename)) {
133 return Avatar::url($this->filename);
139 static function defaultImage($size)
141 static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
142 AVATAR_STREAM_SIZE => 'stream',
143 AVATAR_MINI_SIZE => 'mini');
144 return Theme::path('default-avatar-'.$sizenames[$size].'.png');