Skip to content

Commit

Permalink
Sanitize Widget's values
Browse files Browse the repository at this point in the history
This is required for Symphony 2.7.1

See symphonycms/symphonycms#2781

Picked from 63ae52b
  • Loading branch information
nitriques committed Jan 17, 2018
1 parent 7bc680e commit 38dfb25
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ public function createRecipeDuplicatorTemplate($mode = '0', $position = '-1', $v
$label = (!empty($values['name'])) ? $values['name'] : __('New Recipe');
$header->appendChild(new XMLElement('h4', '<strong>' . $label . '</strong> <span class="type">' . $modes[$mode] . '</span>'));
$li->appendChild($header);
$li->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][mode]", $mode, 'hidden'));
$li->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][mode]", General::sanitize($mode), 'hidden'));

$group = new XMLElement('div');
$group->setAttribute('class', 'two columns');

// Name
$label = Widget::Label(__('Name'), null, 'column');
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][name]", $values['name']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][name]", General::sanitize($values['name'])));
if(is_array($error) && isset($error['missing'])) {
$group->appendChild(Widget::Error($label, $error['missing']));
}
Expand All @@ -275,7 +275,7 @@ public function createRecipeDuplicatorTemplate($mode = '0', $position = '-1', $v
// Handle
$label_text = $mode === 'regex' ? __('Regular Expression') : __('Handle') . '<i>e.g. /image/{handle}/path/to/my-image.jpg</i>';
$label = Widget::Label(__($label_text), null, 'column');
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][url-parameter]", $values['url-parameter']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][url-parameter]", General::sanitize($values['url-parameter'])));
if(is_array($error) && isset($error['invalid'])) {
$group->appendChild(Widget::Error($label, $error['invalid']));
}
Expand All @@ -290,10 +290,10 @@ public function createRecipeDuplicatorTemplate($mode = '0', $position = '-1', $v
$group = new XMLElement('div');
$group->setAttribute('class', 'two columns');
$label = Widget::Label(__('Width'), null, 'column');
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][width]", $values['width']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][width]", General::sanitize($values['width'])));
$group->appendChild($label);
$label = Widget::Label(__('Height'), null, 'column');
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][height]", $values['height']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][height]", General::sanitize($values['height'])));
$group->appendChild($label);
$li->appendChild($group);
}
Expand All @@ -307,15 +307,15 @@ public function createRecipeDuplicatorTemplate($mode = '0', $position = '-1', $v
$group->appendChild($label);
$label = Widget::Label(__('Background Color'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][background]", $values['background']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][background]", General::sanitize($values['background'])));
$group->appendChild($label);
$li->appendChild($group);
}

// regex mode
if ($mode === 'regex') {
$label = Widget::Label(__('JIT Parameter'));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][jit-parameter]", $values['jit-parameter']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][jit-parameter]", General::sanitize($values['jit-parameter'])));
$li->appendChild($label);
}

Expand All @@ -325,7 +325,7 @@ public function createRecipeDuplicatorTemplate($mode = '0', $position = '-1', $v
if ($mode !== '0') {
$label = Widget::Label(__('Image quality'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][quality]", $values['quality']));
$label->appendChild(Widget::Input("jit_image_manipulation[recipes][{$position}][quality]", General::sanitize($values['quality'])));
$group->appendChild($label);
}
if ($mode !== 'regex') {
Expand Down Expand Up @@ -415,34 +415,40 @@ public function appendPreferences($context){
// checkbox to disable regular rules
$label = Widget::Label();
$input = Widget::Input('settings[image][disable_regular_rules]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('disable_regular_rules', 'image') == 'yes') $input->setAttribute('checked', 'checked');
if (Symphony::Configuration()->get('disable_regular_rules', 'image') == 'yes') {
$input->setAttribute('checked', 'checked');
}
$label->setValue($input->generate() . ' ' . __('Disable dynamic URLs and use named recipes only'));

$group->appendChild($label);

// checkbox to disable up-scaling
$label = Widget::Label();
$input = Widget::Input('settings[image][disable_upscaling]', 'yes', 'checkbox');
if (Symphony::Configuration()->get('disable_upscaling', 'image') == 'yes') $input->setAttribute('checked', 'checked');
if (Symphony::Configuration()->get('disable_upscaling', 'image') == 'yes') {
$input->setAttribute('checked', 'checked');
}
$label->setValue($input->generate() . ' ' . __('Disable upscaling of images beyond the original size'));
$group->appendChild($label);

// checkbox to diable proxy transformation of images
$label = Widget::Label();
$input = Widget::Input('settings[image][disable_proxy_transform]', 'yes', 'checkbox');
if (Symphony::Configuration()->get('disable_proxy_transform', 'image') == 'yes') $input->setAttribute('checked', 'checked');
if (Symphony::Configuration()->get('disable_proxy_transform', 'image') == 'yes') {
$input->setAttribute('checked', 'checked');
}
$label->setValue($input->generate() . ' ' . __('Prevent ISP proxy transformation'));
$group->appendChild($label);

// text input to allow external request origins
$label = Widget::Label(__('Add Cross-Origin Header'));
$input = Widget::Input('settings[image][allow_origin]', Symphony::Configuration()->get('allow_origin', 'image'));
$input = Widget::Input('settings[image][allow_origin]', General::sanitize(Symphony::Configuration()->get('allow_origin', 'image')));
$label->appendChild($input);
$group->appendChild($label);

// textarea for trusted sites
$label = Widget::Label(__('Trusted Sites'));
$label->appendChild(Widget::Textarea('jit_image_manipulation[trusted_external_sites]', 5, 50, $this->trusted()));
$label->appendChild(Widget::Textarea('jit_image_manipulation[trusted_external_sites]', 5, 50, General::sanitize($this->trusted())));

$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('Leave empty to disable external linking. Single rule per line. Add * at end for wild card matching.'), array('class' => 'help')));
Expand Down

0 comments on commit 38dfb25

Please sign in to comment.