A few old friends and I often hang together on our usual IRC channel, and while discussing we like to share links. I took that as a pretext to deploy a small Pligg and play with it. Since I wanted to use it along with the IRC channel I thought it might be a good idea to make Pligg capable of notifying an IRC channel of an upcoming story.
Rumaging through PHP libraries capable of speaking IRC I ended up using
Net_SmartIRC which is available in Debian as
php-net-smartirc.
The examples packaged with the class are quite good at teaching its use so I soon wrote a small proof-of-concept of notifying an IRC channel from PHP - please note that I rarely code PHP, I am an hobbyist sysadmin with rather basic programming skills in general. The following code is capable of logging on, sending a message and exiting :
PHP Code:
<?php
include_once('/usr/share/php/Net/SmartIRC.php');
$notification_channel = '#my_test_channel';
class mynotifier
{
function notification(&$irc)
{
global $notify_once_id;
global $notification_channel;
$irc->message(SMARTIRC_TYPE_CHANNEL, $notification_channel, 'Please remain calm, this is a test.');
$irc->unregisterTimeid($notify_once_id);
}
function termination(&$irc)
{
global $termination_id;
$irc->quit();
$irc->unregisterTimeid($termination_id);
}
}
$notifier = &new mynotifier();
$irc = &new Net_SmartIRC();
//$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$notify_once_id = $irc->registerTimehandler(0, $notifier, 'notification');
$termination_id = $irc->registerTimehandler(1, $notifier, 'termination');
$irc->connect('irc.eu.freenode.net', 6667);
$irc->login('TestNotifier', 'PHP IRC notification service', '0', 'TestNotifier');
$irc->join(array($notification_channel));
$irc->listen();
$irc->disconnect();
?>
I guess my next step will be splicing it into Pligg for another proof of concept. I tried wedging my code into submit.php but the best I obtained was the behavior of the unpatched submit.php... For now I feel like my ambition has overtaken my compentence...
But I'll keep trying for a while. From skimming the forums it sounds like Pligg has a concept of hooks but I can't quite figure it out. Could any of you tell me more about this and where I can splice my code to see how it works.
If I manage to get it to work I guess it will be a candidate for a plugin, but let's not get ahead of ourselves here...