1<?php 2 3require_once dirname(__FILE__)."/pfcglobalconfig.class.php"; 4require_once dirname(__FILE__)."/pfci18n.class.php"; 5require_once dirname(__FILE__)."/commands/join.class.php"; 6 7class pfcInfo 8{ 9 var $c = null; 10 var $errors = array(); 11 12 function pfcInfo( $serverid, $data_private_path = "" ) 13 { 14 // check if the cache already exists 15 // if it doesn't exists, just stop the process 16 // because we can't initialize the chat from the external API 17 if ($data_private_path == "") $data_private_path = dirname(__FILE__)."/../data/private"; 18 $cachefile = pfcGlobalConfig::_GetCacheFile( $serverid, $data_private_path ); 19 if (!file_exists($cachefile)) 20 { 21 $this->errors[] = _pfc("Error: the cached config file doesn't exists"); 22 return; 23 } 24 // then intitialize the pfcglobalconfig 25 $params = array(); 26 $params["serverid"] = $serverid; 27 $params["data_private_path"] = $data_private_path; 28 $this->c =& pfcGlobalConfig::Instance($params); 29 } 30 31 function free() 32 { 33 // free the pfcglobalconfig instance 34 pfcGlobalConfig::Instance(array(), true); 35 } 36 37 /** 38 * @return array(string) a list of errors 39 */ 40 function getErrors() 41 { 42 if ($this->c != null) 43 return array_merge($this->errors, $this->c->getErrors()); 44 else 45 return $this->errors; 46 } 47 function hasErrors() 48 { 49 return count($this->getErrors()) > 0; 50 } 51 52 /** 53 * @param $channel the returned list is the list of nicknames present on the given channel (NULL for the whole server) 54 * @param $timeout is the time to wait before a nickname is considered offline 55 * @return array(string) a list of online nicknames 56 */ 57 function getOnlineNick($channel = NULL, $timeout = 20) 58 { 59 if ($this->hasErrors()) return array(); 60 61 $ct =& pfcContainer::Instance(); 62 63 if ($channel != NULL) $channel = pfcCommand_join::GetRecipient($channel); 64 65 $res = $ct->getOnlineNick($channel); 66 $users = array(); 67 if (isset($res["nickid"])) 68 { 69 for($i = 0; $i < count($res["nickid"]); $i++) 70 { 71 if (time()-$timeout < $res["timestamp"][$i]) 72 $users[] = $ct->getNickname($res["nickid"][$i]); 73 } 74 } 75 return $users; 76 } 77 78 /** 79 * Return the last $nb message from the $channel room. 80 * The messages format is very basic, it's raw data (it will certainly change in future) 81 */ 82 function getLastMsg($channel, $nb) 83 { 84 if ($this->hasErrors()) return array(); 85 86 // to be sure the $nb params is a positive number 87 if ( !( $nb >= 0 ) ) $nb = 10; 88 89 // to get the channel recipient name 90 // @todo must use another function to get a private message last messages 91 $channel = pfcCommand_join::GetRecipient($channel); 92 93 $ct =& pfcContainer::Instance(); 94 $lastmsg_id = $ct->getLastId($channel); 95 $lastmsg_raw = $ct->read($channel, $lastmsg_id-$nb); 96 return $lastmsg_raw; 97 } 98 99 /** 100 * Rehash the server config (same as /rehash command) 101 * Usefull to take into account new server's parameters 102 */ 103 function rehash() 104 { 105 if ($this->hasErrors()) return false; 106 107 $destroyed = $this->c->destroyCache(); 108 return $destroyed; 109 } 110} 111 112?>