Skip to content

Commit

Permalink
Merge chatserver.php and update chat code
Browse files Browse the repository at this point in the history
  • Loading branch information
mucill committed Jun 5, 2015
1 parent bd89c93 commit b5810a2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 131 deletions.
55 changes: 27 additions & 28 deletions admin/admin_template/default/index_template.inc.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
<?php
/**
* Akasia Template
*
* Copyright (C) 2015 Eddy Subratha ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* Template for Backend
*
* Copyright (C) 2015 Arie Nugraha ([email protected])
* Create by Eddy Subratha ([email protected])
*
* Slims 8 (Akasia)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

// Need to modified script to adaptive new theme
include 'function.php';
// Need to modified script to adaptive new theme
include 'function.php';
?>
<!-- =====================================================================
___ __ ____ __ __ ___ __ _ _ __ ___ ____ __
/ __)( ) (_ _)( \/ )/ __) /__\ ( )/ ) /__\ / __)(_ _) /__\
\__ \ )(__ _)(_ ) ( \__ \ /(__)\ ) ( /(__)\ \__ \ _)(_ /(__)\
(___/(____)(____)(_/\/\_)(___/ (__)(__)(_)\_)(__)(__)(___/(____)(__)(__)

By Eddy Subratha ([email protected])

========================================================================== -->

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
Expand Down Expand Up @@ -125,7 +124,7 @@
<?php
// Chat
// =============================================
if($sysconf['chat_system']['enabled']) : ?>
if($sysconf['chat_system']['enabled'] && $sysconf['chat_system']['librarian']) : ?>
<aside class="s-chat s-maximize">
<a href="#" id="pchat-hide" class="s-chat-header"><?php echo __('Chat With Members'); ?></a>
<div class="s-chat-content">
Expand All @@ -137,7 +136,7 @@
</aside>

<script>
$.get('../chat_server.php', {}, function(){});
$.get('../chatserver.php', {}, function(){});
var Server;
function log( text ) {
$log = $('#log');
Expand All @@ -153,7 +152,7 @@ function send( text ) {

$(document).ready(function() {
log('Connecting...');
Server = new FancyWebSocket("ws://<?php echo $sysconf['chat_system']['host'].':'.$sysconf['chat_system']['port']; ?>");
Server = new FancyWebSocket('ws://<?php echo $sysconf['chat_system']['server'] ?>:<?php echo $sysconf['chat_system']['server_port'] ?>');
$('#message').keypress(function(e) {
if ( e.keyCode == 13 && this.value ) {
log( 'You: ' + this.value );
Expand Down
72 changes: 0 additions & 72 deletions chat_server.php

This file was deleted.

24 changes: 14 additions & 10 deletions chatserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// prevent the server from timing out
set_time_limit(0);

define('INDEX_AUTH', 1);
// call configuration
define('INDEX_AUTH', '1');
require 'sysconfig.inc.php';

// include the web sockets server script (the server is started at the far bottom of this file)
require 'sysconfig.inc.php';
require LIB.'phpwebsocket.php';
require 'lib/phpwebsocket.php';

// when a client sends data to the server
function wsOnMessage($clientID, $message, $messageLength, $binary) {
Expand All @@ -25,34 +26,37 @@ function wsOnMessage($clientID, $message, $messageLength, $binary) {
else
//Send the message to everyone but the person who said it
foreach ( $Server->wsClients as $id => $client )
if ( $id != $clientID )
$Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\"");
if ( $id != $clientID ) {
$_message = explode("|", $message);
$Server->wsSend($id, $_message[0]." ".$clientID." : ".$_message[1]);
}
}

// when a client connects
function wsOnOpen($clientID)
{
echo $clientID;
global $Server;
$ip = long2ip( $Server->wsClients[$clientID][6] );

$Server->log( "$ip ($clientID) has connected." );
$Server->log("Someone has connected." );

//Send a join notice to everyone but the person who joined
foreach ( $Server->wsClients as $id => $client )
if ( $id != $clientID )
$Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.");
$Server->wsSend($id, "Someone has joined the room.");
}

// when a client closes or lost connection
function wsOnClose($clientID, $status) {
global $Server;
$ip = long2ip( $Server->wsClients[$clientID][6] );

$Server->log( "$ip ($clientID) has disconnected." );
$Server->log( "Someone has disconnected." );

//Send a user left notice to everyone in the room
foreach ( $Server->wsClients as $id => $client )
$Server->wsSend($id, "Visitor $clientID ($ip) has left the room.");
$Server->wsSend($id, "Someone has left the room.");
}

// start the server
Expand All @@ -62,4 +66,4 @@ function wsOnClose($clientID, $status) {
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer($sysconf['chat_system']['server'], $sysconf['chat_system']['server_port']);
$Server->wsStartServer($sysconf['chat_system']['server'], $sysconf['chat_system']['server_port']);
20 changes: 5 additions & 15 deletions sysconfig.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,22 +596,12 @@ function stripslashes_deep($value)
$sysconf['social']['ym'] = 'Yahoo! Messenger';

/* CHATTING SYSTEM */
$sysconf['chat_system']['enabled'] = true;
$sysconf['chat_system']['vendors'] = 'phpwebscoketchat';
<<<<<<< HEAD
$sysconf['chat_system']['opac'] = TRUE;
$sysconf['chat_system']['librarian'] = TRUE;
$sysconf['chat_system']['server'] = '127.0.0.1';
$sysconf['chat_system']['enabled'] = true;
$sysconf['chat_system']['vendors'] = 'phpwebscoketchat';
$sysconf['chat_system']['opac'] = true;
$sysconf['chat_system']['librarian'] = true;
$sysconf['chat_system']['server'] = '127.0.0.1';
$sysconf['chat_system']['server_port'] = 9300;
=======
$sysconf['chat_system']['opac'] = false;
$sysconf['chat_system']['librarian'] = false;
$sysconf['chat_system']['librarian'] = '/usr/local/bin/php';
$sysconf['chat_system']['host'] = '127.0.0.1'; // You need an IP Address to use Chat
$sysconf['chat_system']['port'] = '9300'; // set Chat port


>>>>>>> 350294370b8751288e55357911b8c562dc726034

// redirect to mobile template on mobile mode
if (defined('LIGHTWEIGHT_MODE') AND !isset($_COOKIE['FULLSITE_MODE']) AND $sysconf['template']['responsive'] === false) {
Expand Down
7 changes: 1 addition & 6 deletions template/default/index_template.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@

<?php
// Chat
if($sysconf['chat_system']['enabled']) :
if($sysconf['chat_system']['enabled'] && $sysconf['chat_system']['opac']) :
?>
<a href="#" id="pchat-toggle" class="animated fadeInUp delay3"><i class="fa fa-comment-o"></i></a>
<aside class="s-chat s-maximize">
Expand Down Expand Up @@ -238,12 +238,7 @@ function send( text ) {

$(document).ready(function() {
log('Connecting...');
<<<<<<< HEAD
Server = new FancyWebSocket('ws://<?php echo $sysconf['chat_system']['server'] ?>:<?php echo $sysconf['chat_system']['server_port'] ?>');
=======
Server = new FancyWebSocket("ws://<?php echo $sysconf['chat_system']['host'].':'.$sysconf['chat_system']['port']; ?>");
>>>>>>> 350294370b8751288e55357911b8c562dc726034

$('#message').keypress(function(e) {
if ( e.keyCode == 13 && this.value ) {
log( 'You: ' + this.value );
Expand Down

0 comments on commit b5810a2

Please sign in to comment.