17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
55 public static function execute($settings, &$state)
57 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
59 if (empty($state[
'asset'])) {
61 if (empty($state[
'assetid'])) {
64 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
69 if (!($state[
'asset'] instanceof
Image)) {
70 trigger_error(
'Unable to create image variety for a '.$state[
'asset']->
type().
' asset', E_USER_NOTICE);
74 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'image_variety');
77 $variety->setAttrValue(
'variety_type',
'resize');
82 if (!@$variety->setAttrValue(
'name', $settings[
'name'])) {
87 if (!@$variety->setAttrValue(
'constrain', $settings[
'constrain'])) {
92 if (!@$variety->setAttrValue(
'width', $settings[
'width'])) {
97 if (!@$variety->setAttrValue(
'height', $settings[
'height'])) {
102 $vid = $state[
'asset']->saveVariety($variety);
105 'imageid' => $state[
'asset']->
id,
106 'varietyid' => $state[
'asset']->
id.
':'.$vid,
107 'name' => $variety->name,
108 'width' => $variety->attr(
'width'),
109 'height' => $variety->attr(
'height'),
125 public static function getInterface($settings, $prefix, $write_access=FALSE)
128 $settings[
'name'] = array_get_index($settings,
'name',
'');
129 $settings[
'constrain'] = (string) array_get_index($settings,
'constrain',
'width');
130 $settings[
'width'] = array_get_index($settings,
'width', 0);
131 $settings[
'height'] = array_get_index($settings,
'height', 0);
132 $width_display_style =
'none';
133 $width_section_display_style =
'none';
134 $height_display_style =
'none';
135 $height_section_display_style =
'none';
136 $dimension_display_style =
'none';
138 switch ($settings[
'constrain']) {
140 $width_display_style =
'inline';
141 $width_section_display_style =
'block';
142 $height_display_style =
'none';
143 $height_section_display_style =
'none';
144 $dimension_display_style =
'none';
148 $width_display_style =
'none';
149 $width_section_display_style =
'none';
150 $height_display_style =
'inline';
151 $height_section_display_style =
'block';
152 $dimension_display_style =
'none';
156 $width_display_style =
'none';
157 $width_section_display_style =
'none';
158 $height_display_style =
'none';
159 $height_section_display_style =
'block';
160 $dimension_display_style =
'inline';
164 $width_display_style =
'inline';
165 $width_section_display_style =
'block';
166 $height_display_style =
'inline';
167 $height_section_display_style =
'block';
168 $dimension_display_style =
'none';
175 text_box($prefix.
'[name]', $settings[
'name']);
177 echo $settings[
'name'];
179 $basic_part_1 = ob_get_contents();
184 echo translate(
'trigger_create_image_variety_basic', $basic_part_1);
187 $js_prefix = preg_replace(
'/[^a-z0-9_]/',
'_', $prefix);
189 <script
type=
"text/javascript">
192 function <?php echo $js_prefix; ?>_update_visible_fields() {
194 var constrain = get_form_element_value(
"<?php echo $prefix; ?>[constrain]");
195 if (constrain ==
'width') {
196 document.getElementById(
"<?php echo $prefix; ?>_width_section").style.display =
"block";
197 document.getElementById(
"<?php echo $prefix; ?>_width_label").style.display =
"inline";
198 document.getElementById(
"<?php echo $prefix; ?>_height_section").style.display =
"none";
199 document.getElementById(
"<?php echo $prefix; ?>_height_label").style.display =
"none";
200 document.getElementById(
"<?php echo $prefix; ?>_dimension_label").style.display =
"none";
201 }
else if (constrain ==
'height') {
202 document.getElementById(
"<?php echo $prefix; ?>_width_section").style.display =
"none";
203 document.getElementById(
"<?php echo $prefix; ?>_width_label").style.display =
"none";
204 document.getElementById(
"<?php echo $prefix; ?>_height_section").style.display =
"block";
205 document.getElementById(
"<?php echo $prefix; ?>_height_label").style.display =
"inline";
206 document.getElementById(
"<?php echo $prefix; ?>_dimension_label").style.display =
"none";
207 }
else if (constrain ==
'dimension') {
208 document.getElementById(
"<?php echo $prefix; ?>_width_section").style.display =
"none";
209 document.getElementById(
"<?php echo $prefix; ?>_width_label").style.display =
"none";
210 document.getElementById(
"<?php echo $prefix; ?>_height_section").style.display =
"block";
211 document.getElementById(
"<?php echo $prefix; ?>_height_label").style.display =
"none";
212 document.getElementById(
"<?php echo $prefix; ?>_dimension_label").style.display =
"inline";
213 }
else if (constrain ==
'none') {
214 document.getElementById(
"<?php echo $prefix; ?>_width_section").style.display =
"block";
215 document.getElementById(
"<?php echo $prefix; ?>_width_label").style.display =
"inline";
216 document.getElementById(
"<?php echo $prefix; ?>_height_section").style.display =
"block";
217 document.getElementById(
"<?php echo $prefix; ?>_height_label").style.display =
"inline";
218 document.getElementById(
"<?php echo $prefix; ?>_dimension_label").style.display =
"none";
227 $javascript =
'onchange="return '.$js_prefix.
'_update_visible_fields();"';
229 'width' => translate(
'width'),
230 'height' => translate(
'height'),
231 'dimension' => translate(
'both'),
232 'none' => translate(
'neither'),
234 echo translate(
'constrain_by').
' ';
236 combo_box($prefix.
'[constrain]', $options, FALSE, $settings[
'constrain'], 0, $javascript);
238 echo $options[$settings[
'constrain']];
242 echo
'<div id="'.$prefix.
'_width_section" style="display:'.$width_section_display_style.
'">';
243 echo
'<span id="'.$prefix.
'_width_label" style="display:'.$width_display_style.
'">';
244 echo translate(
'width');
245 echo
' </span>';
247 int_text_box($prefix.
'[width]', $settings[
'width'], FALSE);
249 echo $settings[
'width'];
253 echo
'<div id="'.$prefix.
'_height_section" style="display:'.$height_section_display_style.
'">';
254 echo
'<span id="'.$prefix.
'_height_label" style="display:'.$height_display_style.
'">';
255 echo translate(
'height');
257 echo
'<span id="'.$prefix.
'_dimension_label" style="display:'.$dimension_display_style.
'">';
258 echo translate(
'dimension');
261 int_text_box($prefix.
'[height]', $settings[
'height'], FALSE);
263 echo $settings[
'height'];
267 $html = ob_get_contents();
288 if (empty($request_data)) {
289 return translate(
'trigger_input_data_missing');
293 if (empty($request_data[
'name'])) {
294 return translate(
'trigger_variety_name_cannot_be_empty');
297 if (!isset($request_data[
'constrain']) || !isset($request_data[
'width']) || !isset($request_data[
'height'])) {
298 return translate(
'trigger_require_constrain_width_height');
301 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'image_variety');
304 $variety->setAttrValue(
'variety_type',
'resize');
307 if (!$variety->setAttrValue(
'name', $request_data[
'name'])) {
308 return translate(
'trigger_cannot_set_variety_value', translate(
'name'));
312 if (!$variety->setAttrValue(
'constrain', $request_data[
'constrain'])) {
313 return translate(
'trigger_cannot_set_variety_value', translate(
'constrain'));
317 if (!$variety->setAttrValue(
'width', $request_data[
'width'])) {
318 return translate(
'trigger_cannot_set_variety_value', translate(
'width'));
322 if (!$variety->setAttrValue(
'height', $request_data[
'height'])) {
323 return translate(
'trigger_cannot_set_variety_value', translate(
'height'));
329 $settings[
'name'] = $request_data[
'name'];
330 $settings[
'constrain'] = $request_data[
'constrain'];
331 $settings[
'width'] = strval($request_data[
'width']);
332 $settings[
'height'] = strval($request_data[
'height']);
348 public static function getLocks($settings, &$state)
350 return Array($state[
'assetid'] => Array(
'all'));