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)
45 { return Memcached_DataObject::staticGet('Profile',$k,$v); }
47 /* the code above is auto generated do not remove the tag below */
50 function getAvatar($width, $height=null)
52 if (is_null($height)) {
55 return Avatar::pkeyGet(array('profile_id' => $this->id,
57 'height' => $height));
60 function getOriginalAvatar()
62 $avatar = DB_DataObject::factory('avatar');
63 $avatar->profile_id = $this->id;
64 $avatar->original = true;
65 if ($avatar->find(true)) {
72 function setOriginal($source)
75 $info = @getimagesize($source);
81 $filename = common_avatar_filename($this->id,
82 image_type_to_extension($info[2]),
83 null, common_timestamp());
84 $filepath = common_avatar_path($filename);
86 copy($source, $filepath);
88 $avatar = new Avatar();
90 $avatar->profile_id = $this->id;
91 $avatar->width = $info[0];
92 $avatar->height = $info[1];
93 $avatar->mediatype = image_type_to_mime_type($info[2]);
94 $avatar->filename = $filename;
95 $avatar->original = true;
96 $avatar->url = common_avatar_url($filename);
97 $avatar->created = DB_DataObject_Cast::dateTime(); # current time
99 # XXX: start a transaction here
101 if (!$this->delete_avatars()) {
106 if (!$avatar->insert()) {
111 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
112 # We don't do a scaled one if original is our scaled size
113 if (!($avatar->width == $size && $avatar->height == $size)) {
114 $s = $avatar->scale($size);
124 function crop_avatars($x, $y, $w, $h)
127 $avatar = $this->getOriginalAvatar();
128 $this->delete_avatars(false); # don't delete original
130 foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
131 # We don't do a scaled one if original is our scaled size
132 if (!($avatar->width == $size && $avatar->height == $size)) {
133 $s = $avatar->scale_and_crop($size, $x, $y, $w, $h);
142 function delete_avatars($original=true)
144 $avatar = new Avatar();
145 $avatar->profile_id = $this->id;
147 while ($avatar->fetch()) {
148 if ($avatar->original) {
149 if ($original == false) {
158 function getBestName()
160 return ($this->fullname) ? $this->fullname : $this->nickname;
163 # Get latest notice on or before date; default now
164 function getCurrentNotice($dt=null)
166 $notice = new Notice();
167 $notice->profile_id = $this->id;
169 $notice->whereAdd('created < "' . $dt . '"');
171 $notice->orderBy('created DESC, notice.id DESC');
173 if ($notice->find(true)) {
179 function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
184 'WHERE profile_id = %d ';
186 return Notice::getStream(sprintf($qry, $this->id),
187 'profile:notices:'.$this->id,
188 $offset, $limit, $since_id, $before_id);
191 function isMember($group)
193 $mem = new Group_member();
195 $mem->group_id = $group->id;
196 $mem->profile_id = $this->id;
205 function isAdmin($group)
207 $mem = new Group_member();
209 $mem->group_id = $group->id;
210 $mem->profile_id = $this->id;