• 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

/away status

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

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

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

Postby joel558 » Tue Mar 06, 2007 1:43 am

Heres something I put together which allows users to use the
/away awayMessage
command.
When a user issues this command, " (Away)" appears beside their name in the nicklist and a notice is sent to chat saying they are now away and gives their awayMessage. A user can issue the /away command with no parameters to return from being away.


Outstanding issues:
-when a user times out, and returns, their away status disappears.. i think this is a result of all metadata being lost..
-there is a lag ( a few seonds) between when they're set to away and when (Away) appears beside their name.. if you look in my Away.class.php file you can see how I tried to fix it, but the issues I ran into.. maybe theres another way to do it?
-not internationalized..

Any comments, suggestions or improvements are welcomed!


Here are the necessary changes, including a couple lines before changes I made.:

/data/public/js/pfcclient.js - around line 1100, added the if metadata lines.
Code: Select all
   buildNickItem: function(nickid)
   {
      var nick = this.getUserMeta(nickid, 'nick');
      if(this.getUserMeta(nickid, 'Away') != ''){
         nick = nick+" (Away)";
      }

/src/pfccontainer.class.php - around line 579, added a rmUserMeta function
Code: Select all
function rmUserMeta($nickid, $key){
   $ret = $this->rmMeta("nickid-to-metadata", $nickid, $key);
   return $ret;
}

/src/commands/Away.class.php - create this file
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_away extends pfcCommand
{
   var $usage = "/away {away message}";

   function run(&$xml_reponse, $p)
   {
      $clientid    = $p["clientid"];
      $param       = $p["param"];
      $sender      = $p["sender"];
      $recipient   = $p["recipient"];
      $recipientid = $p["recipientid"];

      $c =& pfcGlobalConfig::Instance();
      $u =& pfcUserConfig::Instance();
      $container  =& pfcContainer::Instance();

      $awayMessage  = trim($param);

      if ($awayMessage == ""){

         //user must be away for us to bring them back..
         if($container->getUserMeta($u->nickid, 'Away') == NULL){
            $cmdp = $p;
            $cmdp["param"] = "Use (".$this->usage.") to set yourself away. Use (/away) to return.";
            $cmd =& pfcCommand::Factory("error");
            $cmd->run($xml_reponse, $cmdp);
            return;
         }else{
            // remove an away message
            $cmdp = $p;
            $cmdp["param"] = "$u->nick has returned";
            $cmdp["flag"] = 1;
            $cmd =& pfcCommand::Factory("notice");
            foreach($u->channels as $id => $chan)
            {
               $cmdp["recipient"]   = $chan["recipient"];
               $cmdp["recipientid"] = $id;
               $cmd->run($xml_reponse, $cmdp);
            }
            //send message to PMs
            foreach( $u->privmsg as $id => $pv )
            {
               $cmdp["recipient"]   = $pv["recipient"];
               $cmdp["recipientid"] = $id;
               $cmd->run($xml_reponse, $cmdp);
            }

            //remove the metadata
             $container->rmUserMeta($u->nickid, 'Away');
             $this->forceWhoisReload($u->nick);

             //force update of nicklist here
             //this doesn't work for some reason..
//             $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($u->nick)."');");
         }

      }else{
         // show an away message
         $cmdp = $p;
         $cmdp["param"] = "$u->nick is now away ($awayMessage)";
         $cmdp["flag"] = 1;
         $cmd =& pfcCommand::Factory("notice");
         //send message to channels
         foreach($u->channels as $id => $chan)
         {
            $cmdp["recipient"]   = $chan["recipient"];
            $cmdp["recipientid"] = $id;
            $cmd->run($xml_reponse, $cmdp);
         }
         //send message to PMs
         foreach( $u->privmsg as $id => $pv )
         {
            $cmdp["recipient"]   = $pv["recipient"];
            $cmdp["recipientid"] = $id;
            $cmd->run($xml_reponse, $cmdp);
         }

         //set user's Away metadata
          $container->setUserMeta($u->nickid, 'Away', $awayMessage);
          $this->forceWhoisReload($u->nick);

          //force update of nicklist here..
          //doesn't work as intended.. gives double (Away) when changing away text..
          //also changes name beside text box too.. for now we'll let it update slowly
//          $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($nickChange)." (Away)');");
      }
   }
}

?>
Last edited by joel558 on Tue Mar 06, 2007 11:17 pm, edited 1 time in total.
joel558
New member
 
Posts: 3
Joined: Mon Mar 05, 2007 2:10 am
Top

Postby Spanner » Tue Mar 06, 2007 5:36 pm

I like the idea, I miss '/away' :)
Spanner
New member
 
