Location: PHPKode > scripts > IrControl > ircontrol/phpirc.php
<?php
/*
 * This class is distrubited under the Public Domain license!
 * This is a PHP5 class. IT WONT WORK under PHP4.
 * Tested on PHP 5.0.5 and on PHP 5.1.
 * Licensed under the PHP license!
 * $author isoTop$
 */
require "defines.phpirc.php";
/**
 * main php:irc class
 *
 * @package php:irc
 * @version 0.2
 * @author Dani 'isoTop' M. <hide@address.com>
 * @access public
 */

ob_implicit_flush(1);
@set_time_limit(0);
ignore_user_abort(true);

class phpirc
{
	public $ip;
	public $port;
	public $socket;
	public $action;
	public $lastid;
	public $lastsend;
	public $anotherlisten = 0;
	public $logit = true;
	public $usesockets = false;
	
	/**
	 * The constructor.
	 */
	function phpirc()
	{
		$this->log("The class phpirc has been called.\n\r");
		$this->lastsend = time();
	}
	
	/**
	 * Connects to an IRC server.
	 *
	 * @param string $ip
	 * @param int $port
	 */
	function connect($ip, $port)
	{
		$this->ip = $ip;
		$this->port = $port;
		
		if(!$this->usesockets)
		{
			$this->socket = fsockopen($this->ip, $this->port, $errornum, $errorstr, 30);
			if (!$this->socket)
			{
				$this->log("Couldn't connect to {$this->ip} on port {$this->port}. {$errorstr} ({$errornum})");
			}
		}
		else
		{
			$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_connect($this->socket, $this->ip, $this->port);
			if (!$this->socket)
			{
				$this->log("Couldn't connect to {$this->ip} on port {$this->port}.");
			}
		}
	}
	
	/**
	 * Sends raw data to thr server.
	 *
	 * @param string $str
	 */
	function rawsend($str)
	{
		fwrite($this->socket, $str);
	}
	
	/**
	 * Sends message to the server.
	 *
	 * @param string $msg
	 * @return boolean
	 */
	function send($msg)
	{
		$this->log("SEND: ".$msg."\n");
		
		if(!$this->usesockets)
		{
			$socket = fwrite($this->socket, $msg."\n\r");
			return $socket;
		}
		else
		{
			$socket = socket_write($this->socket, $msg."\n\r");
			return $socket;
		}

		if(!$socket)
		{
			$this->log("There was an error while sending your message. Your message was '{$msg}'");
			return false;
		}
	}
	
	/**
	 * Login to the server.
	 *
	 * @param string $nick
	 * @param string $username
	 * @param string $realname
	 */
	function login($nick, $username, $realname)
	{
		$this->nick = $nick;
		$this->username = $username;
		$this->realname = $realname;
		$logged = $this->send("NICK {$this->nick}\n\rUSER {$this->username} 0 * :{$this->realname}");
	}
	
	/**
	 * Disconnects from the server and exiting the program.
	 *
	 * @param string $msg
	 */
	function quit($msg)
	{
		$this->send('QUIT :'.$msg);
		fclose($this->socket);
		die("You have disconnected from {$this->ip}.");
	}
	
	function restart($msg)
	{
		$this->send('QUIT :'.$msg);
		fclose($this->socket);

		$this->connect($this->ip, $this->port);
	}
	
	/**
	 * Joins the channels that are in the array $channels.
	 *
	 * @param array $channels
	 */
	function join($channels)
	{
		if (!is_array($channels))
		{
			$channels = array($channels);
		}
		
		foreach($channels as $channel)
		{
			$this->channels[] = $channel;
		}
	}
	
