21
21
namespace Xibo\Widget;
23
23
use InvalidArgumentException;
24
use Xibo\Helper\Sanitize;
25
class ShellCommand extends ModuleWidget
26
class ShellCommand extends Module
27
28
public function validate()
29
if ($this->getOption('windowsCommand') == '' && $this->getOption('linuxCommand') == '' && $this->getOption('commandCode') == '')
30
if ($this->getOption('windowsCommand') == '' && $this->getOption('linuxCommand') == '')
30
31
throw new InvalidArgumentException(__('You must enter a command'));
34
* Adds a Shell Command Widget
36
* path="/playlist/widget/shellCommand/{playlistId}",
37
* operationId="WidgetShellCommandAdd",
39
* summary="Add a Shell Command Widget",
40
* description="Add a new Shell Command Widget to the specified playlist",
44
* description="The playlist ID to add a Widget to",
51
* description="Optional Widget Name",
58
* description="The Widget Duration",
65
* description="(0, 1) Select 1 only if you will provide duration parameter as well",
70
* name="windowsCommand",
72
* description="Enter a Windows command line compatible command",
77
* name="linuxCommand",
79
* description="Enter a Android / Linux command line compatible command",
84
* name="launchThroughCmd",
86
* description="flag (0,1) Windows only, Should the player launch this command through the windows command line (cmd.exe)? This is useful for batch files, if you try to terminate this command only the command line will be terminated",
91
* name="terminateCommand",
93
* description="flag (0,1) Should the player forcefully terminate the command after the duration specified, 0 to let the command terminate naturally",
100
* description="flag (0,1) Windows only, should the player use taskkill to terminate commands",
105
* name="commandCode",
107
* description="Enter a reference code for exiting command in CMS",
113
* description="successful operation",
114
* @SWG\Schema(ref="#/definitions/Widget"),
117
* description="Location of the new widget",
123
37
public function add()
125
39
// Any Options (we need to encode shell commands, as they sit on the options rather than the raw
126
$this->setOption('name', $this->getSanitizer()->getString('name'));
127
$this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
128
$this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
131
$windows = $this->getSanitizer()->getString('windowsCommand');
132
$linux = $this->getSanitizer()->getString('linuxCommand');
134
$this->setOption('launchThroughCmd', $this->getSanitizer()->getCheckbox('launchThroughCmd'));
135
$this->setOption('terminateCommand', $this->getSanitizer()->getCheckbox('terminateCommand'));
136
$this->setOption('useTaskkill', $this->getSanitizer()->getCheckbox('useTaskkill'));
137
$this->setOption('commandCode', $this->getSanitizer()->getString('commandCode'));
138
$this->setOption('windowsCommand', urlencode($windows));
139
$this->setOption('linuxCommand', urlencode($linux));
40
$this->setDuration(1);
41
$this->SetOption('windowsCommand', urlencode(Sanitize::getString('windowsCommand')));
42
$this->SetOption('linuxCommand', urlencode(Sanitize::getString('linuxCommand')));
141
44
// Save the widget
142
45
$this->validate();
149
52
public function edit()
151
54
// Any Options (we need to encode shell commands, as they sit on the options rather than the raw
152
$this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
153
$this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
154
$this->setOption('name', $this->getSanitizer()->getString('name'));
157
$windows = $this->getSanitizer()->getString('windowsCommand');
158
$linux = $this->getSanitizer()->getString('linuxCommand');
160
$this->setOption('launchThroughCmd', $this->getSanitizer()->getCheckbox('launchThroughCmd'));
161
$this->setOption('terminateCommand', $this->getSanitizer()->getCheckbox('terminateCommand'));
162
$this->setOption('useTaskkill', $this->getSanitizer()->getCheckbox('useTaskkill'));
163
$this->setOption('commandCode', $this->getSanitizer()->getString('commandCode'));
164
$this->setOption('windowsCommand', urlencode($windows));
165
$this->setOption('linuxCommand', urlencode($linux));
55
$this->setDuration(1);
56
$this->SetOption('windowsCommand', urlencode(Sanitize::getString('windowsCommand')));
57
$this->SetOption('linuxCommand', urlencode(Sanitize::getString('linuxCommand')));
167
59
// Save the widget
168
60
$this->validate();
174
66
if ($this->module->previewEnabled == 0)
175
67
return parent::Preview($width, $height);
177
$windows = $this->getOption('windowsCommand');
178
$linux = $this->getOption('linuxCommand');
180
if ($windows == '' && $linux == '') {
181
return __('Stored Command: %s', $this->getOption('commandCode'));
185
$preview = '<p>' . __('Windows Command') . ': ' . urldecode($windows) . '</p>';
186
$preview .= '<p>' . __('Linux Command') . ': ' . urldecode($linux) . '</p>';
69
$msgWindows = __('Windows Command');
70
$msgLinux = __('Linux Command');
73
$preview .= '<p>' . $msgWindows . ': ' . urldecode($this->GetOption('windowsCommand')) . '</p>';
74
$preview .= '<p>' . $msgLinux . ': ' . urldecode($this->GetOption('linuxCommand')) . '</p>';
192
79
public function hoverPreview()