/[drupal]/contributions/modules/wymeditor/wymeditor.module
ViewVC logotype

Contents of /contributions/modules/wymeditor/wymeditor.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Wed Mar 28 09:57:26 2007 UTC (2 years, 7 months ago) by moxide
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +12 -11 lines
File MIME type: text/x-php
#131707 Attach WYMeditor on all bodys' textareas
1 <?php
2 // $Id: wymeditor.module,v 1.5 2007/03/18 14:01:07 moxide Exp $
3
4 /**
5 * @file
6 * Integration of WYMeditor (http://www.wymeditor.org) into Drupal.
7 */
8
9 /**
10 * Implementation of hook_form_alter().
11 */
12 function wymeditor_form_alter($form_id, &$form) {
13 if(user_access(t('access WYMeditor'))) {
14 $body_found = FALSE;
15 foreach (element_children($form) as $e) {
16 // If we find the body textarea, we activate the editor.
17 if(isset($form[$e]['body']) && $form[$e]['body']['#type'] == 'textarea') {
18 $body_found = TRUE;
19 break;
20 }
21 }
22 if($body_found) {
23 // Get the profile settings
24 $wym_profiles = _wymeditor_get_profiles();
25 $settings = unserialize($wym_profiles[0]['settings']);
26
27 // IMCE settings
28 if(module_exist('imce')) {
29 $image_dialog = $settings['image_dialog'] == 'enabled' ? 'image_imce.htm' : 'image.htm';
30 $link_dialog = $settings['link_dialog'] == 'enabled' ? 'link_imce.htm' : 'link.htm';
31 } else {
32 $image_dialog = 'image.htm';
33 $link_dialog = 'link.htm';
34 }
35
36 // Get the containers and classes from DB
37 $wym_containers = _wymeditor_get_containers();
38 $wym_classes = _wymeditor_get_classes();
39
40 // Include the javascript and css files
41 $module_path = drupal_get_path('module','wymeditor');
42 theme_add_style($module_path.'/wymeditor/skins/editor-skin.css');
43
44 drupal_add_js( $module_path.'/wymeditor.js');
45 drupal_add_js( $module_path.'/wymeditor/browser.js');
46 drupal_add_js( $module_path.'/wymeditor/util.js');
47 drupal_add_js( $module_path.'/wymeditor/config.js');
48 drupal_add_js( $module_path.'/wymeditor/wym.js');
49
50 $module_path = base_path() . $module_path;
51
52 // Hide the Drupal's body textarea, set the onkeyup event
53 $form[$e]['body']['#attributes'] = array(
54 'onkeyup' => 'setHTML()',
55 'style' => 'display: none',
56 );
57 $form[$e]['body']['#resizable'] = FALSE ;
58
59 // Build the editor html code
60 // Add the onload event and sets the dialogs'path of WYMeditor
61 $editor = '<script type="text/javascript">
62 addLoadEvent(function(){
63 init(\'edit-body\');
64 dialogs["base"]="'.$module_path.'/wymeditor/dialogs/";
65 dialogs["image"]="'.$image_dialog.'";
66 dialogs["link"]="'.$link_dialog.'";
67 '.($settings['default_state'] == 'enabled' ? '' : 'wymToggleDisplay();').'});
68 </script>';
69
70 $editor .= '
71 <div id="wym-div" class="editor" onfocusout="bCleanPaste=false;displayPasteCleanup(true)" width="99%" height="600px">
72 <div id="topdiv">
73
74 <!-- caretpos keeps cursor position -->
75 <input type="hidden" name="caretpos" id="caretpos" value="0" />
76
77 <div id="toolbars">
78
79 <!-- basic commands -->
80 <div id="m_basic">
81 <a id="m_strong" title="Strong" href="#wymedit" onclick="execCom(\'Bold\');getCleanHTML();return false;">Strong</a>
82 <a id="m_italic" title="Italics" href="#wymedit" onclick="execCom(\'Italic\');getCleanHTML();return false;">Italic</a>
83 <a id="m_sup" title="Supercript" href="#wymedit" onclick="execCom(\'Superscript\');getCleanHTML();return false;">Superscript</a>
84 <a id="m_sub" title="Subscript" href="#wymedit" onclick="execCom(\'Subscript\');getCleanHTML();return false;">Subscript</a>
85 <!-- we must remove class attribute before converting from P to OL or UL -->
86 <a id="m_ordered_list" title="Ordered list" href="#wymedit" onclick="removeClassAttr();execCom(\'InsertOrderedList\');getCleanHTML();return false;">Ordered List</a>
87 <a id="m_unordered_list" title="Unordered list" href="#wymedit" onclick="removeClassAttr();execCom(\'InsertUnorderedList\');getCleanHTML();return false;">Unordered List</a>
88 <a id="m_indent" title="Indent" href="#" onclick="execCom(\'Indent\');getCleanHTML();return false;">Indent</a>
89 <a id="m_outdent" title="Outdent" href="#" onclick="execCom(\'Outdent\');getCleanHTML();return false;">Outdent</a>
90 </div>
91
92 <div id="m_undo_redo">
93 <a id="m_undo" title="Undo" href="#wymedit" onclick="execCom(\'Undo\');return false;">Undo</a>
94 <a id="m_redo" title="Redo" href="#wymedit" onclick="execCom(\'Redo\');return false;">Redo</a>
95 </div>
96
97 <!-- objects : link, image, table -->
98 <div id="m_objects">
99 <a id="m_link" title="Create link" href="#wymedit" onclick="openDialog(\'link\');getCleanHTML();return false;">Link</a>
100 <a id="m_unlink" title="Unlink" href="#wymedit" onclick="execCom(\'Unlink\');getCleanHTML();return false;">Unlink</a>
101 <a id="m_image" title="Insert image" href="#wymedit" onclick="openDialog(\'image\');getCleanHTML();return false;">Image</a>
102 <a id="m_table" title="Insert table" href="#wymedit" onclick="openDialog(\'table\');getCleanHTML();return false;">Table</a>
103 </div>
104
105 <!-- table : advanced commands -->
106 <div id="m_table_advanced">
107 <a id="m_table_insert_row_after" title="Insert new row after current row" href="#wymedit" onclick="table_insertObject(\'ROW\',false);getCleanHTML();return false;">Insert Row After</a>
108 <a id="m_table_insert_row_before" title="Insert new row before current row" href="#wymedit" onclick="table_insertObject(\'ROW\',true);getCleanHTML();return false;">Insert Row Before</a>
109 <a id="m_table_insert_col_after" title="Insert new column after current column" href="#wymedit" onclick="table_insertObject(\'COL\',false);getCleanHTML();return false;">Insert Col After</a>
110 <a id="m_table_insert_col_before" title="Insert new column before current column" href="#wymedit" onclick="table_insertObject(\'COL\',true);getCleanHTML();return false;">Insert Col Before</a>
111 <a id="m_table_delete_row" title="Delete current row" href="#wymedit" onclick="table_deleteObject(\'ROW\');getCleanHTML();return false;">Delete Row</a>
112 <a id="m_table_delete_col" title="Delete current column" href="#wymedit" onclick="table_deleteObject(\'COL\');getCleanHTML();return false;">Delete Col</a>
113 </div>
114
115 <!-- advanced commands -->
116 <div id="m_advanced">
117 <a id="m_paste" title="Paste from Word" href="#wymedit" onclick="openDialog(\'paste\');getCleanHTML();return false;">Paste from Word</a>
118 </div>
119 </div>
120
121 <div id="panels">
122 <!-- containers (h1..h6, pre, ...) -->
123 <div id="m_containers">
124 <h2>Containers</h2>';
125
126 // Format and add the containers
127 foreach($wym_containers as $c) {
128 $editor .= '<a href="#wymedit" onclick="setContainer(\''. $c['tagname'] .'\');getCleanHTML();return false;">'. $c['description'] .'</a>';
129 }
130 $editor .= '<a id="m_table_header" href="#wymedit" onclick="switchCellType();getCleanHTML();return false;">Table Header</a>';
131 $editor .= '</div>
132 <!-- classes : setClass(class name,list of allowed containers,list of incompatible classes) -->
133 <div id="m_class">
134 <h2>Classes</h2>
135 <a id="m_remove_class" href="#wymedit" onclick="removeClassAttr();getCleanHTML();displayClasses();return false;">Remove Classes</a>
136 <h2>Common</h2>';
137
138 // Format and add the classes
139 foreach($wym_classes as $c) {
140 $editor .= '<a href="#wymedit" name="' .$c['name']. '" onclick="setClass(\''. $c['name'].'\',\''. $c['allowed'].'\',\'' .$c['incompat'].'\',\'' .$c['compat']. '\');getCleanHTML();return false;">' .$c['description'].'</a>';
141 }
142 $editor .= '
143 </div>
144
145 <!-- miscellaneous -->
146 <div id="m_misc">
147 <h2>Info</h2>
148 Copy-Paste clean up:<span id="m_paste_cleanup_flag_on" style="display: inline;">ON</span><span id="m_paste_cleanup_flag_off" style="display: none;">OFF</span>
149 </div>
150 </div>
151
152 <!-- the editor - saveCaret saves cursor position - setImgEvent handles click on images -->
153 <div contentEditable name="editor" id="editor"
154 onblur="getCleanHTML()"
155 onbeforedeactivate="saveCaret()"
156 onkeyup="saveCaret();displayClasses()"
157 onclick="saveCaret();release();setImgEvent();displayClasses()"
158 oncopy="bCleanPaste=true;displayPasteCleanup(false)"
159 oncut="bCleanPaste=true;displayPasteCleanup(false)"
160 onbeforepaste="event.returnValue=false"
161 onpaste="pasteData()"
162 ondrop="event.returnValue=false"
163 onresizestart="event.returnValue=false">
164 </div>';
165
166 // Add WYMeditor's iframe
167 $editor .= '<!-- the editor -->
168 <iframe id="iframe_editor" src="'.$module_path.'/wymeditor/iframe.htm"></iframe>
169 </div>
170 </div>';
171
172 // Add the Display/Hide link
173 $editor .= $settings['display_link'] == 'enabled' ? '<a href="#wymedit" onclick="wymToggleDisplay();">'.t('Display/Hide WYMeditor').'</a>' : '';
174
175 // At last, add the editor html code to the form
176 $form[$e]['body']['#suffix'] = $editor;
177
178
179 }
180 }
181 }
182
183 /**
184 * Implementation of hook_help().
185 */
186 function wymeditor_help($section) {
187 /* INFO:
188 * The help hook is for displaying helpful messages at the top of pages indicated
189 * by $section to further explain how they work. Adding certain "keywords" to the end of
190 * a given path (like admin/modules#description) will cause this text to display elsewhere
191 * in the page as well (in this case, in the description section for the given module).
192 */
193 switch ($section) {
194 case 'admin/help#wymeditor':
195 return t('TODO: Create admin help text.');
196 case 'admin/modules#description':
197 return t('WYMeditor : an html/javascript WYSIWYM editor.');
198 case 'node/add#wymeditor':
199 return t('TODO: enter description of node.');
200 // OPTIONAL: Add additional cases for other paths that should display help text.
201 }
202 }
203
204 /**
205 * Implementation of hook_menu().
206 */
207 function wymeditor_menu($may_cache) {
208 $items = array();
209
210 $access = user_access( t('administer WYMeditor') );
211 if ($may_cache) {
212 $items[] = array(
213 'path' => 'admin/settings/wymeditor',
214 'title' => t('wymeditor'),
215 'callback' => 'wymeditor_settings_profile',
216 'access' => $access,
217 );
218 $items[] = array(
219 'path' => 'admin/settings/wymeditor/profile',
220 'title' => t('profiles'),
221 'callback' => 'wymeditor_settings_profile',
222 'type' => MENU_DEFAULT_LOCAL_TASK,
223 'weight' => 1,
224 'access' => $access,
225 );
226 $items[] = array(
227 'path' => 'admin/settings/wymeditor/container',
228 'title' => t('containers'),
229 'callback' => 'wymeditor_settings_container',
230 'type' => MENU_LOCAL_TASK,
231 'weight' => 2,
232 'access' => $access,
233 );
234 $items[] = array(
235 'path' => 'admin/settings/wymeditor/class',
236 'title' => t('classes'),
237 'callback' => 'wymeditor_settings_class',
238 'type' => MENU_LOCAL_TASK,
239 'weight' => 3,
240 'access' => $access,
241 );
242 }
243
244 return $items;
245 }
246
247 // Callback functions
248
249 /**
250 * Callback of 'admin/settings/wymeditor/profile'
251 * @param $op Operation name (view,add,edit or delete)
252 * @param $arg the Id of the profile to be edited or deleted
253 */
254 function wymeditor_settings_profile($op = 'view', $arg = null) {
255 switch ($op) {
256 case 'delete' :
257 $output = wymeditor_delete_confirm('profile',$arg);
258 break;
259 case 'add' :
260 drupal_set_title(t('Add new profile'));
261 $output = wymeditor_profiles_form();
262 break;
263 case 'edit' :
264 drupal_set_title(t('Edit profile'));
265 $output = wymeditor_profiles_form($arg);
266 break;
267 case 'view' :
268 default :
269 drupal_set_title(t('WYMeditor profiles'));
270 $output = wymeditor_profiles_overview();
271
272 }
273 return $output;
274 }
275
276 /**
277 * Callback of 'admin/settings/wymeditor/container'
278 *
279 * @param $op Operation name (view,add,edit or delete)
280 * @param $arg the Id of the container to be edited or deleted
281 */
282 function wymeditor_settings_container($op = 'view', $arg = null) {
283 switch ($op) {
284 case 'delete' :
285 $output = wymeditor_delete_confirm('container', $arg);
286 break;
287 case 'add' :
288 drupal_set_title(t('Add new container'));
289 $output = wymeditor_containers_form();
290 break;
291 case 'edit' :
292 drupal_set_title(t('Edit container'));
293 $output = wymeditor_containers_form($arg);
294 break;
295
296 case 'view' :
297 default :
298 drupal_set_title(t('WYMeditor containers'));
299 $output = wymeditor_containers_overview();
300
301 }
302 return $output;
303 }
304
305 /**
306 * Callback of 'admin/settings/wymeditor/class'
307 * @param $op Operation name (view,add,edit or delete)
308 * @param $arg the Id of the class to be edited or deleted
309 */
310 function wymeditor_settings_class($op = 'view', $arg = null) {
311 switch ($op) {
312 case 'delete' :
313 $output = wymeditor_delete_confirm('class', $arg);
314 break;
315 case 'add' :
316 drupal_set_title(t('Add new class'));
317 $output = wymeditor_classes_form();
318 break;
319 case 'edit' :
320 drupal_set_title(t('Edit class'));
321 $output = wymeditor_classes_form($arg);
322 break;
323 case 'view' :
324 default :
325 drupal_set_title(t('WYMeditor classes'));
326 $output = wymeditor_classes_overview();
327
328 }
329 return $output;
330 }
331
332 /**
333 * Returns a themed table of profiles
334 */
335 function wymeditor_profiles_overview() {
336 // Get the array of profiles
337 $profiles = _wymeditor_get_profiles();
338
339 $output = '<p>'.t('Here is the list of the profiles :').'</p>';
340 if(isset($profiles)) {
341 $titles = array(
342 t('Profile name'),
343 array ('data' => t('Operations'), 'colspan' => 2),
344 );
345 foreach($profiles as $p) {
346 $rows[] = array(
347 $p['name'],
348 l(t('edit'), "admin/settings/wymeditor/profile/edit/{$p['pid']}"),
349 l(t('delete'), "admin/settings/wymeditor/profile/delete/{$p['pid']}"),
350 );
351 }
352 } else {
353 $output .= '<p><i>'.t('No profile defined yet, please add a new one.').'</i></p>';
354 }
355 $output .= theme('table', $titles, $rows);
356 $output .= l(t('Add new profile'), 'admin/settings/wymeditor/profile/add');
357 return $output;
358 }
359
360 /**
361 * Returns a themed table of classes
362 */
363 function wymeditor_classes_overview() {
364
365 // Get the array of classes
366 $classes = _wymeditor_get_classes();
367
368 $output = '<p>'.t('Here is the list of the available classes :').'</p>';
369 $titles = array(
370 t('Class name'),
371 t('Description'),
372 t('Allowed containers'),
373 t('Incompatible classes'),
374 t('Compatible classes'),
375 array ('data' => t('Operations'), 'colspan' => 2),
376 );
377 foreach($classes as $c) {
378 $rows[] = array(
379 $c['name'],$c['description'], $c['allowed'],$c['incompat'],$c['compat'],
380 l(t('edit'), "admin/settings/wymeditor/class/edit/{$c['cid']}"),
381 l(t('delete'), "admin/settings/wymeditor/class/delete/{$c['cid']}"),
382 );
383 }
384 $output .= theme('table', $titles, $rows);
385 $output .= l(t('Add new class'), 'admin/settings/wymeditor/class/add');
386 return $output;
387
388 }
389
390 /**
391 * Returns a themed table of containers
392 */
393 function wymeditor_containers_overview() {
394
395 $output = '<p>'.t('Here is the list of the available containers :').'</p>';
396 $titles = array(
397 t('Description'),
398 t('Tag name'),
399 array ('data' => t('Operations'), 'colspan' => 2),
400 );
401 $containers = _wymeditor_get_containers();
402 foreach($containers as $c) {
403 $rows[] = array(
404 $c['description'], $c['tagname'],
405 l(t('edit'), "admin/settings/wymeditor/container/edit/{$c['cid']}"),
406 l(t('delete'), "admin/settings/wymeditor/container/delete/{$c['cid']}"),
407 );
408 }
409 $output .= theme('table', $titles, $rows);
410 $output .= l(t('Add new container'), 'admin/settings/wymeditor/container/add');
411 return $output;
412 }
413
414 /**
415 * Builds a delete confirmation form
416 * @param $type the type name (container or class)
417 * @param $id the Id of the container or class to be deleted
418 */
419 function wymeditor_delete_confirm($type, $id) {
420 if(!isset($id)) {
421 return;
422 }
423
424 switch ($type) {
425 case 'profile' :
426 $data = _wymeditor_get_profiles($id);
427 if(isset($data)) {
428 $name = $data[0]['name'];
429 }
430 break;
431 case 'container' :
432 $data = _wymeditor_get_containers($id);
433 if(isset($data)) {
434 $name = $data[0]['description'];
435 }
436 break;
437 case 'class' :
438 $data = _wymeditor_get_classes($id);
439 if(isset($data)) {
440 $name = $data[0]['description'];
441 }
442 break;
443 default :
444 return;
445 }
446 if(isset($name)) {
447 $form['type'] = array('#type' => 'value', '#value' => $type);
448 $form['id'] = array('#type' => 'value', '#value' => $id);
449 return confirm_form('wymeditor_delete_form', $form, t('Are you sure you want to delete the %type <em>%name</em>?', array('%type' => $type, '%name' => $name )), 'admin/settings/wymeditor/'.$type, '<p>'.t('This action cannot be undone.').'</p>', t('Delete'), t('Cancel'));
450 }
451
452 }
453
454 /**
455 * Actually deletes a profile, container or class
456 */
457 function wymeditor_delete_form_submit($form_id, $form){
458 if(isset($form['id']) && is_numeric($form['id'])) {
459 switch ($form['type']) {
460 case 'profile' :
461 db_query("DELETE FROM {wymeditor_profiles} WHERE pid=%d", $form['id']);
462 break;
463 case 'container' :
464 db_query("DELETE FROM {wymeditor_containers} WHERE cid=%d", $form['id']);
465 break;
466 case 'class' :
467 db_query("DELETE FROM {wymeditor_classes} WHERE cid=%d", $form['id']);
468 break;
469 default :
470 return;
471 }
472 drupal_set_message(t('The %type has been successfully deleted.', array ('%type' => $form['type'])));
473 drupal_goto('admin/settings/wymeditor/'. $form['type']);
474 }
475
476 }
477
478 /**
479 * Builds the profile add/edit form
480 *
481 * @param $pid Id of the profile to be edited. If null, show an add form.
482 */
483 function wymeditor_profiles_form($pid = null) {
484 if(isset($pid)) {
485 $profiles = _wymeditor_get_profiles($pid);
486 $form['pid'] = array(
487 '#type' => 'hidden',
488 '#value' => $pid,
489 );
490 $settings = unserialize($profiles[0]['settings']);
491 }
492 $form['name'] = array(
493 '#type' => 'textfield',
494 '#title' => t('Profile name'),
495 '#default_value' => $profiles[0]['name'],
496 '#size' => 60,
497 '#maxlength' => 64,
498 '#description' => t('Enter the profile name.'),
499 '#required' => TRUE,
500 );
501 $form['basic'] = array(
502 '#type' => 'fieldset',
503 '#title' => t('Basic settings'),
504 '#collapsible' => TRUE,
505 '#collapsed' => FALSE,
506 );
507 $form['basic']['default_state'] = array(
508 '#type' => 'select',
509 '#title' => t('Default state'),
510 '#default_value' => $settings['default_state'] ? $settings['default_state'] : 'enabled',
511 '#options' => array('disabled' => 'disabled', 'enabled' => 'enabled'),
512 '#description' => t('Decide if WYMeditor should be enabled or disabled by default.'),
513 );
514 $form['basic']['display_link'] = array(
515 '#type' => 'select',
516 '#title' => t('Display/Hide link'),
517 '#default_value' => $settings['display_link'] ? $settings['display_link'] : 'enabled',
518 '#options' => array('disabled' => 'disabled', 'enabled' => 'enabled'),
519 '#description' => t('If enabled, a \'Display/Hide WYMeditor\' link will appear.'),
520 );
521 $form['imce'] = array(
522 '#type' => 'fieldset',
523 '#title' => t('IMCE settings'),
524 '#collapsible' => TRUE,
525 '#collapsed' => FALSE,
526 '#description' => t('These settings will be ignored if IMCE module is not active.'),
527 );
528 $form['imce']['image_dialog'] = array(
529 '#type' => 'select',
530 '#title' => t('Image dialog'),
531 '#default_value' => $settings['image_dialog'] ? $settings['image_dialog'] : 'disabled',
532 '#options' => array('disabled' => 'disabled', 'enabled' => 'enabled'),
533 '#description' => t('Enable to activate IMCE in image dialog.'),
534 );
535 $form['imce']['link_dialog'] = array(
536 '#type' => 'select',
537 '#title' => t('Link dialog'),
538 '#default_value' => $settings['link_dialog'] ? $settings['link_dialog'] : 'disabled',
539 '#options' => array('disabled' => 'disabled', 'enabled' => 'enabled'),
540 '#description' => t('Enable to activate IMCE in link dialog.'),
541 );
542 $form['submit'] =array(
543 '#type' => 'submit',
544 '#value' => t('Save'),
545 );
546 return drupal_get_form('wymeditor_profiles_form', $form);
547 }
548
549 /**
550 * Builds the container add/edit form
551 *
552 * @param $cid Id of the container to be edited. If null, show an add form.
553 */
554 function wymeditor_containers_form($cid = null) {
555 if(isset($cid)) {
556 $container = _wymeditor_get_containers($cid);
557 $form['cid'] = array(
558 '#type' => 'hidden',
559 '#value' => $cid,
560 );
561 }
562 $form['description'] = array(
563 '#type' => 'textfield',
564 '#title' => t('Description'),
565 '#default_value' => $container[0]['description'],
566 '#size' => 60,
567 '#maxlength' => 64,
568 '#description' => t('Enter the container description. e.g : Paragraph.'),
569 '#required' => TRUE,
570 );
571 $form['tagname'] = array(
572 '#type' => 'textfield',
573 '#title' => t('Tag name'),
574 '#default_value' => $container[0]['tagname'],
575 '#size' => 60,
576 '#maxlength' => 64,
577 '#description' => t('Enter the actual XHTML tag name of this container. e.g : P.'),
578 '#required' => TRUE,
579 );
580 $form['weight'] = array(
581 '#type' => 'weight',
582 '#title' => t('Weight'),
583 '#default_value' => $container[0]['weight'],
584 '#delta' => 20,
585 '#description' => t('Allows you to change the order of containers.'),
586 );
587 $form['submit'] =array(
588 '#type' => 'submit',
589 '#value' => t('Save'),
590 );
591 return drupal_get_form('wymeditor_containers_form', $form);
592 }
593
594 /**
595 * Builds the class add/edit form
596 *
597 * @param $cid Id of the class to be edited. If null, show an add form.
598 */
599 function wymeditor_classes_form($cid = null) {
600 if(isset($cid)) {
601 $container = _wymeditor_get_classes($cid);
602 $form['cid'] = array(
603 '#type' => 'hidden',
604 '#value' => $cid,
605 );
606 }
607 $form['name'] = array(
608 '#type' => 'textfield',
609 '#title' => t('Name'),
610 '#default_value' => $container[0]['name'],
611 '#size' => 60,
612 '#maxlength' => 64,
613 '#description' => t('Enter the actual class name. e.g : align-left.'),
614 '#required' => TRUE,
615 );
616 $form['description'] = array(
617 '#type' => 'textfield',
618 '#title' => t('Description'),
619 '#default_value' => $container[0]['description'],
620 '#size' => 60,
621 '#maxlength' => 64,
622 '#description' => t('Enter the class description that will be shown in WYMeditor. e.g : Align Left.'),
623 '#required' => TRUE,
624 );
625 $form['allowed'] = array(
626 '#type' => 'textfield',
627 '#title' => t('Allowed containers'),
628 '#default_value' => $container[0]['allowed'],
629 '#size' => 60,
630 '#maxlength' => 64,
631 '#description' => t('Enter a list of <strong>comma separated</strong> container tags, on which this class applies. e.g : P,DIV,IMG. <br />A \'*\' (wildcard) means <em>All containers</em>. An empty textfield means <em>No container</em>.'),
632 );
633 $form['incompat'] = array(
634 '#type' => 'textfield',
635 '#title' => t('Incompatible classes'),
636 '#default_value' => $container[0]['incompat'],
637 '#size' => 60,
638 '#maxlength' => 64,
639 '#description' => t('Enter a list of <strong>comma separated</strong> class names, with which this class is incompatible. e.g : align-right,align-center. <br />A \'*\' (wildcard) means <em>All classes</em>. An empty textfield means <em>No class</em>.'),
640 );
641 $form['compat'] = array(
642 '#type' => 'textfield',
643 '#title' => t('Compatible classes'),
644 '#default_value' => $container[0]['compat'],
645 '#size' => 60,
646 '#maxlength' => 64,
647 '#description' => t('Enter a list of <strong>comma separated</strong> class names, with which this class is compatible. e.g : border-thick, background-red. <br />A \'*\' (wildcard) means <em>All classes</em>. An empty textfield means <em>No class</em>.'),
648 );
649 $form['weight'] = array(
650 '#type' => 'weight',
651 '#title' => t('Weight'),
652 '#default_value' => $container[0]['weight'],
653 '#delta' => 20,
654 '#description' => t('Weight allows you to change the order of classes.'),
655 );
656 $form['submit'] =array(
657 '#type' => 'submit',
658 '#value' => t('Save'),
659 );
660 return drupal_get_form('wymeditor_classes_form', $form);
661 }
662
663 /**
664 * Submit task, associated to profiles_form
665 */
666 function wymeditor_profiles_form_submit($form_id, $form){
667 // Is it an 'edit' form or an 'add' form?
668 $settings= serialize($form);
669 if(isset($form['pid'])) {
670 db_query("UPDATE {wymeditor_profiles}
671 SET name='%s',settings='%s' WHERE pid=%d",
672 $form['name'], $settings, $form['pid']);
673 drupal_set_message(t('The profile has been updated'));
674 }
675 else {
676 db_query("INSERT INTO {wymeditor_profiles} (name, settings) VALUES ('%s', '%s')",
677 $form['name'], $settings);
678 drupal_set_message(t('The new profile has been added'));
679
680 }
681 drupal_goto('admin/settings/wymeditor/profiles');
682
683 }
684
685 /**
686 * Submit task, associated to containers_form
687 */
688 function wymeditor_containers_form_submit($form_id, $form){
689 // Is it an 'edit' form or an 'add' form?
690 if(isset($form['cid'])) {
691 db_query("UPDATE {wymeditor_containers}
692 SET description='%s', tagname='%s', weight=%d WHERE cid=%d",
693 $form['description'], $form['tagname'], $form['weight'], $form['cid']);
694 drupal_set_message(t('The container has been updated'));
695 }
696 else {
697 db_query("INSERT INTO {wymeditor_containers} (description, tagname, weight) VALUES ('%s', '%s', %d)",
698 $form['description'], $form['tagname'], $form['weight']);
699 drupal_set_message(t('The new container has been added'));
700
701 }
702 drupal_goto('admin/settings/wymeditor/container');
703
704 }
705
706 /**
707 * Submit task, associated to classes_form
708 */
709 function wymeditor_classes_form_submit($form_id, $form){
710 // Is it an 'edit' form or an 'add' form?
711 if(isset($form['cid'])) {
712 db_query("UPDATE {wymeditor_classes}
713 SET name='%s', description='%s', allowed='%s', incompatible='%s', compatible='%s', weight=%d WHERE cid=%d",
714 $form['name'], $form['description'], $form['allowed'], $form['incompat'],
715 $form['compat'], $form['weight'], $form['cid']
716 );
717 drupal_set_message(t('The class has been updated'));
718 }
719 else {
720 db_query("INSERT INTO {wymeditor_classes} (name, description, allowed, incompatible, compatible, weight)
721 VALUES ('%s', '%s', '%s', '%s', '%s', %d)",
722 $form['name'], $form['description'], $form['allowed'], $form['incompat'], $form['compat'], $form['weight']);
723 drupal_set_message(t('The new class has been added')
724 );
725
726 }
727 drupal_goto('admin/settings/wymeditor/class');
728
729 }
730
731 /**
732 * Implementation of hook_perm().
733 */
734 function wymeditor_perm() {
735 return array( t('administer WYMeditor'), t('access WYMeditor') );
736 }
737
738 /**
739 * Returns profiles as an array (pid,name,settings)
740 *
741 * @param $pid Id of the profile to be returned. If null, return all profiles.
742 */
743 function _wymeditor_get_profiles($pid = null){
744 if(isset($pid)) {
745 $result = db_query('SELECT * FROM {wymeditor_profiles} WHERE pid=%d ORDER BY name', $pid);
746 }
747 else {
748 $result = db_query('SELECT * FROM {wymeditor_profiles} ORDER BY name', $pid);
749 }
750 while ($p = db_fetch_object($result)) {
751 $profiles[] = array(
752 'pid' => $p->pid,
753 'name' => $p->name,
754 'settings' => $p->settings,
755 );
756 }
757 return $profiles;
758 }
759
760 /**
761 * Returns containers as an array (cid,description, tagname,weight)
762 *
763 * @param $cid Id of the container to be returned. If null, return all containers.
764 */
765 function _wymeditor_get_containers($cid = null){
766 if(isset($cid)) {
767 $result = db_query('SELECT * FROM {wymeditor_containers} WHERE cid=%d ORDER BY weight', $cid);
768 }
769 else {
770 $result = db_query('SELECT * FROM {wymeditor_containers} ORDER BY weight', $cid);
771 }
772 while ($c = db_fetch_object($result)) {
773 $containers[] = array(
774 'cid' => $c->cid,
775 'description' => $c->description, // description which appears in wymeditor
776 'tagname' => $c->tagname, // actual tag name
777 'weight' => $c->weight,
778 );
779 }
780 return $containers;
781 }
782
783 /**
784 * Returns classes as an array (cid,name,description,allowed,incompat,compat,weight)
785 *
786 * @param $cid Id of the class to be returned. If null, return all classes.
787 */
788 function _wymeditor_get_classes($cid = null){
789 if(isset($cid)) {
790 $result = db_query('SELECT * FROM {wymeditor_classes} WHERE cid=%d ORDER BY weight', $cid);
791 }
792 else {
793 $result = db_query('SELECT * FROM {wymeditor_classes} ORDER BY weight', $cid);
794 }
795 while ($c = db_fetch_object($result)) {
796 $classes[] = array(
797 'cid' => $c->cid,
798 'name' => $c->name,
799 'description' => $c->description,
800 'allowed' => $c->allowed, // allowed containers
801 'incompat' => $c->incompatible, // incompatible classes
802 'compat' => $c->compatible, // compatible classes
803 'weight' => $c->weight,
804 );
805 }
806 return $classes;
807 }

  ViewVC Help
Powered by ViewVC 1.1.2