mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 09:44:38 +02:00
Fix issue reported by @olafgleba in processwire/processwire-issues#1497 where image variation list wouldn't delete corresponding webp extras when jpg/png variation deleted and webpAdd option used.
This commit is contained in:
@@ -168,6 +168,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
foreach(self::$defaultConfig as $key => $value) $this->set($key, $value);
|
foreach(self::$defaultConfig as $key => $value) $this->set($key, $value);
|
||||||
$this->labels = array(
|
$this->labels = array(
|
||||||
'width' => $this->_('Width:'),
|
'width' => $this->_('Width:'),
|
||||||
@@ -1418,6 +1419,13 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
*/
|
*/
|
||||||
public function ___executeVariations() {
|
public function ___executeVariations() {
|
||||||
|
|
||||||
|
$files = $this->wire()->files;
|
||||||
|
$modules = $this->wire()->modules;
|
||||||
|
$user = $this->wire()->user;
|
||||||
|
$input = $this->wire()->input;
|
||||||
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
|
$pages = $this->wire()->pages;
|
||||||
|
$config = $this->wire()->config;
|
||||||
$pageimage = $this->getPageimage();
|
$pageimage = $this->getPageimage();
|
||||||
|
|
||||||
if(!$this->page || !$pageimage) throw new WireException("No file provided");
|
if(!$this->page || !$pageimage) throw new WireException("No file provided");
|
||||||
@@ -1434,22 +1442,38 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
$url = $pageimage->url() . "?nc=$mtime";
|
$url = $pageimage->url() . "?nc=$mtime";
|
||||||
$originalLabel = $this->_('Original');
|
$originalLabel = $this->_('Original');
|
||||||
$extraLabel = $this->_('%s of above');
|
$extraLabel = $this->_('%s of above');
|
||||||
$hasEditPermission = $this->wire('user')->hasPermission('page-edit-images', $this->masterPage);
|
$hasEditPermission = $user->hasPermission('page-edit-images', $this->masterPage);
|
||||||
$variations = $pageimage->getVariations(array('info' => true, 'verbose' => 1));
|
$variations = $pageimage->getVariations(array('info' => true, 'verbose' => 1));
|
||||||
$adminThumbOptions = $this->wire('config')->adminThumbOptions;
|
$adminThumbOptions = $config->adminThumbOptions;
|
||||||
$delete = $this->wire('input')->post('delete');
|
$delete = $input->post('delete');
|
||||||
|
|
||||||
if(is_array($delete) && count($delete) && $hasEditPermission) {
|
if(is_array($delete) && count($delete) && $hasEditPermission) {
|
||||||
|
$deleteUrls = array();
|
||||||
|
$deleteErrors = array();
|
||||||
foreach($delete as $name) {
|
foreach($delete as $name) {
|
||||||
if(!isset($variations[$name])) continue;
|
if(!isset($variations[$name])) continue;
|
||||||
$info = $variations[$name];
|
$info = $variations[$name];
|
||||||
if(is_file($info['path']) && $this->wire('files')->unlink($info['path'])) {
|
if($files->exists($info['path']) && $files->unlink($info['path'])) {
|
||||||
$this->message($this->_('Deleted image variation') . " - $info[url]");
|
$deleteUrls[] = $info['url'];
|
||||||
|
if(!empty($info['webpPath']) && $files->exists($info['webpPath'])) {
|
||||||
|
if($files->unlink($info['webpPath'])) {
|
||||||
|
$deleteUrls[] = $info['webpUrl'];
|
||||||
|
} else {
|
||||||
|
$deleteErrors[] = $info['webpUrl'];
|
||||||
|
}
|
||||||
|
}
|
||||||
unset($variations[$name]);
|
unset($variations[$name]);
|
||||||
} else {
|
} else {
|
||||||
$this->error($this->_('Error deleting image variation') . " - $info[url]");
|
$deleteErrors[] = $info['url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach($deleteUrls as $url) {
|
||||||
|
$this->message($this->_('Deleted image variation') . " - $url");
|
||||||
|
}
|
||||||
|
foreach($deleteErrors as $url) {
|
||||||
|
$this->error($this->_('Error deleting image variation') . " - $url");
|
||||||
|
}
|
||||||
|
$this->wire()->session->redirect("./?id={$this->page->id}&file=$pageimage->basename");
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
@@ -1506,8 +1530,8 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
if(strpos($suffix, 'pid') === 0) {
|
if(strpos($suffix, 'pid') === 0) {
|
||||||
$suffix = ltrim($suffix, 'pid');
|
$suffix = ltrim($suffix, 'pid');
|
||||||
$refpage = null;
|
$refpage = null;
|
||||||
if(ctype_digit($suffix)) $refpage = $this->wire('pages')->get((int) $suffix);
|
if(ctype_digit($suffix)) $refpage = $pages->get((int) $suffix);
|
||||||
if($refpage && $refpage->id && $this->wire('user')->hasPermission('page-view', $refpage)) {
|
if($refpage && $refpage->id && $user->hasPermission('page-view', $refpage)) {
|
||||||
$notes[] = $this->_x('Inserted from page:', 'notes') . " <a target='_blank' href='$refpage->url'>$refpage->path</a>";
|
$notes[] = $this->_x('Inserted from page:', 'notes') . " <a target='_blank' href='$refpage->url'>$refpage->path</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1516,8 +1540,6 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
$width = (int) $info['width'];
|
$width = (int) $info['width'];
|
||||||
$height = (int) $info['height'];
|
$height = (int) $info['height'];
|
||||||
if(!$width || !$height) list($width, $height) = getimagesize($info['path']);
|
if(!$width || !$height) list($width, $height) = getimagesize($info['path']);
|
||||||
// $dimensions = $width . 'x' . $height;
|
|
||||||
// if(in_array('hidpi', $info['suffix'])) $dimensions .= " ($info[hidpiWidth]x$info[hidpiHeight] {$this->labels['hidpi']})";
|
|
||||||
$filesize = filesize($info['path']);
|
$filesize = filesize($info['path']);
|
||||||
$filesizeStr = wireBytesStr($filesize);
|
$filesizeStr = wireBytesStr($filesize);
|
||||||
$mtime = filemtime($info['path']);
|
$mtime = filemtime($info['path']);
|
||||||
@@ -1567,14 +1589,14 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var InputfieldCheckbox $checkbox */
|
/** @var InputfieldCheckbox $checkbox */
|
||||||
$checkbox = $this->wire('modules')->get('InputfieldCheckbox');
|
$checkbox = $modules->get('InputfieldCheckbox');
|
||||||
$checkbox->label = ' ';
|
$checkbox->label = ' ';
|
||||||
$checkbox->addClass('delete');
|
$checkbox->addClass('delete');
|
||||||
$checkbox->attr('id+name', 'delete_all');
|
$checkbox->attr('id+name', 'delete_all');
|
||||||
$checkbox->val(1);
|
$checkbox->val(1);
|
||||||
|
|
||||||
/** @var MarkupAdminDataTable $table */
|
/** @var MarkupAdminDataTable $table */
|
||||||
$table = $this->wire('modules')->get('MarkupAdminDataTable');
|
$table = $modules->get('MarkupAdminDataTable');
|
||||||
$table->setEncodeEntities(false);
|
$table->setEncodeEntities(false);
|
||||||
$table->headerRow(array(
|
$table->headerRow(array(
|
||||||
'#',
|
'#',
|
||||||
@@ -1597,7 +1619,6 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
"<span style='display: none;'>$row[filesize] </span>$row[filesizeStr]",
|
"<span style='display: none;'>$row[filesize] </span>$row[filesizeStr]",
|
||||||
$row['modified'],
|
$row['modified'],
|
||||||
implode('<br />', $row['notes']),
|
implode('<br />', $row['notes']),
|
||||||
//($hasEditPermission ? "<label><input type='checkbox' class='delete' name='delete[]' value='$row[name]' /> </label>" : " ")
|
|
||||||
($row['cnt'] && $row['deletable'] ? $checkbox->render() : " ")
|
($row['cnt'] && $row['deletable'] ? $checkbox->render() : " ")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -1607,38 +1628,42 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
|||||||
$num, $pageimage->basename
|
$num, $pageimage->basename
|
||||||
));
|
));
|
||||||
|
|
||||||
$varcnt = $this->wire('sanitizer')->entities($this->wire('input')->get('varcnt'));
|
$varcnt = $sanitizer->entities($input->get('varcnt'));
|
||||||
|
|
||||||
$form = $this->wire('modules')->get('InputfieldForm');
|
/** @var InputfieldForm $form */
|
||||||
|
$form = $modules->get('InputfieldForm');
|
||||||
$form->attr('id', 'ImageVariations');
|
$form->attr('id', 'ImageVariations');
|
||||||
$form->action = "./?id={$this->page->id}&file=$pageimage->basename&varcnt=$varcnt";
|
$form->action = "./?id={$this->page->id}&file=$pageimage->basename&varcnt=$varcnt";
|
||||||
$form->prependMarkup = $table->render();
|
$form->prependMarkup = $table->render();
|
||||||
|
|
||||||
if($hasEditPermission) {
|
if($hasEditPermission) {
|
||||||
$submit = $this->wire('modules')->get('InputfieldSubmit');
|
/** @var InputfieldSubmit $submit */
|
||||||
|
$submit = $modules->get('InputfieldSubmit');
|
||||||
$submit->attr('value', $this->_('Delete Checked'));
|
$submit->attr('value', $this->_('Delete Checked'));
|
||||||
$submit->addClass('delete-checked');
|
$submit->addClass('delete-checked');
|
||||||
$submit->icon = 'trash';
|
$submit->icon = 'trash';
|
||||||
$form->add($submit);
|
$form->add($submit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$button = $this->wire('modules')->get('InputfieldButton');
|
/** @var InputfieldButton $button */
|
||||||
|
$button = $modules->get('InputfieldButton');
|
||||||
$button->attr('value', $this->_('Close'));
|
$button->attr('value', $this->_('Close'));
|
||||||
$button->addClass('pw-modal-cancel');
|
$button->addClass('pw-modal-cancel');
|
||||||
$button->icon = 'times-circle';
|
$button->icon = 'times-circle';
|
||||||
$form->add($button);
|
$form->add($button);
|
||||||
|
|
||||||
$hidden = $this->wire('modules')->get('InputfieldHidden');
|
/** @var InputfieldHidden $hidden */
|
||||||
|
$hidden = $modules->get('InputfieldHidden');
|
||||||
$hidden->attr('id+name', 'varcnt_id');
|
$hidden->attr('id+name', 'varcnt_id');
|
||||||
$hidden->attr('value', $varcnt);
|
$hidden->attr('value', $varcnt);
|
||||||
$hidden->attr('data-cnt', count($variations));
|
$hidden->attr('data-cnt', count($variations));
|
||||||
$form->add($hidden);
|
$form->add($hidden);
|
||||||
|
|
||||||
$this->wire('modules')->get('JqueryMagnific');
|
$modules->get('JqueryMagnific');
|
||||||
|
|
||||||
$out = $form->render();
|
$out = $form->render();
|
||||||
|
|
||||||
if($this->wire('config')->demo) {
|
if($config->demo) {
|
||||||
$out = "<p class='detail'>Note: " . $this->labels['demoMode'] . "</p>" . $out;
|
$out = "<p class='detail'>Note: " . $this->labels['demoMode'] . "</p>" . $out;
|
||||||
} else {
|
} else {
|
||||||
$out = "<br />" . $out;
|
$out = "<br />" . $out;
|
||||||
|
Reference in New Issue
Block a user