Project

General

Profile

1
<?php
2

    
3
// $Id: include.php 1102 2009-07-30 21:37:53Z ruud $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
function reverse_htmlentities($mixed) {
27
	$mixed = str_replace(array('&gt;','&lt;','&quot;','&amp;'), array('>','<','"','&'), $mixed);
28
	return $mixed;
29
}
30

    
31
function get_template_name() {
32
	// returns the template name of the current displayed page
33

    
34
	// 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
35
	// require_once('../../config.php');
36
	require_once(WB_PATH. '/framework/class.database.php');
37

    
38
	// work out default editor.css file for FCKEditor
39
	if(file_exists(WB_PATH .'/templates/' .DEFAULT_TEMPLATE .'/editor.css')) {
40
		$fck_template_dir = DEFAULT_TEMPLATE;
41
	} else {
42
		$fck_template_dir = "none";
43
	}
44

    
45
	// check if a editor.css file exists in the specified template directory of current page
46
	if (isset($_GET["page_id"]) && (int) $_GET["page_id"] > 0) {
47
		$pageid = (int) $_GET["page_id"];
48

    
49
		// obtain template folder of current page from the database
50
		if(!isset($admin)) { 
51
			$database = new database(); 
52
		}
53
		$query_page = "SELECT template FROM " .TABLE_PREFIX ."pages WHERE page_id =$pageid"; 
54
		$pagetpl = $database->get_one($query_page);   // if empty, default template is used
55

    
56
		// check if a specific template is defined for current page
57
		if(isset($pagetpl) && $pagetpl != '') {
58
			// check if a specify editor.css file is contained in that folder
59
			if(file_exists(WB_PATH.'/templates/'.$pagetpl.'/editor.css')) {
60
				$fck_template_dir = $pagetpl;
61
			}
62
		}
63
	}
64
	return $fck_template_dir;
65
}
66

    
67
function show_wysiwyg_editor($name, $id, $content, $width, $height) {
68
	// create new FCKEditor instance
69
	require_once(WB_PATH.'/modules/fckeditor/fckeditor/fckeditor.php');
70
	$oFCKeditor = new FCKeditor($name);
71

    
72
	// set defaults (Note: custom settings defined in: "/my_config/my_fckconfig.js" instead of "/editor/fckconfig.js")
73
	$oFCKeditor->BasePath = WB_URL.'/modules/fckeditor/fckeditor/';
74
	$oFCKeditor->Config['CustomConfigurationsPath'] = WB_URL .'/modules/fckeditor/wb_config/wb_fckconfig.js';
75
	$oFCKeditor->ToolbarSet = 'WBToolbar';        // toolbar defined in my_fckconfig.js
76

    
77
	// obtain template name of current page (if empty, no editor.css files exists)
78
	$template_name = get_template_name();
79

    
80
	// work out default CSS file to be used for FCK textarea
81
	if($template_name == "none") {
82
		// no editor.css file exists in default template folder, or template folder of current page
83
		$css_file = WB_URL .'/modules/fckeditor/wb_config/wb_fckeditorarea.css';
84
	} else {
85
		// editor.css file exists in default template folder or template folder of current page
86
		$css_file = WB_URL .'/templates/' .$template_name .'/editor.css';
87
	}
88
	// set CSS file depending on $css_file
89
	$oFCKeditor->Config['EditorAreaCSS'] = $css_file;
90

    
91
	// work out settings for the FCK "Style" toolbar
92
	if ($template_name == "none") {
93
		// no custom editor.css exists, use default XML definitions
94
		$oFCKeditor->Config['StylesXmlPath'] = WB_URL.'/modules/fckeditor/wb_config/wb_fckstyles.xml';
95
	} else {
96
		// file editor.css exists in template folder, parse it and create XML definitions
97
		$oFCKeditor->Config['StylesXmlPath'] = WB_URL.'/modules/fckeditor/css_to_xml.php?template_name=' .$template_name;
98
	}
99

    
100
	// custom templates can be defined via /wb_config/wb_fcktemplates.xml
101
	if(file_exists(WB_PATH .'/modules/fckeditor/wb_config/wb_fcktemplates.xml')) {
102
		$oFCKeditor->Config['TemplatesXmlPath'] = WB_URL.'/modules/fckeditor/wb_config/wb_fcktemplates.xml';
103
	}
104

    
105
  // set required file connectors (overwrite settings which may be made in fckconfig.js or my_fckconfig.js)
106
	$connectorPath = $oFCKeditor->BasePath.'editor/filemanager/connectors/php/connector.php';
107
  $oFCKeditor->Config['LinkBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
108
		.$connectorPath;
109
  $oFCKeditor->Config['ImageBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
110
		.$connectorPath;
111
  $oFCKeditor->Config['FlashBrowserURL'] = $oFCKeditor->BasePath.'editor/filemanager/browser/default/browser.html?Connector='
112
		.$connectorPath;
113

    
114
	$oFCKeditor->Value = reverse_htmlentities($content);
115
	$oFCKeditor->Height = $height;
116
	$oFCKeditor->Create();
117
}
118

    
119
?>
(3-3/6)