diff options
-rw-r--r-- | .gitignore | 1 | ||||
-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 | ||||
-rw-r--r-- | chat/readme.html | 90 | ||||
-rw-r--r-- | readme.md | 4 |
7 files changed, 264 insertions, 157 deletions
@@ -1,2 +1 @@ -/chat/lib/config.php /nbproject/*
\ No newline at end of file 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 /> diff --git a/chat/readme.html b/chat/readme.html index d733b16..2b909fc 100644 --- a/chat/readme.html +++ b/chat/readme.html @@ -42,9 +42,9 @@ <header> <div class="container"> <h1> - AJAX Chat + AJAX Chat for SMF <span class="version"> - v 0.8.8 standalone ( <a href="https://blueimp.net/ajax/">blueimp.net/ajax/</a> ) + v 0.8.8 smf ( <a href="https://blueimp.net/ajax/">blueimp.net/ajax/</a> ) </span> </h1> </div> @@ -67,12 +67,12 @@ </ol> </div> + <div style="margin-right: 28em;"> <h2 style="margin-top:0;">Version Information</h2> <div class="subsection"> - This is the <strong>standalone</strong> version of blueimp's AJAX Chat designed to run on its own, without another web application.<br> - If you want to integrate AJAX Chat with one of the forums we support, go back and choose the right version. <br> - This version is good for customizing your own integration, or using on its own. + This is the version of Blueimp's AJAX Chat desinged to be run with <a href="http://www.simplemachines.org/" style="font-weight:bold;">smf</a>.<br> + If you want to integrate AJAX Chat with one of the other forums we support, go back and choose the right version. <p class="note"> AJAX stands for "Asynchronous JavaScript and XML".<br> @@ -117,85 +117,19 @@ If you get an error message like "<strong>Cannot modify header information - headers already sent</strong>" it is likely because you have used one of the above programs to edit files. </section> - <h3>Configure Database Settings</h3> - <div class="subsection"> - <p> - The first and most important thing you need to do is tell AJAX Chat how to connect to your database. This, and all core settings must be located inside the file <span class="filename">lib/config.php</span>. <br> - <strong>You need to create this file.</strong> <br> - An example <span class="filename">config.php</span> file can be found in <span class="filename">lib/config.php.example</span> that shipped with chat.<br> - Duplicate this file and save it as config.php (or just delete .example from the end of the file name) and then fill out at least the following four fields in the file: - </p> - <p> - <code> - $config['dbConnection']['host'] = '<em>your_database_hostname</em>';<br> - $config['dbConnection']['user'] = '<em>your_database_username</em>';<br> - $config['dbConnection']['pass'] = '<em>your_database_password</em>';<br> - $config['dbConnection']['name'] = '<em>your_database_name</em>'; - </code> - </p> - <p>Sufficed to say you need this information. Talk to your hosting provider if you don't know.</p> - <p> - In most cases, chat will function with only these fields filled out and you can proceed to the next step.<br> - </p> - <p class="note"> - If your host does not use mysqli you will need to change the connection type field:<br> - $config['dbConnection']['type'] = null;<br> - If this is set to "null" it defaults to "mysqli" if existing, else to "mysql". In most cases this field can be left as null.<br> - <br> - You can reference an existing database connection link or object by changing:<br> - $config['dbConnection']['link'] = null;<br> - If this is set to null, a new database connection is created. - </p> - </div> - - <h3>Choose Your Channel Settings</h3> + <h3>Upload to Server</h3> <div class="subsection"> - <p>Edit the file <span class="filename">lib/data/channels.php.</span><br> - We have provided you with two sample channels, named public and private. You can add your own, or leave it as-is.<br> - Channels follow the following format: - <br> - <code>$channels[<em>channel id</em>] = '<em>channel name</em>';</code> - Each channel must have a unique channel id number and a unique name.<br> - Whitespace in the channel names will be converted to the underscore "_".</p> + Upload the chat folder to your server into your phpBB3 forum directory:<br> + eg. <span class="filename">http://example.org/smf/chat/</span> </div> - <h3>Add Your Users</h3> - <div class="subsection"> - <p class="note"> - The Standalone version of chat uses a php file to store users and rooms while the database is used for chat messages, invites and bans.<br> - The integration versions typically make use of a database for users and rooms. If you desire a way to manage users without having to edit a php file, consider using an integration version. - </p> - <p> - Edit users in <span class="filename">lib/data/users.php</span>.<br> - Users follow the following format: - </p> - <p><code>$users[<em>user id</em>] = array();<br> - $users[<em>user id</em>]['userRole'] = <em>AJAX_CHAT_ROLE</em>;<br> - $users[<em>user id</em>]['userName'] = '<em>user name</em>';<br> - $users[<em>user id</em>]['password'] = '<em>user password</em>';<br> - $users[<em>user id</em>]['channels'] = array(<em>allowed channel ids</em>);</code><br> - Each user must have a unique user id number and a unique name.<br> - The first user in the list (user id 0) is used for the guest user settings. All guest users will have access to the channels set for this user and the user role AJAX_CHAT_GUEST.<br> - Registered users can have the user roles AJAX_CHAT_USER, AJAX_CHAT_MODERATOR or AJAX_CHAT_ADMIN. (this is case sensitive, type it exactly)<br> - The list of channels a user has access to can be set for each user individually. Channel id's are separated by commas. eg: array(0,1,23); allows channels 0, 1 and 23.<br> - Whitespace in the user names will be converted to the underscore "_". - </p> - </div> - - <h3>Upload to Your Server</h3> - <div class="subsection"> - <p>Upload the chat folder to your server somewhere under your document root:<br> - e.g. http://example.org/path/to/chat/</p> - </div> - <h3>Create the Database Tables</h3> + <h3>Create the Database Tables</h3> <div class="subsection"> <p>There are two options available to you to create the database. The first, and usually the easiest option, is to run the installation script included with AJAX Chat. Alternatively, you may use a database tool like PHPMyAdmin to manually create the tables.</p> <ol> <li> - To use the installation script, visit the following URL in your browser:<br> - <span class="filename">http://example.org/path/to/chat/install.php</span><br> - Where - "http://example.org/path/to/chat/" is the real URL to your chat directory.<br> + <span class="filename">http://example.org/phpBB3/chat/install.php</span><br> + Where "http://example.org/smf/chat/" is the real URL to your chat directory.<br> Be sure to delete the install.php file after you have completed this step! </li> <li>To install it manually using PHPMyAdmin or a similar tool, copy the contents of the <span class="filename">chat.sql</span> file and run it as a query.</li> @@ -466,4 +400,4 @@ return null; </div> </body> -</html>
\ No newline at end of file +</html> @@ -1,7 +1,7 @@ -AJAX Chat Standalone +AJAX Chat for SMF ==================== -This is the standalone version of Blueimp's AJAX Chat. If you are looking for a version to integrate with your forum, select a different branch. +This is the version of Blueimp's AJAX Chat for SMF. AJAX stands for "Asynchronous JavaScript and XML". The AJAX Chat clients (the user browsers) use JavaScript to query the web server for updates. |