diff --git a/Dockerfile b/Dockerfile index 58ec6e1..de56e01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,21 +23,22 @@ RUN chmod +x /var/www/html/docker-utils/install-composer && \ ./composer.phar update && \ chmod +x /var/www/html/docker-utils/init-server +# Create a default copy of content and theme in case of empty directories binding +RUN mkdir -p /var/www/html/content.default/ && \ + cp -R /var/www/html/content/* /var/www/html/content.default/ && \ + mkdir -p /var/www/html/themes.default/ && \ + cp -R /var/www/html/themes/* /var/www/html/themes.default/ && \ + mkdir -p /var/www/html/media.default/ && \ + cp -R /var/www/html/media/* /var/www/html/media.default/ + # Expose useful volumes (see documentation) VOLUME /var/www/html/settings VOLUME /var/www/html/media VOLUME /var/www/html/cache VOLUME /var/www/html/plugins VOLUME /var/www/html/data - -# Create a default copy of content and theme in case of empty directories binding -RUN mkdir -p /var/www/html/content.default/ && \ - cp -R /var/www/html/content/* /var/www/html/content.default/ && \ - mkdir -p /var/www/html/themes.default/ && \ - cp -R /var/www/html/themes/* /var/www/html/themes.default/ - VOLUME /var/www/html/content VOLUME /var/www/html/themes -# Inject default values if content and themes are mounted with empty directories, adjust rights and start the server +# Inject default values for persistant data and start the server CMD ["/var/www/html/docker-utils/init-server"] \ No newline at end of file diff --git a/docker-utils/init-server b/docker-utils/init-server index f3bacd9..2320690 100644 --- a/docker-utils/init-server +++ b/docker-utils/init-server @@ -1,5 +1,12 @@ #!/bin/sh + +# mount data from persistant storage if not empty find /var/www/html/content -type d -empty -exec cp -R /var/www/html/content.default/* /var/www/html/content \; find /var/www/html/themes -type d -empty -exec cp -R /var/www/html/themes.default/* /var/www/html/themes \; +find /var/www/html/media -type d -empty -exec cp -R /var/www/html/media.default/* /var/www/html/media \; + +# Fix ownership (in case of new folders) chown -R www-data:www-data /var/www/html/ -apache2-foreground \ No newline at end of file + +# Start Apache in foreground +exec apache2-foreground \ No newline at end of file diff --git a/system/typemill/Middleware/OldInputMiddleware.php b/system/typemill/Middleware/OldInputMiddleware.php index 2da4a77..8ceee8f 100644 --- a/system/typemill/Middleware/OldInputMiddleware.php +++ b/system/typemill/Middleware/OldInputMiddleware.php @@ -16,22 +16,38 @@ class OldInputMiddleware } public function __invoke(Request $request, RequestHandler $handler) - { + { + if(isset($_SESSION) && isset($_SESSION['old'])) + { + $this->view->getEnvironment()->addGlobal('old', $_SESSION['old']); + } + + $response = $handler->handle($request); + + # unset old values after the request is processed. This keeps old values also if there is a redirect to another page and before the page is rendered but removes the values on page refresh. if(isset($_SESSION)) { - if(isset($_SESSION['old'])) - { - $this->view->getEnvironment()->addGlobal('old', $_SESSION['old']); - unset($_SESSION['old']); - } - if(!empty($request->getParsedBody())) - { - $_SESSION['old'] = $request->getParsedBody(); - } + unset($_SESSION['old']); + + if(!empty($request->getParsedBody())) + { + $oldinput = $request->getParsedBody(); + + if(is_array($oldinput)) + { + foreach($oldinput as $key => $value) + { + if (stripos($key, 'pass') !== false) + { + unset($oldinput[$key]); + } + } + } + + $_SESSION['old'] = $oldinput; + } } - - $response = $handler->handle($request); - + return $response; } } \ No newline at end of file diff --git a/system/typemill/Models/Storage.php b/system/typemill/Models/Storage.php index 0dc3bab..881b34c 100644 --- a/system/typemill/Models/Storage.php +++ b/system/typemill/Models/Storage.php @@ -667,20 +667,24 @@ class Storage public function getImageList() { - $thumbs = array_diff(scandir($this->thumbsFolder), array('..', '.')); - $imagelist = array(); + $imagelist = []; - foreach ($thumbs as $key => $name) + if(is_dir($this->thumbsFolder)) { - $imagelist[] = [ - 'name' => $name, - 'timestamp' => filemtime($this->thumbsFolder . $name), - 'src_thumb' => 'media/thumbs/' . $name, - 'src_live' => 'media/live/' . $name, - ]; + $thumbs = array_diff(scandir($this->thumbsFolder), array('..', '.')); + + foreach ($thumbs as $key => $name) + { + $imagelist[] = [ + 'name' => $name, + 'timestamp' => filemtime($this->thumbsFolder . $name), + 'src_thumb' => 'media/thumbs/' . $name, + 'src_live' => 'media/live/' . $name, + ]; + } + + $imagelist = Helpers::array_sort($imagelist, 'timestamp', SORT_DESC); } - - $imagelist = Helpers::array_sort($imagelist, 'timestamp', SORT_DESC); return $imagelist; } @@ -895,24 +899,28 @@ class Storage public function getFileList() { - $files = scandir($this->fileFolder); - $filelist = array(); + $filelist = []; - foreach ($files as $key => $name) + if(is_dir($this->fileFolder)) { - if (!in_array($name, array(".","..","filerestrictions.yaml")) && file_exists($this->fileFolder . $name)) - { - $filelist[] = [ - 'name' => $name, - 'timestamp' => filemtime($this->fileFolder . $name), - 'bytes' => filesize($this->fileFolder . $name), - 'info' => pathinfo($this->fileFolder . $name), - 'url' => 'media/files/' . $name, - ]; - } - } + $files = scandir($this->fileFolder); - $filelist = Helpers::array_sort($filelist, 'timestamp', SORT_DESC); + foreach ($files as $key => $name) + { + if (!in_array($name, array(".","..","filerestrictions.yaml")) && file_exists($this->fileFolder . $name)) + { + $filelist[] = [ + 'name' => $name, + 'timestamp' => filemtime($this->fileFolder . $name), + 'bytes' => filesize($this->fileFolder . $name), + 'info' => pathinfo($this->fileFolder . $name), + 'url' => 'media/files/' . $name, + ]; + } + } + + $filelist = Helpers::array_sort($filelist, 'timestamp', SORT_DESC); + } return $filelist; } diff --git a/system/typemill/author/js/vue-medialib.js b/system/typemill/author/js/vue-medialib.js index 0b4561e..70979db 100644 --- a/system/typemill/author/js/vue-medialib.js +++ b/system/typemill/author/js/vue-medialib.js @@ -603,7 +603,7 @@ const medialib = { { this.deleteFile(media); } - }, + }, loadFiles(filetype) { var fileself = this; @@ -615,7 +615,12 @@ const medialib = { }) .then(function (response) { - fileself.filedata = response.data.files; + fileself.filedata = []; + const files = response.data.files; + if(files && Array.isArray(files)) + { + fileself.filedata = files; + } fileself.showFiles(filetype); }) .catch(function (error) @@ -704,8 +709,13 @@ const medialib = { }) .then(function (response) { - imageself.imagedata = response.data.images; - imageself.showImages() + imageself.imagedata = []; + const images = response.data.images; + if (images && Array.isArray(images)) + { + imageself.imagedata = images; + } + imageself.showImages(); }) .catch(function (error) { diff --git a/system/typemill/author/partials/fields.twig b/system/typemill/author/partials/fields.twig index 87240f4..afb613d 100644 --- a/system/typemill/author/partials/fields.twig +++ b/system/typemill/author/partials/fields.twig @@ -39,9 +39,13 @@ - {% elseif (field.type == 'paragraph') and (field.getContent() != '') %} + {% elseif (field.type == 'paragraph') %} + + {% if (field.getContent() != '') %} - {{ markdown(field.getContent()) }} + {{ markdown(field.getContent()) }} + + {% endif %} {% elseif field.type == 'checkbox' %} diff --git a/system/typemill/settings/defaults.yaml b/system/typemill/settings/defaults.yaml index 0ea0719..e8c45fb 100644 --- a/system/typemill/settings/defaults.yaml +++ b/system/typemill/settings/defaults.yaml @@ -1,4 +1,4 @@ -version: '2.17.1' +version: '2.17.4' title: 'Typemill' author: 'Unknown' copyright: false diff --git a/system/typemill/system.php b/system/typemill/system.php index 472c371..3dc7b32 100644 --- a/system/typemill/system.php +++ b/system/typemill/system.php @@ -263,20 +263,18 @@ $timer['permissions'] = microtime(true); * SEGMENTS WITH SESSION * ****************************/ +$session_segments = ['setup', 'tm/', 'api/']; + # if website is restricted to registered user if( ( isset($settings['access']) && $settings['access'] ) || ( isset($settings['pageaccess']) && $settings['pageaccess'] ) ) { # activate session for all routes $session_segments = [$urlinfo['route']]; } -else -{ - $session_segments = ['setup', 'tm/', 'api/']; - # let plugins add own segments for session, eg. to enable csrf for forms - $client_segments = $dispatcher->dispatch(new OnSessionSegmentsLoaded([]), 'onSessionSegmentsLoaded')->getData(); - $session_segments = array_merge($session_segments, $client_segments); -} +# let plugins add own segments for session, eg. to enable csrf for forms +$client_segments = $dispatcher->dispatch(new OnSessionSegmentsLoaded([]), 'onSessionSegmentsLoaded')->getData(); +$session_segments = array_merge($session_segments, $client_segments); # start session # Session::startSessionForSegments($session_segments, $urlinfo['route']);