Project

General

Profile

1 1142 Luisehahne
<?php
2 1241 Luisehahne
/**
3
 *
4 1271 Luisehahne
 * @category        modules
5 1359 Luisehahne
 * @package         wysiwyg
6 1271 Luisehahne
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8 1359 Luisehahne
 * @copyright       2009-2010, Website Baker Org. e.V.
9 1271 Luisehahne
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12 1349 Luisehahne
 * @requirements    PHP 5.2.2 and higher
13 1271 Luisehahne
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16 1241 Luisehahne
 *
17 1277 Luisehahne
 */
18 1142 Luisehahne
19
function reverse_htmlentities($mixed) {
20
	$mixed = str_replace(array('&gt;','&lt;','&quot;','&amp;'), array('>','<','"','&'), $mixed);
21
	return $mixed;
22
}
23
24
function get_template_name() {
25 1359 Luisehahne
	global $database;
26 1142 Luisehahne
	// returns the template name of the current displayed page
27
28
	// Loading config.php is not needed here, it is loaded before. It breaks the module when the editor is called form another dir as WB_PATH/modules/mymodule
29
	// require_once('../../config.php');
30
31 1161 Luisehahne
	// work out default editor.css file for CKeditor
32 1142 Luisehahne
	if(file_exists(WB_PATH .'/templates/' .DEFAULT_TEMPLATE .'/editor.css')) {
33
		$fck_template_dir = DEFAULT_TEMPLATE;
34
	} else {
35
		$fck_template_dir = "none";
36
	}
37
38
	// check if a editor.css file exists in the specified template directory of current page
39
	if (isset($_GET["page_id"]) && (int) $_GET["page_id"] > 0) {
40
		$pageid = (int) $_GET["page_id"];
41
42
		// obtain template folder of current page from the database
43 1161 Luisehahne
		$query_page = "SELECT template FROM " .TABLE_PREFIX ."pages WHERE page_id =$pageid";
44 1142 Luisehahne
		$pagetpl = $database->get_one($query_page);   // if empty, default template is used
45
46
		// check if a specific template is defined for current page
47
		if(isset($pagetpl) && $pagetpl != '') {
48
			// check if a specify editor.css file is contained in that folder
49
			if(file_exists(WB_PATH.'/templates/'.$pagetpl.'/editor.css')) {
50
				$fck_template_dir = $pagetpl;
51
			}
52
		}
53
	}
54
	return $fck_template_dir;
55
}
56
57
function show_wysiwyg_editor($name, $id, $content, $width, $height) {
58 1161 Luisehahne
	// create new CKeditor instance
59 1142 Luisehahne
	require_once(WB_PATH.'/modules/fckeditor/fckeditor/fckeditor.php');
60
	$oFCKeditor = new FCKeditor($name);
61
62
	// set defaults (Note: custom settings defined in: "/my_config/my_fckconfig.js" instead of "/editor/fckconfig.js")
63
	$oFCKeditor->BasePath = WB_URL.'/modules/fckeditor/fckeditor/';
64
	$oFCKeditor->Config['CustomConfigurationsPath'] = WB_URL .'/modules/fckeditor/wb_config/wb_fckconfig.js';
65
	$oFCKeditor->ToolbarSet = 'WBToolbar';        // toolbar defined in my_fckconfig.js
66
67
	// obtain template name of current page (if empty, no editor.css files exists)
68
	$template_name = get_template_name();
69
70
	// work out default CSS file to be used for FCK textarea
71
	if($template_name == "none") {
72
		// no editor.css file exists in default template folder, or template folder of current page
73
		$css_file = WB_URL .'/modules/fckeditor/wb_config/wb_fckeditorarea.css';
74
	} else {
75
		// editor.css file exists in default template folder or template folder of current page
76
		$css_file = WB_URL .'/templates/' .$template_name .'/editor.css';
77
	}
78
	// set CSS file depending on $css_file
79
	$oFCKeditor->Config['EditorAreaCSS'] = $css_file;
80
81
	// work out settings for the FCK "Style" toolbar
82
	if ($template_name == "none") {
83
		// no custom editor.css exists, use default XML definitions
84
		$oFCKeditor->Config['StylesXmlPath'] = WB_URL.'/modules/fckeditor/wb_config/wb_fckstyles.xml';
85
	} else {
86
		// file editor.css exists in template folder, parse it and create XML definitions
87
		$oFCKeditor->Config['StylesXmlPath'] = WB_URL.'/modules/fckeditor/css_to_xml.php?template_name=' .$template_name;
88
	}
89
90
	// custom templates can be defined via /wb_config/wb_fcktemplates.xml
91
	if(file_exists(WB_PATH .'/modules/fckeditor/wb_config/wb_fcktemplates.xml')) {
92 1168 Luisehahne
		$oFCKeditor->Config['TemplatesXmlPath'] = WB_URL.'/modules/fckeditor/wb_config/wb_fcktemplates.xml';
93 1142 Luisehahne
	}
94
95
  // set required file connectors (overwrite settings which may be made in fckconfig.js or my_fckconfig.js)
96
	$connectorPath = $oFCKeditor->BasePath.'editor/filemanager/connectors/php/connector.php';
97
  $oFCKeditor->Config['LinkBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
98
		.$connectorPath;
99
  $oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
100
		.$connectorPath;
101
  $oFCKeditor->Config['FlashBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
102
		.$connectorPath;
103
104 1182 Luisehahne
  if(defined('EDITOR_WIDTH'))
105
  {
106 1241 Luisehahne
    $width = ( ($width > EDITOR_WIDTH ) OR (EDITOR_WIDTH <= 0) ) ? $width : EDITOR_WIDTH;
107 1182 Luisehahne
  }
108
109 1142 Luisehahne
	$oFCKeditor->Value = reverse_htmlentities($content);
110
    $oFCKeditor->Width  = $width;
111
	$oFCKeditor->Height = $height;
112
	$oFCKeditor->Create();
113
}