| Current Path : /var/www/html/administrator/components/com_jchat/Framework/View/ |
| Current File : /var/www/html/administrator/components/com_jchat/Framework/View/View.php |
<?php
namespace JExtstore\Component\JChat\Administrator\Framework;
/**
*
* @package JCHAT::FRAMEWORK::administrator::components::com_jchat
* @subpackage framework
* @subpackage view
* @author Joomla! Extensions Store
* @copyright (C) 2024 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
/**
* Base view for all display core
*
* @package JCHAT::FRAMEWORK::administrator::components::com_jchat
* @subpackage framework
* @subpackage view
* @since 2.0
*/
class View extends HtmlView {
/**
* User object for ACL authorise check
*
* @access protected
* @var Object
*/
protected $user;
/**
* Reference to application
*
* @access public
* @var Object
*/
public $app;
/**
* Document object, needed by views to inject
* CSS/JS tags into document output
*
* @access public
* @var Object
*/
public $doc;
/**
* Reference to option executed
*
* @access public
* @var string
*/
public $option;
/**
* Inject language constant into JS Domain maintaining same name mapping
*
* @access protected
* @param $translations array
* @param $document Object&
* @return void
*/
protected function injectJsTranslations($translations, $document): void {
$jsInject = null;
// Do translations
foreach ( $translations as $translation ) {
$jsTranslation = strtoupper ( $translation );
$translated = Text::_( $jsTranslation, true );
$jsInject .= <<<JS
var $translation = '{$translated}';
JS;
}
$document->getWebAssetManager()->addInlineScript($jsInject);
}
/**
* Manage injecting jQuery framework into document with class inheritance support
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadJQuery($document, $loadJStorage = true): void {
$wa = $document->getWebAssetManager();
$wa->useScript('jquery');
$wa->useScript('jquery-noconflict');
array_map ( function ($script) use ($wa) {
$wa->useScript ( 'bootstrap.' . $script );
}, [
'collapse',
'modal',
'popover',
'tab'
] );
$wa->useScript('core');
// jQuery foundation framework
if($loadJStorage) {
$wa->registerAndUseScript('jchat.jstorage', 'administrator/components/com_jchat/js/jstorage.min.js', [], [], ['jquery']);
}
$base = Uri::root();
$document->getWebAssetManager()->addInlineScript("var jchatBaseURI='$base';");
}
/**
* Manage injecting Bootstrap framework into document
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadBootstrap($document): void {
// Main styles for admin interface
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.boostrap-interface', 'administrator/components/com_jchat/css/bootstrap-interface.css');
if(version_compare(JVERSION, '5', '>=')) {
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.dark-theme', 'administrator/components/com_jchat/css/dark-theme.css');
}
// Main JS file for admin interface
$document->getWebAssetManager()->registerAndUseScript ( 'jchat.boostrap-interface', 'administrator/components/com_jchat/js/bootstrap-interface.js', [], [], ['jquery']);
}
/**
* Manage injecting valildation plugin into document
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadValidation($document): void {
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.simplevalidation', 'administrator/components/com_jchat/css/simplevalidation.css');
$document->getWebAssetManager()->registerAndUseScript ( 'jchat.simplevalidation', 'administrator/components/com_jchat/js/jquery.simplevalidation.js', [], [], ['jquery']);
}
/**
* Manage injecting valildation plugin into document
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadFrontendValidation($document): void {
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.simplevalidation', 'components/com_jchat/css/simplevalidation.css');
$document->getWebAssetManager()->registerAndUseScript ( 'jchat.simplevalidation', 'components/com_jchat/js/jquery.simplevalidation.js', [], [], ['jquery']);
}
/**
* Manage injecting jQuery UI framework into document
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadJQueryUI($document): void {
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.jquery.ui', 'administrator/components/com_jchat/css/jqueryui/jquery.ui.all.css');
$document->getWebAssetManager()->registerAndUseScript ( 'jchat.jquery-ui', 'administrator/components/com_jchat/js/jquery.ui.js', [], [], ['jquery']);
}
/**
* Manage loading of the Select2 library from CDN
*
* @access protected
* @param Object& $doc
* @return void
*/
protected function loadSelect2($document): void {
$document->getWebAssetManager()->registerAndUseStyle ( 'jchat.select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css');
$document->getWebAssetManager()->registerAndUseScript ( 'jchat.select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js', [], [], ['jquery']);
}
/**
* Class constructor
*
* @param array $config
* return Object
*/
public function __construct($config = array()) {
parent::__construct ( $config );
$this->app = Factory::getApplication ();
$this->option = $this->app->getInput()->get ( 'option' );
$this->user = $this->app->getIdentity ();
$this->doc = $this->app->getDocument();
if (method_exists($this, 'setDocument')) {
$this->setDocument($this->doc);
}
}
}