From 7f318402de6c8655757013e8f323f1e4b903dc71 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 11 Aug 2009 14:49:54 -0600 Subject: [PATCH] Move prefs callbacks into Horde_Registry_Application --- ansel/lib/Api.php | 36 ----- ansel/lib/Application.php | 42 ++++++ chora/lib/Api.php | 10 -- chora/lib/Application.php | 11 ++ crumb/lib/Api.php | 14 -- crumb/lib/Application.php | 11 ++ fima/lib/Api.php | 46 ------ fima/lib/Application.php | 48 ++++++ folks/lib/Api.php | 10 -- folks/lib/Application.php | 11 ++ gollem/lib/Api.php | 28 ---- gollem/lib/Application.php | 34 +++++ imp/lib/Api.php | 325 ---------------------------------------- imp/lib/Application.php | 336 ++++++++++++++++++++++++++++++++++++++++++ ingo/lib/Api.php | 10 -- ingo/lib/Application.php | 11 ++ jeta/lib/Api.php | 14 -- jeta/lib/Application.php | 11 ++ kastalia/lib/Api.php | 14 -- kastalia/lib/Application.php | 11 ++ kronolith/lib/Api.php | 223 ---------------------------- kronolith/lib/Application.php | 230 +++++++++++++++++++++++++++++ nag/lib/Api.php | 40 ----- nag/lib/Application.php | 45 ++++++ news/lib/Api.php | 16 +- news/lib/Application.php | 11 ++ skeleton/lib/Api.php | 10 -- skeleton/lib/Application.php | 11 ++ skoli/lib/Api.php | 14 -- skoli/lib/Application.php | 11 ++ turba/lib/Api.php | 69 --------- turba/lib/Application.php | 74 ++++++++++ 32 files changed, 911 insertions(+), 876 deletions(-) delete mode 100644 crumb/lib/Api.php delete mode 100644 fima/lib/Api.php delete mode 100644 jeta/lib/Api.php delete mode 100644 kastalia/lib/Api.php delete mode 100644 skoli/lib/Api.php diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index 4715ca0d9..51fa72816 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -29,42 +29,6 @@ class Ansel_Api extends Horde_Registry_Api } /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'default_category_select': - $default_category = Horde_Util::getFormData('default_category_select'); - if (!is_null($default_category)) { - $GLOBALS['prefs']->setValue('default_category', $default_category); - return true; - } - break; - - case 'default_gallerystyle_select': - $default_style = Horde_Util::getFormData('default_gallerystyle_select'); - if (!is_null($default_style)) { - $GLOBALS['prefs']->setValue('default_gallerystyle', $default_style); - return true; - } - break; - } - - return $updated; - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Ansel::getMenu(); - } - - /** * Browse through Ansel's gallery tree. * * @param string $path The level of the tree to browse. diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index e99e070ae..9b521a54e 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -15,4 +15,46 @@ class Ansel_Application extends Horde_Registry_Application { public $version = 'H4 (2.0-git)'; + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'default_category_select': + $default_category = Horde_Util::getFormData('default_category_select'); + if (!is_null($default_category)) { + $GLOBALS['prefs']->setValue('default_category', $default_category); + return true; + } + break; + + case 'default_gallerystyle_select': + $default_style = Horde_Util::getFormData('default_gallerystyle_select'); + if (!is_null($default_style)) { + $GLOBALS['prefs']->setValue('default_gallerystyle', $default_style); + return true; + } + break; + } + + return $updated; + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Ansel::getMenu(); + } + } diff --git a/chora/lib/Api.php b/chora/lib/Api.php index b8662d65d..25a764fdf 100644 --- a/chora/lib/Api.php +++ b/chora/lib/Api.php @@ -31,14 +31,4 @@ class Chora_Api extends Horde_Registry_Api return $perms; } - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Chora::getMenu(); - } - } diff --git a/chora/lib/Application.php b/chora/lib/Application.php index c8ea97659..8eee94307 100644 --- a/chora/lib/Application.php +++ b/chora/lib/Application.php @@ -15,4 +15,15 @@ class Chora_Application extends Horde_Registry_Application * @var string */ public $version = 'H4 (3.0-git)'; + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Chora::getMenu(); + } + } diff --git a/crumb/lib/Api.php b/crumb/lib/Api.php deleted file mode 100644 index 0a95673a7..000000000 --- a/crumb/lib/Api.php +++ /dev/null @@ -1,14 +0,0 @@ -setValue('active_ledger', $active_ledger); - return true; - } - } - break; - - case 'closedperiodselect': - $period = Horde_Util::getFormData('closedperiod'); - if ((int)$period['year'] > 0 && (int)$period['month'] > 0) { - $period = mktime(0, 0, 0, $period['month'] + 1, 0, $period['year']); - } else { - $period = 0; - } - $GLOBALS['prefs']->setValue('closed_period', $period); - return true; - } - - return $updated; - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Fima::getMenu(); - } - -} diff --git a/fima/lib/Application.php b/fima/lib/Application.php index b50e46e74..a3b8266d8 100644 --- a/fima/lib/Application.php +++ b/fima/lib/Application.php @@ -2,4 +2,52 @@ class Fima_Application extends Horde_Regsitry_Application { public $version = '1.0.1'; + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'ledgerselect': + $active_ledger = Horde_Util::getFormData('active_ledger'); + if (!is_null($active_ledger)) { + $ledgers = Fima::listLedgers(); + if (is_array($ledgers) && + array_key_exists($active_ledger, $ledgers)) { + $GLOBALS['prefs']->setValue('active_ledger', $active_ledger); + return true; + } + } + break; + + case 'closedperiodselect': + $period = Horde_Util::getFormData('closedperiod'); + if ((int)$period['year'] > 0 && (int)$period['month'] > 0) { + $period = mktime(0, 0, 0, $period['month'] + 1, 0, $period['year']); + } else { + $period = 0; + } + $GLOBALS['prefs']->setValue('closed_period', $period); + return true; + } + + return $updated; + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Fima::getMenu(); + } + } diff --git a/folks/lib/Api.php b/folks/lib/Api.php index 83a7d3965..92460c760 100644 --- a/folks/lib/Api.php +++ b/folks/lib/Api.php @@ -31,16 +31,6 @@ class Folks_Api extends Horde_Registry_Api } /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Folks::getMenu(); - } - - /** * Returns profile image URL. * * @param string $user User uid diff --git a/folks/lib/Application.php b/folks/lib/Application.php index f65e9498f..7de69c3f5 100644 --- a/folks/lib/Application.php +++ b/folks/lib/Application.php @@ -10,4 +10,15 @@ class Folks_Application extends Horde_Registry_Application { public $version = 'H4 (0.1-git)'; + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Folks::getMenu(); + } + } diff --git a/gollem/lib/Api.php b/gollem/lib/Api.php index 0e8eb953b..d1e1849f6 100644 --- a/gollem/lib/Api.php +++ b/gollem/lib/Api.php @@ -38,34 +38,6 @@ class Gollem_Api extends Horde_Registry_Api } /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'columnselect': - $columns = Horde_Util::getFormData('columns'); - if (!empty($columns)) { - $GLOBALS['prefs']->setValue('columns', $columns); - return true; - } - break; - } - - return $updated; - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Gollem::getMenu(); - } - - /** * Browses through the VFS tree. * * Each VFS backend is listed as a directory at the top level. No modify diff --git a/gollem/lib/Application.php b/gollem/lib/Application.php index 95211c260..1fd3fd594 100644 --- a/gollem/lib/Application.php +++ b/gollem/lib/Application.php @@ -18,4 +18,38 @@ class Gollem_Application extends Horde_Registry_Application * @var string */ public $version = 'H4 (2.0-git)'; + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'columnselect': + $columns = Horde_Util::getFormData('columns'); + if (!empty($columns)) { + $GLOBALS['prefs']->setValue('columns', $columns); + return true; + } + break; + } + + return $updated; + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Gollem::getMenu(); + } + } diff --git a/imp/lib/Api.php b/imp/lib/Api.php index eacc1b13e..ffa9bf605 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -134,331 +134,6 @@ class IMP_Api extends Horde_Registry_Api } } - /** - * Code to run when viewing prefs for this application. - * - * @param string $group The prefGroup name. - */ - public function prefsInit($group) - { - /* Add necessary javascript files here (so they are added to the - * document HEAD). */ - switch ($group) { - case 'flags': - Horde::addScriptFile('colorpicker.js', 'horde', true); - Horde::addScriptFile('flagmanagement.js', 'imp', true); - - Horde::addInlineScript(array( - 'ImpFlagmanagement.new_prompt = ' . Horde_Serialize::serialize(_("Please enter the label for the new flag:"), Horde_Serialize::JSON, Horde_Nls::getCharset()), - 'ImpFlagmanagement.confirm_delete = ' . Horde_Serialize::serialize(_("Are you sure you want to delete this flag?"), Horde_Serialize::JSON, Horde_Nls::getCharset()) - )); - break; - } - } - - /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'sentmailselect': - return $this->_prefsSentmailSelect($updated); - - case 'draftsselect': - return $updated | $this->_prefsHandleFolders($updated, 'drafts_folder', 'drafts', 'drafts_new'); - - case 'spamselect': - return $updated | $this->_prefsHandleFolders($updated, 'spam_folder', 'spam', 'spam_new'); - - case 'trashselect': - return $this->_prefsTrashSelect($updated); - - case 'sourceselect': - return $this->_prefsSourceSelect($updated); - - case 'initialpageselect': - $this->_prefsInitialPageSelect(); - return true; - - case 'encryptselect': - $this->_prefsEncryptSelect(); - return true; - - case 'defaultsearchselect': - $this->_prefsDefaultSearchSelect(); - return true; - - case 'soundselect': - return $GLOBALS['prefs']->setValue('nav_audio', Horde_Util::getFormData('nav_audio')); - - case 'flagmanagement': - $this->_prefsFlagManagement(); - return false; - } - } - - /** - * Do anything that we need to do as a result of certain preferences - * changing. - */ - public function prefsCallback() - { - global $prefs; - - /* Always check to make sure we have a valid trash folder if delete to - * trash is active. */ - if (($prefs->isDirty('use_trash') || $prefs->isDirty('trash_folder')) && - $prefs->getValue('use_trash') && - !$prefs->getValue('trash_folder') && - !$prefs->getValue('use_vtrash')) { - $GLOBALS['notification']->push(_("You have activated move to Trash but no Trash folder is defined. You will be unable to delete messages until you set a Trash folder in the preferences."), 'horde.warning'); - } - - if ($prefs->isDirty('use_vtrash') || $prefs->isDirty('use_vinbox')) { - $imp_search = new IMP_Search(); - $imp_search->initialize(true); - } - - if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) { - $imp_folder = IMP_Folder::singleton(); - $imp_folder->clearFlistCache(); - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->init(); - } - - if ($prefs->isDirty('mail_domain')) { - $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain')); - $prefs->setValue('maildomain', $maildomain); - if (!empty($maildomain)) { - $_SESSION['imp']['maildomain'] = $maildomain; - } - } - - if ($prefs->isDirty('compose_popup')) { - Horde::addInlineScript(array( - 'if (window.parent.frames.horde_menu) window.parent.frames.horde_menu.location.reload();' - )); - } - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return IMP::getMenu(); - } - - /** - * Setup notifications handler for the preferences page. This will only - * be called if in dimp view mode. - */ - public function prefsStatus() - { - require_once dirname(__FILE__) . '/Application.php'; - new IMP_Application(array('init' => array('authentication' => 'none'))); - - $notification = Horde_Notification::singleton(); - $notification->detach('status'); - $notification->attach('status', array('prefs' => true, 'viewmode' => 'dimp'), 'IMP_Notification_Listener_Status'); - } - - /** - * TODO - */ - protected function _prefsSentmailSelect($updated) - { - if (!$GLOBALS['conf']['user']['allow_folders'] || - $GLOBALS['prefs']->isLocked('sent_mail_folder')) { - return $updated; - } - - $sent_mail_folder = Horde_Util::getFormData('sent_mail_folder'); - $sent_mail_new = Horde_String::convertCharset(Horde_Util::getFormData('sent_mail_new'), Horde_Nls::getCharset(), 'UTF7-IMAP'); - $sent_mail_default = $GLOBALS['prefs']->getValue('sent_mail_folder'); - - if (empty($sent_mail_folder) && !empty($sent_mail_new)) { - $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_new); - } elseif (($sent_mail_folder == '-1') && !empty($sent_mail_default)) { - $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_default); - } - - if (!empty($sent_mail_folder)) { - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($sent_mail_folder)) { - $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe')); - } - } - $GLOBALS['identity']->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false)); - - return true; - } - - /** - * TODO - */ - protected function _prefsHandlefolders($updated, $pref, $folder, $new) - { - if (!$GLOBALS['conf']['user']['allow_folders']) { - return $updated; - } - - $folder = Horde_Util::getFormData($folder); - if (isset($folder) && !$GLOBALS['prefs']->isLocked($pref)) { - $new = Horde_String::convertCharset(Horde_Util::getFormData($new), Horde_Nls::getCharset(), 'UTF7-IMAP'); - if ($folder == IMP::PREF_NO_FOLDER) { - $GLOBALS['prefs']->setValue($pref, ''); - } else { - if (empty($folder) && !empty($new)) { - $folder = $GLOBALS['imp_imap']->appendNamespace($new); - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) { - $folder = null; - } - } - if (!empty($folder)) { - $GLOBALS['prefs']->setValue($pref, IMP::folderPref($folder, false)); - return true; - } - } - } - - return $updated; - } - - /** - * TODO - */ - protected function _prefsTrashSelect($updated) - { - global $prefs; - - if (Horde_Util::getFormData('trash') == IMP::PREF_VTRASH) { - if ($prefs->isLocked('use_vtrash')) { - return false; - } - - $prefs->setValue('use_vtrash', 1); - $prefs->setValue('trash_folder', ''); - } else { - if ($prefs->isLocked('trash_folder')) { - return false; - } - - $updated = $updated | $this->_prefsHandleFolders($updated, 'trash_folder', 'trash', 'trash_new'); - if ($updated) { - $prefs->setValue('use_vtrash', 0); - $prefs->setDirty('trash_folder', true); - } - } - - return $updated; - } - - /** - * TODO - */ - protected function _prefsSourceSelect($updated) - { - $search_sources = Horde_Util::getFormData('search_sources'); - if (!is_null($search_sources)) { - $GLOBALS['prefs']->setValue('search_sources', $search_sources); - unset($_SESSION['imp']['cache']['ac_ajax']); - $updated = true; - } - - $search_fields_string = Horde_Util::getFormData('search_fields_string'); - if (!is_null($search_fields_string)) { - $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); - $updated = true; - } - - $add_source = Horde_Util::getFormData('add_source'); - if (!is_null($add_source)) { - $GLOBALS['prefs']->setValue('add_source', $add_source); - $updated = true; - } - - return $updated; - } - - /** - * TODO - */ - protected function _prefsInitialPageSelect() - { - $initial_page = Horde_Util::getFormData('initial_page'); - $GLOBALS['prefs']->setValue('initial_page', $initial_page); - } - - /** - * TODO - */ - protected function _prefsEncryptSelect() - { - $default_encrypt = Horde_Util::getFormData('default_encrypt'); - $GLOBALS['prefs']->setValue('default_encrypt', $default_encrypt); - } - - /** - * TODO - */ - protected function _prefsDefaultSearchSelect() - { - $default_search = Horde_Util::getFormData('default_search'); - $GLOBALS['prefs']->setValue('default_search', $default_search); - } - - /** - * TODO - */ - protected function _prefsFlagManagement() - { - $imp_flags = IMP_Imap_Flags::singleton(); - $action = Horde_Util::getFormData('flag_action'); - $data = Horde_Util::getFormData('flag_data'); - - if ($action == 'add') { - $imp_flags->addFlag($data); - return; - } - - $def_color = $GLOBALS['prefs']->getValue('msgflags_color'); - - // Don't set updated on these actions. User may want to do more actions. - foreach ($imp_flags->getList() as $key => $val) { - $md5 = hash('md5', $key); - - switch ($action) { - case 'delete': - if ($data == ('bg_' . $md5)) { - $imp_flags->deleteFlag($key); - } - break; - - default: - /* Change labels for user-defined flags. */ - if ($val['t'] == 'imapp') { - $label = Horde_Util::getFormData('label_' . $md5); - if (strlen($label) && ($label != $val['l'])) { - $imp_flags->updateFlag($key, array('l' => $label)); - } - } - - /* Change background for all flags. */ - $bg = strtolower(Horde_Util::getFormData('bg_' . $md5)); - if ((isset($val['b']) && ($bg != $val['b'])) || - (!isset($val['b']) && ($bg != $def_color))) { - $imp_flags->updateFlag($key, array('b' => $bg)); - } - break; - } - } - } - /* IMP-specific functions. */ /** diff --git a/imp/lib/Application.php b/imp/lib/Application.php index c450d488a..58e017da4 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -162,6 +162,8 @@ class IMP_Application extends Horde_Registry_Application IMP::initialize(); } + /* Horde_Auth_Application methods. */ + /** * Return login parameters used on the login page. * @@ -357,4 +359,338 @@ class IMP_Application extends Horde_Registry_Application return $auth->listUsers(); } + /* Preferences display/handling methods. */ + + /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + * + * @return array A list of variables to export to the prefs display page. + */ + public function prefsInit($group) + { + /* Add necessary javascript files here (so they are added to the + * document HEAD). */ + switch ($group) { + case 'flags': + Horde::addScriptFile('colorpicker.js', 'horde', true); + Horde::addScriptFile('flagmanagement.js', 'imp', true); + + Horde::addInlineScript(array( + 'ImpFlagmanagement.new_prompt = ' . Horde_Serialize::serialize(_("Please enter the label for the new flag:"), Horde_Serialize::JSON, Horde_Nls::getCharset()), + 'ImpFlagmanagement.confirm_delete = ' . Horde_Serialize::serialize(_("Are you sure you want to delete this flag?"), Horde_Serialize::JSON, Horde_Nls::getCharset()) + )); + break; + } + } + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'sentmailselect': + return $this->_prefsSentmailSelect($updated); + + case 'draftsselect': + return $updated | $this->_prefsHandleFolders($updated, 'drafts_folder', 'drafts', 'drafts_new'); + + case 'spamselect': + return $updated | $this->_prefsHandleFolders($updated, 'spam_folder', 'spam', 'spam_new'); + + case 'trashselect': + return $this->_prefsTrashSelect($updated); + + case 'sourceselect': + return $this->_prefsSourceSelect($updated); + + case 'initialpageselect': + $this->_prefsInitialPageSelect(); + return true; + + case 'encryptselect': + $this->_prefsEncryptSelect(); + return true; + + case 'defaultsearchselect': + $this->_prefsDefaultSearchSelect(); + return true; + + case 'soundselect': + return $GLOBALS['prefs']->setValue('nav_audio', Horde_Util::getFormData('nav_audio')); + + case 'flagmanagement': + $this->_prefsFlagManagement(); + return false; + } + } + + /** + * Do anything that we need to do as a result of certain preferences + * changing. + */ + public function prefsCallback() + { + global $prefs; + + /* Always check to make sure we have a valid trash folder if delete to + * trash is active. */ + if (($prefs->isDirty('use_trash') || $prefs->isDirty('trash_folder')) && + $prefs->getValue('use_trash') && + !$prefs->getValue('trash_folder') && + !$prefs->getValue('use_vtrash')) { + $GLOBALS['notification']->push(_("You have activated move to Trash but no Trash folder is defined. You will be unable to delete messages until you set a Trash folder in the preferences."), 'horde.warning'); + } + + if ($prefs->isDirty('use_vtrash') || $prefs->isDirty('use_vinbox')) { + $imp_search = new IMP_Search(); + $imp_search->initialize(true); + } + + if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) { + $imp_folder = IMP_Folder::singleton(); + $imp_folder->clearFlistCache(); + $imaptree = IMP_Imap_Tree::singleton(); + $imaptree->init(); + } + + if ($prefs->isDirty('mail_domain')) { + $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain')); + $prefs->setValue('maildomain', $maildomain); + if (!empty($maildomain)) { + $_SESSION['imp']['maildomain'] = $maildomain; + } + } + + if ($prefs->isDirty('compose_popup')) { + Horde::addInlineScript(array( + 'if (window.parent.frames.horde_menu) window.parent.frames.horde_menu.location.reload();' + )); + } + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return IMP::getMenu(); + } + + /** + * Setup notifications handler for the preferences page. This will only + * be called if in dimp view mode. + */ + public function prefsStatus() + { + require_once dirname(__FILE__) . '/Application.php'; + new IMP_Application(array('init' => array('authentication' => 'none'))); + + $notification = Horde_Notification::singleton(); + $notification->detach('status'); + $notification->attach('status', array('prefs' => true, 'viewmode' => 'dimp'), 'IMP_Notification_Listener_Status'); + } + + /** + * TODO + */ + protected function _prefsSentmailSelect($updated) + { + if (!$GLOBALS['conf']['user']['allow_folders'] || + $GLOBALS['prefs']->isLocked('sent_mail_folder')) { + return $updated; + } + + $sent_mail_folder = Horde_Util::getFormData('sent_mail_folder'); + $sent_mail_new = Horde_String::convertCharset(Horde_Util::getFormData('sent_mail_new'), Horde_Nls::getCharset(), 'UTF7-IMAP'); + $sent_mail_default = $GLOBALS['prefs']->getValue('sent_mail_folder'); + + if (empty($sent_mail_folder) && !empty($sent_mail_new)) { + $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_new); + } elseif (($sent_mail_folder == '-1') && !empty($sent_mail_default)) { + $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_default); + } + + if (!empty($sent_mail_folder)) { + $imp_folder = IMP_Folder::singleton(); + if (!$imp_folder->exists($sent_mail_folder)) { + $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe')); + } + } + $GLOBALS['identity']->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false)); + + return true; + } + + /** + * TODO + */ + protected function _prefsHandlefolders($updated, $pref, $folder, $new) + { + if (!$GLOBALS['conf']['user']['allow_folders']) { + return $updated; + } + + $folder = Horde_Util::getFormData($folder); + if (isset($folder) && !$GLOBALS['prefs']->isLocked($pref)) { + $new = Horde_String::convertCharset(Horde_Util::getFormData($new), Horde_Nls::getCharset(), 'UTF7-IMAP'); + if ($folder == IMP::PREF_NO_FOLDER) { + $GLOBALS['prefs']->setValue($pref, ''); + } else { + if (empty($folder) && !empty($new)) { + $folder = $GLOBALS['imp_imap']->appendNamespace($new); + $imp_folder = IMP_Folder::singleton(); + if (!$imp_folder->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) { + $folder = null; + } + } + if (!empty($folder)) { + $GLOBALS['prefs']->setValue($pref, IMP::folderPref($folder, false)); + return true; + } + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsTrashSelect($updated) + { + global $prefs; + + if (Horde_Util::getFormData('trash') == IMP::PREF_VTRASH) { + if ($prefs->isLocked('use_vtrash')) { + return false; + } + + $prefs->setValue('use_vtrash', 1); + $prefs->setValue('trash_folder', ''); + } else { + if ($prefs->isLocked('trash_folder')) { + return false; + } + + $updated = $updated | $this->_prefsHandleFolders($updated, 'trash_folder', 'trash', 'trash_new'); + if ($updated) { + $prefs->setValue('use_vtrash', 0); + $prefs->setDirty('trash_folder', true); + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsSourceSelect($updated) + { + $search_sources = Horde_Util::getFormData('search_sources'); + if (!is_null($search_sources)) { + $GLOBALS['prefs']->setValue('search_sources', $search_sources); + unset($_SESSION['imp']['cache']['ac_ajax']); + $updated = true; + } + + $search_fields_string = Horde_Util::getFormData('search_fields_string'); + if (!is_null($search_fields_string)) { + $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); + $updated = true; + } + + $add_source = Horde_Util::getFormData('add_source'); + if (!is_null($add_source)) { + $GLOBALS['prefs']->setValue('add_source', $add_source); + $updated = true; + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsInitialPageSelect() + { + $initial_page = Horde_Util::getFormData('initial_page'); + $GLOBALS['prefs']->setValue('initial_page', $initial_page); + } + + /** + * TODO + */ + protected function _prefsEncryptSelect() + { + $default_encrypt = Horde_Util::getFormData('default_encrypt'); + $GLOBALS['prefs']->setValue('default_encrypt', $default_encrypt); + } + + /** + * TODO + */ + protected function _prefsDefaultSearchSelect() + { + $default_search = Horde_Util::getFormData('default_search'); + $GLOBALS['prefs']->setValue('default_search', $default_search); + } + + /** + * TODO + */ + protected function _prefsFlagManagement() + { + $imp_flags = IMP_Imap_Flags::singleton(); + $action = Horde_Util::getFormData('flag_action'); + $data = Horde_Util::getFormData('flag_data'); + + if ($action == 'add') { + $imp_flags->addFlag($data); + return; + } + + $def_color = $GLOBALS['prefs']->getValue('msgflags_color'); + + // Don't set updated on these actions. User may want to do more actions. + foreach ($imp_flags->getList() as $key => $val) { + $md5 = hash('md5', $key); + + switch ($action) { + case 'delete': + if ($data == ('bg_' . $md5)) { + $imp_flags->deleteFlag($key); + } + break; + + default: + /* Change labels for user-defined flags. */ + if ($val['t'] == 'imapp') { + $label = Horde_Util::getFormData('label_' . $md5); + if (strlen($label) && ($label != $val['l'])) { + $imp_flags->updateFlag($key, array('l' => $label)); + } + } + + /* Change background for all flags. */ + $bg = strtolower(Horde_Util::getFormData('bg_' . $md5)); + if ((isset($val['b']) && ($bg != $val['b'])) || + (!isset($val['b']) && ($bg != $def_color))) { + $imp_flags->updateFlag($key, array('b' => $bg)); + } + break; + } + } + } + } diff --git a/ingo/lib/Api.php b/ingo/lib/Api.php index 20172ad4a..b874ccfe0 100644 --- a/ingo/lib/Api.php +++ b/ingo/lib/Api.php @@ -48,16 +48,6 @@ class Ingo_Api extends Horde_Registry_Api } /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Ingo::getMenu(); - } - - /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index 659209ff9..5411618a1 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -13,4 +13,15 @@ class Ingo_Application extends Horde_Registry_Application * @var string */ public $version = 'H4 (2.0-git)'; + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Ingo::getMenu(); + } + } diff --git a/jeta/lib/Api.php b/jeta/lib/Api.php deleted file mode 100644 index 066ffa692..000000000 --- a/jeta/lib/Api.php +++ /dev/null @@ -1,14 +0,0 @@ -isLocked('day_hour_start') || - !$GLOBALS['prefs']->isLocked('day_hour_end')) { - $out['day_hour_start_options'] = array(); - for ($i = 0; $i <= 48; ++$i) { - $out['day_hour_start_options'][$i] = date(($GLOBALS['prefs']->getValue('twentyFour')) ? 'G:i' : 'g:ia', mktime(0, $i * 30, 0)); - } - $out['day_hour_end_options'] = $out['day_hour_start_options']; - } - - if (!empty($GLOBALS['conf']['holidays']['enable'])) { - if (class_exists('Date_Holidays')) { - foreach (Date_Holidays::getInstalledDrivers() as $driver) { - if ($driver['id'] == 'Composite') { - continue; - } - $_prefs['holiday_drivers']['enum'][$driver['id']] = $driver['title']; - } - asort($_prefs['holiday_drivers']['enum']); - } else { - $GLOBALS['notification']->push(_("Holidays support is not available on this server."), 'horde.error'); - } - } - - return $out; - } - - /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'remote_cal_management': - return $this->_prefsRemoteCalManagement($updated); - - case 'shareselect': - return $this->_prefsShareSelect($updated); - - case 'holiday_drivers': - $this->_prefsHolidayDrivers($updated); - return true; - - case 'sourceselect': - return $this->_prefsSourceSelect($updated); - - case 'fb_cals_select': - $this->_prefsFbCalsSelect($updated); - return true; - - case 'default_alarm_management': - $GLOBALS['prefs']->setValue('default_alarm', (int)Horde_Util::getFormData('alarm_value') * (int)Horde_Util::getFormData('alarm_unit')); - return true; - } - } - - /** - * TODO - */ - public function prefsCallback() - { - if ($GLOBALS['prefs']->isDirty('event_alarms')) { - $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); - if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) { - $horde_alarm = Horde_Alarm::factory(); - foreach ($alarms as $alarm) { - $alarm['start'] = new Horde_Date($alarm['start']); - $alarm['end'] = new Horde_Date($alarm['end']); - $horde_alarm->set($alarm); - } - } - } - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Kronolith::getMenu(); - } - - /** - * TODO - */ - protected function _prefsRemoteCalManagement($updated) - { - $calName = Horde_Util::getFormData('remote_name'); - $calUrl = trim(Horde_Util::getFormData('remote_url')); - $calUser = trim(Horde_Util::getFormData('remote_user')); - $calPasswd = trim(Horde_Util::getFormData('remote_password')); - - $key = Horde_Auth::getCredential('password'); - if ($key) { - $calUser = base64_encode(Secret::write($key, $calUser)); - $calPasswd = base64_encode(Secret::write($key, $calPasswd)); - } - - $calActionID = Horde_Util::getFormData('remote_action', 'add'); - - if ($calActionID == 'add') { - if (!empty($calName) && !empty($calUrl)) { - $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - $cals[] = array('name' => $calName, - 'url' => $calUrl, - 'user' => $calUser, - 'password' => $calPasswd); - $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); - return $updated; - } - } elseif ($calActionID == 'delete') { - $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - foreach ($cals as $key => $cal) { - if ($cal['url'] == $calUrl) { - unset($cals[$key]); - break; - } - } - $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); - return $updated; - } elseif ($calActionID == 'edit') { - $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); - foreach ($cals as $key => $cal) { - if ($cal['url'] == $calUrl) { - $cals[$key]['name'] = $calName; - $cals[$key]['url'] = $calUrl; - $cals[$key]['user'] = $calUser; - $cals[$key]['password'] = $calPasswd; - break; - } - } - $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); - return $updated; - } - - return false; - } - - /** - * TODO - */ - protected function _prefsShareSelect($updated) - { - $default_share = Horde_Util::getFormData('default_share'); - if (!is_null($default_share)) { - $sharelist = Kronolith::listCalendars(); - if ((is_array($sharelist)) > 0 && - isset($sharelist[$default_share])) { - $GLOBALS['prefs']->setValue('default_share', $default_share); - return true; - } - } - - return $updated; - } - - /** - * TODO - */ - protected function _prefsHolidayDrivers() - { - $holiday_driversSelected = Horde_Util::getFormData('holiday_drivers'); - $holiday_driversFiltered = array(); - - if (is_array($holiday_driversSelected)) { - foreach ($holiday_driversSelected as $holiday_driver) { - $holiday_driversFiltered[] = $holiday_driver; - } - } - - $GLOBALS['prefs']->setValue('holiday_drivers', serialize($holiday_driversFiltered)); - } - - /** - * TODO - */ - protected function _prefsSourceSelect($updated) - { - $search_sources = Horde_Util::getFormData('search_sources'); - if (!is_null($search_sources)) { - $GLOBALS['prefs']->setValue('search_sources', $search_sources); - $updated = true; - } - - $search_fields_string = Horde_Util::getFormData('search_fields_string'); - if (!is_null($search_fields_string)) { - $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); - $updated = true; - } - - return $updated; - } - - /** - * TODO - */ - protected function _prefsHandleFbCalsSelect() - { - $fb_calsSelected = Horde_Util::getFormData('fb_cals'); - $fb_cals = Kronolith::listCalendars(); - $fb_calsFiltered = array(); - - if (isset($fb_calsSelected) && is_array($fb_calsSelected)) { - foreach ($fb_calsSelected as $fb_cal) { - $fb_calsFiltered[] = $fb_cal; - } - } - - $GLOBALS['prefs']->setValue('fb_cals', serialize($fb_calsFiltered)); - } - - /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index d68693cae..4d8a527b0 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -7,4 +7,234 @@ class Kronolith_Application extends Horde_Registry_Application { public $version = 'H3 (3.0-git)'; + + /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + * + * @return array A list of variables to export to the prefs display page. + */ + public function prefsInit($group) + { + $out = array(); + + if (!$GLOBALS['prefs']->isLocked('day_hour_start') || + !$GLOBALS['prefs']->isLocked('day_hour_end')) { + $out['day_hour_start_options'] = array(); + for ($i = 0; $i <= 48; ++$i) { + $out['day_hour_start_options'][$i] = date(($GLOBALS['prefs']->getValue('twentyFour')) ? 'G:i' : 'g:ia', mktime(0, $i * 30, 0)); + } + $out['day_hour_end_options'] = $out['day_hour_start_options']; + } + + if (!empty($GLOBALS['conf']['holidays']['enable'])) { + if (class_exists('Date_Holidays')) { + foreach (Date_Holidays::getInstalledDrivers() as $driver) { + if ($driver['id'] == 'Composite') { + continue; + } + $_prefs['holiday_drivers']['enum'][$driver['id']] = $driver['title']; + } + asort($_prefs['holiday_drivers']['enum']); + } else { + $GLOBALS['notification']->push(_("Holidays support is not available on this server."), 'horde.error'); + } + } + + return $out; + } + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'remote_cal_management': + return $this->_prefsRemoteCalManagement($updated); + + case 'shareselect': + return $this->_prefsShareSelect($updated); + + case 'holiday_drivers': + $this->_prefsHolidayDrivers($updated); + return true; + + case 'sourceselect': + return $this->_prefsSourceSelect($updated); + + case 'fb_cals_select': + $this->_prefsFbCalsSelect($updated); + return true; + + case 'default_alarm_management': + $GLOBALS['prefs']->setValue('default_alarm', (int)Horde_Util::getFormData('alarm_value') * (int)Horde_Util::getFormData('alarm_unit')); + return true; + } + } + + /** + * Do anything that we need to do as a result of certain preferences + * changing. + */ + public function prefsCallback() + { + if ($GLOBALS['prefs']->isDirty('event_alarms')) { + $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); + if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) { + $horde_alarm = Horde_Alarm::factory(); + foreach ($alarms as $alarm) { + $alarm['start'] = new Horde_Date($alarm['start']); + $alarm['end'] = new Horde_Date($alarm['end']); + $horde_alarm->set($alarm); + } + } + } + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Kronolith::getMenu(); + } + + /** + * TODO + */ + protected function _prefsRemoteCalManagement($updated) + { + $calName = Horde_Util::getFormData('remote_name'); + $calUrl = trim(Horde_Util::getFormData('remote_url')); + $calUser = trim(Horde_Util::getFormData('remote_user')); + $calPasswd = trim(Horde_Util::getFormData('remote_password')); + + $key = Horde_Auth::getCredential('password'); + if ($key) { + $calUser = base64_encode(Secret::write($key, $calUser)); + $calPasswd = base64_encode(Secret::write($key, $calPasswd)); + } + + $calActionID = Horde_Util::getFormData('remote_action', 'add'); + + if ($calActionID == 'add') { + if (!empty($calName) && !empty($calUrl)) { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + $cals[] = array('name' => $calName, + 'url' => $calUrl, + 'user' => $calUser, + 'password' => $calPasswd); + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } + } elseif ($calActionID == 'delete') { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + foreach ($cals as $key => $cal) { + if ($cal['url'] == $calUrl) { + unset($cals[$key]); + break; + } + } + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } elseif ($calActionID == 'edit') { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + foreach ($cals as $key => $cal) { + if ($cal['url'] == $calUrl) { + $cals[$key]['name'] = $calName; + $cals[$key]['url'] = $calUrl; + $cals[$key]['user'] = $calUser; + $cals[$key]['password'] = $calPasswd; + break; + } + } + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } + + return false; + } + + /** + * TODO + */ + protected function _prefsShareSelect($updated) + { + $default_share = Horde_Util::getFormData('default_share'); + if (!is_null($default_share)) { + $sharelist = Kronolith::listCalendars(); + if ((is_array($sharelist)) > 0 && + isset($sharelist[$default_share])) { + $GLOBALS['prefs']->setValue('default_share', $default_share); + return true; + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsHolidayDrivers() + { + $holiday_driversSelected = Horde_Util::getFormData('holiday_drivers'); + $holiday_driversFiltered = array(); + + if (is_array($holiday_driversSelected)) { + foreach ($holiday_driversSelected as $holiday_driver) { + $holiday_driversFiltered[] = $holiday_driver; + } + } + + $GLOBALS['prefs']->setValue('holiday_drivers', serialize($holiday_driversFiltered)); + } + + /** + * TODO + */ + protected function _prefsSourceSelect($updated) + { + $search_sources = Horde_Util::getFormData('search_sources'); + if (!is_null($search_sources)) { + $GLOBALS['prefs']->setValue('search_sources', $search_sources); + $updated = true; + } + + $search_fields_string = Horde_Util::getFormData('search_fields_string'); + if (!is_null($search_fields_string)) { + $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); + $updated = true; + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsHandleFbCalsSelect() + { + $fb_calsSelected = Horde_Util::getFormData('fb_cals'); + $fb_cals = Kronolith::listCalendars(); + $fb_calsFiltered = array(); + + if (isset($fb_calsSelected) && is_array($fb_calsSelected)) { + foreach ($fb_calsSelected as $fb_cal) { + $fb_calsFiltered[] = $fb_cal; + } + } + + $GLOBALS['prefs']->setValue('fb_cals', serialize($fb_calsFiltered)); + } + } diff --git a/nag/lib/Api.php b/nag/lib/Api.php index bb6afd569..cbafad121 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -34,46 +34,6 @@ class Nag_Api extends Horde_Registry_Api } /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'tasklistselect': - $default_tasklist = Horde_Util::getFormData('default_tasklist'); - if (!is_null($default_tasklist)) { - $tasklists = Nag::listTasklists(); - if (is_array($tasklists) && - isset($tasklists[$default_tasklist])) { - $GLOBALS['prefs']->setValue('default_tasklist', $default_tasklist); - return true; - } - } - break; - - case 'showsummaryselect': - $GLOBALS['prefs']->setValue('summary_categories', Horde_Util::getFormData('summary_categories')); - return true; - - case 'defaultduetimeselect': - $GLOBALS['prefs']->setValue('default_due_time', Horde_Util::getFormData('default_due_time')); - return true; - } - - return $updated; - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Nag::getMenu(); - } - - /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/nag/lib/Application.php b/nag/lib/Application.php index a77904bb8..b0fbc0a71 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -13,4 +13,49 @@ class Nag_Application extends Horde_Registry_Application */ public $version = 'H4 (3.0-git)'; + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'tasklistselect': + $default_tasklist = Horde_Util::getFormData('default_tasklist'); + if (!is_null($default_tasklist)) { + $tasklists = Nag::listTasklists(); + if (is_array($tasklists) && + isset($tasklists[$default_tasklist])) { + $GLOBALS['prefs']->setValue('default_tasklist', $default_tasklist); + return true; + } + } + break; + + case 'showsummaryselect': + $GLOBALS['prefs']->setValue('summary_categories', Horde_Util::getFormData('summary_categories')); + return true; + + case 'defaultduetimeselect': + $GLOBALS['prefs']->setValue('default_due_time', Horde_Util::getFormData('default_due_time')); + return true; + } + + return $updated; + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Nag::getMenu(); + } + } diff --git a/news/lib/Api.php b/news/lib/Api.php index 514a8cc7d..da84576fb 100644 --- a/news/lib/Api.php +++ b/news/lib/Api.php @@ -41,21 +41,11 @@ class News_Api extends Horde_Registry_Api } /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return News::getMenu(); - } - - /** * Callback for comment API * - * @param int $id Internal data identifier - * @param string $type Type of data to retreive (title, owner...) - * @param array $params Additional parameters + * @param int $id Internal data identifier + * @param string $type Type of data to retreive (title, owner...) + * @param array $params Additional parameters */ public function commentCallback($id, $type = 'title', $params = null) { diff --git a/news/lib/Application.php b/news/lib/Application.php index 400bcff32..f109d93b5 100644 --- a/news/lib/Application.php +++ b/news/lib/Application.php @@ -13,4 +13,15 @@ class News_Application extends Horde_Registry_Application { public $version = 'H4 (0.1-git)'; + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return News::getMenu(); + } + } diff --git a/skeleton/lib/Api.php b/skeleton/lib/Api.php index b799261e1..542171af5 100644 --- a/skeleton/lib/Api.php +++ b/skeleton/lib/Api.php @@ -1,14 +1,4 @@ isLocked('default_dir')) { - require TURBA_BASE . '/config/sources.php'; - $out['default_dir_options'] = array(); - foreach ($cfgSources as $key => $info) { - $out['default_dir_options'][$key] = $info['title']; - } - } - - foreach (Turba::getAddressBooks() as $key => $curSource) { - if (empty($curSource['map']['__uid'])) { - continue; - } - if (!empty($curSource['browse'])) { - $GLOBALS['_prefs']['sync_books']['enum'][$key] = $curSource['title']; - } - $sync_books = @unserialize($GLOBALS['prefs']->getValue('sync_books')); - if (empty($sync_books)) { - $GLOBALS['prefs']->setValue('sync_books', serialize(array(Turba::getDefaultAddressbook()))); - } - } - - return $out; - } - - /** - * TODO - */ - public function prefsHandle($item, $updated) - { - switch ($item) { - case 'columnselect': - $columns = Horde_Util::getFormData('columns'); - if (!empty($columns)) { - $GLOBALS['prefs']->setValue('columns', $columns); - return true; - } - break; - - case 'addressbookselect': - $addressbooks = Horde_Util::getFormData('addressbooks'); - $GLOBALS['prefs']->setValue('addressbooks', str_replace("\r", '', $addressbooks)); - return true; - } - - return $updated; - } - - /** - * Generate the menu to use on the prefs page. - * - * @return Horde_Menu A Horde_Menu object. - */ - public function prefsMenu() - { - return Turba::getMenu(); - } - - /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/turba/lib/Application.php b/turba/lib/Application.php index 799240d0f..d176fc957 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -13,4 +13,78 @@ class Turba_Application extends Horde_Registry_Application */ public $version = 'H3 (3.0-git)'; + /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + * + * @return array A list of variables to export to the prefs display page. + */ + public function prefsInit($group) + { + $out = array(); + + /* Assign variables for select lists. */ + if (!$GLOBALS['prefs']->isLocked('default_dir')) { + require TURBA_BASE . '/config/sources.php'; + $out['default_dir_options'] = array(); + foreach ($cfgSources as $key => $info) { + $out['default_dir_options'][$key] = $info['title']; + } + } + + foreach (Turba::getAddressBooks() as $key => $curSource) { + if (empty($curSource['map']['__uid'])) { + continue; + } + if (!empty($curSource['browse'])) { + $GLOBALS['_prefs']['sync_books']['enum'][$key] = $curSource['title']; + } + $sync_books = @unserialize($GLOBALS['prefs']->getValue('sync_books')); + if (empty($sync_books)) { + $GLOBALS['prefs']->setValue('sync_books', serialize(array(Turba::getDefaultAddressbook()))); + } + } + + return $out; + } + + /** + * Special preferences handling on update. + * + * @param string $item The preference name. + * @param boolean $updated Set to true if preference was updated. + * + * @return boolean True if preference was updated. + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'columnselect': + $columns = Horde_Util::getFormData('columns'); + if (!empty($columns)) { + $GLOBALS['prefs']->setValue('columns', $columns); + return true; + } + break; + + case 'addressbookselect': + $addressbooks = Horde_Util::getFormData('addressbooks'); + $GLOBALS['prefs']->setValue('addressbooks', str_replace("\r", '', $addressbooks)); + return true; + } + + return $updated; + } + + /** + * Generate the menu to use on the prefs page. + * + * @return Horde_Menu A Horde_Menu object. + */ + public function prefsMenu() + { + return Turba::getMenu(); + } + } -- 2.11.0