Cutting the Stream: Counting and stripping tags cont.

As I continue to work on truncating long activity stream posts, there aremore and more steps that need to be taken to clean up the code.

I don’t have time to fully explain everything I have done lately, so this iscurrently more a bunch of useful links and the current function and classesto point in the right direction.

First off, with some activities coming from the forum, they have BBCode inthem which is not parsed by the activity stream. Updating thestrip_html_tags() function to remove BBCode tags too is easy:

Argh! Knackernuts! While I get on to Posterous about the continued issue with object and embed in markdown, get the code from

The function now also replaces inserts html line breaks before newline characters with the php nl2br() function after all tags have been stripped. The function name is perhaps becoming inaccurate, but the function is doing what I demand of it!

I also had some issues getting html_count class working in production, where it had been fine in testing.…

The issues here was that html_count is designed to parse the contents of an external file, not a string. Now, I can call an individual activity as an external file, but this requires post data to be sent.Wez Furlong’s do_post_request function set me on the track to solving that one:

However, it seemed a little (understatement of the year) inefficient to be generating an external file and parsing that for each activity in a stream (which can get very long when you ‘show older posts’ a few times), particularly when all that data being parsed is already in my hands at that point, so html_count needed tweaking to be able to handle strings and files – there are now two classes: string_html_tag_count and file_html_tag_count. These could easily be wrapped into one class with a switch to select which variant you wished to use. I just haven’t spent the extra few minutes doing that, as this is all taking far too long as is!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *