--- C:/Documents and Settings/John/Bureau/textimage-6.x-2.1/textimage/textimage.module Fri Feb 13 00:14:50 2009 +++ C:/www/website/mdelec/sites/all/modules/textimage/textimage.module Sat Sep 26 10:48:27 2009 @@ -120,6 +120,7 @@ 'title' => '', 'attributes' => array(), 'getsize' => TRUE, + 'image' => TRUE, ), ), ); @@ -224,6 +225,86 @@ } /** + * Implementation of hook_filter(). + */ +function textimage_filter($op, $delta = 0, $format = -1, $text = '') { + switch ($op) { + case 'list': + include_once('./'. drupal_get_path('module', 'textimage') .'/textimage_admin.inc'); + + $filters = array(); + foreach (textimage_get_presets() as $preset) { + if (isset($preset->settings['pattern']) && !empty($preset->settings['pattern'])) { + $filters[$preset->pid] = $preset->name; + } + } + + return $filters; + + case 'description': + $preset = _textimage_preset_load($delta); + return t("Replaces anything matching the regular expression: %pattern with the image generated by the '%presetname' textimage preset.", array('%pattern' => $preset['settings']['pattern'], '%presetname' => $preset->name)); + + case "process": + $preset = _textimage_preset_load($delta); + return preg_replace($preset['settings']['pattern'] .'Ue', 'textimage_title_convert($preset, "$0")', $text); + + case 'no cache': + return TRUE; + + default: + return $text; + } +} + +/** + * Implementation of hook_filter_tips(). + */ +function textimage_filter_tips($delta, $format, $long = FALSE) { + $preset = _textimage_preset_load($delta); + if ($long) { + return t('The textimage filter will replace headings matching the regular expression %pattern with images according to the settings of the textimage preset %presetname.', array('%pattern' => $preset['settings']['pattern'], '@preset-admin-url' => url('admin/settings/textimage/preset/'. $preset->pid . '/edit'), '%presetname' => $preset->name)); + } + else { + return t("The textimage filter '%presetname' is enabled.", array('%presetname' => $preset->name)); + } +} + +function _textimage_strip_tags($text) { + return preg_replace('/<\/?(i|b|em|strong)>/', '', $text); +} + +function _textimage_strip_accent($text) { + // Decode utf8 + $text = utf8_decode($text); + + // Create conversion arrays + $with = array('À','Á','Â','Ã','Ä','Å','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý','à','á','â','ã','ä','å','ç','è','é','ê','ë','ì','í','î','ï','ð','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ'); + $none = array('A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','O','O','O','O','O','U','U','U','U','Y','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','o','o','o','o','o','o','u','u','u','u','y','y'); + + // Replace and utf8 encode + return utf8_encode(str_replace($with, $none, $text)); +} + +/** + * Turn a title into a textimage image. + */ +function textimage_title_convert($preset, $title) { + // Remove escapes from single quotes + $title = preg_replace("/\\\'/","'", $title); + $title = _textimage_strip_tags($title); + + // Get plain text + preg_match('/^(<.*?>)*([^<]*)(<.*?>)*($)/s', $title, $matches); + + // Get path of image + $path = theme('textimage_image', $preset['pid'], $matches[2], array(), 'png', '', '', array(), TRUE, FALSE); + + // Set title + return '
' . $title . '
'; +} + +/** * Menu Callback function converts the current textimage path into an image. On * first request, the image is returned to the browser from Drupal and then * saved to the disk. On subsequent requests (with Clean URLs enabled), the @@ -247,7 +328,10 @@ * */ function textimage_image() { - $args = explode('/', str_replace(base_path() . file_directory_path() .'/textimage/', '', request_uri())); + global $language; + + + $args = explode('/', substr(request_uri(), stripos(request_uri(), file_directory_path() . '/textimage/') + strlen(file_directory_path() . '/textimage/'))); // @TODO - Add support for non-clean urls. $preset = array_shift($args); @@ -272,7 +356,11 @@ if (!$img = textimage_build_image('url', $preset, $text, $additional_text, $format)) { return FALSE; } - + + // Remove language for avoiding problem with goto and language prefix + $language->prefix = ''; + $language->domain = ''; + drupal_goto($img); } @@ -323,7 +411,7 @@ elseif (!$result) { drupal_access_denied(); - return FALSE; + exit; } else { @@ -385,6 +473,10 @@ // Convert text case switch ($case) { + case 'upper_noaccent' : + $text = _textimage_strip_accent($text); + // No break here so handled by upper after + case 'upper': $text = drupal_strtoupper($text); break; @@ -403,13 +495,8 @@ } // Generate the textimage - $img = textimage_text_to_image($text, $size, $font, $color, $back_color, $angle, $maximum_width, $fixed_width, $align); - - // Add margin - if ($margin_top || $margin_right || $margin_bottom || $margin_left) { - $img = textimage_image_add_margin($img, $margin_top, $margin_right, $margin_bottom, $margin_left, $back_color); - } - + $img = textimage_text_to_image($text, $size, $font, $color, $back_color, $angle, $maximum_width, $fixed_width, $align, $margin_top, $margin_right, $margin_bottom, $margin_left); + // Add a border if ($stroke_width && $stroke_color) { $img = textimage_image_add_stroke($img, $stroke_width, $stroke_color); @@ -653,7 +740,7 @@ * @return $image * A GD image resource. */ -function textimage_text_to_image($text, $fontsize, $font, $foreground_color = '#000000', $background_color = NULL, $angle = 0, $maximum_width = 0, $fixed_width = 0, $align = ALIGN_LEFT) { +function textimage_text_to_image($text, $fontsize, $font, $foreground_color = '#000000', $background_color = NULL, $angle = 0, $maximum_width = 0, $fixed_width = 0, $align = ALIGN_LEFT, $margin_top = 0, $margin_right = 0, $margin_bottom = 0, $margin_left = 0) { // Set rotation angle. $q_angle = -$angle; while ($q_angle > 0 || $q_angle <= -90) { @@ -723,8 +810,13 @@ // Create the textimage. list($r, $g, $b) = _textimage_hex2rgb($foreground_color); $fore = imagecolorallocate($image, $r, $g, $b); - - imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text); + + // Add margin + if ($margin_top || $margin_right || $margin_bottom || $margin_left) { + $image = textimage_image_add_margin($image, $margin_top, $margin_right, $margin_bottom, $margin_left, $background_color); + } + + imagettftext($image, $fontsize, $q_angle, $x + $margin_left, $y + $margin_top, $fore, $font, $text); if ($rotation !== 0) { $image = imagerotate($image, $rotation, 0); } @@ -864,9 +956,13 @@ /** * Theme function for displaying textimages */ -function theme_textimage_image($preset, $text, $additional_text = array(), $format = 'png', $alt = '', $title = '', $attributes = array(), $getsize = TRUE) { +function theme_textimage_image($preset, $text, $additional_text = array(), $format = 'png', $alt = '', $title = '', $attributes = array(), $getsize = TRUE, $image = TRUE) { if (!$path = textimage_build_image('theme', $preset, $text, $additional_text, $format)) { return FALSE; } - return theme('image', $path, $alt, $title, $attributes, $getsize); + if ($image) { + return theme('image', $path, $alt, $title, $attributes, $getsize); + } + + return $path; }