Add preference to define default font family/size for the HTML compose editor
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Jul 2010 00:26:36 +0000 (18:26 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Jul 2010 00:34:19 +0000 (18:34 -0600)
Essentially makes HTML compose mode a WYSIWYG editor, since it now will
send th message using the same default font as appears on the screen.

imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Compose.php
imp/lib/Prefs/Ui.php
imp/lib/Ui/Compose.php

index a17d91f..6f4f328 100644 (file)
@@ -392,7 +392,8 @@ $prefGroups['compose'] = array(
     'members' => array(
         'stationery_link', 'mailto_handler', 'compose_cc', 'compose_bcc',
         'compose_spellcheck', 'compose_confirm', 'set_priority',
-        'compose_popup', 'compose_html', 'mail_domain', 'compose_cursor',
+        'compose_popup', 'compose_html', 'compose_html_font_family',
+        'compose_html_font_size', 'mail_domain', 'compose_cursor',
         'sending_charset', 'encryptselect', 'save_attachments',
         'disposition_request_read'
     )
@@ -469,6 +470,25 @@ $_prefs['compose_html'] = array(
     'desc' => _("Compose messages with an HTML editor by default?")
 );
 
+// For the HTML editor, this is the default font family.
+// This needs to be in CSS-parseable format.
+$_prefs['compose_html_font_family'] = array(
+    'value' => 'Arial',
+    'advanced' => true,
+    'locked' => true,
+    'type' => 'string',
+    'desc' => _("The default font family to use in the HTML editor.")
+);
+
+// For the HTML editor, this is the default font size.
+$_prefs['compose_html_font_size'] = array(
+    'value' => 14,
+    'advanced' => true,
+    'locked' => true,
+    'type' => 'number',
+    'desc' => _("The default font size to use in the HTML editor (in pixels).")
+);
+
 // default outgoing mail domain and address completion
 $_prefs['mail_domain'] = array(
     'value' => '',
index 79255de..532f176 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Add preference to define default font family/size for the HTML compose
+      editor.
 [mms] Honor nav_expanded preference (DIMP).
 [mms] Allow admin to define list of safe e-mail addresses that will not
       experience HTML image blocking (Request #9129).
index 22a876a..48dc42a 100644 (file)
@@ -1072,6 +1072,24 @@ class IMP_Compose
             $htmlBody->setCharset($charset);
             $htmlBody->setDisposition('inline');
             $htmlBody->setDescription(Horde_String::convertCharset(_("HTML Version"), $nls_charset, $charset));
+
+            /* Add default font CSS information here. The data comes to us
+             * with no HTML body tag - so simply wrap the data in a body
+             * tag with the CSS information. */
+            $styles = array();
+            if ($font_family = $GLOBALS['prefs']->getValue('compose_html_font_family')) {
+                $styles[] = 'font-family:' . $font_family;
+            }
+            if ($font_size = intval($GLOBALS['prefs']->getValue('compose_html_font_size'))) {
+                $styles[] = 'font-size:' . $font_size . 'px';
+            }
+
+            if (!empty($styles)) {
+                $body_html = '<body style="' . implode(';', $styles) . '">' .
+                    $body_html .
+                    '</body>';
+            }
+
             $htmlBody->setContents($GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($body_html, 'cleanhtml', array('charset' => $charset)));
 
             $textBody->setDescription(Horde_String::convertCharset(_("Plaintext Version"), $nls_charset, $charset));
index 5e8217a..e2d58e9 100644 (file)
@@ -87,6 +87,11 @@ class IMP_Prefs_Ui
                 $ui->suppress[] = 'disposition_request_read';
             }
 
+            if (!$prefs->getValue('compose_html')) {
+                $ui->suppress[] = 'compose_html_font_family';
+                $ui->suppress[] = 'compose_html_font_size';
+            }
+
             /* Sort encodings. */
             if (!$prefs->isLocked('sending_charset')) {
                 asort($registry->nlsconfig['encodings']);
index 26f8e84..0df1b8e 100644 (file)
@@ -149,6 +149,18 @@ class IMP_Ui_Compose
     {
         $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('Ckeditor', array('basic' => $basic));
 
+        $font_family = $GLOBALS['prefs']->getValue('compose_html_font_family');
+        if (!$font_family) {
+            $font_family = 'Arial';
+        }
+
+        $font_size = intval($GLOBALS['prefs']->getValue('compose_html_font_size'));
+        $font_size = $font_size
+            /* Font size should be between 8 and 24 pixels. Or else recipients
+             * will hate us. Default to 14px. */
+            ? min(24, max(8, $font_size)) . 'px'
+            : '14px';
+
         $config = array(
             /* To more closely match "normal" textarea behavior, send <BR> on
              * enter instead of <P>. */
@@ -174,9 +186,9 @@ class IMP_Ui_Compose
 
             /* Default display font. This is NOT the font used to send
              * the message, however. */
-            'contentsCss: "body { font-family: Arial; font-size: 12px; }"',
-            'font_defaultLabel: "Arial"',
-            'fontSize_defaultLabel: "12px"'
+            'contentsCss: "body { font-family: ' . $font_family . '; font-size: ' . $font_size . '; }"',
+            'font_defaultLabel: "' . $font_family . '"',
+            'fontSize_defaultLabel: "' . $font_size . '"'
         );
 
         $buttons = $GLOBALS['prefs']->getValue('ckeditor_buttons');