3
* Xibo - Digital Signage - http://www.xibo.org.uk
4
* Copyright (C) 2014-2015 Daniel Garner
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
22
namespace Xibo\Widget;
26
use Respect\Validation\Validator as v;
27
use Xibo\Exception\ConfigurationException;
28
use Xibo\Factory\ModuleFactory;
32
* @package Xibo\Widget
34
class TwitterMetro extends TwitterBase
37
public $codeSchemaVersion = 1;
38
private $resourceFolder;
41
* TwitterMetro constructor.
43
public function init()
45
$this->resourceFolder = PROJECT_ROOT . '/web/modules/twittermetro';
47
// Initialise extra validation rules
48
v::with('Xibo\\Validation\\Rules\\');
52
* Install or Update this module
53
* @param ModuleFactory $moduleFactory
55
public function installOrUpdate($moduleFactory)
57
if ($this->module == null) {
59
$module = $moduleFactory->createEmpty();
60
$module->name = 'Twitter Metro';
61
$module->type = 'twittermetro';
62
$module->class = 'Xibo\Widget\TwitterMetro';
63
$module->description = 'Twitter Metro Search Module';
64
$module->imageUri = 'forms/library.gif';
66
$module->previewEnabled = 1;
67
$module->assignable = 1;
68
$module->regionSpecific = 1;
69
$module->renderAs = 'html';
70
$module->schemaVersion = $this->codeSchemaVersion;
71
$module->defaultDuration = 60;
72
$module->settings = [];
74
$this->setModule($module);
75
$this->installModule();
78
// Check we are all installed
79
$this->installFiles();
85
public function installFiles()
87
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/jquery-1.11.1.min.js')->save();
88
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-metro-render.js')->save();
89
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-layout-scaler.js')->save();
90
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/xibo-image-render.js')->save();
91
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/emojione/emojione.sprites.svg')->save();
92
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/web/modules/vendor/bootstrap.min.css')->save();
94
foreach ($this->mediaFactory->createModuleFileFromFolder($this->resourceFolder) as $media) {
95
/* @var \Xibo\Entity\Media $media */
101
* Override the apikey/secret
102
* @param string $setting
103
* @param null $default
104
* @return mixed|string
106
public function getSetting($setting, $default = NULL)
108
if ($setting == 'apiKey' || $setting == 'apiSecret' || $setting == 'cachePeriod') {
109
// Create a Twitter Module as the source of this modules settings
110
// only go to the stock twitter module
111
if ($this->parent === null)
112
$this->parent = $this->moduleFactory->createByClass('Xibo\Widget\Twitter');
114
return $this->parent->getSetting($setting, $default);
117
return parent::getSetting($setting, $default);
123
public function layoutDesignerJavaScript()
125
// We use the same javascript as the data set view designer
126
return 'twittermetro-form-javascript';
130
* Get the template HTML, CSS, widgetOriginalWidth, widgetOriginalHeight giving its orientation (0:Landscape 1:Portrait)
133
public function getTemplateData() {
135
$orientation = ($this->getSanitizer()->getDouble('width', $this->region->width) > $this->getSanitizer()->getDouble('height', $this->region->height)) ? 0 : 1;
137
$templateArray = array(
138
array( 'template' => '<div class="cell-[itemType] [ShadowType] cell" id="item-[itemId]" style="[Photo]"> <div class="item-container [ShadowType]" style="[Color]"> <div class="item-text">[Tweet]</div> <div class="userData"> <div class="tweet-profilePic">[ProfileImage|normal]</div> <div class="tweet-userData"> <div class="user">[User]</div> <small>[Date]</small></div> </div> </div> </div>',
139
'styleSheet' => 'body { font-family: "Helvetica", "Arial", sans-serif; line-height: 1; margin: 0; } #content { width: 1920px !important; height: 1080px !important; background: rgba(255, 255, 255, 0.6); color: rgba(255, 255, 255, 1); } .row-1 { height: 360px; } .page { float: left; margin: 0; padding: 0; } .cell-1 { width: 310px; } .cell-2 { width: 630px; } .cell-3 { width: 950px; } .cell-1, .cell-2, .cell-3 { float: left; height: inherit; margin: 5px; background-repeat: no-repeat; background-size: cover; background-position-x: 50%; background-position-y: 50%; } .item-container { padding: 10px; color: #fff; height: 350px; } .userData { height: 50px; } .darken-container { background-color: rgba(0, 0, 0, 0.4); } .tweet-profilePic { width: 20%; float: left; } .tweet-profilePic img { width: 48px; } .tweet-userData { width: 80%; float: left; text-align: right; } .item-text { padding: 10px; color: #fff; } .emojione { width: 26px; height: 26px; } .cell-1 .item-text { line-height: 30px; font-size: 25px; height: 280px; } .cell-2 .item-text { line-height: 40px; font-size: 40px; height: 280px; } .cell-3 .item-text { line-height: 53px; font-size: 50px; height: 280px; } .user { font-size: 14px; font-weight: bold; padding-top: 20px; } .shadow { text-shadow: 1px 1px 2px rgba(0, 0, 3, 1); } .no-shadow { text-shadow: none !important; } small { font-size: 70%; }',
140
'originalWidth' => '1920',
141
'originalHeight' => '1080'
143
array( 'template' => '<div class="cell-[itemType] [ShadowType] cell" id="item-[itemId]" style="[Photo]"> <div class="item-container [ShadowType]" style="[Color]"> <div class="item-text">[Tweet]</div> <div class="userData"> <div class="tweet-profilePic">[ProfileImage|normal]</div> <div class="tweet-userData"> <div class="user">[User]</div> <small>[Date]</small></div> </div> </div> </div>',
144
'styleSheet' => 'body { font-family: "Helvetica", "Arial", sans-serif; line-height: 1; margin: 0; } #content { width: 1080px !important; height: 1920px !important; background: rgba(255, 255, 255, 0.6); color: rgba(255, 255, 255, 1); } .row-1 { height: 320px; } .page { float: left; margin: 0; padding: 0; } .cell-1 { width: 350px; } .cell-2 { width: 710px; } .cell-3 { width: 1070px; } .cell-1, .cell-2, .cell-3 { float: left; height: inherit; margin: 5px; background-repeat: no-repeat; background-size: cover; background-position-x: 50%; background-position-y: 50%; } .item-container { padding: 10px; color: #fff; height: 310px; } .userData { height: 50px; } .darken-container { background-color: rgba(0, 0, 0, 0.4); } .tweet-profilePic { width: 20%; float: left; } .tweet-profilePic img { width: 48px; } .tweet-userData { width: 80%; float: left; text-align: right; } .item-text { padding: 10px; color: #fff; } .emojione { width: 26px; height: 26px; } .cell-1 .item-text { line-height: 30px; font-size: 25px; height: 240px; } .cell-2 .item-text { line-height: 40px; font-size: 40px; height: 240px; } .cell-3 .item-text { line-height: 53px; font-size: 50px; height: 240px; } .user { font-size: 14px; font-weight: bold; padding-top: 20px; } .shadow { text-shadow: 1px 1px 2px rgba(0, 0, 3, 1); } .no-shadow { text-shadow: none !important; } small { font-size: 70%; }',
145
'originalWidth' => '1080',
146
'originalHeight' => '1920'
150
return $templateArray[$orientation];
154
* Loads color templates for this module
156
private function loadColorTemplates()
158
$this->module->settings['colortemplates'] = [];
160
// Scan the folder for template files
161
foreach (glob(PROJECT_ROOT . '/modules/twittermetro/*.colortemplate.json') as $template) {
162
// Read the contents, json_decode and add to the array
163
$this->module->settings['colortemplates'][] = json_decode(file_get_contents($template), true);
168
* Color templates available
171
public function colorTemplatesAvailable()
173
if (!isset($this->module->settings['colortemplates']))
174
$this->loadColorTemplates();
176
return $this->module->settings['colortemplates'];
180
* Form for updating the module settings
182
public function settingsForm()
184
return 'twittermetro-form-settings';
187
public function validate()
189
// If overrideColorTemplate is false we have to define a template Id
190
if($this->getOption('overrideColorTemplate') == 0 && ( $this->getOption('colorTemplateId') == '' || $this->getOption('colorTemplateId') == null) )
191
throw new \InvalidArgumentException(__('Please choose a template'));
193
if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
194
throw new \InvalidArgumentException(__('Please enter a duration'));
196
if (!v::string()->notEmpty()->validate($this->getOption('searchTerm')))
197
throw new \InvalidArgumentException(__('Please enter a search term'));
203
public function add()
205
$this->setCommonOptions();
215
public function edit()
217
$this->setCommonOptions();
225
* Set common options from Request Params
227
private function setCommonOptions()
229
$this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
230
$this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
231
$this->setOption('name', $this->getSanitizer()->getString('name'));
232
$this->setOption('searchTerm', $this->getSanitizer()->getString('searchTerm'));
233
$this->setOption('effect', $this->getSanitizer()->getString('effect'));
234
$this->setOption('speed', $this->getSanitizer()->getInt('speed'));
235
$this->setOption('backgroundColor', $this->getSanitizer()->getString('backgroundColor'));
236
$this->setOption('noTweetsMessage', $this->getSanitizer()->getString('noTweetsMessage'));
237
$this->setOption('dateFormat', $this->getSanitizer()->getString('dateFormat'));
238
$this->setOption('resultType', $this->getSanitizer()->getString('resultType'));
239
$this->setOption('tweetDistance', $this->getSanitizer()->getInt('tweetDistance'));
240
$this->setOption('tweetCount', $this->getSanitizer()->getInt('tweetCount', 60));
241
$this->setOption('removeUrls', $this->getSanitizer()->getCheckbox('removeUrls'));
242
$this->setOption('removeMentions', $this->getSanitizer()->getCheckbox('removeMentions'));
243
$this->setOption('removeHashtags', $this->getSanitizer()->getCheckbox('removeHashtags'));
244
$this->setOption('overrideColorTemplate', $this->getSanitizer()->getCheckbox('overrideColorTemplate'));
245
$this->setOption('updateInterval', $this->getSanitizer()->getInt('updateInterval', 60));
246
$this->setOption('colorTemplateId', $this->getSanitizer()->getString('colorTemplateId'));
247
$this->setOption('resultContent', $this->getSanitizer()->getString('resultContent'));
248
$this->setOption('removeRetweets', $this->getSanitizer()->getCheckbox('removeRetweets'));
250
if( $this->getOption('overrideColorTemplate') == 1 ){
252
// Convert the colors array to string to be able to save it
253
$stringColor = $this->getSanitizer()->getStringArray('color')[0];
254
for ($i=1; $i < count($this->getSanitizer()->getStringArray('color')); $i++) {
255
if(!empty($this->getSanitizer()->getStringArray('color')[$i]))
256
$stringColor .= "|" . $this->getSanitizer()->getStringArray('color')[$i];
258
$this->setOption('templateColours', $stringColor);
263
* @param int $displayId
264
* @param bool $isPreview
266
* @throws ConfigurationException
268
protected function getTwitterFeed($displayId = 0, $isPreview = true)
270
if (!extension_loaded('curl'))
271
throw new ConfigurationException(__('cURL extension is required for Twitter'));
273
// Do we need to add a geoCode?
275
$distance = $this->getOption('tweetDistance');
276
if ($distance != 0) {
277
// Use the display ID or the default.
278
if ($displayId != 0) {
279
// Look up the lat/long
280
$display = $this->displayFactory->getById($displayId);
281
$defaultLat = $display->latitude;
282
$defaultLong = $display->longitude;
284
$defaultLat = $this->getConfig()->GetSetting('DEFAULT_LAT');
285
$defaultLong = $this->getConfig()->GetSetting('DEFAULT_LONG');
288
// Built the geoCode string.
289
$geoCode = implode(',', array($defaultLat, $defaultLong, $distance)) . 'mi';
292
// Search content filtered by type of tweets
293
$searchTerm = $this->getOption('searchTerm');
294
$resultContent = $this->getOption('resultContent');
296
switch ($resultContent) {
304
$searchTerm .= ' -filter:media';
308
// Only tweets with native images
309
$searchTerm .= ' filter:twimg';
317
// Search term retweets filter
318
$searchTerm .= ($this->getOption('removeRetweets')) ? ' -filter:retweets' : '';
320
// Connect to twitter and get the twitter feed.
321
$cache = $this->getPool()->getItem(md5($searchTerm . $this->getOption('resultType') . $this->getOption('tweetCount', 60) . $geoCode));
323
$data = $cache->get();
325
if ($cache->isMiss()) {
327
$this->getLog()->debug('Querying API for ' . $searchTerm);
329
// We need to search for it
330
if (!$token = $this->getToken())
333
// We have the token, make a tweet
334
if (!$data = $this->searchApi($token, $searchTerm, $this->getOption('resultType'), $geoCode, $this->getOption('tweetCount', 60)))
339
$cache->expiresAfter($this->getSetting('cachePeriod', 3600));
340
$this->getPool()->saveDeferred($cache);
343
// Get the template data
344
$templateData = $this->getTemplateData();
345
$template = $this->parseLibraryReferences($isPreview, $templateData['template']);
347
// Parse the text template
349
preg_match_all('/\[.*?\]/', $template, $matches);
351
// Build an array to return
354
// Expiry time for any media that is downloaded
355
$expires = $this->getDate()->parse()->addHours($this->getSetting('cachePeriodImages', 24))->format('U');
357
// Remove URL setting
358
$removeUrls = $this->getOption('removeUrls', 1) == 1;
359
$removeMentions = $this->getOption('removeMentions', 1) == 1;
360
$removeHashTags = $this->getOption('removeHashTags', 1) == 1;
362
// If we have nothing to show, display a no tweets message.
363
if (count($data->statuses) <= 0) {
364
// Create ourselves an empty tweet so that the rest of the code can continue as normal
365
$user = new \stdClass();
367
$user->screen_name = '';
368
$user->profile_image_url = '';
369
$user->location = '';
371
$tweet = new \stdClass();
372
$tweet->full_text = $this->getOption('noTweetsMessage', __('There are no tweets to display'));
373
$tweet->created_at = '';
374
$tweet->user = $user;
376
// Append to our statuses
377
$data->statuses[] = $tweet;
380
// Make an emojione client
381
$emoji = new Client(new Ruleset());
382
$emoji->imageType = 'svg';
383
$emoji->sprites = true;
384
$emoji->imagePathSVGSprites = $this->getResourceUrl('emojione/emojione.sprites.svg');
386
// Get the date format to apply
387
$dateFormat = $this->getOption('dateFormat', $this->getConfig()->GetSetting('DATE_FORMAT'));
389
// This should return the formatted items.
390
foreach ($data->statuses as $tweet) {
391
// Substitute for all matches in the template
392
$rowString = $template;
394
foreach ($matches[0] as $sub) {
395
// Always clear the stored template replacement
397
$tagOptions = array();
399
// Get the options from the tag and create an array
400
$subClean = str_replace('[', '', str_replace(']', '', $sub));
401
if (stripos($subClean, '|') > -1) {
402
$tagOptions = explode('|', $subClean);
405
$subClean = $tagOptions[0];
407
// Remove the tag from the first position
408
array_shift($tagOptions);
411
// Maybe make this more generic?
414
// Get the tweet text to operate on
415
$tweetText = $tweet->full_text;
417
// Replace URLs with their display_url before removal
418
if (isset($tweet->entities->urls)) {
419
foreach ($tweet->entities->urls as $url) {
420
$tweetText = str_replace($url->url, $url->display_url, $tweetText);
424
// Clean up the tweet text
425
// thanks to https://github.com/solarbug (https://github.com/xibosignage/xibo/issues/703)
428
$tweetText = preg_replace('/(\s+|^)@\S+/', '', $tweetText);
432
$tweetText = preg_replace('/(\s+|^)#\S+/', '', $tweetText);
435
// Regex taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
436
$tweetText = preg_replace('~(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))~', '', $tweetText); // remove urls
438
$replace = $emoji->toImage($tweetText);
442
$replace = $tweet->user->name;
446
$replace = ($tweet->user->screen_name != '') ? ('@' . $tweet->user->screen_name) : '';
450
if($tweet->created_at != '')
451
$replace = $this->getDate()->getLocalDate(strtotime($tweet->created_at), $dateFormat);
455
$replace = $tweet->user->location;
459
// Grab the profile image
460
if ($tweet->user->profile_image_url != '') {
462
// Original Default Image
464
if( count($tagOptions) > 0 ) {
465
// Image options ( normal, bigger, mini )
466
$imageSizeType = '_' . $tagOptions[0];
469
// Twitter image size
470
$tweet->user->profile_image_url = str_replace('_normal', $imageSizeType, $tweet->user->profile_image_url);
472
// Grab the profile image
473
$file = $this->mediaFactory->queueDownload('twitter_' . $tweet->user->id, $tweet->user->profile_image_url, $expires);
475
// Tag this layout with this file
476
$this->assignMedia($file->mediaId);
478
$replace = ($isPreview)
479
? '<img src="' . $this->getApp()->urlFor('library.download', ['id' => $file->mediaId, 'type' => 'image']) . '?preview=1" />'
480
: '<img src="' . $file->storedAs . '" />';
485
// See if there is a profile image
486
if (!$this->tweetHasPhoto($tweet)) {
488
// Get the colors array
489
if( $this->getOption('overrideColorTemplate') == 0 ) {
491
$templates = $this->colorTemplatesAvailable();
493
foreach ($templates as $tmplt) {
494
if( $tmplt['id'] == $this->getOption('colorTemplateId') ){
495
$colorArray = $tmplt['colors'];
500
$colorArray = explode("|", $this->getOption('templateColours'));
503
// Find a random color
504
$randomNum = rand(0,count($colorArray)-1);
505
$randomColor = $colorArray[$randomNum];
507
$replace = 'background-color:' . $randomColor;
512
// See if there is a profile image
513
$replace = ($this->tweetHasPhoto($tweet)) ? 'shadow darken-container' : '';
517
// See if there are any photos associated with this tweet.
518
if ($this->tweetHasPhoto($tweet)) {
520
// See if it's an image from a tweet or RT, and only take the first one
521
$mediaObject = (isset($tweet->entities->media))
522
? $tweet->entities->media[0]
523
: $tweet->retweeted_status->entities->media[0];
525
$photoUrl = $mediaObject->media_url;
527
if ($photoUrl != '') {
528
$file = $this->mediaFactory->queueDownload('twitter_photo_' . $tweet->user->id . '_' . $mediaObject->id_str, $photoUrl, $expires);
530
// Tag this layout with this file
531
$this->assignMedia($file->mediaId);
533
$replace = "background-image: url("
534
. (($isPreview) ? $this->getApp()->urlFor('library.download', ['id' => $file->mediaId, 'type' => 'image']) : $file->storedAs)
540
case 'TwitterLogoWhite':
541
//Get the Twitter logo image file path
542
$replace = $this->getResourceUrl('twitter/twitter_white.png');
545
case 'TwitterLogoBlue':
546
//Get the Twitter logo image file path
547
$replace = $this->getResourceUrl('twitter/twitter_blue.png');
551
$replace = '[' . $subClean . ']';
554
$rowString = str_replace($sub, $replace, $rowString);
557
// Substitute the replacement we have found (it might be '')
558
$return[] = $rowString;
561
// Process the download queue
562
$this->mediaFactory->processDownloads();
564
// Return the data array
570
* @param int $displayId
573
public function getResource($displayId = 0)
575
// Make sure we are set up correctly
576
if ($this->getSetting('apiKey') == '' || $this->getSetting('apiSecret') == '') {
577
$this->getLog()->error('Twitter Module not configured. Missing API Keys');
582
$isPreview = ($this->getSanitizer()->getCheckbox('preview') == 1);
584
// Replace the View Port Width?
585
$data['viewPortWidth'] = ($isPreview) ? $this->region->width : '[[ViewPortWidth]]';
587
// Information from the Module
588
$duration = $this->getCalculatedDurationForGetResource();
590
// Generate a JSON string of substituted items.
591
$items = $this->getTwitterFeed($displayId, $isPreview);
593
// Get the template data
594
$templateData = $this->getTemplateData();
596
// Return empty string if there are no items to show.
597
if (count($items) == 0)
601
'type' => $this->getModuleType(),
602
'fx' => $this->getOption('effect', 'noAnim'),
603
'speed' => $this->getOption('speed', 500),
604
'duration' => $duration,
605
'numItems' => count($items),
606
'originalWidth' => $this->region->width,
607
'originalHeight' => $this->region->height,
608
'previewWidth' => $this->getSanitizer()->getDouble('width', 0),
609
'previewHeight' => $this->getSanitizer()->getDouble('height', 0),
610
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0),
611
'widgetDesignWidth' => $templateData['originalWidth'],
612
'widgetDesignHeight'=> $templateData['originalHeight'],
613
'resultContent'=> $this->getSanitizer()->string($this->getOption('resultContent'))
616
// Replace the control meta with our data from twitter
617
$data['controlMeta'] = '<!-- NUMITEMS=' . count($items) . ' -->' . PHP_EOL . '<!-- DURATION=' . $duration . ' -->';
619
// Replace the head content
622
$backgroundColor = $this->getOption('backgroundColor');
623
if ($backgroundColor != '') {
624
$headContent .= '<style type="text/css">body, .page, .item { background-color: ' . $backgroundColor . ' }</style>';
627
// Add our fonts.css file
628
$headContent .= '<link href="' . (($isPreview) ? $this->getApp()->urlFor('library.font.css') : 'fonts.css') . '" rel="stylesheet" media="screen">
629
<link href="' . $this->getResourceUrl('vendor/bootstrap.min.css') . '" rel="stylesheet" media="screen">';
631
// Add the CSS if it isn't empty
632
$css = $templateData['styleSheet'];
635
$headContent .= '<style type="text/css">' . $this->parseLibraryReferences($isPreview, $css) . '</style>';
637
$headContent .= '<style type="text/css">' . file_get_contents($this->getConfig()->uri('css/client.css', true)) . '</style>';
639
// Replace the Head Content with our generated javascript
640
$data['head'] = $headContent;
642
// Add some scripts to the JavaScript Content
643
$javaScriptContent = '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/jquery-1.11.1.min.js') . '"></script>';
645
// Get the colors array
646
if( $this->getOption('overrideColorTemplate') == 0 ) {
648
$templates = $this->colorTemplatesAvailable();
650
foreach ($templates as $tmplt) {
651
if( $tmplt['id'] == $this->getOption('colorTemplateId') ){
652
$colorArray = $tmplt['colors'];
657
$colorArray = explode("|", $this->getOption('templateColours'));
660
// Need the cycle plugin?
661
if ($this->getOption('effect') != 'none')
662
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/jquery-cycle-2.1.6.min.js') . '"></script>';
664
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-layout-scaler.js') . '"></script>';
665
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-metro-render.js') . '"></script>';
666
$javaScriptContent .= '<script type="text/javascript" src="' . $this->getResourceUrl('xibo-image-render.js') . '"></script>';
668
$javaScriptContent .= '<script type="text/javascript">';
669
$javaScriptContent .= ' var options = ' . json_encode($options) . ';';
670
$javaScriptContent .= ' var items = ' . json_encode($items) . ';';
671
$javaScriptContent .= ' var colors = ' . json_encode($colorArray) . ';';
672
$javaScriptContent .= ' $(document).ready(function() { ';
673
$javaScriptContent .= ' $("body").xiboLayoutScaler(options); $("#content").xiboMetroRender(options, items, colors); $("#content").find("img").xiboImageRender(options); $("#content").find(".cell").xiboImageRender(options);';
674
$javaScriptContent .= ' }); ';
675
$javaScriptContent .= '</script>';
677
// Replace the Head Content with our generated javascript
678
$data['javaScript'] = $javaScriptContent;
680
// Update and save widget if we've changed our assignments.
681
if ($this->hasMediaChanged())
682
$this->widget->save(['saveWidgetOptions' => false, 'notifyDisplays' => true]);
684
return $this->renderTemplate($data);
688
public function isValid()
690
// Using the information you have in your module calculate whether it is valid or not.
701
private function tweetHasPhoto($tweet)
703
return ((isset($tweet->entities->media)
704
&& count($tweet->entities->media) > 0)
705
|| (isset($tweet->retweeted_status->entities->media)
706
&& count($tweet->retweeted_status->entities->media) > 0));