Advertisement
Guest User

Untitled

a guest
Jul 12th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.71 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.  * phpBB2 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.             case 'SID':
  39.                 return $this->_requestVars['sid'];
  40.  
  41.             case 'FORUM_LOGIN_URL':
  42.                 if($user->data['session_logged_in']) {
  43.                     return ($this->getRequestVar('view') == 'logs') ? './?view=logs' : './';
  44.                 } else {
  45.                     return '../login_ip.php';
  46.                 }
  47.                
  48.             case 'REDIRECT_URL':
  49.                 if($user->data['session_logged_in']) {
  50.                     return '';
  51.                 } else {
  52.                     return ($this->getRequestVar('view') == 'logs' ? 'chat/?view=logs' : 'chat/');
  53.                 }
  54.            
  55.             default:
  56.                 return null;
  57.         }
  58.     }
  59.  
  60.     // Returns true if the userID of the logged in user is identical to the userID of the authentication system
  61.     // or the user is authenticated as guest in the chat and the authentication system
  62.     function revalidateUserID() {
  63.         global $user;
  64.        
  65.         if($this->getUserRole() === AJAX_CHAT_GUEST && !$user->data['session_logged_in'] || ($this->getUserID() === $user->data['user_id'])) {
  66.             return true;
  67.         }
  68.         return false;
  69.     }
  70.  
  71.     // Returns an associative array containing userName, userID and userRole
  72.     // Returns null if login is invalid
  73.     function getValidLoginUserData() {
  74.         global $user;
  75.        
  76.         // Check if we have a valid registered user:
  77.         if($user->data['session_logged_in']) {
  78.             $userData = array();
  79.             $userData['userID'] = $user->data['user_id'];
  80.                
  81.             $userData['userName'] = $this->trimUserName($user->data['username']);
  82.            
  83.             if($user->data['user_level'] == ADMIN)
  84.                 $userData['userRole'] = AJAX_CHAT_ADMIN;
  85.             elseif($user->data['user_level'] == MOD)
  86.                 $userData['userRole'] = AJAX_CHAT_MODERATOR;
  87.             else
  88.                 $userData['userRole'] = AJAX_CHAT_USER;
  89.  
  90.             return $userData;
  91.            
  92.         } else {
  93.             // Guest users:
  94.             return $this->getGuestUser();
  95.         }
  96.     }
  97.  
  98.     // Store the channels the current user has access to
  99.     // Make sure channel names don't contain any whitespace
  100.     function &getChannels() {
  101.         if($this->_channels === null) {
  102.             global $user;
  103.  
  104.             $this->_channels = array();
  105.  
  106.             $allChannels = $this->getAllChannels();
  107.  
  108.             foreach($allChannels as $key=>$value) {
  109.                 // Check if we have to limit the available channels:
  110.                 if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
  111.                     continue;
  112.                 }
  113.  
  114.                 // Get the persmissions for the current forum_id:
  115.                 $auth = auth(AUTH_READ, $value, $user->data);
  116.  
  117.                 // Add the valid channels to the channel list (the defaultChannelID is always valid):
  118.                 if($auth['auth_read'] ||  $value == $this->getConfig('defaultChannelID')) {
  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_status=0;';
  142.             $result = $db->sql_query($sql);
  143.  
  144.             $defaultChannelFound = false;
  145.            
  146.             while ($row = $db->sql_fetchrow($result)) {
  147.                 $forumName = $this->trimChannelName($row['forum_name']);
  148.  
  149.                 $this->_allChannels[$forumName] = $row['forum_id'];
  150.  
  151.                 if(!$defaultChannelFound && $row['forum_id'] == $this->getConfig('defaultChannelID')) {
  152.                     $defaultChannelFound = true;
  153.                 }
  154.             }
  155.             $db->sql_freeresult($result);
  156.            
  157.             if(!$defaultChannelFound) {
  158.                 // Add the default channel as first array element to the channel list:
  159.                 $this->_allChannels = array_merge(
  160.                     array(
  161.                         $this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID')
  162.                     ),
  163.                     $this->_allChannels
  164.                 );
  165.             }
  166.         }
  167.         return $this->_allChannels;
  168.     }
  169.  
  170.     // Method to set the style cookie depending on the phpBB user style
  171.     function setStyle() {
  172.         global $db,$board_config,$userdata;
  173.    
  174.         if(isset($_COOKIE[$this->getConfig('sessionName').'_style']) && in_array($_COOKIE[$this->getConfig('sessionName').'_style'], $this->getConfig('styleAvailable')))
  175.             return;
  176.        
  177.         $styleID = (!$board_config['override_user_style'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_style'] > 0) ? $user->data['user_style'] : $board_config['default_style'];
  178.         $sql = 'SELECT
  179.                         style_name
  180.                     FROM
  181.                         '.THEMES_TABLE.'
  182.                     WHERE
  183.                         themes_id = '.$this->db->makeSafe($styleID).';';
  184.         $result = $db->sql_query($sql);
  185.         $styleName = $db->sql_fetchfield('style_name');
  186.         $db->sql_freeresult($result);
  187.        
  188.         if(!in_array($styleName, $this->getConfig('styleAvailable'))) {
  189.             $styleName = $this->getConfig('styleDefault');
  190.         }
  191.        
  192.         setcookie(
  193.             $this->getConfig('sessionName').'_style',
  194.             $styleName,
  195.             time()+60*60*24*$this->getConfig('sessionCookieLifeTime'),
  196.             $this->getConfig('sessionCookiePath'),
  197.             $this->getConfig('sessionCookieDomain'),
  198.             $this->getConfig('sessionCookieSecure')
  199.         );
  200.         return;
  201.     }
  202.  
  203. }
  204. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement