1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Remember to include the javascript as well |
4
|
|
|
* |
5
|
|
|
* @package Intraface_CMS |
6
|
|
|
*/ |
7
|
|
|
class Intraface_modules_cms_HTML_Editor |
8
|
|
|
{ |
9
|
|
|
public $allowed_tags; |
10
|
|
|
public $implemented_editors = array( |
11
|
|
|
'none', 'tinymce', 'wiki' |
12
|
|
|
); |
13
|
|
|
public $editor; |
14
|
|
|
public $options; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Constructor |
18
|
|
|
*/ |
19
|
|
|
function __construct($allowed_tags = '') |
20
|
|
|
{ |
21
|
|
|
$this->allowed_tags = $allowed_tags; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function setEditor($editor) |
25
|
|
|
{ |
26
|
|
|
if (!in_array($editor, $this->implemented_editors)) { |
27
|
|
|
throw new Exception($editor . 'editor not implemented'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$this->editor = $editor; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function get($textarea_attributes, $initial_value = '', $editor_attributes = array()) |
34
|
|
|
{ |
35
|
|
|
$output = ''; |
|
|
|
|
36
|
|
|
switch ($this->editor) { |
37
|
|
|
case 'tinymce': |
38
|
|
|
// return tinymce textarea |
39
|
|
|
|
40
|
|
|
$blockformat = array(); |
41
|
|
|
$button = array(); |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
if (!empty($editor_attributes['plugins']) and is_array($editor_attributes['plugins'])) { |
|
|
|
|
45
|
|
|
if (in_array('save', $editor_attributes['plugins'])) { |
46
|
|
|
$button[] = 'save'; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$button[] = 'undo'; |
51
|
|
|
$button[] = 'redo'; |
52
|
|
|
|
53
|
|
|
if (!empty($this->allowed_tags) and is_array($this->allowed_tags)) { |
|
|
|
|
54
|
|
|
if (in_array('p', $this->allowed_tags)) { |
55
|
|
|
$blockformat[] = 'p'; |
56
|
|
|
} |
57
|
|
|
if (in_array('h1', $this->allowed_tags)) { |
58
|
|
|
$blockformat[] = 'h1'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (in_array('h2', $this->allowed_tags)) { |
62
|
|
|
$blockformat[] = 'h2'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (in_array('h3', $this->allowed_tags)) { |
66
|
|
|
$blockformat[] = 'h3'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (in_array('h4', $this->allowed_tags)) { |
70
|
|
|
$blockformat[] = 'h4'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (in_array('blockquote', $this->allowed_tags)) { |
74
|
|
|
$blockformat[] = 'blockquote'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (in_array('strong', $this->allowed_tags)) { |
78
|
|
|
$button[] = 'bold'; |
79
|
|
|
} elseif (in_array('b', $this->allowed_tags)) { |
80
|
|
|
$button[] = 'bold'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (in_array('em', $this->allowed_tags)) { |
84
|
|
|
$button[] = 'italic'; |
85
|
|
|
} elseif (in_array('i', $this->allowed_tags)) { |
86
|
|
|
$button[] = 'italic'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (in_array('a', $this->allowed_tags)) { |
90
|
|
|
$button[]= 'link'; |
91
|
|
|
$button[]= 'unlink'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (in_array('ul', $this->allowed_tags)) { |
95
|
|
|
$button[] = 'bullist'; |
96
|
|
|
} |
97
|
|
|
if (in_array('ol', $this->allowed_tags)) { |
98
|
|
|
$button[] = 'numlist'; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (!empty($blockformat)) { |
103
|
|
|
$button[] = 'formatselect'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
|
108
|
|
|
// link, unlink - hvis link er tilladte |
109
|
|
|
// bold, italic - hvis de er tilladte |
110
|
|
|
// formatselect - if blockformats !empty |
111
|
|
|
// bullist, numlist - if lists are availabel |
112
|
|
|
// spellchecker - if it is turned on |
113
|
|
|
|
114
|
|
|
// original list of buttons1: , bold, italic, formatselect, separator, bullist,numlist,separator,undo,redo,separator,link,unlink,separator,sub,sup,separator, tablecontrols, separator,charmap,separator,cleanup,code,spellchecker,separator,help,pasteword |
|
|
|
|
115
|
|
|
|
116
|
|
|
if (!empty($editor_attributes['plugins']) and is_array($editor_attributes['plugins'])) { |
|
|
|
|
117
|
|
|
if (in_array('spellchecker', $editor_attributes['plugins'])) { |
|
|
|
|
118
|
|
|
// $button[] = 'spellchecker'; |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if (in_array('table', $editor_attributes['plugins']) and in_array('table', $this->allowed_tags)) { |
|
|
|
|
122
|
|
|
$button[] = 'tablecontrols'; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$button[] = 'code'; |
127
|
|
|
$button[] = 'pasteword'; |
128
|
|
|
|
129
|
|
|
$output = '<textarea'.$this->_parseTextareaAttributes($textarea_attributes).'>'.htmlentities(utf8_decode($initial_value)).'</textarea>'."\n"; |
130
|
|
|
$output .= '<script language="javascript" type="text/javascript">'."\n"; |
131
|
|
|
$output .= 'tinyMCE.init({'."\n"; |
132
|
|
|
$output .= ' mode : "exact",'."\n"; |
133
|
|
|
$output .= ' elements : "'.$textarea_attributes['id'].'",'."\n"; |
134
|
|
|
$output .= ' theme : "advanced",'."\n"; |
135
|
|
|
if (!empty($editor_attributes['plugins']) and is_array($editor_attributes['plugins'])) { |
|
|
|
|
136
|
|
|
$output .= ' plugins : "'.implode($editor_attributes['plugins'], ',').'",'."\n"; |
137
|
|
|
} |
138
|
|
|
$output .= ' theme_advanced_buttons1 : "'.implode($button, ',').'",'."\n"; |
139
|
|
|
$output .= ' theme_advanced_buttons2 : "",'."\n"; |
140
|
|
|
$output .= ' theme_advanced_buttons3 : "",'."\n"; |
141
|
|
|
$output .= ' theme_advanced_blockformats : "'.implode($blockformat, ',').'",'."\n"; |
142
|
|
|
$output .= ' theme_advanced_toolbar_location : "top",'."\n"; |
143
|
|
|
$output .= ' theme_advanced_toolbar_align : "left",'."\n"; |
144
|
|
|
$output .= ' cleanup : true,'."\n"; |
145
|
|
|
$output .= ' clean_on_startup : true,'."\n"; |
146
|
|
|
$output .= ' verify_html : true,'."\n"; |
147
|
|
|
$output .= ' apply_source_formatting : true,'."\n"; |
148
|
|
|
$output .= ' relative_urls : false,'."\n"; |
149
|
|
|
$output .= ' convert_urls : false,'."\n"; |
150
|
|
|
$output .= ' entity_encoding : "raw",'."\n"; |
151
|
|
|
$output .= ' remove_linebreaks : true'."\n"; |
152
|
|
|
//$output .= ' spellchecker_languages : "+Danish=da, English=en"'; |
|
|
|
|
153
|
|
|
|
154
|
|
|
$output .= '});'."\n"; |
155
|
|
|
$output .= '</script>'."\n"; |
156
|
|
|
|
157
|
|
|
break; |
158
|
|
|
/* |
|
|
|
|
159
|
|
|
case 'widgeditor': |
160
|
|
|
if (!empty($texarea_attributes['class'])) $texarea_attributes['class'] .= ' widgeditor'; |
161
|
|
|
else $texarea_attributes['class'] .= 'widgeditor'; |
162
|
|
|
$output = '<textarea'.$this->_parseTextareaAttributes($textarea_attributes).'>'.htmlentities($initial_value).'</textarea>'; |
163
|
|
|
break; |
164
|
|
|
*/ |
165
|
|
|
case 'wiki': |
166
|
|
|
// fall through |
167
|
|
|
default: |
168
|
|
|
// return ordinary textarea |
169
|
|
|
$output = '<textarea'.$this->_parseTextareaAttributes($textarea_attributes).'>'.htmlspecialchars($initial_value).'</textarea>'; |
170
|
|
|
break; |
171
|
|
|
} |
172
|
|
|
return $output; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
function _parseTextareaAttributes($textarea_attributes) |
176
|
|
|
{ |
177
|
|
|
$output = ''; |
178
|
|
|
if (array_key_exists('id', $textarea_attributes)) { |
179
|
|
|
$output .= ' id="'.$textarea_attributes['id'].'"'; |
180
|
|
|
} |
181
|
|
|
if (array_key_exists('name', $textarea_attributes)) { |
182
|
|
|
$output .= ' name="'.$textarea_attributes['name'].'"'; |
183
|
|
|
} |
184
|
|
|
if (array_key_exists('cols', $textarea_attributes)) { |
185
|
|
|
$output .= ' cols="'.$textarea_attributes['cols'].'"'; |
186
|
|
|
} |
187
|
|
|
if (array_key_exists('rows', $textarea_attributes)) { |
188
|
|
|
$output .= ' rows="'.$textarea_attributes['rows'].'"'; |
189
|
|
|
} |
190
|
|
|
if (array_key_exists('class', $textarea_attributes)) { |
191
|
|
|
$output .= ' class="'.$textarea_attributes['class'].'"'; |
192
|
|
|
} |
193
|
|
|
return $output; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.