/** * Add photo to album * * @params = $album Album guid * $photo Photo type * $access Private or Public ( its actually depend on album privacy) * * @return bool; */ public function AddPhoto($album, $photo = 'ossnphoto', $access = OSSN_PUBLIC) { //check access if (!in_array($access, ossn_access_types())) { $access = OSSN_PUBLIC; } //album initialize $this->album = new OssnAlbums(); $this->album = $this->album->GetAlbum($album); //check if album guid is not less than 0 and validate photo uploader if (!empty($album) && $album > 0 && $this->album->album->owner_guid == ossn_loggedin_user()->guid) { //initialize variables $this->owner_guid = $album; $this->type = 'object'; $this->subtype = 'ossn:aphoto'; $this->setFile($photo); $this->permission = $access; $this->setPath('album/photos/'); $this->setExtension(array('jpg', 'png', 'jpeg', 'gif')); //add file if ($this->addFile()) { $sizes = ossn_photos_sizes(); $resize = $this->getFiles(); if (isset($resize->{0}->value)) { $datadir = ossn_get_userdata("object/{$album}/{$resize->{0}->value}"); $file_name = str_replace('album/photos/', '', $resize->{0}->value); //crop photos and create new photos from source $sizes = ossn_photos_sizes(); foreach ($sizes as $size => $params) { $params = explode('x', $params); $width = $params[1]; $height = $params[0]; if ($size !== 'view') { $resized = ossn_resize_image($datadir, $width, $height, true); } else { $resized = ossn_resize_image($datadir, $width, $height, false); } //create newly created image $image = ossn_get_userdata("object/{$album}/album/photos/{$size}_{$file_name}"); file_put_contents($image, $resized); } //return true if photos is added to database return true; } } return false; } }
/** * Create a photo album * * @params = $owner_id User guid who is creating album * $name Album name * $acess Album access * $type Album type (user, group, page etc) * * @return bool; */ public function CreateAlbum($owner_id, $name, $access = OSSN_PUBLIC, $type = 'user') { //check if acess type is valid else set public if (!in_array($access, ossn_access_types())) { $access = OSSN_PUBLIC; } //check if owner is valid user if (!empty($owner_id) && !empty($name) && $owner_id > 0) { $this->owner_guid = $owner_id; $this->type = $type; $this->subtype = 'ossn:album'; $this->data->access = $access; $this->title = strip_tags($name); //add ablum if ($this->addObject()) { $this->getObjectId = $this->getObjectId(); return true; } return false; } }