Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type_code_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/content_type/content_type_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
55  function paintBackend(&$asset, $prefix)
56  {
57  if ($asset->writeAccess('attributes')) {
58  $size = $GLOBALS['SQ_SYSTEM']->getUserPrefs($asset->type(), 'SQ_CODE_EDITOR_SIZE');
59  $html = $asset->attr('edit_content');
60  $html = str_replace('&lt;?php', '<?php', $html);
61  $html = str_replace('&lt;script', '<script', $html);
62  text_area($prefix.'_html', $html, '', '', 0, 'style="width: '.$size['width'].'; height: '.$size['height'].'; font-family: \'Courier New\', Courier, monospace; display: block"');
63  $line_number_prefs = $GLOBALS['SQ_SYSTEM']->getUserPrefs($asset->type(), 'SQ_CODE_EDITOR_LINE_NUMBERS');
64  $current_line_settings = $asset->attr('line_numbers');
65  foreach ($current_line_settings as $name => $value) {
66  $line_number_prefs[$name] = $value;
67  }
68  ?>
69  <table class="sq-backend-table" style="width: 350px;">
70  <tr>
71  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
72  <?php echo translate('show_line_numbers'); ?>
73  </td>
74  <td class="sq-backend-table-cell" style="width: 100%;">
75  <?php
76  check_box($prefix.'_show_line_numbers', '1', $line_number_prefs['use_line_numbers']);
77  ?>
78  </td>
79  </tr>
80  <tr>
81  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
82  <?php echo translate('line_number_orientation'); ?>
83  </td>
84  <td class="sq-backend-table-cell" style="width: 100%;">
85  <?php
86  radio_button($prefix.'_line_number_left', 'left', $line_number_prefs['line_number_left'] == TRUE);
87  label(translate('left'), $prefix.'_line_number_left');
88  radio_button($prefix.'_line_number_left', 'right', $line_number_prefs['line_number_left'] == FALSE);
89  label(translate('right'), $prefix.'_line_number_left');
90  ?>
91  </td>
92  </tr>
93  <tr>
94  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
95  <?php echo translate('line_number_style'); ?>
96  </td>
97  <td class="sq-backend-table-cell" style="width: 100%;">
98  <?php
99  combo_box($prefix.'_line_style', Array('span'=>'Span','list'=>'List'), FALSE, $line_number_prefs['line_number_style']);
100  ?>
101  </td>
102  </tr>
103  <tr>
104  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
105  <?php echo translate('line_number_class'); ?>
106  </td>
107  <td class="sq-backend-table-cell" style="width: 100%;">
108  <?php
109  text_box($prefix.'_line_class', $line_number_prefs['line_number_class']);
110  ?>
111  </td>
112  </tr>
113  </table>
114  <?php
115  }//end if write access
116  return TRUE;
117 
118  }//end paintBackend()
119 
120 
131  function processBackend($link, &$asset, $prefix)
132  {
133  if ($asset->writeAccess('attributes')) {
134  $line_number_prefs = $GLOBALS['SQ_SYSTEM']->getUserPrefs($asset->type(), 'SQ_CODE_EDITOR_LINE_NUMBERS');
135  $new_line_data = Array();
136  // We only want to store new line number details, if they differ from the global prefs
137  if (isset($_POST[$prefix.'_show_line_numbers']) != $line_number_prefs['use_line_numbers']) {
138  $new_line_data['use_line_numbers'] = isset($_POST[$prefix.'_show_line_numbers']);
139  }
140  $side = FALSE;
141  if (isset($_POST[$prefix.'_line_number_left']) && $_POST[$prefix.'_line_number_left'] == 'left') {
142  $side = TRUE;
143  }
144  if ($side != $line_number_prefs['line_number_left']) {
145  $new_line_data['line_number_left'] = $side;
146  }
147  if (isset($_POST[$prefix.'_line_style']) && $_POST[$prefix.'_line_style'] != $line_number_prefs['line_number_style']) {
148  $new_line_data['line_number_style'] = $_POST[$prefix.'_line_style'];
149  } else {
150  $new_line_data['line_number_style'] = 'span';
151  }
152  $new_line_data['line_number_class'] = '';
153  if (isset($_POST[$prefix.'_line_class']) && $_POST[$prefix.'_line_class'] != $line_number_prefs['line_number_class']) {
154  $new_line_data['line_number_class'] = $_POST[$prefix.'_line_class'];
155  }
156  $asset->setAttrValue('line_numbers', $new_line_data);
157 
158  if (isset($_POST[$prefix.'_html'])) {
159  $html = $_POST[$prefix.'_html'];
160 
161  $asset->setAttrValue('edit_content', str_replace(Array('<script','<?php'), Array('&lt;script', '&lt;?php'), $html));
162 
163  $html = $asset->syntaxHighlight($html);
164 
165  $current_html = $asset->attr('html');
166  if ($html != $current_html) {
167  if (!$asset->setAttrValue('html', $html)) return FALSE;
168  }
169  }
170 
171  }//end if write access
172  return $asset->writeAccess('attributes');
173 
174  }//end processBackend()
175 
176 
187  function paint(&$asset, $editing=FALSE, $generating=FALSE)
188  {
189  // This may be changed to use the styles of the design, to show
190  // what it will look like. If $editing == TRUE, then we do this
191  $output = $asset->attr('html');
192  if ($generating) {
193  // escape dangerous content
194  require_once SQ_FUDGE_PATH.'/general/text.inc';
195  escape_php($output);
196  }
197  echo $output;
198 
199  }//end paint()
200 
201 
202 }//end class
203 
204 ?>