This file is indexed.

/usr/share/php/Horde/Image/Swf.php is in php-horde-image 2.5.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<?php
/**
 * Copyright 2002-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @author    Chuck Hagenbuch <chuck@horde.org>
 * @category  Horde
 * @license   http://www.horde.org/licenses/lgpl21 LGPL-2.1
 * @package   Image
 */

/**
 * This class implements the Horde_Image API for SWF, using the PHP Ming
 * extension.
 *
 * @author    Chuck Hagenbuch <chuck@horde.org>
 * @category  Horde
 * @copyright 2002-2017 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl21 LGPL-2.1
 * @package   Image
 */
class Horde_Image_Swf extends Horde_Image_Base
{
    /**
     * Capabilites of this driver.
     *
     * @var string[]
     */
    protected $_capabilities = array(
        'canvas',
        'circle',
        'dashedLine',
        'line',
        'polygon',
        'polyline',
        'rectangle',
        'roundedRectangle',
        'text',
    );

    /**
     * SWF root movie.
     *
     * @var resource
     */
    protected $_movie;

    /**
     * Constructor.
     *
     * @see Horde_Image_Base::_construct
     */
    public function __construct($params, $context = array())
    {
        parent::__construct($params, $context);

        $this->_movie = new SWFMovie();
        $this->_movie->setDimension($this->_width, $this->_height);

        $color = Horde_Image::getRGB($this->_background);
        $this->_movie->setBackground($color[0], $color[1], $color[2]);
        $this->_movie->setRate(30);
    }

    /**
     * Returns the MIME type for this image.
     *
     * @return string  The MIME type for this image.
     */
    public function getContentType()
    {
        return 'application/x-shockwave-flash';
    }

    /**
     * Displays the current image.
     */
    public function display()
    {
        $this->headers();
        $this->_movie->output();
    }

    /**
     * Returns the raw data for this image.
     *
     * @return string  The raw image data.
     */
    public function raw()
    {
        ob_start();
        $this->_movie->output();
        $data = ob_get_clean();
        return $data;
    }

    /**
     * Creates a color that can be accessed in this object.
     *
     * When a color is set, the rgba values are returned in an array.
     *
     * @param string $name  The name of the color.
     *
     * @return array  The red, green, blue, alpha values of the color.
     */
    public function allocateColor($name)
    {
        list($r, $g, $b) = Horde_Image::getRGB($name);
        return array('red' => $r, 'green' => $g, 'blue' => $b, 'alpha' => 255);
    }

    /**
     * Translates font names.
     *
     * @param string $font  A font name.
     *
     * @return string  An SWF font name.
     */
    public function getFont($font)
    {
        switch ($font) {
        case 'sans-serif':
            return '_sans';
        case 'serif':
            return '_serif';
        case 'monospace':
            return '_typewriter';
        default:
            return $font;
        }
    }

    /**
     * Draws a text string on the image in a specified location, with the
     * specified style information.
     *
     * @param string $text        The text to draw.
     * @param integer $x          The left x coordinate of the start of the
     *                            text string.
     * @param integer $y          The top y coordinate of the start of the text
     *                            string.
     * @param string $font        The font identifier you want to use for the
     *                            text.
     * @param string $color       The color that you want the text displayed in.
     * @param integer $direction  An integer that specifies the orientation of
     *                            the text.
     * @param string $fontsize    Size of the font (small, medium, large, giant)
     */
    public function text(
        $string, $x, $y, $font = 'monospace', $color = 'black', $direction = 0
    )
    {
        $color = $this->allocateColor($color);

        $text = new SWFTextField(SWFTEXTFIELD_NOEDIT);
        $text->setColor(
            $color['red'], $color['green'], $color['blue'], $color['alpha']
        );
        $text->setFont(new SWFBrowserFont($this->getFont($font)));
        $text->addString($string);

        $t = $this->_movie->add($text);
        $t->moveTo($x, $y);
        $t->rotate($direction);
    }

