~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Widget/WebPage.php

  • Committer: Dan Garner
  • Date: 2015-08-11 09:29:02 UTC
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: git-v1:a86fb4369b7395c13367577d23b14c0ab4528c1a
Transitions fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
use InvalidArgumentException;
24
24
use Respect\Validation\Validator as v;
 
25
use Xibo\Factory\MediaFactory;
 
26
use Xibo\Helper\Sanitize;
25
27
 
26
 
/**
27
 
 * Class WebPage
28
 
 * @package Xibo\Widget
29
 
 */
30
 
class WebPage extends ModuleWidget
 
28
class WebPage extends Module
31
29
{
32
30
    /**
33
31
     * Install Files
34
32
     */
35
33
    public function installFiles()
36
34
    {
37
 
        $this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/jquery-1.11.1.min.js')->save();
38
 
        $this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/xibo-layout-scaler.js')->save();
39
 
        $this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/xibo-webpage-render.js')->save();
 
35
        MediaFactory::createModuleFile('modules/vendor/jquery-1.11.1.min.js')->save();
 
36
        MediaFactory::createModuleFile('modules/xibo-layout-scaler.js')->save();
 
37
        MediaFactory::createModuleFile('modules/xibo-webpage-render.js')->save();
40
38
    }
41
39
 
42
40
    public function validate()
43
41
    {
44
 
        if (!v::url()->notEmpty()->validate(urldecode($this->getOption('uri'))))
 
42
        if (!v::url()->notEmpty()->validate($this->getOption('uri')))
45
43
            throw new InvalidArgumentException(__('Please enter a link'));
46
44
 
47
 
        if ($this->getUseDuration() == 1 && $this->getDuration() == 0)
 
45
        if ($this->getDuration() == 0)
48
46
            throw new InvalidArgumentException(__('You must enter a duration.'));
49
 
 
50
 
        if ($this->getOption('modeid') == null)
51
 
            throw new InvalidArgumentException(__('You must select a mode.'));
52
47
    }
53
48
 
54
49
    /**
55
 
     * Adds a Webpage Widget
56
 
     * @SWG\Post(
57
 
     *  path="/playlist/widget/webpage/{playlistId}",
58
 
     *  operationId="WidgetWebpageAdd",
59
 
     *  tags={"widget"},
60
 
     *  summary="Add a Web page Widget",
61
 
     *  description="Add a new Web page Widget to the specified playlist",
62
 
     *  @SWG\Parameter(
63
 
     *      name="playlistId",
64
 
     *      in="path",
65
 
     *      description="The playlist ID to add a Web page to",
66
 
     *      type="integer",
67
 
     *      required=true
68
 
     *   ),
69
 
     *  @SWG\Parameter(
70
 
     *      name="name",
71
 
     *      in="formData",
72
 
     *      description="Optional Widget Name",
73
 
     *      type="string",
74
 
     *      required=false
75
 
     *  ),
76
 
     *  @SWG\Parameter(
77
 
     *      name="duration",
78
 
     *      in="formData",
79
 
     *      description="The Web page Duration",
80
 
     *      type="integer",
81
 
     *      required=false
82
 
     *  ),
83
 
     *  @SWG\Parameter(
84
 
     *      name="useDuration",
85
 
     *      in="formData",
86
 
     *      description="(0, 1) Select 1 only if you will provide duration parameter as well",
87
 
     *      type="integer",
88
 
     *      required=false
89
 
     *  ),
90
 
     *  @SWG\Parameter(
91
 
     *      name="transparency",
92
 
     *      in="formData",
93
 
     *      description=" flag (0,1) should the HTML be shown with a transparent background?",
94
 
     *      type="integer",
95
 
     *      required=false
96
 
     *   ),
97
 
     *  @SWG\Parameter(
98
 
     *      name="uri",
99
 
     *      in="formData",
100
 
     *      description=" string containing the location (URL) of the web page",
101
 
     *      type="string",
102
 
     *      required=true
103
 
     *   ),
104
 
     *  @SWG\Parameter(
105
 
     *      name="scaling",
106
 
     *      in="formData",
107
 
     *      description="For Manual position the percentage to scale the Web page (0-100)",
108
 
     *      type="integer",
109
 
     *      required=false
110
 
     *   ),
111
 
     *  @SWG\Parameter(
112
 
     *      name="offsetLeft",
113
 
     *      in="formData",
114
 
     *      description="For Manual position, the starting point from the left in pixels",
115
 
     *      type="integer",
116
 
     *      required=false
117
 
     *   ),
118
 
     *  @SWG\Parameter(
119
 
     *      name="offsetTop",
120
 
     *      in="formData",
121
 
     *      description="For Manual position, the starting point from the Top in pixels",
122
 
     *      type="integer",
123
 
     *      required=false
124
 
     *   ),
125
 
     *  @SWG\Parameter(
126
 
     *      name="pageWidth",
127
 
     *      in="formData",
128
 
     *      description="For Manual Position and Best Fit, The width of the page - if empty it will use region width",
129
 
     *      type="integer",
130
 
     *      required=false
131
 
     *   ),
132
 
     *  @SWG\Parameter(
133
 
     *      name="pageHeight",
134
 
     *      in="formData",
135
 
     *      description="For Manual Position and Best Fit, The height of the page - if empty it will use region height",
136
 
     *      type="integer",
137
 
     *      required=false
138
 
     *   ),
139
 
     *  @SWG\Parameter(
140
 
     *      name="modeId",
141
 
     *      in="formData",
142
 
     *      description="The mode option for Web page, 1- Open Natively, 2- Manual Position, 3- Best Ft",
143
 
     *      type="integer",
144
 
     *      required=true
145
 
     *   ),
146
 
     *  @SWG\Response(
147
 
     *      response=201,
148
 
     *      description="successful operation",
149
 
     *      @SWG\Schema(ref="#/definitions/Widget"),
150
 
     *      @SWG\Header(
151
 
     *          header="Location",
152
 
     *          description="Location of the new widget",
153
 
     *          type="string"
154
 
     *      )
155
 
     *  )
156
 
     * )
 
50
     * Add Media
157
51
     */
158
52
    public function add()
159
53
    {
160
54
        $this->setOption('xmds', true);
161
 
        $this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
162
 
        $this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
163
 
        $this->setOption('name', $this->getSanitizer()->getString('name'));
164
 
        $this->setOption('transparency', $this->getSanitizer()->getCheckbox('transparency'));
165
 
        $this->setOption('uri', urlencode($this->getSanitizer()->getString('uri')));
166
 
        $this->setOption('scaling', $this->getSanitizer()->getInt('scaling'));
167
 
        $this->setOption('offsetLeft', $this->getSanitizer()->getInt('offsetLeft'));
168
 
        $this->setOption('offsetTop', $this->getSanitizer()->getInt('offsetTop'));
169
 
        $this->setOption('pageWidth', $this->getSanitizer()->getInt('pageWidth'));
170
 
        $this->setOption('pageHeight', $this->getSanitizer()->getInt('pageHeight'));
171
 
        $this->setOption('modeid', $this->getSanitizer()->getInt('modeId'));
 
55
        $this->setDuration(Sanitize::getInt('duration'));
 
56
        $this->setOption('name', Sanitize::getString('name'));
 
57
        $this->setOption('transparency', Sanitize::getCheckbox('transparency'));
 
58
        $this->setOption('uri', Sanitize::getString('uri'));
 
59
        $this->setOption('scaling', Sanitize::getInt('scaling'));
 
60
        $this->setOption('offsetLeft', Sanitize::getInt('offsetLeft'));
 
61
        $this->setOption('offsetTop', Sanitize::getInt('offsetTop'));
 
62
        $this->setOption('pageWidth', Sanitize::getInt('pageWidth'));
 
63
        $this->setOption('pageHeight', Sanitize::getInt('pageHeight'));
 
64
        $this->setOption('modeid', Sanitize::getInt('modeId'));
172
65
 
173
66
        // Save the widget
174
67
        $this->validate();
175
68
        $this->saveWidget();
176
69
    }
177
 
    
 
70
 
178
71
    /**
179
 
     * Edit a Webpage Widget
 
72
     * Edit Media
180
73
     */
181
74
    public function edit()
182
75
    {
183
76
        $this->setOption('xmds', true);
184
 
        $this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
185
 
        $this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
186
 
        $this->setOption('name', $this->getSanitizer()->getString('name'));
187
 
        $this->setOption('transparency', $this->getSanitizer()->getCheckbox('transparency'));
188
 
        $this->setOption('uri', urlencode($this->getSanitizer()->getString('uri')));
189
 
        $this->setOption('scaling', $this->getSanitizer()->getInt('scaling'));
190
 
        $this->setOption('offsetLeft', $this->getSanitizer()->getInt('offsetLeft'));
191
 
        $this->setOption('offsetTop', $this->getSanitizer()->getInt('offsetTop'));
192
 
        $this->setOption('pageWidth', $this->getSanitizer()->getInt('pageWidth'));
193
 
        $this->setOption('pageHeight', $this->getSanitizer()->getInt('pageHeight'));
194
 
        $this->setOption('modeid', $this->getSanitizer()->getInt('modeId'));
 
77
        $this->setDuration(Sanitize::getInt('duration'));
 
78
        $this->setOption('name', Sanitize::getString('name'));
 
79
        $this->setOption('transparency', Sanitize::getCheckbox('transparency'));
 
80
        $this->setOption('uri', Sanitize::getString('uri'));
 
81
        $this->setOption('scaling', Sanitize::getInt('scaling'));
 
82
        $this->setOption('offsetLeft', Sanitize::getInt('offsetLeft'));
 
83
        $this->setOption('offsetTop', Sanitize::getInt('offsetTop'));
 
84
        $this->setOption('pageWidth', Sanitize::getInt('pageWidth'));
 
85
        $this->setOption('pageHeight', Sanitize::getInt('pageHeight'));
 
86
        $this->setOption('modeid', Sanitize::getInt('modeId'));
195
87
 
196
88
        // Save the widget
197
89
        $this->validate();
225
117
        $data = [];
226
118
 
227
119
        // Replace the View Port Width?
228
 
        $isPreview = ($this->getSanitizer()->getCheckbox('preview') == 1);
 
120
        $isPreview = (Sanitize::getCheckbox('preview') == 1);
229
121
 
230
122
        // Replace the View Port Width?
231
123
        $data['viewPortWidth'] = ($isPreview) ? $this->region->width : '[[ViewPortWidth]]';
232
124
 
233
125
        // Get some parameters
234
 
        $width = $this->getSanitizer()->getDouble('width', 0);
235
 
        $height = $this->getSanitizer()->getDouble('height', 0);
 
126
        $width = Sanitize::getDouble('width', 0);
 
127
        $height = Sanitize::getDouble('height', 0);
236
128
 
237
129
        // Work out the url
238
130
        $url = urldecode($this->getOption('uri'));
253
145
            'offsetTop' => intval($this->getOption('offsetTop', 0)),
254
146
            'offsetLeft' => intval($this->getOption('offsetLeft', 0)),
255
147
            'scale' => ($this->getOption('scaling', 100) / 100),
256
 
            'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0)
 
148
            'scaleOverride' => Sanitize::getDouble('scale_override', 0)
257
149
        );
258
150
 
259
151
        // Head Content
282
174
        return $this->renderTemplate($data);
283
175
    }
284
176
 
285
 
    /** @inheritdoc */
 
177
    public function getName()
 
178
    {
 
179
        return $this->getOption('name');
 
180
    }
 
181
 
286
182
    public function IsValid()
287
183
    {
288
184
        // Can't be sure because the client does the rendering