/
Application.php
129 lines (114 loc) · 3.85 KB
/
Application.php
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
<?php
/**
* Trean application API
*
* Copyright 2002-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsdl.php.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
*/
/* Determine the base directories. */
if (!defined('TREAN_BASE')) {
define('TREAN_BASE', realpath(__DIR__ . '/..'));
}
if (!defined('HORDE_BASE')) {
/* If Horde does not live directly under the app directory, the HORDE_BASE
* constant should be defined in config/horde.local.php. */
if (file_exists(TREAN_BASE . '/config/horde.local.php')) {
include TREAN_BASE . '/config/horde.local.php';
} else {
define('HORDE_BASE', realpath(TREAN_BASE . '/..'));
}
}
/* Load the Horde Framework core (needed to autoload
* Horde_Registry_Application::). */
require_once HORDE_BASE . '/lib/core.php';
class Trean_Application extends Horde_Registry_Application
{
/**
*/
public $version = 'H5 (1.1.9-git)';
/**
* Global variables defined:
* - $trean_db: Horde_Db object
* - $trean_gateway: Trean_Bookmarks object
*/
protected function _init()
{
/* For now, autoloading the Content_* classes depend on there being a
* registry entry for the 'content' application that contains at least
* the fileroot entry. */
$GLOBALS['injector']->getInstance('Horde_Autoloader')
->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix(
'/^Content_/',
$GLOBALS['registry']->get('fileroot', 'content') . '/lib/'
));
if (!class_exists('Content_Tagger')) {
throw new Horde_Exception('The Content_Tagger class could not be found. Make sure the Content application is installed.');
}
$GLOBALS['injector']->bindFactory('Trean_TagBrowser', 'Trean_Factory_TagBrowser', 'create');
// Set the timezone variable.
$GLOBALS['registry']->setTimeZone();
// Create db and gateway instances.
$GLOBALS['trean_db'] = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_Db')
->create('trean', 'storage');
$GLOBALS['trean_gateway'] = $GLOBALS['injector']
->getInstance('Trean_Bookmarks');
}
/**
*/
public function perms()
{
return array(
'max_bookmarks' => array(
'title' => _("Maximum Number of Bookmarks"),
'type' => 'int'
),
);
}
/**
*/
public function menu($menu)
{
$menu->add(Horde::url('browse.php'), _("_Browse"), 'trean-browse', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
$menu->add(Horde::url('data.php'), _("_Import"), 'horde-data');
}
/**
* Add additional items to the sidebar.
*
* @param Horde_View_Sidebar $sidebar The sidebar object.
*/
public function sidebar($sidebar)
{
$sidebar->addNewButton(_("_New Bookmark"), Horde::url('add.php'));
$sidebar->containers['tags'] = array(
'header' => array(
'id' => 'trean-toggle-tags',
'label' => _("Tags"),
'collapsed' => false,
),
);
$tagger = $GLOBALS['injector']->getInstance('Trean_Tagger');
$tags = $tagger->listBookmarkTags();
natcasesort($tags);
foreach ($tags as $tag) {;
$url = Horde::url('tag/' . urlencode($tag));
$row = array(
'url' => $url,
'cssClass' => 'trean-tag',
'label' => $tag,
);
$sidebar->addRow($row, 'tags');
}
}
/**
*/
public function cleanupData()
{
$GLOBALS['import_step'] = 1;
return Horde_Data::IMPORT_FILE;
}
}