/usr/share/horde/mnemo/lib/Application.php is in php-horde-mnemo 4.2.12-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 | <?php
/**
* Mnemo application API.
*
* This file defines Horde's core API interface. Other core Horde libraries
* can interact with Mnemo through this API.
*
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @package Mnemo
*/
/* Determine the base directories. */
if (!defined('MNEMO_BASE')) {
define('MNEMO_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(MNEMO_BASE . '/config/horde.local.php')) {
include MNEMO_BASE . '/config/horde.local.php';
} else {
define('HORDE_BASE', realpath(MNEMO_BASE . '/..'));
}
}
/* Load the Horde Framework core (needed to autoload
* Horde_Registry_Application::). */
require_once HORDE_BASE . '/lib/core.php';
class Mnemo_Application extends Horde_Registry_Application
{
/**
*/
public $features = array(
'activesync' => true,
'modseq' => true,
);
/**
*/
public $version = 'H5 (4.2.12)';
/**
* Global variables defined:
* $mnemo_shares - TODO
*/
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."));
}
Mnemo::initialize();
}
/**
*/
public function perms()
{
return array(
'max_notes' => array(
'title' => _("Maximum Number of Notes"),
'type' => 'int'
)
);
}
/**
*/
public function menu($menu)
{
global $conf, $injector;
$menu->add(Horde::url('list.php'), _("_List Notes"), 'mnemo-list', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
/* Search. */
$menu->add(Horde::url('search.php'), _("_Search"), 'mnemo-search');
/* Import/Export */
if ($conf['menu']['import_export']) {
$menu->add(Horde::url('data.php'), _("_Import/Export"), 'horde-data');
}
}
/**
* Add additional items to the sidebar.
*
* @param Horde_View_Sidebar $sidebar The sidebar object.
*/
public function sidebar($sidebar)
{
$perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
if (Mnemo::getDefaultNotepad(Horde_Perms::EDIT) &&
($perms->hasAppPermission('max_notes') === true ||
$perms->hasAppPermission('max_notes') > Mnemo::countMemos())) {
$sidebar->addNewButton(
_("_New Note"),
Horde::url('memo.php')->add('actionID', 'add_memo'));
}
$url = Horde::url('');
$edit = Horde::url('notepads/edit.php');
$user = $GLOBALS['registry']->getAuth();
$sidebar->containers['my'] = array(
'header' => array(
'id' => 'mnemo-toggle-my',
'label' => _("My Notepads"),
'collapsed' => false,
),
);
if (!$GLOBALS['prefs']->isLocked('default_notepad')) {
$sidebar->containers['my']['header']['add'] = array(
'url' => Horde::url('notepads/create.php'),
'label' => _("Create a new Notepad"),
);
}
$sidebar->containers['shared'] = array(
'header' => array(
'id' => 'mnemo-toggle-shared',
'label' => _("Shared Notepads"),
'collapsed' => true,
),
);
foreach (Mnemo::listNotepads() as $name => $notepad) {
$url->add(array(
'display_notepad' => $name,
'actionID' => in_array($name, $GLOBALS['display_notepads'])
? 'remove_displaylist'
: 'add_displaylist'
));
$row = array(
'selected' => in_array($name, $GLOBALS['display_notepads']),
'url' => $url,
'label' => Mnemo::getLabel($notepad),
'color' => $notepad->get('color') ?: '#dddddd',
'edit' => $edit->add('n', $notepad->getName()),
'type' => 'checkbox',
);
if ($notepad->get('owner') == $user) {
$sidebar->addRow($row, 'my');
} else {
$sidebar->addRow($row, 'shared');
}
}
}
/**
*/
public function hasPermission($permission, $allowed, $opts = array())
{
if (is_array($allowed)) {
switch ($permission) {
case 'max_notes':
$allowed = max($allowed);
break;
}
}
return $allowed;
}
/* Topbar method. */
/**
*/
public function topbarCreate(Horde_Tree_Renderer_Base $tree, $parent = null,
array $params = array())
{
global $registry;
$add = Horde::url('memo.php', true)->add('actionID', 'add_memo');
$tree->addNode(array(
'id' => $parent . '__new',
'parent' => $parent,
'label' => _("New Note"),
'expanded' => false,
'params' => array(
'icon' => Horde_Themes::img('add.png'),
'url' => $add
)
));
$user = $registry->getAuth();
foreach (Mnemo::listNotepads(false, Horde_Perms::SHOW) as $name => $notepad) {
if (!$notepad->hasPermission($user, Horde_Perms::EDIT)) {
continue;
}
$tree->addNode(array(
'id' => $parent . $name . '__new',
'parent' => $parent . '__new',
'label' => sprintf(_("in %s"), Mnemo::getLabel($notepad)),
'expanded' => false,
'params' => array(
'icon' => Horde_Themes::img('add.png'),
'url' => $add->copy()->add('memolist', $name)
)
));
}
$tree->addNode(array(
'id' => $parent . '__search',
'parent' => $parent,
'label' => _("Search"),
'expanded' => false,
'params' => array(
'icon' => Horde_Themes::img('search.png'),
'url' => Horde::url('search.php')
)
));
}
/**
*/
public function removeUserData($user)
{
$error = false;
$notepads = $GLOBALS['mnemo_shares']->listShares(
$user, array('attributes' => $user));
foreach ($notepads as $notepad => $share) {
$driver = $GLOBALS['injector']
->getInstance('Mnemo_Factory_Driver')
->create($notepad);
try {
$driver->deleteAll();
} catch (Mnemo_Exception $e) {
Horde::log($e, 'NOTICE');
$error = true;
}
try {
$GLOBALS['mnemo_shares']->removeShare($share);
} catch (Horde_Share_Exception $e) {
Horde::log($e, 'NOTICE');
$error = true;
}
}
// Get a list of all shares this user has perms to and remove the perms.
try {
$shares = $GLOBALS['mnemo_shares']->listShares($user);
foreach ($shares as $share) {
$share->removeUser($user);
}
} catch (Horde_Share_Exception $e) {
Horde::log($e, 'NOTICE');
$error = true;
}
if ($error) {
throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
}
}
/* Download data. */
/**
* @throws Mnemo_Exception
*/
public function download(Horde_Variables $vars)
{
global $injector, $registry;
switch ($vars->actionID) {
case 'export':
/* Get the full, sorted memo list. */
$notes = Mnemo::listMemos();
switch ($vars->exportID) {
case Horde_Data::EXPORT_CSV:
$data = array();
foreach ($notes as $note) {
unset(
$note['desc'],
$note['memo_id'],
$note['memolist_id'],
$nore['uid']
);
$note['tags'] = implode(',', $note['tags']);
if ($note['body'] instanceof Mnemo_Exception) {
$note['body'] = $note['body']->getMessage();
}
$data[] = $note;
}
$injector->getInstance('Horde_Core_Factory_Data')
->create('Csv',
array('cleanup' => array($this, 'cleanupData')))
->exportFile(_("notes.csv"), $data, true);
exit;
}
}
}
/**
*/
public function cleanupData()
{
$GLOBALS['import_step'] = 1;
return Horde_Data::IMPORT_FILE;
}
}
|