Merge pull request #180 from Jmeyering/master

Allow converting of r/n to /n when editing files in October backend
This commit is contained in:
Samuel Georges 2014-05-20 10:22:41 +10:00
commit e96a4c684f
2 changed files with 37 additions and 2 deletions

View File

@ -169,4 +169,17 @@ return array(
'defaultMask' => ['file' => null, 'folder' => null],
);
/*
|--------------------------------------------------------------------------
| Convert Line Endings
|--------------------------------------------------------------------------
|
| Determines if October should convert line endings from the windows style
| \r\n to the unix style \n.
|
*/
'convertLineEndings' => false,
);

View File

@ -1,5 +1,6 @@
<?php namespace Cms\Controllers;
use Config;
use URL;
use Lang;
use Flash;
@ -143,6 +144,11 @@ class Index extends Controller
$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');
@ -361,4 +367,20 @@ class Index extends Controller
return $settings;
}
}
/**
* convertLineEndings Replaces Windows style (/r/n) line endings with unix style (/n)
* line endings.
*
* @param string $markup The markup to convert to unix style endings
*
* @return string $markup
*/
private function convertLineEndings($markup)
{
$markup = str_replace("\r\n", "\n", $markup);
$markup = str_replace("\r", "\n", $markup);
return $markup;
}
}