function index() { App::import('Vendor', 'phpFreeChat', array('file' => 'phpfreechat' . DS . 'src' . DS . 'phpfreechat.class.php')); Configure::write('debug', '0'); $this->layout = '2col_layout'; $this->Group->id = $this->ZTAuth->user('group_id'); $group = $this->Group->read(); $params["serverid"] = md5(__FILE__); $params["theme"] = "animated"; $params["theme_url"] = 'vendors/phpfreechat/themes/'; $params["data_public_url"] = 'vendors/phpfreechat/data/public'; $params["theme"] = 'msn'; $params["language"] = 'ru_RU'; $params["display_pfc_logo"] = false; $params["title"] = 'Бумер чат'; $params["nick"] = $this->ZTAuth->user('username'); $params["isadmin"] = $this->isAuthorized($this->ZTAuth->user('username'), $this->name, 'admin'); $params["nickmeta"] = array('Статус' => $group['Group']['user_status']); $params["nickmarker"] = false; $params["frozen_nick"] = true; // $params["debug"] = true; // $params["server_script_path"] = '../../vendors/phpfreechat/chat.php'; $chat = new phpFreeChat($params); $this->set('chat', $chat->printChat(true)); }
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(); $nicktochange = phpFreeChat::FilterNickname($param); if ($c->frozen_nick) { // assign a random nick $cmdp = $p; $cmdp["param"] = $nicktochange . "" . rand(1, 1000); $cmd =& pfcCommand::Factory("nick"); $cmd->run($xml_reponse, $cmdp); } else { if ($nicktochange == "") { $nicktochange = $u->nick; $msg = _pfc("Please enter your nickname"); } else { $msg = "'" . $nicktochange . "' is used, please choose another nickname."; } $xml_reponse->script("var newnick = prompt('" . addslashes($msg) . "', '" . addslashes($nicktochange) . "'); if (newnick) pfc.sendRequest('/nick \"'+newnick+'\"');"); } }
function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $msg = $p["param"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $flag = isset($p["flag"]) ? $p["flag"] : 7; $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); if ($c->shownotice > 0 && ($c->shownotice & $flag) == $flag) { $msg = phpFreeChat::FilterSpecialChar($msg); $msg = $flag == 7 ? '(' . $sender . ') ' . $msg : $msg; $nick = $ct->getNickname($u->nickid); $res = $ct->write($recipient, $nick, "notice", $msg); if (is_array($res)) { $cmdp = $p; $cmdp["param"] = implode(",", $res); $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); return; } } }
function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $owner = isset($p["owner"]) ? $p["owner"] : ''; $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); $newnick = phpFreeChat::FilterNickname($param); $oldnick = $ct->getNickname($u->nickid); if ($this->name == 'nick') { // if the user want to change his nickname but the frozen_nick is enable // then send him a warning if ($this->name == 'nick' && $oldnick != '' && $newnick != $oldnick && $c->frozen_nick == true && $owner != $this->proxyname) { $msg = _pfc("You are not allowed to change your nickname"); $xml_reponse->script("pfc.handleResponse('" . $this->proxyname . "', 'nick', '" . addslashes($msg) . "');"); return false; } $newnickid = $ct->getNickId($newnick); $oldnickid = $u->nickid; if ($newnick == $oldnick && $newnickid == $oldnickid) { $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'notchanged', '" . addslashes($newnick) . "');"); return true; } // now check the nickname is not yet used (unsensitive case) // 'BoB' and 'bob' must be considered same nicknames $nick_in_use = $this->_checkNickIsUsed($newnick, $oldnickid); if ($nick_in_use) { if ($c->frozen_nick) { $xml_reponse->script("pfc.handleResponse('nick', 'notallowed', '" . addslashes($newnick) . "');"); } else { $xml_reponse->script("pfc.handleResponse('nick', 'isused', '" . addslashes($newnick) . "');"); } return false; } } // allow nick changes only from the parameters array (server side) if ($this->name != 'connect' && $c->frozen_nick == true && $oldnick != $c->nick && $c->nick != '' && $owner != $this->proxyname) { // change the user nickname $cmdp = $p; $cmdp["param"] = $c->nick; $cmdp["owner"] = $this->proxyname; $cmd =& pfcCommand::Factory("nick"); return $cmd->run($xml_reponse, $cmdp); } // forward the command to the next proxy or to the final command return $this->next->run($xml_reponse, $p); }
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) == "") { // error $cmdp = $p; $cmdp["param"] = _pfc("Missing parameter"); $cmdp["param"] .= " (" . $this->usage . ")"; $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); return; } $msg = phpFreeChat::PreFilterMsg($param); $ct->write($recipient, "*me*", $this->name, $u->getNickname() . " " . $msg); }
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(); $nick = $u->getNickname(); $text_src = phpFreeChat::PreFilterMsg(trim($param)); $text_src = str_replace(" ", "", $text_src); try { $p = new Parser($text_src); $p->setDebug($ct, $nick, $recipient); $ov = $p->Parse(); $text = $nick . " : " . $text_src . " >> " . $ov->str . " = " . $ov->val; } catch (Exception $e) { $text = "Error: " . $e->getMessage(); } $ct->write($recipient, $nick, "send", $text); }
<?php require_once dirname(__FILE__) . "/../src/phpfreechat.class.php"; $params["serverid"] = md5(__FILE__); // calculate a unique id for this chat $params["language"] = "hy_AM"; $chat = new phpFreeChat($params); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>phpFreeChat demo</title> <?php $chat->printJavascript(); ?> <?php $chat->printStyle(); ?> </head> <body> <?php $chat->printChat(); ?> <?php // print the current file echo "<h2>The source code</h2>";
<?php require_once dirname(__FILE__) . "/../src/phpfreechat.class.php"; $params["serverid"] = md5(__FILE__); // calculate a unique id for this chat //echo "<pre>";print_r($params);exit; $chat = new phpFreeChat($params); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>phpFreeChat demo</title> </head> <body> <?php $chat->printChat(); ?> <?php // print the current file echo "<h2>The source code</h2>"; $filename = __FILE__; echo "<p><code>" . $filename . "</code></p>"; echo "<pre style=\"margin: 0 50px 0 50px; padding: 10px; background-color: #DDD;\">"; $content = file_get_contents($filename); highlight_string($content); echo "</pre>";
</div> <div id="pfc_input_container"> <table style="margin:0;padding:0;border-collapse:collapse;"> <tbody> <tr> <td class="pfc_td1"> <p id="pfc_handle" <?php if (!$frozen_nick) { echo ' title="' . _pfc("Enter your nickname here") . '"' . ' onclick="pfc.askNick(\'\')"' . ' style="cursor: pointer"'; } ?> ><?php echo phpFreeChat::FilterSpecialChar($u->nick); ?> </p> </td> <td class="pfc_td2"> <input type="text" id="pfc_words" title="<?php echo _pfc("Enter your message here"); ?> " maxlength="<?php echo $max_text_len; ?> "/> </td>
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) == '') { // error $cmdp = $p; $cmdp["param"] = _pfc("Missing parameter"); $cmdp["param"] .= " (" . $this->usage . ")"; $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); return false; } $newnick = phpFreeChat::FilterNickname($param); $oldnick = $ct->getNickname($u->nickid); $newnickid = $ct->getNickId($newnick); $oldnickid = $u->nickid; // new nickname is undefined (not used) and // current nickname (oldnick) is mine and // oldnick is different from new nick // -> this is a nickname change if ($oldnick != $newnick && $oldnick != '') { // really change the nick (rename it) $ct->changeNick($newnick, $oldnick); $u->nick = $newnick; $u->saveInCache(); $this->forceWhoisReload($u->nickid); // notify all the joined channels/privmsg $cmdp = $p; $cmdp["param"] = _pfc("%s changes his nickname to %s", $oldnick, $newnick); $cmdp["flag"] = 1; $cmd =& pfcCommand::Factory("notice"); foreach ($u->channels as $id => $chan) { $cmdp["recipient"] = $chan["recipient"]; $cmdp["recipientid"] = $id; $cmd->run($xml_reponse, $cmdp); } foreach ($u->privmsg as $id => $pv) { $cmdp["recipient"] = $pv["recipient"]; $cmdp["recipientid"] = $id; $cmd->run($xml_reponse, $cmdp); } $xml_reponse->script("pfc.handleResponse('nick', 'changed', '" . addslashes($newnick) . "');"); return true; } // new nickname is undefined (not used) // -> this is a first connection (this piece of code is called by /connect command) if ($newnickid == '') { // this is a first connection : create the nickname on the server $ct->createNick($u->nickid, $newnick); $u->nick = $newnick; $u->saveInCache(); $this->forceWhoisReload($u->nickid); $xml_reponse->script("pfc.handleResponse('nick', 'connected', '" . addslashes($newnick) . "');"); return true; } return false; }
/** * Filter messages before they are sent to container */ function PreFilterMsg($msg) { $c =& pfcGlobalConfig::Instance(); if (preg_match("/^\\[/i", $msg)) { // add 25 characteres if the message starts with [ : means there is a bbcode $msg = utf8_substr($msg, 0, $c->max_text_len + 25); } else { $msg = utf8_substr($msg, 0, $c->max_text_len); } $msg = phpFreeChat::FilterSpecialChar($msg); // $msg = phpFreeChat::FilterSmiley($msg); /* if ($msg[0] == "\n") $msg = substr($msg, 1); */ // delete the first \n generated by FF /* if (strpos($msg,"\n") > 0) $msg = "<br/>".$msg; $msg = str_replace("\r\n", "<br/>", $msg); $msg = str_replace("\n", "<br/>", $msg); $msg = str_replace("\t", " ", $msg);*/ //$msg = str_replace(" ", " ", $msg); // $msg = preg_replace('/(http\:\/\/[^\s]*)/i', "<a href=\"$1\">$1</a>", $msg ); return $msg; }
/// Author: Rafał "Endzio" Enden /// modules/chat/index.php defined('KioCMS') || exit; $lang = include_lang('modules/chat'); $chat = get_config('chat'); $title[] = 'Chat'; $module['columns'] = 2; //file_exists(root_dir.'modules/chat/data/private/cache/'.md5(__FILE__).'.php') ? unlink(root_dir.'modules/chat/data/private/cache/'.md5(__FILE__).'.php') : ''; require_once root_dir . 'modules/chat/src/phpfreechat.class.php'; $params = array(); $params["title"] = "Quick chat"; $params["isadmin"] = strtolower($user['username']) == 'test' ? true : false; // do not use it on production servers ;) $params["serverid"] = md5(__FILE__); // calculate a unique id for this chat $params["nick"] = defined('LOGGED') ? $user['username'] : '******' . rand(); // setup the intitial nickname $params["debug"] = false; $params["max_msg"] = 0; $params["frozen_nick"] = true; $params["theme_url"] = local_dir . "modules/chat/data/public/themes"; $params["theme_default_url"] = local_dir . "modules/chat/data/public/themes"; $params["server_script_url"] = local_url . "chat/"; // Must ending with slash (/) $params["client_script_path"] = root_dir . 'modules/chat/index.php'; $params["data_public_url"] = local_dir . "modules/chat/data/public"; $params["prototypejs_url"] = local_dir . "modules/chat/data/public/js/prototype.js"; $pfc = new phpFreeChat($params); echo '<div style="text-align: left;">'; $pfc->printChat(); echo '</div>';
global $CONFIG; require_once dirname(__FILE__) . "/src/phpfreechat.class.php"; $params = array(); $params['title'] = elgg_echo('Chat'); $params['nick'] = $_SESSION['user']->username; // setup the intitial nickname $params['isadmin'] = isadminloggedin(); $params['serverid'] = 'phpfreechat'; // calculate a unique id for this chat $params['debug'] = false; if (get_plugin_setting('container_type', 'chat') == 'Mysql') { $params['container_type'] = 'Mysql'; $params['container_cfg_mysql_host'] = $CONFIG->dbhost; $params['container_cfg_mysql_port'] = 3306; $params['container_cfg_mysql_database'] = $CONFIG->dbname; $params['container_cfg_mysql_table'] = $CONFIG->dbprefix . "phpfreechat"; $params['container_cfg_mysql_username'] = $CONFIG->dbuser; $params['container_cfg_mysql_password'] = $CONFIG->dbpass; } $params['theme'] = get_plugin_setting('theme', 'chat'); $params['frozen_nick'] = get_plugin_setting('strict_access', 'chat') == 1; $params['channels'] = explode(',', get_plugin_setting('channels', 'chat')); $chat = new phpFreeChat($params); if (get_plugin_setting('use_popup', 'chat')) { include dirname(dirname(__FILE__)) . '/popup.inc.php'; } else { // Format Page $body = elgg_view_layout('one_column', $chat->printChat(true)); // Draw it echo page_draw(elgg_echo('Chat'), $body); }
function render($mode, Doku_Renderer $renderer, $data) { global $conf, $USERINFO, $ID; if (auth_quickaclcheck($ID) >= AUTH_READ) { if ($mode == 'xhtml') { $renderer->info['cache'] = FALSE; ob_start(); require_once DOKU_INC . 'lib/plugins/freechat/phpfreechat/src/phpfreechat.class.php'; $params = array(); $params['serverid'] = md5($conf['title']); if (isset($data['chatid']) && $data['chatid'] != '') { $params['serverid'] = md5($data['chatid']); } $params['focus_on_connect'] = true; $params['language'] = $this->getConf('language'); $params['theme'] = $this->getConf('template'); $params['height'] = $this->getConf('height') . 'px'; $params["title"] = $this->getConf('title'); if (isset($data['rooms'])) { $params["channels"] = explode(',', $data['rooms']); } else { $params["channels"] = explode(',', $this->getConf('channels')); } $params['frozen_nick'] = $this->getConf('frozen_nick'); $params['frozen_nick'] = !($params['frozen_nick'] == 'off' || $params['frozen_nick'] == 0); if (isset($data['locked'])) { $params['frozen_channels'] = explode(',', $data['locked']); } else { if ($this->getConf('frozen_channels') != '') { $params['frozen_channels'] = explode(',', $this->getConf('frozen_channels')); } } $params['isadmin'] = false; if ($this->getConf('admin_group') != '' && isset($USERINFO['grps'])) { $temp = explode(',', $this->getConf('admin_group')); foreach ($temp as $item) { if (in_array(trim($item), $USERINFO['grps'])) { $params['isadmin'] = true; } } } $params['startwithsound'] = false; $params['display_pfc_logo'] = true; $params['showsmileys'] = false; $params['nick'] = isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : "******" . rand(1, 1000); if ($this->getConf('fullname')) { if (isset($USERINFO['name']) && !empty($USERINFO['name'])) { $params['nick'] = $USERINFO['name']; } } // $params['channels'] = array('Generale'); $params['data_public_path'] = DOKU_INC . 'data/cache/public'; $params['data_public_url'] = DOKU_URL . 'data/cache/public'; $params['data_public_path'] = DOKU_INC . 'lib/plugins/freechat/phpfreechat/data/public'; $params['data_public_url'] = DOKU_URL . 'lib/plugins/freechat/phpfreechat/data/public'; // $params['data_public_path'] = DOKU_INC.'data/tmp'; // $params['data_public_url'] = DOKU_URL.'data/tmp'; $params['data_private_path'] = DOKU_INC . 'data/cache/freechat/private'; $params['server_script_path'] = DOKU_INC . 'lib/plugins/freechat/backend.php'; $params['server_script_url'] = DOKU_URL . 'lib/plugins/freechat/backend.php'; // $params['debug'] = true; // store in session the parameters list for the backend script @session_start(); $_SESSION['freechat_params_list'] = $params; $pfc = new phpFreeChat($params); $pfc->printChat(); $content = ob_get_contents(); ob_end_clean(); $renderer->doc .= $content; /* echo "<pre>"; print_r($params); echo "</pre>"; */ return true; } } return false; }
function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $c =& pfcGlobalConfig::Instance(); // do nothing if the recipient is not defined if ($recipient == "") { return; } // check this methode is not being called if (isset($_SESSION["pfc_lock_readnewmsg_" . $c->getId() . "_" . $clientid])) { // kill the lock if it has been created more than 10 seconds ago $last_10sec = time() - 10; $last_lock = $_SESSION["pfc_lock_readnewmsg_" . $c->getId() . "_" . $clientid]; if ($last_lock < $last_10sec) { $_SESSION["pfc_lock_" . $c->getId() . "_" . $clientid] = 0; } if ($_SESSION["pfc_lock_readnewmsg_" . $c->getId() . "_" . $clientid] != 0) { exit; } } // create a new lock $_SESSION["pfc_lock_readnewmsg_" . $c->getId() . "_" . $clientid] = time(); // read the last from_id value $container =& pfcContainer::Instance(); $from_id_sid = "pfc_from_id_" . $c->getId() . "_" . $clientid . "_" . $recipientid; $from_id = 0; if (isset($_SESSION[$from_id_sid])) { $from_id = $_SESSION[$from_id_sid]; } else { $from_id = $container->getLastId($recipient) - $c->max_msg - 1; if ($from_id < 0) { $from_id = 0; } } // check if this is the first time you get messages $oldmsg_sid = "pfc_oldmsg_" . $c->getId() . "_" . $clientid . "_" . $recipientid; $oldmsg = false; if (isset($_SESSION[$oldmsg_sid])) { unset($_SESSION[$oldmsg_sid]); $oldmsg = true; } $new_msg = $container->read($recipient, $from_id); $new_from_id = $new_msg["new_from_id"]; $data = $new_msg["data"]; // transform new message in html format $js = array(); $data_sent = false; foreach ($data as $d) { $m_id = $d["id"]; $m_date = gmdate($c->date_format, $d["timestamp"] + $c->time_offset); $m_time = gmdate($c->time_format, $d["timestamp"] + $c->time_offset); $m_sender = $d["sender"]; $m_recipientid = $recipientid; $m_cmd = $d["cmd"]; $m_param = phpFreeChat::PostFilterMsg($d["param"]); $js[] = array($m_id, $m_date, $m_time, $m_sender, $m_recipientid, $m_cmd, $m_param, gmdate($c->date_format, time() + $c->time_offset) == $m_date ? 1 : 0, $oldmsg ? 1 : 0); // is it a new message in the current session or is it a part of the history $data_sent = true; } if (count($js) != 0) { require_once dirname(__FILE__) . '/../pfcjson.class.php'; $json = new pfcJSON(); $js = $json->encode($js); $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', (" . $js . "));"); } if ($data_sent) { // store the new msg id $_SESSION[$from_id_sid] = $new_from_id; } // remove the lock $_SESSION["pfc_lock_readnewmsg_" . $c->getId() . "_" . $clientid] = 0; }
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(); $nick = $ct->getNickname($u->nickid); //phpFreeChat::FilterSpecialChar($sender); $text = phpFreeChat::PreFilterMsg($param); // $offline = $container->getMeta("offline", "nickname", $u->privmsg[$recipientid]["name"]); // if this channel is a pv (one to one channel), // first of all, check if the other user is connected // if he is not connected anymore, display an error $can_send = true; if (isset($u->privmsg[$recipientid])) { $pvnickid = $u->privmsg[$recipientid]["pvnickid"]; $pvnick = $ct->getNickname($pvnickid); //$u->privmsg[$recipientid]["name"]; // $pvnickid = $ct->getNickId($pvnick); // now check if this user is currently online $onlineusers = $ct->getOnlineNick(NULL); if (!in_array($pvnickid, $onlineusers["nickid"])) { // send an error because the user is not online $cmdp = $p; $cmdp["param"] = _pfc("Can't send the message, %s is offline", $pvnick); $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); $can_send = false; } } // check the sent text is not empty and the user has a none empty nickname $errors = array(); if ($text == "") { $errors["pfc_words"] = _pfc("Text cannot be empty"); } if ($nick == "") { $errors["pfc_handle"] = _pfc("Please enter your nickname"); } if (count($errors) > 0) { // an error occured, just ignore the message and display errors $cmdp = $p; $cmdp["param"] = $errors; $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); if (isset($errors["pfc_handle"])) { // the nick is empty so give it focus $xml_reponse->script("\$('pfc_handle').focus();"); } $can_send = false; } // Now send the message if there is no errors if ($can_send) { $msgid = $ct->write($recipient, $nick, "send", $text); if (is_array($msgid)) { $cmdp = $p; $cmdp["param"] = implode(",", $msgid); $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); return; } // a message has been posted so : // - clear errors // - give focus to "words" field // @todo move this code in the handleResponse function $xml_reponse->script("pfc.clearError(Array('pfc_words" . "','pfc_handle" . "'));"); $xml_reponse->script("\$('pfc_words').focus();"); } $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '');"); }