diff --git a/content/index.md b/content/index.md index ffdee6e..0d8f3d5 100644 --- a/content/index.md +++ b/content/index.md @@ -1,4 +1,4 @@ # Typemill -*Typemill is a user-friendly and lightweight open source CMS for publishing text-works like prose, lyrics, manuals, documentations, studies and more. Just download and start.* +Typemill is a user-friendly and lightweight open source CMS for publishing text-works like prose, lyrics, manuals, documentations, studies and more. Just download and start. diff --git a/system/Controllers/SettingsController.php b/system/Controllers/SettingsController.php index 0e66c71..cf426aa 100644 --- a/system/Controllers/SettingsController.php +++ b/system/Controllers/SettingsController.php @@ -172,7 +172,7 @@ class SettingsController extends Controller public function showThemes($request, $response, $args) { - $userSettings = $this->c->get('settings'); + $userSettings = $this->c->get('settings'); $themes = $this->getThemes(); $themedata = array(); $fieldsModel = new Fields(); @@ -332,7 +332,7 @@ class SettingsController extends Controller $userInput = isset($params[$themeName]) ? $params[$themeName] : false; $validate = new Validation(); $themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName); - + if(isset($themeSettings['settings']['images'])) { # get the default settings @@ -375,12 +375,23 @@ class SettingsController extends Controller if($userInput) { - /* validate the user-input */ - $this->validateInput('themes', $themeName, $userInput, $validate); - + # validate the user-input and return image-fields if they are defined + $imageFields = $this->validateInput('themes', $themeName, $userInput, $validate); + /* set user input as theme settings */ $userSettings['themes'][$themeName] = $userInput; } + + # handle images + $images = $request->getUploadedFiles(); + + if(!isset($_SESSION['errors']) && isset($images[$themeName])) + { + $userInput = $this->saveImages($imageFields, $userInput, $userSettings, $images[$themeName]); + + # set user input as theme settings + $userSettings['themes'][$themeName] = $userInput; + } /* check for errors and redirect to path, if errors found */ if(isset($_SESSION['errors'])) @@ -428,11 +439,22 @@ class SettingsController extends Controller else { /* validate the user-input */ - $this->validateInput('plugins', $pluginName, $userInput[$pluginName], $validate); + $imageFields = $this->validateInput('plugins', $pluginName, $userInput[$pluginName], $validate); /* use the input data */ $pluginSettings[$pluginName] = $userInput[$pluginName]; } + + # handle images + $images = $request->getUploadedFiles(); + + if(!isset($_SESSION['errors']) && isset($images[$pluginName])) + { + $userInput[$pluginName] = $this->saveImages($imageFields, $userInput[$pluginName], $userSettings, $images[$pluginName]); + + # set user input as theme settings + $pluginSettings[$pluginName] = $userInput[$pluginName]; + } /* deactivate the plugin, if there is no active flag */ if(!isset($userInput[$pluginName]['active'])) @@ -465,6 +487,9 @@ class SettingsController extends Controller /* fetch the original settings from the folder (plugin or theme) to get the field definitions */ $originalSettings = \Typemill\Settings::getObjectSettings($objectType, $objectName); + # images get special treatment + $imageFieldDefinitions = array(); + if(isset($originalSettings['forms']['fields'])) { /* flaten the multi-dimensional array with fieldsets to a one-dimensional array */ @@ -509,6 +534,12 @@ class SettingsController extends Controller { /* validate user input for this field */ $validate->objectField($fieldName, $fieldValue, $objectName, $fieldDefinition, $skiprequired); + + if($fieldDefinition['type'] == 'image') + { + # we want to return all images-fields for further processing + $imageFieldDefinitions[$fieldName] = $fieldDefinition; + } } if(!$fieldDefinition && $fieldName != 'active') { @@ -516,6 +547,45 @@ class SettingsController extends Controller } } } + + return $imageFieldDefinitions; + } + + protected function saveImages($imageFields, $userInput, $userSettings, $files) + { + + # initiate image processor with standard image sizes + $processImages = new ProcessImage($userSettings['images']); + + if(!$processImages->checkFolders()) + { + $this->c->flash->addMessage('error', 'Please make sure that your media folder exists and is writable.'); + return false; + } + + foreach($imageFields as $fieldName => $imageField) + { + if(isset($userInput[$fieldName])) + { + # handle single input with single file upload + $image = $files[$fieldName]; + + if($image->getError() === UPLOAD_ERR_OK) + { + # not the most elegant, but createImage expects a base64-encoded string. + $imageContent = $image->getStream()->getContents(); + $imageData = base64_encode($imageContent); + $imageSrc = 'data: ' . $image->getClientMediaType() . ';base64,' . $imageData; + + if($processImages->createImage($imageSrc, $image->getClientFilename(), $userSettings['images'], $overwrite = NULL)) + { + # returns image path to media library + $userInput[$fieldName] = $processImages->publishImage(); + } + } + } + } + return $userInput; } /*********************** @@ -751,13 +821,13 @@ class SettingsController extends Controller private function getLanguages() { - return array( - 'en' => 'English', - 'ru' => 'Russian', - 'nl' => 'Dutch, Flemish', - 'de' => 'German', - 'it' => 'Italian', - 'fr' => 'French', - ); - } -} + return array( + 'en' => 'English', + 'ru' => 'Russian', + 'nl' => 'Dutch, Flemish', + 'de' => 'German', + 'it' => 'Italian', + 'fr' => 'French', + ); + } +} diff --git a/system/Models/Fields.php b/system/Models/Fields.php index a304e75..c38a8db 100644 --- a/system/Models/Fields.php +++ b/system/Models/Fields.php @@ -86,7 +86,7 @@ class Fields } else { - $field->unsetAttribute('chhecked'); + $field->unsetAttribute('checked'); } } else diff --git a/system/Models/Folder.php b/system/Models/Folder.php index 587438f..0dcaeda 100644 --- a/system/Models/Folder.php +++ b/system/Models/Folder.php @@ -506,7 +506,9 @@ class Folder { # if it is the first round, create an empty array if(!$i){ $i = 0; $breadcrumb = array();} - + + if(!$searchArray){ return $breadcrumb;} + while($i < count($searchArray)) { if(!isset($content[$searchArray[$i]])){ return false; } diff --git a/system/Models/Validation.php b/system/Models/Validation.php index 14f8b2c..84b0554 100644 --- a/system/Models/Validation.php +++ b/system/Models/Validation.php @@ -27,6 +27,15 @@ class Validation return false; }, 'invalid values'); + Validator::addRule('image_types', function($field, $value, array $params, array $fields) use ($user) + { + $allowed = ['jpg', 'jpeg', 'png']; + $pathinfo = pathinfo($value); + $extension = strtolower($pathinfo['extension']); + if(array_search($extension, $allowed)){ return true; } + return false; + }, 'only jpg, jpeg, png allowed'); + Validator::addRule('userAvailable', function($field, $value, array $params, array $fields) use ($user) { $userdata = $user->getUser($value); @@ -434,6 +443,7 @@ class Validation case "image": $v->rule('noHTML', $fieldName); $v->rule('lengthMax', $fieldName, 1000); + $v->rule('image_types', $fieldName); break; default: $v->rule('lengthMax', $fieldName, 1000); diff --git a/system/author/css/style.css b/system/author/css/style.css index 2adabc7..6d2a3b8 100644 --- a/system/author/css/style.css +++ b/system/author/css/style.css @@ -1114,7 +1114,7 @@ ul.cardInfo{ border: 0px; } .cardFields.open{ - max-height: 5000px; + max-height: 20000px; transition: max-height 0.5s ease-in; overflow: hidden; border: 1px; @@ -2490,6 +2490,8 @@ footer a:focus, footer a:hover, footer a:active } .blox .TOC li:before{ color: #bbb; } +.mbfix{ margin-bottom: 0px!important; } + @media only screen and (min-width: 600px) { section{ diff --git a/system/author/editor/publish-controller.twig b/system/author/editor/publish-controller.twig index 10bfaf5..ea6186a 100644 --- a/system/author/editor/publish-controller.twig +++ b/system/author/editor/publish-controller.twig @@ -1,3 +1,5 @@ +{% set itemurl = (item.urlRelWoF == '/') ? '' : item.urlRelWoF %} +
- + + +