View Single Post
  #4 (permalink)  
Old 07-25-2007, 08:47 PM
liotier's Avatar
liotier liotier is offline
Casual Pligger
 
Join Date: Jul 2007
Location: Paris La Défense, France
Posts: 70
Done ! Please behold IRC notification by Pligg !

This is a prototype : it works fine for me but you need to overwrite a file from the standard Pligg and edit it with your parameters, and it probably ignores any convention used by those who are familiar with working on Pligg. To reach release quality this functionality should probably be architectured as a Pligg plugin.

To use it, you need to install Net_SmartIRC which is available in Debian as php-net-smartirc. Make sure that the path of that library as declared in my submit.php is correct.

Then you need to edit my submit.php to set connect parameters, login parameters, and the channel. Make a backup of your original submit.php and replace it with mine. That is all !

Please find attached the complete file.

Please tell me if you like it - I need some feedback !

Here is a diff of my submit.php against submit.php from Pligg 9.7 :

PHP Code:
51a52,96
// --------------------------------------------------------
// Begin IRC notification preliminary declarations
// --------------------------------------------------------
> include_once('/usr/share/php/Net/SmartIRC.php');
// FIXME The notification channel should of course be set by the user.
$IRC_notification_channel '#jimtest';
> class 
myIRCnotifier
> {
>     function 
IRC_notification(&$irc)
>     {
>         global 
$IRC_notify_once_id;
>         global 
$IRC_notification_channel;
>         global 
$db;
>         global 
$URLMethod;
>         
$linkres=new Link;
>         
$linkres->id=$link_id strip_tags($_POST['id']);
>         
$linkres->read();
>         
$IRC_notification_pligg_username $db->get_var("SELECT user_login FROM " table_users " WHERE user_id = $linkres->author");
>         if (
$URLMethod == 1) {
>             
$IRC_link_url=my_base_url.my_pligg_base."/story.php?id=".$link_id;
>             }
>         if (
$URLMethod == 2) {
>             
$IRC_link_url=my_base_url.my_pligg_base."/story/".$link_id;
>             }
>         
$IRC_notification_message $IRC_notification_pligg_username' posted "' .$linkres->title'" at ' .$IRC_link_url;
>         
$irc->message(SMARTIRC_TYPE_CHANNEL$IRC_notification_channel$IRC_notification_message);
>         
$irc->unregisterTimeid($IRC_notify_once_id);
>     }

>     function 
IRC_termination(&$irc)
>     {
>         global 
$IRC_termination_id;
>         
$irc->quit();
>         
$irc->unregisterTimeid($IRC_termination_id);
>     }
> }
$IRCnotifier = &new myIRCnotifier();
$irc = &new Net_SmartIRC();
$irc->setUseSockets(TRUE);
$IRC_notify_once_id $irc->registerTimehandler(0$IRCnotifier'IRC_notification');
$IRC_termination_id $irc->registerTimehandler(1$IRCnotifier'IRC_termination');
// --------------------------------------------------------
// End IRC notification preliminary declarations
// --------------------------------------------------------

66a112,119
>       // Begin IRC notification
>       // FIXME The connect and login parameters should of course be set by the user.
>       $irc->connect('irc.eu.freenode.net'6667);
>       
$irc->login('PliggNotifier''Pligg PHP IRC notification service''0''PliggNotifier');
>       
$irc->join(array($IRC_notification_channel));
>       
$irc->listen();
>       
$irc->disconnect();
>       
// End IRC notification 
Reply With Quote