Skip to content

Commit

Permalink
Misc issues for 4.0.4 (#2125)
Browse files Browse the repository at this point in the history
* Widget: embedded to have a head option xibosignage/xibo#3141
* Widget: embedded javascript should allow library references. xibosignage/xibo#3134
* Regular Maintenance: linked files shouldn't be removed. xibosignage/xibo#3143
  • Loading branch information
dasgarner authored Oct 3, 2023
1 parent 90d230a commit 7dde61d
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public function editWidget(Request $request, Response $response, $id)
foreach ($widget->mediaIds as $mediaId) {
try {
$this->mediaFactory->getById($mediaId);
} catch (NotFoundException $notFoundException) {
} catch (NotFoundException) {
throw new InvalidArgumentException(sprintf(
__('Your library reference %d does not exist.'),
$mediaId
Expand Down
2 changes: 1 addition & 1 deletion lib/Entity/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ public function applyProperties(array $properties): Widget
}
}

// Is this a medtor selector? and if so should we assign the library media
// Is this a media selector? and if so should we assign the library media
if ($property->type === 'mediaSelector') {
if (!empty($value) && is_numeric($value)) {
$this->assignMedia(intval($value));
Expand Down
28 changes: 19 additions & 9 deletions lib/Factory/MediaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,18 @@ public function query($sortOrder = null, $filterBy = [])
// Unused only?
if ($sanitizedFilter->getInt('unusedOnly') === 1) {
$body .= '
AND media.mediaId NOT IN (SELECT mediaId FROM `lkwidgetmedia`)
AND media.mediaId NOT IN (SELECT mediaId FROM `lkmediadisplaygroup`)
AND media.mediaId NOT IN (SELECT mediaId FROM `menu_category` WHERE mediaId IS NOT NULL)
AND media.mediaId NOT IN (SELECT mediaId FROM `menu_product` WHERE mediaId IS NOT NULL)
AND media.mediaId NOT IN (SELECT backgroundImageId FROM `layout` WHERE backgroundImageId IS NOT NULL)
AND media.type <> \'module\'
AND media.type <> \'font\'
AND media.type <> \'playersoftware\'
AND media.type <> \'savedreport\'
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `display_media`)
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `lkwidgetmedia`)
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `lkmediadisplaygroup`)
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `menu_category` WHERE `mediaId` IS NOT NULL)
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `menu_product` WHERE `mediaId` IS NOT NULL)
AND `media`.`mediaId` NOT IN (
SELECT `backgroundImageId` FROM `layout` WHERE `backgroundImageId` IS NOT NULL
)
AND `media`.`type` <> \'module\'
AND `media`.`type` <> \'font\'
AND `media`.`type` <> \'playersoftware\'
AND `media`.`type` <> \'savedreport\'
';

// DataSets with library images
Expand Down Expand Up @@ -665,6 +668,13 @@ public function query($sortOrder = null, $filterBy = [])
}
}

// Unlinked only?
if ($sanitizedFilter->getInt('unlinkedOnly') === 1) {
$body .= '
AND `media`.`mediaId` NOT IN (SELECT `mediaId` FROM `display_media`)
';
}

if ($sanitizedFilter->getString('name') != null) {
$terms = explode(',', $sanitizedFilter->getString('name'));
$logicalOperator = $sanitizedFilter->getString('logicalOperatorName', ['default' => 'OR']);
Expand Down
8 changes: 7 additions & 1 deletion lib/Factory/ModuleXmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private function getStencils(\DOMNodeList $nodes): array
} else if ($childNode->nodeName === 'hbs') {
$stencil->hbsId = $childNode->getAttribute('id');
$stencil->hbs = trim($childNode->textContent);
} else if ($childNode->nodeName === 'head') {
$stencil->head = trim($childNode->textContent);
} else if ($childNode->nodeName === 'style') {
$stencil->style = trim($childNode->textContent);
} else if ($childNode->nodeName === 'elements') {
Expand All @@ -77,7 +79,11 @@ private function getStencils(\DOMNodeList $nodes): array
}
}

