]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User_urlshortener_prefs.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[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 Managed_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     /* the code above is auto generated do not remove the tag below */
38     ###END_AUTOCODE
39
40     public static function schemaDef()
41     {
42         return array(
43             'fields' => array(
44                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
45                 'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
46                 'maxurllength' => array('type' => 'int', 'not null' => true, 'description' => 'urls greater than this length will be shortened, 0 = always, null = never'),
47                 'maxnoticelength' => array('type' => 'int', 'not null' => true, 'description' => 'notices with content greater than this value will have all urls shortened, 0 = always, -1 = only if notice text is longer than max allowed'),
48         
49                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
50                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
51             ),
52             'primary key' => array('user_id'),
53             'foreign keys' => array(
54                 'user_urlshortener_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
55             ),
56         );
57     }
58
59     static function maxUrlLength($user)
60     {
61         $def = common_config('url', 'maxurllength');
62
63         $prefs = self::getPrefs($user);
64
65         if (empty($prefs)) {
66             return $def;
67         } else {
68             return $prefs->maxurllength;
69         }
70     }
71
72     static function maxNoticeLength($user)
73     {
74         $def = common_config('url', 'maxnoticelength');
75
76         if ($def == -1) {
77             /*
78              * maxContent==0 means infinite length,
79              * but maxNoticeLength==0 means "always shorten"
80              * so if maxContent==0 we must set this to -1
81              */
82             $def = Notice::maxContent() ?: -1;
83         }
84
85         $prefs = self::getPrefs($user);
86
87         if (empty($prefs)) {
88             return $def;
89         } else {
90             return $prefs->maxnoticelength;
91         }
92     }
93
94     static function urlShorteningService($user)
95     {
96         $def = common_config('url', 'shortener');
97
98         $prefs = self::getPrefs($user);
99
100         if (empty($prefs)) {
101             if (!empty($user)) {
102                 return $user->urlshorteningservice;
103             } else {
104                 return $def;
105             }
106         } else {
107             return $prefs->urlshorteningservice;
108         }
109     }
110
111     static function getPrefs($user)
112     {
113         if (empty($user)) {
114             return null;
115         }
116
117         $prefs = User_urlshortener_prefs::getKV('user_id', $user->id);
118
119         return $prefs;
120     }
121 }