Move RFC 2397 image data generation to Horde::
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 29 Jun 2009 05:38:20 +0000 (23:38 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 29 Jun 2009 05:38:20 +0000 (23:38 -0600)
imp/compose-dimp.php
imp/lib/IMP.php
imp/templates/chunks/message.php
imp/templates/index/index-dimp.inc

index 9d4f258..c96c0a7 100644 (file)
@@ -308,7 +308,7 @@ if ($get_sig && !empty($sig)) {
 $t = new IMP_Template(IMP_TEMPLATES . '/imp/');
 $t->setOption('gettext', true);
 $t->set('title', $title);
-$t->set('closelink', IMP::img('close.png', 'X', array('id' => 'compose_close'), $registry->getImageDir('horde')));
+$t->set('closelink', Horde::img('close.png', 'X', array('id' => 'compose_close'), $registry->getImageDir('horde')));
 
 $compose_result = IMP_Views_Compose::showCompose(array(
     'folder' => $folder,
index 7b6877d..b24750e 100644 (file)
@@ -1614,24 +1614,7 @@ class IMP
      */
     public function stylesheetCallback($matches)
     {
-        return $matches[1] . IMP::base64ImgData($matches[2]) . $matches[3];
-    }
-
-    /**
-     * TODO - Move to Horde core
-     */
-    public function base64ImgData($file)
-    {
-        /* Only encode image files if they are below 3,000 bytes. RFC 2397
-         * only requires support of up to 1,024 characters (base64 encoded,
-         * not the size of the image).  However, browsers that support data
-         * URLs generally support more. Opera seems to have the smallest
-         * allowance - 4100 characters - so use Opera as a limit. */
-        $filename = realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file);
-
-        return (filesize($filename) <= 3000)
-            ? 'data:image/' . substr($file, strrpos($file, '.') + 1) . ';base64,' . base64_encode(file_get_contents($filename))
-            : $file;
+        return $matches[1] . Horde::base64ImgData($matches[2]) . $matches[3];
     }
 
     /**
@@ -1720,64 +1703,6 @@ class IMP
     }
 
     /**
-     * Constructs a correctly-pathed link to an image.
-     * TODO - Move to Horde core
-     *
-     * @param string $src   The image file.
-     * @param string $alt   Text describing the image.
-     * @param mixed  $attr  Any additional attributes for the image tag. Can
-     *                      be a pre-built string or an array of key/value
-     *                      pairs that will be assembled and html-encoded.
-     * @param string $dir   The root graphics directory.
-     *
-     * @return string  The full image tag.
-     */
-    static public function img($src, $alt = '', $attr = '', $dir = null)
-    {
-        /* If browser does not support images, simply return the ALT text. */
-        if (!$GLOBALS['browser']->hasFeature('images') ||
-            !$GLOBALS['browser']->hasFeature('dataurl')) {
-            return Horde::img($src, $alt, $attr, $dir);
-        }
-
-        /* If no directory has been specified, get it from the registry. */
-        if (is_null($dir)) {
-            $dir = $GLOBALS['registry']->getImageDir();
-        }
-
-        /* If a directory has been provided, prepend it to the image source. */
-        if (!empty($dir)) {
-            $src = $dir . '/' . $src;
-        }
-
-        /* Build all of the tag attributes. */
-        $attributes = array('alt' => $alt);
-        if (is_array($attr)) {
-            $attributes = array_merge($attributes, $attr);
-        }
-        if (empty($attributes['title'])) {
-            $attributes['title'] = '';
-        }
-
-        $img = '<img';
-        $charset = NLS::getCharset();
-        $old_error = error_reporting(0);
-        foreach ($attributes as $attribute => $value) {
-            $img .= ' ' . $attribute . '="' . ($attribute == 'src' ? $value : htmlspecialchars($value, ENT_COMPAT, $charset)) . '"';
-        }
-        error_reporting($old_error);
-
-        /* If the user supplied a pre-built string of attributes, add that. */
-        if (is_string($attr) && !empty($attr)) {
-            $img .= ' ' . $attr;
-        }
-
-        /* Return the closed image tag. */
-        return $img . ' src="' . IMP::base64ImgData($src) . '" />';
-    }
-
-
-    /**
      * Do garbage collection in the statically served file directory.
      *
      * @param string $type  Either 'css' or 'js'.
index 1bbec47..8313d4e 100644 (file)
@@ -8,7 +8,7 @@
 
 $horde_img = $registry->getImageDir('horde');
 
-$close_img = IMP::img('close.png', 'X', array(), $horde_img);
+$close_img = Horde::img('close.png', 'X', array(), $horde_img);
 $menu_view = $prefs->getValue('menu_view');
 $show_text = ($menu_view == 'text' || $menu_view == 'both');
 
@@ -58,7 +58,7 @@ function _createDAfmsg($text, $image, $id, $class = '', $show_text = true)
    <div class="msgHeaders">
     <div id="msgHeaders">
      <div class="dimpOptions noprint">
-      <div id="msg_print"><?php echo IMP::img('print.png', '', '', $horde_img) ?><a><?php echo _("Print") ?></a></div>
+      <div id="msg_print"><?php echo Horde::img('print.png', '', '', $horde_img) ?><a><?php echo _("Print") ?></a></div>
 <?php if (!empty($conf['user']['allow_view_source'])): ?>
       <div id="msg_view_source"><span class="iconImg"></span><a><?php echo _("View Message Source") ?></a></div>
 <?php endif; ?>
index fcf44c6..5fa96ea 100644 (file)
@@ -40,8 +40,8 @@ function _simpleButton($id, $text, $image, $imagedir = null)
         . (strlen($id) ? ' id="' . $id . '"' : '')
         . (strlen($ak) ? ' accesskey="' . $ak . '"' : '') . '>'
         . ($imagedir
-            ? IMP::img($image, Horde::stripAccessKey($text), '', $imagedir)
-            : IMP::img($image, Horde::stripAccessKey($text)))
+            ? Horde::img($image, Horde::stripAccessKey($text), '', $imagedir)
+            : Horde::img($image, Horde::stripAccessKey($text)))
         . '<a>'
         . Horde::highlightAccessKey($text, $ak) . '</a></li>';
 }
@@ -179,7 +179,7 @@ function _simpleButton($id, $text, $image, $imagedir = null)
         <input autocomplete="off" id="qsearch_input" type="text" size="25" />
        </form>
        <span>
-        <?php echo IMP::img('close.png', '', array('id' => 'qsearch_close', 'style' => 'display:none', 'title' => _("Clear Search")), $hordeimg) ?>
+        <?php echo Horde::img('close.png', '', array('id' => 'qsearch_close', 'style' => 'display:none', 'title' => _("Clear Search")), $hordeimg) ?>
        </span>
       </div>
       <span>
@@ -271,7 +271,7 @@ function _simpleButton($id, $text, $image, $imagedir = null)
         <div id="msgHeaders" style="display:none">
          <div class="dimpOptions noprint">
           <div id="msg_newwin_options"><span class="iconImg"></span><a><?php echo _("Open in new window") ?></a></div>
-          <div id="msg_print"><?php echo IMP::img('print.png', '', '', $hordeimg) ?><a><?php echo _("Print") ?></a></div>
+          <div id="msg_print"><?php echo Horde::img('print.png', '', '', $hordeimg) ?><a><?php echo _("Print") ?></a></div>
 <?php if (!empty($conf['user']['allow_view_source'])): ?>
           <div id="msg_view_source"><span class="iconImg"></span><a><?php echo _("View Message Source") ?></a></div>
 <?php endif; ?>