Project

General

Profile

1
<?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: wb_wrapper_edit_area.php 2033 2013-12-16 03:04:56Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/include/editarea/wb_wrapper_edit_area.php $
16
 * @lastmodified    $Date: 2013-12-16 04:04:56 +0100 (Mon, 16 Dec 2013) $
17
 *
18
 */
19

    
20
function loader_help()
21
{
22

    
23
?>
24
<script type="text/javascript">
25
/*<![CDATA[*/
26
		var url  = '<?php print WB_URL; ?>/include/editarea/edit_area_full.js';
27
		try{
28
			script = document.createElement("script");
29
			script.type = "text/javascript";
30
			script.src  = url;
31
			script.charset= "UTF-8";
32
			head = document.getElementsByTagName("head")[0];
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
if (!function_exists('getEditareaDefaultSettings')) {
43
    function getEditareaDefaultSettings() {
44
        
45
    /**
46
     * toolbar: define the toolbar that will be displayed, each element being separated by a ",".
47
     * Type: String (combinaison of: "|", "*", "search", "go_to_line", "undo", "redo", "change_smooth_selection", "reset_highlight", "highlight", "word_wrap", "help", "save", "load", "new_document", "syntax_selection")
48
     * "|" or "separator" make appears a separator in the toolbar.
49
     * "*" or "return" make appears a line-break in the toolbar
50
     * Default: "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"
51
     */
52
    
53
    return array (
54
    		'id' => "src"	// should contain the id of the textarea that should be converted into an editor
55
    		,'language' => "en"
56
    		,'syntax' => ""
57
    		,'start_highlight' => false	// if start with highlight
58
    		,'is_multi_files' => false		// enable the multi file mode (the textarea content is ignored)
59
    		,'min_width' => 400
60
    		,'min_height' => 125
61
    		,'allow_resize' => "y"	// possible values: "no", "both", "x", "y"
62
    		,'allow_toggle' => true		// true or false
63
    		,'plugins' => "" // comma separated plugin list
64
    		,'browsers' => "all"	// all or known
65
    		,'display' => "onload" 		// onload or later
66
    		,'toolbar' => "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"
67
    		,'begin_toolbar' => ""		//  "new_document, save, load, |"
68
    		,'end_toolbar' => ""		// or end_toolbar
69
    		,'font_size' => "10"		// not for IE
70
    		,'font_family' => "monospace, verdana"	// can be "verdana,monospace". Allow non monospace font but Firefox get smaller tabulation with non monospace fonts. IE doesn't change the tabulation width and Opera doesn't take this option into account... 
71
    		,'cursor_position' => "begin"
72
    		,'gecko_spellcheck' => false	// enable/disable by default the gecko_spellcheck
73
    		,'max_undo' => 30
74
    		,'fullscreen' => false
75
    		,'is_editable' => true
76
    		,'word_wrap' => false		// define if the text is wrapped of not in the textarea
77
    		,'replace_tab_by_spaces' => false
78
    		,'debug' => false		// used to display some debug information into a newly created textarea. Can be usefull to display trace info in it if you want to modify the code
79
    		,'show_line_colors' => false	// if the highlight is disabled for the line currently beeing edited (if enabled => heavy CPU use)
80
    		,'syntax_selection_allow' => "basic,brainfuck,c,coldfusion,cpp,css,html,java,js,pas,perl,php,python,ruby,robotstxt,sql,tsql,vb,xml"
81
    		,'smooth_selection' => true
82
    		,'autocompletion' => false	// NOT IMPLEMENTED			
83
    		,'load_callback' => ""		// click on load button (function name)
84
    		,'save_callback' => ""		// click on save button (function name)
85
    		,'change_callback' => ""	// textarea onchange trigger (function name)
86
    		,'submit_callback' => ""	// form submited (function name)
87
    		,'EA_init_callback' => ""	// EditArea initiliazed (function name)
88
    		,'EA_delete_callback' => ""	// EditArea deleted (function name)
89
    		,'EA_load_callback' => ""	// EditArea fully loaded and displayed (function name)
90
    		,'EA_unload_callback' => ""	// EditArea delete while being displayed (function name)
91
    		,'EA_toggle_on_callback' => ""	         // EditArea toggled on (function name)
92
    		,'EA_toggle_off_callback' => ""	        // EditArea toggled off (function name)
93
    		,'EA_file_switch_on_callback' => ""	    // a new tab is selected (called for the newly selected file)
94
    		,'EA_file_switch_off_callback' => ""	// a new tab is selected (called for the previously selected file)
95
    		,'EA_file_close_callback' => ""		    // close a tab
96
    	);
97
    }
98
}
99
if (!function_exists('registerEditArea')) {
100
    
101
function registerEditArea( $initId = null 
102
            ,$syntax = "php"
103
            ,$syntax_selection = true
104
            ,$allow_resize = "both"
105
            ,$allow_toggle = true
106
            ,$start_highlight = true
107
            ,$min_width = 600
108
            ,$min_height = 450
109
            ,$toolbar = "default" 
110
            ) 
111
{                
112

    
113
$isArray = true;
114
if( is_array($initId) ){
115
//    $json = json_encode($sInitId, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG);
116
    $aInitEditArea = getEditareaDefaultSettings();
117
    $aInitEditArea = array_merge($aInitEditArea,$initId);      
118
} else {
119
    $id = $initId;
120
    $aInitEditArea = getEditareaDefaultSettings();    
121
    $aInitEditArea['id'] = $initId;
122
    $aInitEditArea['syntax'] = $syntax;
123
    $aInitEditArea['syntax_selection_allow'] = $syntax_selection;
124
    $aInitEditArea['allow_resize'] = $allow_resize;
125
    $aInitEditArea['allow_toggle'] = $allow_toggle;
126
    $aInitEditArea['start_highlight'] = $start_highlight;
127
    $aInitEditArea['min_width'] = $min_width;
128
    $aInitEditArea['min_height'] = $min_height;
129
    $aInitEditArea['toolbar'] = $toolbar;
130
}
131
		// set default toolbar if no user defined was specified
132
		if ($aInitEditArea['toolbar'] == 'default') {
133
			$aInitEditArea['toolbar'] = 'search, fullscreen, |, undo, redo, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help';
134
//			$aInitEditArea['toolbar'] = (!$aInitEditArea['syntax_selection_allow']) ? str_replace('syntax_selection,', '', $aInitEditArea['toolbar']) : $aInitEditArea['toolbar'];
135
		}
136

    
137
		// check if used Website Baker backend language is supported by EditArea
138
		$language = 'en';
139

    
140
		if (defined('LANGUAGE') && is_readable(dirname(__FILE__).'/langs/'.strtolower(LANGUAGE).'.js'))
141
        {
142
			$aInitEditArea['language'] = strtolower(LANGUAGE);
143
		}
144

    
145
		// check if highlight syntax is supported by edit_area
146
		$aInitEditArea['syntax'] = in_array($aInitEditArea['syntax'], array('css', 'html', 'js', 'php', 'xml')) ? $aInitEditArea['syntax'] : 'basic';
147

    
148
		// check if resize option is supported by edit_area
149
		$aInitEditArea['allow_resize'] = in_array($aInitEditArea['allow_resize'], array('no', 'both', 'x', 'y')) ? $aInitEditArea['allow_resize'] : 'no';
150

    
151
		if(!defined('LOADER_HELP')) {
152
			loader_help();
153
	        define('LOADER_HELP', true);
154
		}
155
        if(version_compare(PHP_VERSION, '5.3', '<'))
156
        {
157
            $json = json_encode($aInitEditArea);
158
        } else {
159
            $json = json_encode($aInitEditArea, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG);
160
        }
161
		// return the Javascript code
162
		$result = <<< EOT
163
		<script type="text/javascript">
164
			editAreaLoader.init( $json );
165
		</script>
166
EOT;
167
		return $result;
168
	}
169
}
170

    
171
if (!function_exists('getEditAreaSyntax')) {
172
	function getEditAreaSyntax($file) 
173
	{
174
		// returns the highlight scheme for edit_area
175
		$syntax = 'php';
176
		if (is_readable($file)) {
177
			// extract file extension
178
			$file_info = pathinfo($file);
179
		
180
			switch ($file_info['extension']) {
181
				case 'htm': case 'html': case 'htt':
182
					$syntax = 'html';
183
	  				break;
184

    
185
	 			case 'css':
186
					$syntax = 'css';
187
	  				break;
188

    
189
				case 'js':
190
					$syntax = 'js';
191
					break;
192

    
193
				case 'xml':
194
					$syntax = 'xml';
195
					break;
196

    
197
	 			case 'php': case 'php3': case 'php4': case 'php5':
198
					$syntax = 'php';
199
	  				break;
200

    
201
				default:
202
					$syntax = 'php';
203
					break;
204
			}
205
		}
206
		return $syntax ;
207
	}
208
}
(5-5/5)