1<?php
2/**
3 * Show bookmarks.
4 *
5 * Copyright 2004-2017 Horde LLC (http://www.horde.org/)
6 *
7 * See the enclosed file LICENSE for license information (BSD). If you
8 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
9 *
10 * @author  Joel Vandal <joel@scopserv.com>
11 */
12class Trean_Block_Bookmarks extends Horde_Core_Block
13{
14    /**
15     */
16    public function __construct($app, $params = array())
17    {
18        parent::__construct($app, $params);
19        $this->_name = _("Bookmarks");
20    }
21
22    /**
23     */
24    protected  function _params()
25    {
26        return array(
27            'bookmarks' => array(
28                'name' => _("Sort by"),
29                'type' => 'enum',
30                'default' => 'title',
31                'values' => array(
32                    'title' => _("Title"),
33                    'most_clicked' => _("Most Clicked")
34                )
35            ),
36            'rows' => array(
37                'name' => _("Display Rows"),
38                'type' => 'enum',
39                'default' => '10',
40                'values' => array(
41                    '10' => _("10 rows"),
42                    '15' => _("15 rows"),
43                    '25' => _("25 rows")
44                )
45            ),
46            'template' => array(
47                'name' => _("Template"),
48                'type' => 'enum',
49                'default' => '1line',
50                'values' => array(
51                    'standard' => _("3 Line"),
52                    '2line' => _("2 Line"),
53                    '1line' => _("1 Line")
54                )
55            )
56        );
57    }
58
59    /**
60     */
61    protected function _title()
62    {
63        global $registry;
64        return Horde::url($registry->getInitialPage(), true)->link() . _("Bookmarks") . '</a>';
65    }
66
67    /**
68     */
69    protected function _content()
70    {
71        $template = TREAN_TEMPLATES . '/block/' . basename($this->_params['template']) . '.inc';
72
73        $sortby = 'title';
74        $sortdir = 0;
75        switch ($this->_params['bookmarks']) {
76        case 'most_clicked':
77            $sortby = 'clicks';
78            $sortdir = 1;
79            break;
80        }
81
82        $html = '';
83        $bookmarks = $GLOBALS['trean_gateway']->listBookmarks($sortby, $sortdir, 0, $this->_params['rows']);
84        foreach ($bookmarks as $bookmark) {
85            ob_start();
86            require $template;
87            $html .= '<div class="linedRow">' . ob_get_clean() . '</div>';
88        }
89
90        if (!$bookmarks) {
91            return '<p><em>' . _("No bookmarks to display") . '</em></p>';
92        }
93
94        return $html;
95    }
96}
97