82
82
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/jquery-1.11.1.min.js')->save();
83
83
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-layout-scaler.js')->save();
84
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-image-render.js')->save();
84
85
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/bootstrap.min.css')->save();
86
87
foreach ($this->mediaFactory->createModuleFileFromFolder($this->resourceFolder) as $media) {
112
113
$this->module->settings['cachePeriod'] = $this->getSanitizer()->getInt('cachePeriod', 300);
116
* Loads templates for this module
118
private function loadTemplates()
120
// Scan the folder for template files
121
foreach (glob(PROJECT_ROOT . '/modules/forecastio/*.template.json') as $template) {
122
// Read the contents, json_decode and add to the array
123
$this->module->settings['templates'][] = json_decode(file_get_contents($template), true);
126
$this->getLog()->debug(count($this->module->settings['templates']));
130
* Templates available
133
public function templatesAvailable()
135
if (!isset($this->module->settings['templates']))
136
$this->loadTemplates();
138
return $this->module->settings['templates'];
141
116
public function validate()
119
if($this->getOption('overrideTemplate') == 0 && ( $this->getOption('templateId') == '' || $this->getOption('templateId') == null) )
120
throw new \InvalidArgumentException(__('Please choose a template'));
143
122
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
144
123
throw new \InvalidArgumentException(__('Please enter a duration'));
165
144
$this->setOption('longitude', $this->getSanitizer()->getDouble('longitude'));
166
145
$this->setOption('latitude', $this->getSanitizer()->getDouble('latitude'));
167
146
$this->setOption('templateId', $this->getSanitizer()->getString('templateId'));
168
$this->setOption('icons', $this->getSanitizer()->getString('icons'));
169
147
$this->setOption('overrideTemplate', $this->getSanitizer()->getCheckbox('overrideTemplate'));
170
148
$this->setOption('units', $this->getSanitizer()->getString('units'));
171
149
$this->setOption('updateInterval', $this->getSanitizer()->getInt('updateInterval', 60));
172
150
$this->setOption('lang', $this->getSanitizer()->getString('lang'));
173
151
$this->setOption('dayConditionsOnly', $this->getSanitizer()->getCheckbox('dayConditionsOnly'));
175
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
176
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
177
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', null));
178
$this->setRawNode('currentTemplate', $this->getSanitizer()->getParam('currentTemplate', null));
179
$this->setRawNode('dailyTemplate', $this->getSanitizer()->getParam('dailyTemplate', null));
153
if( $this->getOption('overrideTemplate') == 1 ){
154
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', null));
155
$this->setRawNode('currentTemplate', $this->getSanitizer()->getParam('currentTemplate', null));
156
$this->setRawNode('dailyTemplate', $this->getSanitizer()->getParam('dailyTemplate', null));
157
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
158
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
180
161
$this->setRawNode('javaScript', $this->getSanitizer()->getParam('javaScript', ''));
182
163
// Save the widget
183
164
$this->validate();
184
165
$this->saveWidget();
196
177
$this->setOption('longitude', $this->getSanitizer()->getDouble('longitude'));
197
178
$this->setOption('latitude', $this->getSanitizer()->getDouble('latitude'));
198
179
$this->setOption('templateId', $this->getSanitizer()->getString('templateId'));
199
$this->setOption('icons', $this->getSanitizer()->getString('icons'));
200
180
$this->setOption('overrideTemplate', $this->getSanitizer()->getCheckbox('overrideTemplate'));
201
181
$this->setOption('units', $this->getSanitizer()->getString('units'));
202
182
$this->setOption('updateInterval', $this->getSanitizer()->getInt('updateInterval', 60));
203
183
$this->setOption('lang', $this->getSanitizer()->getString('lang'));
204
184
$this->setOption('dayConditionsOnly', $this->getSanitizer()->getCheckbox('dayConditionsOnly'));
186
if( $this->getOption('overrideTemplate') == 1 ){
187
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', null));
188
$this->setRawNode('currentTemplate', $this->getSanitizer()->getParam('currentTemplate', null));
189
$this->setRawNode('dailyTemplate', $this->getSanitizer()->getParam('dailyTemplate', null));
190
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
191
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
206
$this->setOption('widgetOriginalWidth', $this->getSanitizer()->getInt('widgetOriginalWidth'));
207
$this->setOption('widgetOriginalHeight', $this->getSanitizer()->getInt('widgetOriginalHeight'));
208
$this->setRawNode('styleSheet', $this->getSanitizer()->getParam('styleSheet', null));
209
$this->setRawNode('currentTemplate', $this->getSanitizer()->getParam('currentTemplate', null));
210
$this->setRawNode('dailyTemplate', $this->getSanitizer()->getParam('dailyTemplate', null));
211
194
$this->setRawNode('javaScript', $this->getSanitizer()->getParam('javaScript', ''));
213
196
// Save the widget
215
198
$this->saveWidget();
218
public function iconsAvailable()
220
// Scan the forecast io folder for icons
223
foreach (array_diff(scandir($this->resourceFolder), array('..', '.')) as $file) {
224
if (stripos($file, '-icons.png'))
225
$icons[] = array('id' => $file, 'value' => ucfirst(str_replace('-', ' ', str_replace('.png', '', $file))));
232
202
* Units supported by Forecast.IO API
233
203
* @return array The Units Available (temperature, wind speed and visible distance)
553
523
// Replace the View Port Width?
554
524
$data['viewPortWidth'] = ($isPreview) ? $this->region->width : '[[ViewPortWidth]]';
526
if( $this->getOption('overrideTemplate') == 0 ) {
528
// Get CSS and HTML from the default templates
530
$template = $this->getTemplateById($this->getOption('templateId'));
532
if (isset($template)) {
533
$body = $template['main'];
534
$dailyTemplate = $template['daily'];
535
$styleSheet = $template['css'];
536
$widgetOriginalWidth = $template['widgetOriginalWidth'];
537
$widgetOriginalHeight = $template['widgetOriginalHeight'];
541
// Get CSS and HTML from the override input fields
543
$body = $this->parseLibraryReferences($isPreview, $this->getRawNode('currentTemplate', ''));
544
$dailyTemplate = $this->parseLibraryReferences($isPreview, $this->getRawNode('dailyTemplate', ''));
545
$styleSheet = $this->getRawNode('styleSheet', '');
546
$widgetOriginalWidth = $this->getSanitizer()->int($this->getOption('widgetOriginalWidth'));
547
$widgetOriginalHeight = $this->getSanitizer()->int($this->getOption('widgetOriginalHeight'));
550
// Parse library references
551
$body = $this->parseLibraryReferences($isPreview, $body);
552
$dailyTemplate = $this->parseLibraryReferences($isPreview, $dailyTemplate);
556
554
// Provide the background images to the templates styleSheet
557
555
$styleSheet = $this->makeSubstitutions([
558
556
'cloudy-image' => $this->getResourceUrl('forecastio/wi-cloudy.jpg'),
565
563
'rain-image' => $this->getResourceUrl('forecastio/wi-rain.jpg'),
566
564
'snow-image' => $this->getResourceUrl('forecastio/wi-snow.jpg'),
567
565
'windy' => $this->getResourceUrl('forecastio/wi-windy.jpg'),
568
], $this->getRawNode('styleSheet', null)
586
584
// Replace any icon sets
587
585
$data['head'] = str_replace('[[ICONS]]', $this->getResourceUrl('forecastio/' . $this->getOption('icons')), $headContent);
589
// Make some body content
590
$body = $this->parseLibraryReferences($isPreview, $this->getRawNode('currentTemplate', null));
591
$dailyTemplate = $this->parseLibraryReferences($isPreview, $this->getRawNode('dailyTemplate', null));
593
587
// Get the JavaScript node
594
588
$javaScript = $this->parseLibraryReferences($isPreview, $this->getRawNode('javaScript', ''));
636
630
'originalWidth' => $this->region->width,
637
631
'originalHeight' => $this->region->height,
638
632
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0),
639
'widgetDesignWidth' => $this->getSanitizer()->int($this->getOption('widgetOriginalWidth')),
640
'widgetDesignHeight'=> $this->getSanitizer()->int($this->getOption('widgetOriginalHeight'))
633
'widgetDesignWidth' => $widgetOriginalWidth,
634
'widgetDesignHeight'=> $widgetOriginalHeight
643
637
$javaScriptContent = '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/jquery-1.11.1.min.js') . '"></script>';
644
638
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-layout-scaler.js') . '"></script>';
639
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-image-render.js') . '"></script>';
645
640
$javaScriptContent .= '<script>
647
642
var options = ' . json_encode($options) . '
649
644
$(document).ready(function() {
650
645
$("body").xiboLayoutScaler(options);
646
$("#content").find("img").xiboImageRender(options);
653
649
$javaScriptContent .= $javaScript;