summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locationinfo/page.inc.php')
-rw-r--r--modules-available/locationinfo/page.inc.php385
1 files changed, 177 insertions, 208 deletions
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 13d7d459..63a02ba2 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -81,7 +81,7 @@ class Page_LocationInfo extends Page
$this->showLocationsTable();
break;
case 'backends':
- $this->showBackendsTable($backends);
+ $this->showBackendsTable($backends ?? []);
break;
case 'edit-panel':
$this->showPanelConfig();
@@ -100,7 +100,7 @@ class Page_LocationInfo extends Page
/**
* Deletes the server from the db.
*/
- private function deleteServer($id)
+ private function deleteServer($id): void
{
User::assertPermission('backend.edit');
if ($id === 0) {
@@ -113,7 +113,7 @@ class Page_LocationInfo extends Page
}
}
- private function deletePanel()
+ private function deletePanel(): void
{
$id = Request::post('uuid', false, 'string');
if ($id === false) {
@@ -130,25 +130,27 @@ class Page_LocationInfo extends Page
}
}
- private function getTime($str)
+ private static function getTime(string $str): ?int
{
$str = explode(':', $str);
- if (count($str) !== 2) return false;
- if ($str[0] < 0 || $str[0] > 23 || $str[1] < 0 || $str[1] > 59) return false;
+ if (count($str) !== 2)
+ return null;
+ if ($str[0] < 0 || $str[0] > 23 || $str[1] < 0 || $str[1] > 59)
+ return null;
return $str[0] * 60 + $str[1];
}
- private function writeLocationConfig()
+ private function writeLocationConfig(): void
{
// Check locations
$locationid = Request::post('locationid', false, 'int');
if ($locationid === false) {
Message::addError('main.parameter-missing', 'locationid');
- return false;
+ return;
}
if (Location::get($locationid) === false) {
Message::addError('location.invalid-location-id', $locationid);
- return false;
+ return;
}
User::assertPermission('location.edit', $locationid);
@@ -167,101 +169,20 @@ class Page_LocationInfo extends Page
$ignoreServer = 0;
}
- // Opening times
- $openingtimes = Request::post('openingtimes', '', 'string');
- if ($openingtimes !== '') {
- $openingtimes = json_decode($openingtimes, true);
- if (!is_array($openingtimes)) {
- $openingtimes = '';
- } else {
- $mangled = array();
- foreach (array_keys($openingtimes) as $key) {
- $entry = $openingtimes[$key];
- if (!isset($entry['days']) || !is_array($entry['days']) || empty($entry['days'])) {
- Message::addError('ignored-line-no-days');
- continue;
- }
- $s = $this->getTime($entry['openingtime']);
- $e = $this->getTime($entry['closingtime']);
- if ($s === false) {
- Message::addError('ignored-invalid-start', $entry['openingtime']);
- continue;
- }
- if ($e === false) {
- Message::addError('ignored-invalid-end', $entry['closingtime']);
- continue;
- }
- if ($e <= $s) {
- Message::addError('ignored-invalid-range', $entry['openingtime'], $entry['closingtime']);
- continue;
- }
- unset($entry['tag']);
- $mangled[] = $entry;
- }
- if (empty($mangled)) {
- $openingtimes = null;
- } else {
- $openingtimes = json_encode($mangled);
- }
- }
- }
$NOW = time();
- // Check if openingtimes changed
- $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :locationid', compact('locationid'));
- $otChanged = $res === false || $res['openingtime'] !== $openingtimes;
- Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, openingtime, lastcalendarupdate, lastchange)
- VALUES (:id, :insertserverid, :serverlocationid, :openingtimes, 0, :now)
+ Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, lastcalendarupdate, lastchange)
+ VALUES (:id, :insertserverid, :serverlocationid, 0, :now)
ON DUPLICATE KEY UPDATE serverid = IF(:ignore_server AND serverid IS NULL, NULL, :serverid), serverlocationid = VALUES(serverlocationid),
- openingtime = VALUES(openingtime), lastcalendarupdate = 0, lastchange = VALUES(lastchange)", array(
+ lastcalendarupdate = 0, lastchange = VALUES(lastchange)", array(
'id' => $locationid,
'insertserverid' => $insertServerId,
'serverid' => $serverid,
- 'openingtimes' => $openingtimes,
'serverlocationid' => $serverlocationid,
'ignore_server' => $ignoreServer,
'now' => $NOW,
));
- if ($otChanged) {
- $tree = Location::getLocationsAssoc();
- $todo = array();
- $done = array();
- foreach ($tree as $l) {
- if ($l['parentlocationid'] == $locationid) {
- $todo[] = $l['locationid'];
- }
- }
- while (!empty($todo)) {
- $loc = array_pop($todo);
- if (in_array($loc, $done))
- continue;
- $done[] = $loc;
- // See if this one inherits
- $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :loc', compact('loc'));
- if ($res === false) {
- $res = Database::exec('INSERT INTO locationinfo_locationconfig (locationid, lastchange)
- VALUES (:locationid, :now) ON DUPLICATE KEY UPDATE lastchange = :now',
- array('locationid' => $loc, 'now' => $NOW));
- } elseif (strlen($res['openingtime']) < 5) {
- $res = Database::exec('UPDATE locationinfo_locationconfig SET lastchange = :now, openingtime = NULL
- WHERE locationid = :locationid',
- array('locationid' => $loc, 'now' => $NOW));
- } else {
- $res = 0;
- }
- if ($res > 0) {
- // Row was updated, which means the openingtime column was empty, which means the openingtime is inherited, descend further
- $todo = array_merge($todo, $tree[$loc]['children']);
- foreach ($tree as $l) {
- if ($l['parentlocationid'] == $loc) {
- $todo[] = $l['locationid'];
- }
- }
- }
- }
- }
-
if ($changeServerRecursive) {
// Recursive overwriting of serverid
$children = Location::getRecursiveFlat($locationid);
@@ -279,29 +200,23 @@ class Page_LocationInfo extends Page
));
}
}
-
- return true;
}
/**
* Get all location ids from the locationids parameter, which is comma separated, then split
- * and remove any ids that don't exist. The cleaned list will be returned
+ * and remove any ids that don't exist. The cleaned list will be returned.
+ * Will show error and redirect to main page if parameter is missing
+ *
* @param bool $failIfEmpty Show error and redirect to main page if parameter is missing or list is empty
* @return array list of locations from parameter
*/
- private function getLocationIdsFromRequest($failIfEmpty)
+ private function getLocationIdsFromRequest(): array
{
- $locationids = Request::post('locationids', false, 'string');
- if ($locationids === false) {
- if (!$failIfEmpty)
- return array();
- Message::addError('main.parameter-missing', 'locationids');
- Util::redirect('?do=locationinfo');
- }
+ $locationids = Request::post('locationids', Request::REQUIRED_EMPTY, 'string');
$locationids = explode(',', $locationids);
$all = array_map(function ($item) { return $item['locationid']; }, Location::queryLocations());
$locationids = array_filter($locationids, function ($item) use ($all) { return in_array($item, $all); });
- if ($failIfEmpty && empty($locationids)) {
+ if (empty($locationids)) {
Message::addError('main.parameter-empty', 'locationids');
Util::redirect('?do=locationinfo');
}
@@ -311,7 +226,7 @@ class Page_LocationInfo extends Page
/**
* Updated the config in the db.
*/
- private function writePanelConfig()
+ private function writePanelConfig(): void
{
// UUID - existing or new
$paneluuid = Request::post('uuid', false, 'string');
@@ -334,7 +249,7 @@ class Page_LocationInfo extends Page
}
// Permission
- $this->assertPanelPermission($paneluuid, 'panel.edit', $params['locationids']);
+ $this->assertPanelPermission($paneluuid, 'panel.edit', $params['locationids'] ?? []);
if ($paneluuid === 'new') {
$paneluuid = Util::randomUuid();
@@ -357,14 +272,17 @@ class Page_LocationInfo extends Page
Util::redirect('?do=locationinfo');
}
- private function preparePanelConfigDefault()
+ /**
+ * @return array{config: array, locationids: array}
+ */
+ private function preparePanelConfigDefault(): array
{
// Check locations
- $locationids = self::getLocationIdsFromRequest(true);
+ $locationids = self::getLocationIdsFromRequest();
if (count($locationids) > 4) {
$locationids = array_slice($locationids, 0, 4);
}
- // Build json struct
+ // Build struct from POST
$conf = array(
'language' => Request::post('language', 'en', 'string'),
'mode' => Request::post('mode', 1, 'int'),
@@ -380,6 +298,7 @@ class Page_LocationInfo extends Page
'switchtime' => Request::post('switchtime', 20, 'int'),
'calupdate' => Request::post('calupdate', 120, 'int'),
'roomupdate' => Request::post('roomupdate', 30, 'int'),
+ 'hostname' => Request::post('hostname', false, 'bool'),
);
if ($conf['roomupdate'] < 15) {
$conf['roomupdate'] = 15;
@@ -401,7 +320,7 @@ class Page_LocationInfo extends Page
'daystoshow' => Request::post('override'.$locationids[$i].'daystoshow', 7, 'int'),
'rotation' => Request::post('override'.$locationids[$i].'rotation', 0, 'int'),
'scale' => Request::post('override'.$locationids[$i].'scale', 50, 'int'),
- 'switchtime' => Request::post('override'.$locationids[$i].'switchtime', 60, 'int')
+ 'switchtime' => Request::post('override'.$locationids[$i].'switchtime', 60, 'int'),
);
$overrides[$locationids[$i]] = $overrideArray;
}
@@ -411,7 +330,10 @@ class Page_LocationInfo extends Page
return array('config' => $conf, 'locationids' => $locationids);
}
- private function preparePanelConfigUrl()
+ /**
+ * @return array{config: array, locationids: array}
+ */
+ private function preparePanelConfigUrl(): array
{
$bookmarkNames = Request::post('bookmarkNames', [], 'array');
$bookmarkUrls = Request::post('bookmarkUrls', [], 'array');
@@ -429,17 +351,22 @@ class Page_LocationInfo extends Page
'url' => Request::post('url', 'https://www.bwlehrpool.de/', 'string'),
'insecure-ssl' => Request::post('insecure-ssl', 0, 'int'),
'reload-minutes' => max(0, Request::post('reloadminutes', 0, 'int')),
- 'iswhitelist' => Request::post('iswhitelist', 0, 'int'),
- 'urllist' => preg_replace("/[\r\n\\s]+/ms", ' ', Request::post('urllist', '', 'string')),
+ 'whitelist' => preg_replace("/[\r\n]+/m", "\n", Request::post('whitelist', '', 'string')),
+ 'blacklist' => preg_replace("/[\r\n]+/m", "\n", Request::post('blacklist', '', 'string')),
'split-login' => Request::post('split-login', 0, 'bool'),
'browser' => Request::post('browser', 'slx-browser', 'string'),
'interactive' => Request::post('interactive', '0', 'bool'),
- 'bookmarks' => $bookmarkString ? $bookmarkString : '',
+ 'bookmarks' => $bookmarkString ?: '',
+ 'allow-tty' => Request::post('allow-tty', '', 'string'),
+ 'zoom-factor' => Request::post('zoom-factor', 100, 'int'),
);
return array('config' => $conf, 'locationids' => []);
}
- private function preparePanelConfigSummary()
+ /**
+ * @return array{config: array, locationids: array}
+ */
+ private function preparePanelConfigSummary(): array
{
// Build json structure
$conf = array(
@@ -452,14 +379,14 @@ class Page_LocationInfo extends Page
$conf['panelupdate'] = 15;
}
// Check locations
- $locationids = self::getLocationIdsFromRequest(true);
+ $locationids = self::getLocationIdsFromRequest();
return array('config' => $conf, 'locationids' => $locationids);
}
/**
* Updates the server settings in the db.
*/
- private function updateServerSettings()
+ private function updateServerSettings(): void
{
User::assertPermission('backend.edit');
$serverid = Request::post('id', -1, 'int');
@@ -501,10 +428,10 @@ class Page_LocationInfo extends Page
*
* @param int $id Server id which connection should be checked.
*/
- private function checkConnection($serverid = 0)
+ private function checkConnection(int $serverid = 0): void
{
if ($serverid === 0) {
- Util::traceError('checkConnection called with no server id');
+ ErrorHandler::traceError('checkConnection called with no server id');
}
User::assertPermission('backend.check');
@@ -517,7 +444,8 @@ class Page_LocationInfo extends Page
LocationInfo::setServerError($serverid, 'Unknown backend type: ' . $dbresult['servertype']);
return;
}
- $credentialsOk = $serverInstance->setCredentials($serverid, json_decode($dbresult['credentials'], true));
+ $credentialsOk = $serverInstance->setCredentials($serverid,
+ (array)json_decode($dbresult['credentials'], true));
if ($credentialsOk) {
$serverInstance->checkConnection();
@@ -526,7 +454,7 @@ class Page_LocationInfo extends Page
LocationInfo::setServerError($serverid, $serverInstance->getErrors());
}
- private function loadBackends()
+ private function loadBackends(): array
{
// Get a list of all the backend types.
$servertypes = array();
@@ -538,7 +466,7 @@ class Page_LocationInfo extends Page
// Build list of defined backends
$serverlist = array();
$dbquery2 = Database::simpleQuery("SELECT * FROM `locationinfo_coursebackend` ORDER BY servername ASC");
- while ($row = $dbquery2->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery2 as $row) {
if (isset($servertypes[$row['servertype']])) {
$row['typename'] = $servertypes[$row['servertype']];
} else {
@@ -564,7 +492,7 @@ class Page_LocationInfo extends Page
/**
* Show the list of backends
*/
- private function showBackendsTable($serverlist)
+ private function showBackendsTable(array $serverlist): void
{
User::assertPermission('backend.*');
$data = array(
@@ -575,7 +503,7 @@ class Page_LocationInfo extends Page
Render::addTemplate('page-servers', $data);
}
- private function showBackendLog()
+ private function showBackendLog(): void
{
$id = Request::get('serverid', false, 'int');
if ($id === false) {
@@ -591,7 +519,7 @@ class Page_LocationInfo extends Page
$server['list'] = [];
$res = Database::simpleQuery('SELECT dateline, message FROM locationinfo_backendlog
WHERE serverid = :id ORDER BY logid DESC LIMIT 100', ['id' => $id]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['dateline_s'] = Util::prettyTime($row['dateline']);
$row['class'] = substr($row['message'], 0, 3) === '[F]' ? 'text-danger' : 'text-warning';
$row['message'] = Substr($row['message'], 3);
@@ -600,7 +528,7 @@ class Page_LocationInfo extends Page
Render::addTemplate('page-server-log', $server);
}
- private function showLocationsTable()
+ private function showLocationsTable(): void
{
$allowedLocations = User::getAllowedLocations('location.edit');
if (empty($allowedLocations)) {
@@ -610,11 +538,12 @@ class Page_LocationInfo extends Page
$locations = Location::getLocations(0, 0, false, true);
// Get hidden state of all locations
- $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, li.openingtime, li.lastcalendarupdate, cb.servertype, cb.servername
+ $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, loc.openingtime, li.lastcalendarupdate, cb.servertype, cb.servername
FROM `locationinfo_locationconfig` AS li
- LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid)");
+ LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid)
+ LEFT JOIN `location` AS loc USING (locationid)");
- while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery as $row) {
$locid = (int)$row['locationid'];
if (!isset($locations[$locid]) || !in_array($locid, $allowedLocations))
continue;
@@ -625,6 +554,7 @@ class Page_LocationInfo extends Page
}
$locations[$locid] += array(
'openingGlyph' => $glyph,
+ 'strong' => $glyph === 'ok',
'backend' => $backend,
'lastCalendarUpdate' => Util::prettyTime($row['lastcalendarupdate']), // TODO
'backendMissing' => !CourseBackend::exists($row['servertype']),
@@ -653,11 +583,20 @@ class Page_LocationInfo extends Page
));
}
- private function showPanelsTable()
+ private function showPanelsTable(): void
{
$visibleLocations = User::getAllowedLocations('panel.list');
+ if (in_array(0, $visibleLocations)) {
+ $visibleLocations = true;
+ }
$editLocations = User::getAllowedLocations('panel.edit');
+ if (in_array(0, $editLocations)) {
+ $editLocations = true;
+ }
$assignLocations = USer::getAllowedLocations('panel.assign-client');
+ if (in_array(0, $assignLocations)) {
+ $assignLocations = true;
+ }
if (empty($visibleLocations)) {
Message::addError('main.no-permission');
return;
@@ -671,7 +610,7 @@ class Page_LocationInfo extends Page
}
$panels = array();
$locations = Location::getLocationsAssoc();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['paneltype'] === 'URL') {
$url = json_decode($row['panelconfig'], true)['url'];
$row['locations'] = $row['locationurl'] = $url;
@@ -680,14 +619,16 @@ class Page_LocationInfo extends Page
} else {
$lids = explode(',', $row['locationids']);
// Permissions
- if (!empty(array_diff($lids, $visibleLocations))) {
+ if ($visibleLocations !== true && !empty(array_diff($lids, $visibleLocations))) {
continue;
}
- $row['edit_disabled'] = !empty(array_diff($lids, $editLocations)) ? 'disabled' : '';
- $row['runmode_disabled'] = !empty(array_diff($lids, $assignLocations)) ? 'disabled' : '';
+ $row['edit_disabled'] = $editLocations !== true && !empty(array_diff($lids, $editLocations))
+ ? 'disabled' : '';
+ $row['runmode_disabled'] = $assignLocations !== true && !empty(array_diff($lids, $assignLocations))
+ ? 'disabled' : '';
// Locations
$locs = array_map(function ($id) use ($locations) {
- return isset($locations[$id]) ? $locations[$id]['locationname'] : $id;
+ return isset($locations[$id]) ? $locations[$id]['locationname'] : "<<deleted=$id>>";
}, $lids);
$row['locations'] = implode(', ', $locs);
}
@@ -726,7 +667,7 @@ class Page_LocationInfo extends Page
*
* @param int $id Serverid
*/
- private function ajaxServerSettings($id)
+ private function ajaxServerSettings(int $id): void
{
User::assertPermission('backend.edit');
$oldConfig = Database::queryFirst('SELECT servername, servertype, credentials
@@ -751,12 +692,13 @@ class Page_LocationInfo extends Page
);
$backend['credentials'] = $backendInstance->getCredentialDefinitions();
foreach ($backend['credentials'] as $cred) {
+ /* @var BackendProperty $cred */
if ($backend['active'] && isset($oldCredentials[$cred->property])) {
- $cred->initForRender($oldCredentials[$cred->property]);
+ $cred->initForRender($backendInstance->mangleProperty($cred->property, $oldCredentials[$cred->property]));
} else {
$cred->initForRender();
}
- $cred->title = Dictionary::translateFile('backend-' . $s, $cred->property, true);
+ $cred->title = Dictionary::translateFile('backend-' . $s, $cred->property);
$cred->helptext = Dictionary::translateFile('backend-' . $s, $cred->property . "_helptext");
$cred->credentialsHtml = Render::parse('server-prop-' . $cred->template, (array)$cred);
}
@@ -774,10 +716,13 @@ class Page_LocationInfo extends Page
*
* @param int $id id of the location
*/
- private function ajaxConfigLocation($id)
+ private function ajaxConfigLocation(int $id): void
{
User::assertPermission('location.edit', $id);
- $locConfig = Database::queryFirst("SELECT serverid, serverlocationid, openingtime FROM `locationinfo_locationconfig` WHERE locationid = :id", array('id' => $id));
+ $locConfig = Database::queryFirst("SELECT info.serverid, info.serverlocationid, loc.openingtime
+ FROM `locationinfo_locationconfig` AS info
+ LEFT JOIN `location` AS loc USING (locationid)
+ WHERE locationid = :id", array('id' => $id));
if ($locConfig !== false) {
$openingtimes = json_decode($locConfig['openingtime'], true);
} else {
@@ -795,7 +740,7 @@ class Page_LocationInfo extends Page
WHERE locationid IN (:locations) AND serverid IS NOT NULL", array('locations' => $chain));
$chain = array_flip($chain);
$best = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($best === false || $chain[$row['locationid']] < $chain[$best['locationid']]) {
$best = $row;
}
@@ -809,7 +754,7 @@ class Page_LocationInfo extends Page
// get Server / ID list
$res = Database::simpleQuery("SELECT serverid, servername FROM locationinfo_coursebackend ORDER BY servername ASC");
$serverList = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['serverid'] == $locConfig['serverid']) {
$row['selected'] = 'selected';
}
@@ -820,10 +765,8 @@ class Page_LocationInfo extends Page
'id' => $id,
'serverlist' => $serverList,
'serverlocationid' => $locConfig['serverlocationid'],
+ 'openingtimes' => $this->compressTimes($openingtimes),
);
- $data['expertMode'] = !$this->isSimpleMode($openingtimes);
- // !! isSimpleMode might have changed $openingtimes, so order is important here...
- $data['schedule_data'] = json_encode($openingtimes);
echo Render::parse('ajax-config-location', $data);
}
@@ -832,71 +775,85 @@ class Page_LocationInfo extends Page
* Checks if simple mode or expert mode is active.
* Tries to merge/compact the opening times schedule, and
* will actually modify the passed array iff it can be
- * transformed into easy opening times.
+ * transformed into simple opening times.
*
- * @param array $array of the saved openingtimes.
- * @return bool True if simple mode, false if expert mode
+ * @return array new optimized openingtimes
*/
- private function isSimpleMode(&$array)
+ private function compressTimes(array $array): array
{
if (empty($array))
- return true;
+ return [];
// Decompose by day
- $new = array();
+ $DAYLIST = array_flip(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']);
+ $new = [];
foreach ($array as $row) {
- $s = $this->getTime($row['openingtime']);
- $e = $this->getTime($row['closingtime']);
- if ($s === false || $e === false || $e <= $s)
+ $s = Page_LocationInfo::getTime($row['openingtime']);
+ $e = Page_LocationInfo::getTime($row['closingtime']);
+ if ($s === null || $e === null || $e <= $s)
continue;
foreach ($row['days'] as $day) {
+ $day = $DAYLIST[$day] ?? -1;
+ if ($day === -1)
+ continue;
$this->addDay($new, $day, $s, $e);
}
}
- // Merge by timespan, but always keep saturday and sunday separate
- $merged = array();
+ // Merge by timespan
+ $merged = [];
foreach ($new as $day => $ranges) {
foreach ($ranges as $range) {
- if ($day === 'Saturday' || $day === 'Sunday') {
- $add = $day;
- } else {
- $add = '';
+ $range = $range[0] . '#' . $range[1];
+ if (!isset($merged[$range])) {
+ $merged[$range] = [];
}
- $key = '#' . $range[0] . '#' . $range[1] . '#' . $add;
- if (!isset($merged[$key])) {
- $merged[$key] = array();
- }
- $merged[$key][$day] = true;
+ $merged[$range][$day] = true;
}
}
- // Check if it passes as simple mode
- if (count($merged) > 3)
- return false;
- foreach ($merged as $days) {
- if (count($days) === 5) {
- $res = array_keys($days);
- $res = array_intersect($res, array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"));
- if (count($res) !== 5)
- return false;
- } elseif (count($days) === 1) {
- if (!isset($days['Saturday']) && !isset($days['Sunday'])) {
- return false;
- }
+ // Finally transform to display struct
+ $new = [];
+ foreach ($merged as $span => $days) {
+ $out = explode('#', $span);
+ $new[] = [
+ 'days' => $this->buildDaysString(array_keys($days)),
+ 'open' => sprintf('%02d:%02d', ($out[0] / 60), ($out[0] % 60)),
+ 'close' => sprintf('%02d:%02d', ($out[1] / 60), ($out[1] % 60)),
+ ];
+ }
+ return $new;
+ }
+
+ /**
+ * @param array $daysArray List of days, "Monday", "Tuesday" etc. Must not contain duplicates.
+ * @return string Human-readable representation of list of days
+ */
+ private function buildDaysString(array $daysArray): string
+ {
+ /* Dictionary::translate('monday') Dictionary::translate('tuesday') Dictionary::translate('wednesday')
+ * Dictionary::translate('thursday') Dictionary::translate('friday') Dictionary::translate('saturday')
+ * Dictionary::translate('sunday')
+ */
+ $DAYLIST = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
+ $output = [];
+ $first = $last = -1;
+ sort($daysArray);
+ $daysArray[] = -1; // One trailing element to enforce a flush
+ foreach ($daysArray as $day) {
+ if ($first === -1) {
+ $first = $last = $day;
+ } elseif ($last + 1 === $day) {
+ // Chain
+ $last++;
} else {
- return false;
+ $string = Dictionary::translate($DAYLIST[$first]);
+ if ($first !== $last) {
+ $string .= ($first + 1 === $last ? ",\xe2\x80\x89" : "\xe2\x80\x89-\xe2\x80\x89")
+ . Dictionary::translate($DAYLIST[$last]);
+ }
+ $output[] = $string;
+ $first = $last = $day;
}
}
- // Valid simple mode, finally transform back to what we know
- $new = array();
- foreach ($merged as $span => $days) {
- preg_match('/^#(\d+)#(\d+)#/', $span, $out);
- $new[] = array(
- 'days' => array_keys($days),
- 'openingtime' => floor($out[1] / 60) . ':' . ($out[1] % 60),
- 'closingtime' => floor($out[2] / 60) . ':' . ($out[2] % 60),
- );
- }
- $array = $new;
- return true;
+ return implode(', ', $output);
}
private function addDay(&$array, $day, $s, $e)
@@ -926,7 +883,7 @@ class Page_LocationInfo extends Page
// $start must lie before range start, otherwise we'd have hit the case above
$e = $current[1];
unset($array[$day][$key]);
- continue;
+ //continue;
}
}
$array[$day][] = array($s, $e);
@@ -934,10 +891,8 @@ class Page_LocationInfo extends Page
/**
* Ajax the config of a panel.
- *
- * @param $id Location ID
*/
- private function showPanelConfig()
+ private function showPanelConfig(): void
{
$id = Request::get('uuid', false, 'string');
if ($id === false) {
@@ -1025,6 +980,7 @@ class Page_LocationInfo extends Page
'locations' => Location::getLocations(),
'locationids' => $panel['locationids'],
'overrides' => json_encode($config['overrides']),
+ 'hostname_checked' => $config['hostname'] ? 'checked' : '',
));
} elseif ($panel['paneltype'] === 'URL') {
@@ -1042,19 +998,29 @@ class Page_LocationInfo extends Page
}
}
+ if (empty($config['blacklist']) && $config['whitelist'] === '*' && !empty($config['urllist'])) {
+ if ($config['iswhitelist']) {
+ $config['whitelist'] = str_replace(' ', "\n", $config['urllist']);
+ } else {
+ $config['blacklist'] = str_replace(' ', "\n", $config['urllist']);
+ }
+ }
+
Render::addTemplate('page-config-panel-url', array(
'new' => $id === 'new',
'uuid' => $id,
'panelname' => $panel['panelname'],
'url' => $config['url'],
+ 'zoom-factor' => $config['zoom-factor'],
'ssl_checked' => $config['insecure-ssl'] ? 'checked' : '',
'reloadminutes' => (int)$config['reload-minutes'],
- 'iswhitelist_' . $config['iswhitelist'] . '_checked' => 'checked',
- 'urllist' => str_replace(' ', "\r\n", $config['urllist']),
+ 'whitelist' => str_replace("\n", "\r\n", $config['whitelist']),
+ 'blacklist' => str_replace("\n", "\r\n", $config['blacklist']),
'split-login_checked' => $config['split-login'] ? 'checked' : '',
'browser' => $config['browser'],
'interactive_checked' => $config['interactive'] ? 'checked' : '',
'bookmarks' => $bookmarksArray,
+ 'allow-tty_' . $config['allow-tty'] . '_checked' => 'checked',
));
} else {
Render::addTemplate('page-config-panel-summary', array(
@@ -1071,7 +1037,7 @@ class Page_LocationInfo extends Page
}
}
- private function showPanel()
+ private function showPanel(): void
{
$uuid = Request::get('uuid', false, 'string');
if ($uuid === false) {
@@ -1079,7 +1045,7 @@ class Page_LocationInfo extends Page
die('Missing parameter uuid');
}
$type = InfoPanel::getConfig($uuid, $config);
- if ($type === false) {
+ if ($type === null) {
http_response_code(404);
die('Panel with given uuid not found');
}
@@ -1089,10 +1055,14 @@ class Page_LocationInfo extends Page
}
$data = array();
- preg_match('#^(.*)/#', $_SERVER['PHP_SELF'], $script);
- preg_match('#^([^?]+)/#', $_SERVER['REQUEST_URI'], $request);
+ preg_match('#^/(.*)/#', $_SERVER['PHP_SELF'], $script);
+ preg_match('#^/([^?]+)/#', $_SERVER['REQUEST_URI'], $request);
if ($script[1] !== $request[1]) {
- $data['dirprefix'] = $script[1] . '/';
+ // Working with server-side redirects
+ $data['api'] = 'api/';
+ } else {
+ // 1:1
+ $data['api'] = 'api.php?do=locationinfo&';
}
if ($type === 'DEFAULT') {
@@ -1102,7 +1072,7 @@ class Page_LocationInfo extends Page
'language' => $config['language'],
);
- die(Render::parse('frontend-default', $data, $module = false, $lang = $config['language']));
+ die(Render::parse('frontend-default', $data, null, $config['language']));
}
if ($type === 'SUMMARY') {
@@ -1114,7 +1084,7 @@ class Page_LocationInfo extends Page
'language' => $config['language'],
);
- die(Render::parse('frontend-summary', $data, $module = false, $lang = $config['language']));
+ die(Render::parse('frontend-summary', $data, null, $config['language']));
}
http_response_code(500);
@@ -1123,10 +1093,9 @@ class Page_LocationInfo extends Page
/**
* @param string|array $panelOrUuid UUID of panel, or array with keys paneltype and locationds
- * @param string $permission
- * @param null|int[] $additionalLocations
+ * @param int[] $additionalLocations
*/
- private function assertPanelPermission($panelOrUuid, $permission, $additionalLocations = null)
+ private function assertPanelPermission($panelOrUuid, string $permission, array $additionalLocations = null): void
{
if (is_array($panelOrUuid)) {
$panel = $panelOrUuid;