IMP Report: PHP Tag Engine Integration

The Independent Media Project has received a large boost forward in the shape of Alex King’s PHP Tag Engine, which he developed for his Tasks Pro application and then spun out into an open source project. The package is extremely well designed and intuitively coded. The biggest problem we actually had was getting a few of the configuration parameters set up correctly, and we’re working with Alex to make the documentation a bit more specific in the areas that we found surprises.

Once the configuration was setup correctly things were smooth as glass. It only took about 20 minutes to modify our query system to support tag retrieval once we had the basics up and running.

I am absolutely certain that it would have taken us at least two weeks to add this functionality from scratch: using PTE took us about 18 hours from start to finish, and a good chunk of that was spent working on other projects or sleeping :).

Lessons Learned

  1. $pte->base_url
    PTE’s base url is set in the pte config file (phptagengine.config.inc.php) and is the full outside world path to your pte install directory:

    http://yourserver.com/where/you/have/pte/
  2. $pte->ajax_handler
    This was so trivial I had trouble believing it could be so simple. Consequently I lost some time trying to make things harder.
    The ajax handler is just a small file you need to create on your site that PTE will use to handle incoming tag read/write/edits from your remote users. It can literally be as simple as

    <?php
    <!-- Your own security/authentication mechanism goes here! -->
    require_once('phptagengine-1.0/phptagengine.inc.php');
    ?>

    It is critical to note that you really want some sort of security block proceeding the ‘require_once’ statement. You don’t technically need it to run PTE, but you need it in a practical sense because you’ll be opening yourself to a world of pain if you leave your front door open to the rest of the world.
  3. Embedded tags in your PHP pages
    If you want to use tags in your document you need to include the following PHP block in the HEAD portion of you web page:
    <?php
    require_once('common/phptagengine-1.0/phptagengine.inc.php');
    $pte->html_head();
    ?>

    In our particular case, we are presenting a view that will allow an artist to edit the metadata (production notes, pricing plan, etc), for her song. We also want to give her the ability to apply tags to the song in question. Each song has a unique id, which is represented in the page by the variable $songid. We can simply add the PTE tagging control by in-lining the following block of PHP where we wish to have the tag control appear:
    <?php html_item_tags($songid); ?>

  4. $pte->tag_browse_url (Handling tag searches)
    This configuration setting is what PTE uses to actually search through your database when a user clicks on a tag link. You get to define what page will be called and can supply any custom parameters you require. The tag-related parameters are, uh, parameterized in your specification so that you can get a feel for the basic shape of the post you will receive:
    $pte->tag_browse_url = 'http://imp.fm/browse.php?view=tags&tagName=<tag>&tagType=<type>

    The last two parameters, tagName and tagType, are specific to PTE. You can change the names to whatever you like: you are the person that will be receiving them in your php code.
    In this case we modified browse.php to look for $_GET parameters named tagName and tagType and used their values to do a tag related query.Once we’ve located the tagName parameter we can do a lookup and find all of the songs tagged with the same name.
    PTE uses two tables for tracking tags; one for tracking tag names and another for tracking items (songs, in our case) to a specific tag. We track all of our songs in a table called music, so we can find every song with the supplied tag by using the following SQL string:

    select music.*, item_tags.tag,item_tags.item, item_tag_names.id from music, item_tags,item_tag_names where music.songid=item_tags.item and item_tags.tag=item_tag_names.id and item_tag_names.name=’$tagName’

    The elements in bold are specific to our own architecture. One could easily use the string above with a different table name and corresponding id name within that table to use this for a different architecture

Tag Types
Another thing I’m happy about with PTE is its built-in concept of a tag type. This dovetails nicely with our plans, because we intend to support a few different flavors of tagging on our system.

Clearly artists can assign whatever tags they feel are appropriate to their art. But we’d also like people that buy or download their art to have the ability to tag the work as well. We’re currently calling this ‘reminds-me-of’ tagging.

We’re doing this because we’ve noticed that people will cite their influences but it is frequently hard to tell that, say, Sonic Youth, was actually influenced by The Shaggs. Including this capability will provide users with a capability to search for art based on what 3rd parties have compared it to instead of what the artist felt was an appropriate and potentially highly subjective homage.

More to come.

-Daniel

One Response to “IMP Report: PHP Tag Engine Integration”

  1. […] Brain Murmurs ยป IMP Report: PHP Tag Engine Integration Alex’s PHP tag engine out in the wild (tags: PHP tag engine AlexKing) […]

Leave a Reply

You must be logged in to post a comment.