3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
23 * Table Definition for profile
25 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
27 class Profile extends Memcached_DataObject
30 /* the code below is auto generated do not remove the above tag */
32 public $__table = 'profile'; // table name
33 public $id; // int(4) primary_key not_null
34 public $nickname; // varchar(64) multiple_key not_null
35 public $fullname; // varchar(255) multiple_key
36 public $profileurl; // varchar(255)
37 public $homepage; // varchar(255) multiple_key
38 public $bio; // varchar(140) multiple_key
39 public $location; // varchar(255) multiple_key
40 public $created; // datetime() not_null
41 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
44 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile',$k,$v); }
46 /* the code above is auto generated do not remove the tag below */
49 function getSearchEngine() {
50 require_once INSTALLDIR.'/classes/SearchEngines.php';
51 static $search_engine;
52 if (!isset($search_engine)) {
53 if (common_config('sphinx', 'enabled')) {
54 $search_engine = new SphinxSearch($this);
55 } elseif ('mysql' === common_config('db', 'type')) {
56 $search_engine = new MySQLSearch($this);
58 $search_engine = new PGSearch($this);
61 return $search_engine;
64 function getAvatar($width, $height=NULL) {
65 if (is_null($height)) {
68 return Avatar::pkeyGet(array('profile_id' => $this->id,
70 'height' => $height));
73 function getOriginalAvatar() {
74 $avatar = DB_DataObject::factory('avatar');
75 $avatar->profile_id = $this->id;
76 $avatar->original = true;
77 if ($avatar->find(true)) {
84 function setOriginal($source) {
86 $info = @getimagesize($source);
92 $filename = common_avatar_filename($this->id,
93 image_type_to_extension($info[2]),
94 NULL, common_timestamp());
95 $filepath = common_avatar_path($filename);
97 copy($source, $filepath);
99 $avatar = new Avatar();
101 $avatar->profile_id = $this->id;
102 $avatar->width = $info[0];
103 $avatar->height = $info[1];
104 $avatar->mediatype = image_type_to_mime_type($info[2]);
105 $avatar->filename = $filename;
106 $avatar->original = true;
107 $avatar->url = common_avatar_url($filename);
108 $avatar->created = DB_DataObject_Cast::dateTime(); # current time
110 # XXX: start a transaction here
112 if (!$this->delete_avatars()) {
117 if (!$avatar->insert()) {
122 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
123 # We don't do a scaled one if original is our scaled size
124 if (!($avatar->width == $size && $avatar->height == $size)) {
125 $s = $avatar->scale($size);
135 function delete_avatars() {
136 $avatar = new Avatar();
137 $avatar->profile_id = $this->id;
139 while ($avatar->fetch()) {
145 function getBestName() {
146 return ($this->fullname) ? $this->fullname : $this->nickname;
149 # Get latest notice on or before date; default now
150 function getCurrentNotice($dt=NULL) {
151 $notice = new Notice();
152 $notice->profile_id = $this->id;
154 $notice->whereAdd('created < "' . $dt . '"');
156 $notice->orderBy('created DESC, notice.id DESC');
158 if ($notice->find(true)) {