Claus Beerta

Stuff i do, don't and other babble.

First Post via Posterous

So, how do you build an interface to post content for your selfmade Blog app if you actually don’t really want to?

Easy: You don’t!

I’ve been looking around for inspirations on how to build a interface to put posts on my selfmade website. Thing is though: Input validation is tedious and error prone. Even if i am the only person who will ever use this interface, i’ll still manage to trick myself. Encodings, Character Sets, HTML Editing etc, then i’d like to post Images and Photos and other Media stuff. Building a frontend for that is a tedious task.

So, why bother?

Posterous to the rescue

While looking around i stumbled over tumblr and posterous both providing a blogger like service that:

  • Doesn’t run on Wordpress. I’ve grown old and tired of it.
  • Both have slick looking and quick interfaces.
  • Neither want to know when your mothers, best friends niece had it’s last teeth pulled while signing up.
  • Both allow posting Markdown content via Email, and they both obviously have rich text editors to edit your posts afterwards.

What Posterous also has is the ability to distribute content to various other sites.

That and Posterous didn’t present the site in german to me unlike Tumblr. I know german, sure, but i don’t want to. My browser says “Give me English Please”, so why send me a german page? I absolutely HATE it when sites do that.

My Content is Mine

Posterous has a simple, yet usefull API that allows me to get my Content back and put it on my site. It also has a comments API where i can feed the comments from posterous back into my database. That way everything i create is under my control, and i can do with it as i see fit. If for some reason the site starts to bother me, i can just delete my account. I will keep my content.

Punch line is: I can use Posterous wonderful interface and features to produce and distribute content, and then just pull it back into my Site.

Here’s the Code to it. It lacks importing comments, but that’s not that urgent.

Triggering the importer

Once posted, Posterous sends a mail back to confirm that something went live. Why thank you, I can use that!

A little procmail action:

:0
 * ^From: .*post@posterous.com.*
 {
     :0 c # Trigger an Update
     ! USER=cbeerta PASSWORD=thoughshallnotknow php index.php --import-posterous

:0 # and store it (for now) $DEFAULT }

And the post will be added to my page immediatly. Nifty.



Reading other people's Code

I don't know if i just suck at understanding other people's (php mostly) code, but i frequently find myself slapping my forehead while reading code other people produce. I don't say i'm a lot better at it, and i know that, that''s why i would never ever put my crap code online for other people to use and work with.

I''m on the search for a Wiki Software (more a Wiki Class) that i can use to start writing something that is in my head, and i don't currently want to write my own Wiki just for that. (I wonder how long i can withstand that urge though). While going through the numerous PHP Wiki's that are available, i'm getting more and more frustrated.

Just an example of what i feel is just bad:


@ini_set('session.use_cookies','1');
@ini_set('session.use_only_cookies','1');
@ini_set('url_rewriter.tags','');
@ini_set('session.use_trans_sid','0');
@ini_set('display_errors','on');
@ini_set('default_charset',wc_charset);
@ini_set('mbstring.func_overload','7');
@ini_set('mbstring.internal_encoding',wc_charset);
@ini_set('mbstring.internal_encoding',wc_charset);
 

Please don't do that, it will drive poor Admin's insane trying to figure out why the settings in your precious php.ini don't seem to work. (Especially enabling display_errors inside the code somewhere is just a no-go, and who knows what the software does if i forbid ini_set in my php setup)

Having a full page of require's, that point to 5 line classes is bad. Having everything just in one single file is not the way to go either, and having 50 lines of Documentation for an absolutely obvious function that is exactly one(!) single line of code, against having not a single line of comments for a 50+ line function is just silly. Either document properly, or don''t document at all!

Writing entire functions in a single line that even grows out of my editor window (which is 200 chars wide) is bad. Having 10+ functions of those beneath each other makes me sad.

After opening another php file, and seeing this:


foreach($_GET as $key => $value){if(in_array($key,$export_vars)){$$key = $value;}}
foreach($_POST as $key => $value){if(in_array($key,$export_vars)){$$key = $value;}}
 

i immediatly quit my editor and rm -rf the thing. You know Spaces don't cost extra money to use in Sourcecode.


/*
    Yes, most of the formatting used in this file is HORRIBLY BAD STYLE. However,
    most of the action happens outside of this file, and I really wanted the code
    to look as small as what it does. Basically. Oh, I just suck. :)
*/

 

At least they're honest with that statement. AND OH BOY IS HE RIGHT! (rm -rf)



Wow:
The ErfurtWiki engine is fully contained in one script file, but almost 200 feature enriching plugins and extensions modules are available.

Guys, THAT IS NOTHING TO BE PROUD OF! 130KB of Code! That's a whopping 4000 Lines! Aaargh!

I've got a headache now, and i still don't have anything that i can use.

It''s not all bad though. Take a look at the source of coWiki. It is nicely structured, has _usefull_ comments in the code, and is beatifully indented.

I think i will just use the Markdown class, and start writing code around that.



Template Engines

Why people still avoid Template engines in their projects is a absolute mistery to me. I download some random PHP script/app, put it onto my webserver at home, and take a look at the source.

If i see a single print/echo line spewing out html, i'm always immediatly tempted to rm -rf the thing. I have no problem customizing a PHP script, but people need to keep content + code apart from each other. It is so much nicer to fire up your random HTML editor with the template and customize it, without worrying to break some random line of php code.



rssReader: New Version

Released version 0.0.4 of rssReader, which adds support for opml (Thanks to Fabian), and a rss output template. (Just call rssReader.php?template=rss and you will get a rss feed out of it.) Have fun.



rssReader 0.0.3

Uploaded a new version of rssReader, wich fixes some trouble with a couple of feeds. I Have not yet had any major problems with the tool. Grab it in the code section of my page.