Archive for category Tips & Tricks

How to allow Style tag/element within your WordPress Blog for inline CSS

If you trust yourself enough to use the <style> tag within your self-hosted WordPress blog then here is how to get them to work:

  • Go to your WordPress installation and locate the wp-includes\kses.php file
  • Open the file in a text editor and locate the $allowedposttags variable
  • Paste the following snippet of code:
    ‘style’ => array(),
  • just after the line that says:
    $allowedposttags = array(

Your code should now look like the image below:

kses.php showing where to add style tag

That gets the backend of WordPress accepting the style tag. If you write a post now and post it using LiveWriter or the “HTML” editor in wp-admin it should get rendered out into your browser as desired.

The problem is, if you create or edit a post using the WYSIWIG “Visual” editor you will find that your style tag gets turned into a comment like so:

 WordPress TinyMCE visual editor showing style tag converted to comments

That’s because the client side JavaScript responsible for the WYSIWYG editor is stripping out the style tag and turning it into a comment. In the default WordPress install the WYSIWYG component is called TinyMCE. Here are the instructions for hacking (that’s the spirit of php isn’t it? ;-) ) TinyMCE to allow the element tag:

  • Open the wp-admin\includes\post.php file in a text editor
  • Locate code where the $initArray variable is defined. Hint: it begins like this:
    // TinyMCE init settings
    $initArray = array (
  • Now add the following line to the end of the array
    ‘extended_valid_elements’ => ‘style’
  • Don’t forget to add a comma to the end of the preceding line! (in this example thats the one ending in “$plugins”)

If all goes to plan the lower half of the $initArray declaration should look like this:

post.php after its been edited to allow element tag

After all that’s done don’t forget to force your browser to flush its cache i.e. by using Control + F5.

You should now be able to use the style element in your posts, allowing you to create inline CSS to your hearts content.

The same principle applies if you want to allow any other html tags in WordPress.

Direct Download Links for SQL Server 2008 Express

I find it a bit annoying that Microsoft are pushing the Web Platform installer so hard these days that they have removed all obvious direct download links for the various SQL Express packages on the “Express” site. Not everyone has the luxury of unmetered downloads – some of us want to archive these installers locally, and not use the Web Platform Installer every time.

To save you the bother, here is my reimagining of the table on the SQL Express downloads page:

Server 2008 Express

Management Tools

Runtime

Runtime with Management Tools

Runtime with Advanced Services

SQL Server Management Database Engine

-

Download Now Download Now Download Now
SQL Server Management Studio Express Download Now

-

Download Now Download Now
Full-Text Search

-

-

-

Download Now
Reporting Services

-

-

-

Download Now
Includes SP1 No Yes No No
Download Size 38.5 168 MB 82.5 MB 230.4 MB 546.5 MB
Cost FREE FREE FREE FREE
Install Direct download button for SQL 2008 Management Tools Direct download button for SQL 2008 Runtime Direct download button for SQL 2008 Runtime with Management Tools Direct download button for SQL 2008 Runtime with Advanced Services

I am a bit confused how they came up with 38.5 MB for the SQL Management Studio download… if you check the direct download link you will see its 168 MB. This seems to tally up more closely with the combined “runtime with management tools” download of 230.4 MB. If they have managed to fit SSMSE into 38.5 MB then I am curious why I can’t find the direct download link – Leave a comment if you know the story behind that.

I have one more comment about SQL Express, but it’s so important I’ve decided to write it as separate blog post in the hope it makes it easier for people/google to find. The post is about whether the various SQL Express downloads include Service Pack 1.

Windows 7 ISO: How to easily switch edition

There have been quite a few blog posts about how to manually switch edition of the Windows 7 ISO, for example to change from Ultimate to Home Premium.

What I wanted was a program that automated all the steps. I was going to write one myself, but thankfully someone has already released a tool to do just that. The guy responsible is Kai Liu and in fact he has two programs:

  • One to turn your ISO into an “All editions” ISO, just like the RC used to work (eicfg_removal_utility)
  • One to switch ISO editions which results in a “bit perfect” rendition of the original MSDN ISOs, verified against the MSDN hash codes (windows7_iso_image_edition_switcher)

You can download them both here: http://code.kliu.org/misc/win7utils/

Kai Liu's Windows 7 ISO Patcher Utils

Here is the original neowin post where he talk about the utilities. For the untrustworthy, both of these utilities come bundled with the source code so you can see exactly what they are doing.

Notes: Both these utilities modify the ISO files in-place (so you don’t need to worry about multiple GB file copies).

One potential draw back is both programs use dialogs to select the ISOs so you won’t be able to automate use of these utilities in a script very easily.

As is often the case it can be hard to find the “original” (trustworthy) executables for utilities like this as they get shared widely, copied, and referenced on random forums. Hence after a bit of research I wanted to do my bit to add Google juice to the genuine “Windows 7 ISO Edition Patching/Switching” article.

Tip for pathping

This lesser known command line utility, introduced on Windows 2000, is something of a hybrid between ping and tracert.

Instead of just determining the path, pathping also sends a barrage of pings to each host along the route. After pathping completes (which can take 5 minutes) it generates statistics for failed pings at each node making it easy to indentify hosts in the route where packet loss is occurring. It also shows averaged round trip times (RTT) to each node, allowing you to identify slow hops, and visualize a packet’s journey.

If you are anything like me though, you may never have paid close attention to pathping’s (somewhat confusing) output…

image

If you look carefully (ok, not that carefully – I’ve circled the section in red) you will see the ASCII art bars “connecting” each host. What’s interesting is pathping shows you both the packet loss between yourself and the host, as well as packet loss on the links between hosts (the bars). As you can see in the screen shot above its perfectly possible to have a host (telstra310) that is not directly reachable, yet is perfectly able to forward on packets. There is an example in the the full pathping documentation that describes such a result like this:

The routers [snip] are dropping packets addressed to them, but this loss does not affect their ability to forward traffic that is not addressed to them.

One thing I still haven’t figured out is what the value in the “This Node/Link” means in a row that has a “Source to Here” entry. I am assuming it means routed packets that entered the host but never left. Answers on a postcard.

Using a telnet client as a port scanner

If you ever need to check if a TCP port is open or reachable, one easy way to do it is using a telnet client.

A telnet client actually comes with Windows, but for some annoying reason it is not installed by default. To install the windows telnet client you need to add it using the “Turn Windows features on and off” like so:

image

Because Telnet is essentially just characters sent over a TCP connection, you can use the telnet client as a poor man’s TCP port scanner. To manually check if TCP port 80 is open or reachable on a server you can type telnet myserver.com 80.

As an example lets see if Google.com has port 80 (HTTP) open … ;-)

image

image

If you get a blank screen with a blinking cursor you have successfully connected to that TCP port.

In this example, if you are feeling particularly sadistic you can now engage in a HTTP conversation. Type GET index.html HTTP/1.0 and press enter and you will see Google’s home page being sent to you. Same idea would apply if you connected to most other TCP-based protocols; POP mail server etc.

image

On the other hand if the TCP port is not open or not reachable you will see this:

image

Troubleshooting ports and firewalls can be a pain. This is the simplest and quickest way I know for checking connectivity.