1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Trean_Block_Bookmarks extends Horde_Core_Block
13: {
14: 15:
16: private $_folder = null;
17:
18: 19:
20: public function __construct($app, $params = array())
21: {
22: parent::__construct($app, $params);
23:
24: $this->_name = _("Bookmarks");
25: }
26:
27: 28:
29: protected function _params()
30: {
31: require_once dirname(__FILE__) . '/../base.php';
32:
33:
34: $folders = Trean::listFolders(Horde_Perms::READ);
35: $default = null;
36: if ($folders instanceof PEAR_Error) {
37: $GLOBALS['notification']->push(sprintf(_("An error occured listing folders: %s"), $folders->getMessage()), 'horde.error');
38: } else {
39: foreach ($folders as $key => $folder) {
40: if (is_null($default)) {
41: $default = $folder->getId();
42: }
43: $values[$folder->getId()] = $folder->get('name');
44: }
45: }
46:
47: return array(
48: 'folder' => array(
49: 'name' => _("Folder"),
50: 'type' => 'enum',
51: 'default' => $default,
52: 'values' => $values
53: ),
54: 'bookmarks' => array(
55: 'name' => _("Sort by"),
56: 'type' => 'enum',
57: 'default' => 'title',
58: 'values' => array(
59: 'title' => _("Title"),
60: 'highest_rated' => _("Highest Rated"),
61: 'most_clicked' => _("Most Clicked")
62: )
63: ),
64: 'rows' => array(
65: 'name' => _("Display Rows"),
66: 'type' => 'enum',
67: 'default' => '10',
68: 'values' => array(
69: '10' => _("10 rows"),
70: '15' => _("15 rows"),
71: '25' => _("25 rows")
72: )
73: ),
74: 'template' => array(
75: 'name' => _("Template"),
76: 'type' => 'enum',
77: 'default' => '1line',
78: 'values' => array(
79: 'standard' => _("3 Line"),
80: '2line' => _("2 Line"),
81: '1line' => _("1 Line")
82: )
83: )
84: );
85: }
86:
87: 88:
89: protected function _title()
90: {
91: global $registry;
92:
93: $folder = $this->_getFolder();
94: if ($folder instanceof PEAR_Error) {
95: $name = $registry->get('name');
96: } else {
97: $name = $folder->get('name');
98: if (!$name) {
99: $name = $this->getName();
100: }
101: }
102:
103: return Horde::url($registry->getInitialPage(), true)->link() . $name . '</a>';
104: }
105:
106: 107:
108: protected function _content()
109: {
110: require_once dirname(__FILE__) . '/../base.php';
111: require_once TREAN_TEMPLATES . '/star_rating_helper.php';
112:
113: $template = TREAN_TEMPLATES . '/block/' . $this->_params['template'] . '.inc';
114:
115: $folder = $this->_getFolder();
116: if ($folder instanceof PEAR_Error) {
117: return $folder;
118: }
119:
120: $sortby = 'title';
121: $sortdir = 0;
122: switch ($this->_params['bookmarks']) {
123: case 'highest_rated':
124: $sortby = 'rating';
125: $sortdir = 1;
126: break;
127:
128: case 'most_clicked':
129: $sortby = 'clicks';
130: $sortdir = 1;
131: break;
132: }
133:
134: $html = '';
135: $bookmarks = $folder->listBookmarks($sortby, $sortdir, 0, $this->_params['rows']);
136: foreach ($bookmarks as $bookmark) {
137: ob_start();
138: require $template;
139: $html .= '<div class="linedRow">' . ob_get_clean() . '</div>';
140: }
141:
142: if (!$bookmarks) {
143: return '<p><em>' . _("No bookmarks to display") . '</em></p>';
144: }
145:
146: return $html;
147: }
148:
149: 150:
151: private function _getFolder()
152: {
153: require_once dirname(__FILE__) . '/../base.php';
154:
155: if ($this->_folder == null) {
156: $this->_folder = $GLOBALS['trean_shares']->getFolder($this->_params['folder']);
157: }
158:
159: return $this->_folder;
160: }
161:
162: }
163: