add more global namespacing

This commit is contained in:
Dennis Eichhorn 2023-08-02 09:01:59 +00:00
parent 368e8d687f
commit 374228321f
2 changed files with 229 additions and 229 deletions

View File

@ -79,13 +79,13 @@ class TCPDF_FONTS {
// build new font name for TCPDF compatibility // build new font name for TCPDF compatibility
$font_path_parts = pathinfo($fontfile); $font_path_parts = pathinfo($fontfile);
if (!isset($font_path_parts['filename'])) { if (!isset($font_path_parts['filename'])) {
$font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1)); $font_path_parts['filename'] = \substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
} }
$font_name = strtolower($font_path_parts['filename']); $font_name = \strtolower($font_path_parts['filename']);
$font_name = preg_replace('/[^a-z0-9_]/', '', $font_name); $font_name = \preg_replace('/[^a-z0-9_]/', '', $font_name);
$search = array('bold', 'oblique', 'italic', 'regular'); $search = array('bold', 'oblique', 'italic', 'regular');
$replace = array('b', 'i', 'i', ''); $replace = array('b', 'i', 'i', '');
$font_name = str_replace($search, $replace, $font_name); $font_name = \str_replace($search, $replace, $font_name);
if (empty($font_name)) { if (empty($font_name)) {
// set generic name // set generic name
$font_name = 'tcpdffont'; $font_name = 'tcpdffont';
@ -102,14 +102,14 @@ class TCPDF_FONTS {
$fmetric['file'] = $font_name; $fmetric['file'] = $font_name;
$fmetric['ctg'] = $font_name.'.ctg.z'; $fmetric['ctg'] = $font_name.'.ctg.z';
// get font data // get font data
$font = file_get_contents($fontfile); $font = \file_get_contents($fontfile);
$fmetric['originalsize'] = strlen($font); $fmetric['originalsize'] = strlen($font);
// autodetect font type // autodetect font type
if (empty($fonttype)) { if (empty($fonttype)) {
if (TCPDF_STATIC::_getULONG($font, 0) == 0x10000) { if (TCPDF_STATIC::_getULONG($font, 0) == 0x10000) {
// True Type (Unicode or not) // True Type (Unicode or not)
$fonttype = 'TrueTypeUnicode'; $fonttype = 'TrueTypeUnicode';
} elseif (substr($font, 0, 4) == 'OTTO') { } elseif (\substr($font, 0, 4) == 'OTTO') {
// Open Type (Unicode or not) // Open Type (Unicode or not)
//Unsupported font format: OpenType with CFF data //Unsupported font format: OpenType with CFF data
return false; return false;
@ -145,7 +145,7 @@ class TCPDF_FONTS {
} }
} }
// set encoding maps (if any) // set encoding maps (if any)
$fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc); $fmetric['enc'] = \preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
$fmetric['diff'] = ''; $fmetric['diff'] = '';
if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) { if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
if (!empty($enc) AND ($enc != 'cp1252') AND isset(TCPDF_FONT_DATA::$encmap[$enc])) { if (!empty($enc) AND ($enc != 'cp1252') AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
@ -168,21 +168,21 @@ class TCPDF_FONTS {
if ($fmetric['type'] == 'Type1') { if ($fmetric['type'] == 'Type1') {
// ---------- TYPE 1 ---------- // ---------- TYPE 1 ----------
// read first segment // read first segment
$a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6)); $a = unpack('Cmarker/Ctype/Vsize', \substr($font, 0, 6));
if ($a['marker'] != 128) { if ($a['marker'] != 128) {
// Font file is not a valid binary Type1 // Font file is not a valid binary Type1
return false; return false;
} }
$fmetric['size1'] = $a['size']; $fmetric['size1'] = $a['size'];
$data = substr($font, 6, $fmetric['size1']); $data = \substr($font, 6, $fmetric['size1']);
// read second segment // read second segment
$a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6)); $a = unpack('Cmarker/Ctype/Vsize', \substr($font, (6 + $fmetric['size1']), 6));
if ($a['marker'] != 128) { if ($a['marker'] != 128) {
// Font file is not a valid binary Type1 // Font file is not a valid binary Type1
return false; return false;
} }
$fmetric['size2'] = $a['size']; $fmetric['size2'] = $a['size'];
$encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']); $encrypted = \substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
$data .= $encrypted; $data .= $encrypted;
// store compressed font // store compressed font
$fmetric['file'] .= '.z'; $fmetric['file'] .= '.z';
@ -192,7 +192,7 @@ class TCPDF_FONTS {
// get font info // get font info
$fmetric['Flags'] = $flags; $fmetric['Flags'] = $flags;
preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches); preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]); $fmetric['name'] = \preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches); preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
$fmetric['bbox'] = trim($matches[1]); $fmetric['bbox'] = trim($matches[1]);
$bv = explode(' ', $fmetric['bbox']); $bv = explode(' ', $fmetric['bbox']);
@ -272,7 +272,7 @@ class TCPDF_FONTS {
} }
$fmetric['Leading'] = 0; $fmetric['Leading'] = 0;
// get charstring data // get charstring data
$eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1)); $eplain = \substr($eplain, (strpos($eplain, '/CharStrings') + 1));
preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER); preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) { if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
$enc_map = TCPDF_FONT_DATA::$encmap[$enc]; $enc_map = TCPDF_FONT_DATA::$encmap[$enc];
@ -382,7 +382,7 @@ class TCPDF_FONTS {
// ---------- get tables ---------- // ---------- get tables ----------
for ($i = 0; $i < $numTables; ++$i) { for ($i = 0; $i < $numTables; ++$i) {
// get table info // get table info
$tag = substr($font, $offset, 4); $tag = \substr($font, $offset, 4);
$offset += 4; $offset += 4;
$table[$tag] = array(); $table[$tag] = array();
$table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset); $table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
@ -508,8 +508,8 @@ class TCPDF_FONTS {
$stringOffset = TCPDF_STATIC::_getUSHORT($font, $offset); $stringOffset = TCPDF_STATIC::_getUSHORT($font, $offset);
$offset += 2; $offset += 2;
$offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset); $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
$fmetric['name'] = substr($font, $offset, $stringLength); $fmetric['name'] = \substr($font, $offset, $stringLength);
$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']); $fmetric['name'] = \preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
break; break;
} else { } else {
$offset += 4; // skip String length, String offset $offset += 4; // skip String length, String offset
@ -907,9 +907,9 @@ class TCPDF_FONTS {
$pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].''; $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].'';
$pfile .= ');'."\n"; $pfile .= ');'."\n";
if (!empty($fmetric['cbbox'])) { if (!empty($fmetric['cbbox'])) {
$pfile .= '$cbbox=array('.substr($fmetric['cbbox'], 1).');'."\n"; $pfile .= '$cbbox=array('.\substr($fmetric['cbbox'], 1).');'."\n";
} }
$pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n"; $pfile .= '$cw=array('.\substr($fmetric['cw'], 1).');'."\n";
$pfile .= '// --- EOF ---'."\n"; $pfile .= '// --- EOF ---'."\n";
// store file // store file
$fp = TCPDF_STATIC::fopenLocal($outpath.$font_name.'.php', 'w'); $fp = TCPDF_STATIC::fopenLocal($outpath.$font_name.'.php', 'w');
@ -933,7 +933,7 @@ class TCPDF_FONTS {
$tlen = ($length / 4); $tlen = ($length / 4);
$offset = 0; $offset = 0;
for ($i = 0; $i < $tlen; ++$i) { for ($i = 0; $i < $tlen; ++$i) {
$v = unpack('Ni', substr($table, $offset, 4)); $v = unpack('Ni', \substr($table, $offset, 4));
$sum += $v['i']; $sum += $v['i'];
$offset += 4; $offset += 4;
} }
@ -969,7 +969,7 @@ class TCPDF_FONTS {
// for each table // for each table
for ($i = 0; $i < $numTables; ++$i) { for ($i = 0; $i < $numTables; ++$i) {
// get table info // get table info
$tag = substr($font, $offset, 4); $tag = \substr($font, $offset, 4);
$offset += 4; $offset += 4;
$table[$tag] = array(); $table[$tag] = array();
$table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset); $table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
@ -1151,7 +1151,7 @@ class TCPDF_FONTS {
$subsetglyphs[$g] = true; $subsetglyphs[$g] = true;
} }
} }
} }
break; break;
} }
case 6: { // Format 6: Trimmed table mapping case 6: { // Format 6: Trimmed table mapping
@ -1300,7 +1300,7 @@ class TCPDF_FONTS {
for ($i = 0; $i < $tot_num_glyphs; ++$i) { for ($i = 0; $i < $tot_num_glyphs; ++$i) {
if (isset($subsetglyphs[$i])) { if (isset($subsetglyphs[$i])) {
$length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]); $length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]);
$glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length); $glyf .= \substr($font, ($glyf_offset + $indexToLoc[$i]), $length);
} else { } else {
$length = 0; $length = 0;
} }
@ -1318,10 +1318,10 @@ class TCPDF_FONTS {
$offset = 12; $offset = 12;
foreach ($table as $tag => $val) { foreach ($table as $tag => $val) {
if (in_array($tag, $table_names)) { if (in_array($tag, $table_names)) {
$table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']); $table[$tag]['data'] = \substr($font, $table[$tag]['offset'], $table[$tag]['length']);
if ($tag == 'head') { if ($tag == 'head') {
// set the checkSumAdjustment to 0 // set the checkSumAdjustment to 0
$table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12); $table[$tag]['data'] = \substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".\substr($table[$tag]['data'], 12);
} }
$pad = 4 - ($table[$tag]['length'] % 4); $pad = 4 - ($table[$tag]['length'] % 4);
if ($pad != 4) { if ($pad != 4) {
@ -1383,7 +1383,7 @@ class TCPDF_FONTS {
} }
// set checkSumAdjustment on head table // set checkSumAdjustment on head table
$checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font)); $checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font));
$font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12); $font = \substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).\substr($font, $table['head']['offset'] + 12);
return $font; return $font;
} }
@ -1523,7 +1523,7 @@ class TCPDF_FONTS {
*/ */
public static function _getfontpath() { public static function _getfontpath() {
if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) { if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) {
if (substr($fdir, -1) != '/') { if (\substr($fdir, -1) != '/') {
$fdir .= '/'; $fdir .= '/';
} }
define('K_PATH_FONTS', $fdir); define('K_PATH_FONTS', $fdir);
@ -2048,7 +2048,7 @@ class TCPDF_FONTS {
} }
/** /**
* Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). * Reverse the RLT \substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
* @param string $str string to manipulate. * @param string $str string to manipulate.
* @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF) * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
* @param bool $forcertl if true forces RTL text direction * @param bool $forcertl if true forces RTL text direction
@ -2064,7 +2064,7 @@ class TCPDF_FONTS {
} }
/** /**
* Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). * Reverse the RLT \substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
* @param array $arr array of unicode values. * @param array $arr array of unicode values.
* @param string $str string to manipulate (or empty value). * @param string $str string to manipulate (or empty value).
* @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF) * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
@ -2081,7 +2081,7 @@ class TCPDF_FONTS {
} }
/** /**
* Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). * Reverse the RLT \substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
* @param array $ta array of characters composing the string. * @param array $ta array of characters composing the string.
* @param string $str string to process * @param string $str string to process
* @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR

View File

@ -173,7 +173,7 @@ class TCPDF_STATIC {
if ($headers === false) { if ($headers === false) {
return false; return false;
} }
return (strpos($headers[0], '200') !== false); return (\strpos($headers[0], '200') !== false);
} }
/** /**
@ -185,7 +185,7 @@ class TCPDF_STATIC {
* <li>HTML Entity (named): "&amp;shy;"</li> * <li>HTML Entity (named): "&amp;shy;"</li>
* <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li> * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
* <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li> * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
* <li>UTF-8 character: chr(194).chr(173)</li> * <li>UTF-8 character: \chr(194).\chr(173)</li>
* </ul> * </ul>
* @param string $txt input string * @param string $txt input string
* @param boolean $unicode True if we are in unicode mode, false otherwise. * @param boolean $unicode True if we are in unicode mode, false otherwise.
@ -194,9 +194,9 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function removeSHY($txt='', $unicode=true) { public static function removeSHY($txt='', $unicode=true) {
$txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); $txt = \preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
if (!$unicode) { if (!$unicode) {
$txt = preg_replace('/([\\xad]{1})/', '', $txt); $txt = \preg_replace('/([\\xad]{1})/', '', $txt);
} }
return $txt; return $txt;
} }
@ -220,8 +220,8 @@ class TCPDF_STATIC {
} }
if (is_string($brd)) { if (is_string($brd)) {
// convert string to array // convert string to array
$slen = strlen($brd); $slen = \strlen($brd);
$newbrd = array(); $newbrd = [];
for ($i = 0; $i < $slen; ++$i) { for ($i = 0; $i < $slen; ++$i) {
$newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter'); $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
} }
@ -230,10 +230,10 @@ class TCPDF_STATIC {
foreach ($brd as $border => $style) { foreach ($brd as $border => $style) {
switch ($position) { switch ($position) {
case 'start': { case 'start': {
if (strpos($border, 'B') !== false) { if (\strpos($border, 'B') !== false) {
// remove bottom line // remove bottom line
$newkey = str_replace('B', '', $border); $newkey = \str_replace('B', '', $border);
if (strlen($newkey) > 0) { if (\strlen($newkey) > 0) {
$brd[$newkey] = $style; $brd[$newkey] = $style;
} }
unset($brd[$border]); unset($brd[$border]);
@ -241,19 +241,19 @@ class TCPDF_STATIC {
break; break;
} }
case 'middle': { case 'middle': {
if (strpos($border, 'B') !== false) { if (\strpos($border, 'B') !== false) {
// remove bottom line // remove bottom line
$newkey = str_replace('B', '', $border); $newkey = \str_replace('B', '', $border);
if (strlen($newkey) > 0) { if (\strlen($newkey) > 0) {
$brd[$newkey] = $style; $brd[$newkey] = $style;
} }
unset($brd[$border]); unset($brd[$border]);
$border = $newkey; $border = $newkey;
} }
if (strpos($border, 'T') !== false) { if (\strpos($border, 'T') !== false) {
// remove bottom line // remove bottom line
$newkey = str_replace('T', '', $border); $newkey = \str_replace('T', '', $border);
if (strlen($newkey) > 0) { if (\strlen($newkey) > 0) {
$brd[$newkey] = $style; $brd[$newkey] = $style;
} }
unset($brd[$border]); unset($brd[$border]);
@ -261,10 +261,10 @@ class TCPDF_STATIC {
break; break;
} }
case 'end': { case 'end': {
if (strpos($border, 'T') !== false) { if (\strpos($border, 'T') !== false) {
// remove bottom line // remove bottom line
$newkey = str_replace('T', '', $border); $newkey = \str_replace('T', '', $border);
if (strlen($newkey) > 0) { if (\strlen($newkey) > 0) {
$brd[$newkey] = $style; $brd[$newkey] = $style;
} }
unset($brd[$border]); unset($brd[$border]);
@ -284,7 +284,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function empty_string($str) { public static function empty_string($str) {
return (is_null($str) OR (is_string($str) AND (strlen($str) == 0))); return (is_null($str) OR (is_string($str) AND (\strlen($str) == 0)));
} }
/** /**
@ -306,8 +306,8 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _escape($s) { public static function _escape($s) {
// the chr(13) substitution fixes the Bugs item #1421290. // the \chr(13) substitution fixes the Bugs item #1421290.
return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', \chr(13) => '\r'));
} }
/** /**
@ -364,8 +364,8 @@ class TCPDF_STATIC {
public static function replacePageNumAliases($page, $replace, $diff=0) { public static function replacePageNumAliases($page, $replace, $diff=0) {
foreach ($replace as $rep) { foreach ($replace as $rep) {
foreach ($rep[3] as $a) { foreach ($rep[3] as $a) {
if (strpos($page, $a) !== false) { if (\strpos($page, $a) !== false) {
$page = str_replace($a, $rep[0], $page); $page = \str_replace($a, $rep[0], $page);
$diff += ($rep[2] - $rep[1]); $diff += ($rep[2] - $rep[1]);
} }
} }
@ -383,9 +383,9 @@ class TCPDF_STATIC {
public static function getTimestamp($date) { public static function getTimestamp($date) {
if (($date[0] == 'D') AND ($date[1] == ':')) { if (($date[0] == 'D') AND ($date[1] == ':')) {
// remove date prefix if present // remove date prefix if present
$date = substr($date, 2); $date = \substr($date, 2);
} }
return strtotime($date); return \strtotime($date);
} }
/** /**
@ -396,7 +396,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function getFormattedDate($time) { public static function getFormattedDate($time) {
return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\''; return \substr_replace(date('YmdHisO', \intval($time)), '\'', (0 - 2), 0).'\'';
} }
/** /**
@ -409,10 +409,10 @@ class TCPDF_STATIC {
*/ */
public static function getRandomSeed($seed='') { public static function getRandomSeed($seed='') {
$rnd = uniqid(rand().microtime(true), true); $rnd = uniqid(rand().microtime(true), true);
if (function_exists('posix_getpid')) { if (\function_exists('posix_getpid')) {
$rnd .= posix_getpid(); $rnd .= posix_getpid();
} }
if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { if (\function_exists('openssl_random_pseudo_bytes') AND (strtoupper(\substr(PHP_OS, 0, 3)) !== 'WIN')) {
// this is not used on windows systems because it is very slow for a know bug // this is not used on windows systems because it is very slow for a know bug
$rnd .= openssl_random_pseudo_bytes(512); $rnd .= openssl_random_pseudo_bytes(512);
} else { } else {
@ -446,11 +446,11 @@ class TCPDF_STATIC {
*/ */
public static function _AES($key, $text) { public static function _AES($key, $text) {
// padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0) // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
$padding = 16 - (strlen($text) % 16); $padding = 16 - (\strlen($text) % 16);
$text .= str_repeat(chr($padding), $padding); $text .= \str_repeat(\chr($padding), $padding);
if (extension_loaded('openssl')) { if (extension_loaded('openssl')) {
$algo = 'aes-256-cbc'; $algo = 'aes-256-cbc';
if (strlen($key) == 16) { if (\strlen($key) == 16) {
$algo = 'aes-128-cbc'; $algo = 'aes-128-cbc';
} }
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo)); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo));
@ -476,14 +476,14 @@ class TCPDF_STATIC {
public static function _AESnopad($key, $text) { public static function _AESnopad($key, $text) {
if (extension_loaded('openssl')) { if (extension_loaded('openssl')) {
$algo = 'aes-256-cbc'; $algo = 'aes-256-cbc';
if (strlen($key) == 16) { if (\strlen($key) == 16) {
$algo = 'aes-128-cbc'; $algo = 'aes-128-cbc';
} }
$iv = str_repeat("\x00", openssl_cipher_iv_length($algo)); $iv = \str_repeat("\x00", openssl_cipher_iv_length($algo));
$text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv); $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv);
return substr($text, 0, -16); return \substr($text, 0, -16);
} }
$iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); $iv = \str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
return $text; return $text;
} }
@ -501,17 +501,17 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) { public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) { if (\function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
// try to use mcrypt function if exist // try to use mcrypt function if exist
return $out; return $out;
} }
if ($last_enc_key != $key) { if ($last_enc_key != $key) {
$k = str_repeat($key, (int) ((256 / strlen($key)) + 1)); $k = \str_repeat($key, (int) ((256 / \strlen($key)) + 1));
$rc4 = range(0, 255); $rc4 = range(0, 255);
$j = 0; $j = 0;
for ($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$t = $rc4[$i]; $t = $rc4[$i];
$j = ($j + $t + ord($k[$i])) % 256; $j = ($j + $t + \ord($k[$i])) % 256;
$rc4[$i] = $rc4[$j]; $rc4[$i] = $rc4[$j];
$rc4[$j] = $t; $rc4[$j] = $t;
} }
@ -520,7 +520,7 @@ class TCPDF_STATIC {
} else { } else {
$rc4 = $last_enc_key_c; $rc4 = $last_enc_key_c;
} }
$len = strlen($text); $len = \strlen($text);
$a = 0; $a = 0;
$b = 0; $b = 0;
$out = ''; $out = '';
@ -531,7 +531,7 @@ class TCPDF_STATIC {
$rc4[$a] = $rc4[$b]; $rc4[$a] = $rc4[$b];
$rc4[$b] = $t; $rc4[$b] = $t;
$k = $rc4[($rc4[$a] + $rc4[$b]) % 256]; $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
$out .= chr(ord($text[$i]) ^ $k); $out .= \chr(\ord($text[$i]) ^ $k);
} }
return $out; return $out;
} }
@ -583,14 +583,14 @@ class TCPDF_STATIC {
*/ */
public static function convertHexStringToString($bs) { public static function convertHexStringToString($bs) {
$string = ''; // string to be returned $string = ''; // string to be returned
$bslength = strlen($bs); $bslength = \strlen($bs);
if (($bslength % 2) != 0) { if (($bslength % 2) != 0) {
// padding // padding
$bs .= '0'; $bs .= '0';
++$bslength; ++$bslength;
} }
for ($i = 0; $i < $bslength; $i += 2) { for ($i = 0; $i < $bslength; $i += 2) {
$string .= chr(hexdec($bs[$i].$bs[($i + 1)])); $string .= \chr(hexdec($bs[$i].$bs[($i + 1)]));
} }
return $string; return $string;
} }
@ -605,9 +605,9 @@ class TCPDF_STATIC {
*/ */
public static function convertStringToHexString($s) { public static function convertStringToHexString($s) {
$bs = ''; $bs = '';
$chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); $chars = \preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $c) { foreach ($chars as $c) {
$bs .= sprintf('%02s', dechex(ord($c))); $bs .= \sprintf('%02s', dechex(\ord($c)));
} }
return $bs; return $bs;
} }
@ -621,11 +621,11 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function getEncPermissionsString($protection) { public static function getEncPermissionsString($protection) {
$binprot = sprintf('%032b', $protection); $binprot = \sprintf('%032b', $protection);
$str = chr(bindec(substr($binprot, 24, 8))); $str = \chr(bindec(\substr($binprot, 24, 8)));
$str .= chr(bindec(substr($binprot, 16, 8))); $str .= \chr(bindec(\substr($binprot, 16, 8)));
$str .= chr(bindec(substr($binprot, 8, 8))); $str .= \chr(bindec(\substr($binprot, 8, 8)));
$str .= chr(bindec(substr($binprot, 0, 8))); $str .= \chr(bindec(\substr($binprot, 0, 8)));
return $str; return $str;
} }
@ -639,13 +639,13 @@ class TCPDF_STATIC {
*/ */
public static function encodeNameObject($name) { public static function encodeNameObject($name) {
$escname = ''; $escname = '';
$length = strlen($name); $length = \strlen($name);
for ($i = 0; $i < $length; ++$i) { for ($i = 0; $i < $length; ++$i) {
$chr = $name[$i]; $chr = $name[$i];
if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) { if (\preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) {
$escname .= $chr; $escname .= $chr;
} else { } else {
$escname .= sprintf('#%02X', ord($chr)); $escname .= \sprintf('#%02X', \ord($chr));
} }
} }
return $escname; return $escname;
@ -662,11 +662,11 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) { public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
if (isset($prop['aopt']) AND is_array($prop['aopt'])) { if (isset($prop['aopt']) AND \is_array($prop['aopt'])) {
// the annotation options are already defined // the annotation options are already defined
return $prop['aopt']; return $prop['aopt'];
} }
$opt = array(); // value to be returned $opt = []; // value to be returned
// alignment: Controls how the text is laid out within the text field. // alignment: Controls how the text is laid out within the text field.
if (isset($prop['alignment'])) { if (isset($prop['alignment'])) {
switch ($prop['alignment']) { switch ($prop['alignment']) {
@ -690,7 +690,7 @@ class TCPDF_STATIC {
} }
// lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
if (isset($prop['lineWidth'])) { if (isset($prop['lineWidth'])) {
$linewidth = intval($prop['lineWidth']); $linewidth = \intval($prop['lineWidth']);
} else { } else {
$linewidth = 1; $linewidth = 1;
} }
@ -732,14 +732,14 @@ class TCPDF_STATIC {
} }
} }
} }
if (isset($prop['border']) AND is_array($prop['border'])) { if (isset($prop['border']) AND \is_array($prop['border'])) {
$opt['border'] = $prop['border']; $opt['border'] = $prop['border'];
} }
if (!isset($opt['mk'])) { if (!isset($opt['mk'])) {
$opt['mk'] = array(); $opt['mk'] = [];
} }
if (!isset($opt['mk']['if'])) { if (!isset($opt['mk']['if'])) {
$opt['mk']['if'] = array(); $opt['mk']['if'] = [];
} }
$opt['mk']['if']['a'] = array(0.5, 0.5); $opt['mk']['if']['a'] = array(0.5, 0.5);
// buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
@ -830,7 +830,7 @@ class TCPDF_STATIC {
} }
// fillColor: Specifies the background color for a field. // fillColor: Specifies the background color for a field.
if (isset($prop['fillColor'])) { if (isset($prop['fillColor'])) {
if (is_array($prop['fillColor'])) { if (\is_array($prop['fillColor'])) {
$opt['mk']['bg'] = $prop['fillColor']; $opt['mk']['bg'] = $prop['fillColor'];
} else { } else {
$opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors); $opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
@ -838,7 +838,7 @@ class TCPDF_STATIC {
} }
// strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width. // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
if (isset($prop['strokeColor'])) { if (isset($prop['strokeColor'])) {
if (is_array($prop['strokeColor'])) { if (\is_array($prop['strokeColor'])) {
$opt['mk']['bc'] = $prop['strokeColor']; $opt['mk']['bc'] = $prop['strokeColor'];
} else { } else {
$opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors); $opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
@ -850,7 +850,7 @@ class TCPDF_STATIC {
} }
// charLimit: Limits the number of characters that a user can type into a text field. // charLimit: Limits the number of characters that a user can type into a text field.
if (isset($prop['charLimit'])) { if (isset($prop['charLimit'])) {
$opt['maxlen'] = intval($prop['charLimit']); $opt['maxlen'] = \intval($prop['charLimit']);
} }
if (!isset($ff)) { if (!isset($ff)) {
$ff = 0; // default value $ff = 0; // default value
@ -951,13 +951,13 @@ class TCPDF_STATIC {
} }
$opt['f'] = $f; $opt['f'] = $f;
// currentValueIndices: Reads and writes single or multiple values of a list box or combo box. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) { if (isset($prop['currentValueIndices']) AND \is_array($prop['currentValueIndices'])) {
$opt['i'] = $prop['currentValueIndices']; $opt['i'] = $prop['currentValueIndices'];
} }
// value: The value of the field data that the user has entered. // value: The value of the field data that the user has entered.
if (isset($prop['value'])) { if (isset($prop['value'])) {
if (is_array($prop['value'])) { if (\is_array($prop['value'])) {
$opt['opt'] = array(); $opt['opt'] = [];
foreach ($prop['value'] AS $key => $optval) { foreach ($prop['value'] AS $key => $optval) {
// exportValues: An array of strings representing the export values for the field. // exportValues: An array of strings representing the export values for the field.
if (isset($prop['exportValues'][$key])) { if (isset($prop['exportValues'][$key])) {
@ -1055,30 +1055,30 @@ class TCPDF_STATIC {
*/ */
public static function extractCSSproperties($cssdata) { public static function extractCSSproperties($cssdata) {
if (empty($cssdata)) { if (empty($cssdata)) {
return array(); return [];
} }
// remove comments // remove comments
$cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata); $cssdata = \preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
// remove newlines and multiple spaces // remove newlines and multiple spaces
$cssdata = preg_replace('/[\s]+/', ' ', $cssdata); $cssdata = \preg_replace('/[\s]+/', ' ', $cssdata);
// remove some spaces // remove some spaces
$cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata); $cssdata = \preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
// remove empty blocks // remove empty blocks
$cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata); $cssdata = \preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
// replace media type parenthesis // replace media type parenthesis
$cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata); $cssdata = \preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
$cssdata = preg_replace('/\}\}/si', '}§', $cssdata); $cssdata = \preg_replace('/\}\}/si', '}§', $cssdata);
// trim string // trim string
$cssdata = trim($cssdata); $cssdata = \trim($cssdata);
// find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv) // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
$cssblocks = array(); $cssblocks = [];
$matches = array(); $matches = [];
if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) { if (\preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
foreach ($matches[1] as $key => $type) { foreach ($matches[1] as $key => $type) {
$cssblocks[$type] = $matches[2][$key]; $cssblocks[$type] = $matches[2][$key];
} }
// remove media blocks // remove media blocks
$cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata); $cssdata = \preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
} }
// keep 'all' and 'print' media, other media types are discarded // keep 'all' and 'print' media, other media types are discarded
if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) { if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
@ -1088,17 +1088,17 @@ class TCPDF_STATIC {
$cssdata .= $cssblocks['print']; $cssdata .= $cssblocks['print'];
} }
// reset css blocks array // reset css blocks array
$cssblocks = array(); $cssblocks = [];
$matches = array(); $matches = [];
// explode css data string into array // explode css data string into array
if (substr($cssdata, -1) == '}') { if (\substr($cssdata, -1) == '}') {
// remove last parethesis // remove last parethesis
$cssdata = substr($cssdata, 0, -1); $cssdata = \substr($cssdata, 0, -1);
} }
$matches = explode('}', $cssdata); $matches = \explode('}', $cssdata);
foreach ($matches as $key => $block) { foreach ($matches as $key => $block) {
// index 0 contains the CSS selector, index 1 contains CSS properties // index 0 contains the CSS selector, index 1 contains CSS properties
$cssblocks[$key] = explode('{', $block); $cssblocks[$key] = \explode('{', $block);
if (!isset($cssblocks[$key][1])) { if (!isset($cssblocks[$key][1])) {
// remove empty definitions // remove empty definitions
unset($cssblocks[$key]); unset($cssblocks[$key]);
@ -1106,26 +1106,26 @@ class TCPDF_STATIC {
} }
// split groups of selectors (comma-separated list of selectors) // split groups of selectors (comma-separated list of selectors)
foreach ($cssblocks as $key => $block) { foreach ($cssblocks as $key => $block) {
if (strpos($block[0], ',') > 0) { if (\strpos($block[0], ',') > 0) {
$selectors = explode(',', $block[0]); $selectors = \explode(',', $block[0]);
foreach ($selectors as $sel) { foreach ($selectors as $sel) {
$cssblocks[] = array(0 => trim($sel), 1 => $block[1]); $cssblocks[] = array(0 => \trim($sel), 1 => $block[1]);
} }
unset($cssblocks[$key]); unset($cssblocks[$key]);
} }
} }
// covert array to selector => properties // covert array to selector => properties
$cssdata = array(); $cssdata = [];
foreach ($cssblocks as $block) { foreach ($cssblocks as $block) {
$selector = $block[0]; $selector = $block[0];
// calculate selector's specificity // calculate selector's specificity
$matches = array(); $matches = [];
$a = 0; // the declaration is not from is a 'style' attribute $a = 0; // the declaration is not from is a 'style' attribute
$b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes $b = \intval(\preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
$c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes $c = \intval(\preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
$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)); // number of pseudo-classes $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)); // number of pseudo-classes
$d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names $d = \intval(\preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
$d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements $d += \intval(\preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
$specificity = $a.$b.$c.$d; $specificity = $a.$b.$c.$d;
// add specificity to the beginning of the selector // add specificity to the beginning of the selector
$cssdata[$specificity.' '.$selector] = $block[1]; $cssdata[$specificity.' '.$selector] = $block[1];
@ -1178,13 +1178,13 @@ class TCPDF_STATIC {
// get the CSS part // get the CSS part
$tidy_head = tidy_get_head($tidy); $tidy_head = tidy_get_head($tidy);
$css = $tidy_head->value; $css = $tidy_head->value;
$css = preg_replace('/<style([^>]+)>/ims', '<style>', $css); $css = \preg_replace('/<style([^>]+)>/ims', '<style>', $css);
$css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css); $css = \preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
$css = str_replace('/*<![CDATA[*/', '', $css); $css = \str_replace('/*<![CDATA[*/', '', $css);
$css = str_replace('/*]]>*/', '', $css); $css = \str_replace('/*]]>*/', '', $css);
preg_match('/<style>(.*)<\/style>/ims', $css, $matches); preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
if (isset($matches[1])) { if (isset($matches[1])) {
$css = strtolower($matches[1]); $css = \strtolower($matches[1]);
} else { } else {
$css = ''; $css = '';
} }
@ -1194,10 +1194,10 @@ class TCPDF_STATIC {
$tidy_body = tidy_get_body($tidy); $tidy_body = tidy_get_body($tidy);
$html = $tidy_body->value; $html = $tidy_body->value;
// fix some self-closing tags // fix some self-closing tags
$html = str_replace('<br>', '<br />', $html); $html = \str_replace('<br>', '<br />', $html);
// remove some empty tag blocks // remove some empty tag blocks
$html = preg_replace('/<div([^\>]*)><\/div>/', '', $html); $html = \preg_replace('/<div([^\>]*)><\/div>/', '', $html);
$html = preg_replace('/<p([^\>]*)><\/p>/', '', $html); $html = \preg_replace('/<p([^\>]*)><\/p>/', '', $html);
if (!TCPDF_STATIC::empty_string($tagvs)) { if (!TCPDF_STATIC::empty_string($tagvs)) {
// set vertical space for some XHTML tags // set vertical space for some XHTML tags
$tagvspaces = $tagvs; $tagvspaces = $tagvs;
@ -1218,45 +1218,45 @@ class TCPDF_STATIC {
public static function isValidCSSSelectorForTag($dom, $key, $selector) { public static function isValidCSSSelectorForTag($dom, $key, $selector) {
$valid = false; // value to be returned $valid = false; // value to be returned
$tag = $dom[$key]['value']; $tag = $dom[$key]['value'];
$class = array(); $class = [];
if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) { if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
$class = explode(' ', strtolower($dom[$key]['attribute']['class'])); $class = \explode(' ', \strtolower($dom[$key]['attribute']['class']));
} }
$id = ''; $id = '';
if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) { if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
$id = strtolower($dom[$key]['attribute']['id']); $id = \strtolower($dom[$key]['attribute']['id']);
} }
$selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector); $selector = \preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
$matches = array(); $matches = [];
if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) { if (\preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
$parentop = array_pop($matches[1]); $parentop = \array_pop($matches[1]);
$operator = $parentop[0]; $operator = $parentop[0];
$offset = $parentop[1]; $offset = $parentop[1];
$lasttag = array_pop($matches[2]); $lasttag = \array_pop($matches[2]);
$lasttag = strtolower(trim($lasttag[0])); $lasttag = \strtolower(\trim($lasttag[0]));
if (($lasttag == '*') OR ($lasttag == $tag)) { if (($lasttag == '*') OR ($lasttag == $tag)) {
// the last element on selector is our tag or 'any tag' // the last element on selector is our tag or 'any tag'
$attrib = array_pop($matches[3]); $attrib = \array_pop($matches[3]);
$attrib = strtolower(trim($attrib[0])); $attrib = \strtolower(\trim($attrib[0]));
if (!empty($attrib)) { if (!empty($attrib)) {
// check if matches class, id, attribute, pseudo-class or pseudo-element // check if matches class, id, attribute, pseudo-class or pseudo-element
switch ($attrib[0]) { switch ($attrib[0]) {
case '.': { // class case '.': { // class
if (in_array(substr($attrib, 1), $class)) { if (\in_array(\substr($attrib, 1), $class)) {
$valid = true; $valid = true;
} }
break; break;
} }
case '#': { // ID case '#': { // ID
if (substr($attrib, 1) == $id) { if (\substr($attrib, 1) == $id) {
$valid = true; $valid = true;
} }
break; break;
} }
case '[': { // attribute case '[': { // attribute
$attrmatch = array(); $attrmatch = [];
if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) { if (\preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
$att = strtolower($attrmatch[1]); $att = \strtolower($attrmatch[1]);
$val = $attrmatch[3]; $val = $attrmatch[3];
if (isset($dom[$key]['attribute'][$att])) { if (isset($dom[$key]['attribute'][$att])) {
switch ($attrmatch[2]) { switch ($attrmatch[2]) {
@ -1267,25 +1267,25 @@ class TCPDF_STATIC {
break; break;
} }
case '~=': { case '~=': {
if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) { if (\in_array($val, \explode(' ', $dom[$key]['attribute'][$att]))) {
$valid = true; $valid = true;
} }
break; break;
} }
case '^=': { case '^=': {
if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) { if ($val == \substr($dom[$key]['attribute'][$att], 0, \strlen($val))) {
$valid = true; $valid = true;
} }
break; break;
} }
case '$=': { case '$=': {
if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) { if ($val == \substr($dom[$key]['attribute'][$att], -\strlen($val))) {
$valid = true; $valid = true;
} }
break; break;
} }
case '*=': { case '*=': {
if (strpos($dom[$key]['attribute'][$att], $val) !== false) { if (\strpos($dom[$key]['attribute'][$att], $val) !== false) {
$valid = true; $valid = true;
} }
break; break;
@ -1293,7 +1293,7 @@ class TCPDF_STATIC {
case '|=': { case '|=': {
if ($dom[$key]['attribute'][$att] == $val) { if ($dom[$key]['attribute'][$att] == $val) {
$valid = true; $valid = true;
} elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) { } elseif (\preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
$valid = true; $valid = true;
} }
break; break;
@ -1323,7 +1323,7 @@ class TCPDF_STATIC {
if ($valid AND ($offset > 0)) { if ($valid AND ($offset > 0)) {
$valid = false; $valid = false;
// check remaining selector part // check remaining selector part
$selector = substr($selector, 0, $offset); $selector = \substr($selector, 0, $offset);
switch ($operator) { switch ($operator) {
case ' ': { // descendant of an element case ' ': { // descendant of an element
while ($dom[$key]['parent'] > 0) { while ($dom[$key]['parent'] > 0) {
@ -1376,22 +1376,22 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function getCSSdataArray($dom, $key, $css) { public static function getCSSdataArray($dom, $key, $css) {
$cssarray = array(); // style to be returned $cssarray = []; // style to be returned
// get parent CSS selectors // get parent CSS selectors
$selectors = array(); $selectors = [];
if (isset($dom[($dom[$key]['parent'])]['csssel'])) { if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
$selectors = $dom[($dom[$key]['parent'])]['csssel']; $selectors = $dom[($dom[$key]['parent'])]['csssel'];
} }
// get all styles that apply // get all styles that apply
foreach($css as $selector => $style) { foreach($css as $selector => $style) {
$pos = strpos($selector, ' '); $pos = \strpos($selector, ' ');
// get specificity // get specificity
$specificity = substr($selector, 0, $pos); $specificity = \substr($selector, 0, $pos);
// remove specificity // remove specificity
$selector = substr($selector, $pos); $selector = \substr($selector, $pos);
// check if this selector apply to current tag // check if this selector apply to current tag
if (self::isValidCSSSelectorForTag($dom, $key, $selector)) { if (self::isValidCSSSelectorForTag($dom, $key, $selector)) {
if (!in_array($selector, $selectors)) { if (!\in_array($selector, $selectors)) {
// add style if not already added on parent selector // add style if not already added on parent selector
$cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style); $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
$selectors[] = $selector; $selectors[] = $selector;
@ -1403,9 +1403,9 @@ class TCPDF_STATIC {
$cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']); $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
} }
// order the css array to account for specificity // order the css array to account for specificity
$cssordered = array(); $cssordered = [];
foreach ($cssarray as $key => $val) { foreach ($cssarray as $key => $val) {
$skey = sprintf('%04d', $key); $skey = \sprintf('%04d', $key);
$cssordered[$val['s'].'_'.$skey] = $val; $cssordered[$val['s'].'_'.$skey] = $val;
} }
// sort selectors alphabetically to account for specificity // sort selectors alphabetically to account for specificity
@ -1424,15 +1424,15 @@ class TCPDF_STATIC {
$tagstyle = ''; // value to be returned $tagstyle = ''; // value to be returned
foreach ($css as $style) { foreach ($css as $style) {
// split single css commands // split single css commands
$csscmds = explode(';', $style['c']); $csscmds = \explode(';', $style['c']);
foreach ($csscmds as $cmd) { foreach ($csscmds as $cmd) {
if (!empty($cmd)) { if (!empty($cmd)) {
$pos = strpos($cmd, ':'); $pos = \strpos($cmd, ':');
if ($pos !== false) { if ($pos !== false) {
$cmd = substr($cmd, 0, ($pos + 1)); $cmd = \substr($cmd, 0, ($pos + 1));
if (strpos($tagstyle, $cmd) !== false) { if (\strpos($tagstyle, $cmd) !== false) {
// remove duplicate commands (last commands have high priority) // remove duplicate commands (last commands have high priority)
$tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle); $tagstyle = \preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
} }
} }
} }
@ -1440,7 +1440,7 @@ class TCPDF_STATIC {
$tagstyle .= ';'.$style['c']; $tagstyle .= ';'.$style['c'];
} }
// remove multiple semicolons // remove multiple semicolons
$tagstyle = preg_replace('/[;]+/', ';', $tagstyle); $tagstyle = \preg_replace('/[;]+/', ';', $tagstyle);
return $tagstyle; return $tagstyle;
} }
@ -1521,11 +1521,11 @@ class TCPDF_STATIC {
* @since 4.8.038 (2010-03-13) * @since 4.8.038 (2010-03-13)
* @public static * @public static
*/ */
public static function revstrpos($haystack, $needle, $offset = 0) { public static function rev\strpos($haystack, $needle, $offset = 0) {
$length = strlen($haystack); $length = \strlen($haystack);
$offset = ($offset > 0)?($length - $offset):abs($offset); $offset = ($offset > 0)?($length - $offset):abs($offset);
$pos = strpos(strrev($haystack), strrev($needle), $offset); $pos = \strpos(strrev($haystack), strrev($needle), $offset);
return ($pos === false)?false:($length - $pos - strlen($needle)); return ($pos === false)?false:($length - $pos - \strlen($needle));
} }
/** /**
@ -1540,21 +1540,21 @@ class TCPDF_STATIC {
// TEX patterns are available at: // TEX patterns are available at:
// http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
$data = file_get_contents($file); $data = file_get_contents($file);
$patterns = array(); $patterns = [];
// remove comments // remove comments
$data = preg_replace('/\%[^\n]*/', '', $data); $data = \preg_replace('/\%[^\n]*/', '', $data);
// extract the patterns part // extract the patterns part
preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
$data = trim(substr($matches[0], 10, -1)); $data = \trim(\substr($matches[0], 10, -1));
// extract each pattern // extract each pattern
$patterns_array = preg_split('/[\s]+/', $data); $patterns_array = \preg_split('/[\s]+/', $data);
// create new language array of patterns // create new language array of patterns
$patterns = array(); $patterns = [];
foreach($patterns_array as $val) { foreach($patterns_array as $val) {
if (!TCPDF_STATIC::empty_string($val)) { if (!TCPDF_STATIC::empty_string($val)) {
$val = trim($val); $val = \trim($val);
$val = str_replace('\'', '\\\'', $val); $val = \str_replace('\'', '\\\'', $val);
$key = preg_replace('/[0-9]+/', '', $val); $key = \preg_replace('/[0-9]+/', '', $val);
$patterns[$key] = $val; $patterns[$key] = $val;
} }
} }
@ -1663,7 +1663,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function getTransformationMatrixProduct($ta, $tb) { public static function getTransformationMatrixProduct($ta, $tb) {
$tm = array(); $tm = [];
$tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
$tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
$tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
@ -1684,8 +1684,8 @@ class TCPDF_STATIC {
public static function getSVGTransformMatrix($attribute) { public static function getSVGTransformMatrix($attribute) {
// identity matrix // identity matrix
$tm = array(1, 0, 0, 1, 0, 0); $tm = array(1, 0, 0, 1, 0, 0);
$transform = array(); $transform = [];
if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { if (\preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
foreach ($transform as $key => $data) { foreach ($transform as $key => $data) {
if (!empty($data[2])) { if (!empty($data[2])) {
$a = 1; $a = 1;
@ -1694,10 +1694,10 @@ class TCPDF_STATIC {
$d = 1; $d = 1;
$e = 0; $e = 0;
$f = 0; $f = 0;
$regs = array(); $regs = [];
switch ($data[1]) { switch ($data[1]) {
case 'matrix': { case 'matrix': {
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)) { 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)) {
$a = $regs[1]; $a = $regs[1];
$b = $regs[2]; $b = $regs[2];
$c = $regs[3]; $c = $regs[3];
@ -1708,27 +1708,27 @@ class TCPDF_STATIC {
break; break;
} }
case 'translate': { case 'translate': {
if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { if (\preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
$e = $regs[1]; $e = $regs[1];
$f = $regs[2]; $f = $regs[2];
} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { } elseif (\preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
$e = $regs[1]; $e = $regs[1];
} }
break; break;
} }
case 'scale': { case 'scale': {
if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { if (\preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
$a = $regs[1]; $a = $regs[1];
$d = $regs[2]; $d = $regs[2];
} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { } elseif (\preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
$a = $regs[1]; $a = $regs[1];
$d = $a; $d = $a;
} }
break; break;
} }
case 'rotate': { case 'rotate': {
if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { if (\preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
$ang = deg2rad($regs[1]); $ang = \deg2rad($regs[1]);
$x = $regs[2]; $x = $regs[2];
$y = $regs[3]; $y = $regs[3];
$a = cos($ang); $a = cos($ang);
@ -1737,8 +1737,8 @@ class TCPDF_STATIC {
$d = $a; $d = $a;
$e = ($x * (1 - $a)) - ($y * $c); $e = ($x * (1 - $a)) - ($y * $c);
$f = ($y * (1 - $d)) - ($x * $b); $f = ($y * (1 - $d)) - ($x * $b);
} elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { } elseif (\preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
$ang = deg2rad($regs[1]); $ang = \deg2rad($regs[1]);
$a = cos($ang); $a = cos($ang);
$b = sin($ang); $b = sin($ang);
$c = -$b; $c = -$b;
@ -1749,14 +1749,14 @@ class TCPDF_STATIC {
break; break;
} }
case 'skewX': { case 'skewX': {
if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { if (\preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
$c = tan(deg2rad($regs[1])); $c = tan(\deg2rad($regs[1]));
} }
break; break;
} }
case 'skewY': { case 'skewY': {
if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { if (\preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
$b = tan(deg2rad($regs[1])); $b = tan(\deg2rad($regs[1]));
} }
break; break;
} }
@ -1780,8 +1780,8 @@ class TCPDF_STATIC {
*/ */
public static function getVectorsAngle($x1, $y1, $x2, $y2) { public static function getVectorsAngle($x1, $y1, $x2, $y2) {
$dprod = ($x1 * $x2) + ($y1 * $y2); $dprod = ($x1 * $x2) + ($y1 * $y2);
$dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); $dist1 = \sqrt(($x1 * $x1) + ($y1 * $y1));
$dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); $dist2 = \sqrt(($x2 * $x2) + ($y2 * $y2));
$angle = acos($dprod / ($dist1 * $dist2)); $angle = acos($dprod / ($dist1 * $dist2));
if (is_nan($angle)) { if (is_nan($angle)) {
$angle = M_PI; $angle = M_PI;
@ -1794,12 +1794,12 @@ class TCPDF_STATIC {
/** /**
* Split string by a regular expression. * Split string by a regular expression.
* This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850 * This is a wrapper for the \preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
* @param string $pattern The regular expression pattern to search for without the modifiers, as a string. * @param string $pattern The regular expression pattern to search for without the modifiers, as a string.
* @param string $modifiers The modifiers part of the pattern, * @param string $modifiers The modifiers part of the pattern,
* @param string $subject The input string. * @param string $subject The input string.
* @param int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter. * @param int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.
* @param int $flags The flags as specified on the preg_split PHP function. * @param int $flags The flags as specified on the \preg_split PHP function.
* @return array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier * @return array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
* @author Nicola Asuni * @author Nicola Asuni
* @since 6.0.023 * @since 6.0.023
@ -1810,18 +1810,18 @@ class TCPDF_STATIC {
$limit = $limit === null ? -1 : $limit; $limit = $limit === null ? -1 : $limit;
$flags = $flags === null ? 0 : $flags; $flags = $flags === null ? 0 : $flags;
// the bug only happens on PHP 5.2 when using the u modifier // the bug only happens on PHP 5.2 when using the u modifier
if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) { if ((\strpos($modifiers, 'u') === FALSE) OR (count(\preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
return preg_split($pattern.$modifiers, $subject, $limit, $flags); return \preg_split($pattern.$modifiers, $subject, $limit, $flags);
} }
// preg_split is bugged - try alternative solution // \preg_split is bugged - try alternative solution
$ret = array(); $ret = [];
while (($nl = strpos($subject, "\n")) !== FALSE) { while (($nl = \strpos($subject, "\n")) !== FALSE) {
$ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags)); $ret = array_merge($ret, \preg_split($pattern.$modifiers, \substr($subject, 0, $nl), $limit, $flags));
$ret[] = "\n"; $ret[] = "\n";
$subject = substr($subject, ($nl + 1)); $subject = \substr($subject, ($nl + 1));
} }
if (strlen($subject) > 0) { if (\strlen($subject) > 0) {
$ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags)); $ret = array_merge($ret, \preg_split($pattern.$modifiers, $subject, $limit, $flags));
} }
return $ret; return $ret;
} }
@ -1834,7 +1834,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function fopenLocal($filename, $mode) { public static function fopenLocal($filename, $mode) {
if (strpos($filename, '://') === false) { if (\strpos($filename, '://') === false) {
$filename = 'file://'.$filename; $filename = 'file://'.$filename;
} elseif (stream_is_local($filename) !== true) { } elseif (stream_is_local($filename) !== true) {
return false; return false;
@ -1885,7 +1885,7 @@ class TCPDF_STATIC {
public static function encodeUrlQuery($url) { public static function encodeUrlQuery($url) {
$urlData = parse_url($url); $urlData = parse_url($url);
if (isset($urlData['query']) && $urlData['query']) { if (isset($urlData['query']) && $urlData['query']) {
$urlQueryData = array(); $urlQueryData = [];
parse_str(urldecode($urlData['query']), $urlQueryData); parse_str(urldecode($urlData['query']), $urlQueryData);
$updatedUrl = $urlData['scheme'] . '://' . $urlData['host'] . $urlData['path'] . '?' . http_build_query($urlQueryData); $updatedUrl = $urlData['scheme'] . '://' . $urlData['host'] . $urlData['path'] . '?' . http_build_query($urlQueryData);
} else { } else {
@ -1903,10 +1903,10 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function file_exists($filename) { public static function file_exists($filename) {
if (preg_match('|^https?://|', $filename) == 1) { if (\preg_match('|^https?://|', $filename) == 1) {
return self::url_exists($filename); return self::url_exists($filename);
} }
if (strpos($filename, '://')) { if (\strpos($filename, '://')) {
return false; // only support http and https wrappers for security reasons return false; // only support http and https wrappers for security reasons
} }
return @file_exists($filename); return @file_exists($filename);
@ -1924,40 +1924,40 @@ class TCPDF_STATIC {
public static function fileGetContents($file) { public static function fileGetContents($file) {
$alt = array($file); $alt = array($file);
// //
if ((strlen($file) > 1) if ((\strlen($file) > 1)
&& ($file[0] === '/') && ($file[0] === '/')
&& ($file[1] !== '/') && ($file[1] !== '/')
&& !empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['DOCUMENT_ROOT'])
&& ($_SERVER['DOCUMENT_ROOT'] !== '/') && ($_SERVER['DOCUMENT_ROOT'] !== '/')
) { ) {
$findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']); $findroot = \strpos($file, $_SERVER['DOCUMENT_ROOT']);
if (($findroot === false) || ($findroot > 1)) { if (($findroot === false) || ($findroot > 1)) {
$alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file)); $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file));
} }
} }
// //
$protocol = 'http'; $protocol = 'http';
if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { if (!empty($_SERVER['HTTPS']) && (\strtolower($_SERVER['HTTPS']) != 'off')) {
$protocol .= 's'; $protocol .= 's';
} }
// //
$url = $file; $url = $file;
if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) { if (\preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) {
$url = $protocol.':'.str_replace(' ', '%20', $url); $url = $protocol.':'.str_replace(' ', '%20', $url);
} }
$url = htmlspecialchars_decode($url); $url = htmlspecialchars_decode($url);
$alt[] = $url; $alt[] = $url;
// //
if (preg_match('%^(https?)://%', $url) if (\preg_match('%^(https?)://%', $url)
&& empty($_SERVER['HTTP_HOST']) && empty($_SERVER['HTTP_HOST'])
&& empty($_SERVER['DOCUMENT_ROOT']) && empty($_SERVER['DOCUMENT_ROOT'])
) { ) {
$urldata = parse_url($url); $urldata = parse_url($url);
if (empty($urldata['query'])) { if (empty($urldata['query'])) {
$host = $protocol.'://'.$_SERVER['HTTP_HOST']; $host = $protocol.'://'.$_SERVER['HTTP_HOST'];
if (strpos($url, $host) === 0) { if (\strpos($url, $host) === 0) {
// convert URL to full server path // convert URL to full server path
$tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url); $tmp = \str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url);
$alt[] = htmlspecialchars_decode(urldecode($tmp)); $alt[] = htmlspecialchars_decode(urldecode($tmp));
} }
} }
@ -1982,7 +1982,7 @@ class TCPDF_STATIC {
} }
// try to use CURL for URLs // try to use CURL for URLs
if (!ini_get('allow_url_fopen') if (!ini_get('allow_url_fopen')
&& function_exists('curl_init') && \function_exists('curl_init')
&& preg_match('%^(https?|ftp)://%', $path) && preg_match('%^(https?|ftp)://%', $path)
) { ) {
// try to get remote file data using cURL // try to get remote file data using cURL
@ -2023,7 +2023,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _getULONG($str, $offset) { public static function _getULONG($str, $offset) {
$v = unpack('Ni', substr($str, $offset, 4)); $v = unpack('Ni', \substr($str, $offset, 4));
return $v['i']; return $v['i'];
} }
@ -2037,7 +2037,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _getUSHORT($str, $offset) { public static function _getUSHORT($str, $offset) {
$v = unpack('ni', substr($str, $offset, 2)); $v = unpack('ni', \substr($str, $offset, 2));
return $v['i']; return $v['i'];
} }
@ -2051,7 +2051,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _getSHORT($str, $offset) { public static function _getSHORT($str, $offset) {
$v = unpack('si', substr($str, $offset, 2)); $v = unpack('si', \substr($str, $offset, 2));
return $v['i']; return $v['i'];
} }
@ -2100,7 +2100,7 @@ class TCPDF_STATIC {
$m = self::_getFWORD($str, $offset); $m = self::_getFWORD($str, $offset);
// fraction // fraction
$f = self::_getUSHORT($str, ($offset + 2)); $f = self::_getUSHORT($str, ($offset + 2));
$v = floatval(''.$m.'.'.$f.''); $v = \floatval(''.$m.'.'.$f.'');
return $v; return $v;
} }
@ -2114,7 +2114,7 @@ class TCPDF_STATIC {
* @public static * @public static
*/ */
public static function _getBYTE($str, $offset) { public static function _getBYTE($str, $offset) {
$v = unpack('Ci', substr($str, $offset, 1)); $v = unpack('Ci', \substr($str, $offset, 1));
return $v['i']; return $v['i'];
} }
/** /**
@ -2132,7 +2132,7 @@ class TCPDF_STATIC {
if ($data === false) { if ($data === false) {
return false; return false;
} }
$rest = ($length - strlen($data)); $rest = ($length - \strlen($data));
if (($rest > 0) && !feof($handle)) { if (($rest > 0) && !feof($handle)) {
$data .= self::rfread($handle, $rest); $data .= self::rfread($handle, $rest);
} }
@ -2154,7 +2154,7 @@ class TCPDF_STATIC {
* Array of page formats * Array of page formats
* measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4) * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)
* @public static * @public static
* *
* @var array<string,float[]> * @var array<string,float[]>
*/ */
public static $page_formats = array( public static $page_formats = array(
@ -2538,12 +2538,12 @@ class TCPDF_STATIC {
* @since 5.0.010 (2010-05-17) * @since 5.0.010 (2010-05-17)
* @public static * @public static
*/ */
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) { public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=[]) {
if (!isset($pagedim[$page])) { if (!isset($pagedim[$page])) {
// initialize array // initialize array
$pagedim[$page] = array(); $pagedim[$page] = [];
} }
if (!in_array($type, self::$pageboxes)) { if (!\in_array($type, self::$pageboxes)) {
return; return;
} }
if ($points) { if ($points) {