Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Action Controller
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Chat
|
||||
* @since 23 Mar 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\chat\modules\front\chat;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Controller
|
||||
*/
|
||||
class _action extends \IPS\Content\Controller
|
||||
{
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user to the chat room
|
||||
*
|
||||
* @return void
|
||||
* @note Forum (local) user ID is in \IPS\Request::i()->id and Chat user ID is in \IPS\Request::i()->user
|
||||
*/
|
||||
protected function addUser()
|
||||
{
|
||||
$member = \IPS\Member::load( intval( \IPS\Request::i()->id ) );
|
||||
|
||||
$map = array(
|
||||
'user_id' => intval( \IPS\Request::i()->user ),
|
||||
'forumUserID' => intval( \IPS\Request::i()->id ),
|
||||
'prefix' => $member->group['prefix'],
|
||||
'suffix' => $member->group['suffix'],
|
||||
'photo' => $member->photo,
|
||||
'username' => $member->member_id ? $member->name : $member->loggedIn()->language()->get('guest'),
|
||||
'formattedUsername' => \IPS\Member\Group::load( $member->member_group_id )->formatName( $member->name ),
|
||||
'canBeIgnored' => $member->member_id ? !$member->group['gbw_cannot_be_ignored'] : 1,
|
||||
'canBypassBadwords' => $member->group['g_bypass_badwords'],
|
||||
'groupID' => $member->member_group_id,
|
||||
'profileUrl' => $member->url(),
|
||||
'canModerate' => $member->group['chat_moderate'],
|
||||
'seo_name' => $member->members_seo_name,
|
||||
'last_update' => time(),
|
||||
);
|
||||
|
||||
/* Update the chatters list */
|
||||
$chatters = ( isset( \IPS\Data\Store::i()->chatters ) ) ? \IPS\Data\Store::i()->chatters : array();
|
||||
$chatters[ $map['user_id'] ] = $map;
|
||||
|
||||
\IPS\Data\Store::i()->chatters = $chatters;
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->json( array(
|
||||
'html' => \IPS\Theme::i()->getTemplate( 'view' )->userRow( $map ),
|
||||
'user' => $map
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load user info
|
||||
*
|
||||
* @return void
|
||||
* @note Forum (local) user ID is in \IPS\Request::i()->id
|
||||
*/
|
||||
protected function loadUserInfo()
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'view', 'chat' )->userInfo( \IPS\Member::load( intval( \IPS\Request::i()->id ) ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore and unignore chats
|
||||
*
|
||||
* @return void
|
||||
* @note Forum (local) user ID is in \IPS\Request::i()->id
|
||||
*/
|
||||
protected function blockUser()
|
||||
{
|
||||
/* Make sure there is an ID */
|
||||
if( !\IPS\Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/* Make sure we can ignore this user */
|
||||
$user = \IPS\Member::load( \IPS\Request::i()->id );
|
||||
|
||||
if( $user->group['gbw_cannot_be_ignored'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_ignore', '3H269/K', 403, '' );
|
||||
}
|
||||
|
||||
/* Update or insert the ignore */
|
||||
try
|
||||
{
|
||||
$existing = \IPS\Db::i()->select( '*', 'core_ignored_users', array( 'ignore_owner_id=? AND ignore_ignore_id=?', \IPS\Member::loggedIn()->member_id, \IPS\Request::i()->id ) )->first();
|
||||
|
||||
\IPS\Db::i()->update( 'core_ignored_users', array( 'ignore_chats' => $existing['ignore_chats'] ? 0 : 1 ), array( 'ignore_id=?', $existing['ignore_id'] ) );
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_ignored_users', array(
|
||||
'ignore_owner_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'ignore_ignore_id' => intval( \IPS\Request::i()->id ),
|
||||
'ignore_chats' => 1
|
||||
) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ban user
|
||||
*
|
||||
* @return void
|
||||
* @note Forum (local) user ID is in \IPS\Request::i()->id
|
||||
*/
|
||||
protected function banUser()
|
||||
{
|
||||
/* Make sure there is an ID */
|
||||
if( !\IPS\Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/* Make sure we can moderate */
|
||||
if( !\IPS\Member::loggedIn()->group['chat_moderate'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_ban', '3H269/L', 403, '' );
|
||||
}
|
||||
|
||||
/* Ban the user */
|
||||
$user = \IPS\Member::load( \IPS\Request::i()->id );
|
||||
$user->chat_banned = 1;
|
||||
$user->save();
|
||||
|
||||
/* Remove us from chatters list */
|
||||
$chatters = ( isset( \IPS\Data\Store::i()->chatters ) ) ? \IPS\Data\Store::i()->chatters : array();
|
||||
|
||||
foreach( $chatters as $uid => $chatter )
|
||||
{
|
||||
if( $chatter['forumUserID'] == $user->member_id )
|
||||
{
|
||||
unset( $chatters[ $uid ] );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->chatters = $chatters;
|
||||
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping to keep us in chatters list
|
||||
*
|
||||
* @return void
|
||||
* @note Forum (local) user ID is in \IPS\Request::i()->id
|
||||
*/
|
||||
protected function ping()
|
||||
{
|
||||
/* Make sure there is an ID */
|
||||
if( !\IPS\Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
|
||||
/* If the data store doesn't exist it was wiped, so recreate it */
|
||||
if( !isset( \IPS\Data\Store::i()->chatters ) )
|
||||
{
|
||||
$chatters = array();
|
||||
$options = $_SESSION['chatOptions'];
|
||||
|
||||
$result = \IPS\Http\Url::external( "http://{$options['serverHost']}{$options['serverPath']}/list.php?room={$options['roomId']}&user={$options['userId']}&access_key={$options['accessKey']}" )->request()->get();
|
||||
|
||||
if( $result )
|
||||
{
|
||||
$results = explode( "~~||~~", $result );
|
||||
$status = array_shift( $results );
|
||||
|
||||
if( $status == 1 )
|
||||
{
|
||||
foreach( $results as $k => $v )
|
||||
{
|
||||
$_thisRecord = explode( ',', $v );
|
||||
|
||||
if( !$_thisRecord[0] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( intval( $_thisRecord[2] ) );
|
||||
$username = str_replace( '~~#~~', ',', $_thisRecord[1] );
|
||||
|
||||
$chatters[ $_thisRecord[0] ] = array(
|
||||
'user_id' => $_thisRecord[0],
|
||||
'username' => htmlspecialchars( $username, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE ),
|
||||
'forumUserID' => $member->member_id,
|
||||
'canBeIgnored' => $member->member_id ? !$member->group['gbw_cannot_be_ignored'] : 1,
|
||||
'canBypassBadwords' => $member->group['g_bypass_badwords'],
|
||||
'groupID' => $member->member_group_id,
|
||||
'prefix' => str_replace( '"', '__DBQ__', $member->group['prefix'] ),
|
||||
'suffix' => str_replace( '"', '__DBQ__', $member->group['suffix'] ),
|
||||
'photo' => $member->photo,
|
||||
'profileUrl' => $member->url(),
|
||||
'canModerate' => $member->group['chat_moderate'],
|
||||
'seo_name' => $member->members_seo_name,
|
||||
'last_update' => time(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$chatters = \IPS\Data\Store::i()->chatters;
|
||||
}
|
||||
|
||||
/* Update us in chatters list - session will be auto-handled */
|
||||
if( isset( $chatters[ \IPS\Request::i()->id ] ) )
|
||||
{
|
||||
$chatters[ \IPS\Request::i()->id ]['last_update'] = time();
|
||||
|
||||
\IPS\Data\Store::i()->chatters = $chatters;
|
||||
}
|
||||
|
||||
/* Return a response */
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,481 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief View File Controller
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Chat
|
||||
* @since 10 Oct 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\chat\modules\front\chat;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* View File Controller
|
||||
*/
|
||||
class _view extends \IPS\Content\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Master chat server URL
|
||||
*/
|
||||
const MASTERSERVER = "http://chatservice.ipsdns.com/";
|
||||
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/* Check that the license allows access, etc. */
|
||||
$licenseData = \IPS\IPS::licenseKey();
|
||||
|
||||
if( !$licenseData )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_license', '4H268/1', 500, 'ipschat_no_license_admin' );
|
||||
}
|
||||
|
||||
if( !isset( $licenseData['chat_limit'] ) OR $licenseData['chat_limit'] < 1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_license', '4H269/1', 500, 'ipschat_no_license_access' );
|
||||
}
|
||||
|
||||
/* Group access check */
|
||||
if( !\IPS\Member::loggedIn()->group['chat_access'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_group_access', '2H269/2', 403, '' );
|
||||
}
|
||||
|
||||
/* Is this a guest that was blocked? */
|
||||
if( !\IPS\Member::loggedIn()->member_id AND isset( \IPS\Request::i()->cookie['chat_blocked'] ) AND \IPS\Request::i()->cookie['chat_blocked'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_access', '2H269/3', 403, '' );
|
||||
}
|
||||
|
||||
/* Or a member? */
|
||||
if( \IPS\Member::loggedIn()->chat_banned )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_access', '2H269/5', 403, '' );
|
||||
}
|
||||
|
||||
/* Spiders also do not have access */
|
||||
if( \IPS\Session\Front::i()->userAgent->spider )
|
||||
{
|
||||
\IPS\Output::i()->error( 'ipschat_no_access', '2H269/4', 403, '' );
|
||||
}
|
||||
|
||||
/* Figure out if chat is online due to time restrictions */
|
||||
if( \IPS\Settings::i()->ipschat_online )
|
||||
{
|
||||
$times = explode( ',', \IPS\Settings::i()->ipschat_online );
|
||||
|
||||
if( count( $times ) AND $times[0] )
|
||||
{
|
||||
/* Do we need to adjust the time zone? */
|
||||
if( isset( $times[2] ) AND $times[2] != \IPS\Member::loggedIn()->timezone )
|
||||
{
|
||||
$start = new \IPS\DateTime( '2015-01-01 ' . $times[0], new \DateTimeZone( $times[2] ) );
|
||||
$start->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
|
||||
$times[0] = $start->format( 'H:i' );
|
||||
|
||||
$end = new \IPS\DateTime( '2015-01-01 ' . $times[1], new \DateTimeZone( $times[2] ) );
|
||||
$end->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
|
||||
$times[1] = $end->format( 'H:i' );
|
||||
}
|
||||
|
||||
$currentTime = new \IPS\DateTime( NULL, new \DateTimeZone( ( isset( $times[2] ) ) ? $times[2] : \IPS\Member::loggedIn()->timezone ) );
|
||||
$currentTime->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
|
||||
$currentTime = $currentTime->format( 'H:i' );
|
||||
|
||||
/* Convert times to floats, as that is simple to compare */
|
||||
$start = str_replace( ':', '.', $times[0] );
|
||||
$end = str_replace( ':', '.', $times[1] );
|
||||
$currentTime = str_replace( ':', '.', $currentTime );
|
||||
|
||||
if( $end > $start )
|
||||
{
|
||||
if( !( $currentTime >= $start ) OR !( $currentTime < $end ) )
|
||||
{
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'chat_currently_offline', FALSE, array( 'sprintf' => $start ) ), '1H269/I', 403, 'chat_offline_admin' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !( $currentTime >= $start ) AND $currentTime >= $end )
|
||||
{
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'chat_currently_offline', FALSE, array( 'sprintf' => $start ) ), '1H269/J', 403, 'chat_offline_admin' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Chat
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Initiate output */
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'jquery/jquery.rangyinputs.js', 'core', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'buzz/buzz.min.js', 'chat', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'esrever/esrever.js', 'chat', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_chat.js', 'chat', 'front' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'chat.css', 'chat', 'front' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'chat_responsive.css', 'chat', 'front' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'chat_title' );
|
||||
|
||||
/* Check rules */
|
||||
if( \IPS\Settings::i()->ipschat_enable_rules )
|
||||
{
|
||||
$proceed = FALSE;
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'chat_rules', 'accept_rules' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->hiddenValues['proceed'] = TRUE;
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
if( $values['proceed'] )
|
||||
{
|
||||
$proceed = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we haven't agreed yet, show the form */
|
||||
if( !$proceed )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->acceptRules( $form );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initiate our options */
|
||||
$options = array(
|
||||
'roomId' => 0,
|
||||
'userId' => 0,
|
||||
'userName' => $this->cleanUsername( \IPS\Member::loggedIn()->member_id ? \IPS\Member::loggedIn()->name : \IPS\Member::loggedIn()->language()->get('guest') ),
|
||||
'accessKey' => '',
|
||||
'serverHost' => '',
|
||||
'serverPath' => '',
|
||||
);
|
||||
|
||||
/* Call master to retrieve info */
|
||||
try
|
||||
{
|
||||
$result = \IPS\Http\Url::external( self::MASTERSERVER . "gateway31.php?api_key=" . \IPS\Settings::i()->ipb_reg_number . "&user={$options['userName']}&level=" . \IPS\Member::loggedIn()->group['chat_moderate'] )->request()->get();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '4H268/2', 500, 'connect_gw_error_0' );
|
||||
}
|
||||
$results = explode( ',', $result );
|
||||
|
||||
|
||||
/* Error? */
|
||||
if( $results[0] == 0 )
|
||||
{
|
||||
switch( $results[1] )
|
||||
{
|
||||
// No license key
|
||||
case 1:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/7', 500, 'connect_gw_error_1' );
|
||||
break;
|
||||
|
||||
// No username
|
||||
case 2:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/8', 500, 'connect_gw_error_2' );
|
||||
break;
|
||||
|
||||
// MySQL error
|
||||
case 3:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H268/3', 500, 'connect_gw_error_3' );
|
||||
break;
|
||||
|
||||
// Invalid room ID
|
||||
case 5:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/A', 500, 'connect_gw_error_5' );
|
||||
break;
|
||||
|
||||
// Chat room full
|
||||
case 6:
|
||||
$key = \IPS\IPS::licenseKey();
|
||||
\IPS\Output::i()->error( 'chat_room_full', ( $key['chat_limit'] ? '1' : '4' ) . 'H269/B', 403, $key['chat_limit'] ? 'license_no_chat' : NULL );
|
||||
break;
|
||||
|
||||
// Chat room full
|
||||
case 7:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/A', 500, 'connect_gw_error_5' );
|
||||
break;
|
||||
|
||||
// The chat room is on a server which is no longer online
|
||||
case 8:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H268/4', 500, 'connect_gw_error_8' );
|
||||
break;
|
||||
|
||||
// No online chat servers could be found
|
||||
case 10:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H268/5', 500, 'connect_gw_error_10' );
|
||||
break;
|
||||
|
||||
// Other
|
||||
default:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/6', 500 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the options we just got from the master chat server */
|
||||
$options['roomId'] = intval($results[3]);
|
||||
$options['serverHost'] = $results[1];
|
||||
$options['serverPath'] = $results[2];
|
||||
|
||||
/* If this is a guest, adjust the URL to send an identifier */
|
||||
$guestFlag = ( !\IPS\Member::loggedIn()->member_id and isset( \IPS\Request::i()->cookie['chat_user_id'] ) ) ? "&userid=" . intval( \IPS\Request::i()->cookie['chat_user_id'] ) : '';
|
||||
|
||||
/* Now join the actual chat room */
|
||||
try
|
||||
{
|
||||
$result = \IPS\Http\Url::external( "http://{$options['serverHost']}{$options['serverPath']}/join31.php?api_key=" . \IPS\Settings::i()->ipb_reg_number . "&user={$options['userName']}&level=" . \IPS\Member::loggedIn()->group['chat_moderate'] . "&room={$options['roomId']}&forumid=" . \IPS\Member::loggedIn()->member_id . "{$guestFlag}&forumgroup=" . \IPS\Member::loggedIn()->member_group_id )->request()->get();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '4H268/2', 500, 'connect_gw_error_0' );
|
||||
}
|
||||
$results = explode( ',', $result );
|
||||
|
||||
/* Error? */
|
||||
if( $results[0] == 0 )
|
||||
{
|
||||
switch( $results[1] )
|
||||
{
|
||||
// No license key
|
||||
case 1:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/C', 500, 'connect_gw_error_1' );
|
||||
break;
|
||||
|
||||
// No username
|
||||
case 2:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/D', 500, 'connect_gw_error_2' );
|
||||
break;
|
||||
|
||||
// No room ID
|
||||
case 3:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/E', 500, 'connect_gw_error_3' );
|
||||
break;
|
||||
|
||||
// MySQL error
|
||||
case 4:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/E', 500, 'connect_gw_error_4' );
|
||||
break;
|
||||
|
||||
// Could not create room
|
||||
case 5:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/F', 500, 'connect_gw_error_5' );
|
||||
break;
|
||||
|
||||
// License key mismatch
|
||||
case 6:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H269/G', 500, 'connect_gw_error_6' );
|
||||
break;
|
||||
|
||||
// Chat room full
|
||||
case 7:
|
||||
$key = \IPS\IPS::licenseKey();
|
||||
\IPS\Output::i()->error( 'chat_room_full', ( $key['chat_limit'] ? '1' : '4' ) . 'H269/H', 500, $key['chat_limit'] ? 'license_no_chat' : NULL );
|
||||
break;
|
||||
|
||||
// Other
|
||||
default:
|
||||
\IPS\Output::i()->error( 'generic_chatconnect_error', '5H268/6', 500, 'connect_gw_error_0' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remember the important parts of this response */
|
||||
$options['userId'] = $results[1];
|
||||
$options['accessKey'] = $results[2];
|
||||
|
||||
/* If this is a guest, set the chat user ID cookie */
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'chat_user_id', $options['userId'], NULL, FALSE );
|
||||
}
|
||||
|
||||
/* Fetch the online users list and build the map */
|
||||
$chatters = array();
|
||||
|
||||
$result = \IPS\Http\Url::external( "http://{$options['serverHost']}{$options['serverPath']}/list.php?room={$options['roomId']}&user={$options['userId']}&access_key={$options['accessKey']}" )->request()->get();
|
||||
|
||||
if( $result )
|
||||
{
|
||||
$results = explode( "~~||~~", $result );
|
||||
$status = array_shift( $results );
|
||||
|
||||
if( $status == 1 )
|
||||
{
|
||||
foreach( $results as $k => $v )
|
||||
{
|
||||
$_thisRecord = explode( ',', $v );
|
||||
|
||||
if( !$_thisRecord[0] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( intval( $_thisRecord[2] ) );
|
||||
$username = str_replace( '~~#~~', ',', $_thisRecord[1] );
|
||||
|
||||
$chatters[ $username ] = array(
|
||||
'user_id' => $_thisRecord[0],
|
||||
'username' => htmlspecialchars( $username, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE ),
|
||||
'formattedUsername' => \IPS\Member\Group::load( $member->member_group_id )->formatName( $member->name ),
|
||||
'forumUserID' => $member->member_id,
|
||||
'canBeIgnored' => $member->member_id ? !$member->group['gbw_cannot_be_ignored'] : 1,
|
||||
'canBypassBadwords' => $member->group['g_bypass_badwords'],
|
||||
'groupID' => $member->member_group_id,
|
||||
'prefix' => str_replace( '"', '__DBQ__', $member->group['prefix'] ),
|
||||
'suffix' => str_replace( '"', '__DBQ__', $member->group['suffix'] ),
|
||||
'photo' => $member->photo,
|
||||
'profileUrl' => $member->url(),
|
||||
'canModerate' => $member->group['chat_moderate'],
|
||||
'seo_name' => $member->members_seo_name,
|
||||
'last_update' => time(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($chatters);
|
||||
|
||||
$forumIdMap = array();
|
||||
|
||||
foreach( $chatters as $chatter )
|
||||
{
|
||||
$forumIdMap[ $chatter['user_id'] ] = $chatter;
|
||||
}
|
||||
|
||||
/* Update the chatters list */
|
||||
if( count( $chatters ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->chatters = $forumIdMap;
|
||||
}
|
||||
|
||||
/* Get badwords list */
|
||||
$badwords = iterator_to_array( \IPS\Db::i()->select( 'm_exact, swop, type', 'core_profanity_filters' )->setKeyField( 'type' ) );
|
||||
|
||||
/* Get groups */
|
||||
$groups = array();
|
||||
|
||||
foreach( \IPS\Member\Group::groups() as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = array( 'prefix' => $group->prefix, 'suffix' => $group->suffix, 'bypassBadwords' => $group->g_bypass_badwords );
|
||||
}
|
||||
|
||||
/* Are we ignoring any chats? */
|
||||
if( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$ignored = iterator_to_array( \IPS\Db::i()->select( 'ignore_ignore_id, ignore_id', 'core_ignored_users', array( 'ignore_owner_id=? and ignore_chats=1', \IPS\Member::loggedIn()->member_id ) )->setKeyField( 'ignore_ignore_id' )->setValueField( 'ignore_id' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$ignored = array();
|
||||
}
|
||||
|
||||
/* Emoticons */
|
||||
$emoticons = array();
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_emoticons', NULL, 'emo_set,emo_position' ) as $row )
|
||||
{
|
||||
$emoticons[ $row['typed'] ] = (string) \IPS\File::get( 'core_Emoticons', $row['image'] )->url;
|
||||
}
|
||||
|
||||
/* We store the chat options in our session in case we choose to leave the room */
|
||||
$_SESSION['chatOptions'] = $options;
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->chat( $forumIdMap );
|
||||
\IPS\Output::i()->endBodyCode .= \IPS\Theme::i()->getTemplate( 'view' )->chatvars( $options, $forumIdMap, $groups, $badwords, $ignored, $emoticons );
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave Chat
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function leave()
|
||||
{
|
||||
/* Check secure key */
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Call server */
|
||||
if( isset( $_SESSION['chatOptions'] ) )
|
||||
{
|
||||
$options = $_SESSION['chatOptions'];
|
||||
|
||||
\IPS\Http\Url::external( "http://{$options['serverHost']}{$options['serverPath']}/leave.php?room={$options['roomId']}&user={$options['userId']}&access_key={$options['accessKey']}" )->request()->get();
|
||||
|
||||
unset( $_SESSION['chatOptions'] );
|
||||
}
|
||||
|
||||
/* Remove us from chatters list */
|
||||
$chatters = ( isset( \IPS\Data\Store::i()->chatters ) ) ? \IPS\Data\Store::i()->chatters : array();
|
||||
|
||||
foreach( $chatters as $uid => $chatter )
|
||||
{
|
||||
if( $chatter['forumUserID'] == \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
unset( $chatters[ $uid ] );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->chatters = $chatters;
|
||||
|
||||
// If this is a popup, close it, otherwise send us back to the suite index
|
||||
if( \IPS\Request::i()->_popup == 1 )
|
||||
{
|
||||
\IPS\Output::i()->output = "<script type='text/javascript'>window.close();</script>";
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "_leaveChat=1" ), 'leave_chat_room' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean username for chat
|
||||
*
|
||||
* @param string Username
|
||||
* @return string
|
||||
*/
|
||||
protected function cleanUsername( $username )
|
||||
{
|
||||
$username = str_replace( "\r", '', $username );
|
||||
$username = str_replace( "\n", '__N__', $username );
|
||||
$username = str_replace( ",", '__C__', $username );
|
||||
$username = str_replace( "=", '__E__', $username );
|
||||
$username = str_replace( "+", '__PS__', $username );
|
||||
$username = str_replace( "&", '__A__', $username );
|
||||
$username = str_replace( "%", '__P__', $username );
|
||||
$username = urlencode($username);
|
||||
|
||||
return $username;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user