Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type_image_prefs.inc
1 <?php
18 require_once SQ_LIB_PATH.'/config/prefs.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/css_dimension/css_dimension.inc';
20 
33 {
34 
35  var $pref_vars = Array (
36  'SQ_CONTENT_TYPE_IMAGE_DEFAULTS' => Array(
37  'name' => 'image_defaults_title',
38  'description' => 'This preference allows you to change the default values',
39  'default' => Array(
40  'caption' => 'Caption',
41  'caption_position' => 'bottom',
42  'use_caption_attr' => FALSE,
43  'width' => '400',
44  'height' => '400',
45  'fit_dimensions' => TRUE,
46  'constrain_proportions' => TRUE,
47  'on_click' => 'none',
48  'html_layout' => 'table',
49  ),
50  'protected' => FALSE,
51  ),
52  'SQ_CONTENT_TYPE_IMAGE_FIELDS' => Array(
53  'name' => 'image_fields_title',
54  'description' => 'This preference allows you to specify which fields are displayed',
55  'default' => Array(
56  'caption_options' => TRUE,
57  'caption_position' => TRUE,
58  'dimension_options' => TRUE,
59  'on_click' => TRUE,
60  'html_layout' => TRUE,
61  ),
62  'protected' => FALSE,
63  ),
64  'SQ_CONTENT_TYPE_IMAGE_CLASSES' => Array(
65  'name' => 'image_css_classes',
66  'description' => 'This preference allows you to specify how the image is displayed',
67  'default' => Array(
68  'surrounding_container' => 'image_table',
69  'image_table_cell' => 'image_table_cell',
70  'caption_table_cell' => 'caption_table_cell',
71  'image_tag' => 'inline_image',
72  'image_div' => 'image_div',
73  'caption_div' => 'caption_div',
74  ),
75  'protected' => FALSE,
76  ),
77  'SQ_CONTENT_TYPE_IMAGE_PREVIEW' => Array(
78  'name' => 'image_preview_css_classes',
79  'description' => 'This preference allows you to specify how the image is displayed',
80  'default' => Array(
81  'surrounding_container' => 'preview_container',
82  'preview_image_table' => 'preview_image_table',
83  'image_table_cell' => 'image_table_cell',
84  'image_tag' => 'preview_image',
85  'close_preview_cell' => 'close_cell',
86  'image_div' => 'preview_image_div',
87  'close_preview_div' => 'close_preview_div',
88  ),
89  'protected' => FALSE,
90  ),
91  );
92 
93 
98  function Content_Type_Image_Prefs($pref_file='')
99  {
100 
101  $this->Prefs($pref_file);
102 
103  }//end constructor
104 
105 
116  function paintBackend(&$o, $have_lock, $pref=NULL)
117  {
118  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
119  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
120  // Images for readonly mode on checkboxes
121  $tick = '<img src="'.sq_web_path('lib').'/web/images/tick.gif" alt="Yes" style="position: relative; right: 0px;"/>';
122  $cross = '<img src="'.sq_web_path('lib').'/web/images/cross.gif" alt="Yes" />';
123  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_DEFAULTS') {
124  if (is_null($pref)) {
125  $o->openField(translate($this->pref_vars['SQ_CONTENT_TYPE_IMAGE_DEFAULTS']['name']));
126  }
127  $value_defaults = $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_DEFAULTS']['default'];
128  ?>
129  <table class="sq-backend-table" style="width: 350px;">
130  <tr>
131  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('caption'); ?>:</td>
132  <td class="sq-backend-table-cell" nowrap="nowrap">
133  <?php
134  if ($have_lock && $is_admin) {
135  text_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[caption]', array_get_index($value_defaults, 'caption', ''), '30');
136  } else {
137  echo $value_defaults['caption'];
138  }
139  ?>
140  </td>
141  </tr>
142  <tr>
143  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('caption_position'); ?>:</td>
144  <td class="sq-backend-table-cell" nowrap="nowrap">
145  <?php
146  if ($have_lock && $is_admin) {
147  combo_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[caption_position]', Array('bottom' => 'Bottom', 'top' => 'Top'), FALSE, array_get_index($value_defaults, 'caption_position', ''));
148  } else {
149  echo ucwords($value_defaults['caption_position']);
150  }
151  ?>
152  </td>
153  </tr>
154  <tr>
155  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('use_caption_attribute'); ?>:</td>
156  <td class="sq-backend-table-cell" nowrap="nowrap">
157  <?php
158  if ($have_lock && $is_admin) {
159  check_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[use_caption_attr]', '1', array_get_index($value_defaults, 'use_caption_attr', FALSE));
160  } else {
161  echo ($value_defaults['use_caption_attr'] == TRUE) ? $tick : $cross;
162  }
163  ?>
164  </td>
165  </tr>
166  <tr>
167  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('width'); ?>:</td>
168  <td class="sq-backend-table-cell" nowrap="nowrap">
169  <?php
170  if ($have_lock && $is_admin) {
171  text_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[width]', array_get_index($value_defaults, 'width', ''), '10');
172  } else {
173  echo $value_defaults['width'];
174  }
175  ?>
176  </td>
177  </tr>
178  <tr>
179  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('height'); ?>:</td>
180  <td class="sq-backend-table-cell" nowrap="nowrap">
181  <?php
182  if ($have_lock && $is_admin) {
183  text_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[height]', array_get_index($value_defaults, 'height', ''), '10');
184  } else {
185  echo $value_defaults['height'];
186  }
187  ?>
188  </td>
189  </tr>
190  <tr>
191  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('constrain_proportions'); ?>:</td>
192  <td class="sq-backend-table-cell" nowrap="nowrap">
193  <?php
194  if ($have_lock && $is_admin) {
195  check_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[constrain_proportions]', '1', array_get_index($value_defaults, 'constrain_proportions', FALSE));
196  } else {
197  echo (array_get_index($value_defaults, 'constrain_proportions', FALSE) == TRUE) ? $tick : $cross;
198  }
199  ?>
200  </td>
201  </tr>
202  <tr>
203  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('fit_dimensions'); ?>:</td>
204  <td class="sq-backend-table-cell" nowrap="nowrap">
205  <?php
206  if ($have_lock && $is_admin) {
207  check_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[fit_dimensions]', '1', array_get_index($value_defaults, 'fit_dimensions', FALSE));
208  } else {
209  echo (array_get_index($value_defaults, 'fit_dimensions', FALSE) == TRUE) ? $tick : $cross;
210  }
211  ?>
212  </td>
213  </tr>
214  <tr>
215  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('on_click'); ?>:</td>
216  <td class="sq-backend-table-cell" nowrap="nowrap">
217  <?php
218  if ($have_lock && $is_admin) {
219  $GLOBALS['SQ_SYSTEM']->am->includeAsset('content_type_image');
220  $dummy_asset = new Content_Type_Image();
221  $onclick = $dummy_asset->getAttribute('on_click');
222  $onclick->value = $value_defaults['on_click'];
223  $onclick->paint('content_type_image_on_click');
224  } else {
225  echo ucwords($value_defaults['on_click']);
226  }
227  ?>
228  </td>
229  </tr>
230  <tr>
231  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('html_layout'); ?>:</td>
232  <td class="sq-backend-table-cell" nowrap="nowrap">
233  <?php
234  if ($have_lock && $is_admin) {
235  combo_box('SQ_CONTENT_TYPE_IMAGE_DEFAULTS[html_layout]', Array('table' => 'Table', 'div' => 'Div'), FALSE, array_get_index($value_defaults, 'html_layout', ''));
236  } else {
237  echo ucwords($value_defaults['html_layout']);
238  }
239  ?>
240  </td>
241  </tr>
242  </table>
243  <?php
244  if (is_null($pref)) $o->closeField();
245  }//end if
246  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_FIELDS') {
247  if (is_null($pref)) {
248  $o->openField(translate($this->pref_vars['SQ_CONTENT_TYPE_IMAGE_FIELDS']['name']));
249  }
250  $fields = $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_FIELDS']['default'];
251  ?>
252  <table class="sq-backend-table" style="width: 200px;">
253  <?php
254  foreach ($fields as $field_name => $value) {
255  ?>
256  <tr>
257  <td class="sq-backend-table-cell" nowrap="nowrap">
258  <?php
259  if ($have_lock && $is_admin) {
260  check_box('SQ_CONTENT_TYPE_IMAGE_FIELDS['.$field_name.']', '1', $value, '', 'id="image_content_'.$field_name.'"');
261  label(ucwords(str_replace('_', ' ', $field_name)), 'image_content_'.$field_name);
262  } else {
263  echo ($value == TRUE) ? $tick : $cross;
264  ?>
265  &nbsp;&nbsp;&nbsp;
266  <?php
267  echo ucwords(str_replace('_', ' ', $field_name));
268  }
269  ?>
270  </td>
271  </tr>
272  <?php
273  }
274  ?>
275  </table>
276  <?php
277  }//end if
278  if (is_null($pref)) $o->closeField();
279  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_CLASSES') {
280  if (is_null($pref)) {
281  $o->openField(translate($this->pref_vars['SQ_CONTENT_TYPE_IMAGE_CLASSES']['name']));
282  }
283  $classes = $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_CLASSES']['default'];
284  ?>
285  <table class="sq-backend-table" style="width: 350px;">
286  <?php
287  foreach ($classes as $name => $class) {
288  ?>
289  <tr>
290  <td class="sq-backend-table-header"><?php echo ucwords(str_replace('_', ' ', $name)); ?></td>
291  <td class="sq-backend-table-cell" nowrap="nowrap">
292  <?php
293  if ($have_lock && $is_admin) {
294  text_box('SQ_CONTENT_TYPE_IMAGE_CLASSES['.$name.']', $class);
295  } else {
296  echo $class;
297  }
298  ?>
299  </td>
300  </tr>
301  <?php
302  }
303  ?>
304  </table>
305  <?php
306  }//end if
307  if (is_null($pref)) $o->closeField();
308 
309  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_PREVIEW') {
310  if (is_null($pref)) {
311  $o->openField(translate($this->pref_vars['SQ_CONTENT_TYPE_IMAGE_PREVIEW']['name']));
312  }
313  $classes = $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_PREVIEW']['default'];
314  ?>
315  <table class="sq-backend-table" style="width: 350px;">
316  <?php
317  foreach ($classes as $name => $class) {
318  ?>
319  <tr>
320  <td class="sq-backend-table-header"><?php echo ucwords(str_replace('_', ' ', $name)); ?></td>
321  <td class="sq-backend-table-cell" nowrap="nowrap">
322  <?php
323  if ($have_lock && $is_admin) {
324  text_box('SQ_CONTENT_TYPE_IMAGE_PREVIEW['.$name.']', $class);
325  } else {
326  echo $class;
327  }
328  ?>
329  </td>
330  </tr>
331  <?php
332  }
333  ?>
334  </table>
335  <?php
336  }//end if
337  if (is_null($pref)) $o->closeField();
338 
339 
340  return TRUE;
341 
342  }//end paintBackend()
343 
344 
355  function processBackend(&$o, $have_lock, $pref=NULL)
356  {
357  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
358  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
359  if (!$is_admin) return FALSE;
360 
361  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_DEFAULTS') {
362  $posted_values = $_POST['SQ_CONTENT_TYPE_IMAGE_DEFAULTS'];
363  if (!isset($posted_values['use_caption_attr'])) {
364  $posted_values['use_caption_attr'] = FALSE;
365  }
366  if (!isset($posted_values['fit_dimensions'])) {
367  $posted_values['fit_dimensions'] = FALSE;
368  }
369  if (!isset($posted_values['constrain_proportions'])) {
370  $posted_values['constrain_proportions'] = FALSE;
371  }
372  $GLOBALS['SQ_SYSTEM']->am->includeAsset('content_type_image');
373  $dummy_asset = new Content_Type_Image();
374  $onclick = $dummy_asset->getAttribute('on_click');
375  $onclick->process('content_type_image_on_click');
376  $posted_values['on_click'] = $onclick->value;
377  $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_DEFAULTS']['default'] = $posted_values;
378  }
379  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_FIELDS') {
380  foreach ($this->pref_vars['SQ_CONTENT_TYPE_IMAGE_FIELDS']['default'] as $name => $val) {
381  $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_FIELDS']['default'][$name] = isset($_POST['SQ_CONTENT_TYPE_IMAGE_FIELDS'][$name]);
382  }
383  }
384  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_CLASSES') {
385  $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_CLASSES']['default'] = $_POST['SQ_CONTENT_TYPE_IMAGE_CLASSES'];
386  }
387  if (is_null($pref) || $pref == 'SQ_CONTENT_TYPE_IMAGE_PREVIEW') {
388  $this->pref_vars['SQ_CONTENT_TYPE_IMAGE_PREVIEW']['default'] = $_POST['SQ_CONTENT_TYPE_IMAGE_PREVIEW'];
389  }
390  return TRUE;
391 
392  }//end processBackend()
393 
394 
395 }//end class
396 
397 ?>