    /**
     * Draws a circle.
     *
     * @param integer $x      The x co-ordinate of the centre.
     * @param integer $y      The y co-ordinate of the centre.
     * @param integer $r      The radius of the circle.
     * @param string  $color  The line color of the circle.
     * @param string  $fill   The color to fill the circle.
     */
    public function circle($x, $y, $r, $color, $fill = 'none')
    {
        $s = new SWFShape();
        $color = $this->allocateColor($color);
        $s->setLine(
            1, $color['red'], $color['green'], $color['blue'], $color['alpha']
        );

        if ($fill != 'none') {
            $fillColor = $this->allocateColor($fill);
            $f = $s->addFill(
                $fillColor['red'],
                $fillColor['green'],
                $fillColor['blue'],
                $fillColor['alpha']
            );
            $s->setRightFill($f);
        }

        $a = $r * 0.414213562; // = tan(22.5 deg)
        $b = $r * 0.707106781; // = sqrt(2)/2 = sin(45 deg)

        $s->movePenTo($x + $r, $y);

        $s->drawCurveTo($x + $r, $y - $a, $x + $b, $y - $b);
        $s->drawCurveTo($x + $a, $y - $r, $x, $y - $r);
        $s->drawCurveTo($x - $a, $y - $r, $x - $b, $y - $b);
        $s->drawCurveTo($x - $r, $y - $a, $x - $r, $y);
        $s->drawCurveTo($x - $r, $y + $a, $x - $b, $y + $b);
        $s->drawCurveTo($x - $a, $y + $r, $x, $y + $r);
        $s->drawCurveTo($x + $a, $y + $r, $x + $b, $y + $b);
        $s->drawCurveTo($x + $r, $y + $a, $x + $r, $y);

        $this->_movie->add($s);
    }

    /**
     * Draws a polygon based on a set of vertices.
     *
     * @param array $vertices  An array of x and y labeled arrays
     *                         (eg. $vertices[0]['x'], $vertices[0]['y'], ...).
     * @param string $color    The color you want to draw the polygon with.
     * @param string $fill     The color to fill the polygon.
     */
    public function polygon($verts, $color, $fill = 'none')
    {
        $color = $this->allocateColor($color);

        if (!is_array($color) || !is_array($verts) || (sizeof($verts) <= 2)) {
            return;
        }

        $shape = new SWFShape();
        $shape->setLine(
            1, $color['red'], $color['green'], $color['blue'], $color['alpha']
        );

        if ($fill != 'none') {
            $fillColor = $this->allocateColor($fill);
            $f = $shape->addFill(
                $fillColor['red'],
                $fillColor['green'],
                $fillColor['blue'],
                $fillColor['alpha']
            );
            $shape->setRightFill($f);
        }

        $first_done = false;
        foreach ($verts as $value) {
            if (!$first_done) {
                $shape->movePenTo($value['x'], $value['y']);
                $first_done = true;
                $first_x = $value['x'];
                $first_y = $value['y'];
            }
            $shape->drawLineTo($value['x'], $value['y']);
        }
        $shape->drawLineTo($first_x, $first_y);

        $this->_movie->add($shape);
    }

    /**
     * Draws a rectangle.
     *
     * @param integer $x       The left x-coordinate of the rectangle.
     * @param integer $y       The top y-coordinate of the rectangle.
     * @param integer $width   The width of the rectangle.
     * @param integer $height  The height of the rectangle.
     * @param string $color    The line color of the rectangle.
     * @param string $fill     The color to fill the rectangle.
     */
    public function rectangle($x, $y, $width, $height, $color, $fill = 'none')
    {
        $verts[0] = array('x' => $x, 'y' => $y);
        $verts[1] = array('x' => $x + $width, 'y' => $y);
        $verts[2] = array('x' => $x + $width, 'y' => $y + $height);
        $verts[3] = array('x' => $x, 'y' => $y + $height);

        $this->polygon($verts, $color, $fill);
    }

