[Phpfreechat-svn] SF.net SVN: phpfreechat: [953] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-02-15 10:35:44
|
Revision: 953 http://svn.sourceforge.net/phpfreechat/?rev=953&view=rev Author: kerphi Date: 2007-02-15 02:35:45 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Optimisation : use the php5 json module if available Modified Paths: -------------- trunk/src/commands/getnewmsg.class.php trunk/src/commands/who.class.php trunk/src/commands/whois.class.php trunk/src/pfccommand.class.php trunk/src/phpfreechat.class.php trunk/themes/default/chat.js.tpl.php Added Paths: ----------- trunk/src/pfcjson.class.php Modified: trunk/src/commands/getnewmsg.class.php =================================================================== --- trunk/src/commands/getnewmsg.class.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/src/commands/getnewmsg.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -20,7 +20,6 @@ * Boston, MA 02110-1301 USA */ -require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); require_once(dirname(__FILE__)."/../pfccommand.class.php"); class pfcCommand_getnewmsg extends pfcCommand @@ -99,7 +98,8 @@ } if (count($js) != 0) { - $json = new Services_JSON(); + require_once dirname(__FILE__).'/../pfcjson.class.php'; + $json = new pfcJSON(); $js = $json->encode($js); $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', (".$js."));"); } Modified: trunk/src/commands/who.class.php =================================================================== --- trunk/src/commands/who.class.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/src/commands/who.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -62,9 +62,9 @@ $chanmeta['meta']['users']['nick'] = $users['nick']; $chanmeta['meta']['users']['nickid'] = $users['nickid']; - require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); - $json = new Services_JSON(); - $js = $json->encode($chanmeta); + require_once dirname(__FILE__).'/../pfcjson.class.php'; + $json = new pfcJSON(); + $js = $json->encode($chanmeta); return $js; } } Modified: trunk/src/commands/whois.class.php =================================================================== --- trunk/src/commands/whois.class.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/src/commands/whois.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -20,7 +20,6 @@ * Boston, MA 02110-1301 USA */ -require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); require_once(dirname(__FILE__)."/../pfccommand.class.php"); class pfcCommand_whois extends pfcCommand @@ -58,7 +57,8 @@ foreach($order as $o) $nickmeta_sorted[$o] = $usermeta[$o]; $usermeta = $nickmeta_sorted; - $json = new Services_JSON(); + require_once dirname(__FILE__).'/../pfcjson.class.php'; + $json = new pfcJSON(); $js = $json->encode($usermeta); $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', ".$js.");"); } Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/src/pfccommand.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -251,8 +251,8 @@ { if ($data != NULL) { - require_once(dirname(__FILE__)."/../lib/json/JSON.php"); - $json = new Services_JSON(); + require_once dirname(__FILE__).'/pfcjson.class.php'; + $json = new pfcJSON(); $js = $json->encode($data); $xml_reponse->script("trace('".$msg." -> ".$js."');"); } Added: trunk/src/pfcjson.class.php =================================================================== --- trunk/src/pfcjson.class.php (rev 0) +++ trunk/src/pfcjson.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -0,0 +1,53 @@ +<?php +/** + * pfcjson.class.php + * + * Copyright © 2006 Stephane Gully <ste...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +class pfcJSON +{ + var $json = null; + + function pfcJSON() + { + // if the php5-json module is not available, use a software json implementation + if (!function_exists('json_encode')) { + require_once(dirname(__FILE__)."/../lib/json/JSON.php"); + $this->json = new Services_JSON(); + } + } + + function encode($v) + { + if ($this->json) + return $this->json->encode($v); + else + return json_encode($v); + } + + function decode($v) + { + if ($this->json) + return $this->json->decode($v); + else + return json_decode($v); + } +} + +?> \ No newline at end of file Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/src/phpfreechat.class.php 2007-02-15 10:35:45 UTC (rev 953) @@ -423,10 +423,10 @@ $c =& pfcGlobalConfig::Instance(); $js = ''; - - require_once(dirname(__FILE__)."/../lib/json/JSON.php"); - $json = new Services_JSON(); + require_once dirname(__FILE__).'/pfcjson.class.php'; + $json = new pfcJSON(); + $labels_to_load = array( "Do you really want to leave this room ?", // _pfc "Hide nickname marker", // _pfc Modified: trunk/themes/default/chat.js.tpl.php =================================================================== --- trunk/themes/default/chat.js.tpl.php 2007-02-15 08:40:35 UTC (rev 952) +++ trunk/themes/default/chat.js.tpl.php 2007-02-15 10:35:45 UTC (rev 953) @@ -12,8 +12,8 @@ <script type="text/javascript"> // <![CDATA[ <?php -require_once(dirname(__FILE__)."/../../lib/json/JSON.php"); -$json = new Services_JSON(); +require_once dirname(__FILE__).'/../../src/pfcjson.class.php'; +$json = new pfcJSON(); ?> <?php $nick = $u->nick != "" ? $json->encode($u->nick) : $json->encode($c->nick); ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |