I’ve spent a little time porting John Gruber’s Title Case script to PHP, and then to ExpressionEngine as a plugin.
The PHP build went relatively quickly, and worked as I hoped (at least for an initial version), but the plugin has given me some fits.
Basically, once I use it as a plugin in ExpressionEngine, the script is suddenly dealing with html entities because EE converts straight quotes in titles to entities (normally I’d be very happy about this). My trouble is in getting the regular expression to function properly when looking for these entities. I can get the regular expression to work in isolation, just not in the plugin.
Anyway, I’ve now spent more time on this than I expected and will go ahead and post my plugin here - it works everywhere except where surrounded by html entities for quotes (these words simply aren’t cased properly by the script).
Hopefully someone out there can take a look and give me some clues… otherwise, I’ll pick up again on improving it tonight.
Thanks in advance.
Update: Version 1.2 now requires that the SmartyPants plugin be installed.
Update: Version 1.3 no longer requires that the SmartyPants plugin be installed, but if it is installed, SmartyPants will be applied automatically to fix the straight quotes this plugin creates.
I have now updated the plugin to allow for the html entities for quotes and apostrophes. I’m sure that this can be done in a much more elegant way, so I’m eager to hear from any PHP experts out there.
I can’t guarantee that this is a 100% accurate PHP port of Gruber’s script, but it is darn close from what I can tell.
Please kick the tires and let me know if you have any suggestions.
You can find the updated plugin posted above.
Updated to version 1.2 - available above
I’ve gone back an updated this plugin again. It now requires that the SmartyPants plugin is also installed.
It solved a lot of problems I was having with converting quotes back and forth. It also adds the nice ability to a lot of punctuation to their proper html entities (something I do on a lot of sites anyway), so the combination made sense.
Let me know of any suggestions.
Nice plugin. Thanks!
Was wondering whether you would consider updating it to check for/include either the SmartyPants plugin or the Typogrify plugin. The Typogrify plugin incorporates SmartyPants so your plugin will work with it.
Also, your plugin version number needs updating, and fashion is missing an ‘h’ in the description.
Thanks again 😊
@Will
Thanks for the suggestions. I’m having trouble downloading the Typogrify plugin (looks promising) for testing.
In the meantime, I’ve taken care of the problems you highlighted (thank you very much), and I’ve removed the dependency on SmartyPants (instead, applying it if it is installed, but not requiring it). I’m happy to add a round of checks for Typogrify if I can find a place to download it properly.
I tried the right-click trick, too. I was also able to unzip the file, but when I opened it in my text-editor all I got was gibberish, so I was (understandably) a little hesitant to upload it to my site.
I’m out of town for the weekend, but I’ll give it a try again as soon as I’m back.
Update: Will got the Typogrify plugin to me, but I’m currently having some trouble implementing it. If we get it working properly, I’ll post an update to this thread.
Sorry about the download problems with the typogrify plugin. I’m sure I had that working properly at some point, but it should be solved now. :)
It seems that EE has a problem with filenames ending in .php.zip—it displays it as a page by default or if you try to download it, it appends a .html ending. I’ve changed the ending of the downloadable file to just .zip, which will then expand to the .php file after you unzip it. It should work with you just clicking on the link now without the need for using the right-click menu.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.