Posts: 4
Joined: Fri Feb 09, 2007 7:14 pm
Top

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

Thank you for this contribution
I will look at your code when the 1.0-final will be ready, then I will certainly integrate your (or a bit modified) contribution.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby seb » Fri Mar 23, 2007 9:17 pm

i copied and paste the code but it's not working. I'm using version 1.0.8 and i assume that the data/public/js/pfcclient.js means in my version /scr/client/pfcclient.js.
The file Away.class.php must be away.class.php?

I get the error that the xml response is invalid. Do you know the solution?

Thnx.

Seb.
seb
Member
 
Posts: 12
Joined: Fri Mar 23, 2007 12:24 pm
Top

Postby robi_bagoes » Wed Jun 13, 2007 9:34 am

Thanks joel. Btw to me it didn't work as it should, so i modified it a bit.
I'm using version 1.0-beta10 .
Instead of Away.class.php, i used away.class.php.
I changed both
Code: Select all
$this->forceWhoisReload($u->nick);

with
Code: Select all
$this->forceWhoisReload($u->nickid);

, activated the line
Code: Select all
$xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($u->nick)."');");

, change
Code: Select all
$xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($nickChange)." (Away)');");

with these (to handle whitespace problems)
Code: Select all
$robi_away_nick=$u->nick." (Away)";
$robi_away_nick="'".addslashes($robi_away_nick)."'";
$xml_reponse->script("pfc.handleResponse('nick', 'changed', $robi_away_nick);");

Then it went just fine.
robi_bagoes
New member
 
Posts: 3
Joined: Wed Jun 13, 2007 8:52 am
Top

Postby seb » Wed Jun 13, 2007 9:39 am

Robi,

Couldyou please give me the complete code that you used.

Thnx.

Seb.
seb
Member
 
Posts: 12
Joined: Fri Mar 23, 2007 12:24 pm
Top

Postby robi_bagoes » Wed Jun 13, 2007 11:36 am

