]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Avatar.php
Merge branch '1.0.x' 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         static function pivotGet($keyCol, $keyVals, $otherCols)
31         {
32             return Memcached_DataObject::pivotGet('Avatar', $keyCol, $keyVals, $otherCols);
33         }
34         
35     // We clean up the file, too
36
37     function delete()
38     {
39         $filename = $this->filename;
40         if (parent::delete()) {
41             @unlink(Avatar::path($filename));
42         }
43     }
44
45     function pkeyGet($kv)
46     {
47         return Memcached_DataObject::pkeyGet('Avatar', $kv);
48     }
49
50     /**
51      * Where should the avatar go for this user?
52      */
53     static function filename($id, $extension, $size=null, $extra=null)
54     {
55         if ($size) {
56             return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
57         } else {
58             return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
59         }
60     }
61
62     static function path($filename)
63     {
64         $dir = common_config('avatar', 'dir');
65
66         if ($dir[strlen($dir)-1] != '/') {
67             $dir .= '/';
68         }
69
70         return $dir . $filename;
71     }
72
73     static function url($filename)
74     {
75         $path = common_config('avatar', 'path');
76
77         if ($path[strlen($path)-1] != '/') {
78             $path .= '/';
79         }
80
81         if ($path[0] != '/') {
82             $path = '/'.$path;
83         }
84
85         $server = common_config('avatar', 'server');
86
87         if (empty($server)) {
88             $server = common_config('site', 'server');
89         }
90
91         $ssl = common_config('avatar', 'ssl');
92
93         if (is_null($ssl)) { // null -> guess
94             if (common_config('site', 'ssl') == 'always' &&
95                 !common_config('avatar', 'server')) {
96                 $ssl = true;
97             } else {
98                 $ssl = false;
99             }
100         }
101
102         $protocol = ($ssl) ? 'https' : 'http';
103
104         return $protocol.'://'.$server.$path.$filename;
105     }
106
107     function displayUrl()
108     {
109         $server = common_config('avatar', 'server');
110         if ($server && !empty($this->filename)) {
111             return Avatar::url($this->filename);
112         } else {
113             return $this->url;
114         }
115     }
116
117     static function defaultImage($size)
118     {
119         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
120                                   AVATAR_STREAM_SIZE => 'stream',
121                                   AVATAR_MINI_SIZE => 'mini');
122         return Theme::path('default-avatar-'.$sizenames[$size].'.png');
123     }
124 }