Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         include
6
 * @author          Christophe Dolivet (EditArea), Christian Sommer
7
 * @author          WebsiteBaker Project
8
 * @copyright       Ryan Djurovich
9
 * @copyright       Website Baker Org. e.V.
10
 * @link            http://websitebaker.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.3
13
 * @requirements    PHP 5.3.6 and higher
14
 * @version         $Id: wb_wrapper_edit_area.php 2 2017-07-02 15:14:29Z Manuela $
15
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/include/editarea/wb_wrapper_edit_area.php $
16
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
17
 *
18
 */
19

    
20
if (!function_exists('loader_help')) {
21
function loader_help()
22
{
23

    
24
?>
25
<script type="text/javascript">
26
/*<![CDATA[*/
27
        var url  = '<?php print WB_URL; ?>/include/editarea/edit_area_full.js';
28
        try{
29
            script = document.createElement("script");
30
            script.type = "text/javascript";
31
            script.src  = url;
32
            script.charset= "UTF-8";
33
            head = document.getElementsByTagName("head")[0];
34
            head[0].appendChild(script);
35
        }catch(e){
36
            document.write("<script type='text/javascript' src='" + url + "' charset=\"UTF-8\"><"+"/script>");
37
        }
38
/*]]>*/
39
</script>
40

    
41
<?php }
42
}
43
if (!function_exists('getEditareaDefaultSettings')) {
44
    function getEditareaDefaultSettings() {
45

    
46
    /**
47
     * toolbar: define the toolbar that will be displayed, each element being separated by a ",".
48
     * 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")
49
     * "|" or "separator" make appears a separator in the toolbar.
50
     * "*" or "return" make appears a line-break in the toolbar
51
     * Default: "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"
52
     */
53

    
54
    return array (
55
            'id' => "src"    // should contain the id of the textarea that should be converted into an editor
56
            ,'language' => "en"
57
            ,'syntax' => ""
58
            ,'start_highlight' => true    // if start with highlight
59
            ,'is_multi_files' => false        // enable the multi file mode (the textarea content is ignored)
60
            ,'min_width' => 400
61
            ,'min_height' => 125
62
            ,'allow_resize' => "y"    // possible values: "no", "both", "x", "y"
63
            ,'allow_toggle' => true        // true or false
64
            ,'plugins' => "" // comma separated plugin list
65
            ,'browsers' => "all"    // all or known
66
            ,'display' => "onload"         // onload or later
67
            ,'toolbar' => "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, change_smooth_selection, highlight, reset_highlight, word_wrap, |, help"
68
            ,'begin_toolbar' => ""        //  "new_document, save, load, |"
69
            ,'end_toolbar' => ""        // or end_toolbar
70
            ,'font_size' => "10"        // not for IE
71
            ,'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...
72
            ,'cursor_position' => "begin"
73
            ,'gecko_spellcheck' => false    // enable/disable by default the gecko_spellcheck
74
            ,'max_undo' => 30
75
            ,'fullscreen' => false
76
            ,'is_editable' => true
77
            ,'word_wrap' => false        // define if the text is wrapped of not in the textarea
78
            ,'replace_tab_by_spaces' => false
79
            ,'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
80
            ,'show_line_colors' => false    // if the highlight is disabled for the line currently beeing edited (if enabled => heavy CPU use)
81
            ,'syntax_selection_allow' => "basic,brainfuck,c,coldfusion,cpp,css,html,java,js,pas,perl,php,python,ruby,robotstxt,sql,tsql,vb,xml"
82
            ,'smooth_selection' => true
83
            ,'autocompletion' => false    // NOT IMPLEMENTED
84
            ,'load_callback' => ""        // click on load button (function name)
85
            ,'save_callback' => ""        // click on save button (function name)
86
            ,'change_callback' => ""    // textarea onchange trigger (function name)
87
            ,'submit_callback' => ""    // form submited (function name)
88
            ,'EA_init_callback' => ""    // EditArea initiliazed (function name)
89
            ,'EA_delete_callback' => ""    // EditArea deleted (function name)
90
            ,'EA_load_callback' => ""    // EditArea fully loaded and displayed (function name)
91
            ,'EA_unload_callback' => ""    // EditArea delete while being displayed (function name)
92
            ,'EA_toggle_on_callback' => ""             // EditArea toggled on (function name)
93
            ,'EA_toggle_off_callback' => ""            // EditArea toggled off (function name)
94
            ,'EA_file_switch_on_callback' => ""        // a new tab is selected (called for the newly selected file)
95
            ,'EA_file_switch_off_callback' => ""    // a new tab is selected (called for the previously selected file)
96
            ,'EA_file_close_callback' => ""            // close a tab
97
        );
98
    }
99
}
100
if (!function_exists('registerEditArea')) {
101

    
102
function registerEditArea(
103
     $initId = null
104
    ,$syntax = "php"
105
    ,$syntax_selection = true
106
    ,$allow_resize = "both"
107
    ,$allow_toggle = true
108
    ,$start_highlight = true
109
    ,$min_width = 600
110
    ,$min_height = 450
111
    ,$toolbar = "default"
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
        // check if used Website Baker backend language is supported by EditArea
137
        $language = 'en';
138
        if (defined('LANGUAGE') && is_readable(dirname(__FILE__).'/langs/'.strtolower(LANGUAGE).'.js'))
139
        {
140
            $aInitEditArea['language'] = strtolower(LANGUAGE);
141
        }
142
        // check if highlight syntax is supported by edit_area
143
        $aInitEditArea['syntax'] = in_array($aInitEditArea['syntax'], array('css', 'html', 'js', 'php', 'xml')) ? $aInitEditArea['syntax'] : 'basic';
144
        // check if resize option is supported by edit_area
145
        $aInitEditArea['allow_resize'] = in_array($aInitEditArea['allow_resize'], array('no', 'both', 'x', 'y')) ? $aInitEditArea['allow_resize'] : 'no';
146
        if(!defined('LOADER_HELP')) {
147
            loader_help();
148
            define('LOADER_HELP', true);
149
        }
150
        if(version_compare(PHP_VERSION, '5.4', '<'))
151
        {
152
            $json = json_encode($aInitEditArea);
153
        } else {
154
            $json = json_encode($aInitEditArea, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG);
155
        }
156
        // return the Javascript code
157
        $result = <<< EOT
158
        <script type="text/javascript">
159
            editAreaLoader.init( $json );
160
        </script>
161
EOT;
162
        return $result;
163
    }
164
}
165

    
166
if (!function_exists('getEditAreaSyntax')) {
167
    function getEditAreaSyntax($file)
168
    {
169
        // returns the highlight scheme for edit_area
170
        $syntax = 'php';
171
        if (is_readable($file)) {
172
            // extract file extension
173
            $file_info = pathinfo($file);
174

    
175
            switch ($file_info['extension']) {
176
                case 'htm': case 'html': case 'htt':
177
                    $syntax = 'html';
178
                      break;
179

    
180
                 case 'css':
181
                    $syntax = 'css';
182
                      break;
183

    
184
                case 'js':
185
                    $syntax = 'js';
186
                    break;
187

    
188
                case 'xml':
189
                    $syntax = 'xml';
190
                    break;
191

    
192
                 case 'php': case 'php3': case 'php4': case 'php5':
193
                    $syntax = 'php';
194
                      break;
195

    
196
                default:
197
                    $syntax = 'php';
198
                    break;
199
            }
200
        }
201
        return $syntax ;
202
    }
203
}
(5-5/5)