summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/configmodule/screensaver.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule/screensaver.inc.php')
-rw-r--r--modules-available/sysconfig/inc/configmodule/screensaver.inc.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/modules-available/sysconfig/inc/configmodule/screensaver.inc.php b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php
new file mode 100644
index 00000000..1797331c
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php
@@ -0,0 +1,102 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_Screensaver::MODID, // ID
+ Dictionary::translateFileModule('sysconfig', 'config-module', 'screensaver_title'), // Title
+ Dictionary::translateFileModule('sysconfig', 'config-module', 'screensaver_description'), // Description
+ Dictionary::translateFileModule('sysconfig', 'config-module', 'group_screensaver'), // Group
+ true, // Only one per config?
+ 700 // Sort order
+);
+
+class ConfigModule_Screensaver extends ConfigModule
+{
+ const MODID = 'Screensaver';
+ const VERSION = 1;
+
+ protected function generateInternal(string $tgz, ?string $parent)
+ {
+ /* Validate if all data are available */
+ if (!$this->validateConfig())
+ return false;
+
+ /* Give the Taskmanager the job and create the tgz */
+ $taskId = 'xscreensaver' . mt_rand() . '-' . microtime(true);
+
+ return Taskmanager::submit('MakeTarball', array(
+ 'id' => $taskId,
+ 'files' => $this->getFileArray(),
+ 'destination' => $tgz,
+ ), false);
+ }
+
+ protected function moduleVersion(): int
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig(): bool
+ {
+ return isset($this->moduleData['texts']['text-no-timeout'])
+ && isset($this->moduleData['texts']['text-idle-kill'])
+ && isset($this->moduleData['texts']['text-shutdown'])
+ && isset($this->moduleData['qss']);
+ }
+
+ public function setData(string $key, $value): bool
+ {
+ switch ($key) {
+ case 'qss':
+ case 'texts':
+ case 'messages':
+ break;
+ default:
+ return false;
+ }
+ $this->moduleData[$key] = $value;
+ return true;
+ }
+
+ public function allowDownload(): bool
+ {
+ return false;
+ }
+
+ /**
+ * Creates a map with filepath => file content
+ */
+ private function getFileArray(): array
+ {
+ $files = array(
+ '/opt/openslx/xscreensaver/style.qss' => $this->moduleData['qss'],
+ '/opt/openslx/xscreensaver/text-idle-kill' => $this->wrapHtmlTags('text-idle-kill'),
+ '/opt/openslx/xscreensaver/text-no-timeout' => $this->wrapHtmlTags('text-no-timeout'),
+ '/opt/openslx/xscreensaver/text-shutdown' => $this->wrapHtmlTags('text-shutdown'),
+ );
+
+ /* Create the message.ini from the messages array */
+ $messages = '';
+ foreach ($this->moduleData['messages'] as $category => $array) {
+ $messages .= '[' . $category . ']' . "\n";
+ foreach ($array as $key => $message) {
+ $messages .= $key . '="' . str_replace(['\\', '"', "\n", "\r"], '-', $message) . '"' . "\n";
+ }
+ }
+ $files['/opt/openslx/xscreensaver/messages.ini'] = $messages;
+
+ /* Add locked files if there are any */
+ if (isset($this->moduleData['texts']['text-idle-kill-locked']))
+ $files['/opt/openslx/xscreensaver/text-idle-kill-locked'] = $this->wrapHtmlTags('text-idle-kill-locked');
+ if (isset($this->moduleData['texts']['text-no-timeout-locked']))
+ $files['/opt/openslx/xscreensaver/text-no-timeout-locked'] = $this->wrapHtmlTags('text-no-timeout-locked');
+ if (isset($this->moduleData['texts']['text-shutdown-locked']))
+ $files['/opt/openslx/xscreensaver/text-shutdown-locked'] = $this->wrapHtmlTags('text-shutdown-locked');
+
+ return $files;
+ }
+
+ private function wrapHtmlTags(string $text_name): string
+ {
+ return '<html><body>' . $this->moduleData['texts'][$text_name] . '</body></html>';
+ }
+}