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 getAvatar($width, $height=NULL) {
50 if (is_null($height)) {
53 return Avatar::pkeyGet(array('profile_id' => $this->id,
55 'height' => $height));
58 function getOriginalAvatar() {
59 $avatar = DB_DataObject::factory('avatar');
60 $avatar->profile_id = $this->id;
61 $avatar->original = true;
62 if ($avatar->find(true)) {
69 function setOriginal($source) {
71 $info = @getimagesize($source);
77 $filename = common_avatar_filename($this->id,
78 image_type_to_extension($info[2]),
79 NULL, common_timestamp());
80 $filepath = common_avatar_path($filename);
82 copy($source, $filepath);
84 $avatar = new Avatar();
86 $avatar->profile_id = $this->id;
87 $avatar->width = $info[0];
88 $avatar->height = $info[1];
89 $avatar->mediatype = image_type_to_mime_type($info[2]);
90 $avatar->filename = $filename;
91 $avatar->original = true;
92 $avatar->url = common_avatar_url($filename);
93 $avatar->created = DB_DataObject_Cast::dateTime(); # current time
95 # XXX: start a transaction here
97 if (!$this->delete_avatars()) {
102 if (!$avatar->insert()) {
107 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
108 # We don't do a scaled one if original is our scaled size
109 if (!($avatar->width == $size && $avatar->height == $size)) {
110 $s = $avatar->scale($size);
120 function delete_avatars() {
121 $avatar = new Avatar();
122 $avatar->profile_id = $this->id;
124 while ($avatar->fetch()) {
130 function getBestName() {
131 return ($this->fullname) ? $this->fullname : $this->nickname;
134 # Get latest notice on or before date; default now
135 function getCurrentNotice($dt=NULL) {
136 $notice = new Notice();
137 $notice->profile_id = $this->id;
139 $notice->whereAdd('created < "' . $dt . '"');
141 $notice->orderBy('created DESC, notice.id DESC');
143 if ($notice->find(true)) {