public static function initialize()
{
$GLOBALS['mnemo_shares'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
// Update the preference for which notepads to display. If the
// user doesn't have any selected notepads for view then fall
// back to some available notepad.
$GLOBALS['display_notepads'] = unserialize($GLOBALS['prefs']->getValue('display_notepads'));
if (($actionID = Horde_Util::getFormData('actionID')) !== null) {
$notepadId = Horde_Util::getFormData('display_notepad');
switch ($actionID) {
case 'add_displaylist':
if (!in_array($notepadId, $GLOBALS['display_notepads'])) {
$GLOBALS['display_notepads'][] = $notepadId;
}
break;
case 'remove_displaylist':
if (in_array($notepadId, $GLOBALS['display_notepads'])) {
$key = array_search($notepadId, $GLOBALS['display_notepads']);
unset($GLOBALS['display_notepads'][$key]);
}
}
}
// Make sure all notepads exist now, to save on checking later.
$_temp = $GLOBALS['display_notepads'] ? $GLOBALS['display_notepads'] : array();
$_all = self::listNotepads();
$GLOBALS['display_notepads'] = array();
foreach ($_temp as $id) {
if (isset($_all[$id])) {
$GLOBALS['display_notepads'][] = $id;
}
}
// All notepads for guests.
if (!count($GLOBALS['display_notepads']) && !$GLOBALS['registry']->getAuth()) {
$GLOBALS['display_notepads'] = array_keys($_all);
}
/* If the user doesn't own a notepad, create one. */
$notepads = $GLOBALS['injector']->getInstance('Mnemo_Factory_Notepads')->create();
if (($new_default = $notepads->ensureDefaultShare()) !== null) {
$GLOBALS['display_notepads'][] = $new_default;
$GLOBALS['prefs']->setValue('default_notepad', $new_default);
}
$GLOBALS['prefs']->setValue('display_notepads', serialize($GLOBALS['display_notepads']));
}