Pligg CMS Forums


Go Back   Pligg CMS Forum > Pligg Help > General Help



IRC notification from Pligg


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2007, 07:44 PM
liotier's Avatar
Casual Pligger
Pligg Version: Slightly modified 9.8.2
Pligg Template: Slightly modified Yget from 9.8.2
 
Join Date: Jul 2007
Location: Paris La Défense, France
Posts: 71
Lightbulb IRC notification from Pligg

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...
Reply With Quote
Sponsor
  #2 (permalink)  
Old 07-23-2007, 11:17 AM
New Pligger
 
Join Date: May 2007
Posts: 23
Send a message via Yahoo to blast
Well, I know that the guys from meneame.net made a few stufs about this :) I'm searching the link right now ;) If I find it, i'll write it ;)
Reply With Quote
  #3 (permalink)  
Old 07-25-2007, 04:57 PM
liotier's Avatar
Casual Pligger
Pligg Version: Slightly modified 9.8.2
Pligg Template: Slightly modified Yget from 9.8.2
 
Join Date: Jul 2007
Location: Paris La Défense, France
Posts: 71
New milestone : I managed to modify submit.php to have it notify a channel when a story is posted. Next step : adding author, title and Pligg URL in the notification. Then I'll post my prototype and a diff.

Jean-Marc Liotier
Reply With Quote
  #4 (permalink)  
Old 07-25-2007, 07:47 PM
liotier's Avatar
Casual Pligger
Pligg Version: Slightly modified 9.8.2
Pligg Template: Slightly modified Yget from 9.8.2
 
Join Date: Jul 2007
Location: Paris La Défense, France
Posts: 71
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 

Jean-Marc Liotier
Reply With Quote
  #5 (permalink)  
Old 07-26-2007, 05:34 AM
liotier's Avatar
Casual Pligger
Pligg Version: Slightly modified 9.8.2
Pligg Template: Slightly modified Yget from 9.8.2
 
Join Date: Jul 2007
Location: Paris La Défense, France
Posts: 71
I forgot to post the link to the submit.php attachment... Here it is.
Attached Files
File Type: php submit.php (12.0 KB, 88 views)

Jean-Marc Liotier
Reply With Quote
  #6 (permalink)  
Old 07-26-2007, 06:00 AM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 2,157
Great work m8, will try when I find time.. If a live demo is available or if you use it at your site, feel free to share the link that we all can have a sneak peak of it. Looking forward for more contributions from you for the benefit of the Pligg and OSS world.
Reply With Quote
  #7 (permalink)  
Old 08-01-2007, 10:44 AM
warefare's Avatar
Casual Pligger
 
Join Date: Mar 2007
Posts: 39
Sounds really good, I will try it too.

Last edited by warefare; 08-01-2007 at 11:38 AM.
Reply With Quote
  #8 (permalink)  
Old 08-14-2007, 09:55 AM
New Pligger
 
Join Date: Aug 2007
Posts: 9
Nice work!

Does it work with the RSS importing module too?

That would just be perfect.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pligg integration with SMF Forum autoinc Modification Tutorials 64 05-19-2008 02:22 AM

Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Use the coupon code PLIGG at Dreamhost.com to receive a discount of up to $84.00 Make a donation to support Pligg CMS development