Example #1
0
 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');
 }