Skip to content

Commit

Permalink
Merge pull request #2760 from xibosignage/develop
Browse files Browse the repository at this point in the history
Release 4.1.1
  • Loading branch information
dasgarner authored Oct 8, 2024
2 parents a66c89c + 1ec819a commit dcb6145
Show file tree
Hide file tree
Showing 79 changed files with 4,933 additions and 4,107 deletions.
19 changes: 9 additions & 10 deletions bin/locale.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -29,14 +29,16 @@

use Slim\Flash\Messages;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Twig\TwigFilter;
use Xibo\Service\ConfigService;
use Xibo\Twig\ByteFormatterTwigExtension;
use Xibo\Twig\DateFormatTwigExtension;
use Xibo\Twig\TransExtension;
use Xibo\Twig\TwigMessages;

error_reporting(E_ALL);
ini_set('display_errors', 1);

define('PROJECT_ROOT', realpath(__DIR__ . '/..'));
require_once PROJECT_ROOT . '/vendor/autoload.php';

Expand All @@ -57,8 +59,6 @@
$view->addExtension(new TwigMessages(new Messages($storage)));

foreach (glob(PROJECT_ROOT . '/views/*.twig') as $file) {
echo var_export($file, true) . PHP_EOL;

$view->getEnvironment()->load(str_replace(PROJECT_ROOT . '/views/', '', $file));
}

Expand Down Expand Up @@ -137,7 +137,7 @@ function __($original)
}
if (!empty($setting->helpText)) {
// replaces any single quote within the value with a backslash followed by a single quote
$helpText = addslashes($setting->helpText);
$helpText = addslashes(trim($setting->helpText));
$content .= 'echo __(\''.$helpText.'\');' . PHP_EOL;
}

Expand All @@ -153,7 +153,7 @@ function __($original)
// Properties translation
foreach ($module->properties as $property) {
if (!empty($property->title)) {
$content .= 'echo __(\''.$property->title.'\');' . PHP_EOL;
$content .= 'echo __(\''.addslashes(trim($property->title)).'\');' . PHP_EOL;
}
if (!empty($property->helpText)) {
// replaces any single quote within the value with a backslash followed by a single quote
Expand All @@ -167,7 +167,7 @@ function __($original)
// Property rule test message
$message = $test->message;
if (!empty($message)) {
$content .= 'echo __(\''.$message.'\');' . PHP_EOL;
$content .= 'echo __(\''.addslashes(trim($message)).'\');' . PHP_EOL;
}
}
}
Expand All @@ -190,11 +190,11 @@ function __($original)
// Properties Translation
foreach ($moduleTemplate->properties as $property) {
if (!empty($property->title)) {
$content .= 'echo __(\''.$property->title.'\');' . PHP_EOL;
$content .= 'echo __(\''.addslashes(trim($property->title)).'\');' . PHP_EOL;
}
if (!empty($property->helpText)) {
// replaces any single quote within the value with a backslash followed by a single quote
$helpText = addslashes($property->helpText);
$helpText = addslashes(trim($property->helpText));
$content .= 'echo __(\''.$helpText.'\');' . PHP_EOL;
}

Expand All @@ -219,6 +219,5 @@ function __($original)
}
}

