The importance of peers at the work place +

tl;dr: What?

I cannot stress how important it is to have someone to share your accomplishments / suffering with at work. Often overlooked, this is one of the most important feats to look for in your future employer’s offering. Make no mistake about it.

Case in point

I was having a really hard time today with some of Croportal’s partner feeds. Two unrelated issues came up, both having something to do with parsing Atom feeds using Zend_Feed:

  • A certain site published it’s feed in Atom format using non-absolute URIs within the <content> element. That’s not a problem per se, since the spec allows it (and defines how to deal with that). However, Zend_Feed has no knowledge of what’s going on (and that’s probably ok, since it’s a general purpose lib). However, publishers place whatever HTML content they want within their <content> element and expect the same behaviour from aggregators as they get from browsers when they open their feed URLs in them (ie. Firefox). This means you have to do a shitload of “magic” on your end. And that shit ain’t trivial.
  • Another site published their feed using Atom as well, except they decided to use the (rarely used) <content type="xhtml"> feature of the Atom protocol. Which is all fine and dandy untill you actually have to pull the content and display it on your end (being an aggregator). The spec is somewhat vague and yet pretty specific at the same time. Except it doesn’t cover what to do in cases such as this:
    ...
    <content type="xhtml">
       <div xmlns="http://www.w3.org/1999/xhtml">
          <p>Paragraph with an <img src="whatever.jpg" /><![CDATA[This is <strong>XHTML</strong> content.]]></p>
       </div>
    </content>
    ...

    Which kind of sucks, since you’re on your own now. I have an actual publisher with such a feed. And the feed validates. What does one do? Well, you start introducing crap code into your codebase. Shit such as this, to handle the case described above:

    ...
    if ($item->content && $item->content['type'] && $item->content['type'] == 'xhtml') {
        $item_simple = simplexml_import_dom($item->content->getDOM());
        $item_summary = $item_simple->asXML();
        // end-tag is fixed in form so it's easy to replace
        $item_summary = str_replace('</content>', '', $item_summary);
        // remove start-tag, possibly including attributes and white space
        $item_summary = preg_replace('/<content[^>]*>/i', '', $item_summary);
    }
    ...

    This sucks on so many levels it’s not even funny. Zend_Feed’s $item->content() method returns only the raw text, but my use case requires the surrounding elements as well (images etc). So, I hack my way around all this using SimpleXML which allows me to (somewhat) easily dump the structure into a somewhat acceptable form of HTML.

    Of course, later on you have to call strip_tags() on content such as this (to display it safely on your end), but — surprise, surprise — you run into another issue: if you have a <![CDATA[ string anywhere within a larger string that you call strip_tags() on, you’re gonna get an empty string back as a result. How’s that for fun, eh? This is where you start pulling your hair out and thinking male prostitution ain’t such a bad line of work after all.

Folks, I’m not making this shit up. This is real world PHP on a (relatively) large scale project.

End result

Several hours and hundreds of lines of code later — both issues are fixed. And everything works flawlessly. Except no one but me is aware of the fact.

No one in the entire company hasn’t got a fucking clue about what has transpired today. Or why shit like that matters. Or how much future money it has saved. Or that I’ve written an URL parser library that can be used generically for any possible scenario that deals with relative/absolute URL conversion, URL joining, URL parsing etc.

Worst of all, no one could hear (and understand) my cries about how horribly broken Zend_Feed, parse_url(), strip_tags(), DOM etc. are.

5 Responses to “The importance of peers at the work place”

  1. I don’t know if it solves the issues that where bugging you, but since ZF 1.9 there is a new component called Zend_Feed_Reader.

  2. Thx, will check it out later today or tomorrow.

  3. I hear you bro. Let me sing that for you:
    http://www.youtube.com/watch?v=Cdk1gwWH-Cg&feature=player_embedded

    :)

  4. Stop whining, you pussy :)
    I have a clue. Tiny clue.

  5. and thats why today ur in a whole day meeting.. weeeee.