Skip to content

Commit

Permalink
Merge branch '5.1-dev' into 5.1/error/main
Browse files Browse the repository at this point in the history
  • Loading branch information
LadySolveig committed Feb 1, 2024
2 parents 1717ea1 + 5f6581a commit c69edde
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function refresh()
}

/**
* Load the changelog for a given extension.
* Load the changelog for a given extension. Outputs HTML encoded in JSON.
*
* @return void
*
Expand All @@ -175,4 +175,26 @@ public function loadChangelog()

echo (new JsonResponse($output));
}

/**
* Load the changelog for a given extension. Outputs HTML.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function loadChangelogRaw()
{
/** @var ManageModel $model */
$model = $this->getModel('manage');

$eid = $this->input->get('eid', 0, 'int');
$source = $this->input->get('source', 'manage', 'string');

if (!$eid) {
return;
}

echo $model->loadChangelog($eid, $source);
}
}
30 changes: 14 additions & 16 deletions administrator/components/com_installer/tmpl/manage/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('com_installer.changelog')
->useScript('table.columns')
->useScript('multiselect');
$wa->useScript('table.columns')
->useScript('multiselect')
->useScript('joomla.dialog-autocreate');

$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
Expand Down Expand Up @@ -118,20 +118,18 @@
</td>
<td class="d-none d-md-table-cell">
<?php if (!empty($item->version)) : ?>
<?php if (!empty($item->changelogurl)) : ?>
<a href="#changelogModal<?php echo $item->extension_id; ?>" class="changelogModal" data-js-extensionid="<?php echo $item->extension_id; ?>" data-js-view="manage" data-bs-toggle="modal">
<?php echo $item->version?>
</a>
<?php
echo HTMLHelper::_(
'bootstrap.renderModal',
'changelogModal' . $item->extension_id,
[
'title' => Text::sprintf('COM_INSTALLER_CHANGELOG_TITLE', $item->name, $item->version),
],
''
);
<?php if (!empty($item->changelogurl)) :
$popupOptions = [
'popupType' => 'ajax',
'textHeader' => Text::sprintf('COM_INSTALLER_CHANGELOG_TITLE', $item->name, $item->version),
'src' => Route::_('index.php?option=com_installer&task=manage.loadChangelogRaw&eid=' . $item->extension_id . '&source=manage&format=raw', false),
'width' => '800px',
'height' => 'fit-content',
];
?>
<button type="button" class="btn btn-info btn-sm"
data-joomla-dialog="<?php echo $this->escape(json_encode($popupOptions, JSON_UNESCAPED_SLASHES)); ?>">
<?php echo $item->version; ?></button>
<?php else : ?>
<?php echo $item->version; ?>
<?php endif; ?>
Expand Down
26 changes: 12 additions & 14 deletions administrator/components/com_installer/tmpl/update/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$wa = $this->document->getWebAssetManager();
$wa->useScript('multiselect')
->useScript('table.columns')
->useScript('com_installer.changelog');
->useScript('joomla.dialog-autocreate');

$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
Expand Down Expand Up @@ -117,20 +117,18 @@
<span class="badge bg-success"><?php echo $item->version; ?></span>
</td>
<td class="d-none d-md-table-cell text-center">
<?php if (!empty($item->changelogurl)) : ?>
<a href="#changelogModal<?php echo $item->extension_id; ?>" class="btn btn-info btn-sm changelogModal" data-js-extensionid="<?php echo $item->extension_id; ?>" data-js-view="update" data-bs-toggle="modal">
<?php echo Text::_('COM_INSTALLER_CHANGELOG'); ?>
</a>
<?php
echo HTMLHelper::_(
'bootstrap.renderModal',
'changelogModal' . $item->extension_id,
[
'title' => Text::sprintf('COM_INSTALLER_CHANGELOG_TITLE', $item->name, $item->version),
],
''
);
<?php if (!empty($item->changelogurl)) :
$popupOptions = [
'popupType' => 'ajax',
'textHeader' => Text::sprintf('COM_INSTALLER_CHANGELOG_TITLE', $item->name, $item->version),
'src' => Route::_('index.php?option=com_installer&task=manage.loadChangelogRaw&eid=' . $item->extension_id . '&source=update&format=raw', false),
'width' => '800px',
'height' => 'fit-content',
];
?>
<button type="button" class="btn btn-info btn-sm"
data-joomla-dialog="<?php echo $this->escape(json_encode($popupOptions, JSON_UNESCAPED_SLASHES)); ?>">
<?php echo Text::_('COM_INSTALLER_CHANGELOG'); ?></button>
<?php else :?>
<span>
<?php echo Text::_('COM_INSTALLER_TYPE_NONAPPLICABLE')?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ protected function addToolbar()

