Skip to content

Commit

Permalink
Merge pull request #364 from xibosignage/release18
Browse files Browse the repository at this point in the history
HotFix for issues in 1.8.8 - will build new latest docker tag
  • Loading branch information
dasgarner authored Apr 13, 2018
2 parents 472fc8c + a1ad51d commit 7d1af99
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 69 deletions.
12 changes: 6 additions & 6 deletions lib/Entity/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class Widget implements \JsonSerializable
*/
public $isNew = false;

/** @var int[] Original Module Media Ids */
private $originalModuleMediaIds = [];

/** @var array[int] Original Media IDs */
private $originalMediaIds = [];

Expand Down Expand Up @@ -427,16 +430,12 @@ public function getPrimaryMedia()

/**
* Clear Media
* this must only clear module media, not "primary" media
*/
public function clearCachedMedia()
{
$this->load();
$this->mediaIds = [];

// Add back in the audio media id's
foreach ($this->audio as $audio) {
$this->mediaIds[] = $audio->mediaId;
}
$this->mediaIds = array_values(array_diff($this->mediaIds, $this->originalModuleMediaIds));
}

/**
Expand Down Expand Up @@ -565,6 +564,7 @@ public function load()
// Load any media assignments for this widget
$this->mediaIds = $this->widgetMediaFactory->getByWidgetId($this->widgetId);
$this->originalMediaIds = $this->mediaIds;
$this->originalModuleMediaIds = $this->widgetMediaFactory->getModuleOnlyByWidgetId($this->widgetId);

// Load any widget audio assignments
$this->audio = $this->widgetAudioFactory->getByWidgetId($this->widgetId);
Expand Down
24 changes: 23 additions & 1 deletion lib/Factory/WidgetMediaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function getByWidgetId($widgetId)
return $this->query(null, array('widgetId' => $widgetId));
}

/**
* Media Linked to Widgets by WidgetId
* @param int $widgetId
* @return array[int]
*/
public function getModuleOnlyByWidgetId($widgetId)
{
return $this->query(null, ['widgetId' => $widgetId, 'moduleOnly' => 1]);
}

/**
* Query Media Linked to Widgets
* @param array $sortOrder
Expand All @@ -58,7 +68,19 @@ public function getByWidgetId($widgetId)
*/
public function query($sortOrder = null, $filterBy = [])
{
$sql = 'SELECT mediaId FROM `lkwidgetmedia` WHERE widgetId = :widgetId AND mediaId <> 0 ';
if ($this->getSanitizer()->getInt('moduleOnly', $filterBy) === 1) {
$sql = '
SELECT lkwidgetmedia.mediaId
FROM `lkwidgetmedia`
INNER JOIN `media`
ON `media`.mediaId = `lkwidgetmedia`.mediaId
WHERE widgetId = :widgetId
AND `lkwidgetmedia`.mediaId <> 0
AND `media`.type = \'module\'
';
} else {
$sql = 'SELECT mediaId FROM `lkwidgetmedia` WHERE widgetId = :widgetId AND mediaId <> 0 ';
}

return array_map(function($element) { return $element['mediaId']; }, $this->getStore()->select($sql, array('widgetId' => $this->getSanitizer()->getInt('widgetId', $filterBy))));
}
Expand Down
21 changes: 10 additions & 11 deletions lib/Widget/Clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ public function getResource($displayId = 0)
$data = [];
$isPreview = ($this->getSanitizer()->getCheckbox('preview') == 1);

// After body content
$options = [
'previewWidth' => $this->getSanitizer()->getDouble('width', 0),
'previewHeight' => $this->getSanitizer()->getDouble('height', 0),
'originalWidth' => $this->region->width,
'originalHeight' => $this->region->height,
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0)
];

// Clock Type
switch ($this->getOption('clockTypeId', 1)) {

Expand Down Expand Up @@ -249,15 +258,6 @@ public function getResource($displayId = 0)
// Replace all the subs
$data['body'] = $format;

// After body content
$options = array(
'previewWidth' => $this->getSanitizer()->getDouble('width', 0),
'previewHeight' => $this->getSanitizer()->getDouble('height', 0),
'originalWidth' => $this->region->width,
'originalHeight' => $this->region->height,
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0)
);

