TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Channel.php 2/18/2012 12:42:46 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Node_Channel 00030 * @brief Class describing a TeamSpeak 3 channel and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Channel extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * The TeamSpeak3_Node_Channel constructor. 00036 * 00037 * @param TeamSpeak3_Node_Server $server 00038 * @param array $info 00039 * @param string $index 00040 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00041 * @return TeamSpeak3_Node_Channel 00042 */ 00043 public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cid") 00044 { 00045 $this->parent = $server; 00046 $this->nodeInfo = $info; 00047 00048 if(!array_key_exists($index, $this->nodeInfo)) 00049 { 00050 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300); 00051 } 00052 00053 $this->nodeId = $this->nodeInfo[$index]; 00054 } 00055 00056 /** 00057 * Returns an array filled with TeamSpeak3_Node_Channel objects. 00058 * 00059 * @param array $filter 00060 * @return array 00061 */ 00062 public function subChannelList(array $filter = array()) 00063 { 00064 $channels = array(); 00065 00066 foreach($this->getParent()->channelList() as $channel) 00067 { 00068 if($channel["pid"] == $this->getId()) 00069 { 00070 $channels[$channel->getId()] = $channel; 00071 } 00072 } 00073 00074 return $this->filterList($channels, $filter); 00075 } 00076 00077 /** 00078 * Returns the TeamSpeak3_Node_Channel object matching the given ID. 00079 * 00080 * @param integer $cid 00081 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00082 * @return TeamSpeak3_Node_Channel 00083 */ 00084 public function subChannelGetById($cid) 00085 { 00086 if(!array_key_exists((string) $cid, $this->subChannelList())) 00087 { 00088 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300); 00089 } 00090 00091 return $this->channelList[(string) $cid]; 00092 } 00093 00094 /** 00095 * Returns the TeamSpeak3_Node_Channel object matching the given name. 00096 * 00097 * @param integer $name 00098 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00099 * @return TeamSpeak3_Node_Channel 00100 */ 00101 public function subChannelGetByName($name) 00102 { 00103 foreach($this->subChannelList() as $channel) 00104 { 00105 if($channel["channel_name"] == $name) return $channel; 00106 } 00107 00108 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300); 00109 } 00110 00111 /** 00112 * Returns an array filled with TeamSpeak3_Node_Client objects. 00113 * 00114 * @param array $filter 00115 * @return array 00116 */ 00117 public function clientList(array $filter = array()) 00118 { 00119 $clients = array(); 00120 00121 foreach($this->getParent()->clientList() as $client) 00122 { 00123 if($client["cid"] == $this->getId()) 00124 { 00125 $clients[$client->getId()] = $client; 00126 } 00127 } 00128 00129 return $this->filterList($clients, $filter); 00130 } 00131 00132 /** 00133 * Returns the TeamSpeak3_Node_Client object matching the given ID. 00134 * 00135 * @param integer $clid 00136 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00137 * @return TeamSpeak3_Node_Client 00138 */ 00139 public function clientGetById($clid) 00140 { 00141 if(!array_key_exists($clid, $this->clientList())) 00142 { 00143 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00144 } 00145 00146 return $this->clientList[intval($clid)]; 00147 } 00148 00149 /** 00150 * Returns the TeamSpeak3_Node_Client object matching the given name. 00151 * 00152 * @param integer $name 00153 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00154 * @return TeamSpeak3_Node_Client 00155 */ 00156 public function clientGetByName($name) 00157 { 00158 foreach($this->clientList() as $client) 00159 { 00160 if($client["client_nickname"] == $name) return $client; 00161 } 00162 00163 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00164 } 00165 00166 /** 00167 * Returns a list of permissions defined for a client in the channel. 00168 * 00169 * @param integer $cldbid 00170 * @param boolean $permsid 00171 * @return void 00172 */ 00173 public function clientPermList($cldbid, $permsid = FALSE) 00174 { 00175 return $this->getParent()->channelClientPermList($this->getId(), $cldbid, $permsid); 00176 } 00177 00178 /** 00179 * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by 00180 * providing the two parameters of each permission. 00181 * 00182 * @param integer $cldbid 00183 * @param integer $permid 00184 * @param integer $permvalue 00185 * @return void 00186 */ 00187 public function clientPermAssign($cldbid, $permid, $permvalue) 00188 { 00189 return $this->getParent()->channelClientPermAssign($this->getId(), $cldbid, $permid, $permvalue); 00190 } 00191 00192 /** 00193 * Alias for clientPermAssign(). 00194 * 00195 * @deprecated 00196 */ 00197 public function clientPermAssignByName($cldbid, $permname, $permvalue) 00198 { 00199 return $this->clientPermAssign($cldbid, $permname, $permvalue); 00200 } 00201 00202 /** 00203 * Removes a set of specified permissions from a client in the channel. Multiple permissions can be removed at once. 00204 * 00205 * @param integer $cldbid 00206 * @param integer $permid 00207 * @return void 00208 */ 00209 public function clientPermRemove($cldbid, $permid) 00210 { 00211 return $this->getParent()->channelClientPermRemove($this->getId(), $cldbid, $permid); 00212 } 00213 00214 /** 00215 * Alias for clientPermRemove(). 00216 * 00217 * @deprecated 00218 */ 00219 public function clientPermRemoveByName($cldbid, $permname) 00220 { 00221 return $this->clientPermRemove($cldbid, $permname); 00222 } 00223 00224 /** 00225 * Returns a list of permissions defined for the channel. 00226 * 00227 * @param boolean $permsid 00228 * @return array 00229 */ 00230 public function permList($permsid = FALSE) 00231 { 00232 return $this->getParent()->channelPermList($this->getId(), $permsid); 00233 } 00234 00235 /** 00236 * Adds a set of specified permissions to the channel. Multiple permissions can be added by 00237 * providing the two parameters of each permission. 00238 * 00239 * @param integer $permid 00240 * @param integer $permvalue 00241 * @return void 00242 */ 00243 public function permAssign($permid, $permvalue) 00244 { 00245 return $this->getParent()->channelPermAssign($this->getId(), $permid, $permvalue); 00246 } 00247 00248 /** 00249 * Alias for permAssign(). 00250 * 00251 * @deprecated 00252 */ 00253 public function permAssignByName($permname, $permvalue) 00254 { 00255 return $this->permAssign($permname, $permvalue); 00256 } 00257 00258 /** 00259 * Removes a set of specified permissions from the channel. Multiple permissions can be removed at once. 00260 * 00261 * @param integer $permid 00262 * @return void 00263 */ 00264 public function permRemove($permid) 00265 { 00266 return $this->getParent()->channelPermRemove($this->getId(), $permid); 00267 } 00268 00269 /** 00270 * Alias for permRemove(). 00271 * 00272 * @deprecated 00273 */ 00274 public function permRemoveByName($permname) 00275 { 00276 return $this->permRemove($permname); 00277 } 00278 00279 /** 00280 * Returns a list of files and directories stored in the channels file repository. 00281 * 00282 * @param string $cpw 00283 * @param string $path 00284 * @param boolean $recursive 00285 * @return void 00286 */ 00287 public function fileList($cpw = "", $path = "/", $recursive = FALSE) 00288 { 00289 return $this->getParent()->channelFileList($this->getId(), $cpw, $path, $recursive); 00290 } 00291 00292 /** 00293 * Returns detailed information about the specified file stored in the channels file repository. 00294 * 00295 * @param string $cpw 00296 * @param string $name 00297 * @return array 00298 */ 00299 public function fileInfo($cpw = "", $name = "/") 00300 { 00301 return $this->getParent()->channelFileInfo($this->getId(), $cpw, $name); 00302 } 00303 00304 /** 00305 * Renames a file in the channels file repository. If the two parameters $tcid and $tcpw are specified, the file 00306 * will be moved into another channels file repository. 00307 * 00308 * @param string $cpw 00309 * @param string $oldname 00310 * @param string $newname 00311 * @param integer $tcid 00312 * @param string $tcpw 00313 * @return void 00314 */ 00315 public function fileRename($cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null) 00316 { 00317 return $this->getParent()->channelFileRename($this->getId(), $cpw, $oldname, $newname, $tcid, $tcpw); 00318 } 00319 00320 /** 00321 * Deletes one or more files stored in the channels file repository. 00322 * 00323 * @param string $cpw 00324 * @param string $path 00325 * @return void 00326 */ 00327 public function fileDelete($cpw = "", $name = "/") 00328 { 00329 return $this->getParent()->channelFileDelete($this->getId(), $cpw, $name); 00330 } 00331 00332 /** 00333 * Creates new directory in a channels file repository. 00334 * 00335 * @param string $cpw 00336 * @param string $dirname 00337 * @return void 00338 */ 00339 public function dirCreate($cpw = "", $dirname = "/") 00340 { 00341 return $this->getParent()->channelDirCreate($this->getId(), $cpw, $dirname); 00342 } 00343 00344 /** 00345 * Returns the level of the channel. 00346 * 00347 * @return integer 00348 */ 00349 public function getLevel() 00350 { 00351 return $this->getParent()->channelGetLevel($this->getId()); 00352 } 00353 00354 /** 00355 * Returns the pathway of the channel which can be used as a clients default channel. 00356 * 00357 * @return string 00358 */ 00359 public function getPathway() 00360 { 00361 return $this->getParent()->channelGetPathway($this->getId()); 00362 } 00363 00364 /** 00365 * Returns the possible spacer type of the channel. 00366 * 00367 * @return integer 00368 */ 00369 public function spacerGetType() 00370 { 00371 return $this->getParent()->channelSpacerGetType($this->getId()); 00372 } 00373 00374 /** 00375 * Returns the possible spacer alignment of the channel. 00376 * 00377 * @return integer 00378 */ 00379 public function spacerGetAlign() 00380 { 00381 return $this->getParent()->channelSpacerGetAlign($this->getId()); 00382 } 00383 00384 /** 00385 * Returns TRUE if the channel is a spacer. 00386 * 00387 * @return boolean 00388 */ 00389 public function isSpacer() 00390 { 00391 return $this->getParent()->channelIsSpacer($this); 00392 } 00393 00394 /** 00395 * Downloads and returns the channels icon file content. 00396 * 00397 * @return TeamSpeak3_Helper_String 00398 */ 00399 public function iconDownload() 00400 { 00401 if($this->iconIsLocal("channel_icon_id") || $this["channel_icon_id"] == 0) return; 00402 00403 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("channel_icon_id")); 00404 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 00405 00406 return $transfer->download($download["ftkey"], $download["size"]); 00407 } 00408 00409 /** 00410 * Changes the channel configuration using given properties. 00411 * 00412 * @param array $properties 00413 * @return void 00414 */ 00415 public function modify(array $properties) 00416 { 00417 $properties["cid"] = $this->getId(); 00418 00419 $this->execute("channeledit", $properties); 00420 $this->resetNodeInfo(); 00421 } 00422 00423 /** 00424 * Sends a text message to all clients in the channel. 00425 * 00426 * @param string $msg 00427 * @param string $cpw 00428 * @return void 00429 */ 00430 public function message($msg, $cpw = null) 00431 { 00432 if($this->getId() != $this->getParent()->whoamiGet("client_channel_id")) 00433 { 00434 $this->getParent()->clientMove($this->getParent()->whoamiGet("client_id"), $this->getId(), $cpw); 00435 } 00436 00437 $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CHANNEL)); 00438 } 00439 00440 /** 00441 * Deletes the channel. 00442 * 00443 * @param boolean $force 00444 * @return void 00445 */ 00446 public function delete($force = FALSE) 00447 { 00448 $this->getParent()->channelDelete($this->getId(), $force); 00449 00450 unset($this); 00451 } 00452 00453 /** 00454 * Moves the channel to the parent channel specified with $pid. 00455 * 00456 * @param integer $pid 00457 * @param integer $order 00458 * @return void 00459 */ 00460 public function move($pid, $order = null) 00461 { 00462 $this->getParent()->channelMove($this->getId(), $pid, $order); 00463 } 00464 00465 /** 00466 * @ignore 00467 */ 00468 protected function fetchNodeList() 00469 { 00470 $this->nodeList = array(); 00471 00472 if($this->getParent()->getLoadClientlistFirst()) 00473 { 00474 foreach($this->clientList() as $client) 00475 { 00476 if($client["cid"] == $this->getId()) 00477 { 00478 $this->nodeList[] = $client; 00479 } 00480 } 00481 00482 foreach($this->subChannelList() as $channel) 00483 { 00484 if($channel["pid"] == $this->getId()) 00485 { 00486 $this->nodeList[] = $channel; 00487 } 00488 } 00489 } 00490 else 00491 { 00492 foreach($this->subChannelList() as $channel) 00493 { 00494 if($channel["pid"] == $this->getId()) 00495 { 00496 $this->nodeList[] = $channel; 00497 } 00498 } 00499 00500 foreach($this->clientList() as $client) 00501 { 00502 if($client["cid"] == $this->getId()) 00503 { 00504 $this->nodeList[] = $client; 00505 } 00506 } 00507 } 00508 } 00509 00510 /** 00511 * @ignore 00512 */ 00513 protected function fetchNodeInfo() 00514 { 00515 $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("channelinfo", array("cid" => $this->getId()))->toList()); 00516 } 00517 00518 /** 00519 * Returns a unique identifier for the node which can be used as a HTML property. 00520 * 00521 * @return string 00522 */ 00523 public function getUniqueId() 00524 { 00525 return $this->getParent()->getUniqueId() . "_ch" . $this->getId(); 00526 } 00527 00528 /** 00529 * Returns the name of a possible icon to display the node object. 00530 * 00531 * @return string 00532 */ 00533 public function getIcon() 00534 { 00535 if($this["channel_maxclients"] != -1 && $this["channel_maxclients"] <= $this["total_clients"]) 00536 { 00537 return "channel_full"; 00538 } 00539 elseif($this["channel_flag_password"]) 00540 { 00541 return "channel_pass"; 00542 } 00543 else 00544 { 00545 return "channel_open"; 00546 } 00547 } 00548 00549 /** 00550 * Returns a symbol representing the node. 00551 * 00552 * @return string 00553 */ 00554 public function getSymbol() 00555 { 00556 return "#"; 00557 } 00558 00559 /** 00560 * Returns a string representation of this node. 00561 * 00562 * @return string 00563 */ 00564 public function __toString() 00565 { 00566 return (string) $this["channel_name"]; 00567 } 00568 } 00569