Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_remote_content_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42  $this->static_screens['details']['force_unlock'] = FALSE;
43 
44  }//end constructor
45 
46 
57  function paintRewritingRestrictions(&$asset, &$o, $prefix)
58  {
59  $options = $asset->attr('url_rewriting_options');
60  $overall = 'none';
61  foreach ($options as $i => $v) {
62  if ($v) {
63  if ($i == 'all') {
64  $overall = 'all';
65  } else {
66  $overall = 'some';
67  }
68  break;
69  }
70  }
71 
72  if ($asset->writeAccess('attributes')) {
73 
74  radio_button($prefix.'_rewrite_type', 'none', ($overall == 'none'), '', 'id="'.$prefix.'_rewrite_type_none"');
75  label(translate('cms_remote_content_tunneling_rule_none'), $prefix.'_rewrite_type_none');
76  echo '<br />';
77 
78  radio_button($prefix.'_rewrite_type', 'all', ($overall == 'all'), '', 'id="'.$prefix.'_rewrite_type_all"');
79  label(translate('cms_remote_content_tunneling_rule_all'), $prefix.'_rewrite_type_all');
80  echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
81  echo translate('cms_remote_content_tunneling_rule_all_note');
82  echo '<br />';
83 
84  radio_button($prefix.'_rewrite_type', 'some', ($overall == 'some'), '', 'id="'.$prefix.'_rewrite_type_some"');
85  label(translate('cms_remote_content_tunneling_rule_some'), $prefix.'_rewrite_type_some');
86  echo '<br />';
87 
88  $pf = $prefix.'_rewrite_some_options';
89  ?>
90 
91  <div style="margin-left: 5ex" id="<?php echo $prefix; ?>_rewrite_type_some_options">
92  <input type="checkbox" name="<?php echo $pf; ?>[]" value="remote_url" id="<?php echo $pf; ?>_remote_url" <?php if ($options['remote_url']) echo 'checked="checked"'; ?> <?php if ($overall != 'some') echo 'disabled="disabled"'; ?> />
93  <label for="<?php echo $pf; ?>_remote_url"><?php echo translate('cms_remote_content_tunneling_option_remote_url'); ?></label>
94  <br />
95 
96  <input type="checkbox" name="<?php echo $pf; ?>[]" value="remote_domain" id="<?php echo $pf; ?>_remote_domain" <?php echo $options['remote_domain'] ? 'checked="checked"' : ''; ?> <?php if ($overall != 'some') echo 'disabled="disabled"'; ?> />
97  <label for="<?php echo $pf; ?>_remote_domain"><?php echo translate('cms_remote_content_tunneling_option_remote_domain'); ?></label>
98  <br />
99 
100  <input type="checkbox" name="<?php echo $pf; ?>[]" value="white_list" id="<?php echo $pf; ?>_white_list" <?php if ($options['white_list']) echo 'checked="checked"'; ?> <?php if ($overall != 'some') echo 'disabled="disabled"'; ?> />
101  <label for="<?php echo $pf; ?>_white_list"><?php echo translate('cms_remote_content_tunneling_option_white_list'); ?></label>
102  <br />
103  <textarea name="<?php echo $prefix.'_white_list'; ?>" onfocus="document.getElementById('<?php echo $pf; ?>_white_list').checked = true" <?php if ($overall != 'some') echo 'disabled="disabled"'; ?>><?php
104  $urls = $asset->attr('url_white_list');
105  echo (is_array($urls)) ? implode("\n", $urls) : '';
106  ?></textarea>
107  <br /><em>(Enter one URL per line)</em>
108  </div>
109 
110  <script type="text/javascript"><!--//<![CDATA[
111  var onclickfn = new Function("toggleOptionDisplay(this);");
112  var inputs = document.getElementsByName('<?php echo $prefix; ?>_rewrite_type');
113  for (var i=0; i < inputs.length; i++) {
114  inputs[i].onclick = onclickfn;
115  }
116  function toggleOptionDisplay(checkbox)
117  {
118  var siblings = document.getElementsByName(checkbox.name);
119  for (var j=0; j < siblings.length; j++) {
120  var container = document.getElementById(siblings[j].id+'_options');
121  if (container == null) continue;
122  var tags = ['INPUT', 'SELECT', 'TEXTAREA'];
123  for (t in tags) {
124  var inputs = container.getElementsByTagName(tags[t]);
125  for (var i=0; i < inputs.length; i++) {
126  inputs[i].disabled = (siblings[j] != checkbox);
127  }
128  }
129  }
130  }
131  //]]> -->
132  </script>
133  <?php
134  return TRUE;
135 
136  } else {
137 
138  // read only
139  echo translate('cms_remote_content_tunneling_rule_'.$overall);
140  if ($overall == 'some') {
141  echo '<ul style="margin-top: 3px">';
142  foreach (Array('remote_url', 'remote_domain', 'white_list') as $type) {
143  if ($options[$type]) {
144  echo '<li>'.translate('cms_remote_content_tunneling_option_'.$type);
145  if ($type == 'white_list') {
146  echo '<br />'.implode('<br />', $asset->attr('url_white_list'));
147  }
148  echo '</li>';
149  }
150  }
151  }
152  /*
153 
154  case 'all':
155  echo translate('page_remote_content_tunneling_rule_all'); // 'All URLs may be tunneled';
156  break;
157  case 'none':
158  echo translate('page_remote_content_tunneling_rule_'.$overall);'No URLs may be tunneled';
159  break;
160  case 'some':
161  echo 'Only the following URLs may be tunneled:';
162  break;
163  */
164  return FALSE;
165  }
166 
167 
168  }//end paintRewritingRestrictions()
169 
170 
181  function processRewritingRestrictions(&$asset, &$o, $prefix)
182  {
183  if ($asset->writeAccess()) {
184  $options = $asset->attr('url_rewriting_options');
185  if (isset($_POST[$prefix.'_white_list'])) {
186  $white_list = explode("\n", trim($_POST[$prefix.'_white_list']));
187  // strip off protocols if necessary
188  foreach ($white_list as $i => $v) {
189  if (empty($v)) unset($white_list[$i]);
190  if (FALSE !== ($x = strpos(substr($v, 0, 7), '://'))) {
191  $white_list[$i] = substr($v, $x+3);
192  }
193  }
194  $asset->setAttrValue('url_white_list', $white_list);
195  }
196  switch ($_POST[$prefix.'_rewrite_type']) {
197  case 'all':
198  foreach ($options as $i => $v) {
199  $options[$i] = FALSE;
200  }
201  $options['all'] = TRUE;
202  break;
203  case 'none':
204  foreach ($options as $i => $v) {
205  $options[$i] = FALSE;
206  }
207  break;
208  case 'some':
209  $posted_options = array_get_index($_POST, $prefix.'_rewrite_some_options', Array());
210  foreach ($options as $i => $v) {
211  $options[$i] = in_array($i, $posted_options);
212  }
213  if (empty($white_list)) {
214  $options['white_list'] = FALSE;
215  }
216  break;
217  }
218  $asset->setAttrValue('url_rewriting_options', $options);
219  return TRUE;
220 
221  }//end if write access
222 
223  return FALSE;
224 
225  }//end processRewritingRestrictions()
226 
227 
238  function paintPostVariableTable(&$asset, &$o, $prefix)
239  {
240  ob_start();
241  ?><table width="100%" class="sq-backend-table">
242  <tr>
243  <th>Name</th>
244  <th>Value</th><?php
245  if ($asset->writeAccess('attributes')) {
246  ?><th>Delete</th><?php
247  }
248  ?></tr><?php
249  foreach ($asset->attr('post_variables') as $index => $variable) {
250  ?><tr>
251  <td><?php echo $variable['name']; ?></td>
252  <td><?php echo $variable['value']; ?></td><?php
253  if ($asset->writeAccess('attributes')) {
254  ?><td><?php check_box($prefix.'_delete['.$index.']'); ?></td><?php
255  }
256  ?></tr><?php
257  }
258  ?></table><?php
259  echo ob_get_clean();
260 
261  return TRUE;
262 
263  }//end paintPostVariableTable()
264 
265 
276  function paintNewPostVariableInput(&$asset, &$o, $prefix)
277  {
278  if (!$asset->writeAccess('attributes')) return FALSE;
279 
280  ob_start();
281  text_box($prefix.'_name', '');
282  echo ' ';
283  text_box($prefix.'_value', '', 50);
284  echo ob_get_clean();
285 
286  return TRUE;
287 
288  }//end paintNewPostVariableInput()
289 
290 
301  function processNewPostVariableInput(&$asset, &$o, $prefix)
302  {
303  $post_variables = $asset->attr('post_variables');
304 
305  $delete_variables = Array();
306  if (isset($_POST[$prefix.'_delete'])) {
307  $delete_variables = array_keys($_POST[$prefix.'_delete']);
308  }
309 
310  // Delete any necessary variables
311  foreach ($delete_variables as $index) {
312  unset($post_variables[$index]);
313  }
314 
315  $create_variables = Array();
316  if (isset($_POST[$prefix.'_name']) && !empty($_POST[$prefix.'_name'])) {
317  $create_variables[trim($_POST[$prefix.'_name'])] = $_POST[$prefix.'_value'];
318  }
319 
320  // Create any new variables, overwriting any existing ones.
321  foreach ($create_variables as $name => $value) {
322  // Checks to see if this particular post variable has been specified already.
323  if (strpos(print_r($post_variables, TRUE), '[name] => '.$name."\n") === FALSE) {
324  // Yes, we use numerical index because post vars can have names like
325  // 'post_variable[name]', which would cause the delete checkboxes to break.
326  $post_variables[] = Array(
327  'name' => $name,
328  'value' => $value,
329  );
330  } else {
331  trigger_localised_error('CMS0059', E_USER_NOTICE);
332  }
333  }
334  return $asset->setAttrValue('post_variables', $post_variables);
335 
336  }//end processNewPostVariableInput()
337 
338 
349  function paintReplaceTagList(&$asset, &$o, $prefix)
350  {
351  $write_access = $asset->writeAccess('attributes');
352 
353  $tag_replacements = $asset->attr('tag_replacements');
354  if (!empty($tag_replacements) || $write_access) {
355  ?>
356  <table width="100%" class="sq-backend-table">
357  <tr><th><?php echo translate('cms_remote_content_tag'); ?></th><th><?php echo translate('cms_remote_content_start_tag'); ?></th><th><?php echo translate('cms_remote_content_end_tag'); ?></th><th><?php echo translate('cms_remote_content_remove_contents'); ?></th><?php echo (($write_access && !empty($tag_replacements)) ? '<th>'.translate('delete').'</th>' : ''); ?></tr>
358  <?php
359 
360  foreach ($tag_replacements as $tag => $tag_info) {
361  if ($write_access) {
362  ?>
363  <tr>
364  <td><?php text_box($prefix.'_tag_replacments[reps]['.$tag.'][tag]', $tag, 30); ?></td>
365  <td><?php text_box($prefix.'_tag_replacments[reps]['.$tag.'][start_tag]', $tag_info['start_tag'], 30); ?></td>
366  <td><?php text_box($prefix.'_tag_replacments[reps]['.$tag.'][end_tag]', $tag_info['end_tag'], 30); ?></td>
367  <td><?php check_box($prefix.'_tag_replacments[reps]['.$tag.'][remove_content]', TRUE, ($tag_info['remove_content'] ? TRUE : FALSE)); ?></td>
368  <td><?php check_box($prefix.'_tag_replacments[reps]['.$tag.'][delete]'); ?>
369  </tr>
370  <?php
371  } else {
372  ?>
373  <tr>
374  <td><?php echo htmlspecialchars($tag); ?></td>
375  <td><?php echo htmlspecialchars($tag_info['start_tag']); ?></td>
376  <td><?php echo htmlspecialchars($tag_info['end_tag']); ?></td>
377  <td><?php echo ($tag_info['remove_content'] ? translate('yes') : translate('no')); ?></td>
378  </tr>
379  <?php
380  }
381  }//end foreach
382  } else if (!$write_access) {
383  echo translate('cms_remote_content_no_tag_replacements');
384  }
385 
386  if ($write_access) {
387  ?>
388  <tr>
389  <td><?php text_box($prefix.'_tag_replacments[reps][new][tag]', '', 30); ?></td>
390  <td><?php text_box($prefix.'_tag_replacments[reps][new][start_tag]', '', 30); ?></td>
391  <td><?php text_box($prefix.'_tag_replacments[reps][new][end_tag]', '', 30); ?></td>
392  <td><?php check_box($prefix.'_tag_replacments[reps][new][remove_content]'); ?></td>
393  <?php echo (!empty($tag_replacements) ? '<td>&nbsp;</td>' : ''); ?>
394  </tr>
395  <?php
396  }
397  ?>
398  </table>
399  <?php
400 
401  }//end paintReplaceTagList()
402 
403 
414  function processReplaceTagList(&$asset, &$o, $prefix)
415  {
416  $reps = $_POST[$prefix.'_tag_replacments']['reps'];
417 
418  $replacements = Array();
419  foreach ($reps as $rep_info) {
420  if (isset($rep_info['delete']) || empty($rep_info['tag'])) {
421  continue;
422  }
423 
424  $remove_content = FALSE;
425  if (isset($rep_info['remove_content'])) {
426  $remove_content = TRUE;
427  }
428 
429  $replacements[$rep_info['tag']] = Array(
430  'start_tag' => $rep_info['start_tag'],
431  'end_tag' => $rep_info['end_tag'],
432  'remove_content' => $remove_content,
433  );
434  }
435 
436  if (!$asset->setAttrValue('tag_replacements', $replacements)) {
437  return FALSE;
438  }
439 
440  return TRUE;
441 
442  }//end processReplaceTagList()
443 
444 
445 }//end class
446 
447 ?>