Here u go seb. I saved it as away.class.php.
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_away extends pfcCommand
{
    var $usage = "/away {away message}";

    function run(&$xml_reponse, $p)
    {
        $clientid    = $p["clientid"];
        $param       = $p["param"];
        $sender      = $p["sender"];
        $recipient   = $p["recipient"];
        $recipientid = $p["recipientid"];

        $c =& pfcGlobalConfig::Instance();
        $u =& pfcUserConfig::Instance();
        $container  =& pfcContainer::Instance();

        $awayMessage  = trim($param);

        if ($awayMessage == ""){

            //user must be away for us to bring them back..
            if($container->getUserMeta($u->nickid, 'Away') == NULL){
                $cmdp = $p;
                $cmdp["param"] = "Use (".$this->usage.") to set yourself away. Use (/away) to return.";
                $cmd =& pfcCommand::Factory("error");
                $cmd->run($xml_reponse, $cmdp);
                return;
            }else{
                // remove an away message
                $cmdp = $p;
                $cmdp["param"] = "$u->nick has returned";
                $cmdp["flag"] = 1;
                $cmd =& pfcCommand::Factory("notice");
                foreach($u->channels as $id => $chan)
                {
                    $cmdp["recipient"]   = $chan["recipient"];
                    $cmdp["recipientid"] = $id;
                    $cmd->run($xml_reponse, $cmdp);
                }
                //send message to PMs
                foreach( $u->privmsg as $id => $pv )
                {
                    $cmdp["recipient"]   = $pv["recipient"];
                    $cmdp["recipientid"] = $id;
                    $cmd->run($xml_reponse, $cmdp);
                }

                //remove the metadata
                $container->rmUserMeta($u->nickid, 'Away');
                $this->forceWhoisReload($u->nickid);

                //force update of nicklist here
                //this doesn't work for some reason..
                $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($u->nick)."');");
            }

        }else{
            // show an away message
            $cmdp = $p;
            $cmdp["param"] = "$u->nick is now away ($awayMessage)";
            $cmdp["flag"] = 1;
            $cmd =& pfcCommand::Factory("notice");
            //send message to channels
            foreach($u->channels as $id => $chan)
            {
                $cmdp["recipient"]   = $chan["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }
            //send message to PMs
            foreach( $u->privmsg as $id => $pv )
            {
                $cmdp["recipient"]   = $pv["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }

            //set user's Away metadata
            $container->setUserMeta($u->nickid, 'Away', $awayMessage);
            $this->forceWhoisReload($u->nickid);

            //force update of nicklist here..
            //doesn't work as intended.. gives double (Away) when changing away text..
            //also changes name beside text box too.. for now we'll let it update slowly
//            $xml_reponse->script("pfc.handleResponse('nick', 'changed', '".addslashes($nickChange)." (Away)');");
       $robi_away_nick=$u->nick." (Away)";
       $robi_away_nick="'".addslashes($robi_away_nick)."'";
            $xml_reponse->script("pfc.handleResponse('nick', 'changed', $robi_away_nick);");

        }
    }
}

?>
Last edited by robi_bagoes on Wed Jun 13, 2007 11:53 am, edited 1 time in total.
robi_bagoes
New member
 
Posts: 3
Joined: Wed Jun 13, 2007 8:52 am
Top

Postby seb » Thu Jun 14, 2007 8:29 pm

Thnx, but i get the XML error again... Do know what can be the problem. i'm usin 1.0.8
seb
Member
 
Posts: 12
Joined: Fri Mar 23, 2007 12:24 pm
Top

Postby runebergen » Thu Sep 04, 2008 1:45 am

Does anyone know how to get this to work ?
runebergen
Member
 
Posts: 30
Joined: Tue Aug 12, 2008 10:00 am
Top

Postby runebergen » Mon Oct 27, 2008 7:10 pm

Works, but the nick doesnt change...

Anyone know how to fix ?
runebergen
Member
 
Posts: 30
Joined: Tue Aug 12, 2008 10:00 am
Top

Postby AJBarnesy » Thu Jan 08, 2009 3:59 am

i got it working but the (Away) next to the nickname disappears
AJBarnesy
Member
 
Posts: 11
Joined: Thu Jan 08, 2009 3:54 am
Top

Postby phpfreechat » Thu Jan 08, 2009 9:04 am

On this point also, if a developer is interested to contribute by committing this patch in the official source code. I can give write access to the subversion. If someone is interested to to it, please create a sourceforge account and contact me by email.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby xoores » Fri Aug 07, 2009 8:36 pm

Okay, I had to make some modifications to your script to make it working. With your code I had problem with usernames. Your code renamed user as $USER (away). And that "(away)" disappeared after few seconds leaving nick changed still to "$USER (away)" So when I clicked on myself, I was able to "Send private message" to myself => nonsense :)

Current status:
* no need to enter message, simple /away is enough
* there is icon indication of away status next to nick
* no nickname changes
!! I haven't figured, how this goddamn localization works. When I put my string into main.php and try to use it in that JS, I get _Message_. Don't know why - it may be problem on my side with cache or something like that.

I wrote this to fit my own requirements. If there is something you may want to change, there will be this message: // CHANGE THIS LINE IF YOU NEED TO near it, so you may use fulltext to search it...
I am using this icon: Image. Place it in {your style}/images/ folder. I had the same problem with image as with localization, so I linked to it directly...

NOTE: I have to apologize for that code - I wrote it in hurry, so it may not be very nice'n'clean :-). I also apologize for my english :)


So, here's HOWTO:


