This file is indexed.

/usr/share/horde/ansel/lib/View/GalleryRenderer/Base.php is in php-horde-ansel 3.0.5+debian0-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
<?php
/**
 * @copyright 2008-2016 Horde LLC (http://www.horde.org)
 * @author Michael J Rubinsky <mrubinsk@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/gpl GPL
 * @package  Ansel
 */
/**
 * Ansel_View_GalleryRenderer::  Base class for all gallery renderers.
 *
 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @copyright 2008-2016 Horde LLC (http://www.horde.org)
 * @author Michael J Rubinsky <mrubinsk@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/gpl GPL
 * @package  Ansel
 */
abstract class Ansel_View_GalleryRenderer_Base
{
    /**
     * The Ansel_View_Gallery object that this Renderer belongs to.
     *
     * @var Ansel_View_Gallery
     */
    public $view;

    /**
     * The gallery id for this view's gallery
     * (Convenience instead of $this->view->gallery->id)
     *
     * @var integer
     */
    public $galleryId;

    /**
     * Gallery slug for current gallery.
     *
     * @var string
     */
    public $gallerySlug;

    /**
     * The current page we are viewing
     *
     * @var integer
     */
    public $page = 0;

    /**
     * The display mode of the current gallery.
     * 0 == Normal
     * 1 == Group by date
     *
     * @var integer
     */
    public $mode;

    /**
     * The style definition.
     *
     * @var Ansel_Style
     */
    public $style;

    /**
     * Holds number of tiles to display per page
     *
     * @var integer
     */
    public $perpage;

    /**
     * The tile number we are starting with on the current page.
     *
     * @var integer
     */
    public $pagestart;

    /**
     * The last tile number on the current page.
     *
     * @var integer
     */
    public $pageend;

    /**
     * The total number of tiles that this view contains
     *
     * @var integer
     */
    public $numTiles;

    /**
     * The Ansel_Image or Ansel_DateGallery objects that appear on the current
     * page in the current view.
     *
     * @var array of Ansel_Image or Ansel_DateGallery objects.
     */
    public $children;

    /**
     * If we are grouping by date, this holds the currently selected date parts.
     *
     * @var array containing sufficient date parts for the current depth.
     */
    public $date = array();

    /**
     * Human readable title for this view type
     *
     * @var string
     */
    public $title;

    /**
     * Constructor
     *
     * @param Ansel_View_Gallery  The view object for this renderer.
     */
    public function __construct(Ansel_View_Gallery $view = null)
    {
        $this->view = $view;
        Ansel_ActionHandler::imageActions(Horde_Util::getFormData('actionID'));
    }

    /**
     * Initialize the renderer. This *must* be called before any attempt is made
     * to display or otherwise interact with the renderer.
     *
     */
    public function init()
    {
        global $prefs, $conf, $registry, $page_output;

        $this->galleryId = $this->view->gallery->id;
        $this->gallerySlug = $this->view->gallery->get('slug');
        $this->page = $this->view->page;

        // Number perpage from prefs or config
        if ($this->view->tilesperpage) {
            $this->perpage = $this->view->tilesperpage;
        } else {
            $this->perpage = min(
                $prefs->getValue('tilesperpage'),
                $conf['thumbnail']['perpage']);
        }
        $this->pagestart = ($this->page * $this->perpage) + 1;

        // Fetch the children
        $this->fetchChildren($this->view->force_grouping);

        // Do we have an explicit style set from the API?
        // If not, use the gallery's
        if (!empty($this->view->style)) {
            $this->style = Ansel::getStyleDefinition($this->view->style);
        } else {
            $this->style = $this->view->gallery->getStyle();
        }

        // Include any widgets
        if (!empty($this->style->widgets) && !$this->view->api) {
            // Special case widgets - these are built in
            if (array_key_exists('Actions', $this->style->widgets)) {
                // Don't show action widget if no actions
                if ($registry->getAuth() ||
                    !empty($conf['report_content']['driver']) &&
                    (($conf['report_content']['allow'] == 'authenticated' &&
                      $registry->isAuthenticated()) ||
                     $conf['report_content']['allow'] == 'all')) {

                    $this->view->addWidget(Ansel_Widget::factory('Actions'));
                }
                unset($this->style->widgets['Actions']);
            }

            // Gallery widgets always receive an array of image ids for
            // the current page.
            $ids = $this->getChildImageIds();
            foreach ($this->style->widgets as $wname => $wparams) {
                $wparams = array_merge($wparams, array('images' => $ids));
                $this->view->addWidget(Ansel_Widget::factory($wname, $wparams));
            }
        }

        if (empty($this->view->api)) {
            $page_output->addScriptFile('views/common.js');
            $page_output->addScriptFile('views/gallery.js');
            $page_output->addScriptFile('popup.js', 'horde');

            $strings = array (
                'delete_conf' => _("Are you sure you want to delete the selected photos?"),
                'choose_gallery_move' => _("You must choose a gallery to move photos to."),
                'choose_images' => _("You must first choose photos.")
            );
            $urls = array(
                'image_date' => strval(Horde::url('edit_dates.php')->add(array('gallery' => $this->galleryId)))
            );
            $js = array(
                'Ansel = window.Ansel || {};',
                'Ansel.galleryview_strings = ' . Horde_Serialize::serialize($strings, Horde_Serialize::JSON),
                'Ansel.galleryview_urls = ' . Horde_Serialize::serialize($urls, Horde_Serialize::JSON),
                'Ansel.has_edit = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT) ? 1 : 0,
                'Ansel.has_delete = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE) ? 1 : 0
            );
            $page_output->addInlineScript($js, true);
        }

        // Perform any initialization of the subclasses.
        $this->_init();
    }

