]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Avatar.php
Merge branch 'ssleverything' into testing
[quix0rs-gnu-social.git] / classes / Avatar.php
1 <?php
2 /**
3  * Table Definition for avatar
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Avatar extends Memcached_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
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
22
23     /* Static get */
24     function staticGet($k,$v=null)
25     { return Memcached_DataObject::staticGet('Avatar',$k,$v); }
26
27     /* the code above is auto generated do not remove the tag below */
28     ###END_AUTOCODE
29
30     # We clean up the file, too
31
32     function delete()
33     {
34         $filename = $this->filename;
35         if (parent::delete()) {
36             @unlink(Avatar::path($filename));
37         }
38     }
39
40     function pkeyGet($kv)
41     {
42         return Memcached_DataObject::pkeyGet('Avatar', $kv);
43     }
44
45     // where should the avatar go for this user?
46
47     static function filename($id, $extension, $size=null, $extra=null)
48     {
49         if ($size) {
50             return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
51         } else {
52             return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
53         }
54     }
55
56     static function path($filename)
57     {
58         $dir = common_config('avatar', 'dir');
59
60         if ($dir[strlen($dir)-1] != '/') {
61             $dir .= '/';
62         }
63
64         return $dir . $filename;
65     }
66
67     static function url($filename)
68     {
69         $path = common_config('avatar', 'path');
70
71         if ($path[strlen($path)-1] != '/') {
72             $path .= '/';
73         }
74
75         if ($path[0] != '/') {
76             $path = '/'.$path;
77         }
78
79         $server = common_config('avatar', 'server');
80
81         if (empty($server)) {
82             $server = common_config('site', 'server');
83         }
84
85         $ssl = common_config('avatar', 'ssl');
86
87         if (is_null($ssl)) { // null -> guess
88             if (common_config('site', 'ssl') == 'always' &&
89                 !common_config('avatar', 'server')) {
90                 $ssl = true;
91             } else {
92                 $ssl = false;
93             }
94         }
95
96         $protocol = ($ssl) ? 'https' : 'http';
97
98         return $protocol.'://'.$server.$path.$filename;
99     }
100
101     function displayUrl()
102     {
103         $server = common_config('avatar', 'server');
104         if ($server) {
105             return Avatar::url($this->filename);
106         } else {
107             return $this->url;
108         }
109     }
110
111     static function defaultImage($size)
112     {
113         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
114                                   AVATAR_STREAM_SIZE => 'stream',
115                                   AVATAR_MINI_SIZE => 'mini');
116         return Theme::path('default-avatar-'.$sizenames[$size].'.png');
117     }
118 }