customize.js.php - add a rmUserMeta function (anywhere)
Code: Select all
function rmUserMeta($nickid, $key){
    return $this->rmMeta("nickid-to-metadata", $nickid, $key);
}

customize.js.php - this file is in theme folder
Those functions are copied from pfcclient.js and are almost untouched. I just added few lines to each.
In this file there are 3 things you should check:
!! line ~48: path to away image. It should be 16x16 image.
* line 103: This message informs you about being away
* line 105: This message informs you about being back
Code: Select all
pfcClient.prototype.buildNickItem = function(nickid)
  {
    var nick = this.getUserMeta(nickid, 'nick');
    var className = (! is_ie) ? 'class' : 'className';

    var nick = this.getUserMeta(nickid, 'nick');
    var isadmin = this.getUserMeta(nickid, 'isadmin');
    var isaway = this.getUserMeta(nickid, 'away');
    if (isadmin == '') isadmin = false;
    if (isaway == '') isaway = false;

    var li = document.createElement('li');

    var a = document.createElement('a');
    a.setAttribute('href','#');
    a.pfc_nick   = nick;
    a.pfc_nickid = nickid;
    a.onclick = function(evt){
      var d = pfc.getNickWhoisBox(this.pfc_nickid);
      document.body.appendChild(d);
      d.style.display = 'block';
      d.style.zIndex = '400';
      d.style.position = 'absolute';
      d.style.left = (mousePosX(evt)-7)+'px';
      d.style.top  = (mousePosY(evt)-7)+'px';
      return false;
    }
    li.appendChild(a);

    var img = document.createElement('img');
    if (isadmin)
      img.setAttribute('src', this.res.getFileUrl('images/user-admin.gif'));
    else
      img.setAttribute('src', this.res.getFileUrl('images/user.gif'));
    img.style.marginRight = '5px';
    img.setAttribute(className, 'pfc_nickbutton');
    a.appendChild(img);


    var img2 = document.createElement('img');
    // CHANGE THIS LINE IF YOU NEED TO --v
    img2.setAttribute('src', 'phpfreechat/data/public/themes/default/images/user-away.gif');
    img2.style.marginRight = '5px';
    // Image will be hidden if user is present
    if ( !isaway ) { img2.setAttribute('style', 'display: none;'); }
    a.appendChild(img2);



    // nobr is not xhtml valid but it's a workeround
    // for IE which doesn't support 'white-space: pre' css rule
    var nobr = document.createElement('nobr');
    var span = document.createElement('span');
    span.setAttribute(className, 'pfc_nickmarker pfc_nick_'+nickid);
    span.innerHTML = nick.escapeHTML();
    nobr.appendChild(span);
    a.appendChild(nobr);

    return li;
  };