$content .= '?>';
file_put_contents($file, $content);
echo 'moduletranslate.file created and data written successfully.';
128 changes: 58 additions & 70 deletions lib/Connector/OpenWeatherMapConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,55 +665,44 @@ public function onScheduleCriteriaRequest(ScheduleCriteriaRequestInterface $even
{
// Initialize Open Weather Schedule Criteria parameters
$event->addType('weather', __('Weather'))
->addMetric('weather_condition', __('Weather Condition'))
->addValues('dropdown', [
'clear_sky' => __('Clear Sky'),
'few_clouds' => __('Few Clouds'),
'scattered_clouds' => __('Scattered Clouds'),
'broken_clouds' => __('Broken Clouds'),
'shower_rain' => __('Shower Rain'),
'rain' => __('Rain'),
'thunderstorm' => __('Thunderstorm'),
'snow' => __('Snow'),
'mist' => __('Mist')
])
->addMetric('temperature_imperial', __('Temperature (Imperial)'))
->addValues('number', [])
->addMetric('temperature_metric', __('Temperature (Metric)'))
->addValues('number', [])
->addMetric('apparent_temperature_imperial', __('Apparent Temperature (Imperial)'))
->addValues('number', [])
->addMetric('apparent_temperature_metric', __('Apparent Temperature (Metric)'))
->addValues('number', [])
->addMetric('wind_speed', __('Wind Speed'))
->addValues('number', [])
->addMetric('wind_direction', __('Wind Direction'))
->addValues('dropdown', [
'N' => __('North'),
'NNE ' => __('North-Northeast'),
'NE' => __('Northeast'),
'ENE' => __('East-Northeast'),
'E' => __('East'),
'ESE' => __('East-Southeast'),
'SE' => __('Southeast'),
'SSE' => __('South-Southeast'),
'S' => __('South'),
'SSW' => __('South-Southwest'),
'SW' => __('Southwest'),
'WSW' => __('West-Southwest'),
'W' => __('West'),
'WNW' => __('West-Northwest'),
'NW' => __('Northwest'),
'NNW' => __('North-Northwest'),
])
->addMetric('wind_bearing', __('Wind Bearing'))
->addValues('number', [])
->addMetric('humidity', __('Humidity (Percent)'))
->addValues('number', [])
->addMetric('pressure', __('Pressure'))
->addValues('number', [])
->addMetric('visibility', __('Visibility'))
->addValues('number', []);
->addMetric('condition', __('Weather Condition'))
->addValues('dropdown', [
'thunderstorm' => __('Thunderstorm'),
'drizzle' => __('Drizzle'),
'rain' => __('Rain'),
'snow' => __('Snow'),
'clear' => __('Clear'),
'clouds' => __('Clouds')
])
->addMetric('temp_imperial', __('Temperature (Imperial)'))
->addValues('number', [])
->addMetric('temp_metric', __('Temperature (Metric)'))
->addValues('number', [])
->addMetric('feels_like_imperial', __('Apparent Temperature (Imperial)'))
->addValues('number', [])
->addMetric('feels_like_metric', __('Apparent Temperature (Metric)'))
->addValues('number', [])
->addMetric('wind_speed', __('Wind Speed'))
->addValues('number', [])
->addMetric('wind_direction', __('Wind Direction'))
->addValues('dropdown', [
'N' => __('North'),
'NE' => __('Northeast'),
'E' => __('East'),
'SE' => __('Southeast'),
'S' => __('South'),
'SW' => __('Southwest'),
'W' => __('West'),
'NW' => __('Northwest'),
])
->addMetric('wind_degrees', __('Wind Direction (degrees)'))
->addValues('number', [])
->addMetric('humidity', __('Humidity (Percent)'))
->addValues('number', [])
->addMetric('pressure', __('Pressure'))
->addValues('number', [])
->addMetric('visibility', __('Visibility (meters)'))
->addValues('number', []);
}

/**
Expand Down Expand Up @@ -744,50 +733,49 @@ private function processXmdsWeatherData($item, $unit, $requestUnit): array
$apparentTempMetric = ($apparentTempImperial - 32) * 5 / 9;

// Round those temperature values
$data['temperature_imperial'] = round($tempImperial, 0);
$data['apparent_temperature_imperial'] = round($apparentTempImperial, 0);
$data['temperature_metric'] = round($tempMetric, 0);
$data['apparent_temperature_metric'] = round($apparentTempMetric, 0);

$data['weather_temp_imperial'] = round($tempImperial, 0);
$data['weather_feels_like_imperial'] = round($apparentTempImperial, 0);
$data['weather_temp_metric'] = round($tempMetric, 0);
$data['weather_feels_like_metric'] = round($apparentTempMetric, 0);

// Humidity
$data['humidity'] = $item['humidity'];
$data['weather_humidity'] = $item['humidity'];

// Pressure
// received in hPa, display in mB
$data['pressure'] = $item['pressure'] / 100;
$data['weather_pressure'] = $item['pressure'] / 100;

// Wind
// metric = meters per second
// imperial = miles per hour
$data['wind_speed'] = $item['wind_speed'] ?? $item['speed'] ?? null;
$data['wind_bearing'] = $item['wind_deg'] ?? $item['deg'] ?? null;
$data['weather_wind_speed'] = $item['wind_speed'] ?? $item['speed'] ?? null;
$data['weather_wind_degrees'] = $item['wind_deg'] ?? $item['deg'] ?? null;

if ($requestUnit === 'metric' && $windSpeedUnit !== 'MPS') {
// We have MPS and need to go to something else
if ($windSpeedUnit === 'MPH') {
// Convert MPS to MPH
$data['wind_speed'] = round($data['wind_speed'] * 2.237, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 2.237, 2);
} else if ($windSpeedUnit === 'KPH') {
// Convert MPS to KPH
$data['wind_speed'] = round($data['wind_speed'] * 3.6, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 3.6, 2);
}
} else if ($requestUnit === 'imperial' && $windSpeedUnit !== 'MPH') {
if ($windSpeedUnit === 'MPS') {
// Convert MPH to MPS
$data['wind_speed'] = round($data['wind_speed'] / 2.237, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] / 2.237, 2);
} else if ($windSpeedUnit === 'KPH') {
// Convert MPH to KPH
$data['wind_speed'] = round($data['wind_speed'] * 1.609344, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 1.609344, 2);
}
}

// Wind direction
$data['wind_direction'] = '--';
if ($data['wind_bearing'] !== null && $data['wind_bearing'] !== 0) {
$data['weather_wind_direction'] = '--';
if ($data['weather_wind_degrees'] !== null && $data['weather_wind_degrees'] !== 0) {
foreach (self::cardinalDirections() as $dir => $angles) {
if ($data['wind_bearing'] >= $angles[0] && $data['wind_bearing'] < $angles[1]) {
$data['wind_direction'] = $dir;
if ($data['weather_wind_degrees'] >= $angles[0] && $data['weather_wind_degrees'] < $angles[1]) {
$data['weather_wind_direction'] = $dir;
break;
}
}
Expand All @@ -796,17 +784,17 @@ private function processXmdsWeatherData($item, $unit, $requestUnit): array
// Visibility
// metric = meters
// imperial = meters?
$data['visibility'] = $item['visibility'] ?? '--';
$data['weather_visibility'] = $item['visibility'] ?? '--';

if ($data['visibility'] !== '--') {
if ($data['weather_visibility'] !== '--') {
// Always in meters
if ($visibilityDistanceUnit === 'mi') {
// Convert meters to miles
$data['visibility'] = $data['visibility'] / 1609;
$data['weather_visibility'] = $data['weather_visibility'] / 1609;
} else {
if ($visibilityDistanceUnit === 'km') {
// Convert meters to KM
$data['visibility'] = $data['visibility'] / 1000;
$data['weather_visibility'] = $data['weather_visibility'] / 1000;
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions lib/Connector/XiboExchangeConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Xibo\Entity\SearchResult;
use Xibo\Event\TemplateProviderEvent;
use Xibo\Event\TemplateProviderImportEvent;
use Xibo\Event\TemplateProviderListEvent;
use Xibo\Support\Sanitizer\SanitizerInterface;

/**
Expand All @@ -50,6 +51,7 @@ public function registerWithDispatcher(EventDispatcherInterface $dispatcher): Co
{
$dispatcher->addListener('connector.provider.template', [$this, 'onTemplateProvider']);
$dispatcher->addListener('connector.provider.template.import', [$this, 'onTemplateProviderImport']);
$dispatcher->addListener('connector.provider.template.list', [$this, 'onTemplateList']);
return $this;
}

Expand Down Expand Up @@ -239,4 +241,25 @@ private function createSearchResult($template) : SearchResult
$searchResult->download = $template->downloadUrl;
return $searchResult;
}

/**
* Add this connector to the list of providers.
* @param \Xibo\Event\TemplateProviderListEvent $event
* @return void
*/
public function onTemplateList(TemplateProviderListEvent $event): void
{
$this->getLogger()->debug('onTemplateList:event');

$providerDetails = new ProviderDetails();
$providerDetails->id = $this->getSourceName();
$providerDetails->link = 'https://xibosignage.com';
$providerDetails->logoUrl = $this->getThumbnail();
$providerDetails->iconUrl = 'exchange-alt';
$providerDetails->message = $this->getTitle();
$providerDetails->backgroundColor = '';
$providerDetails->mediaTypes = ['xlf'];

$event->addProvider($providerDetails);
}
}
3 changes: 3 additions & 0 deletions lib/Controller/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,9 @@ public function assignDisplayGroup(Request $request, Response $response, $id)
$displayGroup->save(['validate' => false]);
}

