Hooks in Second Crack

Second Crack

If you haven’t figured it out yet, I’m pretty excited about the fact this blog is running on Second Crack. I’m so excited, I’ve started customizing it (and contributing my changes back to Marco, if he wants them).


The first thing I have added is the ability to utilize hooks. I’ve done this using the “push” style of events. When the engine runs the update and publishes a post, it fires off a method that will look for any scripts in the /hooks directory that have a filename that starts with post_. It will then expect that the rest of the filename matches the class inside of the file (i.e. post_dummy.php should define a class named Dummy). The class should extend the Hooks class and implement the doHook method. The doHook method is passed a Post object representing the post being published. I’ve included a sample hook that simply writes the error_log so that others can see how to implement their own hooks.


Now for my first real hook submission, I had planned to do a hook that will post to Twitter “New Post: ” followed by the post name and a URL to the post. I took it a step further and connected in bit.ly support. I’m using the hook for this blog, but it’s not ready to be released. Also, since it looks like Marco beat me to the punch and has already implemented a Twitter hook, I will probably just discard mine and use his. However, I may still add in the Bit.ly support (though I’ll make it configurable)


Next up? Maybe an email hook. I can see this being useful for the Dropbox-PHP project. When I post a release to the site, it would be nice if it could email the mailing list notifying everyone of the release and what is in it (of course along with a link back to the blog).

Comments !