    /**
     * Stub to be overridden by child classes if needed.
     */
    protected function _init()
    {
    }

    /**
     * Return an initialized Horde_View instance, populated with all the values
     * common to all Gallery views.
     *
     * @return Horde_View
     */
    protected function _getHordeView()
    {
        global $registry, $injector, $prefs;

        $view = $injector->getInstance('Horde_View');
        $view->addTemplatePath(ANSEL_TEMPLATES .  '/view' . (!empty($this->view->api) ? '/api' : ''));
        $view->gallery = $this->view->gallery;
        $view->numTiles = $this->numTiles;
        $view->pergage = $this->perpage;
        $view->pagestart = $this->pagestart;
        $view->pageend = $this->pageend;
        $view->gallery_desc = $injector
            ->getInstance('Horde_Core_Factory_TextFilter')
            ->filter(
                $this->view->gallery->get('desc'),
                'text2html',
                array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
        $view->children = $this->children;
        $view->view = $this->view;
        $view->style = $this->style;

        // Don't bother if we are being called from the api
        if (empty($this->view->api)) {
            $view->option_edit = $this->view->gallery->hasPermission(
                $registry->getAuth(), Horde_Perms::EDIT);

            $view->option_select = $view->option_delete = $this->view->gallery->hasPermission(
                $registry->getAuth(), Horde_Perms::DELETE);

            $view->option_move = ($view->option_delete && $injector
                ->getInstance('Ansel_Storage')
                ->countGalleries($registry->getAuth(), array('perm' => Horde_Perms::EDIT)));

            $view->option_copy = ($view->option_edit && $injector
                ->getInstance('Ansel_Storage')
                ->countGalleries($registry->getAuth(), array('perm' => Horde_Perms::EDIT)));

            // See if we requested a show_actions change (fallback for non-js)
            if (Horde_Util::getFormData('actionID', '') == 'show_actions') {
                $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions'));
            }
        }
        $view->tilesperrow = $this->view->tilesperrow ? $this->view->tilesperrow : $prefs->getValue('tilesperrow');
        $view->cellwidth = round(100 / $view->tilesperrow);
        $this->_setupPager($view);

        return $view;
    }

    /**
     * Return the current pagerurl.
     *
     * @return Horde_Url  The url
     */
    protected function _getPagerUrl()
    {
        $date_params = Ansel::getDateParameter(array(
            'year' => !empty($this->view->year) ? $this->view->year : 0,
            'month' => !empty($this->view->month) ? $this->view->month : 0,
            'day' => !empty($this->view->day) ? $this->view->day : 0));

        if (!empty($this->view->gallery_view_url)) {
            $pagerurl = new Horde_Url(str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->gallery_view_url)));
            $pagerurl->add($date_params)->setRaw(true);
        } else {
            // Build the pager url. Add the needed variables directly to the
            // url instead of passing it as a preserved variable to the pager
            // since the logic to build the URL is already in getUrlFor()
            $pager_params =  array_merge(
                array('gallery' => $this->galleryId,
                      'view' => 'Gallery',
                      'slug' => $this->view->gallery->get('slug')),
                $date_params);
            $pagerurl = Ansel::getUrlfor('view', $pager_params, true);
        }

        return $pagerurl;
    }

    /**
     * Populate the Horde_View with the $pager object.
     *
     * @param Horde_View $view  The Horde_View object.
     */
    protected function _setupPager(Horde_View &$view)
    {
        $vars = Horde_Variables::getDefaultVariables();
        if (!empty($this->view->page)) {
            $vars->add('page', $this->view->page);
            $view->page = $this->view->page;
        } else {
            $view->page = 0;
        }
        $pagerurl = $this->_getPagerUrl();
        if (!empty($this->view->urlCallback)) {
            $callback = $this->view->urlCallback;
        } else {
            $callback = null;
        }

        $params = array(
            'num' => $this->numTiles,
            'url' => $pagerurl,
            'perpage' => $this->perpage,
            'url_callback' => $callback);
        $view->pager = new Horde_Core_Ui_Pager('page', $vars, $params);
    }

    /**
     * Default implementation for fetching children/images for this view.
     * Other view classes can override this if they need anything special.
     *
     * @param boolean $noauto  Flag to indicate if we shouldn't automatically
     *                         drill down on views that support this. E.g.,
     *                         DateMode.
     */
    public function fetchChildren($noauto)
    {
        // Total number of tiles for this gallery view
        $this->numTiles = $this->view->gallery->countGalleryChildren(Horde_Perms::SHOW, false, $noauto);

        // Children to display on this page
        $this->children = $this->view->gallery->getGalleryChildren(
            Horde_Perms::SHOW,
            $this->page * $this->perpage,
            $this->perpage,
            !empty($this->view->force_grouping));

        // The last tile number to display on the current page
        $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1);
    }

    /**
     * Return the image ids contained in the gallery.
     *
     * @return array  An array of image ids.
     */
    public function getChildImageIds()
    {
        $ids = array();
        foreach ($this->children as $child) {
            if ($child instanceof Ansel_Image) {
                $ids[] = $child->id;
            }
        }

        return $ids;
    }

    /**
     * Return the HTML for this view. Done this way so we can override this in
     * subclasses if desired.
     *
     * @return string
     */
    abstract public function html();
}