コード例 #1
0
ファイル: FileHelperTest.php プロジェクト: nnmer/october
 public function testFormatIniString()
 {
     $data = ['var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/simple.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertNotEmpty($str);
     $this->assertEquals(file_get_contents($path), $str);
     $data = ['section' => ['sectionVar1' => 'section value 1', 'sectionVar2' => 'section value 2'], 'section data' => ['sectionVar3' => 'section value 3', 'sectionVar4' => 'section value 4'], 'var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/sections.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertEquals(file_get_contents($path), $str);
     $data = ['section' => ['sectionVar1' => 'section value 1', 'sectionVar2' => 'section value 2', 'subsection' => ['subsectionVar1' => 'subsection value 1', 'subsectionVar2' => 'subsection value 2'], 'sectionVar3' => 'section value 3'], 'section data' => ['sectionVar3' => 'section value 3', 'sectionVar4' => 'section value 4', 'subsection' => ['subsectionVar1' => 'subsection value 1', 'subsectionVar2' => 'subsection value 2']], 'var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/subsections.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertEquals(file_get_contents($path), $str);
 }
コード例 #2
0
 /**
  * Saves the object to the disk.
  */
 public function save()
 {
     $this->code = trim($this->code);
     $this->markup = trim($this->markup);
     $trim = function (&$values) use(&$trim) {
         foreach ($values as &$value) {
             if (!is_array($value)) {
                 $value = trim($value);
             } else {
                 $trim($value);
             }
         }
     };
     $trim($this->settings);
     if (array_key_exists('components', $this->settings) && count($this->settings['components']) == 0) {
         unset($this->settings['components']);
     }
     $this->validate();
     $content = [];
     if ($this->settings) {
         $content[] = FileHelper::formatIniString($this->settings);
     }
     if ($this->code) {
         if ($this->wrapCodeToPhpTags() && array_get($this->originalData, 'code') != $this->code) {
             $code = preg_replace('/^\\<\\?php/', '', $this->code);
             $code = preg_replace('/^\\<\\?/', '', $code);
             $code = preg_replace('/\\?>$/', '', $code);
             $content[] = '<?php' . PHP_EOL . $this->code . PHP_EOL . '?>';
         } else {
             $content[] = $this->code;
         }
     }
     $content[] = $this->markup;
     $this->content = trim(implode(PHP_EOL . '==' . PHP_EOL, $content));
     parent::save();
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: tamboer/LaravelOctober
 /**
  * Executes the page, layout, component and plugin AJAX handlers.
  * @return mixed Returns the AJAX Response object or null.
  */
 protected function execAjaxHandlers()
 {
     if ($handler = trim(Request::header('X_OCTOBER_REQUEST_HANDLER'))) {
         try {
             /*
              * Validate the handler name
              */
             if (!preg_match('/^(?:\\w+\\:{2})?on[A-Z]{1}[\\w+]*$/', $handler)) {
                 throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name' => $handler]));
             }
             /*
              * Validate the handler partial list
              */
             if ($partialList = trim(Request::header('X_OCTOBER_REQUEST_PARTIALS'))) {
                 $partialList = explode('&', $partialList);
                 foreach ($partialList as $partial) {
                     if (!CmsFileHelper::validateName($partial)) {
                         throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name' => $partial]));
                     }
                 }
             } else {
                 $partialList = [];
             }
             $responseContents = [];
             /*
              * Execute the handler
              */
             if (!($result = $this->runAjaxHandler($handler))) {
                 throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name' => $handler]));
             }
             /*
              * If the handler returned an array, we should add it to output for rendering.
              * If it is a string, add it to the array with the key "result".
              */
             if (is_array($result)) {
                 $responseContents = array_merge($responseContents, $result);
             } elseif (is_string($result)) {
                 $responseContents['result'] = $result;
             }
             /*
              * Render partials and return the response as array that will be converted to JSON automatically.
              */
             foreach ($partialList as $partial) {
                 $responseContents[$partial] = $this->renderPartial($partial);
             }
             /*
              * If the handler returned a redirect, process it so framework.js knows to redirect
              * the browser and not the request!
              */
             if ($result instanceof RedirectResponse) {
                 $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
             }
             return Response::make()->setContent($responseContents);
         } catch (ValidationException $ex) {
             /*
              * Handle validation errors
              */
             $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields();
             $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage();
             return Response::make($responseContents, 406);
         } catch (Exception $ex) {
             return Response::make($ex->getMessage(), 500);
         }
     }
     return null;
 }
コード例 #4
0
ファイル: CmsObject.php プロジェクト: tamboer/LaravelOctober
 /**
  * Sets the object file name.
  * @param string $fileName Specifies the file name.
  * @return \Cms\Classes\CmsObject Returns the object instance.
  */
 public function setFileName($fileName)
 {
     $fileName = trim($fileName);
     if (!strlen($fileName)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.file_name_required', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
     if (!FileHelper::validateExtension($fileName, static::$allowedExtensions)) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file_extension', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]);
     }
     if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) {
         throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file', ['name' => $fileName])]);
     }
     if (!strlen(File::extension($fileName))) {
         $fileName .= '.htm';
     }
     $this->fileName = $fileName;
     return $this;
 }
コード例 #5
0
 /**
  * Saves the object to the disk.
  */
 public function save()
 {
     $this->code = trim($this->code);
     $this->markup = trim($this->markup);
     $trim = function (&$values) use(&$trim) {
         foreach ($values as &$value) {
             if (!is_array($value)) {
                 $value = trim($value);
             } else {
                 $trim($value);
             }
         }
     };
     $trim($this->settings);
     $this->validate();
     $content = [];
     if ($this->settings) {
         $content[] = FileHelper::formatIniString($this->settings);
     }
     if ($this->code) {
         $code = preg_replace('/^\\<\\?php/', '', $this->code);
         $code = preg_replace('/^\\<\\?/', '', $code);
         $code = preg_replace('/\\?>$/', '', $code);
         $content[] = '<?php' . PHP_EOL . $this->code . PHP_EOL . '?>';
     }
     $content[] = $this->markup;
     $this->content = trim(implode(PHP_EOL . '==' . PHP_EOL, $content));
     parent::save();
 }