| Current Path : /var/www/html/components/com_jchat/View/Messaging/ |
| Current File : /var/www/html/components/com_jchat/View/Messaging/HtmlView.php |
<?php
namespace JExtstore\Component\JChat\Site\View\Messaging;
/**
* @author Joomla! Extensions Store
* @package JCHAT::FORM::components::com_jchat
* @subpackage views
* @subpackage form
* @Copyright (C) 2015 Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Session\Session;
use Joomla\Registry\Registry;
use JExtstore\Component\JChat\Administrator\Framework\View as JChatView;
use JExtstore\Component\JChat\Administrator\Framework\Helpers\Users as JChatHelpersUsers;
/**
* View for JS client
*
* @package JCHAT::FORM::components::com_jchat
* @subpackage views
* @subpackage form
* @since 1.0
*/
class HtmlView extends JChatView {
// Template view variables
protected $menuTitle;
protected $activeMenu;
protected $cparams;
protected $registeredUsers;
protected $pendingMessages;
protected $params;
/**
* Return application/json response to JS client APP
* Replace $tpl optional param with $userData contents to inject
*
* @access public
* @param string $userData
* @return void
*/
public function display($tpl = null) {
$this->menuTitle = null;
$this->activeMenu = $this->app->getMenu()->getActive ();
if(!$this->activeMenu) {
$pmItemid = $this->app->getMenu()->getDefault()->id;
} else {
$pmItemid = $this->activeMenu->id;
}
$this->cparams = $this->getModel ()->getComponentParams();
if (isset ( $this->activeMenu )) {
$this->menuTitle = $this->activeMenu->title;
}
$model = $this->getModel();
$this->registeredUsers = $model->getData();
$this->pendingMessages = $model->getPendingMessages();
$this->loadJQuery($this->doc, false);
// Inject js vars
$this->doc->getWebAssetManager()->addInlineScript("var jchat_show_search=" . $this->cparams->get('show_search', 1) . ";" .
"var jchat_hide_sidebar=" . $this->cparams->get('hide_sidebar', 0) . ";" .
"var jchat_allow_media_objects=" . $this->cparams->get('allow_media_objects', 1) . ";" .
"var jchat_auto_close_popups=" . $this->cparams->get('auto_close_popups', 1) . ";" .
"var jchat_messaging_debug=" . $this->cparams->get('enable_debug', 0) . ";" .
"var jchat_privatemessaging_maximized=" . $this->cparams->get('privatemessaging_maximized', 0) . ";" .
"var jchat_auto_open_msgspopup=" . $this->cparams->get('auto_open_msgspopup', 1) . ";" .
"var jchat_avatarenable=" . $this->cparams->get('avatarenable', 1) . ";" .
"var jchat_my_avatar='" . JChatHelpersUsers::getAvatar(session_id()) . "';" .
"var jchat_my_userid=" . $this->user->id . ";" .
"var jchat_itemid=" . $pmItemid . ";" .
"var jchat_form_token='" . Session::getFormToken() . "';" .
"var jchat_messages_deletion=" . $this->cparams->get('messages_deletion', 0) . ";" .
"var jchat_messages_forward_whatsapp=" . $this->cparams->get('messages_forward_whatsapp', 0) . ";" .
"var jchat_enable_images_lightbox=" . $this->cparams->get('enable_images_lightbox', 0));
$userFieldName = $this->cparams->get('usefullname', 'username');
$this->doc->getWebAssetManager()->addInlineScript("var jchat_my_username='" . $this->user->{$userFieldName} . "';");
$this->doc->getWebAssetManager()->registerAndUseScript ('jchat.messaging', 'components/com_jchat/js/messaging.js', [], [], ['jquery'] );
$this->doc->getWebAssetManager()->registerAndUseStyle ( 'jchat.messaging', 'components/com_jchat/css/messaging.css');
// Add override color styles
if($colorOverride = $this->cparams->get('chat_color_override', null)) {
$this->doc->getWebAssetManager()->addInlineStyle ( "#jchat_private_messaging #jchat_userslist li.jchat_userbox.jchat_active, #jchat_private_messaging #jchat_userslist li.jchat_userbox.jchat_active div,#jchat_private_messaging div.jchat_userslist_ctrls div.jchat_userslist_reply{background-color:$colorOverride !important}" );
}
// Inject js translations
$translations = array('COM_JCHAT_NOMESSAGES_FOUND',
'COM_JCHAT_LOAD_OLDER_MESSAGES',
'COM_JCHAT_LOAD_NOFOUND_OLDER_MESSAGES',
'COM_JCHAT_OLDER_MESSAGES_LOADING',
'COM_JCHAT_CONFIRM_DELETE_MESSAGE',
'COM_JCHAT_CONFIRM_DELETE',
'COM_JCHAT_DISCARD_DELETE',
'COM_JCHAT_CONFIRM_DELETE_SUBMESSAGE',
'COM_JCHAT_USER_NOT_CONNECTED');
$this->injectJsTranslations($translations, $this->doc);
// Add meta info
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document
*/
protected function _prepareDocument() {
$document = $this->app->getDocument();
$menus = $this->app->getMenu();
$title = null;
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $menus->getActive();
if(is_null($menu)) {
return;
}
$this->params = new Registry();
$menuParams = $menu->getParams()->toString();
$this->params->loadString($menuParams);
$title = $this->params->get('page_title', Text::_('COM_JCHAT_PRIVATE_MESSAGING'));
$this->setDocumentTitle($title);
if ($this->params->get('menu-meta_description')) {
$document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('robots')) {
$document->setMetadata('robots', $this->params->get('robots'));
}
}
}