1<?php 2/** 3 * whois.class.php 4 * 5 * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the 19 * Free Software Foundation, 51 Franklin St, Fifth Floor, 20 * Boston, MA 02110-1301 USA 21 */ 22 23require_once(dirname(__FILE__)."/../pfccommand.class.php"); 24 25class pfcCommand_whois extends pfcCommand 26{ 27 var $usage = "/whois nickname"; 28 29 function run(&$xml_reponse, $p) 30 { 31 $clientid = $p["clientid"]; 32 $param = $p["param"]; 33 $params = $p["params"]; 34 $sender = $p["sender"]; 35 $recipient = $p["recipient"]; 36 $recipientid = $p["recipientid"]; 37 38 $c =& pfcGlobalConfig::Instance(); 39 $u =& pfcUserConfig::Instance(); 40 $ct =& pfcContainer::Instance(); 41 42 // $xml_reponse->script("trace('".implode(',',$params)."');"); 43 // return; 44 45 // get the nickid from the parameters 46 // if the run command is whois2 then the parameter is a nickid 47 $nickid = ''; 48 if ($this->name == 'whois2') 49 $nickid = $params[0]; 50 else 51 $nickid = $ct->getNickId($params[0]); 52 53 if ($nickid) 54 { 55 $usermeta = $ct->getAllUserMeta($nickid); 56 $usermeta['nickid'] = $nickid; 57 unset($usermeta['cmdtoplay']); // used internaly 58 59 // remove private usermeta from the list if the client is not admin 60 $isadmin = $ct->getUserMeta($u->nickid, 'isadmin'); 61 if (!$isadmin) 62 foreach($c->nickmeta_private as $nmp) 63 unset($usermeta[$nmp]); 64 65 // sort the list 66 $nickmeta_sorted = array(); 67 $order = array_merge(array_diff(array_keys($usermeta),array_keys($c->nickmeta)),array_keys($c->nickmeta)); 68 foreach($order as $o) $nickmeta_sorted[$o] = $usermeta[$o]; 69 $usermeta = $nickmeta_sorted; 70 71 require_once dirname(__FILE__).'/../pfcjson.class.php'; 72 $json = new pfcJSON(); 73 $js = $json->encode($usermeta); 74 $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', ".$js.");"); 75 } 76 else 77 $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ko','".$param."');"); 78 } 79} 80 81?>