| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Headline Images |
|---|
| 4 | Plugin URI: http://www.coldforged.org/image-headlines-plugin-for-wordpress-15/ |
|---|
| 5 | Description: Replaces Post headlines with PNG images of text, from ALA's <a href="http://www.alistapart.com/articles/dynatext/">Dynamic Text Replacement</a>. Includes soft-shadows, improved configuration, and previews. Configure on the <a href="../wp-admin/admin.php?page=image-headlines.php">Headline Images Configuration</a> page. |
|---|
| 6 | Version: 2.6 |
|---|
| 7 | Author: Brian "ColdForged" Dupuis |
|---|
| 8 | Author URI: http://www.coldforged.org |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | /* |
|---|
| 12 | Bundled font is the beautiful Warp 1 by Alex Gollner. Take a |
|---|
| 13 | gander at some of his other fonts at |
|---|
| 14 | |
|---|
| 15 | http://www.project.com/alex/fonts/index.html |
|---|
| 16 | */ |
|---|
| 17 | |
|---|
| 18 | /* |
|---|
| 19 | Plugin originally by Joel �Jaykul� Bennett, but heavily modified |
|---|
| 20 | to the point seen here. |
|---|
| 21 | |
|---|
| 22 | Dynamic Heading Generator |
|---|
| 23 | By Stewart Rosenberger |
|---|
| 24 | http://www.stewartspeak.com/headings/ |
|---|
| 25 | http://www.alistapart.com/articles/dynatext/ |
|---|
| 26 | |
|---|
| 27 | This script generates PNG images of text, written in |
|---|
| 28 | the font/size that you specify. These PNG images are passed |
|---|
| 29 | back to the browser. Optionally, they can be cached for later use. |
|---|
| 30 | If a cached image is found, a new image will not be generated, |
|---|
| 31 | and the existing copy will be sent to the browser. |
|---|
| 32 | |
|---|
| 33 | Additional documentation on PHP's image handling capabilities can |
|---|
| 34 | be found at http://www.php.net/image/ |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | define( "IMAGEHEADLINES_VERSION", "2.5" ); |
|---|
| 38 | |
|---|
| 39 | if (! isset($wp_version)) |
|---|
| 40 | { |
|---|
| 41 | require_once (dirname(dirname(dirname(__FILE__))) . "/wp-config.php"); |
|---|
| 42 | global $wp_version; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | if (substr($wp_version, 0, 3) == "1.1" || substr($wp_version, 0, 3) == "1.0" || substr($wp_version, 0, 3) == "1.2" ) |
|---|
| 46 | { |
|---|
| 47 | echo "The Image Headlines Plugin requires at least WordPress version 1.3"; |
|---|
| 48 | return; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | define( "FONT_DIRECTORY", dirname(dirname(__FILE__))."/image-headlines" ); |
|---|
| 52 | |
|---|
| 53 | if (function_exists('load_plugin_textdomain')) |
|---|
| 54 | { |
|---|
| 55 | load_plugin_textdomain('headlinedomain'); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (! function_exists('ImageHeadline_update_option')) |
|---|
| 59 | { |
|---|
| 60 | function ImageHeadline_update_option($option, $new_settings) |
|---|
| 61 | { |
|---|
| 62 | update_option($option, $new_settings); |
|---|
| 63 | } |
|---|
| 64 | function ImageHeadline_get_settings($option) |
|---|
| 65 | { |
|---|
| 66 | $settings = get_settings($option); |
|---|
| 67 | |
|---|
| 68 | // HACK for problems with some WordPress 1.3 installations. |
|---|
| 69 | if( is_string($settings) ) |
|---|
| 70 | { |
|---|
| 71 | $unserialized = @ unserialize(stripslashes($settings)); |
|---|
| 72 | if( $unserialized !== FALSE ) |
|---|
| 73 | $settings = $unserialized; |
|---|
| 74 | } |
|---|
| 75 | return $settings; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | if (! function_exists('ImageHeadline_option_set')) |
|---|
| 80 | { |
|---|
| 81 | function ImageHeadline_option_set($option) |
|---|
| 82 | { |
|---|
| 83 | if (! $options = ImageHeadline_get_settings('ImageHeadline_options')) |
|---|
| 84 | return false; |
|---|
| 85 | else |
|---|
| 86 | return (in_array($option, $options)); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if (! function_exists('ImageHeadline_add_options_page')) |
|---|
| 92 | { |
|---|
| 93 | function ImageHeadline_add_options_page() |
|---|
| 94 | { |
|---|
| 95 | if (function_exists('add_options_page')) |
|---|
| 96 | add_options_page(__("Headline Options Page"), __('Headlines'), 7, basename(__FILE__)); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | if (! function_exists('ImageHeadline_option_set')) |
|---|
| 102 | { |
|---|
| 103 | function ImageHeadline_option_set($option) |
|---|
| 104 | { |
|---|
| 105 | if (! $options = ImageHeadline_get_settings('ImageHeadline_options')) |
|---|
| 106 | return false; |
|---|
| 107 | else |
|---|
| 108 | return (in_array($option, $options)); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | if (!function_exists('ImageHeadline_check_flag')) |
|---|
| 114 | { |
|---|
| 115 | function ImageHeadline_check_flag($flagname, $allflags) |
|---|
| 116 | { |
|---|
| 117 | echo (in_array($flagname, $allflags) ? 'checked="checked"' : ''); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | if (!function_exists('ImageHeadline_check_select')) |
|---|
| 122 | { |
|---|
| 123 | function ImageHeadline_check_select($flagname, $allflags, $value) |
|---|
| 124 | { |
|---|
| 125 | echo ($allflags[$flagname] == $value ? ' selected="selected"' : ''); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | if (!function_exists('ImageHeadline_check_radio')) |
|---|
| 131 | { |
|---|
| 132 | function ImageHeadline_check_radio($flagname, $allflags, $value) |
|---|
| 133 | { |
|---|
| 134 | echo ($allflags[$flagname] == $value ? 'checked="checked"' : ''); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | if( !function_exists('ImageHeadline_gd_version' ) ) |
|---|
| 139 | { |
|---|
| 140 | function ImageHeadline_gd_version() { |
|---|
| 141 | static $gd_version_number = null; |
|---|
| 142 | if ($gd_version_number === null) { |
|---|
| 143 | // Use output buffering to get results from phpinfo() |
|---|
| 144 | // without disturbing the page we're in. Output |
|---|
| 145 | // buffering is "stackable" so we don't even have to |
|---|
| 146 | // worry about previous or encompassing buffering. |
|---|
| 147 | ob_start(); |
|---|
| 148 | phpinfo(8); |
|---|
| 149 | $module_info = ob_get_contents(); |
|---|
| 150 | ob_end_clean(); |
|---|
| 151 | if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", |
|---|
| 152 | $module_info,$matches)) { |
|---|
| 153 | $gd_version_number = $matches[1]; |
|---|
| 154 | } else { |
|---|
| 155 | $gd_version_number = 0; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | return $gd_version_number; |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | if( !function_exists('ImageHeadline_readint')) |
|---|
| 163 | { |
|---|
| 164 | function ImageHeadline_readint( $file, $offset, $size ) |
|---|
| 165 | { |
|---|
| 166 | @fseek( $file, $offset, SEEK_SET ); |
|---|
| 167 | $string = @fread( $file, $size ); |
|---|
| 168 | $myarray = @unpack( (( $size == 2 ) ? "n" : "N")."*", $string ); |
|---|
| 169 | return intval($myarray[1]); |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if( !function_exists('ImageHeadline_get_ttf_font_name')) |
|---|
| 174 | { |
|---|
| 175 | function ImageHeadline_get_ttf_font_name( $fullpath ) |
|---|
| 176 | { |
|---|
| 177 | $return_string = ''; |
|---|
| 178 | |
|---|
| 179 | $thefile = @fopen( $fullpath, "rb" ); |
|---|
| 180 | if( $thefile ) |
|---|
| 181 | { |
|---|
| 182 | // Read the number of records. |
|---|
| 183 | $num_tables = ImageHeadline_readint( $thefile, 4, 2 ); |
|---|
| 184 | |
|---|
| 185 | // Loop through looking for the name record. |
|---|
| 186 | $offset = 12; |
|---|
| 187 | $name_offset = 0; |
|---|
| 188 | $name_length = 0; |
|---|
| 189 | for( $x = 0; ( $x < $num_tables ) && !feof( $thefile ) && ( $name_offset == 0 ); $x++ ) |
|---|
| 190 | { |
|---|
| 191 | @fseek( $thefile, $offset, SEEK_SET ); |
|---|
| 192 | $tag = @fread( $thefile, 4 ); |
|---|
| 193 | |
|---|
| 194 | if( !strcmp( $tag, 'name' ) ) |
|---|
| 195 | { |
|---|
| 196 | // Found the 'name' tag so read the offset into the file of |
|---|
| 197 | // the name table. |
|---|
| 198 | $offset += 8; |
|---|
| 199 | $name_offset = ImageHeadline_readint( $thefile, $offset, 4 ); |
|---|
| 200 | $name_length = ImageHeadline_readint( $thefile, $offset+4, 4 ); |
|---|
| 201 | } else { |
|---|
| 202 | $offset += 16; |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | // See if we have an offset to the name table. |
|---|
| 207 | if( $name_offset != 0 ) |
|---|
| 208 | { |
|---|
| 209 | // Yay, likely this is a valid TTF file. That's nice. See how many name entries |
|---|
| 210 | // we have. |
|---|
| 211 | $num_names = ImageHeadline_readint( $thefile, $name_offset+2, 2 ); |
|---|
| 212 | $string_storage_offset = ImageHeadline_readint( $thefile, $name_offset+4, 2 ); |
|---|
| 213 | $name_id_offset = $name_offset + 12; |
|---|
| 214 | |
|---|
| 215 | // Let's find the name record that we desire. We're looking for a name ID |
|---|
| 216 | // of 4. |
|---|
| 217 | $name_string_offset = 0; |
|---|
| 218 | $good_count = 0; |
|---|
| 219 | $preferred = 0; |
|---|
| 220 | for( $x = 0; ( $x < $num_names ) && !feof( $thefile ) /*&& ( $name_string_offset == 0 )*/; $x++ ) |
|---|
| 221 | { |
|---|
| 222 | $name_id = ImageHeadline_readint( $thefile, $name_id_offset, 2 ); |
|---|
| 223 | if( $name_id == 4 ) |
|---|
| 224 | { |
|---|
| 225 | $good_names[$good_count]["platform_id"] = ImageHeadline_readint( $thefile, $name_id_offset-6, 2 ); |
|---|
| 226 | $good_names[$good_count]["encoding_id"] = ImageHeadline_readint( $thefile, $name_id_offset-4, 2 ); |
|---|
| 227 | $good_names[$good_count]["language_id"] = ImageHeadline_readint( $thefile, $name_id_offset-2, 2 ); |
|---|
| 228 | |
|---|
| 229 | // Odd I know... we're searching for a Windows platform string with these |
|---|
| 230 | // precise parameters. It's the most common among fonts that I've seen. Not that this is a |
|---|
| 231 | // Unicode string so we'll have to deal with that rather naively below. The problem with |
|---|
| 232 | // the other formats is that many shareware/freeware fonts -- which a lot of people |
|---|
| 233 | // will probably use -- is that they're inconsistent with their string settings (like the |
|---|
| 234 | // bundled font... one of the strings is left at "Arial". |
|---|
| 235 | if( ( $good_names[$good_count]["platform_id"] == 3 ) && |
|---|
| 236 | ( $good_names[$good_count]["encoding_id"] == 1 ) && |
|---|
| 237 | ( $good_names[$good_count]["language_id"] == 1033 ) ) { |
|---|
| 238 | $preferred = $good_count; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | $good_names[$good_count]["string_length"] = ImageHeadline_readint( $thefile, $name_id_offset+2, 2 ); |
|---|
| 242 | $good_names[$good_count++]["string_offset"] = ImageHeadline_readint( $thefile, $name_id_offset+4, 2 ); |
|---|
| 243 | } |
|---|
| 244 | $name_id_offset += 12; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | // Did we find one? |
|---|
| 248 | if( $good_count ) |
|---|
| 249 | { |
|---|
| 250 | // This getting old yet? What a goofy file format, and PHP is far from the most |
|---|
| 251 | // efficient binary file parsers available. Anyway, we apparently have our string. |
|---|
| 252 | // Let's read out the damned thing and have done with it. |
|---|
| 253 | @fseek( $thefile, $name_offset + $string_storage_offset + $good_names[$preferred]["string_offset"], SEEK_SET ); |
|---|
| 254 | $return_string = @fread( $thefile, $good_names[$preferred]["string_length"] ); |
|---|
| 255 | for( $x = 0; $x < 32; $x++ ) |
|---|
| 256 | $unicode_chars[] = chr($x); |
|---|
| 257 | $return_string = str_replace( $unicode_chars, "", $return_string ); |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | fclose( $thefile ); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | return $return_string; |
|---|
| 264 | } |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | if( !function_exists( 'ImageHeadline_clear_cache' ) ) |
|---|
| 268 | { |
|---|
| 269 | function ImageHeadline_clear_cache( $dirname, $lifetime ) |
|---|
| 270 | { |
|---|
| 271 | if( ( $mydir = @opendir( $dirname ) ) !== false ) |
|---|
| 272 | { |
|---|
| 273 | while( ( $file = @readdir( $mydir ) ) !== false ) |
|---|
| 274 | { |
|---|
| 275 | if( preg_match("/[a-f0-9]{32}\.png/i", $file) ) |
|---|
| 276 | { |
|---|
| 277 | $difftime = ( time() - filectime( "$dirname/$file" ) ) / 60 / 60 / 24; |
|---|
| 278 | if( $difftime > $lifetime ) |
|---|
| 279 | { |
|---|
| 280 | @unlink( "$dirname/$file" ); |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | if( !function_exists( 'ImageHeadline_maybe_clear_cache' ) ) |
|---|
| 289 | { |
|---|
| 290 | function ImageHeadline_maybe_clear_cache( $dirname, $lifetime ) |
|---|
| 291 | { |
|---|
| 292 | $clearit = false; |
|---|
| 293 | |
|---|
| 294 | // Determine if the cache needs clearing. We do this every 12 hours. |
|---|
| 295 | if( file_exists( "$dirname/cache.info" ) ) |
|---|
| 296 | { |
|---|
| 297 | $difftime = time() - filectime( "$dirname/cache.info" ); |
|---|
| 298 | if( $difftime > ( 12 * 60 * 60 ) ) |
|---|
| 299 | { |
|---|
| 300 | $clearit = true; |
|---|
| 301 | @touch( "$dirname/cache.info" ); |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | else |
|---|
| 305 | { |
|---|
| 306 | if( ( $file = @fopen( "$dirname/cache.info", "wb" ) ) !== false ) |
|---|
| 307 | { |
|---|
| 308 | @fwrite( $file, "Hi there." ); |
|---|
| 309 | @fclose( $file ); |
|---|
| 310 | } |
|---|
| 311 | $clearit = true; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | if( $clearit ) |
|---|
| 315 | { |
|---|
| 316 | ImageHeadline_clear_cache($dirname, $lifetime); |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | if( !function_exists( 'ImageHeadline_traverse_directory' ) ) |
|---|
| 321 | { |
|---|
| 322 | function ImageHeadline_traverse_directory($dirname, &$return_array) |
|---|
| 323 | { |
|---|
| 324 | $current_num = count($return_array); |
|---|
| 325 | |
|---|
| 326 | // Get a list of files in the directory. |
|---|
| 327 | if( ($mydir = @opendir( $dirname )) !== false ) |
|---|
| 328 | { |
|---|
| 329 | while(($file = readdir($mydir))!== false ) |
|---|
| 330 | { |
|---|
| 331 | if ($file != "." && $file != "..") |
|---|
| 332 | { |
|---|
| 333 | $font_name = ImageHeadline_get_ttf_font_name( $dirname."/".$file ); |
|---|
| 334 | if( $font_name != '' ) |
|---|
| 335 | { |
|---|
| 336 | $return_array[$current_num]["font_name"] = $font_name; |
|---|
| 337 | $return_array[$current_num++]["font_file"] = $dirname."/".$file; |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | closedir($mydir); |
|---|
| 343 | } |
|---|
| 344 | return $current_num; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | if( !function_exists( 'ImageHeadline_get_fonts' ) ) |
|---|
| 349 | { |
|---|
| 350 | /* Returns an associative array of font file names and the corresponding font name */ |
|---|
| 351 | function ImageHeadline_get_fonts() |
|---|
| 352 | { |
|---|
| 353 | $num_fonts = 0; |
|---|
| 354 | $return_array = Array(); |
|---|
| 355 | |
|---|
| 356 | // Get a list of files in the directory. We'll also check the upload directory |
|---|
| 357 | // since that's an easy place for WordPress administrators to put new files. |
|---|
| 358 | ImageHeadline_traverse_directory( FONT_DIRECTORY, $return_array ); |
|---|
| 359 | ImageHeadline_traverse_directory( get_settings('fileupload_realpath'), $return_array ); |
|---|
| 360 | |
|---|
| 361 | // For each supposed font file parse out a font name string. |
|---|
| 362 | return $return_array; |
|---|
| 363 | } |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | if( !function_exists( 'ImageHeadline_gaussian' ) ) { |
|---|
| 367 | function ImageHeadline_gaussian( &$image, $width, $height, $spread ) |
|---|
| 368 | { |
|---|
| 369 | $use_GD1 = ImageHeadline_option_set( 'only_use_imagecreate' ); |
|---|
| 370 | if( $use_GD1 ) |
|---|
| 371 | return; |
|---|
| 372 | |
|---|
| 373 | // Check for silly spreads |
|---|
| 374 | if( $spread == 0 ) |
|---|
| 375 | return; |
|---|
| 376 | |
|---|
| 377 | if( $spread > 10 ) |
|---|
| 378 | $spread = 10; |
|---|
| 379 | |
|---|
| 380 | if( strlen( $memory_limit = trim(ini_get('memory_limit' )) ) > 0 ) |
|---|
| 381 | { |
|---|
| 382 | $last = strtolower($memory_limit{strlen($memory_limit)-1}); |
|---|
| 383 | switch($last) { |
|---|
| 384 | // The 'G' modifier is available since PHP 5.1.0 |
|---|
| 385 | case 'g': |
|---|
| 386 | $memory_limit *= 1024; |
|---|
| 387 | case 'm': |
|---|
| 388 | $memory_limit *= 1024; |
|---|
| 389 | case 'k': |
|---|
| 390 | $memory_limit *= 1024; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | if( $memory_limit <= 8 * 1024 * 1024 ) |
|---|
| 394 | { |
|---|
| 395 | $use_low_memory_method = true; |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | } else { |
|---|
| 399 | $use_low_memory_method = false; |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | // Perform gaussian blur convlution. First, prepare the convolution |
|---|
| 403 | // kernel and precalculated multiplication array. Algorithm |
|---|
| 404 | // adapted from the simply exceptional code by Mario Klingemann |
|---|
| 405 | // <http://incubator.quasimondo.com>. Kernel is essentially an |
|---|
| 406 | // approximation of a gaussian distribution by utilizing squares. |
|---|
| 407 | $kernelsize = $spread*2-1; |
|---|
| 408 | $kernel = array_fill( 0, $kernelsize, 0 ); |
|---|
| 409 | $mult = array_fill( 0, $kernelsize, array_fill( 0, 256, 0 ) ); |
|---|
| 410 | for( $i = 1; $i < $spread; $i++ ) |
|---|
| 411 | { |
|---|
| 412 | $smi = $spread - $i; |
|---|
| 413 | $kernel[$smi-1]=$kernel[$spread+$i-1]=$smi*$smi; |
|---|
| 414 | for( $j = 0; $j < 256; $j++ ) |
|---|
| 415 | { |
|---|
| 416 | $mult[$smi-1][$j] = $mult[$spread+$i-1][$j] = $kernel[$smi-1]*$j; |
|---|
| 417 | } |
|---|
| 418 | } |
|---|
| 419 | $kernel[$spread-1]=$spread*$spread; |
|---|
| 420 | for( $j = 0; $j < 256; $j++ ) |
|---|
| 421 | { |
|---|
| 422 | $mult[$spread-1][$j] = $kernel[$spread-1]*$j; |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | if( !$use_low_memory_method ) { |
|---|
| 426 | |
|---|
| 427 | // Kernel and multiplication array calculated, let's get the image |
|---|
| 428 | // read out into a usable format. |
|---|
| 429 | $imagebytes = $width*$height; |
|---|
| 430 | $i = 0; |
|---|
| 431 | for( $x = 0; $x < $width; $x++ ) |
|---|
| 432 | { |
|---|
| 433 | for( $y = 0; $y < $height; $y++ ) |
|---|
| 434 | { |
|---|
| 435 | $rgb = imagecolorat( $image, $x, $y ); |
|---|
| 436 | $imagearray[$i++] = $rgb; |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | // Everything's set. Let's run the first pass. Our first pass will be a |
|---|
| 442 | // vertical pass. |
|---|
| 443 | for( $x = 0; $x < $width; $x++ ) |
|---|
| 444 | { |
|---|
| 445 | for( $y = 0; $y < $height; $y++ ) |
|---|
| 446 | { |
|---|
| 447 | $sum = 0; |
|---|
| 448 | $cr = $cg = $cb = 0; |
|---|
| 449 | for( $j = 0; $j < $kernelsize; $j++ ) |
|---|
| 450 | { |
|---|
| 451 | $kernely = $y + ( $j - ( $spread - 1 ) ); |
|---|
| 452 | if( ( $kernely >= 0 ) && ( $kernely < $height ) ) |
|---|
| 453 | { |
|---|
| 454 | if( !$use_low_memory_method ) { |
|---|
| 455 | $ci = ( $x * $height ) + $kernely; |
|---|
| 456 | $rgb = $imagearray[$ci]; |
|---|
| 457 | } else { |
|---|
| 458 | $rgb = imagecolorat( $image, $x, $kernely ); |
|---|
| 459 | } |
|---|
| 460 | $cr += $mult[$j][($rgb >> 16 ) & 0xFF]; |
|---|
| 461 | $cg += $mult[$j][($rgb >> 8 ) & 0xFF]; |
|---|
| 462 | $cb += $mult[$j][$rgb & 0xFF]; |
|---|
| 463 | $sum += $kernel[$j]; |
|---|
| 464 | } |
|---|
| 465 | } |
|---|
| 466 | $ci = ( $x * $height ) + $y; |
|---|
| 467 | $shadowarray[$ci] = ( ( intval(round($cr/$sum)) & 0xff ) << 16 ) | ( ( intval(round($cg/$sum)) & 0xff ) << 8 ) | ( intval(round($cb/$sum)) & 0xff ); |
|---|
| 468 | } |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | // Free up some memory |
|---|
| 472 | if( isset( $imagearray ) ) { |
|---|
| 473 | unset( $imagearray ); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | // Now let's make with the horizontal passing. That sentence |
|---|
| 477 | // contruct never gets old: "make with the". Oh the humor. |
|---|
| 478 | for( $x = 0; $x < $width; $x++ ) |
|---|
| 479 | { |
|---|
| 480 | for( $y = 0; $y < $height; $y++ ) |
|---|
| 481 | { |
|---|
| 482 | $sum = 0; |
|---|
| 483 | $cr = $cg = $cb = 0; |
|---|
| 484 | for( $j = 0; $j < $kernelsize; $j++ ) |
|---|
| 485 | { |
|---|
| 486 | $kernelx = $x + ( $j - ( $spread - 1 ) ); |
|---|
| 487 | if( ( $kernelx >= 0 ) && ( $kernelx < $width ) ) |
|---|
| 488 | { |
|---|
| 489 | $ci = ( $kernelx * $height ) + $y; |
|---|
| 490 | $cr += $mult[$j][($shadowarray[$ci] >> 16 ) & 0xFF]; |
|---|
| 491 | $cg += $mult[$j][($shadowarray[$ci] >> 8 ) & 0xFF]; |
|---|
| 492 | $cb += $mult[$j][$shadowarray[$ci] & 0xFF]; |
|---|
| 493 | $sum += $kernel[$j]; |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | $r = intval(round($cr/$sum)); |
|---|
| 497 | $g = intval(round($cg/$sum)); |
|---|
| 498 | $b = intval(round($cb/$sum)); |
|---|
| 499 | |
|---|
| 500 | if( $r < 0 ) $r = 0; |
|---|
| 501 | else if( $r > 255 ) $r = 255; |
|---|
| 502 | if( $g < 0 ) $g = 0; |
|---|
| 503 | else if( $g > 255 ) $g = 255; |
|---|
| 504 | if( $b < 0 ) $b = 0; |
|---|
| 505 | else if( $b > 255 ) $b = 255; |
|---|
| 506 | |
|---|
| 507 | $color = ( $r << 16 ) | ($g << 8 ) | $b; |
|---|
| 508 | |
|---|
| 509 | if( !isset( $colors[ $color ] ) ) { |
|---|
| 510 | $colors[ $color ] = imagecolorallocate( $image, $r, $g, $b ); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | imagesetpixel( $image, $x, $y, $colors[$color] ); |
|---|
| 514 | } |
|---|
| 515 | } |
|---|
| 516 | } |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | /* To override the format for a particular transformation, specify the name of |
|---|
| 520 | the settings to override followed by an '=' and the value to set it to. |
|---|
| 521 | Separate multiple settings with an ampersand (&) */ |
|---|
| 522 | if( !function_exists( 'ImageHeadline_render' ) ) { |
|---|
| 523 | function ImageHeadline_render($text, $format_override='') { |
|---|
| 524 | $current_settings = ImageHeadline_get_settings('ImageHeadline_settings'); |
|---|
| 525 | global $DebugImgHead; |
|---|
| 526 | |
|---|
| 527 | // Clear the cache if necessary. |
|---|
| 528 | ImageHeadline_maybe_clear_cache( $current_settings['cache_folder'], isset($current_settings['image_lifetime']) ? $current_settings['image_lifetime'] : 14 ); |
|---|
| 529 | |
|---|
| 530 | // Check for format overrides. |
|---|
| 531 | if( $format_override != '' ) { |
|---|
| 532 | $formats = explode( '&', $format_override ); |
|---|
| 533 | foreach( $formats as $format ) { |
|---|
| 534 | $setting = explode( "=", $format, 2 ); |
|---|
| 535 | if( isset( $current_settings[ $setting[0] ] ) ) { |
|---|
| 536 | $current_settings[ $setting[0] ] = $setting[1]; |
|---|
| 537 | } |
|---|
| 538 | } |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | $mime_type = 'image/png' ; |
|---|
| 542 | $extension = '.png' ; |
|---|
| 543 | $send_buffer_size = 4096 ; |
|---|
| 544 | |
|---|
| 545 | $retVal = $text; |
|---|
| 546 | |
|---|
| 547 | // check for GD support |
|---|
| 548 | if(get_magic_quotes_gpc()) |
|---|
| 549 | $text = stripslashes($text) ; |
|---|
| 550 | |
|---|
| 551 | $hashinput = basename($current_settings['font_file']) . |
|---|
| 552 | IMAGEHEADLINES_VERSION . |
|---|
| 553 | $current_settings['font_size'] . |
|---|
| 554 | $current_settings['font_color'] . |
|---|
| 555 | $current_settings['background_color'] . |
|---|
| 556 | $current_settings['left_padding'] . |
|---|
| 557 | $current_settings['max_width'] . |
|---|
| 558 | $current_settings['space_between_lines'] . |
|---|
| 559 | $current_settings['line_indent'] . |
|---|
| 560 | $current_settings['background_image'] . |
|---|
| 561 | ImageHeadline_option_set('transparent_background') . |
|---|
| 562 | ImageHeadline_option_set('shadows') . |
|---|
| 563 | ImageHeadline_option_set('split_lines') . |
|---|
| 564 | $current_settings['soft_shadows'] . |
|---|
| 565 | $text; |
|---|
| 566 | |
|---|
| 567 | // look for cached copy, send if it exists |
|---|
| 568 | if( ImageHeadline_option_set( 'shadows' ) ) |
|---|
| 569 | { |
|---|
| 570 | if( !$current_settings['soft_shadows'] ) |
|---|
| 571 | { |
|---|
| 572 | $hash = md5( |
|---|
| 573 | $hashinput . |
|---|
| 574 | $current_settings['shadow_first_color'] . |
|---|
| 575 | $current_settings['shadow_second_color'] . |
|---|
| 576 | $current_settings['shadow_offset']) ; |
|---|
| 577 | } |
|---|
| 578 | else |
|---|
| 579 | { |
|---|
| 580 | $hash = md5( |
|---|
| 581 | $hashinput . |
|---|
| 582 | $current_settings['shadow_color'] . |
|---|
| 583 | $current_settings['shadow_horizontal_offset'] . |
|---|
| 584 | $current_settings['shadow_vertical_offset'] . |
|---|
| 585 | $current_settings['shadow_spread']) ; |
|---|
| 586 | } |
|---|
| 587 | } |
|---|
| 588 | else |
|---|
| 589 | { |
|---|
| 590 | $hash = md5($hashinput) ; |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | $cache_filename = $current_settings['cache_folder'] . '/' . $hash . $extension ; |
|---|
| 594 | $generated_url = $current_settings['cache_url'] . '/' . $hash . $extension ; |
|---|
| 595 | |
|---|
| 596 | if( file_exists( $cache_filename )) |
|---|
| 597 | { |
|---|
| 598 | list($width, $height, $type, $attr) = getimagesize($cache_filename); |
|---|
| 599 | $retVal = "<img src='$generated_url' alt='$text' width='$width' height='$height' />" ; |
|---|
| 600 | } elseif( is_writable( $current_settings['cache_folder'] ) ){ |
|---|
| 601 | |
|---|
| 602 | // check font availability |
|---|
| 603 | $font_found = is_readable($current_settings['font_file']) ; |
|---|
| 604 | if( !$font_found ) { |
|---|
| 605 | if( $DebugImgHead ) echo('Error: The server is missing the specified font.') ; |
|---|
| 606 | $retVal = $text; |
|---|
| 607 | } else { |
|---|
| 608 | |
|---|
| 609 | // create image |
|---|
| 610 | $background_rgb = ImageHeadline_hex_to_rgb($current_settings['background_color'], $DebugImgHead) ; |
|---|
| 611 | $font_rgb = ImageHeadline_hex_to_rgb($current_settings['font_color'], $DebugImgHead) ; |
|---|
| 612 | |
|---|
| 613 | $box["width"] = 0; |
|---|
| 614 | $box["height"] = 0; |
|---|
| 615 | $current_y = -1; |
|---|
| 616 | $max_y = -1; |
|---|
| 617 | |
|---|
| 618 | // Calculate how much additional space is needed for shadows. |
|---|
| 619 | $vertical_shadow_spacing = $horizontal_shadow_spacing = 0; |
|---|
| 620 | if( ImageHeadline_option_set( 'shadows' ) ) |
|---|
| 621 | { |
|---|
| 622 | if( !$current_settings['soft_shadows'] ) |
|---|
| 623 | { |
|---|
| 624 | $vertical_shadow_spacing = $horizontal_shadow_spacing = 2; |
|---|
| 625 | } |
|---|
| 626 | else |
|---|
| 627 | { |
|---|
| 628 | $vertical_shadow_spacing += $current_settings['shadow_vertical_offset'] + $current_settings['shadow_spread']; |
|---|
| 629 | $horizontal_shadow_spacing += $current_settings['shadow_horizontal_offset'] + $current_settings['shadow_spread']; |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | // Split the text into complete lines of no greater than max_width if we've been |
|---|
| 634 | // told to split lines. Otherwise, work with the whole text regardless of line length. |
|---|
| 635 | if( ImageHeadline_option_set( 'split_lines' ) ) { |
|---|
| 636 | $text_array = ImageHeadline_break_text_into_lines( $text, $current_settings ); |
|---|
| 637 | } else { |
|---|
| 638 | $text_array[] = $text; |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | // Now we need to calculate the overall dimensions of the resultant image. We have to |
|---|
| 642 | //take into account the number of lines, all formatting options (e.g. space between |
|---|
| 643 | // lines, indent) as well as use of shadows and spreads for shadows. |
|---|
| 644 | foreach( $text_array as $line ) |
|---|
| 645 | { |
|---|
| 646 | $bbox = @ImageTTFBBox($current_settings['font_size'],0,$current_settings['font_file'],$line); |
|---|
| 647 | $width = $current_settings['left_padding'] + $horizontal_shadow_spacing + ( max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]) ) + 2; |
|---|
| 648 | $height = ( max($bbox[1],$bbox[3],$bbox[5],$bbox[7]) - min($bbox[1],$bbox[3],$bbox[5],$bbox[7]) ) + $vertical_shadow_spacing; |
|---|
| 649 | |
|---|
| 650 | // If this isn't the first line of multi-line text, we have to take into account |
|---|
| 651 | // the space between each line vertically as well any line indent horizontally. |
|---|
| 652 | if( $max_y > 0 ) |
|---|
| 653 | { |
|---|
| 654 | $box["height"] += $current_settings['space_between_lines']; |
|---|
| 655 | $width += $current_settings['line_indent']; |
|---|
| 656 | } |
|---|
| 657 | |
|---|
| 658 | if( $height > $max_y ) |
|---|
| 659 | { |
|---|
| 660 | $max_y = $height; |
|---|
| 661 | } |
|---|
| 662 | if( $current_y == -1 ) |
|---|
| 663 | { |
|---|
| 664 | $current_y = abs(min($bbox[5], $bbox[7])) - 1; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | // Increment height and latch width to the widest line. |
|---|
| 668 | if( $box["width"] < $width ) |
|---|
| 669 | { |
|---|
| 670 | $box["width"] = $width; |
|---|
| 671 | } |
|---|
| 672 | } |
|---|
| 673 | $box["height"] += count( $text_array ) * $max_y; |
|---|
| 674 | |
|---|
| 675 | // Creat the image and fill it with our background color. |
|---|
| 676 | if( ImageHeadline_option_set( 'only_use_imagecreate' ) ) { |
|---|
| 677 | $image = @ImageCreate($box["width"],$box["height"]); |
|---|
| 678 | } else { |
|---|
| 679 | $image = @ImageCreateTrueColor($box["width"],$box["height"]); |
|---|
| 680 | } |
|---|
| 681 | $background_color = @ImageColorAllocate($image,$background_rgb['red'], $background_rgb['green'], $background_rgb['blue'] ) ; |
|---|
| 682 | imagefill( $image, 0, 0, $background_color ); |
|---|
| 683 | |
|---|
| 684 | if( !$image || !$box ) { |
|---|
| 685 | if( $DebugImgHead ) echo('Error: The server could not create this heading image.') ; |
|---|
| 686 | $retVal = $text; |
|---|
| 687 | } else { |
|---|
| 688 | // allocate colors and draw text |
|---|
| 689 | $current_settings['font_color'] = @ImageColorAllocate($image,$font_rgb['red'], $font_rgb['green'], $font_rgb['blue']) ; |
|---|
| 690 | |
|---|
| 691 | // Blit the background image in there. This is always fun. |
|---|
| 692 | if( ImageHeadline_option_set('use_background_image') ) |
|---|
| 693 | { |
|---|
| 694 | if(!empty( $current_settings['background_image'] ) && is_readable( $current_settings['background_image'] ) ) { |
|---|
| 695 | list($widthi, $heighti, $typei, $attri) = getImageSize($current_settings['background_image']); |
|---|
| 696 | $backgroundimage = ImageCreateFromPNG( $current_settings['background_image'] ); //NOTE use png for this |
|---|
| 697 | ImageColorTransparent($backgroundimage,$background_color); |
|---|
| 698 | |
|---|
| 699 | // merge the two together with alphablending on! |
|---|
| 700 | ImageAlphaBlending($backgroundimage, true); |
|---|
| 701 | |
|---|
| 702 | ImageCopyMerge ( $image, $backgroundimage, 0, 0, 0, 0, $widthi, $heighti, 99); |
|---|
| 703 | } else { |
|---|
| 704 | if( $debug ) echo "Image not found: ".$current_settings['background_image']." is apparently missing."; |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | $saved_y = $current_y; |
|---|
| 709 | |
|---|
| 710 | // Render the shadows depending on the selected method. |
|---|
| 711 | if( ImageHeadline_option_set( 'shadows' ) ) |
|---|
| 712 | { |
|---|
| 713 | if( !$current_settings['soft_shadows'] ) |
|---|
| 714 | { |
|---|
| 715 | // "Classic" method of text drawn in two different colors. |
|---|
| 716 | $current_x = 0; |
|---|
| 717 | $shadow_rgb = ImageHeadline_hex_to_rgb($current_settings['shadow_first_color'], $DebugImgHead); |
|---|
| 718 | $shadow_1 = @ImageColorAllocate($image,$shadow_rgb['red'], $shadow_rgb['green'], $shadow_rgb['blue']); |
|---|
| 719 | $shadow_rgb = ImageHeadline_hex_to_rgb($current_settings['shadow_second_color'], $DebugImgHead); |
|---|
| 720 | $shadow_2 = @ImageColorAllocate($image,$shadow_rgb['red'], $shadow_rgb['green'], $shadow_rgb['blue']); |
|---|
| 721 | foreach( $text_array as $line ) |
|---|
| 722 | { |
|---|
| 723 | ImageTTFText($image, $current_settings['font_size'], 0, $current_x + $current_settings['left_padding'] + $current_settings['shadow_offset'] * 2, $current_y + $current_settings['shadow_offset'] * 2, $shadow_2, $current_settings['font_file'], $line) ; |
|---|
| 724 | ImageTTFText($image, $current_settings['font_size'], 0, $current_x + $current_settings['left_padding'] + $current_settings['shadow_offset'], $current_y + $current_settings['shadow_offset'], $shadow_1, $current_settings['font_file'], $line) ; |
|---|
| 725 | |
|---|
| 726 | $current_y += $max_y + $current_settings['space_between_lines']; |
|---|
| 727 | if( $current_x == 0 ) |
|---|
| 728 | { |
|---|
| 729 | $current_x += $current_settings['line_indent']; |
|---|
| 730 | } |
|---|
| 731 | } |
|---|
| 732 | } |
|---|
| 733 | else /* soft shadows */ |
|---|
| 734 | { |
|---|
| 735 | // Gaussian blurred "soft-shadow" method. |
|---|
| 736 | if( ImageHeadline_option_set( 'only_use_imagecreate' ) ) { |
|---|
| 737 | $shadow_image = @ImageCreate( $box['width'], $box['height']); |
|---|
| 738 | } else { |
|---|
| 739 | $shadow_image = @ImageCreateTrueColor( $box['width'], $box['height']); |
|---|
| 740 | } |
|---|
| 741 | imagefill( $shadow_image, 0, 0, $background_color ); |
|---|
| 742 | |
|---|
| 743 | $shadow_rgb = ImageHeadline_hex_to_rgb($current_settings['shadow_color'], $DebugImgHead); |
|---|
| 744 | $shadow_color = @ImageColorAllocate($shadow_image,$shadow_rgb['red'], $shadow_rgb['green'], $shadow_rgb['blue']); |
|---|
| 745 | $current_x = 0; |
|---|
| 746 | foreach( $text_array as $line ) |
|---|
| 747 | { |
|---|
| 748 | ImageTTFText($shadow_image, $current_settings['font_size'], 0, $current_x + $current_settings['left_padding'] + $current_settings['shadow_horizontal_offset'], $current_y + $current_settings['shadow_vertical_offset'], $shadow_color, $current_settings['font_file'], $line) ; |
|---|
| 749 | |
|---|
| 750 | $current_y += $max_y + $current_settings['space_between_lines']; |
|---|
| 751 | if( $current_x == 0 ) |
|---|
| 752 | { |
|---|
| 753 | $current_x += $current_settings['line_indent']; |
|---|
| 754 | } |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | ImageHeadline_gaussian( $shadow_image, $box['width'], $box['height'], $current_settings['shadow_spread'] ); |
|---|
| 758 | if(ImageHeadline_option_set('transparent_background')) |
|---|
| 759 | ImageColorTransparent($shadow_image,$background_color) ; |
|---|
| 760 | |
|---|
| 761 | ImageAlphaBlending($shadow_image, true ); |
|---|
| 762 | ImageCopyMerge( $image, $shadow_image, 0,0,0,0, $box["width"], $box["height"],50); |
|---|
| 763 | |
|---|
| 764 | ImageDestroy($shadow_image); |
|---|
| 765 | } |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | $current_x = 0; |
|---|
| 769 | $current_y = $saved_y; |
|---|
| 770 | foreach( $text_array as $line ) |
|---|
| 771 | { |
|---|
| 772 | ImageTTFText($image, $current_settings['font_size'], 0, $current_x + $current_settings['left_padding'], $current_y, $current_settings['font_color'], $current_settings['font_file'], $line) ; |
|---|
| 773 | |
|---|
| 774 | $current_y += $max_y + $current_settings['space_between_lines']; |
|---|
| 775 | if( $current_x == 0 ) |
|---|
| 776 | { |
|---|
| 777 | $current_x += $current_settings['line_indent']; |
|---|
| 778 | } |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | // set transparency |
|---|
| 782 | if(ImageHeadline_option_set('transparent_background')) |
|---|
| 783 | ImageColorTransparent($image,$background_color) ; |
|---|
| 784 | |
|---|
| 785 | @ImagePNG($image,$cache_filename) ; |
|---|
| 786 | ImageDestroy($image) ; |
|---|
| 787 | if( file_exists( $cache_filename ) ) |
|---|
| 788 | { |
|---|
| 789 | $retVal = "<img src='$generated_url' alt='".addslashes($text)."' width='".$box['width']."' height='".$box['height']."' />" ; |
|---|
| 790 | } else { |
|---|
| 791 | if( $DebugImgHead ) echo( "Unknown Error creating file." ); |
|---|
| 792 | $retVal = $text; |
|---|
| 793 | } |
|---|
| 794 | } |
|---|
| 795 | } |
|---|
| 796 | } else { |
|---|
| 797 | if( $DebugImgHead ) echo( "Error: The Folder [".dirname( $cache_filename )."] is not writeable." ); |
|---|
| 798 | $retVal = $text; |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | return $retVal; |
|---|
| 802 | } |
|---|
| 803 | } |
|---|
| 804 | |
|---|
| 805 | if( !function_exists( 'ImageHeadline_hex_to_rgb' ) ) { |
|---|
| 806 | /* |
|---|
| 807 | decode an HTML hex-code into an array of R,G, and B values. |
|---|
| 808 | accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff |
|---|
| 809 | */ |
|---|
| 810 | function ImageHeadline_hex_to_rgb($hex, $DebugImgHead) |
|---|
| 811 | { |
|---|
| 812 | // remove '#' |
|---|
| 813 | if(substr($hex,0,1) == '#') |
|---|
| 814 | $hex = substr($hex,1) ; |
|---|
| 815 | |
|---|
| 816 | // expand short form ('fff') color |
|---|
| 817 | if(strlen($hex) == 3) |
|---|
| 818 | { |
|---|
| 819 | $hex = substr($hex,0,1) . substr($hex,0,1) . |
|---|
| 820 | substr($hex,1,1) . substr($hex,1,1) . |
|---|
| 821 | substr($hex,2,1) . substr($hex,2,1) ; |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | if(strlen($hex) != 6 && $DebugImgHead ) { |
|---|
| 825 | echo('Error: Invalid color "'.$hex.'"') ; |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | // convert |
|---|
| 829 | $rgb['red'] = hexdec(substr($hex,0,2)) ; |
|---|
| 830 | $rgb['green'] = hexdec(substr($hex,2,2)) ; |
|---|
| 831 | $rgb['blue'] = hexdec(substr($hex,4,2)) ; |
|---|
| 832 | |
|---|
| 833 | return $rgb ; |
|---|
| 834 | } |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | if( !function_exists( 'ImageHeadline_break_text_into_lines' ) ) { |
|---|
| 838 | /* |
|---|
| 839 | Break the line into several lines if it exceeds the maximum allowed |
|---|
| 840 | width. |
|---|
| 841 | */ |
|---|
| 842 | function ImageHeadline_break_text_into_lines( $text, $current_settings ) |
|---|
| 843 | { |
|---|
| 844 | |
|---|
| 845 | // the returned array of strings to be on separate lines. |
|---|
| 846 | $text_array = array(); |
|---|
| 847 | |
|---|
| 848 | // Figure out how big a space is. Yes, I'm being anal. |
|---|
| 849 | $bbox = imagettfbbox($current_settings['font_size'],0, $current_settings['font_file'], ' '); |
|---|
| 850 | $space_width = max($bbox[2],$bbox[4]) - min($bbox[0], $bbox[6]); |
|---|
| 851 | |
|---|
| 852 | // Split the array into word components. |
|---|
| 853 | $words = explode( ' ', $text ); |
|---|
| 854 | $current_line = ''; |
|---|
| 855 | $current_width = $current_settings['left_padding']; |
|---|
| 856 | foreach( $words as $word ) |
|---|
| 857 | { |
|---|
| 858 | $bbox = imagettfbbox($current_settings['font_size'], 0, $current_settings['font_file'], $word ); |
|---|
| 859 | $word_width = max($bbox[2],$bbox[4]) - min($bbox[0], $bbox[6]); |
|---|
| 860 | |
|---|
| 861 | // See if the current word will fit on the line. |
|---|
| 862 | if( $word_width + $current_width + $space_width > $current_settings['max_width'] ) |
|---|
| 863 | { |
|---|
| 864 | // It won't. Check the border case where we have a friggin' |
|---|
| 865 | // huge first word. If so, it'll have to be rendered on the |
|---|
| 866 | // line regardless. |
|---|
| 867 | if( $current_line != '' ) |
|---|
| 868 | { |
|---|
| 869 | $text_array[] = $current_line; |
|---|
| 870 | $current_width = $word_width + $current_settings['left_padding'] + $current_settings['line_indent']; |
|---|
| 871 | $current_line = $word; |
|---|
| 872 | } |
|---|
| 873 | else |
|---|
| 874 | { |
|---|
| 875 | $text_array[] = $word; |
|---|
| 876 | $current_width = $current_settings['left_padding'] + $current_settings['line_indent']; |
|---|
| 877 | $current_line = ''; |
|---|
| 878 | } |
|---|
| 879 | |
|---|
| 880 | continue; |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | // Word fits, so append it. |
|---|
| 884 | if( $current_line != '' ) |
|---|
| 885 | { |
|---|
| 886 | $current_line .= ' '; |
|---|
| 887 | } |
|---|
| 888 | |
|---|
| 889 | $current_line .= $word; |
|---|
| 890 | $current_width += $word_width + $space_width; |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | if( $current_line != '' ) |
|---|
| 894 | { |
|---|
| 895 | $text_array[] = $current_line; |
|---|
| 896 | } |
|---|
| 897 | |
|---|
| 898 | return $text_array; |
|---|
| 899 | } |
|---|
| 900 | } |
|---|
| 901 | |
|---|
| 902 | if( !function_exists( 'imageheadlines' ) ) { |
|---|
| 903 | /* |
|---|
| 904 | Main workhorse function for actually replacing headlines with text. |
|---|
| 905 | */ |
|---|
| 906 | function imageheadlines($text) { |
|---|
| 907 | $current_settings = ImageHeadline_get_settings('ImageHeadline_settings'); |
|---|
| 908 | global $DebugImgHead; |
|---|
| 909 | |
|---|
| 910 | // Check for XML feeds. Don't replace in feeds. |
|---|
| 911 | // If you have $before set, and it doesn't match, we're done. |
|---|
| 912 | if( strpos($text, $current_settings['before_text']) === FALSE ) { |
|---|
| 913 | return $text; |
|---|
| 914 | } else { |
|---|
| 915 | if( !empty($current_settings['before_text']) ) { |
|---|
| 916 | $text = substr( $text, strlen($current_settings['before_text']) ); |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | // If you have problems, set this to TRUE and see what pops up ;-) |
|---|
| 920 | $DebugImgHead = true; |
|---|
| 921 | |
|---|
| 922 | if( ImageHeadline_option_set( 'disable_headlines' ) ) |
|---|
| 923 | { |
|---|
| 924 | return $text; |
|---|
| 925 | } |
|---|
| 926 | else |
|---|
| 927 | { |
|---|
| 928 | // get/make an image for this text. |
|---|
| 929 | return ImageHeadline_render( $text ); |
|---|
| 930 | } |
|---|
| 931 | } |
|---|
| 932 | } |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | if( is_plugin_page() ) { |
|---|
| 936 | global $user_level; |
|---|
| 937 | |
|---|
| 938 | // Set up the default settings. |
|---|
| 939 | $default_settings = array( |
|---|
| 940 | 'font_file' => FONT_DIRECTORY."/warp1.ttf", |
|---|
| 941 | 'font_size' => 18, |
|---|
| 942 | 'font_color' => '#FF0000', |
|---|
| 943 | 'background_color' => '#FFF', |
|---|
| 944 | 'shadow_color' => '#000', |
|---|
| 945 | 'shadow_spread' => 3, |
|---|
| 946 | 'shadow_vertical_offset' => 2, |
|---|
| 947 | 'shadow_horizontal_offset' => 2, |
|---|
| 948 | 'left_padding' => 0, |
|---|
| 949 | 'max_width' => 450, |
|---|
| 950 | 'space_between_lines' => 5, |
|---|
| 951 | 'line_indent' => 10, |
|---|
| 952 | 'preview_text' => 'The quick brown fox jumped over the lazy dog.', |
|---|
| 953 | 'cache_url' => ( get_option('use_fileupload') ? get_settings('fileupload_url'):get_settings( 'siteurl' )."/wp-content/image-headlines" ), |
|---|
| 954 | 'cache_folder' => ( get_option('use_fileupload') ? get_settings('fileupload_realpath'):dirname(dirname(__FILE__))."/image-headlines" ), |
|---|
| 955 | 'soft_shadows' => 1, |
|---|
| 956 | 'shadow_first_color' => '#FFF', |
|---|
| 957 | 'shadow_second_color' => '#BBB', |
|---|
| 958 | 'shadow_offset' => 1, |
|---|
| 959 | 'background_image' => '', |
|---|
| 960 | 'before_text' => '-image-', |
|---|
| 961 | 'image_lifetime' => 14 |
|---|
| 962 | ); |
|---|
| 963 | |
|---|
| 964 | $default_options = array( |
|---|
| 965 | 'shadows', |
|---|
| 966 | 'split_lines', |
|---|
| 967 | 'transparent_background', |
|---|
| 968 | ); |
|---|
| 969 | |
|---|
| 970 | global $ImageHeadline_options; |
|---|
| 971 | |
|---|
| 972 | if( isset( $_POST['update_options'] ) ) |
|---|
| 973 | { |
|---|
| 974 | ImageHeadline_update_option('ImageHeadline_options', $_POST['ImageHeadline_options']); |
|---|
| 975 | |
|---|
| 976 | $new_settings = array_merge(ImageHeadline_get_settings('ImageHeadline_settings'), $_POST['ImageHeadline_settings']); |
|---|
| 977 | foreach($default_settings as $key => $val) |
|---|
| 978 | if (!isset($new_settings[$key])) |
|---|
| 979 | $new_settings[$key] = $val; |
|---|
| 980 | |
|---|
| 981 | // A bit of error checking. |
|---|
| 982 | if( $new_settings['shadow_spread'] <= 0 ) |
|---|
| 983 | { |
|---|
| 984 | $new_settings['shadow_spread'] = 1; |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | if( $new_settings['shadow_spread'] > 10 ) |
|---|
| 988 | { |
|---|
| 989 | $new_settings['shadow_spread'] = 10; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | $new_settings['preview_text'] = apply_filters('title_save_pre', $new_settings['preview_text']); |
|---|
| 993 | |
|---|
| 994 | ImageHeadline_update_option('ImageHeadline_settings', $new_settings); |
|---|
| 995 | |
|---|
| 996 | echo '<div class="updated"><p><strong>' . __('Options updated.', 'headlinedomain') . '</strong></p></div>'; |
|---|
| 997 | $ImageHeadline_options = ImageHeadline_get_settings('ImageHeadline_options'); |
|---|
| 998 | $ImageHeadline_settings = ImageHeadline_get_settings('ImageHeadline_settings'); |
|---|
| 999 | if(!is_array($ImageHeadline_settings)) |
|---|
| 1000 | $ImageHeadline_settings = $default_settings; |
|---|
| 1001 | if(!is_array($ImageHeadline_options)) |
|---|
| 1002 | $ImageHeadline_options = $default_options; |
|---|
| 1003 | } |
|---|
| 1004 | else |
|---|
| 1005 | { |
|---|
| 1006 | add_option('ImageHeadline_options', $default_options); |
|---|
| 1007 | add_option('ImageHeadline_settings', $default_settings); |
|---|
| 1008 | $ImageHeadline_options = ImageHeadline_get_settings('ImageHeadline_options'); |
|---|
| 1009 | $ImageHeadline_settings = ImageHeadline_get_settings('ImageHeadline_settings'); |
|---|
| 1010 | if(!is_array($ImageHeadline_settings)) |
|---|
| 1011 | $ImageHeadline_settings = $default_settings; |
|---|
| 1012 | if(!is_array($ImageHeadline_options)) |
|---|
| 1013 | $ImageHeadline_options = $default_options; |
|---|
| 1014 | } |
|---|
| 1015 | |
|---|
| 1016 | $ImageHeadline_settings = array_merge( $default_settings, $ImageHeadline_settings ); |
|---|
| 1017 | ImageHeadline_update_option('ImageHeadline_settings', $ImageHeadline_settings); |
|---|
| 1018 | |
|---|
| 1019 | $edited_preview_text = format_to_edit($ImageHeadline_settings['preview_text']); |
|---|
| 1020 | $edited_preview_text = apply_filters('title_edit_pre', $edited_preview_text); |
|---|
| 1021 | $render_title = apply_filters('the_title', $ImageHeadline_settings['preview_text']); |
|---|
| 1022 | |
|---|
| 1023 | // Check for some errors. |
|---|
| 1024 | if( ( ImageHeadline_gd_version() < 2 ) || (!function_exists( 'ImageCreate' ) ) ) |
|---|
| 1025 | { |
|---|
| 1026 | if( function_exists( 'ImageCreate' ) ) |
|---|
| 1027 | { |
|---|
| 1028 | $ImageHeadline_options[] = 'only_use_imagecreate'; |
|---|
| 1029 | if(ImageHeadline_option_set( 'disable_headlines' ) ) |
|---|
| 1030 | { |
|---|
| 1031 | // Somebody must have installed what we need... enable us again. |
|---|
| 1032 | unset($ImageHeadline_options[array_search('disable_headlines',$ImageHeadline_options)]); |
|---|
| 1033 | $ImageHeadline_options = array_values( $ImageHeadline_options ); |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | if( $ImageHeadline_settings['soft_shadows'] == 1 ) |
|---|
| 1037 | { |
|---|
| 1038 | $ImageHeadline_settings['soft_shadows'] = 0; |
|---|
| 1039 | ImageHeadline_update_option('ImageHeadline_settings', $ImageHeadline_settings); |
|---|
| 1040 | } |
|---|
| 1041 | } |
|---|
| 1042 | else |
|---|
| 1043 | { |
|---|
| 1044 | $ImageHeadline_options[] = 'disable_headlines'; |
|---|
| 1045 | echo '<div class="updated" style="background-color: #FF8080;border: 3px solid #F00;"><p><strong>' . __('FATAL: Your PHP installation does not support the ImageCreateTrueColor() or the ImageCreate() function. Unforunately, there is not much this plugin can do without that. Talk to your hosting administrator about upgrading to a version that supports image manipulation and try again with the plugin.', 'headlinedomain') . '</strong></p></div>'; |
|---|
| 1046 | } |
|---|
| 1047 | ImageHeadline_update_option('ImageHeadline_options', $ImageHeadline_options); |
|---|
| 1048 | } |
|---|
| 1049 | else |
|---|
| 1050 | { |
|---|
| 1051 | if( ImageHeadline_option_set( 'disable_headlines' ) ) |
|---|
| 1052 | { |
|---|
| 1053 | unset($ImageHeadline_options[array_search('disable_headlines',$ImageHeadline_options)]); |
|---|
| 1054 | $ImageHeadline_options = array_values( $ImageHeadline_options ); |
|---|
| 1055 | ImageHeadline_update_option('ImageHeadline_options', $ImageHeadline_options); |
|---|
| 1056 | } |
|---|
| 1057 | if(ImageHeadline_option_set( 'only_use_imagecreate' ) && function_exists( 'ImageCreateTrueColor' ) ) |
|---|
| 1058 | { |
|---|
| 1059 | unset($ImageHeadline_options[array_search('only_use_imagecreate',$ImageHeadline_options)]); |
|---|
| 1060 | $ImageHeadline_options = array_values( $ImageHeadline_options ); |
|---|
| 1061 | ImageHeadline_update_option('ImageHeadline_options', $ImageHeadline_options); |
|---|
| 1062 | } |
|---|
| 1063 | } |
|---|
| 1064 | |
|---|
| 1065 | |
|---|
| 1066 | if( !ImageHeadline_option_set( 'disable_headlines' ) ) |
|---|
| 1067 | { |
|---|
| 1068 | if( !file_exists( $ImageHeadline_settings['cache_folder'] ) ) { |
|---|
| 1069 | if( !@mkdir ( $ImageHeadline_settings['cache_folder'], 0755 ) ) { |
|---|
| 1070 | echo '<div class="updated" style="background-color: #FF8080;border: 3px solid #F00;"><p><strong>' . __('FATAL: The directory you specified to cache the image files did not exist and I could not create it. Either create it for me or select a different directory.', 'headlinedomain') . '</strong></p></div>'; |
|---|
| 1071 | } |
|---|
| 1072 | } |
|---|
| 1073 | if( !is_writable( $ImageHeadline_settings['cache_folder'] ) ) |
|---|
| 1074 | { |
|---|
| 1075 | echo '<div class="updated" style="background-color: #FF8080;border: 3px solid #F00;"><p><strong>' . __('FATAL: The directory you specified to cache the image files is not writeable from the Apache task. Either select a different directory or make the directory you specified writable by the Apache task (chmod 755 the directory).', 'headlinedomain') . '</strong></p></div>'; |
|---|
| 1076 | $cache_folder_error = true; |
|---|
| 1077 | } |
|---|
| 1078 | |
|---|
| 1079 | $fonts = ImageHeadline_get_fonts(); |
|---|
| 1080 | $allowed_types = explode(' ', trim(strtolower(get_settings('fileupload_allowedtypes')))); |
|---|
| 1081 | |
|---|
| 1082 | if ( ( get_option('use_fileupload') ) && $user_level >= get_settings('fileupload_minlevel') ) { |
|---|
| 1083 | if( in_array('ttf', $allowed_types) ) { |
|---|
| 1084 | $upload_text = __('. You may use the <a href="','headlinedomain').get_settings( 'siteurl' )."/wp-admin/upload.php\">".__('Upload</a> feature of WordPress to upload more fonts','headlinedomain'); |
|---|
| 1085 | } else { |
|---|
| 1086 | $upload_text = __('. Upload more fonts using the Upload feature of WordPress, but first you must <a href="','headlinedomain').get_settings( 'siteurl' )."/wp-admin/options-misc.php\">".__('allow</a> TTF files to be uploaded','headlinedomain'); |
|---|
| 1087 | } |
|---|
| 1088 | } else { |
|---|
| 1089 | $upload_text = ''; |
|---|
| 1090 | } |
|---|
| 1091 | |
|---|
| 1092 | ?> |
|---|
| 1093 | |
|---|
| 1094 | <div class="wrap"> |
|---|
| 1095 | <h2><?php _e("Headline Image Options", 'headlinedomain') ?></h2> |
|---|
| 1096 | <form name="headline_form" method="post"> |
|---|
| 1097 | <fieldset class="options"> |
|---|
| 1098 | <legend> |
|---|
| 1099 | <?php _e("Preview", 'headlinedomain')?> |
|---|
| 1100 | </legend> |
|---|
| 1101 | <?php _e('This is a preview of your current settings. Save your settings to update the preview.', 'headlinedomain' ) ?> |
|---|
| 1102 | <p> |
|---|
| 1103 | <?php echo imageheadlines( $ImageHeadline_settings['before_text'].$render_title ); ?> |
|---|
| 1104 | </p> |
|---|
| 1105 | <label for="preview_text"> |
|---|
| 1106 | <?php _e('Preview text to display:', 'headlinedomain' ) ?> |
|---|
| 1107 | </label> |
|---|
| 1108 | <input type="text" name="ImageHeadline_settings[preview_text]" value="<?php echo stripslashes($edited_preview_text) ?>" size="70"> |
|---|
| 1109 | </fieldset> |
|---|
| 1110 | <fieldset class="options"> |
|---|
| 1111 | <legend> |
|---|
| 1112 | <?php _e("General Configuration", 'headlinedomain')?> |
|---|
| 1113 | |
|---|
| 1114 | </legend> |
|---|
| 1115 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1116 | <tr valign="top"> |
|---|
| 1117 | <th width="45%" scope="row"><?php if( $cache_folder_error ) echo "<span style='color: #f00;'>"; _e('Image cache folder <em>(Where images will be cached on your server. MUST be a full path to a folder writeable by the Apache process.):', 'headlinedomain' ); if( $cache_folder_error ) echo "</span>" ?></th> |
|---|
| 1118 | <td><input type="text" name="ImageHeadline_settings[cache_folder]" value="<?php echo stripslashes($ImageHeadline_settings['cache_folder']) ?>" size="70" /></td> |
|---|
| 1119 | </tr> |
|---|
| 1120 | <tr valign="top"> |
|---|
| 1121 | <th width="45%" scope="row"><?php _e('Image cache URL <em>(URL to the same folder as above.)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1122 | <td><input type="text" name="ImageHeadline_settings[cache_url]" value="<?php echo $ImageHeadline_settings['cache_url'] ?>" size="70" /></td> |
|---|
| 1123 | </tr> |
|---|
| 1124 | <tr valign="top"> |
|---|
| 1125 | <th width="45%" scope="row"><?php _e('Image cache lifetime <em>(time in days that images will remain in cache)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1126 | <td><input type="text" name="ImageHeadline_settings[image_lifetime]" value="<?php echo $ImageHeadline_settings['image_lifetime'] ?>" size="4" /></td> |
|---|
| 1127 | </tr> |
|---|
| 1128 | </table> |
|---|
| 1129 | </fieldset> |
|---|
| 1130 | <fieldset class="options"> |
|---|
| 1131 | <legend> |
|---|
| 1132 | <?php _e("Font and Colors", 'headlinedomain')?> |
|---|
| 1133 | |
|---|
| 1134 | </legend> |
|---|
| 1135 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1136 | <tr valign="center"> |
|---|
| 1137 | <th width="45%" scope="row"><?php _e('Font <em>(must be a .ttf file', 'headlinedomain' ); echo $upload_text; _e('.)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1138 | <?php if( count( $fonts ) > 0 ) { ?> |
|---|
| 1139 | <td><select name="ImageHeadline_settings[font_file]"> |
|---|
| 1140 | <?php for( $x = 0; $x < count( $fonts ); $x++ ) { ?> |
|---|
| 1141 | <option value="<?php echo $fonts[$x]["font_file"];?>"<?php ImageHeadline_check_select('font_file',$ImageHeadline_settings,$fonts[$x]["font_file"]);?>><?php echo $fonts[$x]["font_name"];?></option> |
|---|
| 1142 | <?php } ?> |
|---|
| 1143 | </select></td> |
|---|
| 1144 | <?php } else { ?> |
|---|
| 1145 | <td>You have no fonts installed. They should be installed in the 'wp-content/image-headlines' directory of your WordPress installation or in your WordPress uploads directory. Only TrueType (TTF) fonts are allowed.</td> |
|---|
| 1146 | <?php } ?> |
|---|
| 1147 | </tr> |
|---|
| 1148 | |
|---|
| 1149 | <tr valign="top"> |
|---|
| 1150 | <th width="45%" scope="row"><?php _e('Font size <em>(in points)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1151 | <td><input type="text" name="ImageHeadline_settings[font_size]" value="<?php echo $ImageHeadline_settings['font_size'] ?>" size="4"></td> |
|---|
| 1152 | </tr> |
|---|
| 1153 | <tr valign="top"> |
|---|
| 1154 | <th width="45%" scope="row"><?php _e('Font color <em>(in HTML format, e.g. #44CCAA)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1155 | <td><input type="text" name="ImageHeadline_settings[font_color]" value="<?php echo $ImageHeadline_settings['font_color'] ?>" size="8"></td> |
|---|
| 1156 | </tr> |
|---|
| 1157 | <tr valign="top"> |
|---|
| 1158 | <th width="45%" scope="row"><?php _e('Background color <em>(in HTML format, e.g. #44CCAA)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1159 | <td><input type="text" name="ImageHeadline_settings[background_color]" value="<?php echo $ImageHeadline_settings['background_color'] ?>" size="8"></td> |
|---|
| 1160 | </tr> |
|---|
| 1161 | <tr valign="top"> |
|---|
| 1162 | <th width="45%" scope="row"></th> |
|---|
| 1163 | <td><input name="ImageHeadline_options[]" type="checkbox" id="transparent_background" value="transparent_background" <?php ImageHeadline_check_flag('transparent_background', $ImageHeadline_options); ?> /><label for="transparent_background"><?php _e("Make background color transparent.", 'headlinedomain')?></label></td> |
|---|
| 1164 | </tr> |
|---|
| 1165 | </table> |
|---|
| 1166 | <fieldset class="options"> |
|---|
| 1167 | <legend> |
|---|
| 1168 | <input name="ImageHeadline_options[]" type="checkbox" id="use_background_image" value="use_background_image" <?php ImageHeadline_check_flag('use_background_image', $ImageHeadline_options); ?> /> |
|---|
| 1169 | <label for="use_background_image"><?php _e("Display a background image", 'headlinedomain')?></label> |
|---|
| 1170 | </legend> |
|---|
| 1171 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1172 | <tr valign="top"> |
|---|
| 1173 | <th width="45%" scope="row"><?php _e('Background image <em>(in PNG format)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1174 | <td><input type="text" name="ImageHeadline_settings[background_image]" value="<?php echo $ImageHeadline_settings['background_image'] ?>" size="70"></td> |
|---|
| 1175 | </tr> |
|---|
| 1176 | </table> |
|---|
| 1177 | </fieldset> |
|---|
| 1178 | </fieldset> |
|---|
| 1179 | <fieldset class="options"> |
|---|
| 1180 | <legend> |
|---|
| 1181 | <?php _e("Line Spacing", 'headlinedomain')?> |
|---|
| 1182 | |
|---|
| 1183 | </legend> |
|---|
| 1184 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1185 | <tr valign="top"> |
|---|
| 1186 | <th width="45%" scope="row"><?php _e('Left padding between image edge and text start <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1187 | <td><input type="text" name="ImageHeadline_settings[left_padding]" value="<?php echo $ImageHeadline_settings['left_padding'] ?>" size="4"></td> |
|---|
| 1188 | </tr> |
|---|
| 1189 | </table> |
|---|
| 1190 | <fieldset class="options"> |
|---|
| 1191 | <legend> |
|---|
| 1192 | <input name="ImageHeadline_options[]" type="checkbox" id="split_lines" value="split_lines" <?php ImageHeadline_check_flag('split_lines', $ImageHeadline_options); ?> /> |
|---|
| 1193 | <label for="split_lines"><?php _e("Split long lines", 'headlinedomain')?></label> |
|---|
| 1194 | </legend> |
|---|
| 1195 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1196 | <tr valign="top"> |
|---|
| 1197 | <th width="45%" scope="row"><?php _e('Maximimum line length before line break <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1198 | <td><input type="text" name="ImageHeadline_settings[max_width]" value="<?php echo $ImageHeadline_settings['max_width'] ?>" size="4" /></td> |
|---|
| 1199 | </tr> |
|---|
| 1200 | <tr valign="top"> |
|---|
| 1201 | <th width="45%" scope="row"><?php _e('Vertical space between lines <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1202 | <td><input type="text" name="ImageHeadline_settings[space_between_lines]" value="<?php echo $ImageHeadline_settings['space_between_lines'] ?>" size="4"></td> |
|---|
| 1203 | </tr> |
|---|
| 1204 | <tr valign="top"> |
|---|
| 1205 | <th width="45%" scope="row"><?php _e('Line indent from left border <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1206 | <td><input type="text" name="ImageHeadline_settings[line_indent]" value="<?php echo $ImageHeadline_settings['line_indent'] ?>" size="4"></td> |
|---|
| 1207 | </tr> |
|---|
| 1208 | </table> |
|---|
| 1209 | </fieldset> |
|---|
| 1210 | </fieldset> |
|---|
| 1211 | <fieldset class="options"> |
|---|
| 1212 | <legend> |
|---|
| 1213 | <input name="ImageHeadline_options[]" type="checkbox" id="shadows" value="shadows" <?php ImageHeadline_check_flag('shadows', $ImageHeadline_options); ?> /> |
|---|
| 1214 | <label for="shadows"><?php _e("Enable shadow behind text", 'headlinedomain')?></label> |
|---|
| 1215 | </legend> |
|---|
| 1216 | <fieldset class="options"> |
|---|
| 1217 | <legend> |
|---|
| 1218 | <input name="ImageHeadline_settings[soft_shadows]" <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) echo "disabled"?> type="radio" value="1" <?php ImageHeadline_check_radio('soft_shadows', $ImageHeadline_settings, 1); ?> /> |
|---|
| 1219 | <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) { ?> |
|---|
| 1220 | <label for="ImageHeadline_settings[soft_shadows]"><?php _e("Use soft-shadows <em>(Not available... requires GD version 2.0 or higher.)</em>", 'headlinedomain')?></label> |
|---|
| 1221 | <?php } else { ?> |
|---|
| 1222 | <label for="ImageHeadline_settings[soft_shadows]"><?php _e("Use soft-shadows <em>(computationally expensive)</em>", 'headlinedomain')?></label> |
|---|
| 1223 | <?php } ?> |
|---|
| 1224 | </legend> |
|---|
| 1225 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1226 | <tr valign="top"> |
|---|
| 1227 | <th width="45%" scope="row"><?php _e('Shadow color <em>(in HTML format, e.g. #44CCAA)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1228 | <td><input type="text" <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) echo "disabled"?> name="ImageHeadline_settings[shadow_color]" value="<?php echo $ImageHeadline_settings['shadow_color'] ?>" size="8"></td> |
|---|
| 1229 | </tr> |
|---|
| 1230 | <tr valign="top"> |
|---|
| 1231 | <th width="45%" scope="row"><?php _e('Shadow spread <em>(in pixels (1 - 10). The larger the spread the more diffuse the effect and slower to process)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1232 | <td><input type="text" <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) echo "disabled"?> name="ImageHeadline_settings[shadow_spread]" value="<?php echo $ImageHeadline_settings['shadow_spread'] ?>" size="2"></td> |
|---|
| 1233 | </tr> |
|---|
| 1234 | <tr valign="top"> |
|---|
| 1235 | <th width="45%" scope="row"><?php _e('Vertical offset <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1236 | <td><input type="text" <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) echo "disabled"?> name="ImageHeadline_settings[shadow_vertical_offset]" value="<?php echo $ImageHeadline_settings['shadow_vertical_offset'] ?>" size="2"></td> |
|---|
| 1237 | </tr> |
|---|
| 1238 | <tr valign="top"> |
|---|
| 1239 | <th width="45%" scope="row"><?php _e('Horizontal offset <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1240 | <td><input type="text" <?php if( ImageHeadline_option_set( 'only_use_imagecreate' )) echo "disabled"?> name="ImageHeadline_settings[shadow_horizontal_offset]" value="<?php echo $ImageHeadline_settings['shadow_horizontal_offset'] ?>" size="2"></td> |
|---|
| 1241 | </tr> |
|---|
| 1242 | </table> |
|---|
| 1243 | </fieldset> |
|---|
| 1244 | <fieldset class="options"> |
|---|
| 1245 | <legend> |
|---|
| 1246 | <input name="ImageHeadline_settings[soft_shadows]" type="radio" value="0" <?php ImageHeadline_check_radio('soft_shadows', $ImageHeadline_settings, 0); ?> /> |
|---|
| 1247 | <label for="ImageHeadline_settings[soft_shadows]"><?php _e("Use classic shadows <em>(simple and fast but not as pretty)</em>", 'headlinedomain')?></label> |
|---|
| 1248 | </legend> |
|---|
| 1249 | <table width="100%" cellspacing="2" cellpadding="5" class="editform"> |
|---|
| 1250 | <tr valign="top"> |
|---|
| 1251 | <th width="45%" scope="row"><?php _e('Shadow offset <em>(in pixels)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1252 | <td><input type="text" name="ImageHeadline_settings[shadow_offset]" value="<?php echo $ImageHeadline_settings['shadow_offset'] ?>" size="2"></td> |
|---|
| 1253 | </tr> |
|---|
| 1254 | <tr valign="top"> |
|---|
| 1255 | <th width="45%" scope="row"><?php _e('First shadow color <em>(in HTML format, e.g. #44CCAA)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1256 | <td><input type="text" name="ImageHeadline_settings[shadow_first_color]" value="<?php echo $ImageHeadline_settings['shadow_first_color'] ?>" size="8"></td> |
|---|
| 1257 | </tr> |
|---|
| 1258 | <tr valign="top"> |
|---|
| 1259 | <th width="45%" scope="row"><?php _e('Second shadow color <em>(in HTML format, e.g. #44CCAA)</em>:', 'headlinedomain' ) ?></th> |
|---|
| 1260 | <td><input type="text" name="ImageHeadline_settings[shadow_second_color]" value="<?php echo $ImageHeadline_settings['shadow_second_color'] ?>" size="8"></td> |
|---|
| 1261 | </tr> |
|---|
| 1262 | </table> |
|---|
| 1263 | </fieldset> |
|---|
| 1264 | </fieldset> |
|---|
| 1265 | <?php if( ImageHeadline_option_set( 'only_use_imagecreate' ) ) { ?> |
|---|
| 1266 | <input name="ImageHeadline_options[]" type="hidden" id="only_use_imagecreate" value="only_use_imagecreate" /> |
|---|
| 1267 | <?php } ?> |
|---|
| 1268 | <p class="submit"> |
|---|
| 1269 | <input type="submit" name="update_options" value="<?php _e('Update Options') ?>" /> |
|---|
| 1270 | </p> |
|---|
| 1271 | </form> |
|---|
| 1272 | </div> |
|---|
| 1273 | <?php |
|---|
| 1274 | } |
|---|
| 1275 | |
|---|
| 1276 | } else { |
|---|
| 1277 | |
|---|
| 1278 | // Add a filter to the titles so all titles (that have the prepended text) |
|---|
| 1279 | // will be replaced with images. |
|---|
| 1280 | add_filter('the_title', 'imageheadlines', 12); |
|---|
| 1281 | add_action('admin_menu', 'ImageHeadline_add_options_page'); |
|---|
| 1282 | } |
|---|
| 1283 | ?> |
|---|