Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
bodycopy_container_prefs.inc
1 <?php
18 require_once SQ_LIB_PATH.'/config/prefs.inc';
19 
32 {
33  public $pref_vars = Array(
34  'SQ_DEFAULT_CONTENT_TYPE' => Array(
35  'name' => 'default_content_type',
36  'description' => 'When bodycopy containers are created they will have this content type by default',
37  'default' => 'content_type_wysiwyg',
38  'protected' => FALSE,
39  ),
40  'SQ_DEFAULT_PRESENTATION_TYPE' => Array(
41  'name' => 'default_presentation_type',
42  'description' => 'When bodycopy containers are created they will have this presentation type by default',
43  'default' => 'div',
44  'protected' => FALSE,
45  ),
46  'SQ_DIV_DISABLE_CREATE' => Array(
47  'name' => 'div_disable_create',
48  'description' => 'If bodycopy containers are disabled for creating, they can not be created in Edit Content Screen',
49  'default' => 'no',
50  'protected' => FALSE,
51  ),
52  'SQ_DIV_DISABLE_DELETE' => Array(
53  'name' => 'div_disable_delete',
54  'description' => 'If bodycopy containers are disabled for deleting, they can not be deleted in Edit Content Screen',
55  'default' => 'no',
56  'protected' => FALSE,
57  ),
58  );
59 
60 
65  function __construct($pref_file='')
66  {
67  parent::__construct($pref_file);
68 
69  }//end constructor
70 
71 
82  public function paintBackend(Backend_Outputter $o, $have_lock, $pref=NULL)
83  {
84  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
85  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
86 
87  if (is_null($pref) || $pref == 'SQ_DEFAULT_CONTENT_TYPE') {
88  if (is_null($pref)) {
89  $o->openField(translate($this->pref_vars['SQ_DEFAULT_CONTENT_TYPE']['name']));
90  }
91 
92  $default_content_type = $this->pref_vars['SQ_DEFAULT_CONTENT_TYPE']['default'];
93  if ($have_lock) {
94  $all_content_types = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants('content_type');
95 
96  //if markdown is not enabled, remove it from the content type
97  $markdown_key = array_search('content_type_markdown', $all_content_types);
98  if ($markdown_key !== FALSE) {
99  $disable_markdown = TRUE;
100  require_once SQ_DATA_PATH.'/private/conf/tools.inc';
101  if (SQ_TOOL_MARKDOWN_ENABLED && is_file(SQ_TOOL_MARKDOWN_PATH)) {
102  include_once SQ_TOOL_MARKDOWN_PATH;
103  if (function_exists('Markdown')) {
104  $disable_markdown = FALSE;
105  }
106  }
107  if ($disable_markdown) {
108  unset($all_content_types[$markdown_key]);
109  }
110  }
111 
112  $content_type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($all_content_types, 'name');
113  combo_box('prefs[SQ_DEFAULT_CONTENT_TYPE]', $content_type_names, FALSE, $default_content_type);
114  echo '<div class="sq-backend-note">'.translate('default_content_type_note').'</div>';
115  } else {
116  echo $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($default_content_type, 'name');
117  }
118 
119  if (is_null($pref)) $o->closeField();
120  }
121 
122  if (is_null($pref) || $pref == 'SQ_DEFAULT_PRESENTATION_TYPE') {
123  if (is_null($pref)) {
124  $o->openField(translate($this->pref_vars['SQ_DEFAULT_PRESENTATION_TYPE']['name']));
125  }
126 
127  $default_pres_type = $this->pref_vars['SQ_DEFAULT_PRESENTATION_TYPE']['default'];
128  $possible_types = Array(
129  'div' => translate('block-level'),
130  'span' => translate('inline'),
131  'none' => translate('raw_html'),
132  );
133 
134  if ($have_lock) {
135  combo_box('prefs[SQ_DEFAULT_PRESENTATION_TYPE]', $possible_types, FALSE, $default_pres_type);
136  echo '<div class="sq-backend-note">'.translate('default_presentation_type_note').'</div>';
137  } else {
138  echo $possible_types[$default_pres_type];
139  }
140 
141  if (is_null($pref)) $o->closeField();
142  }
143 
144 
145  if (is_null($pref) || $pref == 'SQ_DIV_DISABLE_CREATE') {
146  if (is_null($pref)) {
147  $o->openField(translate($this->pref_vars['SQ_DIV_DISABLE_CREATE']['name']));
148  }
149  $div_disable_create = $this->pref_vars['SQ_DIV_DISABLE_CREATE']['default'];
150  ?>
151  <table class="sq-backend-table" style="width: 100px;">
152  <tr>
153  <td class="sq-backend-table-header" nowrap="nowrap">
154  <?php
155  echo translate('disable');
156  ?>
157  </td>
158  <td class="sq-backend-table-cell" style="width: 100%;">
159  <?php
160  if ($have_lock && $is_admin) {
161  combo_box('prefs[SQ_DIV_DISABLE_CREATE][default]', Array('yes' => 'Yes', 'no' => 'No'), FALSE, $div_disable_create);
162  } else {
163  echo ucfirst($div_disable_create);
164  }
165  ?>
166  </td>
167  </tr>
168  </table>
169  <?php
170  $o->note(translate('div_disable_create_note'));
171 
172  if (is_null($pref)) $o->closeField();
173 
174  }//end if show SQ_DIV_DISABLE_CREATE
175 
176  if (is_null($pref) || $pref == 'SQ_DIV_DISABLE_DELETE') {
177  if (is_null($pref)) {
178  $o->openField(translate($this->pref_vars['SQ_DIV_DISABLE_DELETE']['name']));
179  }
180  $div_disable_delete = $this->pref_vars['SQ_DIV_DISABLE_DELETE']['default'];
181  ?>
182  <table class="sq-backend-table" style="width: 100px;">
183  <tr>
184  <td class="sq-backend-table-header" nowrap="nowrap">
185  <?php
186  echo translate('disable');
187  ?>
188  </td>
189  <td class="sq-backend-table-cell" style="width: 100%;">
190  <?php
191  if ($have_lock && $is_admin) {
192  combo_box('prefs[SQ_DIV_DISABLE_DELETE][default]', Array('yes' => 'Yes', 'no' => 'No'), FALSE, $div_disable_delete);
193  } else {
194  echo ucfirst($div_disable_delete);
195  }
196  ?>
197  </td>
198  </tr>
199  </table>
200  <?php
201  $o->note(translate('div_disable_delete_note'));
202 
203  if (is_null($pref)) $o->closeField();
204 
205  }//end if show SQ_DIV_DISABLE_DELETE
206  return TRUE;
207 
208 
209 
210  }//end paintBackend()
211 
212 
223  public function processBackend(Backend_Outputter $o, $have_lock, $pref=NULL)
224  {
225  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
226  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
227  if (!$is_admin) return FALSE;
228 
229  if (is_null($pref) || $pref == 'SQ_DEFAULT_CONTENT_TYPE') {
230  if (isset($_POST['prefs']['SQ_DEFAULT_CONTENT_TYPE'])) {
231  $this->pref_vars['SQ_DEFAULT_CONTENT_TYPE']['default'] = $_POST['prefs']['SQ_DEFAULT_CONTENT_TYPE'];
232  }
233  }
234 
235  if (is_null($pref) || $pref == 'SQ_DEFAULT_PRESENTATION_TYPE') {
236  if (isset($_POST['prefs']['SQ_DEFAULT_PRESENTATION_TYPE'])) {
237  $this->pref_vars['SQ_DEFAULT_PRESENTATION_TYPE']['default'] = $_POST['prefs']['SQ_DEFAULT_PRESENTATION_TYPE'];
238  }
239  }
240 
241  // Div DISABLE CREATE
242  if (is_null($pref) || $pref == 'SQ_DIV_DISABLE_CREATE') {
243  if (isset($_POST['prefs']['SQ_DIV_DISABLE_CREATE'])) {
244  $this->pref_vars['SQ_DIV_DISABLE_CREATE']['default'] = $_POST['prefs']['SQ_DIV_DISABLE_CREATE']['default'];
245  }
246  }
247 
248  // Div DISABLE DELETE
249  if (is_null($pref) || $pref == 'SQ_DIV_DISABLE_DELETE') {
250  if (isset($_POST['prefs']['SQ_DIV_DISABLE_DELETE'])) {
251  $this->pref_vars['SQ_DIV_DISABLE_DELETE']['default'] = $_POST['prefs']['SQ_DIV_DISABLE_DELETE']['default'];
252  }
253  }
254 
255  return TRUE;
256 
257  }//end processBackend()
258 
259 
269  public function mergePrefs(Array $prefs1, Array $prefs2)
270  {
271  $merged_prefs = Array();
272  $pref_vars = Array('SQ_DEFAULT_CONTENT_TYPE');
273 
274  foreach ($pref_vars as $var_name) {
275  if (isset($prefs1[$var_name]) && !isset($prefs2[$var_name])) {
276  // this is only set in prefs1
277  $merged_prefs[$var_name] = $prefs1[$var_name];
278  } else if (isset($prefs2[$var_name]) && !isset($prefs1[$var_name])) {
279  // this is only set in prefs2
280  $merged_prefs[$var_name] = $prefs2[$var_name];
281  } else if (isset($prefs1[$var_name]) && isset($prefs2[$var_name])) {
282  // this is set in both prefs
283  switch ($var_name) {
284  case 'SQ_DEFAULT_CONTENT_TYPE' :
285  // prefer non-wysiwyg
286  if ($prefs1[$var_name] == 'content_type_wysiwyg') {
287  $merged_prefs[$var_name] = $prefs2[$var_name];
288  } else {
289  $merged_prefs[$var_name] = $prefs1[$var_name];
290  }
291  break;
292  }
293 
294  $merged_prefs[$var_name]['name'] = $prefs1[$var_name]['name'];
295  $merged_prefs[$var_name]['description'] = $prefs1[$var_name]['description'];
296  $merged_prefs[$var_name]['protected'] = ($prefs1[$var_name]['protected'] || $prefs2[$var_name]['protected']);
297  }
298  }
299 
300  return $merged_prefs;
301 
302  }//end mergePrefs()
303 
304 
305 }//end class
306 
307 ?>