Guest User

Untitled

a guest
May 8th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. <?php
  2. /*
  3. * @package AJAX_Chat
  4. * @author Sebastian Tschan
  5. * @copyright (c) Sebastian Tschan
  6. * @license GNU Affero General Public License
  7. * @link https://blueimp.net/ajax/
  8. *
  9. * phpBB3 integration:
  10. * http://www.phpbb.com/
  11. */
  12.  
  13. class CustomAJAXChat extends AJAXChat {
  14.  
  15. // Initialize custom configuration settings
  16. function initCustomConfig() {
  17. global $db;
  18.  
  19. // Use the existing phpBB database connection:
  20. $this->setConfig('dbConnection', 'link', $db->db_connect_id);
  21. }
  22.  
  23. // Initialize custom request variables:
  24. function initCustomRequestVars() {
  25. global $user;
  26.  
  27. // Auto-login phpBB users:
  28. if(!$this->getRequestVar('logout') && ($user->data['user_id'] != ANONYMOUS)) {
  29. $this->setRequestVar('login', true);
  30. }
  31. }
  32.  
  33. // Replace custom template tags:
  34. function replaceCustomTemplateTags($tag, $tagContent) {
  35. global $user;
  36.  
  37. switch($tag) {
  38.  
  39. case 'FORUM_LOGIN_URL':
  40. if($user->data['is_registered']) {
  41. return ($this->getRequestVar('view') == 'logs') ? './?view=logs' : './';
  42. } else {
  43. return $this->htmlEncode(generate_board_url().'/ucp.php?mode=login');
  44. }
  45.  
  46. case 'REDIRECT_URL':
  47. if($user->data['is_registered']) {
  48. return '';
  49. } else {
  50. return $this->htmlEncode($this->getRequestVar('view') == 'logs' ? $this->getChatURL().'?view=logs' : $this->getChatURL());
  51. }
  52.  
  53. default:
  54. return null;
  55. }
  56. }
  57.  
  58. // Returns true if the userID of the logged in user is identical to the userID of the authentication system
  59. // or the user is authenticated as guest in the chat and the authentication system
  60. function revalidateUserID() {
  61. global $user;
  62.  
  63. if($this->getUserRole() === AJAX_CHAT_GUEST && $user->data['user_id'] == ANONYMOUS || ($this->getUserID() === $user->data['user_id'])) {
  64. return true;
  65. }
  66. return false;
  67. }
  68.  
  69. // Returns an associative array containing userName, userID and userRole
  70. // Returns null if login is invalid
  71. function getValidLoginUserData() {
  72. global $auth,$user;
  73.  
  74. // Return false if given user is a bot:
  75. if($user->data['is_bot']) {
  76. return false;
  77. }
  78.  
  79. // Check if we have a valid registered user:
  80. if($user->data['is_registered']) {
  81. $userData = array();
  82. $userData['userID'] = $user->data['user_id'];
  83.  
  84. $userData['userName'] = $this->trimUserName($user->data['username']);
  85.  
  86. if($auth->acl_get('a_'))
  87. $userData['userRole'] = AJAX_CHAT_ADMIN;
  88. elseif($auth->acl_get('m_'))
  89. $userData['userRole'] = AJAX_CHAT_MODERATOR;
  90. else
  91. $userData['userRole'] = AJAX_CHAT_USER;
  92.  
  93. return $userData;
  94.  
  95. } else {
  96. // Guest users:
  97. return $this->getGuestUser();
  98. }
  99. }
  100.  
  101. // Store the channels the current user has access to
  102. // Make sure channel names don't contain any whitespace
  103. function &getChannels() {
  104. if($this->_channels === null) {
  105. global $auth;
  106.  
  107. $this->_channels = array();
  108.  
  109. $allChannels = $this->getAllChannels();
  110.  
  111. foreach($allChannels as $key=>$value) {
  112. // Check if we have to limit the available channels:
  113. if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
  114. continue;
  115. }
  116.  
  117. // Add the valid channels to the channel list (the defaultChannelID is always valid):
  118. if($value == $this->getConfig('defaultChannelID') || $auth->acl_get('f_read', $value)) {
  119. $this->_channels[$key] = $value;
  120. }
  121. }
  122. }
  123. return $this->_channels;
  124. }
  125.  
  126. // Store all existing channels
  127. // Make sure channel names don't contain any whitespace
  128. function &getAllChannels() {
  129. if($this->_allChannels === null) {
  130. global $db;
  131.  
  132. $this->_allChannels = array();
  133.  
  134. // Get valid phpBB forums:
  135. $sql = 'SELECT
  136. forum_id,
  137. forum_name
  138. FROM
  139. '.FORUMS_TABLE.'
  140. WHERE
  141. forum_type=1
  142. AND
  143. forum_password=\'\';';
  144. $result = $db->sql_query($sql);
  145.  
  146. $defaultChannelFound = false;
  147.  
  148. while ($row = $db->sql_fetchrow($result)) {
  149. $forumName = $this->trimChannelName($row['forum_name']);
  150.  
  151. $this->_allChannels[$forumName] = $row['forum_id'];
  152.  
  153. if(!$defaultChannelFound && $row['forum_id'] == $this->getConfig('defaultChannelID')) {
  154. $defaultChannelFound = true;
  155. }
  156. }
  157. $db->sql_freeresult($result);
  158.  
  159. if(!$defaultChannelFound) {
  160. // Add the default channel as first array element to the channel list:
  161. $this->_allChannels = array_merge(
  162. array(
  163. $this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID')
  164. ),
  165. $this->_allChannels
  166. );
  167. }
  168. }
  169. return $this->_allChannels;
  170. }
  171.  
  172. // Method to set the style cookie depending on the phpBB user style
  173. function setStyle() {
  174. global $config,$user,$db;
  175.  
  176. if(isset($_COOKIE[$this->getConfig('sessionName').'_style']) && in_array($_COOKIE[$this->getConfig('sessionName').'_style'], $this->getConfig('styleAvailable')))
  177. return;
  178.  
  179. $styleID = (!$config['override_user_style'] && $user->data['user_id'] != ANONYMOUS) ? $user->data['user_style'] : $config['default_style'];
  180. $sql = 'SELECT
  181. style_name
  182. FROM
  183. '.STYLES_TABLE.'
  184. WHERE
  185. style_id = \''.$db->sql_escape($styleID).'\';';
  186. $result = $db->sql_query($sql);
  187. $styleName = $db->sql_fetchfield('style_name');
  188. $db->sql_freeresult($result);
  189.  
  190. if(!in_array($styleName, $this->getConfig('styleAvailable'))) {
  191. $styleName = $this->getConfig('styleDefault');
  192. }
  193.  
  194. setcookie(
  195. $this->getConfig('sessionName').'_style',
  196. $styleName,
  197. time()+60*60*24*$this->getConfig('sessionCookieLifeTime'),
  198. $this->getConfig('sessionCookiePath'),
  199. $this->getConfig('sessionCookieDomain'),
  200. $this->getConfig('sessionCookieSecure')
  201. );
  202. return;
  203. }
  204. // ~cXc~ Custom Commands
  205. function parseCustomCommands($text, $textParts) {
  206. switch($textParts[0]) {
  207. // ~cXc~ AFK Status Mod Part 1of2
  208. case '/afk':
  209. case '/away':
  210. if(count($textParts) insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has went away from keyboard');
  211. } else {
  212. $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' is '.implode(' ', array_slice($textParts, 1)));
  213. }
  214. $this->setUserName($this->getLoginUserName().' - AFK');
  215. $this->updateOnlineList();
  216. $this->addInfoMessage($this->getUserName(), 'userName');
  217. $this->setSessionVar('BusyAFK', true);
  218. return true;
  219. case '/bck':
  220. case '/back':
  221. if(count($textParts) insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has returned :)');
  222. } else {
  223. $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' is back '.implode(' ', array_slice($textParts, 1)));
  224. }
  225. $this->setUserName($this->getLoginUserName());
  226. $this->updateOnlineList();
  227. $this->addInfoMessage($this->getUserName(), 'userName');
  228. $this->setSessionVar('BusyAFK', false);
  229. return true;
  230. // end ~cXc~ AFK Status Mod Part 1of2
  231. // now close function parseCustomCommands($text, $textParts)
  232. }
  233. }
  234. // end ~cXc~ Custom Commands
  235. // ~cXc~ Better AFK Status Mod Part 2of2
  236. function onNewMessage($text) {
  237. // Reset AFK status on first inserted message:
  238. if($this->getSessionVar('BusyAFK')) {
  239. $this->setUserName($this->getLoginUserName());
  240. $this->updateOnlineList();
  241. $this->addInfoMessage($this->getUserName(), 'userName');
  242. $this->setSessionVar('BusyAFK', false);
  243. }
  244. return true;
  245. }
  246. // end ~cXc~ Better AFK Status Mod Part 2of2
  247. }
  248. ?>
Advertisement
Add Comment
Please, Sign In to add comment