-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathckeditor.php
More file actions
189 lines (158 loc) · 5.81 KB
/
ckeditor.php
File metadata and controls
189 lines (158 loc) · 5.81 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
*
* Plugin CKEditor
* @author Stephane F
*
**/
class ckeditor extends plxPlugin {
public $valid_path = false;
/**
* Constructeur de la classe ckeditor
*
* @param default_lang langue par défaut utilisée par PluXml
* @return null
* @authors Stephane F
**/
public function __construct($default_lang) {
# Appel du constructeur de la classe plxPlugin (obligatoire)
parent::__construct($default_lang);
# droits pour accéder à la page config.php du plugin
$this->setConfigProfil(PROFIL_ADMIN);
$this->addHook('AdminTopBottom', 'AdminTopBottom');
$this->valid_path = is_dir(PLX_ROOT.($this->getParam("folder")));
if($this->valid_path) {
# répertoire racine d'installation de PluXml sur le serveur
$dir = str_replace("\\", "/", dirname($_SERVER["SCRIPT_NAME"]));
$this->racine = trim(preg_replace("/\/(core|plugins)\/(.*)/", "", $dir), "/")."/";
$this->racine = $this->racine[0]!="/" ? "/".$this->racine : $this->racine;
# déclaration pour ajouter l'éditeur
$static = $this->getParam('static')==1 ? '' : '|statique';
if(!preg_match('/(parametres_edittpl|comment'.$static.')/', basename($_SERVER['SCRIPT_NAME']))) {
$this->addHook('AdminTopEndHead', 'AdminTopEndHead');
$this->addHook('AdminFootEndBody', 'AdminFootEndBody');
}
if(!isset($_POST['new_category'])) {
# conversion des liens abs/rel dans les articles et les pages statiques
$this->addHook('plxAdminEditArticle', 'Abs2Rel');
$this->addHook('plxAdminEditStatique', 'Abs2Rel');
# conversion des liens rel/abs dans les articles et les pages statiques
$this->addHook('AdminArticleTop', 'Rel2Abs');
$this->addHook('AdminStaticTop', 'Rel2Abs');
}
}
}
/**
* Méthode qui affiche un message si le répertoire de stockage des fichiers n'est pas définit dans la config du plugin
*
* @return stdio
* @author Stephane F
**/
public function AdminTopBottom() {
$string = '
if($plxAdmin->plxPlugins->aPlugins["'.__CLASS__.'"]->getParam("folder")=="") {
echo "<p class=\"warning\">Plugin '.__CLASS__.'<br />'.$this->getLang("L_ERR_FOLDER_NOT_DEFINED").'</p>";
plxMsg::Display();
} elseif(!$plxAdmin->plxPlugins->aPlugins["'.__CLASS__.'"]->valid_path) {
echo "<p class=\"warning\">Plugin '.__CLASS__.'<br />'.$this->getLang("L_ERR_FOLDER_INVALID_DIR").'</p>";
plxMsg::Display();
}';
echo '<?php '.$string.' ?>';
}
/**
* Méthode qui ajoute la déclaration du script javascript de ckeditor dans la partie <head>
*
* @return stdio
* @author Stephane F
**/
public function AdminTopEndHead() {
$plxAdmin = plxAdmin::getinstance();
$_SESSION['FILEMAN_FILES_ROOT'] = $this->racine.trim($this->getParam('folder'), "/");
if($plxAdmin->aConf['userfolders'] AND $_SESSION['profil']==PROFIL_WRITER) {
$_SESSION['FILEMAN_FILES_ROOT'] .= "/".$_SESSION['user'];
}
echo '<script src="'.PLX_PLUGINS.__CLASS__.'/ckeditor/ckeditor.js"></script>'."\n";
echo "<style>.cke_dialog_contents tr:hover { background-color: #fff; }</style>\n";
}
/**
* Méthode qui ajoute la déclaration du script javascript de ckeditor en bas de page
*
* @return stdio
* @author Stephane F
**/
public function AdminFootEndBody() {
$extra = trim($this->getParam('extraPlugins'));
$extraPlugins = ($extra !='' ? ','.$extra : '');
$extraPlugins = str_replace(' ', '', $extraPlugins);
$height = trim($this->getParam('height'));
if($height!='') $height = 'height:'.(is_numeric($height) ? $height : '"'.$height.'"').',';
?>
<script>
<!--
if(typeof CKEDITOR != 'undefined') {
var roxyFileman = "<?php echo PLX_PLUGINS.__CLASS__.'/fileman/index.html?integration='.__CLASS__ ?>";
var textareas = document.getElementsByTagName("textarea");
for(var i=0;i<textareas.length;i++) {
var n = textareas[i].name;
if(n=="content" || n=="chapo") {
CKEDITOR.replace('id_'+n, {
extraPlugins: 'justify,showblocks,embed,embedbase,lineutils,widgetselection,widget,notification,notificationaggregator,toolbar<?php echo $extraPlugins ?>',
<?php echo $height ?>
scayt_autoStartup: true,
extraAllowedContent: 'video[*]{*}',
filebrowserBrowseUrl: roxyFileman,
filebrowserImageBrowseUrl: roxyFileman+'&type=image',
removeDialogTabs: 'link:upload;image:upload',
entities: false,
allowedContent: true,
language: '<?php echo $this->default_lang ?>',
embed_provider : '//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
});
}
}
}
-->
</script>
<?php
//extraAllowedContent: 'video[*]{*};source[*]{*}',
}
/**
* Méthode qui convertit les liens absolus en liens relatifs
*
* @return stdio
* @author Stephane F
**/
public function Abs2Rel() {
echo '<?php
# Préparation des variables
$abs_path_images = "'.$this->racine.$this->getParam('folder').'";
$rel_path_images = "'.$this->getParam('folder').'";
# Les liens absolus commençant par http://www.domaine.com/ sont convertis en liens relatifs
if(isset($content["chapo"])) {
$content["chapo"] = str_replace($abs_path_images, $rel_path_images, $content["chapo"]);
}
$content["content"] = str_replace($abs_path_images, $rel_path_images, $content["content"]);
?>';
}
/**
* Méthode qui convertit les liens relatifs en liens absolus
*
* @return stdio
* @author Stephane F
**/
public function Rel2Abs() {
echo '<?php
if(!isset($_POST["draft"]) AND !isset($_POST["publish"]) AND !isset($_POST["update"]) AND !isset($_POST["moderate"])) {
# Préparation des variables
$abs_path_images = "'.$this->racine.$this->getParam('folder').'";
$rel_path_images = "'.$this->getParam('folder').'";
# Les liens relatifs sont convertis en liens absolus, pour que les images soient visibles dans CKEditor
if(isset($chapo)) {
$chapo = str_replace($rel_path_images, $abs_path_images, $chapo);
}
$content = str_replace($rel_path_images, $abs_path_images, $content);
}
?>';
}
}
?>