Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type_code_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_CODE_EDITOR_SIZE' => Array(
37  'name' => 'code_editor_size',
38  'description' => 'This preference allows you to change the size of the Raw HTML editor',
39  'default' => Array('width' => '400', 'height' => '400'),
40  'protected' => FALSE,
41  ),
42  'SQ_CODE_EDITOR_HTML_CLASSES' => Array(
43  'name' => 'html_code_classes',
44  'description' => 'Changes the CSS classes used to display the code of Highlighted HTML',
45  'default' => Array(
46  'attribute_names' => 'html_attribute',
47  'attribute_value' => 'html_attribute_values',
48  'tag_brackets' => 'html_tag_brackets',
49  'tag_name' => 'html_tag_names',
50  'html_comment' => 'html_comment',
51  ),
52  'protected' => FALSE,
53  ),
54  'SQ_CODE_EDITOR_PHP_CLASSES' => Array(
55  'name' => 'php_code_classes',
56  'description' => 'Changes the CSS classes used to display the code of Highlighted PHP',
57  'default' => Array(
58  'background' => 'php_background',
59  'default' => 'php_default',
60  'html' => 'php_html',
61  'comment' => 'php_comment',
62  'keyword' => 'php_keyword',
63  'string' => 'php_string',
64  ),
65  'protected' => FALSE,
66  ),
67  'SQ_CODE_EDITOR_JS_CLASSES' => Array(
68  'name' => 'javascript_code_classes',
69  'description' => 'Changes the CSS classes used to display the code of Highlighted Javascript',
70  'default' => Array(
71  'reserved' => 'js_reserved',
72  'function' => 'js_function',
73  'brackets' => 'js_brackets',
74  'comment' => 'js_comment',
75  'default' => 'js_default',
76  'string' => 'js_string',
77  ),
78  'protected' => FALSE,
79  ),
80  'SQ_CODE_EDITOR_LINE_NUMBERS' => Array(
81  'name' => 'line_numbers',
82  'description' => 'Whether to use line numbers, and what options to use',
83  'default' => Array(
84  'use_line_numbers' => FALSE,
85  'line_number_left' => TRUE,
86  'line_number_style' => 'span',
87  'line_number_class' => 'line_numbers',
88  ),
89  'protected' => FALSE,
90  ),
91  );
92  var $css_dimension_width;
93  var $css_dimension_height;
94 
95 
100  function Content_Type_Code_Prefs($pref_file='')
101  {
102  $this->Prefs($pref_file);
103  $this->css_dimension_width = new Asset_Attribute_CSS_Dimension();
104  $this->css_dimension_height = new Asset_Attribute_CSS_Dimension();
105 
106  }//end constructor
107 
108 
119  function paintBackend(&$o, $have_lock, $pref=NULL)
120  {
121  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
122  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
123 
124  // Width and Height
125  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_SIZE') {
126  if (is_null($pref)) {
127  $o->openField(translate($this->pref_vars['SQ_CODE_EDITOR_SIZE']['name']));
128  }
129  $code_editor_size = $this->pref_vars['SQ_CODE_EDITOR_SIZE']['default'];
130  ?>
131  <table class="sq-backend-table" style="width: 350px;">
132  <tr>
133  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('width') ?></td>
134  <td class="sq-backend-table-cell" style="width: 100%;">
135  <?php
136  if ($have_lock && $is_admin) {
137  $this->css_dimension_width->paint('code_width', $have_lock, $code_editor_size['width']);
138  } else {
139  echo $code_editor_size['width'];
140  }
141  ?>
142  </td>
143  </tr>
144  <tr>
145  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('height') ?></td>
146  <td class="sq-backend-table-cell" style="width: 100%;">
147  <?php
148  if ($have_lock && $is_admin) {
149  $this->css_dimension_height->paint('code_height', $have_lock, $code_editor_size['height']);
150  } else {
151  echo $code_editor_size['height'];
152  }
153  ?>
154  </td>
155  </tr>
156  </table>
157  <?php
158  if (is_null($pref)) $o->closeField();
159  }//end if all prefs, or code_editor_size
160 
161  // Classes
162  if (is_null($pref)) {
163  $o->openField(translate($this->pref_vars['SQ_CODE_EDITOR_HTML_CLASSES']['name']));
164  }
165  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_HTML_CLASSES') {
166  $html_classes = $this->pref_vars['SQ_CODE_EDITOR_HTML_CLASSES']['default'];
167  ?>
168  <table class="sq-backend-table" style="width: 350px;">
169  <?php
170  foreach ($html_classes as $class_name => $choice) {
171  ?>
172  <tr>
173  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
174  <?php echo ucwords(str_replace('_', ' ', $class_name)); ?>
175  </td>
176  <td class="sq-backend-table-cell" style="width: 100%;">
177  <?php
178  if ($have_lock && $is_admin) {
179  text_box('SQ_CODE_EDITOR_HTML_CLASSES['.$class_name.']', $choice);
180  } else {
181  echo $choice;
182  }
183  ?>
184  </td>
185  </tr>
186  <?php
187  }
188  ?>
189  </table>
190  <?php
191  if (is_null($pref)) $o->closeField();
192  }
193  if (is_null($pref)) {
194  $o->openField(translate($this->pref_vars['SQ_CODE_EDITOR_PHP_CLASSES']['name']));
195  }
196 
197  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_PHP_CLASSES') {
198  $php_classes = $this->pref_vars['SQ_CODE_EDITOR_PHP_CLASSES']['default'];
199  ?>
200  <table class="sq-backend-table" style="width: 350px;">
201  <?php
202  foreach ($php_classes as $class_name => $choice) {
203  ?>
204  <tr>
205  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
206  <?php echo ucwords(str_replace('_', ' ', $class_name)); ?>
207  </td>
208  <td class="sq-backend-table-cell" style="width: 100%;">
209  <?php
210  if ($have_lock && $is_admin) {
211  text_box('SQ_CODE_EDITOR_PHP_CLASSES['.$class_name.']', $choice);
212  } else {
213  echo $choice;
214  }
215  ?>
216  </td>
217  </tr>
218  <?php
219  }
220  ?>
221  </table>
222  <?php
223  if (is_null($pref)) $o->closeField();
224  }
225  if (is_null($pref)) {
226  $o->openField(translate($this->pref_vars['SQ_CODE_EDITOR_JS_CLASSES']['name']));
227  }
228  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_JS_CLASSES') {
229  $js_classes = $this->pref_vars['SQ_CODE_EDITOR_JS_CLASSES']['default'];
230  ?>
231  <table class="sq-backend-table" style="width: 350px;">
232  <?php
233  foreach ($js_classes as $class_name => $choice) {
234  ?>
235  <tr>
236  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
237  <?php echo ucwords(str_replace('_', ' ', $class_name)); ?>
238  </td>
239  <td class="sq-backend-table-cell" style="width: 100%;">
240  <?php
241  if ($have_lock && $is_admin) {
242  text_box('SQ_CODE_EDITOR_JS_CLASSES['.$class_name.']', $choice);
243  } else {
244  echo $choice;
245  }
246  ?>
247  </td>
248  </tr>
249  <?php
250  }
251  ?>
252  </table>
253  <?php
254  }
255 
256  // Line Numbers
257  if (is_null($pref)) {
258  $o->openField(translate($this->pref_vars['SQ_CODE_EDITOR_LINE_NUMBERS']['name']));
259  }
260  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_LINE_NUMBERS') {
261  $line_prefs = $this->pref_vars['SQ_CODE_EDITOR_LINE_NUMBERS']['default'];
262  ?>
263  <table class="sq-backend-table" style="width: 350px;">
264  <tr>
265  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
266  <?php echo translate('show_line_numbers'); ?>
267  </td>
268  <td class="sq-backend-table-cell" style="width: 100%;">
269  <?php
270  if ($have_lock && $is_admin) {
271  check_box('SQ_CODE_show_line_numbers', '1', $line_prefs['use_line_numbers']);
272  } else {
273  echo ($line_prefs['use_line_numbers'] == TRUE) ? translate('yes') : translate('no');
274  }
275  ?>
276  </td>
277  </tr>
278  <tr>
279  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
280  <?php echo translate('line_number_orientation'); ?>
281  </td>
282  <td class="sq-backend-table-cell" style="width: 100%;">
283  <?php
284  if ($have_lock && $is_admin) {
285  radio_button('SQ_CODE_line_number_left', 'left', $line_prefs['line_number_left'] == TRUE);
286  label(translate('left'), 'SQ_CODE_line_number_left');
287  radio_button('SQ_CODE_line_number_left', 'right', $line_prefs['line_number_left'] == FALSE);
288  label(translate('right'), 'SQ_CODE_line_number_left');
289  } else {
290  echo ($line_prefs['line_number_left'] == TRUE) ? translate('left') : translate('right');
291  }
292  ?>
293  </td>
294  </tr>
295  <tr>
296  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
297  <?php echo translate('line_number_style'); ?>
298  </td>
299  <td class="sq-backend-table-cell" style="width: 100%;">
300  <?php
301  if ($have_lock && $is_admin) {
302  combo_box('SQ_CODE_line_style', Array('span'=>'Span','list'=>'List'), FALSE, $line_prefs['line_number_style']);
303  } else {
304  echo ucwords($line_prefs['line_number_style']);
305  }
306  ?>
307  </td>
308  </tr>
309  <tr>
310  <td class="sq-backend-table-header" nowrap="nowrap" style="width: 100px;">
311  <?php echo translate('line_number_class'); ?>
312  </td>
313  <td class="sq-backend-table-cell" style="width: 100%;">
314  <?php
315  if ($have_lock && $is_admin) {
316  text_box('SQ_CODE_line_class', $line_prefs['line_number_class']);
317  } else {
318  echo $line_prefs['line_number_class'];
319  }
320  ?>
321  </td>
322  </tr>
323  </table>
324  <?php
325  }//end if line numbers
326  if (is_null($pref)) $o->closeField();
327 
328  return TRUE;
329 
330  }//end paintBackend()
331 
332 
343  function processBackend($o, $have_lock, $pref=NULL)
344  {
345  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
346  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
347  if (!$is_admin) return FALSE;
348  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_SIZE') {
349  $this->css_dimension_width->process('code_width');
350  $this->css_dimension_height->process('code_height');
351  $this->pref_vars['SQ_CODE_EDITOR_SIZE']['default']['width'] = $this->css_dimension_width->getContent();
352  $this->pref_vars['SQ_CODE_EDITOR_SIZE']['default']['height'] = $this->css_dimension_height->getContent();
353  return TRUE;
354  }
355  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_HTML_CLASSES') {
356  $this->pref_vars['SQ_CODE_EDITOR_HTML_CLASSES']['default'] = $_POST['SQ_CODE_EDITOR_HTML_CLASSES'];
357  }
358  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_PHP_CLASSES') {
359  $this->pref_vars['SQ_CODE_EDITOR_PHP_CLASSES']['default'] = $_POST['SQ_CODE_EDITOR_PHP_CLASSES'];
360  }
361  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_JS_CLASSES') {
362  $this->pref_vars['SQ_CODE_EDITOR_JS_CLASSES']['default'] = $_POST['SQ_CODE_EDITOR_JS_CLASSES'];
363  }
364  if (is_null($pref) || $pref == 'SQ_CODE_EDITOR_LINE_NUMBERS') {
365  $line_prefs = $this->pref_vars['SQ_CODE_EDITOR_LINE_NUMBERS']['default'];
366  $line_prefs['use_line_numbers'] = isset($_POST['SQ_CODE_show_line_numbers']);
367  $line_prefs['line_number_style'] = $_POST['SQ_CODE_line_style'];
368  $line_prefs['line_number_class'] = $_POST['SQ_CODE_line_class'];
369  $line_prefs['line_number_left'] = ($_POST['SQ_CODE_line_number_left'] == 'right') ? FALSE : TRUE;
370  $this->pref_vars['SQ_CODE_EDITOR_LINE_NUMBERS']['default'] = $line_prefs;
371  }
372  return TRUE;
373 
374  }//end processBackend()
375 
376 
377 }//end class
378 
379 ?>