Skip to content

Commit

Permalink
Merge branch '4.4' into 4.9
Browse files Browse the repository at this point in the history
# Conflicts:
#	core-bundle/src/Resources/contao/drivers/DC_Folder.php
#	core-bundle/src/Resources/contao/drivers/DC_Table.php
#	core-bundle/src/Resources/contao/library/Contao/Config.php
#	core-bundle/src/Resources/public/core.min.js
  • Loading branch information
leofeyer committed Sep 22, 2020
2 parents 5e53eff + 37c7444 commit ac00969
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/Resources/contao/drivers/DC_Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ public function showAll()
$icon = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['icon'] ?: 'filemounts.svg';
$label = Image::getHtml($icon) . ' <label>' . $label . '</label>';

// 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() . '
<div id="tl_buttons">' . ((Input::get('act') == 'select') ? '
Expand All @@ -459,7 +467,7 @@ public function showAll()
<div id="paste_hint" data-add-to-scroll-offset="20">
<p>' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '</p>
</div>' : '') . '
<div class="tl_listing_container tree_view" id="tl_listing">' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
<div class="tl_listing_container tree_view" id="tl_listing"' . $prevPickerValue . '>' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
<div class="tl_select_trigger">
<label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">
</div>' : '') . '
Expand Down
30 changes: 27 additions & 3 deletions src/Resources/contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,14 @@ protected function treeView()
<p class="tl_empty">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
}

// 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') ? '
<form id="tl_select" class="tl_form' . ((Input::get('act') == 'select') ? ' unselectable' : '') . '" method="post" novalidate>
<div class="tl_formbody_edit">
Expand All @@ -3651,7 +3659,7 @@ protected function treeView()
<div id="paste_hint" data-add-to-scroll-offset="20">
<p>' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '</p>
</div>' : '') . '
<div class="tl_listing_container tree_view" id="tl_listing">' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? '
<div class="tl_listing_container tree_view" id="tl_listing"' . $prevPickerValue . '>' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? '
<div class="tl_select_trigger">
<label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">
</div>' : '') . '
Expand Down Expand Up @@ -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') ? '
<form id="tl_select" class="tl_form' . ((Input::get('act') == 'select') ? ' unselectable' : '') . '" method="post" novalidate>
Expand All @@ -4203,7 +4219,7 @@ protected function parentView()
<div id="paste_hint" data-add-to-scroll-offset="20">
<p>' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '</p>
</div>' : '') . '
<div class="tl_listing_container parent_view' . ($this->strPickerFieldType ? ' picker unselectable' : '') . '" id="tl_listing">
<div class="tl_listing_container parent_view' . ($this->strPickerFieldType ? ' picker unselectable' : '') . '" id="tl_listing"' . $prevPickerValue . '>
<div class="tl_header click2edit toggle_select hover-div">';

// List all records of the child table
Expand Down Expand Up @@ -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') ? '
<form id="tl_select" class="tl_form' . ((Input::get('act') == 'select') ? ' unselectable' : '') . '" method="post" novalidate>
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_select">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' : '') . '
<div class="tl_listing_container list_view" id="tl_listing">' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
<div class="tl_listing_container list_view" id="tl_listing"' . $prevPickerValue . '>' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
<div class="tl_select_trigger">
<label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">
</div>' : '') . '
Expand Down
29 changes: 21 additions & 8 deletions src/Resources/contao/library/Contao/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace Contao;

use Symfony\Component\Filesystem\Filesystem;
use Webmozart\PathUtil\Path;

/**
* Loads and writes the local configuration file
*
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions src/Resources/public/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<inp.length; i++) {
if (inp[i].checked && !inp[i].id.match(/^(check_all_|reset_)/)) {
val.push(inp[i].get('value'));
if (inp[i].id.match(/^(check_all_|reset_)/)) {
continue;
}
// Add currently selected value, otherwise remove (#1816)
sIndex = val.indexOf(inp[i].get('value'));
if (inp[i].checked) {
if (sIndex == -1) {
val.push(inp[i].get('value'));
}
} else if (sIndex != -1) {
val.splice(sIndex, 1);
}
}
if (opt.callback) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/core.min.js

Large diffs are not rendered by default.

0 comments on commit ac00969

Please sign in to comment.