[Phpfreechat-svn] SF.net SVN: phpfreechat: [641] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-07-04 15:34:08
|
Revision: 641 Author: kerphi Date: 2006-07-04 08:33:50 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=641&view=rev Log Message: ----------- Finish the work on the API used to query the chat infos from external scripts Modified Paths: -------------- trunk/demo/demo32_show_last_messages-chat.php trunk/demo/demo32_show_last_messages-config.php trunk/demo/demo32_show_last_messages-showlastmsg.php trunk/src/pfcglobalconfig.class.php trunk/src/pfcinfo.class.php Modified: trunk/demo/demo32_show_last_messages-chat.php =================================================================== --- trunk/demo/demo32_show_last_messages-chat.php 2006-07-03 16:43:41 UTC (rev 640) +++ trunk/demo/demo32_show_last_messages-chat.php 2006-07-04 15:33:50 UTC (rev 641) @@ -1,10 +1,8 @@ <?php require_once dirname(__FILE__)."/../src/phpfreechat.class.php"; -$params["serverid"] = md5("Show last messages demo"); // calculate a unique id for this chat -$params["title"] = "Show last posted messages channel"; -//$params["max_msg"] = 1; -$chat = new phpFreeChat($params); +require_once dirname(__FILE__)."/demo32_show_last_messages-config.php"; +$chat = new phpFreeChat($pfc_config); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> @@ -40,4 +38,4 @@ ?> </body> -</html> +</html> \ No newline at end of file Modified: trunk/demo/demo32_show_last_messages-config.php =================================================================== --- trunk/demo/demo32_show_last_messages-config.php 2006-07-03 16:43:41 UTC (rev 640) +++ trunk/demo/demo32_show_last_messages-config.php 2006-07-04 15:33:50 UTC (rev 641) @@ -4,7 +4,7 @@ $params["title"] = "Show last posted messages channel"; $params["serverid"] = md5($params["title"]); // calculate a unique id for this chat $params["max_msg"] = 20; -$params["channels"] = "channel1"; +$params["channels"] = array("channel1"); $pfc_config =& pfcGlobalConfig::Instance( $params ); ?> \ No newline at end of file Modified: trunk/demo/demo32_show_last_messages-showlastmsg.php =================================================================== --- trunk/demo/demo32_show_last_messages-showlastmsg.php 2006-07-03 16:43:41 UTC (rev 640) +++ trunk/demo/demo32_show_last_messages-showlastmsg.php 2006-07-04 15:33:50 UTC (rev 641) @@ -1,27 +1,32 @@ <?php require_once dirname(__FILE__)."/../src/pfcinfo.class.php"; -$info = new pfcInfo( md5("Show last posted messages channel") ); -$lastmsg_raw = $info->getLastMsg("channel1", 10); -print_r($lastmsg_raw); +$pfcinfo = new pfcInfo( md5("Show last posted messages channel") ); +$errors = $pfcinfo->getErrors(); +if (count($errors)) +{ + foreach($errors as $e) + echo $e; +} +$lastmsg_raw = $pfcinfo->getLastMsg("channel1", 10); -echo "<h1>A demo which explains how to get the last posted messages</h1>"; +echo "<h1>A demo which explains how to get the last posted messages on a given channel</h1>"; echo '<div style="margin: auto; width: 70%; border: 1px solid red; background-color: #FDD; padding: 1em;">'; -$nbmsg = count($lastmsg_raw["messages"]); -$info = "<strong>%d</strong> last messages on <strong>'%s'</strong> channel are:"; -echo "<p>".sprintf($info, $nbmsg, "")."</p>"; +$nbmsg = count($lastmsg_raw["data"]); +$info = "<strong>%d</strong> last messages on <strong>'%s'</strong> are:"; +echo "<p>".sprintf($info, $nbmsg, "channel1")."</p>"; $bg = 1; echo '<table style="margin: auto; width: 70%; border: 1px solid red; background-color: #FEE;">'; // format messages to a readable string // be carreful ! this format will change in future -foreach($lastmsg_raw["messages"] as $m) +foreach($lastmsg_raw["data"] as $m) { - echo '<tr style="background-color: '.($bg == 1 ? "#FFE;" : "#EEF;").'">'; - echo '<td>'.$m[2].'</td>'; - echo '<td style="color:#F75; text-align: right;">'.$m[3].'</td>'; - echo "<td>".$m[4]."</td>"; + echo '<tr style="background-color:'.($bg == 1 ? "#FFE;" : "#EEF;").'">'; + echo '<td style="width:100px;">'.$m["date"].'</td>'; + echo '<td style="width:80px;color:#F55;text-align:right;font-weight:bold;">'.$m["sender"].'</td>'; + echo '<td>'.$m["param"].'</td>'; echo "</tr>"; if ($bg == 1) $bg = 2; Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-07-03 16:43:41 UTC (rev 640) +++ trunk/src/pfcglobalconfig.class.php 2006-07-04 15:33:50 UTC (rev 641) @@ -103,6 +103,21 @@ // setup the local for translated messages pfcI18N::Init(isset($params["language"]) ? $params["language"] : ""); + // check the serverid is really defined + if (!isset($params["serverid"])) + $this->errors[] = _pfc("'%s' parameter is mandatory by default use '%s' value", "serverid", "md5(__FILE__)"); + $this->serverid = $params["serverid"]; + + // _getCacheFile needs data_private_path + if (!isset($params["data_private_path"])) + $this->data_private_path = dirname(__FILE__)."/../data/private"; + else + $this->data_private_path = $params["data_private_path"]; + if (!isset($params["data_public_path"])) + $this->data_public_path = dirname(__FILE__)."/../data/public"; + else + $this->data_public_path = $params["data_public_path"]; + // check if a cached configuration allready exists // don't load parameters if the cache exists $cachefile = $this->_getCacheFile(); @@ -136,9 +151,6 @@ else $this->$k = $v; } - - if ($this->data_private_path == "") $this->data_private_path = dirname(__FILE__)."/../data/private"; - if ($this->data_public_path == "") $this->data_public_path = dirname(__FILE__)."/../data/public"; } // now load or save the configuration in the cache @@ -325,10 +337,6 @@ // load debug url $this->debugurl = relativePath($this->client_script_path, dirname(__FILE__)."/../debug"); - // check the serverid is really defined - if ($this->serverid == "") - $this->errors[] = _pfc("'%s' parameter is mandatory by default use '%s' value", "serverid", "md5(__FILE__)"); - // check if channels parameter is a strings array if (!is_array($this->channels)) $this->errors[] = _pfc("'%s' parameter must be an array", "channels"); @@ -414,9 +422,11 @@ return $this->serverid; } - function _getCacheFile() + function _getCacheFile($serverid = "", $data_private_path = "") { - return $this->data_private_path."/cache/pfcglobalconfig_".$this->getId(); + if ($serverid == "") $serverid = $this->getId(); + if ($data_private_path == "") $data_private_path = $this->data_private_path; + return $data_private_path."/cache/pfcglobalconfig_".$serverid; } function destroyCache() Modified: trunk/src/pfcinfo.class.php =================================================================== --- trunk/src/pfcinfo.class.php 2006-07-03 16:43:41 UTC (rev 640) +++ trunk/src/pfcinfo.class.php 2006-07-04 15:33:50 UTC (rev 641) @@ -1,20 +1,41 @@ <?php require_once dirname(__FILE__)."/pfcglobalconfig.class.php"; +require_once dirname(__FILE__)."/pfci18n.class.php"; +require_once dirname(__FILE__)."/commands/join.class.php"; class pfcInfo extends pfcGlobalConfig { var $container; + var $errors = array(); - function pfcInfo( $serverid ) + function pfcInfo( $serverid, $data_private_path = "" ) { - $cachefile = dirname(__FILE__)."/../data/private/cache/pfcglobalconfig_".$serverid; - $pfc_configvar = unserialize(file_get_contents($cachefile)); - foreach($pfc_configvar as $key => $val) - $this->$key = $val; + // check if the cache allready exists + // if it doesn't exists, just stop the process + // because we can't initialize the chat from the external API + if ($data_private_path == "") $data_private_path = dirname(__FILE__)."/../data/private"; + $cachefile = $this->_getCacheFile( $serverid, $data_private_path ); + if (!file_exists($cachefile)) + { + $this->errors[] = _pfc("Error: the cached config file doesn't exists"); + return; + } + // then intitialize the pfcglobalconfig + $params["serverid"] = $serverid; + $params["data_private_path"] = $data_private_path; + pfcGlobalConfig::pfcGlobalConfig($params); } - + /** + * @return array(string) a list of errors + */ + function getErrors() + { + return $this->errors; + } + + /** * @return array(string) a list of online nicknames */ function getOnlineNick($channel = NULL) @@ -30,13 +51,15 @@ function getLastMsg($channel, $nb) { - $container =& $this->getContainerInstance(); + // to get the channel recipient name + // @todo must use another function to get a private message last messages + $channel = pfcCommand_join::GetRecipient($channel); + + $container =& $this->getContainerInstance(); $lastmsg_id = $container->getLastId($channel); - echo $lastmsg_id; - die(); $lastmsg_raw = $container->read($channel, $lastmsg_id-10); return $lastmsg_raw; } } -?> +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |