source: extensions/FCKEditor/fckeditor.php @ 4629

Last change on this file since 4629 was 4629, checked in by patdenice, 14 years ago

[Plugin][FCK Editor]
Update to CKEditor v3.0.2
Add simple WYSIWYG editor to category edition, picture edition, NBM.
Still available for Additional Pages and PWG Stuffs.

File size: 3.6 KB
Line 
1<?php
2
3add_event_handler('get_admin_plugin_menu_links', 'load_fckeditor_script');
4 
5function load_fckeditor_script($plugin_menu_links)
6{
7  global $page, $template, $conf;
8
9  if (!isset($page['page'])) return $plugin_menu_links;
10
11  if (!($config = unserialize($conf['FCKEditor'])))
12  {
13    $config = array();
14  }
15  $toolbar = 'Full';
16  $width = '750px';
17  $height = '200px';
18  $areas = array();
19
20  // Category edit
21  if ($page['page'] == 'cat_modify')
22  {
23    $areas[] = 'comment';
24    $areas[] = 'mail_content';
25    $toolbar = 'Basic';
26    $template->set_prefilter('categories', 'add_remove_button');
27  }
28  // Picture modify
29  elseif ($page['page'] == 'picture_modify')
30  {
31    $areas[] = 'description';
32    $toolbar = 'Basic';
33    $template->set_prefilter('picture_modify', 'add_remove_button');
34  }
35  // Notification by mail
36  elseif ($page['page'] == 'notification_by_mail')
37  {
38    $areas[] = 'send_customize_mail_content';
39    $toolbar = 'Basic';
40    $template->set_prefilter('notification_by_mail', 'add_remove_button');
41  }
42  elseif ($page['page'] == 'plugin')
43  {
44    $section = $_GET['section'];
45    // Additional pages
46    if ($section == 'AdditionalPages/admin/add_page.php')
47    {
48      $areas[] = 'ap_content';
49      $width = '100%';
50      $height = '400px';
51      $template->set_prefilter('plugin_admin_content', 'add_remove_button');
52    }
53    // PWG Stuffs
54    elseif ($section == 'PWG_Stuffs/admin/add_module.php' and $_GET['type'] == 'Personal')
55    {
56      $areas[] = 'personal_content';
57      $width = '100%';
58      $height = '250px';
59      $template->set_prefilter('module_options', 'add_remove_button_stuffs');
60    }
61  }
62
63  if (!empty($areas))
64  {
65    $head_element = '
66<style type="text/css">
67FORM#catModify TABLE TABLE { width: 100%; }
68</style>
69<script type="text/javascript" src="'.FCK_PATH.'ckeditor/ckeditor.js"></script>
70<script type="text/javascript">
71CKEDITOR.config.toolbar_Basic =
72[
73  ["Source"],["Bold","Italic","Underline"],
74  ["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
75  ["Styles","Format","Font","FontSize"],
76  ["Link","Unlink","ShowBlocks"]
77];
78CKEDITOR.config.width = "'.$width.'";
79CKEDITOR.config.height = "'.$height.'";
80CKEDITOR.config.toolbar = "'.$toolbar.'";
81window.onload = function()
82{
83';
84    foreach ($areas as $area)
85    {
86      if (!isset($config[$area]) or $config[$area])
87      {
88        $head_element .= 'CKEDITOR.replace("'.$area.'");';
89      }
90    }
91    $head_element .= '
92}
93
94function toogleEditor(name) {
95  if (typeof( CKEDITOR.instances[name] ) != "undefined") {
96    CKEDITOR.instances[name].destroy();
97    jQuery.post("plugins/FCKEditor/update_config.php", {area: name, status: "off"});
98  } else {
99    CKEDITOR.replace(name);
100    jQuery.post("plugins/FCKEditor/update_config.php", {area: name, status: "on"});
101  }
102}
103</script>';
104
105    $template->append('head_elements', $head_element);
106  }
107  return $plugin_menu_links;
108}
109
110function add_remove_button($content, &$smarty)
111{
112  $pattern = '#(<textarea.*?name="(.*?)".*?</textarea>)#ims';
113  $replacement = '$1</td></tr><tr><td></td><td><a href="#" onClick="toogleEditor(\'$2\'); return false;" style="border-bottom: none; float: right;">FCK Editor On/Off</a>';
114  return preg_replace($pattern, $replacement, $content);
115}
116
117function add_remove_button_stuffs($content, &$smarty)
118{
119  $pattern = '#<textarea.*?</textarea>#ims';
120  $replacement = '<textarea name="personal_content" id="personal_content" rows="10" cols="50" style="width:100%; height: 300px;">{$PERSONAL_CONTENT}</textarea>
121<br><a href="#" onClick="toogleEditor(\'personal_content\'); return false;" style="border-bottom: none; float: right;">FCK Editor On/Off</a>';
122  return preg_replace($pattern, $replacement, $content);
123}
124
125?>
Note: See TracBrowser for help on using the repository browser.