Files
IPB/applications/chat/Application.php
T
2025-12-19 05:32:19 -08:00

96 lines
2.6 KiB
PHP

<?php
/**
* @brief Chat Application Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2014 Invision Power Services, Inc.
* @package IPS Social Suite
* @subpackage Chat
* @since 03 Jan 2014
* @version
*/
namespace IPS\chat;
/**
* Chat Application Class
*/
class _Application extends \IPS\Application
{
/**
* Install 'other' items.
*
* @return void
*/
public function installOther()
{
/* Set non guests to be able to access */
foreach( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
{
$group->chat_access = TRUE;
$group->save();
}
}
/**
* [Node] Get Icon for tree
*
* @note Return the class for the icon (e.g. 'globe')
* @return string|null
*/
protected function get__icon()
{
return 'comment';
}
/**
* Is chat online? Returns error message if not
*
* @return string|TRUE
*/
public function offlineMessage()
{
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 ) )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'chat_currently_offline', FALSE, array( 'sprintf' => $start ) );
}
}
else
{
if( !( $currentTime >= $start ) AND $currentTime >= $end )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'chat_currently_offline', FALSE, array( 'sprintf' => $start ) );
}
}
}
}
}
}