These changes add the ability of having an ignorelist in pfc
There are 4 files to put into it for the commands and one file to have minor changes for not delivering msgs from ignored sources.
I built it from the /ban /unban /banlist command-classes.
new file: ./commands/ignore.class.php
- Code: Select all
- <?php
 require_once(dirname(__FILE__)."/../pfccommand.class.php");
 class pfcCommand_ignore extends pfcCommand
 {
 var $usage = "/ignore {nickname}";
 
 function run(&$xml_reponse, $p)
 {
 $clientid = $p["clientid"];
 $param = $p["param"];
 $params = $p["params"];
 $sender = $p["sender"];
 $recipient = $p["recipient"];
 $recipientid = $p["recipientid"];
 
 $c =& pfcGlobalConfig::Instance();
 $u =& pfcUserConfig::Instance();
 $nick = isset($params[0]) ? $params[0] : '';
 $channame = $u->channels[$recipientid]["name"];
 
 if ($nick == '')
 {
 // error
 $cmdp = $p;
 $cmdp["param"] = _pfc("Missing parameter");
 $cmdp["param"] .= " (".$this->usage.")";
 $cmd =& pfcCommand::Factory("error");
 $cmd->run($xml_reponse, $cmdp);
 return;
 }
 $ct =& pfcContainer::Instance();
 $nickidtoignore = $ct->getNickId($nick);
 
 
 // update the ignorelist
 $ignorelist = $ct->getUserMeta($sender, 'ignorelist_nickid');
 if ($ignorelist == NULL)
 $ignorelist = array();
 else
 $ignorelist = unserialize($ignorelist);
 $ignorelist[] = $nickidtoignore; // append the nickid to the ignorelist
 $ct->setUserMeta($sender, 'ignorelist_nickid', serialize($ignorelist));
 }
 }
 ?>
new file: ./commands/ignorelist.class.php
- Code: Select all
- <?php
 require_once(dirname(__FILE__)."/../pfccommand.class.php");
 class pfcCommand_ignorelist extends pfcCommand
 {
 var $desc = "This command list the ignored users";
 
 function run(&$xml_reponse, $p)
 {
 $c =& pfcGlobalConfig::Instance();
 $u =& pfcUserConfig::Instance();
 
 $ct =& pfcContainer::Instance();
 $ignorelist = $ct->getUserMeta($p["sender"], 'ignorelist_nickid');
 
 if ($ignorelist == NULL) $ignorelist = array(); else $ignorelist = unserialize($ignorelist);
 $msg = "";
 // $msg .= "<p>"._pfc("The ignored user list is:")."</p>";
 $msg .= "<p>The ignored user list is:</p>";
 if (count($ignorelist)>0)
 {
 $msg .= "<ul>";
 foreach($ignorelist as $b)
 {
 $n = $ct->getNickname($b);
 $msg .= "<li style="margin-left:50px">".$n."</li>";
 }
 $msg .= "</ul>";
 }
 else
 {
 $msg .= "<p>("._pfc("Empty").")</p>";
 }
 /*
 $msg .= "<p>"._pfc("'/unignore {nickname}' will remove the ignoring of {nickname}")."</p>";
 $msg .= "<p>"._pfc("'/unignore all' will remove all ignoring")."</p>";
 */
 $msg .= "<p>'/unignore {nickname}' will remove the ignoring of {nickname}</p>";
 $msg .= "<p>'/unignoreall' will remove all ignoring</p>";
 $xml_reponse->script("pfc.handleResponse('banlist', 'ok', '".addslashes($msg)."');");
 }
 }
 ?>
new file: ./commands/unignore.class.php
- Code: Select all
- <?php
 require_once(dirname(__FILE__)."/../pfccommand.class.php");
 class pfcCommand_unignore extends pfcCommand
 {
 var $usage = "/unignore {nickname}";
 
 function run(&$xml_reponse, $p)
 {
 $clientid = $p["clientid"];
 $param = $p["param"];
 $params = $p["params"];
 $sender = $p["sender"];
 $recipient = $p["recipient"];
 $recipientid = $p["recipientid"];
 
 $c =& pfcGlobalConfig::Instance();
 $u =& pfcUserConfig::Instance();
 $ct =& pfcContainer::Instance();
 $nick = isset($params[0]) ? $params[0] : '';
 $nickid = $ct->getNickId($nick);
 
 if ($nick == "")
 {
 // error
 $cmdp = $p;
 $cmdp["param"] = _pfc("Missing parameter");
 $cmdp["param"] .= " (".$this->usage.")";
 $cmd =& pfcCommand::Factory("error");
 $cmd->run($xml_reponse, $cmdp);
 return;
 }
 
 $updated = false;
 // $msg = "<p>"._pfc("Nobody has been unignored")."</p>";
 $msg = "<p>Nobody has been unignored</p>";
 
 // update the ignorelist
 $ignorelist = $ct->getUserMeta($sender, 'ignorelist_nickid');
 if ($ignorelist == NULL)
 $ignorelist = array();
 else
 $ignorelist = unserialize($ignorelist);
 $nb = count($ignorelist);
 if (in_array($nickid, $ignorelist))
 {
 $ignorelist = array_diff($ignorelist, array($nickid));
 $ct->setUserMeta($sender, 'ignorelist_nickid', serialize($ignorelist));
 $updated = true;
 // $msg = "<p>"._pfc("%s has been unignored", $nick)."</p>";
 $msg = "<p>".$nick." has been unignored</p>";
 }
 
 if ($updated)
 $xml_reponse->script("pfc.handleResponse('unban', 'ok', '".$msg."');");
 else
 $xml_reponse->script("pfc.handleResponse('unban', 'ko', '".$msg."');");
 }
 }
 ?>
