diff --git a/src/Resources/contao/drivers/DC_Folder.php b/src/Resources/contao/drivers/DC_Folder.php index 1dd58c25a3..a6886948fb 100644 --- a/src/Resources/contao/drivers/DC_Folder.php +++ b/src/Resources/contao/drivers/DC_Folder.php @@ -444,6 +444,14 @@ public function showAll() $icon = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['icon'] ?: 'filemounts.svg'; $label = Image::getHtml($icon) . ' '; + // Pass previously selected values to picker (#1816) + $prevPickerValue = ''; + + if ($this->strPickerFieldType) + { + $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; + } + // Build the tree $return = $this->panel() . Message::generate() . '
' . ((Input::get('act') == 'select') ? ' @@ -459,7 +467,7 @@ public function showAll()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? ' +
' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
' : '') . ' diff --git a/src/Resources/contao/drivers/DC_Table.php b/src/Resources/contao/drivers/DC_Table.php index 2fe521c983..645a7e86fe 100644 --- a/src/Resources/contao/drivers/DC_Table.php +++ b/src/Resources/contao/drivers/DC_Table.php @@ -3643,6 +3643,14 @@ protected function treeView()

' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '

'; } + // Pass previously selected values to picker (#1816) + $prevPickerValue = ''; + + if ($this->strPickerFieldType) + { + $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; + } + $return .= ((Input::get('act') == 'select') ? '
@@ -3651,7 +3659,7 @@ protected function treeView()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? ' +
' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? '
' : '') . ' @@ -4194,6 +4202,14 @@ protected function parentView() return $return; } + // Pass previously selected values to picker (#1816) + $prevPickerValue = ''; + + if ($this->strPickerFieldType) + { + $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; + } + $return .= ((Input::get('act') == 'select') ? ' @@ -4203,7 +4219,7 @@ protected function parentView()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
+
'; // List all records of the child table @@ -4824,12 +4840,20 @@ protected function listView() { $result = $objRow->fetchAllAssoc(); + // Pass previously selected values to picker (#1816) + $prevPickerValue = ''; + + if ($this->strPickerFieldType) + { + $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; + } + $return .= ((Input::get('act') == 'select') ? '
' : '') . ' -
' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? ' +
' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
' : '') . ' diff --git a/src/Resources/contao/library/Contao/Config.php b/src/Resources/contao/library/Contao/Config.php index 5cc00777b6..9f6cd92301 100644 --- a/src/Resources/contao/library/Contao/Config.php +++ b/src/Resources/contao/library/Contao/Config.php @@ -10,6 +10,9 @@ namespace Contao; +use Symfony\Component\Filesystem\Filesystem; +use Webmozart\PathUtil\Path; + /** * Loads and writes the local configuration file * @@ -251,37 +254,47 @@ public function save() $strFile .= "\n" . $this->strBottom . "\n"; } - $strTemp = md5(uniqid(mt_rand(), true)); + $strTemp = Path::join($this->strRootDir, 'system/tmp', md5(uniqid(mt_rand(), true))); // Write to a temp file first - $objFile = fopen($this->strRootDir . '/system/tmp/' . $strTemp, 'w'); + $objFile = fopen($strTemp, 'w'); fwrite($objFile, $strFile); fclose($objFile); // Make sure the file has been written (see #4483) - if (!filesize($this->strRootDir . '/system/tmp/' . $strTemp)) + if (!filesize($strTemp)) { - System::log('The local configuration file could not be written. Have your reached your quota limit?', __METHOD__, TL_ERROR); + System::log('The local configuration file could not be written. Have you reached your quota limit?', __METHOD__, TL_ERROR); return; } + $fs = new Filesystem(); + // Adjust the file permissions (see #8178) - $this->Files->chmod('system/tmp/' . $strTemp, 0666 & ~umask()); + $fs->chmod($strTemp, 0666 & ~umask()); + + $strDestination = Path::join($this->strRootDir, 'system/config/localconfig.php'); + + // Get the realpath in case it is a symlink (see #2209) + if ($realpath = realpath($strDestination)) + { + $strDestination = $realpath; + } // Then move the file to its final destination - $this->Files->rename('system/tmp/' . $strTemp, 'system/config/localconfig.php'); + $fs->rename($strTemp, $strDestination, true); // Reset the Zend OPcache if (\function_exists('opcache_invalidate')) { - opcache_invalidate($this->strRootDir . '/system/config/localconfig.php', true); + opcache_invalidate($strDestination, true); } // Recompile the APC file (thanks to Trenker) if (\function_exists('apc_compile_file') && !ini_get('apc.stat')) { - apc_compile_file($this->strRootDir . '/system/config/localconfig.php'); + apc_compile_file($strDestination); } $this->blnIsModified = false; diff --git a/src/Resources/public/core.js b/src/Resources/public/core.js index 3fdf7d1df5..56916530ab 100644 --- a/src/Resources/public/core.js +++ b/src/Resources/public/core.js @@ -926,16 +926,29 @@ var Backend = return; } var frm = window.frames['simple-modal-iframe'], - val = [], ul, inp, field, act, it, i; + val = [], ul, inp, field, act, it, i, pickerValue, sIndex; if (frm === undefined) { alert('Could not find the SimpleModal frame'); return; } ul = frm.document.getElementById(opt.id); + // Load the previous values (#1816) + if (pickerValue = ul.get('data-picker-value')) { + val = JSON.parse(pickerValue); + } inp = ul.getElementsByTagName('input'); for (i=0; in)&&(t.width=Math.min(n,900)),new SimpleModal({width:t.width,hideFooter:!0,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}}).show({title:t.title,contents:''})},openModalIframe:function(e){var t=e||{},n=(window.getSize().x-20).toInt(),a=(window.getSize().y-137).toInt();(!t.width||t.width>n)&&(t.width=Math.min(n,900)),(!t.height||t.height>a)&&(t.height=a),new SimpleModal({width:t.width,hideFooter:!0,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}}).show({title:t.title,contents:''})},openModalSelector:function(e){var r=e||{},t=(window.getSize().x-20).toInt(),n=(window.getSize().y-192).toInt();r.id||(r.id="tl_select"),(!r.width||r.width>t)&&(r.width=Math.min(t,900)),(!r.height||r.height>n)&&(r.height=n);var a=new SimpleModal({width:r.width,btn_ok:Contao.lang.close,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}});a.addButton(Contao.lang.close,"btn",function(){this.buttons[0].hasClass("btn-disabled")||this.hide()}),a.addButton(Contao.lang.apply,"btn primary",function(){if(!this.buttons[1].hasClass("btn-disabled")){var e,t,n,a,o,i,l=window.frames["simple-modal-iframe"],s=[];if(void 0!==l){for(t=(e=l.document.getElementById(r.id)).getElementsByTagName("input"),i=0;i',model:"modal"})},openModalBrowser:function(n,e,t,a,o){Backend.openModalSelector({id:"tl_listing",title:a.document.getElement("div.mce-title").get("text"),url:Contao.routes.backend_picker+"?context="+("file"==t?"link":"file")+"&extras[fieldType]=radio&extras[filesOnly]=true&extras[source]="+o+"&value="+e+"&popup=1",callback:function(e,t){a.document.getElementById(n).value=t.join(",")}})},getScrollOffset:function(){window.sessionStorage.setItem("contao_backend_offset",window.getScroll().y)},initScrollOffset:function(){Cookie.dispose("BE_PAGE_OFFSET"),$$('.tl_submit_container button[name][name!="save"]').each(function(e){e.addEvent("click",function(){window.sessionStorage.removeItem("contao_backend_offset")})});var e=window.sessionStorage.getItem("contao_backend_offset");if(window.sessionStorage.removeItem("contao_backend_offset"),e){var t=window.document.getElementById("header"),i=0;t&&t.addClass("down"),$$("[data-add-to-scroll-offset]").each(function(e){var t=e.get("data-add-to-scroll-offset"),n=e.getScrollSize().y,a=!1,o=!1;t?("-"===t.charAt(0)&&(a=!0,t=t.substring(1)),"%"===t.charAt(t.length-1)&&(o=!0,t=t.substring(0,t.length-1)),t=parseInt(t,10),o&&(t=Math.round(n*t/100)),a&&(t*=-1),i+=t):i+=n}),this.vScrollTo(parseInt(e,10)+i)}},autoSubmit:function(e){Backend.getScrollOffset();var t=new Element("input",{type:"hidden",name:"SUBMIT_TYPE",value:"auto"}),n=$(e)||e;t.inject(n,"bottom"),n.submit()},vScrollTo:function(e){window.addEvent("load",function(){window.scrollTo(null,parseInt(e))})},limitPreviewHeight:function(){var l=0;$$("div.limit_height").each(function(e){var t,n,a,o,i=e.getParent(".tl_content");i&&(i.hasClass("wrapper_start")||i.hasClass("wrapper_stop"))||(0===l&&(l=e.className.replace(/[^0-9]*/,"").toInt()),l&&(t=new Element("div",{class:"limit_toggler"}),n=new Element("button",{type:"button",html:"...",class:"unselectable","data-state":0}).inject(t),a=e.getCoordinates(),e.setStyle("height",l),a.height<=l||(n.addEvent("click",function(){o=t.getPrevious("div").getStyle("height").toInt(),t.getPrevious("div").setStyle("height",l div:first-child")))for(n=0;n'}).inject(i,"top");e.previewsContainer=t.getElement(".dropzone-previews"),e.clickable=!1;var c=new Dropzone(i,e);c.on("queuecomplete",function(){window.location.reload()}),c.on("dragover",function(e){if(e.dataTransfer&&e.dataTransfer.types&&-1!==e.dataTransfer.types.indexOf("Files")){i.getElements(".tl_folder_dropping").removeClass("tl_folder_dropping");var t=e.target&&$(e.target);if(t){var n=t.match(".tl_folder")?t:t.getParent(".tl_folder");if(n=n||(n=t.getParent(".parent"))&&n.getPrevious(".tl_folder")){var a=n.getElement('img[src$="/icons/new.svg"]');a=a&&a.getParent("a")}}if(a&&a.href){if(c.options.url=""+a.href,n.addClass("tl_folder_dropping"),l!==n){l=n,s=(new Date).getTime();var o=n.getElement('img[src$="/icons/folPlus.svg"]');(o=o&&o.getParent("a"))&&setTimeout(function(){if(l===n&&s+900<(new Date).getTime()){var e=document.createEvent("HTMLEvents");e.initEvent("click",!0,!0),o.dispatchEvent(e),s=l=void 0}},1e3)}}else c.options.url=r,s=l=void 0}}),c.on("drop",function(e){e.dataTransfer&&e.dataTransfer.types&&-1!==e.dataTransfer.types.indexOf("Files")&&(t.addClass("dropzone-filetree-enabled"),Backend.getScrollOffset())}),c.on("dragleave",function(){i.getElements(".tl_folder_dropping").removeClass("tl_folder_dropping"),s=l=void 0})},crawl:function(){var a=2e3,e=$("tl_crawl"),c=e.getElement("div.progress-bar"),d=e.getElement("p.progress-count"),g=e.getElement("div.results");!function n(){new Request({url:window.location.href,onSuccess:function(e){var t=JSON.decode(e);!function(e){var t,n=e.total-e.pending,a=0n)&&(t.width=Math.min(n,900)),new SimpleModal({width:t.width,hideFooter:!0,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}}).show({title:t.title,contents:''})},openModalIframe:function(e){var t=e||{},n=(window.getSize().x-20).toInt(),a=(window.getSize().y-137).toInt();(!t.width||t.width>n)&&(t.width=Math.min(n,900)),(!t.height||t.height>a)&&(t.height=a),new SimpleModal({width:t.width,hideFooter:!0,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}}).show({title:t.title,contents:''})},openModalSelector:function(e){var d=e||{},t=(window.getSize().x-20).toInt(),n=(window.getSize().y-192).toInt();d.id||(d.id="tl_select"),(!d.width||d.width>t)&&(d.width=Math.min(t,900)),(!d.height||d.height>n)&&(d.height=n);var a=new SimpleModal({width:d.width,btn_ok:Contao.lang.close,draggable:!1,overlayOpacity:.7,onShow:function(){document.body.setStyle("overflow","hidden")},onHide:function(){document.body.setStyle("overflow","auto")}});a.addButton(Contao.lang.close,"btn",function(){this.buttons[0].hasClass("btn-disabled")||this.hide()}),a.addButton(Contao.lang.apply,"btn primary",function(){if(!this.buttons[1].hasClass("btn-disabled")){var e,t,n,a,o,i,l,s,r=window.frames["simple-modal-iframe"],c=[];if(void 0!==r){for((l=(e=r.document.getElementById(d.id)).get("data-picker-value"))&&(c=JSON.parse(l)),t=e.getElementsByTagName("input"),i=0;i',model:"modal"})},openModalBrowser:function(n,e,t,a,o){Backend.openModalSelector({id:"tl_listing",title:a.document.getElement("div.mce-title").get("text"),url:Contao.routes.backend_picker+"?context="+("file"==t?"link":"file")+"&extras[fieldType]=radio&extras[filesOnly]=true&extras[source]="+o+"&value="+e+"&popup=1",callback:function(e,t){a.document.getElementById(n).value=t.join(",")}})},getScrollOffset:function(){window.sessionStorage.setItem("contao_backend_offset",window.getScroll().y)},initScrollOffset:function(){Cookie.dispose("BE_PAGE_OFFSET"),$$('.tl_submit_container button[name][name!="save"]').each(function(e){e.addEvent("click",function(){window.sessionStorage.removeItem("contao_backend_offset")})});var e=window.sessionStorage.getItem("contao_backend_offset");if(window.sessionStorage.removeItem("contao_backend_offset"),e){var t=window.document.getElementById("header"),i=0;t&&t.addClass("down"),$$("[data-add-to-scroll-offset]").each(function(e){var t=e.get("data-add-to-scroll-offset"),n=e.getScrollSize().y,a=!1,o=!1;t?("-"===t.charAt(0)&&(a=!0,t=t.substring(1)),"%"===t.charAt(t.length-1)&&(o=!0,t=t.substring(0,t.length-1)),t=parseInt(t,10),o&&(t=Math.round(n*t/100)),a&&(t*=-1),i+=t):i+=n}),this.vScrollTo(parseInt(e,10)+i)}},autoSubmit:function(e){Backend.getScrollOffset();var t=new Element("input",{type:"hidden",name:"SUBMIT_TYPE",value:"auto"}),n=$(e)||e;t.inject(n,"bottom"),n.submit()},vScrollTo:function(e){window.addEvent("load",function(){window.scrollTo(null,parseInt(e))})},limitPreviewHeight:function(){var l=0;$$("div.limit_height").each(function(e){var t,n,a,o,i=e.getParent(".tl_content");i&&(i.hasClass("wrapper_start")||i.hasClass("wrapper_stop"))||(0===l&&(l=e.className.replace(/[^0-9]*/,"").toInt()),l&&(t=new Element("div",{class:"limit_toggler"}),n=new Element("button",{type:"button",html:"...",class:"unselectable","data-state":0}).inject(t),a=e.getCoordinates(),e.setStyle("height",l),a.height<=l||(n.addEvent("click",function(){o=t.getPrevious("div").getStyle("height").toInt(),t.getPrevious("div").setStyle("height",l div:first-child")))for(n=0;n'}).inject(i,"top");e.previewsContainer=t.getElement(".dropzone-previews"),e.clickable=!1;var c=new Dropzone(i,e);c.on("queuecomplete",function(){window.location.reload()}),c.on("dragover",function(e){if(e.dataTransfer&&e.dataTransfer.types&&-1!==e.dataTransfer.types.indexOf("Files")){i.getElements(".tl_folder_dropping").removeClass("tl_folder_dropping");var t=e.target&&$(e.target);if(t){var n=t.match(".tl_folder")?t:t.getParent(".tl_folder");if(n=n||(n=t.getParent(".parent"))&&n.getPrevious(".tl_folder")){var a=n.getElement('img[src$="/icons/new.svg"]');a=a&&a.getParent("a")}}if(a&&a.href){if(c.options.url=""+a.href,n.addClass("tl_folder_dropping"),l!==n){l=n,s=(new Date).getTime();var o=n.getElement('img[src$="/icons/folPlus.svg"]');(o=o&&o.getParent("a"))&&setTimeout(function(){if(l===n&&s+900<(new Date).getTime()){var e=document.createEvent("HTMLEvents");e.initEvent("click",!0,!0),o.dispatchEvent(e),s=l=void 0}},1e3)}}else c.options.url=r,s=l=void 0}}),c.on("drop",function(e){e.dataTransfer&&e.dataTransfer.types&&-1!==e.dataTransfer.types.indexOf("Files")&&(t.addClass("dropzone-filetree-enabled"),Backend.getScrollOffset())}),c.on("dragleave",function(){i.getElements(".tl_folder_dropping").removeClass("tl_folder_dropping"),s=l=void 0})},crawl:function(){var a=2e3,e=$("tl_crawl"),c=e.getElement("div.progress-bar"),d=e.getElement("p.progress-count"),g=e.getElement("div.results");!function n(){new Request({url:window.location.href,onSuccess:function(e){var t=JSON.decode(e);!function(e){var t,n=e.total-e.pending,a=0