PHP 5.3 and Typo3 4.3 – t3lib_error_Exception

If you are already using PHP 5.3.x and you’ve just upgraded to Typo 4.3 or greater, Typo3 might start throwing exceptions where previously everything had worked out just fine.

This is because the Typo3 developers chose to take some of the error handling into their own hands and raise exceptions for certain errors. Now these “certain errors” for which exceptions are raised include E_DEPRECATED, and as a bunch of functions have been deprecated in PHP 5.3, well, you know where I’m going with this.

Fortunately, there is a configuration variable which allows to change the default behavior:

$TYPO3_CONF_VARS['SYS']['exceptionalErrors']

The default value (defined in “t3lib/config_default.php”) is

E_ALL ^ E_NOTICE ^ E_WARNING ^ E_USER_ERROR ^ E_USER_NOTICE ^ E_USER_WARNING

To disable the deprecation exceptions, just add a ^ E_DEPRECATED like this (the line goes in your localconf.php file):

$TYPO3_CONF_VARS['SYS']['exceptionalErrors'] = E_ALL ^ E_NOTICE ^ E_WARNING ^ E_USER_ERROR ^ E_USER_NOTICE ^ E_USER_WARNING ^ E_DEPRECATED;

Thanks to this guy (link in German) for sending me onto the right path.

Hard to debug, or why you should always use the right Content-Type

Today I came along a really nasty bug in a WebApp, which was caused by not setting the correct Content-Type. Took me a while to figure it out. The App had been working fine for a while now, and after writing a small extension to it, it broke down completely, because a JSON response sent from my server was suddenly invalid and could not be parsed by jQuery. The first problem was that my handler for the AJAX requests did not set a Content-Type, which somehow defaulted to text/html. The second problem was, that I had forgotten a closing tag in the HTML which was encoded inside the JSON string returned from the handler. Because the Content-Type was text/html, the browser tried to fix the missing tag by appending it to the end of the response, which obviously broke my JSON string.

From now on I will definitely always set the right Content-Type, so I never have to deal with such a bug again.

Git Hooks: Automatically checking out a repository after pushing to it

I’ve been experimenting with file-based blogging software (namely Blosxom) lately, and I wanted to automatically transfer my university notes from my computer to my server. I also wanted to add some versioning for backup, so the obvious thing to do was to use Git.

Git Hooks are pretty easy to use. When creating a repository with git init, a folder hooks/ is automatically created within your .git/ directory, which contains sample/skeleton scripts for all available hooks. To enable a hook, you just set its executable bit using chmod +x hook-file.

For checking out my repository after pushing, I used the post-receive hook, so I added the following to the .git/hooks/post-receive file:

pwd = Dir.pwd
Dir.chdir("../")
%x[echo "GIT_DIR = #{pwd} git checkout -f" 1>&2]
%x[GIT_DIR="#{pwd}" git checkout -f]

What the above Ruby code does is simple. It first stores the current working directory, which for a called hooks always seems to be the .git/ folder of the repository. Then it changes to the parent folder (the actual, checked out repository), and executes a git checkout -f there. Note that with the -f option will overwrite all modification in your repository, so be careful with that.

The GIT_DIR variable needs to be set, because git does not seem to automatically recognize the .git/ folder when called within a hook, which is probably due to some environment variable being or not being set. If someone knows the exact reason, feel free to drop a comment :)

More on Git hooks can be found here.

Blosxom and UTF8

A few days ago I installed Blosxom to store my university notes which I write in Markdown and in German language, and which are UTF8 encoded. But I couldn’t get Blosxom to not screw up the encoding even if I set the correct Content-Type Header in HTML. It turned out that you need to modify the line which says something like

$header = {-type=>$content_type}; # Around line 280

to this

$header = {-type=>$content_type, -charset=>'utf8-'};

This tells the Perl CGI module to send the correct HTTP encoding headers for your document. You should also add

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

to your HTML Head section (which you can find around line 430 if you are using the default template.

And voila, the multibyte characters aren’t screwed up anymore :)

Note: This fix does not work for static file generation in Blosxom, only for dynamic mode.

LaTeXiT – Easy LaTeX Formula Generation

Some days ago I found a nice Mac OS X application called “LaTeXiT”, which makes LaTeX formula generation really easy. If you are already working in a LaTeX environment you’ve got no problem anyway, but what if you’d like to use your LaTeX formulas in Pages (or Word), Keynote, etc… Either you go with the “generate from console” approach, or you use LaTeXiT. But see for yourself:

Get it here.

LaTeX: Footnotes in itemize (and minipages).

Sometimes LaTeX can be a real pain… Today I wrote a document where I needed a caption inside an \item marker, e.g.:

\begin{itemize}
    \item [ Something \footnote{More} ] Lorem ipsum
\end{itemize
}

But that didn’t work. The footnote number was displayed, but there was no footnote at the bottom of the page. A workaround is to include the package “footnote”, and create a “save note environment” for itemize, by including the following in the document header:

\usepackage{footnote}
\makesavenoteenv{minpage
}   % If you want to include minipages.
\makesavenoteenv{itemize}

Facebook Multi Friend Selector with jQuery

Recently, I needed to build a feature where connected Facebook users (in a FB connect application) could select a bunch of their friends in order to interact with them through the app. This was supposed to happen through a Multi Friend Selector like the following:

Facebook Multi Friend Selector

Facebook offers such a feature through the XFBML fb:multi-friend-selector Tag, but it resulted very hard to interact with it through JavaScript (showing it after the user clicks a button, performing a certain action after he selected his friends, etc…). I ended up using jQuery Multi Friend Selector which imitates the behaviour of the XFBML Tag.