Skip to content

Commit

Permalink
XMDS: ensure that the CDN URL is obeyed if present. (#2891)
Browse files Browse the repository at this point in the history
* XMDS: ensure that the CDN URL is obeyed if present.
 fixes xibosignage/xibo#3578
  • Loading branch information
dasgarner authored Feb 6, 2025
1 parent c7f25f9 commit 58bfa79
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
29 changes: 24 additions & 5 deletions lib/Widget/Render/WidgetDataProviderCache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 Xibo Signage Ltd
* Copyright (C) 2025 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -33,6 +33,7 @@
use Xibo\Helper\DateFormatHelper;
use Xibo\Helper\LinkSigner;
use Xibo\Helper\ObjectVars;
use Xibo\Service\ConfigServiceInterface;
use Xibo\Support\Exception\GeneralException;
use Xibo\Widget\Provider\DataProvider;
use Xibo\Widget\Provider\DataProviderInterface;
Expand Down Expand Up @@ -324,6 +325,7 @@ private function decorateMediaForPreview(callable $urlFor, ?string $data): ?stri

/**
* Decorate for a player
* @param \Xibo\Service\ConfigServiceInterface $configService
* @param \Xibo\Entity\Display $display
* @param string $encryptionKey
* @param array $data The data
Expand All @@ -332,25 +334,40 @@ private function decorateMediaForPreview(callable $urlFor, ?string $data): ?stri
* @throws \Xibo\Support\Exception\NotFoundException
*/
public function decorateForPlayer(
ConfigServiceInterface $configService,
Display $display,
string $encryptionKey,
array $data,
array $storedAs
array $storedAs,
): array {
$this->getLog()->debug('decorateForPlayer');

$cdnUrl = $configService->getSetting('CDN_URL');

foreach ($data as $row => $item) {
// Each data item can be an array or an object
if (is_array($item)) {
foreach ($item as $key => $value) {
if (is_string($value)) {
$data[$row][$key] = $this->decorateMediaForPlayer($display, $encryptionKey, $storedAs, $value);
$data[$row][$key] = $this->decorateMediaForPlayer(
$cdnUrl,
$display,
$encryptionKey,
$storedAs,
$value,
);
}
}
} else if (is_object($item)) {
foreach (ObjectVars::getObjectVars($item) as $key => $value) {
if (is_string($value)) {
$item->{$key} = $this->decorateMediaForPlayer($display, $encryptionKey, $storedAs, $value);
$item->{$key} = $this->decorateMediaForPlayer(
$cdnUrl,
$display,
$encryptionKey,
$storedAs,
$value
);
}
}
}
Expand All @@ -359,6 +376,7 @@ public function decorateForPlayer(
}

/**
* @param string|null $cdnUrl
* @param \Xibo\Entity\Display $display
* @param string $encryptionKey
* @param array $storedAs
Expand All @@ -367,6 +385,7 @@ public function decorateForPlayer(
* @throws \Xibo\Support\Exception\NotFoundException
*/
private function decorateMediaForPlayer(
?string $cdnUrl,
Display $display,
string $encryptionKey,
array $storedAs,
Expand All @@ -390,7 +409,7 @@ private function decorateMediaForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'M',
$value[1],
$storedAs[$value[1]]
Expand Down
11 changes: 6 additions & 5 deletions lib/Widget/Render/WidgetHtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ public function decorateForPlayer(
? '&v=7&serverKey=' . $this->config->getSetting('SERVER_KEY') . '&hardwareKey=' . $display->license
: null;
$encryptionKey = $this->config->getApiKeyDetails()['encryptionKey'];
$cdnUrl = $this->config->getSetting('CDN_URL');

$matches = [];
preg_match_all('/\[\[(.*?)\]\]/', $output, $matches);
Expand All @@ -374,7 +375,7 @@ public function decorateForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'P',
1,
'bundle.min.js',
Expand All @@ -393,7 +394,7 @@ public function decorateForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'P',
1,
'fonts.css',
Expand Down Expand Up @@ -442,7 +443,7 @@ public function decorateForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'M',
$value[1],
$storedAs[$value[1]]
Expand Down Expand Up @@ -470,7 +471,7 @@ public function decorateForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'P',
$asset->id,
$asset->getFilename(),
Expand Down Expand Up @@ -499,7 +500,7 @@ public function decorateForPlayer(
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'P',
$asset->id,
$asset->getFilename(),
Expand Down
16 changes: 11 additions & 5 deletions lib/Xmds/Soap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 Xibo Signage Ltd
* Copyright (C) 2025 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -386,6 +386,8 @@ protected function doRequiredFiles(
$document = new \DOMDocument('1.0');
$document->loadXML($output);

$cdnUrl = $this->configService->getSetting('CDN_URL');

foreach ($document->documentElement->childNodes as $node) {
if ($node instanceof \DOMElement) {
if ($node->getAttribute('download') === 'http') {
Expand Down Expand Up @@ -415,7 +417,7 @@ protected function doRequiredFiles(
$newUrl = LinkSigner::generateSignedLink(
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
null,
$cdnUrl,
$type,
$realId,
$node->getAttribute('saveAs'),
Expand Down Expand Up @@ -719,6 +721,7 @@ protected function doRequiredFiles(

// Keep a list of path names added to RF to prevent duplicates
$pathsAdded = [];
$cdnUrl = $this->configService->getSetting('CDN_URL');

foreach ($sth->fetchAll() as $row) {
$parsedRow = $this->getSanitizer($row);
Expand Down Expand Up @@ -768,7 +771,7 @@ protected function doRequiredFiles(
$file->setAttribute('path', LinkSigner::generateSignedLink(
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
null,
$cdnUrl,
'M',
$id,
$path,
Expand Down Expand Up @@ -797,6 +800,8 @@ protected function doRequiredFiles(
// Reset the paths added array to start again with layouts
$pathsAdded = [];

$cdnUrl = $this->configService->getSetting('CDN_URL');

// Go through each layout and see if we need to supply any resource nodes.
foreach ($layouts as $layoutId) {
try {
Expand Down Expand Up @@ -856,7 +861,7 @@ protected function doRequiredFiles(
$file->setAttribute('path', LinkSigner::generateSignedLink(
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
null,
$cdnUrl,
'L',
$layoutId,
$fileName,
Expand Down Expand Up @@ -2523,6 +2528,7 @@ protected function doGetResource(
}

$widgetData = $widgetDataProviderCache->decorateForPlayer(
$this->configService,
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
$dataProvider->getData(),
Expand Down Expand Up @@ -2995,7 +3001,7 @@ private function addDependency(
$httpFilePath = LinkSigner::generateSignedLink(
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
null,
$this->configService->getSetting('CDN_URL'),
RequiredFile::$TYPE_DEPENDENCY,
$dependency->id,
$dependencyBasePath,
Expand Down
8 changes: 5 additions & 3 deletions lib/Xmds/Soap7.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 Xibo Signage Ltd
* Copyright (C) 2025 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand All @@ -23,8 +23,8 @@
namespace Xibo\Xmds;

use Xibo\Entity\Bandwidth;
use Xibo\Helper\LinkSigner;
use Xibo\Event\XmdsWeatherRequestEvent;
use Xibo\Helper\LinkSigner;
use Xibo\Support\Exception\GeneralException;
use Xibo\Support\Exception\NotFoundException;

Expand Down Expand Up @@ -159,6 +159,7 @@ public function GetData($serverKey, $hardwareKey, $widgetId)
$media = [];
$requiredFiles = [];
$mediaIds = $widgetDataProviderCache->getCachedMediaIds();
$cdnUrl = $this->configService->getSetting('CDN_URL');

if (count($mediaIds) > 0) {
$this->getLog()->debug('Processing media links');
Expand Down Expand Up @@ -217,7 +218,7 @@ public function GetData($serverKey, $hardwareKey, $widgetId)
'path' => LinkSigner::generateSignedLink(
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
null,
$cdnUrl,
'M',
intval($row['mediaId']),
$row['storedAs'],
Expand All @@ -230,6 +231,7 @@ public function GetData($serverKey, $hardwareKey, $widgetId)

$resource = json_encode([
'data' => $widgetDataProviderCache->decorateForPlayer(
$this->configService,
$this->display,
$this->configService->getApiKeyDetails()['encryptionKey'],
$dataProvider->getData(),
Expand Down
5 changes: 3 additions & 2 deletions web/xmds.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 Xibo Signage Ltd
* Copyright (C) 2025 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -190,6 +190,7 @@

// Issue magic packet
$libraryLocation = $container->get('configService')->getSetting('LIBRARY_LOCATION');
$cdnUrl = $container->get('configService')->getSetting('CDN_URL');

// Issue content type header
$isCss = false;
Expand Down Expand Up @@ -225,7 +226,7 @@
$url = LinkSigner::generateSignedLink(
$display,
$encryptionKey,
null,
$cdnUrl,
'P',
$replacementFile->realId,
$replacementFile->path,
Expand Down

0 comments on commit 58bfa79

Please sign in to comment.