Project

General

Profile

1 1428 Luisehahne
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         include
6
 * @author		    Christophe Dolivet (EditArea), Christian Sommer (WB wrapper)
7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.x
13
 * @requirements    PHP 5.2.2 and higher
14
 * @version         $Id$
15
 * @filesource		$HeadURL$
16
 * @lastmodified    $Date$
17
 *
18
 */
19
20
function loader_help()
21
{
22
23
?>
24
<script type="text/javascript">
25
/*<![CDATA[*/
26 1429 Luisehahne
		var url  = '<?php print WB_URL; ?>/include/editarea/edit_area_full.js';
27 1428 Luisehahne
		try{
28
			script = document.createElement("script");
29
			script.type = "text/javascript";
30 1429 Luisehahne
			script.src  = url;
31 1428 Luisehahne
			script.charset= "UTF-8";
32
			head = document.getElementsByTagName("head");
33
			head[0].appendChild(script);
34
		}catch(e){
35
			document.write("<script type='text/javascript' src='" + url + "' charset=\"UTF-8\"><"+"/script>");
36
		}
37
/*]]>*/
38
</script>
39
40
<?php
41
42
}
43
if (!function_exists('registerEditArea')) {
44
	function registerEditArea(
45
                $id = 'code_area',
46
                $syntax = 'php',
47
                $syntax_selection = true,
48
                $allow_resize = 'both',
49
                $allow_toggle = true,
50
                $start_highlight = true,
51
                $min_width = 600,
52
                $min_height = 450,
53
                $toolbar = 'default'  )
54
	{
55
56
		// set default toolbar if no user defined was specified
57
		if ($toolbar == 'default') {
58
			$toolbar = 'search, fullscreen, |, undo, redo, |, select_font, syntax_selection, |, highlight, reset_highlight, |, help';
59
			$toolbar = (!$syntax_selection) ? str_replace('syntax_selection,', '', $toolbar) : $toolbar;
60
		}
61
62
		// check if used Website Baker backend language is supported by EditArea
63
		$language = 'en';
64
		if (defined('LANGUAGE') && file_exists(dirname(__FILE__) . '/langs/' . strtolower(LANGUAGE) . '.js'))
65
        {
66
			$language = strtolower(LANGUAGE);
67
		}
68
69
		// check if highlight syntax is supported by edit_area
70
		$syntax = in_array($syntax, array('css', 'html', 'js', 'php', 'xml')) ? $syntax : 'php';
71
72
		// check if resize option is supported by edit_area
73
		$allow_resize = in_array($allow_resize, array('no', 'both', 'x', 'y')) ? $allow_resize : 'no';
74
75
		if(!defined('LOADER_HELP')) {
76
			loader_help();
77
	        define('LOADER_HELP', true);
78
		}
79
80
		// return the Javascript code
81
		$result = <<< EOT
82
		<script type="text/javascript">
83
			editAreaLoader.init({
84
				id: 				'$id',
85
				start_highlight:	$start_highlight,
86
				syntax:			    '$syntax',
87
				min_width:			$min_width,
88
				min_height:		    $min_height,
89
				allow_resize: 		'$allow_resize',
90
				allow_toggle: 		$allow_toggle,
91
				toolbar: 			'$toolbar',
92
				language:			'$language'
93
			});
94
		</script>
95
EOT;
96
		return $result;
97
	}
98
}
99
100
if (!function_exists('getEditAreaSyntax')) {
101
	function getEditAreaSyntax($file)
102
	{
103
		// returns the highlight scheme for edit_area
104
		$syntax = 'php';
105
		if (is_readable($file)) {
106
			// extract file extension
107
			$file_info = pathinfo($file);
108
109
			switch ($file_info['extension']) {
110
				case 'htm': case 'html': case 'htt':
111
					$syntax = 'html';
112
	  				break;
113
114
	 			case 'css':
115
					$syntax = 'css';
116
	  				break;
117
118
				case 'js':
119
					$syntax = 'js';
120
					break;
121
122
				case 'xml':
123
					$syntax = 'xml';
124
					break;
125
126
	 			case 'php': case 'php3': case 'php4': case 'php5':
127
					$syntax = 'php';
128
	  				break;
129
130
				default:
131
					$syntax = 'php';
132
					break;
133
			}
134
		}
135
		return $syntax ;
136
	}
137
}
138
139 909 doc
?>