Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions plugins/captcha/recaptcha/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Joomla\CMS\Captcha\Google\HttpBridgePostRequestMethod;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Utilities\IpHelper;
Expand All @@ -33,6 +32,14 @@ class PlgCaptchaRecaptcha extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Reports the privacy related capabilities for this plugin to site administrators.
*
Expand Down Expand Up @@ -70,13 +77,13 @@ public function onInit($id = 'dynamic_recaptcha_1')
throw new \RuntimeException(Text::_('PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY'));
}

// Load callback first for browser compatibility
HTMLHelper::_('script', 'plg_captcha_recaptcha/recaptcha.min.js', array('version' => 'auto', 'relative' => true));
$apiSrc = 'https://www.google.com/recaptcha/api.js?onload=Joomla.initReCaptcha2&render=explicit&hl='
. Factory::getLanguage()->getTag();

HTMLHelper::_(
'script',
'https://www.google.com/recaptcha/api.js?onload=Joomla.initReCaptcha2&render=explicit&hl=' . Factory::getLanguage()->getTag()
);
// Load assets, the callback should be first
$this->app->getDocument()->getWebAssetManager()
->registerAndUseScript('plg_captcha_recaptcha', 'plg_captcha_recaptcha/recaptcha.min.js', [], ['defer' => true])
->registerAndUseScript('plg_captcha_recaptcha.api', $apiSrc, [], ['defer' => true], ['plg_captcha_recaptcha']);

return true;
}
Expand Down
33 changes: 14 additions & 19 deletions plugins/captcha/recaptcha_invisible/recaptcha_invisible.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Joomla\CMS\Captcha\Google\HttpBridgePostRequestMethod;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Utilities\IpHelper;
Expand All @@ -31,6 +30,14 @@ class PlgCaptchaRecaptcha_Invisible extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Reports the privacy related capabilities for this plugin to site administrators.
*
Expand Down Expand Up @@ -68,25 +75,13 @@ public function onInit($id = 'dynamic_recaptcha_invisible_1')
throw new \RuntimeException(Text::_('PLG_RECAPTCHA_INVISIBLE_ERROR_NO_PUBLIC_KEY'));
}

// Load callback first for browser compatibility
HTMLHelper::_(
'script',
'plg_captcha_recaptcha_invisible/recaptcha.min.js',
array('version' => 'auto', 'relative' => true),
array('async' => 'async', 'defer' => 'defer')
);
$apiSrc = 'https://www.google.com/recaptcha/api.js?onload=Joomla.initReCaptchaInvisible&render=explicit&hl='
. Factory::getLanguage()->getTag();

// Load Google reCAPTCHA api js
$file = 'https://www.google.com/recaptcha/api.js'
. '?onload=Joomla.initReCaptchaInvisible'
. '&render=explicit'
. '&hl=' . Factory::getLanguage()->getTag();
HTMLHelper::_(
'script',
$file,
array(),
array('async' => 'async', 'defer' => 'defer')
);
// Load assets, the callback should be first
$this->app->getDocument()->getWebAssetManager()
->registerAndUseScript('plg_captcha_recaptchainvisible', 'plg_captcha_recaptcha_invisible/recaptcha.min.js', [], ['defer' => true])
->registerAndUseScript('plg_captcha_recaptchainvisible.api', $apiSrc, [], ['defer' => true], ['plg_captcha_recaptchainvisible']);

