Exemple #1
0
 public function onSave()
 {
     $this->validateRequestTheme();
     $type = Request::input('templateType');
     $templatePath = trim(Request::input('templatePath'));
     $template = $templatePath ? $this->loadTemplate($type, $templatePath) : $this->createTemplate($type);
     $settings = Request::input('settings') ?: [];
     $settings = $this->upgradeSettings($settings);
     $templateData = [];
     if ($settings) {
         $templateData['settings'] = $settings;
     }
     $fields = ['markup', 'code', 'fileName', 'content'];
     foreach ($fields as $field) {
         if (array_key_exists($field, $_POST)) {
             $templateData[$field] = Request::input($field);
         }
     }
     if (!empty($templateData['markup']) && Config::get('cms.convertLineEndings', false) === true) {
         $templateData['markup'] = $this->convertLineEndings($templateData['markup']);
     }
     if (!Request::input('templateForceSave') && $template->mtime) {
         if (Request::input('templateMtime') != $template->mtime) {
             throw new ApplicationException('mtime-mismatch');
         }
     }
     $template->fill($templateData);
     $template->save();
     /*
      * Extensibility
      */
     Event::fire('cms.template.save', [$this, $template, $type]);
     $this->fireEvent('template.save', [$template, $type]);
     Flash::success(Lang::get('cms::lang.template.saved'));
     $result = ['templatePath' => $template->fileName, 'templateMtime' => $template->mtime, 'tabTitle' => $this->getTabTitle($type, $template)];
     if ($type == 'page') {
         $result['pageUrl'] = URL::to($template->url);
         $router = new Router($this->theme);
         $router->clearCache();
         CmsCompoundObject::clearCache($this->theme);
     }
     return $result;
 }