Craig Andrews wrote:
I just committed a change to 0.9.x which pluginizes the URL Shorteners:
http://gitorious.org/laconica/mainline/commit/beae3db41375879e725af053edf8041bbd76ac8c
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
--
Evan Prodromou
CEO, Control Yourself, Inc.
[email protected] - http://identi.ca/evan - +1-514-554-3826
_______________________________________________
Laconica-dev mailing list
[email protected]
http://mail.laconi.ca/mailman/listinfo/laconica-dev