return true;
}
Expand Down
16 changes: 12 additions & 4 deletions plugins/editors-xtd/readmore/readmore.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\CMSPlugin;
Expand All @@ -30,6 +28,14 @@ class PlgButtonReadmore extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Readmore button
*
Expand All @@ -41,10 +47,12 @@ class PlgButtonReadmore extends CMSPlugin
*/
public function onDisplay($name)
{
HTMLHelper::_('script', 'com_content/admin-article-readmore.min.js', array('version' => 'auto', 'relative' => true));
$doc = $this->app->getDocument();
$doc->getWebAssetManager()
->registerAndUseScript('com_content.admin-article-readmore', 'com_content/admin-article-readmore.min.js', [], ['defer' => true], ['core']);

// Pass some data to javascript
Factory::getDocument()->addScriptOptions(
$doc->addScriptOptions(
'xtd-readmore',
array(
'exists' => Text::_('PLG_READMORE_ALREADY_EXISTS', true),
Expand Down
32 changes: 22 additions & 10 deletions plugins/editors/codemirror/codemirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// No direct access
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
Expand Down Expand Up @@ -57,6 +55,14 @@ class PlgEditorCodemirror extends CMSPlugin
*/
protected $modePath = 'media/vendor/codemirror/mode/%N/%N';

/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Initialises the Editor.
*
Expand All @@ -75,13 +81,13 @@ public function onInit()
$done = true;

// Most likely need this later
$doc = Factory::getDocument();
$doc = $this->app->getDocument();

// Codemirror shall have its own group of plugins to modify and extend its behavior
PluginHelper::importPlugin('editors_codemirror');

// At this point, params can be modified by a plugin before going to the layout renderer.
Factory::getApplication()->triggerEvent('onCodeMirrorBeforeInit', array(&$this->params, &$this->basePath, &$this->modePath));
$this->app->triggerEvent('onCodeMirrorBeforeInit', array(&$this->params, &$this->basePath, &$this->modePath));

$displayData = (object) array('params' => $this->params);
$font = $this->params->get('fontFamily', '0');
Expand All @@ -105,7 +111,7 @@ public function onInit()
LayoutHelper::render('editors.codemirror.styles', $displayData, __DIR__ . '/layouts');
ob_end_clean();

Factory::getApplication()->triggerEvent('onCodeMirrorAfterInit', array(&$this->params, &$this->basePath, &$this->modePath));
$this->app->triggerEvent('onCodeMirrorAfterInit', array(&$this->params, &$this->basePath, &$this->modePath));
}

/**
Expand Down Expand Up @@ -199,7 +205,8 @@ public function onDisplay(
{
$options->theme = $theme;

HTMLHelper::_('stylesheet', $this->basePath . 'theme/' . $theme . '.css', array('version' => 'auto'));
$this->app->getDocument()->getWebAssetManager()
->registerAndUseStyle('codemirror.theme', $this->basePath . 'theme/' . $theme . '.css');
}

// Special options for tagged modes (xml/html).
Expand Down Expand Up @@ -252,11 +259,11 @@ public function onDisplay(
);

// At this point, displayData can be modified by a plugin before going to the layout renderer.
$results = Factory::getApplication()->triggerEvent('onCodeMirrorBeforeDisplay', array(&$displayData));
$results = $this->app->triggerEvent('onCodeMirrorBeforeDisplay', array(&$displayData));

$results[] = LayoutHelper::render('editors.codemirror.element', $displayData, __DIR__ . '/layouts');

foreach (Factory::getApplication()->triggerEvent('onCodeMirrorAfterDisplay', array(&$displayData)) as $result)
foreach ($this->app->triggerEvent('onCodeMirrorAfterDisplay', array(&$displayData)) as $result)
{
$results[] = $result;
}
Expand Down Expand Up @@ -321,7 +328,12 @@ protected function getFontInfo($font)
*/
protected function loadKeyMap($keyMap)
{
$ext = JDEBUG ? '.js' : '.min.js';
HTMLHelper::_('script', $this->basePath . 'keymap/' . $keyMap . $ext, array('version' => 'auto'));
$this->app->getDocument()->getWebAssetManager()
->registerAndUseScript(
'codemirror.keymap.' . $keyMap,
$this->basePath . 'keymap/' . $keyMap . '.min.js',
[],
['defer' => true]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

$params = $displayData->params;
$fontFamily = $displayData->fontFamily ?? 'monospace';
Expand All @@ -32,9 +31,10 @@
$b = hexdec($color[5] . $color[6]);
$highlightMatchColor = 'rgba(' . $r . ', ' . $g . ', ' . $b . ', .5)';

HTMLHelper::_('stylesheet', 'plg_editors_codemirror/codemirror.css', array('version' => 'auto', 'relative' => true));

Factory::getDocument()->addStyleDeclaration(
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseStyle('plg_editors_codemirror', 'plg_editors_codemirror/codemirror.css');
$wa->addInlineStyle(
<<<CSS
.CodeMirror {
font-family: $fontFamily;
Expand Down
18 changes: 14 additions & 4 deletions plugins/editors/tinymce/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Log\Log;
Expand Down Expand Up @@ -62,9 +61,20 @@ class PlgEditorTinymce extends CMSPlugin
*/
public function onInit()
{
HTMLHelper::_('behavior.core');
HTMLHelper::_('script', $this->_basePath . '/tinymce.min.js', array('version' => 'auto'));
HTMLHelper::_('script', 'plg_editors_tinymce/tinymce.min.js', array('version' => 'auto', 'relative' => true));
$wa = $this->app->getDocument()->getWebAssetManager();

if (!$wa->assetExists('script', 'tinymce'))
{
$wa->registerScript('tinymce', $this->_basePath . '/tinymce.min.js', [], ['defer' => true]);
}

if (!$wa->assetExists('script', 'plg_editors_tinymce'))
{
$wa->registerScript('plg_editors_tinymce', 'plg_editors_tinymce/tinymce.min.js', [], ['defer' => true], ['core', 'tinymce']);
}

$wa->useScript('tinymce')
->useScript('plg_editors_tinymce');
}

/**
Expand Down
20 changes: 13 additions & 7 deletions plugins/installer/webinstaller/webinstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Rule\UrlRule;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -77,15 +76,25 @@ class PlgInstallerWebinstaller extends CMSPlugin
public function onInstallerAddInstallationTab()
{
$installfrom = $this->getInstallFrom();
$doc = $this->app->getDocument();
$lang = $this->app->getLanguage();

// Push language strings to the JavaScript store
Text::script('PLG_INSTALLER_WEBINSTALLER_CANNOT_INSTALL_EXTENSION_IN_PLUGIN');
Text::script('PLG_INSTALLER_WEBINSTALLER_REDIRECT_TO_EXTERNAL_SITE_TO_INSTALL');

// TEMPORARY - Make sure Bootstrap is booted so that our client initialisation scripts can find the tab
HTMLHelper::_('bootstrap.framework');
HTMLHelper::_('script', 'plg_installer_webinstaller/client.min.js', ['version' => 'auto', 'relative' => true]);
HTMLHelper::_('stylesheet', 'plg_installer_webinstaller/client.min.css', ['version' => 'auto', 'relative' => true]);

$doc->getWebAssetManager()
->registerAndUseStyle('plg_installer_webinstaller.client', 'plg_installer_webinstaller/client.min.css')
->registerAndUseScript(
'plg_installer_webinstaller.client',
'plg_installer_webinstaller/client.min.js',
[],
['defer' => true],
['core', 'jquery']
);

$devLevel = Version::PATCH_VERSION;

Expand All @@ -94,9 +103,6 @@ public function onInstallerAddInstallationTab()
$devLevel .= '-' . Version::EXTRA_VERSION;
}

$doc = Factory::getDocument();
$lang = Factory::getLanguage();

$doc->addScriptOptions(
'plg_installer_webinstaller',
[
Expand Down Expand Up @@ -135,7 +141,7 @@ private function isRTL()
{
if ($this->rtl === null)
{
$this->rtl = strtolower(Factory::getDocument()->getDirection()) === 'rtl' ? 1 : 0;
$this->rtl = strtolower($this->app->getDocument()->getDirection()) === 'rtl' ? 1 : 0;
}

return $this->rtl;
Expand Down
11 changes: 8 additions & 3 deletions plugins/quickicon/extensionupdate/extensionupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
defined('_JEXEC') or die;

use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
Expand Down Expand Up @@ -74,8 +73,14 @@ public function onGetIcons($context)
Text::script('INFO');
Text::script('WARNING');

HTMLHelper::_('behavior.core');
HTMLHelper::_('script', 'plg_quickicon_extensionupdate/extensionupdatecheck.min.js', array('version' => 'auto', 'relative' => true));
$this->app->getDocument()->getWebAssetManager()
->registerAndUseScript(
'plg_quickicon_extensionupdate',
'plg_quickicon_extensionupdate/extensionupdatecheck.min.js',
[],
['defer' => true],
['core']
);

return array(
array(
Expand Down
5 changes: 2 additions & 3 deletions plugins/quickicon/joomlaupdate/src/Extension/Joomlaupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Joomla\CMS\Document\Document;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
Expand Down Expand Up @@ -123,8 +122,8 @@ public function getCoreUpdateNotification(QuickIconsEvent $event)
]
);

HTMLHelper::_('behavior.core');
HTMLHelper::_('script', 'plg_quickicon_joomlaupdate/jupdatecheck.min.js', array('version' => 'auto', 'relative' => true));
$this->document->getWebAssetManager()
->registerAndUseScript('plg_quickicon_joomlaupdate', 'plg_quickicon_joomlaupdate/jupdatecheck.min.js', [], ['defer' => true], ['core']);

// Add the icon to the result array
$result = $event->getArgument('result', []);
Expand Down
5 changes: 2 additions & 3 deletions plugins/quickicon/overridecheck/overridecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
Expand Down Expand Up @@ -80,8 +79,8 @@ public function onGetIcons($context)
Text::script('PLG_QUICKICON_OVERRIDECHECK_UPTODATE', true);
Text::script('PLG_QUICKICON_OVERRIDECHECK_OVERRIDEFOUND', true);

HTMLHelper::_('behavior.core');
HTMLHelper::_('script', 'plg_quickicon_overridecheck/overridecheck.js', array('version' => 'auto', 'relative' => true));
$this->app->getDocument()->getWebAssetManager()
->registerAndUseScript('plg_quickicon_overridecheck', 'plg_quickicon_overridecheck/overridecheck.js', [], ['defer' => true], ['core']);

return array(
array(
Expand Down
Loading