diff --git a/CHANGELOG.md b/CHANGELOG.md index 33e959d88..c9874e1d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ * **Build 300** (2015-10-xx) - Added new helper `Twig::parse` for parsing Twig. + - Page settings now support infinite array nesting with October flavored INI syntax via `Ini::parse` and `Ini::render`. * **Build 298** (2015-09-24) - Added the ability to use a wildcard URL parameter in CMS pages (see CMS > Pages docs). diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 9e1170e2f..3b3c16b0a 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -1,5 +1,6 @@ settings) { - $content[] = FileHelper::formatIniString($this->settings); + $content[] = Ini::render($this->settings); } if ($this->code) { diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index 7e3484684..131bc0542 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -5,6 +5,7 @@ use Lang; use Cache; use Config; use Validator; +use Cms\Helpers\File as FileHelper; use ApplicationException; use ValidationException; use RecursiveDirectoryIterator; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index eff540c21..f4aea84e7 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -18,7 +18,6 @@ use Twig_Environment; use Cms\Twig\Loader as TwigLoader; use Cms\Twig\DebugExtension; use Cms\Twig\Extension as CmsTwigExtension; -use Cms\Classes\FileHelper as CmsFileHelper; use Cms\Models\MaintenanceSettings; use System\Models\RequestLog; use System\Classes\ErrorHandler; diff --git a/modules/cms/classes/FileHelper.php b/modules/cms/helpers/File.php similarity index 63% rename from modules/cms/classes/FileHelper.php rename to modules/cms/helpers/File.php index 8029e9c25..a99457e43 100644 --- a/modules/cms/classes/FileHelper.php +++ b/modules/cms/helpers/File.php @@ -1,4 +1,4 @@ - $value) { - if (is_array($value)) { - if ($level == 1) { - $sections[$key] = self::formatIniString($value, $level+1); - } - else { - foreach ($value as $val) { - $content .= $key.'[] = "'.self::escapeIniString($val).'"'.PHP_EOL; - } - } - } - elseif (strlen($value)) { - $content .= $key.' = "'.self::escapeIniString($value).'"'.PHP_EOL; - } - } - - foreach ($sections as $key => $section) { - $content .= PHP_EOL.'['.$key.']'.PHP_EOL.$section.PHP_EOL; - } - - return trim($content); - } - - /** - * Escapes a string for saving in INI format - * @param string $string Specifies the string to escape - * @return string Returns the processed string - */ - public static function escapeIniString($string) - { - return str_replace('"', '\"', $string); - } } diff --git a/modules/system/assets/ui/js/input.trigger.js b/modules/system/assets/ui/js/input.trigger.js index 1e63ea0d6..af4f62189 100644 --- a/modules/system/assets/ui/js/input.trigger.js +++ b/modules/system/assets/ui/js/input.trigger.js @@ -11,9 +11,6 @@ this.options = options || {}; - // @deprecated remove if year >= 2016 - if (this.options.triggerType !== false && this.options.triggerAction === false) this.options.triggerAction = this.options.triggerType - if (this.options.triggerCondition === false) throw new Error('Trigger condition is not specified.') diff --git a/modules/system/providers.php b/modules/system/providers.php index 9dd2df7ed..fa7636402 100644 --- a/modules/system/providers.php +++ b/modules/system/providers.php @@ -27,12 +27,12 @@ return [ 'October\Rain\Foundation\Providers\ArtisanServiceProvider', 'October\Rain\Database\DatabaseServiceProvider', 'October\Rain\Filesystem\FilesystemServiceProvider', + 'October\Rain\Parse\ParseServiceProvider', 'October\Rain\Html\HtmlServiceProvider', 'October\Rain\Html\UrlServiceProvider', 'October\Rain\Network\NetworkServiceProvider', 'October\Rain\Scaffold\ScaffoldServiceProvider', 'October\Rain\Flash\FlashServiceProvider', 'October\Rain\Mail\MailServiceProvider', - 'October\Rain\Parse\ParseServiceProvider', ]; diff --git a/tests/fixtures/cms/filehelper/sections.ini b/tests/fixtures/cms/filehelper/sections.ini deleted file mode 100644 index b5f310f2a..000000000 --- a/tests/fixtures/cms/filehelper/sections.ini +++ /dev/null @@ -1,10 +0,0 @@ -var1 = "value 1" -var2 = "value 21" - -[section] -sectionVar1 = "section value 1" -sectionVar2 = "section value 2" - -[section data] -sectionVar3 = "section value 3" -sectionVar4 = "section value 4" \ No newline at end of file diff --git a/tests/fixtures/cms/filehelper/simple.ini b/tests/fixtures/cms/filehelper/simple.ini deleted file mode 100644 index 73da84056..000000000 --- a/tests/fixtures/cms/filehelper/simple.ini +++ /dev/null @@ -1,2 +0,0 @@ -var1 = "value 1" -var2 = "value 21" \ No newline at end of file diff --git a/tests/fixtures/cms/filehelper/subsections.ini b/tests/fixtures/cms/filehelper/subsections.ini deleted file mode 100644 index 07984e675..000000000 --- a/tests/fixtures/cms/filehelper/subsections.ini +++ /dev/null @@ -1,15 +0,0 @@ -var1 = "value 1" -var2 = "value 21" - -[section] -sectionVar1 = "section value 1" -sectionVar2 = "section value 2" -subsection[] = "subsection value 1" -subsection[] = "subsection value 2" -sectionVar3 = "section value 3" - -[section data] -sectionVar3 = "section value 3" -sectionVar4 = "section value 4" -subsection[] = "subsection value 1" -subsection[] = "subsection value 2" \ No newline at end of file diff --git a/tests/unit/cms/classes/FileHelperTest.php b/tests/unit/cms/classes/FileHelperTest.php deleted file mode 100644 index 43f7f6ae4..000000000 --- a/tests/unit/cms/classes/FileHelperTest.php +++ /dev/null @@ -1,92 +0,0 @@ -assertFalse(FileHelper::validateName('')); - $this->assertTrue(FileHelper::validateName('01test-testdat')); - $this->assertTrue(FileHelper::validateName('test/testdat')); - $this->assertFalse(FileHelper::validateName('test\testdat')); - $this->assertTrue(FileHelper::validateName('01test-test.dat')); - $this->assertFalse(FileHelper::validateName('test@test.dat')); - $this->assertFalse(FileHelper::validateName('test::test')); - $this->assertFalse(FileHelper::validateName('@test')); - } - - 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($this->getContents($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($this->getContents($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($this->getContents($path), $str); - } - - // - // Helpers - // - - protected function getContents($path) - { - $content = file_get_contents($path); - $content = preg_replace('~\R~u', PHP_EOL, $content); // Normalize EOL - return $content; - } - -} diff --git a/tests/unit/cms/helpers/FileTest.php b/tests/unit/cms/helpers/FileTest.php new file mode 100644 index 000000000..dde19f0c3 --- /dev/null +++ b/tests/unit/cms/helpers/FileTest.php @@ -0,0 +1,18 @@ +assertFalse(FileHelper::validateName('')); + $this->assertTrue(FileHelper::validateName('01test-testdat')); + $this->assertTrue(FileHelper::validateName('test/testdat')); + $this->assertFalse(FileHelper::validateName('test\testdat')); + $this->assertTrue(FileHelper::validateName('01test-test.dat')); + $this->assertFalse(FileHelper::validateName('test@test.dat')); + $this->assertFalse(FileHelper::validateName('test::test')); + $this->assertFalse(FileHelper::validateName('@test')); + } +}