<?php
/**
/* OSPHPChat Alpha 1 - 2011
/*
/* File: /modules/chat/ajax.php
/*
/* Website: www.OSPHPChat.com
/*
/* Author: Daniel Hood <danny@osphpchat.com>
/*
/*
/*
**/
if ($mode == 'send')
{
$message = $OSPHPChat->Purify->get('message', 'POST', 'string');
{
if ($OSPHPChat->User->auth->check_auth('main_talk'))
{
if ($message{0} == '/')
{
$message =
substr($message,
1);
if (file_exists('modules/chat/commands/' .
$cmd[0] .
'.php'))
{
include('commands/' . $cmd[0] . '.php');
$command = $cmd[0];
$command = new $command(&$OSPHPChat, $message);
if ($command->allowed())
{
{
'user_id' => $OSPHPChat->User->user_info['id'],
'to' => 'room:' . $OSPHPChat->Messages->room . ';',
'message' => $command->help(),
'date' => $OSPHPChat->data,
'time' => $OSPHPChat->time,
'color' => $OSPHPChat->User->user_info['message_color'],
'user_color' => $OSPHPChat->User->user_info['user_color'],
'username' => $OSPHPChat->User->user_info['username']
);
$OSPHPChat->Messages->send_message($data);
}
else
{
$command->execute();
}
}
else
{
$error = "You are not permitted to use this command.";
}
}
}
else
{
'user_id' => $OSPHPChat->User->user_info['id'],
'to' => 'room:' . $OSPHPChat->Messages->room . ';',
'message' => $message,
'date' => $OSPHPChat->data,
'time' => $OSPHPChat->time,
'color' => $OSPHPChat->User->user_info['message_color'],
'user_color' => $OSPHPChat->User->user_info['user_color'],
'username' => $OSPHPChat->User->user_info['username']
);
$OSPHPChat->Messages->send_message($data);
}
}
else
{
$error = "You are not permitted to talk.";
}
}
else
{
$error = "You cannot send blank messages.";
}
if ($error)
{
echo json_encode
($error);
}
}
elseif ($mode == 'load')
{
$OSPHPChat->Messages->starting_id = $_SESSION['last_message'];
$OSPHPChat->Messages->get_messages();
foreach ($OSPHPChat->Messages->get_messages() as $message)
{
// Establishes User Color \\
if (isset($message['user_color']))
{
$message['sender'] = "<a href='#' style='color:#" . $message['user_color'] . ";'>" . $message['username'] . "</a>";
}
else
{
$message['sender'] = "<a href='#'>" . $message['username'] . "</a>";
}
// Establishes Message Color \\
if (isset($message['color']))
{
$message['text'] = "<span style='color:#" . $message['color'] . ";'>" . $message['message'] . "</span>";
}
else
{
$message['text'] = "<span>" . $message['message'] . "</span>";
}
$_SESSION['last_message'] = $message['id'];
$Smarty->assign('message', $message);
$Messages[] = $Smarty->fetch('_message.tpl');
}
echo json_encode
($Messages);
}
elseif ($mode == 'users')
{
$offline_time =
time() -
15;
// Getting [new] online users \\
$online_users = $OSPHPChat->db->Execute("SELECT * FROM `" . $OSPHPChat->config['database']['tables']['users'] . "` WHERE `online_time`> '" . $offline_time . "'");
while ($online_user = $online_users->FetchRow())
{
$All_users[$online_user['id']] =
array(
'id' => $online_user['id'],
'username' => $online_user['username']
);
if (!
isset($_SESSION['online_users'][$online_user['id']]))
{
$Smarty->assign('user', $online_user);
$Users[online
][$online_user['id']] =
array(
'html' => $Smarty->fetch('_user_list.tpl'),
'id' => $online_user['id']
);
}
$Userids_online[$online_user['id']] = $online_user['username'];
}
// Removing offline users \\
if (is_array($_SESSION['online_users']))
{
foreach ($_SESSION['online_users'] as $online_user)
{
if (!
isset($Userids_online[$online_user['id']]))
{
$Users['offline'][] = $online_user;
}
}
}
$_SESSION['online_users'] = $All_users;
echo json_encode
($Users);
}
?>