3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
24 class User_urlshortener_prefs extends Managed_DataObject
27 /* the code below is auto generated do not remove the above tag */
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
37 /* the code above is auto generated do not remove the tag below */
40 public static function schemaDef()
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'),
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'),
52 'primary key' => array('user_id'),
53 'foreign keys' => array(
54 'user_urlshortener_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
59 static function maxUrlLength($user)
61 $def = common_config('url', 'maxlength');
63 $prefs = self::getPrefs($user);
68 return $prefs->maxurllength;
72 static function maxNoticeLength($user)
74 $def = common_config('url', 'maxnoticelength');
78 * maxContent==0 means infinite length,
79 * but maxNoticeLength==0 means "always shorten"
80 * so if maxContent==0 we must set this to -1
82 $def = Notice::maxContent() ?: -1;
85 $prefs = self::getPrefs($user);
90 return $prefs->maxnoticelength;
94 static function urlShorteningService($user)
96 $def = common_config('url', 'shortener');
98 $prefs = self::getPrefs($user);
102 return $user->urlshorteningservice;
107 return $prefs->urlshorteningservice;
111 static function getPrefs($user)
117 $prefs = User_urlshortener_prefs::getKV('user_id', $user->id);