| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
class TCPDF_STATIC { |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
private static $tcpdf_version = '6.11.3'; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public static $alias_tot_pages = '{:ptp:}'; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static $alias_num_page = '{:pnp:}'; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public static $alias_group_tot_pages = '{:ptg:}'; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public static $alias_group_num_page = '{:png:}'; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public static $alias_right_shift = '{rsc:'; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public static $byterange_string = '/ByteRange[0 ********** ********** **********]'; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
protected const CURLOPT_DEFAULT = [ |
| 115 |
CURLOPT_CONNECTTIMEOUT => 5, |
| 116 |
CURLOPT_MAXREDIRS => 5, |
| 117 |
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS, |
| 118 |
CURLOPT_SSL_VERIFYHOST => 2, |
| 119 |
CURLOPT_SSL_VERIFYPEER => true, |
| 120 |
CURLOPT_TIMEOUT => 30, |
| 121 |
CURLOPT_USERAGENT => 'tcpdf', |
| 122 |
]; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
protected const CURLOPT_FIXED = [ |
| 130 |
CURLOPT_FAILONERROR => true, |
| 131 |
CURLOPT_RETURNTRANSFER => true, |
| 132 |
]; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public static function getTCPDFVersion() { |
| 143 |
return self::$tcpdf_version; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public static function getTCPDFProducer() { |
| 153 |
return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29"; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public static function isValidURL($url) { |
| 164 |
$headers = @get_headers($url); |
| 165 |
if ($headers === false) { |
| 166 |
return false; |
| 167 |
} |
| 168 |
return (strpos($headers[0], '200') !== false); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public static function removeSHY($txt='', $unicode=true) { |
| 189 |
$txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); |
| 190 |
if (!$unicode) { |
| 191 |
$txt = preg_replace('/([\\xad]{1})/', '', $txt); |
| 192 |
} |
| 193 |
return $txt; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
public static function getBorderMode($brd, $position='start', $opencell=true) { |
| 207 |
if ((!$opencell) OR empty($brd)) { |
| 208 |
return $brd; |
| 209 |
} |
| 210 |
if ($brd == 1) { |
| 211 |
$brd = 'LTRB'; |
| 212 |
} |
| 213 |
if (is_string($brd)) { |
| 214 |
|
| 215 |
$slen = strlen($brd); |
| 216 |
$newbrd = array(); |
| 217 |
for ($i = 0; $i < $slen; ++$i) { |
| 218 |
$newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter'); |
| 219 |
} |
| 220 |
$brd = $newbrd; |
| 221 |
} |
| 222 |
foreach ($brd as $border => $style) { |
| 223 |
switch ($position) { |
| 224 |
case 'start': { |
| 225 |
if (strpos($border, 'B') !== false) { |
| 226 |
|
| 227 |
$newkey = str_replace('B', '', $border); |
| 228 |
if (strlen($newkey) > 0) { |
| 229 |
$brd[$newkey] = $style; |
| 230 |
} |
| 231 |
unset($brd[$border]); |
| 232 |
} |
| 233 |
break; |
| 234 |
} |
| 235 |
case 'middle': { |
| 236 |
if (strpos($border, 'B') !== false) { |
| 237 |
|
| 238 |
$newkey = str_replace('B', '', $border); |
| 239 |
if (strlen($newkey) > 0) { |
| 240 |
$brd[$newkey] = $style; |
| 241 |
} |
| 242 |
unset($brd[$border]); |
| 243 |
$border = $newkey; |
| 244 |
} |
| 245 |
if (strpos($border, 'T') !== false) { |
| 246 |
|
| 247 |
$newkey = str_replace('T', '', $border); |
| 248 |
if (strlen($newkey) > 0) { |
| 249 |
$brd[$newkey] = $style; |
| 250 |
} |
| 251 |
unset($brd[$border]); |
| 252 |
} |
| 253 |
break; |
| 254 |
} |
| 255 |
case 'end': { |
| 256 |
if (strpos($border, 'T') !== false) { |
| 257 |
|
| 258 |
$newkey = str_replace('T', '', $border); |
| 259 |
if (strlen($newkey) > 0) { |
| 260 |
$brd[$newkey] = $style; |
| 261 |
} |
| 262 |
unset($brd[$border]); |
| 263 |
} |
| 264 |
break; |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
return $brd; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public static function empty_string($str) { |
| 279 |
return (is_null($str) OR (is_string($str) AND (strlen($str) == 0))); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public static function getObjFilename($type='tmp', $file_id='') { |
| 291 |
return tempnam(K_PATH_CACHE, '__tcpdf_'.$file_id.'_'.$type.'_'.md5(TCPDF_STATIC::getRandomSeed()).'_'); |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
public static function _escape($s) { |
| 301 |
|
| 302 |
return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public static function _escapeXML($str) { |
| 313 |
$replaceTable = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); |
| 314 |
$str = strtr($str === null ? '' : $str, $replaceTable); |
| 315 |
return $str; |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
public static function objclone($object) { |
| 326 |
if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) { |
| 327 |
|
| 328 |
return @$object->clone(); |
| 329 |
} |
| 330 |
return @clone($object); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
public static function sendOutputData($data, $length) { |
| 341 |
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
| 342 |
|
| 343 |
header('Content-Length: '.$length); |
| 344 |
} |
| 345 |
echo $data; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
public static function replacePageNumAliases($page, $replace, $diff=0) { |
| 357 |
foreach ($replace as $rep) { |
| 358 |
foreach ($rep[3] as $a) { |
| 359 |
if (strpos($page, $a) !== false) { |
| 360 |
$page = str_replace($a, $rep[0], $page); |
| 361 |
$diff += ($rep[2] - $rep[1]); |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
return array($page, $diff); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
public static function getTimestamp($date) { |
| 376 |
if (($date[0] == 'D') AND ($date[1] == ':')) { |
| 377 |
|
| 378 |
$date = substr($date, 2); |
| 379 |
} |
| 380 |
return strtotime($date); |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
public static function getFormattedDate($time) { |
| 391 |
return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\''; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public static function getRandomSeed($seed='') { |
| 403 |
$rnd = uniqid(rand().microtime(true), true); |
| 404 |
if (function_exists('posix_getpid')) { |
| 405 |
$rnd .= posix_getpid(); |
| 406 |
} |
| 407 |
|
| 408 |
if (function_exists('random_bytes')) { |
| 409 |
$rnd .= random_bytes(512); |
| 410 |
} elseif (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { |
| 411 |
|
| 412 |
$rnd .= openssl_random_pseudo_bytes(512); |
| 413 |
} else { |
| 414 |
for ($i = 0; $i < 23; ++$i) { |
| 415 |
$rnd .= uniqid('', true); |
| 416 |
} |
| 417 |
} |
| 418 |
return $rnd.$seed.__FILE__.microtime(true); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
public static function _md5_16($str) { |
| 429 |
return pack('H*', md5($str)); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public static function _AES($key, $text) { |
| 443 |
|
| 444 |
$padding = 16 - (strlen($text) % 16); |
| 445 |
$text .= str_repeat(chr($padding), $padding); |
| 446 |
if (extension_loaded('openssl')) { |
| 447 |
$algo = 'aes-256-cbc'; |
| 448 |
if (strlen($key) == 16) { |
| 449 |
$algo = 'aes-128-cbc'; |
| 450 |
} |
| 451 |
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo)); |
| 452 |
$text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv); |
| 453 |
return $iv.substr($text, 0, -16); |
| 454 |
} |
| 455 |
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); |
| 456 |
$text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); |
| 457 |
$text = $iv.$text; |
| 458 |
return $text; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
public static function _AESnopad($key, $text) { |
| 472 |
if (extension_loaded('openssl')) { |
| 473 |
$algo = 'aes-256-cbc'; |
| 474 |
if (strlen($key) == 16) { |
| 475 |
$algo = 'aes-128-cbc'; |
| 476 |
} |
| 477 |
$iv = str_repeat("\x00", openssl_cipher_iv_length($algo)); |
| 478 |
$text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv); |
| 479 |
return substr($text, 0, -16); |
| 480 |
} |
| 481 |
$iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); |
| 482 |
$text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); |
| 483 |
return $text; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) { |
| 499 |
if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) { |
| 500 |
|
| 501 |
return $out; |
| 502 |
} |
| 503 |
if ($last_enc_key != $key) { |
| 504 |
$k = str_repeat($key, (int) ((256 / strlen($key)) + 1)); |
| 505 |
$rc4 = range(0, 255); |
| 506 |
$j = 0; |
| 507 |
for ($i = 0; $i < 256; ++$i) { |
| 508 |
$t = $rc4[$i]; |
| 509 |
$j = ($j + $t + ord($k[$i])) % 256; |
| 510 |
$rc4[$i] = $rc4[$j]; |
| 511 |
$rc4[$j] = $t; |
| 512 |
} |
| 513 |
$last_enc_key = $key; |
| 514 |
$last_enc_key_c = $rc4; |
| 515 |
} else { |
| 516 |
$rc4 = $last_enc_key_c; |
| 517 |
} |
| 518 |
$len = strlen($text); |
| 519 |
$a = 0; |
| 520 |
$b = 0; |
| 521 |
$out = ''; |
| 522 |
for ($i = 0; $i < $len; ++$i) { |
| 523 |
$a = ($a + 1) % 256; |
| 524 |
$t = $rc4[$a]; |
| 525 |
$b = ($b + $t) % 256; |
| 526 |
$rc4[$a] = $rc4[$b]; |
| 527 |
$rc4[$b] = $t; |
| 528 |
$k = $rc4[($rc4[$a] + $rc4[$b]) % 256]; |
| 529 |
$out .= chr(ord($text[$i]) ^ $k); |
| 530 |
} |
| 531 |
return $out; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
public static function getUserPermissionCode($permissions, $mode=0) { |
| 543 |
$options = array( |
| 544 |
'owner' => 2, |
| 545 |
'print' => 4, |
| 546 |
'modify' => 8, |
| 547 |
'copy' => 16, |
| 548 |
'annot-forms' => 32, |
| 549 |
'fill-forms' => 256, |
| 550 |
'extract' => 512, |
| 551 |
'assemble' => 1024, |
| 552 |
'print-high' => 2048 |
| 553 |
); |
| 554 |
$protection = 2147422012; |
| 555 |
foreach ($permissions as $permission) { |
| 556 |
if (isset($options[$permission])) { |
| 557 |
if (($mode > 0) OR ($options[$permission] <= 32)) { |
| 558 |
|
| 559 |
if ($options[$permission] == 2) { |
| 560 |
|
| 561 |
$protection += $options[$permission]; |
| 562 |
} else { |
| 563 |
$protection -= $options[$permission]; |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
return $protection; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
public static function convertHexStringToString($bs) { |
| 580 |
$string = ''; |
| 581 |
$bslength = strlen($bs); |
| 582 |
if (($bslength % 2) != 0) { |
| 583 |
|
| 584 |
$bs .= '0'; |
| 585 |
++$bslength; |
| 586 |
} |
| 587 |
for ($i = 0; $i < $bslength; $i += 2) { |
| 588 |
$string .= chr(hexdec($bs[$i].$bs[($i + 1)])); |
| 589 |
} |
| 590 |
return $string; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
public static function convertStringToHexString($s) { |
| 602 |
$bs = ''; |
| 603 |
$chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); |
| 604 |
foreach ($chars as $c) { |
| 605 |
$bs .= sprintf('%02s', dechex(ord($c))); |
| 606 |
} |
| 607 |
return $bs; |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
public static function getEncPermissionsString($protection) { |
| 619 |
$binprot = sprintf('%032b', $protection); |
| 620 |
$str = chr(bindec(substr($binprot, 24, 8))); |
| 621 |
$str .= chr(bindec(substr($binprot, 16, 8))); |
| 622 |
$str .= chr(bindec(substr($binprot, 8, 8))); |
| 623 |
$str .= chr(bindec(substr($binprot, 0, 8))); |
| 624 |
return $str; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
public static function encodeNameObject($name) { |
| 636 |
$escname = ''; |
| 637 |
$length = strlen($name); |
| 638 |
for ($i = 0; $i < $length; ++$i) { |
| 639 |
$chr = $name[$i]; |
| 640 |
if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) { |
| 641 |
$escname .= $chr; |
| 642 |
} else { |
| 643 |
$escname .= sprintf('#%02X', ord($chr)); |
| 644 |
} |
| 645 |
} |
| 646 |
return $escname; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) { |
| 660 |
if (isset($prop['aopt']) AND is_array($prop['aopt'])) { |
| 661 |
|
| 662 |
return $prop['aopt']; |
| 663 |
} |
| 664 |
$opt = array(); |
| 665 |
|
| 666 |
if (isset($prop['alignment'])) { |
| 667 |
switch ($prop['alignment']) { |
| 668 |
case 'left': { |
| 669 |
$opt['q'] = 0; |
| 670 |
break; |
| 671 |
} |
| 672 |
case 'center': { |
| 673 |
$opt['q'] = 1; |
| 674 |
break; |
| 675 |
} |
| 676 |
case 'right': { |
| 677 |
$opt['q'] = 2; |
| 678 |
break; |
| 679 |
} |
| 680 |
default: { |
| 681 |
$opt['q'] = ($rtl)?2:0; |
| 682 |
break; |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
if (isset($prop['lineWidth'])) { |
| 688 |
$linewidth = intval($prop['lineWidth']); |
| 689 |
} else { |
| 690 |
$linewidth = 1; |
| 691 |
} |
| 692 |
|
| 693 |
if (isset($prop['borderStyle'])) { |
| 694 |
switch ($prop['borderStyle']) { |
| 695 |
case 'border.d': |
| 696 |
case 'dashed': { |
| 697 |
$opt['border'] = array(0, 0, $linewidth, array(3, 2)); |
| 698 |
$opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2)); |
| 699 |
break; |
| 700 |
} |
| 701 |
case 'border.b': |
| 702 |
case 'beveled': { |
| 703 |
$opt['border'] = array(0, 0, $linewidth); |
| 704 |
$opt['bs'] = array('w'=>$linewidth, 's'=>'B'); |
| 705 |
break; |
| 706 |
} |
| 707 |
case 'border.i': |
| 708 |
case 'inset': { |
| 709 |
$opt['border'] = array(0, 0, $linewidth); |
| 710 |
$opt['bs'] = array('w'=>$linewidth, 's'=>'I'); |
| 711 |
break; |
| 712 |
} |
| 713 |
case 'border.u': |
| 714 |
case 'underline': { |
| 715 |
$opt['border'] = array(0, 0, $linewidth); |
| 716 |
$opt['bs'] = array('w'=>$linewidth, 's'=>'U'); |
| 717 |
break; |
| 718 |
} |
| 719 |
case 'border.s': |
| 720 |
case 'solid': { |
| 721 |
$opt['border'] = array(0, 0, $linewidth); |
| 722 |
$opt['bs'] = array('w'=>$linewidth, 's'=>'S'); |
| 723 |
break; |
| 724 |
} |
| 725 |
default: { |
| 726 |
break; |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
if (isset($prop['border']) AND is_array($prop['border'])) { |
| 731 |
$opt['border'] = $prop['border']; |
| 732 |
} |
| 733 |
if (!isset($opt['mk'])) { |
| 734 |
$opt['mk'] = array(); |
| 735 |
} |
| 736 |
if (!isset($opt['mk']['if'])) { |
| 737 |
$opt['mk']['if'] = array(); |
| 738 |
} |
| 739 |
$opt['mk']['if']['a'] = array(0.5, 0.5); |
| 740 |
|
| 741 |
if (isset($prop['buttonAlignX'])) { |
| 742 |
$opt['mk']['if']['a'][0] = $prop['buttonAlignX']; |
| 743 |
} |
| 744 |
|
| 745 |
if (isset($prop['buttonAlignY'])) { |
| 746 |
$opt['mk']['if']['a'][1] = $prop['buttonAlignY']; |
| 747 |
} |
| 748 |
|
| 749 |
if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) { |
| 750 |
$opt['mk']['if']['fb'] = true; |
| 751 |
} |
| 752 |
|
| 753 |
if (isset($prop['buttonScaleHow'])) { |
| 754 |
switch ($prop['buttonScaleHow']) { |
| 755 |
case 'scaleHow.proportional': { |
| 756 |
$opt['mk']['if']['s'] = 'P'; |
| 757 |
break; |
| 758 |
} |
| 759 |
case 'scaleHow.anamorphic': { |
| 760 |
$opt['mk']['if']['s'] = 'A'; |
| 761 |
break; |
| 762 |
} |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
if (isset($prop['buttonScaleWhen'])) { |
| 767 |
switch ($prop['buttonScaleWhen']) { |
| 768 |
case 'scaleWhen.always': { |
| 769 |
$opt['mk']['if']['sw'] = 'A'; |
| 770 |
break; |
| 771 |
} |
| 772 |
case 'scaleWhen.never': { |
| 773 |
$opt['mk']['if']['sw'] = 'N'; |
| 774 |
break; |
| 775 |
} |
| 776 |
case 'scaleWhen.tooBig': { |
| 777 |
$opt['mk']['if']['sw'] = 'B'; |
| 778 |
break; |
| 779 |
} |
| 780 |
case 'scaleWhen.tooSmall': { |
| 781 |
$opt['mk']['if']['sw'] = 'S'; |
| 782 |
break; |
| 783 |
} |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
if (isset($prop['buttonPosition'])) { |
| 788 |
switch ($prop['buttonPosition']) { |
| 789 |
case 0: |
| 790 |
case 'position.textOnly': { |
| 791 |
$opt['mk']['tp'] = 0; |
| 792 |
break; |
| 793 |
} |
| 794 |
case 1: |
| 795 |
case 'position.iconOnly': { |
| 796 |
$opt['mk']['tp'] = 1; |
| 797 |
break; |
| 798 |
} |
| 799 |
case 2: |
| 800 |
case 'position.iconTextV': { |
| 801 |
$opt['mk']['tp'] = 2; |
| 802 |
break; |
| 803 |
} |
| 804 |
case 3: |
| 805 |
case 'position.textIconV': { |
| 806 |
$opt['mk']['tp'] = 3; |
| 807 |
break; |
| 808 |
} |
| 809 |
case 4: |
| 810 |
case 'position.iconTextH': { |
| 811 |
$opt['mk']['tp'] = 4; |
| 812 |
break; |
| 813 |
} |
| 814 |
case 5: |
| 815 |
case 'position.textIconH': { |
| 816 |
$opt['mk']['tp'] = 5; |
| 817 |
break; |
| 818 |
} |
| 819 |
case 6: |
| 820 |
case 'position.overlay': { |
| 821 |
$opt['mk']['tp'] = 6; |
| 822 |
break; |
| 823 |
} |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
if (isset($prop['fillColor'])) { |
| 828 |
if (is_array($prop['fillColor'])) { |
| 829 |
$opt['mk']['bg'] = $prop['fillColor']; |
| 830 |
} else { |
| 831 |
$opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
if (isset($prop['strokeColor'])) { |
| 836 |
if (is_array($prop['strokeColor'])) { |
| 837 |
$opt['mk']['bc'] = $prop['strokeColor']; |
| 838 |
} else { |
| 839 |
$opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
if (isset($prop['rotation'])) { |
| 844 |
$opt['mk']['r'] = $prop['rotation']; |
| 845 |
} |
| 846 |
|
| 847 |
if (isset($prop['charLimit'])) { |
| 848 |
$opt['maxlen'] = intval($prop['charLimit']); |
| 849 |
} |
| 850 |
$ff = 0; |
| 851 |
|
| 852 |
if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { |
| 853 |
$ff += 1 << 0; |
| 854 |
} |
| 855 |
|
| 856 |
if (isset($prop['required']) AND ($prop['required'] == 'true')) { |
| 857 |
$ff += 1 << 1; |
| 858 |
} |
| 859 |
|
| 860 |
if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) { |
| 861 |
$ff += 1 << 12; |
| 862 |
} |
| 863 |
|
| 864 |
if (isset($prop['password']) AND ($prop['password'] == 'true')) { |
| 865 |
$ff += 1 << 13; |
| 866 |
} |
| 867 |
|
| 868 |
if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) { |
| 869 |
$ff += 1 << 14; |
| 870 |
} |
| 871 |
|
| 872 |
if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) { |
| 873 |
$ff += 1 << 15; |
| 874 |
} |
| 875 |
|
| 876 |
if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) { |
| 877 |
$ff += 1 << 16; |
| 878 |
} |
| 879 |
|
| 880 |
if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) { |
| 881 |
$ff += 1 << 17; |
| 882 |
} |
| 883 |
|
| 884 |
if (isset($prop['editable']) AND ($prop['editable'] == 'true')) { |
| 885 |
$ff += 1 << 18; |
| 886 |
} |
| 887 |
|
| 888 |
if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) { |
| 889 |
$ff += 1 << 19; |
| 890 |
} |
| 891 |
|
| 892 |
if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) { |
| 893 |
$ff += 1 << 20; |
| 894 |
} |
| 895 |
|
| 896 |
if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) { |
| 897 |
$ff += 1 << 21; |
| 898 |
} |
| 899 |
|
| 900 |
if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) { |
| 901 |
$ff += 1 << 22; |
| 902 |
} |
| 903 |
|
| 904 |
if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) { |
| 905 |
$ff += 1 << 23; |
| 906 |
} |
| 907 |
|
| 908 |
if (isset($prop['comb']) AND ($prop['comb'] == 'true')) { |
| 909 |
$ff += 1 << 24; |
| 910 |
} |
| 911 |
|
| 912 |
if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) { |
| 913 |
$ff += 1 << 25; |
| 914 |
} |
| 915 |
|
| 916 |
if (isset($prop['richText']) AND ($prop['richText'] == 'true')) { |
| 917 |
$ff += 1 << 25; |
| 918 |
} |
| 919 |
|
| 920 |
if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) { |
| 921 |
$ff += 1 << 26; |
| 922 |
} |
| 923 |
$opt['ff'] = $ff; |
| 924 |
|
| 925 |
if (isset($prop['defaultValue'])) { |
| 926 |
$opt['dv'] = $prop['defaultValue']; |
| 927 |
} |
| 928 |
$f = 4; |
| 929 |
|
| 930 |
if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { |
| 931 |
$f += 1 << 6; |
| 932 |
} |
| 933 |
|
| 934 |
if (isset($prop['display'])) { |
| 935 |
if ($prop['display'] == 'display.visible') { |
| 936 |
|
| 937 |
} elseif ($prop['display'] == 'display.hidden') { |
| 938 |
$f += 1 << 1; |
| 939 |
} elseif ($prop['display'] == 'display.noPrint') { |
| 940 |
$f -= 1 << 2; |
| 941 |
} elseif ($prop['display'] == 'display.noView') { |
| 942 |
$f += 1 << 5; |
| 943 |
} |
| 944 |
} |
| 945 |
$opt['f'] = $f; |
| 946 |
|
| 947 |
if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) { |
| 948 |
$opt['i'] = $prop['currentValueIndices']; |
| 949 |
} |
| 950 |
|
| 951 |
if (isset($prop['value'])) { |
| 952 |
if (is_array($prop['value'])) { |
| 953 |
$opt['opt'] = array(); |
| 954 |
foreach ($prop['value'] AS $key => $optval) { |
| 955 |
|
| 956 |
if (isset($prop['exportValues'][$key])) { |
| 957 |
$opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]); |
| 958 |
} else { |
| 959 |
$opt['opt'][$key] = $prop['value'][$key]; |
| 960 |
} |
| 961 |
} |
| 962 |
} else { |
| 963 |
$opt['v'] = $prop['value']; |
| 964 |
} |
| 965 |
} |
| 966 |
|
| 967 |
if (isset($prop['richValue'])) { |
| 968 |
$opt['rv'] = $prop['richValue']; |
| 969 |
} |
| 970 |
|
| 971 |
if (isset($prop['submitName'])) { |
| 972 |
$opt['tm'] = $prop['submitName']; |
| 973 |
} |
| 974 |
|
| 975 |
if (isset($prop['name'])) { |
| 976 |
$opt['t'] = $prop['name']; |
| 977 |
} |
| 978 |
|
| 979 |
if (isset($prop['userName'])) { |
| 980 |
$opt['tu'] = $prop['userName']; |
| 981 |
} |
| 982 |
|
| 983 |
if (isset($prop['highlight'])) { |
| 984 |
switch ($prop['highlight']) { |
| 985 |
case 'none': |
| 986 |
case 'highlight.n': { |
| 987 |
$opt['h'] = 'N'; |
| 988 |
break; |
| 989 |
} |
| 990 |
case 'invert': |
| 991 |
case 'highlight.i': { |
| 992 |
$opt['h'] = 'i'; |
| 993 |
break; |
| 994 |
} |
| 995 |
case 'push': |
| 996 |
case 'highlight.p': { |
| 997 |
$opt['h'] = 'P'; |
| 998 |
break; |
| 999 |
} |
| 1000 |
case 'outline': |
| 1001 |
case 'highlight.o': { |
| 1002 |
$opt['h'] = 'O'; |
| 1003 |
break; |
| 1004 |
} |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
return $opt; |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
public static function formatPageNumber($num) { |
| 1025 |
return number_format((float)$num, 0, '', '.'); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
public static function formatTOCPageNumber($num) { |
| 1038 |
return number_format((float)$num, 0, '', '.'); |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
public static function extractCSSproperties($cssdata) { |
| 1050 |
if (empty($cssdata)) { |
| 1051 |
return array(); |
| 1052 |
} |
| 1053 |
|
| 1054 |
$cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata); |
| 1055 |
|
| 1056 |
$cssdata = preg_replace('/[\s]+/', ' ', $cssdata); |
| 1057 |
|
| 1058 |
$cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata); |
| 1059 |
|
| 1060 |
$cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata); |
| 1061 |
|
| 1062 |
$cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata); |
| 1063 |
$cssdata = preg_replace('/\}\}/si', '}§', $cssdata); |
| 1064 |
|
| 1065 |
$cssdata = trim($cssdata); |
| 1066 |
|
| 1067 |
$cssblocks = array(); |
| 1068 |
$matches = array(); |
| 1069 |
if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) { |
| 1070 |
foreach ($matches[1] as $key => $type) { |
| 1071 |
$cssblocks[$type] = $matches[2][$key]; |
| 1072 |
} |
| 1073 |
|
| 1074 |
$cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata); |
| 1075 |
} |
| 1076 |
|
| 1077 |
if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) { |
| 1078 |
$cssdata .= $cssblocks['all']; |
| 1079 |
} |
| 1080 |
if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) { |
| 1081 |
$cssdata .= $cssblocks['print']; |
| 1082 |
} |
| 1083 |
|
| 1084 |
$cssblocks = array(); |
| 1085 |
$matches = array(); |
| 1086 |
|
| 1087 |
if (substr($cssdata, -1) == '}') { |
| 1088 |
|
| 1089 |
$cssdata = substr($cssdata, 0, -1); |
| 1090 |
} |
| 1091 |
$matches = explode('}', $cssdata); |
| 1092 |
foreach ($matches as $key => $block) { |
| 1093 |
|
| 1094 |
$cssblocks[$key] = explode('{', $block); |
| 1095 |
if (!isset($cssblocks[$key][1])) { |
| 1096 |
|
| 1097 |
unset($cssblocks[$key]); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
|
| 1101 |
foreach ($cssblocks as $key => $block) { |
| 1102 |
if (strpos($block[0], ',') > 0) { |
| 1103 |
$selectors = explode(',', $block[0]); |
| 1104 |
foreach ($selectors as $sel) { |
| 1105 |
$cssblocks[] = array(0 => trim($sel), 1 => $block[1]); |
| 1106 |
} |
| 1107 |
unset($cssblocks[$key]); |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
$cssdata = array(); |
| 1112 |
foreach ($cssblocks as $block) { |
| 1113 |
$selector = $block[0]; |
| 1114 |
|
| 1115 |
$matches = array(); |
| 1116 |
$a = 0; |
| 1117 |
$b = intval(preg_match_all('/[\#]/', $selector, $matches)); |
| 1118 |
$c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); |
| 1119 |
$c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); |
| 1120 |
$d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); |
| 1121 |
$d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); |
| 1122 |
$specificity = $a.$b.$c.$d; |
| 1123 |
|
| 1124 |
$cssdata[$specificity.' '.$selector] = $block[1]; |
| 1125 |
} |
| 1126 |
|
| 1127 |
ksort($cssdata, SORT_STRING); |
| 1128 |
|
| 1129 |
return $cssdata; |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) { |
| 1146 |
|
| 1147 |
if (TCPDF_STATIC::empty_string($tidy_options)) { |
| 1148 |
$tidy_options = array ( |
| 1149 |
'clean' => 1, |
| 1150 |
'drop-empty-paras' => 0, |
| 1151 |
'drop-proprietary-attributes' => 1, |
| 1152 |
'fix-backslash' => 1, |
| 1153 |
'hide-comments' => 1, |
| 1154 |
'join-styles' => 1, |
| 1155 |
'lower-literals' => 1, |
| 1156 |
'merge-divs' => 1, |
| 1157 |
'merge-spans' => 1, |
| 1158 |
'output-xhtml' => 1, |
| 1159 |
'word-2000' => 1, |
| 1160 |
'wrap' => 0, |
| 1161 |
'output-bom' => 0, |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
); |
| 1166 |
} |
| 1167 |
|
| 1168 |
$tidy = tidy_parse_string($html, $tidy_options); |
| 1169 |
|
| 1170 |
$tidy->cleanRepair(); |
| 1171 |
|
| 1172 |
$tidy_head = tidy_get_head($tidy); |
| 1173 |
$css = $tidy_head->value; |
| 1174 |
$css = preg_replace('/<style([^>]+)>/ims', '<style>', $css); |
| 1175 |
$css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css); |
| 1176 |
$css = str_replace('/*<![CDATA[*/', '', $css); |
| 1177 |
$css = str_replace('/*]]>*/', '', $css); |
| 1178 |
preg_match('/<style>(.*)<\/style>/ims', $css, $matches); |
| 1179 |
if (isset($matches[1])) { |
| 1180 |
$css = strtolower($matches[1]); |
| 1181 |
} else { |
| 1182 |
$css = ''; |
| 1183 |
} |
| 1184 |
|
| 1185 |
$css = '<style>'.$default_css.$css.'</style>'; |
| 1186 |
|
| 1187 |
$tidy_body = tidy_get_body($tidy); |
| 1188 |
$html = $tidy_body->value; |
| 1189 |
|
| 1190 |
$html = str_replace('<br>', '<br />', $html); |
| 1191 |
|
| 1192 |
$html = preg_replace('/<div([^\>]*)><\/div>/', '', $html); |
| 1193 |
$html = preg_replace('/<p([^\>]*)><\/p>/', '', $html); |
| 1194 |
if (!TCPDF_STATIC::empty_string($tagvs)) { |
| 1195 |
|
| 1196 |
$tagvspaces = $tagvs; |
| 1197 |
} |
| 1198 |
|
| 1199 |
return $css.$html; |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
public static function isValidCSSSelectorForTag($dom, $key, $selector) { |
| 1212 |
$valid = false; |
| 1213 |
$tag = $dom[$key]['value']; |
| 1214 |
$class = array(); |
| 1215 |
if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) { |
| 1216 |
$class = explode(' ', strtolower($dom[$key]['attribute']['class'])); |
| 1217 |
} |
| 1218 |
$id = ''; |
| 1219 |
if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) { |
| 1220 |
$id = strtolower($dom[$key]['attribute']['id']); |
| 1221 |
} |
| 1222 |
$selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector); |
| 1223 |
$matches = array(); |
| 1224 |
if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) { |
| 1225 |
$parentop = array_pop($matches[1]); |
| 1226 |
$operator = $parentop[0]; |
| 1227 |
$offset = $parentop[1]; |
| 1228 |
$lasttag = array_pop($matches[2]); |
| 1229 |
$lasttag = strtolower(trim($lasttag[0])); |
| 1230 |
if (($lasttag == '*') OR ($lasttag == $tag)) { |
| 1231 |
|
| 1232 |
$attrib = array_pop($matches[3]); |
| 1233 |
$attrib = strtolower(trim($attrib[0])); |
| 1234 |
if (!empty($attrib)) { |
| 1235 |
|
| 1236 |
switch ($attrib[0]) { |
| 1237 |
case '.': { |
| 1238 |
if (in_array(substr($attrib, 1), $class)) { |
| 1239 |
$valid = true; |
| 1240 |
} |
| 1241 |
break; |
| 1242 |
} |
| 1243 |
case '#': { |
| 1244 |
if (substr($attrib, 1) == $id) { |
| 1245 |
$valid = true; |
| 1246 |
} |
| 1247 |
break; |
| 1248 |
} |
| 1249 |
case '[': { |
| 1250 |
$attrmatch = array(); |
| 1251 |
if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) { |
| 1252 |
$att = strtolower($attrmatch[1]); |
| 1253 |
$val = $attrmatch[3]; |
| 1254 |
if (isset($dom[$key]['attribute'][$att])) { |
| 1255 |
switch ($attrmatch[2]) { |
| 1256 |
case '=': { |
| 1257 |
if ($dom[$key]['attribute'][$att] == $val) { |
| 1258 |
$valid = true; |
| 1259 |
} |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
case '~=': { |
| 1263 |
if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) { |
| 1264 |
$valid = true; |
| 1265 |
} |
| 1266 |
break; |
| 1267 |
} |
| 1268 |
case '^=': { |
| 1269 |
if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) { |
| 1270 |
$valid = true; |
| 1271 |
} |
| 1272 |
break; |
| 1273 |
} |
| 1274 |
case '$=': { |
| 1275 |
if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) { |
| 1276 |
$valid = true; |
| 1277 |
} |
| 1278 |
break; |
| 1279 |
} |
| 1280 |
case '*=': { |
| 1281 |
if (strpos($dom[$key]['attribute'][$att], $val) !== false) { |
| 1282 |
$valid = true; |
| 1283 |
} |
| 1284 |
break; |
| 1285 |
} |
| 1286 |
case '|=': { |
| 1287 |
if ($dom[$key]['attribute'][$att] == $val) { |
| 1288 |
$valid = true; |
| 1289 |
} elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) { |
| 1290 |
$valid = true; |
| 1291 |
} |
| 1292 |
break; |
| 1293 |
} |
| 1294 |
default: { |
| 1295 |
$valid = true; |
| 1296 |
} |
| 1297 |
} |
| 1298 |
} |
| 1299 |
} |
| 1300 |
break; |
| 1301 |
} |
| 1302 |
case ':': { |
| 1303 |
if ($attrib[1] == ':') { |
| 1304 |
|
| 1305 |
|
| 1306 |
} else { |
| 1307 |
|
| 1308 |
|
| 1309 |
} |
| 1310 |
break; |
| 1311 |
} |
| 1312 |
} |
| 1313 |
} else { |
| 1314 |
$valid = true; |
| 1315 |
} |
| 1316 |
if ($valid AND ($offset > 0)) { |
| 1317 |
$valid = false; |
| 1318 |
|
| 1319 |
$selector = substr($selector, 0, $offset); |
| 1320 |
switch ($operator) { |
| 1321 |
case ' ': { |
| 1322 |
while ($dom[$key]['parent'] > 0) { |
| 1323 |
if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) { |
| 1324 |
$valid = true; |
| 1325 |
break; |
| 1326 |
} else { |
| 1327 |
$key = $dom[$key]['parent']; |
| 1328 |
} |
| 1329 |
} |
| 1330 |
break; |
| 1331 |
} |
| 1332 |
case '>': { |
| 1333 |
$valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector); |
| 1334 |
break; |
| 1335 |
} |
| 1336 |
case '+': { |
| 1337 |
for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { |
| 1338 |
if ($dom[$i]['tag'] AND $dom[$i]['opening']) { |
| 1339 |
$valid = self::isValidCSSSelectorForTag($dom, $i, $selector); |
| 1340 |
break; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
break; |
| 1344 |
} |
| 1345 |
case '~': { |
| 1346 |
for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { |
| 1347 |
if ($dom[$i]['tag'] AND $dom[$i]['opening']) { |
| 1348 |
if (self::isValidCSSSelectorForTag($dom, $i, $selector)) { |
| 1349 |
break; |
| 1350 |
} |
| 1351 |
} |
| 1352 |
} |
| 1353 |
break; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
} |
| 1359 |
return $valid; |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
public static function getCSSdataArray($dom, $key, $css) { |
| 1372 |
$cssarray = array(); |
| 1373 |
|
| 1374 |
$selectors = array(); |
| 1375 |
if (isset($dom[($dom[$key]['parent'])]['csssel'])) { |
| 1376 |
$selectors = $dom[($dom[$key]['parent'])]['csssel']; |
| 1377 |
} |
| 1378 |
|
| 1379 |
foreach($css as $selector => $style) { |
| 1380 |
$pos = strpos($selector, ' '); |
| 1381 |
|
| 1382 |
$specificity = substr($selector, 0, $pos); |
| 1383 |
|
| 1384 |
$selector = substr($selector, $pos); |
| 1385 |
|
| 1386 |
if (self::isValidCSSSelectorForTag($dom, $key, $selector)) { |
| 1387 |
if (!in_array($selector, $selectors)) { |
| 1388 |
|
| 1389 |
$cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style); |
| 1390 |
$selectors[] = $selector; |
| 1391 |
} |
| 1392 |
} |
| 1393 |
} |
| 1394 |
if (isset($dom[$key]['attribute']['style'])) { |
| 1395 |
|
| 1396 |
$cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']); |
| 1397 |
} |
| 1398 |
|
| 1399 |
$cssordered = array(); |
| 1400 |
foreach ($cssarray as $key => $val) { |
| 1401 |
$skey = sprintf('%04d', $key); |
| 1402 |
$cssordered[$val['s'].'_'.$skey] = $val; |
| 1403 |
} |
| 1404 |
|
| 1405 |
ksort($cssordered, SORT_STRING); |
| 1406 |
return array($selectors, $cssordered); |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
public static function getTagStyleFromCSSarray($css) { |
| 1417 |
$tagstyle = ''; |
| 1418 |
foreach ($css as $style) { |
| 1419 |
|
| 1420 |
$csscmds = explode(';', $style['c']); |
| 1421 |
foreach ($csscmds as $cmd) { |
| 1422 |
if (!empty($cmd)) { |
| 1423 |
$pos = strpos($cmd, ':'); |
| 1424 |
if ($pos !== false) { |
| 1425 |
$cmd = substr($cmd, 0, ($pos + 1)); |
| 1426 |
if (strpos($tagstyle, $cmd) !== false) { |
| 1427 |
|
| 1428 |
$tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle); |
| 1429 |
} |
| 1430 |
} |
| 1431 |
} |
| 1432 |
} |
| 1433 |
$tagstyle .= ';'.$style['c']; |
| 1434 |
} |
| 1435 |
|
| 1436 |
$tagstyle = preg_replace('/[;]+/', ';', $tagstyle); |
| 1437 |
return $tagstyle; |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
public static function intToRoman($number) { |
| 1448 |
$roman = ''; |
| 1449 |
if ($number >= 4000) { |
| 1450 |
|
| 1451 |
return strval($number); |
| 1452 |
} |
| 1453 |
while ($number >= 1000) { |
| 1454 |
$roman .= 'M'; |
| 1455 |
$number -= 1000; |
| 1456 |
} |
| 1457 |
while ($number >= 900) { |
| 1458 |
$roman .= 'CM'; |
| 1459 |
$number -= 900; |
| 1460 |
} |
| 1461 |
while ($number >= 500) { |
| 1462 |
$roman .= 'D'; |
| 1463 |
$number -= 500; |
| 1464 |
} |
| 1465 |
while ($number >= 400) { |
| 1466 |
$roman .= 'CD'; |
| 1467 |
$number -= 400; |
| 1468 |
} |
| 1469 |
while ($number >= 100) { |
| 1470 |
$roman .= 'C'; |
| 1471 |
$number -= 100; |
| 1472 |
} |
| 1473 |
while ($number >= 90) { |
| 1474 |
$roman .= 'XC'; |
| 1475 |
$number -= 90; |
| 1476 |
} |
| 1477 |
while ($number >= 50) { |
| 1478 |
$roman .= 'L'; |
| 1479 |
$number -= 50; |
| 1480 |
} |
| 1481 |
while ($number >= 40) { |
| 1482 |
$roman .= 'XL'; |
| 1483 |
$number -= 40; |
| 1484 |
} |
| 1485 |
while ($number >= 10) { |
| 1486 |
$roman .= 'X'; |
| 1487 |
$number -= 10; |
| 1488 |
} |
| 1489 |
while ($number >= 9) { |
| 1490 |
$roman .= 'IX'; |
| 1491 |
$number -= 9; |
| 1492 |
} |
| 1493 |
while ($number >= 5) { |
| 1494 |
$roman .= 'V'; |
| 1495 |
$number -= 5; |
| 1496 |
} |
| 1497 |
while ($number >= 4) { |
| 1498 |
$roman .= 'IV'; |
| 1499 |
$number -= 4; |
| 1500 |
} |
| 1501 |
while ($number >= 1) { |
| 1502 |
$roman .= 'I'; |
| 1503 |
--$number; |
| 1504 |
} |
| 1505 |
return $roman; |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
public static function revstrpos($haystack, $needle, $offset = 0) { |
| 1518 |
$length = strlen($haystack); |
| 1519 |
$offset = ($offset > 0)?($length - $offset):abs($offset); |
| 1520 |
$pos = strpos(strrev($haystack), strrev($needle), $offset); |
| 1521 |
return ($pos === false)?false:($length - $pos - strlen($needle)); |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
public static function getHyphenPatternsFromTEX($file) { |
| 1533 |
|
| 1534 |
|
| 1535 |
$data = file_get_contents($file); |
| 1536 |
$patterns = array(); |
| 1537 |
|
| 1538 |
$data = preg_replace('/\%[^\n]*/', '', $data); |
| 1539 |
|
| 1540 |
preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); |
| 1541 |
$data = trim(substr($matches[0], 10, -1)); |
| 1542 |
|
| 1543 |
$patterns_array = preg_split('/[\s]+/', $data); |
| 1544 |
|
| 1545 |
$patterns = array(); |
| 1546 |
foreach($patterns_array as $val) { |
| 1547 |
if (!TCPDF_STATIC::empty_string($val)) { |
| 1548 |
$val = trim($val); |
| 1549 |
$val = str_replace('\'', '\\\'', $val); |
| 1550 |
$key = preg_replace('/[0-9]+/', '', $val); |
| 1551 |
$patterns[$key] = $val; |
| 1552 |
} |
| 1553 |
} |
| 1554 |
return $patterns; |
| 1555 |
} |
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
public static function getPathPaintOperator($style, $default='S') { |
| 1580 |
$op = ''; |
| 1581 |
switch($style) { |
| 1582 |
case 'S': |
| 1583 |
case 'D': { |
| 1584 |
$op = 'S'; |
| 1585 |
break; |
| 1586 |
} |
| 1587 |
case 's': |
| 1588 |
case 'd': { |
| 1589 |
$op = 's'; |
| 1590 |
break; |
| 1591 |
} |
| 1592 |
case 'f': |
| 1593 |
case 'F': { |
| 1594 |
$op = 'f'; |
| 1595 |
break; |
| 1596 |
} |
| 1597 |
case 'f*': |
| 1598 |
case 'F*': { |
| 1599 |
$op = 'f*'; |
| 1600 |
break; |
| 1601 |
} |
| 1602 |
case 'B': |
| 1603 |
case 'FD': |
| 1604 |
case 'DF': { |
| 1605 |
$op = 'B'; |
| 1606 |
break; |
| 1607 |
} |
| 1608 |
case 'B*': |
| 1609 |
case 'F*D': |
| 1610 |
case 'DF*': { |
| 1611 |
$op = 'B*'; |
| 1612 |
break; |
| 1613 |
} |
| 1614 |
case 'b': |
| 1615 |
case 'fd': |
| 1616 |
case 'df': { |
| 1617 |
$op = 'b'; |
| 1618 |
break; |
| 1619 |
} |
| 1620 |
case 'b*': |
| 1621 |
case 'f*d': |
| 1622 |
case 'df*': { |
| 1623 |
$op = 'b*'; |
| 1624 |
break; |
| 1625 |
} |
| 1626 |
case 'CNZ': { |
| 1627 |
$op = 'W n'; |
| 1628 |
break; |
| 1629 |
} |
| 1630 |
case 'CEO': { |
| 1631 |
$op = 'W* n'; |
| 1632 |
break; |
| 1633 |
} |
| 1634 |
case 'n': { |
| 1635 |
$op = 'n'; |
| 1636 |
break; |
| 1637 |
} |
| 1638 |
default: { |
| 1639 |
if (!empty($default)) { |
| 1640 |
$op = self::getPathPaintOperator($default, ''); |
| 1641 |
} else { |
| 1642 |
$op = ''; |
| 1643 |
} |
| 1644 |
} |
| 1645 |
} |
| 1646 |
return $op; |
| 1647 |
} |
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
public static function getTransformationMatrixProduct($ta, $tb) { |
| 1659 |
$tm = array(); |
| 1660 |
$tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); |
| 1661 |
$tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); |
| 1662 |
$tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); |
| 1663 |
$tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]); |
| 1664 |
$tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4]; |
| 1665 |
$tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5]; |
| 1666 |
return $tm; |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
public static function getSVGTransformMatrix($attribute) { |
| 1678 |
|
| 1679 |
$tm = array(1, 0, 0, 1, 0, 0); |
| 1680 |
$transform = array(); |
| 1681 |
if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { |
| 1682 |
foreach ($transform as $key => $data) { |
| 1683 |
if (!empty($data[2])) { |
| 1684 |
$a = 1; |
| 1685 |
$b = 0; |
| 1686 |
$c = 0; |
| 1687 |
$d = 1; |
| 1688 |
$e = 0; |
| 1689 |
$f = 0; |
| 1690 |
$regs = array(); |
| 1691 |
switch ($data[1]) { |
| 1692 |
case 'matrix': { |
| 1693 |
if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1694 |
$a = $regs[1]; |
| 1695 |
$b = $regs[2]; |
| 1696 |
$c = $regs[3]; |
| 1697 |
$d = $regs[4]; |
| 1698 |
$e = $regs[5]; |
| 1699 |
$f = $regs[6]; |
| 1700 |
} |
| 1701 |
break; |
| 1702 |
} |
| 1703 |
case 'translate': { |
| 1704 |
if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1705 |
$e = $regs[1]; |
| 1706 |
$f = $regs[2]; |
| 1707 |
} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1708 |
$e = $regs[1]; |
| 1709 |
} |
| 1710 |
break; |
| 1711 |
} |
| 1712 |
case 'scale': { |
| 1713 |
if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1714 |
$a = $regs[1]; |
| 1715 |
$d = $regs[2]; |
| 1716 |
} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1717 |
$a = $regs[1]; |
| 1718 |
$d = $a; |
| 1719 |
} |
| 1720 |
break; |
| 1721 |
} |
| 1722 |
case 'rotate': { |
| 1723 |
if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { |
| 1724 |
$ang = deg2rad($regs[1]); |
| 1725 |
$x = $regs[2]; |
| 1726 |
$y = $regs[3]; |
| 1727 |
$a = cos($ang); |
| 1728 |
$b = sin($ang); |
| 1729 |
$c = -$b; |
| 1730 |
$d = $a; |
| 1731 |
$e = ($x * (1 - $a)) - ($y * $c); |
| 1732 |
$f = ($y * (1 - $d)) - ($x * $b); |
| 1733 |
} elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { |
| 1734 |
$ang = deg2rad($regs[1]); |
| 1735 |
$a = cos($ang); |
| 1736 |
$b = sin($ang); |
| 1737 |
$c = -$b; |
| 1738 |
$d = $a; |
| 1739 |
$e = 0; |
| 1740 |
$f = 0; |
| 1741 |
} |
| 1742 |
break; |
| 1743 |
} |
| 1744 |
case 'skewX': { |
| 1745 |
if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { |
| 1746 |
$c = tan(deg2rad($regs[1])); |
| 1747 |
} |
| 1748 |
break; |
| 1749 |
} |
| 1750 |
case 'skewY': { |
| 1751 |
if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { |
| 1752 |
$b = tan(deg2rad($regs[1])); |
| 1753 |
} |
| 1754 |
break; |
| 1755 |
} |
| 1756 |
} |
| 1757 |
$tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f)); |
| 1758 |
} |
| 1759 |
} |
| 1760 |
} |
| 1761 |
return $tm; |
| 1762 |
} |
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
public static function getVectorsAngle($x1, $y1, $x2, $y2) { |
| 1775 |
$dprod = ($x1 * $x2) + ($y1 * $y2); |
| 1776 |
$dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); |
| 1777 |
$dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); |
| 1778 |
$angle = acos($dprod / ($dist1 * $dist2)); |
| 1779 |
if (is_nan($angle)) { |
| 1780 |
$angle = M_PI; |
| 1781 |
} |
| 1782 |
if ((($x1 * $y2) - ($x2 * $y1)) < 0) { |
| 1783 |
$angle *= -1; |
| 1784 |
} |
| 1785 |
return $angle; |
| 1786 |
} |
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) { |
| 1802 |
|
| 1803 |
$limit = $limit === null ? -1 : $limit; |
| 1804 |
$flags = $flags === null ? 0 : $flags; |
| 1805 |
|
| 1806 |
if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) { |
| 1807 |
$ret = preg_split($pattern.$modifiers, $subject, $limit, $flags); |
| 1808 |
if ($ret === false) { |
| 1809 |
return array(); |
| 1810 |
} |
| 1811 |
return is_array($ret) ? $ret : array(); |
| 1812 |
} |
| 1813 |
|
| 1814 |
$ret = array(); |
| 1815 |
while (($nl = strpos($subject, "\n")) !== FALSE) { |
| 1816 |
$ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags)); |
| 1817 |
$ret[] = "\n"; |
| 1818 |
$subject = substr($subject, ($nl + 1)); |
| 1819 |
} |
| 1820 |
if (strlen($subject) > 0) { |
| 1821 |
$ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags)); |
| 1822 |
} |
| 1823 |
return $ret; |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
public static function fopenLocal($filename, $mode) { |
| 1834 |
if (strpos($filename, '://') === false) { |
| 1835 |
$filename = 'file://'.$filename; |
| 1836 |
} elseif (stream_is_local($filename) !== true) { |
| 1837 |
return false; |
| 1838 |
} |
| 1839 |
return fopen($filename, $mode); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
public static function url_exists($url) { |
| 1850 |
$crs = curl_init(); |
| 1851 |
$curlopts = []; |
| 1852 |
if ( |
| 1853 |
(ini_get('open_basedir') == '') |
| 1854 |
&& (ini_get('safe_mode') === '' |
| 1855 |
|| ini_get('safe_mode') === false) |
| 1856 |
) { |
| 1857 |
$curlopts[CURLOPT_FOLLOWLOCATION] = true; |
| 1858 |
} |
| 1859 |
$curlopts = array_replace($curlopts, self::CURLOPT_DEFAULT); |
| 1860 |
$curlopts = array_replace($curlopts, K_CURLOPTS); |
| 1861 |
$curlopts = array_replace($curlopts, self::CURLOPT_FIXED); |
| 1862 |
$curlopts[CURLOPT_URL] = $url; |
| 1863 |
curl_setopt_array($crs, $curlopts); |
| 1864 |
curl_exec($crs); |
| 1865 |
$code = curl_getinfo($crs, CURLINFO_HTTP_CODE); |
| 1866 |
if (PHP_VERSION_ID < 80000) { |
| 1867 |
curl_close($crs); |
| 1868 |
} |
| 1869 |
return ($code == 200); |
| 1870 |
} |
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
public static function encodeUrlQuery($url) { |
| 1881 |
$urlData = parse_url($url); |
| 1882 |
if (isset($urlData['query']) && $urlData['query']) { |
| 1883 |
$urlQueryData = array(); |
| 1884 |
parse_str(urldecode($urlData['query']), $urlQueryData); |
| 1885 |
$port = isset($urlData['port']) ? ':'.$urlData['port'] : ''; |
| 1886 |
$updatedUrl = $urlData['scheme'].'://'.$urlData['host'].$port.$urlData['path'].'?'.http_build_query($urlQueryData); |
| 1887 |
} else { |
| 1888 |
$updatedUrl = $url; |
| 1889 |
} |
| 1890 |
return $updatedUrl; |
| 1891 |
} |
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
public static function file_exists($filename) { |
| 1902 |
if (preg_match('|^https?://|', $filename) == 1) { |
| 1903 |
return self::url_exists($filename); |
| 1904 |
} |
| 1905 |
if (strpos($filename, '://')) { |
| 1906 |
return false; |
| 1907 |
} |
| 1908 |
return @file_exists($filename); |
| 1909 |
} |
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
public static function fileGetContents($file) { |
| 1921 |
$alt = array($file); |
| 1922 |
|
| 1923 |
if ((strlen($file) > 1) |
| 1924 |
&& ($file[0] === '/') |
| 1925 |
&& ($file[1] !== '/') |
| 1926 |
&& !empty($_SERVER['DOCUMENT_ROOT']) |
| 1927 |
&& ($_SERVER['DOCUMENT_ROOT'] !== '/') |
| 1928 |
) { |
| 1929 |
$findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']); |
| 1930 |
if (($findroot === false) || ($findroot > 1)) { |
| 1931 |
$alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file)); |
| 1932 |
} |
| 1933 |
} |
| 1934 |
|
| 1935 |
$protocol = 'http'; |
| 1936 |
if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { |
| 1937 |
$protocol .= 's'; |
| 1938 |
} |
| 1939 |
|
| 1940 |
$url = $file; |
| 1941 |
if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) { |
| 1942 |
$url = $protocol.':'.str_replace(' ', '%20', $url); |
| 1943 |
} |
| 1944 |
$url = htmlspecialchars_decode($url); |
| 1945 |
$alt[] = $url; |
| 1946 |
|
| 1947 |
if (preg_match('%^(https?)://%', $url) |
| 1948 |
&& empty($_SERVER['HTTP_HOST']) |
| 1949 |
&& empty($_SERVER['DOCUMENT_ROOT']) |
| 1950 |
) { |
| 1951 |
$urldata = parse_url($url); |
| 1952 |
if (empty($urldata['query'])) { |
| 1953 |
$host = $protocol.'://'.$_SERVER['HTTP_HOST']; |
| 1954 |
if (strpos($url, $host) === 0) { |
| 1955 |
|
| 1956 |
$tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url); |
| 1957 |
$alt[] = htmlspecialchars_decode(urldecode($tmp)); |
| 1958 |
} |
| 1959 |
} |
| 1960 |
} |
| 1961 |
|
| 1962 |
if (isset($_SERVER['SCRIPT_URI']) |
| 1963 |
&& !preg_match('%^(https?|ftp)://%', $file) |
| 1964 |
&& !preg_match('%^//%', $file) |
| 1965 |
) { |
| 1966 |
$urldata = @parse_url($_SERVER['SCRIPT_URI']); |
| 1967 |
$alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file; |
| 1968 |
} |
| 1969 |
|
| 1970 |
$alt = array_unique($alt); |
| 1971 |
foreach ($alt as $path) { |
| 1972 |
if (!self::file_exists($path)) { |
| 1973 |
continue; |
| 1974 |
} |
| 1975 |
$ret = @file_get_contents($path); |
| 1976 |
if ( $ret != false ) { |
| 1977 |
return $ret; |
| 1978 |
} |
| 1979 |
|
| 1980 |
if (!ini_get('allow_url_fopen') |
| 1981 |
&& function_exists('curl_init') |
| 1982 |
&& preg_match('%^(https?|ftp)://%', $path) |
| 1983 |
) { |
| 1984 |
|
| 1985 |
$crs = curl_init(); |
| 1986 |
$curlopts = []; |
| 1987 |
if ( |
| 1988 |
(ini_get('open_basedir') == '') |
| 1989 |
&& (ini_get('safe_mode') === '' |
| 1990 |
|| ini_get('safe_mode') === false) |
| 1991 |
) { |
| 1992 |
$curlopts[CURLOPT_FOLLOWLOCATION] = true; |
| 1993 |
} |
| 1994 |
$curlopts = array_replace($curlopts, self::CURLOPT_DEFAULT); |
| 1995 |
$curlopts = array_replace($curlopts, K_CURLOPTS); |
| 1996 |
$curlopts = array_replace($curlopts, self::CURLOPT_FIXED); |
| 1997 |
$curlopts[CURLOPT_URL] = $url; |
| 1998 |
curl_setopt_array($crs, $curlopts); |
| 1999 |
$ret = curl_exec($crs); |
| 2000 |
if (PHP_VERSION_ID < 80000) { |
| 2001 |
curl_close($crs); |
| 2002 |
} |
| 2003 |
if ($ret !== false) { |
| 2004 |
return $ret; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
} |
| 2008 |
return false; |
| 2009 |
} |
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
public static function _getULONG($str, $offset) { |
| 2021 |
$v = unpack('Ni', substr($str, $offset, 4)); |
| 2022 |
return $v['i']; |
| 2023 |
} |
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
public static function _getUSHORT($str, $offset) { |
| 2035 |
$v = unpack('ni', substr($str, $offset, 2)); |
| 2036 |
return $v['i']; |
| 2037 |
} |
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
public static function _getSHORT($str, $offset) { |
| 2049 |
$v = unpack('si', substr($str, $offset, 2)); |
| 2050 |
return $v['i']; |
| 2051 |
} |
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
public static function _getFWORD($str, $offset) { |
| 2063 |
$v = self::_getUSHORT($str, $offset); |
| 2064 |
if ($v > 0x7fff) { |
| 2065 |
$v -= 0x10000; |
| 2066 |
} |
| 2067 |
return $v; |
| 2068 |
} |
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
public static function _getUFWORD($str, $offset) { |
| 2080 |
$v = self::_getUSHORT($str, $offset); |
| 2081 |
return $v; |
| 2082 |
} |
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
public static function _getFIXED($str, $offset) { |
| 2094 |
|
| 2095 |
$m = self::_getFWORD($str, $offset); |
| 2096 |
|
| 2097 |
$f = self::_getUSHORT($str, ($offset + 2)); |
| 2098 |
$v = floatval(''.$m.'.'.$f.''); |
| 2099 |
return $v; |
| 2100 |
} |
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
public static function _getBYTE($str, $offset) { |
| 2112 |
$v = unpack('Ci', substr($str, $offset, 1)); |
| 2113 |
return $v['i']; |
| 2114 |
} |
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
public static function rfread($handle, $length) { |
| 2126 |
$data = fread($handle, $length); |
| 2127 |
if ($data === false) { |
| 2128 |
return false; |
| 2129 |
} |
| 2130 |
$rest = ($length - strlen($data)); |
| 2131 |
if (($rest > 0) && !feof($handle)) { |
| 2132 |
$data .= self::rfread($handle, $rest); |
| 2133 |
} |
| 2134 |
return $data; |
| 2135 |
} |
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
public static function _freadint($f) { |
| 2144 |
$a = unpack('Ni', fread($f, 4)); |
| 2145 |
return $a['i']; |
| 2146 |
} |
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
public static $page_formats = array( |
| 2156 |
|
| 2157 |
'A0' => array( 2383.937, 3370.394), |
| 2158 |
'A1' => array( 1683.780, 2383.937), |
| 2159 |
'A2' => array( 1190.551, 1683.780), |
| 2160 |
'A3' => array( 841.890, 1190.551), |
| 2161 |
'A4' => array( 595.276, 841.890), |
| 2162 |
'A5' => array( 419.528, 595.276), |
| 2163 |
'A6' => array( 297.638, 419.528), |
| 2164 |
'A7' => array( 209.764, 297.638), |
| 2165 |
'A8' => array( 147.402, 209.764), |
| 2166 |
'A9' => array( 104.882, 147.402), |
| 2167 |
'A10' => array( 73.701, 104.882), |
| 2168 |
'A11' => array( 51.024, 73.701), |
| 2169 |
'A12' => array( 36.850, 51.024), |
| 2170 |
|
| 2171 |
'B0' => array( 2834.646, 4008.189), |
| 2172 |
'B1' => array( 2004.094, 2834.646), |
| 2173 |
'B2' => array( 1417.323, 2004.094), |
| 2174 |
'B3' => array( 1000.630, 1417.323), |
| 2175 |
'B4' => array( 708.661, 1000.630), |
| 2176 |
'B5' => array( 498.898, 708.661), |
| 2177 |
'B6' => array( 354.331, 498.898), |
| 2178 |
'B7' => array( 249.449, 354.331), |
| 2179 |
'B8' => array( 175.748, 249.449), |
| 2180 |
'B9' => array( 124.724, 175.748), |
| 2181 |
'B10' => array( 87.874, 124.724), |
| 2182 |
'B11' => array( 62.362, 87.874), |
| 2183 |
'B12' => array( 42.520, 62.362), |
| 2184 |
|
| 2185 |
'C0' => array( 2599.370, 3676.535), |
| 2186 |
'C1' => array( 1836.850, 2599.370), |
| 2187 |
'C2' => array( 1298.268, 1836.850), |
| 2188 |
'C3' => array( 918.425, 1298.268), |
| 2189 |
'C4' => array( 649.134, 918.425), |
| 2190 |
'C5' => array( 459.213, 649.134), |
| 2191 |
'C6' => array( 323.150, 459.213), |
| 2192 |
'C7' => array( 229.606, 323.150), |
| 2193 |
'C8' => array( 161.575, 229.606), |
| 2194 |
'C9' => array( 113.386, 161.575), |
| 2195 |
'C10' => array( 79.370, 113.386), |
| 2196 |
'C11' => array( 56.693, 79.370), |
| 2197 |
'C12' => array( 39.685, 56.693), |
| 2198 |
'C76' => array( 229.606, 459.213), |
| 2199 |
'DL' => array( 311.811, 623.622), |
| 2200 |
'DLE' => array( 323.150, 637.795), |
| 2201 |
'DLX' => array( 340.158, 666.142), |
| 2202 |
'DLP' => array( 280.630, 595.276), |
| 2203 |
|
| 2204 |
'E0' => array( 2491.654, 3517.795), |
| 2205 |
'E1' => array( 1757.480, 2491.654), |
| 2206 |
'E2' => array( 1247.244, 1757.480), |
| 2207 |
'E3' => array( 878.740, 1247.244), |
| 2208 |
'E4' => array( 623.622, 878.740), |
| 2209 |
'E5' => array( 439.370, 623.622), |
| 2210 |
'E6' => array( 311.811, 439.370), |
| 2211 |
'E7' => array( 221.102, 311.811), |
| 2212 |
'E8' => array( 155.906, 221.102), |
| 2213 |
'E9' => array( 110.551, 155.906), |
| 2214 |
'E10' => array( 76.535, 110.551), |
| 2215 |
'E11' => array( 53.858, 76.535), |
| 2216 |
'E12' => array( 36.850, 53.858), |
| 2217 |
|
| 2218 |
'G0' => array( 2715.591, 3838.110), |
| 2219 |
'G1' => array( 1919.055, 2715.591), |
| 2220 |
'G2' => array( 1357.795, 1919.055), |
| 2221 |
'G3' => array( 958.110, 1357.795), |
| 2222 |
'G4' => array( 677.480, 958.110), |
| 2223 |
'G5' => array( 479.055, 677.480), |
| 2224 |
'G6' => array( 337.323, 479.055), |
| 2225 |
'G7' => array( 238.110, 337.323), |
| 2226 |
'G8' => array( 167.244, 238.110), |
| 2227 |
'G9' => array( 119.055, 167.244), |
| 2228 |
'G10' => array( 82.205, 119.055), |
| 2229 |
'G11' => array( 59.528, 82.205), |
| 2230 |
'G12' => array( 39.685, 59.528), |
| 2231 |
|
| 2232 |
'RA0' => array( 2437.795, 3458.268), |
| 2233 |
'RA1' => array( 1729.134, 2437.795), |
| 2234 |
'RA2' => array( 1218.898, 1729.134), |
| 2235 |
'RA3' => array( 864.567, 1218.898), |
| 2236 |
'RA4' => array( 609.449, 864.567), |
| 2237 |
'SRA0' => array( 2551.181, 3628.346), |
| 2238 |
'SRA1' => array( 1814.173, 2551.181), |
| 2239 |
'SRA2' => array( 1275.591, 1814.173), |
| 2240 |
'SRA3' => array( 907.087, 1275.591), |
| 2241 |
'SRA4' => array( 637.795, 907.087), |
| 2242 |
|
| 2243 |
'4A0' => array( 4767.874, 6740.787), |
| 2244 |
'2A0' => array( 3370.394, 4767.874), |
| 2245 |
|
| 2246 |
'A2_EXTRA' => array( 1261.417, 1754.646), |
| 2247 |
'A3+' => array( 932.598, 1369.134), |
| 2248 |
'A3_EXTRA' => array( 912.756, 1261.417), |
| 2249 |
'A3_SUPER' => array( 864.567, 1440.000), |
| 2250 |
'SUPER_A3' => array( 864.567, 1380.472), |
| 2251 |
'A4_EXTRA' => array( 666.142, 912.756), |
| 2252 |
'A4_SUPER' => array( 649.134, 912.756), |
| 2253 |
'SUPER_A4' => array( 643.465, 1009.134), |
| 2254 |
'A4_LONG' => array( 595.276, 986.457), |
| 2255 |
'F4' => array( 595.276, 935.433), |
| 2256 |
'SO_B5_EXTRA' => array( 572.598, 782.362), |
| 2257 |
'A5_EXTRA' => array( 490.394, 666.142), |
| 2258 |
|
| 2259 |
'ANSI_E' => array( 2448.000, 3168.000), |
| 2260 |
'ANSI_D' => array( 1584.000, 2448.000), |
| 2261 |
'ANSI_C' => array( 1224.000, 1584.000), |
| 2262 |
'ANSI_B' => array( 792.000, 1224.000), |
| 2263 |
'ANSI_A' => array( 612.000, 792.000), |
| 2264 |
|
| 2265 |
'USLEDGER' => array( 1224.000, 792.000), |
| 2266 |
'LEDGER' => array( 1224.000, 792.000), |
| 2267 |
'ORGANIZERK' => array( 792.000, 1224.000), |
| 2268 |
'BIBLE' => array( 792.000, 1224.000), |
| 2269 |
'USTABLOID' => array( 792.000, 1224.000), |
| 2270 |
'TABLOID' => array( 792.000, 1224.000), |
| 2271 |
'ORGANIZERM' => array( 612.000, 792.000), |
| 2272 |
'USLETTER' => array( 612.000, 792.000), |
| 2273 |
'LETTER' => array( 612.000, 792.000), |
| 2274 |
'USLEGAL' => array( 612.000, 1008.000), |
| 2275 |
'LEGAL' => array( 612.000, 1008.000), |
| 2276 |
'GOVERNMENTLETTER' => array( 576.000, 756.000), |
| 2277 |
'GLETTER' => array( 576.000, 756.000), |
| 2278 |
'JUNIORLEGAL' => array( 576.000, 360.000), |
| 2279 |
'JLEGAL' => array( 576.000, 360.000), |
| 2280 |
|
| 2281 |
'QUADDEMY' => array( 2520.000, 3240.000), |
| 2282 |
'SUPER_B' => array( 936.000, 1368.000), |
| 2283 |
'QUARTO' => array( 648.000, 792.000), |
| 2284 |
'GOVERNMENTLEGAL' => array( 612.000, 936.000), |
| 2285 |
'FOLIO' => array( 612.000, 936.000), |
| 2286 |
'MONARCH' => array( 522.000, 756.000), |
| 2287 |
'EXECUTIVE' => array( 522.000, 756.000), |
| 2288 |
'ORGANIZERL' => array( 396.000, 612.000), |
| 2289 |
'STATEMENT' => array( 396.000, 612.000), |
| 2290 |
'MEMO' => array( 396.000, 612.000), |
| 2291 |
'FOOLSCAP' => array( 595.440, 936.000), |
| 2292 |
'COMPACT' => array( 306.000, 486.000), |
| 2293 |
'ORGANIZERJ' => array( 198.000, 360.000), |
| 2294 |
|
| 2295 |
'P1' => array( 1587.402, 2437.795), |
| 2296 |
'P2' => array( 1218.898, 1587.402), |
| 2297 |
'P3' => array( 793.701, 1218.898), |
| 2298 |
'P4' => array( 609.449, 793.701), |
| 2299 |
'P5' => array( 396.850, 609.449), |
| 2300 |
'P6' => array( 303.307, 396.850), |
| 2301 |
|
| 2302 |
'ARCH_E' => array( 2592.000, 3456.000), |
| 2303 |
'ARCH_E1' => array( 2160.000, 3024.000), |
| 2304 |
'ARCH_D' => array( 1728.000, 2592.000), |
| 2305 |
'BROADSHEET' => array( 1296.000, 1728.000), |
| 2306 |
'ARCH_C' => array( 1296.000, 1728.000), |
| 2307 |
'ARCH_B' => array( 864.000, 1296.000), |
| 2308 |
'ARCH_A' => array( 648.000, 864.000), |
| 2309 |
|
| 2310 |
|
| 2311 |
'ANNENV_A2' => array( 314.640, 414.000), |
| 2312 |
'ANNENV_A6' => array( 342.000, 468.000), |
| 2313 |
'ANNENV_A7' => array( 378.000, 522.000), |
| 2314 |
'ANNENV_A8' => array( 396.000, 584.640), |
| 2315 |
'ANNENV_A10' => array( 450.000, 692.640), |
| 2316 |
'ANNENV_SLIM' => array( 278.640, 638.640), |
| 2317 |
|
| 2318 |
'COMMENV_N6_1/4' => array( 252.000, 432.000), |
| 2319 |
'COMMENV_N6_3/4' => array( 260.640, 468.000), |
| 2320 |
'COMMENV_N8' => array( 278.640, 540.000), |
| 2321 |
'COMMENV_N9' => array( 278.640, 638.640), |
| 2322 |
'COMMENV_N10' => array( 296.640, 684.000), |
| 2323 |
'COMMENV_N11' => array( 324.000, 746.640), |
| 2324 |
'COMMENV_N12' => array( 342.000, 792.000), |
| 2325 |
'COMMENV_N14' => array( 360.000, 828.000), |
| 2326 |
|
| 2327 |
'CATENV_N1' => array( 432.000, 648.000), |
| 2328 |
'CATENV_N1_3/4' => array( 468.000, 684.000), |
| 2329 |
'CATENV_N2' => array( 468.000, 720.000), |
| 2330 |
'CATENV_N3' => array( 504.000, 720.000), |
| 2331 |
'CATENV_N6' => array( 540.000, 756.000), |
| 2332 |
'CATENV_N7' => array( 576.000, 792.000), |
| 2333 |
'CATENV_N8' => array( 594.000, 810.000), |
| 2334 |
'CATENV_N9_1/2' => array( 612.000, 756.000), |
| 2335 |
'CATENV_N9_3/4' => array( 630.000, 810.000), |
| 2336 |
'CATENV_N10_1/2' => array( 648.000, 864.000), |
| 2337 |
'CATENV_N12_1/2' => array( 684.000, 900.000), |
| 2338 |
'CATENV_N13_1/2' => array( 720.000, 936.000), |
| 2339 |
'CATENV_N14_1/4' => array( 810.000, 882.000), |
| 2340 |
'CATENV_N14_1/2' => array( 828.000, 1044.000), |
| 2341 |
|
| 2342 |
'JIS_B0' => array( 2919.685, 4127.244), |
| 2343 |
'JIS_B1' => array( 2063.622, 2919.685), |
| 2344 |
'JIS_B2' => array( 1459.843, 2063.622), |
| 2345 |
'JIS_B3' => array( 1031.811, 1459.843), |
| 2346 |
'JIS_B4' => array( 728.504, 1031.811), |
| 2347 |
'JIS_B5' => array( 515.906, 728.504), |
| 2348 |
'JIS_B6' => array( 362.835, 515.906), |
| 2349 |
'JIS_B7' => array( 257.953, 362.835), |
| 2350 |
'JIS_B8' => array( 181.417, 257.953), |
| 2351 |
'JIS_B9' => array( 127.559, 181.417), |
| 2352 |
'JIS_B10' => array( 90.709, 127.559), |
| 2353 |
'JIS_B11' => array( 62.362, 90.709), |
| 2354 |
'JIS_B12' => array( 45.354, 62.362), |
| 2355 |
|
| 2356 |
'PA0' => array( 2381.102, 3174.803), |
| 2357 |
'PA1' => array( 1587.402, 2381.102), |
| 2358 |
'PA2' => array( 1190.551, 1587.402), |
| 2359 |
'PA3' => array( 793.701, 1190.551), |
| 2360 |
'PA4' => array( 595.276, 793.701), |
| 2361 |
'PA5' => array( 396.850, 595.276), |
| 2362 |
'PA6' => array( 297.638, 396.850), |
| 2363 |
'PA7' => array( 198.425, 297.638), |
| 2364 |
'PA8' => array( 147.402, 198.425), |
| 2365 |
'PA9' => array( 99.213, 147.402), |
| 2366 |
'PA10' => array( 73.701, 99.213), |
| 2367 |
|
| 2368 |
'PASSPORT_PHOTO' => array( 99.213, 127.559), |
| 2369 |
'E' => array( 233.858, 340.157), |
| 2370 |
'L' => array( 252.283, 360.000), |
| 2371 |
'3R' => array( 252.283, 360.000), |
| 2372 |
'KG' => array( 289.134, 430.866), |
| 2373 |
'4R' => array( 289.134, 430.866), |
| 2374 |
'4D' => array( 340.157, 430.866), |
| 2375 |
'2L' => array( 360.000, 504.567), |
| 2376 |
'5R' => array( 360.000, 504.567), |
| 2377 |
'8P' => array( 430.866, 575.433), |
| 2378 |
'6R' => array( 430.866, 575.433), |
| 2379 |
'6P' => array( 575.433, 720.000), |
| 2380 |
'8R' => array( 575.433, 720.000), |
| 2381 |
'6PW' => array( 575.433, 864.567), |
| 2382 |
'S8R' => array( 575.433, 864.567), |
| 2383 |
'4P' => array( 720.000, 864.567), |
| 2384 |
'10R' => array( 720.000, 864.567), |
| 2385 |
'4PW' => array( 720.000, 1080.000), |
| 2386 |
'S10R' => array( 720.000, 1080.000), |
| 2387 |
'11R' => array( 790.866, 1009.134), |
| 2388 |
'S11R' => array( 790.866, 1224.567), |
| 2389 |
'12R' => array( 864.567, 1080.000), |
| 2390 |
'S12R' => array( 864.567, 1292.598), |
| 2391 |
|
| 2392 |
'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), |
| 2393 |
'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), |
| 2394 |
'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), |
| 2395 |
'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), |
| 2396 |
|
| 2397 |
'CREDIT_CARD' => array( 153.014, 242.646), |
| 2398 |
'BUSINESS_CARD' => array( 153.014, 242.646), |
| 2399 |
'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), |
| 2400 |
'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), |
| 2401 |
'BUSINESS_CARD_IT' => array( 155.906, 240.945), |
| 2402 |
'BUSINESS_CARD_UK' => array( 155.906, 240.945), |
| 2403 |
'BUSINESS_CARD_FR' => array( 155.906, 240.945), |
| 2404 |
'BUSINESS_CARD_DE' => array( 155.906, 240.945), |
| 2405 |
'BUSINESS_CARD_ES' => array( 155.906, 240.945), |
| 2406 |
'BUSINESS_CARD_CA' => array( 144.567, 252.283), |
| 2407 |
'BUSINESS_CARD_US' => array( 144.567, 252.283), |
| 2408 |
'BUSINESS_CARD_JP' => array( 155.906, 257.953), |
| 2409 |
'BUSINESS_CARD_HK' => array( 153.071, 255.118), |
| 2410 |
'BUSINESS_CARD_AU' => array( 155.906, 255.118), |
| 2411 |
'BUSINESS_CARD_DK' => array( 155.906, 255.118), |
| 2412 |
'BUSINESS_CARD_SE' => array( 155.906, 255.118), |
| 2413 |
'BUSINESS_CARD_RU' => array( 141.732, 255.118), |
| 2414 |
'BUSINESS_CARD_CZ' => array( 141.732, 255.118), |
| 2415 |
'BUSINESS_CARD_FI' => array( 141.732, 255.118), |
| 2416 |
'BUSINESS_CARD_HU' => array( 141.732, 255.118), |
| 2417 |
'BUSINESS_CARD_IL' => array( 141.732, 255.118), |
| 2418 |
|
| 2419 |
'4SHEET' => array( 2880.000, 4320.000), |
| 2420 |
'6SHEET' => array( 3401.575, 5102.362), |
| 2421 |
'12SHEET' => array( 8640.000, 4320.000), |
| 2422 |
'16SHEET' => array( 5760.000, 8640.000), |
| 2423 |
'32SHEET' => array(11520.000, 8640.000), |
| 2424 |
'48SHEET' => array(17280.000, 8640.000), |
| 2425 |
'64SHEET' => array(23040.000, 8640.000), |
| 2426 |
'96SHEET' => array(34560.000, 8640.000), |
| 2427 |
|
| 2428 |
|
| 2429 |
'EN_EMPEROR' => array( 3456.000, 5184.000), |
| 2430 |
'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), |
| 2431 |
'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), |
| 2432 |
'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), |
| 2433 |
'EN_ATLAS' => array( 1872.000, 2448.000), |
| 2434 |
'EN_COLOMBIER' => array( 1692.000, 2484.000), |
| 2435 |
'EN_ELEPHANT' => array( 1656.000, 2016.000), |
| 2436 |
'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), |
| 2437 |
'EN_IMPERIAL' => array( 1584.000, 2160.000), |
| 2438 |
'EN_PRINCESS' => array( 1548.000, 2016.000), |
| 2439 |
'EN_CARTRIDGE' => array( 1512.000, 1872.000), |
| 2440 |
'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), |
| 2441 |
'EN_ROYAL' => array( 1440.000, 1800.000), |
| 2442 |
'EN_SHEET' => array( 1404.000, 1692.000), |
| 2443 |
'EN_HALF_POST' => array( 1404.000, 1692.000), |
| 2444 |
'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), |
| 2445 |
'EN_DOUBLE_POST' => array( 1368.000, 2196.000), |
| 2446 |
'EN_MEDIUM' => array( 1260.000, 1656.000), |
| 2447 |
'EN_DEMY' => array( 1260.000, 1620.000), |
| 2448 |
'EN_LARGE_POST' => array( 1188.000, 1512.000), |
| 2449 |
'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), |
| 2450 |
'EN_POST' => array( 1116.000, 1386.000), |
| 2451 |
'EN_CROWN' => array( 1080.000, 1440.000), |
| 2452 |
'EN_PINCHED_POST' => array( 1062.000, 1332.000), |
| 2453 |
'EN_BRIEF' => array( 972.000, 1152.000), |
| 2454 |
'EN_FOOLSCAP' => array( 972.000, 1224.000), |
| 2455 |
'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), |
| 2456 |
'EN_POTT' => array( 900.000, 1080.000), |
| 2457 |
|
| 2458 |
'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), |
| 2459 |
'BE_COLOMBIER' => array( 1757.480, 2409.449), |
| 2460 |
'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), |
| 2461 |
'BE_ELEPHANT' => array( 1746.142, 2182.677), |
| 2462 |
'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), |
| 2463 |
'BE_GRAND_JESUS' => array( 1559.055, 2069.291), |
| 2464 |
'BE_JESUS' => array( 1530.709, 2069.291), |
| 2465 |
'BE_RAISIN' => array( 1417.323, 1842.520), |
| 2466 |
'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), |
| 2467 |
'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), |
| 2468 |
'BE_COQUILLE' => array( 1218.898, 1587.402), |
| 2469 |
'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), |
| 2470 |
'BE_RUCHE' => array( 1020.472, 1303.937), |
| 2471 |
'BE_PROPATRIA' => array( 977.953, 1218.898), |
| 2472 |
'BE_LYS' => array( 898.583, 1125.354), |
| 2473 |
'BE_POT' => array( 870.236, 1088.504), |
| 2474 |
'BE_ROSETTE' => array( 765.354, 983.622), |
| 2475 |
|
| 2476 |
'FR_UNIVERS' => array( 2834.646, 3685.039), |
| 2477 |
'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), |
| 2478 |
'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), |
| 2479 |
'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), |
| 2480 |
'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), |
| 2481 |
'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), |
| 2482 |
'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), |
| 2483 |
'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), |
| 2484 |
'FR_JOURNAL' => array( 1842.520, 2664.567), |
| 2485 |
'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), |
| 2486 |
'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), |
| 2487 |
'FR_CLOCHE' => array( 1700.787, 2267.717), |
| 2488 |
'FR_SOLEIL' => array( 1700.787, 2267.717), |
| 2489 |
'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), |
| 2490 |
'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), |
| 2491 |
'FR_JESUS' => array( 1587.402, 2154.331), |
| 2492 |
'FR_RAISIN' => array( 1417.323, 1842.520), |
| 2493 |
'FR_CAVALIER' => array( 1303.937, 1757.480), |
| 2494 |
'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), |
| 2495 |
'FR_CARRE' => array( 1275.591, 1587.402), |
| 2496 |
'FR_COQUILLE' => array( 1247.244, 1587.402), |
| 2497 |
'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), |
| 2498 |
'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), |
| 2499 |
'FR_DOUBLE_POT' => array( 1133.858, 1757.480), |
| 2500 |
'FR_ECU' => array( 1133.858, 1474.016), |
| 2501 |
'FR_COURONNE' => array( 1020.472, 1303.937), |
| 2502 |
'FR_TELLIERE' => array( 963.780, 1247.244), |
| 2503 |
'FR_POT' => array( 878.740, 1133.858), |
| 2504 |
); |
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
public static function getPageSizeFromFormat($format) { |
| 2515 |
if (isset(self::$page_formats[$format])) { |
| 2516 |
return self::$page_formats[$format]; |
| 2517 |
} |
| 2518 |
return self::$page_formats['A4']; |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) { |
| 2537 |
if (!isset($pagedim[$page])) { |
| 2538 |
|
| 2539 |
$pagedim[$page] = array(); |
| 2540 |
} |
| 2541 |
if (!in_array($type, self::$pageboxes)) { |
| 2542 |
return; |
| 2543 |
} |
| 2544 |
if ($points) { |
| 2545 |
$k = 1; |
| 2546 |
} |
| 2547 |
$pagedim[$page][$type]['llx'] = ($llx * $k); |
| 2548 |
$pagedim[$page][$type]['lly'] = ($lly * $k); |
| 2549 |
$pagedim[$page][$type]['urx'] = ($urx * $k); |
| 2550 |
$pagedim[$page][$type]['ury'] = ($ury * $k); |
| 2551 |
return $pagedim; |
| 2552 |
} |
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
public static function swapPageBoxCoordinates($page, $pagedim) { |
| 2563 |
foreach (self::$pageboxes as $type) { |
| 2564 |
|
| 2565 |
if (isset($pagedim[$page][$type])) { |
| 2566 |
$tmp = $pagedim[$page][$type]['llx']; |
| 2567 |
$pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly']; |
| 2568 |
$pagedim[$page][$type]['lly'] = $tmp; |
| 2569 |
$tmp = $pagedim[$page][$type]['urx']; |
| 2570 |
$pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury']; |
| 2571 |
$pagedim[$page][$type]['ury'] = $tmp; |
| 2572 |
} |
| 2573 |
} |
| 2574 |
return $pagedim; |
| 2575 |
} |
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
public static function getPageLayoutMode($layout='SinglePage') { |
| 2584 |
switch ($layout) { |
| 2585 |
case 'default': |
| 2586 |
case 'single': |
| 2587 |
case 'SinglePage': { |
| 2588 |
$layout_mode = 'SinglePage'; |
| 2589 |
break; |
| 2590 |
} |
| 2591 |
case 'continuous': |
| 2592 |
case 'OneColumn': { |
| 2593 |
$layout_mode = 'OneColumn'; |
| 2594 |
break; |
| 2595 |
} |
| 2596 |
case 'two': |
| 2597 |
case 'TwoColumnLeft': { |
| 2598 |
$layout_mode = 'TwoColumnLeft'; |
| 2599 |
break; |
| 2600 |
} |
| 2601 |
case 'TwoColumnRight': { |
| 2602 |
$layout_mode = 'TwoColumnRight'; |
| 2603 |
break; |
| 2604 |
} |
| 2605 |
case 'TwoPageLeft': { |
| 2606 |
$layout_mode = 'TwoPageLeft'; |
| 2607 |
break; |
| 2608 |
} |
| 2609 |
case 'TwoPageRight': { |
| 2610 |
$layout_mode = 'TwoPageRight'; |
| 2611 |
break; |
| 2612 |
} |
| 2613 |
default: { |
| 2614 |
$layout_mode = 'SinglePage'; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
return $layout_mode; |
| 2618 |
} |
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
public static function getPageMode($mode='UseNone') { |
| 2627 |
switch ($mode) { |
| 2628 |
case 'UseNone': { |
| 2629 |
$page_mode = 'UseNone'; |
| 2630 |
break; |
| 2631 |
} |
| 2632 |
case 'UseOutlines': { |
| 2633 |
$page_mode = 'UseOutlines'; |
| 2634 |
break; |
| 2635 |
} |
| 2636 |
case 'UseThumbs': { |
| 2637 |
$page_mode = 'UseThumbs'; |
| 2638 |
break; |
| 2639 |
} |
| 2640 |
case 'FullScreen': { |
| 2641 |
$page_mode = 'FullScreen'; |
| 2642 |
break; |
| 2643 |
} |
| 2644 |
case 'UseOC': { |
| 2645 |
$page_mode = 'UseOC'; |
| 2646 |
break; |
| 2647 |
} |
| 2648 |
case '': { |
| 2649 |
$page_mode = 'UseAttachments'; |
| 2650 |
break; |
| 2651 |
} |
| 2652 |
default: { |
| 2653 |
$page_mode = 'UseNone'; |
| 2654 |
} |
| 2655 |
} |
| 2656 |
return $page_mode; |
| 2657 |
} |
| 2658 |
|
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|