public static function deleteAllMedia($path, $filename) { $upload = File::getNoExtension($filename); if (file_exists(\Rebond\Config::getPath('media') . $path . $filename)) { unlink(\Rebond\Config::getPath('media') . $path . $filename); } $files = glob(\Rebond\Config::getPath('media') . $path . $upload . '-*.*'); foreach ($files as $file) { unlink($file); } }
public function produceViews() { foreach ($this->views as $view) { $viewPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/template/' . $view . '.tpl'; if (file_exists($viewPath) && in_array($view, ['filter', 'form-success'])) { $this->info[] = '<div class="exist">' . $view . ' already exists.</div>'; continue; } $propertyList = []; $propertyList2 = []; $multipleKey = []; $primaryKey = null; $viewTpl = new Template(Template::SITE, ['generator', 'views']); $viewTpl->set('package', $this->package); $viewTpl->set('entity', $this->entity); $viewTpl->set('isGenerated', false); $viewTpl->set('hasStatus', false); if (!in_array($view, ['filter'])) { foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $viewList = $property->getAttribute('view-list') == 'false' ? false : true; $skip = $property->getAttribute('persistent') == 'false' ? true : false; $skip = in_array($view, ['listing', 'bus-listing', 'admin-listing', 'admin-trail']) && (!$viewList || in_array($type, ['foreignKeyLink', 'singleKeyList'])) ? true : $skip; if ($skip) { continue; } $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'appId' : 'id'; $primaryKey = $propertyName; $viewTpl->set('primaryKey', $primaryKey); } if ($type == 'multipleKey') { $multipleKey[] = $propertyName . 'Id'; } if ($type == 'status') { $viewTpl->set('hasStatus', true); } $propertyList[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view); if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) { $propertyList2[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view . '-2'); } } $viewTpl->set('propertyList', implode('', $propertyList)); if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) { $viewTpl->set('propertyList2', implode('', $propertyList2)); } } $realView = $view; if (in_array($view, ['bus-editor', 'editor'])) { if (!isset($primaryKey)) { $realView .= '-nokey'; } } else { if (in_array($view, ['bus-listing', 'listing'])) { if (count($multipleKey) > 0) { $viewTpl->set('multipleKey', $multipleKey); $realView .= '-multikey'; } else { if (!isset($primaryKey)) { $realView .= '-nokey'; } } } } if (file_exists($viewPath) && in_array($view, ['editor', 'view', 'listing', 'form', 'list', 'detail', 'single'])) { if (!$this->generate) { continue; } $fileNoExt = \Rebond\Util\File::getNoExtension($viewPath); $viewPath = $fileNoExt . '-generated.tpl'; $viewTpl->set('isGenerated', true); $this->info[] = '<div class="exist">' . $view . ' already exists. ' . $view . '-generated has been created.</div>'; } else { $this->info[] = '<div>' . $view . ' created.</div>'; } $render = str_replace('<#php', '<?php', $viewTpl->render($realView)); \Rebond\Util\File::save($viewPath, 'w', $render); } }
public function tpl_edit() { // auth Util\Auth::isAdminAuthorized($this->signedUser, 'admin.designer', true, '/'); // check $file = Util\Converter::string('f'); $app = Util\Converter::string('app'); $save = Util\Converter::string('save', 'post'); if (empty($file)) { Util\Session::adminError('itemNotFound', [$file], '/designer/tpl'); } $validator = Util\Validate::validateFilename('file', $file, true); if (!$validator->isValid()) { Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl'); } $filePath = FULL_PATH . 'views/www/'; if (!empty($app)) { $filePath = FULL_PATH . 'Rebond/App/' . $app . '/template/'; $validator = Util\Validate::validateAlphaNumeric('app', $app, true); if (!$validator->isValid()) { Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl'); } } if (!file_exists($filePath)) { Util\Session::adminError('itemNotFound', [$filePath], '/designer/tpl'); } // action if (isset($save)) { $filePost = Util\Converter::string('file', 'post'); $tplFile = Util\Converter::string('tpl-file', 'post'); $appPost = Util\Converter::string('app', 'post'); $file = FULL_PATH . 'views/' . \Rebond\Config::getPath('siteFolder') . '/' . $filePost; if (!empty($appPost)) { $file = \Rebond\Config::getPath('rebond') . 'App/' . $appPost . '/template/' . $filePost; } if (!isset($file) || Util\File::getExtension($file) != 'tpl') { Util\Session::adminError('fileNotFoundOrValid', [$file], '/designer/css'); } if (!copy($file, Util\File::getNoExtension($file) . '-' . Util\Format::date(time(), 'string') . '.bak')) { Util\Session::adminError('itemNotCopied', [$file], '/designer/css'); } file_put_contents($file, $tplFile); Util\Session::adminSuccess('saved', '/designer/tpl'); } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'designer']); $tplMain->set('file', $file); $tplMain->set('app', $app); $tplMain->set('filePath', $filePath); $tplMain->set('editable', Util\File::getExtension($file) == 'tpl'); // layout $this->tplLayout->set('column1', $tplMain->render('tpl-form')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'designerTpl'); $this->tplMaster->addCss('/css/codemirror.css'); $this->tplMaster->addJs('/js/codemirror/codemirror.js'); $this->tplMaster->addJs('/js/codemirror/htmlmixed.js'); $this->tplMaster->addJs('/js/codemirror/xml.js'); $this->tplMaster->addJs('/js/codemirror/clike.js'); $this->tplMaster->addJs('/js/codemirror/php.js'); return $this->tplMaster->render('tpl-default'); }
public static function crop($serverPath, $path, $filename, $x, $y, $destWidth, $destHeight) { list($path, $filename) = self::validateFilename($serverPath, $path, $filename); $extension = File::getExtension($filename); $temp = explode('-', File::getNoExtension($filename)); $noExtension = $temp[0]; $compression = self::getCompression($extension); $newName = $noExtension . '_' . $destWidth . 'x' . $destHeight . '.' . $extension; if (file_exists($serverPath . $path . $newName)) { $newName = $noExtension . '_' . $destWidth . 'x' . $destHeight . '_' . uniqid() . '.' . $extension; } self::create($serverPath, $path, $filename, $x, $y, $destWidth, $destHeight, $newName, $destWidth, $destHeight, $compression); return $newName; }
public function uploadify() { $json = []; $json['result'] = ResultType::ERROR; // check $id = Converter::int('userId', 'post', 0); $this->signedUser = \Rebond\Core\User\Data::loadById($id); if (!isset($this->signedUser)) { $json['message'] = Lang::lang('accessNonAuthorized'); return json_encode($json); } if (!$this->hasPrivilege('admin.media.upload')) { return $this->noPrivilege('admin.media.upload'); } $folderId = Converter::int('folderId', 'post'); $isSelectable = Converter::int('isSelectable', 'post', 1); if (!isset($folderId)) { $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); } $upload = \Rebond\Util\Media::upload('', $_FILES['Filedata']); $originalName = $_FILES['Filedata']['name']; if ($upload == ResultType::ERROR) { $json['message'] = Lang::lang('errorFileUpload', [$originalName]); Log::log(Error::MEDIA_NOT_SAVED, $json['message'], __FILE__, __LINE__); return json_encode($json); } list($w, $h) = getimagesize(\Rebond\Config::getPath('media') . $upload); $ext = \Rebond\Util\File::getExtension(\Rebond\Config::getPath('media') . $upload); $noExt = \Rebond\Util\File::getNoExtension($originalName); $media = new \Rebond\Core\Media\Model(); $media->setFolderId($folderId); $media->setTitle($noExt); $media->setAlt($noExt); $media->setOriginalFilename($originalName); $media->setExtension($ext); $media->setWidth($w); $media->setHeight($h); $media->setFilesize(filesize(\Rebond\Config::getPath('media') . $upload)); $mimeType = new \finfo(FILEINFO_MIME_TYPE); $media->setMimetype($mimeType->file(\Rebond\Config::getPath('media') . $upload)); $media->setUpload($upload); $media->setIsSelectable($isSelectable); $media->save(); $json['result'] = ResultType::SUCCESS; $json['id'] = $media->getId(); $json['message'] = Lang::lang('mediaUploaded', [$originalName]); return json_encode($json); }