/* Import plugin specific language pack */ tinyMCE.importPluginLanguagePack('wordpress', 'en'); var TinyMCE_wordpressPlugin = { getInfo : function() { return { longname : 'WordPress Plugin', author : 'WordPress', authorurl : 'http://wordpress.org', infourl : 'http://wordpress.org', version : '1' }; }, getControlHTML : function(control_name) { switch (control_name) { case "wp_more": return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_more_button', '{$pluginurl}/images/more.gif', 'wpMore'); case "wp_page": return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_page_button', '{$pluginurl}/images/page.gif', 'wpPage'); case "wp_help": var buttons = tinyMCE.getButtonHTML(control_name, 'lang_help_button_title', '{$pluginurl}/images/help.gif', 'wpHelp'); var hiddenControls = '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
'; return buttons+hiddenControls; case "wp_adv": return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_adv_button', '{$pluginurl}/images/toolbars.gif', 'wpAdv'); case "wp_adv_start": return ''; } return ''; }, execCommand : function(editor_id, element, command, user_interface, value) { var inst = tinyMCE.getInstanceById(editor_id); var focusElm = inst.getFocusElement(); var doc = inst.getDoc(); function getAttrib(elm, name) { return elm.getAttribute(name) ? elm.getAttribute(name) : ""; } // Handle commands switch (command) { case "wpMore": var flag = ""; var template = new Array(); var altMore = tinyMCE.getLang('lang_wordpress_more_alt'); // Is selection a image if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") { flag = getAttrib(focusElm, 'class'); if (flag != 'mce_plugin_wordpress_more') // Not a wordpress return true; action = "update"; } html = '' + ''; tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html); tinyMCE.selectedInstance.repaint(); return true; case "wpPage": var flag = ""; var template = new Array(); var altPage = tinyMCE.getLang('lang_wordpress_more_alt'); // Is selection a image if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") { flag = getAttrib(focusElm, 'name'); if (flag != 'mce_plugin_wordpress_page') // Not a wordpress return true; action = "update"; } html = '' + ''; tinyMCE.execCommand("mceInsertContent",true,html); tinyMCE.selectedInstance.repaint(); return true; case "wpHelp": var template = new Array(); template['file'] = tinyMCE.baseURL + '/wp-mce-help.php'; template['width'] = 480; template['height'] = 380; args = { resizable : 'yes', scrollbars : 'yes' }; tinyMCE.openWindow(template, args); return true; case "wpAdv": var adv = document.getElementById('wpadvbar'); if ( adv.style.display == 'none' ) { adv.style.display = 'block'; tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonSelected'); } else { adv.style.display = 'none'; tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonNormal'); } return true; } // Pass to next handler in chain return false; }, cleanup : function(type, content) { switch (type) { case "insert_to_editor": var startPos = 0; var altMore = tinyMCE.getLang('lang_wordpress_more_alt'); var altPage = tinyMCE.getLang('lang_wordpress_page_alt'); // Parse all tags and replace them with images while ((startPos = content.indexOf('', startPos)) != -1) { // Insert image var contentAfter = content.substring(startPos + 11); content = content.substring(0, startPos); content += ''; content += contentAfter; startPos++; } var startPos = 0; // Parse all tags and replace them with images while ((startPos = content.indexOf('', startPos)) != -1) { // Insert image var contentAfter = content.substring(startPos + 15); content = content.substring(0, startPos); content += ''; content += contentAfter; startPos++; } // Look for \n in
, replace with 
var startPos = -1; while ((startPos = content.indexOf('', startPos+1); var innerPos = content.indexOf('>', startPos+1); var chunkBefore = content.substring(0, innerPos); var chunkAfter = content.substring(endPos); var innards = content.substring(innerPos, endPos); innards = innards.replace(/\n/g, '
'); content = chunkBefore + innards + chunkAfter; } break; case "get_from_editor": // Parse all img tags and replace them with var startPos = -1; while ((startPos = content.indexOf('', startPos); var attribs = this._parseAttributes(content.substring(startPos + 4, endPos)); if (attribs['class'] == "mce_plugin_wordpress_more" || attribs['name'] == "mce_plugin_wordpress_more") { endPos += 2; var embedHTML = ''; // Insert embed/object chunk chunkBefore = content.substring(0, startPos); chunkAfter = content.substring(endPos); content = chunkBefore + embedHTML + chunkAfter; } if (attribs['class'] == "mce_plugin_wordpress_page" || attribs['name'] == "mce_plugin_wordpress_page") { endPos += 2; var embedHTML = ''; // Insert embed/object chunk chunkBefore = content.substring(0, startPos); chunkAfter = content.substring(endPos); content = chunkBefore + embedHTML + chunkAfter; } } // Remove normal line breaks content = content.replace(/\n|\r/g, ' '); // Look for
in
, replace with \n
				var startPos = -1;
				while ((startPos = content.indexOf('', startPos+1);
					var innerPos = content.indexOf('>', startPos+1);
					var chunkBefore = content.substring(0, innerPos);
					var chunkAfter = content.substring(endPos);
					
					var innards = content.substring(innerPos, endPos);
					innards = innards.replace(new RegExp('', 'g'), '\n');
					innards = innards.replace(new RegExp('\\s$', ''), '');
					content = chunkBefore + innards + chunkAfter;
				}

				// Remove anonymous, empty paragraphs.
				content = content.replace(new RegExp('

(\\s| )*

', 'mg'), ''); // Handle table badness. content = content.replace(new RegExp('<(table( [^>]*)?)>.*?<((tr|thead)( [^>]*)?)>', 'mg'), '<$1><$3>'); content = content.replace(new RegExp('<(tr|thead|tfoot)>.*?<((td|th)( [^>]*)?)>', 'mg'), '<$1><$2>'); content = content.replace(new RegExp('.*?<(td( [^>]*)?|th( [^>]*)?|/tr|/thead|/tfoot)>', 'mg'), '<$2>'); content = content.replace(new RegExp('.*?<(tr|/table)>', 'mg'), '<$1>'); content = content.replace(new RegExp('<(/?(table|tbody|tr|th|td)[^>]*)>(\\s*|(
)*)*', 'g'), '<$1>'); // Pretty it up for the source editor. var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p'; content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>\\s*', 'mg'), '\n<$1>'); content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>'); content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>'); content = content.replace(new RegExp('\\s*
\\s*', 'mg'), '
\n'); content = content.replace(new RegExp('^\\s*', ''), ''); content = content.replace(new RegExp('\\s*$', ''), ''); break; } // Pass through to next handler in chain return content; }, handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonNormal'); tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonNormal'); if (node == null) return; do { if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_more') == 0) tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonSelected'); if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_page') == 0) tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonSelected'); } while ((node = node.parentNode)); return true; }, saveCallback : function(el, content, body) { // We have a TON of cleanup to do. // Mark

if it has any attributes. content = content.replace(new RegExp('(]+>.*?)

', 'mg'), '$1'); // Decode the ampersands of time. // content = content.replace(new RegExp('&', 'g'), '&'); // Get it ready for wpautop. content = content.replace(new RegExp('[\\s]*

[\\s]*', 'mgi'), ''); content = content.replace(new RegExp('[\\s]*

[\\s]*', 'mgi'), '\n\n'); content = content.replace(new RegExp('\\n\\s*\\n\\s*\\n*', 'mgi'), '\n\n'); content = content.replace(new RegExp('\\s*
\\s*', 'gi'), '\n'); // Fix some block element newline issues var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre'; content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); content = content.replace(new RegExp('
  • ', 'g'), '\t
  • '); // Unmark special paragraph closing tags content = content.replace(new RegExp('', 'g'), '

    \n'); content = content.replace(new RegExp('\\s*(]+>.*

    )', 'mg'), '\n$1'); // Trim any whitespace content = content.replace(new RegExp('^\\s*', ''), ''); content = content.replace(new RegExp('\\s*$', ''), ''); // Hope. return content; }, _parseAttributes : function(attribute_string) { var attributeName = ""; var attributeValue = ""; var withInName; var withInValue; var attributes = new Array(); var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g'); var titleText = tinyMCE.getLang('lang_wordpress_more'); var titleTextPage = tinyMCE.getLang('lang_wordpress_page'); if (attribute_string == null || attribute_string.length < 2) return null; withInName = withInValue = false; for (var i=0; i]*\\s)?)(src|href)\\s*=', 'gi'), '<$1 x$4='); else h = tinyMCE.orgFixGeckoBaseHREFBug(m, e, h); return h; }; tinyMCE.orgStoreAwayURLs = tinyMCE.storeAwayURLs; tinyMCE.storeAwayURLs = function(s) { // Remove all mce_src, mce_href and replace them with new ones s = s.replace(new RegExp('mce_(href|src)\\s*=\\s*\"[^ >\"]*\"', 'gi'), ''); s = s.replace(new RegExp('<((a|img|select|area|iframe|base|input|script|embed|object|link)\\s([^>]*\\s)?)(src|href)\\s*=\\s*"([^"]*)"', 'gi'), '<$1 $4="$5" mce_$4="$5"'); return s; };