if ($canDo->get('core.create')) {
$toolbar->popupButton('batch', 'JTOOLBAR_BULK_IMPORT')
->selector('collapseModal')
->popupType('inline')
->textHeader(Text::_('COM_REDIRECT_BATCH_OPTIONS'))
->url('#joomla-dialog-batch')
->modalWidth('800px')
->modalHeight('fit-content')
->listCheck(false);
}

Expand Down
10 changes: 1 addition & 9 deletions administrator/components/com_redirect/tmpl/links/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,7 @@
&& $user->authorise('core.edit', 'com_redirect')
&& $user->authorise('core.edit.state', 'com_redirect')
) : ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
[
'title' => Text::_('COM_REDIRECT_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
],
$this->loadTemplate('batch_body')
); ?>
<template id="joomla-dialog-batch"><?php echo $this->loadTemplate('batch_body'); ?></template>
<?php endif; ?>

<input type="hidden" name="task" value="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
<div class="control-group col-md-12 mt-3">
<label for="batch_urls" class="form-label"><?php echo Text::sprintf('COM_REDIRECT_BATCH_TIP', $separator); ?></label>
<div class="controls">
<textarea class="form-control" rows="10" value="" id="batch_urls" name="batch_urls"></textarea>
<textarea class="form-control" rows="10" id="batch_urls" name="batch_urls"></textarea>
</div>
</div>
<div class="btn-toolbar pb-3">
<joomla-toolbar-button task="links.batch" class="ms-auto">
<button type="button" class="btn btn-success"><?php echo Text::_('JGLOBAL_BATCH_PROCESS'); ?></button>
</joomla-toolbar-button>
</div>
</div>
</div>

This file was deleted.

10 changes: 1 addition & 9 deletions administrator/components/com_redirect/tmpl/links/emptystate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@
&& $user->authorise('core.edit', 'com_redirect')
&& $user->authorise('core.edit.state', 'com_redirect')
) {
$displayData['formAppend'] = HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
[
'title' => Text::_('COM_REDIRECT_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
],
$this->loadTemplate('batch_body')
);
$displayData['formAppend'] = '<template id="joomla-dialog-batch">' . $this->loadTemplate('batch_body') . '</template>';
}