    /**
     * Draws a rounded rectangle.
     *
     * @param integer $x       The left x-coordinate of the rectangle.
     * @param integer $y       The top y-coordinate of the rectangle.
     * @param integer $width   The width of the rectangle.
     * @param integer $height  The height of the rectangle.
     * @param integer $round   The width of the corner rounding.
     * @param string $color    The line color of the rectangle.
     * @param string $fill     The color to fill the rectangle.
     */
    public function roundedRectangle(
        $x, $y, $width, $height, $round, $color = 'black', $fill = 'none'
    )
    {
        if ($round <= 0) {
            // Optimize out any calls with no corner rounding.
            return $this->rectangle($x, $y, $width, $height, $color, $fill);
        }

        $s = new SWFShape();
        $color = $this->allocateColor($color);
        $s->setLine(
            1, $color['red'], $color['green'], $color['blue'], $color['alpha']
        );

        if ($fill != 'none') {
            $fillColor = $this->allocateColor($fill);
            $f = $s->addFill(
                $fillColor['red'],
                $fillColor['green'],
                $fillColor['blue'],
                $fillColor['alpha']
            );
            $s->setRightFill($f);
        }

        // Set corner points to avoid lots of redundant math.
        $x1 = $x + $round;
        $y1 = $y + $round;

        $x2 = $x + $width - $round;
        $y2 = $y + $round;

        $x3 = $x + $width - $round;
        $y3 = $y + $height - $round;

        $x4 = $x + $round;
        $y4 = $y + $height - $round;

        // Draw the upper left corner.
        $s->movePenTo($x1, $y2);
        $s->drawArc($round, 270, 360);

        // Connect the top left and right curves.
        $s->movePenTo($x1, $y);
        $s->drawLineTo($x2, $y);

        // Draw the upper right corner.
        $s->movePenTo($x2, $y2);
        $s->drawArc($round, 0, 90);

        // Connect the top right and lower right curves.
        $s->movePenTo($x + $width, $y2);
        $s->drawLineTo($x + $width, $y3);

        // Draw the lower right corner.
        $s->movePenTo($x3, $y3);
        $s->drawArc($round, 90, 180);

        // Connect the bottom right and bottom left curves.
        $s->movePenTo($x3, $y + $height);
        $s->drawLineTo($x4, $y + $height);

        // Draw the lower left corner.
        $s->movePenTo($x4, $y4);
        $s->drawArc($round, 180, 270);

        // Connect the bottom left and top left curves.
        $s->movePenTo($x, $y4);
        $s->drawLineTo($x, $y1);

        $this->_movie->add($s);
    }

    /**
     * Draws a line.
     *
     * @param integer $x0    The x coordinate of the start.
     * @param integer $y0    The y coordinate of the start.
     * @param integer $x1    The x coordinate of the end.
     * @param integer $y1    The y coordinate of the end.
     * @param string $color  The line color.
     * @param string $width  The width of the line.
     */
    public function line($x1, $y1, $x2, $y2, $color = 'black', $width = 1)
    {
        $color = $this->allocateColor($color);
        if (!is_array($color)) {
            return;
        }

        $shape = new SWFShape();
        $shape->setLine(
            $width,
            $color['red'],
            $color['green'],
            $color['blue'],
            $color['alpha']
        );
        $shape->movePenTo($x1, $y1);
        $shape->drawLineTo($x2, $y2);

        $this->_movie->add($shape);
    }

