OSDN Git Service

ADD: Mocchiが手がけたファイル管理プラグイン一式をコミット
[nucleus-jp/nucleus-plugins.git] / trunk / NP_TinyMCE2j / NP_TinyMCE2j.php
1 <?php
2
3 /**
4   * Plugin for Nucleus CMS (http://plugins.nucleuscms.org/)
5   * Copyright (C) 2003 The Nucleus Plugins Project
6   *
7   * This program is free software; you can redistribute it and/or
8   * modify it under the terms of the GNU General Public License
9   * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   *
12   * see license.txt for the full license
13   */
14
15 /**
16  * Usage:
17  *              
18  *
19  * Versions:
20  *  0.9c        2005-09-28  eph
21  *              - upgrade to TinyMCE 2RC3
22  *              - lots of path fixes
23  *              - experimental GZip option. Should load quicker if it works
24  *  0.9b        2005-09-24  eph
25  *              - upgrade to TinyMCE 2RC2
26  *              - addition of File Manager
27  *              - bugfixes and cleaner uninstall
28  *      0.9             2005-07-16      roel
29  *              - initial implementation, mostly copied over from NP_EditControls by karma - http://demuynck.org 
30  */
31
32 class NP_TinyMCE2j extends NucleusPlugin {
33
34         function NP_TinyMCE2j() {
35                 // $this->baseUrl = $this->getAdminURL();
36                 // hardcoded relative path to avoid domain security issues (IE6 'Access is denied' error) 
37                 global $CONF;
38                 $this->baseUrl = str_replace ($CONF['AdminURL'],'',$this->getAdminURL()); 
39                 
40         }
41
42         function getName()              { return 'TinyMCE 2RC3'; }
43         function getAuthor()    { return 'karma | roel | eph'; }
44         function getURL()               { return 'http://demuynck.org/'; }
45         function getVersion()   { return '0.9c'; }
46         function getMinNucleusVersion() { return 300; }
47         function getDescription()
48         {
49                 return 'WYSIWYG XHTML 1.0 editor. Mozilla, MSIE and FireFox (Safari experimental).';
50         }
51                 
52
53
54         /**
55          * Make sure plugin still works when a database table prefix is activated for 
56          * the Nucleus installation. (Nucleus refuses to install plugins which do not
57          * support SqlTablePrefix when a database prefix is active)
58          */
59
60         function supportsFeature($what) {
61         switch($what) {
62                 case 'HelpPage':
63                                 return 0;
64                                 break;
65                         case 'SqlTablePrefix':
66                                         return 1;
67                                         break;
68                 default:
69                                 return 0;
70         }
71         }
72
73         function install() {
74                 // create plugin options (per-blog options)
75                 $this->createBlogOption('use_tinymce', 'Use TinyMCE editor', 'yesno', 'yes');
76
77                 // create plugin options (admin)
78                 $this->createOption('use_tgzip', 'Use TinyMCE GZip compression (experimental)', 'yesno', 'no');
79                 
80                 // disable the default javascript editbar that comes with nucleus
81                 mysql_query("UPDATE ".sql_table('config')." SET value='1' WHERE name='DisableJSTools'");
82                 
83                 // disable auto-linebreak conversions
84                 $this->setLinebreakConversion(0);
85                 
86         }
87         
88         function setLinebreakConversion($mode) {
89                 // modify auto-linebreak on the fly. Thx to alfmiti :)
90                 mysql_query("UPDATE ".sql_table('blog')." SET bconvertbreaks=".$mode);
91
92         }
93
94         function unInstall() {
95                 // restore to standard settings
96                 $this->setLinebreakConversion(1);
97                 mysql_query("UPDATE ".sql_table('config')." SET value='2' WHERE name='DisableJSTools'");
98         }
99
100         /**
101          * List of events we want to subscribe to
102          */
103         function getEventList() {
104                 return array(
105                         'AdminPrePageHead',                     // include javascript on admin add/edit pages
106                         'BookmarkletExtraHead',                 // include javascript on bookmarklet pages
107                         'PreSendContentType'                    // we need to force text/html instead of application/xhtml+xml
108                 );
109         }
110         
111         /**
112          * Hook into the <head> section of bookmarkler area pages.
113          * Insert extra script/css includes there.
114          */
115         function event_BookmarkletExtraHead(&$data)
116         {
117                 $this->_getExtraHead($data['extrahead']);       
118         }
119
120         /**
121          * Hook into the <head> section of admin area pages. When the requested page is an "add item" or
122          * "edit item" form, include the extra code.
123          */
124         function event_AdminPrePageHead(&$data) 
125         {
126                 $action = $data['action'];
127                 if (($action != 'createitem') && ($action != 'itemedit'))
128                         return;
129                 
130                 $this->_getExtraHead($data['extrahead']);
131                 
132         }       
133         
134         /**
135          * Returns the extra code that needs to be inserted in the <head>...</head> section of pages that
136          * use tinyMCE
137          */
138         function _getExtraHead(&$extrahead)
139         {
140                 global $CONF, $manager;
141
142                 // Found no function to detect blogid in this time -> do the long way
143                 if (is_array($manager->blogs)) {
144                         $tmp_keys = array_keys($manager->blogs);
145                         $blogid = $tmp_keys[0];
146                 }      
147                 
148                 // get the options for the current blog
149                 $bUseEditor     = ($this->getBlogOption($blogid, 'use_tinymce') == 'yes');
150
151                 // add code for html editor
152                 if ($bUseEditor)
153                 {
154                         // To avoid conflicts if a other user use only textmode we must set this on all calls
155                         $CONF['DisableJsTools'] = 1; // overrule simple global settings
156                         $this->setLinebreakConversion(0);
157                         
158                         // GZip compression?
159                         if ($this->getOption('use_tgzip') == 'yes')
160                                 $editorCode = '<script type="text/javascript" src="'.$this->baseUrl.'tiny_mce_gzip.php"></script>';
161                         else 
162                                 $editorCode = '<script type="text/javascript" src="'.$this->baseUrl.'tiny_mce.js"></script>';
163
164                 if(_CHARSET == 'UTF-8'){
165                         $lang_jp = 'ja_utf8';
166                 }elseif(_CHARSET == 'EUC-JP'){
167                         $lang_jp = 'ja_euc';
168                 }else{
169                         $lang_jp = 'en';
170                 }
171                         $editorCode .= <<<EOD
172 <script type="text/javascript">
173  tinyMCE.init({ 
174         language : "{$lang_jp}",
175         mode : "textareas",
176         theme : "advanced",
177         document_base_url : "{$CONF['IndexURL']}",
178         plugins : "paste,ibrowser,filemanager,emotions,searchreplace,table",
179         theme_advanced_buttons1 : "bold,italic,underline,strikethrough,forecolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,link,unlink",
180         theme_advanced_buttons1_add : "ibrowser,filemanager,emotions,separator,code",
181         theme_advanced_buttons2 : "undo,redo,separator,tablecontrols,separator,pastetext,pasteword,search,replace",
182         theme_advanced_buttons3 : "",
183         theme_advanced_toolbar_location : "top",
184         theme_advanced_toolbar_align : "left",
185         theme_advanced_path_location : "bottom",
186         extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],span[class|align|style]",
187         paste_create_paragraphs : true,
188         paste_use_dialog : true,
189         paste_auto_cleanup_on_paste : true,
190         theme_advanced_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1",
191         debug : false
192
193 });
194 </script>
195 EOD;
196
197                         $extrahead .= $editorCode;
198                 } else {
199                         $CONF['DisableJsTools'] = 2;
200                         $linebreak_conversion = $this->getOption('enable_br') == 'yes' ? 1 : 0;
201                         $this->setLinebreakConversion($linebreak_conversion);
202                 }
203
204         }
205         
206         /**
207          * Nucleus sends its admin area pages as application/xhtml+xml to browsers that can handle this.
208          *
209          * Unfortunately, this causes javascripts that alter page contents through non-DOM methods
210          * to stop working correctly. As the jscalendar and htmlarea both need this, we're forcing
211          * the content-type to text/html for add/edit item forms.
212          */
213         function event_PreSendContentType(&$data)
214         {
215                 $pageType = $data['pageType'];
216                 if ($pageType == 'skin')
217                         return;
218                 if (    ($pageType != 'bookmarklet-add')
219                         &&      ($pageType != 'bookmarklet-edit')
220                         &&      ($pageType != 'admin-createitem')
221                         &&      ($pageType != 'admin-itemedit')
222                         )
223                         return;
224                 
225                 if ($data['contentType'] == 'application/xhtml+xml')
226                         $data['contentType'] = 'text/html';
227         }
228         
229 }
230 ?>