> Great idea -- that was on my list of things to get done soon.
>
> However, what do you think about a design that's integrates the Plugin
> class and the URL shortener class?
>
> The actual URL shortening code would look something like:
>
>     $shorturl = $longurl;
>
>     Event::handle('ShortenUrl', array($longurl, &$shorturl,
> $user->urlshorteningservice));
>
>     return $shorturl;
>
> The code for listing services would look something like...
>
>     $services = array();
>
>     Event::handle('EnumerateUrlShorteners', array(&$services));
>
>     foreach ($services as $service) {
>         // add to drop-down menu
>     }
>
> Then plugins just look like this:
>
>      class MyShortenerPlugin extends Plugin {
>
>          function onShortenUrl($longurl, &$shorturl, $service) {
>                 if (is_null($service)) { // unconfigured or anonymous user
>                   $service = common_config('site', 'defaultshortener');
>                 }
>               if ($service == 'myshortener') {
>                      $shorturl = $this->someshorteningmethod($longurl);
>                      return false; // Don't continue processing!
>                 }
>                 return true;
>          }
>
>          function onEnumerateUrlShorteners(&$services) {
>              $services[] = array('myshortener', true, _('My Shortener
> Service'));
>              return true;
>          }
>     }
>
> I think it would lighten things up a lot. Having a second level of
> registration (besides the regular hook registration) seems like overkill.
>
> -Evan

I considered a design like that, but I really wanted the shortener
implementation (ex lilurl) separated from the the specific shortener
service (ur1.ca). I'd really like a syntax like this when the plugin
configuration stuff has been decided:

addPlugin('SimpleUrl','is.gd',
            array(),
            array('SimpleUrl',array('http://is.gd/api.php?longurl='));
addPlugin('SimpleUrl','snipr.com',
            array(),
            
array('SimpleUrl',array('http://snipr.com/site/snip?r=simple&link='));
addPlugin('SimpleUrl','metamark.net',
            array(),
            
array('SimpleUrl',array('http://metamark.net/api/rest/simple?long_url='));

So that adding a new URL shortener service (as long as it's API is
support, such as SimpleUrl, TightUrl, LilUrl, etc), is just a
configuration modification that requires code modification.

I couldn't figure out how to do that using Events and Handlers.

~Craig

_______________________________________________
Laconica-dev mailing list
[email protected]
http://mail.laconi.ca/mailman/listinfo/laconica-dev

Reply via email to