pfcClient.prototype.handleResponse = function(cmd, resp, param)
  {
    // display some debug messages
    if (pfc_debug)
      if (cmd != "update")
      {
        var param2 = param;
        if (cmd == "who" || cmd == "who2")
        {
          param2 = $H(param2);
          param2.set('meta', $H(param2.get('meta')));
          param2.get('meta').set('users', $H(param2.get('meta').get('users')));
          trace('handleResponse: '+cmd + "-"+resp+"-"+param2.inspect());
        }
        else
        if (cmd == "whois" || cmd == "whois2")
        {
          param2 = $H(param2);
          trace('handleResponse: '+cmd + "-"+resp+"-"+param2.inspect());
        }
        else
        if (cmd == "getnewmsg" || cmd == "join")
        {
          param2 = $A(param2);
          trace('handleResponse: '+cmd + "-"+resp+"-"+param2.inspect());
        }
        else
          trace('handleResponse: '+cmd + "-"+resp+"-"+param);
      }

    // Away response
    if (cmd == "away")
    {
        if( resp == 'away' ) {
            var msg;
            ( param ) ? msg=' ('+param+')' : msg='';
            this.displayMsg( cmd, ('You are now away'+msg) );  // CHANGE THIS LINE IF YOU NEED TO
        } else {
            this.displayMsg( cmd, ('You are no longer away') );  // CHANGE THIS LINE IF YOU NEED TO
        }
    }

    if (cmd != "update")
    {
       // speed up timeout if activity
       this.last_activity_time = new Date().getTime();
       var delay = this.calcDelay();
       if (this.timeout_time - new Date().getTime() > delay)
       {
          clearTimeout(this.timeout);
          this.timeout = setTimeout('pfc.updateChat(true)', delay);
          this.timeout_time = new Date().getTime() + delay;
       }
    }

    if (cmd == "connect")
    {
      if (resp == "ok")
      {
        this.nickname = param[0];
        this.isconnected = true;

        // start the polling system
        this.updateChat(true);
      }
      else
        this.isconnected = false;
      this.refresh_loginlogout();
    }
    else if (cmd == "quit")
    {
      if (resp =="ok")
      {
        // stop updates
        this.updateChat(false);
        this.isconnected = false;
        this.refresh_loginlogout();
      }
    }
    else if (cmd == "join" || cmd == "join2")
    {
      if (resp =="ok")
      {
        // create the new channel
        var tabid = param[0];
        var name  = param[1];
        this.gui.createTab(name, tabid, "ch");
        if (cmd != "join2" || this.gui.tabs.length == 1) this.gui.setTabById(tabid);
        this.refresh_Smileys();
        this.refresh_WhosOnline();
      }
      else if (resp == "max_channels")
      {
        this.displayMsg( cmd, this.res.getLabel('Maximum number of joined channels has been reached') );
      }
      else
        alert(cmd + "-"+resp+"-"+param);
    }
    else if (cmd == "leave")
    {
      if (resp =="ok")
      {
        // remove the channel
        var tabid = param;
        this.gui.removeTabById(tabid);

        // synchronize the channel client arrays
        /*
        var index = -1;
        index = this.channelids.indexOf(tabid);
        this.channelids = this.channelids.without(tabid);
        this.channels   = this.channels.without(this.channels[index]);
        */

        // synchronize the privmsg client arrays
        index = -1;
        index = indexOf(this.privmsgids, tabid);
        this.privmsgids = without(this.privmsgids, tabid);
        this.privmsgs   = without(this.privmsgs, this.privmsgs[index]);

      }
    }
    else if (cmd == "privmsg" || cmd == "privmsg2")
    {
      if (resp == "ok")
      {
        // create the new channel
        var tabid = param[0];
        var name  = param[1];
        this.gui.createTab(name, tabid, "pv");
        if (cmd != "privmsg2" || this.gui.tabs.length == 1) this.gui.setTabById(tabid);

        this.privmsgs.push(name);
        this.privmsgids.push(tabid);

      }
      else if (resp == "max_privmsg")
      {
        this.displayMsg( cmd, this.res.getLabel('Maximum number of private chat has been reached') );
      }
      else if (resp == "unknown")
      {
        // speak to unknown user
        this.displayMsg( cmd, this.res.getLabel('You are trying to speak to a unknown (or not connected) user') );
      }
      else if (resp == "speak_to_myself")
      {
        this.displayMsg( cmd, this.res.getLabel('You are not allowed to speak to yourself') );
      }
      else
        alert(cmd + "-"+resp+"-"+param);
    }
    else if (cmd == "nick")
    {
      // give focus the the input text box if wanted
      if (pfc_focus_on_connect) this.el_words.focus();

      if (resp == "connected" || resp == "notchanged")
      {
        cmd = '';
      }

      if (resp == "ok" || resp == "notchanged" || resp == "changed" || resp == "connected")
      {
        this.setUserMeta(this.nickid, 'nick', param);
        this.el_handle.innerHTML = this.getUserMeta(this.nickid, 'nick').escapeHTML();
        this.nickname = this.getUserMeta(this.nickid, 'nick');
        this.updateNickBox(this.nickid);

        // clear the possible error box generated by the bellow displayMsg(...) function
        this.clearError(Array(this.el_words));
      }
      else if (resp == "isused")
      {
        this.setError(this.res.getLabel('Chosen nickname is already used'), Array());
        this.askNick(param,this.res.getLabel('Chosen nickname is already used'));
      }
      else if (resp == "notallowed")
      {
        // When frozen_nick is true and the nickname is already used, server will return
        // the 'notallowed' status. It will display a message and stop chat update.
        // If the chat update is not stopped, this will loop forever
        // as long as the forced nickname is not changed.

        // display a message
        this.setError(this.res.getLabel('Chosen nickname is not allowed'), Array());
        // then stop chat updates
        this.updateChat(false);
        this.isconnected = false;
        this.refresh_loginlogout();
      }
    }
    else if (cmd == "update")
    {
    }
    else if (cmd == "version")
    {
      if (resp == "ok")
      {
        this.displayMsg( cmd, this.res.getLabel('phpfreechat current version is %s',param) );
      }
    }
    else if (cmd == "help")
    {
      if (resp == "ok")
      {
        this.displayMsg( cmd, param);
      }
    }
    else if (cmd == "rehash")
    {
      if (resp == "ok")
      {
        this.displayMsg( cmd, this.res.getLabel('Configuration has been rehashed') );
      }
      else if (resp == "ko")
      {
        this.displayMsg( cmd, this.res.getLabel('A problem occurs during rehash') );
      }
    }
    else if (cmd == "banlist")
    {
      if (resp == "ok" || resp == "ko")
      {
        this.displayMsg( cmd, param );
      }
    }
    else if (cmd == "unban")
    {
      if (resp == "ok" || resp == "ko")
      {
        this.displayMsg( cmd, param );
      }
    }
    else if (cmd == "auth")
    {
      if (resp == "ban")
      {
        alert(param);
      }
      if (resp == "frozen")
      {
        alert(param);
      }
      else if (resp == "nick")
      {
        this.displayMsg( cmd, param );
      }
    }
    else if (cmd == "debug")
    {
      if (resp == "ok" || resp == "ko")
      {
        this.displayMsg( cmd, param );
      }
    }
    else if (cmd == "clear")
    {
      var tabid     = this.gui.getTabId();
      var container = this.gui.getChatContentFromTabId(tabid);
      container.innerHTML = "";
    }
    else if (cmd == "identify")
    {
      this.displayMsg( cmd, param );
    }
    else if (cmd == "checknickchange")
    {
      this.displayMsg( cmd, param );
    }
    else if (cmd == "whois" || cmd == "whois2")
    {
      param = $H(param);
      var nickid = param.get('nickid');
      if (resp == "ok")
      {
        this.setUserMeta(nickid, param);
        this.updateNickBox(nickid);
        this.updateNickWhoisBox(nickid);
      }
      if (cmd == "whois")
      {
        // display the whois info
        var um = this.getAllUserMeta(nickid);
        var um_keys = um.keys();
        var msg = '';
        for (var i=0; i<um_keys.length; i++)
        {
          var k = um_keys[i];
          var v = um.get(k);
          if (v &&
              // these parameter are used internaly (don't display it)
              k != 'nickid' &&
              k != 'floodtime' &&
              k != 'flood_nbmsg' &&
              k != 'flood_nbchar')
            msg = msg + '<strong>' + k + '</strong>: ' + v + '<br/>';
        }
        this.displayMsg( cmd, msg );
      }
    }
    else if (cmd == "who" || cmd == "who2")
    {
      param = $H(param);
      var chan   = param.get('chan');
      var chanid = param.get('chanid');
      var meta   = $H(param.get('meta'));
      meta.set('users', $H(meta.get('users')));
      if (resp == "ok")
      {
        this.setChanMeta(chanid,meta);
        // send /whois commands for unknown users
        for (var i=0; i<meta.get('users').get('nickid').length; i++)
        {
          var nickid = meta.get('users').get('nickid')[i];
          var nick   = meta.get('users').get('nick')[i];
          var um = this.getAllUserMeta(nickid);
          if (!um) this.sendRequest('/whois2 "'+nickid+'"');
        }

        // update the nick list display on the current channel
        this.updateNickListBox(chanid);
      }
      if (cmd == "who")
      {
        // display the whois info
        var cm = this.getAllChanMeta(chanid);
        var cm_keys = cm.keys();
        var msg = '';
        for (var i=0; i<cm_keys.length; i++)
        {
          var k = cm_keys[i];
          var v = cm[k];
          if (k != 'users')
          {
            msg = msg + '<strong>' + k + '</strong>: ' + v + '<br/>';
          }
        }
        this.displayMsg( cmd, msg );
      }
    }
    else if (cmd == "getnewmsg")
    {
      if (resp == "ok")
      {
        this.handleComingRequest(param);
      }
    }
    else if (cmd == "send")
    {
    }
    else if (cmd == "away")
    {
    }
    else
      alert(cmd + "-"+resp+"-"+param);
  };

