Changeset 18498 for trunk/wp-admin/includes/post.php
- Timestamp:
- 08/03/2011 10:19:00 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/post.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/post.php
r18449 r18498 1406 1406 return $url; 1407 1407 } 1408 1409 /**1410 * Adds the TinyMCE editor used on the Write and Edit screens.1411 *1412 * @package WordPress1413 * @since 2.7.01414 *1415 * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated1416 * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded1417 * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string1418 * to the URL when queueing them with the mce_external_plugins filter.1419 *1420 * @param bool $teeny optional Output a trimmed down version used in Press This.1421 * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.1422 */1423 function wp_tiny_mce( $teeny = false, $settings = false ) {1424 global $concatenate_scripts, $compress_scripts, $tinymce_version, $editor_styles;1425 1426 if ( ! user_can_richedit() )1427 return;1428 1429 $baseurl = includes_url('js/tinymce');1430 1431 $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-11432 1433 /*1434 The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.1435 By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.1436 The + sign marks the default language. More information:1437 http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker1438 */1439 $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');1440 1441 if ( $teeny ) {1442 $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs') );1443 $ext_plugins = '';1444 } else {1445 $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'wordpress', 'wpfullscreen', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );1446 1447 /*1448 The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.1449 It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.1450 The url should be absolute and should include the js file name to be loaded. Example:1451 array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )1452 If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.1453 */1454 $mce_external_plugins = apply_filters('mce_external_plugins', array());1455 1456 $ext_plugins = '';1457 if ( ! empty($mce_external_plugins) ) {1458 1459 /*1460 The following filter loads external language files for TinyMCE plugins.1461 It takes an associative array 'plugin_name' => 'path', where path is the1462 include path to the file. The language file should follow the same format as1463 /tinymce/langs/wp-langs.php and should define a variable $strings that1464 holds all translated strings.1465 When this filter is not used, the function will try to load {mce_locale}.js.1466 If that is not found, en.js will be tried next.1467 */1468 $mce_external_languages = apply_filters('mce_external_languages', array());1469 1470 $loaded_langs = array();1471 $strings = '';1472 1473 if ( ! empty($mce_external_languages) ) {1474 foreach ( $mce_external_languages as $name => $path ) {1475 if ( @is_file($path) && @is_readable($path) ) {1476 include_once($path);1477 $ext_plugins .= $strings . "\n";1478 $loaded_langs[] = $name;1479 }1480 }1481 }1482 1483 foreach ( $mce_external_plugins as $name => $url ) {1484 1485 if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);1486 1487 $plugins[] = '-' . $name;1488 1489 $plugurl = dirname($url);1490 $strings = $str1 = $str2 = '';1491 if ( ! in_array($name, $loaded_langs) ) {1492 $path = str_replace( WP_PLUGIN_URL, '', $plugurl );1493 $path = WP_PLUGIN_DIR . $path . '/langs/';1494 1495 if ( function_exists('realpath') )1496 $path = trailingslashit( realpath($path) );1497 1498 if ( @is_file($path . $mce_locale . '.js') )1499 $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";1500 1501 if ( @is_file($path . $mce_locale . '_dlg.js') )1502 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";1503 1504 if ( 'en' != $mce_locale && empty($strings) ) {1505 if ( @is_file($path . 'en.js') ) {1506 $str1 = @file_get_contents($path . 'en.js');1507 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";1508 }1509 1510 if ( @is_file($path . 'en_dlg.js') ) {1511 $str2 = @file_get_contents($path . 'en_dlg.js');1512 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";1513 }1514 }1515 1516 if ( ! empty($strings) )1517 $ext_plugins .= "\n" . $strings . "\n";1518 }1519 1520 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";1521 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";1522 }1523 }1524 }1525 1526 if ( $teeny ) {1527 $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );1528 $mce_buttons = implode($mce_buttons, ',');1529 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = '';1530 } else {1531 $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));1532 $mce_buttons = implode($mce_buttons, ',');1533 1534 $mce_buttons_2 = array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' );1535 $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2);1536 $mce_buttons_2 = implode($mce_buttons_2, ',');1537 1538 $mce_buttons_3 = apply_filters('mce_buttons_3', array());1539 $mce_buttons_3 = implode($mce_buttons_3, ',');1540 1541 $mce_buttons_4 = apply_filters('mce_buttons_4', array());1542 $mce_buttons_4 = implode($mce_buttons_4, ',');1543 }1544 $no_captions = (bool) apply_filters( 'disable_captions', '' );1545 1546 // TinyMCE init settings1547 $initArray = array (1548 'mode' => 'specific_textareas',1549 'editor_selector' => 'theEditor',1550 'width' => '100%',1551 'theme' => 'advanced',1552 'skin' => 'wp_theme',1553 'theme_advanced_buttons1' => $mce_buttons,1554 'theme_advanced_buttons2' => $mce_buttons_2,1555 'theme_advanced_buttons3' => $mce_buttons_3,1556 'theme_advanced_buttons4' => $mce_buttons_4,1557 'language' => $mce_locale,1558 'spellchecker_languages' => $mce_spellchecker_languages,1559 'theme_advanced_toolbar_location' => 'top',1560 'theme_advanced_toolbar_align' => 'left',1561 'theme_advanced_statusbar_location' => 'bottom',1562 'theme_advanced_resizing' => true,1563 'theme_advanced_resize_horizontal' => false,1564 'dialog_type' => 'modal',1565 'formats' => "{1566 alignleft : [1567 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},1568 {selector : 'img,table', classes : 'alignleft'}1569 ],1570 aligncenter : [1571 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},1572 {selector : 'img,table', classes : 'aligncenter'}1573 ],1574 alignright : [1575 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},1576 {selector : 'img,table', classes : 'alignright'}1577 ],1578 strikethrough : {inline : 'del'}1579 }",1580 'relative_urls' => false,1581 'remove_script_host' => false,1582 'convert_urls' => false,1583 'apply_source_formatting' => false,1584 'remove_linebreaks' => true,1585 'gecko_spellcheck' => true,1586 'keep_styles' => false,1587 'entities' => '38,amp,60,lt,62,gt',1588 'accessibility_focus' => true,1589 'tabfocus_elements' => 'major-publishing-actions',1590 'media_strict' => false,1591 'paste_remove_styles' => true,1592 'paste_remove_spans' => true,1593 'paste_strip_class_attributes' => 'all',1594 'paste_text_use_dialog' => true,1595 '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',1596 'wpeditimage_disable_captions' => $no_captions,1597 'wp_fullscreen_content_css' => "$baseurl/plugins/wpfullscreen/css/wp-fullscreen.css",1598 'plugins' => implode( ',', $plugins ),1599 );1600 1601 if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {1602 $mce_css = array();1603 $style_uri = get_stylesheet_directory_uri();1604 if ( ! is_child_theme() ) {1605 foreach ( $editor_styles as $file )1606 $mce_css[] = "$style_uri/$file";1607 } else {1608 $style_dir = get_stylesheet_directory();1609 $template_uri = get_template_directory_uri();1610 $template_dir = get_template_directory();1611 foreach ( $editor_styles as $file ) {1612 if ( file_exists( "$template_dir/$file" ) )1613 $mce_css[] = "$template_uri/$file";1614 if ( file_exists( "$style_dir/$file" ) )1615 $mce_css[] = "$style_uri/$file";1616 }1617 }1618 $mce_css = implode( ',', $mce_css );1619 } else {1620 $mce_css = '';1621 }1622 1623 $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );1624 1625 if ( ! empty($mce_css) )1626 $initArray['content_css'] = $mce_css;1627 1628 if ( is_array($settings) )1629 $initArray = array_merge($initArray, $settings);1630 1631 // For people who really REALLY know what they're doing with TinyMCE1632 // You can modify initArray to add, remove, change elements of the config before tinyMCE.init1633 // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".1634 // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.1635 if ( $teeny ) {1636 $initArray = apply_filters('teeny_mce_before_init', $initArray);1637 } else {1638 $initArray = apply_filters('tiny_mce_before_init', $initArray);1639 }1640 1641 if ( empty($initArray['theme_advanced_buttons3']) && !empty($initArray['theme_advanced_buttons4']) ) {1642 $initArray['theme_advanced_buttons3'] = $initArray['theme_advanced_buttons4'];1643 $initArray['theme_advanced_buttons4'] = '';1644 }1645 1646 if ( ! isset($concatenate_scripts) )1647 script_concat_settings();1648 1649 $language = $initArray['language'];1650 1651 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])1652 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');1653 1654 /**1655 * Deprecated1656 *1657 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.1658 * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter.1659 * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).1660 */1661 $version = apply_filters('tiny_mce_version', '');1662 $version = 'ver=' . $tinymce_version . $version;1663 1664 if ( 'en' != $language )1665 include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');1666 1667 $mce_options = '';1668 foreach ( $initArray as $k => $v ) {1669 if ( is_bool($v) ) {1670 $val = $v ? 'true' : 'false';1671 $mce_options .= $k . ':' . $val . ', ';1672 continue;1673 } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {1674 $mce_options .= $k . ':' . $v . ', ';1675 continue;1676 }1677 1678 $mce_options .= $k . ':"' . $v . '", ';1679 }1680 1681 $mce_options = rtrim( trim($mce_options), '\n\r,' );1682 1683 do_action('before_wp_tiny_mce', $initArray); ?>1684 1685 <script type="text/javascript">1686 /* <![CDATA[ */1687 tinyMCEPreInit = {1688 base : "<?php echo $baseurl; ?>",1689 suffix : "",1690 query : "<?php echo $version; ?>",1691 mceInit : {<?php echo $mce_options; ?>},1692 load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}1693 };1694 /* ]]> */1695 </script>1696 1697 <?php1698 if ( $compressed )1699 echo "<script type='text/javascript' src='$baseurl/wp-tinymce.php?c=1&$version'></script>\n";1700 else1701 echo "<script type='text/javascript' src='$baseurl/tiny_mce.js?$version'></script>\n";1702 1703 if ( 'en' != $language && isset($lang) )1704 echo "<script type='text/javascript'>\n$lang\n</script>\n";1705 else1706 echo "<script type='text/javascript' src='$baseurl/langs/wp-langs-en.js?$version'></script>\n";1707 ?>1708 1709 <script type="text/javascript">1710 /* <![CDATA[ */1711 <?php1712 if ( $ext_plugins )1713 echo "$ext_plugins\n";1714 1715 if ( ! $compressed ) {1716 ?>1717 (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.mceInit.language,th=t.mceInit.theme,pl=t.mceInit.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();1718 <?php } ?>1719 tinyMCE.init(tinyMCEPreInit.mceInit);1720 /* ]]> */1721 </script>1722 <?php1723 1724 do_action('after_wp_tiny_mce', $initArray);1725 }1726 1727 // Load additional inline scripts based on active plugins.1728 function wp_preload_dialogs($init) {1729 $plugins = preg_split('/[ ,-]+/', $init['plugins']);1730 1731 if ( in_array( 'wpdialogs', $plugins, true ) ) {1732 wp_print_scripts('wpdialogs-popup');1733 wp_print_styles('wp-jquery-ui-dialog');1734 }1735 1736 if ( in_array( 'wplink', $plugins, true ) ) {1737 require_once ABSPATH . 'wp-admin/includes/internal-linking.php';1738 ?><div style="display:none;"><?php wp_link_dialog(); ?></div><?php1739 wp_print_scripts('wplink');1740 wp_print_styles('wplink');1741 }1742 1743 // Distraction Free Writing mode1744 if ( in_array( 'wpfullscreen', $plugins, true ) ) {1745 wp_fullscreen_html();1746 wp_print_scripts('wp-fullscreen');1747 }1748 1749 wp_print_scripts('word-count');1750 }1751 1752 function wp_quicktags() {1753 global $tinymce_version;1754 1755 wp_preload_dialogs( array( 'plugins' => 'wpdialogs,wplink,wpfullscreen' ) );1756 1757 if ( !user_can_richedit() ) {1758 wp_enqueue_style( 'tinymce-buttons', includes_url('js/tinymce/themes/advanced/skins/wp_theme/ui.css'), array(), $tinymce_version );1759 wp_print_styles('tinymce-buttons');1760 }1761 }1762 1763 function wp_print_editor_js() {1764 wp_print_scripts('editor');1765 }1766 1767 function wp_fullscreen_html() {1768 global $content_width, $post;1769 1770 $width = isset($content_width) && 800 > $content_width ? $content_width : 800;1771 $width = $width + 10; // compensate for the padding1772 $dfw_width = get_user_setting( 'dfw_width', $width );1773 $save = isset($post->post_status) && $post->post_status == 'publish' ? __('Update') : __('Save');1774 ?>1775 <div id="wp-fullscreen-body">1776 <div id="fullscreen-topbar">1777 <div id="wp-fullscreen-toolbar">1778 <div id="wp-fullscreen-close"><a href="#" onclick="fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>1779 <div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">1780 1781 <div id="wp-fullscreen-mode-bar"><div id="wp-fullscreen-modes">1782 <a href="#" onclick="fullscreen.switchmode('tinymce');return false;"><?php _e('Visual'); ?></a>1783 <a href="#" onclick="fullscreen.switchmode('html');return false;"><?php _e('HTML'); ?></a>1784 </div></div>1785 1786 <div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="wp_themeSkin">1787 <?php1788 1789 $media_link_type = 'image';1790 if ( is_multisite() && ( ( ! $mu_media_buttons = get_site_option( 'mu_media_buttons' ) ) || empty( $mu_media_buttons['image'] ) ) )1791 $media_link_type = 'media';1792 1793 $buttons = array(1794 // format: title, onclick, show in both editors1795 'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'onclick' => 'fullscreen.b();', 'both' => false ),1796 'italic' => array( 'title' => __('Italic (Ctrl + I)'), 'onclick' => 'fullscreen.i();', 'both' => false ),1797 '0' => 'separator',1798 'bullist' => array( 'title' => __('Unordered list (Alt + Shift + U)'), 'onclick' => 'fullscreen.ul();', 'both' => false ),1799 'numlist' => array( 'title' => __('Ordered list (Alt + Shift + O)'), 'onclick' => 'fullscreen.ol();', 'both' => false ),1800 '1' => 'separator',1801 'blockquote' => array( 'title' => __('Blockquote (Alt+Shift+Q)'), 'onclick' => 'fullscreen.blockquote();', 'both' => false ),1802 'image' => array( 'title' => __('Insert/edit image (Alt + Shift + M)'), 'onclick' => "jQuery('#add_{$media_link_type}').click();", 'both' => true ),1803 '2' => 'separator',1804 'link' => array( 'title' => __('Insert/edit link (Alt + Shift + A)'), 'onclick' => 'fullscreen.link();', 'both' => true ),1805 'unlink' => array( 'title' => __('Unlink (Alt + Shift + S)'), 'onclick' => 'fullscreen.unlink();', 'both' => false ),1806 '3' => 'separator',1807 'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'onclick' => 'fullscreen.help();', 'both' => false )1808 );1809 1810 $buttons = apply_filters( 'wp_fullscreen_buttons', $buttons );1811 1812 foreach ( $buttons as $button => $args ) {1813 if ( 'separator' == $args ) { ?>1814 <div><span aria-orientation="vertical" role="separator" class="mceSeparator"></span></div>1815 <?php continue;1816 } ?>1817 1818 <div<?php if ( $args['both'] ) { ?> class="wp-fullscreen-both"<?php } ?>>1819 <a title="<?php echo $args['title']; ?>" onclick="<?php echo $args['onclick']; ?>return false;" class="mceButton mceButtonEnabled mce_<?php echo $button; ?>" href="#" id="wp_fs_<?php echo $button; ?>" role="button" aria-pressed="false">1820 <span class="mceIcon mce_<?php echo $button; ?>"></span>1821 </a>1822 </div>1823 <?php1824 } ?>1825 1826 </div></div>1827 1828 <div id="wp-fullscreen-save">1829 <span><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>1830 <img src="images/wpspin_light.gif" alt="" />1831 <input type="button" class="button-primary" value="<?php echo $save; ?>" onclick="fullscreen.save();" />1832 </div>1833 1834 </div>1835 </div>1836 </div>1837 1838 <div id="wp-fullscreen-wrap" style="width:<?php echo $dfw_width; ?>px;">1839 <label id="wp-fullscreen-title-prompt-text" for="wp-fullscreen-title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label>1840 <input type="text" id="wp-fullscreen-title" value="" autocomplete="off" />1841 1842 <div id="wp-fullscreen-container">1843 <textarea id="wp_mce_fullscreen"></textarea>1844 </div>1845 1846 <div id="wp-fullscreen-status">1847 <div id="wp-fullscreen-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></div>1848 <div id="wp-fullscreen-tagline"><?php _e('Just write.'); ?></div>1849 </div>1850 </div>1851 </div>1852 1853 <div class="fullscreen-overlay" id="fullscreen-overlay"></div>1854 <div class="fullscreen-overlay fullscreen-fader fade-600" id="fullscreen-fader"></div>1855 <?php1856 }1857 1858
Note: See TracChangeset
for help on using the changeset viewer.