summaryrefslogtreecommitdiffstats
path: root/chat/lib
diff options
context:
space:
mode:
Diffstat (limited to 'chat/lib')
-rw-r--r--chat/lib/class/CustomAJAXChat.php186
-rw-r--r--chat/lib/config.php (renamed from chat/lib/config.php.example)10
-rw-r--r--chat/lib/custom.php8
-rw-r--r--chat/lib/template/loggedOut.html7
4 files changed, 145 insertions, 66 deletions
diff --git a/chat/lib/class/CustomAJAXChat.php b/chat/lib/class/CustomAJAXChat.php
index a18e640..5fad81f 100644
--- a/chat/lib/class/CustomAJAXChat.php
+++ b/chat/lib/class/CustomAJAXChat.php
@@ -5,36 +5,89 @@
* @copyright (c) Sebastian Tschan
* @license Modified MIT License
* @link https://blueimp.net/ajax/
+ *
+ * MyBB integration:
+ * http://www.mybboard.net/
*/
class CustomAJAXChat extends AJAXChat {
+ // Initialize custom configuration settings
+ function initCustomConfig() {
+ global $db;
+
+ // Use the existing MyBB database connection:
+ $this->setConfig('dbConnection', 'link', $db->current_link);
+ }
+
+ // Initialize custom request variables:
+ function initCustomRequestVars() {
+ global $mybb;
+
+ // Auto-login MyBB users:
+ if(!$this->getRequestVar('logout') && $mybb->user['uid']) {
+ $this->setRequestVar('login', true);
+ }
+ }
+
+ // Replace custom template tags:
+ function replaceCustomTemplateTags($tag, $tagContent) {
+ global $mybb;
+
+ switch($tag) {
+
+ case 'FORUM_LOGIN_URL':
+ if($mybb->user['uid']) {
+ return ($this->getRequestVar('view') == 'logs') ? './?view=logs' : './';
+ } else {
+ return $mybb->settings['bburl'].'/member.php';
+ }
+
+ case 'REDIRECT_URL':
+ if($mybb->user['uid']) {
+ return '';
+ } else {
+ return $this->htmlEncode($this->getRequestVar('view') == 'logs' ? $this->getChatURL().'?view=logs' : $this->getChatURL());
+ }
+
+ 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 $mybb;
+
+ if($this->getUserRole() === AJAX_CHAT_GUEST && !$mybb->user['uid'] || ($this->getUserID() === $mybb->user['uid'])) {
+ return true;
+ }
+ return false;
+ }
+
// Returns an associative array containing userName, userID and userRole
// Returns null if login is invalid
function getValidLoginUserData() {
+ global $mybb;
- $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($mybb->user['uid']) {
+ $userData = array();
+ $userData['userID'] = $mybb->user['uid'];
+
+ $userData['userName'] = $this->trimUserName($mybb->user['username']);
+
+ // Take the userrole from the MyBB users primary group:
+ if($mybb->user['usergroup'] == 4)
+ $userData['userRole'] = AJAX_CHAT_ADMIN;
+ else if($mybb->user['usergroup'] == 3)
+ $userData['userRole'] = AJAX_CHAT_MODERATOR;
+ else
+ $userData['userRole'] = AJAX_CHAT_USER;
+
+ return $userData;
- return null;
} else {
// Guest users:
return $this->getGuestUser();
@@ -46,18 +99,13 @@ class CustomAJAXChat extends AJAXChat {
function &getChannels() {
if($this->_channels === null) {
$this->_channels = array();
-
- $customUsers = $this->getCustomUsers();
-
- // Get the channels, the user has access to:
- if($this->getUserRole() == AJAX_CHAT_GUEST) {
- $validChannels = $customUsers[0]['channels'];
- } else {
- $validChannels = $customUsers[$this->getUserID()]['channels'];
- }
-
- // Add the valid channels to the channel list (the defaultChannelID is always valid):
- foreach($this->getAllChannels() as $key=>$value) {
+
+ $allChannels = $this->getAllChannels();
+
+ // Build the forum permissions for all forums:
+ $forumPermissions = forum_permissions();
+
+ foreach($allChannels as $key=>$value) {
if ($value == $this->getConfig('defaultChannelID')) {
$this->_channels[$key] = $value;
continue;
@@ -66,7 +114,9 @@ class CustomAJAXChat extends AJAXChat {
if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
continue;
}
- if(in_array($value, $validChannels)) {
+
+ // Add the valid channels to the channel list (the defaultChannelID is always valid):
+ if($forumPermissions[$value]['canview'] == '1' || $value == $this->getConfig('defaultChannelID')) {
$this->_channels[$key] = $value;
}
}
@@ -78,18 +128,32 @@ 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;
+
+ $this->_allChannels = array();
+
+ // Get all MyBB forums:
+ $sql = 'SELECT
+ fid,
+ name
+ FROM
+ '.TABLE_PREFIX.'forums
+ WHERE
+ type=\'f\';';
+ $result = $db->query($sql);
+
$defaultChannelFound = false;
-
- foreach($customChannels as $name=>$id) {
- $this->_allChannels[$this->trimChannelName($name)] = $id;
- if($id == $this->getConfig('defaultChannelID')) {
+
+ while ($row = $db->fetch_array($result)) {
+ $forumName = $this->trimChannelName($row['name']);
+
+ $this->_allChannels[$forumName] = $row['fid'];
+
+ if(!$defaultChannelFound && $row['fid'] == $this->getConfig('defaultChannelID')) {
$defaultChannelFound = true;
}
}
-
+
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
@@ -105,20 +169,28 @@ 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 MyBB user style
+ function setStyle() {
+ global $theme;
+
+ if(isset($_COOKIE[$this->getConfig('sessionName').'_style']) && in_array($_COOKIE[$this->getConfig('sessionName').'_style'], $this->getConfig('styleAvailable')))
+ return;
+
+ $styleName = $theme['name'];
+
+ 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..05defbf 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'] = 'MyBB';
// 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..8e73d4d 100644
--- a/chat/lib/custom.php
+++ b/chat/lib/custom.php
@@ -5,6 +5,12 @@
* @copyright (c) Sebastian Tschan
* @license Modified MIT License
* @link https://blueimp.net/ajax/
+ *
+ * MyBB integration:
+ * http://www.mybboard.net/
*/
-// Include custom libraries and initialization code here
+// MyBB initialization:
+define('IN_MYBB', 1);
+
+require(dirname(AJAX_CHAT_PATH).'/global.php');
diff --git a/chat/lib/template/loggedOut.html b/chat/lib/template/loggedOut.html
index 5e225aa..2d08193 100644
--- a/chat/lib/template/loggedOut.html
+++ b/chat/lib/template/loggedOut.html
@@ -28,7 +28,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,7 +36,8 @@
<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">
+ <form id="loginForm" action="[FORUM_LOGIN_URL/]" method="post" enctype="application/x-www-form-urlencoded">
+ <input type="hidden" name="action" id="actionField" value="do_login"/>
<input type="hidden" name="login" id="loginField" value="login"/>
<input type="hidden" name="redirect" id="redirectField" value="[REDIRECT_URL/]"/>
<div><label for="userNameField">[LANG]userName[/LANG]:</label><br />
@@ -60,4 +61,4 @@
<div id="copyright"><a href="https://blueimp.net/ajax/">AJAX Chat</a> &copy; <a href="https://blueimp.net">blueimp.net</a></div>
</div>
</body>
-</html> \ No newline at end of file
+</html>