1<?php 2/** 3 * log.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 */ 22require_once dirname(__FILE__)."/../pfci18n.class.php"; 23require_once dirname(__FILE__)."/../pfcuserconfig.class.php"; 24require_once dirname(__FILE__)."/../pfcproxycommand.class.php"; 25 26/** 27 * pfcProxyCommand_log 28 * this proxy will log "everything" from the chat 29 * @author Stephane Gully <stephane.gully@gmail.com> 30 */ 31class pfcProxyCommand_log extends pfcProxyCommand 32{ 33 function run(&$xml_reponse, $p) 34 { 35 $cmdtocheck = array("send", "me", "notice"); 36 if ( in_array($this->name, $cmdtocheck) ) 37 { 38 $clientid = $p["clientid"]; 39 $param = $p["param"]; 40 $sender = $p["sender"]; 41 $recipient = $p["recipient"]; 42 $recipientid = $p["recipientid"]; 43 $c =& pfcGlobalConfig::Instance(); 44 $u =& pfcUserConfig::Instance(); 45 46 $logpath = ($c->proxies_cfg[$this->proxyname]["path"] == "" ? $c->data_private_path."/logs" : 47 $c->proxies_cfg[$this->proxyname]["path"]); 48 $logpath .= "/".$c->getId(); 49 50 if (!file_exists($logpath)) @mkdir_r($logpath); 51 if (file_exists($logpath) && is_writable($logpath)) 52 { 53 $logfile = $logpath."/chat.log"; 54 if (is_writable($logpath)) 55 { 56 // @todo write logs in a cleaner structured language (xml, html ... ?) 57 $log = $recipient."\t"; 58 $log .= date("d/m/Y")."\t"; 59 $log .= date("H:i:s")."\t"; 60 $log .= $sender."\t"; 61 $log .= $param."\n"; 62 file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX); 63 } 64 } 65 } 66 67 // forward the command to the next proxy or to the final command 68 return $this->next->run($xml_reponse, $p); 69 } 70} 71 72?>