-
Notifications
You must be signed in to change notification settings - Fork 0
/
TinyMCE.php
executable file
·327 lines (326 loc) · 8.67 KB
/
TinyMCE.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/**
* TinyMCE Nodule Class
*/
class TinyMCE extends TextArea
{
/**
* Default Themes
*/
const O2K7 = 'o2k7', O2K7Silver = 'o2k7_silver', O2K7Black = 'o2k7_black';
/**
* Default Themes
*/
const Basic = 'simple', Advanced = 'advanced';
/**
* Toolbar Strip Items
*/
const Anchor = 'anchor',
BGColor = 'backcolor',
Blockquote = 'blockquote',
Bold = 'bold',
BulletedList = 'bullist',
Button = 'Button',
CharMap = 'charmap',
Checkbox = 'Checkbox',
Cleanup = 'cleanup',
Code = 'code',
Copy = 'copy',
Cut = 'cut',
Emotions = 'emotions',
Font = 'fontselect',
FontSize = 'fontsizeselect',
Form = 'Form',
Format = 'formatselect',
FullPage = 'fullpage',
FullScreen = 'fullscreen',
Help = 'help',
HiddenField = 'HiddenField',
HorizontalRule = 'hr',
Image = 'image',
ImageButton = 'ImageButton',
Indent = 'indent',
Italic = 'italic',
JustifyCenter = 'justifycenter',
JustifyFull = 'justifyfull',
JustifyLeft = 'justifyleft',
JustifyRight = 'justifyright',
Link = 'link',
Media = 'media',
NewPage = 'newdocument',
NonBreaking = 'nonbreaking',
NumberedList = 'numlist',
Outdent = 'outdent',
PageBreak = 'pagebreak',
Paste = 'paste',
PasteFromWord = 'pasteword',
PasteText = 'pastetext',
Preview = 'preview',
Prints = 'print',
Radio = 'Radio',
Redo = 'redo',
RemoveFormat = 'removeformat',
Replace = 'replace',
RowBreak = '/',
Save = 'Save',
Search = 'search',
Select = 'Select',
SelectAll = 'selectall',
Seperator = '|',
ShowBlocks = 'ShowBlocks',
Source = 'Source',
SpellChecker = 'spellchecker',
Strike = 'strikethrough',
Styles = 'styleselect',
Subscript = 'sub',
Superscript = 'sup',
Table = 'Table',
Templates = 'template',
Textarea = 'Textarea',
TextColor = 'forecolor',
TextField = 'TextField',
Underline = 'underline',
Undo = 'undo',
Unlink = 'unlink',
VisualAid = 'visualaid',
VisualChars = 'visualchars';
/**
* Arraylist Holder for Toolbar Strips
*
* @var ImplicitArrayList
*/
private $Strips;
/**
* Array holder for Configuration options
*
* @var string|array
*/
private $Config;
/**
* Allows for handling of Toolbar Properties as if they were a real subclass
*
* @var Toolbar Innersugar
*/
static $_InToolbar = 'HandleToolbar';
/**
* Constructor
*
* @param string $text
* @param integer $left
* @param integer $top
* @param integer $width
* @param integer $height
* @return tinyMCE
*/
function TinyMCE($text = '', $left=0, $top=0, $width=500, $height=300)
{
parent::TextArea($text, $left, $top, $width, $height);
$this->Strips = new ImplicitArrayList($this, 'AddStrip', 'RemoveStripAt', 'ClearStrips');
$this->Strips->InsertFunctionName = 'InsertStrip';
$this->SetDefaults();
}
/**
* Sets the defaults of this tinyMCE instance
*/
private function SetDefaults()
{
$this->SetConfig('onchange_callback', '_N.TinyMCEBridge');
}
/**
* Returns the raw contents of the tinyMCE
* @return string
*/
// function GetText() {return $this->TextHolder->Text;}
/**
* Sets the Text of the tinyMCE
*
* @param string $text
*/
function SetText($text)
{
parent::SetText($text);
if($this->ShowStatus == Component::Shown)
ClientScript::Queue($this, "tinymce.get('$this').setContent", array($text));
}
function GetStrips() {return $this->Strips;}
/**
* Strips->Add() Delegate. Use $object->Strips->Add() instead of calling this method.
*/
function AddStrip($strip)
{
$this->Strips->Add($strip, true);
$this->SetToolbar($this->Strips->Elements);
}
/**
* Strips->Insert() Delegate. Use $object->Strips->Insert() instead of calling this method.
*/
function InsertStrip($strip, $index)
{
$this->Strips->Insert($strip, true);
$this->SetToolbar($this->Strips->Elements);
}
/**
* Strips->Remove() Delegate. Use $object->Strips->Remove() instead of calling this method.
*/
function RemoveStripAt($index)
{
$this->Strips->RemoveAt($index, true);
$this->SetToolbar($this->Strips->Elements);
}
/**
* Strips->Clear() Delegate. Use $object->Strips->Clear() instead of calling this method.
*/
function ClearStrips()
{
$this->Strips->Clear(true);
$this->SetToolbar($this->Strips->Elements);
}
/**
* Set a tinyMCE configuration option. See {@link http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html} for all options.
*
* @param mixed $option
* @param mixed $value
*/
function SetConfig($option, $value)
{
$this->Config[$option] = $value;
$this->Refresh();
}
/**
* Re-renders the tinyMCE instance. In most cases there is no need to call manually.
*
* @param mixed $race Whether to render with race condition safeguard.
*/
function Refresh($race = false)
{
if($this->ShowStatus == Component::Shown)
{
ClientScript::Queue($this,"tinymce.get('$this').destroy");
$args = ClientScript::ClientFormat($this->Config);
ClientScript::RaceQueue($this,
'tinymce', "var e=new tinymce.Editor('$this', $args);e.render();");
}
}
/**
* Toolbar InnerSugar Handler
*/
function HandleToolbar()
{
$args = func_get_args();
$invocation = InnerSugar::$Invocation;
$prop = strtolower(InnerSugar::$Tail);
if($invocation == InnerSugar::Set)
{
switch($prop)
{
case 'orientation':
$this->SetConfig('theme_advanced_toolbar_location', $args[0]);
break;
case 'alignment':
$this->SetConfig('theme_advanced_toolbar_align', $args[0]);
break;
default: throw new SugarException();
}
}
elseif($invocation == InnerSugar::Get)
{
$lookup = array(
'orientation' => 'theme_advanced_toolbar_location',
'alignment' => 'theme_advanced_toolbar_align');
if(isset($this->Config[$lookup[$prop]]))
return $this->Config[$lookup[$prop]];
}
}
/**
* Sets the current Skin of your tinyMCE instance. Please note that if you
* use a skin variant, your theme must be set to Advanced.
*
* Important: If creating your own variant, use skin_variant string structure
*
* @param tinyMCE::O2K7|tinyMCE::O2K7Silver|tinyMCE::O2K7Black|Custom $skin
*/
function SetSkin($skin)
{
$skin = explode('_', $skin);
$this->Config['skin'] = $skin[0];
if(isset($skin[1]))
$this->Config['skin_variant'] = $skin[1];
$this->Refresh();
}
/**
* Sets the current Theme of your tinyMCE instance.
*
* @param tinyMCE::Basic|tinyMCE::Advanced|Custom $theme
*/
function SetTheme($theme)
{
$this->SetConfig('theme', $theme);
}
/**
* Sets the Toolbar of the TinyMCE instance.
*
* If an array of arrays containting Toolbar Items is provided then Toolbar will be set to contain those items.
* In most cases this should be done via the Strips->Add syntax, and not directly through ->Toolbar.
*
* @param array(arrays) $toolbar
*/
function SetToolbar($toolbar)
{
if(is_array($toolbar))
{
/*Currently only works with plugins of same name,
but will later me modified to support plugins with multiple
properties, hence the lookup*/
$pluginLookup = array(
'emotions' => 'emotions',
'fullpage' => 'fullpage',
'fullscreen' => 'fullscreen',
'media ' => 'media',
'nonbreaking' => 'nonbreaking',
'pagebreak' => 'pagebreak',
'preview' => 'preview',
'print' => 'print',
'spellchecker' => 'spellchecker',
'visualchars' => 'visualchars');
$usedPlugins = array();
$i = 0;
foreach($toolbar as $strip)
{
if(is_array($strip))
{
if($intersection = array_intersect($pluginLookup, $strip))
array_merge($usedPlugins, $intersection);
$elements = implode(',', $strip);
$this->SetConfig('theme_advanced_buttons' . $i++, $elements);
}
}
if($usedPlugins)
$this->SetConfig('plugins', implode(',', $usedPlugins));
}
$this->Refresh(true);
}
function Leave()
{
// if($this->ShowStatus == Component::Shown)
ClientScript::Queue($this,"tinymce.get('$this').remove");
}
/**
* Do not call manually! Override of default Show(). Triggers when tinyMCE instance is initially shown.
*/
function Show()
{
parent::Show();
$relativePath = System::GetRelativePath(getcwd(), dirname(__FILE__));
//Add tinymce script files
ClientScript::AddSource($relativePath . 'tinymce/jscripts/tiny_mce/tiny_mce.js', false);
/*Add NOLOH bridge script file*/
//Debug Version
// ClientScript::AddSource($relativePath . 'Bridge/bridge.js', false);
//Minified Version
ClientScript::AddSource($relativePath . 'Bridge/bridge-min.js', false);
$args = ClientScript::ClientFormat($this->Config);
ClientScript::RaceQueue($this,
'tinymce', "var e=new tinymce.Editor('$this', $args);e.render();");
}
}
?>