$collectUrlsEnabled = RedirectHelper::collectUrlsEnabled();
Expand Down
4 changes: 3 additions & 1 deletion build/media_source/com_installer/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
],
"attributes": {
"type": "module"
}
},
"deprecated": true,
"deprecatedMsg": "Use joomla.dialog asset for changelog popup"
},
{
"name": "com_installer.installer",
Expand Down
2 changes: 1 addition & 1 deletion components/com_tags/src/Helper/RouteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected static function _findItem($needles = null)

if ($items) {
foreach ($items as $item) {
if (isset($item->query, $item->query['view'])) {
if (isset($item->query['view'])) {
$lang = ($item->language != '' ? $item->language : '*');

if (!isset(self::$lookup[$lang])) {
Expand Down
38 changes: 23 additions & 15 deletions libraries/src/Document/Renderer/Html/MetasRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\WebAsset\WebAssetAttachBehaviorInterface;
use Joomla\CMS\WebAsset\WebAssetManager;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -51,33 +51,41 @@ public function render($head, $params = [], $content = null)
$app = Factory::getApplication();
$wa = $this->_doc->getWebAssetManager();

// Check for AttachBehavior and web components
foreach ($wa->getAssets('script', true) as $asset) {
if ($asset instanceof WebAssetAttachBehaviorInterface) {
$asset->onAttachCallback($this->_doc);
}
}
// Add a dummy asset for script options, this will prevent WebAssetManager from extra re-calculation later on.
$scriptOptionsAsset = $wa->addInline('script', '', ['name' => 'joomla.script.options'], [], ['core'])
->getAsset('script', 'joomla.script.options');

// Check for AttachBehavior
$onAttachCallCache = WebAssetManager::callOnAttachCallback($wa->getAssets('script', true), $this->_doc);

// Trigger the onBeforeCompileHead event
$app->getDispatcher()->dispatch(
'onBeforeCompileHead',
new BeforeCompileHeadEvent('onBeforeCompileHead', ['subject' => $app, 'document' => $this->_doc])
);

// Re-Check for AttachBehavior for newly added assets
WebAssetManager::callOnAttachCallback($wa->getAssets('script', true), $this->_doc, $onAttachCallCache);

// Add Script Options as inline asset
$scriptOptions = $this->_doc->getScriptOptions();

if ($scriptOptions) {
// Overriding ScriptOptions asset is not allowed
if ($scriptOptionsAsset !== $wa->getAsset('script', 'joomla.script.options')) {
throw new \RuntimeException('Detected an override for "joomla.script.options" asset');
}

$jsonFlags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | (JDEBUG ? JSON_PRETTY_PRINT : 0);
$jsonOptions = json_encode($scriptOptions, $jsonFlags);
$jsonOptions = $jsonOptions ?: '{}';

$wa->addInlineScript(
$jsonOptions,
['name' => 'joomla.script.options', 'position' => 'before'],
['type' => 'application/json', 'class' => 'joomla-script-options new'],
['core']
);

// Set content and update attributes of dummy asset to correct ones
$scriptOptionsAsset->setOption('content', $jsonOptions ?: '{}');
$scriptOptionsAsset->setOption('position', 'before');
$scriptOptionsAsset->setAttribute('type', 'application/json');
$scriptOptionsAsset->setAttribute('class', 'joomla-script-options new');
} else {
$wa->disableScript('joomla.script.options');
}

// Lock the AssetManager
Expand Down
21 changes: 15 additions & 6 deletions libraries/src/Mail/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,25 @@ public static function convertRelativeToAbsoluteUrls($content)
self::checkContent($content);
}

// Replace relative links, image sources with absolute Urls
// Replace relative links, image sources with absolute Urls and lazyloading
$protocols = '[a-zA-Z0-9\-]+:';
$attributes = ['href=', 'src=', 'poster='];
$attributes = ['href=', 'src=', 'poster=', 'loading=', 'data-path='];

foreach ($attributes as $attribute) {
if (strpos($content, $attribute) !== false) {
$regex = '#\s' . $attribute . '"(?!/|' . $protocols . '|\#|\')([^"]*)"#m';

$content = preg_replace($regex, ' ' . $attribute . '"' . $siteUrl . '$1"', $content);

// If the attribute is 'loading=', remove loading="lazy"
if ($attribute === 'loading=') {
$content = preg_replace('/\s' . $attribute . '"lazy"/i', '', $content);
} elseif ($attribute === 'data-path=') {
// If the attribute is 'data-path=', remove the entire attribute
$content = preg_replace('/\s' . $attribute . '"([^"]*)"/i', '', $content);
} else {
// Define a regular expression pattern for matching relative URLs in the specified attribute
$regex = '#\s' . $attribute . '"(?!/|' . $protocols . '|\#|\')([^"]*)"#m';

// Replace relative URLs with absolute URLs using the siteUrl variable
$content = preg_replace($regex, ' ' . $attribute . '"' . $siteUrl . '$1"', $content);
}
self::checkContent($content);
}
}
Expand Down

0 comments on commit c69edde

Please sign in to comment.