// Queue display to check for cache updates
$display->notify();

// Return
$this->getState()->hydrate([
'httpStatus' => 204,
Expand Down
19 changes: 19 additions & 0 deletions lib/Controller/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
namespace Xibo\Controller;

use Parsedown;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response as Response;
use Slim\Http\ServerRequest as Request;
use Xibo\Entity\SearchResult;
use Xibo\Entity\SearchResults;
use Xibo\Event\TemplateProviderEvent;
use Xibo\Event\TemplateProviderListEvent;
use Xibo\Factory\LayoutFactory;
use Xibo\Factory\TagFactory;
use Xibo\Support\Exception\AccessDeniedException;
Expand Down Expand Up @@ -767,4 +769,21 @@ public function editForm(Request $request, Response $response, $id)

return $this->render($request, $response);
}

/**
* Get list of Template providers with their details.
*
* @param Request $request
* @param Response $response
* @return Response|ResponseInterface
*/
public function providersList(Request $request, Response $response): Response|\Psr\Http\Message\ResponseInterface
{
$event = new TemplateProviderListEvent();
$this->getDispatcher()->dispatch($event, $event->getName());

$providers = $event->getProviders();

return $response->withJson($providers);
}
}
2 changes: 1 addition & 1 deletion lib/Entity/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public function getLogLevel(): string
$restingLogLevel = $this->getSetting('logLevel', 'error');
$isElevated = $this->isElevatedLogging();

return $isElevated ? 'debug' : $restingLogLevel;
return $isElevated ? 'audit' : $restingLogLevel;
}

/**
Expand Down
Loading

0 comments on commit dcb6145

Please sign in to comment.