Mnemo: convert to class constants
authorBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 02:28:51 +0000 (22:28 -0400)
committerBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 02:28:51 +0000 (22:28 -0400)
mnemo/config/prefs.php.dist
mnemo/lib/Api.php
mnemo/lib/Driver/kolab.php
mnemo/lib/Driver/sql.php
mnemo/lib/Mnemo.php
mnemo/memo.php
mnemo/templates/list/memo_headers.inc
mnemo/view.php

index b1b37c3..916c3fa 100644 (file)
@@ -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:")
 );
index 1df7a5f..3cc704e 100644 (file)
@@ -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.
index a2f2091..6cbe7d1 100644 (file)
@@ -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);
index b2ee2b6..a829963 100644 (file)
@@ -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);
index a4da090..c2b3c77 100644 (file)
  */
 
 /**
- * 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 <jon@horde.org>
@@ -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]));
         }
 
index 9bab912..e3e50b2 100644 (file)
@@ -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;
index e21b811..deb98ca 100644 (file)
@@ -29,16 +29,16 @@ function doPrefsUpdate(column, sortDown)
  <tr class="item leftAlign">
   <th class="nosort" width="3%"><?php echo Horde::img('edit.png', _("Edit Note"), '') ?></th>
 <?php if ($showNotepad): ?>
-  <th id="s<?php echo MNEMO_SORT_NOTEPAD ?>"<?php if ($sortby == MNEMO_SORT_NOTEPAD) echo ' class="' . $sortdirclass . '"' ?> width="2%">
-   <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($baseurl, 'sortby', MNEMO_SORT_NOTEPAD)), _("Sort by Notepad"), 'sortlink', '', '', _("Notepad")) ?>&nbsp;
+  <th id="s<?php echo Mnemo::SORT_NOTEPAD ?>"<?php if ($sortby == Mnemo::SORT_NOTEPAD) echo ' class="' . $sortdirclass . '"' ?> width="2%">
+   <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($baseurl, 'sortby', Mnemo::SORT_NOTEPAD)), _("Sort by Notepad"), 'sortlink', '', '', _("Notepad")) ?>&nbsp;
   </th>
 <?php endif; ?>
-  <th id="s<?php echo MNEMO_SORT_DESC ?>"<?php if ($sortby == MNEMO_SORT_DESC) echo ' class="' . $sortdirclass . '"' ?> width="82%">
-    <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter('list.php', 'sortby', MNEMO_SORT_DESC)), _("Sort by Note Text"), 'sortlink', '', '', _("No_te")) ?>
+  <th id="s<?php echo Mnemo::SORT_DESC ?>"<?php if ($sortby == Mnemo::SORT_DESC) echo ' class="' . $sortdirclass . '"' ?> width="82%">
+    <?php echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter('list.php', 'sortby', Mnemo::SORT_DESC)), _("Sort by Note Text"), 'sortlink', '', '', _("No_te")) ?>
   </th>
-  <th id="s<?php echo MNEMO_SORT_CATEGORY ?>"<?php if ($sortby == MNEMO_SORT_CATEGORY) echo ' class="' . $sortdirclass . '"' ?> width="15%">
+  <th id="s<?php echo Mnemo::SORT_CATEGORY ?>"<?php if ($sortby == Mnemo::SORT_CATEGORY) echo ' class="' . $sortdirclass . '"' ?> width="15%">
     <?php
-    echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter('list.php', 'sortby', MNEMO_SORT_CATEGORY)), _("Sort by Category"), 'sortlink', '', '', _("_Category"));
+    echo Horde::widget(Horde::applicationUrl(Horde_Util::addParameter('list.php', 'sortby', Mnemo::SORT_CATEGORY)), _("Sort by Category"), 'sortlink', '', '', _("_Category"));
     if (Horde_Auth::getAuth() && (!$GLOBALS['prefs']->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'));
index 49fd281..e7a4249 100644 (file)
@@ -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;