1
|
|
|
<?php |
2
|
|
|
/**************************************************************************** |
3
|
|
|
* common functions for text editors |
4
|
|
|
* |
5
|
|
|
****************************************************************************/ |
6
|
|
|
|
7
|
|
|
// used in both lib1 and lib2 code |
8
|
|
|
|
9
|
|
|
use OcLegacy\Editor\EditorConstants; |
10
|
|
|
|
11
|
|
|
require_once __DIR__ . '/smiley.inc.php'; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Do all the conversions needed to process HTML or plain text editor input, |
16
|
|
|
* for either storing it into the database or (when swiching modes) |
17
|
|
|
* re-displaying it in another editor mode. |
18
|
|
|
* |
19
|
|
|
* oldDescMode is the mode in which the editor was running which output the $text, |
20
|
|
|
* or 0 if the text came from the database with `htm_text` = 0. |
21
|
|
|
* |
22
|
|
|
* descMode is == descMode if the user hit the editor's "save" button, |
23
|
|
|
* or the new mode if the user hit another mode button |
24
|
|
|
* @param mixed $oldDescMode |
25
|
|
|
* @param mixed $descMode |
26
|
|
|
* @param mixed $text |
27
|
|
|
* @param & $representText |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param $oldDescMode |
32
|
|
|
* @param $descMode |
33
|
|
|
* @param $text |
34
|
|
|
* @return mixed|string |
35
|
|
|
*/ |
36
|
|
|
function processEditorInput($oldDescMode, $descMode, $text, &$representText) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
global $opt; |
39
|
|
|
|
40
|
|
|
// save HTML input => verify / tidy / filter; |
41
|
|
|
// also implemented in okapi/services/logs/submit.php |
42
|
|
|
$purifier = new OcHTMLPurifier($opt); |
43
|
|
|
$text = $purifier->purify($text); |
44
|
|
|
$representText = $text; |
45
|
|
|
|
46
|
|
|
return $text; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
// $texthtml0 is set if the text is from cache_desc.desc or cache_logs.text |
51
|
|
|
// and text_html is 0, i.e. the text was edited in the "text" editor mode. |
52
|
|
|
// |
53
|
|
|
// If $wrap is > 0, longer lines will be wrapped to new lines. |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $text |
57
|
|
|
* @param $texthtml0 |
58
|
|
|
* |
59
|
|
|
* @return mixed|string |
60
|
|
|
*/ |
61
|
|
|
function html2plaintext($text, $texthtml0) |
62
|
|
|
{ |
63
|
|
|
global $smiley; |
64
|
|
|
|
65
|
|
|
if ($texthtml0) { |
66
|
|
|
$text = str_replace( |
67
|
|
|
[ |
68
|
|
|
'<p>', |
69
|
|
|
"\n", |
70
|
|
|
"\r", |
71
|
|
|
], |
72
|
|
|
'', |
73
|
|
|
$text |
74
|
|
|
); |
75
|
|
|
$text = str_replace( |
76
|
|
|
[ |
77
|
|
|
'<br />', |
78
|
|
|
'</p>', |
79
|
|
|
], |
80
|
|
|
"\n", |
81
|
|
|
$text |
82
|
|
|
); |
83
|
|
|
$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); |
84
|
|
|
} else { |
85
|
|
|
// convert smileys ... |
86
|
|
|
$countSmileyImage = count($smiley['image']); |
87
|
|
|
for ($n = 0; $n < $countSmileyImage; $n++) { |
88
|
|
|
$text = mb_ereg_replace( |
89
|
|
|
'<img [^>]*?src=[^>]+?' . str_replace('.', '\.', $smiley['file'][$n]) . '[^>]+?>', |
90
|
|
|
'[s![' . $smiley['text'][$n] . ']!s]', |
91
|
|
|
$text |
92
|
|
|
); |
93
|
|
|
// the [s[ ]s] is needed to protect the spaces around the smileys |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// REDMINE-1249: Missing log text in mail notification |
97
|
|
|
// simpler solution that converts html to text as the previous class html2text emptied the text completely |
98
|
|
|
// implementation for line wrap, url's and probably more is missing |
99
|
|
|
$text = preg_replace( "/\n\s+/", "\n", rtrim(html_entity_decode(strip_tags($text)))); |
100
|
|
|
|
101
|
|
|
$text = str_replace( |
102
|
|
|
[ |
103
|
|
|
'[s![', |
104
|
|
|
']!s]', |
105
|
|
|
], |
106
|
|
|
'', |
107
|
|
|
$text |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $text; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
function editorJsPath() |
119
|
|
|
{ |
120
|
|
|
return 'resource2/ocstyle/js/editor.js?ft=' . filemtime('resource2/ocstyle/js/editor.js'); |
121
|
|
|
} |
122
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.