73
73
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/jquery-1.11.1.min.js')->save();
74
74
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-finance-render.js')->save();
75
75
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-layout-scaler.js')->save();
76
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-image-render.js')->save();
76
77
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/bootstrap.min.css')->save();
80
* Loads templates for this module
82
private function loadTemplates()
84
$this->module->settings['templates'] = [];
86
// Scan the folder for template files
87
foreach (glob(PROJECT_ROOT . '/modules/currencies/*.template.json') as $template) {
88
// Read the contents, json_decode and add to the array
89
$this->module->settings['templates'][] = json_decode(file_get_contents($template), true);
97
public function templatesAvailable()
99
if (!isset($this->module->settings['templates']))
100
$this->loadTemplates();
102
return $this->module->settings['templates'];
106
81
* Form for updating the module settings
108
83
public function settingsForm()
124
99
public function validate()
101
if($this->getOption('overrideTemplate') == 0 && ( $this->getOption('templateId') == '' || $this->getOption('templateId') == null) )
102
throw new \InvalidArgumentException(__('Please choose a template'));
126
104
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
127
105
throw new \InvalidArgumentException(__('Please enter a duration'));
163
141
$this->setOption('backgroundColor', $this->getSanitizer()->getString('backgroundColor'));
164
142
$this->setOption('noRecordsMessage', $this->getSanitizer()->getString('noRecordsMessage'));
165
143
$this->setOption('dateFormat', $this->getSanitizer()->getString('dateFormat'));
166
$this->setOption('overrideTemplate', $this->getSanitizer()->getCheckbox('overrideTemplate'));
144
$this->setOption('reverseConversion', $this->getSanitizer()->getCheckbox('reverseConversion'));
167
145
$this->setOption('updateInterval', $this->getSanitizer()->getInt('updateInterval', 60));
168
146
$this->setOption('templateId', $this->getSanitizer()->getString('templateId'));
169
147
$this->setOption('durationIsPerPage', $this->getSanitizer()->getCheckbox('durationIsPerPage'));
170
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
171
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
172
$this->setOption('maxItemsPerPage', $this->getSanitizer()->getInt('maxItemsPerPage', 4));
173
$this->setRawNode('mainTemplate', $this->getSanitizer()->getParam('mainTemplate', $this->getSanitizer()->getParam('mainTemplate', null)));
174
$this->setRawNode('itemTemplate', $this->getSanitizer()->getParam('itemTemplate', $this->getSanitizer()->getParam('itemTemplate', null)));
175
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', $this->getSanitizer()->getParam('styleSheet', null)));
176
148
$this->setRawNode('javaScript', $this->getSanitizer()->getParam('javaScript', ''));
149
$this->setOption('overrideTemplate', $this->getSanitizer()->getCheckbox('overrideTemplate'));
151
if( $this->getOption('overrideTemplate') == 1 ){
152
$this->setRawNode('mainTemplate', $this->getSanitizer()->getParam('mainTemplate', $this->getSanitizer()->getParam('mainTemplate', null)));
153
$this->setRawNode('itemTemplate', $this->getSanitizer()->getParam('itemTemplate', $this->getSanitizer()->getParam('itemTemplate', null)));
154
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', $this->getSanitizer()->getParam('styleSheet', null)));
155
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
156
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
157
$this->setOption('maxItemsPerPage', $this->getSanitizer()->getInt('maxItemsPerPage', 4));
210
195
// quote each item
211
196
$itemsJoined = array();
212
198
foreach ($items as $key => $item) {
200
// Remove the multiplier if there's one
201
$item = explode('|', $item)[0];
203
$baseItemPair = ( $reverseConversion ) ? ( trim($item) . trim($base) ) : ( trim($base) . trim($item) );
215
( $useVariation ) ? ('\'' . trim($base) . trim($item) . '=X' . '\'') : ('\'' . trim($base) . trim($item) . '\'')
207
( $useVariation ) ? ('\'' . $baseItemPair . '=X' . '\'') : ('\'' . $baseItemPair . '\'')
260
252
// Replace all matches.
262
254
preg_match_all('/\[.*?\]/', $source, $matches);
256
// Get the currencies' items
257
$items = $this->getOption('items');
259
if (strstr($items, ','))
260
$items = explode(',', $items);
264
$reverseConversion = ($this->getOption('reverseConversion', 0) == 1);
265
267
foreach ($matches[0] as $sub) {
299
301
// Replace the other tags
300
302
switch ($replace) {
301
303
case 'NameShort':
302
// Replace the name to have just the second currency
303
if (isset($data['Name']))
304
$replacement = str_replace(($baseCurrency . '/'),'',$data['Name']);
304
// Replace the name to have just the second currency (or the first if the currency is reversed)
305
$replaceBase = ( $reverseConversion ) ? ('/' . $baseCurrency) : ($baseCurrency . '/');
307
if (isset($data['Name']))
308
$replacement = trim(str_replace($replaceBase,'',$data['Name']));
314
// Initialize replacement with empty string
317
// Get the current currency name/code
318
$pairName = ( $reverseConversion ) ? ('/' . $baseCurrency) : ($baseCurrency . '/');
320
if (isset($data['Name']))
321
$currencyName = trim(str_replace($pairName,'',$data['Name']));
323
// Search for the item that relates to the actual currency
324
foreach ($items as $item) {
327
$itemName = trim(explode('|', $item)[0]);
329
// Compare the item name with the actual currency and test if the inputed value has a multiplier flag
330
if( sizeof(explode('|', $item)) > 1 && strcmp($itemName, $currencyName) == 0 ){
332
// Get the multiplier
333
$replacement = explode('|', $item)[1];
308
339
case 'CurrencyFlag':
309
$currencyCode = str_replace(($baseCurrency . '/'),'',$data['Name']);
340
$replaceBase = ( $reverseConversion ) ? ('/' . $baseCurrency) : ($baseCurrency . '/');
341
$currencyCode = str_replace($replaceBase,'',$data['Name']);
311
343
if (!file_exists(PROJECT_ROOT . '/web/modules/currencies/currency-flags/' . $currencyCode . '.svg'))
312
344
$currencyCode = 'default';
372
case 'LastTradePriceOnlyValue':
376
// Get the converted currency name
377
$currencyName = ( $reverseConversion ) ? ('/' . $baseCurrency) : ($baseCurrency . '/');
379
if (isset($data['Name']))
380
$currencyName = trim(str_replace($currencyName, '', $data['Name']));
382
// Get the field's name and set the replacement as the default value from the API
383
$fieldName = str_replace('Value', '', $replace);
384
$replacement = $data[$fieldName];
386
// Search for the item that relates to the actual currency
387
foreach ($items as $item) {
390
$itemName = trim(explode('|', $item)[0]);
392
// Compare the item name with the actual currency and test if the inputed value has a multiplier flag
393
if( sizeof(explode('|', $item)) > 1 && strcmp($itemName, $currencyName) == 0 ){
394
// Get the multiplier
395
$multiplier = explode('|', $item)[1];
397
// Set the replacement to be the API value times the multiplier
398
$replacement = $data[$fieldName] * (float)$multiplier;
340
404
case 'ChangeStyle':
341
405
// Default value as no change
342
406
$replacement = 'value-equal';
491
if( $this->getOption('overrideTemplate') == 0 ) {
493
$template = $this->getTemplateById($this->getOption('templateId'));
495
if (isset($template)) {
496
$mainTemplate = $template['main'];
497
$itemTemplate = $template['item'];
498
$styleSheet = $template['css'];
499
$widgetOriginalWidth = $template['widgetOriginalWidth'];
500
$widgetOriginalHeight = $template['widgetOriginalHeight'];
501
$maxItemsPerPage = $template['maxItemsPerPage'];
506
$mainTemplate = $this->getRawNode('mainTemplate');
507
$itemTemplate = $this->getRawNode('itemTemplate');
508
$styleSheet = $this->getRawNode('styleSheet', '');
509
$widgetOriginalWidth = $this->getSanitizer()->int($this->getOption('widgetOriginalWidth'));
510
$widgetOriginalHeight = $this->getSanitizer()->int($this->getOption('widgetOriginalHeight'));
511
$maxItemsPerPage = $this->getSanitizer()->int($this->getOption('maxItemsPerPage'));
433
514
// Run through each item and substitute with the template
434
$mainTemplate = $this->parseLibraryReferences($isPreview, $this->getRawNode('mainTemplate'));
435
$itemTemplate = $this->parseLibraryReferences($isPreview, $this->getRawNode('itemTemplate'));
515
$mainTemplate = $this->parseLibraryReferences($isPreview, $mainTemplate);
516
$itemTemplate = $this->parseLibraryReferences($isPreview, $itemTemplate);
437
518
$renderedItems = [];
453
534
'originalHeight' => $this->region->height,
454
535
'previewWidth' => $this->getSanitizer()->getDouble('width', 0),
455
536
'previewHeight' => $this->getSanitizer()->getDouble('height', 0),
456
'widgetDesignWidth' => $this->getSanitizer()->int($this->getOption('widgetOriginalWidth')),
457
'widgetDesignHeight'=> $this->getSanitizer()->int($this->getOption('widgetOriginalHeight')),
537
'widgetDesignWidth' => $widgetOriginalWidth,
538
'widgetDesignHeight'=> $widgetOriginalHeight,
458
539
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0),
459
'maxItemsPerPage' => $this->getSanitizer()->int($this->getOption('maxItemsPerPage'))
540
'maxItemsPerPage' => $maxItemsPerPage
462
543
$itemsPerPage = $options['maxItemsPerPage'];
485
566
// Add the CSS if it isn't empty, and replace the wallpaper
486
$css = $this->makeSubstitutions([], $this->getRawNode('styleSheet', null), '');
567
$css = $this->makeSubstitutions([], $styleSheet, '');
488
569
if ($css != '') {
489
570
$headContent .= '<style type="text/css">' . $this->parseLibraryReferences($isPreview, $css) . '</style>';
501
582
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-layout-scaler.js') . '"></script>';
502
583
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-finance-render.js') . '"></script>';
584
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-image-render.js') . '"></script>';
504
586
$javaScriptContent .= '<script type="text/javascript">';
505
587
$javaScriptContent .= ' var options = ' . json_encode($options) . ';';
506
588
$javaScriptContent .= ' var items = ' . json_encode($renderedItems) . ';';
507
589
$javaScriptContent .= ' var body = ' . json_encode($mainTemplate) . ';';
508
590
$javaScriptContent .= ' $(document).ready(function() { ';
509
$javaScriptContent .= ' $("body").xiboLayoutScaler(options); $("#content").xiboFinanceRender(options, items, body); ';
591
$javaScriptContent .= ' $("body").xiboLayoutScaler(options); $("#content").xiboFinanceRender(options, items, body); $("#content").find("img").xiboImageRender(options); ';
510
592
$javaScriptContent .= ' }); ';
511
593
$javaScriptContent .= $javaScript;
512
594
$javaScriptContent .= '</script>';