<?php
/*
Copyright (c) Siropu
This is a PREMIUM PAID Add-on. If you obtained this copy illegally, please go to https://www.siropu.com/ and purchase a licence to get the latest version and to receive support.
Chat Add-on by Siropu
XenForo Profile: https://xenforo.com/community/members/siropu.92813/
Website: https://www.siropu.com/
Contact: contact@siropu.com
*/
class Siropu_Chat_Listener
{
public static function load_class_datawriter($class, &$extend)
{
switch ($class)
{
case 'XenForo_DataWriter_Discussion_Thread':
$extend[] = 'Siropu_Chat_DataWriter_Discussion_Thread';
break;
case 'XenForo_DataWriter_DiscussionMessage_Post':
$extend[] = 'Siropu_Chat_DataWriter_Discussion_Post';
break;
}
}
public static function template_create(&$templateName, array &$params, XenForo_Template_Abstract $template)
{
if ($templateName == 'PAGE_CONTAINER')
{
$template->preloadTemplate('siropu_chat');
$template->preloadTemplate('siropu_chat_disabled');
}
}
public static function navigation_tabs(array &$extraTabs, $selectedTabId)
{
$options = XenForo_Application::get('options');
if ($options->siropu_chat_enabled
&& $options->siropu_chat_page_enabled
&& (Siropu_Chat_Helper::userHasPermission('view') || Siropu_Chat_Helper::userHasPermission('use')))
{
$extraTabs['chat'] = array(
'href' => XenForo_Link::buildPublicLink('chat'),
'title' => new XenForo_Phrase('siropu_chat'),
'position' => 'middle',
'selected' => ($selectedTabId == 'chat') ? true : false,
'linksTemplate' => (Siropu_Chat_Helper::userHasPermission('viewArchive') || Siropu_Chat_Helper::userHasPermission('viewBanned')) ? 'siropu_chat_tab_links' : '',
'counter' => count(self::_getModel()->getActiveUsers()),
);
}
}
public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'page_container_head'
&& self::_getOptions()->siropu_chat_enabled
&& self::_getOptions()->siropu_chat_fa_enabled
&& self::_getOptions()->siropu_chat_fa_include)
{
$contents .= '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">';
}
if (in_array($hookName, array('forum_list_nodes', 'footer')))
{
$displayMode = self::_getOptions()->siropu_chat_display_mode;
$templateParams = $template->getParams();
if (self::_getOptions()->siropu_chat_enabled
&& (Siropu_Chat_Helper::userHasPermission('view') || Siropu_Chat_Helper::userHasPermission('use'))
&& $templateParams['controllerName'] != 'Siropu_Chat_ControllerPublic_Chat')
{
if ($displayMode == 'above_forums_list' && $hookName == 'forum_list_nodes')
{
$contents = self::_getChat($template, $templateParams, true) . $contents;
}
else if ($displayMode == 'below_forums_list' && $hookName == 'forum_list_nodes')
{
$contents .= self::_getChat($template, $templateParams, true);
}
else if ($displayMode == 'all' && $hookName == 'footer')
{
$contents .= self::_getChat($template, $templateParams);
}
}
}
}
protected static function _getChat($template, $templateParams, $nodeList = false)
{
$userID = self::_getVisitor()->user_id;
$session = self::_getModel()->getSession($userID);
if ($session['user_is_banned'] && !self::_getOptions()->siropu_chat_banned_view_access)
{
return false;
}
$settings = Siropu_Chat_Helper::prepareUserSettings($session);
if (@$settings['disabled'])
{
$viewParams = array(
'nodeList' => $nodeList
);
return $template->create('siropu_chat_disabled', array_merge($viewParams, $templateParams));
}
$inverse = $settings ? @$settings['inverse'] : false;
$messages = self::_getModel()->getMessages(false, array('page' => 1, 'perPage' => self::_getOptions()->siropu_chat_messages_limit), $inverse);
$displayMode = self::_getOptions()->siropu_chat_display_mode;
switch ($displayMode)
{
case 'all':
$mode = 'AllPages';
break;
case 'above_forums_list':
case 'below_forums_list':
$mode = 'Forums';
break;
}
$viewParams = array(
'chatClass' => "siropuChat{$mode}",
'chatMode' => $displayMode,
'chatMessages' => $messages,
'chatLastRow' => Siropu_Chat_Helper::prepareLastRow($messages, $inverse),
'chatUsers' => self::_getModel()->getActiveUsers(),
'chatSession' => $session,
'chatSettings' => $settings,
'chatColors' => Siropu_Chat_Helper::prepareColorList(),
'chatNotice' => Siropu_Chat_Helper::getNotices(),
'chatAds' => Siropu_Chat_Helper::getAds(),
'bbCodeParser' => XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create())
);
return $template->create('siropu_chat', array_merge($viewParams, $templateParams));
}
protected static function _getVisitor()
{
return XenForo_Visitor::getInstance();
}
protected static function _getOptions()
{
return XenForo_Application::get('options');
}
protected static function _getModel()
{
return XenForo_Model::create('Siropu_Chat_Model');
}
}