? textimage-cache.patch
Index: textimage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/textimage/textimage.module,v
retrieving revision 1.14
diff -u -F^f -r1.14 textimage.module
--- textimage.module	22 Jan 2007 14:10:34 -0000	1.14
+++ textimage.module	29 Jul 2007 15:31:56 -0000
@@ -8,14 +8,14 @@
 /**
 * Implementation of hook_help().
 */
-function textimage_help($section) {
-  $output = "";
-
-  switch ($section) {
+function textimage_help($section) {
+  $output = "";
+
+  switch ($section) {
     case 'admin/help#textimage':
-      $output .= '<h2 id="textimage-introduction">The dynamic text to image generator!</h2>';
+      $output .= '<h2 id="textimage-introduction">The dynamic text to image generator!</h2>';
       $output .= '<p>Text image is a module which allows you to create dynamic images using any font installed on the server.</p>';
-      $output .= '<p>Creating images from text has several important advantages and disadvantages. The greatest advantage is it allows you to use any font you wish for headlines and titles without the user needing to install the font. Another advantage is the wide browser support for images and available accessibility features (alt and title tags for instance), so screen readers should be able to handle your images without problem. You might also prefer text images over the <a href="http://www.mikeindustries.com/sifr/">sIFR approach</a> because generated images are not disabled by many ad-blocking tools. However, an important limitation of Text Image module is wrapping of text, which it does not currently support and cannot compete with the dynamic abilities of a Flash based solution. If you need to create images with wrapped text, sIFR may be a better solution.</p>';
+      $output .= '<p>Creating images from text has several important advantages and disadvantages. The greatest advantage is it allows you to use any font you wish for headlines and titles without the user needing to install the font. Another advantage is the wide browser support for images and available accessibility features (alt and title tags for instance), so screen readers should be able to handle your images without problem. You might also prefer text images over the <a href="http://www.mikeindustries.com/sifr/">sIFR approach</a> because generated images are not disabled by many ad-blocking tools. However, an important limitation of Text Image module is wrapping of text, which it does not currently support and cannot compete with the dynamic abilities of a Flash based solution. If you need to create images with wrapped text, sIFR may be a better solution.</p>';
       $output .= '<h2>Installing Fonts</h2>';
       $output .= '<p>Text image is dependent on the GD2 library for text manipulations. You can check what version of GD you have on the <a href="!config">Text Image configuration page</a>. Before you can begin using Text Image you must upload at least one TrueType font to the server and tell Text Image where you uploaded it. All fonts must have the .tff extension to be seen by Text Image. If you do not have any TTF fonts to start using Text Image, you can download some free GNU fonts from the <a href="http://savannah.nongnu.org/projects/freefont/">Free UCS Outline Fonts Project</a>. Once the fonts are uploaded, enter the UNIX-style path the fonts on the <a href="!config">configuration page</a>. If you are using Text Image with the Captcha module, you\'ll also need to set a seperate directory on the <a href="!captcha">Text Image Captcha Settings</a> for fonts to be used at random.</p>';
       $output .= '<h2 id="textimage-configuration">Configuration</h2>';
@@ -37,21 +37,21 @@ function textimage_help($section) {
         '!example2' => base_path() . drupal_get_path('module', 'textimage') . '/misc/example2.png',
         '!example3' => base_path() . drupal_get_path('module', 'textimage') . '/misc/example3.png',
       ));
-      break;
-    case 'admin/build/modules#description':
-    case 'admin/build/modules/textimage':
-    case 'admin/settings/textimage':
-      $output = t('Provides text to image manipulations and image based captcha challenge (with Captcha module).');
-      break;
-  }
-  return $output;
-}
-
-/**
-* Implementation of hook_menu().
-*/
-function textimage_menu($may_cache) {
-  $items = array();
+      break;
+    case 'admin/build/modules#description':
+    case 'admin/build/modules/textimage':
+    case 'admin/settings/textimage':
+      $output = t('Provides text to image manipulations and image based captcha challenge (with Captcha module).');
+      break;
+  }
+  return $output;
+}
+
+/**
+* Implementation of hook_menu().
+*/
+function textimage_menu($may_cache) {
+  $items = array();
   
   if ($may_cache) {
     $items[] = array(
@@ -116,7 +116,7 @@ function textimage_menu($may_cache) {
         'weight' => 5,
         'type' => MENU_LOCAL_TASK
       );
-    }
+    }
   }
   else {
     $suffix = arg(2) != null ? '/' . arg(2) : '';
@@ -142,16 +142,16 @@ function textimage_menu($may_cache) {
       'access' => user_access('administer site configuration'),
       'type' => MENU_CALLBACK,
     );
-  }
-  return $items;
-}
+  }
+  return $items;
+}
 
 /**
 * Implementation of hook_perm().
-*/
-function textimage_perm() {
-  return array('access textimages');
-}
+*/
+function textimage_perm() {
+  return array('access textimages');
+}
 
 function textimage_settings_form() {
   $form = array();
@@ -551,11 +551,14 @@ function textimage_preset_flush_confirm_
 }
 
 function textimage_get_presets() {
-  $result = db_query('SELECT pid, name, settings FROM {textimage_preset}');
-  $presets = array();
-  while ($preset = db_fetch_array($result)) {
-    $preset['settings'] = unserialize($preset['settings']);
-    $presets[$preset['name']] = $preset;
+  static $presets;
+  if (empty($presets)) {
+    $result = db_query('SELECT pid, name, settings FROM {textimage_preset}');
+    $presets = array();
+    while ($preset = db_fetch_array($result)) {
+      $preset['settings'] = unserialize($preset['settings']);
+      $presets[$preset['name']] = $preset;
+    }
   }
   return $presets;
 }
@@ -991,22 +994,22 @@ function _textimage_recursive_delete($pa
   }
   @rmdir($path);
 }