    /**
     * Draws a dashed line.
     *
     * @param integer $x0           The x co-ordinate of the start.
     * @param integer $y0           The y co-ordinate of the start.
     * @param integer $x1           The x co-ordinate of the end.
     * @param integer $y1           The y co-ordinate of the end.
     * @param string $color         The line color.
     * @param string $width         The width of the line.
     * @param integer $dash_length  The length of a dash on the dashed line.
     * @param integer $dash_space   The length of a space in the dashed line.
     */
    public function dashedLine(
        $x0, $y0, $x1, $y1, $color = 'black', $width = 1, $dash_length = 2,
        $dash_space = 2
    )
    {
        // Get the length of the line in pixels.
        $line_length = max(
            ceil(sqrt(pow(($x1 - $x0), 2) + pow(($y1 - $y0), 2))),
            2
        );

        $cosTheta = ($x1 - $x0) / $line_length;
        $sinTheta = ($y1 - $y0) / $line_length;
        $lastx = $x0;
        $lasty = $y0;

        // Draw the dashed line.
        for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
            $x = ($dash_length * $cosTheta) + $lastx;
            $y = ($dash_length * $sinTheta) + $lasty;

            $this->line($lastx, $lasty, $x, $y, $color);

            $lastx = $x + ($dash_space * $cosTheta);
            $lasty = $y + ($dash_space * $sinTheta);
        }
    }

    /**
     * Draws a polyline (a non-closed, non-filled polygon) based on a set of
     * vertices.
     *
     * @param array $vertices  An array of x and y labeled arrays
     *                         (eg. $vertices[0]['x'], $vertices[0]['y'], ...).
     * @param string $color    The color you want to draw the line with.
     * @param string $width    The width of the line.
     */
    public function polyline($verts, $color, $width = 1)
    {
        $color = $this->allocateColor($color);

        $shape = new SWFShape();
        $shape->setLine(
            $width,
            $color['red'],
            $color['green'],
            $color['blue'],
            $color['alpha']
        );

        $first_done = false;
        foreach ($verts as $value) {
            if (!$first_done) {
                $shape->movePenTo($value['x'], $value['y']);
                $first_done = true;
            }
            $shape->drawLineTo($value['x'], $value['y']);
        }

        $this->_movie->add($shape);
    }

    /**
     * Draws an arc.
     *
     * @param integer $x      The x co-ordinate of the centre.
     * @param integer $y      The y co-ordinate of the centre.
     * @param integer $r      The radius of the arc.
     * @param integer $start  The start angle of the arc.
     * @param integer $end    The end angle of the arc.
     * @param string $color   The line color of the arc.
     * @param string $fill    The fill color of the arc.
     */
    public function arc(
        $x, $y, $r, $start, $end, $color = 'black', $fill = 'none'
    )
    {
        $s = new SWFShape();
        $color = $this->allocateColor($color);
        $s->setLine(
            1, $color['red'], $color['green'], $color['blue'], $color['alpha']
        );

        if ($fill != 'none') {
            $fillColor = $this->allocateColor($fill);
            $s->setRightFill(
                $fillColor['red'],
                $fillColor['green'],
                $fillColor['blue'],
                $fillColor['alpha']
            );
        }

        $pts = Horde_Image::arcPoints($r, $start, $end);
        $s->movePenTo($x, $y);
        $s->drawArc($r, $start + 90, $end + 90);
        $s->movePenTo($x, $y);
        $s->drawLineTo(round($pts['x1']) + $x, round($pts['y1']) + $y);
        $s->movePenTo($x, $y);
        $s->drawLineTo(round($pts['x2']) + $x, round($pts['y2']) + $y);

        $this->_movie->add($s);
    }

    /**
     * Draws a rectangle filled with a gradient.
     *
     * @param integer $x       The left x-coordinate of the rectangle.
     * @param integer $y       The top y-coordinate of the rectangle.
     * @param integer $width   The width of the rectangle.
     * @param integer $height  The height of the rectangle.
     * @param string $color    The outline color of the rectangle.
     * @param string $fill1    The name of the start color for the gradient.
     * @param string $fill2    The name of the end color for the gradient.
     */
    public function gradientRectangle(
        $x, $y, $width, $height, $color = 'black',
        $fill1 = 'black', $fill2 = 'white'
    )
    {
        $s = new SWFShape();

        if ($color != 'none') {
            $color = $this->allocateColor($color);
            $s->setLine(
                1,
                $color['red'],
                $color['green'],
                $color['blue'],
                $color['alpha']
            );
        }

        $fill1 = $this->allocateColor($fill1);
        $fill2 = $this->allocateColor($fill2);
        $gradient = new SWFGradient();
        $gradient->addEntry(
            0.0,
            $fill1['red'],
            $fill1['green'],
            $fill1['blue'],
            $fill1['alpha']
        );
        $gradient->addEntry(
            1.0,
            $fill2['red'],
            $fill2['green'],
            $fill2['blue'],
            $fill2['alpha']
        );

        $f = $s->addFill($gradient, SWFFILL_LINEAR_GRADIENT);
        $f->scaleTo($width / $this->_width);
        $f->moveTo($x, $y);
        $s->setRightFill($f);

        $verts[0] = array('x' => $x, 'y' => $y);
        $verts[1] = array('x' => $x + $width, 'y' => $y);
        $verts[2] = array('x' => $x + $width, 'y' => $y + $height);
        $verts[3] = array('x' => $x, 'y' => $y + $height);

        $first_done = false;
        foreach ($verts as $vert) {
            if (!$first_done) {
                $s->movePenTo($vert['x'], $vert['y']);
                $first_done = true;
                $first_x = $vert['x'];
                $first_y = $vert['y'];
            }
            $s->drawLineTo($vert['x'], $vert['y']);
        }
        $s->drawLineTo($first_x, $first_y);

        $this->_movie->add($s);
    }
}