• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

/ignore /ignorelist /unignore /unignoreall

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
21 posts • Page 1 of 2 • 1, 2

Postby Andreas » Tue Feb 20, 2007 4:20 pm

I'd like to contribute a little "hack":

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
Last edited by Andreas on Tue Feb 20, 2007 4:22 pm, edited 1 time in total.
Andreas
New member
 
Posts: 7
Joined: Sun Feb 18, 2007 10:01 am
Location: Germany
  • Website
Top

Postby dannic » Tue Feb 20, 2007 5:17 pm

Great Contribution
dannic
Member
 
Posts: 18
Joined: Fri Jan 05, 2007 1:12 am
Top

Postby phpfreechat » Thu Mar 08, 2007 11:53 am

Thank you Andreas for your contribution, I will have a look to your code when the 1.0-final will be released. Then I will certainly integrate your code in the official pfc source code.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby eric » Sun Mar 18, 2007 9:24 am

Works nicely on latest version - please polish up and include in the source!

Thank you Andreas
eric
New member
 
Posts: 6
Joined: Thu Jul 06, 2006 8:07 am
Top

Postby lackattack » Thu Apr 05, 2007 6:05 am

Hello Andreas,

I am trying your code and I like it. Thank you!

It would be even nicer if it would put a strikethrough on the nick or changed the icon of people who are ignored.
lackattack
New member
 
Posts: 8
Joined: Thu Apr 05, 2007 5:52 am
Location: Montreal, Quebec
  • Website
Top

Postby itsjareds » Sun Nov 25, 2007 9:48 pm

Very well done, only thing is it messes with my timestamp. Now it says "null null".
Later,
Jared

My site: ItsJareds.co.nr
itsjareds
Member
 
Posts: 13
Joined: Sat Nov 24, 2007 12:13 am
Location: North Carolina, USA
  • Website
Top

Postby MaDc0w » Tue Aug 12, 2008 8:12 pm

itsjareds wrote:Very well done, only thing is it messes with my timestamp. Now it says "null null".

Change in ./commands/getnewmsg.class.php

Code: Select all
        $m_date        = $d["date"];
        $m_time        = $d["time"];

to

Code: Select all
        $m_date        = date($c->date_format, $d["timestamp"] + $c->time_offset);
        $m_time        = date($c->time_format, $d["timestamp"] + $c->time_offset);
MaDc0w
MaDc0w
Member
 
Posts: 20
Joined: Tue Aug 12, 2008 10:32 am
  • Website
Top

Postby bjhanifin » Wed Apr 29, 2009 3:04 pm

This is exactly what I was looking for. I was about to try to write this myself. Thank you for sharing.

FYI, users with spaces in their nicks require you to quote their nick ( e.g. /ignore "Mr. Tester" ).

Update: It was not working, but I found my mistake. I thought getnewmsg.class.php was a new file like the others. In fact, I named it incorrectly (getnewmessage.class.php). I pasted the contents into the existing class file and /ignore works now.
Last edited by bjhanifin on Wed Apr 29, 2009 4:17 pm, edited 1 time in total.
bjhanifin
New member
 
Posts: 9
Joined: Wed Apr 29, 2009 2:57 pm
Location: San Diego, CA
  • Website
Top

Postby bjhanifin » Wed Apr 29, 2009 4:43 pm

I just discovered /ignorelist is unique to the issuing user. :-/ Darn, I need a global /devoicelist.

If our site ends up using PhpFreeChat, I will probably try to figure out how to combine /ignore and /ban into /devoice commands.
bjhanifin
New member
 
Posts: 9
Joined: Wed Apr 29, 2009 2:57 pm
Location: San Diego, CA
  • Website
Top

Postby Kelly » Thu May 14, 2009 12:33 pm

I tried adding this modification to my chat, but the result was that my chat disappeared/wouldn't display, so I restored to the original files.

This behavior often suggests a syntax error somewhere, but I wasn't able to find any. I'm wondering if there have been changes in the core code since this modification was published that make the above coding obsolete?

Kerphi, you mentioned that you'd be adding this functionality to the final 1.0 version. Any news on that front? I'm currently using 1.2.

I'm open to any suggestions that anyone who is successfully running this mod with 1.2 can provide.

Thanks :)
Kelly
Member
 
Posts: 20
Joined: Thu May 07, 2009 4:59 am
Top

Postby hazefm » Thu Aug 20, 2009 12:19 am

Updated getnewmsg.class.php:
works with 1.2 06-30-2008

Code: Select all
<?php
/**
 * getnewmsg.class.php
 *
 * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

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);
    // end
    $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 - 1;
      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        = date($c->date_format, $d["timestamp"] + $c->time_offset);
      $m_time        = date($c->time_format, $d["timestamp"] + $c->time_offset);
      $m_sender      = $d["sender"];
      $m_recipientid = $recipientid;
      $m_cmd         = $d["cmd"];
      $m_param       = phpFreeChat::PostFilterMsg(pfc_make_hyperlink($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($c->date_format, time() + $c->time_offset) == $m_date ? 1 : 0, // posted today ?
                    $oldmsg ? 1 : 0); // is it a new message in the current session or is it a part of the history
      $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;
   
  }
}

?>
Last edited by hazefm on Thu Aug 20, 2009 12:36 am, edited 1 time in total.
hazefm
Member
 
Posts: 13
Joined: Tue Aug 18, 2009 2:35 am
Top

Postby carlis » Sat Aug 07, 2010 7:54 pm

Does it works with version 1.3? Before installing...
carlis
New member
 
Posts: 6
Joined: Thu Jul 08, 2010 6:22 pm
Top

Postby TheSeaKing » Fri Aug 20, 2010 7:33 am

carlis wrote:Does it works with version 1.3? Before installing...

Same question. ^^;
TheSeaKing
Member
 
Posts: 21
Joined: Sat Nov 22, 2008 6:40 am
Top

Postby waiheke » Sun Oct 31, 2010 3:31 pm

me too ^^^^ asking that question
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top

Postby mvirtue » Wed Feb 09, 2011 1:37 am

I'd also like to know the answer to that ^^^^^^ one
mvirtue
New member
 
Posts: 3
Joined: Wed Feb 09, 2011 1:36 am
Top

Next

Post a reply
21 posts • Page 1 of 2 • 1, 2

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 7 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub