]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User_urlshortener_prefs.php
Merge branch '0.9.x' into merge
[quix0rs-gnu-social.git] / classes / User_urlshortener_prefs.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
21     exit(1);
22 }
23
24 class User_urlshortener_prefs extends Memcached_DataObject
25 {
26     ###START_AUTOCODE
27     /* the code below is auto generated do not remove the above tag */
28
29     public $__table = 'user_urlshortener_prefs';         // table name
30     public $user_id;                         // int(4)  primary_key not_null
31     public $urlshorteningservice;            // varchar(50)   default_ur1.ca
32     public $maxurllength;                    // int(4)   not_null
33     public $maxnoticelength;                 // int(4)   not_null
34     public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
35     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
36
37     /* Static get */
38     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_urlshortener_prefs',$k,$v); }
39
40     /* the code above is auto generated do not remove the tag below */
41     ###END_AUTOCODE
42
43     function sequenceKey()
44     {
45         return array(false, false, false);
46     }
47
48     static function maxUrlLength($user)
49     {
50         $def = common_config('url', 'maxlength');
51
52         $prefs = self::getPrefs($user);
53
54         if (empty($prefs)) {
55             return $def;
56         } else {
57             return $prefs->maxurllength;
58         }
59     }
60
61     static function maxNoticeLength($user)
62     {
63         $def = common_config('url', 'maxnoticelength');
64
65         if ($def == -1) {
66             $def = Notice::maxContent();
67         }
68
69         $prefs = self::getPrefs($user);
70
71         if (empty($prefs)) {
72             return $def;
73         } else {
74             return $prefs->maxnoticelength;
75         }
76     }
77
78     static function urlShorteningService($user)
79     {
80         $def = common_config('url', 'shortener');
81
82         $prefs = self::getPrefs($user);
83
84         if (empty($prefs)) {
85             if (!empty($user)) {
86                 return $user->urlshorteningservice;
87             } else {
88                 return $def;
89             }
90         } else {
91             return $prefs->urlshorteningservice;
92         }
93     }
94
95     static function getPrefs($user)
96     {
97         if (empty($user)) {
98             return null;
99         }
100
101         $prefs = User_urlshortener_prefs::staticGet('user_id', $user->id);
102
103         return $prefs;
104     }
105 }