Archive

Posts Tagged ‘WordPress’

Visual Code Editor 1.2.5

March 4th, 2010

I’ve updated Visual Code Editor. Not so much an upgrade, but tested it out with SyntaxHighlighter Evolved 2.3.8 and WordPress 2.9.2.

SyntaxHighlighter Evolved fixes a lot of the problems that VCE also fixed (for SyntaxHighlighter Plus 1.x). But VCE still comes into play when you want to use tinyMCE (the post editor) in WordPress.

  • Adds `<pre>` & `<code>` to block format menu
  • Allows extra attributes for compatibility in some syntax highlighters (ie, `<pre lang=”php” line=’5′>`)
  • Unescape WP’s double escaping of & (not needed with SHE)
  • Allows iFrames in the post
  • Support for syntax highlighting in comments
  • Removes extra `<pre>` tags around SyntaxHighllighter Plus’s sourcecode blocks

I tested it out with SHE and they both play very well together. Although the fixes in VCE are no longer needed, it still adds some functionality to the Visual Editor. Since nothing broke, I’m not going to fix it (remove the fixes). This allows its continued use in other client side syntax highlighters.

Go get it –> http://wordpress.org/extend/plugins/visual-code-editor/

Also, I highly recommend SyntaxHighlighter Evolved.

Visual Code Editor , , , ,

Visual Code Editor with WP-Codebox

January 26th, 2009

This is a test using the Visual Code Editor plugin with the WP-CodeBox plugin.

Original code:

	<Tr>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#l1title#
		</td>
		<td rowspan=16>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#r1title#
		</td>
	</tr>
<!--- ORDER --->
<cfhttpparam name="x_invoice_num"         type="formfield" value="#invoice_num#" >
<cfhttpparam name="x_description"         type="formfield" value="ScenicMesa.com online order">
<cfloop list="#x_line_items#" delimiters="#chr(9)#" index="i">
	<cfhttpparam name="x_line_item"       type="formfield" value="#i#">
</cfloop>

And here is WP-CodeBox enabled:

Rendering of WP-Codebox

Rendering of WP-Codebox - I took this screen capture just before turning deactivating the plugin.

Visual Code Edior allows for syntax and code editing right in WordPress’ invocation of TinyMCE. Therefore, all html entitied are escaped. As you can see this sometimes does not work with WP-CodeBox since it expects non-escaped code. This is why WP-CodeBox made it on my “Plugins that failed to help” list.

Now for SyntaxHighlighter Plus, which, on the other hand expects escaped code. And so it works well when editing code in visual mode of the WordPress post editor:

	<Tr>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#l1title#
		</td>
		<td rowspan=16>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td style="background-color:##598CB5;color:white;font-weight:bold;">
			#r1title#
		</td>
	</tr><!--- ORDER --->
<cfhttpparam name="x_invoice_num"         type="formfield" value="#invoice_num#" >
<cfhttpparam name="x_description"         type="formfield" value="ScenicMesa.com online order">
<cfloop list="#x_line_items#" delimiters="#chr(9)#" index="i">
	<cfhttpparam name="x_line_item"       type="formfield" value="#i#">
</cfloop>

Visual Code Editor , ,

Visual Code Editor 1.2.2: support for code in comments

January 20th, 2009

Visual Code Editor 1.2.2 now supports code and syntax highlighting in comments.

Testing iframe code…

<iframe src='/test.html'></iframe>

PHP, Visual Code Editor ,

Visual Code Editor 1.2.1: adds iframe, supports php4

January 16th, 2009

Visual Code Editor 1.2 allows iFrames in WordPress’s visual editor (TinyMCE). Example

And 1.2.1 has a code fix for WordPress installations on PHP4. Thanks to Keith for tipping me off!

PHP, TinyMCE, Visual Code Editor , , ,

Visual Code Editor 1.1.1 – Tested with WordPress 2.7

December 12th, 2008

Visual Code Editor is compatible with WordPress 2.7.

The only difference in 1.1.1 is that it states so. ‘Officially’.

No upgrade worries!

Visual Code Editor

