diff --git a/chat/css/XenForo.css b/chat/css/XenForo.css new file mode 100644 index 0000000..3cc9387 --- /dev/null +++ b/chat/css/XenForo.css @@ -0,0 +1,323 @@ +/* + * @package AJAX_Chat + * @author ManOnDaMoon + * @copyright (c) Sebastian Tschan + * @license GNU Affero General Public License + * @link https://blueimp.net/ajax/ + */ +@import url('global.css'); + +@import url('fonts.css'); + +@import url('print.css'); + +@media screen , projection , handheld { /* Main Buttons */ + #content #logoutButton,#content #submitButton,#loginForm #loginButton { + font: 12pt Calibri, 'Trebuchet MS', Verdana, Geneva, Arial, Helvetica, + sans-serif; + color: White; + font-weight: bold; + background: #e68c17 + url('../../styles/default/xenforo/gradients/form-button-white-25px.png') + repeat-x center -7px; + border: 3px solid White; + border-radius: 8px; + -webkit-border-radius: 8px; + -moz-border-radius: 8px; + -khtml-border-radius: 8px; + text-align: center; + box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2); + -webkit-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2); + -moz-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2); + -khtml-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2); + display: inline-block; + cursor: pointer; + height: 33px; + background-color: #e68c17; + padding: 0 10px 0 10px; + } + #content #logoutButton:hover,#content #submitButton:hover,#loginForm #loginButton:hover + { + box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); + -webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); + -moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); + -khtml-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); + position: relative; + top: 2px; + } + + /* BbCode Buttons */ + #content #bbCodeContainer input { + font-style: normal; + font-size: 12px; + font-family: Calibri, 'Trebuchet MS', Verdana, Geneva, Arial, Helvetica, + sans-serif; + color: rgb(0, 0, 0); + background: rgb(220, 220, 235) + url('../../styles/default/xenforo/gradients/form-button-white-25px.png') + repeat-x top; + padding: 0px 6px; + border: 1px solid rgb(221, 221, 235); + border-top-color: rgb(255, 255, 255); + border-bottom-color: rgb(179, 179, 189); + border-radius: 7px; + -webkit-border-radius: 7px; + -moz-border-radius: 7px; + -khtml-border-radius: 7px; + text-align: center; + box-shadow: 0px 1px 4px 0px rgb(200, 200, 210); + -webkit-box-shadow: 0px 1px 4px 0px rgb(200, 200, 210); + -moz-box-shadow: 0px 1px 4px 0px rgb(200, 200, 210); + -khtml-box-shadow: 0px 1px 4px 0px rgb(200, 200, 210); + text-shadow: 0 0 0 transparent, 0px -1px 2px white; + outline: none; + line-height: 23px; + display: inline-block; + cursor: pointer; + box-sizing: border-box; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + height: 23px; + } + #content #bbCodeContainer input:hover { + color: black; + text-decoration: none; + background-color: rgb(255, 255, 200); + border-color: rgb(255, 255, 200); + border-top-color: white; + border-bottom-color: rgb(190, 190, 170); + } + #content textarea { + font-size: 13px; + font-family: Calibri, 'Trebuchet MS', Verdana, Geneva, Arial, Helvetica, + sans-serif; + color: #000000; + background-color: rgb(240, 247, 252); + border-width: 1px; + border-style: solid; + border-top-color: rgb(192, 192, 192); + border-right-color: rgb(233, 233, 233); + border-bottom-color: rgb(233, 233, 233); + border-left-color: rgb(192, 192, 192); + border-radius: 4px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + -khtml-border-radius: 4px; + outline: 0; + } + #content textarea:focus { + background: rgb(255, 255, 240) + url('../../styles/default/xenforo/gradients/form-element-focus-25.png') + repeat-x; + border-top-color: rgb(150, 150, 150); + border-bottom-color: rgb(230, 230, 230); + } + #content select,#loginForm select,#loginForm input { + background-color: #F7F7FF; + color: #60A0DC; + border: 1px solid #a5cae4; + } + #content select:focus,#loginForm select:focus,#loginForm input:focus { + background: rgb(255, 255, 240) + url('../../styles/default/xenforo/gradients/form-element-focus-25.png') + repeat-x; + border-top-color: rgb(150, 150, 150); + border-bottom-color: rgb(230, 230, 230); + } +} + +/* Status Icon */ +#content #statusIconContainer { + background-image: url('../img/loading-sprite.png'); +} + +#content .statusContainerOff { + background-position: 0px 0px; +} + +#content .statusContainerOn { + background-position: 0px -22px; +} + +#content .statusContainerAlert { + background-position: 0px -44px; +} + +/* Other Theme Elements */ +#loginContent { + background-color: #176093; + color: #F7F7FF; +} + +#loginContent h1 { + color: #60A0DC; +} + +#loginContent a { + color: #60A0DC; +} + +#loginContent #errorContainer { + color: red; +} + +#content { + background-color: #F7F7FF; + color: #176093; + font-size: 12px; +} + +#content #headlineContainer { + top: 0; + left: 0; + width: 100%; + background: #176093; +} + +#content h1, #content #copyright, #content #copyright a { + color: #F7F7FF; +} + +#content #copyright { + font-style: italic; + font-size: 0.8em; +} + +#content #headlineContainer h1 { + color: #F7F7FF; + margin-left: 20px; +} + +#content a { + color: #176093; +} + +:hover { + +} + +#content #chatList { + position: absolute; + left: 20px; + right: 220px; + top: 90px; + bottom: 150px; + overflow: auto; +} + +#content #chatList,#content #colorCodesContainer { + background-color: rgb(240, 247, 252); + border: 1px solid #a5cae4; + border-radius: 10px; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + -khtml-border-radius: 10px; +} + +#content #onlineListContainer { + position: absolute; + right: 20px; + top: 90px; + width: 170px; + bottom: 150px; +} + +#content #onlineListContainer,#content #helpContainer,#content #settingsContainer, #content #reportContainer + { + padding: 10px; + background-color: rgb(240, 247, 252); + border: 1px solid #a5cae4; + border-radius: 10px; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + -khtml-border-radius: 10px; +} + +#content #onlineListContainer #onlineList, #content #helpContainer #helpList, #content #settingsContainer #settingsList, #content #reportContainer #reportList { + padding-top: 5px; +} + +#content #bbCodeContainer,#content #emoticonsContainer { + background-color: rgb(240, 247, 252); + padding: 5px; +} + +#content #colorCodesContainer a { + border-color: #a5cae4; +} + +#content #optionsContainer input { + background-color: transparent; +} + +#content .rowEven { + background: #d7edfc + url('../../styles/default/xenforo/gradients/category-23px-light.png') + repeat-x top; +} + +#content .rowOdd { + background-color: #F7F7FF; +} + +#content .guest { + color: gray; +} + +#content .user { + color: #176093; +} + +#content .moderator { + color: #00AA00; +} + +#content .admin { + color: red; +} + +#content .chatBot { + color: #60A0DC; +} + +#content #chatList .chatBotErrorMessage { + color: red; +} + +#content #chatList a { + color: #60A0DC; +} + +#content #chatList .deleteSelected { + border-color: red; +} + +#content #onlineListContainer h3,#content #helpContainer h3,#content #settingsContainer h3,#content #reportContainer h3 + { + font-size: 11px; + height: auto; + width: auto; + margin: -5px -5px 5px; + background: #f9d9b0 + url('../../styles/default/xenforo/gradients/category-23px-light.png') + repeat-x top; + color: #6d3f03; + border-top: 1px solid #f9d9b0; + border-bottom: 1px solid #f9bc6d; +} + + +#content #chatList .report { + display:block; + float:right; + width:10px; + height:10px; + margin-top:2px; + margin-left:5px; + background:url('../img/report.gif') 0 0 no-repeat; +} + +#content #chatList .report:hover { + background-position:0 -10px;; +} diff --git a/chat/lib/class/CustomAJAXChat.php b/chat/lib/class/CustomAJAXChat.php index a18e640..2e0f2b0 100644 --- a/chat/lib/class/CustomAJAXChat.php +++ b/chat/lib/class/CustomAJAXChat.php @@ -1,75 +1,134 @@ 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; + // Fetch current visitor info + $visitor = XenForo_Visitor::getInstance(); + + if ($visitor['user_id']) { + //Registered user + return $this->_setupUserData($visitor); + } else { + + if ($login = $this->getRequestVar('userName')) + { + //Authenticate + $password = $this->getRequestVar('password'); + + $loginModel = $this->_getLoginModel(); + + $needCaptcha = $loginModel->requireLoginCaptcha($login); + if ($needCaptcha) + { + switch (XenForo_Application::getOptions()->loginLimit) + { + case 'captcha': + case 'block': + return null; + } } + + $userModel = $this->_getUserModel(); + + $userId = $userModel->validateAuthentication($login, $password); + if (!$userId) + { + $loginModel->logLoginAttempt($login); + + return null; + } + + $loginModel->clearLoginAttempts($login); + + $userModel->setUserRememberCookie($userId); + + XenForo_Model_Ip::log($userId, 'user', $userId, 'login'); + + $userModel->deleteSessionActivity(0, $this->getSessionIP()); + + $session = XenForo_Application::get('session'); + $session->changeUserId($userId); + XenForo_Visitor::setup($userId); + + return $this->_setupUserData(XenForo_Visitor::getInstance()); + } + else + { + return $this->getGuestUser(); + } + } + } + + // 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() { + // Gets current visitor info + $visitor = XenForo_Visitor::getInstance(); + + return ($this->getUserRole() === AJAX_CHAT_GUEST && !$visitor['user_id'] || ($this->getUserID() === $visitor['user_id'])); + } + + // Add values to the request variables array: $this->_requestVars['customVariable'] = null; + function initCustomRequestVars() { + if($this->getRequestVar('logout') != true) { + // Fetch current visitor info + $visitor = XenForo_Visitor::getInstance(); + + // Auto login if user is authenticated in XenForo + if ($visitor['user_id'] != 0) { + $this->setRequestVar('login', true); } - - return null; - } else { - // Guest users: - return $this->getGuestUser(); } } + + // Store the channels the current user has access to // Make sure channel names don't contain any whitespace 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']; - } + // Fetch visitor & visitor permissions combo + $visitor = XenForo_Visitor::getInstance(); + $permissionCombinationId = $visitor['permission_combination_id']; + + /* @var $nodeModel XenForo_Model_Node */ + $nodeModel = XenForo_Model::create("XenForo_Model_Node"); + + $categoryModel = $this->_getCategoryModel(); // 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; - } + foreach ($this->getAllChannels() AS $key => $nodeId) { // 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($nodeId, $this->getConfig('limitChannelList'))) { continue; } - if(in_array($value, $validChannels)) { - $this->_channels[$key] = $value; + + // Checks user permissions, using canViewCategory, whether this actually is a category or not (same behavior). + if(in_array($nodeId, $this->_channels) || $categoryModel->canViewCategory(array('node_id' => $nodeId))) { + $this->_channels[$key] = $nodeId; } } + +// // Setting default channel info from config. +// $this->_channels[$this->getConfig('defaultChannelID')] = $this->getConfig('defaultChannelName'); + } return $this->_channels; } @@ -78,47 +137,72 @@ function &getChannels() { // Make sure channel names don't contain any whitespace function &getAllChannels() { if($this->_allChannels === null) { - // Get all existing channels: - $customChannels = $this->getCustomChannels(); - - $defaultChannelFound = false; - - foreach($customChannels as $name=>$id) { - $this->_allChannels[$this->trimChannelName($name)] = $id; - if($id == $this->getConfig('defaultChannelID')) { - $defaultChannelFound = true; - } + $this->_allChannels = array(); + + /* @var $nodeModel XenForo_Model_Node */ + $nodeModel = XenForo_Model::create("XenForo_Model_Node"); + // Get all forums and/or categories (depending on config) + $allChannels = $nodeModel->getAllNodes(); + + foreach($allChannels as $nodeId=>$node) { + $nodeTitle = $this->trimChannelName($node['title']); + $this->_allChannels[$nodeTitle] = $nodeId; } - 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')]); - $this->_allChannels = array_merge( - array( - $this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID') - ), - $this->_allChannels - ); - } + // Default channel, public to everyone: + $this->_allChannels[$this->trimChannelName($this->getConfig('defaultChannelName'))] = $this->getConfig('defaultChannelID'); } return $this->_allChannels; } - function &getCustomUsers() { - // List containing the registered chat users: - $users = null; - require(AJAX_CHAT_PATH.'lib/data/users.php'); - return $users; + /** + * + * @param XenForo_Visitor $visitor + * @return multitype:string unknown Ambigous + */ + protected function _setupUserData($visitor) + { + $userData = array(); + $userData['userID'] = $visitor['user_id']; + $userData['userName'] = $this->trimUserName($visitor['username']); + + // TODO : Use permissions to set role. + if ($visitor['is_admin']) + { + $userData['userRole'] = AJAX_CHAT_ADMIN; + } else { + if ($visitor['is_moderator']) { + $userData['userRole'] = AJAX_CHAT_MODERATOR; + } else { + $userData['userRole'] = AJAX_CHAT_USER; + } + } + + return $userData; + } + + /** + * @return XenForo_Model_Login + * + */ + protected function _getLoginModel() { + return XenForo_Model::create("XenForo_Model_Login"); } - 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); + /** + * @return XenForo_Model_User + * + */ + protected function _getUserModel() { + return XenForo_Model::create("XenForo_Model_User"); } - -} \ No newline at end of file + + /** + * @return XenForo_Model_Category + * + */ + protected function _getCategoryModel() { + return XenForo_Model::create("XenForo_Model_Category"); + } +} +?> \ No newline at end of file diff --git a/chat/lib/config.php.example b/chat/lib/config.php.example index 023adcd..e9cd730 100644 --- a/chat/lib/config.php.example +++ b/chat/lib/config.php.example @@ -55,9 +55,9 @@ $config['langNames'] = array( ); // Available styles: -$config['styleAvailable'] = array('beige','black','grey','Oxygen','Lithium','Sulfur','Cobalt','Mercury','Uranium','Plum','prosilver','subblack2','subSilver','Core','MyBB','vBulletin'); +$config['styleAvailable'] = array('XenForo', 'beige','black','grey','Oxygen','Lithium','Sulfur','Cobalt','Mercury','Uranium','Plum','prosilver','subblack2','subSilver','Core','MyBB','vBulletin'); // Default style: -$config['styleDefault'] = 'prosilver'; +$config['styleDefault'] = 'XenForo'; // The encoding used for the XHTML content: $config['contentEncoding'] = 'UTF-8'; diff --git a/chat/lib/custom.php b/chat/lib/custom.php index a9d0884..b5c2e19 100644 --- a/chat/lib/custom.php +++ b/chat/lib/custom.php @@ -8,4 +8,22 @@ */ // Include custom libraries and initialization code here + +// How to use XenForo Objects: Once initialized the below you can use XenForo objects +define('XF_ROOT', AJAX_CHAT_PATH . '../'); +define('TIMENOW', time()); +define('SESSION_BYPASS', false); // if true: logged in user info and sessions are not needed +require_once(XF_ROOT . '/library/XenForo/Autoloader.php'); +XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT . '/library'); +XenForo_Application::initialize(XF_ROOT . '/library', XF_ROOT); +XenForo_Application::set('page_start_time', TIMENOW); +XenForo_Application::disablePhpErrorHandler(); + +// Loads class dependencies, initilizing XF code events listeners. +$dependencies = new XenForo_Dependencies_Public(); +$dependencies->preLoadData(); + +XenForo_Session::startPublicSession(); +error_reporting(E_ALL & ~E_NOTICE); // Turn off the strict error reporting. + ?> \ No newline at end of file diff --git a/readme.md b/readme.md index 931d8b8..210f95b 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,11 @@ -AJAX Chat Standalone -==================== +AJAX Chat for XenForo +===================== -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 XenForo. AJAX stands for "Asynchronous JavaScript and XML". The AJAX Chat clients (the user browsers) use JavaScript to query the web server for updates. -Instead of delivering a complete HTML page only updated data is sent in XML format. +Instead of delivering a complete HTML page only updated data is sent in XML format. By using JavaScript the chat page can be updated without having to reload the whole page. @@ -14,7 +14,7 @@ Requirements -| *Server-Side* | *Client-Side* | +| *Server-Side* | *Client-Side* | | ---------------------- | ---------------------------- | | PHP >= 5 | Enabled JavaScript | | MySQL >= 4 | Enabled Cookies |