	/**
	 * Logs the conversation. returns false if the lenght of $msg is smaller than 1 characters.
	 *
	 * @param string $msg
	 */
	function log($msg)
	{
		if(strlen($msg) > 0)
		{
			echo $msg;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Checks if $this->socket is socket or stream.
	 *
	 * @return boolean
	 */
	function state()
	{
		return in_array(strtolower(get_resource_type($this->socket)), array("socket", "stream"));
	}
	
	/**
	 * Changes the mode of a nick or a channel
	 *
	 * @param string $mode
	 * @param string $nick
	 */
	function mode($mode, $nick)
	{
		$this->send("MODE ".$nick." ".$mode);
	}
	
	/**
	 * Sends a message to a channel or a nick.
	 *
	 * @param string $msg
	 * @param string $channel
	 */
	function send_to_channel($msg, $channel)
	{
		$this->send("PRIVMSG {$channel} :{$msg}");
	}
	
	/**
	 * Sends a notice to the nick $nick
	 *
	 * @param string $msg
	 * @param string $channel
	 */
	function notice($msg, $nick)
	{
		$this->send("NOTICE {$nick} {$msg}");
	}
	
	/**
	 * Unjoins a channel.
	 *
	 * @param string $msg
	 * @param string $channel
	 */
	function unjoin($msg, $channel)
	{
		$this->send("PART ".$channel." ".$msg);
	}
	
	/**
	 * Givs/takes an op from/to the nick $nick
	 *
	 * @param string $channel
	 * @param string $nick
	 * @param string $mode
	 */
	function op($channel, $nick, $mode)
	{
		if($mode == "give")
		{
			$this->send("MODE {$channel} +o {$nick}");
		}
		elseif($mode == "take")
		{
			$this->send("MODE {$channel} -o {$nick}");
		}
		else 
		{
			$this->log("You didn't give enaugh parameters.");
		}
	}
	
	/**
	 * Analyses the type of an IRC message and returns the type.
	 *
	 * @param string $line
	 * @return int SMARTIRC_TYPE_* constant
	 */
	function _gettype($line)
	{
		if (preg_match('/^:.* [0-9]{3} .*$/', $line) == 1)
		{
			$lineex = explode(' ', $line);
			$code = $lineex[1];

			switch ($code) {
				case SMARTIRC_RPL_WELCOME:
					return SMARTIRC_TYPE_LOGIN;
				case SMARTIRC_RPL_YOURHOST:
					return SMARTIRC_TYPE_LOGIN;
				case SMARTIRC_RPL_CREATED:
					return SMARTIRC_TYPE_LOGIN;
				case SMARTIRC_RPL_MYINFO:
					return SMARTIRC_TYPE_LOGIN;
				case SMARTIRC_RPL_BOUNCE:
					return SMARTIRC_TYPE_LOGIN;
				case SMARTIRC_RPL_LUSERCLIENT:
					return SMARTIRC_TYPE_INFO;
				case SMARTIRC_RPL_LUSEROP:
					return SMARTIRC_TYPE_INFO;
				case SMARTIRC_RPL_LUSERUNKNOWN:
					return SMARTIRC_TYPE_INFO;
				case SMARTIRC_RPL_LUSERME:
					return SMARTIRC_TYPE_INFO;
				case SMARTIRC_RPL_LUSERCHANNELS:
					return SMARTIRC_TYPE_INFO;
				case SMARTIRC_RPL_MOTDSTART:
					return SMARTIRC_TYPE_MOTD;
				case SMARTIRC_RPL_MOTD:
					return SMARTIRC_TYPE_MOTD;
				case SMARTIRC_RPL_ENDOFMOTD:
					return SMARTIRC_TYPE_MOTD;
				case SMARTIRC_RPL_NAMREPLY:
					return SMARTIRC_TYPE_NAME;
				case SMARTIRC_RPL_ENDOFNAMES:
					return SMARTIRC_TYPE_NAME;
				case SMARTIRC_RPL_WHOREPLY:
					return SMARTIRC_TYPE_WHO;
				case SMARTIRC_RPL_ENDOFWHO:
					return SMARTIRC_TYPE_WHO;
				case SMARTIRC_RPL_LISTSTART:
					return SMARTIRC_TYPE_NONRELEVANT;
				case SMARTIRC_RPL_LIST:
					return SMARTIRC_TYPE_LIST;
				case SMARTIRC_RPL_LISTEND:
					return SMARTIRC_TYPE_LIST;
				case SMARTIRC_RPL_BANLIST:
					return SMARTIRC_TYPE_BANLIST;
				case SMARTIRC_RPL_ENDOFBANLIST:
					return SMARTIRC_TYPE_BANLIST;
				case SMARTIRC_RPL_TOPIC:
					return SMARTIRC_TYPE_TOPIC;
				case SMARTIRC_RPL_WHOISUSER:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOISSERVER:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOISOPERATOR:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOISIDLE:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOISIDLE:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_ENDOFWHOIS:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOISCHANNELS:
					return SMARTIRC_TYPE_WHOIS;
				case SMARTIRC_RPL_WHOWASUSER:
					return SMARTIRC_TYPE_WHOWAS;
				case SMARTIRC_RPL_ENDOFWHOWAS:
					return SMARTIRC_TYPE_WHOWAS;
				case SMARTIRC_RPL_UMODEIS:
					return SMARTIRC_TYPE_USERMODE;
				case SMARTIRC_RPL_CHANNELMODEIS:
					return SMARTIRC_TYPE_CHANNELMODE;
				case SMARTIRC_ERR_NICKNAMEINUSE:
					return SMARTIRC_TYPE_ERROR;
				case SMARTIRC_ERR_NOTREGISTERED:
					return SMARTIRC_TYPE_ERROR;
			}
		}
		
		if (preg_match('/^:.* PRIVMSG .* :'.chr(1).'ACTION .*'.chr(1).'$/', $line) == 1)
		{
			return SMARTIRC_TYPE_ACTION;
		}
		else if (preg_match('/^:.* PRIVMSG .* :'.chr(1).'.*'.chr(1).'$/', $line) == 1)
		{
			return SMARTIRC_TYPE_CTCP;
		}
		else if (preg_match('/^:.* PRIVMSG (\&|\#|\+|\!).* :.*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_CHANNEL;
		}
		else if (preg_match('/^:.* PRIVMSG .*:.*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_QUERY;
		}
		else if (preg_match('/^:.* NOTICE .* :.*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_NOTICE;
		}
		else if (preg_match('/^:.* INVITE .* .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_INVITE;
		}
		else if (preg_match('/^:.* JOIN .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_JOIN;
		}
		else if (preg_match('/^:.* TOPIC .* :.*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_TOPICCHANGE;
		}
		else if (preg_match('/^:.* NICK .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_NICKCHANGE;
		}
		else if (preg_match('/^:.* KICK .* .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_KICK;
		}
		else if (preg_match('/^:.* PART .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_PART;
		}
		else if (preg_match('/^:.* MODE .* .*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_MODECHANGE;
		}
		else if (preg_match('/^:.* QUIT :.*$/', $line) == 1)
		{
			return SMARTIRC_TYPE_QUIT;
		}
		else
		{
			//$this->log(SMARTIRC_DEBUG_msgAGETYPES, 'DEBUG_msgAGETYPES: SMARTIRC_TYPE_UNKNOWN!: "'.$line.'"', __FILE__, __LINE__);
			return SMARTIRC_TYPE_UNKNOWN;
		}
	}
	
	function sendtoobj($obj, $function)
	{
		$this->sendto->is_send = 1;
		$this->sendto->object = $obj;
		$this->sendto->function = $function;
	}

	function addlistenfun($obj, $function)
	{
		$this->anotherlisten = 1;
		$this->listenmore->obj = $obj;
		$this->listenmore->fun = $function;
	}	
	
	/**
	 * Listens to the IRC socket in a loop.
	 */
	function listen()
	{
		if($this->anotherlisten)
		{
			$this->listenmore->obj->{$this->listenmore->fun}();
		}
	
		while ($this->state())
		{
			if(!$this->usesockets)
			{
				$read = fread($this->socket, 10240);
			}
			else
			{
				$read = socket_read($this->socket, 2048, PHP_NORMAL_READ);
			}
			
			$lines = explode("\r\n", $read);
					
			foreach($lines as $line)
			{
				$msg = explode(" ", $line);
	
				if(@$msg[1] == "001") $this->send("JOIN ".implode(',', $this->channels));
	
				$messagehandler = new messagehandler($line, &$this);
				$messagehandler->checkforactions();
			}
	
			$this->log($read);
				
			$ping = explode("PING :", $read);
			if(@strlen($ping[1]) > 0)
			{
				$this->send("PONG ".$ping[1]);
			}
	
			$private_message = explode("PRIVMSG", $read);
			$private_message = explode(":", @$j[1]);
			$this->log(@$private_message[1]);
		}
	}
	
	function register_action($type, $regex, $object, $method)
	{
		$newid = $this->action->lastid + 1;
		$this->action->$newid = new action($type, $regex, $object, $method);
		$this->action->lastid++;
	}
}

class messagehandler
{
	/**
	 * The constructor of the class.
	 *
	 * @param string $msg
	 * @param object $irc
	 */
	function messagehandler($msg, $irc)
	{
		$this->irc =& $irc;
		$this->rawmessage = $msg;
		$this->type = $irc->_gettype(@$this->rawmessage);
		
		$msg_words = explode(" ", $msg);
		$this->channel = @$msg_words[2];
		
		if(substr($msg, 0, 1) == ":")
		{
			$exploded_message = explode(":", substr($msg, 1));
			$this->message = @$exploded_message[1];
			$this->linex = explode(" ", @$exploded_message[1]);

			$user = explode("!", substr($msg, 1));
			$this->user = $user[0];
		}
		else
		{
			$exploded_message = explode(":", substr($msg, 0));
			$this->message = @$exploded_message[1];
			$this->linex = explode(" ", @$exploded_message[1]);
			
			$user = explode("!", substr($msg, 0));
			$this->user = $user[0];
		}
		
		return $this;
	}
	
	function checkforactions()
	{
		if($this->irc->action->lastid != 0)
		{
			for($i = 1; $i <= $this->irc->action->lastid; $i++)
			{
				if($this->irc->action->$i->type & $this->type)
				{
					if(preg_match($this->irc->action->$i->regex, $this->message))
					{
						$this->irc->log("<span style='color: #FF0000;'>FOUND ACTION!</span>\n");
						$obj = $this->irc->action->$i->obj;
						$method = $this->irc->action->$i->method;
						$obj->{$method}($this, $this->irc);
					}
				}
			}
		}
	}	
}

class action
{
	function action($type, $regex, $object, $method)
	{
		$this->type = $type;
		$this->regex = $regex;
		$this->obj = $object;
		$this->method = $method;
		return $this;
	}
}

function getheaders($url)
{
	$url_info = parse_url($url);
	$port = isset($url_info['port']) ? $url_info['port'] : 80;
	$socket = fsockopen($url_info['host'], $port, $errno, $errstr, 30);

	if($socket)
	{
		$head = "HEAD ".@$url_info['path']."?".@$url_info['query']." HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";	 
		fwrite($socket, $head);
		
		while(!feof($socket))
		{
			if($header = trim(fread($socket, 1024)))
			{
				$hed = explode(": ", $header);
				if(preg_match("/Location/i", $hed[0]))
				{
					return $hed[1];
				}
			}
		}
	}
	else
	{
		return false;
	}
}

class functions
{	
	function google($msg, $irc)
	{
		$headers = getheaders('http://www.google.com/search?hl=en&q='.urlencode(str_replace("!google\s", '', $msg->message)).'&btnI=I%27m+Feeling+Lucky');
		$irc->send_to_channel("{$msg->user}, {$headers}", $msg->channel);
	}
	
	function calc($msg, $irc)
	{
		$url = file('http://www.google.com/search?q='.urlencode(str_replace("!calc\s", '', $msg->message)).'&calc=1');
		foreach ($url as $line => $str)
		{
			if(preg_match("#.*<td nowrap><font size=\+1><b>(.*)</b></td>.*#iU", $str, $result))
			{
				break;
			}
		}
		$irc->send_to_channel("{$msg->user}, ".@$result[1], $msg->channel);
	}
	
	function spam($msg, $irc)
	{
		$spam = explode('*', str_replace("!spam ", '', $msg->message));
		$number = (int) $spam[1];
		
		for ($i = 1; $i <= $number; $i++)
		{
			$irc->send_to_channel($spam[0], $msg->channel);
			sleep(1);
		}
	}
	
	function morfix($msg, $irc)
	{
		$url = '/default2.asp?q='.urlencode(str_replace("!morfix\s", '', $msg->message)).'';

		$cookie = getheaders("http://milon.morfix.co.il/");
		$cookie = $cookie[9];
		$cookie = str_replace("Set-Cookie: ", '', $cookie);
		$cookie = str_replace("; path=/", '', $cookie);
		
		$socket = fsockopen("milon.morfix.co.il", 80, $errornum, $errorstr, 20);
		$file = '';
		if ($socket)
		{
			$out = "GET ".$url." HTTP/1.0\r\n";
			$out .= "Host: milon.morfix.co.il\r\n";
			$out .= "Cookie: ".$cookie."\r\n";
   			$out .= "\r\n\r\n";
   			fwrite($socket, $out);
   			while (!feof($socket))
   			{
   				$fg = fread($socket, 10240);
   				$file .=  $fg; 
   			}
   			fclose($socket);
		}
		else
		{
			$irc->log("{$errorstr} ({$errornum})");
			exit;
		}
		
		$result = array();
		$nums = 1;
		for($i = 0; $i <= 6; $i++)
		{
			$start = strpos($file, 'OptionH'.$i);
			$end = strpos($file, "MMDiv".$i.".style.visibility='visible'");
			$lenght = $end - $start;
			
			$str = explode("\n", trim(substr($file, $start, $lenght)));
			foreach ($str as $key => $value)
			{
				$str[$key] = '"'.trim(str_replace('"', '', substr($value, strpos($value, '"'), strlen($value)))).'"';
			}
			
			$str = array(@$str[0],@$str[1],@$str[2]);
			$finish = implode(",",$str);
			
			if(strlen(trim(str_replace('"', '', str_replace(",", '', $finish)))) < 3)
			{
				$finish = 0;
			}
			
			if($finish)
			{
				$result[$nums] = $finish;
				$nums++;
			}
		}
		
		if($nums == 1)
		{
			$irc->send_to_channel($msg->user.", I can't find this word.", $msg->channel);
		}
		for($j = 1; $j < $nums; $j++)
		{
			sleep(1);
			if($j < 4)
			{
				$irc->send_to_channel($msg->user.", ".$j.". ".$result[$j], $msg->channel);
			}
			else
			{
				$irc->notice($j.". ".$result[$j], $msg->user);
			}
		}
	}
	
	function join($msg, $irc)
	{
		if ($msg->user == "isoTop" || $msg->user == "dorkiaa")
		{
			$irc->send("JOIN ".str_replace("!join ", '', $msg->message));
		}
	}
	
	function unjoin($msg, $irc)
	{
		if ($msg->user == "dorkiaa")
		{
			$irc->unjoin(preg_replace("/!(unjoin|÷éùúà)\s/", '', $msg->message), $msg->channel);
		}
	}
	
	function admins($msg, $irc)
	{
		$irc->send_to_channel($msg->user.", the admins are "hide@address.com(", ", $msg->admins), $msg->channel);
	}
	
	function addadmin($msg, $irc)
	{
		if(in_array($msg->user, $this->admins))
		{
			$this->admins[] = $msg->linex[1];
			$irc->send_to_channel($msg->user.", the admins now are: "hide@address.com(",", $this->admins), $msg->channel);
		}
		else
		{
			$irc->send_to_channel($msg->user.", you are not admin... Idiot!",$msg->channel);
		}
	}
	
	function deladmin($msg, $irc)
	{
		if(in_array($msg->user, $this->admins))
		{
			if(count($this->admins) > 1)
			{
				if($msg->linex[1] != $msg->user)
				{
					unset($this->admins[array_search($msg->linex[1], $this->admins)]);
						
					$adminstr = implode(",", $this->admins);
					$irc->send_to_channel($msg->user.", the admins now are: "hide@address.com(',', $this->admins), $msg->channel);
				}
				else
				{
					$irc->send_to_channel($msg->user.", you can't delete the last admin!", $msg->channel);
				}
			}
			else
			{
				$irc->send_to_channel($msg->user.", you can't delete yourself, idiot!", $msg->channel);
			}
		}
		else
		{
			$irc->send_to_channel($msg->user.", you are not admin... Idiot!", $msg->channel);
		}
	}
	
	function phpversion($msg, $irc)
	{
		$irc->send_to_channel($msg->user.", I am running on php ".phpversion().".", $msg->channel);
	}
	
	function welcome($msg, $irc)
	{
		$irc->send_to_channel("{$msg->user}, Welcome to {$msg->channel}!", $msg->channel);
	}
	
	function channels($msg, $irc)
	{
		$channels = implode(",", $irc->channels);
		$irc->send_to_channel($msg->user.", I'm in ".$adminstr, $msg->channel);
	}
	
	function infresh($msg, $irc)
	{
		$fresh = file("http://www.fresh.co.il/");
		foreach($fresh as $line => $str)
		{
			if(strstr($str, "online.php?"))
			{
				if(!strstr($str, "class"))
				{
					$irc->send_to_channel($msg->user . ", " . substr($str, strpos($str, "</a>: ") + strlen("</a>: ")), $msg->channel);
				}
			}
		}
		
	}
	
	function op($msg, $irc)
	{
		if(in_array($msg->user, $this->admins))
		{
			$irc->op($msg->linex[0], $msg->user, "give");
		}
		$irc->notice("Welcom in {$msg->user}", $msg->user);
		$irc->send_to_channel("Welcom {$msg->user} to {$msg->channel}", str_replace(":", '', $msg->channel));	
	}
	
	function killme($msg, $irc)
	{
		if(@in_array($msg->user, $this->admins) || $msg->user == "dorkiaa")
		{
			$irc->send_to_channel($msg->user.", I don't like to be killed :(", $msg->channel);
			$irc->quit($msg->user." killed me :-( ");
		}
		else
		{
			$irc->send_to_channel($msg->user.", I'm sorrry, but I can die only if one of my creators will kill me.", $msg->channel);
		}
	}
	
	function raw($msg, $irc)
	{
		if(in_array($msg->user, $this->admins))
		{
			$irc->send(str_replace("!raw", '', $msg->message));
		}
	}
	
	function register($msg, $irc)
	{
		if(in_array($msg->user, $this->admins))
		{
			$irc->send_to_channel("AUTH 1021989", "nickserv");
		}
	}
	
	function mp3($msg, $irc)
	{
		$file = @implode('', file("/tmp/bmpsong"));
		if (@trim($file) != '')
		{
			$irc->send_to_channel($msg->user.", this computer plays ".$file, $msg->channel);
		}
		else
		{
			$irc->send_to_channel($msg->user.", this computer doesn't play anything...");
		}
	}
	
	function games($msg, $irc)
	{
		$start = -1;
		$end = -1;
		$games = array();
		$file = file("http://www.one.co.il/cat/live/ticker.aspx");
		
		foreach($file as $key => $line)
		{
			if(strpos($line, "<span id=Span4"))
			{
				$start = $key;
			}
			if(strpos($line,"<span id=Span3"))
			{
				$end = $key;
			}
		}
		
		foreach($file as $key => $line)
		{
			if($key >= $start && $key <= $end)
			{
				$str[] = $line;
			}
		}
		
		foreach($str as $key => $line)
		{
			if(strpos($line, "javascript:openlive"))
			{
				echo $line;
				$game = array("time" => $str[$key+1], "score" => $str[$key+2],"teams" => $str[$key+3]);
				$game['time'] = substr($game['time'], (strpos($game['time'], "40>")+3), (strpos($game['time'], "<img") + 4)-(strpos($game['time'], "40>")+3));
				$game['time'] = trim(str_replace("<img", '', $game['time']));
				$game['score'] = substr($game['score'], (strpos($game['score'],"center>")+7));
				$game['score'] = trim(str_replace("</td>", '', $game['score']));
				$game['score'] = explode("<br>", $game['score']);
				$game['teams'] = substr($game['teams'], strpos($game['teams'], "Ticker>")+7);
				$game['teams'] = trim(str_replace("</td>", '', $game['teams']));
				$game['teams'] = explode("<br>", $game['teams']);

				$games[] = $game;
			}
		}
		
		foreach($games as $i => $game)
		{
			$irc->send_to_channel(''.$game['teams'][0]." ðâã ".$game['teams'][1]." úåöàä: ".$game['score'][0].":".$game['score'][1]." æîï:".$game['time'], $msg->channel);
		}
	}
	
	function restart($msg, $irc)
	{
		if ($msg->user == "dorkiaa" || $msg->user == "isoTop")
		{
			$irc->restart("Bye Bye, I will be back in a few seconds");
		}
	}
}

echo '<pre style="font-family: Arial; font-size: 14px;">';

$irc = new phpirc();
$irc->connect("irc.fresh.co.il", 6667);
$irc->login("phpirc", "phpirc", "php");
$irc->join(array("#warmth"));

$functions = new functions();

$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!(morfix|îåøôé÷ñ)/i', $functions, 'morfix');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!(restart|àúçì)/i', $functions, 'restart');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!calc/i', $functions, 'calc');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!mp3/i', $functions, 'mp3');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!spam/i', $functions, 'spam');
//$irc->register_action(SMARTIRC_RPL_WELCOME, '/mode/i', $functions, 'mode');
$irc->register_action(SMARTIRC_TYPE_CHANNEL,'/!join/i', $functions, 'join');
$irc->register_action(SMARTIRC_TYPE_CHANNEL,'/!(unjoin|÷éùúà)/i', $functions, 'unjoin');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/^!register/i', $functions, 'register');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!(kill|úîåú)/i', $functions, 'killme');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!(phpversion|âøñä)/i', $functions, 'phpversion');
$irc->register_action(SMARTIRC_TYPE_QUERY, '/!raw/i', $functions, 'raw');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!(fresh|ôøù)/i', $functions, 'infresh');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!games/i', $functions, 'games');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/addadmin/i', $functions, 'addadmin');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/deladmin/i', $functions, 'deladmin');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!admins/i', $functions, 'admins');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!channels/i', $functions, 'channels');
$irc->register_action(SMARTIRC_TYPE_CHANNEL, '/!google/i', $functions, 'google');


$irc->listen();

echo "</pre>";
?>
Return current item: IrControl