public function getMedia($createIfNotExist = true) { if (!isset($this->media)) { $this->media = \Rebond\Core\Media\Data::loadById($this->mediaId, $createIfNotExist); } return $this->media; }
public function getAvatar($createIfNotExist = true) { if (!isset($this->avatar)) { $this->avatar = \Rebond\Core\Media\Data::loadById($this->avatarId, $createIfNotExist); } return $this->avatar; }
public function crop() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.media.crop', true, '/media'); // action $id = Converter::int('id'); $x = Converter::int('x', 'post'); $y = Converter::int('y', 'post'); $w = Converter::int('w', 'post'); $h = Converter::int('h', 'post'); $media = \Rebond\Core\Media\Data::loadById($id); if (!isset($media)) { Session::adminError('itemNotFound', [$id], '/media'); } // action if (isset($_POST['save'])) { $file = \Rebond\Util\Media::showFromModel($media, 920, 900, \Rebond\Core\RatioType::KEEP_MIN); $filename = \Rebond\Util\File::getFilename($file); $upload = \Rebond\Util\Media::crop(\Rebond\Config::getPath('media'), $media->getPath(), $filename, $x, $y, $w, $h); // add Media // copy media by setting MediaId to 0 $fullPathFile = \Rebond\Config::getPath('media') . $media->getPath() . $upload; $media->setId(0); $media->setOriginalFilename($upload); $media->setWidth($_POST['w']); $media->setHeight($_POST['h']); $media->setFilesize(filesize($fullPathFile)); $media->setUpload($upload); $media->setCreatedDate('now'); $media->save(); Session::adminSuccess('saved', '/media'); } // view $this->setTpl(); // media $tplMain = new Template(Template::SITE, ['admin', 'media']); $tplMain->set('model', $media); // layout $this->tplLayout->add('column1', $tplMain->render('crop')); //master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'mediaCrop'); return $this->tplMaster->render('tpl-default'); }
public function getMedia() { if (!$this->hasPrivilege('admin.media')) { return $this->noPrivilege('admin.media'); } $json = []; $json['result'] = ResultType::ERROR; // check $id = Converter::int('id', 'post', 0); $mediaModel = \Rebond\Core\Media\Data::loadById($id); if (!isset($mediaModel)) { $json['message'] = Lang::lang('mediaInvalid'); return json_encode($json); } $json['result'] = ResultType::SUCCESS; $json['html'] = \Rebond\Util\Media::showFromModel($mediaModel, 512, 512, \Rebond\Core\RatioType::KEEP_MAX); return json_encode($json); }