-
Notifications
You must be signed in to change notification settings - Fork 1
/
CKEditor.php
97 lines (83 loc) · 3.17 KB
/
CKEditor.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
<?php
namespace firdows\mkeditor;
use yii\helpers\ArrayHelper;
//use iutbay\yii2kcfinder\KCFinderAsset;
class CKEditor extends \dosamigos\ckeditor\CKEditor {
/**
* @inheritdoc
*/
public $filemanager = false;
public $uploadDir = '';
public $uploadURL = '';
public $onChange = false;
/**
* Registers CKEditor plugin
*/
protected function registerPlugin() {
if ($this->filemanager) {
$this->registerKCFinder();
}
if ($this->onChange) {
$this->registerOnChange();
}
parent::registerPlugin();
}
/**
* Registers KCFinder
*/
protected function registerKCFinder() {
$view = $this->getView();
$kcfinder = KCFinderAsset::register($view);
$kcfinderUrl = $kcfinder->baseUrl;
$browseOptions = [
'filebrowserBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=files',
'filebrowserImageBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=images',
'filebrowserFlashBrowseUrl' => $kcfinder->baseUrl . '/browse.php?opener=ckeditor&type=flash',
'filebrowserUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=files',
'filebrowserImageUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=images',
'filebrowserFlashUploadUrl' => $kcfinder->baseUrl . '/upload.php?opener=ckeditor&type=flash',
];
$this->clientOptions = ArrayHelper::merge($browseOptions, $this->clientOptions);
$config = $kcfinder->basePath . '/conf/config.php';
$data = file_get_contents($config);
$data = str_replace('"upload"', "'upload'", $data);
$data = str_replace('""', "''", $data);
$data = str_replace("'disabled' => true,", "'disabled' => false,", $data);
$data = str_replace("'uploadURL' => 'upload',", "'uploadURL' => '{$this->uploadURL}',", $data);
$data = str_replace("'uploadDir' => '',", "'uploadDir' => '{$this->uploadDir}',", $data);
file_put_contents($config, $data);
}
/**
*
* Method register editor on change
*
*/
protected function registerOnChange() {
$ckeditor = \dosamigos\ckeditor\CKEditorAsset::register($this->view);
$plugin = __DIR__ . '/plugins';
$this->recurse_copy($plugin, $ckeditor->basePath . '/plugins');
$browseOptions = [
'config.extraPlugins' => 'onchange'
];
$this->clientOptions = ArrayHelper::merge($browseOptions, $this->clientOptions);
}
/**
*
* @param type ต้นทาง
* @param type ปลายทาง
*/
private function recurse_copy($src, $dst) {
$dir = opendir($src);
@mkdir($dst);
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
$this->recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
}