GeSHi Renderer & Proxy Classes for b2 (evolution)

Well, very inspired by Aral Balkan yesterday, got straight in Dreamweaver and started following the instructions, until I found I only had one of the files he had. I didn’t realize b2evolution was not infact b2/cafelog, it has changed considerably, ever…

Well, very inspired by Aral Balkan yesterday, got straight in Dreamweaver and started following the instructions, until I found I only had one of the files he had. I didn’t realize b2evolution was not infact b2/cafelog, it has changed considerably, everything is now very OO. Thankfully now there’s no need for hacks to the source (I hope).

Now you have to create a PHP sub-class of Renderer, and get that to do some preg_match’ing of it’s own. My PHP hat is still fairly new, but I’ll try and go through what I had to do to get it all working….you can just download it if you feel lazy.

First of all, GeSHi will (at present) only work on PHP 4 and some PHP 5 installations (specifics yet to be confirmed), but I’ve written a workaround later on in this post.

First up download the zip file provided (contains the Renderer plugin and CSS file) geshi_for_b2.zip, then download and unzip GeSHi to your b2 blog root.

  • Unzip the first file, and put _geshi.renderer.php in “b2root/plugins/renderers/” (where b2root is your blog’s root directory)
  • Place geshi.css in “your_skin_directory/geshi.css” (e.g. on mine this is “b2root/skins/custom/”)
  • Add to “b2root/config/_config.php”:
    include_once (dirname(__FILE__ ) . ‘/../geshi.php’);
  • Add to “b2root/skins/custom/_main.php” (where custom is your current skin):
    <link rel=”stylesheet” href=”geshi.css” type=”text/css” />

All done 🙂 you should now be good to go…

Usage:

  • Wrap any code in [as], [java] or [php] (etc) tags.
  • Click the tick next to “Geshi” in the Renderers palette.

Sample Actionscript:

[as]Date.prototype.getDateOffset = function(offset)
{
var retDate = new Date(this);
retDate.setTime(retDate.getTime()+offset*86400000);
return retDate;
}[/as]

Good news is, your code remains editable in the admin section, you save some CPU cycles as the CSS is pre-generated (you can generate more with cssgen.php provided with GeSHi). I’ve included CSS for Actionscript, PHP, Java, HTML, but the renderer is only looking for the 1st three of those for speed reasons, you can enable as many as you like in under a minute.

Now for PHP 5 :s :

(Un)lucky for me, my webhost is running PHP 5, which GeSHi doesn’t like, so in light of this, I’ve written a Proxy Renderer class, that will get a script on a PHP 4 server to generate the required highlighted code, and return it to the Proxy plug-in.

To install, simply download the geshiproxy_for_b2.zip files and modify the commented code in the “geshiproxy_Rendererplugin.php” file to point to your PHP 4 server (this could be a free host with banners for example). Put that file in your “b2root/plugins/renderers” folder. Next up, put the “doGeshi.php” file on your PHP 4 webhost, at the location defined in the Proxy class.

This is currently the method I am using, and so far so good as long as you’ve installed GeSHi to your other host of course.

Good luck, please feel free as always to comment on anything.

5 thoughts on “GeSHi Renderer & Proxy Classes for b2 (evolution)”

  1. nice tip. I use wordpress myself, I wonder if this’ll work on wordpress as well since it’s an offshoot of the original b2 blog code.

  2. Man, I need to get around the blogs more. Nice work! I’m so jealous of the new blog engines based on b2. I guess getting in early isn’t always the best thing. I’ve got so many hacks in there that, well… I guess I have to take a week off sometime and port everything to b2evolution or wordpress. It’s *really* great to hear that b2evolution is OO — from what little I’ve seen of wordpress, it appears to be much closer to the original b2.

Comments are closed.