]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
fix args in returnto
[quix0rs-gnu-social.git] / classes / Profile.php
index d91bcf3ed3b5d43d817138530e4c12c1e8e285a9..b7bd2a2d9293260525fae5f53958e40e5ed8417e 100644 (file)
@@ -73,29 +73,64 @@ class Profile extends DB_DataObject
                }
        }
 
-       function validateNickname() {
-               return Validate::string($this->nickname, array('min_length' => 1, 'max_length' => 64,
-                                                                                                          'format' => VALIDATE_ALPHA_LOWER . VALIDATE_NUM));
-       }
+       function setOriginal($source) {
 
-       function validateProfileurl() {
-               return Validate::uri($this->profileurl, array('allowed_schemes' => array('http', 'https')));
-       }
+               $info = @getimagesize($source);
 
-       function validateHomepage() {
-               return (strlen($this->homepage) == 0) ||
-                 Validate::uri($this->homepage, array('allowed_schemes' => array('http', 'https'))));
-       }
+               if (!$info) {
+                       return NULL;
+               }
 
-       function validateBio() {
-               return Validate::string($this->bio, array('min_length' => 0, 'max_length' => 140));
-       }
+               $filename = common_avatar_filename($this->id,
+                                                                                  image_type_to_extension($info[2]),
+                                                                                  NULL, common_timestamp());
+               $filepath = common_avatar_path($filename);
+
+               copy($source, $filepath);
+
+               $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->filename = $filename;
+               $avatar->original = true;
+               $avatar->url = common_avatar_url($filename);
+               $avatar->created = DB_DataObject_Cast::dateTime(); # current time
+
+               # XXX: start a transaction here
 
-       function validateLocation() {
-               return Validate::string($this->location, array('min_length' => 0, 'max_length' => 255));
+               if (!$this->delete_avatars()) {
+                       @unlink($filepath);
+                       return NULL;
+               }
+
+               if (!$avatar->insert()) {
+                       @unlink($filepath);
+                       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;
        }
 
-       function validateFullname() {
-               return Validate::string($this->fullname, array('min_length' => 0, 'max_length' => 255));
+       function delete_avatars() {
+               $avatar = DB_DataObject::factory('avatar');
+               $avatar->profile_id = $this->id;
+               $avatar->find();
+               while ($avatar->fetch()) {
+                       $avatar->delete();
+               }
+               return true;
        }
 }