src/commands/away.class.php - new file
In this file there are 2 lines you may want to update:
* line ~31: global "User $U is now away"
* line ~58: global "User $U has returned"
Code: Select all
<?php
require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_away extends pfcCommand
{
    var $usage = "/away [ {away message} ]";

    function run(&$xml_reponse, $p)
    {
        $clientid    = $p["clientid"];
        $param       = $p["param"];
        $sender      = $p["sender"];
        $recipient   = $p["recipient"];
        $recipientid = $p["recipientid"];

        $c =& pfcGlobalConfig::Instance();
        $u =& pfcUserConfig::Instance();
        $container  =& pfcContainer::Instance();

        $awayMessage  = trim($param);
        ( $awayMessage == '' ) ? $tparm = 'false' : $tparm = '''.$awayMessage.''';

        $current = $container->getUserMeta($u->nickid, 'away');

        if ( $current == "" ){
            // if message is entered, it shows it within brackets
            ( $awayMessage == '' ) ? $msg = false : $msg = ' ('.$awayMessage.')';
            $is_away='away';
            // show an away message
            $cmdp = $p;
            $cmdp["param"] = "$u->nick is now away$msg";  // CHANGE THIS LINE IF YOU NEED TO
            $cmdp["flag"] = 1;
            $cmd =& pfcCommand::Factory("notice");
            //send message to channels
            foreach($u->channels as $id => $chan)
            {
                $cmdp["recipient"]   = $chan["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }
            //send message to PMs
            foreach( $u->privmsg as $id => $pv )
            {
                $cmdp["recipient"]   = $pv["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }

            //set user's Away metadata
            ( $awayMessage == '' ) ? $newMeta = 'yes' : $newMeta = $awayMessage;  // important to correctly set meta
            $container->setUserMeta($u->nickid, 'away', $newMeta);
            $this->forceWhoisReload($u->nickid);


        }else{
            // remove an away message
            $cmdp = $p;
            $cmdp["param"] = "$u->nick has returned";  // CHANGE THIS LINE IF YOU NEED TO
            $cmdp["flag"] = 1;
            $cmd =& pfcCommand::Factory("notice");
            foreach($u->channels as $id => $chan)
            {
                $cmdp["recipient"]   = $chan["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }
            //send message to PMs
            foreach( $u->privmsg as $id => $pv )
            {
                $cmdp["recipient"]   = $pv["recipient"];
                $cmdp["recipientid"] = $id;
                $cmd->run($xml_reponse, $cmdp);
            }

            //remove the metadata
            $container->rmUserMeta($u->nickid, 'away');
            $this->forceWhoisReload($u->nickid);
            $is_away='present';

        }
       
        $xml_reponse->script("pfc.handleResponse('".$this->name."', '".$is_away."', ".$tparm.");");

    }
}
?>
xoores
New member
 
Posts: 4
Joined: Fri Aug 07, 2009 7:53 pm
Top

Postby xoores » Sat Aug 08, 2009 10:57 am

@kerphi: I can do that - but today I leave for about 10 days. So when I come back, I will commit this.
xoores
New member
 
Posts: 4
Joined: Fri Aug 07, 2009 7:53 pm
Top

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

Does this script work with version 1.3?
TheSeaKing
Member
 
Posts: 21
Joined: Sat Nov 22, 2008 6:40 am
Top

Next

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

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 2 guests

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