- Code: Select all
<?php
//topic.class.php
require_once(dirname(__FILE__)."/../pfccommand.class.php");
class pfcCommand_topic extends pfcCommand
{
var $usage = "/topic {message}";
function run(&$xml_reponse, $p)
{
$clientid = $p["clientid"];
$param = $p["param"];
$sender = $p["sender"];
$recipient = $p["recipient"];
$recipientid = $p["recipientid"];
$c =& pfcGlobalConfig::Instance();
$u =& pfcUserConfig::Instance();
$ct =& pfcContainer::Instance();
if (trim($param) == "")
{
$fh = @fopen('topic.dat', 'r+');
$topic = @fread($fh, filesize('topic.dat'));
fclose($fh);
$ct->write($recipient, "*topic*", $this->name, "current topic: [i][u]".$topic."[/i][/u]");
return;
}
$msg = phpFreeChat::PreFilterMsg($param);
$ct->write($recipient, "*topic*", $this->name, $u->getNickname()." changes the topic to: [i][u]".$msg."[/i][/u]");
// Write out the topic data
$fh = @fopen('topic.dat', 'r+');
$topic = @fread($fh, filesize('topic.dat'));
if ($topic == $msg."n"){
fclose($fh);
die(0);
}else{
@fclose($fh); // if it errors, then the file doesn't exist, and the stream was never open
$fh = fopen('topic.dat', 'w');
fwrite($fh, $msg."n");
}
fclose($fh);
}
}
?>
One problem is, I cannot seem to figure out away to only allow admins or operators access to change the topic.
Now for the template hack (default)
replace this:
- Code: Select all
<h2 id="pfc_title"><?php echo $title; ?></h2>
with this:
- Code: Select all
<?php
$fh = @fopen('topic.dat', 'r+');
$topic = @fread($fh, filesize('topic.dat'));
fclose($fh);
?>
<h2 id="pfc_title"><?php echo $topic; ?></h2>
The problem is, I'm just learning ajax, I am unsure how to have this piece of code refresh w/o refreshing the whole page.
Hopefully someone with knowledge will step in and help out..