1<?php
2/**
3 * Copyright 2004-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL-2). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl.
7 *
8 * @author   Chuck Hagenbuch <chuck@horde.org>
9 * @category Horde
10 * @license  http://www.horde.org/licenses/lgpl LGPL-2
11 * @package  Horde
12 */
13
14require_once __DIR__ . '/../../lib/Application.php';
15Horde_Registry::appInit('horde');
16
17$vars = $injector->getInstance('Horde_Variables');
18
19$path = $vars->path;
20if (empty($path)) {
21    $list = array();
22    $apps = $registry->listApps(null, false, Horde_Perms::READ);
23    foreach ($apps as $app) {
24        if ($registry->hasMethod('browse', $app)) {
25            $list[$app] = array('name' => $registry->get('name', $app),
26                                'icon' => $registry->get('icon', $app),
27                                'browseable' => true);
28        }
29    }
30} else {
31    $pieces = explode('/', $path);
32    $list = $registry->callByPackage($pieces[0], 'browse', array('path' => $path));
33}
34
35if (!count($list)) {
36    $notification->push(_("Nothing to browse, go back."), 'horde.warning');
37}
38
39$rows = array();
40foreach ($list as $path => $values) {
41    $row = array();
42
43    // Set the icon.
44    if (!empty($values['icon'])) {
45        $row['icon'] = Horde_Themes_Image::tag($values['icon'], array(
46            'alt' => $values['name']
47        ));
48    } elseif (!empty($values['browseable'])) {
49        $row['icon'] = Horde_Themes_Image::tag('tree/folder.png');
50    } else {
51        $row['icon'] = Horde_Themes_Image::tag('tree/leaf.png');
52    }
53
54    // Set the name/link.
55    $name = $values['name'] ?: basename($path);
56    if (!empty($values['browseable'])) {
57        $url = Horde::url('services/obrowser', false, array('app' => 'horde'))->add('path', $path);
58        $row['name'] = $url->link() . htmlspecialchars($name) . '</a>';
59    } else {
60        $js = "return chooseObject('" . addslashes($path) . "');";
61        $row['name'] = Horde::link('#', sprintf(_("Choose %s"), $name), '', '', $js) . htmlspecialchars($name) . '</a>';
62    }
63
64    $rows[] = $row;
65}
66
67$view = new Horde_View(array(
68    'templatePath' => HORDE_TEMPLATES . '/services'
69));
70$view->addHelper('Horde_Core_View_Helper_Image');
71
72$view->rows = $rows;
73
74$page_output->addScriptFile('obrowser.js', 'horde');
75$page_output->addScriptFile('stripe.js', 'horde');
76$page_output->topbar = $page_output->sidebar = false;
77
78$page_output->header();
79$notification->notify(array('listeners' => 'status'));
80echo $view->render('obrowser');
81$page_output->footer();
82