diff options
Diffstat (limited to 'chat/lib')
-rw-r--r-- | chat/lib/class/CustomAJAXChat.php | 277 | ||||
-rw-r--r-- | chat/lib/config.php (renamed from chat/lib/config.php.example) | 10 | ||||
-rw-r--r-- | chat/lib/custom.php | 6 | ||||
-rw-r--r-- | chat/lib/template/loggedOut.html | 33 |
4 files changed, 250 insertions, 76 deletions
diff --git a/chat/lib/class/CustomAJAXChat.php b/chat/lib/class/CustomAJAXChat.php index a18e640..8cc255a 100644 --- a/chat/lib/class/CustomAJAXChat.php +++ b/chat/lib/class/CustomAJAXChat.php @@ -3,38 +3,117 @@ * @package AJAX_Chat * @author Sebastian Tschan * @copyright (c) Sebastian Tschan - * @license Modified MIT License + * @license GNU Affero General Public License * @link https://blueimp.net/ajax/ + * + * SMF integration: + * http://www.simplemachines.org/ */ class CustomAJAXChat extends AJAXChat { + // Initialize custom configuration settings + function initCustomConfig() { + global $db_name,$db_connection; + + // Use the existing SMF database connection: + $this->setConfig('dbConnection', 'link', $db_connection); + } + + // Override the database connection method to make sure the SMF database is selected: + function initDataBaseConnection() { + global $db_name; + + // Call the parent method to initialize the database connection: + parent::initDataBaseConnection(); + + // Select the SMF database: + $this->db->select($db_name); + if($this->db->error()) { + echo $this->db->getError(); + die(); + } + } + + // Initialize custom request variables: + function initCustomRequestVars() { + global $context; + + // Auto-login phpBB users: + if(!$this->getRequestVar('logout') && !$context['user']['is_guest']) { + $this->setRequestVar('login', true); + } + } + + // Replace custom template tags: + function replaceCustomTemplateTags($tag, $tagContent) { + global $context,$boardurl; + + switch($tag) { + + case 'FORUM_LOGIN_URL': + if(!$context['user']['is_guest']) { + return ($this->getRequestVar('view') == 'logs') ? './?view=logs' : './'; + } else { + return $this->htmlEncode($boardurl).'/index.php?action=login2'; + } + + + case 'REDIRECT_URL': + if(!$context['user']['is_guest']) { + return ''; + } else { + $redirectURL = $this->getRequestVar('view') == 'logs' ? $this->getChatURL().'?view=logs' : $this->getChatURL(); + if(!$this->getRequestVar('logout')) { + // Set the redirect URL after login to the chat: + ssi_login($redirectURL, false); + } else { + // Reset the redirect URL on logout: + ssi_login($boardurl.'/index.php', false); + } + return $redirectURL; + } + + default: + return null; + } + } + + // Returns true if the userID of the logged in user is identical to the userID of the authentication system + // or the user is authenticated as guest in the chat and the authentication system + function revalidateUserID() { + global $context; + + if($this->getUserRole() === AJAX_CHAT_GUEST && $context['user']['is_guest'] || ($this->getUserID() === $context['user']['id'])) { + return true; + } + return false; + } + // Returns an associative array containing userName, userID and userRole // Returns null if login is invalid function getValidLoginUserData() { + global $context,$user_info; - $customUsers = $this->getCustomUsers(); - - if($this->getRequestVar('password')) { - // Check if we have a valid registered user: - - $userName = $this->getRequestVar('userName'); - $userName = $this->convertEncoding($userName, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding')); - - $password = $this->getRequestVar('password'); - $password = $this->convertEncoding($password, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding')); - - 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; - } - } + // Check if we have a valid registered user: + if(!$context['user']['is_guest']) { + $userData = array(); + $userData['userID'] = $context['user']['id']; + + $userData['userName'] = $this->trimUserName($context['user']['name']); + + if($context['user']['is_admin']) + $userData['userRole'] = AJAX_CHAT_ADMIN; + // $context['user']['is_mod'] is always false if no board is loaded. + // As a workaround we check the permission 'calendar_post'. + // This is only set to true for global moderators by default: + elseif(in_array('calendar_post', $user_info['permissions'])) + $userData['userRole'] = AJAX_CHAT_MODERATOR; + else + $userData['userRole'] = AJAX_CHAT_USER; + + return $userData; - return null; } else { // Guest users: return $this->getGuestUser(); @@ -45,30 +124,53 @@ class CustomAJAXChat extends AJAXChat { // Make sure channel names don't contain any whitespace function &getChannels() { if($this->_channels === null) { + global $db_prefix,$user_info; + $this->_channels = array(); - $customUsers = $this->getCustomUsers(); + $sql = 'SELECT + ID_BOARD, + name + FROM + '.$db_prefix.'boards AS b + WHERE + '.$user_info['query_see_board'].';'; + + // Create a new SQL query: + $result = $this->db->sqlQuery($sql); - // Get the channels, the user has access to: - if($this->getUserRole() == AJAX_CHAT_GUEST) { - $validChannels = $customUsers[0]['channels']; - } else { - $validChannels = $customUsers[$this->getUserID()]['channels']; + // Stop if an error occurs: + if($result->error()) { + echo $result->getError(); + die(); } - - // Add the valid channels to the channel list (the defaultChannelID is always valid): - foreach($this->getAllChannels() as $key=>$value) { - if ($value == $this->getConfig('defaultChannelID')) { - $this->_channels[$key] = $value; - continue; - } + + $defaultChannelFound = false; + + while($row = $result->fetch()) { // Check if we have to limit the available channels: - if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) { + if($this->getConfig('limitChannelList') && !in_array($row['ID_BOARD'], $this->getConfig('limitChannelList'))) { continue; } - if(in_array($value, $validChannels)) { - $this->_channels[$key] = $value; + + $forumName = $this->trimChannelName($row['name']); + + $this->_channels[$forumName] = $row['ID_BOARD']; + + if(!$defaultChannelFound && $row['ID_BOARD'] == $this->getConfig('defaultChannelID')) { + $defaultChannelFound = true; } + } + $result->free(); + + if(!$defaultChannelFound) { + // Add the default channel as first array element to the channel list: + $this->_channels = array_merge( + array( + $this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID') + ), + $this->_channels + ); } } return $this->_channels; @@ -78,22 +180,40 @@ class CustomAJAXChat extends AJAXChat { // Make sure channel names don't contain any whitespace function &getAllChannels() { if($this->_allChannels === null) { - // Get all existing channels: - $customChannels = $this->getCustomChannels(); + global $db_prefix,$user_info; - $defaultChannelFound = false; + $this->_allChannels = array(); + + $sql = 'SELECT + ID_BOARD, + name + FROM + '.$db_prefix.'boards;'; + + // Create a new SQL query: + $result = $this->db->sqlQuery($sql); - foreach($customChannels as $name=>$id) { - $this->_allChannels[$this->trimChannelName($name)] = $id; - if($id == $this->getConfig('defaultChannelID')) { + // Stop if an error occurs: + if($result->error()) { + echo $result->getError(); + die(); + } + + $defaultChannelFound = false; + + while($row = $result->fetch()) { + $forumName = $this->trimChannelName($row['name']); + + $this->_allChannels[$forumName] = $row['ID_BOARD']; + + if(!$defaultChannelFound && $row['ID_BOARD'] == $this->getConfig('defaultChannelID')) { $defaultChannelFound = true; } - } - + } + $result->free(); + if(!$defaultChannelFound) { - // Add the default channel as first array element to the channel list - // First remove it in case it appeard under a different ID - unset($this->_allChannels[$this->getConfig('defaultChannelName')]); + // Add the default channel as first array element to the channel list: $this->_allChannels = array_merge( array( $this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID') @@ -105,20 +225,49 @@ class CustomAJAXChat extends AJAXChat { return $this->_allChannels; } - function &getCustomUsers() { - // List containing the registered chat users: - $users = null; - require(AJAX_CHAT_PATH.'lib/data/users.php'); - return $users; - } - - function getCustomChannels() { - // List containing the custom channels: - $channels = null; - require(AJAX_CHAT_PATH.'lib/data/channels.php'); - // Channel array structure should be: - // ChannelName => ChannelID - return array_flip($channels); + // Method to set the style cookie depending on the SMF user style: + function setStyle() { + global $db_prefix,$settings; + + if(isset($_COOKIE[$this->getConfig('sessionName').'_style']) && in_array($_COOKIE[$this->getConfig('sessionName').'_style'], $this->getConfig('styleAvailable'))) + return; + + $sql = 'SELECT + value + FROM + '.$db_prefix.'themes + WHERE + ID_THEME = '.$this->db->makeSafe($settings['theme_id']).' + AND + variable = \'name\';'; + + // Create a new SQL query: + $result = $this->db->sqlQuery($sql); + + // Stop if an error occurs: + if($result->error()) { + echo $result->getError(); + die(); + } + + $row = $result->fetch(); + $styleName = $row['value']; + + $result->free(); + + if(!in_array($styleName, $this->getConfig('styleAvailable'))) { + $styleName = $this->getConfig('styleDefault'); + } + + setcookie( + $this->getConfig('sessionName').'_style', + $styleName, + time()+60*60*24*$this->getConfig('sessionCookieLifeTime'), + $this->getConfig('sessionCookiePath'), + $this->getConfig('sessionCookieDomain'), + $this->getConfig('sessionCookieSecure') + ); + return; } -}
\ No newline at end of file +} diff --git a/chat/lib/config.php.example b/chat/lib/config.php index 46815ee..3057adc 100644 --- a/chat/lib/config.php.example +++ b/chat/lib/config.php @@ -22,13 +22,13 @@ $config = array(); // Database connection values: $config['dbConnection'] = array(); // Database hostname: -$config['dbConnection']['host'] = 'localhost'; +$config['dbConnection']['host'] = null; // Database username: -$config['dbConnection']['user'] = 'root'; +$config['dbConnection']['user'] = null; // Database password: -$config['dbConnection']['pass'] = ''; +$config['dbConnection']['pass'] = null; // Database name: -$config['dbConnection']['name'] = 'chat'; +$config['dbConnection']['name'] = null; // Database type: $config['dbConnection']['type'] = null; // Database link: @@ -59,7 +59,7 @@ $config['langNames'] = array( // Available styles: $config['styleAvailable'] = array('beige','black','grey','Oxygen','Lithium','Sulfur','Cobalt','Mercury','Uranium','Pine','Plum','prosilver','Core','MyBB','vBulletin','XenForo'); // Default style: -$config['styleDefault'] = 'prosilver'; +$config['styleDefault'] = 'Core'; // The encoding used for the XHTML content: $config['contentEncoding'] = 'UTF-8'; diff --git a/chat/lib/custom.php b/chat/lib/custom.php index 5e8b655..fccb308 100644 --- a/chat/lib/custom.php +++ b/chat/lib/custom.php @@ -5,6 +5,10 @@ * @copyright (c) Sebastian Tschan * @license Modified MIT License * @link https://blueimp.net/ajax/ + * + * SMF integration: + * http://www.simplemachines.org/ */ -// Include custom libraries and initialization code here +// SMF initialization: +require_once(dirname(AJAX_CHAT_PATH) . '/SSI.php'); diff --git a/chat/lib/template/loggedOut.html b/chat/lib/template/loggedOut.html index 5e225aa..2ed4fbe 100644 --- a/chat/lib/template/loggedOut.html +++ b/chat/lib/template/loggedOut.html @@ -12,6 +12,28 @@ <script src="js/config.js" type="text/javascript" charset="UTF-8"></script> <script type="text/javascript"> // <![CDATA[ + function handleLogin() { + var loginForm = document.getElementById('loginForm'); + var userNameField = document.getElementById('userNameField'); + var passwordField = document.getElementById('passwordField'); + var channelField = document.getElementById('channelField'); + var redirectField = document.getElementById('redirectField'); + if(passwordField.value.length == 0) { + loginForm.setAttribute('action', '[LOGIN_URL/]'); + userNameField.setAttribute('name', 'userName'); + } else { + var channelRequest = 'channelName=' + encodeURIComponent(channelField.value); + var regExp = /\?/; + if(regExp.test(redirectField.value)) { + redirectField.value += '&'; + } else { + redirectField.value += '?'; + } + redirectField.value += channelRequest; + } + return true; + } + function initializeLoginPage() { document.getElementById('userNameField').focus(); if(!ajaxChat.isCookieEnabled()) { @@ -28,7 +50,7 @@ ajaxChatConfig.cookieDomain = '[COOKIE_DOMAIN/]'; ajaxChatConfig.cookieSecure = '[COOKIE_SECURE/]'; - ajaxChat.init(ajaxChatConfig, ajaxChatLang, true, true, false); + ajaxChat.init(ajaxChatConfig, ajaxChatLang, false, true, false); // ]]> </script> </head> @@ -36,13 +58,12 @@ <div id="loginContent"> <h1 id="loginHeadline">[LANG]title[/LANG]</h1> <div id="errorContainer">[ERROR_MESSAGES/]<noscript><div>[LANG]requiresJavaScript[/LANG]</div></noscript></div> - <form id="loginForm" action="[LOGIN_URL/]" method="post" enctype="application/x-www-form-urlencoded"> - <input type="hidden" name="login" id="loginField" value="login"/> - <input type="hidden" name="redirect" id="redirectField" value="[REDIRECT_URL/]"/> + <form id="loginForm" action="[FORUM_LOGIN_URL/]" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return handleLogin();"> + <input type="hidden" name="redirectURL" id="redirectField" value="[REDIRECT_URL/]"/> <div><label for="userNameField">[LANG]userName[/LANG]:</label><br /> - <input type="text" name="userName" id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]"/></div> + <input type="text" name="user" id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]"/></div> <div><label for="passwordField">[LANG]password[/LANG]*:</label><br /> - <input type="password" name="password" id="passwordField"/></div> + <input type="password" name="passwrd" id="passwordField"/></div> <div><label for="channelField">[LANG]channel[/LANG]:</label><br /> <select name="channelName" id="channelField">[CHANNEL_OPTIONS/]</select></div> <div><label for="languageSelection">[LANG]language[/LANG]:</label><br /> |