forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionsGetTinyMCE.php
177 lines (152 loc) · 6.12 KB
/
functionsGetTinyMCE.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
<?php
global $tinyMCELibs;
$tinyMCEuid = uniqid();
// Basic configurations
$basicValidElements = 'a[role|href|target|data-toggle|data-parent|data-dismiss|aria-expanded|aria-controls|class|title],' .
'div[class|role|data-toggle|aria-labelledby|aria-hidden|aria-expanded|data-target|data-parent|style],' .
'button[class|data-toggle|data-target|data-dismiss|type|aria-expanded],' .
'span[class|aria-hidden|style],' .
'ul[class],' .
'li[class],' .
'i[class],' .
'img[class|src|alt|data-src|style],' .
'nav[class],' .
'input[class|type|data-toggle|placeholder|aria-describedby],' .
'label[for|class|data-toggle],' .
'textarea[class|rows|placeholder],' .
'h1[class],h2[class],h3[class],h4[class],h5[class],h6[class],' .
'p[class|style],' .
'br,' .
'hr[class],' .
'ol[class],' .
'blockquote[class],' .
'abbr[title],' .
'code,'.
'pre[class]';
$basicValidStyles = 'a{role|href|target|data-toggle|data-parent|data-dismiss|aria-expanded|aria-controls|class|title};' .
'div{class|role|data-toggle|aria-labelledby|aria-hidden|aria-expanded|data-target|data-parent|style};' .
'span{class|aria-hidden|style};' .
'img{class|src|alt|data-src|style};' .
'p{class|style};';
// Allowing all attributes, CSS, and tags
$extendedValidElements = '*[*]';
$extendedValidStyles = '';
// Toolbar and Plugins based on simpleMode or full feature
if ($simpleMode) {
// Conditional assignment based on PHP variables
$validElements = $basicValidElements;
$validStyles = $basicValidStyles;
$tinyMCEplugins = 'code preview autolink fullscreen link pagebreak nonbreaking anchor wordcount help ';
$tinyMCEtoolbar = 'fullscreen | styleselect align bold italic strikethrough underline | link | numlist bullist | removeformat | code';
$tinyMCEmenubar = false;
} else {
// Conditional assignment based on PHP variables
$validElements = $allowAllTags ? $extendedValidElements : $basicValidElements;
$validStyles = $allowCSS ? $extendedValidStyles : $basicValidStyles;
$tinyMCEplugins = 'code preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help';
$tinyMCEtoolbar = 'fullscreen | formatselect | align bold italic strikethrough underline | forecolor backcolor | link image media pageembed | numlist bullist | removeformat | code';
$tinyMCEmenubar = 'edit insert view format table tools help';
}
if (empty($tinyMCELibs)) {
$tinyMCELibs = 1;
?>
<script type="text/javascript" src="<?php echo getURL('node_modules/tinymce/tinymce.min.js'); ?>"></script>
<style>
.tox-statusbar__branding,
.tox-promotion {
display: none !important;
}
</style>
<?php
} else {
$tinyMCELibs++;
}
?>
<script>
<?php
if ($simpleMode) {
?>
function image_upload_handler<?php echo $tinyMCEuid; ?>(blobInfo, success, failure) {
avideoToastError('Image upload disabled');
}
<?php
} else {
?>
if (typeof videos_id === 'undefined') {
videos_id = -1;
}
const image_upload_handler<?php echo $tinyMCEuid; ?> = (blobInfo, progress) => new Promise((resolve, reject) => {
if (!videos_id) {
console.log('images_upload_handler !videos_id', videos_id);
$('#inputTitle').val("Article automatically booked");
saveVideo(false);
}
const xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', webSiteRootURL + 'objects/uploadArticleImage.php?video_id=' + videos_id);
xhr.upload.onprogress = (e) => {
progress(e.loaded / e.total * 100);
};
xhr.onload = () => {
if (xhr.status === 403) {
reject({
message: 'HTTP Error: ' + xhr.status,
remove: true
});
return;
}
if (xhr.status < 200 || xhr.status >= 300) {
reject('HTTP Error: ' + xhr.status);
return;
}
const json = JSON.parse(xhr.responseText);
if (!json || typeof json.url != 'string') {
reject('Invalid JSON: ' + xhr.responseText);
return;
}
resolve(json.url);
};
xhr.onerror = () => {
reject('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
};
const formData = new FormData();
formData.append('file_data', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
});
<?php
}
$language = ($_SESSION['language'] == 'en_US') ? 'us' : $_SESSION['language'];
$langFile = 'node_modules/tinymce-langs/langs/' . $language . '.js';
if (file_exists($global['systemRootPath'] . $langFile)) {
$language = "'{$language}'";
$language_url = "'" . getURL($langFile) . "'";
} else {
$language = 'null';
$language_url = 'null';
}
?>
setTimeout(function() {
tinymce.init({
language: <?php echo $language; ?>,
language_url: <?php echo $language_url; ?>,
selector: '#<?php echo $id; ?>', // change this value according to your HTML
plugins: '<?php echo $tinyMCEplugins; ?>',
toolbar: '<?php echo $tinyMCEtoolbar; ?>',
menubar: '<?php echo $tinyMCEmenubar; ?>',
height: 400,
convert_urls: false,
mobile: {
theme: 'silver'
},
images_upload_handler: image_upload_handler<?php echo $tinyMCEuid; ?>,
<?php
if (!empty($validElements)) {
echo "extended_valid_elements: '{$validElements}',";
}
if (!empty($valid_styles)) {
echo "valid_styles: '{$validStyles}',";
}
?>
});
}, <?php echo $tinyMCELibs * 500; ?>);
</script>