Visual Code Editor 1.1 – valid xhtml

December 6th, 2008

Gremmie noticed that Syntax Higlighter Plus adds it’s own <pre> tag when outputting to page. That creates a nested <pre> tag which is not valid xhtml. So I fixed that with 1.1. Using <pre> in visual mode is still required. The fix is to remove the extra <pre> on output to page.

Also updated are the instructions of how to post code snippets:

  • In visual mode, create a [/sourcecode] block
  • Select the sourcecode block
  • Select Preformatted from TinyMCE’s format menu
  • Paste in your code

    Log into your WP Admin and update the plugin for the fix!

    Visual Code Editor, Web Coding

    Migrating from BlogCFC to WordPress

    November 24th, 2008

    Using WordPresses’ RSS import, I was able to copy every post from blogCFC easily. WordPress expects a local file when doing so. And blogCFC’s rss feed is limited to 15. To override that, edit file ‘blog.cfc’. It will be in the following path under your blogCFC installation: /org/camden/blog/. Just set arguments.params.maxEntries to something very very high. If you have less than 1500 posts, the following will do (starting at around line 742):

    <!--- Right now, we force this in. Useful to limit throughput of RSS feed. I may remove this later. --->
    <cfif (structKeyExists(arguments.params,"maxEntries") and arguments.params.maxEntries gt 15) or not structKeyExists(arguments.params,"maxEntries")>
    	<cfset arguments.params.maxEntries = 15>
    </cfif>
    <cfset arguments.params.maxEntries = 1500>
    

    Then, reinit your session to refresh the blog’s cache. Then go to your feed’s url with your web browser. You should have every single article there. Save that rss as a local xml file. Upload that file into WordPress. Great!

    But comments are not copied. So I made and used the below script to copy all post comments from blogCFC to WordPress. Not too difficult! 10 minutes tops.

    First, prep the blogCFC database. In the tblblogentries table (where blogcfc keeps the blog posts), add a column named ‘wpid’. For each row, enter WordPresses’s ID of the same post. I had 43 entried so it did not take a heck of a long time. Just sort both tables by title and do it. I suppose you can write a script for this too, but not worth the effort for 43 entries.

    With that done, here is the CF code:

    <cfquery name="read" dataSource="your-blogcfc-datasource">
    SELECT tblblogcomments.*, tblblogentries.wpid
    FROM tblblogcomments INNER JOIN tblblogentries ON tblblogcomments.entryidfk = tblblogentries.id
    </cfquery>
    
    <cfoutput query="read">
    	#wpid# #name# #email# #posted# #website#<br>
    
    	<cfquery name="ins" dataSource="your-wordpress-datasource">
    	INSERT INTO wp_comments
    	(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_content, comment_approved)
    	VALUES
    	('#wpid#', '#name#', '#email#', '#website#', '#posted#', '#comment#', 1)
    	</cfquery>
    </cfoutput>
    

    Run that page in a browser and all comments are imported! Nice. Then one more step. For each WP post, you have to update the post count. Again, not a big deal. Sort your WP comments table (wp_comments) by comment_post_id and do some simple math.

    ColdFusion, MySQL, News

    Visual Code Editor v1.0

    November 18th, 2008

    Visual Code Editor modifies WordPress’s behavior so that code format is preserved when using the visual editor. It will work with any syntax highlighter that accepts encoded (or escaped) syntax.

    Download the plugin: http://wordpress.org/extend/plugins/visual-code-editor/

    WordPress is really nice. But it mangles syntax in posts. I set out to end that with a non source-code-editing method: a plugin!

    The problem in WordPress comes in when you edit your post twice. When you load that post again, WP converts ampersands into “&”. Which is nice. But if you edit that post again, WP re encodes ampersands again. Giving you “&”. Want to guess what happens if you save and load it again? :)

    Now lets compound that with the visual editor, which automatically encodes for you as you type or paste. That only accelerates the process. And the fault here is with WP when it loads the post. Not with TinyMCE, at all.
    Lets make matters even worse. WP’s default settings for TinyMCE is really screwy. It’s horrible for programmers who want to blog.

    • Users have to switch to HTML or TEXT views to insert <pre> or <code> tags.
    • TinyMCE does not allow unknown attributes for tags like <pre line=”1″>.

    That may sound really picky. But most syntax highlight plugins require either <pre> or <code> and to use special attributes in them to display properly. Some require the syntax to have all entities escaped, some require the opposite. What a freaking nightmare. So I set out to end this nonsense.

    Enter Visual Code Editor. It’s a plugin I wrote for WordPress. Visual Code Editor makes it possible (and trouble free) to post and edit code snippets in wordpress’s visual editor.

    • Adds <pre> & <code> to block format menu
    • Allows extra attributes for compatibility in some syntax highlighters (ie, <pre lang=”php” line=’5′>)
    • Unescape WP’s double escaping of &
    • v1.1: Removes extra <pre> tags around SyntaxHighlighter Plus’s sourcecode blocks
    • v1.1.1: Tested with WordPress 2.7

    And the nicest thing is… it’s a plugin! You don’t have to go around editing WP’s base installation. Download, extract, upload, activate, done.

    Coupled with the SyntaxHighlighter Plus plugin, you get results like this:

    syntax highlight

    Syntax highlighter Plus runs through javascript on the client and expects the code to have entities encoded. Thanks to my plugin and TinyMCE, we’re golden. I chose Syntax highlighter Plus for a few reasons.

    • it’s the easiest to use and is smart.
    • It runs in javascript, search engines do not see tons of inline css muddying the page.
    • The page also downloads faster because of that.
    • The ‘copy to clipboard’ does not require flash.

    All you have to do is create a [/sourcecode] block, select the sourcecode block, select Preformatted from Tiny’s format menu, then paste in your code. It should look like this:

    syntax highlight   

    The Preformatted area tells TinyMCE to leave the formatting the heck alone. makes Syntax highlighter Plus do it’s magic on the viewer side. And you can still edit all of your code in the visual editor. Awesome!I also left the door open for other syntax highlighters, which instead of using , use <pre lang=”xxx” [line="5"]> or even <code>, etc.   

    Feel free to download the plugin, which is now in the WordPress PlugIn Directory! Yippee I learnt how ta use SVN today! http://wordpress.org/extend/plugins/visual-code-editor/

    Plugins that failed to help

    I did my homework before writing this plugin. I tried all of the following. All of which failed in one way or another.

    • Chili Code Highlighter
    • CodeHighlighter
    • Developer Formatter
    • Disable wpautop
    • Editor Extender
    • EmbedIt
    • Google Syntax Highlighter for WordPress
    • Preserve Code Formatting
    • Raw HTML capability
    • Text Control
    • TinyMCE Entities Patch
    • Code Snippet
    • Dean’s Code Highlighter
    • Highlight Source Pro
    • iG:Syntax Hiliter
    • Sniplets
    • Snippet Highlight
    • WP-CodeBox
    • WP-Syntax

    Visual Code Editor , , ,

    WordPress Plugin, Visual Code Editor, posts and edits code snippets in wordpress’s visual editor

    November 14th, 2008

    I will be moving my blog from blogCFC to WordPress. So I have it installed and played with skins and syntax highlighting… which is quite lacking.

    The problem comes in when you edit your post twice. When you load that post again, WP converts ampersands into “&amp;”. Which is nice. But if you edit that post again, WP re encodes ampersands again. Giving you “&amp;&amp;”. Want to guess what happens if you save and load it again? :)

    Now lets compound that with the visual editor, which automatically encodes for you as you type or paste. That only accelerates the process. And the fault here is with WP when it loads the post. Not with TinyMCE, at all.
    Lets make matters even worse. WP’s init for TinyMCE is really screwy. Looking at the code you’d think they were rocket scientists. But… dang it… the defaults are horrible for programmers who want to blog!

    • Users have to switch to HTML or TEXT views to insert <pre> or <code> tags.
    • TinyMCE does not allow unknown attributes for tags like <pre line=”1″>.

    That may sound really picky. But most syntax highlight plugins require either <pre> or <code> and to use special attributes in them to display properly. Some require the syntax to have all entities escaped, some require the opposite.  What a freaking nightmare.  So I set out to end this nonsense.

    Enter Visual Code Editor. It’s a plugin I wrote for WordPress. Visual Code Editor makes it possible (and trouble free) to post and edit code snippets in wordpress’s visual editor.

    • Adds <pre> & <code> to block format menu
    • Allows extra attributes for compatibility in some syntax highlighters (ie, <pre lang=”php” line=’5′>)
    • Unescape WP’s double escaping of &
    • v1.1: Removes extra <pre> tags around SyntaxHighlighter Plus’s sourcecode blocks

    And the nicest thing is… it’s a plugin! You don’t have to go around editing WP’s base installation. Download, extract, upload, activate, done.Coupled with the SyntaxHighlighter Plus plugin, you get results like this:

    syntax highlight 

    Syntax highlighter Plus runs through javascript on the client and expects the code to have entities encoded. Thanks to my plugin and TinyMCE, we’re golden. I chose Syntax highlighter Plus for a few reasons. 

    • it’s the easiest to use and is smart.
    • It runs in javascript, search engines do not see tons of inline css muddying the page.
    • The page also downloads faster because of that.
    • The ‘copy to clipboard’ does not require flash.

    All you have to do is create a [/sourcecode] block, select the sourcecode block, select Preformatted from Tiny’s format menu, then paste in your code.

    It should look like this:

    syntax highlight 

    The Preformatted area tells TinyMCE to leave the formatting the heck alone. makes Syntax highlighter Plus do it’s magic on the viewer side. And you can still edit all of your code in the visual editor. Awesome! 

    I also left the door open for other syntax highlighters, which instead of using , use <pre lang=”xxx” [line="5"]> or even <code>, etc.

    Feel free to download the plugin, which is now in the WordPress PlugIn Directory! Yippee I learnt how ta use SVN today! http://wordpress.org/extend/plugins/visual-code-editor/

    Plugins that failed to help

    I did my homework before writing this plugin. I tried all of the following. All of which failed in one way or another.

    • Chili Code Highlighter
    • CodeHighlighter
    • Developer Formatter
    • Disable wpautop
    • Editor Extender
    • EmbedIt
    • Google Syntax Highlighter for WordPress
    • Preserve Code Formatting
    • Raw HTML capability
    • Text Control
    • TinyMCE Entities Patch
    • Code Snippet
    • Dean’s Code Highlighter
    • Highlight Source Pro
    • iG:Syntax Hiliter
    • Sniplets
    • Snippet Highlight
    • WP-CodeBox
    • WP-Syntax

    Here are the plugins that I am currently running:

    WHEW! That’s enough blogging for today. I gotta get some work done!

    PHP, TinyMCE, Visual Code Editor

    Post code snippets in WordPress

    February 14th, 2007

    Here is the simplest way to easily add source code to WordPress with the built-in TinyMCE editor. There are a lot of posts of people looking for a simple solution like this. And Many people wrote plugins, that don’t really work. MoxieCode gets badmouthed for a poorly written editor. Well that’s all pretty silly. All we needed to do is read some of TinyMCE’s documentation and figure a clever CSS fix.

    At the end, you’ll be able to visually embed code just like:

    @ require('../../../wp-config.php');
     function wp_translate_tinymce_lang($text) {  if ( ! function_exists('__') ) {   return $text;  } else {   $search1 = "/^tinyMCELang[(['\"])(.*)1]( ?= ?)(['\"])(.*)4/Uem";   $replace1 = "'tinyMCELang[121]3'.stripslashes('4').__('5').stripslashes('4')";
       $search2 = "/ : (['\"])(.*)1/Uem";   $replace2 = "' : '.stripslashes('1').__('2').stripslashes('1')";
       $search = array($search1, $search2);   $replace = array($replace1, $replace2);
       $text = preg_replace($search, $replace, $text);
       return $text;  } }

    No plugins are needed. Minimal code changes are neccesary. And it works.

    1. Edit tiny_mce_config.php:
    /[wordpressInstallRoot]/wp-includes/js/tinymce/tiny_mce_config.php

    1a. Add the Format select box:
    Line 31, starts with “$mce_buttons = apply_filters(‘mce_buttons’, array(‘…”
    Append to the end of that array, “, ‘formatselect’, ‘cleanup’, ‘removeformat’”. So you should now have that line as:

    $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'separator', 'bullist', 'numlist', 'outdent', 'indent', 'separator', 'justifyleft', 'justifycenter', 'justifyright', 'separator', 'link', 'unlink', 'image', 'wp_more', 'separator', 'spellchecker', 'separator', 'wp_help', 'wp_adv_start', 'wp_adv', 'separator', 'formatselect', 'underline', 'justifyfull', 'forecolor', 'separator', 'separator', 'charmap', 'separator', 'undo', 'redo', 'wp_adv_end', 'formatselect', 'cleanup', 'removeformat'));

    1b. Use your blog’s style:
    Line 43, starts with “$mce_popups_css = get_option(’siteurl’)…”
    Replace lines 43 through 49 with:

     $mce_popups_css = '/[wordpressInstallRoot]/wp-includes/js/tinymce/plugins/wordpress/popups.css'; $mce_css = '/[wordpressInstallRoot]/wp-includes/js/tinymce/plugins/wordpress/wordpress.css, /[wordpressInstallRoot]/wp-content/themes/[yourCurrentTheme]/style.css'; $mce_css = apply_filters('mce_css', $mce_css); /*if ( $_SERVER['HTTPS'] ) {  $mce_css = str_replace('http://', 'https://', $mce_css);  $mce_popups_css = str_replace('http://', 'https://', $mce_popups_css); }*/

    1c. Install the Block Format Menu:
    In front of line 57, add:

    theme_advanced_blockformats : "pre,p,div,h1,h2,h3,h4,h5,h6,blockquote,code",

    1d. Modify TinyMCE’s line break behaviour:
    Replace lines 72 through 75 with:

     force_p_newlines : false, force_br_newlines : false, convert_newlines_to_brs : false, remove_linebreaks : false,

    1e. Modify TinyMce’s pasting behaviour:
    Replace lines 76 through 78 with:

     paste_create_paragraphs : false, paste_create_linebreaks: true, paste_auto_cleanup_on_paste : true,

    2. Edit your stylesheet for proper viewing in TinyMCE.
    /[wordpressInstallRoot]/wp-content/themes/[yourCurrentTheme]/style.css’

    By default TinyMCE will pick up the BODY style of your stylesheet. Pretty slick, except that most sites have content in a div or td of a different style. So lets fix that.

    2a. Add a style for TinyMCE’s body:
    This part really depends on your current wordpress theme. What you need to do is find the style of your content div or td, and apply that to TinyMCE’s window.
    At the top of your stylesheet, add:

    body.mceContentBody { text-align: left; background: #FFF;}

    The contents of this should match the contents of your div or td.

    2b. The style of our embedded code:
    Add another section to style our blocks of code, similar to:

    PRE { background-color:#EFEFEF; border-left:5px solid #DDDDDD; color:#000000; font-family:"Andale Mono","Courier New",fixed-width; font-size:11px; margin:15px 0px 15px 10px; overflow:auto; padding:5px 5px 20px 5px; line-height:1em; width: 530px;}

    Of course, you style is to your own taste. But I would suggest only fixed width fonts, non breaking lines, and auto overflow for scrollbars. The bottom padding of 20px is important for the bottom scroll bar. It’s actually a workaround for a particular browser. What to guess which one? I set the width to the width of my div as well, so that in TinyMCE, I get the correct view of it – scrollbars and all.

    Instructions

    Enter your post as you normally would. Let TinyMCE go buck wild – making <p> tags all over the place.
    For each block of code you pasted, select the block and use the format menu to select ‘Preformatted’. You should see that block of code in all its glory. “Hey, the line breaks are gone!” BloggerSayWha? Don’t fret. Save the post and the line breaks will magically appear.

    Enjoy =)

    TinyMCE