new file: ./commands/unignoreall.class.php
- Code: Select all
- <?php
 require_once(dirname(__FILE__)."/../pfccommand.class.php");
 class pfcCommand_unignoreall extends pfcCommand
 {
 var $usage = "/unignoreall";
 
 function run(&$xml_reponse, $p)
 {
 $clientid = $p["clientid"];
 $param = $p["param"];
 $params = $p["params"];
 $sender = $p["sender"];
 $recipient = $p["recipient"];
 $recipientid = $p["recipientid"];
 
 $c =& pfcGlobalConfig::Instance();
 $u =& pfcUserConfig::Instance();
 $ct =& pfcContainer::Instance();
 // update the ignorelist
 $ignorelist = array();
 $ct->setUserMeta($sender, 'ignorelist_nickid', serialize($ignorelist));
 // $msg = "<p>"._pfc("All users have been unignored")."</p>";
 $msg = "<p>All users have been unignored</p>";
 
 $xml_reponse->script("pfc.handleResponse('unban', 'ok', '".$msg."');");
 }
 }
 ?>
modified file: ./commands/getnewmsg.class.php
- Code: Select all
- <?php
 require_once(dirname(__FILE__)."/../pfccommand.class.php");
 class pfcCommand_getnewmsg extends pfcCommand
 {
 function run(&$xml_reponse, $p)
 {
 
 $clientid = $p["clientid"];
 $param = $p["param"];
 $sender = $p["sender"];
 $recipient = $p["recipient"];
 $recipientid = $p["recipientid"];
 
 $c =& pfcGlobalConfig::Instance();
 // do nothing if the recipient is not defined
 if ($recipient == "") return;
 
 // check this methode is not being called
 if( isset($_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid]) )
 {
 // kill the lock if it has been created more than 10 seconds ago
 $last_10sec = time()-10;
 $last_lock = $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid];
 if ($last_lock < $last_10sec) $_SESSION["pfc_lock_".$c->getId()."_".$clientid] = 0;
 if ( $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] != 0 ) exit;
 }
 // create a new lock
 $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] = time();
 // read the last from_id value
 $container =& pfcContainer::Instance();
 
 // added for ignoring
 $ignorelist = $container->getUserMeta($sender, 'ignorelist_nickid');
 $ignorelist = ($ignorelist == NULL) ? array() : unserialize($ignorelist);
 
 $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$recipientid;
 $from_id = 0;
 if (isset($_SESSION[$from_id_sid]))
 $from_id = $_SESSION[$from_id_sid];
 else
 {
 $from_id = $container->getLastId($recipient)-$c->max_msg;
 if ($from_id < 0) $from_id = 0;
 }
 // check if this is the first time you get messages
 $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$recipientid;
 $oldmsg = false;
 if (isset($_SESSION[$oldmsg_sid]))
 {
 unset($_SESSION[$oldmsg_sid]);
 $oldmsg = true;
 }
 
 $new_msg = $container->read($recipient, $from_id);
 $new_from_id = $new_msg["new_from_id"];
 $data = $new_msg["data"];
 
 // transform new message in html format
 $js = array();
 $data_sent = false;
 foreach ($data as $d)
 {
 $m_id = $d["id"];
 $m_date = $d["date"];
 $m_time = $d["time"];
 $m_sender = $d["sender"];
 $m_recipientid = $recipientid;
 $m_cmd = $d["cmd"];
 $m_param = phpFreeChat::PostFilterMsg($d["param"]);
 
 //added for ignoring
 $ignore = false;
 $msg = "";
 if (count($ignorelist)>0)
 {
 foreach($ignorelist as $b)
 {
 $n = $container->getNickname($b);
 if ($n == $m_sender) $ignore = true;
 }
 }
 
 if( !$ignore )
 {
 $js[] = array($m_id,
 $m_date,
 $m_time,
 $m_sender,
 $m_recipientid,
 $m_cmd,
 $m_param,
 date("d/m/Y") == $m_date ? 1 : 0,
 $oldmsg ? 1 : 0);
 $data_sent = true;
 }
 }
 if (count($js) != 0)
 {
 require_once dirname(__FILE__).'/../pfcjson.class.php';
 $json = new pfcJSON();
 $js = $json->encode($js);
 $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', (".$js."));");
 }
 if ($data_sent)
 {
 // store the new msg id
 $_SESSION[$from_id_sid] = $new_from_id;
 }
 
 // remove the lock
 $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] = 0;
 
 }
 }
 ?>
Localisation is not implemented. Though the _pfc("foo") commands are in, they are as comment for not getting into trouble with missing loca-strings.
P.S.: works4me with 1.09beta, rev.971


