Untitled diff

Created Diff never expires
30 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
105 lines
47 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
121 lines
<?php
<?php
/*
/*
* @package AJAX_Chat
* @package AJAX_Chat
* @author Sebastian Tschan
* @author Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @license GNU Affero General Public License
* @license GNU Affero General Public License
* @link https://blueimp.net/ajax/
* @link https://blueimp.net/ajax/
*/
*/
class CustomAJAXChat extends AJAXChat {
class CustomAJAXChat extends AJAXChat {
// Returns an associative array containing userName, userID and userRole
// Returns an associative array containing userName, userID and userRole
// Returns null if login is invalid
// Returns null if login is invalid
function getValidLoginUserData() {
function getValidLoginUserData() {
$customUsers = $this->getCustomUsers();
$customUsers = $this->getCustomUsers();
if(isset($_COOKIE['login'])) {
$userData = array();
if($this->getRequestVar('password')) {
$userData['userID'] = $_COOKIE['loginid'];
// Check if we have a valid registered user:
$userData['userName'] = $_COOKIE['login'];
if($_COOKIE['loginrole'] == "3") {
$userName = $this->getRequestVar('userName');
$userData['userRole'] = AJAX_CHAT_ADMIN;
$userName = $this->convertEncoding($userName, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding'));
} else if($_COOKIE['loginrole'] == "2") {
$userData['userRole'] = AJAX_CHAT_MODERATOR;
$password = $this->getRequestVar('password');
} else {
$password = $this->convertEncoding($password, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding'));
$userData['userRole'] = AJAX_CHAT_USER;
foreach($customUsers as $key=>$value) {
if(($value['userName'] == $userName) && ($value['password'] == $password)) {
$userData = array();
$userData['userID'] = $key;
$userData['userName'] = $this->trimUserName($value['userName']);
$userData['userRole'] = $value['userRole'];
return $userData;
}
}
}
return $userData;
return null;
} else {
} else {
// Guest users:
// Guest users:
return null;
return $this->getGuestUser();
}
}
}
}
// Store the channels the current user has access to
// Store the channels the current user has access to
// Make sure channel names don't contain any whitespace
// Make sure channel names don't contain any whitespace
function &getChannels() {
function &getChannels() {
if($this->_channels === null) {
if($this->_channels === null) {
$this->_channels = array();
$this->_channels = array();
$allChannels = $this->getAllChannels();
$customUsers = $this->getCustomUsers();
foreach($allChannels as $key=>$value) {
// Get the channels, the user has access to:
// Check if we have to limit the available channels:
if($this->getUserRole() == AJAX_CHAT_GUEST) {
if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
$validChannels = $customUsers[0]['channels'];
continue;
} else {
}
$validChannels = $customUsers[$this->getUserID()]['channels'];
}
// Add the valid channels to the channel list (the defaultChannelID is always valid):
if($value == $this->getConfig('defaultChannelID')) {
// Add the valid channels to the channel list (the defaultChannelID is always valid):
$this->_channels[$key] = $value;
foreach($this->getAllChannels() as $key=>$value) {
}
// Check if we have to limit the available channels:
}
if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
}
continue;
return $this->_channels;
}
if(in_array($value, $validChannels) || $value == $this->getConfig('defaultChannelID')) {
$this->_channels[$key] = $value;
}
}
}
return $this->_channels;
}
}
// Store all existing channels
// Store all existing channels
// Make sure channel names don't contain any whitespace
// Make sure channel names don't contain any whitespace
function &getAllChannels() {
function &getAllChannels() {
if($this->_allChannels === null) {
if($this->_allChannels === null) {
// Get all existing channels:
// Get all existing channels:
$customChannels = $this->getCustomChannels();
$customChannels = $this->getCustomChannels();
$defaultChannelFound = false;
$defaultChannelFound = false;
foreach($customChannels as $key=>$value) {
foreach($customChannels as $key=>$value) {
$forumName = $this->trimChannelName($value);
$forumName = $this->trimChannelName($value);
$this->_allChannels[$forumName] = $key;
$this->_allChannels[$forumName] = $key;
if($key == $this->getConfig('defaultChannelID')) {
if($key == $this->getConfig('defaultChannelID')) {
$defaultChannelFound = true;
$defaultChannelFound = true;
}
}
}
}
if(!$defaultChannelFound) {
if(!$defaultChannelFound) {
// Add the default channel as first array element to the channel list:
// Add the default channel as first array element to the channel list:
$this->_allChannels = array_merge(
$this->_allChannels = array_merge(
array(
array(
$this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID')
$this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID')
),
),
$this->_allChannels
$this->_allChannels
);
);
}
}
}
}
return $this->_allChannels;
return $this->_allChannels;
}
}
function &getCustomUsers() {
function &getCustomUsers() {
// List containing the registered chat users:
// List containing the registered chat users:
$users = null;
$users = null;
require(AJAX_CHAT_PATH.'lib/data/users.php');
require(AJAX_CHAT_PATH.'lib/data/users.php');
return $users;
return $users;
}
}
function &getCustomChannels() {
function &getCustomChannels() {
// List containing the custom channels:
// List containing the custom channels:
$channels = null;
$channels = null;
require(AJAX_CHAT_PATH.'lib/data/channels.php');
require(AJAX_CHAT_PATH.'lib/data/channels.php');
return $channels;
return $channels;
}
}
}
}
?>
?>