18 require_once SQ_LIB_PATH.
'/config/prefs.inc';
33 var $pref_vars = Array(
34 'SQ_WYSIWYG_STYLE' => Array(
35 'name' =>
'wysiwyg_style',
36 'description' =>
'This preference allows you to change the style and size of the WYSIWYG editor',
48 'SQ_WYSIWYG_PLUGINS' => Array(
49 'name' =>
'wysiwyg_plugins',
50 'description' =>
'This preference allows you to select which features of the WYSIWYG editor you would like make available while editing',
54 'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE' => Array(
55 'name' =>
'wysiwyg_disable_image_resize',
56 'description' =>
'This preference allows you to select whether to disable the image resizing functionality in WYSIWYG',
60 'SQ_THESAURUS' => Array (
61 'name' =>
'thesaurus',
62 'description' =>
'Which thesaurus asset you want to use when editing content, for example to provide keyword expansions',
66 'SQ_WYSIWYG_LINK_TYPES' => Array(
67 'name' =>
'core_ct_wysiwyg_link_type_templates',
68 'description' =>
'List of link types to be used in the Insert Link popup',
72 'template' =>
'http://%%link%%',
76 'template' =>
'https://%%link%%',
80 'template' =>
'mailto:%%link%%',
84 'template' =>
'ftp://%%link%%',
88 'template' =>
'rtsp://%%link%%',
93 'SQ_LIVE_LINK_ONLY' => Array (
94 'name' =>
'live_link_only',
95 'description' =>
'To allow links pointing only to live asset',
108 $this->
Prefs($pref_file);
125 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
126 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
128 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_STYLE') {
129 if (is_null($pref)) {
130 $o->openField(translate($this->pref_vars[
'SQ_WYSIWYG_STYLE'][
'name']));
133 $wysiwyg_style = $this->pref_vars[
'SQ_WYSIWYG_STYLE'][
'default'];
134 $size_units = Array(
'%' =>
'%',
'px' =>
'px');
136 <table
class=
"sq-backend-table" style=
"width: 350px;">
138 <td
class=
"sq-backend-table-header" nowrap=
"nowrap"><?php echo translate(
'body_type'); ?></td>
139 <td
class=
"sq-backend-table-cell" style=
"width: 100%;">
141 if ($have_lock && $is_admin) {
142 combo_box(
'prefs[SQ_WYSIWYG_STYLE][body_type]', Array(
'div' => translate(
'div'),
'iframe' => translate(
'iframe')), FALSE, $wysiwyg_style[
'body_type']);
144 echo $wysiwyg_style[
'body_type'];
147 <br /><i><?php echo translate(
'mozilla_always_uses_iframe'); ?></i>
151 <td
class=
"sq-backend-table-header" nowrap=
"nowrap"><?php echo translate(
'width'); ?></td>
152 <td
class=
"sq-backend-table-cell" style=
"width: 100%;">
154 if (!is_numeric($wysiwyg_style[
'width'])) {
155 $wysiwyg_style[
'width'] = preg_replace(
'/[^0-9]/',
'', $wysiwyg_style[
'width']);
157 if ($have_lock && $is_admin) {
158 int_text_box(
'prefs[SQ_WYSIWYG_STYLE][width]', $wysiwyg_style[
'width'], FALSE, 5);
161 if (isset($wysiwyg_style[
'units'][
'width'])) {
162 $default_unit = $wysiwyg_style[
'units'][
'width'];
164 combo_box(
'prefs[SQ_WYSIWYG_STYLE][units][width]', $size_units, FALSE, $default_unit);
166 if (isset($wysiwyg_style[
'width'])) {
167 echo $wysiwyg_style[
'width'];
170 if (isset($wysiwyg_style[
'units'][
'width'])) {
171 echo $wysiwyg_style[
'units'][
'width'];
178 <td
class=
"sq-backend-table-header" nowrap=
"nowrap"><?php echo translate(
'height'); ?></td>
179 <td
class=
"sq-backend-table-cell" style=
"width: 100%;">
181 if (!is_numeric($wysiwyg_style[
'height'])) {
182 $wysiwyg_style[
'height'] = preg_replace(
'/[^0-9]/',
'', $wysiwyg_style[
'height']);
184 if ($have_lock && $is_admin) {
185 int_text_box(
'prefs[SQ_WYSIWYG_STYLE][height]', $wysiwyg_style[
'height'], FALSE, 5);
187 $default_unit =
'px';
188 if (isset($wysiwyg_style[
'units'][
'height'])) {
189 $default_unit = $wysiwyg_style[
'units'][
'height'];
191 combo_box(
'prefs[SQ_WYSIWYG_STYLE][units][height]', $size_units, FALSE, $default_unit);
193 if (isset($wysiwyg_style[
'height'])) {
194 echo $wysiwyg_style[
'height'];
196 if (isset($wysiwyg_style[
'units'][
'height'])) {
197 echo $wysiwyg_style[
'units'][
'height'];
206 if (is_null($pref)) $o->closeField();
211 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_PLUGINS') {
212 if (is_null($pref)) {
213 $o->openField(translate($this->pref_vars[
'SQ_WYSIWYG_PLUGINS'][
'name']));
217 if (!empty($this->pref_vars[
'SQ_WYSIWYG_PLUGINS'][
'default'])) {
218 $plugins = explode(
'|', $this->pref_vars[
'SQ_WYSIWYG_PLUGINS'][
'default']);
220 $all = in_array(
'all', $plugins);
223 if ($have_lock && $is_admin) {
224 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
225 $all_plugins = list_dirs(SQ_FUDGE_PATH.
'/wysiwyg/plugins');
227 if (!empty($all_plugins)) {
228 hidden_field(
'prefs[SQ_WYSIWYG_PLUGINS_PRESENT]',
'1');
231 $ROOT_PATH = SQ_FUDGE_PATH.
'/wysiwyg/';
232 foreach ($all_plugins as $plugin_name) {
233 $plugin_path = SQ_FUDGE_PATH.
'/wysiwyg/plugins/'.$plugin_name;
234 if (!is_file($plugin_path.
'/'.$plugin_name.
'.inc')) {
237 include $plugin_path.
'/'.$plugin_name.
'.inc';
238 $check_result = call_user_func(Array($plugin_name,
'check_usable'));
239 $extra = ($check_result === TRUE) ?
'' :
'disabled="disabled"';
240 check_box(
'prefs[SQ_WYSIWYG_PLUGINS]['.$plugin_name.
']',
'1', ($all || in_array($plugin_name, $plugins)),
'',$extra);
241 echo
' '.ucwords(str_replace(
'_',
' ', $plugin_name));
242 if ($check_result !== TRUE) {
243 echo
' <i>('.$check_result.
')</i>'; }
248 echo translate(
'all_plugins_selected');
250 if (empty($plugins)) {
251 echo translate(
'no_plugins_selected');
254 foreach ($plugins as $plugin_name) {
255 echo
'<li class="sq-backend-data">'.ucwords(str_replace(
'_',
' ', $plugin_name)).
'</li>';
262 if (is_null($pref)) $o->closeField();
266 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE') {
267 if (is_null($pref)) {
268 $o->openField(translate($this->pref_vars[
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE'][
'name']));
270 $wysiwyg_disable_image_resize = $this->pref_vars[
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE'][
'default'];
272 <table
class=
"sq-backend-table" style=
"width: 100px;">
274 <td
class=
"sq-backend-table-header" nowrap=
"nowrap">
276 echo translate(
'disable');
279 <td
class=
"sq-backend-table-cell" style=
"width: 100%;">
281 if ($have_lock && $is_admin) {
282 combo_box(
'prefs[SQ_WYSIWYG_DISABLE_IMAGE_RESIZE][default]', Array(
'yes' =>
'Yes',
'no' =>
'No'), FALSE, $wysiwyg_disable_image_resize);
284 echo ucfirst($wysiwyg_disable_image_resize);
291 if (is_null($pref)) $o->closeField();
295 if ($GLOBALS[
'SQ_SYSTEM']->am->installed(
'thesaurus') && (is_null($pref) || $pref ==
'SQ_THESAURUS')) {
296 if (is_null($pref)) {
297 $o->openField(translate($this->pref_vars[
'SQ_THESAURUS'][
'name']));
300 if ($have_lock && $is_admin) {
301 asset_finder(
'prefs[SQ_THESAURUS]', $this->pref_vars[
'SQ_THESAURUS'][
'default'], Array(
'thesaurus'=>
'A'));
302 $o->note(translate(
'thesaurus_used_by_matrix_expand_keywords_plugin'));
304 if (!$this->pref_vars[
'SQ_THESAURUS'][
'default']) {
305 echo
'('.translate(
'none_selected').
')';
307 $name = reset($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($this->pref_vars[
'SQ_THESAURUS'][
'default']),
'thesaurus', TRUE,
'name'));
308 echo $name.
' (#'.$this->pref_vars[
'SQ_THESAURUS'][
'default'].
')';
311 if (is_null($pref)) $o->closeField();
314 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_LINK_TYPES') {
315 $pref_var =& $this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'];
317 if (is_null($pref)) {
318 $o->openField(translate($this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'name']));
321 if ($have_lock && $is_admin) {
323 ?><table
class=
"sq-backend-table" style=
"width:auto">
327 <th><?php echo translate(
'delete_question') ?></th>
329 foreach ($pref_var[
'default'] as $key => $item) {
333 ?><td><?php text_box(
'prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][type]', $item[
'type'], 10) ?></td><?php
334 ?><td><?php text_box(
'prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][template]', $item[
'template'], 50) ?></td><?php
335 ?><td><?php check_box(
'prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][delete]', 1, FALSE,
'document.getElementById("prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][type]").disabled = document.getElementById("prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][template]").disabled = this.checked') ?></td><?php
339 ?><td><?php hidden_field(
'prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][type]', $item[
'type']); echo $item[
'type'] ?></td><?php
340 ?><td><?php hidden_field(
'prefs[SQ_WYSIWYG_LINK_TYPES][default]['.$key.
'][template]', $item[
'template']); echo $item[
'template'] ?></td><?php
347 <td colspan=
"3"><a href=
"#" id=
"prefs[SQ_WYSIWYG_LINK_TYPES][add]" onclick=
"sq_wysiwyg_link_types_addAnother(this.parentNode.parentNode); return false;">Add another...</a></td>
350 <script type=
"text/javascript">
351 sq_wysiwyg_link_types_nextIndex = <?php echo (
int)count($pref_var[
'default']); ?>;
352 function sq_wysiwyg_link_types_addAnother(node) {
353 var parent = node.parentNode;
356 tr = document.createElement(
'tr');
359 td1 = document.createElement(
'td');
360 td1.innerHTML =
'<input type="text" name="prefs[SQ_WYSIWYG_LINK_TYPES][default][' + sq_wysiwyg_link_types_nextIndex +
'][type]" value="" size="10" />';
361 td2 = document.createElement(
'td');
362 td2.innerHTML =
'<input type="text" name="prefs[SQ_WYSIWYG_LINK_TYPES][default][' + sq_wysiwyg_link_types_nextIndex +
'][template]" value="" size="50" />';
363 td3 = document.createElement(
'td');
364 td3.innerHTML =
'<em>new</em>';
370 parent.insertBefore(tr, node);
373 sq_wysiwyg_link_types_nextIndex++;
380 ?><table
class=
"sq-backend-table" style=
"width:auto">
385 foreach ($pref_var[
'default'] as $item) {
387 ?><td><?php echo $item[
'type'] ?></td><?php
388 ?><td><?php echo $item[
'template'] ?></td><?php
394 $o->note(translate(
'core_ct_wysiwyg_link_type_templates_note'));
395 if (is_null($pref)) $o->closeField();
398 if (is_null($pref) || $pref ==
'SQ_LIVE_LINK_ONLY') {
400 if (is_null($pref)) {
401 $o->openField(translate($this->pref_vars[
'SQ_LIVE_LINK_ONLY'][
'name']));
404 $pref_var =& $this->pref_vars[
'SQ_LIVE_LINK_ONLY'][
'default'];
405 if ($have_lock && $is_admin) {
406 $options = Array(1 =>
'Yes', 0 =>
'No');
407 combo_box(
'prefs[SQ_LIVE_LINK_ONLY]', $options, FALSE, $pref_var);
408 echo $o->note(translate(
'live_link_only_note'));
410 echo ($pref_var) ? translate(
'yes') : translate(
'no');
413 if (is_null($pref)) $o->closeField();
434 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
435 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
436 if (!$is_admin)
return FALSE;
440 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_STYLE') {
441 if (isset($_POST[
'prefs'][
'SQ_WYSIWYG_STYLE'])) {
442 $this->pref_vars[
'SQ_WYSIWYG_STYLE'][
'default'] = $_POST[
'prefs'][
'SQ_WYSIWYG_STYLE'];
448 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_PLUGINS') {
449 if (isset($_POST[
'prefs'][
'SQ_WYSIWYG_PLUGINS_PRESENT'])) {
450 $wysiwyg_plugins = Array();
451 if (isset($_POST[
'prefs'][
'SQ_WYSIWYG_PLUGINS'])) {
452 $wysiwyg_plugins = $_POST[
'prefs'][
'SQ_WYSIWYG_PLUGINS'];
457 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
458 $all_plugins = list_dirs(SQ_FUDGE_PATH.
'/wysiwyg/plugins');
460 foreach ($all_plugins as $plugin_name) {
461 $plugin_path = SQ_FUDGE_PATH.
'/wysiwyg/plugins/'.$plugin_name;
462 if (!is_file($plugin_path.
'/'.$plugin_name.
'.inc')) {
466 if (!isset($wysiwyg_plugins[$plugin_name]) || !$wysiwyg_plugins[$plugin_name]) {
470 $plugin_list .= $plugin_name.
'|';
474 $plugin_list =
'all';
476 $plugin_list = trim($plugin_list,
'|');
478 $this->pref_vars[
'SQ_WYSIWYG_PLUGINS'][
'default'] = $plugin_list;
483 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE') {
484 if (isset($_POST[
'prefs'][
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE'])) {
485 $this->pref_vars[
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE'][
'default'] = $_POST[
'prefs'][
'SQ_WYSIWYG_DISABLE_IMAGE_RESIZE'][
'default'];
490 if (is_null($pref) || $pref ==
'SQ_THESAURUS') {
491 if (isset($_POST[
'prefs'][
'SQ_THESAURUS'])) {
492 $this->pref_vars[
'SQ_THESAURUS'][
'default'] = $_POST[
'prefs'][
'SQ_THESAURUS'][
'assetid'];
497 if (is_null($pref) || $pref ==
'SQ_WYSIWYG_LINK_TYPES') {
498 if (isset($_POST[
'prefs'][
'SQ_WYSIWYG_LINK_TYPES'])) {
500 $this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default'] = $_POST[
'prefs'][
'SQ_WYSIWYG_LINK_TYPES'][
'default'];
502 foreach ($this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default'] as $key => $value) {
504 $allowed_sub_keys = Array(
'type',
'template',
'delete');
505 foreach ($value as $sub_key) {
506 if (!in_array($sub_key, $allowed_sub_keys)) {
507 unset($this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default'][$key][$sub_key]);
512 if (array_get_index($value,
'delete', FALSE)) {
513 unset($this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default'][$key]);
517 $this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default'] = array_values($this->pref_vars[
'SQ_WYSIWYG_LINK_TYPES'][
'default']);
522 if (is_null($pref) || $pref ==
'SQ_LIVE_LINK_ONLY') {
523 if (isset($_POST[
'prefs'][
'SQ_LIVE_LINK_ONLY'])) {
524 $this->pref_vars[
'SQ_LIVE_LINK_ONLY'][
'default'] = $_POST[
'prefs'][
'SQ_LIVE_LINK_ONLY'][
'default'];
544 $merged_prefs = Array();
545 $pref_vars = Array(
'SQ_WYSIWYG_STYLE',
'SQ_WYSIWYG_PLUGINS',
'SQ_THESAURUS');
547 foreach ($pref_vars as $var_name) {
548 if (isset($prefs1[$var_name]) && !isset($prefs2[$var_name])) {
550 $merged_prefs[$var_name] = $prefs1[$var_name];
551 }
else if (isset($prefs2[$var_name]) && !isset($prefs1[$var_name])) {
553 $merged_prefs[$var_name] = $prefs2[$var_name];
554 }
else if (isset($prefs1[$var_name]) && isset($prefs2[$var_name])) {
557 case 'SQ_WYSIWYG_STYLE' :
559 $merged_prefs[$var_name] = $prefs1[$var_name];
562 case 'SQ_WYSIWYG_PLUGINS' :
563 $plug1 = explode(
'|', $prefs1[
'SQ_WYSIWYG_PLUGINS'][
'default']);
564 if (is_array($prefs2[
'SQ_WYSIWYG_PLUGINS']) && isset($prefs2[
'SQ_WYSIWYG_PLUGINS'][
'default'])) {
565 $plug2 = explode(
'|', $prefs2[
'SQ_WYSIWYG_PLUGINS'][
'default']);
567 $plug2 = explode(
'|', $prefs2[
'SQ_WYSIWYG_PLUGINS']);
569 $merged_prefs[
'SQ_WYSIWYG_PLUGINS'][
'default'] = implode(
'|', array_unique(array_merge($plug1, $plug2)));
572 case 'SQ_THESAURUS' :
574 $merged_prefs[
'SQ_THESAURUS'][
'default'] = $prefs1[$var_name][
'default'];
579 $merged_prefs[$var_name][
'name'] = $prefs1[$var_name][
'name'];
580 $merged_prefs[$var_name][
'description'] = $prefs1[$var_name][
'description'];
582 if (isset($prefs2[$var_name][
'protected'])) {
583 $merged_prefs[$var_name][
'protected'] = ($prefs1[$var_name][
'protected'] || $prefs2[$var_name][
'protected']);
585 $merged_prefs[$var_name][
'protected'] = $prefs1[$var_name][
'protected'];
590 return $merged_prefs;