-
Notifications
You must be signed in to change notification settings - Fork 1
/
TinyMceElFinder.php
73 lines (67 loc) · 1.73 KB
/
TinyMceElFinder.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
<?php
require_once __DIR__ . '/ElFinderHelper.php';
ElFinderHelper::importTinyMceFileManager();
/**
* elFinder file manager for TinyMCE.
*
* @author Robert Korulczyk <robert@korulczyk.pl>
* @author Bogdan Savluk <Savluk.Bogdan@gmail.com>
* @license http://opensource.org/licenses/BSD-3-Clause
*/
class TinyMceElFinder extends TinyMceFileManager {
/** @var string */
public $popupConnectorRoute = false;
/** @var array */
public $popupConnectorParams = [];
/** @var string */
public $popupTitle = 'Files';
public function getFileBrowserCallback() {
if (empty($this->popupConnectorRoute)) {
throw new CException('$popupConnectorRoute must be set!');
}
$connectorUrl = CJSON::encode(Yii::app()->controller->createUrl($this->popupConnectorRoute, $this->popupConnectorParams));
$title = CJSON::encode($this->popupTitle);
$tinymceVersion = 4;
if (method_exists($this, 'getTinymceVersion')) {
$tinymceVersion = $this->getTinymceVersion();
}
if ($tinymceVersion === 6) {
/* @noinspection ALL */
$script = <<<JS
function (callback, value, meta) {
window.tinymceImageUploadCallback = callback;
tinymce.activeEditor.windowManager.openUrl({
url: $connectorUrl,
title: $title,
width: 900,
height: 450,
resizable: "yes"
});
return false;
}
JS;
} else {
/* @noinspection ALL */
$script = <<<JS
function (field_name, url, type, win) {
tinymce.activeEditor.windowManager.open(
{
file: $connectorUrl,
title: $title,
width: 900,
height: 450,
resizable: "yes"
},
{
setUrl: function(url) {
win.document.getElementById(field_name).value = url;
}
}
);
window.tinymceImageUploadCallback = tinymce.activeEditor.windowManager.getParams().setUrl;
}
JS;
}
return 'js:' . $script;
}
}