-
-/**
-* Returns an array of files with TTF extensions in the specified directory.
-*/
-function _textimage_font_list($fontdir) {
-  $filelist = array();
-  if (is_dir($fontdir) && $handle = opendir($fontdir)) {
-    while ($file = readdir($handle)) {
-      if (preg_match("/\.ttf$/i",$file) == 1)
-        $filelist[] = $file;
-    }
-    closedir($handle);
-  }
-
-  return $filelist;
-}
+
+/**
+* Returns an array of files with TTF extensions in the specified directory.
+*/
+function _textimage_font_list($fontdir) {
+  $filelist = array();
+  if (is_dir($fontdir) && $handle = opendir($fontdir)) {
+    while ($file = readdir($handle)) {
+      if (preg_match("/\.ttf$/i",$file) == 1)
+        $filelist[] = $file;
+    }
+    closedir($handle);
+  }
+
+  return $filelist;
+}
 
 function _textimage_number_validate($field, $field_name) {
   if (!empty($field['#value']) && !is_numeric($field['#value'])) {
@@ -1020,42 +1023,42 @@ function _textimage_hex_validate($field,
   }
 }
 
-/**
-* Returns an array of files with jpg, png, and gif extensions in the specified directory.
-*/
-function _textimage_image_list($imagesdir) {
-  $filelist = array();
-  if (is_dir($imagesdir) && $handle = opendir($imagesdir)) {
-    while ($file = readdir($handle)) {
-      if (preg_match("/\.gif|\.png|\.jpg$/i",$file) == 1)
-        $filelist[] = $imagesdir.'/'.$file;
-    }
-    closedir($handle);
-  }
-
-  return $filelist;
-}
-
-/**
-* Creates transparent image resources for images with graphic backgrounds
-*/
-function _textimage_create_transparent_image($x, $y) {
-  $i = imagecreatetruecolor($x, $y);
-  $b = imagecreatefromstring(base64_decode(_textimage_blankpng()));
-  imagealphablending($i, false);
-  imagesavealpha($i, true);
-  imagecopyresized($i, $b ,0 ,0 ,0 ,0 ,$x, $y, imagesx($b), imagesy($b));
-  return $i;
-}
- 
-function _textimage_blankpng() {
-  $c  = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m";
-  $c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg";
-  $c .= "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN";
-  $c .= "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ";
-  $c .= "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA";
-  $c .= "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
-  return $c;
+/**
+* Returns an array of files with jpg, png, and gif extensions in the specified directory.
+*/
+function _textimage_image_list($imagesdir) {
+  $filelist = array();
+  if (is_dir($imagesdir) && $handle = opendir($imagesdir)) {
+    while ($file = readdir($handle)) {
+      if (preg_match("/\.gif|\.png|\.jpg$/i",$file) == 1)
+        $filelist[] = $imagesdir.'/'.$file;
+    }
+    closedir($handle);
+  }
+
+  return $filelist;
+}
+
+/**
+* Creates transparent image resources for images with graphic backgrounds
+*/
+function _textimage_create_transparent_image($x, $y) {
+  $i = imagecreatetruecolor($x, $y);
+  $b = imagecreatefromstring(base64_decode(_textimage_blankpng()));
+  imagealphablending($i, false);
+  imagesavealpha($i, true);
+  imagecopyresized($i, $b ,0 ,0 ,0 ,0 ,$x, $y, imagesx($b), imagesy($b));
+  return $i;
+}
+ 
+function _textimage_blankpng() {
+  $c  = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m";
+  $c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg";
+  $c .= "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN";
+  $c .= "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ";
+  $c .= "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA";
+  $c .= "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
+  return $c;
 }
 
 /**