if ($stencil->twig !== null || $stencil->hbs !== null || $stencil->style !== null) {
if ($stencil->twig !== null
|| $stencil->hbs !== null
|| $stencil->head !== null
|| $stencil->style !== null
) {
$stencils[] = $stencil;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/MediaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ public function removeExpiredFiles()
[
'expires' => Carbon::now()->format('U'),
'allModules' => 1,
'length' => 100
'unlinkedOnly' => 1,
'length' => 100,
]
) as $entry) {
// If the media type is a module, then pretend it's a generic file
Expand Down
4 changes: 4 additions & 0 deletions lib/Widget/Definition/Stencil.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Stencil implements \JsonSerializable
/** @var string|null */
public $hbs;

/** @var string|null */
public $head;

/** @var string|null */
public $style;

Expand All @@ -59,6 +62,7 @@ public function jsonSerialize(): array
return [
'hbsId' => $this->hbsId,
'hbs' => $this->hbs,
'head' => $this->head,
'style' => $this->style,
'width' => $this->width,
'height' => $this->height,
Expand Down
20 changes: 20 additions & 0 deletions lib/Widget/Render/WidgetHtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ private function render(
'gapBetweenHbs' => $module->stencil->gapBetweenHbs,
];
}
if ($module->stencil->head !== null) {
$twig['head'][] = $this->twig->fetchFromString(
$this->decorateTranslations($module->stencil->head),
$module->getPropertyValues()
);
}
if ($module->stencil->style !== null) {
$twig['style'][] = $module->stencil->style;
}
Expand Down Expand Up @@ -620,6 +626,7 @@ private function render(
foreach ($moduleTemplates as $moduleTemplate) {
// Handle extends.
$extension = $moduleTemplate->getUnmatchedProperty('extends');
$isExtensionHasHead = false;
$isExtensionHasStyle = false;

// Render out any hbs
Expand Down Expand Up @@ -659,12 +666,25 @@ private function render(
],
];

if ($extension->stencil->head !== null) {
$twig['head'][] = $extension->stencil->head;
$isExtensionHasHead = true;
}

if ($extension->stencil->style !== null) {
$twig['style'][] = $extension->stencil->style;
$isExtensionHasStyle = true;
}
}

// Render the module template's head, if present and not already output by the extension
if ($moduleTemplate->stencil !== null
&& $moduleTemplate->stencil->head !== null
&& !$isExtensionHasHead
) {
$twig['head'][] = $moduleTemplate->stencil->head;
}

// Render the module template's style, if present and not already output by the extension
if ($moduleTemplate->stencil !== null
&& $moduleTemplate->stencil->style !== null
Expand Down
27 changes: 17 additions & 10 deletions modules/embedded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,28 @@
<property id="embedStyle" type="code" allowLibraryRefs="true" variant="css">
<title>Custom Style Sheets</title>
</property>
<property id="embedScript" type="code" variant="javascript">
<property id="embedJavaScript" type="code" allowLibraryRefs="true" variant="javascript">
<title>JavaScript</title>
<helpText>Add JavaScript to be included in the HTML. Do not use [] array notation as this is reserved for library references. Do not include script tags.</helpText>
</property>
<property id="embedScript" type="code" variant="html">
<title>HEAD content to embed</title>
<helpText>Please include script tags.</helpText>
<helpText>Add content to appear within the HEAD tags on this embedded HTML. Please include script tags.</helpText>
</property>
</properties>
<preview></preview>
<stencil>
<head><![CDATA[
{{embedScript|raw}}
]]></head>
<twig><![CDATA[
{{embedHtml|raw}}
<script type="text/javascript">
{{embedScript|raw}}
</script>
<style>
{{embedStyle|raw}}
</style>
{{embedHtml|raw}}
<script type="text/javascript">
{{embedJavaScript|raw}}
</script>
<style>
{{embedStyle|raw}}
</style>
]]></twig>
</stencil>
<onInitialize><![CDATA[
Expand All @@ -90,4 +97,4 @@ if(properties.scaleContent) {
$('body').xiboLayoutScaler(globalOptions);
}
]]></onInitialize>
</module>
</module>
17 changes: 10 additions & 7 deletions modules/widget-html-render.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<!-- Copyright 2006-2022 Xibo Signage Ltd. Part of the Xibo Open Source Digital Signage Solution. Released under the AGPLv3 or later. -->
<script type="text/javascript" src="[[PlayerBundle]]"></script>
<link href="[[FontBundle]]" rel="stylesheet">
{% for item in head %}
{{ item|raw }}
{% endfor %}
<style type="text/css">
body {
margin: 0;
Expand All @@ -46,6 +49,13 @@
margin-bottom:0;
}
</style>
{% if style|length > 0 %}
<style type="text/css">
{% for item in style %}
{{ item|raw }}
{% endfor %}
</style>
{% endif %}
</head>
<body>
<div id="content"></div>
Expand All @@ -59,13 +69,6 @@
<script id="{{ asset.id }}" type="text/javascript" src="[[assetId={{ asset.id }}]]"></script>
{% endif %}
{% endfor %}
{% if style|length > 0 %}
<style type="text/css">
{% for item in style %}
{{ item|raw }}
{% endfor %}
</style>
{% endif %}
</body>
<script type="text/javascript">
var xiboICTargetId = {{ widgetId }};
Expand Down

0 comments on commit 7dde61d

Please sign in to comment.