$javaScriptContent = '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/jquery-1.11.1.min.js') . '"></script>';
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/moment.js') . '"></script>';
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-layout-scaler.js') . '"></script>';
Expand Down Expand Up @@ -312,8 +312,7 @@ function updateClock() {
}

// If we are a preview, then pass in the width and height
$data['previewWidth'] = $this->getSanitizer()->getDouble('width', 0);
$data['previewHeight'] = $this->getSanitizer()->getDouble('height', 0);
$data['options'] = json_encode($options);

// Replace the View Port Width?
$data['viewPortWidth'] = ($isPreview) ? $this->region->width : '[[ViewPortWidth]]';
Expand Down
5 changes: 4 additions & 1 deletion lib/Widget/ModuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Xibo\Widget;

use Jenssegers\Date\Date;
use Xibo\Exception\XiboException;
use Xibo\Factory\ModuleFactory;

/**
Expand Down Expand Up @@ -107,9 +108,11 @@ public function getCacheDuration();
/**
* Get Resource or Cache
* @param int $displayId The displayId we're requesting for, or 0 for preview
* @param \Xibo\Entity\Region|null $region
* @return string
* @throws XiboException
*/
public function getResourceOrCache($displayId);
public function getResourceOrCache($displayId, $region = null);

/**
* Get Resource
Expand Down
38 changes: 36 additions & 2 deletions lib/Widget/ModuleWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ public final function setCacheDate($displayId, $overrideDuration = null)
}

/** @inheritdoc */
public final function getResourceOrCache($displayId)
public final function getResourceOrCache($displayId, $region = null)
{
$this->getLog()->debug('getResourceOrCache for displayId ' . $displayId . ' and widgetId ' . $this->getWidgetId());

Expand All @@ -1338,11 +1338,21 @@ public final function getResourceOrCache($displayId)
. $this->getWidgetId()
. DIRECTORY_SEPARATOR;

$cacheFile = $this->getCacheKey($displayId);
$cacheKey = $this->getCacheKey($displayId);

// If we are a non-preview, then we'd expect to be provided with a region.
// we use this to save a width/height aware version of this
if ($displayId !== 0) {
/** @var \Xibo\Entity\Region $region */
$cacheFile = $cacheKey . '_' . $region->width . '_' . $region->height;
} else {
$cacheFile = $cacheKey;
}

$this->getLog()->debug('Cache details - modifiedDt: ' . (($modifiedDt === null) ? 'layoutDt' : $modifiedDt->format('Y-m-d H:i:s'))
. ', cacheDt: ' . $cachedDt->format('Y-m-d H:i:s')
. ', cacheDuration: ' . $cacheDuration
. ', cacheKey: ' . $cacheKey
. ', cacheFile: ' . $cacheFile);

if (!file_exists($cachePath))
Expand All @@ -1360,6 +1370,14 @@ public final function getResourceOrCache($displayId)

// We need to generate and cache this resource
try {
// The cache has expired, so we remove all cache entries that match our cache key
// including the preview (which will also be out of date)
$this->getLog()->debug('Deleting old cache for this cache key: ' . $cacheKey);

foreach (glob($cachePath . $cacheKey . '*') as $fileName) {
unlink($fileName);
}

// Clear the resources widget content
$this->clearMedia();

Expand Down Expand Up @@ -1414,6 +1432,22 @@ public final function getResourceOrCache($displayId)
$resource = file_get_contents($cachePath . $cacheFile);
}

// If we are the preview, then we should look at updating the preview width, height and scale_override with
// the ones we've been given
// this is a workaround to making the cache key aware of the below parameters, which would create a new cache
// file each and every time the region changed size.
if ($displayId == 0) {
// Support keyword replacement and parsing for known combinations of these in existing widgets
// (for backwards compatibility)
$previewWidth = $this->getSanitizer()->getDouble('width', 0);
$previewHeight = $this->getSanitizer()->getDouble('height', 0);
$scaleOverride = $this->getSanitizer()->getDouble('scale_override', 0);

$resource = preg_replace('/"previewWidth":(\d*?),/', '"previewWidth":' . $previewWidth . ',', $resource);
$resource = preg_replace('/"previewHeight":(\d*?),/', '"previewHeight":' . $previewHeight . ',', $resource);
$resource = preg_replace('/"scaleOverride":(\d*?),/', '"scaleOverride":' . $scaleOverride . ',', $resource);
}

// Return the resource
return $resource;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Xmds/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ protected function doGetResource($serverKey, $hardwareKey, $layoutId, $regionId,
$requiredFile = $this->requiredFileFactory->getByDisplayAndWidget($this->display->displayId, $mediaId);

$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($mediaId), $this->regionFactory->getById($regionId));
$resource = $module->getResourceOrCache($this->display->displayId);
$resource = $module->getResourceOrCache($this->display->displayId, $this->regionFactory->getById($regionId));

$requiredFile->bytesRequested = $requiredFile->bytesRequested + strlen($resource);
$requiredFile->save();
Expand Down
5 changes: 3 additions & 2 deletions modules/clock-get-resource-analog.twig
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@
$(document).ready(function() {
var previewWidth = {{ previewWidth }};
var previewHeight = {{ previewHeight }};
var options = {{ options|raw }};
var previewWidth = options.previewWidth;
var previewHeight = options.previewHeight;
if (previewWidth == 0 || previewHeight == 0)
var size = Math.min($(window).width(), $(window).height());
Expand Down
5 changes: 3 additions & 2 deletions modules/clock-get-resource-flip.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
$(document).ready(function() {
// Show Seconds: {{ showSeconds }}
// Offset: {{ offset }}
var width = {{ previewWidth }};
var height = {{ previewHeight }};
var options = {{ options|raw }};
var width = options.previewWidth;
var height = options.previewHeight;
if (width == 0 || height == 0) {
width = $(window).width();
Expand Down
88 changes: 45 additions & 43 deletions web/theme/default/js/xibo-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,53 +157,55 @@ var text_callback = function(dialog, extraData) {

// Do we have a media selector?
var $selectPicker = $(".ckeditor_library_select");
$selectPicker.selectpicker({
if ($selectPicker.length > 0) {
$selectPicker.selectpicker({
liveSearch: true
})
.ajaxSelectPicker({
ajax: {
type: 'GET',
url: $selectPicker.data().searchUrl,
data: function () {
return {
media: '{{{q}}}',
type: 'image',
start: 0,
length: 50
};
}
},
preprocessData: function(data) {
var library = [];
if (data.hasOwnProperty('data')) {
$.each(data.data, function (index, element) {
library.push({
'value': element.mediaId,
'text': element.name,
'data': {
'image-url': $selectPicker.data().imageUrl.replace(':id', element.mediaId)
},
'disabled': false
.ajaxSelectPicker({
ajax: {
type: 'GET',
url: $selectPicker.data().searchUrl,
data: function () {
return {
media: '{{{q}}}',
type: 'image',
start: 0,
length: 50
};
}
},
preprocessData: function (data) {
var library = [];
if (data.hasOwnProperty('data')) {
$.each(data.data, function (index, element) {
library.push({
'value': element.mediaId,
'text': element.name,
'data': {
'image-url': $selectPicker.data().imageUrl.replace(':id', element.mediaId)
},
'disabled': false
});
});
});
}
return library;
},
preserveSelected: false,
emptyRequest: true
})
.on('changed.bs.select', function (e) {
console.log(e);
var select = $(e.target);
var linkedTo = select.data().linkedTo;
var value = $(e.target).find(":selected").data().imageUrl;

if (value !== undefined && value !== "" && linkedTo != null) {
if (CKEDITOR.instances[linkedTo] != undefined) {
CKEDITOR.instances[linkedTo].insertHtml("<img src=\"" + value + "\" />");
}
return library;
},
preserveSelected: false,
emptyRequest: true
})
.on('changed.bs.select', function (e) {
console.log(e);
var select = $(e.target);
var linkedTo = select.data().linkedTo;
var value = $(e.target).find(":selected").data().imageUrl;

if (value !== undefined && value !== "" && linkedTo != null) {
if (CKEDITOR.instances[linkedTo] != undefined) {
CKEDITOR.instances[linkedTo].insertHtml("<img src=\"" + value + "\" />");
}
}
}
});
});
}

// Turn the background colour into a picker
$("#backgroundColor").colorpicker();
Expand Down

0 comments on commit 7d1af99

Please sign in to comment.