Beispiel #1
0
function load_tinyMCE_js($type, $http_base, $base, $root, $element, $suffix)
{
    global $cfg;
    global $do_not_load;
    if ($do_not_load) {
        return '';
    }
    // return zip, nada, nothing
    /*
     * Make sure the tinyMCE language is set up correctly!
     *
     * If we don't do this here, then $cfg['tinymce_language'] will not exist and we will croak further down below.
     */
    SetUpLanguageAndLocale($cfg['language'], true);
    $mce_basepath = merge_path_elems($base, get_remainder_upto_slash($element) . 'tiny_mce/jscripts/tiny_mce/');
    $mce_files = array();
    /*
    To facilitate the lazyloading of tinyMCE in parts when the $suffix is set to '_dev', we do this as
    a two-stage process:
    
    the first stage if for all of 'em and loads the tinyMCE 'core' code at least, lazyloaded or flattened.
    
    When we're in '_dev' mode, the second stage is triggered by the first stage having added a lazyload
    instruction for '2nd-stage.tiny_mce_ccms.js', a fake filename, which will nevertheless trigger the Combiner
    into going here AGAIN and that time around we add the flattened set of language files and plugins.
    
    When we're NOT in '_dev' mode, the second stage won't happen, because the trigger isn't written into
    the produced JS code, so we're good to go either way!
    */
    $stage2 = strmatch_tail($element, "2nd-stage.tiny_mce_ccms.js");
    if (!$stage2) {
        // Add core
        $mce_files[] = merge_path_elems($mce_basepath, "tiny_mce" . $suffix . ".js");
    } else {
        if ($suffix != '_full') {
            /*
            _full is a prebuilt version with everything included by the ant build.
            
            In all other cases, we need to load the language files and plugins ourselves in some way.
            */
            $plugin_suffix = '_src';
            // Add core language(s)
            $languages = array($cfg['tinymce_language']);
            if ($cfg['tinymce_language'] != 'en') {
                $languages[] = 'en';
            }
            foreach ($languages as $lang) {
                $mce_files[] = merge_path_elems($mce_basepath, "langs/" . $lang . ".js");
            }
            // Add themes
            $themes = array('advanced');
            foreach ($themes as $theme) {
                $mce_files[] = merge_path_elems($mce_basepath, "themes", $theme, "editor_template" . $plugin_suffix . ".js");
                foreach ($languages as $lang) {
                    $mce_files[] = merge_path_elems($mce_basepath, "themes", $theme, "langs", $lang . ".js");
                    $mce_files[] = merge_path_elems($mce_basepath, "themes", $theme, "langs", $lang . "_dlg.js");
                }
            }
            // Add plugins
            $pluginarr = get_tinyMCE_plugin_list();
            foreach ($pluginarr as $plugin => $info) {
                if (!is_real_tinyMCE_plugin($plugin)) {
                    continue;
                }
                $mce_files[] = merge_path_elems($mce_basepath, "plugins", $plugin, "editor_plugin" . $plugin_suffix . ".js");
                foreach ($languages as $lang) {
                    $mce_files[] = merge_path_elems($mce_basepath, "plugins", $plugin, "langs", $lang . ".js");
                    $mce_files[] = merge_path_elems($mce_basepath, "plugins", $plugin, "langs", $lang . "_dlg.js");
                }
            }
        }
    }
    // now load all content:
    $my_content = '';
    foreach ($mce_files as $jsf) {
        $path = realpath($jsf);
        if (is_file($path)) {
            $c = @file_get_contents($path) . "\n";
            if ($c !== false) {
                $my_content .= <<<EOT42


/*
#------------------------------------------------------------------------------------
# processed: ({$path} :: {$jsf})
#------------------------------------------------------------------------------------
*/


EOT42;
                $my_content .= $c;
            } else {
                send_response_status_header(404);
                // Not Found
                die("\n" . get_response_code_string(404) . " - Combiner: could not load data from file: type='{$type}', element='{$element}'\n");
            }
        } else {
            $my_content .= <<<EOT42


/*
#####################################################################################
# file not found: ({$path} :: {$jsf})
#####################################################################################
*/


EOT42;
        }
    }
    if (!$stage2 && $suffix == '_dev') {
        // Add 2nd stage into the lazyload chain:
        $my_content = preg_replace('/;\\s*load\\(\\);\\s*\\}\\(\\)\\);/', ';

	// hack/tweak to make dev mode lazyloading work with the CCMS Combiner: delayload the language and plugin code as well!
	include(\'../../../../2nd-stage.tiny_mce_ccms.js\');

	load();
}());
			', $my_content);
    }
    return $my_content;
}
Beispiel #2
0
 public function __construct($textarea_ids, $usr_options = null, $js_load_callback = 'jsComplete')
 {
     global $cfg;
     $this->rootdir = $cfg['rootdir'];
     $this->MCE_language = $cfg['tinymce_language'];
     $this->FM_language = $cfg['MT_FileManager_language'];
     $this->js_load_callback = $js_load_callback;
     // split the ID set and create a full MCE options array for each of 'em, keeping track of generic and specific user options
     $editarea_tags = explode(',', $textarea_ids);
     $options = array();
     $generic_user_opts = isset($usr_options[0]) && is_array($usr_options[0]) ? $usr_options[0] : array();
     foreach ($editarea_tags as $tag) {
         $user_opts = isset($usr_options[$tag]) && is_array($usr_options[$tag]) ? $usr_options[$tag] : array();
         $options[$tag] = array_merge(array('theme' => 'advanced'), $generic_user_opts, $user_opts);
         // do this defaulting in two steps: some of the item names are dependent on the actual theme picked for this tinyMCE instance:
         $theme = $options[$tag]['theme'];
         if ($cfg['iframe']) {
             $iframe_def_options = array('extended_valid_elements' => 'iframe[align<bottom?left?middle?right?top|class|frameborder|height|id|longdesc|marginheight|marginwidth|name|scrolling<auto?no?yes|src|style|title|width]');
         } else {
             $iframe_def_options = array();
         }
         $options[$tag] = array_merge(array('skin' => 'o2k7', 'skin_variant' => 'silver', 'mode' => 'exact', 'elements' => $tag, 'language' => $this->MCE_language, 'dialog_type' => 'modal', 'paste_auto_cleanup_on_paste' => true, 'autoresize_on_init' => true, 'autosave_ask_before_unload' => false, 'relative_urls' => false, 'convert_urls' => true, 'remove_script_host' => true, 'document_base_url' => $this->rootdir, 'content_css' => $this->rootdir . 'admin/img/styles/base.css,' . $this->rootdir . 'admin/img/styles/liquid.css,' . $this->rootdir . 'admin/img/styles/layout.css' . ',' . $this->rootdir . 'admin/img/styles/sprite.css,' . $this->rootdir . 'admin/img/styles/last_minute_fixes.css' . ',' . $this->rootdir . 'admin/img/styles/ie.css?only-when=%3d%3d+IE', 'spellchecker_languages' => '+English=en,Dutch=nl,German=de,Spanish=es,French=fr,Italian=it,Russian=ru', "theme_{$theme}_toolbar_location" => 'top', "theme_{$theme}_toolbar_align" => 'left', "theme_{$theme}_statusbar_location" => 'bottom', "theme_{$theme}_resizing" => true, "theme_{$theme}_resizing_use_cookie" => 1, "theme_{$theme}_resize_horizontal" => true, "theme_{$theme}_resizing_min_width" => 362, "theme_{$theme}_resizing_min_height" => 100, "theme_{$theme}_resizing_max_width" => null, "theme_{$theme}_resizing_max_height" => 0xffff), $iframe_def_options, $options[$tag]);
         // make sure, when the FileManager is required, that it's options are set up as well:
         if (isset($options[$tag]['FileManager'])) {
             $session_id = session_id();
             if (!empty($session_id)) {
                 $sid_def_options = array('uploadAuthData' => array('session' => $session_id));
             } else {
                 $sid_def_options = array();
             }
             $fm_user_opts = is_array($options[$tag]['FileManager']) ? $options[$tag]['FileManager'] : array();
             $options[$tag]['FileManager'] = array_merge(array('url' => $this->rootdir . 'lib/includes/js/mootools-filemanager/ccms/manager.php', 'baseURL' => $this->rootdir, 'assetBasePath' => $this->rootdir . 'lib/includes/js/mootools-filemanager/Assets', 'language' => $this->FM_language, 'selectable' => true, 'destroy' => true, 'upload' => true, 'rename' => true, 'download' => true, 'createFolders' => true, 'hideClose' => false, 'hideOverlay' => false, 'uploadAuthData' => array(), 'propagateData' => array('editor_req_type' => null)), $sid_def_options, $fm_user_opts);
         } else {
             unset($options[$tag]['FileManager']);
         }
         $pluginarr = get_tinyMCE_plugin_list(!empty($options[$tag]['plugins']) ? $options[$tag]['plugins'] : null);
         $plugs = array_keys($pluginarr);
         $plugs = array_filter($plugs, 'is_real_tinyMCE_plugin');
         $options[$tag]['plugins'] = implode(',', $plugs);
         dump_request_to_logfile(array('pluginarr' => $pluginarr));
         /*
         now create a list of buttons:
         
         we've moved the construction of the toolbars to the backend as we've found that using many small toolbars helps when the editor is resizing:
         wider (larger) toolbars block the editor from shrinking.
         
         The 'grouping' setting instructs us which tools should sit on the same toolbar.
         */
         $btngrp = array();
         $btnset = array();
         foreach ($pluginarr as $name => $info) {
             $bs = $info['buttons'];
             if (empty($bs)) {
                 continue;
             }
             $grp = $info['grouping'];
             $bsa = explode(',', $bs);
             foreach ($bsa as $btn1) {
                 $bdef = explode(':', $btn1);
                 if (count($bdef) > 1) {
                     // a button which is wider than the usual ones: length is specced as number of 'regular' buttons eqv.:
                     $bdef[1] = intval($bdef[1]);
                 } else {
                     $bdef[1] = $bdef[0] == '|' ? 10 : 22;
                     /* [px] width per button */
                 }
                 if (!isset($btngrp[$grp])) {
                     $btngrp[$grp] = array();
                 }
                 // also check whether button isn't already in the group/toolbar-set: some adv(anced) plugins override existing buttons/functions:
                 $xsist = array_key_exists($bdef[0], $btnset);
                 if (!$xsist) {
                     $btngrp[$grp][] = $bdef;
                     $btnset[$bdef[0]] = true;
                 }
             }
         }
         ksort($btngrp);
         dump_request_to_logfile(array('pluginarr' => $pluginarr, 'btngrp' => $btngrp));
         // bigger toolbar chunks are bad because you are limiting the shrinking capability of the editor window...
         $tbdef = $this->generateToolbarLayout($btngrp, 100);
         dump_request_to_logfile(array('pluginarr' => $pluginarr, 'btngrp' => $btngrp, 'tbdef' => $tbdef));
         for ($i = count($tbdef); $i > 0; $i--) {
             $options[$tag]["theme_{$theme}_buttons" . $i] = $tbdef[$i - 1];
         }
         // and make sure we blow away any inadvertedly user defined toolbars:
         for ($i = count($tbdef) + 1; isset($options[$tag]["theme_{$theme}_buttons" . $i]); $i++) {
             unset($options[$tag]["theme_{$theme}_buttons" . $i]);
         }
     }
     $this->options = $options;
 }