Net_SmartIRC
[ class tree: Net_SmartIRC ] [ index: Net_SmartIRC ] [ all elements ]

Source for file irccommands.php

Documentation is available at irccommands.php

  1. <?php
  2. /**
  3.  * $Id: irccommands.php 241047 2007-08-10 15:10:30Z amir $
  4.  * $Revision: 241047 $
  5.  * $Author: amir $
  6.  * $Date: 2007-08-11 00:40:30 +0930 (Sat, 11 Aug 2007) $
  7.  *
  8.  * Copyright (c) 2002-2004 Mirco Bauer <meebey@meebey.net> <http://www.meebey.net>
  9.  * 
  10.  * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
  11.  * 
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26.  
  27. {
  28.     /**
  29.      * sends a new message
  30.      *
  31.      * Sends a message to a channel or user.
  32.      *
  33.      * @see DOCUMENTATION
  34.      * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types'
  35.      * @param string $destination can be a user or channel
  36.      * @param mixed $message the message
  37.      * @return boolean 
  38.      * @access public
  39.      */
  40.     function message($type$destination$messagearray$priority = SMARTIRC_MEDIUM)
  41.     {
  42.         if (!is_array($messagearray)) {
  43.             $messagearray = array($messagearray);
  44.         }
  45.         
  46.         switch ($type{
  47.             case SMARTIRC_TYPE_CHANNEL:
  48.             case SMARTIRC_TYPE_QUERY:
  49.                 foreach ($messagearray as $message{
  50.                     $this->_send('PRIVMSG '.$destination.' :'.$message$priority);
  51.                 }
  52.             break;
  53.             case SMARTIRC_TYPE_ACTION:
  54.                 foreach ($messagearray as $message{
  55.                     $this->_send('PRIVMSG '.$destination.' :'.chr(1).'ACTION '.$message.chr(1)$priority);
  56.                 }
  57.             break;
  58.             case SMARTIRC_TYPE_NOTICE:
  59.                 foreach ($messagearray as $message{
  60.                     $this->_send('NOTICE '.$destination.' :'.$message$priority);
  61.                 }
  62.             break;
  63.             case SMARTIRC_TYPE_CTCP// backwards compatibilty
  64.             case SMARTIRC_TYPE_CTCP_REPLY:
  65.                 foreach ($messagearray as $message{
  66.                     $this->_send('NOTICE '.$destination.' :'.chr(1).$message.chr(1)$priority);
  67.                 }
  68.             break;
  69.             case SMARTIRC_TYPE_CTCP_REQUEST:
  70.                 foreach ($messagearray as $message{
  71.                     $this->_send('PRIVMSG '.$destination.' :'.chr(1).$message.chr(1)$priority);
  72.                 }
  73.             break;
  74.             default:
  75.                 return false;
  76.         }
  77.         
  78.         return true;
  79.     }
  80.     
  81.     /**
  82.      * returns an object reference to the specified channel
  83.      *
  84.      * If the channel does not exist (because not joint) false will be returned.
  85.      *
  86.      * @param string $channelname 
  87.      * @return object reference to the channel object
  88.      * @access public
  89.      */
  90.     function &channel($channelname)
  91.     {
  92.         if (isset($this->_channels[strtolower($channelname)])) {
  93.             return $this->_channels[strtolower($channelname)];
  94.         else {
  95.             return false;
  96.         }
  97.     }
  98.     
  99.     // <IRC methods>
  100.     /**
  101.      * Joins one or more IRC channels with an optional key.
  102.      *
  103.      * @param mixed $channelarray 
  104.      * @param string $key 
  105.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  106.      * @return void 
  107.      * @access public
  108.      */
  109.     function join($channelarray$key = null$priority = SMARTIRC_MEDIUM)
  110.     {
  111.         if (!is_array($channelarray)) {
  112.             $channelarray = array($channelarray);
  113.         }
  114.         
  115.         $channellist implode(','$channelarray);
  116.         
  117.         if ($key !== null{
  118.             $this->_send('JOIN '.$channellist.' '.$key$priority);
  119.         else {
  120.             $this->_send('JOIN '.$channellist$priority);
  121.         }
  122.     }
  123.     
  124.     /**
  125.      * parts from one or more IRC channels with an optional reason
  126.      *
  127.      * @param mixed $channelarray 
  128.      * @param string $reason 
  129.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  130.      * @return void 
  131.      * @access public
  132.      */
  133.     function part($channelarray$reason = null$priority = SMARTIRC_MEDIUM)
  134.     {
  135.         if (!is_array($channelarray)) {
  136.             $channelarray = array($channelarray);
  137.         }
  138.         
  139.         $channellist implode(','$channelarray);
  140.         
  141.         if ($reason !== null{
  142.             $this->_send('PART '.$channellist.' :'.$reason$priority);
  143.         else {
  144.             $this->_send('PART '.$channellist$priority);
  145.         }
  146.     }
  147.     
  148.     /**
  149.      * Kicks one or more user from an IRC channel with an optional reason.
  150.      *
  151.      * @param string $channel 
  152.      * @param mixed $nicknamearray 
  153.      * @param string $reason 
  154.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  155.      * @return void 
  156.      * @access public
  157.      */
  158.     function kick($channel$nicknamearray$reason = null$priority = SMARTIRC_MEDIUM)
  159.     {
  160.         if (!is_array($nicknamearray)) {
  161.             $nicknamearray = array($nicknamearray);
  162.         }
  163.         
  164.         $nicknamelist implode(','$nicknamearray);
  165.         
  166.         if ($reason !== null{
  167.             $this->_send('KICK '.$channel.' '.$nicknamelist.' :'.$reason$priority);
  168.         else {
  169.             $this->_send('KICK '.$channel.' '.$nicknamelist$priority);
  170.         }
  171.     }
  172.     
  173.     /**
  174.      * gets a list of one ore more channels
  175.      *
  176.      * Requests a full channellist if $channelarray is not given.
  177.      * (use it with care, usualy its a looooong list)
  178.      *
  179.      * @param mixed $channelarray 
  180.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  181.      * @return void 
  182.      * @access public
  183.      */
  184.     function getList($channelarray = null$priority = SMARTIRC_MEDIUM)
  185.     {
  186.         if ($channelarray !== null{
  187.             if (!is_array($channelarray)) {
  188.                 $channelarray = array($channelarray);
  189.             }
  190.             
  191.             $channellist implode(','$channelarray);
  192.             $this->_send('LIST '.$channellist$priority);
  193.         else {
  194.             $this->_send('LIST'$priority);
  195.         }
  196.     }
  197.  
  198.     /**
  199.      * requests all nicknames of one or more channels
  200.      *
  201.      * The requested nickname list also includes op and voice state
  202.      *
  203.      * @param mixed $channelarray 
  204.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  205.      * @return void 
  206.      * @access public
  207.      */
  208.     function names($channelarray = null$priority = SMARTIRC_MEDIUM)
  209.     {
  210.         if ($channelarray !== null{
  211.             if (!is_array($channelarray)) {
  212.                 $channelarray = array($channelarray);
  213.             }
  214.             
  215.             $channellist implode(','$channelarray);
  216.             $this->_send('NAMES '.$channellist$priority);
  217.         else {
  218.             $this->_send('NAMES'$priority);
  219.         }
  220.     }
  221.     
  222.     /**
  223.      * sets a new topic of a channel
  224.      *
  225.      * @param string $channel 
  226.      * @param string $newtopic 
  227.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  228.      * @return void 
  229.      * @access public
  230.      */
  231.     function setTopic($channel$newtopic$priority = SMARTIRC_MEDIUM)
  232.     {
  233.         $this->_send('TOPIC '.$channel.' :'.$newtopic$priority);
  234.     }
  235.     
  236.     /**
  237.      * gets the topic of a channel
  238.      *
  239.      * @param string $channel 
  240.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  241.      * @return void 
  242.      * @access public
  243.      */
  244.     function getTopic($channel$priority = SMARTIRC_MEDIUM)
  245.     {
  246.         $this->_send('TOPIC '.$channel$priority);
  247.     }
  248.     
  249.     /**
  250.      * sets or gets the mode of an user or channel
  251.      *
  252.      * Changes/requests the mode of the given target.
  253.      *
  254.      * @param string $target the target, can be an user (only yourself) or a channel
  255.      * @param string $newmode the new mode like +mt
  256.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  257.      * @return void 
  258.      * @access public
  259.      */
  260.     function mode($target$newmode = null$priority = SMARTIRC_MEDIUM)
  261.     {
  262.         if ($newmode !== null{
  263.             $this->_send('MODE '.$target.' '.$newmode$priority);
  264.         else {
  265.             $this->_send('MODE '.$target$priority);
  266.         }
  267.     }
  268.     
  269.     /**
  270.      * ops an user in the given channel
  271.      *
  272.      * @param string $channel 
  273.      * @param string $nickname 
  274.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  275.      * @return void 
  276.      * @access public
  277.      */
  278.     function op($channel$nickname$priority = SMARTIRC_MEDIUM)
  279.     {
  280.         $this->mode($channel'+o '.$nickname$priority);
  281.     }
  282.     
  283.     /**
  284.      * deops an user in the given channel
  285.      *
  286.      * @param string $channel 
  287.      * @param string $nickname 
  288.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  289.      * @return void 
  290.      * @access public
  291.      */
  292.     function deop($channel$nickname$priority = SMARTIRC_MEDIUM)
  293.     {
  294.         $this->mode($channel'-o '.$nickname$priority);
  295.     }
  296.     
  297.     /**
  298.      * voice a user in the given channel
  299.      *
  300.      * @param string $channel 
  301.      * @param string $nickname 
  302.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  303.      * @return void 
  304.      * @access public
  305.      */
  306.     function voice($channel$nickname$priority = SMARTIRC_MEDIUM)
  307.     {
  308.         $this->mode($channel'+v '.$nickname$priority);
  309.     }
  310.     
  311.     /**
  312.      * devoice a user in the given channel
  313.      *
  314.      * @param string $channel 
  315.      * @param string $nickname 
  316.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  317.      * @return void 
  318.      * @access public
  319.      */
  320.     function devoice($channel$nickname$priority = SMARTIRC_MEDIUM)
  321.     {
  322.         $this->mode($channel'-v '.$nickname$priority);
  323.     }
  324.     
  325.     /**
  326.      * bans a hostmask for the given channel or requests the current banlist
  327.      *
  328.      * The banlist will be requested if no hostmask is specified
  329.      *
  330.      * @param string $channel 
  331.      * @param string $hostmask 
  332.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  333.      * @return void 
  334.      * @access public
  335.      */
  336.     function ban($channel$hostmask = null$priority = SMARTIRC_MEDIUM)
  337.     {
  338.         if ($hostmask !== null{
  339.             $this->mode($channel'+b '.$hostmask$priority);
  340.         else {
  341.             $this->mode($channel'b'$priority);
  342.         }
  343.     }
  344.     
  345.     /**
  346.      * unbans a hostmask on the given channel
  347.      *
  348.      * @param string $channel 
  349.      * @param string $hostmask 
  350.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  351.      * @return void 
  352.      * @access public
  353.      */
  354.     function unban($channel$hostmask$priority = SMARTIRC_MEDIUM)
  355.     {
  356.         $this->mode($channel'-b '.$hostmask$priority);
  357.     }
  358.     
  359.     /**
  360.      * invites a user to the specified channel
  361.      *
  362.      * @param string $nickname 
  363.      * @param string $channel 
  364.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  365.      * @return void 
  366.      * @access public
  367.      */
  368.     function invite($nickname$channel$priority = SMARTIRC_MEDIUM)
  369.     {
  370.         $this->_send('INVITE '.$nickname.' '.$channel$priority);
  371.     }
  372.     
  373.     /**
  374.      * changes the own nickname
  375.      *
  376.      * Trys to set a new nickname, nickcollisions are handled.
  377.      *
  378.      * @param string $newnick 
  379.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  380.      * @return void 
  381.      * @access public
  382.      */
  383.     function changeNick($newnick$priority = SMARTIRC_MEDIUM)
  384.     {
  385.         $this->_send('NICK '.$newnick$priority);
  386.         $this->_nick $newnick;
  387.     }
  388.     
  389.     /**
  390.      * requests a 'WHO' from the specified target
  391.      *
  392.      * @param string $target 
  393.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  394.      * @return void 
  395.      * @access public
  396.      */
  397.     function who($target$priority = SMARTIRC_MEDIUM)
  398.     {
  399.         $this->_send('WHO '.$target$priority);
  400.     }
  401.     
  402.     /**
  403.      * requests a 'WHOIS' from the specified target
  404.      *
  405.      * @param string $target 
  406.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  407.      * @return void 
  408.      * @access public
  409.      */
  410.     function whois($target$priority = SMARTIRC_MEDIUM)
  411.     {
  412.         $this->_send('WHOIS '.$target$priority);
  413.     }
  414.     
  415.     /**
  416.      * requests a 'WHOWAS' from the specified target
  417.      * (if he left the IRC network)
  418.      *
  419.      * @param string $target 
  420.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  421.      * @return void 
  422.      * @access public
  423.      */
  424.     function whowas($target$priority = SMARTIRC_MEDIUM)
  425.     {
  426.         $this->_send('WHOWAS '.$target$priority);
  427.     }
  428.     
  429.     /**
  430.      * sends QUIT to IRC server and disconnects
  431.      *
  432.      * @param string $quitmessage optional quitmessage
  433.      * @param integer $priority message priority, default is SMARTIRC_CRITICAL
  434.      * @return void 
  435.      * @access public
  436.      */
  437.     function quit($quitmessage = null$priority = SMARTIRC_CRITICAL)
  438.     {
  439.         if ($quitmessage !== null{
  440.             $this->_send('QUIT :'.$quitmessage$priority);
  441.         else {
  442.             $this->_send('QUIT'$priority);
  443.         }
  444.  
  445.         $this->disconnect(true);
  446.     }
  447. }
  448. ?>

Documentation generated on Mon, 11 Mar 2019 15:32:23 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.