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
function loader_help()
18
{
19
?>
20
   <script type="text/javascript">
21
      var head= document.getElementsByTagName('head')[0];
22
      var script= document.createElement('script');
23
      script.type= 'text/javascript';
24
      script.src= '<?php print WB_URL; ?>/include/editarea/edit_area_full.js';
25
      head.appendChild(script);
26
   </script>
27
<?php
28

    
29
}
30

    
31
if (!function_exists('registerEditArea')) {
32
	function registerEditArea($id = 'code_area', $syntax = 'php', $syntax_selection = true
33
		, $allow_resize = 'no', $allow_toggle = true, $start_highlight = true
34
		, $min_width = 600, $min_height = 300, $toolbar = 'default')
35
	{
36

    
37
		// set default toolbar if no user defined was specified
38
		if ($toolbar == 'default') {
39
			$toolbar = 'search, fullscreen, |, undo, redo, |, select_font, syntax_selection, |, highlight, reset_highlight, |, help';
40
			$toolbar = (!$syntax_selection) ? str_replace('syntax_selection,', '', $toolbar) : $toolbar;
41
		}
42

    
43
		// check if used Website Baker backend language is supported by EditArea
44
		$language = 'en';
45
		if (defined('LANGUAGE') && file_exists(dirname(__FILE__) . '/langs/' . strtolower(LANGUAGE) . '.js')) {
46
			$language = strtolower(LANGUAGE);
47
		}
48

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

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

    
55
        loader_help();
56
		// return the Javascript code
57
		$result = <<< EOT
58
		<script type="text/javascript">
59
			editAreaLoader.init({
60
				id: 				'$id'
61
				,start_highlight:	$start_highlight
62
				,syntax:			'$syntax'
63
				,min_width:			$min_width
64
				,min_height:		$min_height
65
				,allow_resize: 		'$allow_resize'
66
				,allow_toggle: 		$allow_toggle
67
				,toolbar: 			'$toolbar'
68
				,language:			'$language'
69
			});
70
		</script>
71
EOT;
72
		return $result;	
73
	}
74
}
75

    
76
if (!function_exists('getEditAreaSyntax')) {
77
	function getEditAreaSyntax($file) 
78
	{
79
		// returns the highlight scheme for edit_area
80
		$syntax = 'php';
81
		if (is_readable($file)) {
82
			// extract file extension
83
			$file_info = pathinfo($file);
84
		
85
			switch ($file_info['extension']) {
86
				case 'htm': case 'html': case 'htt':
87
					$syntax = 'html';
88
	  				break;
89

    
90
	 			case 'css':
91
					$syntax = 'css';
92
	  				break;
93

    
94
				case 'js':
95
					$syntax = 'js';
96
					break;
97

    
98
				case 'xml':
99
					$syntax = 'xml';
100
					break;
101

    
102
	 			case 'php': case 'php3': case 'php4': case 'php5':
103
					$syntax = 'php';
104
	  				break;
105

    
106
				default:
107
					$syntax = 'php';
108
					break;
109
			}
110
		}
111
		return $syntax ;
112
	}
113
}
114

    
115
?>
(5-5/5)