X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FProfile.php;h=f3bfe299cfb8d474dfae3ad57e29f2b8517f29cd;hb=095aecdd5cdd77f26ec6e61fc9eda97c10a522fc;hp=31bdf71d59b9923abacbab890e692b8864f442bf;hpb=5e061d2060702516328a723ad6c9577eb0aa782d;p=quix0rs-gnu-social.git diff --git a/classes/Profile.php b/classes/Profile.php index 31bdf71d59..f3bfe299cf 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -69,77 +69,54 @@ class Profile extends Memcached_DataObject } } - function setOriginal($source) + function setOriginal($filename) { - - $info = @getimagesize($source); - - if (!$info) { - return null; - } - - $filename = common_avatar_filename($this->id, - image_type_to_extension($info[2]), - null, common_timestamp()); - $filepath = common_avatar_path($filename); - - copy($source, $filepath); + $imagefile = new ImageFile($this->id, Avatar::path($filename)); $avatar = new Avatar(); - $avatar->profile_id = $this->id; - $avatar->width = $info[0]; - $avatar->height = $info[1]; - $avatar->mediatype = image_type_to_mime_type($info[2]); + $avatar->width = $imagefile->width; + $avatar->height = $imagefile->height; + $avatar->mediatype = image_type_to_mime_type($imagefile->type); $avatar->filename = $filename; $avatar->original = true; - $avatar->url = common_avatar_url($filename); + $avatar->url = Avatar::url($filename); $avatar->created = DB_DataObject_Cast::dateTime(); # current time # XXX: start a transaction here - if (!$this->delete_avatars()) { - @unlink($filepath); - return null; - } - - if (!$avatar->insert()) { - @unlink($filepath); + if (!$this->delete_avatars() || !$avatar->insert()) { + @unlink(Avatar::path($filename)); return null; } foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { # We don't do a scaled one if original is our scaled size if (!($avatar->width == $size && $avatar->height == $size)) { - $s = $avatar->scale($size); - if (!$s) { - return null; - } - } - } - return $avatar; - } + $scaled_filename = $imagefile->resize($size); - function crop_avatars($x, $y, $w, $h) - { + //$scaled = DB_DataObject::factory('avatar'); + $scaled = new Avatar(); + $scaled->profile_id = $this->id; + $scaled->width = $size; + $scaled->height = $size; + $scaled->original = false; + $scaled->mediatype = image_type_to_mime_type($imagefile->type); + $scaled->filename = $scaled_filename; + $scaled->url = Avatar::url($scaled_filename); + $scaled->created = DB_DataObject_Cast::dateTime(); # current time - $avatar = $this->getOriginalAvatar(); - $this->delete_avatars(false); # don't delete original - - foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { - # We don't do a scaled one if original is our scaled size - if (!($avatar->width == $size && $avatar->height == $size)) { - $s = $avatar->scale_and_crop($size, $x, $y, $w, $h); - if (!$s) { - return NULL; + if (!$scaled->insert()) { + return null; } } } - return true; + + return $avatar; } - function delete_avatars($original=true) + function delete_avatars($original=true) { $avatar = new Avatar(); $avatar->profile_id = $this->id; @@ -187,4 +164,43 @@ class Profile extends Memcached_DataObject 'profile:notices:'.$this->id, $offset, $limit, $since_id, $before_id); } + + function isMember($group) + { + $mem = new Group_member(); + + $mem->group_id = $group->id; + $mem->profile_id = $this->id; + + if ($mem->find()) { + return true; + } else { + return false; + } + } + + function isAdmin($group) + { + $mem = new Group_member(); + + $mem->group_id = $group->id; + $mem->profile_id = $this->id; + $mem->is_admin = 1; + + if ($mem->find()) { + return true; + } else { + return false; + } + } + + function avatarUrl($size=AVATAR_PROFILE_SIZE) + { + $avatar = $this->getAvatar($size); + if ($avatar) { + return $avatar->displayUrl(); + } else { + return Avatar::defaultImage($size); + } + } }