/
include.php
157 lines (135 loc) · 6.24 KB
/
include.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
<?php
/**
*
* @category modules
* @package wysiwyg
* @author Michael Tenschert
* @author WebsiteBaker Project
* @copyright 2004-2009, Ryan Djurovich
* @copyright 2009-2010, Website Baker Org. e.V.
* @link http://www.websitebaker2.org/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WebsiteBaker 2.8.x
* @requirements PHP 4.4.9 and higher
* @version $Id: $
* @filesource $HeadURL: $
* @lastmodified $Date: $
*
*/
// prevent this file from being accessed directly
if ( !defined('WB_PATH'))
{
die(header('Location: index.php'));
}
// Prevent mixing-up when moving from SourceCode to WYSIWYG and back
function reverse_htmlentities($mixed)
{
$mixed = str_replace(array( '>', '<', '"', '&' ), array( '>', '<', '"', '&' ), $mixed);
return $mixed;
}
function get_ck_template($sub = '/editor.css')
{
global $page_template;
$default_tpl = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.$sub;
$template = $default_tpl = file_exists($default_tpl) ? $default_tpl : 'none';
$pageid = ( isset ( $_GET['page_id'] ) && (int)$_GET['page_id'] ) ? intval($_GET['page_id']) : 0;
// check if an editor.css file exists in the specified template directory of current page
if ( isset ( $pageid ) && (int)$pageid > 0 )
{
// $sql = 'SELECT `template` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$pageid;
// $template = $database->get_one($sql);
$template = WB_PATH.'/templates/'.$page_template.$sub;
$template = file_exists($template)
? str_replace(WB_PATH, WB_URL, $template) : str_replace(WB_PATH, WB_URL, $default_tpl);
} else {
$template = 'none';
}
return $template;
}
// For the editor.css we need to know if it exists and where it is
function get_css_template_name()
{
// returns the template name of the current displayed page
$ck_css_template_dir = get_ck_template('/editor.css');
if( $ck_css_template_dir == 'none' )
{
$ck_css_template_dir = get_ck_template('/css/editor.css');
}
return $ck_css_template_dir;
}
// For the editor.styles.js we need to know if it exists and where it is
// returns the template name of the current displayed page
// work out default editor.styles.js file for CKEditor
function get_styles_template_name()
{
$ck_styles_template_dir = get_ck_template('/editor.styles.js');
if( $ck_styles_template_dir == 'none' )
{
$ck_styles_template_dir = get_ck_template('/js/editor.styles.js');
}
return $ck_styles_template_dir;
}
function show_wysiwyg_editor($name, $id, $content, $width = '100%', $height = '350px')
{
// create new CKeditor instance
include_once ( WB_PATH.'/modules/ckeditor/ckeditor/ckeditor.php' );
$ckeditor = new CKEditor($name);
$ckeditor->basePath = WB_URL.'/modules/ckeditor/ckeditor/';
$ckeditor->config['height'] = $height;
$ckeditor->config['width'] = $width;
// obtain template name of current page for editor.css (if empty, no editor.css files exists)
$css_template_name = get_css_template_name();
if (file_exists(WB_PATH.'/modules/ckeditor/wb_config/custom/editor.css'))
{
$ck_editor_files = WB_URL.'/modules/ckeditor/wb_config/custom/editor.css';
} else {
$ck_editor_files = WB_URL.'/modules/ckeditor/wb_config/default/editor.css';
}
$ckeditor->config['contentsCss'] = ( $css_template_name == 'none' )
? $ck_editor_files : $css_template_name;
// obtain template name of current page for editor.styles.js (if empty, no editor.styles.js files exists)
$styles_template_name = get_styles_template_name();
// editor.styles.js file exists in default template folder, or template folder of current page
if (file_exists(WB_PATH.'/modules/ckeditor/wb_config/custom/editor.styles.js'))
{
$ck_styles_files = WB_URL.'/modules/ckeditor/wb_config/custom/editor.styles.js';
} else {
$ck_styles_files = WB_URL.'/modules/ckeditor/wb_config/default/editor.styles.js';
}
$styles_url = ( $styles_template_name == "none" )
? $ck_styles_files : $styles_template_name;
// The Styles dropdown in the editor. The styles_set needs to be set in each editor.styles.js!
$ckeditor->config['stylesSet'] = 'wb:'.$styles_url;
// The Templates list ("presets" like two columns with a picture) in the editor.
// The templates definition set to use. It accepts a comma separated list.
$ckeditor->config['templates'] = 'default';
// The list of templates definition files to load.
if (file_exists(WB_PATH.'/modules/ckeditor/wb_config/custom/editor.templates.js'))
{
$ck_templates_files[] = WB_URL.'/modules/ckeditor/wb_config/custom/editor.templates.js';
} else {
$ck_templates_files[] = WB_URL.'/modules/ckeditor/wb_config/default/editor.templates.js';
}
$ckeditor->config['templates_files'] = $ck_templates_files;
// The filebrowser are called in the include, because later on we can make switches, use WB_URL and so on
$connectorPath = $ckeditor->basePath.'filemanager/connectors/php/connector.php';
$ckeditor->config['filebrowserBrowseUrl'] = $ckeditor->basePath.'filemanager/browser/default/browser.html?Connector='.$connectorPath;
$ckeditor->config['filebrowserImageBrowseUrl'] = $ckeditor->basePath.'filemanager/browser/default/browser.html?Type=Image&Connector='.$connectorPath;
$ckeditor->config['filebrowserFlashBrowseUrl'] = $ckeditor->basePath.'filemanager/browser/default/browser.html?Type=Flash&Connector='.$connectorPath;
// The Uploader has to be called, too.
$uploadPath = $ckeditor->basePath.'filemanager/connectors/php/upload.php?Type=';
$ckeditor->config['filebrowserUploadUrl'] = $uploadPath.'File';
$ckeditor->config['filebrowserImageUploadUrl'] = $uploadPath.'Image';
$ckeditor->config['filebrowserFlashUploadUrl'] = $uploadPath.'Flash';
// Setup the CKE language
$ckeditor->config['language'] = strtolower(LANGUAGE);
// Get the config file
if (file_exists(WB_PATH.'/modules/ckeditor/wb_config/custom/wb_ckconfig.js'))
{
$ckeditor->config['customConfig'] = WB_URL.'/modules/ckeditor/wb_config/custom/wb_ckconfig.js';
} else {
$ckeditor->config['customConfig'] = WB_URL.'/modules/ckeditor/wb_config/default/wb_ckconfig.js';
}
$ckeditor->editor($name, reverse_htmlentities($content));
}
?>