Esempio n. 1
0
 /**
  * @static
  *
  * @global string $wp_version
  * @global string $tinymce_version
  *
  * @param string $editor_id
  * @param array  $set
  */
 public static function editor_settings($editor_id, $set)
 {
     global $wp_version, $tinymce_version;
     if (empty(self::$first_init)) {
         if (is_admin()) {
             add_action('admin_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('admin_print_footer_scripts', array(__CLASS__, 'enqueue_scripts'), 1);
         } else {
             add_action('wp_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('wp_print_footer_scripts', array(__CLASS__, 'enqueue_scripts'), 1);
         }
     }
     if (self::$this_quicktags) {
         $qtInit = array('id' => $editor_id, 'buttons' => '');
         if (is_array($set['quicktags'])) {
             $qtInit = array_merge($qtInit, $set['quicktags']);
         }
         if (empty($qtInit['buttons'])) {
             $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
         }
         if ($set['_content_editor_dfw']) {
             $qtInit['buttons'] .= ',dfw';
         }
         /**
          * Filters the Quicktags settings.
          *
          * @since 3.3.0
          *
          * @param array  $qtInit    Quicktags settings.
          * @param string $editor_id The unique editor ID, e.g. 'content'.
          */
         $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id);
         self::$qt_settings[$editor_id] = $qtInit;
         self::$qt_buttons = array_merge(self::$qt_buttons, explode(',', $qtInit['buttons']));
     }
     if (self::$this_tinymce) {
         if (empty(self::$first_init)) {
             self::$baseurl = includes_url('js/tinymce');
             $mce_locale = get_locale();
             self::$mce_locale = $mce_locale = empty($mce_locale) ? 'en' : strtolower(substr($mce_locale, 0, 2));
             // ISO 639-1
             /** This filter is documented in wp-admin/includes/media.php */
             $no_captions = (bool) apply_filters('disable_captions', '');
             $ext_plugins = '';
             if ($set['teeny']) {
                 /**
                  * Filters the list of teenyMCE plugins.
                  *
                  * @since 2.7.0
                  *
                  * @param array  $plugins   An array of teenyMCE plugins.
                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
                  */
                 self::$plugins = $plugins = apply_filters('teeny_mce_plugins', array('colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink'), $editor_id);
             } else {
                 /**
                  * Filters the list of TinyMCE external plugins.
                  *
                  * The filter takes an associative array of external plugins for
                  * TinyMCE in the form 'plugin_name' => 'url'.
                  *
                  * The url should be absolute, and should include the js filename
                  * to be loaded. For example:
                  * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
                  *
                  * If the external plugin adds a button, it should be added with
                  * one of the 'mce_buttons' filters.
                  *
                  * @since 2.5.0
                  *
                  * @param array $external_plugins An array of external TinyMCE plugins.
                  */
                 $mce_external_plugins = apply_filters('mce_external_plugins', array());
                 $plugins = array('charmap', 'colorpicker', 'hr', 'lists', 'media', 'paste', 'tabfocus', 'textcolor', 'fullscreen', 'wordpress', 'wpautoresize', 'wpeditimage', 'wpemoji', 'wpgallery', 'wplink', 'wpdialogs', 'wptextpattern', 'wpview', 'wpembed');
                 if (!self::$has_medialib) {
                     $plugins[] = 'image';
                 }
                 /**
                  * Filters the list of default TinyMCE plugins.
                  *
                  * The filter specifies which of the default plugins included
                  * in WordPress should be added to the TinyMCE instance.
                  *
                  * @since 3.3.0
                  *
                  * @param array $plugins An array of default TinyMCE plugins.
                  */
                 $plugins = array_unique(apply_filters('tiny_mce_plugins', $plugins));
                 if (($key = array_search('spellchecker', $plugins)) !== false) {
                     // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
                     // It can be added with 'mce_external_plugins'.
                     unset($plugins[$key]);
                 }
                 if (!empty($mce_external_plugins)) {
                     /**
                      * Filters the translations loaded for external TinyMCE 3.x plugins.
                      *
                      * The filter takes an associative array ('plugin_name' => 'path')
                      * where 'path' is the include path to the file.
                      *
                      * The language file should follow the same format as wp_mce_translation(),
                      * and should define a variable ($strings) that holds all translated strings.
                      *
                      * @since 2.5.0
                      *
                      * @param array $translations Translations for external TinyMCE plugins.
                      */
                     $mce_external_languages = apply_filters('mce_external_languages', array());
                     $loaded_langs = array();
                     $strings = '';
                     if (!empty($mce_external_languages)) {
                         foreach ($mce_external_languages as $name => $path) {
                             if (@is_file($path) && @is_readable($path)) {
                                 include_once $path;
                                 $ext_plugins .= $strings . "\n";
                                 $loaded_langs[] = $name;
                             }
                         }
                     }
                     foreach ($mce_external_plugins as $name => $url) {
                         if (in_array($name, $plugins, true)) {
                             unset($mce_external_plugins[$name]);
                             continue;
                         }
                         $url = set_url_scheme($url);
                         $mce_external_plugins[$name] = $url;
                         $plugurl = dirname($url);
                         $strings = '';
                         // Try to load langs/[locale].js and langs/[locale]_dlg.js
                         if (!in_array($name, $loaded_langs, true)) {
                             $path = str_replace(content_url(), '', $plugurl);
                             $path = WP_CONTENT_DIR . $path . '/langs/';
                             if (function_exists('realpath')) {
                                 $path = trailingslashit(realpath($path));
                             }
                             if (@is_file($path . $mce_locale . '.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
                             }
                             if (@is_file($path . $mce_locale . '_dlg.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
                             }
                             if ('en' != $mce_locale && empty($strings)) {
                                 if (@is_file($path . 'en.js')) {
                                     $str1 = @file_get_contents($path . 'en.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str1, 1) . "\n";
                                 }
                                 if (@is_file($path . 'en_dlg.js')) {
                                     $str2 = @file_get_contents($path . 'en_dlg.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str2, 1) . "\n";
                                 }
                             }
                             if (!empty($strings)) {
                                 $ext_plugins .= "\n" . $strings . "\n";
                             }
                         }
                         $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
                         $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
                     }
                 }
             }
             self::$plugins = $plugins;
             self::$ext_plugins = $ext_plugins;
             self::$first_init = array('theme' => 'modern', 'skin' => 'lightgray', 'language' => self::$mce_locale, 'formats' => '{' . 'alignleft: [' . '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' . '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' . '],' . 'aligncenter: [' . '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' . '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' . '],' . 'alignright: [' . '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' . '{selector: "img,table,dl.wp-caption", classes: "alignright"}' . '],' . 'strikethrough: {inline: "del"}' . '}', 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => false, 'browser_spellcheck' => true, 'fix_list_elements' => true, 'entities' => '38,amp,60,lt,62,gt', 'entity_encoding' => 'raw', 'keep_styles' => false, 'cache_suffix' => 'wp-mce-' . $tinymce_version, 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform', 'end_container_on_empty_block' => true, 'wpeditimage_disable_captions' => $no_captions, 'wpeditimage_html5_captions' => current_theme_supports('html5', 'caption'), 'plugins' => implode(',', $plugins), 'wp_lang_attr' => get_bloginfo('language'));
             if (!empty($mce_external_plugins)) {
                 self::$first_init['external_plugins'] = wp_json_encode($mce_external_plugins);
             }
             $suffix = SCRIPT_DEBUG ? '' : '.min';
             $version = 'ver=' . $wp_version;
             $dashicons = includes_url("css/dashicons{$suffix}.css?{$version}");
             // WordPress default stylesheet and dashicons
             $mce_css = array($dashicons, self::$baseurl . '/skins/wordpress/wp-content.css?' . $version);
             $editor_styles = get_editor_stylesheets();
             if (!empty($editor_styles)) {
                 foreach ($editor_styles as $style) {
                     $mce_css[] = $style;
                 }
             }
             /**
              * Filters the comma-delimited list of stylesheets to load in TinyMCE.
              *
              * @since 2.1.0
              *
              * @param string $stylesheets Comma-delimited list of stylesheets.
              */
             $mce_css = trim(apply_filters('mce_css', implode(',', $mce_css)), ' ,');
             if (!empty($mce_css)) {
                 self::$first_init['content_css'] = $mce_css;
             }
         }
         if ($set['teeny']) {
             /**
              * Filters the list of teenyMCE buttons (Text tab).
              *
              * @since 2.7.0
              *
              * @param array  $buttons   An array of teenyMCE buttons.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mce_buttons = apply_filters('teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id);
             $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
         } else {
             $mce_buttons = array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker');
             if (!wp_is_mobile()) {
                 if ($set['_content_editor_dfw']) {
                     $mce_buttons[] = 'dfw';
                 } else {
                     $mce_buttons[] = 'fullscreen';
                 }
             }
             $mce_buttons[] = 'wp_adv';
             /**
              * Filters the first-row list of TinyMCE buttons (Visual tab).
              *
              * @since 2.0.0
              *
              * @param array  $buttons   First-row list of buttons.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mce_buttons = apply_filters('mce_buttons', $mce_buttons, $editor_id);
             $mce_buttons_2 = array('formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo');
             if (!wp_is_mobile()) {
                 $mce_buttons_2[] = 'wp_help';
             }
             /**
              * Filters the second-row list of TinyMCE buttons (Visual tab).
              *
              * @since 2.0.0
              *
              * @param array  $buttons   Second-row list of buttons.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2, $editor_id);
             /**
              * Filters the third-row list of TinyMCE buttons (Visual tab).
              *
              * @since 2.0.0
              *
              * @param array  $buttons   Third-row list of buttons.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
             /**
              * Filters the fourth-row list of TinyMCE buttons (Visual tab).
              *
              * @since 2.5.0
              *
              * @param array  $buttons   Fourth-row list of buttons.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
         }
         $body_class = $editor_id;
         if ($post = get_post()) {
             $body_class .= ' post-type-' . sanitize_html_class($post->post_type) . ' post-status-' . sanitize_html_class($post->post_status);
             if (post_type_supports($post->post_type, 'post-formats')) {
                 $post_format = get_post_format($post);
                 if ($post_format && !is_wp_error($post_format)) {
                     $body_class .= ' post-format-' . sanitize_html_class($post_format);
                 } else {
                     $body_class .= ' post-format-standard';
                 }
             }
         }
         $body_class .= ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_locale())));
         if (!empty($set['tinymce']['body_class'])) {
             $body_class .= ' ' . $set['tinymce']['body_class'];
             unset($set['tinymce']['body_class']);
         }
         $mceInit = array('selector' => "#{$editor_id}", 'resize' => 'vertical', 'menubar' => false, 'wpautop' => (bool) $set['wpautop'], 'indent' => !$set['wpautop'], 'toolbar1' => implode($mce_buttons, ','), 'toolbar2' => implode($mce_buttons_2, ','), 'toolbar3' => implode($mce_buttons_3, ','), 'toolbar4' => implode($mce_buttons_4, ','), 'tabfocus_elements' => $set['tabfocus_elements'], 'body_class' => $body_class);
         // Merge with the first part of the init array
         $mceInit = array_merge(self::$first_init, $mceInit);
         if (is_array($set['tinymce'])) {
             $mceInit = array_merge($mceInit, $set['tinymce']);
         }
         /*
          * For people who really REALLY know what they're doing with TinyMCE
          * You can modify $mceInit to add, remove, change elements of the config
          * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
          * and "extended_valid_elements" can be done through this filter. Best
          * is to use the default cleanup by not specifying valid_elements,
          * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
          */
         if ($set['teeny']) {
             /**
              * Filters the teenyMCE config before init.
              *
              * @since 2.7.0
              *
              * @param array  $mceInit   An array with teenyMCE config.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
         } else {
             /**
              * Filters the TinyMCE config before init.
              *
              * @since 2.5.0
              *
              * @param array  $mceInit   An array with TinyMCE config.
              * @param string $editor_id Unique editor identifier, e.g. 'content'.
              */
             $mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
         }
         if (empty($mceInit['toolbar3']) && !empty($mceInit['toolbar4'])) {
             $mceInit['toolbar3'] = $mceInit['toolbar4'];
             $mceInit['toolbar4'] = '';
         }
         self::$mce_settings[$editor_id] = $mceInit;
     }
     // end if self::$this_tinymce
 }
Esempio n. 2
0
 public static function editor_settings($editor_id, $set)
 {
     $first_run = false;
     if (empty(self::$first_init)) {
         if (is_admin()) {
             add_action('admin_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('admin_footer', array(__CLASS__, 'enqueue_scripts'), 1);
         } else {
             add_action('wp_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('wp_footer', array(__CLASS__, 'enqueue_scripts'), 1);
         }
     }
     if (self::$this_quicktags) {
         $qtInit = array('id' => $editor_id, 'buttons' => '');
         if (is_array($set['quicktags'])) {
             $qtInit = array_merge($qtInit, $set['quicktags']);
         }
         if (empty($qtInit['buttons'])) {
             $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
         }
         if ($set['dfw']) {
             $qtInit['buttons'] .= ',fullscreen';
         }
         $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id);
         self::$qt_settings[$editor_id] = $qtInit;
         self::$qt_buttons = array_merge(self::$qt_buttons, explode(',', $qtInit['buttons']));
     }
     if (self::$this_tinymce) {
         if (empty(self::$first_init)) {
             self::$baseurl = includes_url('js/tinymce');
             self::$mce_locale = $mce_locale = '' == get_locale() ? 'en' : strtolower(substr(get_locale(), 0, 2));
             // only ISO 639-1
             $no_captions = (bool) apply_filters('disable_captions', '');
             $plugins = array('inlinepopups', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs');
             $first_run = true;
             $ext_plugins = '';
             if ($set['teeny']) {
                 self::$plugins = $plugins = apply_filters('teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id);
             } else {
                 /*
                 The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
                 It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
                 The url should be absolute and should include the js file name to be loaded. Example:
                 array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
                 If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
                 */
                 $mce_external_plugins = apply_filters('mce_external_plugins', array());
                 if (!empty($mce_external_plugins)) {
                     /*
                     The following filter loads external language files for TinyMCE plugins.
                     It takes an associative array 'plugin_name' => 'path', where path is the
                     include path to the file. The language file should follow the same format as
                     /tinymce/langs/wp-langs.php and should define a variable $strings that
                     holds all translated strings.
                     When this filter is not used, the function will try to load {mce_locale}.js.
                     If that is not found, en.js will be tried next.
                     */
                     $mce_external_languages = apply_filters('mce_external_languages', array());
                     $loaded_langs = array();
                     $strings = '';
                     if (!empty($mce_external_languages)) {
                         foreach ($mce_external_languages as $name => $path) {
                             if (@is_file($path) && @is_readable($path)) {
                                 include_once $path;
                                 $ext_plugins .= $strings . "\n";
                                 $loaded_langs[] = $name;
                             }
                         }
                     }
                     foreach ($mce_external_plugins as $name => $url) {
                         $url = set_url_scheme($url);
                         $plugins[] = '-' . $name;
                         $plugurl = dirname($url);
                         $strings = $str1 = $str2 = '';
                         if (!in_array($name, $loaded_langs)) {
                             $path = str_replace(content_url(), '', $plugurl);
                             $path = WP_CONTENT_DIR . $path . '/langs/';
                             if (function_exists('realpath')) {
                                 $path = trailingslashit(realpath($path));
                             }
                             if (@is_file($path . $mce_locale . '.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
                             }
                             if (@is_file($path . $mce_locale . '_dlg.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
                             }
                             if ('en' != $mce_locale && empty($strings)) {
                                 if (@is_file($path . 'en.js')) {
                                     $str1 = @file_get_contents($path . 'en.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str1, 1) . "\n";
                                 }
                                 if (@is_file($path . 'en_dlg.js')) {
                                     $str2 = @file_get_contents($path . 'en_dlg.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str2, 1) . "\n";
                                 }
                             }
                             if (!empty($strings)) {
                                 $ext_plugins .= "\n" . $strings . "\n";
                             }
                         }
                         $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
                         $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
                     }
                 }
                 $plugins = array_unique(apply_filters('tiny_mce_plugins', $plugins));
             }
             if ($set['dfw']) {
                 $plugins[] = 'wpfullscreen';
             }
             self::$plugins = $plugins;
             self::$ext_plugins = $ext_plugins;
             if (in_array('spellchecker', $plugins)) {
                 /*
                 translators: These languages show up in the spellchecker drop-down menu, in the order specified, and with the first
                 language listed being the default language. They must be comma-separated and take the format of name=code, where name
                 is the language name (which you may internationalize), and code is a valid ISO 639 language code. Please test the
                 spellchecker with your values.
                 */
                 $mce_spellchecker_languages = __('English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
                 /*
                 The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
                 By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
                 The + sign marks the default language. More: http://www.tinymce.com/wiki.php/Plugin:spellchecker.
                 */
                 $mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+' . $mce_spellchecker_languages);
             }
             self::$first_init = array('mode' => 'exact', 'width' => '100%', 'theme' => 'advanced', 'skin' => 'wp_theme', 'language' => self::$mce_locale, 'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_align' => 'left', 'theme_advanced_statusbar_location' => 'bottom', 'theme_advanced_resizing' => true, 'theme_advanced_resize_horizontal' => false, 'dialog_type' => 'modal', 'formats' => "{\r\n\t\t\t\t\t\talignleft : [\r\n\t\t\t\t\t\t\t{selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},\r\n\t\t\t\t\t\t\t{selector : 'img,table', classes : 'alignleft'}\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t\taligncenter : [\r\n\t\t\t\t\t\t\t{selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},\r\n\t\t\t\t\t\t\t{selector : 'img,table', classes : 'aligncenter'}\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t\talignright : [\r\n\t\t\t\t\t\t\t{selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},\r\n\t\t\t\t\t\t\t{selector : 'img,table', classes : 'alignright'}\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t\tstrikethrough : {inline : 'del'}\r\n\t\t\t\t\t}", 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => false, 'remove_linebreaks' => true, 'gecko_spellcheck' => true, 'fix_list_elements' => true, 'keep_styles' => false, 'entities' => '38,amp,60,lt,62,gt', 'accessibility_focus' => true, 'media_strict' => false, 'paste_remove_styles' => true, 'paste_remove_spans' => true, 'paste_strip_class_attributes' => 'all', 'paste_text_use_dialog' => true, 'webkit_fake_resize' => false, 'preview_styles' => 'font-family font-weight text-decoration text-transform', 'schema' => 'html5', 'wpeditimage_disable_captions' => $no_captions, 'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css', 'plugins' => implode(',', $plugins));
             if (in_array('spellchecker', $plugins)) {
                 self::$first_init['spellchecker_rpc_url'] = self::$baseurl . '/plugins/spellchecker/rpc.php';
                 self::$first_init['spellchecker_languages'] = $mce_spellchecker_languages;
             }
             // load editor_style.css if the current theme supports it
             if (!empty($GLOBALS['editor_styles']) && is_array($GLOBALS['editor_styles'])) {
                 $editor_styles = $GLOBALS['editor_styles'];
                 $mce_css = array();
                 $editor_styles = array_unique(array_filter($editor_styles));
                 $style_uri = get_stylesheet_directory_uri();
                 $style_dir = get_stylesheet_directory();
                 // Support externally referenced styles (like, say, fonts).
                 foreach ($editor_styles as $key => $file) {
                     if (preg_match('~^(https?:)?//~', $file)) {
                         $mce_css[] = esc_url_raw($file);
                         unset($editor_styles[$key]);
                     }
                 }
                 // Look in a parent theme first, that way child theme CSS overrides.
                 if (is_child_theme()) {
                     $template_uri = get_template_directory_uri();
                     $template_dir = get_template_directory();
                     foreach ($editor_styles as $key => $file) {
                         if ($file && file_exists("{$template_dir}/{$file}")) {
                             $mce_css[] = "{$template_uri}/{$file}";
                         }
                     }
                 }
                 foreach ($editor_styles as $file) {
                     if ($file && file_exists("{$style_dir}/{$file}")) {
                         $mce_css[] = "{$style_uri}/{$file}";
                     }
                 }
                 $mce_css = implode(',', $mce_css);
             } else {
                 $mce_css = '';
             }
             $mce_css = trim(apply_filters('mce_css', $mce_css), ' ,');
             if (!empty($mce_css)) {
                 self::$first_init['content_css'] = $mce_css;
             }
         }
         if ($set['teeny']) {
             $mce_buttons = apply_filters('teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id);
             $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
         } else {
             $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv'), $editor_id);
             $mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', 'pastetext', 'pasteword', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help'), $editor_id);
             $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
             $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
         }
         $body_class = $editor_id;
         if ($post = get_post()) {
             $body_class .= ' post-type-' . sanitize_html_class($post->post_type) . ' post-status-' . sanitize_html_class($post->post_status);
             if (post_type_supports($post->post_type, 'post-formats')) {
                 $post_format = get_post_format($post);
                 if ($post_format && !is_wp_error($post_format)) {
                     $body_class .= ' post-format-' . sanitize_html_class($post_format);
                 } else {
                     $body_class .= ' post-format-standard';
                 }
             }
         }
         if (!empty($set['tinymce']['body_class'])) {
             $body_class .= ' ' . $set['tinymce']['body_class'];
             unset($set['tinymce']['body_class']);
         }
         if ($set['dfw']) {
             // replace the first 'fullscreen' with 'wp_fullscreen'
             if (($key = array_search('fullscreen', $mce_buttons)) !== false) {
                 $mce_buttons[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_2)) !== false) {
                 $mce_buttons_2[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_3)) !== false) {
                 $mce_buttons_3[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_4)) !== false) {
                 $mce_buttons_4[$key] = 'wp_fullscreen';
             }
         }
         $mceInit = array('elements' => $editor_id, 'wpautop' => (bool) $set['wpautop'], 'remove_linebreaks' => (bool) $set['wpautop'], 'apply_source_formatting' => (bool) (!$set['wpautop']), 'theme_advanced_buttons1' => implode($mce_buttons, ','), 'theme_advanced_buttons2' => implode($mce_buttons_2, ','), 'theme_advanced_buttons3' => implode($mce_buttons_3, ','), 'theme_advanced_buttons4' => implode($mce_buttons_4, ','), 'tabfocus_elements' => $set['tabfocus_elements'], 'body_class' => $body_class);
         // The main editor doesn't use the TinyMCE resizing cookie.
         $mceInit['theme_advanced_resizing_use_cookie'] = 'content' !== $editor_id || empty($set['editor_height']);
         if ($first_run) {
             $mceInit = array_merge(self::$first_init, $mceInit);
         }
         if (is_array($set['tinymce'])) {
             $mceInit = array_merge($mceInit, $set['tinymce']);
         }
         // For people who really REALLY know what they're doing with TinyMCE
         // You can modify $mceInit to add, remove, change elements of the config before tinyMCE.init
         // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
         // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
         if ($set['teeny']) {
             $mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
         } else {
             $mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
         }
         if (empty($mceInit['theme_advanced_buttons3']) && !empty($mceInit['theme_advanced_buttons4'])) {
             $mceInit['theme_advanced_buttons3'] = $mceInit['theme_advanced_buttons4'];
             $mceInit['theme_advanced_buttons4'] = '';
         }
         self::$mce_settings[$editor_id] = $mceInit;
     }
     // end if self::$this_tinymce
 }
Esempio n. 3
0
 public static function editor_settings($editor_id, $set)
 {
     global $editor_styles;
     $first_run = false;
     if (empty(self::$first_init)) {
         if (is_admin()) {
             add_action('admin_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('admin_footer', array(__CLASS__, 'enqueue_scripts'), 1);
         } else {
             add_action('wp_print_footer_scripts', array(__CLASS__, 'editor_js'), 50);
             add_action('wp_footer', array(__CLASS__, 'enqueue_scripts'), 1);
         }
     }
     if (self::$this_quicktags) {
         $qtInit = array('id' => $editor_id, 'buttons' => '');
         if (is_array($set['quicktags'])) {
             $qtInit = array_merge($qtInit, $set['quicktags']);
         }
         if (empty($qtInit['buttons'])) {
             $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close';
         }
         if ($set['dfw']) {
             $qtInit['buttons'] .= ',fullscreen';
         }
         $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id);
         self::$qt_settings[$editor_id] = $qtInit;
         self::$qt_buttons = array_merge(self::$qt_buttons, explode(',', $qtInit['buttons']));
     }
     if (self::$this_tinymce) {
         if (empty(self::$first_init)) {
             self::$baseurl = includes_url('js/tinymce');
             self::$mce_locale = $mce_locale = '' == get_locale() ? 'en' : strtolower(substr(get_locale(), 0, 2));
             // only ISO 639-1
             $no_captions = (bool) apply_filters('disable_captions', '');
             //Firefox does not work with TinyMCE correctly if TinyMCE loads plugins so we start off with an empty list of plugins
             $plugins = array();
             // $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wpdialogs' );
             $plugins = array('paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wpdialogs');
             // inlinepopups plugin is required and supported only for TinyMCE Version 3
             if ($set['major_version'] < 4) {
                 array_unshift($plugins, 'spellchecker');
                 array_unshift($plugins, 'inlinepopups');
             } else {
                 array_unshift($plugins, 'textcolor');
                 array_unshift($plugins, 'charmap');
             }
             $first_run = true;
             if ($set['teeny']) {
                 self::$plugins = $plugins = apply_filters('teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wpdialogs'), $editor_id);
                 $ext_plugins = '';
             } else {
                 /*
                 The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
                 It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
                 The url should be absolute and should include the js file name to be loaded. Example:
                 array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
                 If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
                 */
                 if ($set['major_version'] < 4) {
                     $mce_external_plugins = apply_filters('mce_external_plugins', array());
                 } else {
                     $mce_external_plugins = apply_filters('mce_external_plugins', array('link' => OP_LIB_URL . 'js/tinymce/plugins/op_link/plugin.js'));
                 }
                 $ext_plugins = '';
                 if (!empty($mce_external_plugins)) {
                     /*
                     The following filter loads external language files for TinyMCE plugins.
                     It takes an associative array 'plugin_name' => 'path', where path is the
                     include path to the file. The language file should follow the same format as
                     /tinymce/langs/wp-langs.php and should define a variable $strings that
                     holds all translated strings.
                     When this filter is not used, the function will try to load {mce_locale}.js.
                     If that is not found, en.js will be tried next.
                     */
                     //$mce_external_languages = apply_filters('mce_external_languages', array());
                     $loaded_langs = array();
                     $strings = '';
                     // if ( ! empty($mce_external_languages) ) {
                     //  foreach ( $mce_external_languages as $name => $path ) {
                     //      if ( @is_file($path) && @is_readable($path) ) {
                     //          include_once($path);
                     //          $ext_plugins .= $strings . "\n";
                     //          $loaded_langs[] = $name;
                     //      }
                     //  }
                     // }
                     foreach ($mce_external_plugins as $name => $url) {
                         if (is_ssl()) {
                             $url = str_replace('http://', 'https://', $url);
                         }
                         $plugins[] = '-' . $name;
                         $plugurl = dirname($url);
                         $strings = $str1 = $str2 = '';
                         if (!in_array($name, $loaded_langs)) {
                             $path = str_replace(content_url(), '', $plugurl);
                             $path = WP_CONTENT_DIR . $path . '/langs/';
                             if (function_exists('realpath')) {
                                 $path = trailingslashit(realpath($path));
                             }
                             if (@is_file($path . $mce_locale . '.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
                             }
                             if (@is_file($path . $mce_locale . '_dlg.js')) {
                                 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
                             }
                             if ('en' != $mce_locale && empty($strings)) {
                                 if (@is_file($path . 'en.js')) {
                                     $str1 = @file_get_contents($path . 'en.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str1, 1) . "\n";
                                 }
                                 if (@is_file($path . 'en_dlg.js')) {
                                     $str2 = @file_get_contents($path . 'en_dlg.js');
                                     $strings .= preg_replace('/([\'"])en\\./', '$1' . $mce_locale . '.', $str2, 1) . "\n";
                                 }
                             }
                             if (!empty($strings)) {
                                 $ext_plugins .= "\n" . $strings . "\n";
                             }
                         }
                         $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
                         $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
                         self::$ext_plugins .= $ext_plugins;
                     }
                 }
                 $plugins = array_unique(apply_filters('tiny_mce_plugins', $plugins));
             }
             if ($set['dfw']) {
                 $plugins[] = 'wpfullscreen';
             }
             self::$plugins = $plugins;
             /*
             The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
             By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
             The + sign marks the default language. More information:
             http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
             */
             $mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
             self::$first_init = array('mode' => 'none', 'width' => '100%', 'spellchecker_languages' => $mce_spellchecker_languages, 'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_align' => 'left', 'theme_advanced_statusbar_location' => 'bottom', 'theme_advanced_resizing' => true, 'theme_advanced_resize_horizontal' => false, 'dialog_type' => 'modal', 'formats' => "{\n                        alignleft : [\n                            {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},\n                            {selector : 'img,table', classes : 'alignleft'}\n                        ],\n                        aligncenter : [\n                            {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},\n                            {selector : 'img,table', classes : 'aligncenter'}\n                        ],\n                        alignright : [\n                            {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},\n                            {selector : 'img,table', classes : 'alignright'}\n                        ],\n                        strikethrough : {inline : 'del'}\n                    }", 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => false, 'remove_linebreaks' => true, 'gecko_spellcheck' => true, 'keep_styles' => false, 'entities' => '38,amp,60,lt,62,gt', 'accessibility_focus' => true, 'tabfocus_elements' => 'major-publishing-actions', 'media_strict' => false, 'paste_remove_styles' => true, 'paste_remove_spans' => true, 'paste_strip_class_attributes' => 'all', 'paste_text_use_dialog' => true, 'extended_valid_elements' => 'article[*],aside[*],audio[*],canvas[*],command[*],datalist[*],details[*],embed[*],figcaption[*],figure[*],footer[*],header[*],hgroup[*],keygen[*],mark[*],meter[*],nav[*],output[*],progress[*],section[*],source[*],summary,time[*],video[*],wbr', 'wpeditimage_disable_captions' => $no_captions, 'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css', 'plugins' => implode(',', $plugins));
             if ($set['major_version'] < 4) {
                 // Stuff required only for v3
                 self::$first_init['skin'] = 'wp_theme';
                 self::$first_init['theme'] = 'advanced';
             } else {
                 // Stuff required only for v4
                 self::$first_init['menubar'] = false;
                 self::$first_init['theme'] = 'modern';
                 self::$first_init['height'] = '100px';
                 self::$first_init['content_css'] = '/wp-includes/js/tinymce/skins/wordpress/wp-content.css';
             }
             // load editor_style.css if the current theme supports it
             if (!empty($editor_styles) && is_array($editor_styles)) {
                 $mce_css = array();
                 $editor_styles = array_unique($editor_styles);
                 $style_uri = get_stylesheet_directory_uri();
                 if (!is_child_theme()) {
                     foreach ($editor_styles as $file) {
                         $mce_css[] = "{$style_uri}/{$file}";
                     }
                 } else {
                     $style_dir = get_stylesheet_directory();
                     $template_uri = get_template_directory_uri();
                     $template_dir = get_template_directory();
                     foreach ($editor_styles as $file) {
                         if (file_exists("{$template_dir}/{$file}")) {
                             $mce_css[] = "{$template_uri}/{$file}";
                         }
                     }
                     foreach ($editor_styles as $file) {
                         if (file_exists("{$style_dir}/{$file}")) {
                             $mce_css[] = "{$style_uri}/{$file}";
                         }
                     }
                 }
                 $mce_css = implode(',', $mce_css);
             } else {
                 $mce_css = '';
             }
             $mce_css = trim(apply_filters('mce_css', $mce_css), ' ,');
             if (!empty($mce_css)) {
                 self::$first_init['content_css'] = $mce_css;
             }
         }
         if ($set['teeny']) {
             $mce_buttons = apply_filters('teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'separator', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id);
             $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
         } else {
             $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', 'hr', '|', 'justifyleft', 'justifycenter', 'justifyright', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv'), $editor_id);
             $mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help'), $editor_id);
             $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
             $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
         }
         if ($set['dfw']) {
             // replace the first 'fullscreen' with 'wp_fullscreen'
             if (($key = array_search('fullscreen', $mce_buttons)) !== false) {
                 $mce_buttons[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_2)) !== false) {
                 $mce_buttons_2[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_3)) !== false) {
                 $mce_buttons_3[$key] = 'wp_fullscreen';
             } elseif (($key = array_search('fullscreen', $mce_buttons_4)) !== false) {
                 $mce_buttons_4[$key] = 'wp_fullscreen';
             }
         }
         if ($set['major_version'] < 4) {
             $mceInit = array('wpautop' => (bool) $set['wpautop'], 'remove_linebreaks' => (bool) $set['wpautop'], 'apply_source_formatting' => (bool) (!$set['wpautop']), 'theme_advanced_buttons1' => implode($mce_buttons, ','), 'theme_advanced_buttons2' => implode($mce_buttons_2, ','), 'theme_advanced_buttons3' => implode($mce_buttons_3, ','), 'theme_advanced_buttons4' => implode($mce_buttons_4, ','));
         } else {
             $mceInit = array('wpautop' => (bool) $set['wpautop'], 'remove_linebreaks' => (bool) $set['wpautop'], 'apply_source_formatting' => (bool) (!$set['wpautop']), 'toolbar1' => implode($mce_buttons, ','), 'toolbar2' => implode($mce_buttons_2, ','), 'toolbar3' => implode($mce_buttons_3, ','), 'toolbar4' => implode($mce_buttons_4, ','));
         }
         if ($first_run) {
             $mceInit = array_merge(self::$first_init, $mceInit);
         }
         if (is_array($set['tinymce'])) {
             $mceInit = array_merge($mceInit, $set['tinymce']);
         }
         // For people who really REALLY know what they're doing with TinyMCE
         // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
         // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
         // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
         if ($set['teeny']) {
             $mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
         } else {
             $mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
         }
         if (empty($mceInit['theme_advanced_buttons3']) && !empty($mceInit['theme_advanced_buttons4'])) {
             $mceInit['theme_advanced_buttons3'] = $mceInit['theme_advanced_buttons4'];
             $mceInit['theme_advanced_buttons4'] = '';
         }
         self::$mce_settings[$editor_id] = $mceInit;
     }
     // end if self::$this_tinymce
 }