From 96cf8a5b3949868fc1cf04b2a89af22ba76c7a1f Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 17 May 2010 22:28:51 -0400 Subject: [PATCH] Mnemo: convert to class constants --- mnemo/config/prefs.php.dist | 12 ++--- mnemo/lib/Api.php | 6 +-- mnemo/lib/Driver/kolab.php | 4 +- mnemo/lib/Driver/sql.php | 4 +- mnemo/lib/Mnemo.php | 87 +++++++++++++++++------------------ mnemo/memo.php | 4 +- mnemo/templates/list/memo_headers.inc | 12 ++--- mnemo/view.php | 4 +- 8 files changed, 66 insertions(+), 67 deletions(-) diff --git a/mnemo/config/prefs.php.dist b/mnemo/config/prefs.php.dist index b1b37c326..916c3fa50 100644 --- a/mnemo/config/prefs.php.dist +++ b/mnemo/config/prefs.php.dist @@ -42,12 +42,12 @@ $_prefs['show_panel'] = array( // user preferred sorting column $_prefs['sortby'] = array( - 'value' => MNEMO_SORT_DESC, + 'value' => Mnemo::SORT_DESC, 'type' => 'enum', 'enum' => array( - MNEMO_SORT_DESC => _("Note Text"), - MNEMO_SORT_CATEGORY => _("Note Category"), - MNEMO_SORT_NOTEPAD => _("Notepad") + Mnemo::SORT_DESC => _("Note Text"), + Mnemo::SORT_CATEGORY => _("Note Category"), + Mnemo::SORT_NOTEPAD => _("Notepad") ), 'desc' => _("Default sorting criteria:") ); @@ -57,8 +57,8 @@ $_prefs['sortdir'] = array( 'value' => 0, 'type' => 'enum', 'enum' => array( - MNEMO_SORT_ASCEND => _("Ascending"), - MNEMO_SORT_DESCEND => _("Descending") + Mnemo::SORT_ASCEND => _("Ascending"), + Mnemo::SORT_DESCEND => _("Descending") ), 'desc' => _("Default sorting direction:") ); diff --git a/mnemo/lib/Api.php b/mnemo/lib/Api.php index 1df7a5f2d..3cc704e5e 100644 --- a/mnemo/lib/Api.php +++ b/mnemo/lib/Api.php @@ -376,8 +376,8 @@ function _mnemo_export($uid, $contentType) } if (is_a($memo['body'], 'PEAR_Error')) { - if ($memo['body']->getCode() == MNEMO_ERR_NO_PASSPHRASE || - $memo['body']->getCode() == MNEMO_ERR_DECRYPT) { + if ($memo['body']->getCode() == Mnemo::ERR_NO_PASSPHRASE || + $memo['body']->getCode() == Mnemo::ERR_DECRYPT) { $memo['body'] = _("This note has been encrypted."); } else { return $memo['body']; @@ -395,7 +395,7 @@ function _mnemo_export($uid, $contentType) // Create the new iCalendar container. $iCal = new Horde_iCalendar('1.1'); $iCal->setAttribute('VERSION', '1.1'); - $iCal->setAttribute('PRODID', '-//The Horde Project//Mnemo ' . MNEMO_VERSION . '//EN'); + $iCal->setAttribute('PRODID', '-//The Horde Project//Mnemo ' . Mnemo::VERSION . '//EN'); $iCal->setAttribute('METHOD', 'PUBLISH'); // Create a new vNote. diff --git a/mnemo/lib/Driver/kolab.php b/mnemo/lib/Driver/kolab.php index a2f2091b2..6cbe7d1ca 100644 --- a/mnemo/lib/Driver/kolab.php +++ b/mnemo/lib/Driver/kolab.php @@ -763,11 +763,11 @@ class Mnemo_Driver_kolab_wrapper_new extends Mnemo_Driver_kolab_wrapper { $passphrase = Mnemo::getPassphrase($note['uid']); } if (empty($passphrase)) { - $body = PEAR::raiseError(_("This note has been encrypted."), MNEMO_ERR_NO_PASSPHRASE); + $body = PEAR::raiseError(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE); } else { $body = $this->decrypt($body, $passphrase); if (is_a($body, 'PEAR_Error')) { - $body->code = MNEMO_ERR_DECRYPT; + $body->code = Mnemo::ERR_DECRYPT; } else { $body = $body->message; Mnemo::storePassphrase($note['memo_id'], $passphrase); diff --git a/mnemo/lib/Driver/sql.php b/mnemo/lib/Driver/sql.php index b2ee2b62e..a829963f2 100644 --- a/mnemo/lib/Driver/sql.php +++ b/mnemo/lib/Driver/sql.php @@ -450,11 +450,11 @@ class Mnemo_Driver_sql extends Mnemo_Driver { $passphrase = Mnemo::getPassphrase($row['memo_id']); } if (empty($passphrase)) { - $body = PEAR::raiseError(_("This note has been encrypted."), MNEMO_ERR_NO_PASSPHRASE); + $body = PEAR::raiseError(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE); } else { $body = $this->decrypt($body, $passphrase); if (is_a($body, 'PEAR_Error')) { - $body->code = MNEMO_ERR_DECRYPT; + $body->code = Mnemo::ERR_DECRYPT; } else { $body = $body->message; Mnemo::storePassphrase($row['memo_id'], $passphrase); diff --git a/mnemo/lib/Mnemo.php b/mnemo/lib/Mnemo.php index a4da090b0..c2b3c7780 100644 --- a/mnemo/lib/Mnemo.php +++ b/mnemo/lib/Mnemo.php @@ -11,41 +11,6 @@ */ /** - * Sort by memo description. - */ -define('MNEMO_SORT_DESC', 0); - -/** - * Sort by memo category. - */ -define('MNEMO_SORT_CATEGORY', 1); - -/** - * Sort by notepad. - */ -define('MNEMO_SORT_NOTEPAD', 2); - -/** - * Sort in ascending order. - */ -define('MNEMO_SORT_ASCEND', 0); - -/** - * Sort in descending order. - */ -define('MNEMO_SORT_DESCEND', 1); - -/** - * No passphrase provided. - */ -define('MNEMO_ERR_NO_PASSPHRASE', 100); - -/** - * Decrypting failed - */ -define('MNEMO_ERR_DECRYPT', 101); - -/** * Mnemo Base Class. * * @author Jon Parise @@ -53,31 +18,65 @@ define('MNEMO_ERR_DECRYPT', 101); * @package Mnemo */ class Mnemo { + /** + * Sort by memo description. + */ + const SORT_DESC = 0; + + /** + * Sort by memo category. + */ + const SORT_CATEGORY = 1; + + /** + * Sort by notepad. + */ + const SORT_NOTEPAD = 2; + + /** + * Sort in ascending order. + */ + const SORT_ASCEND = 0; + + /** + * Sort in descending order. + */ + const SORT_DESCEND = 1; + + /** + * No passphrase provided. + */ + const ERR_NO_PASSPHRASE = 100; + + /** + * Decrypting failed + */ + const ERR_DECRYPT = 101; /** * Retrieves the current user's note list from storage. This function will * also sort the resulting list, if requested. * - * @param constant $sortby The field by which to sort. (MNEMO_SORT_DESC, - * MNEMO_SORT_CATEGORY, MNEMO_SORT_NOTEPAD) + * @param constant $sortby The field by which to sort. (self::SORT_DESC, + * self::SORT_CATEGORY, self::SORT_NOTEPAD) * @param constant $sortdir The direction by which to sort. - * (MNEMO_SORT_ASC, MNEMO_SORT_DESC) + * (self::SORT_ASC, self::SORT_DESC) * * @return array A list of the requested notes. * * @see Mnemo_Driver::listMemos() */ - public static function listMemos($sortby = MNEMO_SORT_DESC, - $sortdir = MNEMO_SORT_ASCEND) + public static function listMemos($sortby = self::SORT_DESC, + $sortdir = self::SORT_ASCEND) { global $conf, $display_notepads; $memos = array(); /* Sort the memo list. */ $sort_functions = array( - MNEMO_SORT_DESC => 'ByDesc', - MNEMO_SORT_CATEGORY => 'ByCategory', - MNEMO_SORT_NOTEPAD => 'ByNotepad', + self::SORT_DESC => 'ByDesc', + self::SORT_CATEGORY => 'ByCategory', + self::SORT_NOTEPAD => 'ByNotepad', ); foreach ($display_notepads as $notepad) { @@ -93,7 +92,7 @@ class Mnemo { /* Sort the array if we have a sort function defined for this * field. */ if (isset($sort_functions[$sortby])) { - $prefix = ($sortdir == MNEMO_SORT_DESCEND) ? '_rsort' : '_sort'; + $prefix = ($sortdir == self::SORT_DESCEND) ? '_rsort' : '_sort'; uasort($memos, array('Mnemo', $prefix . $sort_functions[$sortby])); } diff --git a/mnemo/memo.php b/mnemo/memo.php index 9bab912c9..e3e50b2e9 100644 --- a/mnemo/memo.php +++ b/mnemo/memo.php @@ -26,7 +26,7 @@ function showPassphrase($memo) /* Check for secure connection. */ $secure_check = Horde::isConnectionSecure(); - if ($memo['body']->getCode() == MNEMO_ERR_NO_PASSPHRASE) { + if ($memo['body']->getCode() == Mnemo::ERR_NO_PASSPHRASE) { if ($secure_check) { $notification->push(_("This note has been encrypted, please provide the password below"), 'horde.message'); return true; @@ -36,7 +36,7 @@ function showPassphrase($memo) return false; } - if ($memo['body']->getCode() == MNEMO_ERR_DECRYPT) { + if ($memo['body']->getCode() == Mnemo::ERR_DECRYPT) { if ($secure_check) { $notification->push(_("This note cannot be decrypted:") . ' ' . $memo['body']->getMessage(), 'horde.message'); return true; diff --git a/mnemo/templates/list/memo_headers.inc b/mnemo/templates/list/memo_headers.inc index e21b8118d..deb98caca 100644 --- a/mnemo/templates/list/memo_headers.inc +++ b/mnemo/templates/list/memo_headers.inc @@ -29,16 +29,16 @@ function doPrefsUpdate(column, sortDown) - width="2%"> -   + width="2%"> +   - width="82%"> - + width="82%"> + - width="15%"> + width="15%"> isLocked('categories') || !$GLOBALS['prefs']->isLocked('category_colors'))) { $categoryUrl = Horde_Util::addParameter(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/prefs.php'), array('app' => 'horde', 'group' => 'categories')); diff --git a/mnemo/view.php b/mnemo/view.php index 49fd2817d..e7a4249ae 100644 --- a/mnemo/view.php +++ b/mnemo/view.php @@ -93,7 +93,7 @@ $show_passphrase = false; if (is_a($memo['body'], 'PEAR_Error')) { /* Check for secure connection. */ $secure_check = Horde::isConnectionSecure(); - if ($memo['body']->getCode() == MNEMO_ERR_NO_PASSPHRASE) { + if ($memo['body']->getCode() == Mnemo::ERR_NO_PASSPHRASE) { if ($secure_check) { $notification->push(_("This note has been encrypted, please provide the password below"), 'horde.message'); $show_passphrase = true; @@ -101,7 +101,7 @@ if (is_a($memo['body'], 'PEAR_Error')) { $notification->push(_("This note has been encrypted, and cannot be decrypted without a secure web connection"), 'horde.error'); $memo['body'] = ''; } - } elseif ($memo['body']->getCode() == MNEMO_ERR_DECRYPT) { + } elseif ($memo['body']->getCode() == Mnemo::ERR_DECRYPT) { if ($secure_check) { $notification->push(_("This note cannot be decrypted:") . ' ' . $memo['body']->getMessage(), 'horde.message'); $show_passphrase = true; -- 2.11.0