public function generator_edit() { // auth Util\Auth::isAdminAuthorized($this->signedUser, 'admin.dev', true, '/'); // check $model = Util\Converter::string('g'); $tplFile = Util\Converter::string('tpl-file', 'post'); $filePath = \Rebond\Config::getPath('model') . $model . '.xml'; if (!in_array($model, ['app', 'bus', 'cms', 'core'])) { Util\Session::adminError('itemNotFound', [$model], '/dev/generator'); } if (!file_exists($filePath)) { Util\Session::adminError('itemNotFound', [$filePath], '/dev/generator'); } // action if (isset($_POST['save'])) { file_put_contents($filePath, $tplFile); Util\Session::adminSuccess('saved', '/dev/generator'); } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'dev']); $tplMain->set('model', $model); $tplMain->set('filePath', $filePath); // layout $this->tplLayout->set('column1', $tplMain->render('model-form')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'devModel'); $this->tplMaster->addCss('/css/codemirror.css'); $this->tplMaster->addJs('/js/codemirror/codemirror.js'); $this->tplMaster->addJs('/js/codemirror/xml.js'); return $this->tplMaster->render('tpl-default'); }
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 lang_edit() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.config.lang.edit', true, '/configuration/lang'); // check $file = Converter::string('f'); $tplFile = Converter::string('tpl-file', 'post'); $filePath = \Rebond\Config::getPath('lang') . $file; if ($file == '') { header('Location: /configuration/lang'); exit; } if (!file_exists($filePath)) { Session::adminError('itemNotFound', [$filePath], '/configuration/lang'); } // action if (isset($_POST['save'])) { file_put_contents($filePath, $tplFile); Session::adminSuccess('saved', '/configuration/lang'); } // view $this->setTpl(); // main $tplMain = new Template(Template::SITE, ['admin', 'configuration']); $tplMain->set('file', $file); $tplMain->set('filePath', $filePath); // layout $this->tplLayout->set('column1', $tplMain->render('lang-form')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'configLang'); $this->tplMaster->addCss('/css/codemirror.css'); $this->tplMaster->addJs('/js/codemirror/codemirror.js'); $this->tplMaster->addJs('/js/codemirror/xml.js'); return $this->tplMaster->render('tpl-default'); }
public function module_export() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.cms.module.export', true, '/cms/module'); // check $id = Converter::int('id', 'get'); $module = \Rebond\Cms\Module\Data::loadById($id); if (!isset($module)) { Session::adminError('itemNotFound', [$id], '/cms/module'); } $exportPath = FULL_PATH . 'files/export/'; $zipFile = \Rebond\Cms\Module\Service::export($module); if ($zipFile === false) { Session::adminError('exportFailed', null, '/cms/module'); } if ($fd = fopen($exportPath . $zipFile, 'r')) { header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="' . $zipFile . '"'); header('Content-length: ' . filesize($exportPath . $zipFile)); header('Cache-control: private'); while (!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } }
private function findModule($moduleName) { if ($moduleName == '') { header('Location: /content/'); exit; } $module = \Rebond\Cms\Module\Data::loadByTitle($moduleName); if (!isset($module)) { Session::adminError('itemNotFound', [$moduleName], '/content/'); } return $module; }
public function membership() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $this->setTpl(); $membershipId = Util\Converter::toInt('id'); if (!isset($membershipId)) { Util\Session::adminError('item.not.found', [Util\Lang::lang('membership'), $membershipId], '/own/memberships'); } $membership = \Own\Bus\Membership\Data::loadById($membershipId, true); $membershipForm = new \Own\Bus\Membership\Form($membership); // action $save = Util\Converter::toString('save', 'post'); $courtIds = Util\Converter::toArray('court', 'post'); if (isset($save)) { if ($membershipForm->setFromPost()->validate()->isValid()) { \Own\Bus\MembershipCourt\Data::deleteByMembershipId($membership->getId()); $newCourts = []; if (isset($courtIds)) { foreach ($courtIds as $courtId) { $membershipCourt = new \Own\Bus\MembershipCourt\Model(); $membershipCourt->setMembershipId($membership->getId()); $membershipCourt->setCourtId($courtId); $newCourts[] = $membershipCourt; } } \Own\Bus\MembershipCourt\Data::saveAll($newCourts); $membership->save(); Util\Session::adminSuccess('saved', '/own/memberships'); } else { Util\Session::set('adminError', $membershipForm->getValidation()->getMessage()); } } $tplEditor = new Util\Template(Util\Template::SITE, ['admin']); $tplEditor->set('item', $membershipForm); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplEditor->render('membership-editor')]); }
public function role_permission() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.user.role', true, '/user/role'); // check $id = Converter::int('id'); $permissionIds = Converter::arr('permission', 'post'); $role = \Rebond\Core\Role\Data::loadById($id); if (!isset($role)) { Session::adminError('itemNotFound', [$id], '/user/role'); } $form = new \Rebond\Core\Role\Form($role); // action if (isset($_POST['save'])) { Auth::isAdminAuthorized($this->signedUser, 'admin.user.role.edit', true, '/user/role-permission?id=' . $id); \Rebond\Core\RolePermission\Data::deleteByRoleId($id); $newPermissions = []; if (isset($permissionIds)) { foreach ($permissionIds as $permissionId) { $rolePermission = new \Rebond\Core\RolePermission\Model(); $rolePermission->setRoleId($role->getId()); $rolePermission->setPermissionId($permissionId); $newPermissions[] = $rolePermission; } } \Rebond\Core\RolePermission\Data::saveAll($newPermissions); Session::adminSuccess('saved', '/user/role'); } // view $this->setTpl(); // main $tplMain = new Template(Template::MODULE, ['core', 'role']); $tplMain->set('item', $form); // layout if (Auth::isAdminAuthorized($this->signedUser, 'admin.user.role.edit', false)) { $this->tplLayout->set('column1', $tplMain->render('editor-permission')); } else { // @todo create viewer-permission template $this->tplLayout->set('column1', $tplMain->render('editor-permission')); } // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-default'); }
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'); }