]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WysiwygEdit/Wikiwyg.php
Add preview and save button on the toolbar.
[SourceForge/phpwiki.git] / lib / WysiwygEdit / Wikiwyg.php
1 <?php
2 rcs_id('$Id: Wikiwyg.php,v 1.5 2006-06-28 14:28:14 jeannicolas Exp $');
3 /**
4  * Wikiwyg is compatible with most internet browsers which
5  * include: IE 5.5+ (Windows), Firefox 1.0+, Mozilla 1.3+
6  * and Netscape 7+.
7  *
8  * Download: http://openjsan.org/doc/i/in/ingy/Wikiwyg/
9  * Suggested installation into themes/default/Wikiwyg/
10  *
11  * @package WysiwygEdit
12  * @author  Reini Urban, based on a patch by Jean-Nicolas GEREONE, STMicroelectronics, 2006
13  */
14
15 require_once("lib/WysiwygEdit.php");
16
17 class WysiwygEdit_Wikiwyg extends WysiwygEdit {
18
19     function WysiwygEdit_Wikiwyg() {
20         global $LANG;
21         $this->_transformer_tags = false;
22         $this->BasePath = DATA_PATH.'/themes/default/Wikiwyg';
23         $this->_htmltextid = "edit:content";
24         $this->_wikitextid = "editareawiki";
25         $this->_jsdefault = "
26 var base_url = '".DATA_PATH."';
27 var data_url = '$this->BasePath';
28 var script_url = '".deduce_script_name()."';
29 ";
30     }
31
32     function Head($name='edit[content]') {
33         global $WikiTheme;
34         foreach (array("Wikiwyg.js","Wikiwyg/Toolbar.js","Wikiwyg/Preview.js","Wikiwyg/Wikitext.js",
35                        "Wikiwyg/Wysiwyg.js","Wikiwyg/Phpwiki.js","Wikiwyg/HTML.js",
36                        "Wikiwyg/Toolbar.js") as $js) {
37             $WikiTheme->addMoreHeaders
38                 (Javascript('', array('src' => $this->BasePath . '/' . $js,
39                                       'language' => 'JavaScript')));
40         }
41         $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT) 
42             ? 'true' : 'false';
43         return JavaScript($this->_jsdefault . "
44 window.onload = function() {
45    var wikiwyg = new Wikiwyg.Phpwiki();
46    var config = {
47             doubleClickToEdit:  $doubleClickToEdit,
48             javascriptLocation: base_url+'/themes/default/Wikiwyg/',
49             toolbar: {
50                 imagesLocation: base_url+'/themes/default/Wikiwyg/images/',
51                 controlLayout: [
52                        'save','preview','|','save_button','|',
53                        'mode_selector', '/',
54                        'p','|',
55                        'h2', 'h3', 'h4','|',
56                        'bold', 'italic', '|',
57                        'sup', 'sub', '|',
58                        'toc',
59                        'wikitext','|',
60                        'pre','|',
61                        'ordered', 'unordered','hr','|',
62                        'link','|',
63                        'table'
64                        ],
65                 styleSelector: [
66                        'label', 'p', 'h2', 'h3', 'h4', 'pre'
67                                 ], 
68                 controlLabels: {
69                        save:     '"._("Apply changes")."',
70                        cancel:   '"._("Exit toolbar")."',
71                        h2:       '"._("Title 1")."',
72                        h3:       '"._("Title 2")."',
73                        h4:       '"._("Title 3")."',
74                        verbatim: '"._("Verbatim")."',
75                        toc:   '"._("Table of content")."', 
76                        wikitext:   '"._("Insert Wikitext section")."', 
77                        sup:      '"._("Sup")."', 
78                        sub:      '"._("Sub")."',
79                        preview:  '"._("Preview")."',   
80                        save_button:'"._("Save")."'   
81                       }
82             },
83             wysiwyg: {
84                 iframeId: 'iframe0'
85             },
86             wikitext: {
87               supportCamelCaseLinks: true
88             }
89    };
90    var div = document.getElementById(\"" . $this->_htmltextid . "\");
91    wikiwyg.createWikiwygArea(div, config);
92    wikiwyg_divs.push(wikiwyg);
93    wikiwyg.editMode();
94 }");
95     }
96
97     function Textarea ($textarea, $wikitext, $name='edit[content]') {
98         $htmltextid = $this->_htmltextid;
99         $textarea->SetAttr('id', $htmltextid);
100         $iframe0 = new RawXml('<iframe id="iframe0" height="0" width="0" frameborder="0"></iframe>');
101         $out = HTML($textarea,
102                     $iframe0,
103                     "\n");
104         return $out;
105     }
106
107     /**
108      * Handler to convert the Wiki Markup to HTML before editing.
109      * This will be converted back by WysiwygEdit_ConvertAfter if required.
110      *  *text* => '<b>text<b>'
111      */
112     function ConvertBefore($text) {
113         return $text;
114     }
115
116     /* 
117      * No special PHP HTML->Wikitext conversion needed. This is done in js thanksfully. 
118      * Avoided in editpage.php: PageEditor->getContent
119      */
120     function ConvertAfter($text) {
121         return TransformInline($text);
122     }
123 }
124
125
126 /*
127  $Log: not supported by cvs2svn $
128  Revision 1.4  2006/06/19 17:33:06  jeannicolas
129
130  Add button to insert table of content plugin
131  Add button to insert wikitext section in wysiwyg mode
132
133  Fix internet explorer issue in wikitext mode. The toolbar in this mode didn't work.
134
135  Revision 1.3  2006/05/31 19:59:57  jeannicolas
136
137
138  Added wysiwyg_editor 1.1b
139
140  Revision 1.2  2006/05/14 17:52:20  rurban
141  fix syntax error. delete a left-over attempt to add CSS links also. We did put everything into phpwiki.css for browser compatibility.
142
143  Revision 1.1  2006/05/13 19:59:55  rurban
144  added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
145  converted wysiwyg_editor-1.3a js to WysiwygEdit framework
146  changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
147
148
149 */
150
151 // Local Variables:
152 // mode: php
153 // tab-width: 8
154 // c-basic-offset: 4
155 // c-hanging-comment-ender-p: nil
156 // indent-tabs-mode: nil
157 // End:
158 ?>