[ Index ] |
PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09) |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 This script is supposed to be used together with the HTML2FPDF.php class 4 Copyright (C) 2004-2005 Renato Coelho 5 */ 6 7 function ConvertColor( $color = "#000000" ) 8 { 9 // returns an associative array (keys: R,G,B) from html code (e.g. #3FE5AA) 10 // W3C approved color array (disabled) 11 // static $common_colors = array('black'=>'#000000','silver'=>'#C0C0C0','gray'=>'#808080', 'white'=>'#FFFFFF','maroon'=>'#800000','red'=>'#FF0000','purple'=>'#800080','fuchsia'=>'#FF00FF','green'=>'#008000','lime'=>'#00FF00','olive'=>'#808000','yellow'=>'#FFFF00','navy'=>'#000080', 'blue'=>'#0000FF','teal'=>'#008080','aqua'=>'#00FFFF'); 12 // All color names array 13 static $common_colors = array( 'antiquewhite' => '#FAEBD7', 'aquamarine' => '#7FFFD4', 'beige' => '#F5F5DC', 'black' => '#000000', 'blue' => '#0000FF', 'brown' => '#A52A2A', 'cadetblue' => '#5F9EA0', 'chocolate' => '#D2691E', 'cornflowerblue' => '#6495ED', 'crimson' => '#DC143C', 'darkblue' => '#00008B', 'darkgoldenrod' => '#B8860B', 'darkgreen' => '#006400', 'darkmagenta' => '#8B008B', 'darkorange' => '#FF8C00', 'darkred' => '#8B0000', 'darkseagreen' => '#8FBC8F', 'darkslategray' => '#2F4F4F', 'darkviolet' => '#9400D3', 'deepskyblue' => '#00BFFF', 'dodgerblue' => '#1E90FF', 'firebrick' => '#B22222', 'forestgreen' => '#228B22', 'gainsboro' => '#DCDCDC', 'gold' => '#FFD700', 'gray' => '#808080', 'green' => '#008000', 'greenyellow' => '#ADFF2F', 'hotpink' => '#FF69B4', 'indigo' => '#4B0082', 'khaki' => '#F0E68C', 'lavenderblush' => '#FFF0F5', 'lemonchiffon' => '#FFFACD', 'lightcoral' => '#F08080', 'lightgoldenrodyellow' => '#FAFAD2', 'lightgreen' => '#90EE90', 'lightsalmon' => '#FFA07A', 'lightskyblue' => '#87CEFA', 'lightslategray' => '#778899', 'lightyellow' => '#FFFFE0', 'limegreen' => '#32CD32', 'magenta' => '#FF00FF', 'mediumaquamarine' => '#66CDAA', 'mediumorchid' => '#BA55D3', 'mediumseagreen' => '#3CB371', 'mediumspringgreen' => '#00FA9A', 'mediumvioletred' => '#C71585', 'mintcream' => '#F5FFFA', 'moccasin' => '#FFE4B5', 'navy' => '#000080', 'olive' => '#808000', 'orange' => '#FFA500', 'orchid' => '#DA70D6', 'palegreen' => '#98FB98', 'palevioletred' => '#D87093', 'peachpuff' => '#FFDAB9', 'pink' => '#FFC0CB', 'powderblue' => '#B0E0E6', 'red' => '#FF0000', 'royalblue' => '#4169E1', 'salmon' => '#FA8072', 'seagreen' => '#2E8B57', 'sienna' => '#A0522D', 'skyblue' => '#87CEEB', 'slategray' => '#708090', 'springgreen' => '#00FF7F', 'tan' => '#D2B48C', 'thistle' => '#D8BFD8', 'turquoise' => '#40E0D0', 'violetred' => '#D02090', 'white' => '#FFFFFF', 'yellow' => '#FFFF00' ); 14 // http://www.w3schools.com/css/css_colornames.asp 15 if ( ( $color{0} != '#' ) and ( strstr( $color, '(' ) === false ) ) $color = $common_colors[strtolower( $color )]; 16 17 if ( $color{0} == '#' ) { // case of #nnnnnn or #nnn 18 $cor = strtoupper( $color ); 19 if ( strlen( $cor ) == 4 ) { // Turn #RGB into #RRGGBB 20 $cor = "#" . $cor{1} . $cor{1} . $cor{2} . $cor{2} . $cor{3} . $cor{3}; 21 } 22 $R = substr( $cor, 1, 2 ); 23 $vermelho = hexdec( $R ); 24 $V = substr( $cor, 3, 2 ); 25 $verde = hexdec( $V ); 26 $B = substr( $cor, 5, 2 ); 27 $azul = hexdec( $B ); 28 $color = array(); 29 $color['R'] = $vermelho; 30 $color['G'] = $verde; 31 $color['B'] = $azul; 32 } else { // case of RGB(r,g,b) 33 $color = str_replace( "rgb(", '', $color ); //remove ´rgb(´ 34 $color = str_replace( "RGB(", '', $color ); //remove ´RGB(´ -- PHP < 5 does not have str_ireplace 35 $color = str_replace( ")", '', $color ); //remove ´)´ 36 $cores = explode( ",", $color ); 37 $color = array(); 38 $color['R'] = $cores[0]; 39 $color['G'] = $cores[1]; 40 $color['B'] = $cores[2]; 41 } 42 if ( empty( $color ) ) return array( 'R' => 255, 'G' => 255, 'B' => 255 ); 43 else return $color; // array['R']['G']['B'] 44 } 45 46 function ConvertSize( $size = 5, $maxsize = 0 ) 47 { 48 // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth 49 // Identify size (remember: we are using 'mm' units here) 50 if ( stristr( $size, 'px' ) ) $size *= 0.2645; //pixels 51 elseif ( stristr( $size, 'cm' ) ) $size *= 10; //centimeters 52 elseif ( stristr( $size, 'mm' ) ) $size += 0; //millimeters 53 elseif ( stristr( $size, 'in' ) ) $size *= 25.4; //inches 54 elseif ( stristr( $size, 'pc' ) ) $size *= 38.1 / 9; //PostScript picas 55 elseif ( stristr( $size, 'pt' ) ) $size *= 25.4 / 72; //72dpi 56 elseif ( stristr( $size, '%' ) ) { 57 $size += 0; //make "90%" become simply "90" 58 $size *= $maxsize / 100; 59 } else $size *= 0.2645; //nothing == px 60 return $size; 61 } 62 63 function value_entity_decode( $html ) 64 { 65 // replace each value entity by its respective char 66 preg_match_all( '|&#(.*?);|', $html, $temparray ); 67 foreach( $temparray[1] as $val ) $html = str_replace( "&#" . $val . ";", chr( $val ), $html ); 68 return $html; 69 } 70 71 function lesser_entity_decode( $html ) 72 { 73 // supports the most used entity codes 74 $html = str_replace( " ", " ", $html ); 75 $html = str_replace( "&", "&", $html ); 76 $html = str_replace( "<", "<", $html ); 77 $html = str_replace( ">", ">", $html ); 78 $html = str_replace( "«", "«", $html ); 79 $html = str_replace( "»", "»", $html ); 80 $html = str_replace( "¶", "¶", $html ); 81 $html = str_replace( "€", "€", $html ); 82 $html = str_replace( "™", "™", $html ); 83 $html = str_replace( "©", "©", $html ); 84 $html = str_replace( "®", "®", $html ); 85 $html = str_replace( "±", "±", $html ); 86 $html = str_replace( "˜", "~", $html ); 87 $html = str_replace( "ˆ", "^", $html ); 88 $html = str_replace( """, '"', $html ); 89 $html = str_replace( "‰", "‰", $html ); 90 $html = str_replace( "‡", "‡", $html ); 91 $html = str_replace( "†", "†", $html ); 92 return $html; 93 } 94 95 function AdjustHTML( $html, $usepre = true ) 96 { 97 // Try to make the html text more manageable (turning it into XHTML) 98 // Remove javascript code from HTML (should not appear in the PDF file) 99 $regexp = '|<script.*?</script>|si'; 100 $html = preg_replace( $regexp, '', $html ); 101 102 $html = str_replace( "\r\n", "\n", $html ); //replace carriagereturn-linefeed-combo by a simple linefeed 103 $html = str_replace( "\f", '', $html ); //replace formfeed by nothing 104 $html = str_replace( "\r", '', $html ); //replace carriage return by nothing 105 if ( $usepre ) { // used to keep \n on content inside <pre> and inside <textarea> 106 // Preserve '\n's in content between the tags <pre> and </pre> 107 $regexp = '#<pre(.*?)>(.+?)</pre>#si'; 108 $thereispre = preg_match_all( $regexp, $html, $temp ); 109 // Preserve '\n's in content between the tags <textarea> and </textarea> 110 $regexp2 = '#<textarea(.*?)>(.+?)</textarea>#si'; 111 $thereistextarea = preg_match_all( $regexp2, $html, $temp2 ); 112 $html = str_replace( "\n", ' ', $html ); //replace linefeed by spaces 113 $html = str_replace( "\t", ' ', $html ); //replace tabs by spaces 114 $regexp3 = '#\s{2,}#s'; // turn 2+ consecutive spaces into one 115 $html = preg_replace( $regexp3, ' ', $html ); 116 $iterator = 0; 117 while ( $thereispre ) { // Recover <pre attributes>content</pre> 118 $temp[2][$iterator] = str_replace( "\n", "<br>", $temp[2][$iterator] ); 119 $html = preg_replace( $regexp, '<erp' . $temp[1][$iterator] . '>' . $temp[2][$iterator] . '</erp>', $html, 1 ); 120 $thereispre--; 121 $iterator++; 122 } 123 $iterator = 0; 124 while ( $thereistextarea ) { // Recover <textarea attributes>content</textarea> 125 $temp2[2][$iterator] = str_replace( " ", " ", $temp2[2][$iterator] ); 126 $html = preg_replace( $regexp2, '<aeratxet' . $temp2[1][$iterator] . '>' . trim( $temp2[2][$iterator] ) . '</aeratxet>', $html, 1 ); 127 $thereistextarea--; 128 $iterator++; 129 } 130 // Restore original tag names 131 $html = str_replace( "<erp", "<pre", $html ); 132 $html = str_replace( "</erp>", "</pre>", $html ); 133 $html = str_replace( "<aeratxet", "<textarea", $html ); 134 $html = str_replace( "</aeratxet>", "</textarea>", $html ); 135 // (the code above might slowdown overall performance?) 136 } //end of if($usepre) 137 else { 138 $html = str_replace( "\n", ' ', $html ); //replace linefeed by spaces 139 $html = str_replace( "\t", ' ', $html ); //replace tabs by spaces 140 $regexp = '/\\s{2,}/s'; // turn 2+ consecutive spaces into one 141 $html = preg_replace( $regexp, ' ', $html ); 142 } 143 // remove redundant <br>'s before </div>, avoiding huge leaps between text blocks 144 // such things appear on computer-generated HTML code 145 $regexp = '/(<br[ \/]?[\/]?>)+?<\/div>/si'; //<?//fix PSPAD highlight bug 146 $html = preg_replace( $regexp, '</div>', $html ); 147 return $html; 148 } 149 150 function dec2alpha( $valor, $toupper = "true" ) 151 { 152 // returns a string from A-Z to AA-ZZ to AAA-ZZZ 153 // OBS: A = 65 ASCII TABLE VALUE 154 if ( ( $valor < 1 ) || ( $valor > 18278 ) ) return "?"; //supports 'only' up to 18278 155 $c1 = $c2 = $c3 = ''; 156 if ( $valor > 702 ) { // 3 letters (up to 18278) 157 $c1 = 65 + floor( ( $valor-703 ) / 676 ); 158 $c2 = 65 + floor( ( ( $valor-703 ) % 676 ) / 26 ); 159 $c3 = 65 + floor( ( ( $valor-703 ) % 676 ) % 26 ); 160 } elseif ( $valor > 26 ) { // 2 letters (up to 702) 161 $c1 = ( 64 + ( int )( ( $valor-1 ) / 26 ) ); 162 $c2 = ( 64 + ( int )( $valor % 26 ) ); 163 if ( $c2 == 64 ) $c2 += 26; 164 } else { // 1 letter (up to 26) 165 $c1 = ( 64 + $valor ); 166 } 167 $alpha = chr( $c1 ); 168 if ( $c2 != '' ) $alpha .= chr( $c2 ); 169 if ( $c3 != '' ) $alpha .= chr( $c3 ); 170 if ( !$toupper ) $alpha = strtolower( $alpha ); 171 return $alpha; 172 } 173 174 function dec2roman( $valor, $toupper = true ) 175 { 176 // returns a string as a roman numeral 177 if ( ( $valor >= 5000 ) || ( $valor < 1 ) ) return "?"; //supports 'only' up to 4999 178 $aux = ( int )( $valor / 1000 ); 179 if ( $aux !== 0 ) { 180 $valor %= 1000; 181 while ( $aux !== 0 ) { 182 $r1 .= "M"; 183 $aux--; 184 } 185 } 186 $aux = ( int )( $valor / 100 ); 187 if ( $aux !== 0 ) { 188 $valor %= 100; 189 switch ( $aux ) { 190 case 3: $r2 = "C"; 191 case 2: $r2 .= "C"; 192 case 1: $r2 .= "C"; 193 break; 194 case 9: $r2 = "CM"; 195 break; 196 case 8: $r2 = "C"; 197 case 7: $r2 .= "C"; 198 case 6: $r2 .= "C"; 199 case 5: $r2 = "D" . $r2; 200 break; 201 case 4: $r2 = "CD"; 202 break; 203 default: break; 204 } 205 } 206 $aux = ( int )( $valor / 10 ); 207 if ( $aux !== 0 ) { 208 $valor %= 10; 209 switch ( $aux ) { 210 case 3: $r3 = "X"; 211 case 2: $r3 .= "X"; 212 case 1: $r3 .= "X"; 213 break; 214 case 9: $r3 = "XC"; 215 break; 216 case 8: $r3 = "X"; 217 case 7: $r3 .= "X"; 218 case 6: $r3 .= "X"; 219 case 5: $r3 = "L" . $r3; 220 break; 221 case 4: $r3 = "XL"; 222 break; 223 default: break; 224 } 225 } 226 switch ( $valor ) { 227 case 3: $r4 = "I"; 228 case 2: $r4 .= "I"; 229 case 1: $r4 .= "I"; 230 break; 231 case 9: $r4 = "IX"; 232 break; 233 case 8: $r4 = "I"; 234 case 7: $r4 .= "I"; 235 case 6: $r4 .= "I"; 236 case 5: $r4 = "V" . $r4; 237 break; 238 case 4: $r4 = "IV"; 239 break; 240 default: break; 241 } 242 $roman = $r1 . $r2 . $r3 . $r4; 243 if ( !$toupper ) $roman = strtolower( $roman ); 244 return $roman; 245 } 246 247 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 30 05:55:15 2009 | Cross-referenced by PHPXref 0.7 |