Project

General

Profile

1
<?php
2
/**
3
 * Website Baker wrapper functions for the Javascript code editor: "EditArea"
4
 *
5
 * EditArea is created by Christophe Dolivet and released under "LGPL", 
6
 * "Apache" and "BSD" licenses. For the integration into Website Baker 
7
 * the LGPL license was choosen.
8
 *
9
 * LICENSE: GNU Lesser General Public License 3.0
10
 * 
11
 * @author		Christophe Dolivet (EditArea), Christian Sommer (WB wrapper)
12
 * @copyright	(c) 2005-2009
13
 * @license		http://www.gnu.org/copyleft/lesser.html
14
 * @version		0.7.2.3 
15
 * @platform	Website Baker 2.7
16
*/
17

    
18
if (!function_exists('registerEditArea')) {
19
	function registerEditArea($id = 'code_area', $syntax = 'php', $syntax_selection = true
20
		, $allow_resize = 'no', $allow_toggle = true, $start_highlight = true
21
		, $min_width = 600, $min_height = 300, $toolbar = 'default')
22
	{ 
23
		// set default toolbar if no user defined was specified
24
		if ($toolbar == 'default') {
25
			$toolbar = 'search, fullscreen, |, undo, redo, |, select_font, syntax_selection, |, highlight, reset_highlight, |, help';
26
			$toolbar = (!$syntax_selection) ? str_replace('syntax_selection,', '', $toolbar) : $toolbar;
27
		}
28
	
29
		// check if used Website Baker backend language is supported by EditArea
30
		$language = 'en';
31
		if (defined('LANGUAGE') && file_exists(dirname(__FILE__) . '/langs/' . strtolower(LANGUAGE) . '.js')) {
32
			$language = strtolower(LANGUAGE);
33
		}
34

    
35
		// check if highlight syntax is supported by edit_area
36
		$syntax = in_array($syntax, array('css', 'html', 'js', 'php', 'xml')) ? $syntax : 'php';
37

    
38
		// check if resize option is supported by edit_area
39
		$allow_resize = in_array($allow_resize, array('no', 'both', 'x', 'y')) ? $allow_resize : 'no';
40

    
41
		// return the Javascript code
42
		$result = <<< EOT
43
		<script language="javascript" type="text/javascript">
44
			editAreaLoader.init({
45
				id: 				'$id'
46
				,start_highlight:	$start_highlight
47
				,syntax:			'$syntax'
48
				,min_width:			$min_width
49
				,min_height:		$min_height
50
				,allow_resize: 		'$allow_resize'
51
				,allow_toggle: 		$allow_toggle
52
				,toolbar: 			'$toolbar'
53
				,language:			'$language'
54
			});
55
		</script>
56
EOT;
57
		return $result;	
58
	}
59
}
60

    
61
if (!function_exists('getEditAreaSyntax')) {
62
	function getEditAreaSyntax($file) 
63
	{
64
		// returns the highlight scheme for edit_area
65
		$syntax = 'php';
66
		if (is_readable($file)) {
67
			// extract file extension
68
			$file_info = pathinfo($file);
69
		
70
			switch ($file_info['extension']) {
71
				case 'htm': case 'html': case 'htt':
72
					$syntax = 'html';
73
	  				break;
74

    
75
	 			case 'css':
76
					$syntax = 'css';
77
	  				break;
78

    
79
				case 'js':
80
					$syntax = 'js';
81
					break;
82

    
83
				case 'xml':
84
					$syntax = 'xml';
85
					break;
86

    
87
	 			case 'php': case 'php3': case 'php4': case 'php5':
88
					$syntax = 'php';
89
	  				break;
90

    
91
				default:
92
					$syntax = 'php';
93
					break;
94
			}
95
		}
96
		return $syntax ;
97
	}
98
}
99

    
100
?>
(5-5/5)