diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 49472163a..80638d1f9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,87 @@ +#################################### +# V1.5.1 +#################################### + +## Added Features: +- Core: + - #208: "Catalog Mode" option added by which user can view room details but not abe to create booking + + +## Improvements: +- Back Office: + - #206: Removed Other Modules setting from admin Hotel Reservation System -> Settings + - #200: Removed shipping option from car rule condition. + - #199: Removed "Display suppliers and manufacturers" and "Display best sellers" options from Admin Preferences controller + - #193: Removed Payment Modules setting from admin Hotel Reservation System -> Settings + - #189: Moved hotel selection from configuration tab to information tab + - #179: Added hotel column in room type feature pricing list + - #177: Removed multishop option + - #149: Removed carrier column from Booking Carts Controller + - #183: Added hotel name along with room name when adding filter of room type for cart rule + - #204, #196, #182: Text Changes + - #110, #111: Code Optimization + +- Core: + - #223: getHotelCartBookingData() : function multiplication optimized + - #225: HotelRoomTypeFeaturePricing.php optimized (Removed unused variables, removed static values assigned) + - #218: Added hotel name column in order confirmation mail and invoice. + - #210: CMS page Delivery is not valid for hotel industry. So changed it to Policies page + - #205: Prevent deleting profile which is used by at least one employee + - #214: blockcart module :: Removed unused hooks displayLeftColumn and displayrightColumn + - #180: license file name changed from LICENSES to LICENSE + - #181: Readme file improvements with more information and links + - #221: dataforfrontsearch() function now calculate and provide "feature_price_diff" value in response + - #175: Changed QloApps versioning system (Ex: X.X.X.X) + - #175: Updated module compatibility check with QloApps version + - #215: "hotelreservationsystem.php" code optimization in hook "actionValidateOrder" + - #117, #118, #119, #120, #121, #122, #134, #137, #138, #139: Changes for PHP7 compatibility + - #178: Text Changes + - #198, #226: Multiple hooks are added in the different QloApps core files + - #217: `auto_generated` column in `address` table added to track address creation source + - #207: New order states 'Partial payment accepted' and 'Awaiting partial payment' added for the partial payment + +- Front Office: + - #222: Disabled mobile keyboard pop up when using date-picker in home search + - #208: Room type listing on search result page moved to different template "room_type_listing.tpl" + - #185: Replaced star rating plugin with jquery Raty in Product Comments module + - #156: "product.js" code multiplication optimized + - #215: "ajax-cart.js" add validation + - #125, #127, #141, #142: Changes for PHP7 compatibility + - #187: Display voucher name along with voucher code on order page + + +## Bug Fixed: +- Back Office: + - #211: Errors on cart rule page when add room type, which is not assigned to hotel, selected in room type condition + - #197: wrong theme information is displayed at Preferences -> Themes admin controller + - #195: Filter by position in the render lists of admin controllers + - #194: Entering wrong discount while Group creation, page redirects to list page + - #192: Using filter in customer Group list, page redirects to previous list + - #189: Room Type associations with its hotel parent category + - #176: Birthday input field width in Helper Form + - #173: Undefined varaible issue Manage Order Refund Request Controller + - #171: Multiple request on single click in Helper List + - #160: "Access Denied" issue when an employee other than super admin create a new room. + - #168: Room number not updating after room reallocation and swap + - #162: Additional facility price changes for room type after saving + - #147: Creating order status without entering "status name", page redirects to blank page + - #148: Creating order refund status without entering "status name", page redirects to list page + - #229: Resolved undefined variable error in Manage Order Refund Request Controller + +- Front Office: + - #212: Design issue of select in the ADDITIONAL FACILITIES if text exceeds from block in the product detail page + - #209: Errors on the search result page: If new group is created and only this group is assigned to the customer + - #203: Guest is unable to submit Refund Request again after entering invalid Refund Reason once + - #158: Hotel selection in search panel for mobile devices + - #169: Wrong price displayed when booking from 1 march to 30 march + - #151: Room search check-in && check-out don't change when friendly URL is disabled. + +- Core: + - #186: Links in mail for my-account, guest tracking and my orders pages are now localized to customer language. + - #109: updated invalid varaible "pshone_mobile" to "phone_mobile" + - #202: "global.css" added missing class for aligning images left and right in discription + + #################################### # V1.5.0 #################################### diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..725ca5195 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | ------------------ | +| 1.5.x | :white_check_mark: | +| 1.4.x | :white_check_mark: | +| < 1.4.0 | :x: | + +## Reporting a Vulnerability + +Please report (suspected) security vulnerabilities to support@qloapps.com. You will receive a response from us within 48 hours. If the issue is confirmed, we will release a patch as soon as possible depending on complexity. diff --git a/admin/ajax.php b/admin/ajax.php index be2c91bc4..2506e809d 100644 --- a/admin/ajax.php +++ b/admin/ajax.php @@ -72,12 +72,12 @@ if (Tools::isSubmit('ajaxProductPackItems')) { if (Tools::isSubmit('getChildrenCategories') && Tools::isSubmit('id_category_parent')) { $children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id, null, Tools::getValue('use_shop_context')); - die(Tools::jsonEncode($children_categories)); + die(json_encode($children_categories)); } if (Tools::isSubmit('getNotifications')) { $notification = new Notification; - die(Tools::jsonEncode($notification->getLastElements())); + die(json_encode($notification->getLastElements())); } if (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEmployeeType')) { @@ -111,7 +111,7 @@ if (Tools::isSubmit('getParentCategoriesId') && $id_category = Tools::getValue(' $output[] = $result; } - die(Tools::jsonEncode($output)); + die(json_encode($output)); } if (Tools::isSubmit('getZones')) { @@ -121,7 +121,7 @@ if (Tools::isSubmit('getZones')) { } $html .= ''; $array = array('hasError' => false, 'errors' => '', 'data' => $html); - die(Tools::jsonEncode($array)); + die(json_encode($array)); } if (Tools::isSubmit('getEmailHTML') && $email = Tools::getValue('email')) { diff --git a/admin/ajax_products_list.php b/admin/ajax_products_list.php index 137020a37..03a5f4999 100644 --- a/admin/ajax_products_list.php +++ b/admin/ajax_products_list.php @@ -137,7 +137,7 @@ if ($items && ($excludeIds || strpos($_SERVER['HTTP_REFERER'], 'AdminScenes') != } } $results = array_values($results); - echo Tools::jsonEncode($results); + echo json_encode($results); } else { - Tools::jsonEncode(new stdClass); + json_encode(new stdClass); } diff --git a/admin/functions.php b/admin/functions.php index 15c397049..ae72f6340 100644 --- a/admin/functions.php +++ b/admin/functions.php @@ -524,8 +524,8 @@ function runAdminTab($tab, $ajax_mode = false) } // we can display the correct url - // die(Tools::jsonEncode(array(Translate::getAdminTranslation('Invalid security token'),$url))); - die(Tools::jsonEncode(Translate::getAdminTranslation('Invalid security token'))); + // die(json_encode(array(Translate::getAdminTranslation('Invalid security token'),$url))); + die(json_encode(Translate::getAdminTranslation('Invalid security token'))); } else { // If this is an XSS attempt, then we should only display a simple, secure page if (ob_get_level() && ob_get_length() > 0) { diff --git a/classes/Blowfish.php b/classes/Blowfish.php index d052820c2..a4aeba50a 100644 --- a/classes/Blowfish.php +++ b/classes/Blowfish.php @@ -377,7 +377,7 @@ class Crypt_Blowfish for ($i = 0; $i < 18; $i++) { $data = 0; for ($j = 4; $j > 0; $j--) { - $data = $data << 8 | ord($key{$k}); + $data = $data << 8 | ord($key[$k]); $k = ($k + 1) % $len; } $this->_P[$i] ^= $data; diff --git a/classes/Cart.php b/classes/Cart.php index 7d380889b..bceb9ac72 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2632,6 +2632,9 @@ class CartCore extends ObjectModel */ public static function desintifier($int, $delimiter = ',') { + if (!$int) + return; + $delimiter_len = $int[0]; $int = strrev(substr($int, 1)); $elm = explode(str_repeat('0', $delimiter_len + 1), $int); @@ -4317,7 +4320,7 @@ class CartCore extends ObjectModel $postData = trim(file_get_contents('php://input')); libxml_use_internal_errors(true); $xml = simplexml_load_string(utf8_decode($postData)); - $cartData = Tools::jsonDecode(Tools::jsonEncode($xml, true)); + $cartData = json_decode(json_encode($xml, true)); $this->id_address_delivery = $cartData->cart->id_address; $this->id_address_invoice = $cartData->cart->id_address; @@ -4344,7 +4347,7 @@ class CartCore extends ObjectModel $postData = trim(file_get_contents('php://input')); libxml_use_internal_errors(true); $xml = simplexml_load_string(utf8_decode($postData)); - $cartData = Tools::jsonDecode(Tools::jsonEncode($xml, true)); + $cartData = json_decode(json_encode($xml, true)); $this->id_address_delivery = $cartData->cart->id_address; $this->id_address_invoice = $cartData->cart->id_address; @@ -4384,14 +4387,14 @@ class CartCore extends ObjectModel $extraDemands = null; foreach ($bookingRows as $booking) { - $booking = Tools::jsonDecode(Tools::jsonEncode($booking, true), true); + $booking = json_decode(json_encode($booking, true), true); if (isset($booking['extra_demands']['extra_demand'])) { $extraDemands = $booking['extra_demands']['extra_demand']; if (isset($extraDemands['id_global_demand'])) { $extraDemands = array($extraDemands); } - // $extraDemands = Tools::jsonDecode($extraDemands, true); - $extraDemands = Tools::jsonEncode($extraDemands); + // $extraDemands = json_decode($extraDemands, true); + $extraDemands = json_encode($extraDemands); } // get room booking info diff --git a/classes/CartRule.php b/classes/CartRule.php index d93f70b8b..88670b0de 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -1220,7 +1220,7 @@ class CartRuleCore extends ObjectModel if ($type == 'shop') { $shops = Context::getContext()->employee->getAssociatedShops(); if (count($shops)) { - $shop_list = ' AND t.id_shop IN ('.implode(array_map('intval', $shops), ',').') '; + $shop_list = ' AND t.id_shop IN ('.implode(',', array_map('intval', $shops)).') '; } } diff --git a/classes/ConfigurationTest.php b/classes/ConfigurationTest.php index 6981c6c76..73296d5a5 100644 --- a/classes/ConfigurationTest.php +++ b/classes/ConfigurationTest.php @@ -94,6 +94,7 @@ class ConfigurationTestCore 'upload_max_filesize' => false, 'max_execution_time' => false, 'fopen' => false, + 'zip' => false, )); } @@ -180,7 +181,7 @@ class ConfigurationTestCore public static function test_magicquotes() { - return !get_magic_quotes_gpc(); + return function_exists('get_magic_quotes_gpc') ? !get_magic_quotes_gpc() : true; } public static function test_upload() @@ -215,6 +216,12 @@ class ConfigurationTestCore return false; } + public static function test_zip() + { + return extension_loaded('zip'); + } + + public static function test_fopen() { return ini_get('allow_url_fopen'); diff --git a/classes/Connection.php b/classes/Connection.php index d44729a10..c14ee13fe 100644 --- a/classes/Connection.php +++ b/classes/Connection.php @@ -136,7 +136,7 @@ class ConnectionCore extends ObjectModel '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).' ORDER BY `date_add` DESC'; $result = Db::getInstance()->getRow($sql, false); - if (!$result['id_guest'] && (int)$cookie->id_guest) { + if (!isset($result['id_guest']) && (int)$cookie->id_guest) { // The old connections details are removed from the database in order to spare some memory Connection::cleanConnectionsPages(); diff --git a/classes/Cookie.php b/classes/Cookie.php index 6747b0c24..89ee0ef6e 100644 --- a/classes/Cookie.php +++ b/classes/Cookie.php @@ -66,7 +66,7 @@ class CookieCore $this->_standalone = $standalone; $this->_expire = is_null($expire) ? time() + 1728000 : (int)$expire; $this->_path = trim(($this->_standalone ? '' : Context::getContext()->shop->physical_uri).$path, '/\\').'/'; - if ($this->_path{0} != '/') { + if ($this->_path[0] != '/') { $this->_path = '/'.$this->_path; } $this->_path = rawurlencode($this->_path); diff --git a/classes/Language.php b/classes/Language.php index 59f5f2e01..af8e9998a 100644 --- a/classes/Language.php +++ b/classes/Language.php @@ -798,7 +798,7 @@ class LanguageCore extends ObjectModel // If the language pack has not been provided, retrieve it from prestashop.com if (!$lang_pack) { - $lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code)); + $lang_pack = json_decode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code)); } // If a language pack has been found or provided, prefill the language object with the value @@ -914,7 +914,7 @@ class LanguageCore extends ObjectModel if (!$lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='.$version.'&iso_lang='.Tools::strtolower((string)$iso))) { $errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.'); - } elseif (!$lang_pack = Tools::jsonDecode($lang_pack_link)) { + } elseif (!$lang_pack = json_decode($lang_pack_link)) { $errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.'); } elseif (empty($lang_pack->error) && ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.Tools::strtolower($lang_pack->iso_code.'.gzip')))) { if (!@file_put_contents($file, $content)) { diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 76c956718..dff3e5ceb 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -628,7 +628,7 @@ abstract class ObjectModelCore implements Core_Foundation_Database_EntityInterfa $this->clearCache(); // Automatically fill dates - if (array_key_exists('date_upd', $this)) { + if (property_exists($this, 'date_upd')) { $this->date_upd = date('Y-m-d H:i:s'); if (isset($this->update_fields) && is_array($this->update_fields) && count($this->update_fields)) { $this->update_fields['date_upd'] = true; @@ -636,7 +636,7 @@ abstract class ObjectModelCore implements Core_Foundation_Database_EntityInterfa } // Automatically fill dates - if (array_key_exists('date_add', $this) && $this->date_add == null) { + if (property_exists($this, 'date_add') && $this->date_add == null) { $this->date_add = date('Y-m-d H:i:s'); if (isset($this->update_fields) && is_array($this->update_fields) && count($this->update_fields)) { $this->update_fields['date_add'] = true; @@ -818,7 +818,7 @@ abstract class ObjectModelCore implements Core_Foundation_Database_EntityInterfa public function toggleStatus() { // Object must have a variable called 'active' - if (!array_key_exists('active', $this)) { + if (!property_exists($this, 'active')) { throw new PrestaShopException('property "active" is missing in object '.get_class($this)); } @@ -1770,7 +1770,7 @@ abstract class ObjectModelCore implements Core_Foundation_Database_EntityInterfa } foreach ($data as $key => $value) { - if (array_key_exists($key, $this)) { + if (property_exists($this, $key)) { $this->$key = $value; } } diff --git a/classes/Product.php b/classes/Product.php index ca3c683bb..1fff837fe 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -5776,7 +5776,7 @@ class ProductCore extends ObjectModel libxml_use_internal_errors(true); $xml = simplexml_load_string(utf8_decode($postData)); - $roomtypeData = Tools::jsonDecode(Tools::jsonEncode($xml), true); + $roomtypeData = json_decode(json_encode($xml), true); // set room map info for the hotel from request return Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'htl_room_type` (`id_product`, `id_hotel`, `adult`, `children`, `date_add`, `date_upd`) VALUES ('.(int)$this->id.', '.(int) $roomtypeData['room_type']['id_hotel'].', '.(int) $roomtypeData['room_type']['adults'].', '.(int) $roomtypeData['room_type']['children'].', \''.date('Y-m-d h:i:s').'\', \''.date('Y-m-d h:i:s').'\')'); diff --git a/classes/Referrer.php b/classes/Referrer.php index a37ee888c..d6b347669 100644 --- a/classes/Referrer.php +++ b/classes/Referrer.php @@ -236,7 +236,7 @@ class ReferrerCore extends ObjectModel if ($implode) { $sql = 'SELECT COUNT(id_order) AS orders, SUM(total_paid_real / conversion_rate) AS sales FROM '._DB_PREFIX_.'orders - WHERE id_order IN ('.implode($implode, ',').') + WHERE id_order IN ('.implode(',', $implode).') '.Shop::addSqlRestriction(Shop::SHARE_ORDER).' AND valid = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); @@ -349,6 +349,6 @@ class ReferrerCore extends ObjectModel 'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency), ); - die('['.Tools::jsonEncode($json_array).']'); + die('['.json_encode($json_array).']'); } } diff --git a/classes/Tools.php b/classes/Tools.php index 502c4e4a8..de13351b7 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -104,65 +104,7 @@ class ToolsCore } } - if (function_exists('mcrypt_create_iv')) { - $bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM); - - if ($bytes !== false && strlen($bytes) === $length) { - return $bytes; - } - } - - // Else try to get $length bytes of entropy. - // Thanks to Zend - - $result = ''; - $entropy = ''; - $msec_per_round = 400; - $bits_per_round = 2; - $total = $length; - $hash_length = 20; - - while (strlen($result) < $length) { - $bytes = ($total > $hash_length) ? $hash_length : $total; - $total -= $bytes; - - for ($i=1; $i < 3; $i++) { - $t1 = microtime(true); - $seed = mt_rand(); - - for ($j=1; $j < 50; $j++) { - $seed = sha1($seed); - } - - $t2 = microtime(true); - $entropy .= $t1 . $t2; - } - - $div = (int) (($t2 - $t1) * 1000000); - - if ($div <= 0) { - $div = 400; - } - - $rounds = (int) ($msec_per_round * 50 / $div); - $iter = $bytes * (int) (ceil(8 / $bits_per_round)); - - for ($i = 0; $i < $iter; $i ++) { - $t1 = microtime(); - $seed = sha1(mt_rand()); - - for ($j = 0; $j < $rounds; $j++) { - $seed = sha1($seed); - } - - $t2 = microtime(); - $entropy .= $t1 . $t2; - } - - $result .= sha1($entropy, true); - } - - return substr($result, 0, $length); + return false; } public static function strReplaceFirst($search, $replace, $subject, $cur = 0) @@ -1071,7 +1013,7 @@ class ToolsCore echo ' '; } @@ -1827,10 +1769,10 @@ class ToolsCore return Tools::strtoupper(Tools::substr($str, 0, 1)).Tools::substr($str, 1); } - public static function ucwords($str) + public static function ucwords($str, $encoding = 'utf-8') { if (function_exists('mb_convert_case')) { - return mb_convert_case($str, MB_CASE_TITLE); + return mb_convert_case($str, MB_CASE_TITLE, $encoding); } return ucwords(Tools::strtolower($str)); } @@ -2665,19 +2607,15 @@ exit; /** * jsonDecode convert json string to php array / object * - * @param string $json + * @param string $data * @param bool $assoc (since 1.4.2.4) if true, convert to associativ array * @return array */ - public static function jsonDecode($json, $assoc = false) + public static function jsonDecode($data, $assoc = false, $depth = 512, $options = 0 + ) { - if (function_exists('json_decode')) { - return json_decode($json, $assoc); - } else { - include_once(_PS_TOOL_DIR_.'json/json.php'); - $pear_json = new Services_JSON(($assoc) ? SERVICES_JSON_LOOSE_TYPE : 0); - return $pear_json->decode($json); - } + Tools::displayAsDeprecated(); + return json_decode($data, $assoc, $depth, $options); } /** @@ -2686,15 +2624,15 @@ exit; * @param array $data * @return string json */ - public static function jsonEncode($data) + public static function jsonEncode($data, $options = 0, $depth = 512) { - if (function_exists('json_encode')) { - return json_encode($data); - } else { - include_once(_PS_TOOL_DIR_.'json/json.php'); - $pear_json = new Services_JSON(); - return $pear_json->encode($data); + Tools::displayAsDeprecated(); + if (PHP_VERSION_ID < 50500) { /* PHP version < 5.5.0 */ + return json_encode($data, $options); } + + return json_encode($data, $options, $depth); + } /** @@ -2859,14 +2797,9 @@ exit; */ public static function ZipTest($from_file) { - if (class_exists('ZipArchive', false)) { - $zip = new ZipArchive(); - return ($zip->open($from_file, ZIPARCHIVE::CHECKCONS) === true); - } else { - require_once(_PS_ROOT_DIR_.'/tools/pclzip/pclzip.lib.php'); - $zip = new PclZip($from_file); - return ($zip->privCheckFormat() === true); - } + $zip = new ZipArchive(); + + return ($zip->open($from_file, ZipArchive::CHECKCONS) === true); } public static function getSafeModeStatus() @@ -2886,23 +2819,12 @@ exit; if (!file_exists($to_dir)) { mkdir($to_dir, 0777); } - if (class_exists('ZipArchive', false)) { - $zip = new ZipArchive(); - if ($zip->open($from_file) === true && $zip->extractTo($to_dir) && $zip->close()) { - return true; - } - return false; - } else { - require_once(_PS_ROOT_DIR_.'/tools/pclzip/pclzip.lib.php'); - $zip = new PclZip($from_file); - $list = $zip->extract(PCLZIP_OPT_PATH, $to_dir, PCLZIP_OPT_REPLACE_NEWER); - foreach ($list as $file) { - if ($file['status'] != 'ok' && $file['status'] != 'already_a_directory') { - return false; - } - } + $zip = new ZipArchive(); + if ($zip->open($from_file) === true && $zip->extractTo($to_dir) && $zip->close()) { return true; } + + return false; } public static function chmodr($path, $filemode) @@ -3631,8 +3553,6 @@ exit; public static function purifyHTML($html, $uri_unescape = null, $allow_style = false) { - require_once(_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php'); - static $use_html_purifier = null; static $purifier = null; diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 6bc800a5f..650355110 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1803,14 +1803,14 @@ class AdminControllerCore extends Controller } if ($conf = Tools::getValue('conf')) { - $this->context->smarty->assign('conf', $this->json ? Tools::jsonEncode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]); + $this->context->smarty->assign('conf', $this->json ? json_encode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]); } foreach (array('errors', 'warnings', 'informations', 'confirmations') as $type) { if (!is_array($this->$type)) { $this->$type = (array)$this->$type; } - $this->context->smarty->assign($type, $this->json ? Tools::jsonEncode(array_unique($this->$type)) : array_unique($this->$type)); + $this->context->smarty->assign($type, $this->json ? json_encode(array_unique($this->$type)) : array_unique($this->$type)); } if ($this->show_page_header_toolbar && !$this->lite_display) { @@ -1824,7 +1824,7 @@ class AdminControllerCore extends Controller $this->context->smarty->assign( array( - 'page' => $this->json ? Tools::jsonEncode($page) : $page, + 'page' => $this->json ? json_encode($page) : $page, 'header' => $this->context->smarty->fetch($header_tpl), 'footer' => $this->context->smarty->fetch($footer_tpl), ) diff --git a/classes/helper/HelperList.php b/classes/helper/HelperList.php index 0686a9dcf..c6e2dbcbb 100644 --- a/classes/helper/HelperList.php +++ b/classes/helper/HelperList.php @@ -435,7 +435,7 @@ class HelperListCore extends Helper 'token' => $token != null ? $token : $this->token, 'action' => self::$cache_lang['Details'], 'params' => $ajax_params, - 'json_params' => Tools::jsonEncode($ajax_params) + 'json_params' => json_encode($ajax_params) )); return $tpl->fetch(); } diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index 15a2eda93..befe153e7 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -142,8 +142,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate */ public function getContent() { - $invoiceAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true); - $deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true); + $invoiceAddressPatternRules = json_decode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true); + $deliveryAddressPatternRules = json_decode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true); $invoice_address = new Address((int)$this->order->id_address_invoice); $country = new Country((int)$invoice_address->id_country); @@ -444,8 +444,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1; - $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from']; - $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to']; + $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = Tools::displayDate($data_v['date_from']); + $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = Tools::displayDate($data_v['date_to']); $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days; $cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days; diff --git a/classes/pdf/PDFGenerator.php b/classes/pdf/PDFGenerator.php index e16cc3a25..4cd27a6bb 100644 --- a/classes/pdf/PDFGenerator.php +++ b/classes/pdf/PDFGenerator.php @@ -24,7 +24,6 @@ * International Registered Trademark & Property of PrestaShop SA */ -require_once(_PS_TOOL_DIR_.'tcpdf/config/lang/eng.php'); require_once(_PS_TOOL_DIR_.'tcpdf/tcpdf.php'); /** diff --git a/classes/tree/TreeToolbarSearch.php b/classes/tree/TreeToolbarSearch.php index 417023e50..edfb693cf 100644 --- a/classes/tree/TreeToolbarSearch.php +++ b/classes/tree/TreeToolbarSearch.php @@ -76,7 +76,7 @@ class TreeToolbarSearchCore extends TreeToolbarButtonCore implements $html = ''; foreach ($data as $item) { - $html .= Tools::jsonEncode($item).','; + $html .= json_encode($item).','; if (array_key_exists('children', $item) && !empty($item['children'])) { $html .= $this->_renderData($item['children']); } diff --git a/classes/tree/TreeToolbarSearchCategories.php b/classes/tree/TreeToolbarSearchCategories.php index 2a6f93d66..a00f387de 100644 --- a/classes/tree/TreeToolbarSearchCategories.php +++ b/classes/tree/TreeToolbarSearchCategories.php @@ -73,7 +73,7 @@ class TreeToolbarSearchCategoriesCore extends TreeToolbarButtonCore implements $html = ''; foreach ($data as $item) { - $html .= Tools::jsonEncode($item).','; + $html .= json_encode($item).','; if (array_key_exists('children', $item) && !empty($item['children'])) { $html .= $this->_renderData($item['children']); } diff --git a/config/config.inc.php b/config/config.inc.php index d362ffb20..c9b3f60ca 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -132,7 +132,7 @@ define('_PS_PRICE_DISPLAY_PRECISION_', Configuration::get('PS_PRICE_DISPLAY_PREC define('_PS_PRICE_COMPUTE_PRECISION_', _PS_PRICE_DISPLAY_PRECISION_); if (Configuration::get('PS_USE_HTMLPURIFIER')) { - require_once(_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php'); + require_once(_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.auto.php'); } /* Load all languages */ diff --git a/config/defines.inc.php b/config/defines.inc.php index 44ec5711d..899b1a0a8 100644 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -140,7 +140,7 @@ define('_PS_TMP_IMG_DIR_', _PS_IMG_DIR_.'tmp/'); define('_PS_TRANS_PATTERN_', '(.*[^\\\\])'); define('_PS_MIN_TIME_GENERATE_PASSWD_', '360'); if (!defined('_PS_MAGIC_QUOTES_GPC_')) { - define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc()); + define('_PS_MAGIC_QUOTES_GPC_', function_exists('get_magic_quotes_gpc')? @get_magic_quotes_gpc() : false); } define('_CAN_LOAD_FILES_', 1); diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index c57e24b1e..ce37b1743 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -495,7 +495,7 @@ class AdminAddressesControllerCore extends AdminController $customer = Customer::searchByName($email); if (!empty($customer)) { $customer = $customer['0']; - echo Tools::jsonEncode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']))); + echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']))); } } die; diff --git a/controllers/admin/AdminAttributeGeneratorController.php b/controllers/admin/AdminAttributeGeneratorController.php index 7c3a69900..8eac6b357 100644 --- a/controllers/admin/AdminAttributeGeneratorController.php +++ b/controllers/admin/AdminAttributeGeneratorController.php @@ -76,7 +76,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController protected static function createCombinations($list) { if (count($list) <= 1) { - return count($list) ? array_map(create_function('$v', 'return (array($v));'), $list[0]) : $list; + return count($list) ? array_map(function ($v) {return (array($v));}, $list[0]) : $list; } $res = array(); $first = array_pop($list); diff --git a/controllers/admin/AdminAttributesGroupsController.php b/controllers/admin/AdminAttributesGroupsController.php index 19e8c55c0..c47cb31e3 100644 --- a/controllers/admin/AdminAttributesGroupsController.php +++ b/controllers/admin/AdminAttributesGroupsController.php @@ -297,7 +297,7 @@ class AdminAttributesGroupsControllerCore extends AdminController $associations = array(); } - $this->fields_form['shop_associations'] = Tools::jsonEncode($associations); + $this->fields_form['shop_associations'] = json_encode($associations); $this->fields_form['input'][] = array( 'type' => 'color', diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php index e5057a4ec..c00efd707 100644 --- a/controllers/admin/AdminCarrierWizardController.php +++ b/controllers/admin/AdminCarrierWizardController.php @@ -652,7 +652,7 @@ class AdminCarrierWizardControllerCore extends AdminController $return['errors'] = $this->errors; } if (count($this->errors) || $die) { - die(Tools::jsonEncode($return)); + die(json_encode($return)); } } @@ -870,7 +870,7 @@ class AdminCarrierWizardControllerCore extends AdminController $return['id_carrier'] = $carrier->id; } } - die(Tools::jsonEncode($return)); + die(json_encode($return)); } protected function changeGroups($id_carrier, $delete = true) diff --git a/controllers/admin/AdminCartRulesController.php b/controllers/admin/AdminCartRulesController.php index 9dccbb5db..87509df72 100644 --- a/controllers/admin/AdminCartRulesController.php +++ b/controllers/admin/AdminCartRulesController.php @@ -140,7 +140,7 @@ class AdminCartRulesControllerCore extends AdminController } } } - echo Tools::jsonEncode(array('html' => $html, 'next_link' => $next_link)); + echo json_encode(array('html' => $html, 'next_link' => $next_link)); } public function setMedia() @@ -589,7 +589,7 @@ class AdminCartRulesControllerCore extends AdminController ) ORDER BY c.`firstname`, c.`lastname` ASC LIMIT 50'); - die(Tools::jsonEncode($customers)); + die(json_encode($customers)); } // Both product filter (free product and product discount) search for products if (Tools::isSubmit('giftProductFilter') || Tools::isSubmit('reductionProductFilter')) { @@ -599,7 +599,7 @@ class AdminCartRulesControllerCore extends AdminController $products, $this->context->employee->id_profile ); - die(Tools::jsonEncode($products)); + die(json_encode($products)); } } @@ -642,7 +642,7 @@ class AdminCartRulesControllerCore extends AdminController public function ajaxProcessSearchProducts() { $array = $this->searchProducts(Tools::getValue('product_search')); - $this->content = trim(Tools::jsonEncode($array)); + $this->content = trim(json_encode($array)); } public function renderForm() @@ -771,6 +771,6 @@ class AdminCartRulesControllerCore extends AdminController if ($vouchers = CartRule::getCartsRuleByCode(Tools::getValue('q'), (int)$this->context->language->id, true)) { $found = true; } - echo Tools::jsonEncode(array('found' => $found, 'vouchers' => $vouchers)); + echo json_encode(array('found' => $found, 'vouchers' => $vouchers)); } } diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index cea2b24b6..ebd03b7a4 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -403,10 +403,10 @@ class AdminCartsControllerCore extends AdminController $errors[] = Tools::displayError('Invalid combination'); } if (count($errors)) { - die(Tools::jsonEncode($errors)); + die(json_encode($errors)); } if ($this->context->cart->deleteProduct($id_product, $id_product_attribute, (int)Tools::getValue('id_customization'))) { - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } } @@ -520,7 +520,7 @@ class AdminCartsControllerCore extends AdminController } } - echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); + echo json_encode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); } } @@ -541,7 +541,7 @@ class AdminCartsControllerCore extends AdminController $this->context->cart->gift_message = $gift_message; } $this->context->cart->save(); - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } @@ -563,7 +563,7 @@ class AdminCartsControllerCore extends AdminController } elseif (Validate::isLoadedObject($message)) { $message->delete(); } - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } @@ -593,7 +593,7 @@ class AdminCartsControllerCore extends AdminController $result = $this->ajaxReturnVars(); $result['cart_detail_html'] = $cart_dtl_tpl;//tpl is added to the returned array - echo Tools::jsonEncode($result); + echo json_encode($result); } } public function ajaxProcessUpdateLang() @@ -604,7 +604,7 @@ class AdminCartsControllerCore extends AdminController $this->context->cart->id_lang = (int)$lang->id; $this->context->cart->save(); } - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } @@ -623,7 +623,7 @@ class AdminCartsControllerCore extends AdminController $errors[] = Tools::displayError('The order cannot be renewed.'); } else { $this->context->cart = $new_cart['cart']; - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } } @@ -632,7 +632,7 @@ class AdminCartsControllerCore extends AdminController { if ($this->tabAccess['edit'] === '1') { if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule'))) { - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } } @@ -663,7 +663,7 @@ class AdminCartsControllerCore extends AdminController $this->context->cart->addCartRule((int)$cart_rule->id); } - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } @@ -681,14 +681,14 @@ class AdminCartsControllerCore extends AdminController $errors[] = Tools::displayError('Can\'t add the voucher.'); } } - echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); + echo json_encode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); } } public function ajaxProcessUpdateAddress() { if ($this->tabAccess['edit'] === '1') { - echo Tools::jsonEncode(array('addresses' => $this->context->customer->getAddresses((int)$this->context->cart->id_lang))); + echo json_encode(array('addresses' => $this->context->customer->getAddresses((int)$this->context->cart->id_lang))); } } @@ -709,7 +709,7 @@ class AdminCartsControllerCore extends AdminController /*$this->context->cart->id_address_invoice = (int)$address_invoice->id;*/ $this->context->cart->save(); - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } @@ -825,7 +825,7 @@ class AdminCartsControllerCore extends AdminController $to_return = array_merge($this->ajaxReturnVars(), array('found' => false)); } - echo Tools::jsonEncode($to_return); + echo json_encode($to_return); } public function ajaxReturnVars() @@ -879,7 +879,7 @@ class AdminCartsControllerCore extends AdminController public function displayAjaxGetSummary() { - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } public function ajaxProcessUpdateProductPrice() @@ -903,7 +903,7 @@ class AdminCartsControllerCore extends AdminController $specific_price->from = '0000-00-00 00:00:00'; $specific_price->to = '0000-00-00 00:00:00'; $specific_price->add(); - echo Tools::jsonEncode($this->ajaxReturnVars()); + echo json_encode($this->ajaxReturnVars()); } } diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 999f85bf8..4d8d9c922 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -961,14 +961,14 @@ class AdminCategoriesControllerCore extends AdminController public function ajaxProcessStatusCategory() { if (!$id_category = (int)Tools::getValue('id_category')) { - die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status')))); + die(json_encode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status')))); } else { $category = new Category((int)$id_category); if (Validate::isLoadedObject($category)) { $category->active = $category->active == 1 ? 0 : 1; $category->save() ? - die(Tools::jsonEncode(array('success' => true, 'text' => $this->l('The status has been updated successfully')))) : - die(Tools::jsonEncode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status')))); + die(json_encode(array('success' => true, 'text' => $this->l('The status has been updated successfully')))) : + die(json_encode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status')))); } } } diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 53689d797..fa01f8cbc 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -896,7 +896,7 @@ class AdminCustomerThreadsControllerCore extends AdminController } if (Tools::isSubmit('syncImapMail')) { - die(Tools::jsonEncode($this->syncImap())); + die(json_encode($this->syncImap())); } } diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 1721be4c5..3150be406 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1104,7 +1104,7 @@ class AdminCustomersControllerCore extends AdminController $to_return = array('found' => false); } - $this->content = Tools::jsonEncode($to_return); + $this->content = json_encode($to_return); } /** diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php index 00a845e0f..ebb22ce89 100644 --- a/controllers/admin/AdminDashboardController.php +++ b/controllers/admin/AdminDashboardController.php @@ -370,7 +370,7 @@ class AdminDashboardControllerCore extends AdminController 'extra' => (int)Tools::getValue('extra') ); - die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true, true, (int)Tools::getValue('dashboard_use_push')))); + die(json_encode(Hook::exec('dashboardData', $params, $id_module, true, true, (int)Tools::getValue('dashboard_use_push')))); } public function ajaxProcessSetSimulationMode() @@ -437,7 +437,7 @@ class AdminDashboardControllerCore extends AdminController } } } - die(Tools::jsonEncode($return)); + die(json_encode($return)); } public function ajaxProcessSaveDashConfig() @@ -475,6 +475,6 @@ class AdminDashboardControllerCore extends AdminController $return['widget_html'] = $module_obj->$hook($params); } - die(Tools::jsonEncode($return)); + die(json_encode($return)); } } diff --git a/controllers/admin/AdminEmployeesController.php b/controllers/admin/AdminEmployeesController.php index 6453095b7..44ab21028 100644 --- a/controllers/admin/AdminEmployeesController.php +++ b/controllers/admin/AdminEmployeesController.php @@ -673,6 +673,6 @@ class AdminEmployeesControllerCore extends AdminController } } } - die(Tools::jsonEncode($this->tabs_list)); + die(json_encode($this->tabs_list)); } } diff --git a/controllers/admin/AdminGroupsController.php b/controllers/admin/AdminGroupsController.php index 72353abde..6762d8f18 100644 --- a/controllers/admin/AdminGroupsController.php +++ b/controllers/admin/AdminGroupsController.php @@ -451,7 +451,7 @@ class AdminGroupsControllerCore extends AdminController $result['discount'] = $category_reduction; $result['hasError'] = false; } - die(Tools::jsonEncode($result)); + die(json_encode($result)); } /** diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index d576bd55b..77cc49d2d 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -665,7 +665,7 @@ class AdminImportControllerCore extends AdminController $_FILES['file']['filename'] = $filename_prefix.str_replace('\0', '', $_FILES['file']['name']); } - die(Tools::jsonEncode($_FILES)); + die(json_encode($_FILES)); } public function renderView() diff --git a/controllers/admin/AdminInformationController.php b/controllers/admin/AdminInformationController.php index e740a895f..cf96c1f69 100644 --- a/controllers/admin/AdminInformationController.php +++ b/controllers/admin/AdminInformationController.php @@ -169,11 +169,11 @@ class AdminInformationControllerCore extends AdminController $this->file_list = array('missing' => array(), 'updated' => array()); $xml = @simplexml_load_file(_PS_API_URL_.'/xml/md5/'._PS_VERSION_.'.xml'); if (!$xml || !isset($xml->ps_root_dir[0])) { - die(Tools::jsonEncode($this->file_list)); + die(json_encode($this->file_list)); } $this->getListOfUpdatedFiles($xml->ps_root_dir[0]); - die(Tools::jsonEncode($this->file_list)); + die(json_encode($this->file_list)); } public function getListOfUpdatedFiles(SimpleXMLElement $dir, $path = '') diff --git a/controllers/admin/AdminLanguagesController.php b/controllers/admin/AdminLanguagesController.php index 8702fef19..56fca56ad 100644 --- a/controllers/admin/AdminLanguagesController.php +++ b/controllers/admin/AdminLanguagesController.php @@ -543,7 +543,7 @@ class AdminLanguagesControllerCore extends AdminController // Get all iso code available if ($lang_packs = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='.Tools::getValue('ps_version').'&iso_lang='.Tools::strtolower(Tools::getValue('iso_lang')))) { - $result = Tools::jsonDecode($lang_packs); + $result = json_decode($lang_packs); if ($lang_packs !== '' && $result && !isset($result->error)) { $this->status = 'ok'; $this->content = $lang_packs; diff --git a/controllers/admin/AdminLoginController.php b/controllers/admin/AdminLoginController.php index 1172dab94..4daeaadf0 100644 --- a/controllers/admin/AdminLoginController.php +++ b/controllers/admin/AdminLoginController.php @@ -219,14 +219,14 @@ class AdminLoginControllerCore extends AdminController } if (Tools::isSubmit('ajax')) { - die(Tools::jsonEncode(array('hasErrors' => false, 'redirect' => $url))); + die(json_encode(array('hasErrors' => false, 'redirect' => $url))); } else { $this->redirect_after = $url; } } } if (Tools::isSubmit('ajax')) { - die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors))); + die(json_encode(array('hasErrors' => true, 'errors' => $this->errors))); } } @@ -270,19 +270,19 @@ class AdminLoginControllerCore extends AdminController if (!$result) { $this->errors[] = Tools::displayError('An error occurred while attempting to change your password.'); } else { - die(Tools::jsonEncode(array( + die(json_encode(array( 'hasErrors' => false, 'confirm' => $this->l('Your password has been emailed to you.', 'AdminTab', false, false) ))); } } else { - die(Tools::jsonEncode(array( + die(json_encode(array( 'hasErrors' => true, 'errors' => array(Tools::displayError('An error occurred while attempting to change your password.')) ))); } } elseif (Tools::isSubmit('ajax')) { - die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors))); + die(json_encode(array('hasErrors' => true, 'errors' => $this->errors))); } } } diff --git a/controllers/admin/AdminModulesController.php b/controllers/admin/AdminModulesController.php index 395bf377f..655daa744 100644 --- a/controllers/admin/AdminModulesController.php +++ b/controllers/admin/AdminModulesController.php @@ -218,7 +218,7 @@ class AdminModulesControllerCore extends AdminController public function displayAjaxRefreshModuleList() { - echo Tools::jsonEncode(array('status' => $this->status)); + echo json_encode(array('status' => $this->status)); } @@ -1091,7 +1091,7 @@ class AdminModulesControllerCore extends AdminController // Get the list of installed module ans prepare it for ajax call. if (($list = Tools::getValue('installed_modules'))) { - Context::getContext()->smarty->assign('installed_modules', Tools::jsonEncode(explode('|', $list))); + Context::getContext()->smarty->assign('installed_modules', json_encode(explode('|', $list))); } // If redirect parameter is present and module already installed, we redirect on configuration module page @@ -1532,7 +1532,7 @@ class AdminModulesControllerCore extends AdminController } // AutoComplete array - $autocomplete_list .= Tools::jsonEncode(array( + $autocomplete_list .= json_encode(array( 'displayName' => (string)$module->displayName, 'desc' => (string)$module->description, 'name' => (string)$module->name, diff --git a/controllers/admin/AdminModulesPositionsController.php b/controllers/admin/AdminModulesPositionsController.php index be5266f61..cf6f52b82 100644 --- a/controllers/admin/AdminModulesPositionsController.php +++ b/controllers/admin/AdminModulesPositionsController.php @@ -552,7 +552,7 @@ class AdminModulesPositionsControllerCore extends AdminController } } $hookableList['hasError'] = false; - die(Tools::jsonEncode($hookableList)); + die(json_encode($hookableList)); } } @@ -582,7 +582,7 @@ class AdminModulesPositionsControllerCore extends AdminController } } } - die(Tools::jsonEncode($hookableModulesList)); + die(json_encode($hookableModulesList)); } } public function ajaxProcessSaveHook() diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index bac43229c..f54b27a73 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1715,7 +1715,7 @@ class AdminOrdersControllerCore extends AdminController $to_return = array('found' => false); } - $this->content = Tools::jsonEncode($to_return); + $this->content = json_encode($to_return); } public function ajaxProcessSendMailValidateOrder() @@ -1745,11 +1745,11 @@ class AdminOrdersControllerCore extends AdminController true, $cart->id_shop )) { - die(Tools::jsonEncode(array('errors' => false, 'result' => $this->l('The email was sent to your customer.')))); + die(json_encode(array('errors' => false, 'result' => $this->l('The email was sent to your customer.')))); } } } - $this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.'))); + $this->content = json_encode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.'))); } } @@ -1759,7 +1759,7 @@ class AdminOrdersControllerCore extends AdminController $id_order = (int) Tools::getValue('id_order'); $order = new Order($id_order); if (!Validate::isLoadedObject($order)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The order object cannot be loaded.') ))); @@ -1768,7 +1768,7 @@ class AdminOrdersControllerCore extends AdminController $old_cart_rules = Context::getContext()->cart->getCartRules(); if ($order->hasBeenShipped()) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot add products to delivered orders. ') ))); @@ -1782,37 +1782,37 @@ class AdminOrdersControllerCore extends AdminController $curr_date = date('Y-m-d'); /*Validations*/ if ($date_from == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter Check In Date.'), ))); } elseif (!Validate::isDateFormat($date_from)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter a Valid Check In Date.'), ))); } elseif ($date_to == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter Check Out Date.'), ))); } elseif (!Validate::isDateFormat($date_to)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter a valid Check out Date.'), ))); } elseif ($date_from < $curr_date) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check In date should not be date before current date.'), ))); } elseif ($date_to <= $date_from) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check out Date Should be after Check In date.'), ))); } elseif (!Validate::isUnsignedInt($product_informations['product_quantity'])) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter a valid Quantity.'), ))); @@ -1836,19 +1836,19 @@ class AdminOrdersControllerCore extends AdminController $total_available_rooms = $hotel_room_data['stats']['num_avail']; if ($total_available_rooms < $req_rm) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Required number of rooms are not available.'), ))); } } else { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Some error occured Please try again.'), ))); } } else { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Some error occured Please try again.'), ))); @@ -1865,7 +1865,7 @@ class AdminOrdersControllerCore extends AdminController $idProduct = $product_informations['product_id']; $product = new Product($idProduct, false, $order->id_lang); if (!Validate::isLoadedObject($product)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The product object cannot be loaded.') ))); @@ -1874,7 +1874,7 @@ class AdminOrdersControllerCore extends AdminController if (isset($product_informations['product_attribute_id']) && $product_informations['product_attribute_id']) { $combination = new Combination($product_informations['product_attribute_id']); if (!Validate::isLoadedObject($combination)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The combination object cannot be loaded.') ))); @@ -1986,9 +1986,9 @@ class AdminOrdersControllerCore extends AdminController if ($update_quantity < 0) { // If product has attribute, minimal quantity is set with minimal quantity of attribute $minimal_quantity = ($product_informations['product_attribute_id']) ? Attribute::getAttributeMinimalQty($product_informations['product_attribute_id']) : $product->minimal_quantity; - die(Tools::jsonEncode(array('error' => sprintf(Tools::displayError('You must add %d minimum quantity', false), $minimal_quantity)))); + die(json_encode(array('error' => sprintf(Tools::displayError('You must add %d minimum quantity', false), $minimal_quantity)))); } elseif (!$update_quantity) { - die(Tools::jsonEncode(array('error' => Tools::displayError('You already have the maximum quantity available for this product.', false)))); + die(json_encode(array('error' => Tools::displayError('You already have the maximum quantity available for this product.', false)))); } // If order is valid, we can create a new invoice or edit an existing invoice @@ -2264,7 +2264,7 @@ class AdminOrdersControllerCore extends AdminController } } - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => true, //'view' => $this->createTemplate('_product_line.tpl')->fetch(), 'can_edit' => $this->tabAccess['add'], @@ -2290,7 +2290,7 @@ class AdminOrdersControllerCore extends AdminController { // $order_detail = new OrderDetail(Tools::getValue('id_order_detail')); // if (!Validate::isLoadedObject($order_detail)) - // die(Tools::jsonEncode(array( + // die(json_encode(array( // 'result' => false, // 'error' => Tools::displayError('The OrderDetail object cannot be loaded.') // ))); @@ -2298,7 +2298,7 @@ class AdminOrdersControllerCore extends AdminController $id_product = Tools::getValue('id_product'); $product = new Product($id_product); if (!Validate::isLoadedObject($product)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The product object cannot be loaded.') ))); @@ -2306,13 +2306,13 @@ class AdminOrdersControllerCore extends AdminController $address = new Address(Tools::getValue('id_address')); if (!Validate::isLoadedObject($address)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The address object cannot be loaded.') ))); } - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => true, 'product' => $product, 'tax_rate' => $product->getTaxesRate($address), @@ -2354,47 +2354,47 @@ class AdminOrdersControllerCore extends AdminController $qty_diff = $product_quantity - $old_product_quantity; /*By webkul to validate fields before deleting the cart and order data form the tables*/ if ($id_hotel == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Hotel Id is mising.'), ))); } elseif ($id_room == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Room Id is missing.'), ))); } elseif ($new_date_from == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter Check In Date.'), ))); } elseif (!Validate::isDateFormat($new_date_from)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter a Valid Check In Date.'), ))); } elseif ($new_date_to == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter Check Out Date.'), ))); } elseif (!Validate::isDateFormat($new_date_to)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Please Enter a valid Check out Date.'), ))); } elseif ($new_date_from < $curr_date) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check In date should not be after current date.'), ))); } elseif ($new_date_to <= $new_date_from) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check out Date Should be after Check In date.'), ))); } elseif (!Validate::isUnsignedInt($product_quantity)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Invalid quantity.'), ))); @@ -2402,7 +2402,7 @@ class AdminOrdersControllerCore extends AdminController $rooms_booked = $obj_booking_detail->getRoomBookinInformationForDateRangeByOrder($id_room, $old_date_from, $old_date_to, $new_date_from, $new_date_to); if ($rooms_booked) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('This Room Unavailable For Selected Duration.'), ))); @@ -2580,7 +2580,7 @@ class AdminOrdersControllerCore extends AdminController )); if (!$res) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => $res, 'error' => Tools::displayError('An error occurred while editing the product line.') ))); @@ -2597,7 +2597,7 @@ class AdminOrdersControllerCore extends AdminController $this->sendChangedNotification($order); - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => $res, 'view' => $view, 'can_edit' => $this->tabAccess['add'], @@ -2627,32 +2627,32 @@ class AdminOrdersControllerCore extends AdminController $product_quantity = (int) $obj_booking_detail->getNumberOfDays($date_from, $date_to); /*By webkul to validate fields before deleting the cart and order data form the tables*/ if ($id_hotel == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Hotel Id is mising.'), ))); } elseif ($id_room == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Room Id is missing.'), ))); } elseif ($date_from == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check In Date is missing.'), ))); } elseif ($date_to == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check Out Date is missing.'), ))); } elseif ($date_to == '') { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Check Out Date is missing.'), ))); } elseif (!Validate::isUnsignedInt($product_quantity)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Invalid quantity.'), ))); @@ -2757,7 +2757,7 @@ class AdminOrdersControllerCore extends AdminController } if (!$res) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => $res, 'error' => Tools::displayError('An error occurred while attempting to delete the product line.') ))); @@ -2795,7 +2795,7 @@ class AdminOrdersControllerCore extends AdminController $this->sendChangedNotification($order); - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => $res, 'order' => $order, 'invoices' => $invoice_array, @@ -2807,28 +2807,28 @@ class AdminOrdersControllerCore extends AdminController protected function doEditProductValidation(OrderDetail $order_detail, Order $order, OrderInvoice $order_invoice = null) { if (!Validate::isLoadedObject($order_detail)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The Order Detail object could not be loaded.') ))); } if (!empty($order_invoice) && !Validate::isLoadedObject($order_invoice)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The invoice object cannot be loaded.') ))); } if (!Validate::isLoadedObject($order)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The order object cannot be loaded.') ))); } if ($order_detail->id_order != $order->id) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot edit the order detail for this order.') ))); @@ -2836,14 +2836,14 @@ class AdminOrdersControllerCore extends AdminController // We can't edit a delivered order if ($order->hasBeenDelivered()) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot edit a delivered order.') ))); } if (!empty($order_invoice) && $order_invoice->id_order != Tools::getValue('id_order')) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot use this invoice for the order') ))); @@ -2854,21 +2854,21 @@ class AdminOrdersControllerCore extends AdminController $product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl')); if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Invalid price') ))); } //commented by webkul here quantity is gap between booking days which is calulated and validated in ajaxProcessEditProductOnOrder(); /*if (!is_array(Tools::getValue('product_quantity')) && !Validate::isUnsignedInt(Tools::getValue('product_quantity'))) - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Invalid quantity') ))); elseif (is_array(Tools::getValue('product_quantity'))) foreach (Tools::getValue('product_quantity') as $qty) if (!Validate::isUnsignedInt($qty)) - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('Invalid quantity') )));*/ @@ -2877,21 +2877,21 @@ class AdminOrdersControllerCore extends AdminController protected function doDeleteProductLineValidation(OrderDetail $order_detail, Order $order) { if (!Validate::isLoadedObject($order_detail)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The Order Detail object could not be loaded.') ))); } if (!Validate::isLoadedObject($order)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The order object cannot be loaded.') ))); } if ($order_detail->id_order != $order->id) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot delete the order detail.') ))); @@ -2899,7 +2899,7 @@ class AdminOrdersControllerCore extends AdminController // We can't edit a delivered order if ($order->hasBeenDelivered()) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('You cannot edit a delivered order.') ))); @@ -2916,13 +2916,13 @@ class AdminOrdersControllerCore extends AdminController $StockAvailable = StockAvailable::getQuantityAvailableByProduct($order_detail->product_id, $order_detail->product_attribute_id, $order_detail->id_shop); $product = new Product($order_detail->product_id, true, null, $order_detail->id_shop); if (!Validate::isLoadedObject($product)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('The Product object could not be loaded.') ))); } else { if (($StockAvailable < $add_quantity) && (!$product->isAvailableWhenOutOfStock((int)$product->out_of_stock))) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => false, 'error' => Tools::displayError('This product is no longer in stock with those attributes ') ))); @@ -3074,7 +3074,7 @@ class AdminOrdersControllerCore extends AdminController $authorized_modules = array(); if (!Validate::isLoadedObject($customer) || !is_array($modules)) { - die(Tools::jsonEncode(array('result' => false))); + die(json_encode(array('result' => false))); } foreach ($modules as $module) { @@ -3093,7 +3093,7 @@ class AdminOrdersControllerCore extends AdminController 'payment_modules' => $payment_modules, )); - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => true, 'view' => $this->createTemplate('_select_payment.tpl')->fetch(), ))); @@ -3128,7 +3128,7 @@ class AdminOrdersControllerCore extends AdminController $result['status'] = 'failed'; } - die(Tools::jsonEncode($result)); + die(json_encode($result)); } // To show rooms extra demands in the modal box in order details view page @@ -3238,8 +3238,8 @@ class AdminOrdersControllerCore extends AdminController if ($idCartBooking = Tools::getValue('id_cart_booking')) { if (Validate::isLoadedObject($objCartbookingCata = new HotelCartBookingData($idCartBooking))) { $roomDemands = Tools::getValue('room_demands'); - $roomDemands = Tools::jsonDecode($roomDemands, true); - $roomDemands = Tools::jsonEncode($roomDemands); + $roomDemands = json_decode($roomDemands, true); + $roomDemands = json_encode($roomDemands); $objCartbookingCata->extra_demands = $roomDemands; if ($objCartbookingCata->save()) { die('1'); @@ -3255,7 +3255,7 @@ class AdminOrdersControllerCore extends AdminController if ($idHtlBooking = Tools::getValue('id_htl_booking')) { if (Validate::isLoadedObject($objBookingDetail = new HotelBookingDetail($idHtlBooking))) { $roomDemands = Tools::getValue('room_demands'); - if ($roomDemands = Tools::jsonDecode($roomDemands, true)) { + if ($roomDemands = json_decode($roomDemands, true)) { $order = new Order($objBookingDetail->id_order); $vatAddress = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $idLang = (int)$order->id_lang; diff --git a/controllers/admin/AdminPerformanceController.php b/controllers/admin/AdminPerformanceController.php index 5f2e4f9b7..3e5976b34 100644 --- a/controllers/admin/AdminPerformanceController.php +++ b/controllers/admin/AdminPerformanceController.php @@ -1014,7 +1014,7 @@ class AdminPerformanceControllerCore extends AdminController $res = @memcache_get_server_status($memcache, $host, $port); } } - die(Tools::jsonEncode(array($res))); + die(json_encode(array($res))); } } die; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 35879aea7..de358ef20 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -600,7 +600,7 @@ class AdminProductsControllerCore extends AdminController public function ajaxProcessAddAttachment() { if ($this->tabAccess['edit'] === '0') { - return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission')))); + return die(json_encode(array('error' => $this->l('You do not have the right permission')))); } if (isset($_FILES['attachment_file'])) { if ((int)$_FILES['attachment_file']['error'] === 1) { @@ -720,7 +720,7 @@ class AdminProductsControllerCore extends AdminController } } - die(Tools::jsonEncode($_FILES)); + die(json_encode($_FILES)); } } @@ -1296,7 +1296,7 @@ class AdminProductsControllerCore extends AdminController ); } - die(Tools::jsonEncode($json)); + die(json_encode($json)); } public function processSpecificPricePriorities() @@ -1632,7 +1632,7 @@ class AdminProductsControllerCore extends AdminController ); } - die(Tools::jsonEncode($json)); + die(json_encode($json)); } public function ajaxProcessDefaultProductAttribute() @@ -1656,7 +1656,7 @@ class AdminProductsControllerCore extends AdminController ); } - die(Tools::jsonEncode($json)); + die(json_encode($json)); } } @@ -1671,7 +1671,7 @@ class AdminProductsControllerCore extends AdminController $combinations[$key]['attributes'][] = array($combination['group_name'], $combination['attribute_name'], $combination['id_attribute']); } - die(Tools::jsonEncode($combinations)); + die(json_encode($combinations)); } } } @@ -1732,13 +1732,13 @@ class AdminProductsControllerCore extends AdminController public function ajaxProcessUpdateImagePosition() { if ($this->tabAccess['edit'] === '0') { - return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission')))); + return die(json_encode(array('error' => $this->l('You do not have the right permission')))); } $res = false; if ($json = Tools::getValue('json')) { $res = true; $json = stripslashes($json); - $images = Tools::jsonDecode($json, true); + $images = json_decode($json, true); foreach ($images as $id => $position) { $img = new Image((int)$id); $img->position = (int)$position; @@ -1755,7 +1755,7 @@ class AdminProductsControllerCore extends AdminController public function ajaxProcessUpdateCover() { if ($this->tabAccess['edit'] === '0') { - return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission')))); + return die(json_encode(array('error' => $this->l('You do not have the right permission')))); } Image::deleteCover((int)Tools::getValue('id_product')); $img = new Image((int)Tools::getValue('id_image')); @@ -2742,7 +2742,7 @@ class AdminProductsControllerCore extends AdminController if ($manufacturers) { foreach ($manufacturers as $manufacturer) { $tmp = array("optionValue" => $manufacturer['id_manufacturer'], "optionDisplay" => htmlspecialchars(trim($manufacturer['name']))); - $jsonArray[] = Tools::jsonEncode($tmp); + $jsonArray[] = json_encode($tmp); } } @@ -2925,7 +2925,9 @@ class AdminProductsControllerCore extends AdminController public function renderForm() { // This nice code (irony) is here to store the product name, because the row after will erase product name in multishop context - $this->product_name = $this->object->name[$this->context->language->id]; + if (Validate::isLoadedObject(($this->object))) { + $this->product_name = $this->object->name[$this->context->language->id]; + } if (!method_exists($this, 'initForm'.$this->tab_display)) { return; @@ -2965,7 +2967,7 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['token'] = $this->token; $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs(); $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); - $this->tpl_form_vars['post_data'] = Tools::jsonEncode($_POST); + $this->tpl_form_vars['post_data'] = json_encode($_POST); $this->tpl_form_vars['save_error'] = !empty($this->errors); $this->tpl_form_vars['mod_evasive'] = Tools::apacheModExists('evasive'); $this->tpl_form_vars['mod_security'] = Tools::apacheModExists('security'); @@ -3339,7 +3341,7 @@ class AdminProductsControllerCore extends AdminController foreach ($hotelRoomInfo as &$room) { if ($room['id_status'] == 3) { $disabledDates = $objRoomDisableDates->getRoomDisableDates($room['id']); - $room['disabled_dates_json'] = Tools::jsonEncode($disabledDates); + $room['disabled_dates_json'] = json_encode($disabledDates); } } $data->assign('htl_room_info', $hotelRoomInfo); @@ -3492,7 +3494,7 @@ class AdminProductsControllerCore extends AdminController $disableDtsArr = array(); foreach ($room_status as $key => $status) { if ($status == 3) { - $disableDtsArr[$key] = Tools::jsonDecode($disable_dates[$key], true); + $disableDtsArr[$key] = json_decode($disable_dates[$key], true); $this->validateDisableDateRanges($disableDtsArr[$key]); } } @@ -3714,7 +3716,7 @@ class AdminProductsControllerCore extends AdminController } if ($booking_calendar_data) { - die(Tools::jsonEncode($booking_calendar_data)); + die(json_encode($booking_calendar_data)); } else { die(0); } @@ -4793,7 +4795,7 @@ class AdminProductsControllerCore extends AdminController } } - die(Tools::jsonEncode(array($image_uploader->getName() => $files))); + die(json_encode(array($image_uploader->getName() => $files))); } /** @@ -5421,28 +5423,28 @@ class AdminProductsControllerCore extends AdminController public function ajaxProcessProductQuantity() { if ($this->tabAccess['edit'] === '0') { - return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission')))); + return die(json_encode(array('error' => $this->l('You do not have the right permission')))); } if (!Tools::getValue('actionQty')) { - return Tools::jsonEncode(array('error' => $this->l('Undefined action'))); + return json_encode(array('error' => $this->l('Undefined action'))); } $product = new Product((int)Tools::getValue('id_product'), true); switch (Tools::getValue('actionQty')) { case 'depends_on_stock': if (Tools::getValue('value') === false) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); + die(json_encode(array('error' => $this->l('Undefined value')))); } if ((int)Tools::getValue('value') != 0 && (int)Tools::getValue('value') != 1) { - die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); + die(json_encode(array('error' => $this->l('Incorrect value')))); } if (!$product->advanced_stock_management && (int)Tools::getValue('value') == 1) { - die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); + die(json_encode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)Tools::getValue('value') == 1 && (Pack::isPack($product->id) && !Pack::allUsesAdvancedStockManagement($product->id) && ($product->pack_stock_type == 2 || $product->pack_stock_type == 1 || ($product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))))) { - die(Tools::jsonEncode(array('error' => $this->l('You cannot use advanced stock management for this pack because').'
'. + die(json_encode(array('error' => $this->l('You cannot use advanced stock management for this pack because').'
'. $this->l('- advanced stock management is not enabled for these room types').'
'. $this->l('- you have chosen to decrement room types quantities.')))); } @@ -5453,15 +5455,15 @@ class AdminProductsControllerCore extends AdminController case 'pack_stock_type': $value = Tools::getValue('value'); if ($value === false) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); + die(json_encode(array('error' => $this->l('Undefined value')))); } if ((int)$value != 0 && (int)$value != 1 && (int)$value != 2 && (int)$value != 3) { - die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); + die(json_encode(array('error' => $this->l('Incorrect value')))); } if ($product->depends_on_stock && !Pack::allUsesAdvancedStockManagement($product->id) && ((int)$value == 1 || (int)$value == 2 || ((int)$value == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)))) { - die(Tools::jsonEncode(array('error' => $this->l('You cannot use this stock management option because:').'
'. + die(json_encode(array('error' => $this->l('You cannot use this stock management option because:').'
'. $this->l('- advanced stock management is not enabled for these room types').'
'. $this->l('- advanced stock management is enabled for the pack')))); } @@ -5471,10 +5473,10 @@ class AdminProductsControllerCore extends AdminController case 'out_of_stock': if (Tools::getValue('value') === false) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); + die(json_encode(array('error' => $this->l('Undefined value')))); } if (!in_array((int)Tools::getValue('value'), array(0, 1, 2))) { - die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); + die(json_encode(array('error' => $this->l('Incorrect value')))); } StockAvailable::setProductOutOfStock($product->id, (int)Tools::getValue('value')); @@ -5482,10 +5484,10 @@ class AdminProductsControllerCore extends AdminController case 'set_qty': if (Tools::getValue('value') === false || (!is_numeric(trim(Tools::getValue('value'))))) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); + die(json_encode(array('error' => $this->l('Undefined value')))); } if (Tools::getValue('id_product_attribute') === false) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined id room type attribute')))); + die(json_encode(array('error' => $this->l('Undefined id room type attribute')))); } StockAvailable::setQuantity($product->id, (int)Tools::getValue('id_product_attribute'), (int)Tools::getValue('value')); @@ -5495,18 +5497,18 @@ class AdminProductsControllerCore extends AdminController $error = ob_get_contents(); if (!empty($error)) { ob_end_clean(); - die(Tools::jsonEncode(array('error' => $error))); + die(json_encode(array('error' => $error))); } break; case 'advanced_stock_management' : if (Tools::getValue('value') === false) { - die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); + die(json_encode(array('error' => $this->l('Undefined value')))); } if ((int)Tools::getValue('value') != 1 && (int)Tools::getValue('value') != 0) { - die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); + die(json_encode(array('error' => $this->l('Incorrect value')))); } if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)Tools::getValue('value') == 1) { - die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); + die(json_encode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); } $product->setAdvancedStockManagement((int)Tools::getValue('value')); @@ -5516,7 +5518,7 @@ class AdminProductsControllerCore extends AdminController break; } - die(Tools::jsonEncode(array('error' => false))); + die(json_encode(array('error' => false))); } public function getCombinationImagesJS() @@ -5666,7 +5668,7 @@ class AdminProductsControllerCore extends AdminController GROUP BY pl.`id_product` LIMIT '.(int)$limit); } - die(Tools::jsonEncode($result)); + die(json_encode($result)); } } diff --git a/controllers/admin/AdminQuickAccessesController.php b/controllers/admin/AdminQuickAccessesController.php index 450a1579b..38923e60d 100644 --- a/controllers/admin/AdminQuickAccessesController.php +++ b/controllers/admin/AdminQuickAccessesController.php @@ -153,7 +153,7 @@ class AdminQuickAccessesControllerCore extends AdminController public function getQuickAccessesList() { $links = QuickAccess::getQuickAccesses($this->context->language->id); - return Tools::jsonEncode(array_map(array($this, 'getLinkToken'), $links)); + return json_encode(array_map(array($this, 'getLinkToken'), $links)); } public function getLinkToken($item) @@ -195,7 +195,7 @@ class AdminQuickAccessesControllerCore extends AdminController $this->errors = array_unique($this->errors); if (!empty($this->errors)) { $this->errors['has_errors'] = true; - $this->ajaxDie(Tools::jsonEncode($this->errors)); + $this->ajaxDie(json_encode($this->errors)); return false; } return $this->getQuickAccessesList(); diff --git a/controllers/admin/AdminRequestSqlController.php b/controllers/admin/AdminRequestSqlController.php index 121bdcf5f..a8e5507b1 100644 --- a/controllers/admin/AdminRequestSqlController.php +++ b/controllers/admin/AdminRequestSqlController.php @@ -197,7 +197,7 @@ class AdminRequestSqlControllerCore extends AdminController unset($attributes[$key]['Default']); unset($attributes[$key]['Extra']); } - die(Tools::jsonEncode($attributes)); + die(json_encode($attributes)); } } diff --git a/controllers/admin/AdminSearchController.php b/controllers/admin/AdminSearchController.php index af5b89e8a..b8dc233dc 100644 --- a/controllers/admin/AdminSearchController.php +++ b/controllers/admin/AdminSearchController.php @@ -191,7 +191,7 @@ class AdminSearchControllerCore extends AdminController $iso_lang = Tools::strtolower(Context::getContext()->language->iso_code); $iso_country = Tools::strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))); if (($json_content = Tools::file_get_contents('https://api-addons.prestashop.com/'._PS_VERSION_.'/search/'.urlencode($this->query).'/'.$iso_country.'/'.$iso_lang.'/')) != false) { - $results = Tools::jsonDecode($json_content, true); + $results = json_decode($json_content, true); if (isset($results['id'])) { $this->_list['addons'] = array($results); } else { diff --git a/controllers/admin/AdminShopController.php b/controllers/admin/AdminShopController.php index a8624c117..e02368fa6 100644 --- a/controllers/admin/AdminShopController.php +++ b/controllers/admin/AdminShopController.php @@ -36,7 +36,7 @@ class AdminShopControllerCore extends AdminController $this->table = 'shop'; $this->className = 'Shop'; $this->multishop_context = Shop::CONTEXT_ALL; - + $this->id_shop_group = (int)Tools::getValue('id_shop_group'); /* if $_GET['id_shop'] is transmitted, virtual url can be loaded in config.php, so we wether transmit shop_id in herfs */ @@ -250,7 +250,7 @@ class AdminShopControllerCore extends AdminController elseif (Shop::getTotalShops() == 1) $this->errors[] = Tools::displayError('You cannot disable the last shop.'); }*/ - + if (Tools::isSubmit('submitAddshopAndStay') || Tools::isSubmit('submitAddshop')) { $shop_group = new ShopGroup((int)Tools::getValue('id_shop_group')); if ($shop_group->shopNameExists(Tools::getValue('name'), (int)Tools::getValue('id_shop'))) { @@ -475,7 +475,7 @@ class AdminShopControllerCore extends AdminController $root_category = new Category($root_categories[0]['id_category']); $children = $root_category->getAllChildren($this->context->language->id); $selected_cat[] = $root_categories[0]['id_category']; - + foreach ($children as $child) { $selected_cat[] = $child->id; } @@ -576,7 +576,7 @@ class AdminShopControllerCore extends AdminController 'zone' => $this->l('Zones'), 'cart_rule' => $this->l('Cart rules'), ); - + // Hook for duplication of shop data $modules_list = Hook::getHookModuleExecList('actionShopDataDuplication'); if (is_array($modules_list) && count($modules_list) > 0) { @@ -586,7 +586,7 @@ class AdminShopControllerCore extends AdminController } asort($import_data); - + if (!$this->object->id) { $this->fields_import_form = array( 'radio' => array( @@ -615,9 +615,9 @@ class AdminShopControllerCore extends AdminController $this->fields_value = array( 'id_shop_group' => (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : - (isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()), + ((isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID())), 'id_category' => (Tools::getValue('id_category') ? Tools::getValue('id_category') : - (isset($obj->id_category)) ? $obj->id_category : (int)Configuration::get('PS_HOME_CATEGORY')), + ((isset($obj->id_category)) ? $obj->id_category : (int)Configuration::get('PS_HOME_CATEGORY'))), 'id_theme_checked' => (isset($obj->id_theme) ? $obj->id_theme : $id_theme) ); @@ -653,7 +653,7 @@ class AdminShopControllerCore extends AdminController if (Tools::isSubmit('id_category_default')) { $_POST['id_category'] = (int)Tools::getValue('id_category_default'); } - + /* Checking fields validity */ $this->validateRules(); @@ -711,13 +711,13 @@ class AdminShopControllerCore extends AdminController if (!array_key_exists('Edit', self::$cache_lang)) { self::$cache_lang['Edit'] = $this->l('Edit', 'Helper'); } - + $tpl->assign(array( 'href' => $this->context->link->getAdminLink('AdminShop').'&shop_id='.(int)$id.'&update'.$this->table, 'action' => self::$cache_lang['Edit'], 'id' => $id )); - + return $tpl->fetch(); } else { return; @@ -738,7 +738,7 @@ class AdminShopControllerCore extends AdminController $root_category = new Category($root_categories[0]['id_category']); $children = $root_category->getAllChildren($this->context->language->id); $selected_cat[] = $root_categories[0]['id_category']; - + foreach ($children as $child) { $selected_cat[] = $child->id; } @@ -860,6 +860,6 @@ class AdminShopControllerCore extends AdminController 'children' => $tree, )); - die(Tools::jsonEncode($tree)); + die(json_encode($tree)); } } diff --git a/controllers/admin/AdminShopUrlController.php b/controllers/admin/AdminShopUrlController.php index d3e334c9d..f0e9f20ae 100644 --- a/controllers/admin/AdminShopUrlController.php +++ b/controllers/admin/AdminShopUrlController.php @@ -281,7 +281,7 @@ class AdminShopUrlControllerCore extends AdminController } $this->tpl_form_vars = array( - 'js_shop_url' => Tools::jsonEncode($list_shop_with_url) + 'js_shop_url' => json_encode($list_shop_with_url) ); $this->fields_value = array( diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 2d53728dc..8494928a5 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -542,7 +542,7 @@ class AdminStatsControllerCore extends AdminStatsTabController } $value .= '%'; - // ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', Tools::jsonEncode($data)); + // ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', json_encode($data)); ConfigurationKPI::updateValue('CONVERSION_RATE', $value); ConfigurationKPI::updateValue('CONVERSION_RATE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); break; @@ -793,8 +793,8 @@ class AdminStatsControllerCore extends AdminStatsTabController if (isset($data)) { $array['data'] = $data; } - die(Tools::jsonEncode($array)); + die(json_encode($array)); } - die(Tools::jsonEncode(array('has_errors' => true))); + die(json_encode(array('has_errors' => true))); } } diff --git a/controllers/admin/AdminStatsTabController.php b/controllers/admin/AdminStatsTabController.php index c8e7e38eb..54b1682fb 100644 --- a/controllers/admin/AdminStatsTabController.php +++ b/controllers/admin/AdminStatsTabController.php @@ -51,7 +51,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor } $this->content .= $this->renderView(); } - + $this->content .= $this->displayMenu(); $this->content .= $this->displayCalendar(); $this->content .= $this->displayStats(); @@ -97,7 +97,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor $identifier = 'module'; $id = Tools::getValue('module'); } - + $action = Context::getContext()->link->getAdminLink('AdminStats'); $action .= ($action && $table ? '&'.Tools::safeOutput($action) : ''); $action .= ($identifier && $id ? '&'.Tools::safeOutput($identifier).'='.(int)$id : ''); @@ -172,7 +172,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor return $tpl->fetch(); } - + public function checkModulesNames($a, $b) { return (bool)($a['displayName'] > $b['displayName']); @@ -205,7 +205,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor if (!isset($module_instance)) { $module_instance = Module::getInstanceByName($module_name); } - + if ($module_instance && $module_instance->active) { $hook = Hook::exec('displayAdminStatsModules', null, $module_instance->id); } @@ -223,9 +223,9 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor public function postProcess() { $this->context = Context::getContext(); - + $this->processDateRange(); - + if (Tools::getValue('submitSettings')) { if ($this->tabAccess['edit'] === '1') { self::$currentIndex .= '&module='.Tools::getValue('module'); @@ -237,7 +237,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor } } } - + public function processDateRange() { if (Tools::isSubmit('submitDatePicker')) { @@ -281,21 +281,21 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor } } } - + public function ajaxProcessSetDashboardDateRange() { $this->processDateRange(); - + if ($this->isXmlHttpRequest()) { if (is_array($this->errors) && count($this->errors)) { - die(Tools::jsonEncode(array( + die(json_encode(array( 'has_errors' => true, 'errors' => array($this->errors), 'date_from' => $this->context->employee->stats_date_from, 'date_to' => $this->context->employee->stats_date_to) )); } else { - die(Tools::jsonEncode(array( + die(json_encode(array( 'has_errors' => false, 'date_from' => $this->context->employee->stats_date_from, 'date_to' => $this->context->employee->stats_date_to) diff --git a/controllers/admin/AdminSupplyOrdersController.php b/controllers/admin/AdminSupplyOrdersController.php index cdae27c2a..485bf6d90 100644 --- a/controllers/admin/AdminSupplyOrdersController.php +++ b/controllers/admin/AdminSupplyOrdersController.php @@ -719,7 +719,7 @@ class AdminSupplyOrdersControllerCore extends AdminController } $this->tpl_form_vars['products_list'] = $products; - $this->tpl_form_vars['product_ids'] = implode($product_ids, '|'); + $this->tpl_form_vars['product_ids'] = implode('|', $product_ids); $this->tpl_form_vars['product_ids_to_delete'] = ''; $this->tpl_form_vars['supplier_id'] = $supply_order->id_supplier; $this->tpl_form_vars['currency'] = $currency; @@ -1771,7 +1771,7 @@ class AdminSupplyOrdersControllerCore extends AdminController } } if ($items) { - die(Tools::jsonEncode($items)); + die(json_encode($items)); } die(1); diff --git a/controllers/admin/AdminTaxRulesGroupController.php b/controllers/admin/AdminTaxRulesGroupController.php index 3c54318ca..ba62da512 100644 --- a/controllers/admin/AdminTaxRulesGroupController.php +++ b/controllers/admin/AdminTaxRulesGroupController.php @@ -546,7 +546,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController foreach ($tax_rules as $key => $result) { $output[$key] = $result; } - die(Tools::jsonEncode($output)); + die(json_encode($output)); } } diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 87a586dcb..0387aa011 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -179,8 +179,8 @@ class AdminTranslationsControllerCore extends AdminController $file_name = $this->link_lang_pack.'?version='._PS_VERSION_; $array_stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 8))); if ($lang_packs = Tools::file_get_contents($file_name, false, $array_stream_context)) { - // Notice : for php < 5.2 compatibility, Tools::jsonDecode. The second parameter to true will set us - if ($lang_packs != '' && $lang_packs = Tools::jsonDecode($lang_packs, true)) { + // Notice : for php < 5.2 compatibility, json_decode. The second parameter to true will set us + if ($lang_packs != '' && $lang_packs = json_decode($lang_packs, true)) { foreach ($lang_packs as $key => $lang_pack) { if (!Language::isInstalled($lang_pack['iso_code'])) { $packs_to_install[$key] = $lang_pack; @@ -1019,7 +1019,7 @@ class AdminTranslationsControllerCore extends AdminController $arr_good_ext = array('.tpl', '.php'); foreach ($files as $key => $file) { - if ($file{0} === '.' || in_array(substr($file, 0, strrpos($file, '.')), $this->all_iso_lang)) { + if ($file[0] === '.' || in_array(substr($file, 0, strrpos($file, '.')), $this->all_iso_lang)) { unset($files[$key]); } elseif ($type_clear === 'file' && !in_array(substr($file, strrpos($file, '.')), $arr_good_ext)) { unset($files[$key]); @@ -2872,7 +2872,7 @@ class AdminTranslationsControllerCore extends AdminController $initial_root_dir = $root_dir; foreach ($modules as $module) { $root_dir = $initial_root_dir; - if ($module{0} == '.') { + if ($module[0] == '.') { continue; } diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 2606da4ab..a03befc81 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -204,7 +204,7 @@ class AddressControllerCore extends FrontController 'hasError' => (bool)$this->errors, 'errors' => $this->errors ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } } @@ -231,7 +231,7 @@ class AddressControllerCore extends FrontController 'id_address_delivery' => (int)$this->context->cart->id_address_delivery, 'id_address_invoice' => (int)$this->context->cart->id_address_invoice ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } // Redirect to old page or current page @@ -364,7 +364,7 @@ class AddressControllerCore extends FrontController 'hasError' => !empty($this->errors), 'errors' => $this->errors ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } } } diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 686694ef8..b1b374b2b 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -168,7 +168,7 @@ class AuthControllerCore extends FrontController 'page' => $this->context->smarty->fetch($this->template), 'token' => Tools::getToken(false) ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } } @@ -349,7 +349,7 @@ class AuthControllerCore extends FrontController 'errors' => $this->errors, 'token' => Tools::getToken(false) ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } else { $this->context->smarty->assign('authentification_error', $this->errors); } @@ -516,7 +516,7 @@ class AuthControllerCore extends FrontController 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false) ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { @@ -690,7 +690,7 @@ class AuthControllerCore extends FrontController 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false) ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } // if registration type is in two steps, we redirect to register address if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) { @@ -730,7 +730,7 @@ class AuthControllerCore extends FrontController 'isSaved' => false, 'id_customer' => 0 ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } $this->context->smarty->assign('account_error', $this->errors); } diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 842629439..4ee5f81cd 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -105,7 +105,7 @@ class CartControllerCore extends FrontController } } elseif (!$this->isTokenValid()) { if (Tools::getValue('ajax')) { - $this->ajaxDie(Tools::jsonEncode(array( + $this->ajaxDie(json_encode(array( 'hasError' => true, 'errors' => array(Tools::displayError('Impossible to add the product to the cart. Please refresh page.')), ))); @@ -137,7 +137,7 @@ class CartControllerCore extends FrontController } if ($total_quantity < $minimal_quantity) { - $this->ajaxDie(Tools::jsonEncode(array( + $this->ajaxDie(json_encode(array( 'hasError' => true, 'errors' => array(sprintf(Tools::displayError('You must add %d minimum quantity', !Tools::getValue('ajax')), $minimal_quantity)), ))); @@ -210,7 +210,7 @@ class CartControllerCore extends FrontController $new_id_address_delivery = (int)Tools::getValue('new_id_address_delivery'); if (!count(Carrier::getAvailableCarrierList(new Product($this->id_product), null, $new_id_address_delivery))) { - $this->ajaxDie(Tools::jsonEncode(array( + $this->ajaxDie(json_encode(array( 'hasErrors' => true, 'error' => Tools::displayError('It is not possible to deliver this product to the selected address.', false), ))); @@ -312,7 +312,7 @@ class CartControllerCore extends FrontController if (isset($hotel_room_data['stats']['num_avail'])) { $total_available_rooms = $hotel_room_data['stats']['num_avail']; if ($total_available_rooms < $req_rm) { - die(Tools::jsonEncode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); + die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms))); } } else { $this->errors[] = Tools::displayError('Rooms are unavailable. Please try with different dates'); @@ -322,10 +322,10 @@ class CartControllerCore extends FrontController } } } else { - die(Tools::jsonEncode(array('status' => 'failed3'))); + die(json_encode(array('status' => 'failed3'))); } } else { - die(Tools::jsonEncode(array('status' => 'failed4'))); + die(json_encode(array('status' => 'failed4'))); } } @@ -416,8 +416,8 @@ class CartControllerCore extends FrontController foreach ($hotel_room_info_arr as $key_hotel_room_info => $val_hotel_room_info) { if ($chkQty < $req_rm) { $roomDemand = Tools::getValue('roomDemands'); - $roomDemand = Tools::jsonDecode($roomDemand, true); - $roomDemand = Tools::jsonEncode($roomDemand); + $roomDemand = json_decode($roomDemand, true); + $roomDemand = json_encode($roomDemand); $obj_htl_cart_booking_data = new HotelCartBookingData(); $obj_htl_cart_booking_data->id_cart = $this->context->cart->id; $obj_htl_cart_booking_data->id_guest = $this->context->cart->id_guest; @@ -519,10 +519,10 @@ class CartControllerCore extends FrontController public function displayAjax() { if ($this->errors) { - $this->ajaxDie(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); + $this->ajaxDie(json_encode(array('hasError' => true, 'errors' => $this->errors))); } if ($this->ajax_refresh) { - $this->ajaxDie(Tools::jsonEncode(array('refresh' => true))); + $this->ajaxDie(json_encode(array('refresh' => true))); } // write cookie if can't on destruct @@ -560,7 +560,7 @@ class CartControllerCore extends FrontController $json = ''; Hook::exec('actionCartListOverride', array('summary' => $result, 'json' => &$json)); - $this->ajaxDie(Tools::jsonEncode(array_merge($result, (array)Tools::jsonDecode($json, true)))); + $this->ajaxDie(json_encode(array_merge($result, (array)json_decode($json, true)))); } // @todo create a hook elseif (file_exists(_PS_MODULE_DIR_.'/blockcart/blockcart-ajax.php')) { diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 526fc6aee..54c5dbe17 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -305,7 +305,7 @@ class ContactControllerCore extends FrontController if (Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { $hotelLocationArray = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY')); if ($hotelLocationArray) { - $this->context->smarty->assign('hotelLocationArray', Tools::jsonEncode($hotelLocationArray)); + $this->context->smarty->assign('hotelLocationArray', json_encode($hotelLocationArray)); } } //End diff --git a/controllers/front/OrderController.php b/controllers/front/OrderController.php index 340d534d9..a0b19b57d 100644 --- a/controllers/front/OrderController.php +++ b/controllers/front/OrderController.php @@ -138,7 +138,7 @@ class OrderControllerCore extends ParentOrderController ) ) ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } if ($this->nbProducts) { diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index cde394877..19c3a1def 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -208,7 +208,7 @@ class OrderDetailControllerCore extends FrontController $hasError = 1; } if ($bookingRefunds = Tools::getValue('bookings_to_refund')) { - if (!count($bookingRefunds = Tools::jsonDecode($bookingRefunds, true))) { + if (!count($bookingRefunds = json_decode($bookingRefunds, true))) { $hasError = 1; } else { foreach ($bookingRefunds as $idHtlBooking) { @@ -248,9 +248,9 @@ class OrderDetailControllerCore extends FrontController // Emails to customer, admin on refund request state change $objOrderReturn->changeIdOrderReturnState(OrderReturnState::ORDER_RETRUN_FIRST_STATUS, $objOrderReturn->id); - die(Tools::jsonEncode(array('status' => 1))); + die(json_encode(array('status' => 1))); } - die(Tools::jsonEncode(array('status' => 0))); + die(json_encode(array('status' => 0))); } // END ajax request handle diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index bb7730527..1c0227326 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -75,7 +75,7 @@ class OrderOpcControllerCore extends ParentOrderController $this->getFormatedSummaryDetail() ); Cart::addExtraCarriers($return); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } else { $this->errors[] = Tools::displayError('An error occurred while updating the cart.'); } @@ -89,7 +89,7 @@ class OrderOpcControllerCore extends ParentOrderController case 'updateTOSStatusAndGetPayments': if (Tools::isSubmit('checked')) { $this->context->cookie->checkedTOS = (int)Tools::getValue('checked'); - $this->ajaxDie(Tools::jsonEncode(array( + $this->ajaxDie(json_encode(array( 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods() ))); @@ -97,7 +97,7 @@ class OrderOpcControllerCore extends ParentOrderController break; case 'getCarrierList': - $this->ajaxDie(Tools::jsonEncode($this->_getCarrierList())); + $this->ajaxDie(json_encode($this->_getCarrierList())); break; case 'editCustomer': @@ -132,14 +132,14 @@ class OrderOpcControllerCore extends ParentOrderController } else { $return['isSaved'] = false; } - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); break; case 'getAddressBlockAndCarriersAndPayments': if ($this->context->customer->isLogged() || $this->context->customer->isGuest()) { // check if customer have addresses if (!Customer::getAddressesTotalById($this->context->customer->id)) { - $this->ajaxDie(Tools::jsonEncode(array('no_address' => 1))); + $this->ajaxDie(json_encode(array('no_address' => 1))); } if (file_exists(_PS_MODULE_DIR_.'blockuserinfo/blockuserinfo.php')) { include_once(_PS_MODULE_DIR_.'blockuserinfo/blockuserinfo.php'); @@ -183,7 +183,7 @@ class OrderOpcControllerCore extends ParentOrderController ), $this->getFormatedSummaryDetail() ); - $this->ajaxDie(Tools::jsonEncode($return)); + $this->ajaxDie(json_encode($return)); } die(Tools::displayError()); break; @@ -265,11 +265,11 @@ class OrderOpcControllerCore extends ParentOrderController 'refresh' => (bool)$this->ajax_refresh), $this->getFormatedSummaryDetail() ); - $this->ajaxDie(Tools::jsonEncode($result)); + $this->ajaxDie(json_encode($result)); } } if (count($this->errors)) { - $this->ajaxDie(Tools::jsonEncode(array( + $this->ajaxDie(json_encode(array( 'hasError' => true, 'errors' => $this->errors ))); @@ -958,8 +958,8 @@ class OrderOpcControllerCore extends ParentOrderController if ($idCartBooking = Tools::getValue('id_cart_booking')) { if (Validate::isLoadedObject($objCartbookingCata = new HotelCartBookingData($idCartBooking))) { $roomDemands = Tools::getValue('room_demands'); - $roomDemands = Tools::jsonDecode($roomDemands, true); - $roomDemands = Tools::jsonEncode($roomDemands); + $roomDemands = json_decode($roomDemands, true); + $roomDemands = json_encode($roomDemands); $objCartbookingCata->extra_demands = $roomDemands; if ($objCartbookingCata->save()) { die('1'); diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 46cfd89d0..cafe51955 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -969,7 +969,7 @@ class ProductControllerCore extends FrontController $totalPrice += $totalRoomPrice; $demandsPrice = 0; if ($roomDemand = Tools::getValue('room_demands')) { - if ($roomDemand = Tools::jsonDecode($roomDemand, true)) { + if ($roomDemand = json_decode($roomDemand, true)) { $objRoomDemandPrice = new HotelRoomTypeDemandPrice(); $demandsPrice = $objRoomDemandPrice->getRoomTypeDemandsTotalPrice( $idProduct, @@ -1009,6 +1009,6 @@ class ProductControllerCore extends FrontController $result['msg'] = 'failed3'; $result['avail_rooms'] = 0; } - die(Tools::jsonEncode($result)); + die(json_encode($result)); } } diff --git a/controllers/front/SearchController.php b/controllers/front/SearchController.php index 7e36fc1a3..ebe5d78a5 100644 --- a/controllers/front/SearchController.php +++ b/controllers/front/SearchController.php @@ -64,12 +64,12 @@ class SearchControllerCore extends FrontController } Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults))); } - $this->ajaxDie(Tools::jsonEncode($searchResults)); + $this->ajaxDie(json_encode($searchResults)); } //Only controller content initialization when the user use the normal search parent::initContent(); - + $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); if ($this->instant_search && !is_array($query)) { diff --git a/install/classes/controllerHttp.php b/install/classes/controllerHttp.php index de96a6a60..caceb3a16 100644 --- a/install/classes/controllerHttp.php +++ b/install/classes/controllerHttp.php @@ -430,7 +430,7 @@ abstract class InstallControllerHttp if (!$success && empty($message)) { $message = print_r(@error_get_last(), true); } - die(Tools::jsonEncode(array( + die(json_encode(array( 'success' => (bool)$success, 'message' => $message, // 'memory' => round(memory_get_peak_usage()/1024/1024, 2).' Mo', diff --git a/install/controllers/console/process.php b/install/controllers/console/process.php index fa56b6bec..afeadfe82 100644 --- a/install/controllers/console/process.php +++ b/install/controllers/console/process.php @@ -221,7 +221,7 @@ class InstallControllerConsoleProcess extends InstallControllerConsole $this->model_install->xml_loader_ids = $this->datas->xml_loader_ids; $result = $this->model_install->populateDatabase(); $this->datas->xml_loader_ids = $this->model_install->xml_loader_ids; - Configuration::updateValue('PS_INSTALL_XML_LOADERS_ID', Tools::jsonEncode($this->datas->xml_loader_ids)); + Configuration::updateValue('PS_INSTALL_XML_LOADERS_ID', json_encode($this->datas->xml_loader_ids)); return $result; } @@ -269,7 +269,7 @@ class InstallControllerConsoleProcess extends InstallControllerConsole { $this->initializeContext(); - if ((!$this->datas->xml_loader_ids || !is_array($this->datas->xml_loader_ids)) && ($xml_ids = Tools::jsonDecode(Configuration::get('PS_INSTALL_XML_LOADERS_ID'), true))) { + if ((!$this->datas->xml_loader_ids || !is_array($this->datas->xml_loader_ids)) && ($xml_ids = json_decode(Configuration::get('PS_INSTALL_XML_LOADERS_ID'), true))) { $this->datas->xml_loader_ids = $xml_ids; } diff --git a/install/controllers/http/system.php b/install/controllers/http/system.php index fa79cfb26..7a6477b5f 100644 --- a/install/controllers/http/system.php +++ b/install/controllers/http/system.php @@ -99,6 +99,7 @@ class InstallControllerHttpSystem extends InstallControllerHttp 'max_execution_time' => $this->l('In the PHP configuration set max_execution_time to minimum 500'), 'upload_max_filesize' => $this->l('In the PHP configuration set upload_max_filesize to minimum 16M'), 'fopen' => $this->l('Cannot open external URLs (requires allow_url_fopen as On).'), + 'zip' => $this->l('ZIP extension is not enabled'), ) ), array( diff --git a/install/dev/index.phtml b/install/dev/index.phtml index 76984a2b5..0eb7e2be0 100644 --- a/install/dev/index.phtml +++ b/install/dev/index.phtml @@ -113,7 +113,7 @@ $this->loader->setDefaultPath(); ?>
Selectionnez la liste des entités à resynchroniser. Afin d'éviter au maximum les erreurs, sélectionnez uniquement les entitiés que vous avez modifier. diff --git a/install/install_version.php b/install/install_version.php index 3623b0fd3..b5333e005 100644 --- a/install/install_version.php +++ b/install/install_version.php @@ -25,4 +25,4 @@ */ define('_PS_INSTALL_VERSION_', '1.6.1.23'); -define('_QLO_INSTALL_VERSION_', '1.5.0.0'); \ No newline at end of file +define('_QLO_INSTALL_VERSION_', '1.5.1.0'); \ No newline at end of file diff --git a/install/models/install.php b/install/models/install.php index adf157ea3..5648853e9 100644 --- a/install/models/install.php +++ b/install/models/install.php @@ -654,7 +654,6 @@ class InstallModelInstall extends InstallAbstractModel 'wkhotelfeaturesblock', 'wkhotelroom', 'wktestimonialblock', - 'socialsharing', 'bankwire', 'cheque', 'paypal', diff --git a/install/theme/views/process.phtml b/install/theme/views/process.phtml index 5eace8bb6..8111f5021 100644 --- a/install/theme/views/process.phtml +++ b/install/theme/views/process.phtml @@ -3,7 +3,7 @@ diff --git a/install/upgrade/classes/AddConfToFile.php b/install/upgrade/classes/AddConfToFile.php index f2525b4d0..d88678740 100644 --- a/install/upgrade/classes/AddConfToFile.php +++ b/install/upgrade/classes/AddConfToFile.php @@ -86,7 +86,7 @@ class AddConfToFile public function checkString($string) { - if (get_magic_quotes_gpc()) { + if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $string = stripslashes($string); } if (!is_numeric($string)) { diff --git a/install/upgrade/php/latin1_database_to_utf8.php b/install/upgrade/php/latin1_database_to_utf8.php index a0fbcc7e5..4b7e6a8bc 100644 --- a/install/upgrade/php/latin1_database_to_utf8.php +++ b/install/upgrade/php/latin1_database_to_utf8.php @@ -25,7 +25,7 @@ */ if (!defined('_PS_MAGIC_QUOTES_GPC_')) { - define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc()); + define('_PS_MAGIC_QUOTES_GPC_', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()); } if (!defined('_PS_MYSQL_REAL_ESCAPE_STRING_')) { define('_PS_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string')); diff --git a/install/upgrade/php/ps1607_language_code_update.php b/install/upgrade/php/ps1607_language_code_update.php index c5fd639dc..5ac86d4d7 100644 --- a/install/upgrade/php/ps1607_language_code_update.php +++ b/install/upgrade/php/ps1607_language_code_update.php @@ -31,7 +31,7 @@ function ps1607_language_code_update() if (is_array($langs) && $langs) { foreach ($langs as $lang) { if (Tools::strlen($lang['language_code']) == 2) { - $result = Tools::jsonDecode(Tools::file_get_contents('https://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.Tools::strtolower($lang['iso_code']))); + $result = json_decode(Tools::file_get_contents('https://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.Tools::strtolower($lang['iso_code']))); if ($result && !isset($result->error) && Tools::strlen($result->language_code) > 2) { Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'lang` SET `language_code` = \''.pSQL($result->language_code).'\' WHERE `id_lang` = '.(int)$lang['id_lang']).' LIMIT 1'; } diff --git a/modules/blockcart/CHANGELOG.txt b/modules/blockcart/CHANGELOG.txt index a589d360e..31cfc3a4b 100644 --- a/modules/blockcart/CHANGELOG.txt +++ b/modules/blockcart/CHANGELOG.txt @@ -1,3 +1,13 @@ +----------------------------- +# V1.6.2 to V1.6.3 +----------------------------- + +## Improved/Changed Features: + +* [CO] : Removed unused hooks displayLeftColumn and displayrightColumn +* [CO] : 'getHotelCartBookingData' function from blockcart.php is removed and called from HotelCartBookingData::getHotelCartBookingData() + + ----------------------------- # V1.6.1 to V1.6.2 ----------------------------- diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php index 4bebdaafb..7a3fe31ad 100644 --- a/modules/blockcart/blockcart.php +++ b/modules/blockcart/blockcart.php @@ -34,7 +34,7 @@ class blockcart extends Module { $this->name = 'blockcart'; $this->tab = 'front_office_features'; - $this->version = '1.6.2'; + $this->version = '1.6.3'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -224,7 +224,8 @@ class blockcart extends Module } $this->assignContentVars($params); - $res = Tools::jsonDecode(Tools::removeHtmlComments($this->display(__FILE__, 'blockcart-json.tpl')), true); + + $res = json_decode(Tools::removeHtmlComments($this->display(__FILE__, 'blockcart-json.tpl')), true); if (isset($params['cookie']->avail_rooms)) { $res['avail_rooms'] = $params['cookie']->avail_rooms; @@ -237,7 +238,7 @@ class blockcart extends Module $res['crossSelling'] = $this->display(__FILE__, 'crossselling.tpl'); } - $res = Tools::jsonEncode($res); + $res = json_encode($res); return $res; } diff --git a/modules/blockcart/checkroomavailabilityajaxprocess.php b/modules/blockcart/checkroomavailabilityajaxprocess.php index 51efaabd4..6fdcb30b0 100644 --- a/modules/blockcart/checkroomavailabilityajaxprocess.php +++ b/modules/blockcart/checkroomavailabilityajaxprocess.php @@ -57,21 +57,21 @@ break; } } - die(Tools::jsonEncode(array('status'=>'success', 'avail_rooms'=>$total_available_rooms))); + die(json_encode(array('status'=>'success', 'avail_rooms'=>$total_available_rooms))); } else { - die(Tools::jsonEncode(array('status'=>'failed1'))); + die(json_encode(array('status'=>'failed1'))); } } else { - die(Tools::jsonEncode(array('status'=>'unavailable_quantity', 'avail_rooms'=>$total_available_rooms))); + die(json_encode(array('status'=>'unavailable_quantity', 'avail_rooms'=>$total_available_rooms))); } } else { - die(Tools::jsonEncode(array('status'=>'failed2'))); + die(json_encode(array('status'=>'failed2'))); } } else { - die(Tools::jsonEncode(array('status'=>'failed3'))); + die(json_encode(array('status'=>'failed3'))); } } else { - die(Tools::jsonEncode(array('status'=>'failed4'))); + die(json_encode(array('status'=>'failed4'))); } } @@ -94,9 +94,9 @@ $result = $obj_htl_cart_booking_data->deleteCartBookingData($id_cart, $id_product); if ($result) { - die(Tools::jsonEncode(array('status'=>'success', 'avail_rooms'=>$total_available_rooms))); + die(json_encode(array('status'=>'success', 'avail_rooms'=>$total_available_rooms))); } else { - die(Tools::jsonEncode(array('status'=>'failed'))); + die(json_encode(array('status'=>'failed'))); } } @@ -109,10 +109,10 @@ $cart_obj = new Cart($id_cart); $update_cart_product = $cart_obj->updateQty($num_rooms_to_decr_from_cart, $id_product, null, false, $operator = 'down', 0, null, true); if ($update_cart_product) { - die(Tools::jsonEncode(array('status'=>'success', 'msg'=>'successfully cart product updated.'))); + die(json_encode(array('status'=>'success', 'msg'=>'successfully cart product updated.'))); } else { - die(Tools::jsonEncode(array('status'=>'failed', 'msg'=>'error while updating cart product.'))); + die(json_encode(array('status'=>'failed', 'msg'=>'error while updating cart product.'))); } } - die(Tools::jsonEncode(array('status'=>'failed', 'msg'=>'error while deleting room from cart booking table.'))); + die(json_encode(array('status'=>'failed', 'msg'=>'error while deleting room from cart booking table.'))); } diff --git a/modules/blockcart/controllers/front/checkroomavailabilityajaxprocess.php b/modules/blockcart/controllers/front/checkroomavailabilityajaxprocess.php index 081eba2a8..547daedfa 100644 --- a/modules/blockcart/controllers/front/checkroomavailabilityajaxprocess.php +++ b/modules/blockcart/controllers/front/checkroomavailabilityajaxprocess.php @@ -50,7 +50,7 @@ class BlockcartCheckRoomAvailabilityAjaxProcessModuleFrontController extends Mod } } die( - Tools::jsonEncode( + json_encode( array( 'status'=>'success', 'msg'=>'successfully cart product updated.', @@ -60,7 +60,7 @@ class BlockcartCheckRoomAvailabilityAjaxProcessModuleFrontController extends Mod ); } die( - Tools::jsonEncode( + json_encode( array('status'=>'failed', 'msg'=>'error while deleting room from cart booking table.') ) ); diff --git a/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php b/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php index 42367ed85..4a95beb6a 100644 --- a/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php +++ b/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php @@ -48,7 +48,7 @@ class AdminBlockCategoriesController extends ModuleAdminController } public function ajaxProcessuploadThumbnailImages() - { + { $category = new Category((int)Tools::getValue('id_category')); if (isset($_FILES['thumbnail'])) @@ -74,7 +74,7 @@ class AdminBlockCategoriesController extends ModuleAdminController { $total_errors['name'] = sprintf(Tools::displayError('An error occurred while uploading the image :')); $total_errors['error'] = sprintf(Tools::displayError('You cannot upload more files')); - die(Tools::jsonEncode(array('thumbnail' => array($total_errors)))); + die(json_encode(array('thumbnail' => array($total_errors)))); } foreach ($files as $key => &$file) @@ -99,7 +99,7 @@ class AdminBlockCategoriesController extends ModuleAdminController unset($file['save_path']); if (isset($file['tmp_name'])) - unset($file['tmp_name']); + unset($file['tmp_name']); //Add image preview and delete url $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$id.'_thumb.jpg', @@ -113,7 +113,7 @@ class AdminBlockCategoriesController extends ModuleAdminController else Tools::clearSmartyCache(); - die(Tools::jsonEncode(array('thumbnail' => $files))); + die(json_encode(array('thumbnail' => $files))); } } } diff --git a/modules/blocklayered/blocklayered-url-indexer.php b/modules/blocklayered/blocklayered-url-indexer.php index bc33f3e59..da474797e 100644 --- a/modules/blocklayered/blocklayered-url-indexer.php +++ b/modules/blocklayered/blocklayered-url-indexer.php @@ -7,5 +7,5 @@ if (substr(Tools::encrypt('blocklayered/index'),0,10) != Tools::getValue('token' die('Bad token'); $blockLayered = new BlockLayered(); -$cursor = Tools::jsonDecode(Tools::getValue('cursor', '{}'), true); +$cursor = json_decode(Tools::getValue('cursor', '{}'), true); echo $blockLayered->indexUrl($cursor, (int)Tools::getValue('truncate')); \ No newline at end of file diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 89c25af64..76e8028fd 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -1621,7 +1621,7 @@ class BlockLayered extends Module 'template_name' => $template['name'], 'attribute_groups' => $attribute_groups, 'features' => $features, - 'filters' => Tools::jsonEncode($filters), + 'filters' => json_encode($filters), 'total_filters' => 6+count($attribute_groups)+count($features) )); @@ -1862,7 +1862,7 @@ class BlockLayered extends Module break; case 'manufacturer': - $query_filters_where .= ' AND p.id_manufacturer IN ('.implode($selected_filters['manufacturer'], ',').')'; + $query_filters_where .= ' AND p.id_manufacturer IN ('.implode(',', $selected_filters['manufacturer']).')'; break; case 'condition': @@ -2005,7 +2005,7 @@ class BlockLayered extends Module $this->products = array(); else { - $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); + $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'); $n = (int)Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')); $nb_day_new_product = (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20); @@ -3049,8 +3049,8 @@ class BlockLayered extends Module $query_filters = ''; else { - array_walk($filter_value, create_function('&$id_manufacturer', '$id_manufacturer = (int)$id_manufacturer;')); - $query_filters = ' AND p.id_manufacturer IN ('.implode($filter_value, ',').')'; + array_walk($filter_value, function (&$id_manufacturer) {$id_manufacturer = (int)$id_manufacturer;}); + $query_filters = ' AND p.id_manufacturer IN ('.implode(',', $filter_value).')'; } if ($ignore_join) return array('where' => $query_filters); @@ -3177,7 +3177,7 @@ class BlockLayered extends Module $vars = array_merge($vars, array('pagination_bottom' => $smarty->assign('paginationId', 'bottom') ->fetch(_PS_THEME_DIR_.'pagination.tpl'))); /* We are sending an array in jSon to the .js controller, it will update both the filters and the products zones */ - return Tools::jsonEncode($vars); + return json_encode($vars); } public function getProducts($selected_filters, &$products, &$nb_products, &$p, &$n, &$pages_nb, &$start, &$stop, &$range) diff --git a/modules/blockwishlist/controllers/front/mywishlist.php b/modules/blockwishlist/controllers/front/mywishlist.php index 61dab94ea..d94e13b95 100644 --- a/modules/blockwishlist/controllers/front/mywishlist.php +++ b/modules/blockwishlist/controllers/front/mywishlist.php @@ -51,7 +51,7 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController elseif (!empty($action) && method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action))) $this->{'ajaxProcess'.Tools::toCamelCase($action)}(); else - die(Tools::jsonEncode(array('error' => 'method doesn\'t exist'))); + die(json_encode(array('error' => 'method doesn\'t exist'))); } /** @@ -150,7 +150,7 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController public function ajaxProcessDeleteList() { if (!$this->context->customer->isLogged()) - die(Tools::jsonEncode(array('success' => false, + die(json_encode(array('success' => false, 'error' => $this->module->l('You aren\'t logged in', 'mywishlist')))); $default = Tools::getIsset('default'); @@ -165,7 +165,7 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController $wishlist->delete(); } else - die(Tools::jsonEncode(array('success' => false, + die(json_encode(array('success' => false, 'error' => $this->module->l('Cannot delete this wishlist', 'mywishlist')))); if ($default_change) @@ -173,19 +173,19 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController $array = WishList::getDefault($id_customer); if (count($array)) - die(Tools::jsonEncode(array( + die(json_encode(array( 'success' => true, 'id_default' => $array[0]['id_wishlist'] ))); } - die(Tools::jsonEncode(array('success' => true))); + die(json_encode(array('success' => true))); } public function ajaxProcessSetDefault() { if (!$this->context->customer->isLogged()) - die(Tools::jsonEncode(array('success' => false, + die(json_encode(array('success' => false, 'error' => $this->module->l('You aren\'t logged in', 'mywishlist')))); $default = Tools::getIsset('default'); @@ -196,16 +196,16 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController { $wishlist = new WishList((int)$id_wishlist); if (Validate::isLoadedObject($wishlist) && $wishlist->id_customer == $this->context->customer->id && $wishlist->setDefault()) - die(Tools::jsonEncode(array('success' => true))); + die(json_encode(array('success' => true))); } - die(Tools::jsonEncode(array('error' => true))); + die(json_encode(array('error' => true))); } public function ajaxProcessProductChangeWishlist() { if (!$this->context->customer->isLogged()) - die(Tools::jsonEncode(array('success' => false, + die(json_encode(array('success' => false, 'error' => $this->module->l('You aren\'t logged in', 'mywishlist')))); $id_product = (int)Tools::getValue('id_product'); @@ -222,7 +222,7 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController !is_int($priority) || ($priority < 0 && $priority > 2) || !$id_old_wishlist || !$id_new_wishlist || (Validate::isLoadedObject($new_wishlist) && $new_wishlist->id_customer != $this->context->customer->id) || (Validate::isLoadedObject($old_wishlist) && $old_wishlist->id_customer != $this->context->customer->id)) - die(Tools::jsonEncode(array('success' => false, 'error' => $this->module->l('Error while moving product to another list', 'mywishlist')))); + die(json_encode(array('success' => false, 'error' => $this->module->l('Error while moving product to another list', 'mywishlist')))); $res = true; $check = (int)Db::getInstance()->getValue('SELECT quantity FROM '._DB_PREFIX_.'wishlist_product @@ -240,7 +240,7 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController } if (!$res) - die(Tools::jsonEncode(array('success' => false, 'error' => $this->module->l('Error while moving product to another list', 'mywishlist')))); - die(Tools::jsonEncode(array('success' => true, 'msg' => $this->module->l('The product has been correctly moved', 'mywishlist')))); + die(json_encode(array('success' => false, 'error' => $this->module->l('Error while moving product to another list', 'mywishlist')))); + die(json_encode(array('success' => true, 'msg' => $this->module->l('The product has been correctly moved', 'mywishlist')))); } } diff --git a/modules/graphnvd3/graphnvd3.php b/modules/graphnvd3/graphnvd3.php index 2c0f4e277..b9cd126d6 100644 --- a/modules/graphnvd3/graphnvd3.php +++ b/modules/graphnvd3/graphnvd3.php @@ -176,6 +176,6 @@ class GraphNvD3 extends ModuleGraphEngine $array['data'][] = array('values' => $nvd3_values, 'key' => $this->_titles['main'][$layer]); } } - die(preg_replace('/"([0-9]+)"/', '$1', Tools::jsonEncode($array))); + die(preg_replace('/"([0-9]+)"/', '$1', json_encode($array))); } } diff --git a/modules/gridhtml/gridhtml.php b/modules/gridhtml/gridhtml.php index 10b2ecec6..d0f68efd4 100644 --- a/modules/gridhtml/gridhtml.php +++ b/modules/gridhtml/gridhtml.php @@ -43,19 +43,19 @@ class GridHtml extends ModuleGridEngine $this->version = '1.3.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; - + Module::__construct(); - + $this->displayName = $this->l('Simple HTML table display'); $this->description = $this->l('Allows the statistics system to display data in a grid.'); } } - + function install() { return (parent::install() AND $this->registerHook('GridEngine')); } - + public static function hookGridEngine($params, $grider) { self::$_columns = $params['columns']; @@ -112,7 +112,7 @@ class GridHtml extends ModuleGridEngine $("#grid_1 tbody").append("'.$params['emptyMsg'].'"); }); } - + function gridNextPage(url) { var from = url.match(/&start=[0-9]+/i); @@ -123,7 +123,7 @@ class GridHtml extends ModuleGridEngine url = url.replace(/&start=[0-9]+/i, "") + from; getGridData(url); } - + function gridPrevPage(url) { var from = url.match(/&start=[0-9]+/i); @@ -145,46 +145,46 @@ class GridHtml extends ModuleGridEngine '; return $html; } - + public function setColumnsInfos(&$infos) { } - + public function setValues($values) { $this->_values = $values; } - + public function setTitle($title) { $this->_title = $title; } - + public function setSize($width, $height) { $this->_width = $width; $this->_height = $height; } - + public function setTotalCount($totalCount) { $this->_totalCount = $totalCount; } - + public function setLimit($start, $limit) { $this->_start = (int)$start; $this->_limit = (int)$limit; } - + public function render() { - echo Tools::jsonEncode(array( + echo json_encode(array( 'total' => $this->_totalCount, 'from' => min($this->_start + 1, $this->_totalCount), 'to' => min($this->_start + $this->_limit, $this->_totalCount), 'values' => $this->_values )); - } + } } diff --git a/modules/hotelreservationsystem/CHANGELOG.txt b/modules/hotelreservationsystem/CHANGELOG.txt index af84d7de1..cd07dd669 100644 --- a/modules/hotelreservationsystem/CHANGELOG.txt +++ b/modules/hotelreservationsystem/CHANGELOG.txt @@ -1,3 +1,37 @@ +------------------------- +# V1.4.1 to V1.4.2 +------------------------- + +## Added Features: + +[+] CO : [#198] Multiple hooks are added in the different QloApps core files + +## Improved/changed features: + +[*] BO : [110, #111] Code Optimization +[*] BO : [#179] Added hotel column in room type feature pricing list +[*] BO : [#204, #196, #182] Text Changes +[*] BO : [#193] Removed Payment Modules setting from admin Hotel Reservation System -> Settings +[*] BO : [#206] Removed Other Modules setting from admin Hotel Reservation System -> Settings + +[*] CO : [#215] "hotelreservationsystem.php" code optimization in hook "actionValidateOrder" +[*] CO : [#221] dataforfrontsearch() function now calculate and provide "feature_price_diff" value in response +[*] CO : [#223] getHotelCartBookingData() : function multiplication optimized +[*] CO : [#225] HotelRoomTypeFeaturePricing.php optimized (Removed unused variables, removed static values assigned) + +## Bug/Issues Resolved: + +[-] FO : Fixed : [#169] Wrong price displayed when booking from 1 march to 30 march +[*] FO : [#215] "ajax-cart.js" add validation + +[-] BO : Fixed : [#162] Additional facility price changes for room type after saving +[-] BO : Fixed : [#168] Room number not updating after room reallocation and swap +[-] BO : Fixed : [#173] Undefined varaible issue Manage Order Refund Request Controller +[-] BO : Fixed : [#211] Errors on cart rule page when add room type, which is not assigned to hotel, selected in room type condition +[-] BO : Fixed : [#229] Resolved undefined variable error in Manage Order Refund Request Controller + + + ------------------------- # V1.4.0 to V1.4.1 ------------------------- diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index 1056deafe..fb4561107 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -840,7 +840,7 @@ class HotelBranchInformation extends ObjectModel libxml_use_internal_errors(true); $xml = simplexml_load_string(utf8_decode($postData)); - $hotelData = Tools::jsonDecode(Tools::jsonEncode($xml)); + $hotelData = json_decode(json_encode($xml)); if (isset($hotelData->hotel->max_order_date)) { if ($maxOrderDate = $hotelData->hotel->max_order_date) { $this->setWsMaxOrderDate($maxOrderDate); @@ -863,7 +863,7 @@ class HotelBranchInformation extends ObjectModel libxml_use_internal_errors(true); $xml = simplexml_load_string(utf8_decode($postData)); - $hotelData = Tools::jsonDecode(Tools::jsonEncode($xml)); + $hotelData = json_decode(json_encode($xml)); if (isset($hotelData->hotel->max_order_date)) { if ($maxOrderDate = $hotelData->hotel->max_order_date) { $this->setWsMaxOrderDate($maxOrderDate); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index fc234d227..61cd21458 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -764,7 +764,7 @@ class HotelCartBookingData extends ObjectModel AND fp.`active`=1 AND fp.`date_from` <= \''.pSQL($date).'\' AND fp.`date_to` >= \''.pSQL($date).'\'' )) { foreach ($featurePrice as $fRow) { - $specialDays = Tools::jsonDecode($fRow['special_days']); + $specialDays = json_decode($fRow['special_days']); if (in_array(strtolower(date('D', strtotime($date))), $specialDays)) { return $fRow; } @@ -1105,7 +1105,7 @@ class HotelCartBookingData extends ObjectModel if ($getTotalPrice) { if ($roomTypeDemands['extra_demands'] - && ($extraDemand = Tools::jsonDecode($roomTypeDemands['extra_demands'], true)) + && ($extraDemand = json_decode($roomTypeDemands['extra_demands'], true)) ) { $totalDemandsPrice += $objRoomDemandPrice->getRoomTypeDemandsTotalPrice( $roomTypeDemands['id_product'], @@ -1116,7 +1116,7 @@ class HotelCartBookingData extends ObjectModel ); } } else { - $roomTypeDemands['extra_demands'] = Tools::jsonDecode( + $roomTypeDemands['extra_demands'] = json_decode( $roomTypeDemands['extra_demands'], true ); @@ -1146,7 +1146,7 @@ class HotelCartBookingData extends ObjectModel foreach ($roomTypeDemands as $key => &$demand) { if ($getTotalPrice) { if ($demand['extra_demands'] - && ($extraDemand = Tools::jsonDecode($demand['extra_demands'], true)) + && ($extraDemand = json_decode($demand['extra_demands'], true)) ) { $totalDemandsPrice += $objRoomDemandPrice->getRoomTypeDemandsTotalPrice( $demand['id_product'], @@ -1157,7 +1157,7 @@ class HotelCartBookingData extends ObjectModel ); } } else { - $demand['extra_demands'] = Tools::jsonDecode( + $demand['extra_demands'] = json_decode( $demand['extra_demands'], true ); @@ -1193,7 +1193,7 @@ class HotelCartBookingData extends ObjectModel // Webservice :: get extra demands for the cart booking public function getWsExtraDemands() { - $extraDemands = Tools::jsonDecode($this->extra_demands, true); + $extraDemands = json_decode($this->extra_demands, true); if (count($extraDemands)) { foreach ($extraDemands as &$demnad) { $demnad['id'] = $demnad['id_global_demand']; diff --git a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php index a51eb1b82..3d490af2c 100644 --- a/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php +++ b/modules/hotelreservationsystem/classes/HotelOrderRestrictDate.php @@ -54,10 +54,8 @@ class HotelOrderRestrictDate extends ObjectModel $obj_ord_rest = new self(); $order_restrict_data = $obj_ord_rest->getDataByHotelId($id_hotel); - $max_order_date_restr = $order_restrict_data['max_order_date']; - - if (isset($max_order_date_restr) && $max_order_date_restr) { - $max_order_date = $max_order_date_restr; + if (isset($order_restrict_data['max_order_date']) && $order_restrict_data['max_order_date']) { + $max_order_date = $order_restrict_data['max_order_date']; } elseif (isset($global_max_order_date) && $global_max_order_date) { $max_order_date = $global_max_order_date; } else { diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeDemandPrice.php b/modules/hotelreservationsystem/classes/HotelRoomTypeDemandPrice.php index 53a2ce945..522b78584 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeDemandPrice.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeDemandPrice.php @@ -143,7 +143,7 @@ class HotelRoomTypeDemandPrice extends ObjectModel } if ($cartChanged) { if (Validate::isLoadedObject($objCartBooking = new HotelCartBookingData($demandInfo['id']))) { - $objCartBooking->extra_demands = Tools::jsonEncode($demandInfo['extra_demands']); + $objCartBooking->extra_demands = json_encode($demandInfo['extra_demands']); $objCartBooking->save(); } } diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index e8e8a3b3a..bffdd1b58 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -82,7 +82,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel public function __construct($id = null, $id_lang = null, $id_shop = null) { $this->moduleInstance = Module::getInstanceByName('hotelreservationsystem'); - parent::__construct($id); + parent::__construct($id, $id_lang, $id_shop); } public function add($autodate = true, $null_values = true) @@ -221,7 +221,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $date_to = date('Y-m-d', strtotime($date_to)); for($date = $date_from; $date < $date_to; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { - if (in_array(strtolower(Date('D', $date)), $specialDays)) { + if (in_array(Tools::strtolower(Date('D', $date)), $specialDays)) { $specialDaysCount++; } } @@ -321,7 +321,6 @@ class HotelRoomTypeFeaturePricing extends ObjectModel */ public function updateRoomTypesFeaturePricesAvailability($featurePricePlans) { - $moduleInstance = new HotelReservationSystem(); $this->errors = array(); if ($featurePricePlans) { if (isset($featurePricePlans['data']) && $featurePricePlans['data']) { @@ -333,8 +332,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product = $key; // feature price rates create and updates if (isset($roomTypeRates['rate'])) { - //$productPriceTE = Product::getPriceStatic((int) $id_product, false); - $productPriceTE = 1000; + $productPriceTE = Product::getPriceStatic((int) $id_product, false); if ($productPriceTE != $roomTypeRates['rate']) { if ($productPriceTE > $roomTypeRates['rate']) { $priceImpactWay = 1; @@ -361,7 +359,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product, $dateFrom, $dateTo, - $type = 'specific_date' + 'specific_date' ); if ($featurePriceExists) { if (!$this->saveFeaturePricePlan($featurePriceExists['id'], 2, $params)) { @@ -378,7 +376,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product, $dateFrom, $dateTo, - $type='date_range' + 'date_range' ); if ($featurePriceExists) { if ($featurePriceExists['date_from'] == $dateFrom @@ -392,7 +390,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $this->errors[] = $this->moduleInstance->l('Some error occured while saving Feature Price Plan Info:: Date From : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Date To : ', 'HotelRoomTypeFeaturePricing').$params['dateFrom'].$this->moduleInstance->l(' Room Type Id : ', 'HotelRoomTypeFeaturePricing').$params['roomTypeId']; } } else { - for($date = $date_from; $date < $date_to; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { + for($date = $dateFrom; $date < $dateTo; $date = date('Y-m-d', strtotime('+1 day', strtotime($date)))) { $currentDate = date('Y-m-d', $date); $nextDayDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); $params['dateFrom'] = $currentDate; @@ -402,7 +400,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $id_product, $currentDate, $nextDayDate, - $type = 'specific_date' + 'specific_date' ); if ($featurePriceExists) { if (!$this->saveFeaturePricePlan( @@ -431,7 +429,6 @@ class HotelRoomTypeFeaturePricing extends ObjectModel if (isset($roomTypeRates['inventory'])) { $totalAvailableNotBooked = 0; $totalAvailableRooms = 0; - $totalRooms = 0; $hotelRoomType = new HotelRoomType(); $hotelBookingDetail = new HotelBookingDetail(); $hotelRoomInformation = new HotelRoomInformation(); @@ -458,17 +455,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel ); $countBookedRooms = count($bookedRoomsInfo); if (isset($roomTypeAvailabilityInfo['stats']['total_rooms'])) { - $totalRooms = $roomTypeAvailabilityInfo['stats']['total_rooms']; $totalAvailableNotBooked = $roomTypeAvailabilityInfo['stats']['total_rooms'] - $countBookedRooms; $totalAvailableRooms = $roomTypeAvailabilityInfo['stats']['num_avail']; - $totalAvailableNotBooked = 5; - $totalAvailableRooms = 3; } - /*p($totalAvailableRooms); - p($roomTypeRates['inventory']); - p($totalAvailableNotBooked); - die;*/ if ($roomTypeRates['inventory'] <= $totalAvailableNotBooked) { if ($roomTypeRates['inventory'] < $totalAvailableRooms) { $numDisabledRooms = $totalAvailableRooms - $roomTypeRates['inventory']; @@ -479,7 +469,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $dateTo ); if ($availableRooms) { - foreach ($availableRooms as $room_k => $room) { + foreach ($availableRooms as $room) { $objRoomDisableDates = new HotelRoomDisableDates(); $params['id_room'] = $room['id']; $params['date_from'] = $dateFrom; @@ -519,7 +509,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel $dateTo ); if ($disabledRooms) { - foreach ($disabledRooms as $k_rm => $disableRoom) { + foreach ($disabledRooms as $disableRoom) { if ($roomsToEnable > 0) { $hotelRoomInformation = new HotelRoomInformation($disableRoom['id']); $objRoomDisableDates = new HotelRoomDisableDates(); @@ -572,13 +562,15 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 'HotelRoomTypeFeaturePricing' ); } - die; + + $result = array(); if (count($this->errors)) { $result['status'] = 'failed'; $result['errors'] = $this->errors; } else { $result['status'] = 'success'; } + return $result; } diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemand.php b/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemand.php index 285cbaa27..b5b6bfa17 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemand.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemand.php @@ -100,7 +100,7 @@ class HotelRoomTypeGlobalDemand extends ObjectModel } if ($cartChanged) { if (Validate::isLoadedObject($objCartBooking = new HotelCartBookingData($demandInfo['id']))) { - $objCartBooking->extra_demands = Tools::jsonEncode($demandInfo['extra_demands']); + $objCartBooking->extra_demands = json_encode($demandInfo['extra_demands']); $objCartBooking->save(); } } diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemandAdvanceOption.php b/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemandAdvanceOption.php index 398aa7545..282139aff 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemandAdvanceOption.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeGlobalDemandAdvanceOption.php @@ -80,7 +80,7 @@ class HotelRoomTypeGlobalDemandAdvanceOption extends ObjectModel } if ($cartChanged) { if (Validate::isLoadedObject($objCartBooking = new HotelCartBookingData($demandInfo['id']))) { - $objCartBooking->extra_demands = Tools::jsonEncode($demandInfo['extra_demands']); + $objCartBooking->extra_demands = json_encode($demandInfo['extra_demands']); $objCartBooking->save(); } } diff --git a/modules/hotelreservationsystem/classes/QloRoomType.php b/modules/hotelreservationsystem/classes/QloRoomType.php index 3aa606312..c5bc3ac02 100644 --- a/modules/hotelreservationsystem/classes/QloRoomType.php +++ b/modules/hotelreservationsystem/classes/QloRoomType.php @@ -156,7 +156,7 @@ class QloRoomType extends QloWebservice // } // // convert object to array - // $address = Tools::jsonDecode(Tools::jsonEncode($address), true); + // $address = json_decode(json_encode($address), true); // $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('address', array()); // $address['country'] = Country::getNameById($this->id_lang, $address['id_country']); diff --git a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementQlo.php b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementQlo.php index 959aa6c45..11280b267 100644 --- a/modules/hotelreservationsystem/classes/WebserviceSpecificManagementQlo.php +++ b/modules/hotelreservationsystem/classes/WebserviceSpecificManagementQlo.php @@ -80,7 +80,7 @@ class WebserviceSpecificManagementQlo implements WebserviceSpecificManagementInt $outputXML = $this->objOutput->getObjectRender()->overrideContent($this->output); if (isset($this->wsObject->urlFragments['outputformat']) && $this->wsObject->urlFragments['outputformat'] == 'json') { $outputXML = simplexml_load_string($outputXML, null, LIBXML_NOCDATA); - $json = Tools::jsonEncode($outputXML); + $json = json_encode($outputXML); $content = preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", $json); header('Content-Type: application/json'); die($content); @@ -153,7 +153,7 @@ class WebserviceSpecificManagementQlo implements WebserviceSpecificManagementInt } } else { // If input type is json - $array = Tools::jsonDecode($inputXML, true); + $array = json_decode($inputXML, true); if (isset($array['json']) && $array['json'] && isset($array[$head])) { return ($head ? $array[$head] : $array); } else { @@ -172,7 +172,7 @@ class WebserviceSpecificManagementQlo implements WebserviceSpecificManagementInt $xmlEntities = $xml->children(); // Convert multi-dimention xml into an array - $array = Tools::jsonDecode(Tools::jsonEncode($xmlEntities), true); + $array = json_decode(json_encode($xmlEntities), true); return ($head ? $array[$head] : $array); } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 9e943ae9c..b8d9921d9 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -493,7 +493,7 @@ class AdminAddHotelController extends ModuleAdminController } } } - die(Tools::jsonEncode($states)); + die(json_encode($states)); } public function ajaxProcessUploadHotelImages() @@ -514,19 +514,19 @@ class AdminAddHotelController extends ModuleAdminController $hotelImgPath = _PS_MODULE_DIR_.'hotelreservationsystem/views/img/hotel_img/'; $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel, $hotelImgPath); if ($imageDetail) { - die(Tools::jsonEncode($imageDetail)); + die(json_encode($imageDetail)); } else { - die(Tools::jsonEncode(array('hasError' => true))); + die(json_encode(array('hasError' => true))); } } else { die( - Tools::jsonEncode( + json_encode( array('hasError' => true, 'message' => $_FILES['hotel_image']['name'].': '.$invalidImg) ) ); } } else { - die(Tools::jsonEncode(array('hasError' => true))); + die(json_encode(array('hasError' => true))); } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 24c94a068..27b7f0694 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -190,7 +190,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController } } if ($objFeaturePrice->special_days) { - $smartyVars['special_days'] = Tools::jsonDecode($objFeaturePrice->special_days, true); + $smartyVars['special_days'] = json_decode($objFeaturePrice->special_days, true); } $smartyVars['objFeaturePrice'] = $objFeaturePrice; $smartyVars['edit'] = 1; @@ -247,7 +247,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $impactValue = Tools::getValue('impact_value'); $dateSelectionType = Tools::getValue('date_selection_type'); $specificDate = date('Y-m-d', strtotime(Tools::getValue('specific_date'))); - $jsonSpecialDays = Tools::jsonEncode($specialDays); + $jsonSpecialDays = json_encode($specialDays); $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); $objFeaturePricing = new HotelRoomTypeFeaturePricing(); @@ -437,18 +437,18 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $product['name'].= ' / '.$onjBranchInfo->hotel_name; } } - echo Tools::jsonEncode($productsByName, true); + echo json_encode($productsByName, true); die; } else { die( - Tools::jsonEncode( + json_encode( array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) ) ); } } else { die( - Tools::jsonEncode( + json_encode( array('status' => 'failed', 'msg' => $this->l('No match found for entered room type name.')) ) ); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php index 56eff9819..1d14a138c 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelRoomsBookingController.php @@ -292,7 +292,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $hotel_id = Tools::getValue('hotel_id'); $obj_room_type = new HotelRoomType(); $room_type_info = $obj_room_type->getRoomTypeByHotelId($hotel_id, Configuration::get('PS_LANG_DEFAULT'), 1); - die(Tools::jsonEncode($room_type_info)); + die(json_encode($room_type_info)); } public function ajaxProcessAddDataToCart() @@ -412,7 +412,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController 'id_cart_book_data' => $obj_cart_book_data->id); if ($obj_cart_book_data->id) { - die(Tools::jsonEncode($cart_data)); + die(json_encode($cart_data)); } else { die(0); } @@ -495,7 +495,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController 'booking_data' => $booking_data, ); } - die(Tools::jsonEncode($cart_data)); + die(json_encode($cart_data)); } else { die(0); } @@ -534,7 +534,7 @@ class AdminHotelRoomsBookingController extends ModuleAdminController $start_date = date('Y-m-d', strtotime('+1 day', strtotime($start_date))); } if ($booking_calendar_data) { - die(Tools::jsonEncode($booking_calendar_data)); + die(json_encode($booking_calendar_data)); } else { die(0); } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php index cabdc0492..54c783038 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminOrderRefundRequestsController.php @@ -261,15 +261,14 @@ class AdminOrderRefundRequestsController extends ModuleAdminController /*If Admin update the status of the order cancellation request*/ if (Tools::isSubmit('submitRefundReqBookings')) { $idOrderReturn = Tools::getValue('id_order_return'); + $idsReturnDetail = Tools::getValue('id_order_return_detail'); if (Validate::isLoadedObject($objOrderReturn = new OrderReturn($idOrderReturn))) { $objOrder = new Order($objOrderReturn->id_order); + $hasOrderPaid = $objOrder->hasBeenPaid(); $idRefundState = Tools::getValue('id_refund_state'); if (Validate::isLoadedObject($objRefundState = new OrderReturnState($idRefundState))) { if ($objRefundState->refunded) { $refundedAmounts = Tools::getValue('refund_amounts'); - $idsReturnDetail = Tools::getValue('id_order_return_detail'); - - $hasOrderPaid = $objOrder->hasBeenPaid(); if ($hasOrderPaid) { if ($idsReturnDetail && count($idsReturnDetail)) { diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 70fa33c49..9325ed028 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -29,7 +29,7 @@ class hotelreservationsystem extends Module public function __construct() { $this->name = 'hotelreservationsystem'; - $this->version = '1.4.1'; + $this->version = '1.4.2'; $this->author = 'Webkul'; $this->need_instance = 0; $this->bootstrap = true; @@ -299,7 +299,7 @@ class hotelreservationsystem extends Module if (Validate::isLoadedObject( $objCartBooking = new HotelCartBookingData($demandInfo['id']) )) { - $objCartBooking->extra_demands = Tools::jsonEncode($demandInfo['extra_demands']); + $objCartBooking->extra_demands = json_encode($demandInfo['extra_demands']); $objCartBooking->save(); } } @@ -411,7 +411,7 @@ class hotelreservationsystem extends Module $idLang ))) { $objHtlBkDtl->hotel_name = $objHotelBranch->hotel_name; - $objHtlBkDtl->room_type_name = $product['product_name']; + $objHtlBkDtl->room_type_name = $product['name']; $objHtlBkDtl->city = $objHotelBranch->city; $objHtlBkDtl->state = State::getNameById($objHotelBranch->state_id); $objHtlBkDtl->country = Country::getNameById($idLang, $objHotelBranch->country_id); @@ -443,7 +443,7 @@ class hotelreservationsystem extends Module if ($objHtlBkDtl->save()) { // save extra demands info if ($objCartBkData->extra_demands - && ($extraDemands = Tools::jsonDecode($objCartBkData->extra_demands, true)) + && ($extraDemands = json_decode($objCartBkData->extra_demands, true)) ) { $objRoomDemandPrice = new HotelRoomTypeDemandPrice(); foreach ($extraDemands as $demand) { diff --git a/modules/paypal/api/ApiPaypalPlus.php b/modules/paypal/api/ApiPaypalPlus.php index 21550cdea..56fd693b7 100644 --- a/modules/paypal/api/ApiPaypalPlus.php +++ b/modules/paypal/api/ApiPaypalPlus.php @@ -99,7 +99,7 @@ class ApiPaypalPlus /* * Init variable */ - $oPayPalToken = Tools::jsonDecode($result); + $oPayPalToken = json_decode($result); if (isset($oPayPalToken->error)) { return false; @@ -159,7 +159,7 @@ class ApiPaypalPlus 'Authorization:Bearer '.$accessToken, ); - $result = Tools::jsonDecode($this->sendByCURL(URL_PPP_WEBPROFILE, Tools::jsonEncode($data), $header)); + $result = json_decode($this->sendByCURL(URL_PPP_WEBPROFILE, json_encode($data), $header)); if (isset($result->id)) { return $result->id; } else { @@ -189,7 +189,7 @@ class ApiPaypalPlus 'Authorization:Bearer '.$accessToken, ); - return Tools::jsonDecode($this->sendByCURL(URL_PPP_WEBPROFILE, false, $header)); + return json_decode($this->sendByCURL(URL_PPP_WEBPROFILE, false, $header)); } } @@ -358,7 +358,7 @@ class ApiPaypalPlus 'Authorization:Bearer '.$access_token, ); - $result = $this->sendByCURL(URL_PPP_CREATE_PAYMENT, Tools::jsonEncode($data), $header); + $result = $this->sendByCURL(URL_PPP_CREATE_PAYMENT, json_encode($data), $header); return $result; } diff --git a/modules/paypal/api/CallApiPaypalPlus.php b/modules/paypal/api/CallApiPaypalPlus.php index 22fce69d8..80444cb9e 100644 --- a/modules/paypal/api/CallApiPaypalPlus.php +++ b/modules/paypal/api/CallApiPaypalPlus.php @@ -57,7 +57,7 @@ class CallApiPaypalPlus extends ApiPaypalPlus if ($accessToken != false) { - $result = Tools::jsonDecode($this->createPayment($this->customer, $this->cart, $accessToken)); + $result = json_decode($this->createPayment($this->customer, $this->cart, $accessToken)); if (isset($result->links)) { @@ -105,7 +105,7 @@ class CallApiPaypalPlus extends ApiPaypalPlus ); $data = array('payer_id' => $payer_id); - $response = $this->sendByCURL(URL_PPP_EXECUTE_PAYMENT.$paymentId.'/execute/', Tools::jsonEncode($data), $header); + $response = $this->sendByCURL(URL_PPP_EXECUTE_PAYMENT.$paymentId.'/execute/', json_encode($data), $header); return $response; } @@ -124,7 +124,7 @@ class CallApiPaypalPlus extends ApiPaypalPlus 'Authorization:Bearer '.$accessToken, ); - return $this->sendByCURL(URL_PPP_EXECUTE_REFUND.$paymentId.'/refund', Tools::jsonEncode($data), $header); + return $this->sendByCURL(URL_PPP_EXECUTE_REFUND.$paymentId.'/refund', json_encode($data), $header); } public function patch($id_payment, $address) @@ -203,7 +203,7 @@ class CallApiPaypalPlus extends ApiPaypalPlus 'Content-Type:application/json', 'Authorization:Bearer '.$accessToken, ); - $body = str_replace('\/transactions\/0\/item_list\/shipping_address', '/transactions/0/item_list/shipping_address', Tools::jsonEncode($payment)); + $body = str_replace('\/transactions\/0\/item_list\/shipping_address', '/transactions/0/item_list/shipping_address', json_encode($payment)); return $this->sendByCURL(URL_PPP_PATCH.$id_payment, $body, $header, false, 'PATCH'); } } diff --git a/modules/paypal/api/sdk/braintree/lib/Braintree/Digest.php b/modules/paypal/api/sdk/braintree/lib/Braintree/Digest.php index ec6d9e090..c859c61b2 100644 --- a/modules/paypal/api/sdk/braintree/lib/Braintree/Digest.php +++ b/modules/paypal/api/sdk/braintree/lib/Braintree/Digest.php @@ -52,8 +52,8 @@ class Digest $outerPad = str_repeat(chr(0x5C), 64); for ($i = 0; $i < 20; $i++) { - $innerPad{$i} = $keyDigest{$i} ^ $innerPad{$i}; - $outerPad{$i} = $keyDigest{$i} ^ $outerPad{$i}; + $innerPad[$i] = $keyDigest[$i] ^ $innerPad[$i]; + $outerPad[$i] = $keyDigest[$i] ^ $outerPad[$i]; } return sha1($outerPad.pack($pack, sha1($innerPad.$message))); diff --git a/modules/paypal/api/sdk/braintree/lib/Braintree/Util.php b/modules/paypal/api/sdk/braintree/lib/Braintree/Util.php index 23d4af6bf..0a7757ce5 100644 --- a/modules/paypal/api/sdk/braintree/lib/Braintree/Util.php +++ b/modules/paypal/api/sdk/braintree/lib/Braintree/Util.php @@ -202,7 +202,7 @@ class Util // every time this function is called. static $callback = null; if ($callback === null) { - $callback = create_function('$matches', 'return strtoupper($matches[1]);'); + $callback = function ($matches) { return strtoupper($matches[1]); }; } return preg_replace_callback('/' . $delimiter . '(\w)/', $callback, $string); diff --git a/modules/paypal/classes/Braintree.php b/modules/paypal/classes/Braintree.php index f62147ed7..4f24350f2 100644 --- a/modules/paypal/classes/Braintree.php +++ b/modules/paypal/classes/Braintree.php @@ -306,7 +306,7 @@ class PrestaBraintree curl_close($ch); - $json = Tools::jsonDecode($resp); + $json = json_decode($resp); Configuration::updateValue('PAYPAL_BRAINTREE_ACCESS_TOKEN', $json->data->accessToken); Configuration::updateValue('PAYPAL_BRAINTREE_REFRESH_TOKEN', $json->data->refreshToken); diff --git a/modules/paypal/controllers/front/submitplus.php b/modules/paypal/controllers/front/submitplus.php index 78b360932..2b6fcab58 100644 --- a/modules/paypal/controllers/front/submitplus.php +++ b/modules/paypal/controllers/front/submitplus.php @@ -68,7 +68,7 @@ class PayPalSubmitplusModuleFrontController extends ModuleFrontController if (!empty($this->id_cart) && !empty($this->paymentId) && !empty($this->token)) { $CallApiPaypalPlus = new CallApiPaypalPlus(); - $payment = Tools::jsonDecode($CallApiPaypalPlus->lookUpPayment($this->paymentId)); + $payment = json_decode($CallApiPaypalPlus->lookUpPayment($this->paymentId)); if (isset($payment->state)) { $this->context->smarty->assign('state', $payment->state); @@ -172,7 +172,7 @@ class PayPalSubmitplusModuleFrontController extends ModuleFrontController $return = array(); if (!$ajax) { $return['error'][] = $this->module->l('An error occured during the payment'); - echo Tools::jsonEncode($return); + echo json_encode($return); die(); } @@ -187,7 +187,7 @@ class PayPalSubmitplusModuleFrontController extends ModuleFrontController && !empty($submit) ) { $CallApiPaypalPlus = new CallApiPaypalPlus(); - $payment = Tools::jsonDecode($CallApiPaypalPlus->executePayment($payerID, $paymentId)); + $payment = json_decode($CallApiPaypalPlus->executePayment($payerID, $paymentId)); if (isset($payment->state)) { @@ -230,7 +230,7 @@ class PayPalSubmitplusModuleFrontController extends ModuleFrontController $paypal_plus_pui = new PaypalPlusPui(); $paypal_plus_pui->id_order = $id_order; - $paypal_plus_pui->pui_informations = Tools::jsonEncode($payment->payment_instruction); + $paypal_plus_pui->pui_informations = json_encode($payment->payment_instruction); $paypal_plus_pui->save(); } @@ -254,7 +254,7 @@ class PayPalSubmitplusModuleFrontController extends ModuleFrontController $return['error'][] = $this->module->l('An error occured during the payment'); } - echo Tools::jsonEncode($return); + echo json_encode($return); die(); } diff --git a/modules/paypal/integral_evolution/notifier.php b/modules/paypal/integral_evolution/notifier.php index be2f95eab..24b32f21f 100644 --- a/modules/paypal/integral_evolution/notifier.php +++ b/modules/paypal/integral_evolution/notifier.php @@ -108,6 +108,6 @@ class PayPalNotifier extends PayPal if ($custom = Tools::getValue('custom')) { $notifier = new PayPalNotifier(); - $result = Tools::jsonDecode($custom, true); + $result = json_decode($custom, true); $notifier->confirmOrder($result); } diff --git a/modules/paypal/ipn.php b/modules/paypal/ipn.php index 55cb90d4b..20f1282ae 100644 --- a/modules/paypal/ipn.php +++ b/modules/paypal/ipn.php @@ -148,7 +148,7 @@ class PayPalIPN extends PayPal $cart_details = Context::getContext()->cart->getSummaryDetails(null, true); $cart_hash = sha1(serialize(Context::getContext()->cart->nbProducts())); - $custom = Tools::jsonDecode(Tools::getValue('custom'), true); + $custom = json_decode(Tools::getValue('custom'), true); $shipping = $cart_details['total_shipping_tax_exc']; $subtotal = $cart_details['total_price_without_tax'] - $cart_details['total_shipping_tax_exc']; @@ -234,7 +234,7 @@ if (Tools::getValue('receiver_email') == Configuration::get('PAYPAL_BUSINESS_ACC if (Tools::getIsset('custom')) { $ipn = new PayPalIPN(); - $custom = Tools::jsonDecode(Tools::getValue('custom'), true); + $custom = json_decode(Tools::getValue('custom'), true); $ipn->confirmOrder($custom); } } diff --git a/modules/paypal/paypal.php b/modules/paypal/paypal.php index 67f1c3c06..b79adf57a 100644 --- a/modules/paypal/paypal.php +++ b/modules/paypal/paypal.php @@ -699,7 +699,7 @@ class PayPal extends PaymentModule //'PayPal_version_tls_checked' => $tls_version, 'Presta_version' => _PS_VERSION_, 'Currencies' => Currency::getCurrencies(), - 'PayPal_account_braintree' => (array) Tools::jsonDecode(Configuration::get('PAYPAL_ACCOUNT_BRAINTREE')), + 'PayPal_account_braintree' => (array) json_decode(Configuration::get('PAYPAL_ACCOUNT_BRAINTREE')), 'Currency_default'=> Configuration::get('PS_CURRENCY_DEFAULT'), //*TO DELETE* 'PayPal_braintree_public_key'=> Configuration::get('PAYPAL_BRAINTREE_PUBLIC_KEY'), //*TO DELETE* 'PayPal_braintree_private_key'=> Configuration::get('PAYPAL_BRAINTREE_PRIVATE_KEY'), @@ -1070,7 +1070,7 @@ class PayPal extends PaymentModule 'currency' => new Currency((int) $cart->id_currency), 'customer' => $this->context->customer, 'business_account' => Configuration::get('PAYPAL_BUSINESS_ACCOUNT'), - 'custom' => Tools::jsonEncode(array('id_cart' => $cart->id, 'hash' => sha1(serialize($cart->nbProducts())))), + 'custom' => json_encode(array('id_cart' => $cart->id, 'hash' => sha1(serialize($cart->nbProducts())))), 'gift_price' => (float) $this->getGiftWrappingPrice(), 'billing_address' => $billing_address, 'delivery_address' => $delivery_address, @@ -1879,7 +1879,7 @@ class PayPal extends PaymentModule } $account_brain = Tools::getValue('account_braintree'); - Configuration::updateValue('PAYPAL_ACCOUNT_BRAINTREE', Tools::jsonEncode($account_brain)); + Configuration::updateValue('PAYPAL_ACCOUNT_BRAINTREE', json_encode($account_brain)); $this->context->smarty->assign('PayPal_save_success', true); @@ -1985,7 +1985,7 @@ class PayPal extends PaymentModule $callApiPaypalPlus = new CallApiPaypalPlus(); - return Tools::jsonDecode($callApiPaypalPlus->executeRefund($id_transaction, $params)); + return json_decode($callApiPaypalPlus->executeRefund($id_transaction, $params)); } } @@ -2052,7 +2052,7 @@ class PayPal extends PaymentModule $message = $this->l('Refund operation result:')." \r\n"; foreach ($response as $key => $value) { if (is_object($value) || is_array($value)) { - $message .= $key.': '.Tools::jsonEncode($value)." \r\n"; + $message .= $key.': '.json_encode($value)." \r\n"; } else { $message .= $key.': '.$value." \r\n"; } @@ -2550,9 +2550,9 @@ class PayPal extends PaymentModule // check digit-by-digit, if they have a difference, return 1 or -1 (greater/lower than) for ($i = 0; $i < Tools::strlen($num1); $i++) { - if ((int) $num1{$i} > (int) $num2{$i}) { + if ((int) $num1[$i] > (int) $num2[$i]) { return 1; - } elseif ((int) $num1{$i} < (int) $num2{$i}) { + } elseif ((int) $num1[$i] < (int) $num2[$i]) { return -1; } @@ -2575,7 +2575,7 @@ class PayPal extends PaymentModule 'address_billing' => new Address($this->context->cart->id_address_invoice), 'cart' => $this->context->cart, 'patternRules' => array('avoid' => array()), - 'cart_image_size' => version_compare(_PS_VERSION_, '1.5', '<') ? 'small' : version_compare(_PS_VERSION_, '1.6', '<') ? 'small_default' : 'cart_default', + 'cart_image_size' => version_compare(_PS_VERSION_, '1.5', '<') ? 'small' : (version_compare(_PS_VERSION_, '1.6', '<') ? 'small_default' : 'cart_default'), 'useStyle14' => version_compare(_PS_VERSION_, '1.5', '<'), 'useStyle15' => version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.6', '<'), )); @@ -2587,7 +2587,7 @@ class PayPal extends PaymentModule public function set_good_context() { - $account_braintree = Tools::jsonDecode(Configuration::get('PAYPAL_ACCOUNT_BRAINTREE'), true); + $account_braintree = json_decode(Configuration::get('PAYPAL_ACCOUNT_BRAINTREE'), true); $currency = new Currency($this->context->cart->id_currency); $this->context_modified = false; $this->id_currency_origin_cart = $this->context->cart->id_currency; @@ -2616,7 +2616,7 @@ class PayPal extends PaymentModule if (Validate::isLoadedObject($order = new Order($params['object']->id_order))) { if ($order->module == $this->name) { $order_detail = PaypalPlusPui::getByIdOrder($params['object']->id_order); - $information = Tools::jsonDecode($order_detail['pui_informations'], true); + $information = json_decode($order_detail['pui_informations'], true); $tab = ' diff --git a/modules/paypal/paypal_login/paypal_login.php b/modules/paypal/paypal_login/paypal_login.php index c497066dc..3e14d73be 100644 --- a/modules/paypal/paypal_login/paypal_login.php +++ b/modules/paypal/paypal_login/paypal_login.php @@ -103,7 +103,7 @@ class PayPalLogin fclose($handle); }*/ - $result = Tools::jsonDecode($result); + $result = json_decode($result); if ($result) { @@ -161,7 +161,7 @@ class PayPalLogin } */ - $result = Tools::jsonDecode($result); + $result = json_decode($result); if ($result) { $login->access_token = $result->access_token; @@ -199,7 +199,7 @@ class PayPalLogin } */ - $result = Tools::jsonDecode($result); + $result = json_decode($result); if ($result) { $customer = new Customer(); diff --git a/modules/paypal/paypal_plus/submit.php b/modules/paypal/paypal_plus/submit.php index edd6e6cfe..c0a231522 100644 --- a/modules/paypal/paypal_plus/submit.php +++ b/modules/paypal/paypal_plus/submit.php @@ -70,7 +70,7 @@ function displayConfirm($context) if (!empty($id_cart) && !empty($paymentId) && !empty($token)) { $CallApiPaypalPlus = new CallApiPaypalPlus(); - $payment = Tools::jsonDecode($CallApiPaypalPlus->lookUpPayment($paymentId)); + $payment = json_decode($CallApiPaypalPlus->lookUpPayment($paymentId)); if (isset($payment->state)) { $context->smarty->assign('state', $payment->state); @@ -158,7 +158,7 @@ function displayAjax($context) include_once _PS_MODULE_DIR_.'paypal/paypal.php'; $CallApiPaypalPlus = new CallApiPaypalPlus(); - $payment = Tools::jsonDecode($CallApiPaypalPlus->executePayment($payerID, $paymentId)); + $payment = json_decode($CallApiPaypalPlus->executePayment($payerID, $paymentId)); if (isset($payment->state)) { $transaction = array( @@ -198,7 +198,7 @@ function displayAjax($context) $order = Order::getOrderByCartId($id_cart); $paypal_plus_pui = new PaypalPlusPui(); $paypal_plus_pui->id_order = $order->id; - $paypal_plus_pui->pui_informations = Tools::jsonEncode($payment->payment_instruction); + $paypal_plus_pui->pui_informations = json_encode($payment->payment_instruction); } } elseif ($submit == 'confirmCancel') { $paypal->validateOrder( @@ -220,7 +220,7 @@ function displayAjax($context) $return['error'][] = $paypal->l('An error occured during the payment'); } - echo Tools::jsonEncode($return); + echo json_encode($return); die(); } diff --git a/modules/productcomments/CHANGELOG.txt b/modules/productcomments/CHANGELOG.txt index 182de589f..8bc631883 100644 --- a/modules/productcomments/CHANGELOG.txt +++ b/modules/productcomments/CHANGELOG.txt @@ -1,3 +1,12 @@ +------------------------- +# V3.5.3 to V3.6.0 +------------------------- + +## Improved/changed features: + +[*] FO : [#185] Replaced star rating plugin with jquery Raty in Product Comments module + +[*] CO : [#178] Text Changes ------------------------- # V3.5.2 to V3.5.3 diff --git a/modules/productcomments/controllers/front/default.php b/modules/productcomments/controllers/front/default.php index 2f7196bcb..e53694ed3 100644 --- a/modules/productcomments/controllers/front/default.php +++ b/modules/productcomments/controllers/front/default.php @@ -144,7 +144,7 @@ class ProductCommentsDefaultModuleFrontController extends ModuleFrontController else $result = false; - die(Tools::jsonEncode(array( + die(json_encode(array( 'result' => $result, 'errors' => $errors ))); diff --git a/modules/productcomments/js/jquery.rating.pack.js b/modules/productcomments/js/jquery.rating.pack.js deleted file mode 100644 index 4921db739..000000000 --- a/modules/productcomments/js/jquery.rating.pack.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - ### jQuery Star Rating Plugin v2.0 - 2008-03-12 ### - By Diego A, http://www.fyneworks.com, diego@fyneworks.com - - v2 by Keith Wood, kbwood@virginbroadband.com.au - - Project: http://plugins.jquery.com/project/MultipleFriendlyStarRating - Website: http://www.fyneworks.com/jquery/star-rating/ - - This is a modified version of the star rating plugin from: - http://www.phpletter.com/Demo/Jquery-Star-Rating-Plugin/ -*/ -eval(function(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';4(w)(3($){$.Y.T=3(c){c=$.15({m:\'X U\',E:\'\',B:z,8:z},c||{});o d={};o e={t:3(n,a,b){2.6(n);$(a).D(\'.j\').A().l(b||\'x\')},6:3(n){$(d[n].7).O(\'.j\').u(\'9\').u(\'x\')},h:3(n){4(!$(d[n].5).Z(\'.m\')){$(d[n].5).D(\'.j\').A().l(\'9\')}},g:3(n,a){d[n].5=a;o b=$(a).L(\'a\').K();$(d[n].7).J(b);e.6(n);e.h(n);4(c.I)c.I.W(d[n].7,[b,a])}};2.V(3(i){o n=2.G;4(!d[n])d[n]={r:0};i=d[n].r;d[n].r++;4(i==0){c.8=$(2).S(\'p\')||c.8;d[n].7=$(\'\');$(2).C(d[n].7);4(c.8||c.B){}F{$(2).C($(\'\'+c.E+\'\').H(3(){e.6(n);$(2).l(\'9\')}).v(3(){e.h(n);$(2).u(\'9\')}).g(3(){e.g(n,2)}))}};f=$(\'\'+2.q+\'\');$(2).N(f);4(c.8){$(f).l(\'M\')}F{$(f).H(3(){e.6(n);e.t(n,2)}).v(3(){e.6(n);e.h(n)}).g(3(){e.g(n,2)})};4(2.14)d[n].5=f;$(2).13();4(i+1==2.12)e.h(n)});11(n 10 d)4(d[n].5){e.t(n,d[n].5,\'9\');$(d[n].7).J($(d[n].5).L(\'a\').K())}16 2}})(w);',62,69,'||this|function|if|currentElem|drain|valueElem|readOnly|star_on||||||eStar|click|reset||star|div|addClass|cancel||var|disabled|value|count|title|fill|removeClass|mouseout|jQuery|star_hover|class|false|andSelf|required|before|prevAll|cancelValue|else|name|mouseover|callback|val|text|children|star_readonly|after|siblings|hidden|type|input|attr|rating|Rating|each|apply|Cancel|fn|is|in|for|length|remove|checked|extend|return'.split('|'),0,{})); \ No newline at end of file diff --git a/modules/productcomments/js/productcomments.js b/modules/productcomments/js/productcomments.js index 0f81eeb0f..bf1712ce9 100644 --- a/modules/productcomments/js/productcomments.js +++ b/modules/productcomments/js/productcomments.js @@ -23,9 +23,17 @@ * International Registered Trademark & Property of PrestaShop SA */ $(document).ready(function(){ - $('input.star').rating(); - $('.auto-submit-star').rating(); - + $('.raty_star').raty({ + starType : 'i', + starOff: 'icon-star-o', + starOn: 'icon-star', + halfShow: false, + score: 3, + hints: null, + readOnly: function() { + return $(this).hasClass('readonly'); + } + }); $('#new_comment_tab_btn').on('click', function(e){ e.preventDefault(); $('.new_comment_form_outer').show(); diff --git a/modules/productcomments/lib/index.php b/modules/productcomments/lib/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/modules/productcomments/lib/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/modules/productcomments/lib/jquery.raty.js b/modules/productcomments/lib/jquery.raty.js new file mode 100644 index 000000000..5b987772d --- /dev/null +++ b/modules/productcomments/lib/jquery.raty.js @@ -0,0 +1,770 @@ +/*! + * Raty - A Star Rating Plugin + * + * The MIT License + * + * author: Washington Botelho + * github: wbotelhos/raty + * version: 3.0.0 + * + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + define(['jquery'], factory); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(require('jquery')); + } else { + factory(root.jQuery); + } +}(this, function($) { + 'use strict'; + + $.raty = { + cancelButton: false, + cancelClass: 'raty-cancel', + cancelHint: 'Cancel this rating!', + cancelOff: 'cancel-off.png', + cancelOn: 'cancel-on.png', + cancelPlace: 'left', + click: undefined, + half: false, + halfShow: true, + hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'], + iconRange: undefined, + mouseout: undefined, + mouseover: undefined, + noRatedMsg: 'Not rated yet!', + number: 5, + numberMax: 20, + path: undefined, + precision: false, + readOnly: false, + round: { down: 0.25, full: 0.6, up: 0.76 }, + score: undefined, + scoreName: 'score', + single: false, + space: true, + starHalf: 'star-half.png', + starOff: 'star-off.png', + starOn: 'star-on.png', + starType: 'img', + target: undefined, + targetFormat: '{score}', + targetKeep: false, + targetScore: undefined, + targetText: '', + targetType: 'hint' + }; + + $.fn.raty = function(options) { + return this.each(function() { + var instance = new $.raty.Raty(this, options); + + return instance._create(); + }); + }; + + $.raty.Raty = (function() { + var Raty = function(element, options) { + this.element = element; + this.self = $(element); + this.opt = $.extend(true, {}, $.raty, options, this.self.data()); + }; + + Raty.prototype = { + _create: function() { + this._executeCallbacks(); + this._adjustNumber(); + this._adjustHints(); + + this.opt.score = this._adjustedScore(this.opt.score); + + if (this.opt.starType !== 'img') { + this._adjustStarName(); + } + + this._setPath(); + this._createStars(); + + if (this.opt.cancelButton) { + this._createCancel(); + } + + if (this.opt.precision) { + this._adjustPrecision(); + } + + this._createScore(); + + this._apply(this.opt.score); + this._setTitle(this.opt.score); + this._target(this.opt.score); + + if (this.opt.readOnly) { + this._lock(); + } else { + this.element.style.cursor = 'pointer'; + + this._binds(); + } + + this.self.data('raty', this); + }, + + // TODO: model spec + _adjustedScore: function(score) { + if (score || score === 0) { + return this._between(score, 0, this.opt.number); + } + }, + + _adjustHints: function() { + if (!this.opt.hints) { + this.opt.hints = []; + } + + if (!this.opt.halfShow && !this.opt.half) { + return; + } + + var steps = this.opt.precision ? 10 : 2; + + for (var i = 0; i < this.opt.number; i++) { + var group = this.opt.hints[i]; + + if (Object.prototype.toString.call(group) !== '[object Array]') { + group = [group]; + } + + this.opt.hints[i] = []; + + for (var j = 0; j < steps; j++) { + var hint = group[j]; + var last = group[group.length - 1]; + + if (last === undefined) { + last = null; + } + + this.opt.hints[i][j] = hint === undefined ? last : hint; + } + } + }, + + _adjustNumber: function() { + this.opt.number = this._between(this.opt.number, 1, this.opt.numberMax); + }, + + _adjustPrecision: function() { + this.opt.half = true; + }, + + _adjustStarName: function() { + var replaces = ['cancelOff', 'cancelOn', 'starHalf', 'starOff', 'starOn']; + + this.opt.path = ''; + + for (var i = 0; i < replaces.length; i++) { + this.opt[replaces[i]] = this.opt[replaces[i]].replace('.', '-'); + } + }, + + // TODO: model spec + _apply: function(score) { + this._fill(score); + + if (score) { + if (score > 0) { + this.scoreField.val(score); + } + + this._roundStars(score); + } + }, + + _attributesForIndex: function(i) { + var name = this._nameForIndex(i); + var attributes = { alt: i, src: this.opt.path + this.opt[name] }; + + if (this.opt.starType !== 'img') { + attributes = { 'data-alt': i, 'class': this.opt[name] }; + } + + attributes.title = this._getHint(i); + + return attributes; + }, + + _between: function(value, min, max) { + return Math.min(Math.max(parseFloat(value), min), max); + }, + + // TODO: model spec + _binds: function() { + if (this.cancelButton) { + this._bindOverCancel(); + this._bindClickCancel(); + this._bindOutCancel(); + } + + this._bindOver(); + this._bindClick(); + this._bindOut(); + }, + + // TODO: model spec + _bindClick: function() { + var that = this; + + this.stars.on('click.raty', function(evt) { + if (that.self.data('readonly')) { + return; + } + + var execute = true; + var score = (that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || $(this).data('alt')); + + if (that.opt.half && !that.opt.precision) { + score = that._roundHalfScore(score); + } + + if (that.opt.click) { + execute = that.opt.click.call(that.element, +score, evt); + } + + if (execute || execute === undefined) { + that._apply(+score); + } + }); + }, + + // TODO: model spec + _bindClickCancel: function() { + this.cancelButton.on('click.raty', function(evt) { + this.scoreField.removeAttr('value'); + + if (this.opt.click) { + this.opt.click.call(this.element, null, evt); + } + }.bind(this)); + }, + + // TODO: model spec + _bindOut: function() { + this.self.on('mouseleave.raty', function(evt) { + var score = +this.scoreField.val() || undefined; + + this._apply(score); + this._target(score, evt); + this._resetTitle(); + + if (this.opt.mouseout) { + this.opt.mouseout.call(this.element, score, evt); + } + }.bind(this)); + }, + + // TODO: model spec + _bindOutCancel: function() { + var that = this; + + this.cancelButton.on('mouseleave.raty', function(evt) { + var icon = that.opt.cancelOff; + + if (that.opt.starType !== 'img') { + icon = that.opt.cancelClass + ' ' + icon; + } + + that._setIcon(this, icon); + + if (that.opt.mouseout) { + var score = +that.scoreField.val() || undefined; + + that.opt.mouseout.call(that.element, score, evt); + } + }); + }, + + // TODO: model spec + _bindOver: function() { + var that = this; + var action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; + + this.stars.on(action, function(evt) { + var score = that._getScoreByPosition(evt, this); + + that._fill(score); + + if (that.opt.half) { + that._roundStars(score, evt); + that._setTitle(score, evt); + + that.self.data('score', score); + } + + that._target(score, evt); + + if (that.opt.mouseover) { + that.opt.mouseover.call(that.element, score, evt); + } + }); + }, + + // TODO: model spec + _bindOverCancel: function() { + var that = this; + + this.cancelButton.on('mouseover.raty', function(evt) { + if (that.self.data('readonly')) { + return; + } + + var starOff = that.opt.path + that.opt.starOff; + var icon = that.opt.cancelOn; + + if (that.opt.starType === 'img') { + that.stars.attr('src', starOff); + } else { + icon = that.opt.cancelClass + ' ' + icon; + + that.stars.attr('class', starOff); + } + + that._setIcon(this, icon); + that._target(null, evt); + + if (that.opt.mouseover) { + that.opt.mouseover.call(that.element, null); + } + }); + }, + + // TODO: model spec + _buildScoreField: function() { + return $('', { name: this.opt.scoreName, type: 'hidden' }).appendTo(this.self); + }, + + // TODO: model spec + _createCancel: function() { + var icon = this.opt.path + this.opt.cancelOff; + var button = $('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': this.opt.cancelClass }); + + if (this.opt.starType === 'img') { + button.attr({ src: icon, alt: 'x' }); + } else { + // TODO: use $.data + button.attr('data-alt', 'x').addClass(icon); + } + + if (this.opt.cancelPlace === 'left') { + this.self.prepend(' ').prepend(button); + } else { + this.self.append(' ').append(button); + } + + this.cancelButton = button; + }, + + // TODO: model spec + _createScore: function() { + var score = $(this.opt.targetScore); + + this.scoreField = score.length ? score : this._buildScoreField(); + }, + + _createStars: function() { + for (var i = 1; i <= this.opt.number; i++) { + var attributes = this._attributesForIndex(i); + + $('<' + this.opt.starType + ' />', attributes).appendTo(this.element); + + if (this.opt.space && i < this.opt.number) { + this.self.append(' '); + } + } + + this.stars = this.self.children(this.opt.starType); + }, + + // TODO: model spec + _error: function(message) { + $(this).text(message); + + $.error(message); + }, + + _executeCallbacks: function() { + var options = ['number', 'readOnly', 'score', 'scoreName', 'target', 'path']; + + for (var i = 0; i < options.length; i++) { + if (typeof this.opt[options[i]] === 'function') { + var value = this.opt[options[i]].call(this.element); + + if (value) { + this.opt[options[i]] = value; + } else { + delete this.opt[options[i]]; + } + } + } + }, + + // TODO: model spec + _fill: function(score) { + var hash = 0; + + for (var i = 1; i <= this.stars.length; i++) { + var icon; + var star = this.stars[i - 1]; + var turnOn = this._turnOn(i, score); + + if (this.opt.iconRange && this.opt.iconRange.length > hash) { + var irange = this.opt.iconRange[hash]; + + icon = this._getRangeIcon(irange, turnOn); + + if (i <= irange.range) { + this._setIcon(star, icon); + } + + if (i === irange.range) { + hash++; + } + } else { + icon = this.opt[turnOn ? 'starOn' : 'starOff']; + + this._setIcon(star, icon); + } + } + }, + + _getDecimal: function(number, fractions) { + var decimal = number.toString().split('.')[1]; + var result = 0; + + if (decimal) { + result = parseInt(decimal.slice(0, fractions), 10); + + if (decimal.slice(1, 5) === '9999') { + result++; + } + } + + return result; + }, + + // TODO: model spec + _getRangeIcon: function(irange, turnOn) { + return turnOn ? irange.on || this.opt.starOn : irange.off || this.opt.starOff; + }, + + // TODO: model spec + _getScoreByPosition: function(evt, icon) { + var score = parseInt(icon.alt || icon.getAttribute('data-alt'), 10); + + if (this.opt.half) { + var size = this._getWidth(); + var percent = parseFloat((evt.pageX - $(icon).offset().left) / size); + + score = score - 1 + percent; + } + + return score; + }, + + // TODO: model spec + _getHint: function(score, evt) { + if (score !== 0 && !score) { + return this.opt.noRatedMsg; + } + + var decimal = this._getDecimal(score, 1); + var integer = Math.ceil(score); + var group = this.opt.hints[(integer || 1) - 1]; + var hint = group; + var set = !evt || this.isMove; + + if (this.opt.precision) { + if (set) { + decimal = decimal === 0 ? 9 : decimal - 1; + } + + hint = group[decimal]; + } else if (this.opt.halfShow || this.opt.half) { + decimal = set && decimal === 0 ? 1 : decimal > 5 ? 1 : 0; + + hint = group[decimal]; + } + + return hint === '' ? '' : hint || score; + }, + + // TODO: model spec + _getWidth: function() { + var width = this.stars[0].width || parseFloat(this.stars.eq(0).css('font-size')); + + if (!width) { + this._error('Could not get the icon width!'); + } + + return width; + }, + + // TODO: model spec + _lock: function() { + var hint = this._getHint(this.scoreField.val()); + + this.element.style.cursor = ''; + this.element.title = hint; + + this.scoreField.prop('readonly', true); + this.stars.prop('title', hint); + + if (this.cancelButton) { + this.cancelButton.hide(); + } + + this.self.data('readonly', true); + }, + + _nameForIndex: function(i) { + return this.opt.score && this.opt.score >= i ? 'starOn' : 'starOff'; + }, + + // TODO: model spec + _resetTitle: function() { + for (var i = 0; i < this.opt.number; i++) { + this.stars[i].title = this._getHint(i + 1); + } + }, + + // TODO: model spec + _roundHalfScore: function(score) { + var integer = parseInt(score, 10); + var decimal = this._getDecimal(score, 1); + + if (decimal !== 0) { + decimal = decimal > 5 ? 1 : 0.5; + } + + return integer + decimal; + }, + + // TODO: model spec + _roundStars: function(score, evt) { + var name = this._starName(score, evt); + + if (name) { + var icon = this.opt[name]; + var star = this.stars[Math.ceil(score) - 1]; + + this._setIcon(star, icon); + } // Full down: [x.00 .. x.25] + }, + + // TODO: model spec + _setIcon: function(star, icon) { + star[this.opt.starType === 'img' ? 'src' : 'className'] = this.opt.path + icon; + }, + + _setPath: function() { + this.opt.path = this.opt.path || ''; + + if (this.opt.path && this.opt.path.slice(-1)[0] !== '/') { + this.opt.path += '/'; + } + }, + + // TODO: model spec + _setTarget: function(target, score) { + if (score) { + score = this.opt.targetFormat.toString().replace('{score}', score); + } + + if (target.is(':input')) { + target.val(score); + } else { + target.html(score); + } + }, + + // TODO: model spec + _setTitle: function(score, evt) { + if (score) { + var integer = parseInt(Math.ceil(score), 10); + var star = this.stars[integer - 1]; + + star.title = this._getHint(score, evt); + } + }, + + _starName: function(score, evt) { + var decimal = +(score % 1).toFixed(2); + + if (evt || this.isMove) { + return decimal > 0.5 ? 'starOn' : 'starHalf'; + } + + if (decimal <= this.opt.round.down) { // Down: [x.00 ... x.25] + return; + } + + if (this.opt.halfShow && decimal < this.opt.round.up) { // Half: [x.26 ... x.75] + return 'starHalf'; + } + + if (decimal < this.opt.round.full) { // Off: [x.26 .. x.6] + return 'starOff'; + } + + return 'starOn'; // Up: [x.26 ...] || [x.6 ...] + }, + + // TODO: model spec + _target: function(score, evt) { + if (this.opt.target) { + var target = $(this.opt.target); + + if (!target.length) { + this._error('Target selector invalid or missing!'); + } + + var mouseover = evt && evt.type === 'mouseover'; + + if (score === undefined) { + score = this.opt.targetText; + } else if (score === null) { + score = mouseover ? this.opt.cancelHint : this.opt.targetText; + } else { + if (this.opt.targetType === 'hint') { + score = this._getHint(score, evt); + } else if (this.opt.precision) { + score = parseFloat(score).toFixed(1); + } + + var mousemove = evt && evt.type === 'mousemove'; + + if (!mouseover && !mousemove && !this.opt.targetKeep) { + score = this.opt.targetText; + } + } + + this._setTarget(target, score); + } + }, + + // TODO: model spec + _turnOn: function(i, score) { + return this.opt.single ? (i === score) : (i <= score); + }, + + // TODO: model spec + _unlock: function() { + this.element.style.cursor = 'pointer'; + this.element.removeAttribute('title'); + + this.scoreField.removeAttr('readonly'); + + this.self.data('readonly', false); + + this._resetTitle(); + + if (this.cancelButton) { + this.cancelButton.css('display', ''); + } + }, + + // TODO: model spec + cancel: function(click) { + if (this.self.data('readonly') !== true) { + this[click ? 'click' : 'score'].call(this, null); + + this.scoreField.removeAttr('value'); + } + }, + + // TODO: model spec + click: function(score) { + if (this.self.data('readonly') !== true) { + score = this._adjustedScore(score); + + this._apply(score); + + if (this.opt.click) { + this.opt.click.call(this.element, score, $.Event('click')); + } + + this._target(score); + } + }, + + // TODO: model spec + getScore: function() { + var score = []; + var value ; + + value = this.scoreField.val(); + + score.push(value ? +value : undefined); + + return (score.length > 1) ? score : score[0]; + }, + + // TODO: model spec + move: function(score) { + var integer = parseInt(score, 10); + var decimal = this._getDecimal(score, 1); + + if (integer >= this.opt.number) { + integer = this.opt.number - 1; + decimal = 10; + } + + var width = this._getWidth(); + var steps = width / 10; + var star = $(this.stars[integer]); + var percent = star.offset().left + steps * decimal; + var evt = $.Event('mousemove', { pageX: percent }); + + this.isMove = true; + + star.trigger(evt); + + this.isMove = false; + }, + + // TODO: model spec + readOnly: function(readonly) { + if (this.self.data('readonly') !== readonly) { + if (readonly) { + this.self.off('.raty').children(this.opt.starType).off('.raty'); + + this._lock(); + } else { + this._binds(); + this._unlock(); + } + + this.self.data('readonly', readonly); + } + }, + + // TODO: model spec + score: function() { + return arguments.length ? this.setScore.apply(this, arguments) : this.getScore(); + }, + + setScore: function(score) { + if (this.self.data('readonly') !== true) { + score = this._adjustedScore(score); + + this._apply(score); + this._target(score); + } + } + }; + + return Raty; + })(); +})); diff --git a/modules/productcomments/productcomments-ajax.php b/modules/productcomments/productcomments-ajax.php index 770d261cc..f3ec718f3 100644 --- a/modules/productcomments/productcomments-ajax.php +++ b/modules/productcomments/productcomments-ajax.php @@ -52,7 +52,7 @@ if (Tools::getValue('action') && Tools::getValue('id_product_comment') && Contex } else if (Tools::getValue('action') && Tools::getValue('secure_key') == $productCom->secure_key) { - $review = Tools::jsonDecode(Tools::getValue('review')); + $review = json_decode(Tools::getValue('review')); $id_product = 0; $content = null; $title = null; diff --git a/modules/productcomments/productcomments.css b/modules/productcomments/productcomments.css index 34f088823..dba2824d0 100644 --- a/modules/productcomments/productcomments.css +++ b/modules/productcomments/productcomments.css @@ -7,22 +7,15 @@ margin: 39px 0 22px; } #product_comments_block_extra .comments_note { margin-bottom: 5px; } - #product_comments_block_extra .comments_note span, - #product_comments_block_extra .star_content { + #product_comments_block_extra .comments_note span{ float: left; color: #333; } - #product_comments_block_extra .star_content { - margin-top: 1px; } - #product_comments_block_extra div.star:after { - content: "\f006"; - font-family: "FontAwesome"; - display: inline-block; - color: #777676; } - #product_comments_block_extra div.star_on:after { - content: "\f005"; - font-family: "FontAwesome"; - display: inline-block; - color: #e9ce18; } + .raty_star i[class^="icon-"] { + font-size: 22px; + color: #e9ce18; + } .raty_star i.icon-star-o { + color: #777777; + } #product_comments_block_extra .comments_advices { clear: both; } diff --git a/modules/productcomments/productcomments.php b/modules/productcomments/productcomments.php index 0ca003205..b894c1f3e 100644 --- a/modules/productcomments/productcomments.php +++ b/modules/productcomments/productcomments.php @@ -42,7 +42,7 @@ class ProductComments extends Module { $this->name = 'productcomments'; $this->tab = 'front_office_features'; - $this->version = '3.5.3'; + $this->version = '3.6.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; @@ -156,6 +156,7 @@ class ProductComments extends Module $id_product_comment = (int)Tools::getValue('id_product_comment'); $comment = new ProductComment($id_product_comment); $comment->delete(); + $this->_html .= '
'.$this->l('Comment deleted').'
'; } elseif (Tools::isSubmit('submitEditCriterion')) { @@ -214,7 +215,8 @@ class ProductComments extends Module elseif ($id_product_comment = (int)Tools::getValue('approveComment')) { $comment = new ProductComment($id_product_comment); - $comment->validate(); + if($comment->validate()) + $this->_html .= '
'.$this->l('Comment approved').'
'; } elseif ($id_product_comment = (int)Tools::getValue('noabuseComment')) { @@ -827,7 +829,6 @@ class ProductComments extends Module public function hookProductTabContent($params) { - $this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js'); $this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js'); $this->context->controller->addJS($this->_path.'js/productcomments.js'); @@ -879,7 +880,7 @@ class ProductComments extends Module $this->page_name = Dispatcher::getInstance()->getController(); if (in_array($this->page_name, array('product', 'productscomparison'))) { - $this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js'); + $this->context->controller->addJS($this->_path.'lib/jquery.raty.js'); if (in_array($this->page_name, array('productscomparison'))) { $this->context->controller->addjqueryPlugin('cluetip'); diff --git a/modules/productcomments/productcomments.tpl b/modules/productcomments/productcomments.tpl index 39685ee2e..e9a73e1f7 100644 --- a/modules/productcomments/productcomments.tpl +++ b/modules/productcomments/productcomments.tpl @@ -24,90 +24,87 @@ *}
- {if $comments} - {if (!$too_early AND ($is_logged OR $allow_guests))} -

- - {l s='Make a review' mod='productcomments'} - -

- -
s with a . + + $ws_accum =& $initial_ws; + + foreach ($children as $node) { + if ($node instanceof HTMLPurifier_Node_Comment) { + $ws_accum[] = $node; + continue; + } + switch ($node->name) { + case 'tbody': + $tbody_mode = true; + // fall through + case 'tr': + $content[] = $node; + $ws_accum =& $content; + break; + case 'caption': + // there can only be one caption! + if ($caption !== false) break; + $caption = $node; + $ws_accum =& $after_caption_ws; + break; + case 'thead': + $tbody_mode = true; + // XXX This breaks rendering properties with + // Firefox, which never floats a to + // the top. Ever. (Our scheme will float the + // first to the top.) So maybe + // s that are not first should be + // turned into ? Very tricky, indeed. + if ($thead === false) { + $thead = $node; + $ws_accum =& $after_thead_ws; + } else { + // Oops, there's a second one! What + // should we do? Current behavior is to + // transmutate the first and last entries into + // tbody tags, and then put into content. + // Maybe a better idea is to *attach + // it* to the existing thead or tfoot? + // We don't do this, because Firefox + // doesn't float an extra tfoot to the + // bottom like it does for the first one. + $node->name = 'tbody'; + $content[] = $node; + $ws_accum =& $content; + } + break; + case 'tfoot': + // see above for some aveats + $tbody_mode = true; + if ($tfoot === false) { + $tfoot = $node; + $ws_accum =& $after_tfoot_ws; + } else { + $node->name = 'tbody'; + $content[] = $node; + $ws_accum =& $content; + } + break; + case 'colgroup': + case 'col': + $cols[] = $node; + $ws_accum =& $cols; + break; + case '#PCDATA': + // How is whitespace handled? We treat is as sticky to + // the *end* of the previous element. So all of the + // nonsense we have worked on is to keep things + // together. + if (!empty($node->is_whitespace)) { + $ws_accum[] = $node; + } + break; + } + } + + if (empty($content)) { + return false; + } + + $ret = $initial_ws; + if ($caption !== false) { + $ret[] = $caption; + $ret = array_merge($ret, $after_caption_ws); + } + if ($cols !== false) { + $ret = array_merge($ret, $cols); + } + if ($thead !== false) { + $ret[] = $thead; + $ret = array_merge($ret, $after_thead_ws); + } + if ($tfoot !== false) { + $ret[] = $tfoot; + $ret = array_merge($ret, $after_tfoot_ws); + } + + if ($tbody_mode) { + // we have to shuffle tr into tbody + $current_tr_tbody = null; + + foreach($content as $node) { + switch ($node->name) { + case 'tbody': + $current_tr_tbody = null; + $ret[] = $node; + break; + case 'tr': + if ($current_tr_tbody === null) { + $current_tr_tbody = new HTMLPurifier_Node_Element('tbody'); + $ret[] = $current_tr_tbody; + } + $current_tr_tbody->children[] = $node; + break; + case '#PCDATA': + //assert($node->is_whitespace); + if ($current_tr_tbody === null) { + $ret[] = $node; + } else { + $current_tr_tbody->children[] = $node; + } + break; + } + } + } else { + $ret = array_merge($ret, $content); + } + + return $ret; + + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ChildDef/index.php b/tools/htmlpurifier/HTMLPurifier/ChildDef/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ChildDef/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/Config.php b/tools/htmlpurifier/HTMLPurifier/Config.php new file mode 100644 index 000000000..3133d8a4f --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Config.php @@ -0,0 +1,920 @@ +defaultPlist; + $this->plist = new HTMLPurifier_PropertyList($parent); + $this->def = $definition; // keep a copy around for checking + $this->parser = new HTMLPurifier_VarParser_Flexible(); + } + + /** + * Convenience constructor that creates a config object based on a mixed var + * @param mixed $config Variable that defines the state of the config + * object. Can be: a HTMLPurifier_Config() object, + * an array of directives based on loadArray(), + * or a string filename of an ini file. + * @param HTMLPurifier_ConfigSchema $schema Schema object + * @return HTMLPurifier_Config Configured object + */ + public static function create($config, $schema = null) + { + if ($config instanceof HTMLPurifier_Config) { + // pass-through + return $config; + } + if (!$schema) { + $ret = HTMLPurifier_Config::createDefault(); + } else { + $ret = new HTMLPurifier_Config($schema); + } + if (is_string($config)) { + $ret->loadIni($config); + } elseif (is_array($config)) $ret->loadArray($config); + return $ret; + } + + /** + * Creates a new config object that inherits from a previous one. + * @param HTMLPurifier_Config $config Configuration object to inherit from. + * @return HTMLPurifier_Config object with $config as its parent. + */ + public static function inherit(HTMLPurifier_Config $config) + { + return new HTMLPurifier_Config($config->def, $config->plist); + } + + /** + * Convenience constructor that creates a default configuration object. + * @return HTMLPurifier_Config default object. + */ + public static function createDefault() + { + $definition = HTMLPurifier_ConfigSchema::instance(); + $config = new HTMLPurifier_Config($definition); + return $config; + } + + /** + * Retrieves a value from the configuration. + * + * @param string $key String key + * @param mixed $a + * + * @return mixed + */ + public function get($key, $a = null) + { + if ($a !== null) { + $this->triggerError( + "Using deprecated API: use \$config->get('$key.$a') instead", + E_USER_WARNING + ); + $key = "$key.$a"; + } + if (!$this->finalized) { + $this->autoFinalize(); + } + if (!isset($this->def->info[$key])) { + // can't add % due to SimpleTest bug + $this->triggerError( + 'Cannot retrieve value of undefined directive ' . htmlspecialchars($key), + E_USER_WARNING + ); + return; + } + if (isset($this->def->info[$key]->isAlias)) { + $d = $this->def->info[$key]; + $this->triggerError( + 'Cannot get value from aliased directive, use real name ' . $d->key, + E_USER_ERROR + ); + return; + } + if ($this->lock) { + list($ns) = explode('.', $key); + if ($ns !== $this->lock) { + $this->triggerError( + 'Cannot get value of namespace ' . $ns . ' when lock for ' . + $this->lock . + ' is active, this probably indicates a Definition setup method ' . + 'is accessing directives that are not within its namespace', + E_USER_ERROR + ); + return; + } + } + return $this->plist->get($key); + } + + /** + * Retrieves an array of directives to values from a given namespace + * + * @param string $namespace String namespace + * + * @return array + */ + public function getBatch($namespace) + { + if (!$this->finalized) { + $this->autoFinalize(); + } + $full = $this->getAll(); + if (!isset($full[$namespace])) { + $this->triggerError( + 'Cannot retrieve undefined namespace ' . + htmlspecialchars($namespace), + E_USER_WARNING + ); + return; + } + return $full[$namespace]; + } + + /** + * Returns a SHA-1 signature of a segment of the configuration object + * that uniquely identifies that particular configuration + * + * @param string $namespace Namespace to get serial for + * + * @return string + * @note Revision is handled specially and is removed from the batch + * before processing! + */ + public function getBatchSerial($namespace) + { + if (empty($this->serials[$namespace])) { + $batch = $this->getBatch($namespace); + unset($batch['DefinitionRev']); + $this->serials[$namespace] = sha1(serialize($batch)); + } + return $this->serials[$namespace]; + } + + /** + * Returns a SHA-1 signature for the entire configuration object + * that uniquely identifies that particular configuration + * + * @return string + */ + public function getSerial() + { + if (empty($this->serial)) { + $this->serial = sha1(serialize($this->getAll())); + } + return $this->serial; + } + + /** + * Retrieves all directives, organized by namespace + * + * @warning This is a pretty inefficient function, avoid if you can + */ + public function getAll() + { + if (!$this->finalized) { + $this->autoFinalize(); + } + $ret = array(); + foreach ($this->plist->squash() as $name => $value) { + list($ns, $key) = explode('.', $name, 2); + $ret[$ns][$key] = $value; + } + return $ret; + } + + /** + * Sets a value to configuration. + * + * @param string $key key + * @param mixed $value value + * @param mixed $a + */ + public function set($key, $value, $a = null) + { + if (strpos($key, '.') === false) { + $namespace = $key; + $directive = $value; + $value = $a; + $key = "$key.$directive"; + $this->triggerError("Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE); + } else { + list($namespace) = explode('.', $key); + } + if ($this->isFinalized('Cannot set directive after finalization')) { + return; + } + if (!isset($this->def->info[$key])) { + $this->triggerError( + 'Cannot set undefined directive ' . htmlspecialchars($key) . ' to value', + E_USER_WARNING + ); + return; + } + $def = $this->def->info[$key]; + + if (isset($def->isAlias)) { + if ($this->aliasMode) { + $this->triggerError( + 'Double-aliases not allowed, please fix '. + 'ConfigSchema bug with' . $key, + E_USER_ERROR + ); + return; + } + $this->aliasMode = true; + $this->set($def->key, $value); + $this->aliasMode = false; + $this->triggerError("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE); + return; + } + + // Raw type might be negative when using the fully optimized form + // of stdClass, which indicates allow_null == true + $rtype = is_int($def) ? $def : $def->type; + if ($rtype < 0) { + $type = -$rtype; + $allow_null = true; + } else { + $type = $rtype; + $allow_null = isset($def->allow_null); + } + + try { + $value = $this->parser->parse($value, $type, $allow_null); + } catch (HTMLPurifier_VarParserException $e) { + $this->triggerError( + 'Value for ' . $key . ' is of invalid type, should be ' . + HTMLPurifier_VarParser::getTypeName($type), + E_USER_WARNING + ); + return; + } + if (is_string($value) && is_object($def)) { + // resolve value alias if defined + if (isset($def->aliases[$value])) { + $value = $def->aliases[$value]; + } + // check to see if the value is allowed + if (isset($def->allowed) && !isset($def->allowed[$value])) { + $this->triggerError( + 'Value not supported, valid values are: ' . + $this->_listify($def->allowed), + E_USER_WARNING + ); + return; + } + } + $this->plist->set($key, $value); + + // reset definitions if the directives they depend on changed + // this is a very costly process, so it's discouraged + // with finalization + if ($namespace == 'HTML' || $namespace == 'CSS' || $namespace == 'URI') { + $this->definitions[$namespace] = null; + } + + $this->serials[$namespace] = false; + } + + /** + * Convenience function for error reporting + * + * @param array $lookup + * + * @return string + */ + private function _listify($lookup) + { + $list = array(); + foreach ($lookup as $name => $b) { + $list[] = $name; + } + return implode(', ', $list); + } + + /** + * Retrieves object reference to the HTML definition. + * + * @param bool $raw Return a copy that has not been setup yet. Must be + * called before it's been setup, otherwise won't work. + * @param bool $optimized If true, this method may return null, to + * indicate that a cached version of the modified + * definition object is available and no further edits + * are necessary. Consider using + * maybeGetRawHTMLDefinition, which is more explicitly + * named, instead. + * + * @return HTMLPurifier_HTMLDefinition|null + */ + public function getHTMLDefinition($raw = false, $optimized = false) + { + return $this->getDefinition('HTML', $raw, $optimized); + } + + /** + * Retrieves object reference to the CSS definition + * + * @param bool $raw Return a copy that has not been setup yet. Must be + * called before it's been setup, otherwise won't work. + * @param bool $optimized If true, this method may return null, to + * indicate that a cached version of the modified + * definition object is available and no further edits + * are necessary. Consider using + * maybeGetRawCSSDefinition, which is more explicitly + * named, instead. + * + * @return HTMLPurifier_CSSDefinition|null + */ + public function getCSSDefinition($raw = false, $optimized = false) + { + return $this->getDefinition('CSS', $raw, $optimized); + } + + /** + * Retrieves object reference to the URI definition + * + * @param bool $raw Return a copy that has not been setup yet. Must be + * called before it's been setup, otherwise won't work. + * @param bool $optimized If true, this method may return null, to + * indicate that a cached version of the modified + * definition object is available and no further edits + * are necessary. Consider using + * maybeGetRawURIDefinition, which is more explicitly + * named, instead. + * + * @return HTMLPurifier_URIDefinition|null + */ + public function getURIDefinition($raw = false, $optimized = false) + { + return $this->getDefinition('URI', $raw, $optimized); + } + + /** + * Retrieves a definition + * + * @param string $type Type of definition: HTML, CSS, etc + * @param bool $raw Whether or not definition should be returned raw + * @param bool $optimized Only has an effect when $raw is true. Whether + * or not to return null if the result is already present in + * the cache. This is off by default for backwards + * compatibility reasons, but you need to do things this + * way in order to ensure that caching is done properly. + * Check out enduser-customize.html for more details. + * We probably won't ever change this default, as much as the + * maybe semantics is the "right thing to do." + * + * @throws HTMLPurifier_Exception + * @return HTMLPurifier_Definition|null + */ + public function getDefinition($type, $raw = false, $optimized = false) + { + if ($optimized && !$raw) { + throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"); + } + if (!$this->finalized) { + $this->autoFinalize(); + } + // temporarily suspend locks, so we can handle recursive definition calls + $lock = $this->lock; + $this->lock = null; + $factory = HTMLPurifier_DefinitionCacheFactory::instance(); + $cache = $factory->create($type, $this); + $this->lock = $lock; + if (!$raw) { + // full definition + // --------------- + // check if definition is in memory + if (!empty($this->definitions[$type])) { + $def = $this->definitions[$type]; + // check if the definition is setup + if ($def->setup) { + return $def; + } else { + $def->setup($this); + if ($def->optimized) { + $cache->add($def, $this); + } + return $def; + } + } + // check if definition is in cache + $def = $cache->get($this); + if ($def) { + // definition in cache, save to memory and return it + $this->definitions[$type] = $def; + return $def; + } + // initialize it + $def = $this->initDefinition($type); + // set it up + $this->lock = $type; + $def->setup($this); + $this->lock = null; + // save in cache + $cache->add($def, $this); + // return it + return $def; + } else { + // raw definition + // -------------- + // check preconditions + $def = null; + if ($optimized) { + if (is_null($this->get($type . '.DefinitionID'))) { + // fatally error out if definition ID not set + throw new HTMLPurifier_Exception( + "Cannot retrieve raw version without specifying %$type.DefinitionID" + ); + } + } + if (!empty($this->definitions[$type])) { + $def = $this->definitions[$type]; + if ($def->setup && !$optimized) { + $extra = $this->chatty ? + " (try moving this code block earlier in your initialization)" : + ""; + throw new HTMLPurifier_Exception( + "Cannot retrieve raw definition after it has already been setup" . + $extra + ); + } + if ($def->optimized === null) { + $extra = $this->chatty ? " (try flushing your cache)" : ""; + throw new HTMLPurifier_Exception( + "Optimization status of definition is unknown" . $extra + ); + } + if ($def->optimized !== $optimized) { + $msg = $optimized ? "optimized" : "unoptimized"; + $extra = $this->chatty ? + " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" + : ""; + throw new HTMLPurifier_Exception( + "Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra + ); + } + } + // check if definition was in memory + if ($def) { + if ($def->setup) { + // invariant: $optimized === true (checked above) + return null; + } else { + return $def; + } + } + // if optimized, check if definition was in cache + // (because we do the memory check first, this formulation + // is prone to cache slamming, but I think + // guaranteeing that either /all/ of the raw + // setup code or /none/ of it is run is more important.) + if ($optimized) { + // This code path only gets run once; once we put + // something in $definitions (which is guaranteed by the + // trailing code), we always short-circuit above. + $def = $cache->get($this); + if ($def) { + // save the full definition for later, but don't + // return it yet + $this->definitions[$type] = $def; + return null; + } + } + // check invariants for creation + if (!$optimized) { + if (!is_null($this->get($type . '.DefinitionID'))) { + if ($this->chatty) { + $this->triggerError( + 'Due to a documentation error in previous version of HTML Purifier, your ' . + 'definitions are not being cached. If this is OK, you can remove the ' . + '%$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, ' . + 'modify your code to use maybeGetRawDefinition, and test if the returned ' . + 'value is null before making any edits (if it is null, that means that a ' . + 'cached version is available, and no raw operations are necessary). See ' . + '' . + 'Customize for more details', + E_USER_WARNING + ); + } else { + $this->triggerError( + "Useless DefinitionID declaration", + E_USER_WARNING + ); + } + } + } + // initialize it + $def = $this->initDefinition($type); + $def->optimized = $optimized; + return $def; + } + throw new HTMLPurifier_Exception("The impossible happened!"); + } + + /** + * Initialise definition + * + * @param string $type What type of definition to create + * + * @return HTMLPurifier_CSSDefinition|HTMLPurifier_HTMLDefinition|HTMLPurifier_URIDefinition + * @throws HTMLPurifier_Exception + */ + private function initDefinition($type) + { + // quick checks failed, let's create the object + if ($type == 'HTML') { + $def = new HTMLPurifier_HTMLDefinition(); + } elseif ($type == 'CSS') { + $def = new HTMLPurifier_CSSDefinition(); + } elseif ($type == 'URI') { + $def = new HTMLPurifier_URIDefinition(); + } else { + throw new HTMLPurifier_Exception( + "Definition of $type type not supported" + ); + } + $this->definitions[$type] = $def; + return $def; + } + + public function maybeGetRawDefinition($name) + { + return $this->getDefinition($name, true, true); + } + + /** + * @return HTMLPurifier_HTMLDefinition|null + */ + public function maybeGetRawHTMLDefinition() + { + return $this->getDefinition('HTML', true, true); + } + + /** + * @return HTMLPurifier_CSSDefinition|null + */ + public function maybeGetRawCSSDefinition() + { + return $this->getDefinition('CSS', true, true); + } + + /** + * @return HTMLPurifier_URIDefinition|null + */ + public function maybeGetRawURIDefinition() + { + return $this->getDefinition('URI', true, true); + } + + /** + * Loads configuration values from an array with the following structure: + * Namespace.Directive => Value + * + * @param array $config_array Configuration associative array + */ + public function loadArray($config_array) + { + if ($this->isFinalized('Cannot load directives after finalization')) { + return; + } + foreach ($config_array as $key => $value) { + $key = str_replace('_', '.', $key); + if (strpos($key, '.') !== false) { + $this->set($key, $value); + } else { + $namespace = $key; + $namespace_values = $value; + foreach ($namespace_values as $directive => $value2) { + $this->set($namespace .'.'. $directive, $value2); + } + } + } + } + + /** + * Returns a list of array(namespace, directive) for all directives + * that are allowed in a web-form context as per an allowed + * namespaces/directives list. + * + * @param array $allowed List of allowed namespaces/directives + * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy + * + * @return array + */ + public static function getAllowedDirectivesForForm($allowed, $schema = null) + { + if (!$schema) { + $schema = HTMLPurifier_ConfigSchema::instance(); + } + if ($allowed !== true) { + if (is_string($allowed)) { + $allowed = array($allowed); + } + $allowed_ns = array(); + $allowed_directives = array(); + $blacklisted_directives = array(); + foreach ($allowed as $ns_or_directive) { + if (strpos($ns_or_directive, '.') !== false) { + // directive + if ($ns_or_directive[0] == '-') { + $blacklisted_directives[substr($ns_or_directive, 1)] = true; + } else { + $allowed_directives[$ns_or_directive] = true; + } + } else { + // namespace + $allowed_ns[$ns_or_directive] = true; + } + } + } + $ret = array(); + foreach ($schema->info as $key => $def) { + list($ns, $directive) = explode('.', $key, 2); + if ($allowed !== true) { + if (isset($blacklisted_directives["$ns.$directive"])) { + continue; + } + if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) { + continue; + } + } + if (isset($def->isAlias)) { + continue; + } + if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') { + continue; + } + $ret[] = array($ns, $directive); + } + return $ret; + } + + /** + * Loads configuration values from $_GET/$_POST that were posted + * via ConfigForm + * + * @param array $array $_GET or $_POST array to import + * @param string|bool $index Index/name that the config variables are in + * @param array|bool $allowed List of allowed namespaces/directives + * @param bool $mq_fix Boolean whether or not to enable magic quotes fix + * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy + * + * @return mixed + */ + public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) + { + $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema); + $config = HTMLPurifier_Config::create($ret, $schema); + return $config; + } + + /** + * Merges in configuration values from $_GET/$_POST to object. NOT STATIC. + * + * @param array $array $_GET or $_POST array to import + * @param string|bool $index Index/name that the config variables are in + * @param array|bool $allowed List of allowed namespaces/directives + * @param bool $mq_fix Boolean whether or not to enable magic quotes fix + */ + public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true) + { + $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def); + $this->loadArray($ret); + } + + /** + * Prepares an array from a form into something usable for the more + * strict parts of HTMLPurifier_Config + * + * @param array $array $_GET or $_POST array to import + * @param string|bool $index Index/name that the config variables are in + * @param array|bool $allowed List of allowed namespaces/directives + * @param bool $mq_fix Boolean whether or not to enable magic quotes fix + * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy + * + * @return array + */ + public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) + { + if ($index !== false) { + $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array(); + } + $mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc(); + + $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema); + $ret = array(); + foreach ($allowed as $key) { + list($ns, $directive) = $key; + $skey = "$ns.$directive"; + if (!empty($array["Null_$skey"])) { + $ret[$ns][$directive] = null; + continue; + } + if (!isset($array[$skey])) { + continue; + } + $value = $mq ? stripslashes($array[$skey]) : $array[$skey]; + $ret[$ns][$directive] = $value; + } + return $ret; + } + + /** + * Loads configuration values from an ini file + * + * @param string $filename Name of ini file + */ + public function loadIni($filename) + { + if ($this->isFinalized('Cannot load directives after finalization')) { + return; + } + $array = parse_ini_file($filename, true); + $this->loadArray($array); + } + + /** + * Checks whether or not the configuration object is finalized. + * + * @param string|bool $error String error message, or false for no error + * + * @return bool + */ + public function isFinalized($error = false) + { + if ($this->finalized && $error) { + $this->triggerError($error, E_USER_ERROR); + } + return $this->finalized; + } + + /** + * Finalizes configuration only if auto finalize is on and not + * already finalized + */ + public function autoFinalize() + { + if ($this->autoFinalize) { + $this->finalize(); + } else { + $this->plist->squash(true); + } + } + + /** + * Finalizes a configuration object, prohibiting further change + */ + public function finalize() + { + $this->finalized = true; + $this->parser = null; + } + + /** + * Produces a nicely formatted error message by supplying the + * stack frame information OUTSIDE of HTMLPurifier_Config. + * + * @param string $msg An error message + * @param int $no An error number + */ + protected function triggerError($msg, $no) + { + // determine previous stack frame + $extra = ''; + if ($this->chatty) { + $trace = debug_backtrace(); + // zip(tail(trace), trace) -- but PHP is not Haskell har har + for ($i = 0, $c = count($trace); $i < $c - 1; $i++) { + // XXX this is not correct on some versions of HTML Purifier + if (isset($trace[$i + 1]['class']) && $trace[$i + 1]['class'] === 'HTMLPurifier_Config') { + continue; + } + $frame = $trace[$i]; + $extra = " invoked on line {$frame['line']} in file {$frame['file']}"; + break; + } + } + trigger_error($msg . $extra, $no); + } + + /** + * Returns a serialized form of the configuration object that can + * be reconstituted. + * + * @return string + */ + public function serialize() + { + $this->getDefinition('HTML'); + $this->getDefinition('CSS'); + $this->getDefinition('URI'); + return serialize($this); + } + +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema.php new file mode 100644 index 000000000..c3fe8cd4a --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema.php @@ -0,0 +1,176 @@ + array( + * 'Directive' => new stdClass(), + * ) + * ) + * + * The stdClass may have the following properties: + * + * - If isAlias isn't set: + * - type: Integer type of directive, see HTMLPurifier_VarParser for definitions + * - allow_null: If set, this directive allows null values + * - aliases: If set, an associative array of value aliases to real values + * - allowed: If set, a lookup array of allowed (string) values + * - If isAlias is set: + * - namespace: Namespace this directive aliases to + * - name: Directive name this directive aliases to + * + * In certain degenerate cases, stdClass will actually be an integer. In + * that case, the value is equivalent to an stdClass with the type + * property set to the integer. If the integer is negative, type is + * equal to the absolute value of integer, and allow_null is true. + * + * This class is friendly with HTMLPurifier_Config. If you need introspection + * about the schema, you're better of using the ConfigSchema_Interchange, + * which uses more memory but has much richer information. + * @type array + */ + public $info = array(); + + /** + * Application-wide singleton + * @type HTMLPurifier_ConfigSchema + */ + protected static $singleton; + + public function __construct() + { + $this->defaultPlist = new HTMLPurifier_PropertyList(); + } + + /** + * Unserializes the default ConfigSchema. + * @return HTMLPurifier_ConfigSchema + */ + public static function makeFromSerial() + { + $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser'); + $r = unserialize($contents); + if (!$r) { + $hash = sha1($contents); + trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR); + } + return $r; + } + + /** + * Retrieves an instance of the application-wide configuration definition. + * @param HTMLPurifier_ConfigSchema $prototype + * @return HTMLPurifier_ConfigSchema + */ + public static function instance($prototype = null) + { + if ($prototype !== null) { + HTMLPurifier_ConfigSchema::$singleton = $prototype; + } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { + HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial(); + } + return HTMLPurifier_ConfigSchema::$singleton; + } + + /** + * Defines a directive for configuration + * @warning Will fail of directive's namespace is defined. + * @warning This method's signature is slightly different from the legacy + * define() static method! Beware! + * @param string $key Name of directive + * @param mixed $default Default value of directive + * @param string $type Allowed type of the directive. See + * HTMLPurifier_VarParser::$types for allowed values + * @param bool $allow_null Whether or not to allow null values + */ + public function add($key, $default, $type, $allow_null) + { + $obj = new stdClass(); + $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type]; + if ($allow_null) { + $obj->allow_null = true; + } + $this->info[$key] = $obj; + $this->defaults[$key] = $default; + $this->defaultPlist->set($key, $default); + } + + /** + * Defines a directive value alias. + * + * Directive value aliases are convenient for developers because it lets + * them set a directive to several values and get the same result. + * @param string $key Name of Directive + * @param array $aliases Hash of aliased values to the real alias + */ + public function addValueAliases($key, $aliases) + { + if (!isset($this->info[$key]->aliases)) { + $this->info[$key]->aliases = array(); + } + foreach ($aliases as $alias => $real) { + $this->info[$key]->aliases[$alias] = $real; + } + } + + /** + * Defines a set of allowed values for a directive. + * @warning This is slightly different from the corresponding static + * method definition. + * @param string $key Name of directive + * @param array $allowed Lookup array of allowed values + */ + public function addAllowedValues($key, $allowed) + { + $this->info[$key]->allowed = $allowed; + } + + /** + * Defines a directive alias for backwards compatibility + * @param string $key Directive that will be aliased + * @param string $new_key Directive that the alias will be to + */ + public function addAlias($key, $new_key) + { + $obj = new stdClass; + $obj->key = $new_key; + $obj->isAlias = true; + $this->info[$key] = $obj; + } + + /** + * Replaces any stdClass that only has the type property with type integer. + */ + public function postProcess() + { + foreach ($this->info as $key => $v) { + if (count((array) $v) == 1) { + $this->info[$key] = $v->type; + } elseif (count((array) $v) == 2 && isset($v->allow_null)) { + $this->info[$key] = -$v->type; + } + } + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php index 692aaa881..d5906cd46 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php @@ -46,4 +46,3 @@ class HTMLPurifier_ConfigSchema_Builder_ConfigSchema } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/Xml.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/Xml.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php index 075916bfd..5fa56f7dd 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/Xml.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php @@ -142,4 +142,3 @@ class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/index.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Exception.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Exception.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Exception.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Exception.php index 53e485eed..2671516c5 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Exception.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Exception.php @@ -9,4 +9,3 @@ class HTMLPurifier_ConfigSchema_Exception extends HTMLPurifier_Exception } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php index 145762e5f..0e08ae8fe 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php @@ -45,4 +45,3 @@ class HTMLPurifier_ConfigSchema_Interchange } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Directive.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Directive.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php index 03812709d..127a39a67 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Directive.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php @@ -87,4 +87,3 @@ class HTMLPurifier_ConfigSchema_Interchange_Directive } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Id.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Id.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php index 5ded05571..126f09d95 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Interchange/Id.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php @@ -56,4 +56,3 @@ class HTMLPurifier_ConfigSchema_Interchange_Id } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/index.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/InterchangeBuilder.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/InterchangeBuilder.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php index a8f35a7c5..655e6dd1b 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/InterchangeBuilder.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php @@ -224,4 +224,3 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Validator.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Validator.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php index b9bf63057..fb3127788 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Validator.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php @@ -246,4 +246,3 @@ class HTMLPurifier_ConfigSchema_Validator } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/ValidatorAtom.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php similarity index 99% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/ValidatorAtom.php rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php index 1a6f90e52..c9aa3644a 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/ValidatorAtom.php +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php @@ -128,4 +128,3 @@ class HTMLPurifier_ConfigSchema_ValidatorAtom } // vim: et sw=4 sts=4 - diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/index.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser new file mode 100644 index 000000000..a5426c736 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser @@ -0,0 +1 @@ +O:25:"HTMLPurifier_ConfigSchema":3:{s:8:"defaults";a:127:{s:19:"Attr.AllowedClasses";N;s:24:"Attr.AllowedFrameTargets";a:0:{}s:15:"Attr.AllowedRel";a:0:{}s:15:"Attr.AllowedRev";a:0:{}s:18:"Attr.ClassUseCDATA";N;s:20:"Attr.DefaultImageAlt";N;s:24:"Attr.DefaultInvalidImage";s:0:"";s:27:"Attr.DefaultInvalidImageAlt";s:13:"Invalid image";s:19:"Attr.DefaultTextDir";s:3:"ltr";s:13:"Attr.EnableID";b:0;s:21:"Attr.ForbiddenClasses";a:0:{}s:13:"Attr.ID.HTML5";N;s:16:"Attr.IDBlacklist";a:0:{}s:22:"Attr.IDBlacklistRegexp";N;s:13:"Attr.IDPrefix";s:0:"";s:18:"Attr.IDPrefixLocal";s:0:"";s:24:"AutoFormat.AutoParagraph";b:0;s:17:"AutoFormat.Custom";a:0:{}s:25:"AutoFormat.DisplayLinkURI";b:0;s:18:"AutoFormat.Linkify";b:0;s:33:"AutoFormat.PurifierLinkify.DocURL";s:3:"#%s";s:26:"AutoFormat.PurifierLinkify";b:0;s:32:"AutoFormat.RemoveEmpty.Predicate";a:4:{s:8:"colgroup";a:0:{}s:2:"th";a:0:{}s:2:"td";a:0:{}s:6:"iframe";a:1:{i:0;s:3:"src";}}s:44:"AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions";a:2:{s:2:"td";b:1;s:2:"th";b:1;}s:33:"AutoFormat.RemoveEmpty.RemoveNbsp";b:0;s:22:"AutoFormat.RemoveEmpty";b:0;s:39:"AutoFormat.RemoveSpansWithoutAttributes";b:0;s:19:"CSS.AllowDuplicates";b:0;s:18:"CSS.AllowImportant";b:0;s:15:"CSS.AllowTricky";b:0;s:16:"CSS.AllowedFonts";N;s:21:"CSS.AllowedProperties";N;s:17:"CSS.DefinitionRev";i:1;s:23:"CSS.ForbiddenProperties";a:0:{}s:16:"CSS.MaxImgLength";s:6:"1200px";s:15:"CSS.Proprietary";b:0;s:11:"CSS.Trusted";b:0;s:20:"Cache.DefinitionImpl";s:10:"Serializer";s:20:"Cache.SerializerPath";N;s:27:"Cache.SerializerPermissions";i:493;s:22:"Core.AggressivelyFixLt";b:1;s:29:"Core.AggressivelyRemoveScript";b:1;s:28:"Core.AllowHostnameUnderscore";b:0;s:23:"Core.AllowParseManyTags";b:0;s:18:"Core.CollectErrors";b:0;s:18:"Core.ColorKeywords";a:148:{s:9:"aliceblue";s:7:"#F0F8FF";s:12:"antiquewhite";s:7:"#FAEBD7";s:4:"aqua";s:7:"#00FFFF";s:10:"aquamarine";s:7:"#7FFFD4";s:5:"azure";s:7:"#F0FFFF";s:5:"beige";s:7:"#F5F5DC";s:6:"bisque";s:7:"#FFE4C4";s:5:"black";s:7:"#000000";s:14:"blanchedalmond";s:7:"#FFEBCD";s:4:"blue";s:7:"#0000FF";s:10:"blueviolet";s:7:"#8A2BE2";s:5:"brown";s:7:"#A52A2A";s:9:"burlywood";s:7:"#DEB887";s:9:"cadetblue";s:7:"#5F9EA0";s:10:"chartreuse";s:7:"#7FFF00";s:9:"chocolate";s:7:"#D2691E";s:5:"coral";s:7:"#FF7F50";s:14:"cornflowerblue";s:7:"#6495ED";s:8:"cornsilk";s:7:"#FFF8DC";s:7:"crimson";s:7:"#DC143C";s:4:"cyan";s:7:"#00FFFF";s:8:"darkblue";s:7:"#00008B";s:8:"darkcyan";s:7:"#008B8B";s:13:"darkgoldenrod";s:7:"#B8860B";s:8:"darkgray";s:7:"#A9A9A9";s:8:"darkgrey";s:7:"#A9A9A9";s:9:"darkgreen";s:7:"#006400";s:9:"darkkhaki";s:7:"#BDB76B";s:11:"darkmagenta";s:7:"#8B008B";s:14:"darkolivegreen";s:7:"#556B2F";s:10:"darkorange";s:7:"#FF8C00";s:10:"darkorchid";s:7:"#9932CC";s:7:"darkred";s:7:"#8B0000";s:10:"darksalmon";s:7:"#E9967A";s:12:"darkseagreen";s:7:"#8FBC8F";s:13:"darkslateblue";s:7:"#483D8B";s:13:"darkslategray";s:7:"#2F4F4F";s:13:"darkslategrey";s:7:"#2F4F4F";s:13:"darkturquoise";s:7:"#00CED1";s:10:"darkviolet";s:7:"#9400D3";s:8:"deeppink";s:7:"#FF1493";s:11:"deepskyblue";s:7:"#00BFFF";s:7:"dimgray";s:7:"#696969";s:7:"dimgrey";s:7:"#696969";s:10:"dodgerblue";s:7:"#1E90FF";s:9:"firebrick";s:7:"#B22222";s:11:"floralwhite";s:7:"#FFFAF0";s:11:"forestgreen";s:7:"#228B22";s:7:"fuchsia";s:7:"#FF00FF";s:9:"gainsboro";s:7:"#DCDCDC";s:10:"ghostwhite";s:7:"#F8F8FF";s:4:"gold";s:7:"#FFD700";s:9:"goldenrod";s:7:"#DAA520";s:4:"gray";s:7:"#808080";s:4:"grey";s:7:"#808080";s:5:"green";s:7:"#008000";s:11:"greenyellow";s:7:"#ADFF2F";s:8:"honeydew";s:7:"#F0FFF0";s:7:"hotpink";s:7:"#FF69B4";s:9:"indianred";s:7:"#CD5C5C";s:6:"indigo";s:7:"#4B0082";s:5:"ivory";s:7:"#FFFFF0";s:5:"khaki";s:7:"#F0E68C";s:8:"lavender";s:7:"#E6E6FA";s:13:"lavenderblush";s:7:"#FFF0F5";s:9:"lawngreen";s:7:"#7CFC00";s:12:"lemonchiffon";s:7:"#FFFACD";s:9:"lightblue";s:7:"#ADD8E6";s:10:"lightcoral";s:7:"#F08080";s:9:"lightcyan";s:7:"#E0FFFF";s:20:"lightgoldenrodyellow";s:7:"#FAFAD2";s:9:"lightgray";s:7:"#D3D3D3";s:9:"lightgrey";s:7:"#D3D3D3";s:10:"lightgreen";s:7:"#90EE90";s:9:"lightpink";s:7:"#FFB6C1";s:11:"lightsalmon";s:7:"#FFA07A";s:13:"lightseagreen";s:7:"#20B2AA";s:12:"lightskyblue";s:7:"#87CEFA";s:14:"lightslategray";s:7:"#778899";s:14:"lightslategrey";s:7:"#778899";s:14:"lightsteelblue";s:7:"#B0C4DE";s:11:"lightyellow";s:7:"#FFFFE0";s:4:"lime";s:7:"#00FF00";s:9:"limegreen";s:7:"#32CD32";s:5:"linen";s:7:"#FAF0E6";s:7:"magenta";s:7:"#FF00FF";s:6:"maroon";s:7:"#800000";s:16:"mediumaquamarine";s:7:"#66CDAA";s:10:"mediumblue";s:7:"#0000CD";s:12:"mediumorchid";s:7:"#BA55D3";s:12:"mediumpurple";s:7:"#9370DB";s:14:"mediumseagreen";s:7:"#3CB371";s:15:"mediumslateblue";s:7:"#7B68EE";s:17:"mediumspringgreen";s:7:"#00FA9A";s:15:"mediumturquoise";s:7:"#48D1CC";s:15:"mediumvioletred";s:7:"#C71585";s:12:"midnightblue";s:7:"#191970";s:9:"mintcream";s:7:"#F5FFFA";s:9:"mistyrose";s:7:"#FFE4E1";s:8:"moccasin";s:7:"#FFE4B5";s:11:"navajowhite";s:7:"#FFDEAD";s:4:"navy";s:7:"#000080";s:7:"oldlace";s:7:"#FDF5E6";s:5:"olive";s:7:"#808000";s:9:"olivedrab";s:7:"#6B8E23";s:6:"orange";s:7:"#FFA500";s:9:"orangered";s:7:"#FF4500";s:6:"orchid";s:7:"#DA70D6";s:13:"palegoldenrod";s:7:"#EEE8AA";s:9:"palegreen";s:7:"#98FB98";s:13:"paleturquoise";s:7:"#AFEEEE";s:13:"palevioletred";s:7:"#DB7093";s:10:"papayawhip";s:7:"#FFEFD5";s:9:"peachpuff";s:7:"#FFDAB9";s:4:"peru";s:7:"#CD853F";s:4:"pink";s:7:"#FFC0CB";s:4:"plum";s:7:"#DDA0DD";s:10:"powderblue";s:7:"#B0E0E6";s:6:"purple";s:7:"#800080";s:13:"rebeccapurple";s:7:"#663399";s:3:"red";s:7:"#FF0000";s:9:"rosybrown";s:7:"#BC8F8F";s:9:"royalblue";s:7:"#4169E1";s:11:"saddlebrown";s:7:"#8B4513";s:6:"salmon";s:7:"#FA8072";s:10:"sandybrown";s:7:"#F4A460";s:8:"seagreen";s:7:"#2E8B57";s:8:"seashell";s:7:"#FFF5EE";s:6:"sienna";s:7:"#A0522D";s:6:"silver";s:7:"#C0C0C0";s:7:"skyblue";s:7:"#87CEEB";s:9:"slateblue";s:7:"#6A5ACD";s:9:"slategray";s:7:"#708090";s:9:"slategrey";s:7:"#708090";s:4:"snow";s:7:"#FFFAFA";s:11:"springgreen";s:7:"#00FF7F";s:9:"steelblue";s:7:"#4682B4";s:3:"tan";s:7:"#D2B48C";s:4:"teal";s:7:"#008080";s:7:"thistle";s:7:"#D8BFD8";s:6:"tomato";s:7:"#FF6347";s:9:"turquoise";s:7:"#40E0D0";s:6:"violet";s:7:"#EE82EE";s:5:"wheat";s:7:"#F5DEB3";s:5:"white";s:7:"#FFFFFF";s:10:"whitesmoke";s:7:"#F5F5F5";s:6:"yellow";s:7:"#FFFF00";s:11:"yellowgreen";s:7:"#9ACD32";}s:30:"Core.ConvertDocumentToFragment";b:1;s:36:"Core.DirectLexLineNumberSyncInterval";i:0;s:20:"Core.DisableExcludes";b:0;s:15:"Core.EnableIDNA";b:0;s:13:"Core.Encoding";s:5:"utf-8";s:26:"Core.EscapeInvalidChildren";b:0;s:22:"Core.EscapeInvalidTags";b:0;s:29:"Core.EscapeNonASCIICharacters";b:0;s:19:"Core.HiddenElements";a:2:{s:6:"script";b:1;s:5:"style";b:1;}s:13:"Core.Language";s:2:"en";s:24:"Core.LegacyEntityDecoder";b:0;s:14:"Core.LexerImpl";N;s:24:"Core.MaintainLineNumbers";N;s:22:"Core.NormalizeNewlines";b:1;s:21:"Core.RemoveInvalidImg";b:1;s:33:"Core.RemoveProcessingInstructions";b:0;s:25:"Core.RemoveScriptContents";N;s:13:"Filter.Custom";a:0:{}s:34:"Filter.ExtractStyleBlocks.Escaping";b:1;s:31:"Filter.ExtractStyleBlocks.Scope";N;s:34:"Filter.ExtractStyleBlocks.TidyImpl";N;s:25:"Filter.ExtractStyleBlocks";b:0;s:14:"Filter.YouTube";b:0;s:12:"HTML.Allowed";N;s:22:"HTML.AllowedAttributes";N;s:20:"HTML.AllowedComments";a:0:{}s:26:"HTML.AllowedCommentsRegexp";N;s:20:"HTML.AllowedElements";N;s:19:"HTML.AllowedModules";N;s:23:"HTML.Attr.Name.UseCDATA";b:0;s:17:"HTML.BlockWrapper";s:1:"p";s:16:"HTML.CoreModules";a:7:{s:9:"Structure";b:1;s:4:"Text";b:1;s:9:"Hypertext";b:1;s:4:"List";b:1;s:22:"NonXMLCommonAttributes";b:1;s:19:"XMLCommonAttributes";b:1;s:16:"CommonAttributes";b:1;}s:18:"HTML.CustomDoctype";N;s:17:"HTML.DefinitionID";N;s:18:"HTML.DefinitionRev";i:1;s:12:"HTML.Doctype";N;s:25:"HTML.FlashAllowFullScreen";b:0;s:24:"HTML.ForbiddenAttributes";a:0:{}s:22:"HTML.ForbiddenElements";a:0:{}s:10:"HTML.Forms";b:0;s:17:"HTML.MaxImgLength";i:1200;s:13:"HTML.Nofollow";b:0;s:11:"HTML.Parent";s:3:"div";s:16:"HTML.Proprietary";b:0;s:14:"HTML.SafeEmbed";b:0;s:15:"HTML.SafeIframe";b:0;s:15:"HTML.SafeObject";b:0;s:18:"HTML.SafeScripting";a:0:{}s:11:"HTML.Strict";b:0;s:16:"HTML.TargetBlank";b:0;s:19:"HTML.TargetNoopener";b:1;s:21:"HTML.TargetNoreferrer";b:1;s:12:"HTML.TidyAdd";a:0:{}s:14:"HTML.TidyLevel";s:6:"medium";s:15:"HTML.TidyRemove";a:0:{}s:12:"HTML.Trusted";b:0;s:10:"HTML.XHTML";b:1;s:28:"Output.CommentScriptContents";b:1;s:19:"Output.FixInnerHTML";b:1;s:18:"Output.FlashCompat";b:0;s:14:"Output.Newline";N;s:15:"Output.SortAttr";b:0;s:17:"Output.TidyFormat";b:0;s:17:"Test.ForceNoIconv";b:0;s:18:"URI.AllowedSchemes";a:7:{s:4:"http";b:1;s:5:"https";b:1;s:6:"mailto";b:1;s:3:"ftp";b:1;s:4:"nntp";b:1;s:4:"news";b:1;s:3:"tel";b:1;}s:8:"URI.Base";N;s:17:"URI.DefaultScheme";s:4:"http";s:16:"URI.DefinitionID";N;s:17:"URI.DefinitionRev";i:1;s:11:"URI.Disable";b:0;s:19:"URI.DisableExternal";b:0;s:28:"URI.DisableExternalResources";b:0;s:20:"URI.DisableResources";b:0;s:8:"URI.Host";N;s:17:"URI.HostBlacklist";a:0:{}s:16:"URI.MakeAbsolute";b:0;s:9:"URI.Munge";N;s:18:"URI.MungeResources";b:0;s:18:"URI.MungeSecretKey";N;s:26:"URI.OverrideAllowedSchemes";b:1;s:20:"URI.SafeIframeRegexp";N;}s:12:"defaultPlist";O:25:"HTMLPurifier_PropertyList":3:{s:7:"*data";a:127:{s:19:"Attr.AllowedClasses";N;s:24:"Attr.AllowedFrameTargets";a:0:{}s:15:"Attr.AllowedRel";a:0:{}s:15:"Attr.AllowedRev";a:0:{}s:18:"Attr.ClassUseCDATA";N;s:20:"Attr.DefaultImageAlt";N;s:24:"Attr.DefaultInvalidImage";s:0:"";s:27:"Attr.DefaultInvalidImageAlt";s:13:"Invalid image";s:19:"Attr.DefaultTextDir";s:3:"ltr";s:13:"Attr.EnableID";b:0;s:21:"Attr.ForbiddenClasses";a:0:{}s:13:"Attr.ID.HTML5";N;s:16:"Attr.IDBlacklist";a:0:{}s:22:"Attr.IDBlacklistRegexp";N;s:13:"Attr.IDPrefix";s:0:"";s:18:"Attr.IDPrefixLocal";s:0:"";s:24:"AutoFormat.AutoParagraph";b:0;s:17:"AutoFormat.Custom";a:0:{}s:25:"AutoFormat.DisplayLinkURI";b:0;s:18:"AutoFormat.Linkify";b:0;s:33:"AutoFormat.PurifierLinkify.DocURL";s:3:"#%s";s:26:"AutoFormat.PurifierLinkify";b:0;s:32:"AutoFormat.RemoveEmpty.Predicate";a:4:{s:8:"colgroup";a:0:{}s:2:"th";a:0:{}s:2:"td";a:0:{}s:6:"iframe";a:1:{i:0;s:3:"src";}}s:44:"AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions";a:2:{s:2:"td";b:1;s:2:"th";b:1;}s:33:"AutoFormat.RemoveEmpty.RemoveNbsp";b:0;s:22:"AutoFormat.RemoveEmpty";b:0;s:39:"AutoFormat.RemoveSpansWithoutAttributes";b:0;s:19:"CSS.AllowDuplicates";b:0;s:18:"CSS.AllowImportant";b:0;s:15:"CSS.AllowTricky";b:0;s:16:"CSS.AllowedFonts";N;s:21:"CSS.AllowedProperties";N;s:17:"CSS.DefinitionRev";i:1;s:23:"CSS.ForbiddenProperties";a:0:{}s:16:"CSS.MaxImgLength";s:6:"1200px";s:15:"CSS.Proprietary";b:0;s:11:"CSS.Trusted";b:0;s:20:"Cache.DefinitionImpl";s:10:"Serializer";s:20:"Cache.SerializerPath";N;s:27:"Cache.SerializerPermissions";i:493;s:22:"Core.AggressivelyFixLt";b:1;s:29:"Core.AggressivelyRemoveScript";b:1;s:28:"Core.AllowHostnameUnderscore";b:0;s:23:"Core.AllowParseManyTags";b:0;s:18:"Core.CollectErrors";b:0;s:18:"Core.ColorKeywords";a:148:{s:9:"aliceblue";s:7:"#F0F8FF";s:12:"antiquewhite";s:7:"#FAEBD7";s:4:"aqua";s:7:"#00FFFF";s:10:"aquamarine";s:7:"#7FFFD4";s:5:"azure";s:7:"#F0FFFF";s:5:"beige";s:7:"#F5F5DC";s:6:"bisque";s:7:"#FFE4C4";s:5:"black";s:7:"#000000";s:14:"blanchedalmond";s:7:"#FFEBCD";s:4:"blue";s:7:"#0000FF";s:10:"blueviolet";s:7:"#8A2BE2";s:5:"brown";s:7:"#A52A2A";s:9:"burlywood";s:7:"#DEB887";s:9:"cadetblue";s:7:"#5F9EA0";s:10:"chartreuse";s:7:"#7FFF00";s:9:"chocolate";s:7:"#D2691E";s:5:"coral";s:7:"#FF7F50";s:14:"cornflowerblue";s:7:"#6495ED";s:8:"cornsilk";s:7:"#FFF8DC";s:7:"crimson";s:7:"#DC143C";s:4:"cyan";s:7:"#00FFFF";s:8:"darkblue";s:7:"#00008B";s:8:"darkcyan";s:7:"#008B8B";s:13:"darkgoldenrod";s:7:"#B8860B";s:8:"darkgray";s:7:"#A9A9A9";s:8:"darkgrey";s:7:"#A9A9A9";s:9:"darkgreen";s:7:"#006400";s:9:"darkkhaki";s:7:"#BDB76B";s:11:"darkmagenta";s:7:"#8B008B";s:14:"darkolivegreen";s:7:"#556B2F";s:10:"darkorange";s:7:"#FF8C00";s:10:"darkorchid";s:7:"#9932CC";s:7:"darkred";s:7:"#8B0000";s:10:"darksalmon";s:7:"#E9967A";s:12:"darkseagreen";s:7:"#8FBC8F";s:13:"darkslateblue";s:7:"#483D8B";s:13:"darkslategray";s:7:"#2F4F4F";s:13:"darkslategrey";s:7:"#2F4F4F";s:13:"darkturquoise";s:7:"#00CED1";s:10:"darkviolet";s:7:"#9400D3";s:8:"deeppink";s:7:"#FF1493";s:11:"deepskyblue";s:7:"#00BFFF";s:7:"dimgray";s:7:"#696969";s:7:"dimgrey";s:7:"#696969";s:10:"dodgerblue";s:7:"#1E90FF";s:9:"firebrick";s:7:"#B22222";s:11:"floralwhite";s:7:"#FFFAF0";s:11:"forestgreen";s:7:"#228B22";s:7:"fuchsia";s:7:"#FF00FF";s:9:"gainsboro";s:7:"#DCDCDC";s:10:"ghostwhite";s:7:"#F8F8FF";s:4:"gold";s:7:"#FFD700";s:9:"goldenrod";s:7:"#DAA520";s:4:"gray";s:7:"#808080";s:4:"grey";s:7:"#808080";s:5:"green";s:7:"#008000";s:11:"greenyellow";s:7:"#ADFF2F";s:8:"honeydew";s:7:"#F0FFF0";s:7:"hotpink";s:7:"#FF69B4";s:9:"indianred";s:7:"#CD5C5C";s:6:"indigo";s:7:"#4B0082";s:5:"ivory";s:7:"#FFFFF0";s:5:"khaki";s:7:"#F0E68C";s:8:"lavender";s:7:"#E6E6FA";s:13:"lavenderblush";s:7:"#FFF0F5";s:9:"lawngreen";s:7:"#7CFC00";s:12:"lemonchiffon";s:7:"#FFFACD";s:9:"lightblue";s:7:"#ADD8E6";s:10:"lightcoral";s:7:"#F08080";s:9:"lightcyan";s:7:"#E0FFFF";s:20:"lightgoldenrodyellow";s:7:"#FAFAD2";s:9:"lightgray";s:7:"#D3D3D3";s:9:"lightgrey";s:7:"#D3D3D3";s:10:"lightgreen";s:7:"#90EE90";s:9:"lightpink";s:7:"#FFB6C1";s:11:"lightsalmon";s:7:"#FFA07A";s:13:"lightseagreen";s:7:"#20B2AA";s:12:"lightskyblue";s:7:"#87CEFA";s:14:"lightslategray";s:7:"#778899";s:14:"lightslategrey";s:7:"#778899";s:14:"lightsteelblue";s:7:"#B0C4DE";s:11:"lightyellow";s:7:"#FFFFE0";s:4:"lime";s:7:"#00FF00";s:9:"limegreen";s:7:"#32CD32";s:5:"linen";s:7:"#FAF0E6";s:7:"magenta";s:7:"#FF00FF";s:6:"maroon";s:7:"#800000";s:16:"mediumaquamarine";s:7:"#66CDAA";s:10:"mediumblue";s:7:"#0000CD";s:12:"mediumorchid";s:7:"#BA55D3";s:12:"mediumpurple";s:7:"#9370DB";s:14:"mediumseagreen";s:7:"#3CB371";s:15:"mediumslateblue";s:7:"#7B68EE";s:17:"mediumspringgreen";s:7:"#00FA9A";s:15:"mediumturquoise";s:7:"#48D1CC";s:15:"mediumvioletred";s:7:"#C71585";s:12:"midnightblue";s:7:"#191970";s:9:"mintcream";s:7:"#F5FFFA";s:9:"mistyrose";s:7:"#FFE4E1";s:8:"moccasin";s:7:"#FFE4B5";s:11:"navajowhite";s:7:"#FFDEAD";s:4:"navy";s:7:"#000080";s:7:"oldlace";s:7:"#FDF5E6";s:5:"olive";s:7:"#808000";s:9:"olivedrab";s:7:"#6B8E23";s:6:"orange";s:7:"#FFA500";s:9:"orangered";s:7:"#FF4500";s:6:"orchid";s:7:"#DA70D6";s:13:"palegoldenrod";s:7:"#EEE8AA";s:9:"palegreen";s:7:"#98FB98";s:13:"paleturquoise";s:7:"#AFEEEE";s:13:"palevioletred";s:7:"#DB7093";s:10:"papayawhip";s:7:"#FFEFD5";s:9:"peachpuff";s:7:"#FFDAB9";s:4:"peru";s:7:"#CD853F";s:4:"pink";s:7:"#FFC0CB";s:4:"plum";s:7:"#DDA0DD";s:10:"powderblue";s:7:"#B0E0E6";s:6:"purple";s:7:"#800080";s:13:"rebeccapurple";s:7:"#663399";s:3:"red";s:7:"#FF0000";s:9:"rosybrown";s:7:"#BC8F8F";s:9:"royalblue";s:7:"#4169E1";s:11:"saddlebrown";s:7:"#8B4513";s:6:"salmon";s:7:"#FA8072";s:10:"sandybrown";s:7:"#F4A460";s:8:"seagreen";s:7:"#2E8B57";s:8:"seashell";s:7:"#FFF5EE";s:6:"sienna";s:7:"#A0522D";s:6:"silver";s:7:"#C0C0C0";s:7:"skyblue";s:7:"#87CEEB";s:9:"slateblue";s:7:"#6A5ACD";s:9:"slategray";s:7:"#708090";s:9:"slategrey";s:7:"#708090";s:4:"snow";s:7:"#FFFAFA";s:11:"springgreen";s:7:"#00FF7F";s:9:"steelblue";s:7:"#4682B4";s:3:"tan";s:7:"#D2B48C";s:4:"teal";s:7:"#008080";s:7:"thistle";s:7:"#D8BFD8";s:6:"tomato";s:7:"#FF6347";s:9:"turquoise";s:7:"#40E0D0";s:6:"violet";s:7:"#EE82EE";s:5:"wheat";s:7:"#F5DEB3";s:5:"white";s:7:"#FFFFFF";s:10:"whitesmoke";s:7:"#F5F5F5";s:6:"yellow";s:7:"#FFFF00";s:11:"yellowgreen";s:7:"#9ACD32";}s:30:"Core.ConvertDocumentToFragment";b:1;s:36:"Core.DirectLexLineNumberSyncInterval";i:0;s:20:"Core.DisableExcludes";b:0;s:15:"Core.EnableIDNA";b:0;s:13:"Core.Encoding";s:5:"utf-8";s:26:"Core.EscapeInvalidChildren";b:0;s:22:"Core.EscapeInvalidTags";b:0;s:29:"Core.EscapeNonASCIICharacters";b:0;s:19:"Core.HiddenElements";a:2:{s:6:"script";b:1;s:5:"style";b:1;}s:13:"Core.Language";s:2:"en";s:24:"Core.LegacyEntityDecoder";b:0;s:14:"Core.LexerImpl";N;s:24:"Core.MaintainLineNumbers";N;s:22:"Core.NormalizeNewlines";b:1;s:21:"Core.RemoveInvalidImg";b:1;s:33:"Core.RemoveProcessingInstructions";b:0;s:25:"Core.RemoveScriptContents";N;s:13:"Filter.Custom";a:0:{}s:34:"Filter.ExtractStyleBlocks.Escaping";b:1;s:31:"Filter.ExtractStyleBlocks.Scope";N;s:34:"Filter.ExtractStyleBlocks.TidyImpl";N;s:25:"Filter.ExtractStyleBlocks";b:0;s:14:"Filter.YouTube";b:0;s:12:"HTML.Allowed";N;s:22:"HTML.AllowedAttributes";N;s:20:"HTML.AllowedComments";a:0:{}s:26:"HTML.AllowedCommentsRegexp";N;s:20:"HTML.AllowedElements";N;s:19:"HTML.AllowedModules";N;s:23:"HTML.Attr.Name.UseCDATA";b:0;s:17:"HTML.BlockWrapper";s:1:"p";s:16:"HTML.CoreModules";a:7:{s:9:"Structure";b:1;s:4:"Text";b:1;s:9:"Hypertext";b:1;s:4:"List";b:1;s:22:"NonXMLCommonAttributes";b:1;s:19:"XMLCommonAttributes";b:1;s:16:"CommonAttributes";b:1;}s:18:"HTML.CustomDoctype";N;s:17:"HTML.DefinitionID";N;s:18:"HTML.DefinitionRev";i:1;s:12:"HTML.Doctype";N;s:25:"HTML.FlashAllowFullScreen";b:0;s:24:"HTML.ForbiddenAttributes";a:0:{}s:22:"HTML.ForbiddenElements";a:0:{}s:10:"HTML.Forms";b:0;s:17:"HTML.MaxImgLength";i:1200;s:13:"HTML.Nofollow";b:0;s:11:"HTML.Parent";s:3:"div";s:16:"HTML.Proprietary";b:0;s:14:"HTML.SafeEmbed";b:0;s:15:"HTML.SafeIframe";b:0;s:15:"HTML.SafeObject";b:0;s:18:"HTML.SafeScripting";a:0:{}s:11:"HTML.Strict";b:0;s:16:"HTML.TargetBlank";b:0;s:19:"HTML.TargetNoopener";b:1;s:21:"HTML.TargetNoreferrer";b:1;s:12:"HTML.TidyAdd";a:0:{}s:14:"HTML.TidyLevel";s:6:"medium";s:15:"HTML.TidyRemove";a:0:{}s:12:"HTML.Trusted";b:0;s:10:"HTML.XHTML";b:1;s:28:"Output.CommentScriptContents";b:1;s:19:"Output.FixInnerHTML";b:1;s:18:"Output.FlashCompat";b:0;s:14:"Output.Newline";N;s:15:"Output.SortAttr";b:0;s:17:"Output.TidyFormat";b:0;s:17:"Test.ForceNoIconv";b:0;s:18:"URI.AllowedSchemes";a:7:{s:4:"http";b:1;s:5:"https";b:1;s:6:"mailto";b:1;s:3:"ftp";b:1;s:4:"nntp";b:1;s:4:"news";b:1;s:3:"tel";b:1;}s:8:"URI.Base";N;s:17:"URI.DefaultScheme";s:4:"http";s:16:"URI.DefinitionID";N;s:17:"URI.DefinitionRev";i:1;s:11:"URI.Disable";b:0;s:19:"URI.DisableExternal";b:0;s:28:"URI.DisableExternalResources";b:0;s:20:"URI.DisableResources";b:0;s:8:"URI.Host";N;s:17:"URI.HostBlacklist";a:0:{}s:16:"URI.MakeAbsolute";b:0;s:9:"URI.Munge";N;s:18:"URI.MungeResources";b:0;s:18:"URI.MungeSecretKey";N;s:26:"URI.OverrideAllowedSchemes";b:1;s:20:"URI.SafeIframeRegexp";N;}s:9:"*parent";N;s:8:"*cache";N;}s:4:"info";a:140:{s:19:"Attr.AllowedClasses";i:-8;s:24:"Attr.AllowedFrameTargets";i:8;s:15:"Attr.AllowedRel";i:8;s:15:"Attr.AllowedRev";i:8;s:18:"Attr.ClassUseCDATA";i:-7;s:20:"Attr.DefaultImageAlt";i:-1;s:24:"Attr.DefaultInvalidImage";i:1;s:27:"Attr.DefaultInvalidImageAlt";i:1;s:19:"Attr.DefaultTextDir";O:8:"stdClass":2:{s:4:"type";i:1;s:7:"allowed";a:2:{s:3:"ltr";b:1;s:3:"rtl";b:1;}}s:13:"Attr.EnableID";i:7;s:17:"HTML.EnableAttrID";O:8:"stdClass":2:{s:3:"key";s:13:"Attr.EnableID";s:7:"isAlias";b:1;}s:21:"Attr.ForbiddenClasses";i:8;s:13:"Attr.ID.HTML5";i:-7;s:16:"Attr.IDBlacklist";i:9;s:22:"Attr.IDBlacklistRegexp";i:-1;s:13:"Attr.IDPrefix";i:1;s:18:"Attr.IDPrefixLocal";i:1;s:24:"AutoFormat.AutoParagraph";i:7;s:17:"AutoFormat.Custom";i:9;s:25:"AutoFormat.DisplayLinkURI";i:7;s:18:"AutoFormat.Linkify";i:7;s:33:"AutoFormat.PurifierLinkify.DocURL";i:1;s:37:"AutoFormatParam.PurifierLinkifyDocURL";O:8:"stdClass":2:{s:3:"key";s:33:"AutoFormat.PurifierLinkify.DocURL";s:7:"isAlias";b:1;}s:26:"AutoFormat.PurifierLinkify";i:7;s:32:"AutoFormat.RemoveEmpty.Predicate";i:10;s:44:"AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions";i:8;s:33:"AutoFormat.RemoveEmpty.RemoveNbsp";i:7;s:22:"AutoFormat.RemoveEmpty";i:7;s:39:"AutoFormat.RemoveSpansWithoutAttributes";i:7;s:19:"CSS.AllowDuplicates";i:7;s:18:"CSS.AllowImportant";i:7;s:15:"CSS.AllowTricky";i:7;s:16:"CSS.AllowedFonts";i:-8;s:21:"CSS.AllowedProperties";i:-8;s:17:"CSS.DefinitionRev";i:5;s:23:"CSS.ForbiddenProperties";i:8;s:16:"CSS.MaxImgLength";i:-1;s:15:"CSS.Proprietary";i:7;s:11:"CSS.Trusted";i:7;s:20:"Cache.DefinitionImpl";i:-1;s:20:"Core.DefinitionCache";O:8:"stdClass":2:{s:3:"key";s:20:"Cache.DefinitionImpl";s:7:"isAlias";b:1;}s:20:"Cache.SerializerPath";i:-1;s:27:"Cache.SerializerPermissions";i:-5;s:22:"Core.AggressivelyFixLt";i:7;s:29:"Core.AggressivelyRemoveScript";i:7;s:28:"Core.AllowHostnameUnderscore";i:7;s:23:"Core.AllowParseManyTags";i:7;s:18:"Core.CollectErrors";i:7;s:18:"Core.ColorKeywords";i:10;s:30:"Core.ConvertDocumentToFragment";i:7;s:24:"Core.AcceptFullDocuments";O:8:"stdClass":2:{s:3:"key";s:30:"Core.ConvertDocumentToFragment";s:7:"isAlias";b:1;}s:36:"Core.DirectLexLineNumberSyncInterval";i:5;s:20:"Core.DisableExcludes";i:7;s:15:"Core.EnableIDNA";i:7;s:13:"Core.Encoding";i:2;s:26:"Core.EscapeInvalidChildren";i:7;s:22:"Core.EscapeInvalidTags";i:7;s:29:"Core.EscapeNonASCIICharacters";i:7;s:19:"Core.HiddenElements";i:8;s:13:"Core.Language";i:1;s:24:"Core.LegacyEntityDecoder";i:7;s:14:"Core.LexerImpl";i:-11;s:24:"Core.MaintainLineNumbers";i:-7;s:22:"Core.NormalizeNewlines";i:7;s:21:"Core.RemoveInvalidImg";i:7;s:33:"Core.RemoveProcessingInstructions";i:7;s:25:"Core.RemoveScriptContents";i:-7;s:13:"Filter.Custom";i:9;s:34:"Filter.ExtractStyleBlocks.Escaping";i:7;s:33:"Filter.ExtractStyleBlocksEscaping";O:8:"stdClass":2:{s:3:"key";s:34:"Filter.ExtractStyleBlocks.Escaping";s:7:"isAlias";b:1;}s:38:"FilterParam.ExtractStyleBlocksEscaping";O:8:"stdClass":2:{s:3:"key";s:34:"Filter.ExtractStyleBlocks.Escaping";s:7:"isAlias";b:1;}s:31:"Filter.ExtractStyleBlocks.Scope";i:-1;s:30:"Filter.ExtractStyleBlocksScope";O:8:"stdClass":2:{s:3:"key";s:31:"Filter.ExtractStyleBlocks.Scope";s:7:"isAlias";b:1;}s:35:"FilterParam.ExtractStyleBlocksScope";O:8:"stdClass":2:{s:3:"key";s:31:"Filter.ExtractStyleBlocks.Scope";s:7:"isAlias";b:1;}s:34:"Filter.ExtractStyleBlocks.TidyImpl";i:-11;s:38:"FilterParam.ExtractStyleBlocksTidyImpl";O:8:"stdClass":2:{s:3:"key";s:34:"Filter.ExtractStyleBlocks.TidyImpl";s:7:"isAlias";b:1;}s:25:"Filter.ExtractStyleBlocks";i:7;s:14:"Filter.YouTube";i:7;s:12:"HTML.Allowed";i:-4;s:22:"HTML.AllowedAttributes";i:-8;s:20:"HTML.AllowedComments";i:8;s:26:"HTML.AllowedCommentsRegexp";i:-1;s:20:"HTML.AllowedElements";i:-8;s:19:"HTML.AllowedModules";i:-8;s:23:"HTML.Attr.Name.UseCDATA";i:7;s:17:"HTML.BlockWrapper";i:1;s:16:"HTML.CoreModules";i:8;s:18:"HTML.CustomDoctype";i:-1;s:17:"HTML.DefinitionID";i:-1;s:18:"HTML.DefinitionRev";i:5;s:12:"HTML.Doctype";O:8:"stdClass":3:{s:4:"type";i:1;s:10:"allow_null";b:1;s:7:"allowed";a:5:{s:22:"HTML 4.01 Transitional";b:1;s:16:"HTML 4.01 Strict";b:1;s:22:"XHTML 1.0 Transitional";b:1;s:16:"XHTML 1.0 Strict";b:1;s:9:"XHTML 1.1";b:1;}}s:25:"HTML.FlashAllowFullScreen";i:7;s:24:"HTML.ForbiddenAttributes";i:8;s:22:"HTML.ForbiddenElements";i:8;s:10:"HTML.Forms";i:7;s:17:"HTML.MaxImgLength";i:-5;s:13:"HTML.Nofollow";i:7;s:11:"HTML.Parent";i:1;s:16:"HTML.Proprietary";i:7;s:14:"HTML.SafeEmbed";i:7;s:15:"HTML.SafeIframe";i:7;s:15:"HTML.SafeObject";i:7;s:18:"HTML.SafeScripting";i:8;s:11:"HTML.Strict";i:7;s:16:"HTML.TargetBlank";i:7;s:19:"HTML.TargetNoopener";i:7;s:21:"HTML.TargetNoreferrer";i:7;s:12:"HTML.TidyAdd";i:8;s:14:"HTML.TidyLevel";O:8:"stdClass":2:{s:4:"type";i:1;s:7:"allowed";a:4:{s:4:"none";b:1;s:5:"light";b:1;s:6:"medium";b:1;s:5:"heavy";b:1;}}s:15:"HTML.TidyRemove";i:8;s:12:"HTML.Trusted";i:7;s:10:"HTML.XHTML";i:7;s:10:"Core.XHTML";O:8:"stdClass":2:{s:3:"key";s:10:"HTML.XHTML";s:7:"isAlias";b:1;}s:28:"Output.CommentScriptContents";i:7;s:26:"Core.CommentScriptContents";O:8:"stdClass":2:{s:3:"key";s:28:"Output.CommentScriptContents";s:7:"isAlias";b:1;}s:19:"Output.FixInnerHTML";i:7;s:18:"Output.FlashCompat";i:7;s:14:"Output.Newline";i:-1;s:15:"Output.SortAttr";i:7;s:17:"Output.TidyFormat";i:7;s:15:"Core.TidyFormat";O:8:"stdClass":2:{s:3:"key";s:17:"Output.TidyFormat";s:7:"isAlias";b:1;}s:17:"Test.ForceNoIconv";i:7;s:18:"URI.AllowedSchemes";i:8;s:8:"URI.Base";i:-1;s:17:"URI.DefaultScheme";i:-1;s:16:"URI.DefinitionID";i:-1;s:17:"URI.DefinitionRev";i:5;s:11:"URI.Disable";i:7;s:15:"Attr.DisableURI";O:8:"stdClass":2:{s:3:"key";s:11:"URI.Disable";s:7:"isAlias";b:1;}s:19:"URI.DisableExternal";i:7;s:28:"URI.DisableExternalResources";i:7;s:20:"URI.DisableResources";i:7;s:8:"URI.Host";i:-1;s:17:"URI.HostBlacklist";i:9;s:16:"URI.MakeAbsolute";i:7;s:9:"URI.Munge";i:-1;s:18:"URI.MungeResources";i:7;s:18:"URI.MungeSecretKey";i:-1;s:26:"URI.OverrideAllowedSchemes";i:7;s:20:"URI.SafeIframeRegexp";i:-1;}} \ No newline at end of file diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedClasses.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedClasses.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedClasses.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedClasses.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedFrameTargets.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedFrameTargets.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedFrameTargets.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedFrameTargets.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRel.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRel.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRel.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRel.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRev.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRev.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRev.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.AllowedRev.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.ClassUseCDATA.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ClassUseCDATA.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.ClassUseCDATA.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ClassUseCDATA.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultImageAlt.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultImageAlt.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultImageAlt.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultImageAlt.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImage.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImage.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImage.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImage.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImageAlt.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImageAlt.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImageAlt.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultInvalidImageAlt.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultTextDir.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultTextDir.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.DefaultTextDir.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.DefaultTextDir.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.EnableID.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.EnableID.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.EnableID.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.EnableID.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.ForbiddenClasses.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ForbiddenClasses.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.ForbiddenClasses.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ForbiddenClasses.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ID.HTML5.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ID.HTML5.txt new file mode 100644 index 000000000..735d4b7a1 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.ID.HTML5.txt @@ -0,0 +1,10 @@ +Attr.ID.HTML5 +TYPE: bool/null +DEFAULT: null +VERSION: 4.8.0 +--DESCRIPTION-- +In HTML5, restrictions on the format of the id attribute have been significantly +relaxed, such that any string is valid so long as it contains no spaces and +is at least one character. In lieu of a general HTML5 compatibility flag, +set this configuration directive to true to use the relaxed rules. +--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklist.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklist.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklist.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklist.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklistRegexp.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklistRegexp.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklistRegexp.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDBlacklistRegexp.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefix.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefix.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefix.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefix.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefixLocal.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefixLocal.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefixLocal.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Attr.IDPrefixLocal.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.AutoParagraph.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.AutoParagraph.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.AutoParagraph.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.AutoParagraph.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.Custom.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Custom.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.Custom.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Custom.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.DisplayLinkURI.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.DisplayLinkURI.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.DisplayLinkURI.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.DisplayLinkURI.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.Linkify.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Linkify.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.Linkify.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.Linkify.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.DocURL.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.DocURL.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.DocURL.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.DocURL.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.PurifierLinkify.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.Predicate.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.Predicate.txt new file mode 100644 index 000000000..6367fe23c --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.Predicate.txt @@ -0,0 +1,14 @@ +AutoFormat.RemoveEmpty.Predicate +TYPE: hash +VERSION: 4.7.0 +DEFAULT: array('colgroup' => array(), 'th' => array(), 'td' => array(), 'iframe' => array('src')) +--DESCRIPTION-- +

+ Given that an element has no contents, it will be removed by default, unless + this predicate dictates otherwise. The predicate can either be an associative + map from tag name to list of attributes that must be present for the element + to be considered preserved: thus, the default always preserves colgroup, + th and td, and also iframe if it + has a src. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt similarity index 89% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt index ca17eb1dc..9228dee22 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.RemoveNbsp.txt @@ -6,7 +6,7 @@ DEFAULT: false

When enabled, HTML Purifier will treat any elements that contain only non-breaking spaces as well as regular whitespace as empty, and remove - them when %AutoForamt.RemoveEmpty is enabled. + them when %AutoFormat.RemoveEmpty is enabled.

See %AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions for a list of elements diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveEmpty.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveSpansWithoutAttributes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveSpansWithoutAttributes.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveSpansWithoutAttributes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/AutoFormat.RemoveSpansWithoutAttributes.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowDuplicates.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowDuplicates.txt new file mode 100644 index 000000000..4d054b1f0 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowDuplicates.txt @@ -0,0 +1,11 @@ +CSS.AllowDuplicates +TYPE: bool +DEFAULT: false +VERSION: 4.8.0 +--DESCRIPTION-- +

+ By default, HTML Purifier removes duplicate CSS properties, + like color:red; color:blue. If this is set to + true, duplicate properties are allowed. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowImportant.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowImportant.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowImportant.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowImportant.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowTricky.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowTricky.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowTricky.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowTricky.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowedFonts.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedFonts.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowedFonts.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedFonts.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowedProperties.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedProperties.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.AllowedProperties.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.AllowedProperties.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.DefinitionRev.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.DefinitionRev.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.DefinitionRev.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.DefinitionRev.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.ForbiddenProperties.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.ForbiddenProperties.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.ForbiddenProperties.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.ForbiddenProperties.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.MaxImgLength.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.MaxImgLength.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.MaxImgLength.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.MaxImgLength.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.Proprietary.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Proprietary.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.Proprietary.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Proprietary.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.Trusted.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Trusted.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/CSS.Trusted.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/CSS.Trusted.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.DefinitionImpl.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.DefinitionImpl.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.DefinitionImpl.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.DefinitionImpl.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPath.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPath.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPath.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPath.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt similarity index 59% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt index b2b83d9ab..2e0cc8104 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt @@ -1,5 +1,5 @@ Cache.SerializerPermissions -TYPE: int +TYPE: int/null VERSION: 4.3.0 DEFAULT: 0755 --DESCRIPTION-- @@ -8,4 +8,9 @@ DEFAULT: 0755 Directory permissions of the files and directories created inside the DefinitionCache/Serializer or other custom serializer path.

+

+ In HTML Purifier 4.8.0, this also supports NULL, + which means that no chmod'ing or directory creation shall + occur. +

--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyFixLt.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyFixLt.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyFixLt.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyFixLt.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyRemoveScript.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyRemoveScript.txt new file mode 100644 index 000000000..b2b6ab149 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AggressivelyRemoveScript.txt @@ -0,0 +1,16 @@ +Core.AggressivelyRemoveScript +TYPE: bool +VERSION: 4.9.0 +DEFAULT: true +--DESCRIPTION-- +

+ This directive enables aggressive pre-filter removal of + script tags. This is not necessary for security, + but it can help work around a bug in libxml where embedded + HTML elements inside script sections cause the parser to + choke. To revert to pre-4.9.0 behavior, set this to false. + This directive has no effect if %Core.Trusted is true, + %Core.RemoveScriptContents is false, or %Core.HiddenElements + does not contain script. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowParseManyTags.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowParseManyTags.txt new file mode 100644 index 000000000..06278f82a --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowParseManyTags.txt @@ -0,0 +1,12 @@ +Core.AllowParseManyTags +TYPE: bool +DEFAULT: false +VERSION: 4.10.1 +--DESCRIPTION-- +

+ This directive allows parsing of many nested tags. + If you set true, relaxes any hardcoded limit from the parser. + However, in that case it may cause a Dos attack. + Be careful when enabling it. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.CollectErrors.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.CollectErrors.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.CollectErrors.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.CollectErrors.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ColorKeywords.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ColorKeywords.txt new file mode 100644 index 000000000..a75844cd5 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ColorKeywords.txt @@ -0,0 +1,160 @@ +Core.ColorKeywords +TYPE: hash +VERSION: 2.0.0 +--DEFAULT-- +array ( + 'aliceblue' => '#F0F8FF', + 'antiquewhite' => '#FAEBD7', + 'aqua' => '#00FFFF', + 'aquamarine' => '#7FFFD4', + 'azure' => '#F0FFFF', + 'beige' => '#F5F5DC', + 'bisque' => '#FFE4C4', + 'black' => '#000000', + 'blanchedalmond' => '#FFEBCD', + 'blue' => '#0000FF', + 'blueviolet' => '#8A2BE2', + 'brown' => '#A52A2A', + 'burlywood' => '#DEB887', + 'cadetblue' => '#5F9EA0', + 'chartreuse' => '#7FFF00', + 'chocolate' => '#D2691E', + 'coral' => '#FF7F50', + 'cornflowerblue' => '#6495ED', + 'cornsilk' => '#FFF8DC', + 'crimson' => '#DC143C', + 'cyan' => '#00FFFF', + 'darkblue' => '#00008B', + 'darkcyan' => '#008B8B', + 'darkgoldenrod' => '#B8860B', + 'darkgray' => '#A9A9A9', + 'darkgrey' => '#A9A9A9', + 'darkgreen' => '#006400', + 'darkkhaki' => '#BDB76B', + 'darkmagenta' => '#8B008B', + 'darkolivegreen' => '#556B2F', + 'darkorange' => '#FF8C00', + 'darkorchid' => '#9932CC', + 'darkred' => '#8B0000', + 'darksalmon' => '#E9967A', + 'darkseagreen' => '#8FBC8F', + 'darkslateblue' => '#483D8B', + 'darkslategray' => '#2F4F4F', + 'darkslategrey' => '#2F4F4F', + 'darkturquoise' => '#00CED1', + 'darkviolet' => '#9400D3', + 'deeppink' => '#FF1493', + 'deepskyblue' => '#00BFFF', + 'dimgray' => '#696969', + 'dimgrey' => '#696969', + 'dodgerblue' => '#1E90FF', + 'firebrick' => '#B22222', + 'floralwhite' => '#FFFAF0', + 'forestgreen' => '#228B22', + 'fuchsia' => '#FF00FF', + 'gainsboro' => '#DCDCDC', + 'ghostwhite' => '#F8F8FF', + 'gold' => '#FFD700', + 'goldenrod' => '#DAA520', + 'gray' => '#808080', + 'grey' => '#808080', + 'green' => '#008000', + 'greenyellow' => '#ADFF2F', + 'honeydew' => '#F0FFF0', + 'hotpink' => '#FF69B4', + 'indianred' => '#CD5C5C', + 'indigo' => '#4B0082', + 'ivory' => '#FFFFF0', + 'khaki' => '#F0E68C', + 'lavender' => '#E6E6FA', + 'lavenderblush' => '#FFF0F5', + 'lawngreen' => '#7CFC00', + 'lemonchiffon' => '#FFFACD', + 'lightblue' => '#ADD8E6', + 'lightcoral' => '#F08080', + 'lightcyan' => '#E0FFFF', + 'lightgoldenrodyellow' => '#FAFAD2', + 'lightgray' => '#D3D3D3', + 'lightgrey' => '#D3D3D3', + 'lightgreen' => '#90EE90', + 'lightpink' => '#FFB6C1', + 'lightsalmon' => '#FFA07A', + 'lightseagreen' => '#20B2AA', + 'lightskyblue' => '#87CEFA', + 'lightslategray' => '#778899', + 'lightslategrey' => '#778899', + 'lightsteelblue' => '#B0C4DE', + 'lightyellow' => '#FFFFE0', + 'lime' => '#00FF00', + 'limegreen' => '#32CD32', + 'linen' => '#FAF0E6', + 'magenta' => '#FF00FF', + 'maroon' => '#800000', + 'mediumaquamarine' => '#66CDAA', + 'mediumblue' => '#0000CD', + 'mediumorchid' => '#BA55D3', + 'mediumpurple' => '#9370DB', + 'mediumseagreen' => '#3CB371', + 'mediumslateblue' => '#7B68EE', + 'mediumspringgreen' => '#00FA9A', + 'mediumturquoise' => '#48D1CC', + 'mediumvioletred' => '#C71585', + 'midnightblue' => '#191970', + 'mintcream' => '#F5FFFA', + 'mistyrose' => '#FFE4E1', + 'moccasin' => '#FFE4B5', + 'navajowhite' => '#FFDEAD', + 'navy' => '#000080', + 'oldlace' => '#FDF5E6', + 'olive' => '#808000', + 'olivedrab' => '#6B8E23', + 'orange' => '#FFA500', + 'orangered' => '#FF4500', + 'orchid' => '#DA70D6', + 'palegoldenrod' => '#EEE8AA', + 'palegreen' => '#98FB98', + 'paleturquoise' => '#AFEEEE', + 'palevioletred' => '#DB7093', + 'papayawhip' => '#FFEFD5', + 'peachpuff' => '#FFDAB9', + 'peru' => '#CD853F', + 'pink' => '#FFC0CB', + 'plum' => '#DDA0DD', + 'powderblue' => '#B0E0E6', + 'purple' => '#800080', + 'rebeccapurple' => '#663399', + 'red' => '#FF0000', + 'rosybrown' => '#BC8F8F', + 'royalblue' => '#4169E1', + 'saddlebrown' => '#8B4513', + 'salmon' => '#FA8072', + 'sandybrown' => '#F4A460', + 'seagreen' => '#2E8B57', + 'seashell' => '#FFF5EE', + 'sienna' => '#A0522D', + 'silver' => '#C0C0C0', + 'skyblue' => '#87CEEB', + 'slateblue' => '#6A5ACD', + 'slategray' => '#708090', + 'slategrey' => '#708090', + 'snow' => '#FFFAFA', + 'springgreen' => '#00FF7F', + 'steelblue' => '#4682B4', + 'tan' => '#D2B48C', + 'teal' => '#008080', + 'thistle' => '#D8BFD8', + 'tomato' => '#FF6347', + 'turquoise' => '#40E0D0', + 'violet' => '#EE82EE', + 'wheat' => '#F5DEB3', + 'white' => '#FFFFFF', + 'whitesmoke' => '#F5F5F5', + 'yellow' => '#FFFF00', + 'yellowgreen' => '#9ACD32' +) +--DESCRIPTION-- + +Lookup array of color names to six digit hexadecimal number corresponding +to color, with preceding hash mark. Used when parsing colors. The lookup +is done in a case-insensitive manner. +--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.ConvertDocumentToFragment.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ConvertDocumentToFragment.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.ConvertDocumentToFragment.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.ConvertDocumentToFragment.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.DirectLexLineNumberSyncInterval.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.DirectLexLineNumberSyncInterval.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.DirectLexLineNumberSyncInterval.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.DirectLexLineNumberSyncInterval.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.DisableExcludes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.DisableExcludes.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.DisableExcludes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.DisableExcludes.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EnableIDNA.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EnableIDNA.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EnableIDNA.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EnableIDNA.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.Encoding.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Encoding.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.Encoding.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Encoding.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidTags.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidTags.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidTags.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidTags.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeNonASCIICharacters.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeNonASCIICharacters.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.EscapeNonASCIICharacters.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeNonASCIICharacters.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.HiddenElements.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.HiddenElements.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.HiddenElements.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.HiddenElements.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.Language.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Language.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.Language.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.Language.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LegacyEntityDecoder.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LegacyEntityDecoder.txt new file mode 100644 index 000000000..392b43649 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LegacyEntityDecoder.txt @@ -0,0 +1,36 @@ +Core.LegacyEntityDecoder +TYPE: bool +VERSION: 4.9.0 +DEFAULT: false +--DESCRIPTION-- +

+ Prior to HTML Purifier 4.9.0, entities were decoded by performing + a global search replace for all entities whose decoded versions + did not have special meanings under HTML, and replaced them with + their decoded versions. We would match all entities, even if they did + not have a trailing semicolon, but only if there weren't any trailing + alphanumeric characters. +

+
'.$this->l('Bank name').''.$information['recipient_banking_instruction']['bank_name'].'

- {$rm_v['data_form']|date_format:"%d-%m-%Y"} + {$rm_v['data_form']}

- {$rm_v['data_to']|date_format:"%d-%m-%Y"} + {$rm_v['data_to']}

diff --git a/themes/hotel-reservation-theme/_partials/room_type_list.tpl b/themes/hotel-reservation-theme/_partials/room_type_list.tpl index 3f9a1181c..0d920373d 100644 --- a/themes/hotel-reservation-theme/_partials/room_type_list.tpl +++ b/themes/hotel-reservation-theme/_partials/room_type_list.tpl @@ -4,7 +4,8 @@
diff --git a/themes/hotel-reservation-theme/css/modules/productcomments/productcomments.css b/themes/hotel-reservation-theme/css/modules/productcomments/productcomments.css index 34f088823..dba2824d0 100644 --- a/themes/hotel-reservation-theme/css/modules/productcomments/productcomments.css +++ b/themes/hotel-reservation-theme/css/modules/productcomments/productcomments.css @@ -7,22 +7,15 @@ margin: 39px 0 22px; } #product_comments_block_extra .comments_note { margin-bottom: 5px; } - #product_comments_block_extra .comments_note span, - #product_comments_block_extra .star_content { + #product_comments_block_extra .comments_note span{ float: left; color: #333; } - #product_comments_block_extra .star_content { - margin-top: 1px; } - #product_comments_block_extra div.star:after { - content: "\f006"; - font-family: "FontAwesome"; - display: inline-block; - color: #777676; } - #product_comments_block_extra div.star_on:after { - content: "\f005"; - font-family: "FontAwesome"; - display: inline-block; - color: #e9ce18; } + .raty_star i[class^="icon-"] { + font-size: 22px; + color: #e9ce18; + } .raty_star i.icon-star-o { + color: #777777; + } #product_comments_block_extra .comments_advices { clear: both; } diff --git a/themes/hotel-reservation-theme/footer.tpl b/themes/hotel-reservation-theme/footer.tpl index ac0aab467..875ffe6ad 100644 --- a/themes/hotel-reservation-theme/footer.tpl +++ b/themes/hotel-reservation-theme/footer.tpl @@ -31,6 +31,7 @@
{if isset($HOOK_FOOTER)} + {hook h='displayFooterBefore'}
+ + + + + +
OriginalTextAttribute
&yen;¥¥
&yen¥¥
&yena&yena&yena
&yen=¥=¥=
+

+ In HTML Purifier 4.9.0, we changed the behavior of entity parsing + to match entities that had missing trailing semicolons in less + cases, to more closely match HTML5 parsing behavior: +

+ + + + + + +
OriginalTextAttribute
&yen;¥¥
&yen¥¥
&yena¥a&yena
&yen=¥=&yen=
+

+ This flag reverts back to pre-HTML Purifier 4.9.0 behavior. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.LexerImpl.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LexerImpl.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.LexerImpl.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.LexerImpl.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.MaintainLineNumbers.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.MaintainLineNumbers.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.MaintainLineNumbers.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.MaintainLineNumbers.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveInvalidImg.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveInvalidImg.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveInvalidImg.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveInvalidImg.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveProcessingInstructions.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveProcessingInstructions.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveProcessingInstructions.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveProcessingInstructions.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveScriptContents.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveScriptContents.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Core.RemoveScriptContents.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.RemoveScriptContents.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.Custom.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.Custom.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.Custom.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.Custom.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.YouTube.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.YouTube.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Filter.YouTube.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Filter.YouTube.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Allowed.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Allowed.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Allowed.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Allowed.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedAttributes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedAttributes.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedAttributes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedAttributes.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedComments.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedComments.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedComments.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedComments.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedCommentsRegexp.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedCommentsRegexp.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedCommentsRegexp.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedCommentsRegexp.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedElements.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedElements.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedElements.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedElements.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedModules.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedModules.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.AllowedModules.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.AllowedModules.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Attr.Name.UseCDATA.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Attr.Name.UseCDATA.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Attr.Name.UseCDATA.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Attr.Name.UseCDATA.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.BlockWrapper.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.BlockWrapper.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.BlockWrapper.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.BlockWrapper.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.CoreModules.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CoreModules.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.CoreModules.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CoreModules.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt similarity index 72% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt index a64e3d7c3..6ed70b599 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.CustomDoctype.txt @@ -4,6 +4,6 @@ VERSION: 2.0.1 DEFAULT: NULL --DESCRIPTION-- -A custom doctype for power-users who defined there own document +A custom doctype for power-users who defined their own document type. This directive only applies when %HTML.Doctype is blank. --# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionID.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionID.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionID.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionID.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionRev.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionRev.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionRev.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.DefinitionRev.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Doctype.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Doctype.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Doctype.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Doctype.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.FlashAllowFullScreen.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.FlashAllowFullScreen.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.FlashAllowFullScreen.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.FlashAllowFullScreen.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenAttributes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenAttributes.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenAttributes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenAttributes.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenElements.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenElements.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenElements.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.ForbiddenElements.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Forms.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Forms.txt new file mode 100644 index 000000000..4a432d89b --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Forms.txt @@ -0,0 +1,11 @@ +HTML.Forms +TYPE: bool +VERSION: 4.13.0 +DEFAULT: false +--DESCRIPTION-- +

+ Whether or not to permit form elements in the user input, regardless of + %HTML.Trusted value. Please be very careful when using this functionality, as + enabling forms in untrusted documents may allow for phishing attacks. +

+--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.MaxImgLength.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.MaxImgLength.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.MaxImgLength.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.MaxImgLength.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Nofollow.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Nofollow.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Nofollow.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Nofollow.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Parent.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Parent.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Parent.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Parent.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Proprietary.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Proprietary.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Proprietary.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Proprietary.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeEmbed.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeEmbed.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeEmbed.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeEmbed.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeIframe.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeIframe.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeIframe.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeIframe.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeObject.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeObject.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeObject.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeObject.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeScripting.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeScripting.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.SafeScripting.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.SafeScripting.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Strict.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Strict.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Strict.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Strict.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TargetBlank.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetBlank.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TargetBlank.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetBlank.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoopener.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoopener.txt new file mode 100644 index 000000000..dd514c0de --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoopener.txt @@ -0,0 +1,10 @@ +--# vim: et sw=4 sts=4 +HTML.TargetNoopener +TYPE: bool +VERSION: 4.8.0 +DEFAULT: TRUE +--DESCRIPTION-- +If enabled, noopener rel attributes are added to links which have +a target attribute associated with them. This prevents malicious +destinations from overwriting the original window. +--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoreferrer.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoreferrer.txt new file mode 100644 index 000000000..cb5a0b0e5 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TargetNoreferrer.txt @@ -0,0 +1,9 @@ +HTML.TargetNoreferrer +TYPE: bool +VERSION: 4.8.0 +DEFAULT: TRUE +--DESCRIPTION-- +If enabled, noreferrer rel attributes are added to links which have +a target attribute associated with them. This prevents malicious +destinations from overwriting the original window. +--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyAdd.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyAdd.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyAdd.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyAdd.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyLevel.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyLevel.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyLevel.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyLevel.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyRemove.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyRemove.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.TidyRemove.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.TidyRemove.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Trusted.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Trusted.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.Trusted.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.Trusted.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.XHTML.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.XHTML.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/HTML.XHTML.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/HTML.XHTML.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.CommentScriptContents.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.CommentScriptContents.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.CommentScriptContents.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.CommentScriptContents.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.FixInnerHTML.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FixInnerHTML.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.FixInnerHTML.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FixInnerHTML.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.FlashCompat.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FlashCompat.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.FlashCompat.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.FlashCompat.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.Newline.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.Newline.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.Newline.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.Newline.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.SortAttr.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.SortAttr.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.SortAttr.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.SortAttr.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.TidyFormat.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.TidyFormat.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Output.TidyFormat.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Output.TidyFormat.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Test.ForceNoIconv.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Test.ForceNoIconv.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/Test.ForceNoIconv.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Test.ForceNoIconv.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt similarity index 96% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt index 666635a5f..eb97307e2 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.AllowedSchemes.txt @@ -8,6 +8,7 @@ array ( 'ftp' => true, 'nntp' => true, 'news' => true, + 'tel' => true, ) --DESCRIPTION-- Whitelist that defines the schemes that a URI is allowed to have. This diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Base.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Base.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Base.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Base.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt similarity index 57% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt index 728e378cb..834bc08c0 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefaultScheme.txt @@ -1,5 +1,5 @@ URI.DefaultScheme -TYPE: string +TYPE: string/null DEFAULT: 'http' --DESCRIPTION-- @@ -7,4 +7,9 @@ DEFAULT: 'http' Defines through what scheme the output will be served, in order to select the proper object validator when no scheme information is present.

+ +

+ Starting with HTML Purifier 4.9.0, the default scheme can be null, in + which case we reject all URIs which do not have explicit schemes. +

--# vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefinitionID.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionID.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefinitionID.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionID.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefinitionRev.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionRev.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DefinitionRev.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DefinitionRev.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Disable.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Disable.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Disable.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Disable.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableExternal.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternal.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableExternal.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternal.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableExternalResources.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternalResources.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableExternalResources.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableExternalResources.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableResources.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableResources.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.DisableResources.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.DisableResources.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Host.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Host.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Host.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Host.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.HostBlacklist.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.HostBlacklist.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.HostBlacklist.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.HostBlacklist.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MakeAbsolute.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MakeAbsolute.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MakeAbsolute.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MakeAbsolute.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Munge.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Munge.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.Munge.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.Munge.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MungeResources.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeResources.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MungeResources.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeResources.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.OverrideAllowedSchemes.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.OverrideAllowedSchemes.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.OverrideAllowedSchemes.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.OverrideAllowedSchemes.txt diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.SafeIframeRegexp.txt b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.SafeIframeRegexp.txt similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/URI.SafeIframeRegexp.txt rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.SafeIframeRegexp.txt diff --git a/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/index.php b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/info.ini b/tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/info.ini similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/schema/info.ini rename to tools/htmlpurifier/HTMLPurifier/ConfigSchema/schema/info.ini diff --git a/tools/htmlpurifier/HTMLPurifier/ContentSets.php b/tools/htmlpurifier/HTMLPurifier/ContentSets.php new file mode 100644 index 000000000..543e3f8f1 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ContentSets.php @@ -0,0 +1,170 @@ + true) indexed by name. + * @type array + * @note This is in HTMLPurifier_HTMLDefinition->info_content_sets + */ + public $lookup = array(); + + /** + * Synchronized list of defined content sets (keys of info). + * @type array + */ + protected $keys = array(); + /** + * Synchronized list of defined content values (values of info). + * @type array + */ + protected $values = array(); + + /** + * Merges in module's content sets, expands identifiers in the content + * sets and populates the keys, values and lookup member variables. + * @param HTMLPurifier_HTMLModule[] $modules List of HTMLPurifier_HTMLModule + */ + public function __construct($modules) + { + if (!is_array($modules)) { + $modules = array($modules); + } + // populate content_sets based on module hints + // sorry, no way of overloading + foreach ($modules as $module) { + foreach ($module->content_sets as $key => $value) { + $temp = $this->convertToLookup($value); + if (isset($this->lookup[$key])) { + // add it into the existing content set + $this->lookup[$key] = array_merge($this->lookup[$key], $temp); + } else { + $this->lookup[$key] = $temp; + } + } + } + $old_lookup = false; + while ($old_lookup !== $this->lookup) { + $old_lookup = $this->lookup; + foreach ($this->lookup as $i => $set) { + $add = array(); + foreach ($set as $element => $x) { + if (isset($this->lookup[$element])) { + $add += $this->lookup[$element]; + unset($this->lookup[$i][$element]); + } + } + $this->lookup[$i] += $add; + } + } + + foreach ($this->lookup as $key => $lookup) { + $this->info[$key] = implode(' | ', array_keys($lookup)); + } + $this->keys = array_keys($this->info); + $this->values = array_values($this->info); + } + + /** + * Accepts a definition; generates and assigns a ChildDef for it + * @param HTMLPurifier_ElementDef $def HTMLPurifier_ElementDef reference + * @param HTMLPurifier_HTMLModule $module Module that defined the ElementDef + */ + public function generateChildDef(&$def, $module) + { + if (!empty($def->child)) { // already done! + return; + } + $content_model = $def->content_model; + if (is_string($content_model)) { + // Assume that $this->keys is alphanumeric + $def->content_model = preg_replace_callback( + '/\b(' . implode('|', $this->keys) . ')\b/', + array($this, 'generateChildDefCallback'), + $content_model + ); + //$def->content_model = str_replace( + // $this->keys, $this->values, $content_model); + } + $def->child = $this->getChildDef($def, $module); + } + + public function generateChildDefCallback($matches) + { + return $this->info[$matches[0]]; + } + + /** + * Instantiates a ChildDef based on content_model and content_model_type + * member variables in HTMLPurifier_ElementDef + * @note This will also defer to modules for custom HTMLPurifier_ChildDef + * subclasses that need content set expansion + * @param HTMLPurifier_ElementDef $def HTMLPurifier_ElementDef to have ChildDef extracted + * @param HTMLPurifier_HTMLModule $module Module that defined the ElementDef + * @return HTMLPurifier_ChildDef corresponding to ElementDef + */ + public function getChildDef($def, $module) + { + $value = $def->content_model; + if (is_object($value)) { + trigger_error( + 'Literal object child definitions should be stored in '. + 'ElementDef->child not ElementDef->content_model', + E_USER_NOTICE + ); + return $value; + } + switch ($def->content_model_type) { + case 'required': + return new HTMLPurifier_ChildDef_Required($value); + case 'optional': + return new HTMLPurifier_ChildDef_Optional($value); + case 'empty': + return new HTMLPurifier_ChildDef_Empty(); + case 'custom': + return new HTMLPurifier_ChildDef_Custom($value); + } + // defer to its module + $return = false; + if ($module->defines_child_def) { // save a func call + $return = $module->getChildDef($def); + } + if ($return !== false) { + return $return; + } + // error-out + trigger_error( + 'Could not determine which ChildDef class to instantiate', + E_USER_ERROR + ); + return false; + } + + /** + * Converts a string list of elements separated by pipes into + * a lookup array. + * @param string $string List of elements + * @return array Lookup array of elements + */ + protected function convertToLookup($string) + { + $array = explode('|', str_replace(' ', '', $string)); + $ret = array(); + foreach ($array as $k) { + $ret[$k] = true; + } + return $ret; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/Context.php b/tools/htmlpurifier/HTMLPurifier/Context.php new file mode 100644 index 000000000..00e509c85 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Context.php @@ -0,0 +1,95 @@ +_storage)) { + trigger_error( + "Name $name produces collision, cannot re-register", + E_USER_ERROR + ); + return; + } + $this->_storage[$name] =& $ref; + } + + /** + * Retrieves a variable reference from the context. + * @param string $name String name + * @param bool $ignore_error Boolean whether or not to ignore error + * @return mixed + */ + public function &get($name, $ignore_error = false) + { + if (!array_key_exists($name, $this->_storage)) { + if (!$ignore_error) { + trigger_error( + "Attempted to retrieve non-existent variable $name", + E_USER_ERROR + ); + } + $var = null; // so we can return by reference + return $var; + } + return $this->_storage[$name]; + } + + /** + * Destroys a variable in the context. + * @param string $name String name + */ + public function destroy($name) + { + if (!array_key_exists($name, $this->_storage)) { + trigger_error( + "Attempted to destroy non-existent variable $name", + E_USER_ERROR + ); + return; + } + unset($this->_storage[$name]); + } + + /** + * Checks whether or not the variable exists. + * @param string $name String name + * @return bool + */ + public function exists($name) + { + return array_key_exists($name, $this->_storage); + } + + /** + * Loads a series of variables from an associative array + * @param array $context_array Assoc array of variables to load + */ + public function loadArray($context_array) + { + foreach ($context_array as $key => $discard) { + $this->register($key, $context_array[$key]); + } + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/Definition.php b/tools/htmlpurifier/HTMLPurifier/Definition.php new file mode 100644 index 000000000..bc6d43364 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Definition.php @@ -0,0 +1,55 @@ +setup) { + return; + } + $this->setup = true; + $this->doSetup($config); + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache.php new file mode 100644 index 000000000..9aa8ff354 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache.php @@ -0,0 +1,129 @@ +type = $type; + } + + /** + * Generates a unique identifier for a particular configuration + * @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config + * @return string + */ + public function generateKey($config) + { + return $config->version . ',' . // possibly replace with function calls + $config->getBatchSerial($this->type) . ',' . + $config->get($this->type . '.DefinitionRev'); + } + + /** + * Tests whether or not a key is old with respect to the configuration's + * version and revision number. + * @param string $key Key to test + * @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config to test against + * @return bool + */ + public function isOld($key, $config) + { + if (substr_count($key, ',') < 2) { + return true; + } + list($version, $hash, $revision) = explode(',', $key, 3); + $compare = version_compare($version, $config->version); + // version mismatch, is always old + if ($compare != 0) { + return true; + } + // versions match, ids match, check revision number + if ($hash == $config->getBatchSerial($this->type) && + $revision < $config->get($this->type . '.DefinitionRev')) { + return true; + } + return false; + } + + /** + * Checks if a definition's type jives with the cache's type + * @note Throws an error on failure + * @param HTMLPurifier_Definition $def Definition object to check + * @return bool true if good, false if not + */ + public function checkDefType($def) + { + if ($def->type !== $this->type) { + trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); + return false; + } + return true; + } + + /** + * Adds a definition object to the cache + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + */ + abstract public function add($def, $config); + + /** + * Unconditionally saves a definition object to the cache + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + */ + abstract public function set($def, $config); + + /** + * Replace an object in the cache + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + */ + abstract public function replace($def, $config); + + /** + * Retrieves a definition object from the cache + * @param HTMLPurifier_Config $config + */ + abstract public function get($config); + + /** + * Removes a definition object to the cache + * @param HTMLPurifier_Config $config + */ + abstract public function remove($config); + + /** + * Clears all objects from cache + * @param HTMLPurifier_Config $config + */ + abstract public function flush($config); + + /** + * Clears all expired (older version or revision) objects from cache + * @note Be careful implementing this method as flush. Flush must + * not interfere with other Definition types, and cleanup() + * should not be repeatedly called by userland code. + * @param HTMLPurifier_Config $config + */ + abstract public function cleanup($config); +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator.php new file mode 100644 index 000000000..b57a51b6c --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator.php @@ -0,0 +1,112 @@ +copy(); + // reference is necessary for mocks in PHP 4 + $decorator->cache =& $cache; + $decorator->type = $cache->type; + return $decorator; + } + + /** + * Cross-compatible clone substitute + * @return HTMLPurifier_DefinitionCache_Decorator + */ + public function copy() + { + return new HTMLPurifier_DefinitionCache_Decorator(); + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function add($def, $config) + { + return $this->cache->add($def, $config); + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function set($def, $config) + { + return $this->cache->set($def, $config); + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function replace($def, $config) + { + return $this->cache->replace($def, $config); + } + + /** + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function get($config) + { + return $this->cache->get($config); + } + + /** + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function remove($config) + { + return $this->cache->remove($config); + } + + /** + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function flush($config) + { + return $this->cache->flush($config); + } + + /** + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function cleanup($config) + { + return $this->cache->cleanup($config); + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Cleanup.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Cleanup.php new file mode 100644 index 000000000..4991777ce --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Cleanup.php @@ -0,0 +1,78 @@ +definitions[$this->generateKey($config)] = $def; + } + return $status; + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function set($def, $config) + { + $status = parent::set($def, $config); + if ($status) { + $this->definitions[$this->generateKey($config)] = $def; + } + return $status; + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function replace($def, $config) + { + $status = parent::replace($def, $config); + if ($status) { + $this->definitions[$this->generateKey($config)] = $def; + } + return $status; + } + + /** + * @param HTMLPurifier_Config $config + * @return mixed + */ + public function get($config) + { + $key = $this->generateKey($config); + if (isset($this->definitions[$key])) { + return $this->definitions[$key]; + } + $this->definitions[$key] = parent::get($config); + return $this->definitions[$key]; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Template.php.in b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Template.php.in new file mode 100644 index 000000000..b1fec8d36 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Decorator/Template.php.in @@ -0,0 +1,82 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Null.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Null.php new file mode 100644 index 000000000..d9a75ce22 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Null.php @@ -0,0 +1,76 @@ +checkDefType($def)) { + return; + } + $file = $this->generateFilePath($config); + if (file_exists($file)) { + return false; + } + if (!$this->_prepareDir($config)) { + return false; + } + return $this->_write($file, serialize($def), $config); + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return int|bool + */ + public function set($def, $config) + { + if (!$this->checkDefType($def)) { + return; + } + $file = $this->generateFilePath($config); + if (!$this->_prepareDir($config)) { + return false; + } + return $this->_write($file, serialize($def), $config); + } + + /** + * @param HTMLPurifier_Definition $def + * @param HTMLPurifier_Config $config + * @return int|bool + */ + public function replace($def, $config) + { + if (!$this->checkDefType($def)) { + return; + } + $file = $this->generateFilePath($config); + if (!file_exists($file)) { + return false; + } + if (!$this->_prepareDir($config)) { + return false; + } + return $this->_write($file, serialize($def), $config); + } + + /** + * @param HTMLPurifier_Config $config + * @return bool|HTMLPurifier_Config + */ + public function get($config) + { + $file = $this->generateFilePath($config); + if (!file_exists($file)) { + return false; + } + return unserialize(file_get_contents($file)); + } + + /** + * @param HTMLPurifier_Config $config + * @return bool + */ + public function remove($config) + { + $file = $this->generateFilePath($config); + if (!file_exists($file)) { + return false; + } + return unlink($file); + } + + /** + * @param HTMLPurifier_Config $config + * @return bool + */ + public function flush($config) + { + if (!$this->_prepareDir($config)) { + return false; + } + $dir = $this->generateDirectoryPath($config); + $dh = opendir($dir); + // Apparently, on some versions of PHP, readdir will return + // an empty string if you pass an invalid argument to readdir. + // So you need this test. See #49. + if (false === $dh) { + return false; + } + while (false !== ($filename = readdir($dh))) { + if (empty($filename)) { + continue; + } + if ($filename[0] === '.') { + continue; + } + unlink($dir . '/' . $filename); + } + closedir($dh); + return true; + } + + /** + * @param HTMLPurifier_Config $config + * @return bool + */ + public function cleanup($config) + { + if (!$this->_prepareDir($config)) { + return false; + } + $dir = $this->generateDirectoryPath($config); + $dh = opendir($dir); + // See #49 (and above). + if (false === $dh) { + return false; + } + while (false !== ($filename = readdir($dh))) { + if (empty($filename)) { + continue; + } + if ($filename[0] === '.') { + continue; + } + $key = substr($filename, 0, strlen($filename) - 4); + if ($this->isOld($key, $config)) { + unlink($dir . '/' . $filename); + } + } + closedir($dh); + return true; + } + + /** + * Generates the file path to the serial file corresponding to + * the configuration and definition name + * @param HTMLPurifier_Config $config + * @return string + * @todo Make protected + */ + public function generateFilePath($config) + { + $key = $this->generateKey($config); + return $this->generateDirectoryPath($config) . '/' . $key . '.ser'; + } + + /** + * Generates the path to the directory contain this cache's serial files + * @param HTMLPurifier_Config $config + * @return string + * @note No trailing slash + * @todo Make protected + */ + public function generateDirectoryPath($config) + { + $base = $this->generateBaseDirectoryPath($config); + return $base . '/' . $this->type; + } + + /** + * Generates path to base directory that contains all definition type + * serials + * @param HTMLPurifier_Config $config + * @return mixed|string + * @todo Make protected + */ + public function generateBaseDirectoryPath($config) + { + $base = $config->get('Cache.SerializerPath'); + $base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base; + return $base; + } + + /** + * Convenience wrapper function for file_put_contents + * @param string $file File name to write to + * @param string $data Data to write into file + * @param HTMLPurifier_Config $config + * @return int|bool Number of bytes written if success, or false if failure. + */ + private function _write($file, $data, $config) + { + $result = file_put_contents($file, $data); + if ($result !== false) { + // set permissions of the new file (no execute) + $chmod = $config->get('Cache.SerializerPermissions'); + if ($chmod !== null) { + chmod($file, $chmod & 0666); + } + } + return $result; + } + + /** + * Prepares the directory that this type stores the serials in + * @param HTMLPurifier_Config $config + * @return bool True if successful + */ + private function _prepareDir($config) + { + $directory = $this->generateDirectoryPath($config); + $chmod = $config->get('Cache.SerializerPermissions'); + if ($chmod === null) { + if (!@mkdir($directory) && !is_dir($directory)) { + trigger_error( + 'Could not create directory ' . $directory . '', + E_USER_WARNING + ); + return false; + } + return true; + } + if (!is_dir($directory)) { + $base = $this->generateBaseDirectoryPath($config); + if (!is_dir($base)) { + trigger_error( + 'Base directory ' . $base . ' does not exist, + please create or change using %Cache.SerializerPath', + E_USER_WARNING + ); + return false; + } elseif (!$this->_testPermissions($base, $chmod)) { + return false; + } + if (!@mkdir($directory, $chmod) && !is_dir($directory)) { + trigger_error( + 'Could not create directory ' . $directory . '', + E_USER_WARNING + ); + return false; + } + if (!$this->_testPermissions($directory, $chmod)) { + return false; + } + } elseif (!$this->_testPermissions($directory, $chmod)) { + return false; + } + return true; + } + + /** + * Tests permissions on a directory and throws out friendly + * error messages and attempts to chmod it itself if possible + * @param string $dir Directory path + * @param int $chmod Permissions + * @return bool True if directory is writable + */ + private function _testPermissions($dir, $chmod) + { + // early abort, if it is writable, everything is hunky-dory + if (is_writable($dir)) { + return true; + } + if (!is_dir($dir)) { + // generally, you'll want to handle this beforehand + // so a more specific error message can be given + trigger_error( + 'Directory ' . $dir . ' does not exist', + E_USER_WARNING + ); + return false; + } + if (function_exists('posix_getuid') && $chmod !== null) { + // POSIX system, we can give more specific advice + if (fileowner($dir) === posix_getuid()) { + // we can chmod it ourselves + $chmod = $chmod | 0700; + if (chmod($dir, $chmod)) { + return true; + } + } elseif (filegroup($dir) === posix_getgid()) { + $chmod = $chmod | 0070; + } else { + // PHP's probably running as nobody, so we'll + // need to give global permissions + $chmod = $chmod | 0777; + } + trigger_error( + 'Directory ' . $dir . ' not writable, ' . + 'please chmod to ' . decoct($chmod), + E_USER_WARNING + ); + } else { + // generic error message + trigger_error( + 'Directory ' . $dir . ' not writable, ' . + 'please alter file permissions', + E_USER_WARNING + ); + } + return false; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/README b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/README new file mode 100755 index 000000000..2e35c1c3d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/README @@ -0,0 +1,3 @@ +This is a dummy file to prevent Git from ignoring this empty directory. + + vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/index.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/Serializer/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCache/index.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCache/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php b/tools/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php new file mode 100644 index 000000000..fd1cc9be4 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php @@ -0,0 +1,106 @@ + array()); + + /** + * @type array + */ + protected $implementations = array(); + + /** + * @type HTMLPurifier_DefinitionCache_Decorator[] + */ + protected $decorators = array(); + + /** + * Initialize default decorators + */ + public function setup() + { + $this->addDecorator('Cleanup'); + } + + /** + * Retrieves an instance of global definition cache factory. + * @param HTMLPurifier_DefinitionCacheFactory $prototype + * @return HTMLPurifier_DefinitionCacheFactory + */ + public static function instance($prototype = null) + { + static $instance; + if ($prototype !== null) { + $instance = $prototype; + } elseif ($instance === null || $prototype === true) { + $instance = new HTMLPurifier_DefinitionCacheFactory(); + $instance->setup(); + } + return $instance; + } + + /** + * Registers a new definition cache object + * @param string $short Short name of cache object, for reference + * @param string $long Full class name of cache object, for construction + */ + public function register($short, $long) + { + $this->implementations[$short] = $long; + } + + /** + * Factory method that creates a cache object based on configuration + * @param string $type Name of definitions handled by cache + * @param HTMLPurifier_Config $config Config instance + * @return mixed + */ + public function create($type, $config) + { + $method = $config->get('Cache.DefinitionImpl'); + if ($method === null) { + return new HTMLPurifier_DefinitionCache_Null($type); + } + if (!empty($this->caches[$method][$type])) { + return $this->caches[$method][$type]; + } + if (isset($this->implementations[$method]) && + class_exists($class = $this->implementations[$method], false)) { + $cache = new $class($type); + } else { + if ($method != 'Serializer') { + trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING); + } + $cache = new HTMLPurifier_DefinitionCache_Serializer($type); + } + foreach ($this->decorators as $decorator) { + $new_cache = $decorator->decorate($cache); + // prevent infinite recursion in PHP 4 + unset($cache); + $cache = $new_cache; + } + $this->caches[$method][$type] = $cache; + return $this->caches[$method][$type]; + } + + /** + * Registers a decorator to add to all new cache objects + * @param HTMLPurifier_DefinitionCache_Decorator|string $decorator An instance or the name of a decorator + */ + public function addDecorator($decorator) + { + if (is_string($decorator)) { + $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator"; + $decorator = new $class; + } + $this->decorators[$decorator->name] = $decorator; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/Doctype.php b/tools/htmlpurifier/HTMLPurifier/Doctype.php new file mode 100644 index 000000000..4acd06e5b --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Doctype.php @@ -0,0 +1,73 @@ +renderDoctype. + * If structure changes, please update that function. + */ +class HTMLPurifier_Doctype +{ + /** + * Full name of doctype + * @type string + */ + public $name; + + /** + * List of standard modules (string identifiers or literal objects) + * that this doctype uses + * @type array + */ + public $modules = array(); + + /** + * List of modules to use for tidying up code + * @type array + */ + public $tidyModules = array(); + + /** + * Is the language derived from XML (i.e. XHTML)? + * @type bool + */ + public $xml = true; + + /** + * List of aliases for this doctype + * @type array + */ + public $aliases = array(); + + /** + * Public DTD identifier + * @type string + */ + public $dtdPublic; + + /** + * System DTD identifier + * @type string + */ + public $dtdSystem; + + public function __construct( + $name = null, + $xml = true, + $modules = array(), + $tidyModules = array(), + $aliases = array(), + $dtd_public = null, + $dtd_system = null + ) { + $this->name = $name; + $this->xml = $xml; + $this->modules = $modules; + $this->tidyModules = $tidyModules; + $this->aliases = $aliases; + $this->dtdPublic = $dtd_public; + $this->dtdSystem = $dtd_system; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/DoctypeRegistry.php b/tools/htmlpurifier/HTMLPurifier/DoctypeRegistry.php new file mode 100644 index 000000000..acc1d64a6 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/DoctypeRegistry.php @@ -0,0 +1,142 @@ +doctypes[$doctype->name] = $doctype; + $name = $doctype->name; + // hookup aliases + foreach ($doctype->aliases as $alias) { + if (isset($this->doctypes[$alias])) { + continue; + } + $this->aliases[$alias] = $name; + } + // remove old aliases + if (isset($this->aliases[$name])) { + unset($this->aliases[$name]); + } + return $doctype; + } + + /** + * Retrieves reference to a doctype of a certain name + * @note This function resolves aliases + * @note When possible, use the more fully-featured make() + * @param string $doctype Name of doctype + * @return HTMLPurifier_Doctype Editable doctype object + */ + public function get($doctype) + { + if (isset($this->aliases[$doctype])) { + $doctype = $this->aliases[$doctype]; + } + if (!isset($this->doctypes[$doctype])) { + trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR); + $anon = new HTMLPurifier_Doctype($doctype); + return $anon; + } + return $this->doctypes[$doctype]; + } + + /** + * Creates a doctype based on a configuration object, + * will perform initialization on the doctype + * @note Use this function to get a copy of doctype that config + * can hold on to (this is necessary in order to tell + * Generator whether or not the current document is XML + * based or not). + * @param HTMLPurifier_Config $config + * @return HTMLPurifier_Doctype + */ + public function make($config) + { + return clone $this->get($this->getDoctypeFromConfig($config)); + } + + /** + * Retrieves the doctype from the configuration object + * @param HTMLPurifier_Config $config + * @return string + */ + public function getDoctypeFromConfig($config) + { + // recommended test + $doctype = $config->get('HTML.Doctype'); + if (!empty($doctype)) { + return $doctype; + } + $doctype = $config->get('HTML.CustomDoctype'); + if (!empty($doctype)) { + return $doctype; + } + // backwards-compatibility + if ($config->get('HTML.XHTML')) { + $doctype = 'XHTML 1.0'; + } else { + $doctype = 'HTML 4.01'; + } + if ($config->get('HTML.Strict')) { + $doctype .= ' Strict'; + } else { + $doctype .= ' Transitional'; + } + return $doctype; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ElementDef.php b/tools/htmlpurifier/HTMLPurifier/ElementDef.php new file mode 100644 index 000000000..d5311cedc --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ElementDef.php @@ -0,0 +1,216 @@ +setup(), this array may also + * contain an array at index 0 that indicates which attribute + * collections to load into the full array. It may also + * contain string indentifiers in lieu of HTMLPurifier_AttrDef, + * see HTMLPurifier_AttrTypes on how they are expanded during + * HTMLPurifier_HTMLDefinition->setup() processing. + */ + public $attr = array(); + + // XXX: Design note: currently, it's not possible to override + // previously defined AttrTransforms without messing around with + // the final generated config. This is by design; a previous version + // used an associated list of attr_transform, but it was extremely + // easy to accidentally override other attribute transforms by + // forgetting to specify an index (and just using 0.) While we + // could check this by checking the index number and complaining, + // there is a second problem which is that it is not at all easy to + // tell when something is getting overridden. Combine this with a + // codebase where this isn't really being used, and it's perfect for + // nuking. + + /** + * List of tags HTMLPurifier_AttrTransform to be done before validation. + * @type array + */ + public $attr_transform_pre = array(); + + /** + * List of tags HTMLPurifier_AttrTransform to be done after validation. + * @type array + */ + public $attr_transform_post = array(); + + /** + * HTMLPurifier_ChildDef of this tag. + * @type HTMLPurifier_ChildDef + */ + public $child; + + /** + * Abstract string representation of internal ChildDef rules. + * @see HTMLPurifier_ContentSets for how this is parsed and then transformed + * into an HTMLPurifier_ChildDef. + * @warning This is a temporary variable that is not available after + * being processed by HTMLDefinition + * @type string + */ + public $content_model; + + /** + * Value of $child->type, used to determine which ChildDef to use, + * used in combination with $content_model. + * @warning This must be lowercase + * @warning This is a temporary variable that is not available after + * being processed by HTMLDefinition + * @type string + */ + public $content_model_type; + + /** + * Does the element have a content model (#PCDATA | Inline)*? This + * is important for chameleon ins and del processing in + * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't + * have to worry about this one. + * @type bool + */ + public $descendants_are_inline = false; + + /** + * List of the names of required attributes this element has. + * Dynamically populated by HTMLPurifier_HTMLDefinition::getElement() + * @type array + */ + public $required_attr = array(); + + /** + * Lookup table of tags excluded from all descendants of this tag. + * @type array + * @note SGML permits exclusions for all descendants, but this is + * not possible with DTDs or XML Schemas. W3C has elected to + * use complicated compositions of content_models to simulate + * exclusion for children, but we go the simpler, SGML-style + * route of flat-out exclusions, which correctly apply to + * all descendants and not just children. Note that the XHTML + * Modularization Abstract Modules are blithely unaware of such + * distinctions. + */ + public $excludes = array(); + + /** + * This tag is explicitly auto-closed by the following tags. + * @type array + */ + public $autoclose = array(); + + /** + * If a foreign element is found in this element, test if it is + * allowed by this sub-element; if it is, instead of closing the + * current element, place it inside this element. + * @type string + */ + public $wrap; + + /** + * Whether or not this is a formatting element affected by the + * "Active Formatting Elements" algorithm. + * @type bool + */ + public $formatting; + + /** + * Low-level factory constructor for creating new standalone element defs + */ + public static function create($content_model, $content_model_type, $attr) + { + $def = new HTMLPurifier_ElementDef(); + $def->content_model = $content_model; + $def->content_model_type = $content_model_type; + $def->attr = $attr; + return $def; + } + + /** + * Merges the values of another element definition into this one. + * Values from the new element def take precedence if a value is + * not mergeable. + * @param HTMLPurifier_ElementDef $def + */ + public function mergeIn($def) + { + // later keys takes precedence + foreach ($def->attr as $k => $v) { + if ($k === 0) { + // merge in the includes + // sorry, no way to override an include + foreach ($v as $v2) { + $this->attr[0][] = $v2; + } + continue; + } + if ($v === false) { + if (isset($this->attr[$k])) { + unset($this->attr[$k]); + } + continue; + } + $this->attr[$k] = $v; + } + $this->_mergeAssocArray($this->excludes, $def->excludes); + $this->attr_transform_pre = array_merge($this->attr_transform_pre, $def->attr_transform_pre); + $this->attr_transform_post = array_merge($this->attr_transform_post, $def->attr_transform_post); + + if (!empty($def->content_model)) { + $this->content_model = + str_replace("#SUPER", $this->content_model, $def->content_model); + $this->child = false; + } + if (!empty($def->content_model_type)) { + $this->content_model_type = $def->content_model_type; + $this->child = false; + } + if (!is_null($def->child)) { + $this->child = $def->child; + } + if (!is_null($def->formatting)) { + $this->formatting = $def->formatting; + } + if ($def->descendants_are_inline) { + $this->descendants_are_inline = $def->descendants_are_inline; + } + } + + /** + * Merges one array into another, removes values which equal false + * @param $a1 Array by reference that is merged into + * @param $a2 Array that merges into $a1 + */ + private function _mergeAssocArray(&$a1, $a2) + { + foreach ($a2 as $k => $v) { + if ($v === false) { + if (isset($a1[$k])) { + unset($a1[$k]); + } + continue; + } + $a1[$k] = $v; + } + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/Encoder.php b/tools/htmlpurifier/HTMLPurifier/Encoder.php new file mode 100644 index 000000000..40a24266a --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Encoder.php @@ -0,0 +1,617 @@ += $c) { + $r .= self::unsafeIconv($in, $out, substr($text, $i)); + break; + } + // wibble the boundary + if (0x80 != (0xC0 & ord($text[$i + $max_chunk_size]))) { + $chunk_size = $max_chunk_size; + } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 1]))) { + $chunk_size = $max_chunk_size - 1; + } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 2]))) { + $chunk_size = $max_chunk_size - 2; + } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 3]))) { + $chunk_size = $max_chunk_size - 3; + } else { + return false; // rather confusing UTF-8... + } + $chunk = substr($text, $i, $chunk_size); // substr doesn't mind overlong lengths + $r .= self::unsafeIconv($in, $out, $chunk); + $i += $chunk_size; + } + return $r; + } else { + return false; + } + } else { + return false; + } + } + + /** + * Cleans a UTF-8 string for well-formedness and SGML validity + * + * It will parse according to UTF-8 and return a valid UTF8 string, with + * non-SGML codepoints excluded. + * + * Specifically, it will permit: + * \x{9}\x{A}\x{D}\x{20}-\x{7E}\x{A0}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF} + * Source: https://www.w3.org/TR/REC-xml/#NT-Char + * Arguably this function should be modernized to the HTML5 set + * of allowed characters: + * https://www.w3.org/TR/html5/syntax.html#preprocessing-the-input-stream + * which simultaneously expand and restrict the set of allowed characters. + * + * @param string $str The string to clean + * @param bool $force_php + * @return string + * + * @note Just for reference, the non-SGML code points are 0 to 31 and + * 127 to 159, inclusive. However, we allow code points 9, 10 + * and 13, which are the tab, line feed and carriage return + * respectively. 128 and above the code points map to multibyte + * UTF-8 representations. + * + * @note Fallback code adapted from utf8ToUnicode by Henri Sivonen and + * hsivonen@iki.fi at under the + * LGPL license. Notes on what changed are inside, but in general, + * the original code transformed UTF-8 text into an array of integer + * Unicode codepoints. Understandably, transforming that back to + * a string would be somewhat expensive, so the function was modded to + * directly operate on the string. However, this discourages code + * reuse, and the logic enumerated here would be useful for any + * function that needs to be able to understand UTF-8 characters. + * As of right now, only smart lossless character encoding converters + * would need that, and I'm probably not going to implement them. + */ + public static function cleanUTF8($str, $force_php = false) + { + // UTF-8 validity is checked since PHP 4.3.5 + // This is an optimization: if the string is already valid UTF-8, no + // need to do PHP stuff. 99% of the time, this will be the case. + if (preg_match( + '/^[\x{9}\x{A}\x{D}\x{20}-\x{7E}\x{A0}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]*$/Du', + $str + )) { + return $str; + } + + $mState = 0; // cached expected number of octets after the current octet + // until the beginning of the next UTF8 character sequence + $mUcs4 = 0; // cached Unicode character + $mBytes = 1; // cached expected number of octets in the current sequence + + // original code involved an $out that was an array of Unicode + // codepoints. Instead of having to convert back into UTF-8, we've + // decided to directly append valid UTF-8 characters onto a string + // $out once they're done. $char accumulates raw bytes, while $mUcs4 + // turns into the Unicode code point, so there's some redundancy. + + $out = ''; + $char = ''; + + $len = strlen($str); + for ($i = 0; $i < $len; $i++) { + $in = ord($str[$i]); + $char .= $str[$i]; // append byte to char + if (0 == $mState) { + // When mState is zero we expect either a US-ASCII character + // or a multi-octet sequence. + if (0 == (0x80 & ($in))) { + // US-ASCII, pass straight through. + if (($in <= 31 || $in == 127) && + !($in == 9 || $in == 13 || $in == 10) // save \r\t\n + ) { + // control characters, remove + } else { + $out .= $char; + } + // reset + $char = ''; + $mBytes = 1; + } elseif (0xC0 == (0xE0 & ($in))) { + // First octet of 2 octet sequence + $mUcs4 = ($in); + $mUcs4 = ($mUcs4 & 0x1F) << 6; + $mState = 1; + $mBytes = 2; + } elseif (0xE0 == (0xF0 & ($in))) { + // First octet of 3 octet sequence + $mUcs4 = ($in); + $mUcs4 = ($mUcs4 & 0x0F) << 12; + $mState = 2; + $mBytes = 3; + } elseif (0xF0 == (0xF8 & ($in))) { + // First octet of 4 octet sequence + $mUcs4 = ($in); + $mUcs4 = ($mUcs4 & 0x07) << 18; + $mState = 3; + $mBytes = 4; + } elseif (0xF8 == (0xFC & ($in))) { + // First octet of 5 octet sequence. + // + // This is illegal because the encoded codepoint must be + // either: + // (a) not the shortest form or + // (b) outside the Unicode range of 0-0x10FFFF. + // Rather than trying to resynchronize, we will carry on + // until the end of the sequence and let the later error + // handling code catch it. + $mUcs4 = ($in); + $mUcs4 = ($mUcs4 & 0x03) << 24; + $mState = 4; + $mBytes = 5; + } elseif (0xFC == (0xFE & ($in))) { + // First octet of 6 octet sequence, see comments for 5 + // octet sequence. + $mUcs4 = ($in); + $mUcs4 = ($mUcs4 & 1) << 30; + $mState = 5; + $mBytes = 6; + } else { + // Current octet is neither in the US-ASCII range nor a + // legal first octet of a multi-octet sequence. + $mState = 0; + $mUcs4 = 0; + $mBytes = 1; + $char = ''; + } + } else { + // When mState is non-zero, we expect a continuation of the + // multi-octet sequence + if (0x80 == (0xC0 & ($in))) { + // Legal continuation. + $shift = ($mState - 1) * 6; + $tmp = $in; + $tmp = ($tmp & 0x0000003F) << $shift; + $mUcs4 |= $tmp; + + if (0 == --$mState) { + // End of the multi-octet sequence. mUcs4 now contains + // the final Unicode codepoint to be output + + // Check for illegal sequences and codepoints. + + // From Unicode 3.1, non-shortest form is illegal + if (((2 == $mBytes) && ($mUcs4 < 0x0080)) || + ((3 == $mBytes) && ($mUcs4 < 0x0800)) || + ((4 == $mBytes) && ($mUcs4 < 0x10000)) || + (4 < $mBytes) || + // From Unicode 3.2, surrogate characters = illegal + (($mUcs4 & 0xFFFFF800) == 0xD800) || + // Codepoints outside the Unicode range are illegal + ($mUcs4 > 0x10FFFF) + ) { + + } elseif (0xFEFF != $mUcs4 && // omit BOM + // check for valid Char unicode codepoints + ( + 0x9 == $mUcs4 || + 0xA == $mUcs4 || + 0xD == $mUcs4 || + (0x20 <= $mUcs4 && 0x7E >= $mUcs4) || + // 7F-9F is not strictly prohibited by XML, + // but it is non-SGML, and thus we don't allow it + (0xA0 <= $mUcs4 && 0xD7FF >= $mUcs4) || + (0xE000 <= $mUcs4 && 0xFFFD >= $mUcs4) || + (0x10000 <= $mUcs4 && 0x10FFFF >= $mUcs4) + ) + ) { + $out .= $char; + } + // initialize UTF8 cache (reset) + $mState = 0; + $mUcs4 = 0; + $mBytes = 1; + $char = ''; + } + } else { + // ((0xC0 & (*in) != 0x80) && (mState != 0)) + // Incomplete multi-octet sequence. + // used to result in complete fail, but we'll reset + $mState = 0; + $mUcs4 = 0; + $mBytes = 1; + $char =''; + } + } + } + return $out; + } + + /** + * Translates a Unicode codepoint into its corresponding UTF-8 character. + * @note Based on Feyd's function at + * , + * which is in public domain. + * @note While we're going to do code point parsing anyway, a good + * optimization would be to refuse to translate code points that + * are non-SGML characters. However, this could lead to duplication. + * @note This is very similar to the unichr function in + * maintenance/generate-entity-file.php (although this is superior, + * due to its sanity checks). + */ + + // +----------+----------+----------+----------+ + // | 33222222 | 22221111 | 111111 | | + // | 10987654 | 32109876 | 54321098 | 76543210 | bit + // +----------+----------+----------+----------+ + // | | | | 0xxxxxxx | 1 byte 0x00000000..0x0000007F + // | | | 110yyyyy | 10xxxxxx | 2 byte 0x00000080..0x000007FF + // | | 1110zzzz | 10yyyyyy | 10xxxxxx | 3 byte 0x00000800..0x0000FFFF + // | 11110www | 10wwzzzz | 10yyyyyy | 10xxxxxx | 4 byte 0x00010000..0x0010FFFF + // +----------+----------+----------+----------+ + // | 00000000 | 00011111 | 11111111 | 11111111 | Theoretical upper limit of legal scalars: 2097151 (0x001FFFFF) + // | 00000000 | 00010000 | 11111111 | 11111111 | Defined upper limit of legal scalar codes + // +----------+----------+----------+----------+ + + public static function unichr($code) + { + if ($code > 1114111 or $code < 0 or + ($code >= 55296 and $code <= 57343) ) { + // bits are set outside the "valid" range as defined + // by UNICODE 4.1.0 + return ''; + } + + $x = $y = $z = $w = 0; + if ($code < 128) { + // regular ASCII character + $x = $code; + } else { + // set up bits for UTF-8 + $x = ($code & 63) | 128; + if ($code < 2048) { + $y = (($code & 2047) >> 6) | 192; + } else { + $y = (($code & 4032) >> 6) | 128; + if ($code < 65536) { + $z = (($code >> 12) & 15) | 224; + } else { + $z = (($code >> 12) & 63) | 128; + $w = (($code >> 18) & 7) | 240; + } + } + } + // set up the actual character + $ret = ''; + if ($w) { + $ret .= chr($w); + } + if ($z) { + $ret .= chr($z); + } + if ($y) { + $ret .= chr($y); + } + $ret .= chr($x); + + return $ret; + } + + /** + * @return bool + */ + public static function iconvAvailable() + { + static $iconv = null; + if ($iconv === null) { + $iconv = function_exists('iconv') && self::testIconvTruncateBug() != self::ICONV_UNUSABLE; + } + return $iconv; + } + + /** + * Convert a string to UTF-8 based on configuration. + * @param string $str The string to convert + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return string + */ + public static function convertToUTF8($str, $config, $context) + { + $encoding = $config->get('Core.Encoding'); + if ($encoding === 'utf-8') { + return $str; + } + static $iconv = null; + if ($iconv === null) { + $iconv = self::iconvAvailable(); + } + if ($iconv && !$config->get('Test.ForceNoIconv')) { + // unaffected by bugs, since UTF-8 support all characters + $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str); + if ($str === false) { + // $encoding is not a valid encoding + trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR); + return ''; + } + // If the string is bjorked by Shift_JIS or a similar encoding + // that doesn't support all of ASCII, convert the naughty + // characters to their true byte-wise ASCII/UTF-8 equivalents. + $str = strtr($str, self::testEncodingSupportsASCII($encoding)); + return $str; + } elseif ($encoding === 'iso-8859-1') { + $str = utf8_encode($str); + return $str; + } + $bug = HTMLPurifier_Encoder::testIconvTruncateBug(); + if ($bug == self::ICONV_OK) { + trigger_error('Encoding not supported, please install iconv', E_USER_ERROR); + } else { + trigger_error( + 'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' . + 'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541', + E_USER_ERROR + ); + } + } + + /** + * Converts a string from UTF-8 based on configuration. + * @param string $str The string to convert + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return string + * @note Currently, this is a lossy conversion, with unexpressable + * characters being omitted. + */ + public static function convertFromUTF8($str, $config, $context) + { + $encoding = $config->get('Core.Encoding'); + if ($escape = $config->get('Core.EscapeNonASCIICharacters')) { + $str = self::convertToASCIIDumbLossless($str); + } + if ($encoding === 'utf-8') { + return $str; + } + static $iconv = null; + if ($iconv === null) { + $iconv = self::iconvAvailable(); + } + if ($iconv && !$config->get('Test.ForceNoIconv')) { + // Undo our previous fix in convertToUTF8, otherwise iconv will barf + $ascii_fix = self::testEncodingSupportsASCII($encoding); + if (!$escape && !empty($ascii_fix)) { + $clear_fix = array(); + foreach ($ascii_fix as $utf8 => $native) { + $clear_fix[$utf8] = ''; + } + $str = strtr($str, $clear_fix); + } + $str = strtr($str, array_flip($ascii_fix)); + // Normal stuff + $str = self::iconv('utf-8', $encoding . '//IGNORE', $str); + return $str; + } elseif ($encoding === 'iso-8859-1') { + $str = utf8_decode($str); + return $str; + } + trigger_error('Encoding not supported', E_USER_ERROR); + // You might be tempted to assume that the ASCII representation + // might be OK, however, this is *not* universally true over all + // encodings. So we take the conservative route here, rather + // than forcibly turn on %Core.EscapeNonASCIICharacters + } + + /** + * Lossless (character-wise) conversion of HTML to ASCII + * @param string $str UTF-8 string to be converted to ASCII + * @return string ASCII encoded string with non-ASCII character entity-ized + * @warning Adapted from MediaWiki, claiming fair use: this is a common + * algorithm. If you disagree with this license fudgery, + * implement it yourself. + * @note Uses decimal numeric entities since they are best supported. + * @note This is a DUMB function: it has no concept of keeping + * character entities that the projected character encoding + * can allow. We could possibly implement a smart version + * but that would require it to also know which Unicode + * codepoints the charset supported (not an easy task). + * @note Sort of with cleanUTF8() but it assumes that $str is + * well-formed UTF-8 + */ + public static function convertToASCIIDumbLossless($str) + { + $bytesleft = 0; + $result = ''; + $working = 0; + $len = strlen($str); + for ($i = 0; $i < $len; $i++) { + $bytevalue = ord($str[$i]); + if ($bytevalue <= 0x7F) { //0xxx xxxx + $result .= chr($bytevalue); + $bytesleft = 0; + } elseif ($bytevalue <= 0xBF) { //10xx xxxx + $working = $working << 6; + $working += ($bytevalue & 0x3F); + $bytesleft--; + if ($bytesleft <= 0) { + $result .= "&#" . $working . ";"; + } + } elseif ($bytevalue <= 0xDF) { //110x xxxx + $working = $bytevalue & 0x1F; + $bytesleft = 1; + } elseif ($bytevalue <= 0xEF) { //1110 xxxx + $working = $bytevalue & 0x0F; + $bytesleft = 2; + } else { //1111 0xxx + $working = $bytevalue & 0x07; + $bytesleft = 3; + } + } + return $result; + } + + /** No bugs detected in iconv. */ + const ICONV_OK = 0; + + /** Iconv truncates output if converting from UTF-8 to another + * character set with //IGNORE, and a non-encodable character is found */ + const ICONV_TRUNCATES = 1; + + /** Iconv does not support //IGNORE, making it unusable for + * transcoding purposes */ + const ICONV_UNUSABLE = 2; + + /** + * glibc iconv has a known bug where it doesn't handle the magic + * //IGNORE stanza correctly. In particular, rather than ignore + * characters, it will return an EILSEQ after consuming some number + * of characters, and expect you to restart iconv as if it were + * an E2BIG. Old versions of PHP did not respect the errno, and + * returned the fragment, so as a result you would see iconv + * mysteriously truncating output. We can work around this by + * manually chopping our input into segments of about 8000 + * characters, as long as PHP ignores the error code. If PHP starts + * paying attention to the error code, iconv becomes unusable. + * + * @return int Error code indicating severity of bug. + */ + public static function testIconvTruncateBug() + { + static $code = null; + if ($code === null) { + // better not use iconv, otherwise infinite loop! + $r = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1" . str_repeat('a', 9000)); + if ($r === false) { + $code = self::ICONV_UNUSABLE; + } elseif (($c = strlen($r)) < 9000) { + $code = self::ICONV_TRUNCATES; + } elseif ($c > 9000) { + trigger_error( + 'Your copy of iconv is extremely buggy. Please notify HTML Purifier maintainers: ' . + 'include your iconv version as per phpversion()', + E_USER_ERROR + ); + } else { + $code = self::ICONV_OK; + } + } + return $code; + } + + /** + * This expensive function tests whether or not a given character + * encoding supports ASCII. 7/8-bit encodings like Shift_JIS will + * fail this test, and require special processing. Variable width + * encodings shouldn't ever fail. + * + * @param string $encoding Encoding name to test, as per iconv format + * @param bool $bypass Whether or not to bypass the precompiled arrays. + * @return Array of UTF-8 characters to their corresponding ASCII, + * which can be used to "undo" any overzealous iconv action. + */ + public static function testEncodingSupportsASCII($encoding, $bypass = false) + { + // All calls to iconv here are unsafe, proof by case analysis: + // If ICONV_OK, no difference. + // If ICONV_TRUNCATE, all calls involve one character inputs, + // so bug is not triggered. + // If ICONV_UNUSABLE, this call is irrelevant + static $encodings = array(); + if (!$bypass) { + if (isset($encodings[$encoding])) { + return $encodings[$encoding]; + } + $lenc = strtolower($encoding); + switch ($lenc) { + case 'shift_jis': + return array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~'); + case 'johab': + return array("\xE2\x82\xA9" => '\\'); + } + if (strpos($lenc, 'iso-8859-') === 0) { + return array(); + } + } + $ret = array(); + if (self::unsafeIconv('UTF-8', $encoding, 'a') === false) { + return false; + } + for ($i = 0x20; $i <= 0x7E; $i++) { // all printable ASCII chars + $c = chr($i); // UTF-8 char + $r = self::unsafeIconv('UTF-8', "$encoding//IGNORE", $c); // initial conversion + if ($r === '' || + // This line is needed for iconv implementations that do not + // omit characters that do not exist in the target character set + ($r === $c && self::unsafeIconv($encoding, 'UTF-8//IGNORE', $r) !== $c) + ) { + // Reverse engineer: what's the UTF-8 equiv of this byte + // sequence? This assumes that there's no variable width + // encoding that doesn't support ASCII. + $ret[self::unsafeIconv($encoding, 'UTF-8//IGNORE', $c)] = $c; + } + } + $encodings[$encoding] = $ret; + return $ret; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/EntityLookup.php b/tools/htmlpurifier/HTMLPurifier/EntityLookup.php new file mode 100644 index 000000000..f12ff13a3 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/EntityLookup.php @@ -0,0 +1,48 @@ +table = unserialize(file_get_contents($file)); + } + + /** + * Retrieves sole instance of the object. + * @param bool|HTMLPurifier_EntityLookup $prototype Optional prototype of custom lookup table to overload with. + * @return HTMLPurifier_EntityLookup + */ + public static function instance($prototype = false) + { + // no references, since PHP doesn't copy unless modified + static $instance = null; + if ($prototype) { + $instance = $prototype; + } elseif (!$instance) { + $instance = new HTMLPurifier_EntityLookup(); + $instance->setup(); + } + return $instance; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/EntityLookup/entities.ser b/tools/htmlpurifier/HTMLPurifier/EntityLookup/entities.ser similarity index 100% rename from tools/htmlpurifier/standalone/HTMLPurifier/EntityLookup/entities.ser rename to tools/htmlpurifier/HTMLPurifier/EntityLookup/entities.ser diff --git a/tools/htmlpurifier/HTMLPurifier/EntityLookup/index.php b/tools/htmlpurifier/HTMLPurifier/EntityLookup/index.php new file mode 100644 index 000000000..051e0122d --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/EntityLookup/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2021 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; diff --git a/tools/htmlpurifier/HTMLPurifier/EntityParser.php b/tools/htmlpurifier/HTMLPurifier/EntityParser.php new file mode 100644 index 000000000..3ef2d09ec --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/EntityParser.php @@ -0,0 +1,285 @@ +_semiOptionalPrefixRegex = "/&()()()($semi_optional)/"; + + $this->_textEntitiesRegex = + '/&(?:'. + // hex + '[#]x([a-fA-F0-9]+);?|'. + // dec + '[#]0*(\d+);?|'. + // string (mandatory semicolon) + // NB: order matters: match semicolon preferentially + '([A-Za-z_:][A-Za-z0-9.\-_:]*);|'. + // string (optional semicolon) + "($semi_optional)". + ')/'; + + $this->_attrEntitiesRegex = + '/&(?:'. + // hex + '[#]x([a-fA-F0-9]+);?|'. + // dec + '[#]0*(\d+);?|'. + // string (mandatory semicolon) + // NB: order matters: match semicolon preferentially + '([A-Za-z_:][A-Za-z0-9.\-_:]*);|'. + // string (optional semicolon) + // don't match if trailing is equals or alphanumeric (URL + // like) + "($semi_optional)(?![=;A-Za-z0-9])". + ')/'; + + } + + /** + * Substitute entities with the parsed equivalents. Use this on + * textual data in an HTML document (as opposed to attributes.) + * + * @param string $string String to have entities parsed. + * @return string Parsed string. + */ + public function substituteTextEntities($string) + { + return preg_replace_callback( + $this->_textEntitiesRegex, + array($this, 'entityCallback'), + $string + ); + } + + /** + * Substitute entities with the parsed equivalents. Use this on + * attribute contents in documents. + * + * @param string $string String to have entities parsed. + * @return string Parsed string. + */ + public function substituteAttrEntities($string) + { + return preg_replace_callback( + $this->_attrEntitiesRegex, + array($this, 'entityCallback'), + $string + ); + } + + /** + * Callback function for substituteNonSpecialEntities() that does the work. + * + * @param array $matches PCRE matches array, with 0 the entire match, and + * either index 1, 2 or 3 set with a hex value, dec value, + * or string (respectively). + * @return string Replacement string. + */ + + protected function entityCallback($matches) + { + $entity = $matches[0]; + $hex_part = @$matches[1]; + $dec_part = @$matches[2]; + $named_part = empty($matches[3]) ? (empty($matches[4]) ? "" : $matches[4]) : $matches[3]; + if ($hex_part !== NULL && $hex_part !== "") { + return HTMLPurifier_Encoder::unichr(hexdec($hex_part)); + } elseif ($dec_part !== NULL && $dec_part !== "") { + return HTMLPurifier_Encoder::unichr((int) $dec_part); + } else { + if (!$this->_entity_lookup) { + $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); + } + if (isset($this->_entity_lookup->table[$named_part])) { + return $this->_entity_lookup->table[$named_part]; + } else { + // exact match didn't match anything, so test if + // any of the semicolon optional match the prefix. + // Test that this is an EXACT match is important to + // prevent infinite loop + if (!empty($matches[3])) { + return preg_replace_callback( + $this->_semiOptionalPrefixRegex, + array($this, 'entityCallback'), + $entity + ); + } + return $entity; + } + } + } + + // LEGACY CODE BELOW + + /** + * Callback regex string for parsing entities. + * @type string + */ + protected $_substituteEntitiesRegex = + '/&(?:[#]x([a-fA-F0-9]+)|[#]0*(\d+)|([A-Za-z_:][A-Za-z0-9.\-_:]*));?/'; + // 1. hex 2. dec 3. string (XML style) + + /** + * Decimal to parsed string conversion table for special entities. + * @type array + */ + protected $_special_dec2str = + array( + 34 => '"', + 38 => '&', + 39 => "'", + 60 => '<', + 62 => '>' + ); + + /** + * Stripped entity names to decimal conversion table for special entities. + * @type array + */ + protected $_special_ent2dec = + array( + 'quot' => 34, + 'amp' => 38, + 'lt' => 60, + 'gt' => 62 + ); + + /** + * Substitutes non-special entities with their parsed equivalents. Since + * running this whenever you have parsed character is t3h 5uck, we run + * it before everything else. + * + * @param string $string String to have non-special entities parsed. + * @return string Parsed string. + */ + public function substituteNonSpecialEntities($string) + { + // it will try to detect missing semicolons, but don't rely on it + return preg_replace_callback( + $this->_substituteEntitiesRegex, + array($this, 'nonSpecialEntityCallback'), + $string + ); + } + + /** + * Callback function for substituteNonSpecialEntities() that does the work. + * + * @param array $matches PCRE matches array, with 0 the entire match, and + * either index 1, 2 or 3 set with a hex value, dec value, + * or string (respectively). + * @return string Replacement string. + */ + + protected function nonSpecialEntityCallback($matches) + { + // replaces all but big five + $entity = $matches[0]; + $is_num = (@$matches[0][1] === '#'); + if ($is_num) { + $is_hex = (@$entity[2] === 'x'); + $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; + // abort for special characters + if (isset($this->_special_dec2str[$code])) { + return $entity; + } + return HTMLPurifier_Encoder::unichr($code); + } else { + if (isset($this->_special_ent2dec[$matches[3]])) { + return $entity; + } + if (!$this->_entity_lookup) { + $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); + } + if (isset($this->_entity_lookup->table[$matches[3]])) { + return $this->_entity_lookup->table[$matches[3]]; + } else { + return $entity; + } + } + } + + /** + * Substitutes only special entities with their parsed equivalents. + * + * @notice We try to avoid calling this function because otherwise, it + * would have to be called a lot (for every parsed section). + * + * @param string $string String to have non-special entities parsed. + * @return string Parsed string. + */ + public function substituteSpecialEntities($string) + { + return preg_replace_callback( + $this->_substituteEntitiesRegex, + array($this, 'specialEntityCallback'), + $string + ); + } + + /** + * Callback function for substituteSpecialEntities() that does the work. + * + * This callback has same syntax as nonSpecialEntityCallback(). + * + * @param array $matches PCRE-style matches array, with 0 the entire match, and + * either index 1, 2 or 3 set with a hex value, dec value, + * or string (respectively). + * @return string Replacement string. + */ + protected function specialEntityCallback($matches) + { + $entity = $matches[0]; + $is_num = (@$matches[0][1] === '#'); + if ($is_num) { + $is_hex = (@$entity[2] === 'x'); + $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; + return isset($this->_special_dec2str[$int]) ? + $this->_special_dec2str[$int] : + $entity; + } else { + return isset($this->_special_ent2dec[$matches[3]]) ? + $this->_special_dec2str[$this->_special_ent2dec[$matches[3]]] : + $entity; + } + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ErrorCollector.php b/tools/htmlpurifier/HTMLPurifier/ErrorCollector.php new file mode 100644 index 000000000..d47e3f2e2 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ErrorCollector.php @@ -0,0 +1,244 @@ +locale =& $context->get('Locale'); + $this->context = $context; + $this->_current =& $this->_stacks[0]; + $this->errors =& $this->_stacks[0]; + } + + /** + * Sends an error message to the collector for later use + * @param int $severity Error severity, PHP error style (don't use E_USER_) + * @param string $msg Error message text + */ + public function send($severity, $msg) + { + $args = array(); + if (func_num_args() > 2) { + $args = func_get_args(); + array_shift($args); + unset($args[0]); + } + + $token = $this->context->get('CurrentToken', true); + $line = $token ? $token->line : $this->context->get('CurrentLine', true); + $col = $token ? $token->col : $this->context->get('CurrentCol', true); + $attr = $this->context->get('CurrentAttr', true); + + // perform special substitutions, also add custom parameters + $subst = array(); + if (!is_null($token)) { + $args['CurrentToken'] = $token; + } + if (!is_null($attr)) { + $subst['$CurrentAttr.Name'] = $attr; + if (isset($token->attr[$attr])) { + $subst['$CurrentAttr.Value'] = $token->attr[$attr]; + } + } + + if (empty($args)) { + $msg = $this->locale->getMessage($msg); + } else { + $msg = $this->locale->formatMessage($msg, $args); + } + + if (!empty($subst)) { + $msg = strtr($msg, $subst); + } + + // (numerically indexed) + $error = array( + self::LINENO => $line, + self::SEVERITY => $severity, + self::MESSAGE => $msg, + self::CHILDREN => array() + ); + $this->_current[] = $error; + + // NEW CODE BELOW ... + // Top-level errors are either: + // TOKEN type, if $value is set appropriately, or + // "syntax" type, if $value is null + $new_struct = new HTMLPurifier_ErrorStruct(); + $new_struct->type = HTMLPurifier_ErrorStruct::TOKEN; + if ($token) { + $new_struct->value = clone $token; + } + if (is_int($line) && is_int($col)) { + if (isset($this->lines[$line][$col])) { + $struct = $this->lines[$line][$col]; + } else { + $struct = $this->lines[$line][$col] = $new_struct; + } + // These ksorts may present a performance problem + ksort($this->lines[$line], SORT_NUMERIC); + } else { + if (isset($this->lines[-1])) { + $struct = $this->lines[-1]; + } else { + $struct = $this->lines[-1] = $new_struct; + } + } + ksort($this->lines, SORT_NUMERIC); + + // Now, check if we need to operate on a lower structure + if (!empty($attr)) { + $struct = $struct->getChild(HTMLPurifier_ErrorStruct::ATTR, $attr); + if (!$struct->value) { + $struct->value = array($attr, 'PUT VALUE HERE'); + } + } + if (!empty($cssprop)) { + $struct = $struct->getChild(HTMLPurifier_ErrorStruct::CSSPROP, $cssprop); + if (!$struct->value) { + // if we tokenize CSS this might be a little more difficult to do + $struct->value = array($cssprop, 'PUT VALUE HERE'); + } + } + + // Ok, structs are all setup, now time to register the error + $struct->addError($severity, $msg); + } + + /** + * Retrieves raw error data for custom formatter to use + */ + public function getRaw() + { + return $this->errors; + } + + /** + * Default HTML formatting implementation for error messages + * @param HTMLPurifier_Config $config Configuration, vital for HTML output nature + * @param array $errors Errors array to display; used for recursion. + * @return string + */ + public function getHTMLFormatted($config, $errors = null) + { + $ret = array(); + + $this->generator = new HTMLPurifier_Generator($config, $this->context); + if ($errors === null) { + $errors = $this->errors; + } + + // 'At line' message needs to be removed + + // generation code for new structure goes here. It needs to be recursive. + foreach ($this->lines as $line => $col_array) { + if ($line == -1) { + continue; + } + foreach ($col_array as $col => $struct) { + $this->_renderStruct($ret, $struct, $line, $col); + } + } + if (isset($this->lines[-1])) { + $this->_renderStruct($ret, $this->lines[-1]); + } + + if (empty($errors)) { + return '

' . $this->locale->getMessage('ErrorCollector: No errors') . '

'; + } else { + return '
  • ' . implode('
  • ', $ret) . '
'; + } + + } + + private function _renderStruct(&$ret, $struct, $line = null, $col = null) + { + $stack = array($struct); + $context_stack = array(array()); + while ($current = array_pop($stack)) { + $context = array_pop($context_stack); + foreach ($current->errors as $error) { + list($severity, $msg) = $error; + $string = ''; + $string .= '
'; + // W3C uses an icon to indicate the severity of the error. + $error = $this->locale->getErrorName($severity); + $string .= "$error "; + if (!is_null($line) && !is_null($col)) { + $string .= "Line $line, Column $col: "; + } else { + $string .= 'End of Document: '; + } + $string .= '' . $this->generator->escape($msg) . ' '; + $string .= '
'; + // Here, have a marker for the character on the column appropriate. + // Be sure to clip extremely long lines. + //$string .= '
';
+                //$string .= '';
+                //$string .= '
'; + $ret[] = $string; + } + foreach ($current->children as $array) { + $context[] = $current; + $stack = array_merge($stack, array_reverse($array, true)); + for ($i = count($array); $i > 0; $i--) { + $context_stack[] = $context; + } + } + } + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/ErrorStruct.php b/tools/htmlpurifier/HTMLPurifier/ErrorStruct.php new file mode 100644 index 000000000..cf869d321 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/ErrorStruct.php @@ -0,0 +1,74 @@ +children[$type][$id])) { + $this->children[$type][$id] = new HTMLPurifier_ErrorStruct(); + $this->children[$type][$id]->type = $type; + } + return $this->children[$type][$id]; + } + + /** + * @param int $severity + * @param string $message + */ + public function addError($severity, $message) + { + $this->errors[] = array($severity, $message); + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/HTMLPurifier/Exception.php b/tools/htmlpurifier/HTMLPurifier/Exception.php new file mode 100644 index 000000000..be85b4c56 --- /dev/null +++ b/tools/htmlpurifier/HTMLPurifier/Exception.php @@ -0,0 +1,12 @@ +preFilter, + * 2->preFilter, 3->preFilter, purify, 3->postFilter, 2->postFilter, + * 1->postFilter. + * + * @note Methods are not declared abstract as it is perfectly legitimate + * for an implementation not to want anything to happen on a step + */ + +class HTMLPurifier_Filter +{ + + /** + * Name of the filter for identification purposes. + * @type string + */ + public $name; + + /** + * Pre-processor function, handles HTML before HTML Purifier + * @param string $html + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return string + */ + public function preFilter($html, $config, $context) + { + return $html; + } + + /** + * Post-processor function, handles HTML after HTML Purifier + * @param string $html + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return string + */ + public function postFilter($html, $config, $context) + { + return $html; + } +} + +// vim: et sw=4 sts=4 diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/Filter/ExtractStyleBlocks.php b/tools/htmlpurifier/HTMLPurifier/Filter/ExtractStyleBlocks.php similarity index 97% rename from tools/htmlpurifier/standalone/HTMLPurifier/Filter/ExtractStyleBlocks.php rename to tools/htmlpurifier/HTMLPurifier/Filter/ExtractStyleBlocks.php index a59935c39..66f70b0fc 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/Filter/ExtractStyleBlocks.php +++ b/tools/htmlpurifier/HTMLPurifier/Filter/ExtractStyleBlocks.php @@ -95,7 +95,10 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter if ($tidy !== null) { $this->_tidy = $tidy; } - $html = preg_replace_callback('#(.+)#isU', array($this, 'styleCallback'), $html); + // NB: this must be NON-greedy because if we have + // + // we must not grab foo '; + // get the body part + $tidy_body = tidy_get_body($tidy); + $html = $tidy_body->value; + // fix some self-closing tags + $html = str_replace('
', '
', $html); + // remove some empty tag blocks + $html = preg_replace('/]*)><\/div>/', '', $html); + $html = preg_replace('/]*)><\/p>/', '', $html); + if ($tagvs !== '') { + // set vertical space for some XHTML tags + $tagvspaces = $tagvs; + } + // return the cleaned XHTML code + CSS + return $css.$html; + } + + /** + * Returns true if the CSS selector is valid for the selected HTML tag + * @param $dom (array) array of HTML tags and properties + * @param $key (int) key of the current HTML tag + * @param $selector (string) CSS selector string + * @return true if the selector is valid, false otherwise + * @since 5.1.000 (2010-05-25) + * @public static + */ + public static function isValidCSSSelectorForTag($dom, $key, $selector) { + $valid = false; // value to be returned + $tag = $dom[$key]['value']; + $class = array(); + if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) { + $class = explode(' ', strtolower($dom[$key]['attribute']['class'])); + } + $id = ''; + if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) { + $id = strtolower($dom[$key]['attribute']['id']); + } + $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector); + $matches = array(); + 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]); + $operator = $parentop[0]; + $offset = $parentop[1]; + $lasttag = array_pop($matches[2]); + $lasttag = strtolower(trim($lasttag[0])); + if (($lasttag == '*') OR ($lasttag == $tag)) { + // the last element on selector is our tag or 'any tag' + $attrib = array_pop($matches[3]); + $attrib = strtolower(trim($attrib[0])); + if (!empty($attrib)) { + // check if matches class, id, attribute, pseudo-class or pseudo-element + switch ($attrib[0]) { + case '.': { // class + if (in_array(substr($attrib, 1), $class)) { + $valid = true; + } + break; + } + case '#': { // ID + if (substr($attrib, 1) == $id) { + $valid = true; + } + break; + } + case '[': { // attribute + $attrmatch = array(); + if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) { + $att = strtolower($attrmatch[1]); + $val = $attrmatch[3]; + if (isset($dom[$key]['attribute'][$att])) { + switch ($attrmatch[2]) { + case '=': { + if ($dom[$key]['attribute'][$att] == $val) { + $valid = true; + } + break; + } + case '~=': { + if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) { + $valid = true; + } + break; + } + case '^=': { + if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) { + $valid = true; + } + break; + } + case '$=': { + if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) { + $valid = true; + } + break; + } + case '*=': { + if (strpos($dom[$key]['attribute'][$att], $val) !== false) { + $valid = true; + } + break; + } + case '|=': { + if ($dom[$key]['attribute'][$att] == $val) { + $valid = true; + } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) { + $valid = true; + } + break; + } + default: { + $valid = true; + } + } + } + } + break; + } + case ':': { // pseudo-class or pseudo-element + if ($attrib[1] == ':') { // pseudo-element + // pseudo-elements are not supported! + // (::first-line, ::first-letter, ::before, ::after) + } else { // pseudo-class + // pseudo-classes are not supported! + // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked) + } + break; + } + } // end of switch + } else { + $valid = true; + } + if ($valid AND ($offset > 0)) { + $valid = false; + // check remaining selector part + $selector = substr($selector, 0, $offset); + switch ($operator) { + case ' ': { // descendant of an element + while ($dom[$key]['parent'] > 0) { + if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) { + $valid = true; + break; + } else { + $key = $dom[$key]['parent']; + } + } + break; + } + case '>': { // child of an element + $valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector); + break; + } + case '+': { // immediately preceded by an element + for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { + if ($dom[$i]['tag'] AND $dom[$i]['opening']) { + $valid = self::isValidCSSSelectorForTag($dom, $i, $selector); + break; + } + } + break; + } + case '~': { // preceded by an element + for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { + if ($dom[$i]['tag'] AND $dom[$i]['opening']) { + if (self::isValidCSSSelectorForTag($dom, $i, $selector)) { + break; + } + } + } + break; + } + } + } + } + } + return $valid; + } + + /** + * Returns the styles array that apply for the selected HTML tag. + * @param $dom (array) array of HTML tags and properties + * @param $key (int) key of the current HTML tag + * @param $css (array) array of CSS properties + * @return array containing CSS properties + * @since 5.1.000 (2010-05-25) + * @public static + */ + public static function getCSSdataArray($dom, $key, $css) { + $cssarray = array(); // style to be returned + // get parent CSS selectors + $selectors = array(); + if (isset($dom[($dom[$key]['parent'])]['csssel'])) { + $selectors = $dom[($dom[$key]['parent'])]['csssel']; + } + // get all styles that apply + foreach($css as $selector => $style) { + $pos = strpos($selector, ' '); + // get specificity + $specificity = substr($selector, 0, $pos); + // remove specificity + $selector = substr($selector, $pos); + // check if this selector apply to current tag + if (self::isValidCSSSelectorForTag($dom, $key, $selector)) { + if (!in_array($selector, $selectors)) { + // add style if not already added on parent selector + $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style); + $selectors[] = $selector; + } + } + } + if (isset($dom[$key]['attribute']['style'])) { + // attach inline style (latest properties have high priority) + $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']); + } + // order the css array to account for specificity + $cssordered = array(); + foreach ($cssarray as $key => $val) { + $skey = sprintf('%04d', $key); + $cssordered[$val['s'].'_'.$skey] = $val; + } + // sort selectors alphabetically to account for specificity + ksort($cssordered, SORT_STRING); + return array($selectors, $cssordered); + } + + /** + * Compact CSS data array into single string. + * @param $css (array) array of CSS properties + * @return string containing merged CSS properties + * @since 5.9.070 (2011-04-19) + * @public static + */ + public static function getTagStyleFromCSSarray($css) { + $tagstyle = ''; // value to be returned + foreach ($css as $style) { + // split single css commands + $csscmds = explode(';', $style['c']); + foreach ($csscmds as $cmd) { + if (!empty($cmd)) { + $pos = strpos($cmd, ':'); + if ($pos !== false) { + $cmd = substr($cmd, 0, ($pos + 1)); + if (strpos($tagstyle, $cmd) !== false) { + // remove duplicate commands (last commands have high priority) + $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle); + } + } + } + } + $tagstyle .= ';'.$style['c']; + } + // remove multiple semicolons + $tagstyle = preg_replace('/[;]+/', ';', $tagstyle); + return $tagstyle; + } + + /** + * Returns the Roman representation of an integer number + * @param $number (int) number to convert + * @return string roman representation of the specified number + * @since 4.4.004 (2008-12-10) + * @public static + */ + public static function intToRoman($number) { + $roman = ''; + while ($number >= 1000) { + $roman .= 'M'; + $number -= 1000; + } + while ($number >= 900) { + $roman .= 'CM'; + $number -= 900; + } + while ($number >= 500) { + $roman .= 'D'; + $number -= 500; + } + while ($number >= 400) { + $roman .= 'CD'; + $number -= 400; + } + while ($number >= 100) { + $roman .= 'C'; + $number -= 100; + } + while ($number >= 90) { + $roman .= 'XC'; + $number -= 90; + } + while ($number >= 50) { + $roman .= 'L'; + $number -= 50; + } + while ($number >= 40) { + $roman .= 'XL'; + $number -= 40; + } + while ($number >= 10) { + $roman .= 'X'; + $number -= 10; + } + while ($number >= 9) { + $roman .= 'IX'; + $number -= 9; + } + while ($number >= 5) { + $roman .= 'V'; + $number -= 5; + } + while ($number >= 4) { + $roman .= 'IV'; + $number -= 4; + } + while ($number >= 1) { + $roman .= 'I'; + --$number; + } + return $roman; + } + + /** + * Find position of last occurrence of a substring in a string + * @param $haystack (string) The string to search in. + * @param $needle (string) substring to search. + * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string. + * @return Returns the position where the needle exists. Returns FALSE if the needle was not found. + * @since 4.8.038 (2010-03-13) + * @public static + */ + public static function revstrpos($haystack, $needle, $offset = 0) { + $length = strlen($haystack); + $offset = ($offset > 0)?($length - $offset):abs($offset); + $pos = strpos(strrev($haystack), strrev($needle), $offset); + return ($pos === false)?false:($length - $pos - strlen($needle)); + } + + /** + * Returns an array of hyphenation patterns. + * @param $file (string) TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ + * @return array of hyphenation patterns + * @author Nicola Asuni + * @since 4.9.012 (2010-04-12) + * @public static + */ + public static function getHyphenPatternsFromTEX($file) { + // TEX patterns are available at: + // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ + $data = file_get_contents($file); + $patterns = array(); + // remove comments + $data = preg_replace('/\%[^\n]*/', '', $data); + // extract the patterns part + preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); + $data = trim(substr($matches[0], 10, -1)); + // extract each pattern + $patterns_array = preg_split('/[\s]+/', $data); + // create new language array of patterns + $patterns = array(); + foreach($patterns_array as $val) { + if (!TCPDF_STATIC::empty_string($val)) { + $val = trim($val); + $val = str_replace('\'', '\\\'', $val); + $key = preg_replace('/[0-9]+/', '', $val); + $patterns[$key] = $val; + } + } + return $patterns; + } + + /** + * Get the Path-Painting Operators. + * @param $style (string) Style of rendering. Possible values are: + *
    + *
  • S or D: Stroke the path.
  • + *
  • s or d: Close and stroke the path.
  • + *
  • f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.
  • + *
  • f* or F*: Fill the path, using the even-odd rule to determine the region to fill.
  • + *
  • B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • + *
  • B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.
  • + *
  • b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • + *
  • b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.
  • + *
  • CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.
  • + *
  • CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path
  • + *
  • n: End the path object without filling or stroking it.
  • + *
+ * @param $default (string) default style + * @author Nicola Asuni + * @since 5.0.000 (2010-04-30) + * @public static + */ + public static function getPathPaintOperator($style, $default='S') { + $op = ''; + switch($style) { + case 'S': + case 'D': { + $op = 'S'; + break; + } + case 's': + case 'd': { + $op = 's'; + break; + } + case 'f': + case 'F': { + $op = 'f'; + break; + } + case 'f*': + case 'F*': { + $op = 'f*'; + break; + } + case 'B': + case 'FD': + case 'DF': { + $op = 'B'; + break; + } + case 'B*': + case 'F*D': + case 'DF*': { + $op = 'B*'; + break; + } + case 'b': + case 'fd': + case 'df': { + $op = 'b'; + break; + } + case 'b*': + case 'f*d': + case 'df*': { + $op = 'b*'; + break; + } + case 'CNZ': { + $op = 'W n'; + break; + } + case 'CEO': { + $op = 'W* n'; + break; + } + case 'n': { + $op = 'n'; + break; + } + default: { + if (!empty($default)) { + $op = self::getPathPaintOperator($default, ''); + } else { + $op = ''; + } + } + } + return $op; + } + + /** + * Get the product of two SVG tranformation matrices + * @param $ta (array) first SVG tranformation matrix + * @param $tb (array) second SVG tranformation matrix + * @return transformation array + * @author Nicola Asuni + * @since 5.0.000 (2010-05-02) + * @public static + */ + public static function getTransformationMatrixProduct($ta, $tb) { + $tm = array(); + $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); + $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); + $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); + $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]); + $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4]; + $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5]; + return $tm; + } + + /** + * Get the tranformation matrix from SVG transform attribute + * @param $attribute (string) transformation + * @return array of transformations + * @author Nicola Asuni + * @since 5.0.000 (2010-05-02) + * @public static + */ + public static function getSVGTransformMatrix($attribute) { + // identity matrix + $tm = array(1, 0, 0, 1, 0, 0); + $transform = array(); + if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { + foreach ($transform as $key => $data) { + if (!empty($data[2])) { + $a = 1; + $b = 0; + $c = 0; + $d = 1; + $e = 0; + $f = 0; + $regs = array(); + switch ($data[1]) { + 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)) { + $a = $regs[1]; + $b = $regs[2]; + $c = $regs[3]; + $d = $regs[4]; + $e = $regs[5]; + $f = $regs[6]; + } + break; + } + case 'translate': { + if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { + $e = $regs[1]; + $f = $regs[2]; + } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { + $e = $regs[1]; + } + break; + } + case 'scale': { + if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { + $a = $regs[1]; + $d = $regs[2]; + } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { + $a = $regs[1]; + $d = $a; + } + break; + } + case 'rotate': { + if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { + $ang = deg2rad($regs[1]); + $x = $regs[2]; + $y = $regs[3]; + $a = cos($ang); + $b = sin($ang); + $c = -$b; + $d = $a; + $e = ($x * (1 - $a)) - ($y * $c); + $f = ($y * (1 - $d)) - ($x * $b); + } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { + $ang = deg2rad($regs[1]); + $a = cos($ang); + $b = sin($ang); + $c = -$b; + $d = $a; + $e = 0; + $f = 0; + } + break; + } + case 'skewX': { + if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { + $c = tan(deg2rad($regs[1])); + } + break; + } + case 'skewY': { + if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { + $b = tan(deg2rad($regs[1])); + } + break; + } + } + $tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f)); + } + } + } + return $tm; + } + + /** + * Returns the angle in radiants between two vectors + * @param $x1 (int) X coordinate of first vector point + * @param $y1 (int) Y coordinate of first vector point + * @param $x2 (int) X coordinate of second vector point + * @param $y2 (int) Y coordinate of second vector point + * @author Nicola Asuni + * @since 5.0.000 (2010-05-04) + * @public static + */ + public static function getVectorsAngle($x1, $y1, $x2, $y2) { + $dprod = ($x1 * $x2) + ($y1 * $y2); + $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); + $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); + $angle = acos($dprod / ($dist1 * $dist2)); + if (is_nan($angle)) { + $angle = M_PI; + } + if ((($x1 * $y2) - ($x2 * $y1)) < 0) { + $angle *= -1; + } + return $angle; + } + + /** + * 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 + * @param $pattern (string) The regular expression pattern to search for without the modifiers, as a string. + * @param $modifiers (string) The modifiers part of the pattern, + * @param $subject (string) The input string. + * @param $limit (int) 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 $flags (int) The flags as specified on the preg_split PHP function. + * @return Returns an array containing substrings of subject split along boundaries matched by pattern.modifier + * @author Nicola Asuni + * @since 6.0.023 + * @public static + */ + public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) { + // 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)) { + return preg_split($pattern.$modifiers, $subject, $limit, $flags); + } + // preg_split is bugged - try alternative solution + $ret = array(); + while (($nl = strpos($subject, "\n")) !== FALSE) { + $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags)); + $ret[] = "\n"; + $subject = substr($subject, ($nl + 1)); + } + if (strlen($subject) > 0) { + $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags)); + } + return $ret; + } + + /** + * Wrapper to use fopen only with local files + * @param filename (string) Name of the file to open + * @param $mode (string) + * @return Returns a file pointer resource on success, or FALSE on error. + * @public static + */ + public static function fopenLocal($filename, $mode) { + if (strpos($filename, '://') === false) { + $filename = 'file://'.$filename; + } elseif (stream_is_local($filename) !== true) { + return false; + } + return fopen($filename, $mode); + } + + /** + * Check if the URL exist. + * @param url (string) URL to check. + * @return Returns TRUE if the URL exists; FALSE otherwise. + * @public static + */ + public static function url_exists($url) { + $crs = curl_init(); + // encode query params in URL to get right response form the server + $url = self::encodeUrlQuery($url); + curl_setopt($crs, CURLOPT_URL, $url); + curl_setopt($crs, CURLOPT_NOBODY, true); + curl_setopt($crs, CURLOPT_FAILONERROR, true); + if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) { + curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true); + } + curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($crs, CURLOPT_TIMEOUT, 30); + curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file'); + curl_exec($crs); + $code = curl_getinfo($crs, CURLINFO_HTTP_CODE); + curl_close($crs); + return ($code == 200); + } + + /** + * Encode query params in URL + * + * @param string $url + * @return string + * @since 6.3.3 (2019-11-01) + * @public static + */ + public static function encodeUrlQuery($url) { + $urlData = parse_url($url); + if (isset($urlData['query']) && $urlData['query']) { + $urlQueryData = []; + parse_str(urldecode($urlData['query']), $urlQueryData); + $updatedUrl = $urlData['scheme'] . '://' . $urlData['host'] . $urlData['path'] . '?' . http_build_query($urlQueryData); + } else { + $updatedUrl = $url; + } + return $updatedUrl; + } + + /** + * Wrapper for file_exists. + * Checks whether a file or directory exists. + * Only allows some protocols and local files. + * @param filename (string) Path to the file or directory. + * @return Returns TRUE if the file or directory specified by filename exists; FALSE otherwise. + * @public static + */ + public static function file_exists($filename) { + if (preg_match('|^https?://|', $filename) == 1) { + return self::url_exists($filename); + } + if (strpos($filename, '://')) { + return false; // only support http and https wrappers for security reasons + } + return @file_exists($filename); + } + + /** + * Reads entire file into a string. + * The file can be also an URL. + * @param $file (string) Name of the file or URL to read. + * @return The function returns the read data or FALSE on failure. + * @author Nicola Asuni + * @since 6.0.025 + * @public static + */ + public static function fileGetContents($file) { + $alt = array($file); + // + if ((strlen($file) > 1) + && ($file[0] === '/') + && ($file[1] !== '/') + && !empty($_SERVER['DOCUMENT_ROOT']) + && ($_SERVER['DOCUMENT_ROOT'] !== '/') + ) { + $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']); + if (($findroot === false) || ($findroot > 1)) { + $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file)); + } + } + // + $protocol = 'http'; + if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { + $protocol .= 's'; + } + // + $url = $file; + if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) { + $url = $protocol.':'.str_replace(' ', '%20', $url); + } + $url = htmlspecialchars_decode($url); + $alt[] = $url; + // + if (preg_match('%^(https?)://%', $url) + && empty($_SERVER['HTTP_HOST']) + && empty($_SERVER['DOCUMENT_ROOT']) + ) { + $urldata = parse_url($url); + if (empty($urldata['query'])) { + $host = $protocol.'://'.$_SERVER['HTTP_HOST']; + if (strpos($url, $host) === 0) { + // convert URL to full server path + $tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url); + $alt[] = htmlspecialchars_decode(urldecode($tmp)); + } + } + } + // + if (isset($_SERVER['SCRIPT_URI']) + && !preg_match('%^(https?|ftp)://%', $file) + && !preg_match('%^//%', $file) + ) { + $urldata = @parse_url($_SERVER['SCRIPT_URI']); + $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file; + } + // + $alt = array_unique($alt); + foreach ($alt as $path) { + if (!self::file_exists($path)) { + continue; + } + $ret = @file_get_contents($path); + if ( $ret != false ) { + return $ret; + } + // try to use CURL for URLs + if (!ini_get('allow_url_fopen') + && function_exists('curl_init') + && preg_match('%^(https?|ftp)://%', $path) + ) { + // try to get remote file data using cURL + $crs = curl_init(); + curl_setopt($crs, CURLOPT_URL, $path); + curl_setopt($crs, CURLOPT_BINARYTRANSFER, true); + curl_setopt($crs, CURLOPT_FAILONERROR, true); + curl_setopt($crs, CURLOPT_RETURNTRANSFER, true); + if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) { + curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true); + } + curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($crs, CURLOPT_TIMEOUT, 30); + curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file'); + $ret = curl_exec($crs); + curl_close($crs); + if ($ret !== false) { + return $ret; + } + } + } + return false; + } + + /** + * Get ULONG from string (Big Endian 32-bit unsigned integer). + * @param $str (string) string from where to extract value + * @param $offset (int) point from where to read the data + * @return int 32 bit value + * @author Nicola Asuni + * @since 5.2.000 (2010-06-02) + * @public static + */ + public static function _getULONG($str, $offset) { + $v = unpack('Ni', substr($str, $offset, 4)); + return $v['i']; + } + + /** + * Get USHORT from string (Big Endian 16-bit unsigned integer). + * @param $str (string) string from where to extract value + * @param $offset (int) point from where to read the data + * @return int 16 bit value + * @author Nicola Asuni + * @since 5.2.000 (2010-06-02) + * @public static + */ + public static function _getUSHORT($str, $offset) { + $v = unpack('ni', substr($str, $offset, 2)); + return $v['i']; + } + + /** + * Get SHORT from string (Big Endian 16-bit signed integer). + * @param $str (string) String from where to extract value. + * @param $offset (int) Point from where to read the data. + * @return int 16 bit value + * @author Nicola Asuni + * @since 5.2.000 (2010-06-02) + * @public static + */ + public static function _getSHORT($str, $offset) { + $v = unpack('si', substr($str, $offset, 2)); + return $v['i']; + } + + /** + * Get FWORD from string (Big Endian 16-bit signed integer). + * @param $str (string) String from where to extract value. + * @param $offset (int) Point from where to read the data. + * @return int 16 bit value + * @author Nicola Asuni + * @since 5.9.123 (2011-09-30) + * @public static + */ + public static function _getFWORD($str, $offset) { + $v = self::_getUSHORT($str, $offset); + if ($v > 0x7fff) { + $v -= 0x10000; + } + return $v; + } + + /** + * Get UFWORD from string (Big Endian 16-bit unsigned integer). + * @param $str (string) string from where to extract value + * @param $offset (int) point from where to read the data + * @return int 16 bit value + * @author Nicola Asuni + * @since 5.9.123 (2011-09-30) + * @public static + */ + public static function _getUFWORD($str, $offset) { + $v = self::_getUSHORT($str, $offset); + return $v; + } + + /** + * Get FIXED from string (32-bit signed fixed-point number (16.16). + * @param $str (string) string from where to extract value + * @param $offset (int) point from where to read the data + * @return int 16 bit value + * @author Nicola Asuni + * @since 5.9.123 (2011-09-30) + * @public static + */ + public static function _getFIXED($str, $offset) { + // mantissa + $m = self::_getFWORD($str, $offset); + // fraction + $f = self::_getUSHORT($str, ($offset + 2)); + $v = floatval(''.$m.'.'.$f.''); + return $v; + } + + /** + * Get BYTE from string (8-bit unsigned integer). + * @param $str (string) String from where to extract value. + * @param $offset (int) Point from where to read the data. + * @return int 8 bit value + * @author Nicola Asuni + * @since 5.2.000 (2010-06-02) + * @public static + */ + public static function _getBYTE($str, $offset) { + $v = unpack('Ci', substr($str, $offset, 1)); + return $v['i']; + } + /** + * Binary-safe and URL-safe file read. + * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached. + * @param $handle (resource) + * @param $length (int) + * @return Returns the read string or FALSE in case of error. + * @author Nicola Asuni + * @since 4.5.027 (2009-03-16) + * @public static + */ + public static function rfread($handle, $length) { + $data = fread($handle, $length); + if ($data === false) { + return false; + } + $rest = ($length - strlen($data)); + if (($rest > 0) && !feof($handle)) { + $data .= self::rfread($handle, $rest); + } + return $data; + } + + /** + * Read a 4-byte (32 bit) integer from file. + * @param $f (string) file name. + * @return 4-byte integer + * @public static + */ + public static function _freadint($f) { + $a = unpack('Ni', fread($f, 4)); + return $a['i']; + } + + + /** + * Array of page formats + * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4) + * @public static + */ + public static $page_formats = array( + // ISO 216 A Series + 2 SIS 014711 extensions + 'A0' => array( 2383.937, 3370.394), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in + 'A1' => array( 1683.780, 2383.937), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in + 'A2' => array( 1190.551, 1683.780), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in + 'A3' => array( 841.890, 1190.551), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in + 'A4' => array( 595.276, 841.890), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in + 'A5' => array( 419.528, 595.276), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in + 'A6' => array( 297.638, 419.528), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in + 'A7' => array( 209.764, 297.638), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in + 'A8' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in + 'A9' => array( 104.882, 147.402), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in + 'A10' => array( 73.701, 104.882), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in + 'A11' => array( 51.024, 73.701), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in + 'A12' => array( 36.850, 51.024), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in + // ISO 216 B Series + 2 SIS 014711 extensions + 'B0' => array( 2834.646, 4008.189), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in + 'B1' => array( 2004.094, 2834.646), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in + 'B2' => array( 1417.323, 2004.094), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in + 'B3' => array( 1000.630, 1417.323), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in + 'B4' => array( 708.661, 1000.630), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in + 'B5' => array( 498.898, 708.661), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in + 'B6' => array( 354.331, 498.898), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in + 'B7' => array( 249.449, 354.331), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in + 'B8' => array( 175.748, 249.449), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in + 'B9' => array( 124.724, 175.748), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in + 'B10' => array( 87.874, 124.724), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in + 'B11' => array( 62.362, 87.874), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in + 'B12' => array( 42.520, 62.362), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in + // ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION + 'C0' => array( 2599.370, 3676.535), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in + 'C1' => array( 1836.850, 2599.370), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in + 'C2' => array( 1298.268, 1836.850), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in + 'C3' => array( 918.425, 1298.268), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in + 'C4' => array( 649.134, 918.425), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in + 'C5' => array( 459.213, 649.134), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in + 'C6' => array( 323.150, 459.213), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in + 'C7' => array( 229.606, 323.150), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in + 'C8' => array( 161.575, 229.606), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in + 'C9' => array( 113.386, 161.575), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in + 'C10' => array( 79.370, 113.386), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in + 'C11' => array( 56.693, 79.370), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in + 'C12' => array( 39.685, 56.693), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in + 'C76' => array( 229.606, 459.213), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in + 'DL' => array( 311.811, 623.622), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in + 'DLE' => array( 323.150, 637.795), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in + 'DLX' => array( 340.158, 666.142), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in + 'DLP' => array( 280.630, 595.276), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4) + // SIS 014711 E Series + 'E0' => array( 2491.654, 3517.795), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in + 'E1' => array( 1757.480, 2491.654), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in + 'E2' => array( 1247.244, 1757.480), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in + 'E3' => array( 878.740, 1247.244), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in + 'E4' => array( 623.622, 878.740), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in + 'E5' => array( 439.370, 623.622), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in + 'E6' => array( 311.811, 439.370), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in + 'E7' => array( 221.102, 311.811), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in + 'E8' => array( 155.906, 221.102), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in + 'E9' => array( 110.551, 155.906), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in + 'E10' => array( 76.535, 110.551), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in + 'E11' => array( 53.858, 76.535), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in + 'E12' => array( 36.850, 53.858), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in + // SIS 014711 G Series + 'G0' => array( 2715.591, 3838.110), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in + 'G1' => array( 1919.055, 2715.591), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in + 'G2' => array( 1357.795, 1919.055), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in + 'G3' => array( 958.110, 1357.795), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in + 'G4' => array( 677.480, 958.110), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in + 'G5' => array( 479.055, 677.480), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in + 'G6' => array( 337.323, 479.055), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in + 'G7' => array( 238.110, 337.323), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in + 'G8' => array( 167.244, 238.110), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in + 'G9' => array( 119.055, 167.244), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in + 'G10' => array( 82.205, 119.055), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in + 'G11' => array( 59.528, 82.205), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in + 'G12' => array( 39.685, 59.528), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in + // ISO Press + 'RA0' => array( 2437.795, 3458.268), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in + 'RA1' => array( 1729.134, 2437.795), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in + 'RA2' => array( 1218.898, 1729.134), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in + 'RA3' => array( 864.567, 1218.898), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in + 'RA4' => array( 609.449, 864.567), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in + 'SRA0' => array( 2551.181, 3628.346), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in + 'SRA1' => array( 1814.173, 2551.181), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in + 'SRA2' => array( 1275.591, 1814.173), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in + 'SRA3' => array( 907.087, 1275.591), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in + 'SRA4' => array( 637.795, 907.087), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in + // German DIN 476 + '4A0' => array( 4767.874, 6740.787), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in + '2A0' => array( 3370.394, 4767.874), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in + // Variations on the ISO Standard + 'A2_EXTRA' => array( 1261.417, 1754.646), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in + 'A3+' => array( 932.598, 1369.134), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in + 'A3_EXTRA' => array( 912.756, 1261.417), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in + 'A3_SUPER' => array( 864.567, 1440.000), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in + 'SUPER_A3' => array( 864.567, 1380.472), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in + 'A4_EXTRA' => array( 666.142, 912.756), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in + 'A4_SUPER' => array( 649.134, 912.756), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in + 'SUPER_A4' => array( 643.465, 1009.134), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in + 'A4_LONG' => array( 595.276, 986.457), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in + 'F4' => array( 595.276, 935.433), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in + 'SO_B5_EXTRA' => array( 572.598, 782.362), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in + 'A5_EXTRA' => array( 490.394, 666.142), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in + // ANSI Series + 'ANSI_E' => array( 2448.000, 3168.000), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in + 'ANSI_D' => array( 1584.000, 2448.000), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in + 'ANSI_C' => array( 1224.000, 1584.000), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in + 'ANSI_B' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in + 'ANSI_A' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in + // Traditional 'Loose' North American Paper Sizes + 'USLEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in + 'LEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in + 'ORGANIZERK' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in + 'BIBLE' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in + 'USTABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in + 'TABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in + 'ORGANIZERM' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in + 'USLETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in + 'LETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in + 'USLEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in + 'LEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in + 'GOVERNMENTLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in + 'GLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in + 'JUNIORLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in + 'JLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in + // Other North American Paper Sizes + 'QUADDEMY' => array( 2520.000, 3240.000), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in + 'SUPER_B' => array( 936.000, 1368.000), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in + 'QUARTO' => array( 648.000, 792.000), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in + 'GOVERNMENTLEGAL' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in + 'FOLIO' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in + 'MONARCH' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in + 'EXECUTIVE' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in + 'ORGANIZERL' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in + 'STATEMENT' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in + 'MEMO' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in + 'FOOLSCAP' => array( 595.440, 936.000), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in + 'COMPACT' => array( 306.000, 486.000), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in + 'ORGANIZERJ' => array( 198.000, 360.000), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in + // Canadian standard CAN 2-9.60M + 'P1' => array( 1587.402, 2437.795), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in + 'P2' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in + 'P3' => array( 793.701, 1218.898), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in + 'P4' => array( 609.449, 793.701), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in + 'P5' => array( 396.850, 609.449), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in + 'P6' => array( 303.307, 396.850), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in + // North American Architectural Sizes + 'ARCH_E' => array( 2592.000, 3456.000), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in + 'ARCH_E1' => array( 2160.000, 3024.000), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in + 'ARCH_D' => array( 1728.000, 2592.000), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in + 'BROADSHEET' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in + 'ARCH_C' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in + 'ARCH_B' => array( 864.000, 1296.000), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in + 'ARCH_A' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in + // -- North American Envelope Sizes + // - Announcement Envelopes + 'ANNENV_A2' => array( 314.640, 414.000), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in + 'ANNENV_A6' => array( 342.000, 468.000), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in + 'ANNENV_A7' => array( 378.000, 522.000), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in + 'ANNENV_A8' => array( 396.000, 584.640), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in + 'ANNENV_A10' => array( 450.000, 692.640), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in + 'ANNENV_SLIM' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in + // - Commercial Envelopes + 'COMMENV_N6_1/4' => array( 252.000, 432.000), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in + 'COMMENV_N6_3/4' => array( 260.640, 468.000), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in + 'COMMENV_N8' => array( 278.640, 540.000), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in + 'COMMENV_N9' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in + 'COMMENV_N10' => array( 296.640, 684.000), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in + 'COMMENV_N11' => array( 324.000, 746.640), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in + 'COMMENV_N12' => array( 342.000, 792.000), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in + 'COMMENV_N14' => array( 360.000, 828.000), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in + // - Catalogue Envelopes + 'CATENV_N1' => array( 432.000, 648.000), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in + 'CATENV_N1_3/4' => array( 468.000, 684.000), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in + 'CATENV_N2' => array( 468.000, 720.000), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in + 'CATENV_N3' => array( 504.000, 720.000), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in + 'CATENV_N6' => array( 540.000, 756.000), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in + 'CATENV_N7' => array( 576.000, 792.000), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in + 'CATENV_N8' => array( 594.000, 810.000), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in + 'CATENV_N9_1/2' => array( 612.000, 756.000), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in + 'CATENV_N9_3/4' => array( 630.000, 810.000), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in + 'CATENV_N10_1/2' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in + 'CATENV_N12_1/2' => array( 684.000, 900.000), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in + 'CATENV_N13_1/2' => array( 720.000, 936.000), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in + 'CATENV_N14_1/4' => array( 810.000, 882.000), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in + 'CATENV_N14_1/2' => array( 828.000, 1044.000), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in + // Japanese (JIS P 0138-61) Standard B-Series + 'JIS_B0' => array( 2919.685, 4127.244), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in + 'JIS_B1' => array( 2063.622, 2919.685), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in + 'JIS_B2' => array( 1459.843, 2063.622), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in + 'JIS_B3' => array( 1031.811, 1459.843), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in + 'JIS_B4' => array( 728.504, 1031.811), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in + 'JIS_B5' => array( 515.906, 728.504), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in + 'JIS_B6' => array( 362.835, 515.906), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in + 'JIS_B7' => array( 257.953, 362.835), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in + 'JIS_B8' => array( 181.417, 257.953), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in + 'JIS_B9' => array( 127.559, 181.417), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in + 'JIS_B10' => array( 90.709, 127.559), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in + 'JIS_B11' => array( 62.362, 90.709), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in + 'JIS_B12' => array( 45.354, 62.362), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in + // PA Series + 'PA0' => array( 2381.102, 3174.803), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in + 'PA1' => array( 1587.402, 2381.102), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in + 'PA2' => array( 1190.551, 1587.402), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in + 'PA3' => array( 793.701, 1190.551), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in + 'PA4' => array( 595.276, 793.701), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in + 'PA5' => array( 396.850, 595.276), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in + 'PA6' => array( 297.638, 396.850), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in + 'PA7' => array( 198.425, 297.638), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in + 'PA8' => array( 147.402, 198.425), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in + 'PA9' => array( 99.213, 147.402), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in + 'PA10' => array( 73.701, 99.213), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in + // Standard Photographic Print Sizes + 'PASSPORT_PHOTO' => array( 99.213, 127.559), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in + 'E' => array( 233.858, 340.157), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in + 'L' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in + '3R' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in + 'KG' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in + '4R' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in + '4D' => array( 340.157, 430.866), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in + '2L' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in + '5R' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in + '8P' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in + '6R' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in + '6P' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in + '8R' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in + '6PW' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in + 'S8R' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in + '4P' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in + '10R' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in + '4PW' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in + 'S10R' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in + '11R' => array( 790.866, 1009.134), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in + 'S11R' => array( 790.866, 1224.567), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in + '12R' => array( 864.567, 1080.000), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in + 'S12R' => array( 864.567, 1292.598), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in + // Common Newspaper Sizes + 'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in + 'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in + 'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in + 'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in + // Business Cards + 'CREDIT_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in + 'BUSINESS_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in + 'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in + 'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in + 'BUSINESS_CARD_IT' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in + 'BUSINESS_CARD_UK' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in + 'BUSINESS_CARD_FR' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in + 'BUSINESS_CARD_DE' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in + 'BUSINESS_CARD_ES' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in + 'BUSINESS_CARD_CA' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in + 'BUSINESS_CARD_US' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in + 'BUSINESS_CARD_JP' => array( 155.906, 257.953), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in + 'BUSINESS_CARD_HK' => array( 153.071, 255.118), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in + 'BUSINESS_CARD_AU' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in + 'BUSINESS_CARD_DK' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in + 'BUSINESS_CARD_SE' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in + 'BUSINESS_CARD_RU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in + 'BUSINESS_CARD_CZ' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in + 'BUSINESS_CARD_FI' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in + 'BUSINESS_CARD_HU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in + 'BUSINESS_CARD_IL' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in + // Billboards + '4SHEET' => array( 2880.000, 4320.000), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in + '6SHEET' => array( 3401.575, 5102.362), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in + '12SHEET' => array( 8640.000, 4320.000), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in + '16SHEET' => array( 5760.000, 8640.000), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in + '32SHEET' => array(11520.000, 8640.000), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in + '48SHEET' => array(17280.000, 8640.000), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in + '64SHEET' => array(23040.000, 8640.000), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in + '96SHEET' => array(34560.000, 8640.000), // = (12192 x 3048 ) mm = (480.00 x 120.00) in + // -- Old European Sizes + // - Old Imperial English Sizes + 'EN_EMPEROR' => array( 3456.000, 5184.000), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in + 'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in + 'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in + 'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in + 'EN_ATLAS' => array( 1872.000, 2448.000), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in + 'EN_COLOMBIER' => array( 1692.000, 2484.000), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in + 'EN_ELEPHANT' => array( 1656.000, 2016.000), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in + 'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in + 'EN_IMPERIAL' => array( 1584.000, 2160.000), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in + 'EN_PRINCESS' => array( 1548.000, 2016.000), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in + 'EN_CARTRIDGE' => array( 1512.000, 1872.000), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in + 'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in + 'EN_ROYAL' => array( 1440.000, 1800.000), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in + 'EN_SHEET' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in + 'EN_HALF_POST' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in + 'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in + 'EN_DOUBLE_POST' => array( 1368.000, 2196.000), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in + 'EN_MEDIUM' => array( 1260.000, 1656.000), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in + 'EN_DEMY' => array( 1260.000, 1620.000), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in + 'EN_LARGE_POST' => array( 1188.000, 1512.000), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in + 'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in + 'EN_POST' => array( 1116.000, 1386.000), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in + 'EN_CROWN' => array( 1080.000, 1440.000), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in + 'EN_PINCHED_POST' => array( 1062.000, 1332.000), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in + 'EN_BRIEF' => array( 972.000, 1152.000), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in + 'EN_FOOLSCAP' => array( 972.000, 1224.000), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in + 'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in + 'EN_POTT' => array( 900.000, 1080.000), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in + // - Old Imperial Belgian Sizes + 'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in + 'BE_COLOMBIER' => array( 1757.480, 2409.449), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in + 'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in + 'BE_ELEPHANT' => array( 1746.142, 2182.677), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in + 'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in + 'BE_GRAND_JESUS' => array( 1559.055, 2069.291), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in + 'BE_JESUS' => array( 1530.709, 2069.291), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in + 'BE_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in + 'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in + 'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in + 'BE_COQUILLE' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in + 'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in + 'BE_RUCHE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in + 'BE_PROPATRIA' => array( 977.953, 1218.898), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in + 'BE_LYS' => array( 898.583, 1125.354), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in + 'BE_POT' => array( 870.236, 1088.504), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in + 'BE_ROSETTE' => array( 765.354, 983.622), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in + // - Old Imperial French Sizes + 'FR_UNIVERS' => array( 2834.646, 3685.039), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in + 'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in + 'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in + 'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in + 'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in + 'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in + 'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in + 'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in + 'FR_JOURNAL' => array( 1842.520, 2664.567), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in + 'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in + 'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in + 'FR_CLOCHE' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in + 'FR_SOLEIL' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in + 'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in + 'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in + 'FR_JESUS' => array( 1587.402, 2154.331), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in + 'FR_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in + 'FR_CAVALIER' => array( 1303.937, 1757.480), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in + 'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in + 'FR_CARRE' => array( 1275.591, 1587.402), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in + 'FR_COQUILLE' => array( 1247.244, 1587.402), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in + 'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in + 'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in + 'FR_DOUBLE_POT' => array( 1133.858, 1757.480), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in + 'FR_ECU' => array( 1133.858, 1474.016), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in + 'FR_COURONNE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in + 'FR_TELLIERE' => array( 963.780, 1247.244), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in + 'FR_POT' => array( 878.740, 1133.858), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in + ); + + + /** + * Get page dimensions from format name. + * @param $format (mixed) The format name @see self::$page_format
    + * @return array containing page width and height in points + * @since 5.0.010 (2010-05-17) + * @public static + */ + public static function getPageSizeFromFormat($format) { + if (isset(self::$page_formats[$format])) { + return self::$page_formats[$format]; + } + return self::$page_formats['A4']; + } + + /** + * Set page boundaries. + * @param $page (int) page number + * @param $type (string) valid values are:
    • 'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;
    • 'CropBox' : the visible region of default user space;
    • 'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;
    • 'TrimBox' : the intended dimensions of the finished page after trimming;
    • 'ArtBox' : the page's meaningful content (including potential white space).
    + * @param $llx (float) lower-left x coordinate in user units. + * @param $lly (float) lower-left y coordinate in user units. + * @param $urx (float) upper-right x coordinate in user units. + * @param $ury (float) upper-right y coordinate in user units. + * @param $points (boolean) If true uses user units as unit of measure, otherwise uses PDF points. + * @param $k (float) Scale factor (number of points in user unit). + * @param $pagedim (array) Array of page dimensions. + * @return pagedim array of page dimensions. + * @since 5.0.010 (2010-05-17) + * @public static + */ + public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) { + if (!isset($pagedim[$page])) { + // initialize array + $pagedim[$page] = array(); + } + if (!in_array($type, self::$pageboxes)) { + return; + } + if ($points) { + $k = 1; + } + $pagedim[$page][$type]['llx'] = ($llx * $k); + $pagedim[$page][$type]['lly'] = ($lly * $k); + $pagedim[$page][$type]['urx'] = ($urx * $k); + $pagedim[$page][$type]['ury'] = ($ury * $k); + return $pagedim; + } + + /** + * Swap X and Y coordinates of page boxes (change page boxes orientation). + * @param $page (int) page number + * @param $pagedim (array) Array of page dimensions. + * @return pagedim array of page dimensions. + * @since 5.0.010 (2010-05-17) + * @public static + */ + public static function swapPageBoxCoordinates($page, $pagedim) { + foreach (self::$pageboxes as $type) { + // swap X and Y coordinates + if (isset($pagedim[$page][$type])) { + $tmp = $pagedim[$page][$type]['llx']; + $pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly']; + $pagedim[$page][$type]['lly'] = $tmp; + $tmp = $pagedim[$page][$type]['urx']; + $pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury']; + $pagedim[$page][$type]['ury'] = $tmp; + } + } + return $pagedim; + } + + /** + * Get the canonical page layout mode. + * @param $layout (string) The page layout. Possible values are:
    • SinglePage Display one page at a time
    • OneColumn Display the pages in one column
    • TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left
    • TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right
    • TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left
    • TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right
    + * @return (string) Canonical page layout name. + * @public static + */ + public static function getPageLayoutMode($layout='SinglePage') { + switch ($layout) { + case 'default': + case 'single': + case 'SinglePage': { + $layout_mode = 'SinglePage'; + break; + } + case 'continuous': + case 'OneColumn': { + $layout_mode = 'OneColumn'; + break; + } + case 'two': + case 'TwoColumnLeft': { + $layout_mode = 'TwoColumnLeft'; + break; + } + case 'TwoColumnRight': { + $layout_mode = 'TwoColumnRight'; + break; + } + case 'TwoPageLeft': { + $layout_mode = 'TwoPageLeft'; + break; + } + case 'TwoPageRight': { + $layout_mode = 'TwoPageRight'; + break; + } + default: { + $layout_mode = 'SinglePage'; + } + } + return $layout_mode; + } + + /** + * Get the canonical page layout mode. + * @param $mode (string) A name object specifying how the document should be displayed when opened:
    • UseNone Neither document outline nor thumbnail images visible
    • UseOutlines Document outline visible
    • UseThumbs Thumbnail images visible
    • FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible
    • UseOC (PDF 1.5) Optional content group panel visible
    • UseAttachments (PDF 1.6) Attachments panel visible
    + * @return (string) Canonical page mode name. + * @public static + */ + public static function getPageMode($mode='UseNone') { + switch ($mode) { + case 'UseNone': { + $page_mode = 'UseNone'; + break; + } + case 'UseOutlines': { + $page_mode = 'UseOutlines'; + break; + } + case 'UseThumbs': { + $page_mode = 'UseThumbs'; + break; + } + case 'FullScreen': { + $page_mode = 'FullScreen'; + break; + } + case 'UseOC': { + $page_mode = 'UseOC'; + break; + } + case '': { + $page_mode = 'UseAttachments'; + break; + } + default: { + $page_mode = 'UseNone'; + } + } + return $page_mode; + } + + +} // END OF TCPDF_STATIC CLASS + +//============================================================+ +// END OF FILE +//============================================================+ diff --git a/tools/tcpdf/sRGB.icc b/tools/tcpdf/sRGB.icc deleted file mode 100644 index 71e338302..000000000 Binary files a/tools/tcpdf/sRGB.icc and /dev/null differ diff --git a/tools/tcpdf/spotcolors.php b/tools/tcpdf/spotcolors.php deleted file mode 100644 index 3ab6e7312..000000000 --- a/tools/tcpdf/spotcolors.php +++ /dev/null @@ -1,61 +0,0 @@ -. -// -// See LICENSE.TXT file for more information. -// ------------------------------------------------------------------- -// -// Description : Array of Spot Colors for TCPDF library -// -//============================================================+ - -/** - * @file - * Arrays of Spot Colors for TCPDF library - * @author Nicola Asuni - * @package com.tecnick.tcpdf - * @since 5.9.012 (2010-11-11) -*/ - -/** - * Array of Spot colors (C,M,Y,K,name) - * Color keys must be in lowercase and without spaces. - * As long as no open standard for spot colours exists, you have to buy a colour book by one of the colour manufacturers and insert the values and names of spot colours directly. - * Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH. - */ -$spotcolor = array( - // the following are just examples, fill the array with your own values - 'mytcpdfblack' => array(0, 0, 0, 100, 'My TCPDF Black'), - 'mytcpdfred' => array(30, 100, 90, 10, 'My TCPDF Red'), - 'mytcpdfgreen' => array(100, 30, 100, 0, 'My TCPDF Green'), - 'mytcpdfblue' => array(100, 60, 10, 5, 'My TCPDF Blue'), - 'mytcpdfyellow' => array(0, 20, 100, 0, 'My TCPDF Yellow'), - // ... -); - -//============================================================+ -// END OF FILE -//============================================================+ - diff --git a/tools/tcpdf/tcpdf.crt b/tools/tcpdf/tcpdf.crt deleted file mode 100644 index f0491391c..000000000 --- a/tools/tcpdf/tcpdf.crt +++ /dev/null @@ -1,40 +0,0 @@ -Bag Attributes - localKeyID: 7B AB 1B 7A BE 4C 85 C0 1A A6 DC 59 3F 79 48 C3 93 38 68 9C -subject=/CN=TCPDF DEMO/O=TCPDF/OU=DEMO/emailAddress=you@example.com/C=IT -issuer=/CN=TCPDF DEMO/O=TCPDF/OU=DEMO/emailAddress=you@example.com/C=IT ------BEGIN CERTIFICATE----- -MIIC1TCCAj6gAwIBAgIKkehOL/XGkB5cjjANBgkqhkiG9w0BAQUFADBhMRMwEQYD -VQQDEwpUQ1BERiBERU1PMQ4wDAYDVQQKEwVUQ1BERjENMAsGA1UECxMEREVNTzEe -MBwGCSqGSIb3DQEJARYPeW91QGV4YW1wbGUuY29tMQswCQYDVQQGEwJJVDAeFw0w -OTA4MjExMjU0NDhaFw0xNDA4MjExMjU0NDhaMGExEzARBgNVBAMTClRDUERGIERF -TU8xDjAMBgNVBAoTBVRDUERGMQ0wCwYDVQQLEwRERU1PMR4wHAYJKoZIhvcNAQkB -Fg95b3VAZXhhbXBsZS5jb20xCzAJBgNVBAYTAklUMIGfMA0GCSqGSIb3DQEBAQUA -A4GNADCBiQKBgQDAqIL0uGKmTR98Lxx2vEEE1OGKkMXFo0JViitALe7Onhxxqx0H -XMUDKF5mvEVu1rcvh7/oAnAfrCuEpL/up3u1mQCgBE7WXBnFFE/AE3jCksh9OkS0 -Z0Xj9woN5bzxRDsGoPiOu/4xzk5qSEXt8jf2Ep90QuNkqLIRT4swAzpDbwIDAQAB -o4GTMIGQMDcGA1UdEgQwMC6gEQYDVQQDDApUQ1BERiBERU1PoAwGA1UECgwFVENQ -REagCwYDVQQLDARERU1PMDcGA1UdEQQwMC6gEQYDVQQDDApUQ1BERiBERU1PoAwG -A1UECgwFVENQREagCwYDVQQLDARERU1PMA8GCSqGSIb3LwEBCgQCBQAwCwYDVR0P -BAQDAgSQMA0GCSqGSIb3DQEBBQUAA4GBAEhTQfqX3ZNdHmpTLDbIj22RHXii2roE -OavCbu9WsHoWpva0qSd+yIoD594VHvYAd29sfzDfiN+7W0aiZfDhq5jpaSQMVlN8 -RGYMupbHY/+a9Gz1wqxnR84mlTtIkZVRYAhsfPwy6M1BEjdMqfdh9h40JIdkdjtb -8faTCfXPePWQ ------END CERTIFICATE----- -Bag Attributes - localKeyID: 7B AB 1B 7A BE 4C 85 C0 1A A6 DC 59 3F 79 48 C3 93 38 68 9C -Key Attributes: ------BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQDAqIL0uGKmTR98Lxx2vEEE1OGKkMXFo0JViitALe7Onhxxqx0H -XMUDKF5mvEVu1rcvh7/oAnAfrCuEpL/up3u1mQCgBE7WXBnFFE/AE3jCksh9OkS0 -Z0Xj9woN5bzxRDsGoPiOu/4xzk5qSEXt8jf2Ep90QuNkqLIRT4swAzpDbwIDAQAB -AoGAXc+wNMmz/5Z+RlIKYia44klmqbplEx+0JULqXI4BQsrqvs67i+I4bJkznoL+ -rEIRYSuQ3sCRKFsFtckjTGpxadnxkB+uwGKc6pZChv99BFX6HFR4hgBlT/BBRAQA -hMDlM2JIRr4S4SMVXR7MHwGMUf9mUeanGLR3ZWtU3aXJrIECQQD7OaYUVYNEEnM9 -uXyjm22CuHyqyEf5gb13sK0uQty67547yJTMUQZd/sQc9KGwhzBbhrob2LO2jAhh -S+f+NSRnAkEAxFHm3fMI5RgXmswxlGm4QW07a/Ueo7ZJG6xjTkFXluJhd+XHswRD -dQIO3zG9nGjNUoeMrPhXhPvKqFc2F9RDuQJAQBEGin74N77gxqfr4ik79y8nE8J5 -oGZ2s/RJZdfFRKLg3mwbjjNHhWb4Ck5UgZkoOt8TzRApXG8/n9hktE5HFwJBALur -M5AueO1Pl5kB489lNJ9OxUQRYUXMxpxuscuoCQwSwmv0O2+0/qtG2WKhUQnI4aYo -L+FV0YwtivBb1jj3T/kCQQDIWOxq8eRowdaMzvJpRUHFgMcf1AVZExKyrugwYOWd -KNsDxC4KaQOsPt8iT/Ulo4g/MJC0HolCOhWibKmR9Ayl ------END RSA PRIVATE KEY----- diff --git a/tools/tcpdf/tcpdf.fdf b/tools/tcpdf/tcpdf.fdf deleted file mode 100644 index a8f7c35d9..000000000 Binary files a/tools/tcpdf/tcpdf.fdf and /dev/null differ diff --git a/tools/tcpdf/tcpdf.p12 b/tools/tcpdf/tcpdf.p12 deleted file mode 100644 index 611f0dfb1..000000000 Binary files a/tools/tcpdf/tcpdf.p12 and /dev/null differ diff --git a/tools/tcpdf/tcpdf.php b/tools/tcpdf/tcpdf.php index a4809fc2f..8b7d81223 100644 --- a/tools/tcpdf/tcpdf.php +++ b/tools/tcpdf/tcpdf.php @@ -1,13 +1,13 @@ value attribute. -// Patrick Benny for text stretch suggestion on Cell(). -// Johannes G�ntert for JavaScript support. -// Denis Van Nuffelen for Dynamic Form. -// Jacek Czekaj for multibyte justification -// Anthony Ferrara for the reintroduction of legacy image methods. -// Sourceforge user 1707880 (hucste) for line-trough mode. -// Larry Stanbery for page groups. -// Martin Hall-May for transparency. -// Aaron C. Spike for Polycurve method. -// Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support. -// Moritz Wagner and Andreas Wurmser for graphic functions. -// Andrew Whitehead for core fonts support. -// Esteban Jo�l Mar�n for OpenType font conversion. -// Teus Hagen for several suggestions and fixes. -// Yukihiro Nakadaira for CID-0 CJK fonts fixes. -// Kosmas Papachristos for some CSS improvements. -// Marcel Partap for some fixes. -// Won Kyu Park for several suggestions, fixes and patches. -// Dominik Dzienia for QR-code support. -// Laurent Minguet for some suggestions. -// Christian Deligant for some suggestions and fixes. -// Travis Harris for crop mark suggestion. -// Aleksey Kuznetsov for some suggestions and text shadows. -// Anyone else that has reported a bug or sent a suggestion. +// * PDF/A-1b support //============================================================+ /** @@ -114,8 +80,8 @@ *
  • font subsetting;
  • *
  • methods to publish some XHTML + CSS code, Javascript and Forms;
  • *
  • images, graphic (geometric figures) and transformation methods; - *
  • supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  • - *
  • 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  • + *
  • supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)
  • + *
  • 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  • *
  • JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  • *
  • automatic page header and footer management;
  • *
  • document encryption up to 256 bit and digital signature certifications;
  • @@ -138,16 +104,23 @@ * Tools to encode your unicode fonts are on fonts/utils directory.

    * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 5.9.179 + * @version 6.3.2 */ -/* - PrestaShop - all calls to file_exists replaced by Tools::file_exists_no_cache() -*/ +// TCPDF configuration +require_once(dirname(__FILE__).'/tcpdf_autoconfig.php'); +// TCPDF static font methods and data +require_once(dirname(__FILE__).'/include/tcpdf_font_data.php'); +// TCPDF static font methods and data +require_once(dirname(__FILE__).'/include/tcpdf_fonts.php'); +// TCPDF static color methods and data +require_once(dirname(__FILE__).'/include/tcpdf_colors.php'); +// TCPDF static image methods and data +require_once(dirname(__FILE__).'/include/tcpdf_images.php'); +// TCPDF static methods and data +require_once(dirname(__FILE__).'/include/tcpdf_static.php'); -// Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file. -require_once(dirname(__FILE__).'/config/tcpdf_config.php'); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * @class TCPDF @@ -155,19 +128,14 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.php'); * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
    * @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. - * @version 5.9.179 + * @version 6.3.2 * @author Nicola Asuni - info@tecnick.com + * @IgnoreAnnotation("protected") + * @IgnoreAnnotation("public") + * @IgnoreAnnotation("pre") */ class TCPDF { - // private properties - - /** - * Current TCPDF version. - * @private - */ - private $tcpdf_version = '5.9.179'; - // Protected properties /** @@ -278,18 +246,30 @@ class TCPDF { */ protected $lMargin; - /** - * Top margin. - * @protected - */ - protected $tMargin; - /** * Right margin. * @protected */ protected $rMargin; + /** + * Cell left margin (used by regions). + * @protected + */ + protected $clMargin; + + /** + * Cell right margin (used by regions). + * @protected + */ + protected $crMargin; + + /** + * Top margin. + * @protected + */ + protected $tMargin; + /** * Page break margin. * @protected @@ -364,6 +344,12 @@ class TCPDF { */ protected $images = array(); + /** + * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag. + * @protected + */ + protected $svg_tag_depth = 0; + /** * Array of Annotations in pages. * @protected @@ -534,36 +520,6 @@ class TCPDF { */ protected $starting_page_number = 1; - /** - * String alias for total number of pages. - * @protected - */ - protected $alias_tot_pages = '{:ptp:}'; - - /** - * String alias for page number. - * @protected - */ - protected $alias_num_page = '{:pnp:}'; - - /** - * String alias for total number of pages in a single group. - * @protected - */ - protected $alias_group_tot_pages = '{:ptg:}'; - - /** - * String alias for group page number. - * @protected - */ - protected $alias_group_num_page = '{:png:}'; - - /** - * String alias for right shift compensation used to correctly align page numbers on the right. - * @protected - */ - protected $alias_right_shift = '{rsc:'; - /** * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image. * @since 2002-07-31 @@ -596,22 +552,6 @@ class TCPDF { */ protected $isunicode = false; - /** - * Object containing unicode data. - * @since 5.9.004 (2010-10-18) - * @author Nicola Asuni - * @protected - */ - protected $unicode; - - /** - * Object containing font encoding maps. - * @since 5.9.123 (2011-10-01) - * @author Nicola Asuni - * @protected - */ - protected $encmaps; - /** * PDF version. * @since 1.5.3 @@ -623,7 +563,7 @@ class TCPDF { * ID of the stored default header template (-1 = not set). * @protected */ - protected $header_xobjid = -1; + protected $header_xobjid = false; /** * If true reset the Header Xobject template at each page @@ -884,12 +824,6 @@ class TCPDF { */ protected $last_enc_key_c; - /** - * Encryption padding string. - * @protected - */ - protected $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"; - /** * File ID (used on document trailer). * @protected @@ -930,7 +864,7 @@ class TCPDF { protected $n_js; /** - * line trough state + * line through state * @protected * @since 2.8.000 (2008-03-19) */ @@ -1252,13 +1186,6 @@ class TCPDF { */ protected $bufferlen = 0; - /** - * If true enables disk caching. - * @protected - * @since 4.5.000 (2008-12-31) - */ - protected $diskcache = false; - /** * Counts the number of fonts. * @protected @@ -1322,27 +1249,6 @@ class TCPDF { */ protected $theadMargins = array(); - /** - * Cache array for UTF8StringToArray() method. - * @protected - * @since 4.5.037 (2009-04-07) - */ - protected $cache_UTF8StringToArray = array(); - - /** - * Maximum size of cache array used for UTF8StringToArray() method. - * @protected - * @since 4.5.037 (2009-04-07) - */ - protected $cache_maxsize_UTF8StringToArray = 8; - - /** - * Current size of cache array used for UTF8StringToArray() method. - * @protected - * @since 4.5.037 (2009-04-07) - */ - protected $cache_size_UTF8StringToArray = 0; - /** * Boolean flag to enable document digital signature. * @protected @@ -1378,6 +1284,20 @@ class TCPDF { */ protected $empty_signature_appearance = array(); + /** + * Boolean flag to enable document timestamping with TSA. + * @protected + * @since 6.0.085 (2014-06-19) + */ + protected $tsa_timestamp = false; + + /** + * Timestamping data. + * @protected + * @since 6.0.085 (2014-06-19) + */ + protected $tsa_data = array(); + /** * Regular expression used to find blank characters (required for word-wrapping). * @protected @@ -1399,20 +1319,6 @@ class TCPDF { */ protected $sig_obj_id = 0; - /** - * ByteRange placemark used during digital signature process. - * @protected - * @since 4.6.028 (2009-08-25) - */ - protected $byterange_string = '/ByteRange[0 ********** ********** **********]'; - - /** - * Placemark used during digital signature process. - * @protected - * @since 4.6.028 (2009-08-25) - */ - protected $sig_annot_ref = '***SIGANNREF*** 0 R'; - /** * ID of page objects. * @protected @@ -1652,18 +1558,10 @@ class TCPDF { protected $page_regions = array(); /** - * Array containing HTML color names and values. + * Boolean value true when page region check is active. * @protected - * @since 5.9.004 (2010-10-18) */ - protected $webcolor = array(); - - /** - * Array containing spot color names and values. - * @protected - * @since 5.9.012 (2010-11-11) - */ - protected $spotcolor = array(); + protected $check_page_regions = true; /** * Array of PDF layers data. @@ -1686,6 +1584,13 @@ class TCPDF { */ protected $n_dests; + /** + * Embedded Files Names + * @protected + * @since 5.9.204 (2013-01-23) + */ + protected $efnames = array(); + /** * Directory used for the last SVG image. * @protected @@ -1770,13 +1675,6 @@ class TCPDF { */ protected $svgtextmode = array(); - /** - * Array of hinheritable SVG properties. - * @protected - * @since 5.0.000 (2010-05-02) - */ - protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode'); - /** * Array of SVG properties. * @protected @@ -1862,6 +1760,13 @@ class TCPDF { */ protected $pdfa_mode = false; + /** + * version of PDF/A mode (1 - 3). + * @protected + * @since 6.2.26 (2019-03-12) + */ + protected $pdfa_version = 1; + /** * Document creation date-time * @protected @@ -1883,6 +1788,13 @@ class TCPDF { */ protected $custom_xmp = ''; + /** + * Custom XMP RDF data. + * @protected + * @since 6.3.0 (2019-09-19) + */ + protected $custom_xmp_rdf = ''; + /** * Overprint mode array. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008). @@ -1906,13 +1818,6 @@ class TCPDF { */ protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); - /** - * Set the document producer metadata. - * @protected - * @since 5.9.152 (2012-03-23) - */ - protected $pdfproducer; - /** * If true print TCPDF meta link. * @protected @@ -1934,44 +1839,40 @@ class TCPDF { /** * This is the class constructor. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes). + * + * IMPORTANT: Please note that this method sets the mb_internal_encoding to ASCII, so if you are using the mbstring module functions with TCPDF you need to correctly set/unset the mb_internal_encoding when needed. + * * @param $orientation (string) page orientation. Possible values are (case insensitive):
    • P or Portrait (default)
    • L or Landscape
    • '' (empty string) for automatic orientation
    * @param $unit (string) User measure unit. Possible values are:
    • pt: point
    • mm: millimeter (default)
    • cm: centimeter
    • in: inch

    A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat(). * @param $unicode (boolean) TRUE means that the input text is unicode (default = true) - * @param $encoding (string) Charset encoding; default is UTF-8. - * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). - * @param $pdfa (boolean) If TRUE set the document to PDF/A mode. + * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8. + * @param $diskcache (boolean) DEPRECATED FEATURE + * @param $pdfa (integer) If not false, set the document to PDF/A mode and the good version (1 or 3). * @public * @see getPageSizeFromFormat(), setPageFormat() */ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) { /* Set internal character encoding to ASCII */ - if (function_exists('mb_internal_encoding') and mb_internal_encoding()) { + if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) { $this->internal_encoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } - // get array of HTML colors - require(dirname(__FILE__).'/htmlcolors.php'); - $this->webcolor = $webcolor; - // get array of custom spot colors - if (Tools::file_exists_no_cache(dirname(__FILE__).'/spotcolors.php')) { - require(dirname(__FILE__).'/spotcolors.php'); - $this->spotcolor = $spotcolor; - } else { - $this->spotcolor = array(); - } - require_once(dirname(__FILE__).'/unicode_data.php'); - $this->unicode = new TCPDF_UNICODE_DATA(); - require_once(dirname(__FILE__).'/encodings_maps.php'); - $this->encmaps = new TCPDF_ENCODING_MAPS(); + // set file ID for trailer + $serformat = (is_array($format) ? json_encode($format) : $format); + $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding)); $this->font_obj_ids = array(); $this->page_obj_id = array(); $this->form_obj_id = array(); + // set pdf/a mode - $this->pdfa_mode = $pdfa; + if ($pdfa != false) { + $this->pdfa_mode = true; + $this->pdfa_version = $pdfa; // 1 or 3 + } else + $this->pdfa_mode = false; + $this->force_srgb = false; - // set disk caching - $this->diskcache = $diskcache ? true : false; // set language direction $this->rtl = false; $this->tmprtl = false; @@ -2032,6 +1933,8 @@ class TCPDF { // page margins (1 cm) $margin = 28.35 / $this->k; $this->SetMargins($margin, $margin); + $this->clMargin = $this->lMargin; + $this->crMargin = $this->rMargin; // internal cell padding $cpadding = $margin / 10; $this->setCellPaddings($cpadding, 0, $cpadding, 0); @@ -2051,7 +1954,6 @@ class TCPDF { $this->SetCompression(); // set default PDF version number $this->setPDFVersion(); - $this->pdfproducer = "\x54\x43\x50\x44\x46\x20".$this->tcpdf_version."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29"; $this->tcpdflink = true; $this->encoding = $encoding; $this->HREF = array(); @@ -2061,8 +1963,13 @@ class TCPDF { $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255); $this->extgstates = array(); $this->setTextShadow(); - // user's rights + // signature $this->sign = false; + $this->tsa_timestamp = false; + $this->tsa_data = array(); + $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature'); + $this->empty_signature_appearance = array(); + // user's rights $this->ur['enabled'] = false; $this->ur['document'] = '/FullSave'; $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export'; @@ -2070,30 +1977,28 @@ class TCPDF { $this->ur['signature'] = '/Modify'; $this->ur['ef'] = '/Create/Delete/Modify/Import'; $this->ur['formex'] = ''; - $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0'); - $this->empty_signature_appearance = array(); // set default JPEG quality $this->jpeg_quality = 75; // initialize some settings - $this->utf8Bidi(array(''), ''); + TCPDF_FONTS::utf8Bidi(array(), '', false, $this->isunicode, $this->CurrentFont); // set default font $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt); + $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt)); + $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt)); // check if PCRE Unicode support is enabled - if ($this->isunicode and (@preg_match('/\pL/u', 'a') == 1)) { + if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) { // PCRE unicode support is turned ON - // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator. - // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. - // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. - //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u'); - $this->setSpacesRE('/[^\S\P{Z}\xa0]/u'); + // \s : any whitespace character + // \p{Z} : any separator + // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words. + // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0) + //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u'); + $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u'); } else { // PCRE unicode support is turned OFF $this->setSpacesRE('/[^\S\xa0]/'); } $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128)); - // set file ID for trailer - $serformat = (is_array($format) ? serialize($format) : $format); - $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding)); // set document creation and modification timestamp $this->doc_creation_timestamp = time(); $this->doc_modification_timestamp = $this->doc_creation_timestamp; @@ -2101,6 +2006,10 @@ class TCPDF { $this->default_graphic_vars = $this->getGraphicVars(); $this->header_xobj_autoreset = false; $this->custom_xmp = ''; + $this->custom_xmp_rdf = ''; + // Call cleanup method after script execution finishes or exit() is called. + // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal. + register_shutdown_function(array($this, '_destroy'), true); } /** @@ -2109,24 +2018,10 @@ class TCPDF { * @since 1.53.0.TC016 */ public function __destruct() { - // restore internal encoding - if (isset($this->internal_encoding) and !empty($this->internal_encoding)) { - mb_internal_encoding($this->internal_encoding); - } - // unset all class variables + // cleanup $this->_destroy(true); } - /** - * Return the current TCPDF version. - * @return TCPDF version string - * @public - * @since 5.9.012 (2010-11-10) - */ - public function getTCPDFVersion() { - return $this->tcpdf_version; - } - /** * Set the units of measure for the document. * @param $unit (string) User measure unit. Possible values are:
    • pt: point
    • mm: millimeter (default)
    • cm: centimeter
    • in: inch

    A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. @@ -2170,705 +2065,37 @@ class TCPDF { } } - /** - * Get page dimensions from format name. - * @param $format (mixed) The format name. It can be:
      - *
    • ISO 216 A Series + 2 SIS 014711 extensions
    • - *
    • A0 (841x1189 mm ; 33.11x46.81 in)
    • - *
    • A1 (594x841 mm ; 23.39x33.11 in)
    • - *
    • A2 (420x594 mm ; 16.54x23.39 in)
    • - *
    • A3 (297x420 mm ; 11.69x16.54 in)
    • - *
    • A4 (210x297 mm ; 8.27x11.69 in)
    • - *
    • A5 (148x210 mm ; 5.83x8.27 in)
    • - *
    • A6 (105x148 mm ; 4.13x5.83 in)
    • - *
    • A7 (74x105 mm ; 2.91x4.13 in)
    • - *
    • A8 (52x74 mm ; 2.05x2.91 in)
    • - *
    • A9 (37x52 mm ; 1.46x2.05 in)
    • - *
    • A10 (26x37 mm ; 1.02x1.46 in)
    • - *
    • A11 (18x26 mm ; 0.71x1.02 in)
    • - *
    • A12 (13x18 mm ; 0.51x0.71 in)
    • - *
    • ISO 216 B Series + 2 SIS 014711 extensions
    • - *
    • B0 (1000x1414 mm ; 39.37x55.67 in)
    • - *
    • B1 (707x1000 mm ; 27.83x39.37 in)
    • - *
    • B2 (500x707 mm ; 19.69x27.83 in)
    • - *
    • B3 (353x500 mm ; 13.90x19.69 in)
    • - *
    • B4 (250x353 mm ; 9.84x13.90 in)
    • - *
    • B5 (176x250 mm ; 6.93x9.84 in)
    • - *
    • B6 (125x176 mm ; 4.92x6.93 in)
    • - *
    • B7 (88x125 mm ; 3.46x4.92 in)
    • - *
    • B8 (62x88 mm ; 2.44x3.46 in)
    • - *
    • B9 (44x62 mm ; 1.73x2.44 in)
    • - *
    • B10 (31x44 mm ; 1.22x1.73 in)
    • - *
    • B11 (22x31 mm ; 0.87x1.22 in)
    • - *
    • B12 (15x22 mm ; 0.59x0.87 in)
    • - *
    • ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
    • - *
    • C0 (917x1297 mm ; 36.10x51.06 in)
    • - *
    • C1 (648x917 mm ; 25.51x36.10 in)
    • - *
    • C2 (458x648 mm ; 18.03x25.51 in)
    • - *
    • C3 (324x458 mm ; 12.76x18.03 in)
    • - *
    • C4 (229x324 mm ; 9.02x12.76 in)
    • - *
    • C5 (162x229 mm ; 6.38x9.02 in)
    • - *
    • C6 (114x162 mm ; 4.49x6.38 in)
    • - *
    • C7 (81x114 mm ; 3.19x4.49 in)
    • - *
    • C8 (57x81 mm ; 2.24x3.19 in)
    • - *
    • C9 (40x57 mm ; 1.57x2.24 in)
    • - *
    • C10 (28x40 mm ; 1.10x1.57 in)
    • - *
    • C11 (20x28 mm ; 0.79x1.10 in)
    • - *
    • C12 (14x20 mm ; 0.55x0.79 in)
    • - *
    • C76 (81x162 mm ; 3.19x6.38 in)
    • - *
    • DL (110x220 mm ; 4.33x8.66 in)
    • - *
    • SIS 014711 E Series
    • - *
    • E0 (879x1241 mm ; 34.61x48.86 in)
    • - *
    • E1 (620x879 mm ; 24.41x34.61 in)
    • - *
    • E2 (440x620 mm ; 17.32x24.41 in)
    • - *
    • E3 (310x440 mm ; 12.20x17.32 in)
    • - *
    • E4 (220x310 mm ; 8.66x12.20 in)
    • - *
    • E5 (155x220 mm ; 6.10x8.66 in)
    • - *
    • E6 (110x155 mm ; 4.33x6.10 in)
    • - *
    • E7 (78x110 mm ; 3.07x4.33 in)
    • - *
    • E8 (55x78 mm ; 2.17x3.07 in)
    • - *
    • E9 (39x55 mm ; 1.54x2.17 in)
    • - *
    • E10 (27x39 mm ; 1.06x1.54 in)
    • - *
    • E11 (19x27 mm ; 0.75x1.06 in)
    • - *
    • E12 (13x19 mm ; 0.51x0.75 in)
    • - *
    • SIS 014711 G Series
    • - *
    • G0 (958x1354 mm ; 37.72x53.31 in)
    • - *
    • G1 (677x958 mm ; 26.65x37.72 in)
    • - *
    • G2 (479x677 mm ; 18.86x26.65 in)
    • - *
    • G3 (338x479 mm ; 13.31x18.86 in)
    • - *
    • G4 (239x338 mm ; 9.41x13.31 in)
    • - *
    • G5 (169x239 mm ; 6.65x9.41 in)
    • - *
    • G6 (119x169 mm ; 4.69x6.65 in)
    • - *
    • G7 (84x119 mm ; 3.31x4.69 in)
    • - *
    • G8 (59x84 mm ; 2.32x3.31 in)
    • - *
    • G9 (42x59 mm ; 1.65x2.32 in)
    • - *
    • G10 (29x42 mm ; 1.14x1.65 in)
    • - *
    • G11 (21x29 mm ; 0.83x1.14 in)
    • - *
    • G12 (14x21 mm ; 0.55x0.83 in)
    • - *
    • ISO Press
    • - *
    • RA0 (860x1220 mm ; 33.86x48.03 in)
    • - *
    • RA1 (610x860 mm ; 24.02x33.86 in)
    • - *
    • RA2 (430x610 mm ; 16.93x24.02 in)
    • - *
    • RA3 (305x430 mm ; 12.01x16.93 in)
    • - *
    • RA4 (215x305 mm ; 8.46x12.01 in)
    • - *
    • SRA0 (900x1280 mm ; 35.43x50.39 in)
    • - *
    • SRA1 (640x900 mm ; 25.20x35.43 in)
    • - *
    • SRA2 (450x640 mm ; 17.72x25.20 in)
    • - *
    • SRA3 (320x450 mm ; 12.60x17.72 in)
    • - *
    • SRA4 (225x320 mm ; 8.86x12.60 in)
    • - *
    • German DIN 476
    • - *
    • 4A0 (1682x2378 mm ; 66.22x93.62 in)
    • - *
    • 2A0 (1189x1682 mm ; 46.81x66.22 in)
    • - *
    • Variations on the ISO Standard
    • - *
    • A2_EXTRA (445x619 mm ; 17.52x24.37 in)
    • - *
    • A3+ (329x483 mm ; 12.95x19.02 in)
    • - *
    • A3_EXTRA (322x445 mm ; 12.68x17.52 in)
    • - *
    • A3_SUPER (305x508 mm ; 12.01x20.00 in)
    • - *
    • SUPER_A3 (305x487 mm ; 12.01x19.17 in)
    • - *
    • A4_EXTRA (235x322 mm ; 9.25x12.68 in)
    • - *
    • A4_SUPER (229x322 mm ; 9.02x12.68 in)
    • - *
    • SUPER_A4 (227x356 mm ; 8.94x14.02 in)
    • - *
    • A4_LONG (210x348 mm ; 8.27x13.70 in)
    • - *
    • F4 (210x330 mm ; 8.27x12.99 in)
    • - *
    • SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)
    • - *
    • A5_EXTRA (173x235 mm ; 6.81x9.25 in)
    • - *
    • ANSI Series
    • - *
    • ANSI_E (864x1118 mm ; 34.00x44.00 in)
    • - *
    • ANSI_D (559x864 mm ; 22.00x34.00 in)
    • - *
    • ANSI_C (432x559 mm ; 17.00x22.00 in)
    • - *
    • ANSI_B (279x432 mm ; 11.00x17.00 in)
    • - *
    • ANSI_A (216x279 mm ; 8.50x11.00 in)
    • - *
    • Traditional 'Loose' North American Paper Sizes
    • - *
    • LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)
    • - *
    • TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)
    • - *
    • LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)
    • - *
    • LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)
    • - *
    • GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)
    • - *
    • JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)
    • - *
    • Other North American Paper Sizes
    • - *
    • QUADDEMY (889x1143 mm ; 35.00x45.00 in)
    • - *
    • SUPER_B (330x483 mm ; 13.00x19.00 in)
    • - *
    • QUARTO (229x279 mm ; 9.00x11.00 in)
    • - *
    • FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)
    • - *
    • EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)
    • - *
    • MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)
    • - *
    • FOOLSCAP (210x330 mm ; 8.27x13.00 in)
    • - *
    • COMPACT (108x171 mm ; 4.25x6.75 in)
    • - *
    • ORGANIZERJ (70x127 mm ; 2.75x5.00 in)
    • - *
    • Canadian standard CAN 2-9.60M
    • - *
    • P1 (560x860 mm ; 22.05x33.86 in)
    • - *
    • P2 (430x560 mm ; 16.93x22.05 in)
    • - *
    • P3 (280x430 mm ; 11.02x16.93 in)
    • - *
    • P4 (215x280 mm ; 8.46x11.02 in)
    • - *
    • P5 (140x215 mm ; 5.51x8.46 in)
    • - *
    • P6 (107x140 mm ; 4.21x5.51 in)
    • - *
    • North American Architectural Sizes
    • - *
    • ARCH_E (914x1219 mm ; 36.00x48.00 in)
    • - *
    • ARCH_E1 (762x1067 mm ; 30.00x42.00 in)
    • - *
    • ARCH_D (610x914 mm ; 24.00x36.00 in)
    • - *
    • ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)
    • - *
    • ARCH_B (305x457 mm ; 12.00x18.00 in)
    • - *
    • ARCH_A (229x305 mm ; 9.00x12.00 in)
    • - *
    • Announcement Envelopes
    • - *
    • ANNENV_A2 (111x146 mm ; 4.37x5.75 in)
    • - *
    • ANNENV_A6 (121x165 mm ; 4.75x6.50 in)
    • - *
    • ANNENV_A7 (133x184 mm ; 5.25x7.25 in)
    • - *
    • ANNENV_A8 (140x206 mm ; 5.50x8.12 in)
    • - *
    • ANNENV_A10 (159x244 mm ; 6.25x9.62 in)
    • - *
    • ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)
    • - *
    • Commercial Envelopes
    • - *
    • COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)
    • - *
    • COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)
    • - *
    • COMMENV_N8 (98x191 mm ; 3.87x7.50 in)
    • - *
    • COMMENV_N9 (98x225 mm ; 3.87x8.87 in)
    • - *
    • COMMENV_N10 (105x241 mm ; 4.12x9.50 in)
    • - *
    • COMMENV_N11 (114x263 mm ; 4.50x10.37 in)
    • - *
    • COMMENV_N12 (121x279 mm ; 4.75x11.00 in)
    • - *
    • COMMENV_N14 (127x292 mm ; 5.00x11.50 in)
    • - *
    • Catalogue Envelopes
    • - *
    • CATENV_N1 (152x229 mm ; 6.00x9.00 in)
    • - *
    • CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)
    • - *
    • CATENV_N2 (165x254 mm ; 6.50x10.00 in)
    • - *
    • CATENV_N3 (178x254 mm ; 7.00x10.00 in)
    • - *
    • CATENV_N6 (191x267 mm ; 7.50x10.50 in)
    • - *
    • CATENV_N7 (203x279 mm ; 8.00x11.00 in)
    • - *
    • CATENV_N8 (210x286 mm ; 8.25x11.25 in)
    • - *
    • CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)
    • - *
    • CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)
    • - *
    • CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)
    • - *
    • CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)
    • - *
    • CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)
    • - *
    • CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)
    • - *
    • CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)
    • - *
    • Japanese (JIS P 0138-61) Standard B-Series
    • - *
    • JIS_B0 (1030x1456 mm ; 40.55x57.32 in)
    • - *
    • JIS_B1 (728x1030 mm ; 28.66x40.55 in)
    • - *
    • JIS_B2 (515x728 mm ; 20.28x28.66 in)
    • - *
    • JIS_B3 (364x515 mm ; 14.33x20.28 in)
    • - *
    • JIS_B4 (257x364 mm ; 10.12x14.33 in)
    • - *
    • JIS_B5 (182x257 mm ; 7.17x10.12 in)
    • - *
    • JIS_B6 (128x182 mm ; 5.04x7.17 in)
    • - *
    • JIS_B7 (91x128 mm ; 3.58x5.04 in)
    • - *
    • JIS_B8 (64x91 mm ; 2.52x3.58 in)
    • - *
    • JIS_B9 (45x64 mm ; 1.77x2.52 in)
    • - *
    • JIS_B10 (32x45 mm ; 1.26x1.77 in)
    • - *
    • JIS_B11 (22x32 mm ; 0.87x1.26 in)
    • - *
    • JIS_B12 (16x22 mm ; 0.63x0.87 in)
    • - *
    • PA Series
    • - *
    • PA0 (840x1120 mm ; 33.07x44.09 in)
    • - *
    • PA1 (560x840 mm ; 22.05x33.07 in)
    • - *
    • PA2 (420x560 mm ; 16.54x22.05 in)
    • - *
    • PA3 (280x420 mm ; 11.02x16.54 in)
    • - *
    • PA4 (210x280 mm ; 8.27x11.02 in)
    • - *
    • PA5 (140x210 mm ; 5.51x8.27 in)
    • - *
    • PA6 (105x140 mm ; 4.13x5.51 in)
    • - *
    • PA7 (70x105 mm ; 2.76x4.13 in)
    • - *
    • PA8 (52x70 mm ; 2.05x2.76 in)
    • - *
    • PA9 (35x52 mm ; 1.38x2.05 in)
    • - *
    • PA10 (26x35 mm ; 1.02x1.38 in)
    • - *
    • Standard Photographic Print Sizes
    • - *
    • PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)
    • - *
    • E (82x120 mm ; 3.25x4.72 in)
    • - *
    • 3R, L (89x127 mm ; 3.50x5.00 in)
    • - *
    • 4R, KG (102x152 mm ; 4.02x5.98 in)
    • - *
    • 4D (120x152 mm ; 4.72x5.98 in)
    • - *
    • 5R, 2L (127x178 mm ; 5.00x7.01 in)
    • - *
    • 6R, 8P (152x203 mm ; 5.98x7.99 in)
    • - *
    • 8R, 6P (203x254 mm ; 7.99x10.00 in)
    • - *
    • S8R, 6PW (203x305 mm ; 7.99x12.01 in)
    • - *
    • 10R, 4P (254x305 mm ; 10.00x12.01 in)
    • - *
    • S10R, 4PW (254x381 mm ; 10.00x15.00 in)
    • - *
    • 11R (279x356 mm ; 10.98x14.02 in)
    • - *
    • S11R (279x432 mm ; 10.98x17.01 in)
    • - *
    • 12R (305x381 mm ; 12.01x15.00 in)
    • - *
    • S12R (305x456 mm ; 12.01x17.95 in)
    • - *
    • Common Newspaper Sizes
    • - *
    • NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)
    • - *
    • NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)
    • - *
    • NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)
    • - *
    • Business Cards
    • - *
    • CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)
    • - *
    • BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)
    • - *
    • BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)
    • - *
    • BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)
    • - *
    • BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)
    • - *
    • BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)
    • - *
    • BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)
    • - *
    • BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)
    • - *
    • Billboards
    • - *
    • 4SHEET (1016x1524 mm ; 40.00x60.00 in)
    • - *
    • 6SHEET (1200x1800 mm ; 47.24x70.87 in)
    • - *
    • 12SHEET (3048x1524 mm ; 120.00x60.00 in)
    • - *
    • 16SHEET (2032x3048 mm ; 80.00x120.00 in)
    • - *
    • 32SHEET (4064x3048 mm ; 160.00x120.00 in)
    • - *
    • 48SHEET (6096x3048 mm ; 240.00x120.00 in)
    • - *
    • 64SHEET (8128x3048 mm ; 320.00x120.00 in)
    • - *
    • 96SHEET (12192x3048 mm ; 480.00x120.00 in)
    • - *
    • Old Imperial English (some are still used in USA)
    • - *
    • EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)
    • - *
    • EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)
    • - *
    • EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)
    • - *
    • EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)
    • - *
    • EN_ATLAS (660x864 mm ; 26.00x34.00 in)
    • - *
    • EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)
    • - *
    • EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)
    • - *
    • EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)
    • - *
    • EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)
    • - *
    • EN_PRINCESS (546x711 mm ; 21.50x28.00 in)
    • - *
    • EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)
    • - *
    • EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)
    • - *
    • EN_ROYAL (508x635 mm ; 20.00x25.00 in)
    • - *
    • EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)
    • - *
    • EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)
    • - *
    • EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)
    • - *
    • EN_MEDIUM (445x584 mm ; 17.50x23.00 in)
    • - *
    • EN_DEMY (445x572 mm ; 17.50x22.50 in)
    • - *
    • EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)
    • - *
    • EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)
    • - *
    • EN_POST (394x489 mm ; 15.50x19.25 in)
    • - *
    • EN_CROWN (381x508 mm ; 15.00x20.00 in)
    • - *
    • EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)
    • - *
    • EN_BRIEF (343x406 mm ; 13.50x16.00 in)
    • - *
    • EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)
    • - *
    • EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)
    • - *
    • EN_POTT (318x381 mm ; 12.50x15.00 in)
    • - *
    • Old Imperial Belgian
    • - *
    • BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)
    • - *
    • BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)
    • - *
    • BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)
    • - *
    • BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)
    • - *
    • BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)
    • - *
    • BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)
    • - *
    • BE_JESUS (540x730 mm ; 21.26x28.74 in)
    • - *
    • BE_RAISIN (500x650 mm ; 19.69x25.59 in)
    • - *
    • BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)
    • - *
    • BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)
    • - *
    • BE_COQUILLE (430x560 mm ; 16.93x22.05 in)
    • - *
    • BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)
    • - *
    • BE_RUCHE (360x460 mm ; 14.17x18.11 in)
    • - *
    • BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)
    • - *
    • BE_LYS (317x397 mm ; 12.48x15.63 in)
    • - *
    • BE_POT (307x384 mm ; 12.09x15.12 in)
    • - *
    • BE_ROSETTE (270x347 mm ; 10.63x13.66 in)
    • - *
    • Old Imperial French
    • - *
    • FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)
    • - *
    • FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)
    • - *
    • FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)
    • - *
    • FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)
    • - *
    • FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)
    • - *
    • FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)
    • - *
    • FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)
    • - *
    • FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)
    • - *
    • FR_JOURNAL (650x940 mm ; 25.59x37.01 in)
    • - *
    • FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)
    • - *
    • FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)
    • - *
    • FR_CLOCHE (600x800 mm ; 23.62x31.50 in)
    • - *
    • FR_SOLEIL (600x800 mm ; 23.62x31.50 in)
    • - *
    • FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)
    • - *
    • FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)
    • - *
    • FR_JESUS (560x760 mm ; 22.05x29.92 in)
    • - *
    • FR_RAISIN (500x650 mm ; 19.69x25.59 in)
    • - *
    • FR_CAVALIER (460x620 mm ; 18.11x24.41 in)
    • - *
    • FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)
    • - *
    • FR_CARRE (450x560 mm ; 17.72x22.05 in)
    • - *
    • FR_COQUILLE (440x560 mm ; 17.32x22.05 in)
    • - *
    • FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)
    • - *
    • FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)
    • - *
    • FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)
    • - *
    • FR_ECU (400x520 mm ; 15.75x20.47 in)
    • - *
    • FR_COURONNE (360x460 mm ; 14.17x18.11 in)
    • - *
    • FR_TELLIERE (340x440 mm ; 13.39x17.32 in)
    • - *
    • FR_POT (310x400 mm ; 12.20x15.75 in)
    • - *
    - * @return array containing page width and height in points - * @public - * @since 5.0.010 (2010-05-17) - */ - public function getPageSizeFromFormat($format) { - // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm) - switch (strtoupper($format)) { - // ISO 216 A Series + 2 SIS 014711 extensions - case 'A0' : {$pf = array( 2383.937, 3370.394); break;} - case 'A1' : {$pf = array( 1683.780, 2383.937); break;} - case 'A2' : {$pf = array( 1190.551, 1683.780); break;} - case 'A3' : {$pf = array( 841.890, 1190.551); break;} - case 'A4' : {$pf = array( 595.276, 841.890); break;} - case 'A5' : {$pf = array( 419.528, 595.276); break;} - case 'A6' : {$pf = array( 297.638, 419.528); break;} - case 'A7' : {$pf = array( 209.764, 297.638); break;} - case 'A8' : {$pf = array( 147.402, 209.764); break;} - case 'A9' : {$pf = array( 104.882, 147.402); break;} - case 'A10': {$pf = array( 73.701, 104.882); break;} - case 'A11': {$pf = array( 51.024, 73.701); break;} - case 'A12': {$pf = array( 36.850, 51.024); break;} - // ISO 216 B Series + 2 SIS 014711 extensions - case 'B0' : {$pf = array( 2834.646, 4008.189); break;} - case 'B1' : {$pf = array( 2004.094, 2834.646); break;} - case 'B2' : {$pf = array( 1417.323, 2004.094); break;} - case 'B3' : {$pf = array( 1000.630, 1417.323); break;} - case 'B4' : {$pf = array( 708.661, 1000.630); break;} - case 'B5' : {$pf = array( 498.898, 708.661); break;} - case 'B6' : {$pf = array( 354.331, 498.898); break;} - case 'B7' : {$pf = array( 249.449, 354.331); break;} - case 'B8' : {$pf = array( 175.748, 249.449); break;} - case 'B9' : {$pf = array( 124.724, 175.748); break;} - case 'B10': {$pf = array( 87.874, 124.724); break;} - case 'B11': {$pf = array( 62.362, 87.874); break;} - case 'B12': {$pf = array( 42.520, 62.362); break;} - // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION - case 'C0' : {$pf = array( 2599.370, 3676.535); break;} - case 'C1' : {$pf = array( 1836.850, 2599.370); break;} - case 'C2' : {$pf = array( 1298.268, 1836.850); break;} - case 'C3' : {$pf = array( 918.425, 1298.268); break;} - case 'C4' : {$pf = array( 649.134, 918.425); break;} - case 'C5' : {$pf = array( 459.213, 649.134); break;} - case 'C6' : {$pf = array( 323.150, 459.213); break;} - case 'C7' : {$pf = array( 229.606, 323.150); break;} - case 'C8' : {$pf = array( 161.575, 229.606); break;} - case 'C9' : {$pf = array( 113.386, 161.575); break;} - case 'C10': {$pf = array( 79.370, 113.386); break;} - case 'C11': {$pf = array( 56.693, 79.370); break;} - case 'C12': {$pf = array( 39.685, 56.693); break;} - case 'C76': {$pf = array( 229.606, 459.213); break;} - case 'DL' : {$pf = array( 311.811, 623.622); break;} - // SIS 014711 E Series - case 'E0' : {$pf = array( 2491.654, 3517.795); break;} - case 'E1' : {$pf = array( 1757.480, 2491.654); break;} - case 'E2' : {$pf = array( 1247.244, 1757.480); break;} - case 'E3' : {$pf = array( 878.740, 1247.244); break;} - case 'E4' : {$pf = array( 623.622, 878.740); break;} - case 'E5' : {$pf = array( 439.370, 623.622); break;} - case 'E6' : {$pf = array( 311.811, 439.370); break;} - case 'E7' : {$pf = array( 221.102, 311.811); break;} - case 'E8' : {$pf = array( 155.906, 221.102); break;} - case 'E9' : {$pf = array( 110.551, 155.906); break;} - case 'E10': {$pf = array( 76.535, 110.551); break;} - case 'E11': {$pf = array( 53.858, 76.535); break;} - case 'E12': {$pf = array( 36.850, 53.858); break;} - // SIS 014711 G Series - case 'G0' : {$pf = array( 2715.591, 3838.110); break;} - case 'G1' : {$pf = array( 1919.055, 2715.591); break;} - case 'G2' : {$pf = array( 1357.795, 1919.055); break;} - case 'G3' : {$pf = array( 958.110, 1357.795); break;} - case 'G4' : {$pf = array( 677.480, 958.110); break;} - case 'G5' : {$pf = array( 479.055, 677.480); break;} - case 'G6' : {$pf = array( 337.323, 479.055); break;} - case 'G7' : {$pf = array( 238.110, 337.323); break;} - case 'G8' : {$pf = array( 167.244, 238.110); break;} - case 'G9' : {$pf = array( 119.055, 167.244); break;} - case 'G10': {$pf = array( 82.205, 119.055); break;} - case 'G11': {$pf = array( 59.528, 82.205); break;} - case 'G12': {$pf = array( 39.685, 59.528); break;} - // ISO Press - case 'RA0': {$pf = array( 2437.795, 3458.268); break;} - case 'RA1': {$pf = array( 1729.134, 2437.795); break;} - case 'RA2': {$pf = array( 1218.898, 1729.134); break;} - case 'RA3': {$pf = array( 864.567, 1218.898); break;} - case 'RA4': {$pf = array( 609.449, 864.567); break;} - case 'SRA0': {$pf = array( 2551.181, 3628.346); break;} - case 'SRA1': {$pf = array( 1814.173, 2551.181); break;} - case 'SRA2': {$pf = array( 1275.591, 1814.173); break;} - case 'SRA3': {$pf = array( 907.087, 1275.591); break;} - case 'SRA4': {$pf = array( 637.795, 907.087); break;} - // German DIN 476 - case '4A0': {$pf = array( 4767.874, 6740.787); break;} - case '2A0': {$pf = array( 3370.394, 4767.874); break;} - // Variations on the ISO Standard - case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;} - case 'A3+' : {$pf = array( 932.598, 1369.134); break;} - case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;} - case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;} - case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;} - case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;} - case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;} - case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;} - case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;} - case 'F4' : {$pf = array( 595.276, 935.433); break;} - case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;} - case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;} - // ANSI Series - case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;} - case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;} - case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;} - case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;} - case 'ANSI_A': {$pf = array( 612.000, 792.000); break;} - // Traditional 'Loose' North American Paper Sizes - case 'USLEDGER': - case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;} - case 'ORGANIZERK': - case 'BIBLE': - case 'USTABLOID': - case 'TABLOID': {$pf = array( 792.000, 1224.000); break;} - case 'ORGANIZERM': - case 'USLETTER': - case 'LETTER' : {$pf = array( 612.000, 792.000); break;} - case 'USLEGAL': - case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;} - case 'GOVERNMENTLETTER': - case 'GLETTER': {$pf = array( 576.000, 756.000); break;} - case 'JUNIORLEGAL': - case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;} - // Other North American Paper Sizes - case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;} - case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;} - case 'QUARTO': {$pf = array( 648.000, 792.000); break;} - case 'GOVERNMENTLEGAL': - case 'FOLIO': {$pf = array( 612.000, 936.000); break;} - case 'MONARCH': - case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;} - case 'ORGANIZERL': - case 'STATEMENT': - case 'MEMO': {$pf = array( 396.000, 612.000); break;} - case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;} - case 'COMPACT': {$pf = array( 306.000, 486.000); break;} - case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;} - // Canadian standard CAN 2-9.60M - case 'P1': {$pf = array( 1587.402, 2437.795); break;} - case 'P2': {$pf = array( 1218.898, 1587.402); break;} - case 'P3': {$pf = array( 793.701, 1218.898); break;} - case 'P4': {$pf = array( 609.449, 793.701); break;} - case 'P5': {$pf = array( 396.850, 609.449); break;} - case 'P6': {$pf = array( 303.307, 396.850); break;} - // North American Architectural Sizes - case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;} - case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;} - case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;} - case 'BROADSHEET': - case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;} - case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;} - case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;} - // --- North American Envelope Sizes --- - // - Announcement Envelopes - case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;} - case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;} - case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;} - case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;} - case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;} - case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;} - // - Commercial Envelopes - case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;} - case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;} - case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;} - case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;} - case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;} - case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;} - case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;} - case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;} - // - Catalogue Envelopes - case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;} - case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;} - case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;} - case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;} - case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;} - case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;} - case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;} - case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;} - case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;} - case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;} - case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;} - case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;} - case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;} - case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;} - // Japanese (JIS P 0138-61) Standard B-Series - case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;} - case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;} - case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;} - case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;} - case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;} - case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;} - case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;} - case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;} - case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;} - case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;} - case 'JIS_B10': {$pf = array( 90.709, 127.559); break;} - case 'JIS_B11': {$pf = array( 62.362, 90.709); break;} - case 'JIS_B12': {$pf = array( 45.354, 62.362); break;} - // PA Series - case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;} - case 'PA1' : {$pf = array( 1587.402, 2381.102); break;} - case 'PA2' : {$pf = array( 1190.551, 1587.402); break;} - case 'PA3' : {$pf = array( 793.701, 1190.551); break;} - case 'PA4' : {$pf = array( 595.276, 793.701); break;} - case 'PA5' : {$pf = array( 396.850, 595.276); break;} - case 'PA6' : {$pf = array( 297.638, 396.850); break;} - case 'PA7' : {$pf = array( 198.425, 297.638); break;} - case 'PA8' : {$pf = array( 147.402, 198.425); break;} - case 'PA9' : {$pf = array( 99.213, 147.402); break;} - case 'PA10': {$pf = array( 73.701, 99.213); break;} - // Standard Photographic Print Sizes - case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;} - case 'E' : {$pf = array( 233.858, 340.157); break;} - case 'L': - case '3R' : {$pf = array( 252.283, 360.000); break;} - case 'KG': - case '4R' : {$pf = array( 289.134, 430.866); break;} - case '4D' : {$pf = array( 340.157, 430.866); break;} - case '2L': - case '5R' : {$pf = array( 360.000, 504.567); break;} - case '8P': - case '6R' : {$pf = array( 430.866, 575.433); break;} - case '6P': - case '8R' : {$pf = array( 575.433, 720.000); break;} - case '6PW': - case 'S8R' : {$pf = array( 575.433, 864.567); break;} - case '4P': - case '10R' : {$pf = array( 720.000, 864.567); break;} - case '4PW': - case 'S10R': {$pf = array( 720.000, 1080.000); break;} - case '11R' : {$pf = array( 790.866, 1009.134); break;} - case 'S11R': {$pf = array( 790.866, 1224.567); break;} - case '12R' : {$pf = array( 864.567, 1080.000); break;} - case 'S12R': {$pf = array( 864.567, 1292.598); break;} - // Common Newspaper Sizes - case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;} - case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;} - case 'NEWSPAPER_TABLOID': - case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;} - // Business Cards - case 'CREDIT_CARD': - case 'BUSINESS_CARD': - case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;} - case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;} - case 'BUSINESS_CARD_IT': - case 'BUSINESS_CARD_UK': - case 'BUSINESS_CARD_FR': - case 'BUSINESS_CARD_DE': - case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;} - case 'BUSINESS_CARD_CA': - case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;} - case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;} - case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;} - case 'BUSINESS_CARD_AU': - case 'BUSINESS_CARD_DK': - case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;} - case 'BUSINESS_CARD_RU': - case 'BUSINESS_CARD_CZ': - case 'BUSINESS_CARD_FI': - case 'BUSINESS_CARD_HU': - case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;} - // Billboards - case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;} - case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;} - case '12SHEET': {$pf = array( 8640.000, 4320.000); break;} - case '16SHEET': {$pf = array( 5760.000, 8640.000); break;} - case '32SHEET': {$pf = array(11520.000, 8640.000); break;} - case '48SHEET': {$pf = array(17280.000, 8640.000); break;} - case '64SHEET': {$pf = array(23040.000, 8640.000); break;} - case '96SHEET': {$pf = array(34560.000, 8640.000); break;} - // Old European Sizes - // - Old Imperial English Sizes - case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;} - case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;} - case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;} - case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;} - case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;} - case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;} - case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;} - case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;} - case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;} - case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;} - case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;} - case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;} - case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;} - case 'EN_SHEET': - case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;} - case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;} - case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;} - case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;} - case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;} - case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;} - case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;} - case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;} - case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;} - case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;} - case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;} - case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;} - case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;} - case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;} - // - Old Imperial Belgian Sizes - case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;} - case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;} - case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;} - case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;} - case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;} - case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;} - case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;} - case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;} - case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;} - case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;} - case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;} - case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;} - case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;} - case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;} - case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;} - case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;} - case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;} - // - Old Imperial French Sizes - case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;} - case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;} - case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;} - case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;} - case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;} - case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;} - case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;} - case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;} - case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;} - case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;} - case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;} - case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;} - case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;} - case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;} - case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;} - case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;} - case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;} - case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;} - case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;} - case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;} - case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;} - case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;} - case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;} - case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;} - case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;} - case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;} - case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;} - case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;} - // DEFAULT ISO A4 - default: {$pf = array( 595.276, 841.890); break;} - } - return $pf; - } - /** * Change the format of the current page - * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numners (width, height) or an array containing the following measures and options:
      + * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numbers (width, height) or an array containing the following measures and options:
        *
      • ['format'] = page format name (one of the above);
      • *
      • ['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
      • *
      • ['PZ'] : The page's preferred zoom (magnification) factor.
      • *
      • ['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:
      • - *
      • ['MediaBox']['llx'] : lower-left x coordinate in points
      • - *
      • ['MediaBox']['lly'] : lower-left y coordinate in points
      • - *
      • ['MediaBox']['urx'] : upper-right x coordinate in points
      • - *
      • ['MediaBox']['ury'] : upper-right y coordinate in points
      • + *
      • ['MediaBox']['llx'] : lower-left x coordinate
      • + *
      • ['MediaBox']['lly'] : lower-left y coordinate
      • + *
      • ['MediaBox']['urx'] : upper-right x coordinate
      • + *
      • ['MediaBox']['ury'] : upper-right y coordinate
      • *
      • ['CropBox'] : the visible region of default user space:
      • - *
      • ['CropBox']['llx'] : lower-left x coordinate in points
      • - *
      • ['CropBox']['lly'] : lower-left y coordinate in points
      • - *
      • ['CropBox']['urx'] : upper-right x coordinate in points
      • - *
      • ['CropBox']['ury'] : upper-right y coordinate in points
      • + *
      • ['CropBox']['llx'] : lower-left x coordinate
      • + *
      • ['CropBox']['lly'] : lower-left y coordinate
      • + *
      • ['CropBox']['urx'] : upper-right x coordinate
      • + *
      • ['CropBox']['ury'] : upper-right y coordinate
      • *
      • ['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:
      • - *
      • ['BleedBox']['llx'] : lower-left x coordinate in points
      • - *
      • ['BleedBox']['lly'] : lower-left y coordinate in points
      • - *
      • ['BleedBox']['urx'] : upper-right x coordinate in points
      • - *
      • ['BleedBox']['ury'] : upper-right y coordinate in points
      • + *
      • ['BleedBox']['llx'] : lower-left x coordinate
      • + *
      • ['BleedBox']['lly'] : lower-left y coordinate
      • + *
      • ['BleedBox']['urx'] : upper-right x coordinate
      • + *
      • ['BleedBox']['ury'] : upper-right y coordinate
      • *
      • ['TrimBox'] : the intended dimensions of the finished page after trimming:
      • - *
      • ['TrimBox']['llx'] : lower-left x coordinate in points
      • - *
      • ['TrimBox']['lly'] : lower-left y coordinate in points
      • - *
      • ['TrimBox']['urx'] : upper-right x coordinate in points
      • - *
      • ['TrimBox']['ury'] : upper-right y coordinate in points
      • + *
      • ['TrimBox']['llx'] : lower-left x coordinate
      • + *
      • ['TrimBox']['lly'] : lower-left y coordinate
      • + *
      • ['TrimBox']['urx'] : upper-right x coordinate
      • + *
      • ['TrimBox']['ury'] : upper-right y coordinate
      • *
      • ['ArtBox'] : the extent of the page's meaningful content:
      • - *
      • ['ArtBox']['llx'] : lower-left x coordinate in points
      • - *
      • ['ArtBox']['lly'] : lower-left y coordinate in points
      • - *
      • ['ArtBox']['urx'] : upper-right x coordinate in points
      • - *
      • ['ArtBox']['ury'] : upper-right y coordinate in points
      • + *
      • ['ArtBox']['llx'] : lower-left x coordinate
      • + *
      • ['ArtBox']['lly'] : lower-left y coordinate
      • + *
      • ['ArtBox']['urx'] : upper-right x coordinate
      • + *
      • ['ArtBox']['ury'] : upper-right y coordinate
      • *
      • ['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:
      • *
      • ['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.
      • *
      • ['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units
      • @@ -2894,56 +2121,56 @@ class TCPDF { * @see getPageSizeFromFormat() */ protected function setPageFormat($format, $orientation='P') { - if (!empty($format) and isset($this->pagedim[$this->page])) { + if (!empty($format) AND isset($this->pagedim[$this->page])) { // remove inherited values unset($this->pagedim[$this->page]); } if (is_string($format)) { // get page measures from format name - $pf = $this->getPageSizeFromFormat($format); + $pf = TCPDF_STATIC::getPageSizeFromFormat($format); $this->fwPt = $pf[0]; $this->fhPt = $pf[1]; } else { // the boundaries of the physical medium on which the page shall be displayed or printed if (isset($format['MediaBox'])) { - $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false, $this->k, $this->pagedim); $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k); $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k); } else { - if (isset($format[0]) and is_numeric($format[0]) and isset($format[1]) and is_numeric($format[1])) { + if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) { $pf = array(($format[0] * $this->k), ($format[1] * $this->k)); } else { if (!isset($format['format'])) { // default value $format['format'] = 'A4'; } - $pf = $this->getPageSizeFromFormat($format['format']); + $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']); } $this->fwPt = $pf[0]; $this->fhPt = $pf[1]; - $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim); } // the visible region of default user space if (isset($format['CropBox'])) { - $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false, $this->k, $this->pagedim); } // the region to which the contents of the page shall be clipped when output in a production environment if (isset($format['BleedBox'])) { - $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false, $this->k, $this->pagedim); } // the intended dimensions of the finished page after trimming if (isset($format['TrimBox'])) { - $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false, $this->k, $this->pagedim); } // the page's meaningful content (including potential white space) if (isset($format['ArtBox'])) { - $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false, $this->k, $this->pagedim); } // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries if (isset($format['BoxColorInfo'])) { $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo']; } - if (isset($format['Rotate']) and (($format['Rotate'] % 90) == 0)) { + if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) { // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']); } @@ -2958,31 +2185,31 @@ class TCPDF { $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']); } $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade'); - if (isset($format['trans']['S']) and in_array($format['trans']['S'], $stansition_styles)) { + if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) { // The transition style that shall be used when moving to this page from another during a presentation $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S']; $valid_effect = array('Split', 'Blinds'); $valid_vals = array('H', 'V'); - if (isset($format['trans']['Dm']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['Dm'], $valid_vals)) { + if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) { $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm']; } $valid_effect = array('Split', 'Box', 'Fly'); $valid_vals = array('I', 'O'); - if (isset($format['trans']['M']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['M'], $valid_vals)) { + if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) { $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M']; } $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push'); - if (isset($format['trans']['Di']) and in_array($format['trans']['S'], $valid_effect)) { - if (((($format['trans']['Di'] == 90) or ($format['trans']['Di'] == 180)) and ($format['trans']['S'] == 'Wipe')) - or (($format['trans']['Di'] == 315) and ($format['trans']['S'] == 'Glitter')) - or (($format['trans']['Di'] == 0) or ($format['trans']['Di'] == 270))) { + if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) { + if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe')) + OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter')) + OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) { $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']); } } - if (isset($format['trans']['SS']) and ($format['trans']['S'] == 'Fly')) { + if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) { $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']); } - if (isset($format['trans']['B']) and ($format['trans']['B'] === true) and ($format['trans']['S'] == 'Fly')) { + if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) { $this->pagedim[$this->page]['trans']['B'] = 'true'; } } else { @@ -2999,59 +2226,6 @@ class TCPDF { $this->setPageOrientation($orientation); } - /** - * Set page boundaries. - * @param $page (int) page number - * @param $type (string) valid values are:
        • 'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;
        • 'CropBox' : the visible region of default user space;
        • 'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;
        • 'TrimBox' : the intended dimensions of the finished page after trimming;
        • 'ArtBox' : the page's meaningful content (including potential white space).
        - * @param $llx (float) lower-left x coordinate in user units - * @param $lly (float) lower-left y coordinate in user units - * @param $urx (float) upper-right x coordinate in user units - * @param $ury (float) upper-right y coordinate in user units - * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points - * @public - * @since 5.0.010 (2010-05-17) - */ - public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) { - if (!isset($this->pagedim[$page])) { - // initialize array - $this->pagedim[$page] = array(); - } - $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); - if (!in_array($type, $pageboxes)) { - return; - } - if ($points) { - $k = 1; - } else { - $k = $this->k; - } - $this->pagedim[$page][$type]['llx'] = ($llx * $k); - $this->pagedim[$page][$type]['lly'] = ($lly * $k); - $this->pagedim[$page][$type]['urx'] = ($urx * $k); - $this->pagedim[$page][$type]['ury'] = ($ury * $k); - } - - /** - * Swap X and Y coordinates of page boxes (change page boxes orientation). - * @param $page (int) page number - * @protected - * @since 5.0.010 (2010-05-17) - */ - protected function swapPageBoxCoordinates($page) { - $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); - foreach ($pageboxes as $type) { - // swap X and Y coordinates - if (isset($this->pagedim[$page][$type])) { - $tmp = $this->pagedim[$page][$type]['llx']; - $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly']; - $this->pagedim[$page][$type]['lly'] = $tmp; - $tmp = $this->pagedim[$page][$type]['urx']; - $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury']; - $this->pagedim[$page][$type]['ury'] = $tmp; - } - } - } - /** * Set page orientation. * @param $orientation (string) page orientation. Possible values are (case insensitive):
        • P or Portrait (default)
        • L or Landscape
        • '' (empty string) for automatic orientation
        @@ -3063,23 +2237,23 @@ class TCPDF { public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') { if (!isset($this->pagedim[$this->page]['MediaBox'])) { // the boundaries of the physical medium on which the page shall be displayed or printed - $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim); } if (!isset($this->pagedim[$this->page]['CropBox'])) { // the visible region of default user space - $this->setPageBoxes($this->page, 'CropBox', $this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'CropBox', $this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true, $this->k, $this->pagedim); } if (!isset($this->pagedim[$this->page]['BleedBox'])) { // the region to which the contents of the page shall be clipped when output in a production environment - $this->setPageBoxes($this->page, 'BleedBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'BleedBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true, $this->k, $this->pagedim); } if (!isset($this->pagedim[$this->page]['TrimBox'])) { // the intended dimensions of the finished page after trimming - $this->setPageBoxes($this->page, 'TrimBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'TrimBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true, $this->k, $this->pagedim); } if (!isset($this->pagedim[$this->page]['ArtBox'])) { // the page's meaningful content (including potential white space) - $this->setPageBoxes($this->page, 'ArtBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true); + $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'ArtBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true, $this->k, $this->pagedim); } if (!isset($this->pagedim[$this->page]['Rotate'])) { // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. @@ -3100,9 +2274,9 @@ class TCPDF { if (empty($orientation)) { $orientation = $default_orientation; } else { - $orientation = strtoupper($orientation{0}); + $orientation = strtoupper($orientation[0]); } - if (in_array($orientation, $valid_orientations) and ($orientation != $default_orientation)) { + if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) { $this->CurOrientation = $orientation; $this->wPt = $this->fhPt; $this->hPt = $this->fwPt; @@ -3111,20 +2285,20 @@ class TCPDF { $this->wPt = $this->fwPt; $this->hPt = $this->fhPt; } - if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) and (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){ + if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){ // swap X and Y coordinates (change page orientation) - $this->swapPageBoxCoordinates($this->page); + $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim); } $this->w = ($this->wPt / $this->k); $this->h = ($this->hPt / $this->k); - if ($this->empty_string($autopagebreak)) { + if (TCPDF_STATIC::empty_string($autopagebreak)) { if (isset($this->AutoPageBreak)) { $autopagebreak = $this->AutoPageBreak; } else { $autopagebreak = true; } } - if ($this->empty_string($bottommargin)) { + if (TCPDF_STATIC::empty_string($bottommargin)) { if (isset($this->bMargin)) { $bottommargin = $this->bMargin; } else { @@ -3154,12 +2328,13 @@ class TCPDF { * Some example patterns are: *
         	 * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
        -	 * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
        -	 * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
        +	 * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
        +	 * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
         	 * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
        -	 * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
        -	 * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
        -	 * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
        +	 *      \s     : any whitespace character
        +	 *      \p{Z}  : any separator
        +	 *      \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
        +	 *      \xa0   : Unicode Character 'NO-BREAK SPACE' (U+00A0)
         	 * 
        * @param $re (string) regular expression (leave empty for default). * @public @@ -3170,13 +2345,13 @@ class TCPDF { $re_parts = explode('/', $re); // get pattern parts $this->re_space = array(); - if (isset($re_parts[1]) and !empty($re_parts[1])) { + if (isset($re_parts[1]) AND !empty($re_parts[1])) { $this->re_space['p'] = $re_parts[1]; } else { $this->re_space['p'] = '[\s]'; } // set pattern modifiers - if (isset($re_parts[2]) and !empty($re_parts[2])) { + if (isset($re_parts[2]) AND !empty($re_parts[2])) { $this->re_space['m'] = $re_parts[2]; } else { $this->re_space['m'] = ''; @@ -3192,7 +2367,7 @@ class TCPDF { */ public function setRTL($enable, $resetx=true) { $enable = $enable ? true : false; - $resetx = ($resetx and ($enable != $this->rtl)); + $resetx = ($resetx AND ($enable != $this->rtl)); $this->rtl = $enable; $this->tmprtl = false; if ($resetx) { @@ -3249,7 +2424,7 @@ class TCPDF { * @since 4.8.014 (2009-11-04) */ public function isRTLTextDir() { - return ($this->rtl or ($this->tmprtl == 'R')); + return ($this->rtl OR ($this->tmprtl == 'R')); } /** @@ -3263,13 +2438,27 @@ class TCPDF { $this->lasth = $h; } + /** + * Return the cell height + * @param $fontsize (int) Font size in internal units + * @param $padding (boolean) If true add cell padding + * @public + */ + public function getCellHeight($fontsize, $padding=TRUE) { + $height = ($fontsize * $this->cell_height_ratio); + if ($padding) { + $height += ($this->cell_padding['T'] + $this->cell_padding['B']); + } + return round($height, 6); + } + /** * Reset the last cell height. * @public * @since 5.9.000 (2010-10-03) */ public function resetLastH() { - $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']; + $this->lasth = $this->getCellHeight($this->FontSize); } /** @@ -3414,7 +2603,7 @@ class TCPDF { public function SetLeftMargin($margin) { //Set left margin $this->lMargin = $margin; - if (($this->page > 0) and ($this->x < $margin)) { + if (($this->page > 0) AND ($this->x < $margin)) { $this->x = $margin; } } @@ -3429,7 +2618,7 @@ class TCPDF { public function SetTopMargin($margin) { //Set top margin $this->tMargin = $margin; - if (($this->page > 0) and ($this->y < $margin)) { + if (($this->page > 0) AND ($this->y < $margin)) { $this->y = $margin; } } @@ -3443,7 +2632,7 @@ class TCPDF { */ public function SetRightMargin($margin) { $this->rMargin = $margin; - if (($this->page > 0) and ($this->x > ($this->w - $margin))) { + if (($this->page > 0) AND ($this->x > ($this->w - $margin))) { $this->x = $this->w - $margin; } } @@ -3475,16 +2664,16 @@ class TCPDF { * @see getCellPaddings(), SetCellPadding() */ public function setCellPaddings($left='', $top='', $right='', $bottom='') { - if (($left !== '') and ($left >= 0)) { + if (($left !== '') AND ($left >= 0)) { $this->cell_padding['L'] = $left; } - if (($top !== '') and ($top >= 0)) { + if (($top !== '') AND ($top >= 0)) { $this->cell_padding['T'] = $top; } - if (($right !== '') and ($right >= 0)) { + if (($right !== '') AND ($right >= 0)) { $this->cell_padding['R'] = $right; } - if (($bottom !== '') and ($bottom >= 0)) { + if (($bottom !== '') AND ($bottom >= 0)) { $this->cell_padding['B'] = $bottom; } } @@ -3511,16 +2700,16 @@ class TCPDF { * @see getCellMargins() */ public function setCellMargins($left='', $top='', $right='', $bottom='') { - if (($left !== '') and ($left >= 0)) { + if (($left !== '') AND ($left >= 0)) { $this->cell_margin['L'] = $left; } - if (($top !== '') and ($top >= 0)) { + if (($top !== '') AND ($top >= 0)) { $this->cell_margin['T'] = $top; } - if (($right !== '') and ($right >= 0)) { + if (($right !== '') AND ($right >= 0)) { $this->cell_margin['R'] = $right; } - if (($bottom !== '') and ($bottom >= 0)) { + if (($bottom !== '') AND ($bottom >= 0)) { $this->cell_margin['B'] = $bottom; } } @@ -3555,7 +2744,7 @@ class TCPDF { $newbrd[$brd[$i]] = true; } $brd = $newbrd; - } elseif (($brd === 1) or ($brd === true) or (is_numeric($brd) and (intval($brd) > 0))) { + } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) { $brd = array('LRTB' => true); } if (!is_array($brd)) { @@ -3573,7 +2762,7 @@ class TCPDF { // process borders foreach ($brd as $border => $style) { $line_width = $this->LineWidth; - if (is_array($style) and isset($style['width'])) { + if (is_array($style) AND isset($style['width'])) { // get border width $line_width = $style['width']; } @@ -3594,16 +2783,16 @@ class TCPDF { } } // correct internal cell padding if required to avoid overlap between text and lines - if ((strpos($border,'T') !== false) and ($this->cell_padding['T'] < $adj)) { + if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) { $this->cell_padding['T'] = $adj; } - if ((strpos($border,'R') !== false) and ($this->cell_padding['R'] < $adj)) { + if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) { $this->cell_padding['R'] = $adj; } - if ((strpos($border,'B') !== false) and ($this->cell_padding['B'] < $adj)) { + if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) { $this->cell_padding['B'] = $adj; } - if ((strpos($border,'L') !== false) and ($this->cell_padding['L'] < $adj)) { + if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) { $this->cell_padding['L'] = $adj; } } @@ -3643,73 +2832,13 @@ class TCPDF { * @since 1.2 */ public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') { - if (($zoom == 'fullpage') or ($zoom == 'fullwidth') or ($zoom == 'real') or ($zoom == 'default') or (!is_string($zoom))) { + if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) { $this->ZoomMode = $zoom; } else { $this->Error('Incorrect zoom display mode: '.$zoom); } - switch ($layout) { - case 'default': - case 'single': - case 'SinglePage': { - $this->LayoutMode = 'SinglePage'; - break; - } - case 'continuous': - case 'OneColumn': { - $this->LayoutMode = 'OneColumn'; - break; - } - case 'two': - case 'TwoColumnLeft': { - $this->LayoutMode = 'TwoColumnLeft'; - break; - } - case 'TwoColumnRight': { - $this->LayoutMode = 'TwoColumnRight'; - break; - } - case 'TwoPageLeft': { - $this->LayoutMode = 'TwoPageLeft'; - break; - } - case 'TwoPageRight': { - $this->LayoutMode = 'TwoPageRight'; - break; - } - default: { - $this->LayoutMode = 'SinglePage'; - } - } - switch ($mode) { - case 'UseNone': { - $this->PageMode = 'UseNone'; - break; - } - case 'UseOutlines': { - $this->PageMode = 'UseOutlines'; - break; - } - case 'UseThumbs': { - $this->PageMode = 'UseThumbs'; - break; - } - case 'FullScreen': { - $this->PageMode = 'FullScreen'; - break; - } - case 'UseOC': { - $this->PageMode = 'UseOC'; - break; - } - case '': { - $this->PageMode = 'UseAttachments'; - break; - } - default: { - $this->PageMode = 'UseNone'; - } - } + $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout); + $this->PageMode = TCPDF_STATIC::getPageMode($mode); } /** @@ -3720,10 +2849,13 @@ class TCPDF { * @since 1.4 */ public function SetCompression($compress=true) { + $this->compress = false; if (function_exists('gzcompress')) { - $this->compress = $compress ? true : false; - } else { - $this->compress = false; + if ($compress) { + if ( !$this->pdfa_mode) { + $this->compress = true; + } + } } } @@ -3804,8 +2936,7 @@ class TCPDF { } /** - * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid. - * 2004-06-11 :: Nicola Asuni : changed bold tag with strong + * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true. * @param $msg (string) The error message * @public * @since 1.0 @@ -3813,8 +2944,11 @@ class TCPDF { public function Error($msg) { // unset all class variables $this->_destroy(true); - // exit program and print error - die('TCPDF ERROR: '.$msg); + if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) { + die('TCPDF ERROR: '.$msg); + } else { + throw new Exception('TCPDF ERROR: '.$msg); + } } /** @@ -3854,14 +2988,14 @@ class TCPDF { $this->x = 0; $this->y = $this->h - (1 / $this->k); $this->lMargin = 0; - $this->_out('q'); + $this->_outSaveGraphicsState(); $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica'; $this->SetFont($font, '', 1); $this->setTextRenderingMode(0, false, false); $msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29"; $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67"; $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B'); - $this->_out('Q'); + $this->_outRestoreGraphicsState(); // restore graphic settings $this->setGraphicVars($gvars); } @@ -3882,10 +3016,10 @@ class TCPDF { * @see getPage(), lastpage(), getNumPages() */ public function setPage($pnum, $resetmargins=false) { - if (($pnum == $this->page) and ($this->state == 2)) { + if (($pnum == $this->page) AND ($this->state == 2)) { return; } - if (($pnum > 0) and ($pnum <= $this->numpages)) { + if (($pnum > 0) AND ($pnum <= $this->numpages)) { $this->state = 2; // save current graphic settings //$gvars = $this->getGraphicVars(); @@ -3993,10 +3127,10 @@ class TCPDF { // we are inside an XObject template return; } - if (!isset($this->original_lMargin) or $keepmargins) { + if (!isset($this->original_lMargin) OR $keepmargins) { $this->original_lMargin = $this->lMargin; } - if (!isset($this->original_rMargin) or $keepmargins) { + if (!isset($this->original_rMargin) OR $keepmargins) { $this->original_rMargin = $this->rMargin; } // terminate previous page @@ -4014,7 +3148,7 @@ class TCPDF { */ public function endPage($tocpage=false) { // check if page is already closed - if (($this->page == 0) or ($this->numpages > $this->page) or (!$this->pageopen[$this->page])) { + if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) { return; } // print page footer @@ -4048,22 +3182,22 @@ class TCPDF { // adjust outlines $tmpoutlines = $this->outlines; foreach ($tmpoutlines as $key => $outline) { - if ($outline['p'] > $this->numpages) { + if (!$outline['f'] AND ($outline['p'] > $this->numpages)) { $this->outlines[$key]['p'] = ($outline['p'] + 1); } } // adjust dests $tmpdests = $this->dests; foreach ($tmpdests as $key => $dest) { - if ($dest['p'] > $this->numpages) { + if (!$dest['f'] AND ($dest['p'] > $this->numpages)) { $this->dests[$key]['p'] = ($dest['p'] + 1); } } // adjust links $tmplinks = $this->links; foreach ($tmplinks as $key => $link) { - if ($link[0] > $this->numpages) { - $this->links[$key][0] = ($link[0] + 1); + if (!$link['f'] AND ($link['p'] > $this->numpages)) { + $this->links[$key]['p'] = ($link['p'] + 1); } } } @@ -4261,7 +3395,7 @@ class TCPDF { * @public */ public function resetHeaderTemplate() { - $this->header_xobjid = -1; + $this->header_xobjid = false; } /** @@ -4279,7 +3413,7 @@ class TCPDF { * @public */ public function Header() { - if ($this->header_xobjid < 0) { + if ($this->header_xobjid === false) { // start a new XObject Template $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin); $headerfont = $this->getHeaderFont(); @@ -4290,9 +3424,9 @@ class TCPDF { } else { $this->x = $this->original_lMargin; } - if (($headerdata['logo']) and ($headerdata['logo'] != K_BLANK_IMAGE)) { - $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); - if (($imgtype == 'eps') or ($imgtype == 'ai')) { + if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { + $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']); + if (($imgtype == 'eps') OR ($imgtype == 'ai')) { $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); } elseif ($imgtype == 'svg') { $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); @@ -4303,7 +3437,7 @@ class TCPDF { } else { $imgy = $this->y; } - $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2); + $cell_height = $this->getCellHeight($headerfont[2] / $this->k); // set starting margin for text data cell if ($this->getRTL()) { $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1); @@ -4334,7 +3468,7 @@ class TCPDF { // print header template $x = 0; $dx = 0; - if (!$this->header_xobj_autoreset and $this->booklet and (($this->page % 2) == 0)) { + if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) { // adjust margins for booklet mode $dx = ($this->original_lMargin - $this->original_rMargin); } @@ -4346,7 +3480,7 @@ class TCPDF { $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); if ($this->header_xobj_autoreset) { // reset header xobject template at each page - $this->header_xobjid = -1; + $this->header_xobjid = false; } } @@ -4380,10 +3514,11 @@ class TCPDF { ); $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, ''); } + $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : ''; if (empty($this->pagegroups)) { - $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); + $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); } else { - $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias(); + $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias(); } $this->SetY($cur_y); //Print page number @@ -4402,7 +3537,7 @@ class TCPDF { * @since 4.0.012 (2008-07-24) */ protected function setHeader() { - if (!$this->print_header) { + if (!$this->print_header OR ($this->state != 2)) { return; } $this->InHeader = true; @@ -4410,7 +3545,8 @@ class TCPDF { $temp_thead = $this->thead; $temp_theadMargins = $this->theadMargins; $lasth = $this->lasth; - $this->_out('q'); + $newline = $this->newline; + $this->_outSaveGraphicsState(); $this->rMargin = $this->original_rMargin; $this->lMargin = $this->original_lMargin; $this->SetCellPadding(0); @@ -4428,11 +3564,11 @@ class TCPDF { } else { $this->SetXY($this->original_lMargin, $this->tMargin); } - $this->_out('Q'); + $this->_outRestoreGraphicsState(); $this->lasth = $lasth; $this->thead = $temp_thead; $this->theadMargins = $temp_theadMargins; - $this->newline = false; + $this->newline = $newline; $this->InHeader = false; } @@ -4442,7 +3578,9 @@ class TCPDF { * @since 4.0.012 (2008-07-24) */ protected function setFooter() { - //Page footer + if ($this->state != 2) { + return; + } $this->InFooter = true; // save current graphic settings $gvars = $this->getGraphicVars(); @@ -4456,7 +3594,7 @@ class TCPDF { $temp_thead = $this->thead; $temp_theadMargins = $this->theadMargins; $lasth = $this->lasth; - $this->_out('q'); + $this->_outSaveGraphicsState(); $this->rMargin = $this->original_rMargin; $this->lMargin = $this->original_lMargin; $this->SetCellPadding(0); @@ -4475,7 +3613,7 @@ class TCPDF { } else { $this->SetXY($this->original_lMargin, $this->tMargin); } - $this->_out('Q'); + $this->_outRestoreGraphicsState(); $this->lasth = $lasth; $this->thead = $temp_thead; $this->theadMargins = $temp_theadMargins; @@ -4496,7 +3634,7 @@ class TCPDF { * @since 5.9.091 (2011-06-15) */ protected function inPageBody() { - return (($this->InHeader === false) and ($this->InFooter === false)); + return (($this->InHeader === false) AND ($this->InFooter === false)); } /** @@ -4515,7 +3653,7 @@ class TCPDF { $this->pagedim[$this->page]['tm'] = $this->tMargin; $this->y = $this->tMargin; } - if (!$this->empty_string($this->thead) and (!$this->inthead)) { + if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) { // set margins $prev_lMargin = $this->lMargin; $prev_rMargin = $this->rMargin; @@ -4536,8 +3674,16 @@ class TCPDF { $this->x += $this->cell_padding['L']; } } + $gvars = $this->getGraphicVars(); + if (!empty($this->theadMargins['gvars'])) { + // set the correct graphic style + $this->setGraphicVars($this->theadMargins['gvars']); + $this->rMargin = $gvars['rMargin']; + $this->lMargin = $gvars['lMargin']; + } // print table header $this->writeHTML($this->thead, false, false, false, false, ''); + $this->setGraphicVars($gvars); // set new top margin to skip the table headers if (!isset($this->theadMargins['top'])) { $this->theadMargins['top'] = $this->tMargin; @@ -4567,6 +3713,16 @@ class TCPDF { return $this->page; } + /** + * Returns the array of spot colors. + * @return (array) Spot colors array. + * @public + * @since 6.0.038 (2013-09-30) + */ + public function getAllSpotColors() { + return $this->spot_colors; + } + /** * Defines a new spot color. * It can be expressed in RGB components or gray scale. @@ -4587,26 +3743,6 @@ class TCPDF { } } - /** - * Return the Spot color array. - * @param $name (string) Name of the spot color. - * @return (array) Spot color array or false if not defined. - * @public - * @since 5.9.125 (2011-10-03) - */ - public function getSpotColor($name) { - if (isset($this->spot_colors[$name])) { - return $this->spot_colors[$name]; - } - $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces - $color = strtolower($color); - if (isset($this->spotcolor[$color])) { - $this->AddSpotColor($this->spotcolor[$color][4], $this->spotcolor[$color][0], $this->spotcolor[$color][1], $this->spotcolor[$color][2], $this->spotcolor[$color][3]); - return $this->spot_colors[$this->spotcolor[$color][4]]; - } - return false; - } - /** * Set the spot color for the specified type ('draw', 'fill', 'text'). * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text'). @@ -4617,9 +3753,9 @@ class TCPDF { * @since 5.9.125 (2011-10-03) */ public function setSpotColor($type, $name, $tint=100) { - $spotcolor = $this->getSpotColor($name); + $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors); if ($spotcolor === false) { - $this->Error('Undefined spot color: '.$name.', you must add it on the spotcolors.php file.'); + $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.'); } $tint = (max(0, min(100, $tint)) / 100); $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']); @@ -4644,7 +3780,7 @@ class TCPDF { } } $this->ColorFlag = ($this->FillColor != $this->TextColor); - if ($this->page > 0) { + if ($this->state == 2) { $this->_out($pdfcolor); } if ($this->inxobj) { @@ -4792,7 +3928,7 @@ class TCPDF { } // set color by case $suffix = ''; - if (($col2 == -1) and ($col3 == -1) and ($col4 == -1)) { + if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) { // Grey scale $col1 = max(0, min(255, $col1)); $intcolor = array('G' => $col1); @@ -4844,7 +3980,7 @@ class TCPDF { } } $this->ColorFlag = ($this->FillColor != $this->TextColor); - if (($type != 'text') and ($this->page > 0)) { + if (($type != 'text') AND ($this->state == 2)) { if (!$ret) { $this->_out($pdfcolor); } @@ -4853,37 +3989,6 @@ class TCPDF { return ''; } - /** - * Convert a color array into a string representation. - * @param $c (array) Array of colors. - * @return (string) The color array representation. - * @protected - * @since 5.9.137 (2011-12-01) - */ - protected function getColorStringFromArray($c) { - $c = array_values($c); - $color = '['; - switch (count($c)) { - case 4: { - // CMYK - $color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100)); - break; - } - case 3: { - // RGB - $color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255)); - break; - } - case 1: { - // grayscale - $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255)); - break; - } - } - $color .= ']'; - return $color; - } - /** * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100). @@ -4939,7 +4044,7 @@ class TCPDF { * Returns the length of a string in user unit. A font must be selected.
        * @param $s (string) The string whose length is to be computed * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained. - * @param $fontstyle (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line-trough
        • O: overline
        or any combination. The default value is regular. + * @param $fontstyle (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line-through
        • O: overline
        or any combination. The default value is regular. * @param $fontsize (float) Font size in points. The default value is the current size. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length. * @return mixed int total string length or array of characted widths @@ -4948,14 +4053,14 @@ class TCPDF { * @since 1.2 */ public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) { - return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray); + return $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont), $s, $this->tmprtl, $this->isunicode, $this->CurrentFont), $fontname, $fontstyle, $fontsize, $getarray); } /** * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.
        * @param $sa (string) The array of chars whose total length is to be computed * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained. - * @param $fontstyle (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line trough
        • O: overline
        or any combination. The default value is regular. + * @param $fontstyle (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line through
        • O: overline
        or any combination. The default value is regular. * @param $fontsize (float) Font size in points. The default value is the current size. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length. * @return mixed int total string length or array of characted widths @@ -4965,14 +4070,16 @@ class TCPDF { */ public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) { // store current values - if (!$this->empty_string($fontname)) { + if (!TCPDF_STATIC::empty_string($fontname)) { $prev_FontFamily = $this->FontFamily; $prev_FontStyle = $this->FontStyle; $prev_FontSizePt = $this->FontSizePt; $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false); } // convert UTF-8 array to Latin1 if required - $sa = $this->UTF8ArrToLatin1($sa); + if ($this->isunicode AND (!$this->isUnicodeFont())) { + $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa); + } $w = 0; // total width $wa = array(); // array of characters widths foreach ($sa as $ck => $char) { @@ -4982,7 +4089,7 @@ class TCPDF { $w += $cw; } // restore previous values - if (!$this->empty_string($fontname)) { + if (!TCPDF_STATIC::empty_string($fontname)) { $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false); } if ($getarray) { @@ -5003,7 +4110,7 @@ class TCPDF { public function GetCharWidth($char, $notlast=true) { // get raw width $chw = $this->getRawCharWidth($char); - if (($this->font_spacing < 0) or (($this->font_spacing > 0) and $notlast)) { + if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) { // increase/decrease font spacing $chw += $this->font_spacing; } @@ -5038,7 +4145,7 @@ class TCPDF { } else { $w = 600; } - return ($w * $this->FontSize / 1000); + return $this->getAbsFontMeasure($w); } /** @@ -5050,7 +4157,7 @@ class TCPDF { */ public function GetNumChars($s) { if ($this->isUnicodeFont()) { - return count($this->UTF8StringToArray($s)); + return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont)); } return strlen($s); } @@ -5061,13 +4168,14 @@ class TCPDF { * @since 4.0.013 (2008-07-28) */ protected function getFontsList() { - $fontsdir = opendir($this->_getfontpath()); - while (($file = readdir($fontsdir)) !== false) { - if (substr($file, -4) == '.php') { - array_push($this->fontlist, strtolower(basename($file, '.php'))); + if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) { + while (($file = readdir($fontsdir)) !== false) { + if (substr($file, -4) == '.php') { + array_push($this->fontlist, strtolower(basename($file, '.php'))); + } } + closedir($fontsdir); } - closedir($fontsdir); } /** @@ -5090,8 +4198,8 @@ class TCPDF { if ($this->pdfa_mode) { $subset = false; } - if ($this->empty_string($family)) { - if (!$this->empty_string($this->FontFamily)) { + if (TCPDF_STATIC::empty_string($family)) { + if (!TCPDF_STATIC::empty_string($this->FontFamily)) { $family = $this->FontFamily; } else { $this->Error('Empty font family'); @@ -5108,13 +4216,13 @@ class TCPDF { } // normalize family name $family = strtolower($family); - if ((!$this->isunicode) and ($family == 'arial')) { + if ((!$this->isunicode) AND ($family == 'arial')) { $family = 'helvetica'; } - if (($family == 'symbol') or ($family == 'zapfdingbats')) { + if (($family == 'symbol') OR ($family == 'zapfdingbats')) { $style = ''; } - if ($this->pdfa_mode and (isset($this->CoreFonts[$family]))) { + if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) { // all fonts must be embedded $family = 'pdfa'.$family; } @@ -5159,86 +4267,69 @@ class TCPDF { } return $fontdata; } - if (isset($type)) { - unset($type); - } - if (isset($cw)) { - unset($cw); - } // get specified font directory (if any) $fontdir = false; - if (!$this->empty_string($fontfile)) { + if (!TCPDF_STATIC::empty_string($fontfile)) { $fontdir = dirname($fontfile); - if ($this->empty_string($fontdir) or ($fontdir == '.')) { + if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) { $fontdir = ''; } else { $fontdir .= '/'; } } - $missing_style = false; // true when the font style variation is missing + // true when the font style variation is missing + $missing_style = false; // search and include font file - if ($this->empty_string($fontfile) or (!Tools::file_exists_no_cache($fontfile))) { + if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) { // build a standard filenames for specified font $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php'; - // search files on various directories - if (($fontdir !== false) and Tools::file_exists_no_cache($fontdir.$tmp_fontfile)) { - $fontfile = $fontdir.$tmp_fontfile; - } elseif (Tools::file_exists_no_cache($this->_getfontpath().$tmp_fontfile)) { - $fontfile = $this->_getfontpath().$tmp_fontfile; - } elseif (Tools::file_exists_no_cache($tmp_fontfile)) { - $fontfile = $tmp_fontfile; - } elseif (!$this->empty_string($style)) { + $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir); + if (TCPDF_STATIC::empty_string($fontfile)) { $missing_style = true; // try to remove the style part $tmp_fontfile = str_replace(' ', '', $family).'.php'; - if (($fontdir !== false) and Tools::file_exists_no_cache($fontdir.$tmp_fontfile)) { - $fontfile = $fontdir.$tmp_fontfile; - } elseif (Tools::file_exists_no_cache($this->_getfontpath().$tmp_fontfile)) { - $fontfile = $this->_getfontpath().$tmp_fontfile; - } else { - $fontfile = $tmp_fontfile; - } + $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir); } } // include font file - if (Tools::file_exists_no_cache($fontfile)) { + if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) { include($fontfile); } else { $this->Error('Could not include font definition file: '.$family.''); } // check font parameters - if ((!isset($type)) or (!isset($cw))) { + if ((!isset($type)) OR (!isset($cw))) { $this->Error('The font definition file has a bad format: '.$fontfile.''); } // SET default parameters - if (!isset($file) or $this->empty_string($file)) { + if (!isset($file) OR TCPDF_STATIC::empty_string($file)) { $file = ''; } - if (!isset($enc) or $this->empty_string($enc)) { + if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) { $enc = ''; } - if (!isset($cidinfo) or $this->empty_string($cidinfo)) { + if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) { $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0); $cidinfo['uni2cid'] = array(); } - if (!isset($ctg) or $this->empty_string($ctg)) { + if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) { $ctg = ''; } - if (!isset($desc) or $this->empty_string($desc)) { + if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) { $desc = array(); } - if (!isset($up) or $this->empty_string($up)) { + if (!isset($up) OR TCPDF_STATIC::empty_string($up)) { $up = -100; } - if (!isset($ut) or $this->empty_string($ut)) { + if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) { $ut = 50; } - if (!isset($cw) or $this->empty_string($cw)) { + if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) { $cw = array(); } - if (!isset($dw) or $this->empty_string($dw)) { + if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) { // set default width - if (isset($desc['MissingWidth']) and ($desc['MissingWidth'] > 0)) { + if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) { $dw = $desc['MissingWidth']; } elseif (isset($cw[32])) { $dw = $cw[32]; @@ -5250,7 +4341,7 @@ class TCPDF { if ($type == 'core') { $name = $this->CoreFonts[$fontkey]; $subset = false; - } elseif (($type == 'TrueType') or ($type == 'Type1')) { + } elseif (($type == 'TrueType') OR ($type == 'Type1')) { $subset = false; } elseif ($type == 'TrueTypeUnicode') { $enc = 'Identity-H'; @@ -5262,11 +4353,11 @@ class TCPDF { $this->Error('Unknow font type: '.$type.''); } // set name if unset - if (!isset($name) or empty($name)) { + if (!isset($name) OR empty($name)) { $name = $fontkey; } // create artificial font style variations if missing (only works with non-embedded fonts) - if (($type != 'core') and $missing_style) { + if (($type != 'core') AND $missing_style) { // style variations $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic'); $name .= $styles[$bistyle]; @@ -5294,14 +4385,18 @@ class TCPDF { } } } - // initialize subsetchars to contain default ASCII values (0-255) - $subsetchars = array_fill(0, 256, true); - $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars)); + // check if the array of characters bounding boxes is defined + if (!isset($cbbox)) { + $cbbox = array(); + } + // initialize subsetchars + $subsetchars = array_fill(0, 255, true); + $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars)); if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts; } - if (isset($diff) and (!empty($diff))) { + if (isset($diff) AND (!empty($diff))) { //Search existing encodings $d = 0; $nb = count($this->diffs); @@ -5317,16 +4412,16 @@ class TCPDF { } $this->setFontSubBuffer($fontkey, 'diff', $d); } - if (!$this->empty_string($file)) { + if (!TCPDF_STATIC::empty_string($file)) { if (!isset($this->FontFiles[$file])) { - if ((strcasecmp($type,'TrueType') == 0) or (strcasecmp($type, 'TrueTypeUnicode') == 0)) { + if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) { $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey)); } elseif ($type != 'core') { $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey)); } } else { // update fontkeys that are sharing this font file - $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] and $subset); + $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset); if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) { $this->FontFiles[$file]['fontkeys'][] = $fontkey; } @@ -5342,7 +4437,7 @@ class TCPDF { * If you just wish to change the current font size, it is simpler to call SetFontSize(). * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:
        • They are in the current directory (the one where the running script lies)
        • They are in one of the directories defined by the include_path parameter
        • They are in the directory defined by the K_PATH_FONTS constant

        * @param $family (string) Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):
        • times (Times-Roman)
        • timesb (Times-Bold)
        • timesi (Times-Italic)
        • timesbi (Times-BoldItalic)
        • helvetica (Helvetica)
        • helveticab (Helvetica-Bold)
        • helveticai (Helvetica-Oblique)
        • helveticabi (Helvetica-BoldOblique)
        • courier (Courier)
        • courierb (Courier-Bold)
        • courieri (Courier-Oblique)
        • courierbi (Courier-BoldOblique)
        • symbol (Symbol)
        • zapfdingbats (ZapfDingbats)
        It is also possible to pass an empty string. In that case, the current family is retained. - * @param $style (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line trough
        • O: overline
        or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined. + * @param $style (string) Font style. Possible values are (case insensitive):
        • empty string: regular
        • B: bold
        • I: italic
        • U: underline
        • D: line through
        • O: overline
        or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined. * @param $size (float) Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font. @@ -5364,6 +4459,10 @@ class TCPDF { $fontdata = $this->AddFont($family, $style, $fontfile, $subset); $this->FontFamily = $fontdata['family']; $this->FontStyle = $fontdata['style']; + if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) { + // save subset chars of the previous font + $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); + } $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']); $this->SetFontSize($size, $out); } @@ -5377,6 +4476,7 @@ class TCPDF { * @see SetFont() */ public function SetFontSize($size, $out=true) { + $size = (float)$size; // font size in points $this->FontSizePt = $size; // font size in user units @@ -5388,13 +4488,13 @@ class TCPDF { } else { $font_height = $size * 1.219; } - if (isset($this->CurrentFont['desc']['Ascent']) and ($this->CurrentFont['desc']['Ascent'] > 0)) { + if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) { $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000); } - if (isset($this->CurrentFont['desc']['Descent']) and ($this->CurrentFont['desc']['Descent'] <= 0)) { + if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) { $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000); } - if (!isset($font_ascent) and !isset($font_descent)) { + if (!isset($font_ascent) AND !isset($font_descent)) { // core font $font_ascent = 0.76 * $font_height; $font_descent = $font_height - $font_ascent; @@ -5405,7 +4505,7 @@ class TCPDF { } $this->FontAscent = ($font_ascent / $this->k); $this->FontDescent = ($font_descent / $this->k); - if ($out and ($this->page > 0) and (isset($this->CurrentFont['i']))) { + if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) { $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); } } @@ -5417,16 +4517,14 @@ class TCPDF { * @since 5.9.152 (2012-03-23) */ public function getFontBBox() { - $result = array(); + $fbbox = array(); if (isset($this->CurrentFont['desc']['FontBBox'])) { - $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1)); - foreach ($bbox as $v) { - $result[] = (intval($v) * $this->FontSize / 1000); - } + $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1)); + $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox); } else { // Find max width if (isset($this->CurrentFont['desc']['MaxWidth'])) { - $maxw = (intval($this->CurrentFont['desc']['MaxWidth']) * $this->FontSize / 1000); + $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth'])); } else { $maxw = 0; if (isset($this->CurrentFont['desc']['MissingWidth'])) { @@ -5444,11 +4542,40 @@ class TCPDF { if ($maxw == 0) { $maxw = 600; } - $maxw = ($maxw * $this->FontSize / 1000); + $maxw = $this->getAbsFontMeasure($maxw); } - $result = array(0, -$this->FontDescent, $maxw, $this->FontAscent); + $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent); } - return $result; + return $fbbox; + } + + /** + * Convert a relative font measure into absolute value. + * @param $s (int) Font measure. + * @return float Absolute measure. + * @since 5.9.186 (2012-09-13) + */ + public function getAbsFontMeasure($s) { + return ($s * $this->FontSize / 1000); + } + + /** + * Returns the glyph bounding box of the specified character in the current font in user units. + * @param $char (int) Input character code. + * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined. + * @since 5.9.186 (2012-09-13) + */ + public function getCharBBox($char) { + $c = intval($char); + if (isset($this->CurrentFont['cw'][$c])) { + // glyph is defined ... use zero width & height for glyphs without outlines + $result = array(0,0,0,0); + if (isset($this->CurrentFont['cbbox'][$c])) { + $result = $this->CurrentFont['cbbox'][$c]; + } + return array_map(array($this,'getAbsFontMeasure'), $result); + } + return false; } /** @@ -5464,10 +4591,10 @@ class TCPDF { public function getFontDescent($font, $style='', $size=0) { $fontdata = $this->AddFont($font, $style); $fontinfo = $this->getFontBuffer($fontdata['fontkey']); - if (isset($fontinfo['desc']['Descent']) and ($fontinfo['desc']['Descent'] <= 0)) { + if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) { $descent = (- $fontinfo['desc']['Descent'] * $size / 1000); } else { - $descent = 1.219 * 0.24 * $size; + $descent = (1.219 * 0.24 * $size); } return ($descent / $this->k); } @@ -5485,7 +4612,7 @@ class TCPDF { public function getFontAscent($font, $style='', $size=0) { $fontdata = $this->AddFont($font, $style); $fontinfo = $this->getFontBuffer($fontdata['fontkey']); - if (isset($fontinfo['desc']['Ascent']) and ($fontinfo['desc']['Ascent'] > 0)) { + if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) { $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000); } else { $ascent = 1.219 * 0.76 * $size; @@ -5505,11 +4632,11 @@ class TCPDF { public function isCharDefined($char, $font='', $style='') { if (is_string($char)) { // get character code - $char = $this->UTF8StringToArray($char); + $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont); $char = $char[0]; } - if ($this->empty_string($font)) { - if ($this->empty_string($style)) { + if (TCPDF_STATIC::empty_string($font)) { + if (TCPDF_STATIC::empty_string($style)) { return (isset($this->CurrentFont['cw'][intval($char)])); } $font = $this->FontFamily; @@ -5533,12 +4660,12 @@ class TCPDF { if (empty($subs)) { return $text; } - if ($this->empty_string($font)) { + if (TCPDF_STATIC::empty_string($font)) { $font = $this->FontFamily; } $fontdata = $this->AddFont($font, $style); $fontinfo = $this->getFontBuffer($fontdata['fontkey']); - $uniarr = $this->UTF8StringToArray($text); + $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont); foreach ($uniarr as $k => $chr) { if (!isset($fontinfo['cw'][$chr])) { // this character is missing on the selected font @@ -5557,7 +4684,7 @@ class TCPDF { } } } - return $this->UniArrSubString($this->UTF8ArrayToUniArray($uniarr)); + return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode)); } /** @@ -5578,9 +4705,9 @@ class TCPDF { * @see Cell(), Write(), Image(), Link(), SetLink() */ public function AddLink() { - //Create a new internal link + // create a new internal link $n = count($this->links) + 1; - $this->links[$n] = array(0, 0); + $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false); return $n; } @@ -5588,19 +4715,25 @@ class TCPDF { * Defines the page and position a link points to. * @param $link (int) The link identifier returned by AddLink() * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page) - * @param $page (int) Number of target page; -1 indicates the current page. This is the default value + * @param $page (int|string) Number of target page; -1 indicates the current page (default value). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages. * @public * @since 1.5 * @see AddLink() */ public function SetLink($link, $y=0, $page=-1) { + $fixed = false; + if (!empty($page) AND (substr($page, 0, 1) == '*')) { + $page = intval(substr($page, 1)); + // this page number will not be changed when moving/add/deleting pages + $fixed = true; + } + if ($page < 0) { + $page = $this->page; + } if ($y == -1) { $y = $this->y; } - if ($page == -1) { - $page = $this->page; - } - $this->links[$link] = array($page, $y); + $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed); } /** @@ -5648,7 +4781,7 @@ class TCPDF { // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); // recalculate coordinates to account for graphic transformations - if (isset($this->transfmatrix) and !empty($this->transfmatrix)) { + if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) { for ($i=$this->transfmatrix_key; $i > 0; --$i) { $maxid = count($this->transfmatrix[$i]) - 1; for ($j=$maxid; $j >= 0; --$j) { @@ -5697,22 +4830,22 @@ class TCPDF { if (!isset($this->PageAnnots[$page])) { $this->PageAnnots[$page] = array(); } - ++$this->n; - $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces); - if (!$this->pdfa_mode) { - if ((($opt['Subtype'] == 'FileAttachment') or ($opt['Subtype'] == 'Sound')) and (!$this->empty_string($opt['FS'])) and Tools::file_exists_no_cache($opt['FS']) and (!isset($this->embeddedfiles[basename($opt['FS'])]))) { - ++$this->n; - $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']); + $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces); + if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) { + if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS'])) + AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS'])) + AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) { + $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']); } } // Add widgets annotation's icons - if (isset($opt['mk']['i']) and Tools::file_exists_no_cache($opt['mk']['i'])) { + if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) { $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true); } - if (isset($opt['mk']['ri']) and Tools::file_exists_no_cache($opt['mk']['ri'])) { + if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) { $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true); } - if (isset($opt['mk']['ix']) and Tools::file_exists_no_cache($opt['mk']['ix'])) { + if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) { $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true); } } @@ -5724,24 +4857,45 @@ class TCPDF { * @see Annotation() */ protected function _putEmbeddedFiles() { - if ($this->pdfa_mode) { - // embedded files are not allowed in PDF/A mode + if ($this->pdfa_mode && $this->pdfa_version != 3) { + // embedded files are not allowed in PDF/A mode version 1 and 2 return; } reset($this->embeddedfiles); foreach ($this->embeddedfiles as $filename => $filedata) { - $data = file_get_contents($filedata['file']); - $filter = ''; - if ($this->compress) { - $data = gzcompress($data); - $filter = ' /Filter /FlateDecode'; + $data = TCPDF_STATIC::fileGetContents($filedata['file']); + if ($data !== FALSE) { + $rawsize = strlen($data); + if ($rawsize > 0) { + // update name tree + $this->efnames[$filename] = $filedata['f'].' 0 R'; + // embedded file specification object + $out = $this->_getobj($filedata['f'])."\n"; + $out .= '<_datastring($filename, $filedata['f']); + $out .= ' /UF '.$this->_datastring($filename, $filedata['f']); + $out .= ' /AFRelationship /Source'; + $out .= ' /EF <> >>'; + $out .= "\n".'endobj'; + $this->_out($out); + // embedded file object + $filter = ''; + if ($this->compress) { + $data = gzcompress($data); + $filter = ' /Filter /FlateDecode'; + } + + if ($this->pdfa_version == 3) { + $filter = ' /Subtype /text#2Fxml'; + } + + $stream = $this->_getrawstream($data, $filedata['n']); + $out = $this->_getobj($filedata['n'])."\n"; + $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <> >>'; + $out .= ' stream'."\n".$stream."\n".'endstream'; + $out .= "\n".'endobj'; + $this->_out($out); + } } - $stream = $this->_getrawstream($data, $filedata['n']); - $out = $this->_getobj($filedata['n'])."\n"; - $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>'; - $out .= ' stream'."\n".$stream."\n".'endstream'; - $out .= "\n".'endobj'; - $this->_out($out); } } @@ -5816,11 +4970,11 @@ class TCPDF { * @protected */ protected function checkPageBreak($h=0, $y='', $addpage=true) { - if ($this->empty_string($y)) { + if (TCPDF_STATIC::empty_string($y)) { $y = $this->y; } $current_page = $this->page; - if ((($y + $h) > $this->PageBreakTrigger) and ($this->inPageBody()) and ($this->AcceptPageBreak())) { + if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) { if ($addpage) { //Automatic page break $x = $this->x; @@ -5850,30 +5004,6 @@ class TCPDF { return false; } - /** - * Removes SHY characters from text. - * Unicode Data:
          - *
        • Name : SOFT HYPHEN, commonly abbreviated as SHY
        • - *
        • HTML Entity (decimal): "&#173;"
        • - *
        • HTML Entity (hex): "&#xad;"
        • - *
        • HTML Entity (named): "&shy;"
        • - *
        • How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
        • - *
        • UTF-8 (hex): 0xC2 0xAD (c2ad)
        • - *
        • UTF-8 character: chr(194).chr(173)
        • - *
        - * @param $txt (string) input string - * @return string without SHY characters. - * @public - * @since (4.5.019) 2009-02-28 - */ - public function removeSHY($txt='') { - $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); - if (!$this->isunicode) { - $txt = preg_replace('/([\\xad]{1})/', '', $txt); - } - return $txt; - } - /** * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.
        * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. @@ -5898,7 +5028,7 @@ class TCPDF { $prev_cell_padding = $this->cell_padding; $this->adjustCellPadding($border); if (!$ignore_min_height) { - $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']; + $min_cell_height = $this->getCellHeight($this->FontSize); if ($h < $min_cell_height) { $h = $min_cell_height; } @@ -5922,7 +5052,9 @@ class TCPDF { if ($this->txtshadow['opacity'] != $alpha['CA']) { $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']); } - $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign)); + if ($this->state == 2) { + $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign)); + } //restore data $this->x = $x; $this->y = $y; @@ -5933,7 +5065,9 @@ class TCPDF { $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']); } } - $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign)); + if ($this->state == 2) { + $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign)); + } $this->cell_padding = $prev_cell_padding; $this->cell_margin = $prev_cell_margin; } @@ -5960,14 +5094,14 @@ class TCPDF { */ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') { // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space - $txt = str_replace($this->unichr(160), ' ', $txt); + $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt); $prev_cell_margin = $this->cell_margin; $prev_cell_padding = $this->cell_padding; - $txt = $this->removeSHY($txt); + $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode); $rs = ''; //string to be returned $this->adjustCellPadding($border); if (!$ignore_min_height) { - $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']; + $min_cell_height = $this->getCellHeight($this->FontSize); if ($h < $min_cell_height) { $h = $min_cell_height; } @@ -6092,7 +5226,7 @@ class TCPDF { } } $basefonty = $yt + $this->FontAscent; - if ($this->empty_string($w) or ($w <= 0)) { + if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) { if ($this->rtl) { $w = $x - $this->lMargin; } else { @@ -6101,11 +5235,11 @@ class TCPDF { } $s = ''; // fill and borders - if (is_string($border) and (strlen($border) == 4)) { + if (is_string($border) AND (strlen($border) == 4)) { // full border $border = 1; } - if ($fill or ($border == 1)) { + if ($fill OR ($border == 1)) { if ($fill) { $op = ($border == 1) ? 'B' : 'f'; } else { @@ -6123,13 +5257,13 @@ class TCPDF { if ($txt != '') { $txt2 = $txt; if ($this->isunicode) { - if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1')) { - $txt2 = $this->UTF8ToLatin1($txt2); + if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) { + $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont); } else { - $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values - $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl); + $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values + $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont); // replace thai chars (if any) - if (defined('K_THAI_TOPCHARS') and (K_THAI_TOPCHARS == true)) { + if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) { // number of chars $numchars = count($unicode); // po pla, for far, for fan @@ -6159,7 +5293,7 @@ class TCPDF { // tonemark at upper right (normal position) $output[] = $ch0; } - } elseif (in_array($ch1, $longtail) or (in_array($ch2, $longtail) and in_array($ch1, $lowvowel))) { + } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) { // tonemark at lower left $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48)); } elseif (in_array($ch1, $upvowel)) { @@ -6174,9 +5308,9 @@ class TCPDF { // tonemark at lower right $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48)); } - } elseif (($ch0 == 0x0e33) and (in_array($ch1, $longtail) or (in_array($ch2, $longtail) and in_array($ch1, $tonemark)))) { + } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) { // add lower left nikhahit and sara aa - if ($this->isCharDefined(0xf711) and $this->isCharDefined(0x0e32)) { + if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) { $output[] = 0xf711; $this->CurrentFont['subsetchars'][0xf711] = true; $output[] = 0x0e32; @@ -6198,13 +5332,13 @@ class TCPDF { // normal character $output[] = $ch0; } - } elseif (in_array($ch1, $lowtail) and in_array($ch0, $lowvowel)) { + } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) { // lower vowel $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38)); - } elseif (($ch0 == 0x0e0d) and in_array($chn, $lowvowel)) { + } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) { // yo ying without lower part $output[] = $this->replaceChar($ch0, 0xf70f); - } elseif (($ch0 == 0x0e10) and in_array($chn, $lowvowel)) { + } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) { // tho santan without lower part $output[] = $this->replaceChar($ch0, 0xf700); } else { @@ -6219,10 +5353,10 @@ class TCPDF { // update font subsetchars $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); } // end of K_THAI_TOPCHARS - $txt2 = $this->arrUTF8ToUTF16BE($unicode, false); + $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false); } } - $txt2 = $this->_escape($txt2); + $txt2 = TCPDF_STATIC::_escape($txt2); // get current text width (considering general font stretching and spacing) $txwidth = $this->GetStringWidth($txt); $width = $txwidth; @@ -6235,7 +5369,7 @@ class TCPDF { $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width); } // check if stretching is required - if (($ratio < 1) or (($ratio > 1) and (($stretch % 2) == 0))) { + if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) { // the text will be stretched to fit cell width if ($stretch > 2) { // set new character spacing @@ -6258,7 +5392,7 @@ class TCPDF { // increase/decrease font spacing $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k)); } - if ($this->ColorFlag and ($this->textrendermode < 4)) { + if ($this->ColorFlag AND ($this->textrendermode < 4)) { $s .= 'q '.$this->TextColor.' '; } // rendering mode @@ -6267,12 +5401,12 @@ class TCPDF { $ns = substr_count($txt, chr(32)); // Justification $spacewidth = 0; - if (($align == 'J') and ($ns > 0)) { + if (($align == 'J') AND ($ns > 0)) { if ($this->isUnicodeFont()) { // get string width without spaces $width = $this->GetStringWidth(str_replace(' ', '', $txt)); // calculate average space width - $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize; + $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1); if ($this->font_stretching != 100) { // word spacing is affected by stretching $spacewidth /= ($this->font_stretching / 100); @@ -6350,8 +5484,8 @@ class TCPDF { $xshift += $this->GetArrStringWidth($uniarr); // + shift justification } else { // character to print - $topchr = $this->arrUTF8ToUTF16BE($uniarr, false); - $topchr = $this->_escape($topchr); + $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false); + $topchr = TCPDF_STATIC::_escape($topchr); $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr); } } @@ -6365,7 +5499,7 @@ class TCPDF { if ($this->overline) { $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width); } - if ($this->ColorFlag and ($this->textrendermode < 4)) { + if ($this->ColorFlag AND ($this->textrendermode < 4)) { $s .= ' Q'; } if ($link) { @@ -6386,7 +5520,7 @@ class TCPDF { } } // reset word spacing - if (!$this->isUnicodeFont() and ($align == 'J')) { + if (!$this->isUnicodeFont() AND ($align == 'J')) { $rs .= ' BT 0 Tw ET'; } // reset stretching and spacing @@ -6488,7 +5622,7 @@ class TCPDF { $mode = 'normal'; } foreach ($brd as $border => $style) { - if (is_array($style) and !empty($style)) { + if (is_array($style) AND !empty($style)) { // apply border style $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '; $s .= $this->SetLineStyle($style, true)."\n"; @@ -6565,34 +5699,34 @@ class TCPDF { $s .= 'S '; } } elseif (strlen($border) == 2) { - if ((strpos($border,'L') !== false) and (strpos($border,'T') !== false)) { // LT + if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT $s .= sprintf('%F %F m ', $xL, $yL); $s .= sprintf('%F %F l ', $xT, $yT); $s .= sprintf('%F %F l ', $xR, $yR); $s .= 'S '; - } elseif ((strpos($border,'T') !== false) and (strpos($border,'R') !== false)) { // TR + } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR $s .= sprintf('%F %F m ', $xT, $yT); $s .= sprintf('%F %F l ', $xR, $yR); $s .= sprintf('%F %F l ', $xB, $yB); $s .= 'S '; - } elseif ((strpos($border,'R') !== false) and (strpos($border,'B') !== false)) { // RB + } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB $s .= sprintf('%F %F m ', $xR, $yR); $s .= sprintf('%F %F l ', $xB, $yB); $s .= sprintf('%F %F l ', $xL, $yL); $s .= 'S '; - } elseif ((strpos($border,'B') !== false) and (strpos($border,'L') !== false)) { // BL + } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL $s .= sprintf('%F %F m ', $xB, $yB); $s .= sprintf('%F %F l ', $xL, $yL); $s .= sprintf('%F %F l ', $xT, $yT); $s .= 'S '; - } elseif ((strpos($border,'L') !== false) and (strpos($border,'R') !== false)) { // LR + } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR $s .= sprintf('%F %F m ', $xL, $yL); $s .= sprintf('%F %F l ', $xT, $yT); $s .= 'S '; $s .= sprintf('%F %F m ', $xR, $yR); $s .= sprintf('%F %F l ', $xB, $yB); $s .= 'S '; - } elseif ((strpos($border,'T') !== false) and (strpos($border,'B') !== false)) { // TB + } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB $s .= sprintf('%F %F m ', $xT, $yT); $s .= sprintf('%F %F l ', $xR, $yR); $s .= 'S '; @@ -6619,7 +5753,7 @@ class TCPDF { $s .= 'S '; } } - if (is_array($style) and !empty($style)) { + if (is_array($style) AND !empty($style)) { // reset border style to previous value $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n"; } @@ -6646,7 +5780,7 @@ class TCPDF { * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false. * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:
        • T: TOP
        • M: middle
        • B: bottom
        . This feature works only when $ishtml=false and the cell must fit in a single page. - * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). + * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). $maxh must be greater than 0 and equal to $h. * @return int Return the number of cells or 1 for html mode. * @public * @since 1.3 @@ -6662,17 +5796,16 @@ class TCPDF { $this->cell_padding['T'] = 0; $this->cell_padding['B'] = 0; $this->setCellMargins(0, 0, 0, 0); - if ($this->empty_string($this->lasth) or $reseth) { + if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) { // reset row height $this->resetLastH(); } - if (!$this->empty_string($y)) { - $this->SetY($y); - } else { - $y = $this->GetY(); + if (!TCPDF_STATIC::empty_string($y)) { + $this->SetY($y); // set y in order to convert negative y values to positive ones } + $y = $this->GetY(); $resth = 0; - if (($h > 0) and $this->inPageBody() and (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) { + if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) { // spit cell in more pages/columns $newh = ($this->PageBreakTrigger - $y); $resth = ($h - $newh); // cell to be printed on the next page/column @@ -6682,7 +5815,7 @@ class TCPDF { $startpage = $this->page; // get current column $startcolumn = $this->current_column; - if (!$this->empty_string($x)) { + if (!TCPDF_STATIC::empty_string($x)) { $this->SetX($x); } else { $x = $this->GetX(); @@ -6692,30 +5825,32 @@ class TCPDF { // apply margins $oy = $y + $mc_margin['T']; if ($this->rtl) { - $ox = $this->w - $x - $mc_margin['R']; + $ox = ($this->w - $x - $mc_margin['R']); } else { - $ox = $x + $mc_margin['L']; + $ox = ($x + $mc_margin['L']); } $this->x = $ox; $this->y = $oy; // set width - if ($this->empty_string($w) or ($w <= 0)) { + if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) { if ($this->rtl) { - $w = $this->x - $this->lMargin - $mc_margin['L']; + $w = ($this->x - $this->lMargin - $mc_margin['L']); } else { - $w = $this->w - $this->x - $this->rMargin - $mc_margin['R']; + $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']); } } // store original margin values $lMargin = $this->lMargin; $rMargin = $this->rMargin; if ($this->rtl) { - $this->rMargin = $this->w - $this->x; - $this->lMargin = $this->x - $w; + $this->rMargin = ($this->w - $this->x); + $this->lMargin = ($this->x - $w); } else { - $this->lMargin = $this->x; - $this->rMargin = $this->w - $this->x - $w; + $this->lMargin = ($this->x); + $this->rMargin = ($this->w - $this->x - $w); } + $this->clMargin = $this->lMargin; + $this->crMargin = $this->rMargin; if ($autopadding) { // add top padding $this->y += $mc_padding['T']; @@ -6725,31 +5860,46 @@ class TCPDF { $nl = 1; } else { // ******* Write simple text $prev_FontSizePt = $this->FontSizePt; + if ($fitcell) { + // ajust height values + $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']); + $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom)); + } // vertical alignment if ($maxh > 0) { // get text height $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border); - if ($fitcell) { + if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) { // try to reduce font size to fit text on cell (use a quick search algorithm) $fmin = 1; $fmax = $this->FontSizePt; - $prev_text_height = $text_height; - $maxit = 100; // max number of iterations - while ($maxit > 0) { + $diff_epsilon = (1 / $this->k); // one point (min resolution) + $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations + while ($maxit >= 0) { $fmid = (($fmax + $fmin) / 2); $this->SetFontSize($fmid, false); $this->resetLastH(); $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border); - if (($text_height == $maxh) or (($text_height < $maxh) and ($fmin >= ($fmax - 0.01)))) { - break; - } elseif ($text_height < $maxh) { + $diff = ($maxh - $text_height); + if ($diff >= 0) { + if ($diff <= $diff_epsilon) { + break; + } $fmin = $fmid; } else { $fmax = $fmid; } --$maxit; } - $this->SetFontSize($this->FontSizePt); + if ($maxit < 0) { + // premature exit, we get the minimum font value to fit the cell + $this->SetFontSize($fmin); + $this->resetLastH(); + $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border); + } else { + $this->SetFontSize($fmid); + $this->resetLastH(); + } } if ($text_height < $maxh) { if ($valign == 'M') { @@ -6798,10 +5948,13 @@ class TCPDF { if ($this->num_columns == 0) { $this->num_columns = 1; } + // disable page regions check + $check_page_regions = $this->check_page_regions; + $this->check_page_regions = false; // get border modes - $border_start = $this->getBorderMode($border, $position='start'); - $border_end = $this->getBorderMode($border, $position='end'); - $border_middle = $this->getBorderMode($border, $position='middle'); + $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell); + $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell); + $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell); // design borders around HTML cells. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page $ccode = ''; @@ -6813,16 +5966,18 @@ class TCPDF { } // account for margin changes if ($page > $startpage) { - if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); } } if ($startpage == $endpage) { // single page for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column - $this->selectColumn($column); + if ($column != $this->current_column) { + $this->selectColumn($column); + } if ($this->rtl) { $this->x -= $mc_margin['R']; } else { @@ -6851,7 +6006,9 @@ class TCPDF { } // end for each column } elseif ($page == $startpage) { // first page for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column - $this->selectColumn($column); + if ($column != $this->current_column) { + $this->selectColumn($column); + } if ($this->rtl) { $this->x -= $mc_margin['R']; } else { @@ -6870,7 +6027,9 @@ class TCPDF { } // end for each column } elseif ($page == $endpage) { // last page for ($column = 0; $column <= $endcolumn; ++$column) { // for each column - $this->selectColumn($column); + if ($column != $this->current_column) { + $this->selectColumn($column); + } if ($this->rtl) { $this->x -= $mc_margin['R']; } else { @@ -6905,7 +6064,7 @@ class TCPDF { $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n"; } // end for each column } - if ($cborder or $fill) { + if ($cborder OR $fill) { $offsetlen = strlen($ccode); // draw border and fill if ($this->inxobj) { @@ -6941,6 +6100,8 @@ class TCPDF { } } } // end for each page + // restore page regions check + $this->check_page_regions = $check_page_regions; // Get end-of-cell Y position $currentY = $this->GetY(); // restore previous values @@ -6954,7 +6115,7 @@ class TCPDF { // check for margin variations between pages (i.e. booklet mode) $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']); $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']); - if (($dl != 0) or ($dr != 0)) { + if (($dl != 0) OR ($dr != 0)) { $this->lMargin += $dl; $this->rMargin += $dr; } @@ -6975,82 +6136,11 @@ class TCPDF { $this->setContentMark(); $this->cell_padding = $prev_cell_padding; $this->cell_margin = $prev_cell_margin; + $this->clMargin = $this->lMargin; + $this->crMargin = $this->rMargin; return $nl; } - /** - * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages) - * @param $brd (mixed) Indicates if borders must be drawn around the cell block. The value can be a number:
        • 0: no border (default)
        • 1: frame
        or a string containing some or all of the following characters (in any order):
        • L: left
        • T: top
        • R: right
        • B: bottom
        or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) - * @param $position (string) multicell position: 'start', 'middle', 'end' - * @return border mode array - * @protected - * @since 4.4.002 (2008-12-09) - */ - protected function getBorderMode($brd, $position='start') { - if ((!$this->opencell) or empty($brd)) { - return $brd; - } - if ($brd == 1) { - $brd = 'LTRB'; - } - if (is_string($brd)) { - // convert string to array - $slen = strlen($brd); - $newbrd = array(); - for ($i = 0; $i < $slen; ++$i) { - $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter'); - } - $brd = $newbrd; - } - foreach ($brd as $border => $style) { - switch ($position) { - case 'start': { - if (strpos($border, 'B') !== false) { - // remove bottom line - $newkey = str_replace('B', '', $border); - if (strlen($newkey) > 0) { - $brd[$newkey] = $style; - } - unset($brd[$border]); - } - break; - } - case 'middle': { - if (strpos($border, 'B') !== false) { - // remove bottom line - $newkey = str_replace('B', '', $border); - if (strlen($newkey) > 0) { - $brd[$newkey] = $style; - } - unset($brd[$border]); - $border = $newkey; - } - if (strpos($border, 'T') !== false) { - // remove bottom line - $newkey = str_replace('T', '', $border); - if (strlen($newkey) > 0) { - $brd[$newkey] = $style; - } - unset($brd[$border]); - } - break; - } - case 'end': { - if (strpos($border, 'T') !== false) { - // remove bottom line - $newkey = str_replace('T', '', $border); - if (strlen($newkey) > 0) { - $brd[$newkey] = $style; - } - unset($brd[$border]); - } - break; - } - } - } - return $brd; - } - /** * This method return the estimated number of lines for print a simple text string using Multicell() method. * @param $txt (string) String for calculating his height @@ -7060,11 +6150,14 @@ class TCPDF { * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:
        • 0: no border (default)
        • 1: frame
        or a string containing some or all of the following characters (in any order):
        • L: left
        • T: top
        • R: right
        • B: bottom
        or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) * @return float Return the minimal height needed for multicell method for printing the $txt param. - * @author Alexander Escalona Fern�ndez, Nicola Asuni + * @author Alexander Escalona Fern\E1ndez, Nicola Asuni * @public * @since 4.5.011 */ public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) { + if ($txt === NULL) { + return 0; + } if ($txt === '') { // empty string return 1; @@ -7076,7 +6169,7 @@ class TCPDF { $this->cell_padding = $cellpadding; } $this->adjustCellPadding($border); - if ($this->empty_string($w) or ($w <= 0)) { + if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) { if ($this->rtl) { $w = $this->x - $this->lMargin; } else { @@ -7090,18 +6183,28 @@ class TCPDF { } $lines = 1; $sum = 0; - $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl); + $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont); $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true); $length = count($chars); $lastSeparator = -1; for ($i = 0; $i < $length; ++$i) { + $c = $chars[$i]; $charWidth = $charsWidth[$i]; - if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) { + if (($c != 160) + AND (($c == 173) + OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode)) + OR (($c == 45) + AND ($i > 0) AND ($i < ($length - 1)) + AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode)) + AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode)) + ) + ) + ) { $lastSeparator = $i; } - if ((($sum + $charWidth) > $wmax) or ($chars[$i] == 10)) { + if ((($sum + $charWidth) > $wmax) OR ($c == 10)) { ++$lines; - if ($chars[$i] == 10) { + if ($c == 10) { $lastSeparator = -1; $sum = 0; } elseif ($lastSeparator != -1) { @@ -7148,12 +6251,12 @@ class TCPDF { * $this->setPage($page); * if ($page == $start_page) { * // first page - * $height = $this->h - $start_y - $this->bMargin; + * $height += $this->h - $start_y - $this->bMargin; * } elseif ($page == $end_page) { * // last page - * $height = $end_y - $this->tMargin; + * $height += $end_y - $this->tMargin; * } else { - * $height = $this->h - $this->tMargin - $this->bMargin; + * $height += $this->h - $this->tMargin - $this->bMargin; * } * } * } @@ -7167,7 +6270,7 @@ class TCPDF { * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:
        • 0: no border (default)
        • 1: frame
        or a string containing some or all of the following characters (in any order):
        • L: left
        • T: top
        • R: right
        • B: bottom
        or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) * @return float Return the minimal height needed for multicell method for printing the $txt param. - * @author Nicola Asuni, Alexander Escalona Fern�ndez + * @author Nicola Asuni, Alexander Escalona Fern\E1ndez * @public */ public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) { @@ -7179,11 +6282,7 @@ class TCPDF { } $this->adjustCellPadding($border); $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border); - $height = $lines * ($this->FontSize * $this->cell_height_ratio); - if ($autopadding) { - // add top and bottom padding - $height += ($this->cell_padding['T'] + $this->cell_padding['B']); - } + $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding); $this->cell_padding = $prev_cell_padding; $this->lasth = $prev_lasth; return $height; @@ -7200,7 +6299,7 @@ class TCPDF { * @param $stretch (int) font stretch mode:
        • 0 = disabled
        • 1 = horizontal scaling only if text is larger than cell width
        • 2 = forced horizontal scaling to fit cell width
        • 3 = character spacing only if text is larger than cell width
        • 4 = forced character spacing to fit cell width
        General font stretching and scaling values will be preserved when possible. * @param $firstline (boolean) if true prints only the first line and return the remaining string. * @param $firstblock (boolean) if true the string is the starting of a line. - * @param $maxh (float) maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. + * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode). * @param $margin (array) margin array of the parent container * @return mixed Return the number of cells or the remaining string if $firstline = true. @@ -7221,13 +6320,13 @@ class TCPDF { // remove carriage returns $s = str_replace("\r", '', $txt); // check if string contains arabic text - if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) { + if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) { $arabic = true; } else { $arabic = false; } // check if string contains RTL text - if ($arabic or ($this->tmprtl == 'R') or preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) { + if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) { $rtlmode = true; } else { $rtlmode = false; @@ -7235,18 +6334,20 @@ class TCPDF { // get a char width $chrwidth = $this->GetCharWidth(46); // dot character // get array of unicode values - $chars = $this->UTF8StringToArray($s); + $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont); + // calculate maximum width for a single character on string + $chrw = $this->GetArrStringWidth($chars, '', '', 0, true); + array_walk($chrw, array($this, 'getRawCharWidth')); + $maxchwidth = max($chrw); // get array of chars - $uchars = $this->UTF8ArrayToUniArray($chars); + $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode); // get the number of characters $nb = count($chars); // replacement for SHY character (minus symbol) $shy_replacement = 45; - $shy_replacement_char = $this->unichr($shy_replacement); + $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode); // widht for SHY replacement $shy_replacement_width = $this->GetCharWidth($shy_replacement); - // max Y - $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B']; // page width $pw = $w = $this->w - $this->lMargin - $this->rMargin; // calculate remaining line width ($w) @@ -7260,24 +6361,28 @@ class TCPDF { if (!$firstline) { $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']); } - if ((!$firstline) and (($chrwidth > $wmax) or ($this->GetCharWidth($chars[0]) > $wmax))) { - // a single character do not fit on column + if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) { + // the maximum width character do not fit on column return ''; } // minimum row height - $row_height = max($h, $this->FontSize * $this->cell_height_ratio); + $row_height = max($h, $this->getCellHeight($this->FontSize)); + // max Y + $maxy = $this->y + $maxh - max($row_height, $h); $start_page = $this->page; $i = 0; // character position $j = 0; // current starting position $sep = -1; // position of the last blank space + $prevsep = $sep; // previous separator $shy = false; // true if the last blank is a soft hypen (SHY) + $prevshy = $shy; // previous shy mode $l = 0; // current string length $nl = 0; //number of lines $linebreak = false; $pc = 0; // previous character // for each character while ($i < $nb) { - if (($maxh > 0) and ($this->y >= $maxy)) { + if (($maxh > 0) AND ($this->y > $maxy) ) { break; } //Get the current character @@ -7293,12 +6398,12 @@ class TCPDF { } else { $talign = $align; } - $tmpstr = $this->UniArrSubString($uchars, $j, $i); + $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i); if ($firstline) { $startx = $this->x; $tmparr = array_slice($chars, $j, ($i - $j)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont); } $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); @@ -7313,25 +6418,26 @@ class TCPDF { $this->SetCellPadding(0); } } - if ($firstblock and $this->isRTLTextDir()) { + if ($firstblock AND $this->isRTLTextDir()) { $tmpstr = $this->stringRightTrim($tmpstr); } - // Skip newlines at the begining of a page or column - if (!empty($tmpstr) or ($this->y < ($this->PageBreakTrigger - $row_height))) { + // Skip newlines at the beginning of a page or column + if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) { $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch); } unset($tmpstr); if ($firstline) { $this->cell_padding = $tmpcellpadding; - return ($this->UniArrSubString($uchars, $i)); + return (TCPDF_FONTS::UniArrSubString($uchars, $i)); } ++$nl; $j = $i + 1; $l = 0; $sep = -1; + $prevsep = $sep; $shy = false; // account for margin changes - if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and ($this->inPageBody())) { + if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) { $this->AcceptPageBreak(); if ($this->rtl) { $this->x -= $margin['R']; @@ -7350,19 +6456,21 @@ class TCPDF { // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. if (($c != 160) - and (($c == 173) - or preg_match($this->re_spaces, $this->unichr($c)) - or (($c == 45) - and ($i < ($nb - 1)) - and @preg_match('/[\p{L}]/'.$this->re_space['m'], $this->unichr($pc)) - and @preg_match('/[\p{L}]/'.$this->re_space['m'], $this->unichr($chars[($i + 1)])) + AND (($c == 173) + OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode)) + OR (($c == 45) + AND ($i < ($nb - 1)) + AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode)) + AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode)) ) ) ) { // update last blank space position + $prevsep = $sep; $sep = $i; // check if is a SHY - if (($c == 173) or ($c == 45)) { + if (($c == 173) OR ($c == 45)) { + $prevshy = $shy; $shy = true; if ($pc == 45) { $tmp_shy_replacement_width = 0; @@ -7376,33 +6484,37 @@ class TCPDF { } } // update string length - if ($this->isUnicodeFont() and ($arabic)) { + if ($this->isUnicodeFont() AND ($arabic)) { // with bidirectional algorithm some chars may be changed affecting the line length // *** very slow *** - $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl)); + $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont)); } else { $l += $this->GetCharWidth($c); } - if (($l > $wmax) or (($c == 173) and (($l + $tmp_shy_replacement_width) > $wmax))) { + if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) { + if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) { + $sep = $prevsep; + $shy = $prevshy; + } // we have reached the end of column if ($sep == -1) { // check if the line was already started - if (($this->rtl and ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth))) - or ((!$this->rtl) and ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) { + if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth))) + OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) { // print a void cell and go to next line $this->Cell($w, $h, '', 0, 1); $linebreak = true; if ($firstline) { - return ($this->UniArrSubString($uchars, $j)); + return (TCPDF_FONTS::UniArrSubString($uchars, $j)); } } else { // truncate the word because do not fit on column - $tmpstr = $this->UniArrSubString($uchars, $j, $i); + $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i); if ($firstline) { $startx = $this->x; $tmparr = array_slice($chars, $j, ($i - $j)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont); } $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); @@ -7417,36 +6529,36 @@ class TCPDF { $this->SetCellPadding(0); } } - if ($firstblock and $this->isRTLTextDir()) { + if ($firstblock AND $this->isRTLTextDir()) { $tmpstr = $this->stringRightTrim($tmpstr); } $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cell_padding = $tmpcellpadding; - return ($this->UniArrSubString($uchars, $i)); + return (TCPDF_FONTS::UniArrSubString($uchars, $i)); } $j = $i; --$i; } } else { // word wrapping - if ($this->rtl and (!$firstblock) and ($sep < $i)) { + if ($this->rtl AND (!$firstblock) AND ($sep < $i)) { $endspace = 1; } else { $endspace = 0; } // check the length of the next string - $strrest = $this->UniArrSubString($uchars, ($sep + $endspace)); - $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $this->stringTrim($strrest)); - if (isset($nextstr[0]) and ($this->GetStringWidth($nextstr[0]) > $pw)) { + $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)); + $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest)); + if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) { // truncate the word because do not fit on a full page width - $tmpstr = $this->UniArrSubString($uchars, $j, $i); + $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i); if ($firstline) { $startx = $this->x; $tmparr = array_slice($chars, $j, ($i - $j)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont); } $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); @@ -7461,14 +6573,14 @@ class TCPDF { $this->SetCellPadding(0); } } - if ($firstblock and $this->isRTLTextDir()) { + if ($firstblock AND $this->isRTLTextDir()) { $tmpstr = $this->stringRightTrim($tmpstr); } $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cell_padding = $tmpcellpadding; - return ($this->UniArrSubString($uchars, $i)); + return (TCPDF_FONTS::UniArrSubString($uchars, $i)); } $j = $i; --$i; @@ -7489,12 +6601,12 @@ class TCPDF { $shy_char_left = ''; $shy_char_right = ''; } - $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace)); + $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace)); if ($firstline) { $startx = $this->x; $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont); } $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); @@ -7510,7 +6622,7 @@ class TCPDF { } } // print the line - if ($firstblock and $this->isRTLTextDir()) { + if ($firstblock AND $this->isRTLTextDir()) { $tmpstr = $this->stringRightTrim($tmpstr); } $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch); @@ -7521,7 +6633,7 @@ class TCPDF { } // return the remaining text $this->cell_padding = $tmpcellpadding; - return ($this->UniArrSubString($uchars, ($sep + $endspace))); + return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace))); } $i = $sep; $sep = -1; @@ -7530,7 +6642,7 @@ class TCPDF { } } // account for margin changes - if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and ($this->inPageBody())) { + if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) { $this->AcceptPageBreak(); if ($this->rtl) { $this->x -= $margin['R']; @@ -7583,12 +6695,12 @@ class TCPDF { break; } } - $tmpstr = $this->UniArrSubString($uchars, $j, $nb); + $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb); if ($firstline) { $startx = $this->x; $tmparr = array_slice($chars, $j, ($nb - $j)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont); } $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); @@ -7603,14 +6715,14 @@ class TCPDF { $this->SetCellPadding(0); } } - if ($firstblock and $this->isRTLTextDir()) { + if ($firstblock AND $this->isRTLTextDir()) { $tmpstr = $this->stringRightTrim($tmpstr); } $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cell_padding = $tmpcellpadding; - return ($this->UniArrSubString($uchars, $nb)); + return (TCPDF_FONTS::UniArrSubString($uchars, $nb)); } ++$nl; } @@ -7634,117 +6746,6 @@ class TCPDF { } } - /** - * Extract a slice of the $strarr array and return it as string. - * @param $strarr (string) The input array of characters. - * @param $start (int) the starting element of $strarr. - * @param $end (int) first element that will not be returned. - * @return Return part of a string - * @public - */ - public function UTF8ArrSubString($strarr, $start='', $end='') { - if (strlen($start) == 0) { - $start = 0; - } - if (strlen($end) == 0) { - $end = count($strarr); - } - $string = ''; - for ($i=$start; $i < $end; ++$i) { - $string .= $this->unichr($strarr[$i]); - } - return $string; - } - - /** - * Extract a slice of the $uniarr array and return it as string. - * @param $uniarr (string) The input array of characters. - * @param $start (int) the starting element of $strarr. - * @param $end (int) first element that will not be returned. - * @return Return part of a string - * @public - * @since 4.5.037 (2009-04-07) - */ - public function UniArrSubString($uniarr, $start='', $end='') { - if (strlen($start) == 0) { - $start = 0; - } - if (strlen($end) == 0) { - $end = count($uniarr); - } - $string = ''; - for ($i=$start; $i < $end; ++$i) { - $string .= $uniarr[$i]; - } - return $string; - } - - /** - * Convert an array of UTF8 values to array of unicode characters - * @param $ta (string) The input array of UTF8 values. - * @return Return array of unicode characters - * @public - * @since 4.5.037 (2009-04-07) - */ - public function UTF8ArrayToUniArray($ta) { - return array_map(array($this, 'unichr'), $ta); - } - - /** - * Returns the unicode caracter specified by UTF-8 value - * @param $c (int) UTF-8 value - * @return Returns the specified character. - * @author Miguel Perez, Nicola Asuni - * @public - * @since 2.3.000 (2008-03-05) - */ - public function unichr($c) { - if (!$this->isunicode) { - return chr($c); - } elseif ($c <= 0x7F) { - // one byte - return chr($c); - } elseif ($c <= 0x7FF) { - // two bytes - return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F); - } elseif ($c <= 0xFFFF) { - // three bytes - return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F); - } elseif ($c <= 0x10FFFF) { - // four bytes - return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F); - } else { - return ''; - } - } - - /** - * Return the image type given the file name or array returned by getimagesize() function. - * @param $imgfile (string) image file name - * @param $iminfo (array) array of image information returned by getimagesize() function. - * @return string image type - * @since 4.8.017 (2009-11-27) - */ - public function getImageFileType($imgfile, $iminfo=array()) { - $type = ''; - if (isset($iminfo['mime']) and !empty($iminfo['mime'])) { - $mime = explode('/', $iminfo['mime']); - if ((count($mime) > 1) and ($mime[0] == 'image') and (!empty($mime[1]))) { - $type = strtolower(trim($mime[1])); - } - } - if (empty($type)) { - $fileinfo = pathinfo($imgfile); - if (isset($fileinfo['extension']) and (!$this->empty_string($fileinfo['extension']))) { - $type = strtolower(trim($fileinfo['extension'])); - } - } - if ($type == 'jpg') { - $type = 'jpeg'; - } - return $type; - } - /** * Set the block dimensions accounting for page breaks and page/column fitting * @param $w (float) width @@ -7760,13 +6761,19 @@ class TCPDF { if ($w <= 0) { // set maximum width $w = ($this->w - $this->lMargin - $this->rMargin); + if ($w <= 0) { + $w = 1; + } } if ($h <= 0) { // set maximum height $h = ($this->PageBreakTrigger - $this->tMargin); + if ($h <= 0) { + $h = 1; + } } // resize the block to be vertically contained on a single page or single column - if ($fitonpage or $this->AutoPageBreak) { + if ($fitonpage OR $this->AutoPageBreak) { $ratio_wh = ($w / $h); if ($h > ($this->PageBreakTrigger - $this->tMargin)) { $h = $this->PageBreakTrigger - $this->tMargin; @@ -7784,7 +6791,7 @@ class TCPDF { // Check whether we need a new page or new column first as this does not fit $prev_x = $this->x; $prev_y = $this->y; - if ($this->checkPageBreak($h, $y) or ($this->y < $prev_y)) { + if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) { $y = $this->y; if ($this->rtl) { $x += ($prev_x - $this->x); @@ -7800,10 +6807,10 @@ class TCPDF { $h = $this->PageBreakTrigger - $y; $w = ($h * $ratio_wh); } - if ((!$this->rtl) and (($x + $w) > ($this->w - $this->rMargin))) { + if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) { $w = $this->w - $this->rMargin - $x; $h = ($w / $ratio_wh); - } elseif (($this->rtl) and (($x - $w) < ($this->lMargin))) { + } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) { $w = $x - $this->lMargin; $h = ($w / $ratio_wh); } @@ -7846,104 +6853,76 @@ class TCPDF { * @since 1.1 */ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) { - if ($x === '') { + if ($this->state != 2) { + return; + } + if (strcmp($x, '') === 0) { $x = $this->x; } - if ($y === '') { + if (strcmp($y, '') === 0) { $y = $this->y; } // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); - $cached_file = false; // true when the file is cached $exurl = ''; // external streams + $imsize = FALSE; // check if we are passing an image as file or string if ($file[0] === '@') { // image from string $imgdata = substr($file, 1); - $file = $this->getObjFilename('img'); - $fp = fopen($file, 'w'); - fwrite($fp, $imgdata); - fclose($fp); - unset($imgdata); - $cached_file = true; - $imsize = @getimagesize($file); - if ($imsize === false) { - unlink($file); - $cached_file = false; - } } else { // image file - if ($file{0} === '*') { + if ($file[0] === '*') { // image as external stream $file = substr($file, 1); $exurl = $file; } - // check if is local file - if (!@Tools::file_exists_no_cache($file)) { - // encode spaces on filename (file is probably an URL) - $file = str_replace(' ', '%20', $file); + // check if file exist and it is valid + if (!@TCPDF_STATIC::file_exists($file)) { + return false; } - if (@Tools::file_exists_no_cache($file)) { - // get image dimensions - $imsize = @getimagesize($file); - } else { - $imsize = false; - } - if ($imsize === false) { - if (function_exists('curl_init')) { - // try to get remote file data using cURL - $cs = curl_init(); // curl session - curl_setopt($cs, CURLOPT_URL, $file); - curl_setopt($cs, CURLOPT_BINARYTRANSFER, true); - curl_setopt($cs, CURLOPT_FAILONERROR, true); - curl_setopt($cs, CURLOPT_RETURNTRANSFER, true); - if ((ini_get('open_basedir') == '') and (ini_get('safe_mode') == 'Off')) { - curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true); - } - curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5); - curl_setopt($cs, CURLOPT_TIMEOUT, 30); - curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF'); - $imgdata = curl_exec($cs); - curl_close($cs); - if ($imgdata !== false) { - // copy image to cache - $file = $this->getObjFilename('img'); - $fp = fopen($file, 'w'); - fwrite($fp, $imgdata); - fclose($fp); - unset($imgdata); - $cached_file = true; - $imsize = @getimagesize($file); - if ($imsize === false) { - unlink($file); - $cached_file = false; - } - } - } elseif (($w > 0) and ($h > 0)) { - // get measures from specified data - $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k; - $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k; - $imsize = array($pw, $ph); + if (($imsize = @getimagesize($file)) === FALSE) { + if (in_array($file, $this->imagekeys)) { + // get existing image data + $info = $this->getImageBuffer($file); + $imsize = array($info['w'], $info['h']); + } elseif (strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE) { + $imgdata = TCPDF_STATIC::fileGetContents($file); } } } - if ($imsize === false) { - if (substr($file, 0, -34) == K_PATH_CACHE.'msk') { // mask file + if (!empty($imgdata)) { + // copy image to cache + $original_file = $file; + $file = TCPDF_STATIC::getObjFilename('img', $this->file_id); + $fp = TCPDF_STATIC::fopenLocal($file, 'w'); + if (!$fp) { + $this->Error('Unable to write file: '.$file); + } + fwrite($fp, $imgdata); + fclose($fp); + unset($imgdata); + $imsize = @getimagesize($file); + if ($imsize === FALSE) { + unlink($file); + $file = $original_file; + } + } + if ($imsize === FALSE) { + if (($w > 0) AND ($h > 0)) { // get measures from specified data $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k; $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k; $imsize = array($pw, $ph); } else { - $this->Error('[Image] Unable to get image: '.$file); + $this->Error('[Image] Unable to get the size of the image: '.$file); } } // file hash - $filehash = md5($this->file_id.$file); + $filehash = md5($file); // get original image width and height in pixels list($pixw, $pixh) = $imsize; // calculate image width and height on document - if (($w <= 0) and ($h <= 0)) { + if (($w <= 0) AND ($h <= 0)) { // convert image size to document unit $w = $this->pixelsToUnits($pixw); $h = $this->pixelsToUnits($pixh); @@ -7951,7 +6930,7 @@ class TCPDF { $w = $h * $pixw / $pixh; } elseif ($h <= 0) { $h = $w * $pixh / $pixw; - } elseif (($fitbox !== false) and ($w > 0) and ($h > 0)) { + } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) { if (strlen($fitbox) !== 2) { // set default alignment $fitbox = '--'; @@ -7965,7 +6944,7 @@ class TCPDF { // height difference $hdiff = ($oldh - $h); // vertical alignment - switch (strtoupper($fitbox{1})) { + switch (strtoupper($fitbox[1])) { case 'T': { break; } @@ -7986,7 +6965,7 @@ class TCPDF { // width difference $wdiff = ($oldw - $w); // horizontal alignment - switch (strtoupper($fitbox{0})) { + switch (strtoupper($fitbox[0])) { case 'L': { if ($this->rtl) { $x -= $wdiff; @@ -8029,23 +7008,25 @@ class TCPDF { $newimage = false; // get existing image data $info = $this->getImageBuffer($file); - if (substr($file, 0, -34) != K_PATH_CACHE.'msk') { + if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) { // check if the newer image is larger $oldsize = ($info['w'] * $info['h']); - if ((($oldsize < $newsize) and ($resize)) or (($oldsize < $pixsize) and (!$resize))) { + if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) { $newimage = true; } } - } elseif (substr($file, 0, -34) != K_PATH_CACHE.'msk') { - // check for cached images with alpha channel - $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; - $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; - if (in_array($tempfile_plain, $this->imagekeys) && Tools::file_exists_no_cache($tempfile_plain)) { + } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) { + // create temp image file (without alpha channel) + $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash; + // create temp alpha file + $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash; + // check for cached images + if (in_array($tempfile_plain, $this->imagekeys)) { // get existing image data $info = $this->getImageBuffer($tempfile_plain); // check if the newer image is larger $oldsize = ($info['w'] * $info['h']); - if ((($oldsize < $newsize) and ($resize)) or (($oldsize < $pixsize) and (!$resize))) { + if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) { $newimage = true; } else { $newimage = false; @@ -8060,82 +7041,92 @@ class TCPDF { //First use of image, get info $type = strtolower($type); if ($type == '') { - $type = $this->getImageFileType($file, $imsize); + $type = TCPDF_IMAGES::getImageFileType($file, $imsize); } elseif ($type == 'jpg') { $type = 'jpeg'; } - $mqr = $this->get_mqr(); - $this->set_mqr(false); - // Specific image handlers + $mqr = TCPDF_STATIC::get_mqr(); + TCPDF_STATIC::set_mqr(false); + // Specific image handlers (defined on TCPDF_IMAGES CLASS) $mtd = '_parse'.$type; // GD image handler function $gdfunction = 'imagecreatefrom'.$type; $info = false; - if ((method_exists($this, $mtd)) and (!($resize and (function_exists($gdfunction) or extension_loaded('imagick'))))) { + if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) { // TCPDF image functions - $info = $this->$mtd($file); - if ($info == 'pngalpha') { + $info = TCPDF_IMAGES::$mtd($file); + if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) + AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) { return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash); } } - if (!$info) { - if (function_exists($gdfunction)) { + if (($info === false) AND function_exists($gdfunction)) { + try { // GD library $img = $gdfunction($file); - if ($resize) { - $imgr = imagecreatetruecolor($neww, $newh); - if (($type == 'gif') or ($type == 'png')) { - $imgr = $this->_setGDImageTransparency($imgr, $img); + if ($img !== false) { + if ($resize) { + $imgr = imagecreatetruecolor($neww, $newh); + if (($type == 'gif') OR ($type == 'png')) { + $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img); + } + imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh); + $img = $imgr; } - imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh); - if (($type == 'gif') or ($type == 'png')) { - $info = $this->_toPNG($imgr); + if (($type == 'gif') OR ($type == 'png')) { + $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id)); } else { - $info = $this->_toJPEG($imgr); - } - } else { - if (($type == 'gif') or ($type == 'png')) { - $info = $this->_toPNG($img); - } else { - $info = $this->_toJPEG($img); + $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id)); } } - } elseif (extension_loaded('imagick')) { + } catch(Exception $e) { + $info = false; + } + } + if (($info === false) AND extension_loaded('imagick')) { + try { // ImageMagick library $img = new Imagick(); - if ($type == 'SVG') { - // get SVG file content - $svgimg = file_get_contents($file); - // get width and height - $regs = array(); - if (preg_match('/]*)>/si', $svgimg, $regs)) { - $svgtag = $regs[1]; - $tmp = array(); - if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) { - $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); - $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit; - $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1); - } else { - $ow = $w; - } - $tmp = array(); - if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) { - $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); - $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit; - $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1); - } else { - $oh = $h; - } - $tmp = array(); - if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) { - $vbw = ($ow * $this->imgscale * $this->k); - $vbh = ($oh * $this->imgscale * $this->k); - $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh); - $svgtag = $vbox.$svgtag; - } - $svgimg = preg_replace('/]*)>/si', '', $svgimg, 1); + if ($type == 'svg') { + if ($file[0] === '@') { + // image from string + $svgimg = substr($file, 1); + } else { + // get SVG file content + $svgimg = TCPDF_STATIC::fileGetContents($file); + } + if ($svgimg !== FALSE) { + // get width and height + $regs = array(); + if (preg_match('/]*)>/si', $svgimg, $regs)) { + $svgtag = $regs[1]; + $tmp = array(); + if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) { + $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); + $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit; + $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1); + } else { + $ow = $w; + } + $tmp = array(); + if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) { + $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false); + $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit; + $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1); + } else { + $oh = $h; + } + $tmp = array(); + if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) { + $vbw = ($ow * $this->imgscale * $this->k); + $vbh = ($oh * $this->imgscale * $this->k); + $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh); + $svgtag = $vbox.$svgtag; + } + $svgimg = preg_replace('/]*)>/si', '', $svgimg, 1); + } + $img->readImageBlob($svgimg); } - $img->readImageBlob($svgimg); } else { $img->readImage($file); } @@ -8144,28 +7135,24 @@ class TCPDF { } $img->setCompressionQuality($this->jpeg_quality); $img->setImageFormat('jpeg'); - $tempname = tempnam(K_PATH_CACHE, 'jpg_'); + $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id); $img->writeImage($tempname); - $info = $this->_parsejpeg($tempname); + $info = TCPDF_IMAGES::_parsejpeg($tempname); unlink($tempname); $img->destroy(); - } else { - return; + } catch(Exception $e) { + $info = false; } } if ($info === false) { - //If false, we cannot process image + // unable to process image return; } - $this->set_mqr($mqr); + TCPDF_STATIC::set_mqr($mqr); if ($ismask) { // force grayscale $info['cs'] = 'DeviceGray'; } - $info['i'] = $this->numimages; - if (!in_array($file, $this->imagekeys)) { - ++$info['i']; - } if ($imgmask !== false) { $info['masked'] = $imgmask; } @@ -8175,39 +7162,24 @@ class TCPDF { // array of alternative images $info['altimgs'] = $altimgs; // add image to document - $this->setImageBuffer($file, $info); - } - if ($cached_file) { - // remove cached file - unlink($file); + $info['i'] = $this->setImageBuffer($file, $info); } // set alignment + $this->img_rb_x = $x + $w; $this->img_rb_y = $y + $h; + // set alignment - if ($this->rtl) { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x - $w; - } - $this->img_rb_x = $ximg; + if ($palign == 'L') { + $ximg = $this->lMargin; + } elseif ($palign == 'C') { + $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; + } elseif ($palign == 'R') { + $ximg = $this->w - $this->rMargin - $w; } else { - if ($palign == 'L') { - $ximg = $this->lMargin; - } elseif ($palign == 'C') { - $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2; - } elseif ($palign == 'R') { - $ximg = $this->w - $this->rMargin - $w; - } else { - $ximg = $x; - } - $this->img_rb_x = $ximg + $w; + $ximg = $x; } - if ($ismask or $hidden) { + + if ($ismask OR $hidden) { // image is not displayed return $info['i']; } @@ -8265,319 +7237,7 @@ class TCPDF { } /** - * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist) - * @param $mqr (boolean) FALSE for off, TRUE for on. - * @since 4.6.025 (2009-08-17) - */ - public function set_mqr($mqr) { - if (!defined('PHP_VERSION_ID')) { - $version = PHP_VERSION; - define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); - } - if (PHP_VERSION_ID < 50300) { - @set_magic_quotes_runtime($mqr); - } - } - - /** - * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist) - * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise. - * @since 4.6.025 (2009-08-17) - */ - public function get_mqr() { - if (!defined('PHP_VERSION_ID')) { - $version = PHP_VERSION; - define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4})); - } - if (PHP_VERSION_ID < 50300) { - return @get_magic_quotes_runtime(); - } - return 0; - } - - /** - * Convert the loaded image to a JPEG and then return a structure for the PDF creator. - * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant. - * @param $image (image) Image object. - * return image JPEG image object. - * @protected - */ - protected function _toJPEG($image) { - $tempname = tempnam(K_PATH_CACHE, 'jpg_'); - imagejpeg($image, $tempname, $this->jpeg_quality); - imagedestroy($image); - $retvars = $this->_parsejpeg($tempname); - // tidy up by removing temporary image - unlink($tempname); - return $retvars; - } - - /** - * Convert the loaded image to a PNG and then return a structure for the PDF creator. - * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant. - * @param $image (image) Image object. - * return image PNG image object. - * @protected - * @since 4.9.016 (2010-04-20) - */ - protected function _toPNG($image) { - // set temporary image file name - $tempname = tempnam(K_PATH_CACHE, 'jpg_'); - // turn off interlaced mode - imageinterlace($image, 0); - // create temporary PNG image - imagepng($image, $tempname); - // remove image from memory - imagedestroy($image); - // get PNG image data - $retvars = $this->_parsepng($tempname); - // tidy up by removing temporary image - unlink($tempname); - return $retvars; - } - - /** - * Set the transparency for the given GD image. - * @param $new_image (image) GD image object - * @param $image (image) GD image object. - * return GD image object. - * @protected - * @since 4.9.016 (2010-04-20) - */ - protected function _setGDImageTransparency($new_image, $image) { - // transparency index - $tid = imagecolortransparent($image); - // default transparency color - $tcol = array('red' => 255, 'green' => 255, 'blue' => 255); - if ($tid >= 0) { - // get the colors for the transparency index - $tcol = imagecolorsforindex($image, $tid); - } - $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']); - imagefill($new_image, 0, 0, $tid); - imagecolortransparent($new_image, $tid); - return $new_image; - } - - /** - * Extract info from a JPEG file without using the GD library. - * @param $file (string) image file to parse - * @return array structure containing the image data - * @protected - */ - protected function _parsejpeg($file) { - $a = getimagesize($file); - if (empty($a)) { - $this->Error('Missing or incorrect image file: '.$file); - } - if ($a[2] != 2) { - $this->Error('Not a JPEG file: '.$file); - } - // bits per pixel - $bpc = isset($a['bits']) ? intval($a['bits']) : 8; - // number of image channels - if (!isset($a['channels'])) { - $channels = 3; - } else { - $channels = intval($a['channels']); - } - // default colour space - switch ($channels) { - case 1: { - $colspace = 'DeviceGray'; - break; - } - case 3: { - $colspace = 'DeviceRGB'; - break; - } - case 4: { - $colspace = 'DeviceCMYK'; - break; - } - default: { - $channels = 3; - $colspace = 'DeviceRGB'; - break; - } - } - // get file content - $data = file_get_contents($file); - // check for embedded ICC profile - $icc = array(); - $offset = 0; - while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) { - // get ICC sequence length - $length = ($this->_getUSHORT($data, ($pos - 2)) - 16); - // marker sequence number - $msn = max(1, ord($data[($pos + 12)])); - // number of markers (total of APP2 used) - $nom = max(1, ord($data[($pos + 13)])); - // get sequence segment - $icc[($msn - 1)] = substr($data, ($pos + 14), $length); - // move forward to next sequence - $offset = ($pos + 14 + $length); - } - // order and compact ICC segments - if (count($icc) > 0) { - ksort($icc); - $icc = implode('', $icc); - if ((ord($icc{36}) != 0x61) or (ord($icc{37}) != 0x63) or (ord($icc{38}) != 0x73) or (ord($icc{39}) != 0x70)) { - // invalid ICC profile - $icc = false; - } - } else { - $icc = false; - } - return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data); - } - - /** - * Extract info from a PNG file without using the GD library. - * @param $file (string) image file to parse - * @return array structure containing the image data - * @protected - */ - protected function _parsepng($file) { - $f = fopen($file, 'rb'); - if ($f === false) { - $this->Error('Can\'t open image file: '.$file); - } - //Check signature - if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { - $this->Error('Not a PNG file: '.$file); - } - //Read header chunk - fread($f, 4); - if (fread($f, 4) != 'IHDR') { - $this->Error('Incorrect PNG file: '.$file); - } - $w = $this->_freadint($f); - $h = $this->_freadint($f); - $bpc = ord(fread($f, 1)); - if ($bpc > 8) { - //$this->Error('16-bit depth not supported: '.$file); - fclose($f); - return false; - } - $ct = ord(fread($f, 1)); - if ($ct == 0) { - $colspace = 'DeviceGray'; - } elseif ($ct == 2) { - $colspace = 'DeviceRGB'; - } elseif ($ct == 3) { - $colspace = 'Indexed'; - } else { - // alpha channel - fclose($f); - return 'pngalpha'; - } - if (ord(fread($f, 1)) != 0) { - //$this->Error('Unknown compression method: '.$file); - fclose($f); - return false; - } - if (ord(fread($f, 1)) != 0) { - //$this->Error('Unknown filter method: '.$file); - fclose($f); - return false; - } - if (ord(fread($f, 1)) != 0) { - //$this->Error('Interlacing not supported: '.$file); - fclose($f); - return false; - } - fread($f, 4); - $channels = ($ct == 2 ? 3 : 1); - $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>'; - //Scan chunks looking for palette, transparency and image data - $pal = ''; - $trns = ''; - $data = ''; - $icc = false; - do { - $n = $this->_freadint($f); - $type = fread($f, 4); - if ($type == 'PLTE') { - // read palette - $pal = $this->rfread($f, $n); - fread($f, 4); - } elseif ($type == 'tRNS') { - // read transparency info - $t = $this->rfread($f, $n); - if ($ct == 0) { - $trns = array(ord($t{1})); - } elseif ($ct == 2) { - $trns = array(ord($t{1}), ord($t{3}), ord($t{5})); - } else { - $pos = strpos($t, chr(0)); - if ($pos !== false) { - $trns = array($pos); - } - } - fread($f, 4); - } elseif ($type == 'IDAT') { - // read image data block - $data .= $this->rfread($f, $n); - fread($f, 4); - } elseif ($type == 'iCCP') { - // skip profile name - $len = 0; - while ((ord(fread($f, 1)) > 0) and ($len < 80)) { - ++$len; - } - // skip null separator - fread($f, 1); - // get compression method - if (ord(fread($f, 1)) != 0) { - //$this->Error('Unknown filter method: '.$file); - fclose($f); - return false; - } - // read ICC Color Profile - $icc = $this->rfread($f, ($n - $len - 2)); - // decompress profile - $icc = gzuncompress($icc); - fread($f, 4); - } elseif ($type == 'IEND') { - break; - } else { - $this->rfread($f, $n + 4); - } - } while ($n); - if (($colspace == 'Indexed') and (empty($pal))) { - //$this->Error('Missing palette in '.$file); - fclose($f); - return false; - } - fclose($f); - return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data); - } - - /** - * Binary-safe and URL-safe file read. - * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached. - * @param $handle (resource) - * @param $length (int) - * @return Returns the read string or FALSE in case of error. - * @author Nicola Asuni - * @protected - * @since 4.5.027 (2009-03-16) - */ - protected function rfread($handle, $length) { - $data = fread($handle, $length); - if ($data === false) { - return false; - } - $rest = $length - strlen($data); - if ($rest > 0) { - $data .= $this->rfread($handle, $rest); - } - return $data; - } - - /** - * Extract info from a PNG image with alpha channel using the GD library. + * Extract info from a PNG image with alpha channel using the Imagick or GD library. * @param $file (string) Name of the file containing the image. * @param $x (float) Abscissa of the upper-left corner. * @param $y (float) Ordinate of the upper-left corner. @@ -8598,17 +7258,16 @@ class TCPDF { * @see Image() */ protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') { + // create temp images if (empty($filehash)) { - $filehash = md5($this->file_id.$file); + $filehash = md5($file); } // create temp image file (without alpha channel) - $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; + $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash; // create temp alpha file - $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; - + $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash; $parsed = false; $parse_error = ''; - // ImageMagick extension if (($parsed === false) AND extension_loaded('imagick')) { try { @@ -8616,24 +7275,30 @@ class TCPDF { $img = new Imagick(); $img->readImage($file); // clone image object - $imga = $this->objclone($img); + $imga = TCPDF_STATIC::objclone($img); // extract alpha channel - $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE); - $img->negateImage(true); + if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) { + $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT); + } else { + $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE); + $img->negateImage(true); + } $img->setImageFormat('png'); $img->writeImage($tempfile_alpha); // remove alpha channel - $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE)); + if (method_exists($imga, 'setImageMatte')) { + $imga->setImageMatte(false); + } else { + $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE)); + } $imga->setImageFormat('png'); $imga->writeImage($tempfile_plain); - $parsed = true; } catch (Exception $e) { // Imagemagick fails, try with GD $parse_error = 'Imagick library error: '.$e->getMessage(); } } - // GD extension if (($parsed === false) AND function_exists('imagecreatefrompng')) { try { @@ -8648,7 +7313,8 @@ class TCPDF { for ($xpx = 0; $xpx < $wpx; ++$xpx) { for ($ypx = 0; $ypx < $hpx; ++$ypx) { $color = imagecolorat($img, $xpx, $ypx); - $alpha = $this->getGDgamma($color); // correct gamma + // get and correct gamma color + $alpha = $this->getGDgamma($img, $color); imagesetpixel($imgalpha, $xpx, $ypx, $alpha); } } @@ -8659,14 +7325,12 @@ class TCPDF { imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx); imagepng($imgplain, $tempfile_plain); imagedestroy($imgplain); - $parsed = true; } catch (Exception $e) { // GD fails $parse_error = 'GD library error: '.$e->getMessage(); } } - if ($parsed === false) { if (empty($parse_error)) { $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.'); @@ -8674,38 +7338,33 @@ class TCPDF { $this->Error($parse_error); } } - // embed mask image $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false); // embed image, masked with previously embedded mask $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask); - // remove temp files - unlink($tempfile_alpha); - unlink($tempfile_plain); } /** * Get the GD-corrected PNG gamma value from alpha color + * @param $img (int) GD image Resource ID. * @param $c (int) alpha color * @protected * @since 4.3.007 (2008-12-04) */ - protected function getGDgamma($c) { - if (!isset($this->gdgammacache["'".$c."'"])) { - // shifts off the first 24 bits (where 8x3 are used for each color), - // and returns the remaining 7 allocated bits (commonly used for alpha) - $alpha = ($c >> 24); + protected function getGDgamma($img, $c) { + if (!isset($this->gdgammacache['#'.$c])) { + $colors = imagecolorsforindex($img, $c); // GD alpha is only 7 bit (0 -> 127) - $alpha = (((127 - $alpha) / 127) * 255); + $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255); // correct gamma - $this->gdgammacache["'".$c."'"] = (pow(($alpha / 255), 2.2) * 255); + $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255); // store the latest values on cache to improve performances if (count($this->gdgammacache) > 8) { // remove one element from the cache array array_shift($this->gdgammacache); } } - return $this->gdgammacache["'".$c."'"]; + return $this->gdgammacache['#'.$c]; } /** @@ -8718,7 +7377,7 @@ class TCPDF { * @see Cell() */ public function Ln($h='', $cell=false) { - if (($this->num_columns > 1) and ($this->y == $this->columns[$this->current_column]['y']) and isset($this->columns[$this->current_column]['x']) and ($this->x == $this->columns[$this->current_column]['x'])) { + if (($this->num_columns > 1) AND ($this->y == $this->columns[$this->current_column]['y']) AND isset($this->columns[$this->current_column]['x']) AND ($this->x == $this->columns[$this->current_column]['x'])) { // revove vertical space from the top of the column return; } @@ -8737,10 +7396,9 @@ class TCPDF { $this->x = $this->lMargin + $cellpadding; } if (is_string($h)) { - $this->y += $this->lasth; - } else { - $this->y += $h; + $h = $this->lasth; } + $this->y += $h; $this->newline = true; } @@ -8786,14 +7444,15 @@ class TCPDF { /** * Defines the abscissa of the current position. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL). - * @param $x (float) The value of the abscissa. + * @param $x (float) The value of the abscissa in user units. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis. * @public * @since 1.2 * @see GetX(), GetY(), SetY(), SetXY() */ public function SetX($x, $rtloff=false) { - if (!$rtloff and $this->rtl) { + $x = floatval($x); + if (!$rtloff AND $this->rtl) { if ($x >= 0) { $this->x = $this->w - $x; } else { @@ -8817,7 +7476,7 @@ class TCPDF { /** * Moves the current abscissa back to the left margin and sets the ordinate. * If the passed value is negative, it is relative to the bottom of the page. - * @param $y (float) The value of the ordinate. + * @param $y (float) The value of the ordinate in user units. * @param $resetx (bool) if true (default) reset the X position. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis. * @public @@ -8825,9 +7484,10 @@ class TCPDF { * @see GetX(), GetY(), SetY(), SetXY() */ public function SetY($y, $resetx=true, $rtloff=false) { + $y = floatval($y); if ($resetx) { //reset x - if (!$rtloff and $this->rtl) { + if (!$rtloff AND $this->rtl) { $this->x = $this->w - $this->rMargin; } else { $this->x = $this->lMargin; @@ -8862,18 +7522,38 @@ class TCPDF { } /** - * Ouput input data and compress it if possible. - * @param $data (string) Data to output. - * @param $length (int) Data length in bytes. - * @protected - * @since 5.9.086 + * Set the absolute X coordinate of the current pointer. + * @param $x (float) The value of the abscissa in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() */ - protected function sendOutputData($data, $length) { - if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) or empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { - // the content length may vary if the server is using compression - header('Content-Length: '.$length); - } - echo $data; + public function SetAbsX($x) { + $this->x = floatval($x); + } + + /** + * Set the absolute Y coordinate of the current pointer. + * @param $y (float) (float) The value of the ordinate in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() + */ + public function SetAbsY($y) { + $this->y = floatval($y); + } + + /** + * Set the absolute X and Y coordinates of the current pointer. + * @param $x (float) The value of the abscissa in user units. + * @param $y (float) (float) The value of the ordinate in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() + */ + public function SetAbsXY($x, $y) { + $this->SetAbsX($x); + $this->SetAbsY($y); } /** @@ -8882,6 +7562,7 @@ class TCPDF { * The method first calls Close() if necessary to terminate the document. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character. * @param $dest (string) Destination where to send the document. It can take one of the following values:
        • I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
        • D: send to the browser and force a file download with the name given by name.
        • F: save to a local server file with the name given by name.
        • S: return the document as a string (name is ignored).
        • FI: equivalent to F + I option
        • FD: equivalent to F + D option
        • E: return the document as base64 mime multi-part email attachment (RFC 2045)
        + * @return string * @public * @since 1.0 * @see Close() @@ -8897,7 +7578,7 @@ class TCPDF { $dest = $dest ? 'D' : 'F'; } $dest = strtoupper($dest); - if ($dest{0} != 'F') { + if ($dest[0] != 'F') { $name = preg_replace('/[\s]+/', '_', $name); $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name); } @@ -8907,28 +7588,22 @@ class TCPDF { $pdfdoc = $this->getBuffer(); // remove last newline $pdfdoc = substr($pdfdoc, 0, -1); - // Remove the original buffer - if (isset($this->diskcache) and $this->diskcache) { - // remove buffer file from cache - unlink($this->buffer); - } - unset($this->buffer); // remove filler space - $byterange_string_len = strlen($this->byterange_string); + $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string); // define the ByteRange $byte_range = array(); $byte_range[0] = 0; - $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10; + $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10; $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2; $byte_range[3] = strlen($pdfdoc) - $byte_range[2]; $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]); // replace the ByteRange $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]); $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange))); - $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc); + $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc); // write the document to a temporary folder - $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_'); - $f = fopen($tempdoc, 'wb'); + $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id); + $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb'); if (!$f) { $this->Error('Unable to create temporary file: '.$tempdoc); } @@ -8936,29 +7611,26 @@ class TCPDF { fwrite($f, $pdfdoc, $pdfdoc_length); fclose($f); // get digital signature via openssl library - $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_'); + $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id); if (empty($this->signature_data['extracerts'])) { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED); } else { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']); } - unlink($tempdoc); // read signature $signature = file_get_contents($tempsign); - unlink($tempsign); // extract signature $signature = substr($signature, $pdfdoc_length); $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13)); $tmparr = explode("\n\n", $signature); $signature = $tmparr[1]; - unset($tmparr); // decode signature $signature = base64_decode(trim($signature)); + // add TSA timestamp to signature + $signature = $this->applyTSA($signature); // convert signature to hex $signature = current(unpack('H*', $signature)); $signature = str_pad($signature, $this->signature_max_length, '0'); - // disable disk caching - $this->diskcache = false; // Add signature to the document $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]); $this->bufferlen = strlen($this->buffer); @@ -8981,7 +7653,7 @@ class TCPDF { header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.basename($name).'"'); - $this->sendOutputData($this->getBuffer(), $this->bufferlen); + TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); } else { echo $this->getBuffer(); } @@ -9013,23 +7685,19 @@ class TCPDF { // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="'.basename($name).'"'); header('Content-Transfer-Encoding: binary'); - $this->sendOutputData($this->getBuffer(), $this->bufferlen); + TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); break; } case 'F': case 'FI': case 'FD': { // save PDF to a local file - if ($this->diskcache) { - copy($this->buffer, $name); - } else { - $f = fopen($name, 'wb'); - if (!$f) { - $this->Error('Unable to create output file: '.$name); - } - fwrite($f, $this->getBuffer(), $this->bufferlen); - fclose($f); + $f = TCPDF_STATIC::fopenLocal($name, 'wb'); + if (!$f) { + $this->Error('Unable to create output file: '.$name); } + fwrite($f, $this->getBuffer(), $this->bufferlen); + fclose($f); if ($dest == 'FI') { // send headers to browser header('Content-Type: application/pdf'); @@ -9039,7 +7707,7 @@ class TCPDF { header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.basename($name).'"'); - $this->sendOutputData(file_get_contents($name), filesize($name)); + TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name)); } elseif ($dest == 'FD') { // send headers to browser if (ob_get_contents()) { @@ -9065,7 +7733,7 @@ class TCPDF { // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="'.basename($name).'"'); header('Content-Transfer-Encoding: binary'); - $this->sendOutputData(file_get_contents($name), filesize($name)); + TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name)); } break; } @@ -9090,31 +7758,59 @@ class TCPDF { return ''; } + protected static $cleaned_ids = array(); /** - * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache. + * Unset all class variables except the following critical variables. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable * @public * @since 4.5.016 (2009-02-24) */ public function _destroy($destroyall=false, $preserve_objcopy=false) { - if ($destroyall and isset($this->diskcache) and $this->diskcache and (!$preserve_objcopy) and (!$this->empty_string($this->buffer))) { - // remove buffer file from cache - unlink($this->buffer); + // restore internal encoding + if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) { + mb_internal_encoding($this->internal_encoding); } + if (isset(self::$cleaned_ids[$this->file_id])) { + $destroyall = false; + } + if ($destroyall AND !$preserve_objcopy) { + self::$cleaned_ids[$this->file_id] = true; + // remove all temporary files + if ($handle = @opendir(K_PATH_CACHE)) { + while ( false !== ( $file_name = readdir( $handle ) ) ) { + if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) { + unlink(K_PATH_CACHE.$file_name); + } + } + closedir($handle); + } + if (isset($this->imagekeys)) { + foreach($this->imagekeys as $file) { + if (strpos($file, K_PATH_CACHE) === 0) { + @unlink($file); + } + } + } + } + $preserve = array( + 'file_id', + 'internal_encoding', + 'state', + 'bufferlen', + 'buffer', + 'cached_files', + 'imagekeys', + 'sign', + 'signature_data', + 'signature_max_length', + 'byterange_string', + 'tsa_timestamp', + 'tsa_data' + ); foreach (array_keys(get_object_vars($this)) as $val) { - if ($destroyall or ( - ($val != 'internal_encoding') - and ($val != 'state') - and ($val != 'bufferlen') - and ($val != 'buffer') - and ($val != 'diskcache') - and ($val != 'sign') - and ($val != 'signature_data') - and ($val != 'signature_max_length') - and ($val != 'byterange_string') - )) { - if ((!$preserve_objcopy or ($val != 'objcopy')) and isset($this->$val)) { + if ($destroyall OR !in_array($val, $preserve)) { + if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) { unset($this->$val); } } @@ -9136,18 +7832,6 @@ class TCPDF { } } - /** - * Return fonts path - * @return string - * @protected - */ - protected function _getfontpath() { - if (!defined('K_PATH_FONTS') and is_dir(dirname(__FILE__).'/fonts')) { - define('K_PATH_FONTS', dirname(__FILE__).'/fonts/'); - } - return defined('K_PATH_FONTS') ? K_PATH_FONTS : ''; - } - /** * Return an array containing variations for the basic page number alias. * @param $a (string) Base alias. @@ -9159,14 +7843,14 @@ class TCPDF { // build array of Unicode + ASCII variants (the order is important) $alias = array('u' => array(), 'a' => array()); $u = '{'.$a.'}'; - $alias['u'][] = $this->_escape($u); + $alias['u'][] = TCPDF_STATIC::_escape($u); if ($this->isunicode) { - $alias['u'][] = $this->_escape($this->UTF8ToLatin1($u)); - $alias['u'][] = $this->_escape($this->utf8StrRev($u, false, $this->tmprtl)); - $alias['a'][] = $this->_escape($this->UTF8ToLatin1($a)); - $alias['a'][] = $this->_escape($this->utf8StrRev($a, false, $this->tmprtl)); + $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont)); + $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont)); + $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont)); + $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont)); } - $alias['a'][] = $this->_escape($a); + $alias['a'][] = TCPDF_STATIC::_escape($a); return $alias; } @@ -9176,7 +7860,7 @@ class TCPDF { * @protected */ protected function getAllInternalPageNumberAliases() { - $basic_alias = array($this->alias_tot_pages, $this->alias_num_page, $this->alias_group_tot_pages, $this->alias_group_num_page, $this->alias_right_shift); + $basic_alias = array(TCPDF_STATIC::$alias_tot_pages, TCPDF_STATIC::$alias_num_page, TCPDF_STATIC::$alias_group_tot_pages, TCPDF_STATIC::$alias_group_num_page, TCPDF_STATIC::$alias_right_shift); $pnalias = array(); foreach($basic_alias as $k => $a) { $pnalias[$k] = $this->getInternalPageNumberAliases($a); @@ -9184,26 +7868,6 @@ class TCPDF { return $pnalias; } - /** - * Replace page number aliases with number. - * @param $page (string) Page content. - * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays). - * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements. - * @return replaced page content and updated $diff parameter as array. - * @protected - */ - protected function replacePageNumAliases($page, $replace, $diff=0) { - foreach ($replace as $rep) { - foreach ($rep[3] as $a) { - if (strpos($page, $a) !== false) { - $page = str_replace($a, $rep[0], $page); - $diff += ($rep[2] - $rep[1]); - } - } - } - return array($page, $diff); - } - /** * Replace right shift page number aliases with spaces to correct right alignment. * This works perfectly only when using monospaced fonts. @@ -9231,7 +7895,7 @@ class TCPDF { if ($type == 'u') { $chrdiff = floor(($diff + 12) * $ratio); $shift = str_repeat(' ', $chrdiff); - $shift = $this->UTF8ToUTF16BE($shift, false); + $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont); } else { $chrdiff = floor(($diff + 11) * $ratio); $shift = str_repeat(' ', $chrdiff); @@ -9249,10 +7913,9 @@ class TCPDF { * @protected */ protected function setPageBoxTypes($boxes) { - $validboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); $this->page_boxes = array(); foreach ($boxes as $box) { - if (in_array($box, $validboxes)) { + if (in_array($box, TCPDF_STATIC::$pageboxes)) { $this->page_boxes[] = $box; } } @@ -9267,20 +7930,21 @@ class TCPDF { // get internal aliases for page numbers $pnalias = $this->getAllInternalPageNumberAliases(); $num_pages = $this->numpages; - $ptpa = $this->formatPageNumber(($this->starting_page_number + $num_pages - 1)); - $ptpu = $this->UTF8ToUTF16BE($ptpa, false); + $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1)); + $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont); $ptp_num_chars = $this->GetNumChars($ptpa); $pagegroupnum = 0; $groupnum = 0; $ptgu = 1; $ptga = 1; + $ptg_num_chars = 1; for ($n = 1; $n <= $num_pages; ++$n) { // get current page $temppage = $this->getPageBuffer($n); $pagelen = strlen($temppage); // set replacements for total pages number - $pnpa = $this->formatPageNumber(($this->starting_page_number + $n - 1)); - $pnpu = $this->UTF8ToUTF16BE($pnpa, false); + $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1)); + $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont); $pnp_num_chars = $this->GetNumChars($pnpa); $pdiff = 0; // difference used for right shift alignment of page numbers $gdiff = 0; // difference used for right shift alignment of page group numbers @@ -9288,13 +7952,13 @@ class TCPDF { if (isset($this->newpagegroup[$n])) { $pagegroupnum = 0; ++$groupnum; - $ptga = $this->formatPageNumber($this->pagegroups[$groupnum]); - $ptgu = $this->UTF8ToUTF16BE($ptga, false); + $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]); + $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont); $ptg_num_chars = $this->GetNumChars($ptga); } ++$pagegroupnum; - $pnga = $this->formatPageNumber($pagegroupnum); - $pngu = $this->UTF8ToUTF16BE($pnga, false); + $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum); + $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont); $png_num_chars = $this->GetNumChars($pnga); // replace page numbers $replace = array(); @@ -9302,7 +7966,7 @@ class TCPDF { $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']); $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']); $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']); - list($temppage, $gdiff) = $this->replacePageNumAliases($temppage, $replace, $gdiff); + list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff); } // replace page numbers $replace = array(); @@ -9310,7 +7974,7 @@ class TCPDF { $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']); $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']); $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']); - list($temppage, $pdiff) = $this->replacePageNumAliases($temppage, $replace, $pdiff); + list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff); // replace right shift alias $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff)); // replace EPS marker @@ -9320,13 +7984,15 @@ class TCPDF { $out = '<<'; $out .= ' /Type /Page'; $out .= ' /Parent 1 0 R'; - $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp); + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp); + } $out .= ' /Resources 2 0 R'; foreach ($this->page_boxes as $box) { $out .= ' /'.$box; $out .= sprintf(' [%F %F %F %F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']); } - if (isset($this->pagedim[$n]['BoxColorInfo']) and !empty($this->pagedim[$n]['BoxColorInfo'])) { + if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) { $out .= ' /BoxColorInfo <<'; foreach ($this->page_boxes as $box) { if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) { @@ -9361,7 +8027,7 @@ class TCPDF { if (!$this->pdfa_mode) { $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>'; } - if (isset($this->pagedim[$n]['trans']) and !empty($this->pagedim[$n]['trans'])) { + if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) { // page transitions if (isset($this->pagedim[$n]['trans']['Dur'])) { $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur']; @@ -9401,10 +8067,6 @@ class TCPDF { $this->_newobj(); $p = $this->_getrawstream($p); $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj'); - if ($this->diskcache) { - // remove temporary files - unlink($this->pages[$n]); - } } //Pages root $out = $this->_getobj(1)."\n"; @@ -9417,18 +8079,6 @@ class TCPDF { $this->_out($out); } - /** - * Output references to page annotations - * @param $n (int) page number - * @protected - * @author Nicola Asuni - * @since 4.7.000 (2008-08-29) - * @deprecated - */ - protected function _putannotsrefs($n) { - $this->_out($this->_getannotsrefs($n)); - } - /** * Get references to page annotations. * @param $n (int) page number @@ -9438,7 +8088,7 @@ class TCPDF { * @since 5.0.010 (2010-05-17) */ protected function _getannotsrefs($n) { - if (!(isset($this->PageAnnots[$n]) or ($this->sign and isset($this->signature_data['cert_type'])))) { + if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) { return ''; } $out = ' /Annots ['; @@ -9457,7 +8107,7 @@ class TCPDF { } } } - if ($this->sign and ($n == $this->signature_appearance['page']) and isset($this->signature_data['cert_type'])) { + if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) { // set reference for signature object $out .= ' '.$this->sig_obj_id.' 0 R'; } @@ -9489,7 +8139,7 @@ class TCPDF { foreach ($this->PageAnnots[$n] as $key => $pl) { $annot_obj_id = $this->PageAnnots[$n][$key]['n']; // create annotation object for grouping radiobuttons - if (isset($this->radiobutton_groups[$n][$pl['txt']]) and is_array($this->radiobutton_groups[$n][$pl['txt']])) { + if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) { $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n']; $annots = '<<'; $annots .= ' /Type /Annot'; @@ -9504,6 +8154,9 @@ class TCPDF { $annots .= ' /Ff 49152'; } $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id); + if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) { + $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id); + } $annots .= ' /FT /Btn'; $annots .= ' /Kids ['; $defval = ''; @@ -9537,11 +8190,13 @@ class TCPDF { $annots .= ' /Subtype /'.$pl['opt']['subtype']; $annots .= ' /Rect ['.$rect.']'; $ft = array('Btn', 'Tx', 'Ch', 'Sig'); - if (isset($pl['opt']['ft']) and in_array($pl['opt']['ft'], $ft)) { + if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) { $annots .= ' /FT /'.$pl['opt']['ft']; $formfield = true; } - $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id); + if ($pl['opt']['subtype'] !== 'Link') { + $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id); + } $annots .= ' /P '.$this->page_obj_id[$n].' 0 R'; $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id); $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp); @@ -9606,7 +8261,7 @@ class TCPDF { $fval |= 4; } $annots .= ' /F '.intval($fval); - if (isset($pl['opt']['as']) and is_string($pl['opt']['as'])) { + if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) { $annots .= ' /AS /'.$pl['opt']['as']; } if (isset($pl['opt']['ap'])) { @@ -9635,17 +8290,17 @@ class TCPDF { } $annots .= ' >>'; } - if (isset($pl['opt']['bs']) and (is_array($pl['opt']['bs']))) { + if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) { $annots .= ' /BS <<'; $annots .= ' /Type /Border'; if (isset($pl['opt']['bs']['w'])) { $annots .= ' /W '.intval($pl['opt']['bs']['w']); } $bstyles = array('S', 'D', 'B', 'I', 'U'); - if (isset($pl['opt']['bs']['s']) and in_array($pl['opt']['bs']['s'], $bstyles)) { + if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) { $annots .= ' /S /'.$pl['opt']['bs']['s']; } - if (isset($pl['opt']['bs']['d']) and (is_array($pl['opt']['bs']['d']))) { + if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) { $annots .= ' /D ['; foreach ($pl['opt']['bs']['d'] as $cord) { $annots .= ' '.intval($cord); @@ -9655,11 +8310,11 @@ class TCPDF { $annots .= ' >>'; } else { $annots .= ' /Border ['; - if (isset($pl['opt']['border']) and (count($pl['opt']['border']) >= 3)) { + if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) { $annots .= intval($pl['opt']['border'][0]).' '; $annots .= intval($pl['opt']['border'][1]).' '; $annots .= intval($pl['opt']['border'][2]); - if (isset($pl['opt']['border'][3]) and is_array($pl['opt']['border'][3])) { + if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) { $annots .= ' ['; foreach ($pl['opt']['border'][3] as $dash) { $annots .= intval($dash).' '; @@ -9671,28 +8326,28 @@ class TCPDF { } $annots .= ']'; } - if (isset($pl['opt']['be']) and (is_array($pl['opt']['be']))) { + if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) { $annots .= ' /BE <<'; $bstyles = array('S', 'C'); - if (isset($pl['opt']['be']['s']) and in_array($pl['opt']['be']['s'], $bstyles)) { + if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) { $annots .= ' /S /'.$pl['opt']['bs']['s']; } else { $annots .= ' /S /S'; } - if (isset($pl['opt']['be']['i']) and ($pl['opt']['be']['i'] >= 0) and ($pl['opt']['be']['i'] <= 2)) { + if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) { $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']); } $annots .= '>>'; } - if (isset($pl['opt']['c']) and (is_array($pl['opt']['c'])) and !empty($pl['opt']['c'])) { - $annots .= ' /C '.$this->getColorStringFromArray($pl['opt']['c']); + if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) { + $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']); } //$annots .= ' /StructParent '; //$annots .= ' /OC '; $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound'); if (in_array(strtolower($pl['opt']['subtype']), $markups)) { // this is a markup type - if (isset($pl['opt']['t']) and is_string($pl['opt']['t'])) { + if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id); } //$annots .= ' /Popup '; @@ -9719,13 +8374,13 @@ class TCPDF { $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false'); } $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); - if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp)) { + if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { $annots .= ' /Name /'.$pl['opt']['name']; } else { $annots .= ' /Name /Note'; } $statemodels = array('Marked', 'Review'); - if (isset($pl['opt']['statemodel']) and in_array($pl['opt']['statemodel'], $statemodels)) { + if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) { $annots .= ' /StateModel /'.$pl['opt']['statemodel']; } else { $pl['opt']['statemodel'] = 'Marked'; @@ -9736,7 +8391,7 @@ class TCPDF { } else { $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None'); } - if (isset($pl['opt']['state']) and in_array($pl['opt']['state'], $states)) { + if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) { $annots .= ' /State /'.$pl['opt']['state']; } else { if ($pl['opt']['statemodel'] == 'Marked') { @@ -9748,20 +8403,44 @@ class TCPDF { break; } case 'link': { - if (is_string($pl['txt'])) { - // external URI link - $annots .= ' /A <_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>'; - } else { - // internal link - if (isset($this->links[$pl['txt']])) { - $l = $this->links[$pl['txt']]; - if (isset($this->page_obj_id[($l[0])])) { - $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k))); + if (is_string($pl['txt']) && !empty($pl['txt'])) { + if ($pl['txt'][0] == '#') { + // internal destination + $annots .= ' /A <>'; + } elseif ($pl['txt'][0] == '%') { + // embedded PDF file + $filename = basename(substr($pl['txt'], 1)); + $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>'; + } elseif ($pl['txt'][0] == '*') { + // embedded generic file + $filename = basename(substr($pl['txt'], 1)); + $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});'; + $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>'; + } else { + $parsedUrl = parse_url($pl['txt']); + if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) { + // relative link to a PDF file + $dest = '[0 /Fit]'; // default page 0 + if (!empty($parsedUrl['fragment'])) { + // check for named destination + $tmp = explode('=', $parsedUrl['fragment']); + $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')'; + } + $annots .= ' /A <_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>'; + } else { + // external URI link + $annots .= ' /A <_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>'; } } + } elseif (isset($this->links[$pl['txt']])) { + // internal link ID + $l = $this->links[$pl['txt']]; + if (isset($this->page_obj_id[($l['p'])])) { + $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k))); + } } $hmodes = array('N', 'I', 'O', 'P'); - if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmodes)) { + if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) { $annots .= ' /H /'.$pl['opt']['h']; } else { $annots .= ' /H /I'; @@ -9771,10 +8450,10 @@ class TCPDF { break; } case 'freetext': { - if (isset($pl['opt']['da']) and !empty($pl['opt']['da'])) { + if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) { $annots .= ' /DA ('.$pl['opt']['da'].')'; } - if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2)) { + if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) { $annots .= ' /Q '.intval($pl['opt']['q']); } if (isset($pl['opt']['rc'])) { @@ -9783,7 +8462,7 @@ class TCPDF { if (isset($pl['opt']['ds'])) { $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id); } - if (isset($pl['opt']['cl']) and is_array($pl['opt']['cl'])) { + if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) { $annots .= ' /CL ['; foreach ($pl['opt']['cl'] as $cl) { $annots .= sprintf('%F ', $cl * $this->k); @@ -9791,17 +8470,17 @@ class TCPDF { $annots .= ']'; } $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter'); - if (isset($pl['opt']['it']) and in_array($pl['opt']['it'], $tfit)) { + if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) { $annots .= ' /IT /'.$pl['opt']['it']; } - if (isset($pl['opt']['rd']) and is_array($pl['opt']['rd'])) { + if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) { $l = $pl['opt']['rd'][0] * $this->k; $r = $pl['opt']['rd'][1] * $this->k; $t = $pl['opt']['rd'][2] * $this->k; $b = $pl['opt']['rd'][3] * $this->k; $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']'; } - if (isset($pl['opt']['le']) and in_array($pl['opt']['le'], $lineendings)) { + if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) { $annots .= ' /LE /'.$pl['opt']['le']; } break; @@ -9846,22 +8525,24 @@ class TCPDF { break; } case 'fileattachment': { - if ($this->pdfa_mode) { - // embedded files are not allowed in PDF/A mode + if ($this->pdfa_mode && $this->pdfa_version != 3) { + // embedded files are not allowed in PDF/A mode version 1 and 2 break; } if (!isset($pl['opt']['fs'])) { break; } $filename = basename($pl['opt']['fs']); - if (isset($this->embeddedfiles[$filename]['n'])) { - $annots .= ' /FS <_datastring($filename, $annot_obj_id).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; + if (isset($this->embeddedfiles[$filename]['f'])) { + $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R'; $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag'); - if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp)) { + if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { $annots .= ' /Name /'.$pl['opt']['name']; } else { $annots .= ' /Name /PushPin'; } + // index (zero-based) of the annotation in the Annots array of this page + $this->embeddedfiles[$filename]['a'] = $key; } break; } @@ -9870,12 +8551,12 @@ class TCPDF { break; } $filename = basename($pl['opt']['fs']); - if (isset($this->embeddedfiles[$filename]['n'])) { + if (isset($this->embeddedfiles[$filename]['f'])) { // ... TO BE COMPLETED ... // /R /C /B /E /CO /CP - $annots .= ' /Sound <_datastring($filename, $annot_obj_id).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; + $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R'; $iconsapp = array('Speaker', 'Mic'); - if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp)) { + if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { $annots .= ' /Name /'.$pl['opt']['name']; } else { $annots .= ' /Name /Speaker'; @@ -9888,19 +8569,19 @@ class TCPDF { } case 'widget': { $hmode = array('N', 'I', 'O', 'P', 'T'); - if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmode)) { + if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) { $annots .= ' /H /'.$pl['opt']['h']; } - if (isset($pl['opt']['mk']) and (is_array($pl['opt']['mk'])) and !empty($pl['opt']['mk'])) { + if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) { $annots .= ' /MK <<'; if (isset($pl['opt']['mk']['r'])) { $annots .= ' /R '.$pl['opt']['mk']['r']; } - if (isset($pl['opt']['mk']['bc']) and (is_array($pl['opt']['mk']['bc']))) { - $annots .= ' /BC '.$this->getColorStringFromArray($pl['opt']['mk']['bc']); + if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) { + $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']); } - if (isset($pl['opt']['mk']['bg']) and (is_array($pl['opt']['mk']['bg']))) { - $annots .= ' /BG '.$this->getColorStringFromArray($pl['opt']['mk']['bg']); + if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) { + $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']); } if (isset($pl['opt']['mk']['ca'])) { $annots .= ' /CA '.$pl['opt']['mk']['ca']; @@ -9929,25 +8610,25 @@ class TCPDF { $annots .= ' /IX '.$info['n'].' 0 R'; } } - if (isset($pl['opt']['mk']['if']) and (is_array($pl['opt']['mk']['if'])) and !empty($pl['opt']['mk']['if'])) { + if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) { $annots .= ' /IF <<'; $if_sw = array('A', 'B', 'S', 'N'); - if (isset($pl['opt']['mk']['if']['sw']) and in_array($pl['opt']['mk']['if']['sw'], $if_sw)) { + if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) { $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw']; } $if_s = array('A', 'P'); - if (isset($pl['opt']['mk']['if']['s']) and in_array($pl['opt']['mk']['if']['s'], $if_s)) { + if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) { $annots .= ' /S /'.$pl['opt']['mk']['if']['s']; } - if (isset($pl['opt']['mk']['if']['a']) and (is_array($pl['opt']['mk']['if']['a'])) and !empty($pl['opt']['mk']['if']['a'])) { + if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) { $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]); } - if (isset($pl['opt']['mk']['if']['fb']) and ($pl['opt']['mk']['if']['fb'])) { + if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) { $annots .= ' /FB true'; } $annots .= '>>'; } - if (isset($pl['opt']['mk']['tp']) and ($pl['opt']['mk']['tp'] >= 0) and ($pl['opt']['mk']['tp'] <= 6)) { + if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) { $annots .= ' /TP '.intval($pl['opt']['mk']['tp']); } $annots .= '>>'; @@ -9957,13 +8638,13 @@ class TCPDF { // set parent $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R'; } - if (isset($pl['opt']['t']) and is_string($pl['opt']['t'])) { + if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id); } - if (isset($pl['opt']['tu']) and is_string($pl['opt']['tu'])) { + if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) { $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id); } - if (isset($pl['opt']['tm']) and is_string($pl['opt']['tm'])) { + if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) { $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id); } if (isset($pl['opt']['ff'])) { @@ -9984,7 +8665,7 @@ class TCPDF { if (isset($pl['opt']['v'])) { $annots .= ' /V'; if (is_array($pl['opt']['v'])) { - foreach ($pl['opt']['v'] as $optval) { + foreach ($pl['opt']['v'] AS $optval) { if (is_float($optval)) { $optval = sprintf('%F', $optval); } @@ -9997,7 +8678,7 @@ class TCPDF { if (isset($pl['opt']['dv'])) { $annots .= ' /DV'; if (is_array($pl['opt']['dv'])) { - foreach ($pl['opt']['dv'] as $optval) { + foreach ($pl['opt']['dv'] AS $optval) { if (is_float($optval)) { $optval = sprintf('%F', $optval); } @@ -10010,7 +8691,7 @@ class TCPDF { if (isset($pl['opt']['rv'])) { $annots .= ' /RV'; if (is_array($pl['opt']['rv'])) { - foreach ($pl['opt']['rv'] as $optval) { + foreach ($pl['opt']['rv'] AS $optval) { if (is_float($optval)) { $optval = sprintf('%F', $optval); } @@ -10020,21 +8701,21 @@ class TCPDF { $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id); } } - if (isset($pl['opt']['a']) and !empty($pl['opt']['a'])) { + if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) { $annots .= ' /A << '.$pl['opt']['a'].' >>'; } - if (isset($pl['opt']['aa']) and !empty($pl['opt']['aa'])) { + if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) { $annots .= ' /AA << '.$pl['opt']['aa'].' >>'; } - if (isset($pl['opt']['da']) and !empty($pl['opt']['da'])) { + if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) { $annots .= ' /DA ('.$pl['opt']['da'].')'; } - if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2)) { + if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) { $annots .= ' /Q '.intval($pl['opt']['q']); } - if (isset($pl['opt']['opt']) and (is_array($pl['opt']['opt'])) and !empty($pl['opt']['opt'])) { + if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) { $annots .= ' /Opt ['; - foreach($pl['opt']['opt'] as $copt) { + foreach($pl['opt']['opt'] AS $copt) { if (is_array($copt)) { $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']'; } else { @@ -10046,9 +8727,9 @@ class TCPDF { if (isset($pl['opt']['ti'])) { $annots .= ' /TI '.intval($pl['opt']['ti']); } - if (isset($pl['opt']['i']) and (is_array($pl['opt']['i'])) and !empty($pl['opt']['i'])) { + if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) { $annots .= ' /I ['; - foreach($pl['opt']['i'] as $copt) { + foreach($pl['opt']['i'] AS $copt) { $annots .= intval($copt).' '; } $annots .= ']'; @@ -10077,7 +8758,7 @@ class TCPDF { $annots .= '>>'; // create new annotation object $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj'); - if ($formfield and !isset($this->radiobutton_groups[$n][$pl['txt']])) { + if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) { // store reference of form object $this->form_obj_id[] = $annot_obj_id; } @@ -10120,1530 +8801,6 @@ class TCPDF { return $this->n; } - /** - * Get ULONG from string (Big Endian 32-bit unsigned integer). - * @param $str (string) string from where to extract value - * @param $offset (int) point from where to read the data - * @return int 32 bit value - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getULONG($str, $offset) { - $v = unpack('Ni', substr($str, $offset, 4)); - return $v['i']; - } - - /** - * Get USHORT from string (Big Endian 16-bit unsigned integer). - * @param $str (string) string from where to extract value - * @param $offset (int) point from where to read the data - * @return int 16 bit value - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getUSHORT($str, $offset) { - $v = unpack('ni', substr($str, $offset, 2)); - return $v['i']; - } - - /** - * Get SHORT from string (Big Endian 16-bit signed integer). - * @param $str (string) String from where to extract value. - * @param $offset (int) Point from where to read the data. - * @return int 16 bit value - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getSHORT($str, $offset) { - $v = unpack('si', substr($str, $offset, 2)); - return $v['i']; - } - - /** - * Get FWORD from string (Big Endian 16-bit signed integer). - * @param $str (string) String from where to extract value. - * @param $offset (int) Point from where to read the data. - * @return int 16 bit value - * @author Nicola Asuni - * @protected - * @since 5.9.123 (2011-09-30) - */ - protected function _getFWORD($str, $offset) { - $v = $this->_getUSHORT($str, $offset); - if ($v > 0x7fff) { - $v -= 0x10000; - } - return $v; - } - - /** - * Get UFWORD from string (Big Endian 16-bit unsigned integer). - * @param $str (string) string from where to extract value - * @param $offset (int) point from where to read the data - * @return int 16 bit value - * @author Nicola Asuni - * @protected - * @since 5.9.123 (2011-09-30) - */ - protected function _getUFWORD($str, $offset) { - $v = $this->_getUSHORT($str, $offset); - return $v; - } - - /** - * Get FIXED from string (32-bit signed fixed-point number (16.16). - * @param $str (string) string from where to extract value - * @param $offset (int) point from where to read the data - * @return int 16 bit value - * @author Nicola Asuni - * @protected - * @since 5.9.123 (2011-09-30) - */ - protected function _getFIXED($str, $offset) { - // mantissa - $m = $this->_getFWORD($str, $offset); - // fraction - $f = $this->_getUSHORT($str, ($offset + 2)); - $v = floatval(''.$m.'.'.$f.''); - return $v; - } - - /** - * Get BYTE from string (8-bit unsigned integer). - * @param $str (string) String from where to extract value. - * @param $offset (int) Point from where to read the data. - * @return int 8 bit value - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getBYTE($str, $offset) { - $v = unpack('Ci', substr($str, $offset, 1)); - return $v['i']; - } - /** - * Update the CIDToGIDMap string with a new value. - * @param $map (string) CIDToGIDMap. - * @param $cid (int) CID value. - * @param $gid (int) GID value. - * @return (string) CIDToGIDMap. - * @author Nicola Asuni - * @protected - * @since 5.9.123 (2011-09-29) - */ - protected function updateCIDtoGIDmap($map, $cid, $gid) { - if (($cid >= 0) and ($cid <= 0xFFFF) and ($gid >= 0)) { - if ($gid > 0xFFFF) { - $gid -= 0x10000; - } - $map[($cid * 2)] = chr($gid >> 8); - $map[(($cid * 2) + 1)] = chr($gid & 0xFF); - } - return $map; - } - - /** - * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable). - * @param $fontfile (string) Font file (full path). - * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional. - * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats. - * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font. - * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder. - * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1). - * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4. - * @return (string) TCPDF font name. - * @author Nicola Asuni - * @public - * @since 5.9.123 (2010-09-30) - */ - public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1) { - if (!Tools::file_exists_no_cache($fontfile)) { - $this->Error('Could not find file: '.$fontfile.''); - } - // font metrics - $fmetric = array(); - // build new font name for TCPDF compatibility - $font_path_parts = pathinfo($fontfile); - if (!isset($font_path_parts['filename'])) { - $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 = preg_replace('/[^a-z0-9_]/', '', $font_name); - $search = array('bold', 'oblique', 'italic', 'regular'); - $replace = array('b', 'i', 'i', ''); - $font_name = str_replace($search, $replace, $font_name); - if (empty($font_name)) { - // set generic name - $font_name = 'tcpdffont'; - } - // set output path - if (empty($outpath)) { - $outpath = $this->_getfontpath(); - } - // check if this font already exist - if (Tools::file_exists_no_cache($outpath.$font_name.'.php')) { - // this font already exist (delete it from fonts folder to rebuild it) - return $font_name; - } - $fmetric['file'] = $font_name.'.z'; - $fmetric['ctg'] = $font_name.'.ctg.z'; - // get font data - $font = file_get_contents($fontfile); - $fmetric['originalsize'] = strlen($font); - // autodetect font type - if (empty($fonttype)) { - if ($this->_getULONG($font, 0) == 0x10000) { - // True Type (Unicode or not) - $fonttype = 'TrueTypeUnicode'; - } elseif (substr($font, 0, 4) == 'OTTO') { - // Open Type (Unicode or not) - $this->Error('Unsupported font format: OpenType with CFF data.'); - } else { - // Type 1 - $fonttype = 'Type1'; - } - } - // set font type - switch ($fonttype) { - case 'CID0CT': - case 'CID0CS': - case 'CID0KR': - case 'CID0JP': { - $fmetric['type'] = 'cidfont0'; - break; - } - case 'Type1': { - $fmetric['type'] = 'Type1'; - if (empty($enc) and (($flags & 4) == 0)) { - $enc = 'cp1252'; - } - break; - } - case 'TrueType': { - $fmetric['type'] = 'TrueType'; - break; - } - case 'TrueTypeUnicode': - default: { - $fmetric['type'] = 'TrueTypeUnicode'; - break; - } - } - // set encoding maps (if any) - $fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc); - $fmetric['diff'] = ''; - if (($fmetric['type'] == 'TrueType') or ($fmetric['type'] == 'Type1')) { - if (!empty($enc) and ($enc != 'cp1252') and isset($this->encmaps->encmap[$enc])) { - // build differences from reference encoding - $enc_ref = $this->encmaps->encmap['cp1252']; - $enc_target = $this->encmaps->encmap[$enc]; - $last = 0; - for ($i = 32; $i <= 255; ++$i) { - if ($enc_target != $enc_ref[$i]) { - if ($i != ($last + 1)) { - $fmetric['diff'] .= $i.' '; - } - $last = $i; - $fmetric['diff'] .= '/'.$enc_target[$i].' '; - } - } - } - } - // parse the font by type - if ($fmetric['type'] == 'Type1') { - // ---------- TYPE 1 ---------- - // read first segment - $a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6)); - if ($a['marker'] != 128) { - $this->Error('Font file is not a valid binary Type1'); - } - $fmetric['size1'] = $a['size']; - $data = substr($font, 6, $fmetric['size1']); - // read second segment - $a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6)); - if ($a['marker'] != 128) { - $this->Error('Font file is not a valid binary Type1'); - } - $fmetric['size2'] = $a['size']; - $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']); - $data .= $encrypted; - // store compressed font - $fp = fopen($outpath.$fmetric['file'], 'wb'); - fwrite($fp, gzcompress($data)); - fclose($fp); - // get font info - $fmetric['Flags'] = $flags; - preg_match('#/FullName[\s]*\(([^\)]*)#', $font, $matches); - $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]); - preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches); - $fmetric['bbox'] = trim($matches[1]); - $bv = explode(' ', $fmetric['bbox']); - $fmetric['Ascent'] = intval($bv[3]); - $fmetric['Descent'] = intval($bv[1]); - preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches); - $fmetric['italicAngle'] = intval($matches[1]); - if ($fmetric['italicAngle'] != 0) { - $fmetric['Flags'] |= 64; - } - preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches); - $fmetric['underlinePosition'] = intval($matches[1]); - preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches); - $fmetric['underlineThickness'] = intval($matches[1]); - preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches); - if ($matches[1] == 'true') { - $fmetric['Flags'] |= 1; - } - // get internal map - $imap = array(); - if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) { - foreach ($fmap as $v) { - $imap[$v[2]] = $v[1]; - } - } - // decrypt eexec encrypted part - $r = 55665; // eexec encryption constant - $c1 = 52845; - $c2 = 22719; - $elen = strlen($encrypted); - $eplain = ''; - for ($i = 0; $i < $elen; ++$i) { - $chr = ord($encrypted[$i]); - $eplain .= chr($chr ^ ($r >> 8)); - $r = ((($chr + $r) * $c1 + $c2) % 65536); - } - if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) { - if ($matches[1] == 'true') { - $fmetric['Flags'] |= 0x40000; - } - } - if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { - $fmetric['StemV'] = intval($matches[1]); - } else { - $fmetric['StemV'] = 70; - } - if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { - $fmetric['StemH'] = intval($matches[1]); - } else { - $fmetric['StemH'] = 30; - } - if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { - $bv = explode(' ', $matches[1]); - if (count($bv) >= 6) { - $v1 = intval($bv[2]); - $v2 = intval($bv[4]); - if ($v1 <= $v2) { - $fmetric['XHeight'] = $v1; - $fmetric['CapHeight'] = $v2; - } else { - $fmetric['XHeight'] = $v2; - $fmetric['CapHeight'] = $v1; - } - } else { - $fmetric['XHeight'] = 450; - $fmetric['CapHeight'] = 700; - } - } else { - $fmetric['XHeight'] = 450; - $fmetric['CapHeight'] = 700; - } - // get the number of random bytes at the beginning of charstrings - if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) { - $lenIV = intval($matches[1]); - } else { - $lenIV = 4; - } - $fmetric['Leading'] = 0; - // get charstring data - $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); - if (!empty($enc) and isset($this->encmaps->encmap[$enc])) { - $enc_map = $this->encmaps->encmap[$enc]; - } else { - $enc_map = false; - } - $fmetric['cw'] = ''; - $fmetric['MaxWidth'] = 0; - $cwidths = array(); - foreach ($matches as $k => $v) { - $cid = 0; - if (isset($imap[$v[1]])) { - $cid = $imap[$v[1]]; - } elseif ($enc_map !== false) { - $cid = array_search($v[1], $enc_map); - if ($cid === false) { - $cid = 0; - } elseif ($cid > 1000) { - $cid -= 1000; - } - } - // decrypt charstring encrypted part - $r = 4330; // charstring encryption constant - $c1 = 52845; - $c2 = 22719; - $cd = $v[2]; - $clen = strlen($cd); - $ccom = array(); - for ($i = 0; $i < $clen; ++$i) { - $chr = ord($cd[$i]); - $ccom[] = ($chr ^ ($r >> 8)); - $r = ((($chr + $r) * $c1 + $c2) % 65536); - } - // decode numbers - $cdec = array(); - $ck = 0; - $i = $lenIV; - while ($i < $clen) { - if ($ccom[$i] < 32) { - $cdec[$ck] = $ccom[$i]; - if (($ck > 0) and ($cdec[$ck] == 13)) { - // hsbw command: update width - $cwidths[$cid] = $cdec[($ck - 1)]; - } - ++$i; - } elseif (($ccom[$i] >= 32) and ($ccom[$i] <= 246)) { - $cdec[$ck] = ($ccom[$i] - 139); - ++$i; - } elseif (($ccom[$i] >= 247) and ($ccom[$i] <= 250)) { - $cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108); - $i += 2; - } elseif (($ccom[$i] >= 251) and ($ccom[$i] <= 254)) { - $cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108); - $i += 2; - } elseif ($ccom[$i] == 255) { - $sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]); - $vsval = unpack('li', $sval); - $cdec[$ck] = $vsval['i']; - $i += 5; - } - ++$ck; - } - } // end for each matches - $fmetric['MissingWidth'] = $cwidths[0]; - $fmetric['MaxWidth'] = $fmetric['MissingWidth']; - $fmetric['AvgWidth'] = 0; - // set chars widths - for ($cid = 0; $cid <= 255; ++$cid) { - if (isset($cwidths[$cid])) { - if ($cwidths[$cid] > $fmetric['MaxWidth']) { - $fmetric['MaxWidth'] = $cwidths[$cid]; - } - $fmetric['AvgWidth'] += $cwidths[$cid]; - $fmetric['cw'] .= ','.$cid.'=>'.$cwidths[$cid]; - } else { - $fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth']; - } - } - $fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths)); - } else { - // ---------- TRUE TYPE ---------- - if ($fmetric['type'] != 'cidfont0') { - // store compressed font - $fp = fopen($outpath.$fmetric['file'], 'wb'); - fwrite($fp, gzcompress($font)); - fclose($fp); - } - $offset = 0; // offset position of the font data - if ($this->_getULONG($font, $offset) != 0x10000) { - // sfnt version must be 0x00010000 for TrueType version 1.0. - return $font; - } - $offset += 4; - // get number of tables - $numTables = $this->_getUSHORT($font, $offset); - $offset += 2; - // skip searchRange, entrySelector and rangeShift - $offset += 6; - // tables array - $table = array(); - // ---------- get tables ---------- - for ($i = 0; $i < $numTables; ++$i) { - // get table info - $tag = substr($font, $offset, 4); - $offset += 4; - $table[$tag] = array(); - $table[$tag]['checkSum'] = $this->_getULONG($font, $offset); - $offset += 4; - $table[$tag]['offset'] = $this->_getULONG($font, $offset); - $offset += 4; - $table[$tag]['length'] = $this->_getULONG($font, $offset); - $offset += 4; - } - // check magicNumber - $offset = $table['head']['offset'] + 12; - if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) { - // magicNumber must be 0x5F0F3CF5 - return $font; - } - $offset += 4; - $offset += 2; // skip flags - // get FUnits - $fmetric['unitsPerEm'] = $this->_getUSHORT($font, $offset); - $offset += 2; - // units ratio constant - $urk = (1000 / $fmetric['unitsPerEm']); - $offset += 16; // skip created, modified - $xMin = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $yMin = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $xMax = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $yMax = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.''; - $macStyle = $this->_getUSHORT($font, $offset); - $offset += 2; - // PDF font flags - $fmetric['Flags'] = $flags; - if (($macStyle & 2) == 2) { - // italic flag - $fmetric['Flags'] |= 64; - } - // get offset mode (indexToLocFormat : 0 = short, 1 = long) - $offset = $table['head']['offset'] + 50; - $short_offset = ($this->_getSHORT($font, $offset) == 0); - $offset += 2; - // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table - $indexToLoc = array(); - $offset = $table['loca']['offset']; - if ($short_offset) { - // short version - $tot_num_glyphs = ($table['loca']['length'] / 2); // numGlyphs + 1 - for ($i = 0; $i < $tot_num_glyphs; ++$i) { - $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2; - $offset += 2; - } - } else { - // long version - $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1 - for ($i = 0; $i < $tot_num_glyphs; ++$i) { - $indexToLoc[$i] = $this->_getULONG($font, $offset); - $offset += 4; - } - } - // get glyphs indexes of chars from cmap table - $offset = $table['cmap']['offset'] + 2; - $numEncodingTables = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables = array(); - for ($i = 0; $i < $numEncodingTables; ++$i) { - $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset); - $offset += 4; - } - // ---------- get os/2 metrics ---------- - $offset = $table['OS/2']['offset']; - $offset += 2; // skip version - // xAvgCharWidth - $fmetric['AvgWidth'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - // usWeightClass - $usWeightClass = round($this->_getUFWORD($font, $offset) * $urk); - // estimate StemV and StemH (400 = usWeightClass for Normal - Regular font) - $fmetric['StemV'] = round((70 * $usWeightClass) / 400); - $fmetric['StemH'] = round((30 * $usWeightClass) / 400); - $offset += 2; - $offset += 2; // usWidthClass - $fsType = $this->_getSHORT($font, $offset); - $offset += 2; - if ($fsType == 2) { - $this->Error('This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.'); - } - // ---------- get font name ---------- - $fmetric['name'] = ''; - $offset = $table['name']['offset']; - $offset += 2; // skip Format selector (=0). - // Number of NameRecords that follow n. - $numNameRecords = $this->_getUSHORT($font, $offset); - $offset += 2; - // Offset to start of string storage (from start of table). - $stringStorageOffset = $this->_getUSHORT($font, $offset); - $offset += 2; - for ($i = 0; $i < $numNameRecords; ++$i) { - $offset += 6; // skip Platform ID, Platform-specific encoding ID, Language ID. - // Name ID. - $nameID = $this->_getUSHORT($font, $offset); - $offset += 2; - if ($nameID == 6) { - // String length (in bytes). - $stringLength = $this->_getUSHORT($font, $offset); - $offset += 2; - // String offset from start of storage area (in bytes). - $stringOffset = $this->_getUSHORT($font, $offset); - $offset += 2; - $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset); - $fmetric['name'] = substr($font, $offset, $stringLength); - $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']); - break; - } else { - $offset += 4; // skip String length, String offset - } - } - if (empty($fmetric['name'])) { - $fmetric['name'] = $font_name; - } - // ---------- get post data ---------- - $offset = $table['post']['offset']; - $offset += 4; // skip Format Type - $fmetric['italicAngle'] = $this->_getFIXED($font, $offset); - $offset += 4; - $fmetric['underlinePosition'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $fmetric['underlineThickness'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - $isFixedPitch = ($this->_getULONG($font, $offset) == 0) ? false : true; - $offset += 2; - if ($isFixedPitch) { - $fmetric['Flags'] |= 1; - } - // ---------- get hhea data ---------- - $offset = $table['hhea']['offset']; - $offset += 4; // skip Table version number - // Ascender - $fmetric['Ascent'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - // Descender - $fmetric['Descent'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - // LineGap - $fmetric['Leading'] = round($this->_getFWORD($font, $offset) * $urk); - $offset += 2; - // advanceWidthMax - $fmetric['MaxWidth'] = round($this->_getUFWORD($font, $offset) * $urk); - $offset += 2; - $offset += 22; // skip some values - // get the number of hMetric entries in hmtx table - $numberOfHMetrics = $this->_getUSHORT($font, $offset); - // ---------- get maxp data ---------- - $offset = $table['maxp']['offset']; - $offset += 4; // skip Table version number - // get the the number of glyphs in the font. - $numGlyphs = $this->_getUSHORT($font, $offset); - // ---------- get CIDToGIDMap ---------- - $ctg = array(); - foreach ($encodingTables as $enctable) { - // get only specified Platform ID and Encoding ID - if (($enctable['platformID'] == $platid) and ($enctable['encodingID'] == $encid)) { - $offset = $table['cmap']['offset'] + $enctable['offset']; - $format = $this->_getUSHORT($font, $offset); - $offset += 2; - switch ($format) { - case 0: { // Format 0: Byte encoding table - $offset += 4; // skip length and version/language - for ($c = 0; $c < 256; ++$c) { - $g = $this->_getBYTE($font, $offset); - $ctg[$c] = $g; - ++$offset; - } - break; - } - case 2: { // Format 2: High-byte mapping through table - $offset += 4; // skip length and version/language - $numSubHeaders = 0; - for ($i = 0; $i < 256; ++$i) { - // Array that maps high bytes to subHeaders: value is subHeader index * 8. - $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8); - $offset += 2; - if ($numSubHeaders < $subHeaderKeys[$i]) { - $numSubHeaders = $subHeaderKeys[$i]; - } - } - // the number of subHeaders is equal to the max of subHeaderKeys + 1 - ++$numSubHeaders; - // read subHeader structures - $subHeaders = array(); - $numGlyphIndexArray = 0; - for ($k = 0; $k < $numSubHeaders; ++$k) { - $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idDelta'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8)); - $subHeaders[$k]['idRangeOffset'] /= 2; - $numGlyphIndexArray += $subHeaders[$k]['entryCount']; - } - for ($k = 0; $k < $numGlyphIndexArray; ++$k) { - $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - for ($i = 0; $i < 256; ++$i) { - $k = $subHeaderKeys[$i]; - if ($k == 0) { - // one byte code - $c = $i; - $g = $glyphIndexArray[0]; - $ctg[$c] = $g; - } else { - // two bytes code - $start_byte = $subHeaders[$k]['firstCode']; - $end_byte = $start_byte + $subHeaders[$k]['entryCount']; - for ($j = $start_byte; $j < $end_byte; ++$j) { - // combine high and low bytes - $c = (($i << 8) + $j); - $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']); - $g = ($glyphIndexArray[$idRangeOffset] + $idDelta[$k]) % 65536; - if ($g < 0) { - $g = 0; - } - $ctg[$c] = $g; - } - } - } - break; - } - case 4: { // Format 4: Segment mapping to delta values - $length = $this->_getUSHORT($font, $offset); - $offset += 2; - $offset += 2; // skip version/language - $segCount = ($this->_getUSHORT($font, $offset) / 2); - $offset += 2; - $offset += 6; // skip searchRange, entrySelector, rangeShift - $endCount = array(); // array of end character codes for each segment - for ($k = 0; $k < $segCount; ++$k) { - $endCount[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $offset += 2; // skip reservedPad - $startCount = array(); // array of start character codes for each segment - for ($k = 0; $k < $segCount; ++$k) { - $startCount[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $idDelta = array(); // delta for all character codes in segment - for ($k = 0; $k < $segCount; ++$k) { - $idDelta[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $idRangeOffset = array(); // Offsets into glyphIdArray or 0 - for ($k = 0; $k < $segCount; ++$k) { - $idRangeOffset[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $gidlen = ($length / 2) - 8 - (4 * $segCount); - $glyphIdArray = array(); // glyph index array - for ($k = 0; $k < $gidlen; ++$k) { - $glyphIdArray[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - for ($k = 0; $k < $segCount; ++$k) { - for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) { - if ($idRangeOffset[$k] == 0) { - $g = ($idDelta[$k] + $c) % 65536; - } else { - $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k)); - $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536; - } - if ($g < 0) { - $g = 0; - } - $ctg[$c] = $g; - } - } - break; - } - case 6: { // Format 6: Trimmed table mapping - $offset += 4; // skip length and version/language - $firstCode = $this->_getUSHORT($font, $offset); - $offset += 2; - $entryCount = $this->_getUSHORT($font, $offset); - $offset += 2; - for ($k = 0; $k < $entryCount; ++$k) { - $c = ($k + $firstCode); - $g = $this->_getUSHORT($font, $offset); - $offset += 2; - $ctg[$c] = $g; - } - break; - } - case 8: { // Format 8: Mixed 16-bit and 32-bit coverage - $offset += 10; // skip reserved, length and version/language - for ($k = 0; $k < 8192; ++$k) { - $is32[$k] = $this->_getBYTE($font, $offset); - ++$offset; - } - $nGroups = $this->_getULONG($font, $offset); - $offset += 4; - for ($i = 0; $i < $nGroups; ++$i) { - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $endCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $startGlyphID = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = $startCharCode; $k <= $endCharCode; ++$k) { - $is32idx = floor($c / 8); - if ((isset($is32[$is32idx])) and (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) { - $c = $k; - } else { - // 32 bit format - // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4) - //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232 - //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888 - $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888; - } - $ctg[$c] = 0; - ++$startGlyphID; - } - } - break; - } - case 10: { // Format 10: Trimmed array - $offset += 10; // skip reserved, length and version/language - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $numChars = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = 0; $k < $numChars; ++$k) { - $c = ($k + $startCharCode); - $g = $this->_getUSHORT($font, $offset); - $ctg[$c] = $g; - $offset += 2; - } - break; - } - case 12: { // Format 12: Segmented coverage - $offset += 10; // skip length and version/language - $nGroups = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = 0; $k < $nGroups; ++$k) { - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $endCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $startGlyphCode = $this->_getULONG($font, $offset); - $offset += 4; - for ($c = $startCharCode; $c <= $endCharCode; ++$c) { - $ctg[$c] = $startGlyphCode; - ++$startGlyphCode; - } - } - break; - } - case 13: { // Format 13: Many-to-one range mappings - // to be implemented ... - break; - } - case 14: { // Format 14: Unicode Variation Sequences - // to be implemented ... - break; - } - } - } - } - if (!isset($ctg[0])) { - $ctg[0] = 0; - } - // get xHeight (height of x) - $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[120]] + 4); - $yMin = $this->_getFWORD($font, $offset); - $offset += 4; - $yMax = $this->_getFWORD($font, $offset); - $offset += 2; - $fmetric['XHeight'] = round(($yMax - $yMin) * $urk); - // get CapHeight (height of H) - $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4); - $yMin = $this->_getFWORD($font, $offset); - $offset += 4; - $yMax = $this->_getFWORD($font, $offset); - $offset += 2; - $fmetric['CapHeight'] = round(($yMax - $yMin) * $urk); - // ceate widths array - $cw = array(); - $offset = $table['hmtx']['offset']; - for ($i = 0 ; $i < $numberOfHMetrics; ++$i) { - $cw[$i] = round($this->_getUFWORD($font, $offset) * $urk); - $offset += 4; // skip lsb - } - if ($numberOfHMetrics < $numGlyphs) { - // fill missing widths with the last value - $cw = array_pad($cw, $numGlyphs, $cw[($numberOfHMetrics - 1)]); - } - $fmetric['MissingWidth'] = $cw[0]; - $fmetric['cw'] = ''; - for ($cid = 0; $cid <= 65535; ++$cid) { - if (isset($ctg[$cid]) and isset($cw[$ctg[$cid]])) { - $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]]; - } - } - } // end of true type - if (($fmetric['type'] == 'TrueTypeUnicode') and (count($ctg) == 256)) { - $fmetric['type'] == 'TrueType'; - } - // ---------- create php font file ---------- - $pfile = '<'.'?'.'php'."\n"; - $pfile .= '// TCPDF FONT FILE DESCRIPTION'."\n"; - $pfile .= '$type=\''.$fmetric['type'].'\';'."\n"; - $pfile .= '$name=\''.$fmetric['name'].'\';'."\n"; - $pfile .= '$up='.$fmetric['underlinePosition'].';'."\n"; - $pfile .= '$ut='.$fmetric['underlineThickness'].';'."\n"; - if ($fmetric['MissingWidth'] > 0) { - $pfile .= '$dw='.$fmetric['MissingWidth'].';'."\n"; - } else { - $pfile .= '$dw='.$fmetric['AvgWidth'].';'."\n"; - } - $pfile .= '$diff=\''.$fmetric['diff'].'\';'."\n"; - if ($fmetric['type'] == 'Type1') { - // Type 1 - $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n"; - $pfile .= '$file=\''.$fmetric['file'].'\';'."\n"; - $pfile .= '$size1='.$fmetric['size1'].';'."\n"; - $pfile .= '$size2='.$fmetric['size2'].';'."\n"; - } else { - $pfile .= '$originalsize='.$fmetric['originalsize'].';'."\n"; - if ($fmetric['type'] == 'cidfont0') { - // CID-0 - switch ($fonttype) { - case 'CID0JP': { - $pfile .= '// Japanese'."\n"; - $pfile .= '$enc=\'UniJIS-UTF16-H\';'."\n"; - $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Japan1\',\'Supplement\'=>5);'."\n"; - $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n"; - break; - } - case 'CID0KR': { - $pfile .= '// Korean'."\n"; - $pfile .= '$enc=\'UniKS-UTF16-H\';'."\n"; - $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Korea1\',\'Supplement\'=>0);'."\n"; - $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ak12.php\');'."\n"; - break; - } - case 'CID0CS': { - $pfile .= '// Chinese Simplified'."\n"; - $pfile .= '$enc=\'UniGB-UTF16-H\';'."\n"; - $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'GB1\',\'Supplement\'=>2);'."\n"; - $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ag15.php\');'."\n"; - break; - } - case 'CID0CT': - default: { - $pfile .= '// Chinese Traditional'."\n"; - $pfile .= '$enc=\'UniCNS-UTF16-H\';'."\n"; - $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'CNS1\',\'Supplement\'=>0);'."\n"; - $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n"; - break; - } - } - } else { - // TrueType - $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n"; - $pfile .= '$file=\''.$fmetric['file'].'\';'."\n"; - $pfile .= '$ctg=\''.$fmetric['ctg'].'\';'."\n"; - // create CIDToGIDMap - $cidtogidmap = str_pad('', 131072, "\x00"); // (256 * 256 * 2) = 131072 - foreach ($ctg as $cid => $gid) { - $cidtogidmap = $this->updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]); - } - // store compressed CIDToGIDMap - $fp = fopen($outpath.$fmetric['ctg'], 'wb'); - fwrite($fp, gzcompress($cidtogidmap)); - fclose($fp); - } - } - $pfile .= '$desc=array('; - $pfile .= '\'Flags\'=>'.$fmetric['Flags'].','; - $pfile .= '\'FontBBox\'=>\'['.$fmetric['bbox'].']\','; - $pfile .= '\'ItalicAngle\'=>'.$fmetric['italicAngle'].','; - $pfile .= '\'Ascent\'=>'.$fmetric['Ascent'].','; - $pfile .= '\'Descent\'=>'.$fmetric['Descent'].','; - $pfile .= '\'Leading\'=>'.$fmetric['Leading'].','; - $pfile .= '\'CapHeight\'=>'.$fmetric['CapHeight'].','; - $pfile .= '\'XHeight\'=>'.$fmetric['XHeight'].','; - $pfile .= '\'StemV\'=>'.$fmetric['StemV'].','; - $pfile .= '\'StemH\'=>'.$fmetric['StemH'].','; - $pfile .= '\'AvgWidth\'=>'.$fmetric['AvgWidth'].','; - $pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].','; - $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].''; - $pfile .= ');'."\n"; - $pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n"; - $pfile .= '// --- EOF ---'."\n"; - // store file - $fp = fopen($outpath.$font_name.'.php', 'w'); - fwrite($fp, $pfile); - fclose($fp); - // return TCPDF font name - return $font_name; - } - - /** - * Returns a subset of the TrueType font data without the unused glyphs. - * @param $font (string) TrueType font data. - * @param $subsetchars (array) Array of used characters (the glyphs to keep). - * @return (string) A subset of TrueType font data without the unused glyphs. - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getTrueTypeFontSubset($font, $subsetchars) { - ksort($subsetchars); - $offset = 0; // offset position of the font data - if ($this->_getULONG($font, $offset) != 0x10000) { - // sfnt version must be 0x00010000 for TrueType version 1.0. - return $font; - } - $offset += 4; - // get number of tables - $numTables = $this->_getUSHORT($font, $offset); - $offset += 2; - // skip searchRange, entrySelector and rangeShift - $offset += 6; - // tables array - $table = array(); - // for each table - for ($i = 0; $i < $numTables; ++$i) { - // get table info - $tag = substr($font, $offset, 4); - $offset += 4; - $table[$tag] = array(); - $table[$tag]['checkSum'] = $this->_getULONG($font, $offset); - $offset += 4; - $table[$tag]['offset'] = $this->_getULONG($font, $offset); - $offset += 4; - $table[$tag]['length'] = $this->_getULONG($font, $offset); - $offset += 4; - } - // check magicNumber - $offset = $table['head']['offset'] + 12; - if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) { - // magicNumber must be 0x5F0F3CF5 - return $font; - } - $offset += 4; - // get offset mode (indexToLocFormat : 0 = short, 1 = long) - $offset = $table['head']['offset'] + 50; - $short_offset = ($this->_getSHORT($font, $offset) == 0); - $offset += 2; - // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table - $indexToLoc = array(); - $offset = $table['loca']['offset']; - if ($short_offset) { - // short version - $tot_num_glyphs = ($table['loca']['length'] / 2); // numGlyphs + 1 - for ($i = 0; $i < $tot_num_glyphs; ++$i) { - $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2; - $offset += 2; - } - } else { - // long version - $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1 - for ($i = 0; $i < $tot_num_glyphs; ++$i) { - $indexToLoc[$i] = $this->_getULONG($font, $offset); - $offset += 4; - } - } - // get glyphs indexes of chars from cmap table - $subsetglyphs = array(); // glyph IDs on key - $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0 - $offset = $table['cmap']['offset'] + 2; - $numEncodingTables = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables = array(); - for ($i = 0; $i < $numEncodingTables; ++$i) { - $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset); - $offset += 4; - } - foreach ($encodingTables as $enctable) { - // get all platforms and encodings - $offset = $table['cmap']['offset'] + $enctable['offset']; - $format = $this->_getUSHORT($font, $offset); - $offset += 2; - switch ($format) { - case 0: { // Format 0: Byte encoding table - $offset += 4; // skip length and version/language - for ($c = 0; $c < 256; ++$c) { - if (isset($subsetchars[$c])) { - $g = $this->_getBYTE($font, $offset); - $subsetglyphs[$g] = true; - } - ++$offset; - } - break; - } - case 2: { // Format 2: High-byte mapping through table - $offset += 4; // skip length and version/language - $numSubHeaders = 0; - for ($i = 0; $i < 256; ++$i) { - // Array that maps high bytes to subHeaders: value is subHeader index * 8. - $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8); - $offset += 2; - if ($numSubHeaders < $subHeaderKeys[$i]) { - $numSubHeaders = $subHeaderKeys[$i]; - } - } - // the number of subHeaders is equal to the max of subHeaderKeys + 1 - ++$numSubHeaders; - // read subHeader structures - $subHeaders = array(); - $numGlyphIndexArray = 0; - for ($k = 0; $k < $numSubHeaders; ++$k) { - $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idDelta'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset); - $offset += 2; - $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8)); - $subHeaders[$k]['idRangeOffset'] /= 2; - $numGlyphIndexArray += $subHeaders[$k]['entryCount']; - } - for ($k = 0; $k < $numGlyphIndexArray; ++$k) { - $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - for ($i = 0; $i < 256; ++$i) { - $k = $subHeaderKeys[$i]; - if ($k == 0) { - // one byte code - $c = $i; - if (isset($subsetchars[$c])) { - $g = $glyphIndexArray[0]; - $subsetglyphs[$g] = true; - } - } else { - // two bytes code - $start_byte = $subHeaders[$k]['firstCode']; - $end_byte = $start_byte + $subHeaders[$k]['entryCount']; - for ($j = $start_byte; $j < $end_byte; ++$j) { - // combine high and low bytes - $c = (($i << 8) + $j); - if (isset($subsetchars[$c])) { - $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']); - $g = ($glyphIndexArray[$idRangeOffset] + $idDelta[$k]) % 65536; - if ($g < 0) { - $g = 0; - } - $subsetglyphs[$g] = true; - } - } - } - } - break; - } - case 4: { // Format 4: Segment mapping to delta values - $length = $this->_getUSHORT($font, $offset); - $offset += 2; - $offset += 2; // skip version/language - $segCount = ($this->_getUSHORT($font, $offset) / 2); - $offset += 2; - $offset += 6; // skip searchRange, entrySelector, rangeShift - $endCount = array(); // array of end character codes for each segment - for ($k = 0; $k < $segCount; ++$k) { - $endCount[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $offset += 2; // skip reservedPad - $startCount = array(); // array of start character codes for each segment - for ($k = 0; $k < $segCount; ++$k) { - $startCount[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $idDelta = array(); // delta for all character codes in segment - for ($k = 0; $k < $segCount; ++$k) { - $idDelta[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $idRangeOffset = array(); // Offsets into glyphIdArray or 0 - for ($k = 0; $k < $segCount; ++$k) { - $idRangeOffset[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - $gidlen = ($length / 2) - 8 - (4 * $segCount); - $glyphIdArray = array(); // glyph index array - for ($k = 0; $k < $gidlen; ++$k) { - $glyphIdArray[$k] = $this->_getUSHORT($font, $offset); - $offset += 2; - } - for ($k = 0; $k < $segCount; ++$k) { - for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) { - if (isset($subsetchars[$c])) { - if ($idRangeOffset[$k] == 0) { - $g = ($idDelta[$k] + $c) % 65536; - } else { - $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k)); - $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536; - } - if ($g < 0) { - $g = 0; - } - $subsetglyphs[$g] = true; - } - } - } - break; - } - case 6: { // Format 6: Trimmed table mapping - $offset += 4; // skip length and version/language - $firstCode = $this->_getUSHORT($font, $offset); - $offset += 2; - $entryCount = $this->_getUSHORT($font, $offset); - $offset += 2; - for ($k = 0; $k < $entryCount; ++$k) { - $c = ($k + $firstCode); - if (isset($subsetchars[$c])) { - $g = $this->_getUSHORT($font, $offset); - $subsetglyphs[$g] = true; - } - $offset += 2; - } - break; - } - case 8: { // Format 8: Mixed 16-bit and 32-bit coverage - $offset += 10; // skip reserved, length and version/language - for ($k = 0; $k < 8192; ++$k) { - $is32[$k] = $this->_getBYTE($font, $offset); - ++$offset; - } - $nGroups = $this->_getULONG($font, $offset); - $offset += 4; - for ($i = 0; $i < $nGroups; ++$i) { - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $endCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $startGlyphID = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = $startCharCode; $k <= $endCharCode; ++$k) { - $is32idx = floor($c / 8); - if ((isset($is32[$is32idx])) and (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) { - $c = $k; - } else { - // 32 bit format - // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4) - //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232 - //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888 - $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888; - } - if (isset($subsetchars[$c])) { - $subsetglyphs[$startGlyphID] = true; - } - ++$startGlyphID; - } - } - break; - } - case 10: { // Format 10: Trimmed array - $offset += 10; // skip reserved, length and version/language - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $numChars = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = 0; $k < $numChars; ++$k) { - $c = ($k + $startCharCode); - if (isset($subsetchars[$c])) { - $g = $this->_getUSHORT($font, $offset); - $subsetglyphs[$g] = true; - } - $offset += 2; - } - break; - } - case 12: { // Format 12: Segmented coverage - $offset += 10; // skip length and version/language - $nGroups = $this->_getULONG($font, $offset); - $offset += 4; - for ($k = 0; $k < $nGroups; ++$k) { - $startCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $endCharCode = $this->_getULONG($font, $offset); - $offset += 4; - $startGlyphCode = $this->_getULONG($font, $offset); - $offset += 4; - for ($c = $startCharCode; $c <= $endCharCode; ++$c) { - if (isset($subsetchars[$c])) { - $subsetglyphs[$startGlyphCode] = true; - } - ++$startGlyphCode; - } - } - break; - } - case 13: { // Format 13: Many-to-one range mappings - // to be implemented ... - break; - } - case 14: { // Format 14: Unicode Variation Sequences - // to be implemented ... - break; - } - } - } - // include all parts of composite glyphs - $new_sga = $subsetglyphs; - while (!empty($new_sga)) { - $sga = $new_sga; - $new_sga = array(); - foreach ($sga as $key => $val) { - if (isset($indexToLoc[$key])) { - $offset = ($table['glyf']['offset'] + $indexToLoc[$key]); - $numberOfContours = $this->_getSHORT($font, $offset); - $offset += 2; - if ($numberOfContours < 0) { // composite glyph - $offset += 8; // skip xMin, yMin, xMax, yMax - do { - $flags = $this->_getUSHORT($font, $offset); - $offset += 2; - $glyphIndex = $this->_getUSHORT($font, $offset); - $offset += 2; - if (!isset($subsetglyphs[$glyphIndex])) { - // add missing glyphs - $new_sga[$glyphIndex] = true; - } - // skip some bytes by case - if ($flags & 1) { - $offset += 4; - } else { - $offset += 2; - } - if ($flags & 8) { - $offset += 2; - } elseif ($flags & 64) { - $offset += 4; - } elseif ($flags & 128) { - $offset += 8; - } - } while ($flags & 32); - } - } - } - $subsetglyphs += $new_sga; - } - // sort glyphs by key (and remove duplicates) - ksort($subsetglyphs); - // build new glyf and loca tables - $glyf = ''; - $loca = ''; - $offset = 0; - $glyf_offset = $table['glyf']['offset']; - for ($i = 0; $i < $tot_num_glyphs; ++$i) { - if (isset($subsetglyphs[$i])) { - $length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]); - $glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length); - } else { - $length = 0; - } - if ($short_offset) { - $loca .= pack('n', ($offset / 2)); - } else { - $loca .= pack('N', $offset); - } - $offset += $length; - } - // array of table names to preserve (loca and glyf tables will be added later) - // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately - $table_names = array('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names - // get the tables to preserve - $offset = 12; - foreach ($table as $tag => $val) { - if (in_array($tag, $table_names)) { - $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']); - if ($tag == 'head') { - // set the checkSumAdjustment to 0 - $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12); - } - $pad = 4 - ($table[$tag]['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table[$tag]['length'] += $pad; - $table[$tag]['data'] .= str_repeat("\x0", $pad); - } - $table[$tag]['offset'] = $offset; - $offset += $table[$tag]['length']; - // check sum is not changed (so keep the following line commented) - //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']); - } else { - unset($table[$tag]); - } - } - // add loca - $table['loca']['data'] = $loca; - $table['loca']['length'] = strlen($loca); - $pad = 4 - ($table['loca']['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table['loca']['length'] += $pad; - $table['loca']['data'] .= str_repeat("\x0", $pad); - } - $table['loca']['offset'] = $offset; - $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']); - $offset += $table['loca']['length']; - // add glyf - $table['glyf']['data'] = $glyf; - $table['glyf']['length'] = strlen($glyf); - $pad = 4 - ($table['glyf']['length'] % 4); - if ($pad != 4) { - // the length of a table must be a multiple of four bytes - $table['glyf']['length'] += $pad; - $table['glyf']['data'] .= str_repeat("\x0", $pad); - } - $table['glyf']['offset'] = $offset; - $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']); - // rebuild font - $font = ''; - $font .= pack('N', 0x10000); // sfnt version - $numTables = count($table); - $font .= pack('n', $numTables); // numTables - $entrySelector = floor(log($numTables, 2)); - $searchRange = pow(2, $entrySelector) * 16; - $rangeShift = ($numTables * 16) - $searchRange; - $font .= pack('n', $searchRange); // searchRange - $font .= pack('n', $entrySelector); // entrySelector - $font .= pack('n', $rangeShift); // rangeShift - $offset = ($numTables * 16); - foreach ($table as $tag => $data) { - $font .= $tag; // tag - $font .= pack('N', $data['checkSum']); // checkSum - $font .= pack('N', ($data['offset'] + $offset)); // offset - $font .= pack('N', $data['length']); // length - } - foreach ($table as $data) { - $font .= $data['data']; - } - // set checkSumAdjustment on head table - $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font)); - $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12); - return $font; - } - - /** - * Returs the checksum of a TTF table. - * @param $table (string) table to check - * @param $length (int) length of table in bytes - * @return int checksum - * @author Nicola Asuni - * @protected - * @since 5.2.000 (2010-06-02) - */ - protected function _getTTFtableChecksum($table, $length) { - $sum = 0; - $tlen = ($length / 4); - $offset = 0; - for ($i = 0; $i < $tlen; ++$i) { - $v = unpack('Ni', substr($table, $offset, 4)); - $sum += $v['i']; - $offset += 4; - } - $sum = unpack('Ni', pack('N', $sum)); - return $sum['i']; - } - - /** - * Outputs font widths - * @param $font (array) font data - * @param $cidoffset (int) offset for CID values - * @return PDF command string for font widths - * @author Nicola Asuni - * @protected - * @since 4.4.000 (2008-12-07) - */ - protected function _putfontwidths($font, $cidoffset=0) { - ksort($font['cw']); - $rangeid = 0; - $range = array(); - $prevcid = -2; - $prevwidth = -1; - $interval = false; - // for each character - foreach ($font['cw'] as $cid => $width) { - $cid -= $cidoffset; - if ($font['subset'] and ($cid > 255) and (!isset($font['subsetchars'][$cid]))) { - // ignore the unused characters (font subsetting) - continue; - } - if ($width != $font['dw']) { - if ($cid == ($prevcid + 1)) { - // consecutive CID - if ($width == $prevwidth) { - if ($width == $range[$rangeid][0]) { - $range[$rangeid][] = $width; - } else { - array_pop($range[$rangeid]); - // new range - $rangeid = $prevcid; - $range[$rangeid] = array(); - $range[$rangeid][] = $prevwidth; - $range[$rangeid][] = $width; - } - $interval = true; - $range[$rangeid]['interval'] = true; - } else { - if ($interval) { - // new range - $rangeid = $cid; - $range[$rangeid] = array(); - $range[$rangeid][] = $width; - } else { - $range[$rangeid][] = $width; - } - $interval = false; - } - } else { - // new range - $rangeid = $cid; - $range[$rangeid] = array(); - $range[$rangeid][] = $width; - $interval = false; - } - $prevcid = $cid; - $prevwidth = $width; - } - } - // optimize ranges - $prevk = -1; - $nextk = -1; - $prevint = false; - foreach ($range as $k => $ws) { - $cws = count($ws); - if (($k == $nextk) and (!$prevint) and ((!isset($ws['interval'])) or ($cws < 4))) { - if (isset($range[$k]['interval'])) { - unset($range[$k]['interval']); - } - $range[$prevk] = array_merge($range[$prevk], $range[$k]); - unset($range[$k]); - } else { - $prevk = $k; - } - $nextk = $k + $cws; - if (isset($ws['interval'])) { - if ($cws > 3) { - $prevint = true; - } else { - $prevint = false; - } - unset($range[$k]['interval']); - --$nextk; - } else { - $prevint = false; - } - } - // output data - $w = ''; - foreach ($range as $k => $ws) { - if (count(array_count_values($ws)) == 1) { - // interval mode is more compact - $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0]; - } else { - // range mode - $w .= ' '.$k.' [ '.implode(' ', $ws).' ]'; - } - } - return '/W ['.$w.' ]'; - } - /** * Output fonts. * @author Nicola Asuni @@ -11656,35 +8813,25 @@ class TCPDF { $this->_newobj(); $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj'); } - $mqr = $this->get_mqr(); - $this->set_mqr(false); + $mqr = TCPDF_STATIC::get_mqr(); + TCPDF_STATIC::set_mqr(false); foreach ($this->FontFiles as $file => $info) { // search and get font file to embedd - $fontdir = $info['fontdir']; - $file = strtolower($file); - $fontfile = ''; - // search files on various directories - if (($fontdir !== false) and Tools::file_exists_no_cache($fontdir.$file)) { - $fontfile = $fontdir.$file; - } elseif (Tools::file_exists_no_cache($this->_getfontpath().$file)) { - $fontfile = $this->_getfontpath().$file; - } elseif (Tools::file_exists_no_cache($file)) { - $fontfile = $file; - } - if (!$this->empty_string($fontfile)) { + $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']); + if (!TCPDF_STATIC::empty_string($fontfile)) { $font = file_get_contents($fontfile); $compressed = (substr($file, -2) == '.z'); - if ((!$compressed) and (isset($info['length2']))) { - $header = (ord($font{0}) == 128); + if ((!$compressed) AND (isset($info['length2']))) { + $header = (ord($font[0]) == 128); if ($header) { // strip first binary header $font = substr($font, 6); } - if ($header and (ord($font[$info['length1']]) == 128)) { + if ($header AND (ord($font[$info['length1']]) == 128)) { // strip second binary header $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6)); } - } elseif ($info['subset'] and ((!$compressed) or ($compressed and function_exists('gzcompress')))) { + } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) { if ($compressed) { // uncompress font $font = gzuncompress($font); @@ -11696,7 +8843,7 @@ class TCPDF { $subsetchars += $fontinfo['subsetchars']; } // rebuild a font subset - $font = $this->_getTrueTypeFontSubset($font, $subsetchars); + $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars); // calculate new font length $info['length1'] = strlen($font); if ($compressed) { @@ -11721,7 +8868,7 @@ class TCPDF { $this->_out($out); } } - $this->set_mqr($mqr); + TCPDF_STATIC::set_mqr($mqr); foreach ($this->fontkeys as $k) { //Font objects $font = $this->getFontBuffer($k); @@ -11734,7 +8881,7 @@ class TCPDF { $out .= ' /Subtype /Type1'; $out .= ' /BaseFont /'.$name; $out .= ' /Name /F'.$font['i']; - if ((strtolower($name) != 'symbol') and (strtolower($name) != 'zapfdingbats')) { + if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) { $out .= ' /Encoding /WinAnsiEncoding'; } if ($k == 'helvetica') { @@ -11744,7 +8891,7 @@ class TCPDF { $out .= ' >>'; $out .= "\n".'endobj'; $this->_out($out); - } elseif (($type == 'Type1') or ($type == 'TrueType')) { + } elseif (($type == 'Type1') OR ($type == 'TrueType')) { // additional Type1 or TrueType font $out = $this->_getobj($this->font_obj_ids[$k])."\n"; $out .= '<_newobj(); $s = '['; for ($i = 32; $i < 256; ++$i) { - $s .= $font['cw'][$i].' '; + if (isset($font['cw'][$i])) { + $s .= $font['cw'][$i].' '; + } else { + $s .= $font['dw'].' '; + } } $s .= ']'; $s .= "\n".'endobj'; @@ -11782,7 +8933,7 @@ class TCPDF { } $s .= ' /'.$fdk.' '.$fdv.''; } - if (!$this->empty_string($font['file'])) { + if (!TCPDF_STATIC::empty_string($font['file'])) { $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R'; } $s .= '>>'; @@ -11830,282 +8981,7 @@ class TCPDF { $out .= "\n".'endobj'; $this->_out($out); // ToUnicode map for Identity-H - $stream = "/CIDInit /ProcSet findresource begin\n"; - $stream .= "12 dict begin\n"; - $stream .= "begincmap\n"; - $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n"; - $stream .= "/CMapName /Adobe-Identity-UCS def\n"; - $stream .= "/CMapType 2 def\n"; - $stream .= "/WMode 0 def\n"; - $stream .= "1 begincodespacerange\n"; - $stream .= "<0000> \n"; - $stream .= "endcodespacerange\n"; - $stream .= "100 beginbfrange\n"; - $stream .= "<0000> <00ff> <0000>\n"; - $stream .= "<0100> <01ff> <0100>\n"; - $stream .= "<0200> <02ff> <0200>\n"; - $stream .= "<0300> <03ff> <0300>\n"; - $stream .= "<0400> <04ff> <0400>\n"; - $stream .= "<0500> <05ff> <0500>\n"; - $stream .= "<0600> <06ff> <0600>\n"; - $stream .= "<0700> <07ff> <0700>\n"; - $stream .= "<0800> <08ff> <0800>\n"; - $stream .= "<0900> <09ff> <0900>\n"; - $stream .= "<0a00> <0aff> <0a00>\n"; - $stream .= "<0b00> <0bff> <0b00>\n"; - $stream .= "<0c00> <0cff> <0c00>\n"; - $stream .= "<0d00> <0dff> <0d00>\n"; - $stream .= "<0e00> <0eff> <0e00>\n"; - $stream .= "<0f00> <0fff> <0f00>\n"; - $stream .= "<1000> <10ff> <1000>\n"; - $stream .= "<1100> <11ff> <1100>\n"; - $stream .= "<1200> <12ff> <1200>\n"; - $stream .= "<1300> <13ff> <1300>\n"; - $stream .= "<1400> <14ff> <1400>\n"; - $stream .= "<1500> <15ff> <1500>\n"; - $stream .= "<1600> <16ff> <1600>\n"; - $stream .= "<1700> <17ff> <1700>\n"; - $stream .= "<1800> <18ff> <1800>\n"; - $stream .= "<1900> <19ff> <1900>\n"; - $stream .= "<1a00> <1aff> <1a00>\n"; - $stream .= "<1b00> <1bff> <1b00>\n"; - $stream .= "<1c00> <1cff> <1c00>\n"; - $stream .= "<1d00> <1dff> <1d00>\n"; - $stream .= "<1e00> <1eff> <1e00>\n"; - $stream .= "<1f00> <1fff> <1f00>\n"; - $stream .= "<2000> <20ff> <2000>\n"; - $stream .= "<2100> <21ff> <2100>\n"; - $stream .= "<2200> <22ff> <2200>\n"; - $stream .= "<2300> <23ff> <2300>\n"; - $stream .= "<2400> <24ff> <2400>\n"; - $stream .= "<2500> <25ff> <2500>\n"; - $stream .= "<2600> <26ff> <2600>\n"; - $stream .= "<2700> <27ff> <2700>\n"; - $stream .= "<2800> <28ff> <2800>\n"; - $stream .= "<2900> <29ff> <2900>\n"; - $stream .= "<2a00> <2aff> <2a00>\n"; - $stream .= "<2b00> <2bff> <2b00>\n"; - $stream .= "<2c00> <2cff> <2c00>\n"; - $stream .= "<2d00> <2dff> <2d00>\n"; - $stream .= "<2e00> <2eff> <2e00>\n"; - $stream .= "<2f00> <2fff> <2f00>\n"; - $stream .= "<3000> <30ff> <3000>\n"; - $stream .= "<3100> <31ff> <3100>\n"; - $stream .= "<3200> <32ff> <3200>\n"; - $stream .= "<3300> <33ff> <3300>\n"; - $stream .= "<3400> <34ff> <3400>\n"; - $stream .= "<3500> <35ff> <3500>\n"; - $stream .= "<3600> <36ff> <3600>\n"; - $stream .= "<3700> <37ff> <3700>\n"; - $stream .= "<3800> <38ff> <3800>\n"; - $stream .= "<3900> <39ff> <3900>\n"; - $stream .= "<3a00> <3aff> <3a00>\n"; - $stream .= "<3b00> <3bff> <3b00>\n"; - $stream .= "<3c00> <3cff> <3c00>\n"; - $stream .= "<3d00> <3dff> <3d00>\n"; - $stream .= "<3e00> <3eff> <3e00>\n"; - $stream .= "<3f00> <3fff> <3f00>\n"; - $stream .= "<4000> <40ff> <4000>\n"; - $stream .= "<4100> <41ff> <4100>\n"; - $stream .= "<4200> <42ff> <4200>\n"; - $stream .= "<4300> <43ff> <4300>\n"; - $stream .= "<4400> <44ff> <4400>\n"; - $stream .= "<4500> <45ff> <4500>\n"; - $stream .= "<4600> <46ff> <4600>\n"; - $stream .= "<4700> <47ff> <4700>\n"; - $stream .= "<4800> <48ff> <4800>\n"; - $stream .= "<4900> <49ff> <4900>\n"; - $stream .= "<4a00> <4aff> <4a00>\n"; - $stream .= "<4b00> <4bff> <4b00>\n"; - $stream .= "<4c00> <4cff> <4c00>\n"; - $stream .= "<4d00> <4dff> <4d00>\n"; - $stream .= "<4e00> <4eff> <4e00>\n"; - $stream .= "<4f00> <4fff> <4f00>\n"; - $stream .= "<5000> <50ff> <5000>\n"; - $stream .= "<5100> <51ff> <5100>\n"; - $stream .= "<5200> <52ff> <5200>\n"; - $stream .= "<5300> <53ff> <5300>\n"; - $stream .= "<5400> <54ff> <5400>\n"; - $stream .= "<5500> <55ff> <5500>\n"; - $stream .= "<5600> <56ff> <5600>\n"; - $stream .= "<5700> <57ff> <5700>\n"; - $stream .= "<5800> <58ff> <5800>\n"; - $stream .= "<5900> <59ff> <5900>\n"; - $stream .= "<5a00> <5aff> <5a00>\n"; - $stream .= "<5b00> <5bff> <5b00>\n"; - $stream .= "<5c00> <5cff> <5c00>\n"; - $stream .= "<5d00> <5dff> <5d00>\n"; - $stream .= "<5e00> <5eff> <5e00>\n"; - $stream .= "<5f00> <5fff> <5f00>\n"; - $stream .= "<6000> <60ff> <6000>\n"; - $stream .= "<6100> <61ff> <6100>\n"; - $stream .= "<6200> <62ff> <6200>\n"; - $stream .= "<6300> <63ff> <6300>\n"; - $stream .= "endbfrange\n"; - $stream .= "100 beginbfrange\n"; - $stream .= "<6400> <64ff> <6400>\n"; - $stream .= "<6500> <65ff> <6500>\n"; - $stream .= "<6600> <66ff> <6600>\n"; - $stream .= "<6700> <67ff> <6700>\n"; - $stream .= "<6800> <68ff> <6800>\n"; - $stream .= "<6900> <69ff> <6900>\n"; - $stream .= "<6a00> <6aff> <6a00>\n"; - $stream .= "<6b00> <6bff> <6b00>\n"; - $stream .= "<6c00> <6cff> <6c00>\n"; - $stream .= "<6d00> <6dff> <6d00>\n"; - $stream .= "<6e00> <6eff> <6e00>\n"; - $stream .= "<6f00> <6fff> <6f00>\n"; - $stream .= "<7000> <70ff> <7000>\n"; - $stream .= "<7100> <71ff> <7100>\n"; - $stream .= "<7200> <72ff> <7200>\n"; - $stream .= "<7300> <73ff> <7300>\n"; - $stream .= "<7400> <74ff> <7400>\n"; - $stream .= "<7500> <75ff> <7500>\n"; - $stream .= "<7600> <76ff> <7600>\n"; - $stream .= "<7700> <77ff> <7700>\n"; - $stream .= "<7800> <78ff> <7800>\n"; - $stream .= "<7900> <79ff> <7900>\n"; - $stream .= "<7a00> <7aff> <7a00>\n"; - $stream .= "<7b00> <7bff> <7b00>\n"; - $stream .= "<7c00> <7cff> <7c00>\n"; - $stream .= "<7d00> <7dff> <7d00>\n"; - $stream .= "<7e00> <7eff> <7e00>\n"; - $stream .= "<7f00> <7fff> <7f00>\n"; - $stream .= "<8000> <80ff> <8000>\n"; - $stream .= "<8100> <81ff> <8100>\n"; - $stream .= "<8200> <82ff> <8200>\n"; - $stream .= "<8300> <83ff> <8300>\n"; - $stream .= "<8400> <84ff> <8400>\n"; - $stream .= "<8500> <85ff> <8500>\n"; - $stream .= "<8600> <86ff> <8600>\n"; - $stream .= "<8700> <87ff> <8700>\n"; - $stream .= "<8800> <88ff> <8800>\n"; - $stream .= "<8900> <89ff> <8900>\n"; - $stream .= "<8a00> <8aff> <8a00>\n"; - $stream .= "<8b00> <8bff> <8b00>\n"; - $stream .= "<8c00> <8cff> <8c00>\n"; - $stream .= "<8d00> <8dff> <8d00>\n"; - $stream .= "<8e00> <8eff> <8e00>\n"; - $stream .= "<8f00> <8fff> <8f00>\n"; - $stream .= "<9000> <90ff> <9000>\n"; - $stream .= "<9100> <91ff> <9100>\n"; - $stream .= "<9200> <92ff> <9200>\n"; - $stream .= "<9300> <93ff> <9300>\n"; - $stream .= "<9400> <94ff> <9400>\n"; - $stream .= "<9500> <95ff> <9500>\n"; - $stream .= "<9600> <96ff> <9600>\n"; - $stream .= "<9700> <97ff> <9700>\n"; - $stream .= "<9800> <98ff> <9800>\n"; - $stream .= "<9900> <99ff> <9900>\n"; - $stream .= "<9a00> <9aff> <9a00>\n"; - $stream .= "<9b00> <9bff> <9b00>\n"; - $stream .= "<9c00> <9cff> <9c00>\n"; - $stream .= "<9d00> <9dff> <9d00>\n"; - $stream .= "<9e00> <9eff> <9e00>\n"; - $stream .= "<9f00> <9fff> <9f00>\n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= "endbfrange\n"; - $stream .= "56 beginbfrange\n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= " \n"; - $stream .= "endbfrange\n"; - $stream .= "endcmap\n"; - $stream .= "CMapName currentdict /CMap defineresource pop\n"; - $stream .= "end\n"; - $stream .= "end"; + $stream = TCPDF_FONT_DATA::$uni_identity_h; // ToUnicode Object $this->_newobj(); $stream = ($this->compress) ? gzcompress($stream) : $stream; @@ -12125,8 +9001,8 @@ class TCPDF { $out .= ' /CIDSystemInfo << '.$cidinfo.' >>'; $out .= ' /FontDescriptor '.($this->n + 1).' 0 R'; $out .= ' /DW '.$font['dw']; // default width - $out .= "\n".$this->_putfontwidths($font, 0); - if (isset($font['ctg']) and (!$this->empty_string($font['ctg']))) { + $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0); + if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) { $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R'; } $out .= ' >>'; @@ -12144,7 +9020,7 @@ class TCPDF { $out .= ' /'.$key.' '.$value; } $fontdir = false; - if (!$this->empty_string($font['file'])) { + if (!TCPDF_STATIC::empty_string($font['file'])) { // A stream containing a TrueType font $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R'; $fontdir = $this->FontFiles[$font['file']]['fontdir']; @@ -12152,23 +9028,15 @@ class TCPDF { $out .= ' >>'; $out .= "\n".'endobj'; $this->_out($out); - if (isset($font['ctg']) and (!$this->empty_string($font['ctg']))) { + if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) { $this->_newobj(); // Embed CIDToGIDMap // A specification of the mapping from CIDs to glyph indices // search and get CTG font file to embedd $ctgfile = strtolower($font['ctg']); // search and get ctg font file to embedd - $fontfile = ''; - // search files on various directories - if (($fontdir !== false) and Tools::file_exists_no_cache($fontdir.$ctgfile)) { - $fontfile = $fontdir.$ctgfile; - } elseif (Tools::file_exists_no_cache($this->_getfontpath().$ctgfile)) { - $fontfile = $this->_getfontpath().$ctgfile; - } elseif (Tools::file_exists_no_cache($ctgfile)) { - $fontfile = $ctgfile; - } - if ($this->empty_string($fontfile)) { + $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir); + if (TCPDF_STATIC::empty_string($fontfile)) { $this->Error('Font file not found: '.$ctgfile); } $stream = $this->_getrawstream(file_get_contents($fontfile)); @@ -12241,7 +9109,7 @@ class TCPDF { $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>'; $out .= ' /FontDescriptor '.($this->n + 1).' 0 R'; $out .= ' /DW '.$font['dw']; - $out .= "\n".$this->_putfontwidths($font, $cidoffset); + $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset); $out .= ' >>'; $out .= "\n".'endobj'; $this->_out($out); @@ -12269,7 +9137,7 @@ class TCPDF { foreach ($this->imagekeys as $file) { $info = $this->getImageBuffer($file); // set object for alternate images array - if ((!$this->pdfa_mode) and isset($info['altimgs']) and !empty($info['altimgs'])) { + if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) { $altoid = $this->_newobj(); $out = '['; foreach ($info['altimgs'] as $altimage) { @@ -12301,7 +9169,7 @@ class TCPDF { } // set color space $icc = false; - if (isset($info['icc']) and ($info['icc'] !== false)) { + if (isset($info['icc']) AND ($info['icc'] !== false)) { // ICC Colour Space $icc = true; $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]'; @@ -12316,11 +9184,11 @@ class TCPDF { $out .= ' /Decode [1 0 1 0 1 0 1 0]'; } $out .= ' /BitsPerComponent '.$info['bpc']; - if (isset($altoid) and ($altoid > 0)) { + if (isset($altoid) AND ($altoid > 0)) { // reference to alternate images dictionary $out .= ' /Alternates '.$altoid.' 0 R'; } - if (isset($info['exurl']) and !empty($info['exurl'])) { + if (isset($info['exurl']) AND !empty($info['exurl'])) { // external stream $out .= ' /Length 0'; $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>'; @@ -12336,13 +9204,33 @@ class TCPDF { if (isset($info['parms'])) { $out .= ' '.$info['parms']; } - if (isset($info['trns']) and is_array($info['trns'])) { + if (isset($info['trns']) AND is_array($info['trns'])) { $trns = ''; $count_info = count($info['trns']); - for ($i=0; $i < $count_info; ++$i) { - $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; + if ($info['cs'] == 'Indexed') { + $maxval =(pow(2, $info['bpc']) - 1); + for ($i = 0; $i < $count_info; ++$i) { + if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) { + // this is not a binary type mask @TODO: create a SMask + $trns = ''; + break; + } elseif (empty($trns) AND ($info['trns'][$i] == 0)) { + // store the first fully transparent value + $trns .= $i.' '.$i.' '; + } + } + } else { + // grayscale or RGB + for ($i = 0; $i < $count_info; ++$i) { + if ($info['trns'][$i] == 0) { + $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; + } + } + } + // Colour Key Masking + if (!empty($trns)) { + $out .= ' /Mask ['.$trns.']'; } - $out .= ' /Mask ['.$trns.']'; } $stream = $this->_getrawstream($info['data']); $out .= ' /Length '.strlen($stream).' >>'; @@ -12376,7 +9264,7 @@ class TCPDF { protected function _putxobjects() { foreach ($this->xobjects as $key => $data) { if (isset($data['outdata'])) { - $stream = trim($data['outdata']); + $stream = str_replace($this->epsmarker, '', trim($data['outdata'])); $out = $this->_getobj($data['n'])."\n"; $out .= '<<'; $out .= ' /Type /XObject'; @@ -12392,7 +9280,7 @@ class TCPDF { $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'; if (!$this->pdfa_mode) { // transparency - if (isset($data['extgstates']) and !empty($data['extgstates'])) { + if (isset($data['extgstates']) AND !empty($data['extgstates'])) { $out .= ' /ExtGState <<'; foreach ($data['extgstates'] as $k => $extgstate) { if (isset($this->extgstates[$k]['name'])) { @@ -12404,7 +9292,7 @@ class TCPDF { } $out .= ' >>'; } - if (isset($data['gradients']) and !empty($data['gradients'])) { + if (isset($data['gradients']) AND !empty($data['gradients'])) { $gp = ''; $gs = ''; foreach ($data['gradients'] as $id => $grad) { @@ -12418,7 +9306,7 @@ class TCPDF { } } // spot colors - if (isset($data['spot_colors']) and !empty($data['spot_colors'])) { + if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) { $out .= ' /ColorSpace <<'; foreach ($data['spot_colors'] as $name => $color) { $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R'; @@ -12434,7 +9322,7 @@ class TCPDF { $out .= ' >>'; } // images or nested xobjects - if (!empty($data['images']) or !empty($data['xobjects'])) { + if (!empty($data['images']) OR !empty($data['xobjects'])) { $out .= ' /XObject <<'; foreach ($data['images'] as $imgid) { $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R'; @@ -12445,11 +9333,11 @@ class TCPDF { $out .= ' >>'; } $out .= ' >>'; //end resources - if (isset($data['group']) and ($data['group'] !== false)) { + if (isset($data['group']) AND ($data['group'] !== false)) { // set transparency group $out .= ' /Group << /Type /Group /S /Transparency'; if (is_array($data['group'])) { - if (isset($data['group']['CS']) and !empty($data['group']['CS'])) { + if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) { $out .= ' /CS /'.$data['group']['CS']; } if (isset($data['group']['I'])) { @@ -12530,7 +9418,7 @@ class TCPDF { } if (!$this->pdfa_mode) { // transparency - if (isset($this->extgstates) and !empty($this->extgstates)) { + if (isset($this->extgstates) AND !empty($this->extgstates)) { $out .= ' /ExtGState <<'; foreach ($this->extgstates as $k => $extgstate) { if (isset($extgstate['name'])) { @@ -12542,7 +9430,7 @@ class TCPDF { } $out .= ' >>'; } - if (isset($this->gradients) and !empty($this->gradients)) { + if (isset($this->gradients) AND !empty($this->gradients)) { $gp = ''; $gs = ''; foreach ($this->gradients as $id => $grad) { @@ -12556,7 +9444,7 @@ class TCPDF { } } // spot colors - if (isset($this->spot_colors) and !empty($this->spot_colors)) { + if (isset($this->spot_colors) AND !empty($this->spot_colors)) { $out .= ' /ColorSpace <<'; foreach ($this->spot_colors as $color) { $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R'; @@ -12582,10 +9470,10 @@ class TCPDF { $this->_putxobjects(); $this->_putresourcedict(); $this->_putdests(); - $this->_putbookmarks(); $this->_putEmbeddedFiles(); $this->_putannotsobjs(); $this->_putjavascript(); + $this->_putbookmarks(); $this->_putencryption(); } @@ -12603,30 +9491,30 @@ class TCPDF { if ($this->docinfounicode) { $this->isunicode = true; } - if (!$this->empty_string($this->title)) { + if (!TCPDF_STATIC::empty_string($this->title)) { // The document's title. $out .= ' /Title '.$this->_textstring($this->title, $oid); } - if (!$this->empty_string($this->author)) { + if (!TCPDF_STATIC::empty_string($this->author)) { // The name of the person who created the document. $out .= ' /Author '.$this->_textstring($this->author, $oid); } - if (!$this->empty_string($this->subject)) { + if (!TCPDF_STATIC::empty_string($this->subject)) { // The subject of the document. $out .= ' /Subject '.$this->_textstring($this->subject, $oid); } - if (!$this->empty_string($this->keywords)) { + if (!TCPDF_STATIC::empty_string($this->keywords)) { // Keywords associated with the document. - $out .= ' /Keywords '.$this->_textstring($this->keywords.' TCPDF', $oid); + $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid); } - if (!$this->empty_string($this->creator)) { + if (!TCPDF_STATIC::empty_string($this->creator)) { // If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted. $out .= ' /Creator '.$this->_textstring($this->creator, $oid); } // restore previous isunicode value $this->isunicode = $prev_isunicode; // default producer - $out .= ' /Producer '.$this->_textstring($this->pdfproducer, $oid); + $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid); // The date and time the document was created, in human-readable form $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp); // The date and time the document was most recently modified, in human-readable form @@ -12650,6 +9538,17 @@ class TCPDF { $this->custom_xmp = $xmp; } + /** + * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag. + * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method! + * @param $xmp (string) Custom XMP RDF data. + * @since 6.3.0 (2019-09-19) + * @public + */ + public function setExtraXMPRDF($xmp) { + $this->custom_xmp_rdf = $xmp; + } + /** * Put XMP data object and return ID. * @return (int) The object ID. @@ -12664,44 +9563,44 @@ class TCPDF { $prev_encrypted = $this->encrypted; $this->encrypted = false; // set XMP data - $xmp = 'unichr(0xfeff).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; + $xmp = 'isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; $xmp .= ''."\n"; $xmp .= "\t".''."\n"; $xmp .= "\t\t".''."\n"; $xmp .= "\t\t\t".'application/pdf'."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t\t".''."\n"; - $xmp .= "\t\t\t\t\t".''.$this->_escapeXML($this->title).''."\n"; + $xmp .= "\t\t\t\t\t".''.TCPDF_STATIC::_escapeXML($this->title).''."\n"; $xmp .= "\t\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t\t".''."\n"; - $xmp .= "\t\t\t\t\t".''.$this->_escapeXML($this->author).''."\n"; + $xmp .= "\t\t\t\t\t".''.TCPDF_STATIC::_escapeXML($this->author).''."\n"; $xmp .= "\t\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t\t".''."\n"; - $xmp .= "\t\t\t\t\t".''.$this->_escapeXML($this->subject).''."\n"; + $xmp .= "\t\t\t\t\t".''.TCPDF_STATIC::_escapeXML($this->subject).''."\n"; $xmp .= "\t\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t\t\t".''."\n"; - $xmp .= "\t\t\t\t\t".''.$this->_escapeXML($this->keywords).''."\n"; + $xmp .= "\t\t\t\t\t".''.TCPDF_STATIC::_escapeXML($this->keywords).''."\n"; $xmp .= "\t\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t".''."\n"; // convert doc creation date format - $dcdate = $this->getFormattedDate($this->doc_creation_timestamp); + $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp); $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2); $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2); - $doccreationdate .= '+'.substr($dcdate, 15, 2).':'.substr($dcdate, 18, 2); - $doccreationdate = $this->_escapeXML($doccreationdate); + $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2); + $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate); // convert doc modification date format - $dmdate = $this->getFormattedDate($this->doc_modification_timestamp); + $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp); $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2); $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2); - $docmoddate .= '+'.substr($dmdate, 15, 2).':'.substr($dmdate, 18, 2); - $docmoddate = $this->_escapeXML($docmoddate); + $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2); + $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate); $xmp .= "\t\t".''."\n"; $xmp .= "\t\t\t".''.$doccreationdate.''."\n"; $xmp .= "\t\t\t".''.$this->creator.''."\n"; @@ -12709,8 +9608,8 @@ class TCPDF { $xmp .= "\t\t\t".''.$doccreationdate.''."\n"; $xmp .= "\t\t".''."\n"; $xmp .= "\t\t".''."\n"; - $xmp .= "\t\t\t".''.$this->_escapeXML($this->keywords).' TCPDF'."\n"; - $xmp .= "\t\t\t".''.$this->_escapeXML($this->pdfproducer).''."\n"; + $xmp .= "\t\t\t".''.TCPDF_STATIC::_escapeXML($this->keywords).''."\n"; + $xmp .= "\t\t\t".''.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).''."\n"; $xmp .= "\t\t".''."\n"; $xmp .= "\t\t".''."\n"; $uuid = 'uuid:'.substr($this->file_id, 0, 8).'-'.substr($this->file_id, 8, 4).'-'.substr($this->file_id, 12, 4).'-'.substr($this->file_id, 16, 4).'-'.substr($this->file_id, 20, 12); @@ -12719,7 +9618,7 @@ class TCPDF { $xmp .= "\t\t".''."\n"; if ($this->pdfa_mode) { $xmp .= "\t\t".''."\n"; - $xmp .= "\t\t\t".'1'."\n"; + $xmp .= "\t\t\t".''.$this->pdfa_version.''."\n"; $xmp .= "\t\t\t".'B'."\n"; $xmp .= "\t\t".''."\n"; } @@ -12731,6 +9630,16 @@ class TCPDF { $xmp .= "\t\t\t\t\t\t".'http://ns.adobe.com/pdf/1.3/'."\n"; $xmp .= "\t\t\t\t\t\t".'pdf'."\n"; $xmp .= "\t\t\t\t\t\t".'Adobe PDF Schema'."\n"; + $xmp .= "\t\t\t\t\t\t".''."\n"; + $xmp .= "\t\t\t\t\t\t\t".''."\n"; + $xmp .= "\t\t\t\t\t\t\t\t".''."\n"; + $xmp .= "\t\t\t\t\t\t\t\t\t".'internal'."\n"; + $xmp .= "\t\t\t\t\t\t\t\t\t".'Adobe PDF Schema'."\n"; + $xmp .= "\t\t\t\t\t\t\t\t\t".'InstanceID'."\n"; + $xmp .= "\t\t\t\t\t\t\t\t\t".'URI'."\n"; + $xmp .= "\t\t\t\t\t\t\t\t".''."\n"; + $xmp .= "\t\t\t\t\t\t\t".''."\n"; + $xmp .= "\t\t\t\t\t\t".''."\n"; $xmp .= "\t\t\t\t\t".''."\n"; $xmp .= "\t\t\t\t\t".''."\n"; $xmp .= "\t\t\t\t\t\t".'http://ns.adobe.com/xap/1.0/mm/'."\n"; @@ -12777,6 +9686,7 @@ class TCPDF { $xmp .= "\t\t\t\t".''."\n"; $xmp .= "\t\t\t".''."\n"; $xmp .= "\t\t".''."\n"; + $xmp .= $this->custom_xmp_rdf; $xmp .= "\t".''."\n"; $xmp .= $this->custom_xmp; $xmp .= ''."\n"; @@ -12797,10 +9707,10 @@ class TCPDF { protected function _putcatalog() { // put XMP $xmpobj = $this->_putXMP(); - // if required, add standard sRGB_IEC61966-2.1 blackscaled ICC colour profile - if ($this->pdfa_mode or $this->force_srgb) { + // if required, add standard sRGB ICC colour profile + if ($this->pdfa_mode OR $this->force_srgb) { $iccobj = $this->_newobj(); - $icc = file_get_contents(dirname(__FILE__).'/sRGB.icc'); + $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc'); $filter = ''; if ($this->compress) { $filter = ' /Filter /FlateDecode'; @@ -12817,18 +9727,25 @@ class TCPDF { $out .= ' /Pages 1 0 R'; //$out .= ' /PageLabels ' //...; $out .= ' /Names <<'; - if ((!$this->pdfa_mode) and ((!empty($this->javascript)) or (!empty($this->js_objects)))) { - $out .= ' /JavaScript '.($this->n_js).' 0 R'; + if ((!$this->pdfa_mode) AND !empty($this->n_js)) { + $out .= ' /JavaScript '.$this->n_js; + } + if (!empty($this->efnames)) { + $out .= ' /EmbeddedFiles <efnames AS $fn => $fref) { + $out .= ' '.$this->_datastring($fn).' '.$fref; + } + $out .= ' ]>>'; } $out .= ' >>'; if (!empty($this->dests)) { - $out .= ' /Dests '.$this->n_dests.' 0 R'; + $out .= ' /Dests '.($this->n_dests).' 0 R'; } $out .= $this->_putviewerpreferences(); - if (isset($this->LayoutMode) and (!$this->empty_string($this->LayoutMode))) { + if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) { $out .= ' /PageLayout /'.$this->LayoutMode; } - if (isset($this->PageMode) and (!$this->empty_string($this->PageMode))) { + if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) { $out .= ' /PageMode /'.$this->PageMode; } if (count($this->outlines) > 0) { @@ -12855,7 +9772,7 @@ class TCPDF { } //$out .= ' /SpiderInfo <<>>'; // set OutputIntent to sRGB IEC61966-2.1 if required - if ($this->pdfa_mode or $this->force_srgb) { + if ($this->pdfa_mode OR $this->force_srgb) { $out .= ' /OutputIntents [<<'; $out .= ' /Type /OutputIntent'; $out .= ' /S /GTS_PDFA1'; @@ -12869,15 +9786,16 @@ class TCPDF { //$out .= ' /PieceInfo <<>>'; if (!empty($this->pdflayers)) { $lyrobjs = ''; - $lyrobjs_print = ''; - $lyrobjs_view = ''; + $lyrobjs_off = ''; + $lyrobjs_lock = ''; foreach ($this->pdflayers as $layer) { - $lyrobjs .= ' '.$layer['objid'].' 0 R'; - if ($layer['print']) { - $lyrobjs_print .= ' '.$layer['objid'].' 0 R'; + $layer_obj_ref = ' '.$layer['objid'].' 0 R'; + $lyrobjs .= $layer_obj_ref; + if ($layer['view'] === false) { + $lyrobjs_off .= $layer_obj_ref; } - if ($layer['view']) { - $lyrobjs_view .= ' '.$layer['objid'].' 0 R'; + if ($layer['lock']) { + $lyrobjs_lock .= $layer_obj_ref; } } $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']'; @@ -12885,8 +9803,8 @@ class TCPDF { $out .= ' /Name '.$this->_textstring('Layers', $oid); $out .= ' /Creator '.$this->_textstring('TCPDF', $oid); $out .= ' /BaseState /ON'; - $out .= ' /ON ['.$lyrobjs_print.']'; - $out .= ' /OFF ['.$lyrobjs_view.']'; + $out .= ' /OFF ['.$lyrobjs_off.']'; + $out .= ' /Locked ['.$lyrobjs_lock.']'; $out .= ' /Intent /View'; $out .= ' /AS ['; $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>'; @@ -12900,10 +9818,12 @@ class TCPDF { $out .= ' >>'; } // AcroForm - if (!empty($this->form_obj_id) or ($this->sign and isset($this->signature_data['cert_type']))) { + if (!empty($this->form_obj_id) + OR ($this->sign AND isset($this->signature_data['cert_type'])) + OR !empty($this->empty_signature_appearance)) { $out .= ' /AcroForm <<'; $objrefs = ''; - if ($this->sign and isset($this->signature_data['cert_type'])) { + if ($this->sign AND isset($this->signature_data['cert_type'])) { // set reference for signature object $objrefs .= $this->sig_obj_id.' 0 R'; } @@ -12920,8 +9840,10 @@ class TCPDF { } $out .= ' /Fields ['.$objrefs.']'; // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields. - $out .= ' /NeedAppearances false'; - if ($this->sign and isset($this->signature_data['cert_type'])) { + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /NeedAppearances false'; + } + if ($this->sign AND isset($this->signature_data['cert_type'])) { if ($this->signature_data['cert_type'] > 0) { $out .= ' /SigFlags 3'; } else { @@ -12929,7 +9851,7 @@ class TCPDF { } } //$out .= ' /CO '; - if (isset($this->annotation_fonts) and !empty($this->annotation_fonts)) { + if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) { $out .= ' /DR <<'; $out .= ' /Font <<'; foreach ($this->annotation_fonts as $fontkey => $fontid) { @@ -12943,7 +9865,8 @@ class TCPDF { //$out .= ' /XFA '; $out .= ' >>'; // signatures - if ($this->sign and isset($this->signature_data['cert_type'])) { + if ($this->sign AND isset($this->signature_data['cert_type']) + AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) { if ($this->signature_data['cert_type'] > 0) { $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>'; } else { @@ -12969,67 +9892,68 @@ class TCPDF { * @protected */ protected function _putviewerpreferences() { + $vp = $this->viewer_preferences; $out = ' /ViewerPreferences <<'; if ($this->rtl) { $out .= ' /Direction /R2L'; } else { $out .= ' /Direction /L2R'; } - if (isset($this->viewer_preferences['HideToolbar']) and ($this->viewer_preferences['HideToolbar'])) { + if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) { $out .= ' /HideToolbar true'; } - if (isset($this->viewer_preferences['HideMenubar']) and ($this->viewer_preferences['HideMenubar'])) { + if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) { $out .= ' /HideMenubar true'; } - if (isset($this->viewer_preferences['HideWindowUI']) and ($this->viewer_preferences['HideWindowUI'])) { + if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) { $out .= ' /HideWindowUI true'; } - if (isset($this->viewer_preferences['FitWindow']) and ($this->viewer_preferences['FitWindow'])) { + if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) { $out .= ' /FitWindow true'; } - if (isset($this->viewer_preferences['CenterWindow']) and ($this->viewer_preferences['CenterWindow'])) { + if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) { $out .= ' /CenterWindow true'; } - if (isset($this->viewer_preferences['DisplayDocTitle']) and ($this->viewer_preferences['DisplayDocTitle'])) { + if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) { $out .= ' /DisplayDocTitle true'; } - if (isset($this->viewer_preferences['NonFullScreenPageMode'])) { - $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode']; + if (isset($vp['NonFullScreenPageMode'])) { + $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode']; } - if (isset($this->viewer_preferences['ViewArea'])) { - $out .= ' /ViewArea /'.$this->viewer_preferences['ViewArea']; + if (isset($vp['ViewArea'])) { + $out .= ' /ViewArea /'.$vp['ViewArea']; } - if (isset($this->viewer_preferences['ViewClip'])) { - $out .= ' /ViewClip /'.$this->viewer_preferences['ViewClip']; + if (isset($vp['ViewClip'])) { + $out .= ' /ViewClip /'.$vp['ViewClip']; } - if (isset($this->viewer_preferences['PrintArea'])) { - $out .= ' /PrintArea /'.$this->viewer_preferences['PrintArea']; + if (isset($vp['PrintArea'])) { + $out .= ' /PrintArea /'.$vp['PrintArea']; } - if (isset($this->viewer_preferences['PrintClip'])) { - $out .= ' /PrintClip /'.$this->viewer_preferences['PrintClip']; + if (isset($vp['PrintClip'])) { + $out .= ' /PrintClip /'.$vp['PrintClip']; } - if (isset($this->viewer_preferences['PrintScaling'])) { - $out .= ' /PrintScaling /'.$this->viewer_preferences['PrintScaling']; + if (isset($vp['PrintScaling'])) { + $out .= ' /PrintScaling /'.$vp['PrintScaling']; } - if (isset($this->viewer_preferences['Duplex']) and (!$this->empty_string($this->viewer_preferences['Duplex']))) { - $out .= ' /Duplex /'.$this->viewer_preferences['Duplex']; + if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) { + $out .= ' /Duplex /'.$vp['Duplex']; } - if (isset($this->viewer_preferences['PickTrayByPDFSize'])) { - if ($this->viewer_preferences['PickTrayByPDFSize']) { + if (isset($vp['PickTrayByPDFSize'])) { + if ($vp['PickTrayByPDFSize']) { $out .= ' /PickTrayByPDFSize true'; } else { $out .= ' /PickTrayByPDFSize false'; } } - if (isset($this->viewer_preferences['PrintPageRange'])) { + if (isset($vp['PrintPageRange'])) { $PrintPageRangeNum = ''; - foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) { + foreach ($vp['PrintPageRange'] as $k => $v) { $PrintPageRangeNum .= ' '.($v - 1).''; } $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']'; } - if (isset($this->viewer_preferences['NumCopies'])) { - $out .= ' /NumCopies '.intval($this->viewer_preferences['NumCopies']); + if (isset($vp['NumCopies'])) { + $out .= ' /NumCopies '.intval($vp['NumCopies']); } $out .= ' >>'; return $out; @@ -13049,6 +9973,10 @@ class TCPDF { * @protected */ protected function _enddoc() { + if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) { + // save subset chars of the previous font + $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); + } $this->state = 1; $this->_putheader(); $this->_putpages(); @@ -13064,7 +9992,7 @@ class TCPDF { $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page $out .= ' /F 4'; $out .= ' /FT /Sig'; - $signame = sprintf('Signature_%03d', ($key + 1)); + $signame = $esa['name'].sprintf(' [%03d]', ($key + 1)); $out .= ' /T '.$this->_textstring($signame, $esa['objid']); $out .= ' /Ff 0'; $out .= ' >>'; @@ -13073,7 +10001,7 @@ class TCPDF { } } // Signature - if ($this->sign and isset($this->signature_data['cert_type'])) { + if ($this->sign AND isset($this->signature_data['cert_type'])) { // widget annotation for signature $out = $this->_getobj($this->sig_obj_id)."\n"; $out .= '<< /Type /Annot'; @@ -13082,7 +10010,7 @@ class TCPDF { $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page $out .= ' /F 4'; $out .= ' /FT /Sig'; - $out .= ' /T '.$this->_textstring('Signature_000', $this->sig_obj_id); + $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id); $out .= ' /Ff 0'; $out .= ' /V '.($this->sig_obj_id + 1).' 0 R'; $out .= ' >>'; @@ -13103,7 +10031,7 @@ class TCPDF { $this->_out('0000000000 65535 f '); $freegen = ($this->n + 2); for ($i=1; $i <= $this->n; ++$i) { - if (!isset($this->offsets[$i]) and ($i > 1)) { + if (!isset($this->offsets[$i]) AND ($i > 1)) { $this->_out(sprintf('0000000000 %05d f ', $freegen)); ++$freegen; } else { @@ -13126,17 +10054,6 @@ class TCPDF { $this->_out($o); $this->_out('%%EOF'); $this->state = 3; // end-of-doc - if ($this->diskcache) { - // remove temporary files used for images - foreach ($this->imagekeys as $key) { - // remove temporary files - unlink($this->images[$key]); - } - foreach ($this->fontkeys as $key) { - // remove temporary files - unlink($this->fonts[$key]); - } - } } /** @@ -13153,7 +10070,7 @@ class TCPDF { // initialize array for graphics tranformation positions inside a page buffer $this->transfmrk[$this->page] = array(); $this->state = 2; - if ($this->empty_string($orientation)) { + if (TCPDF_STATIC::empty_string($orientation)) { if (isset($this->CurOrientation)) { $orientation = $this->CurOrientation; } elseif ($this->fwPt > $this->fhPt) { @@ -13164,7 +10081,7 @@ class TCPDF { $orientation = 'P'; } } - if ($this->empty_string($format)) { + if (TCPDF_STATIC::empty_string($format)) { $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)]; $this->setPageOrientation($orientation); } else { @@ -13180,7 +10097,7 @@ class TCPDF { // start a new group $this->currpagegroup = $this->newpagegroup[$this->page]; $this->pagegroups[$this->currpagegroup] = 1; - } elseif (isset($this->currpagegroup) and ($this->currpagegroup > 0)) { + } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) { ++$this->pagegroups[$this->currpagegroup]; } } @@ -13298,28 +10215,6 @@ class TCPDF { } - /** - * Read a 4-byte (32 bit) integer from file. - * @param $f (string) file name. - * @return 4-byte integer - * @protected - */ - protected function _freadint($f) { - $a = unpack('Ni', fread($f, 4)); - return $a['i']; - } - - /** - * Add "\" before "\", "(" and ")" - * @param $s (string) string to escape. - * @return string escaped string. - * @protected - */ - protected function _escape($s) { - // the chr(13) substitution fixes the Bugs item #1421290. - return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); - } - /** * Format a data string for meta information * @param $s (string) data string to escape. @@ -13332,7 +10227,7 @@ class TCPDF { $n = $this->n; } $s = $this->_encrypt_data($n, $s); - return '('. $this->_escape($s).')'; + return '('. TCPDF_STATIC::_escape($s).')'; } /** @@ -13343,7 +10238,7 @@ class TCPDF { */ public function setDocCreationTimestamp($time) { if (is_string($time)) { - $time = getTimestamp($time); + $time = TCPDF_STATIC::getTimestamp($time); } $this->doc_creation_timestamp = intval($time); } @@ -13356,7 +10251,7 @@ class TCPDF { */ public function setDocModificationTimestamp($time) { if (is_string($time)) { - $time = getTimestamp($time); + $time = TCPDF_STATIC::getTimestamp($time); } $this->doc_modification_timestamp = intval($time); } @@ -13381,32 +10276,6 @@ class TCPDF { return $this->doc_modification_timestamp; } - /** - * Returns timestamp in seconds from formatted date-time. - * @param $date (string) Formatted date-time. - * @return int seconds. - * @public - * @since 5.9.152 (2012-03-23) - */ - public function getTimestamp($date) { - if (($date[0] == 'D') and ($date[1] == ':')) { - // remove date prefix if present - $date = substr($date, 2); - } - return strtotime($date); - } - - /** - * Returns a formatted date-time. - * @param $time (int) Time in seconds. - * @return string escaped date string. - * @public - * @since 5.9.152 (2012-03-23) - */ - public function getFormattedDate($time) { - return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\''; - } - /** * Returns a formatted date for meta information * @param $n (int) Object ID. @@ -13416,10 +10285,10 @@ class TCPDF { * @since 4.6.028 (2009-08-25) */ protected function _datestring($n=0, $timestamp=0) { - if ((empty($timestamp)) or ($timestamp < 0)) { + if ((empty($timestamp)) OR ($timestamp < 0)) { $timestamp = $this->doc_creation_timestamp; } - return $this->_datastring('D:'.$this->getFormattedDate($timestamp), $n); + return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n); } /** @@ -13432,44 +10301,11 @@ class TCPDF { protected function _textstring($s, $n=0) { if ($this->isunicode) { //Convert string to UTF-16BE - $s = $this->UTF8ToUTF16BE($s, true); + $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont); } return $this->_datastring($s, $n); } - /** - * THIS METHOD IS DEPRECATED - * Format a text string - * @param $s (string) string to escape. - * @return string escaped string. - * @protected - * @deprecated - */ - protected function _escapetext($s) { - if ($this->isunicode) { - if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1')) { - $s = $this->UTF8ToLatin1($s); - } else { - //Convert string to UTF-16BE and reverse RTL language - $s = $this->utf8StrRev($s, false, $this->tmprtl); - } - } - return $this->_escape($s); - } - - /** - * Escape some special characters (< > &) for XML output. - * @param $str (string) Input string to convert. - * @return converted string - * @since 5.9.121 (2011-09-28) - * @protected - */ - protected function _escapeXML($str) { - $replaceTable = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); - $str = strtr($str, $replaceTable); - return $str; - } - /** * get raw output stream. * @param $s (string) string to output. @@ -13486,28 +10322,6 @@ class TCPDF { return $this->_encrypt_data($n, $s); } - /** - * Format output stream (DEPRECATED). - * @param $s (string) string to output. - * @param $n (int) object reference for encryption mode - * @protected - * @deprecated - */ - protected function _getstream($s, $n=0) { - return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream'; - } - - /** - * Output a stream (DEPRECATED). - * @param $s (string) string to output. - * @param $n (int) object reference for encryption mode - * @protected - * @deprecated - */ - protected function _putstream($s, $n=0) { - $this->_out($this->_getstream($s, $n)); - } - /** * Output a string to the document. * @param $s (string) string to output. @@ -13518,7 +10332,7 @@ class TCPDF { if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['outdata'] .= $s."\n"; - } elseif ((!$this->InFooter) and isset($this->footerlen[$this->page]) and ($this->footerlen[$this->page] > 0)) { + } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) { // puts data before page footer $pagebuff = $this->getPageBuffer($this->page); $page = substr($pagebuff, 0, -$this->footerlen[$this->page]); @@ -13527,299 +10341,18 @@ class TCPDF { // update footer position $this->footerpos[$this->page] += strlen($s."\n"); } else { + // set page data $this->setPageBuffer($this->page, $s."\n", true); } - } else { + } elseif ($this->state > 0) { + // set general data $this->setBuffer($s."\n"); } } - /** - * Converts UTF-8 strings to codepoints array.
        - * Invalid byte sequences will be replaced with 0xFFFD (replacement character)
        - * Based on: http://www.faqs.org/rfcs/rfc3629.html - *
        -	 *    Char. number range  |        UTF-8 octet sequence
        -	 *       (hexadecimal)    |              (binary)
        -	 *    --------------------+-----------------------------------------------
        -	 *    0000 0000-0000 007F | 0xxxxxxx
        -	 *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
        -	 *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
        -	 *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
        -	 *    ---------------------------------------------------------------------
        -	 *
        -	 *   ABFN notation:
        -	 *   ---------------------------------------------------------------------
        -	 *   UTF8-octets = *( UTF8-char )
        -	 *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
        -	 *   UTF8-1      = %x00-7F
        -	 *   UTF8-2      = %xC2-DF UTF8-tail
        -	 *
        -	 *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
        -	 *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
        -	 *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
        -	 *                 %xF4 %x80-8F 2( UTF8-tail )
        -	 *   UTF8-tail   = %x80-BF
        -	 *   ---------------------------------------------------------------------
        -	 * 
        - * @param $str (string) string to process. - * @return array containing codepoints (UTF-8 characters values) - * @protected - * @author Nicola Asuni - * @since 1.53.0.TC005 (2005-01-05) - */ - protected function UTF8StringToArray($str) { - // build a unique string key - $strkey = md5($str); - if (isset($this->cache_UTF8StringToArray[$strkey])) { - // return cached value - $chrarray = $this->cache_UTF8StringToArray[$strkey]['s']; - if (!isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']])) { - if ($this->isunicode) { - foreach ($chrarray as $chr) { - // store this char for font subsetting - $this->CurrentFont['subsetchars'][$chr] = true; - } - // update font subsetchars - $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); - } - $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true; - } - return $chrarray; - } - // check cache size - if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) { - // remove first element - array_shift($this->cache_UTF8StringToArray); - } - // new cache array for selected string - $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array()); - ++$this->cache_size_UTF8StringToArray; - if (!$this->isunicode) { - // split string into array of equivalent codes - $strarr = array(); - $strlen = strlen($str); - for ($i=0; $i < $strlen; ++$i) { - $strarr[] = ord($str[$i]); - } - // insert new value on cache - $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr; - $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true; - return $strarr; - } - $unichar = -1; // last unicode char - $unicode = array(); // array containing unicode values - $bytes = array(); // array containing single character byte sequences - $numbytes = 1; // number of octetc needed to represent the UTF-8 character - $str .= ''; // force $str to be a string - $length = strlen($str); - for ($i = 0; $i < $length; ++$i) { - $char = ord($str[$i]); // get one string character at time - if (count($bytes) == 0) { // get starting octect - if ($char <= 0x7F) { - $unichar = $char; // use the character "as is" because is ASCII - $numbytes = 1; - } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN) - $bytes[] = ($char - 0xC0) << 0x06; - $numbytes = 2; - } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN) - $bytes[] = ($char - 0xE0) << 0x0C; - $numbytes = 3; - } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN) - $bytes[] = ($char - 0xF0) << 0x12; - $numbytes = 4; - } else { - // use replacement character for other invalid sequences - $unichar = 0xFFFD; - $bytes = array(); - $numbytes = 1; - } - } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN - $bytes[] = $char - 0x80; - if (count($bytes) == $numbytes) { - // compose UTF-8 bytes to a single unicode value - $char = $bytes[0]; - for ($j = 1; $j < $numbytes; ++$j) { - $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06)); - } - if ((($char >= 0xD800) and ($char <= 0xDFFF)) or ($char >= 0x10FFFF)) { - /* The definition of UTF-8 prohibits encoding character numbers between - U+D800 and U+DFFF, which are reserved for use with the UTF-16 - encoding form (as surrogate pairs) and do not directly represent - characters. */ - $unichar = 0xFFFD; // use replacement character - } else { - $unichar = $char; // add char to array - } - // reset data for next char - $bytes = array(); - $numbytes = 1; - } - } else { - // use replacement character for other invalid sequences - $unichar = 0xFFFD; - $bytes = array(); - $numbytes = 1; - } - if ($unichar >= 0) { - // insert unicode value into array - $unicode[] = $unichar; - // store this char for font subsetting - $this->CurrentFont['subsetchars'][$unichar] = true; - $unichar = -1; - } - } - // update font subsetchars - $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); - // insert new value on cache - $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode; - $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true; - return $unicode; - } - - /** - * Converts UTF-8 strings to UTF16-BE.
        - * @param $str (string) string to process. - * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF) - * @return string - * @author Nicola Asuni - * @since 1.53.0.TC005 (2005-01-05) - * @see UTF8StringToArray(), arrUTF8ToUTF16BE() - * @protected - */ - protected function UTF8ToUTF16BE($str, $setbom=false) { - if (!$this->isunicode) { - return $str; // string is not in unicode - } - $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values - return $this->arrUTF8ToUTF16BE($unicode, $setbom); - } - - /** - * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.
        - * @param $str (string) string to process. - * @return string - * @author Andrew Whitehead, Nicola Asuni - * @protected - * @since 3.2.000 (2008-06-23) - */ - protected function UTF8ToLatin1($str) { - if (!$this->isunicode) { - return $str; // string is not in unicode - } - $outstr = ''; // string to be returned - $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values - foreach ($unicode as $char) { - if ($char < 256) { - $outstr .= chr($char); - } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) { - // map from UTF-8 - $outstr .= chr($this->unicode->uni_utf8tolatin[$char]); - } elseif ($char == 0xFFFD) { - // skip - } else { - $outstr .= '?'; - } - } - return $outstr; - } - - /** - * Converts UTF-8 characters array to array of Latin1 characters
        - * @param $unicode (array) array containing UTF-8 unicode values - * @return array - * @author Nicola Asuni - * @protected - * @since 4.8.023 (2010-01-15) - */ - protected function UTF8ArrToLatin1($unicode) { - if ((!$this->isunicode) or $this->isUnicodeFont()) { - return $unicode; - } - $outarr = array(); // array to be returned - foreach ($unicode as $char) { - if ($char < 256) { - $outarr[] = $char; - } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) { - // map from UTF-8 - $outarr[] = $this->unicode->uni_utf8tolatin[$char]; - } elseif ($char == 0xFFFD) { - // skip - } else { - $outarr[] = 63; // '?' character - } - } - return $outarr; - } - - /** - * Converts array of UTF-8 characters to UTF16-BE string.
        - * Based on: http://www.faqs.org/rfcs/rfc2781.html - *
        -	 *   Encoding UTF-16:
        -	 *
        -	 *   Encoding of a single character from an ISO 10646 character value to
        -	 *    UTF-16 proceeds as follows. Let U be the character number, no greater
        -	 *    than 0x10FFFF.
        -	 *
        -	 *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
        -	 *       terminate.
        -	 *
        -	 *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
        -	 *       U' must be less than or equal to 0xFFFFF. That is, U' can be
        -	 *       represented in 20 bits.
        -	 *
        -	 *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
        -	 *       0xDC00, respectively. These integers each have 10 bits free to
        -	 *       encode the character value, for a total of 20 bits.
        -	 *
        -	 *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
        -	 *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
        -	 *       bits of W2. Terminate.
        -	 *
        -	 *    Graphically, steps 2 through 4 look like:
        -	 *    U' = yyyyyyyyyyxxxxxxxxxx
        -	 *    W1 = 110110yyyyyyyyyy
        -	 *    W2 = 110111xxxxxxxxxx
        -	 * 
        - * @param $unicode (array) array containing UTF-8 unicode values - * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF) - * @return string - * @protected - * @author Nicola Asuni - * @since 2.1.000 (2008-01-08) - * @see UTF8ToUTF16BE() - */ - protected function arrUTF8ToUTF16BE($unicode, $setbom=false) { - $outstr = ''; // string to be returned - if ($setbom) { - $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) - } - foreach ($unicode as $char) { - if ($char == 0x200b) { - // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B) - } elseif ($char == 0xFFFD) { - $outstr .= "\xFF\xFD"; // replacement character - } elseif ($char < 0x10000) { - $outstr .= chr($char >> 0x08); - $outstr .= chr($char & 0xFF); - } else { - $char -= 0x10000; - $w1 = 0xD800 | ($char >> 0x0a); - $w2 = 0xDC00 | ($char & 0x3FF); - $outstr .= chr($w1 >> 0x08); - $outstr .= chr($w1 & 0xFF); - $outstr .= chr($w2 >> 0x08); - $outstr .= chr($w2 & 0xFF); - } - } - return $outstr; - } - // ==================================================== - /** * Set header font. - * @param $font (array) font + * @param $font (array) Array describing the basic font parameters: (family, style, size). * @public * @since 1.1 */ @@ -13829,7 +10362,7 @@ class TCPDF { /** * Get header font. - * @return array() + * @return array() Array describing the basic font parameters: (family, style, size). * @public * @since 4.0.012 (2008-07-24) */ @@ -13839,7 +10372,7 @@ class TCPDF { /** * Set footer font. - * @param $font (array) font + * @param $font (array) Array describing the basic font parameters: (family, style, size). * @public * @since 1.1 */ @@ -13849,7 +10382,7 @@ class TCPDF { /** * Get Footer font. - * @return array() + * @return array() Array describing the basic font parameters: (family, style, size). * @public * @since 4.0.012 (2008-07-24) */ @@ -13896,15 +10429,12 @@ class TCPDF { * @public */ public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) { - if (!$this->empty_string($url) and ($url{0} == '#')) { + if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) { // convert url to internal link $lnkdata = explode(',', $url); - if (isset($lnkdata[0])) { - $page = intval(substr($lnkdata[0], 1)); - if (empty($page) or ($page <= 0)) { - $page = $this->page; - } - if (isset($lnkdata[1]) and (strlen($lnkdata[1]) > 0)) { + if (isset($lnkdata[0]) ) { + $page = substr($lnkdata[0], 1); + if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) { $lnky = floatval($lnkdata[1]); } else { $lnky = 0; @@ -13933,148 +10463,6 @@ class TCPDF { return $ret; } - /** - * Returns an array (RGB or CMYK) from an html color name, or a six-digit (i.e. #3FE5AA), or three-digit (i.e. #7FF) hexadecimal color, or a javascript color array, or javascript color name. - * @param $hcolor (string) HTML color. - * @param $defcol (array) Color to return in case of error. - * @return array RGB or CMYK color, or false in case of error. - * @public - */ - public function convertHTMLColorToDec($hcolor='#FFFFFF', $defcol=array('R'=>128,'G'=>128,'B'=>128)) { - $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces - $color = strtolower($color); - // check for javascript color array syntax - if (strpos($color, '[') !== false) { - if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\]]/', $color, $m) > 0) { - $returncolor = array(); - switch ($m[1]) { - case 'cmyk': { - // RGB - $returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100))); - $returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100))); - $returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100))); - $returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100))); - break; - } - case 'rgb': { - // RGB - $returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255))); - $returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255))); - $returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255))); - break; - } - case 'g': { - // grayscale - $returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255))); - break; - } - case 't': - default: { - // transparent (empty array) - break; - } - } - return $returncolor; - } - } elseif (($dotpos = strpos($color, '.')) !== false) { - // remove class parent (i.e.: color.red) - $color = substr($color, ($dotpos + 1)); - if ($color == 'transparent') { - // transparent (empty array) - return array(); - } - } - if (strlen($color) == 0) { - return $defcol; - } - // RGB ARRAY - if (substr($color, 0, 3) == 'rgb') { - $codes = substr($color, 4); - $codes = str_replace(')', '', $codes); - $returncolor = explode(',', $codes); - foreach ($returncolor as $key => $val) { - if (strpos($val, '%') > 0) { - // percentage - $returncolor[$key] = (255 * intval($val) / 100); - } else { - $returncolor[$key] = intval($val); - } - // normalize value - $returncolor[$key] = max(0, min(255, $returncolor[$key])); - } - return $returncolor; - } - // CMYK ARRAY - if (substr($color, 0, 4) == 'cmyk') { - $codes = substr($color, 5); - $codes = str_replace(')', '', $codes); - $returncolor = explode(',', $codes); - foreach ($returncolor as $key => $val) { - if (strpos($val, '%') !== false) { - // percentage - $returncolor[$key] = (100 * intval($val) / 100); - } else { - $returncolor[$key] = intval($val); - } - // normalize value - $returncolor[$key] = max(0, min(100, $returncolor[$key])); - } - return $returncolor; - } - if ($color{0} != '#') { - // COLOR NAME - if (isset($this->webcolor[$color])) { - // web color - $color_code = $this->webcolor[$color]; - } else { - // spot color - $returncolor = $this->getSpotColor($color); - if ($returncolor === false) { - $returncolor = $defcol; - } - return $returncolor; - } - } else { - $color_code = substr($color, 1); - } - // HEXADECIMAL REPRESENTATION - switch (strlen($color_code)) { - case 3: { - // 3-digit RGB hexadecimal representation - $r = substr($color_code, 0, 1); - $g = substr($color_code, 1, 1); - $b = substr($color_code, 2, 1); - $returncolor = array(); - $returncolor['R'] = max(0, min(255, hexdec($r.$r))); - $returncolor['G'] = max(0, min(255, hexdec($g.$g))); - $returncolor['B'] = max(0, min(255, hexdec($b.$b))); - break; - } - case 6: { - // 6-digit RGB hexadecimal representation - $returncolor = array(); - $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2)))); - $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2)))); - $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2)))); - break; - } - case 8: { - // 8-digit CMYK hexadecimal representation - $returncolor = array(); - $returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55))); - $returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55))); - $returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55))); - $returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55))); - break; - } - default: { - $returncolor = $defcol; - break; - } - } - return $returncolor; - } - /** * Converts pixels to User's Units. * @param $px (int) pixels @@ -14099,53 +10487,6 @@ class TCPDF { // ENCRYPTION METHODS ---------------------------------- - /** - * Returns a string containing random data to be used as a seed for encryption methods. - * @param $seed (string) starting seed value - * @return string containing random data - * @author Nicola Asuni - * @since 5.9.006 (2010-10-19) - * @protected - */ - protected function getRandomSeed($seed='') { - $seed .= microtime(); - 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 - $seed .= openssl_random_pseudo_bytes(512); - } else { - for ($i = 0; $i < 23; ++$i) { - $seed .= uniqid('', true); - } - } - $seed .= uniqid('', true); - $seed .= rand(); - $seed .= getmypid(); - $seed .= __FILE__; - $seed .= $this->bufferlen; - if (isset($_SERVER['REMOTE_ADDR'])) { - $seed .= $_SERVER['REMOTE_ADDR']; - } - if (isset($_SERVER['HTTP_USER_AGENT'])) { - $seed .= $_SERVER['HTTP_USER_AGENT']; - } - if (isset($_SERVER['HTTP_ACCEPT'])) { - $seed .= $_SERVER['HTTP_ACCEPT']; - } - if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { - $seed .= $_SERVER['HTTP_ACCEPT_ENCODING']; - } - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE']; - } - if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) { - $seed .= $_SERVER['HTTP_ACCEPT_CHARSET']; - } - $seed .= rand(); - $seed .= uniqid('', true); - $seed .= microtime(); - return $seed; - } - /** * Compute encryption key depending on object number where the encrypted data is stored. * This is used for all strings and streams without crypt filter specifier. @@ -14161,7 +10502,7 @@ class TCPDF { // AES padding $objkey .= "\x73\x41\x6C\x54"; // sAlT } - $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5)); + $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5)); $objkey = substr($objkey, 0, 16); return $objkey; } @@ -14182,15 +10523,15 @@ class TCPDF { switch ($this->encryptdata['mode']) { case 0: // RC4-40 case 1: { // RC4-128 - $s = $this->_RC4($this->_objectkey($n), $s); + $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c); break; } case 2: { // AES-128 - $s = $this->_AES($this->_objectkey($n), $s); + $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s); break; } case 3: { // AES-256 - $s = $this->_AES($this->encryptdata['key'], $s); + $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s); break; } } @@ -14209,38 +10550,38 @@ class TCPDF { } $this->encryptdata['objid'] = $this->_newobj(); $out = '<<'; - if (!isset($this->encryptdata['Filter']) or empty($this->encryptdata['Filter'])) { + if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) { $this->encryptdata['Filter'] = 'Standard'; } $out .= ' /Filter /'.$this->encryptdata['Filter']; - if (isset($this->encryptdata['SubFilter']) and !empty($this->encryptdata['SubFilter'])) { + if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) { $out .= ' /SubFilter /'.$this->encryptdata['SubFilter']; } - if (!isset($this->encryptdata['V']) or empty($this->encryptdata['V'])) { + if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) { $this->encryptdata['V'] = 1; } // V is a code specifying the algorithm to be used in encrypting and decrypting the document $out .= ' /V '.$this->encryptdata['V']; - if (isset($this->encryptdata['Length']) and !empty($this->encryptdata['Length'])) { + if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) { // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256 $out .= ' /Length '.$this->encryptdata['Length']; } else { $out .= ' /Length 40'; } if ($this->encryptdata['V'] >= 4) { - if (!isset($this->encryptdata['StmF']) or empty($this->encryptdata['StmF'])) { + if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) { $this->encryptdata['StmF'] = 'Identity'; } - if (!isset($this->encryptdata['StrF']) or empty($this->encryptdata['StrF'])) { + if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) { // The name of the crypt filter that shall be used when decrypting all strings in the document. $this->encryptdata['StrF'] = 'Identity'; } // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries. - if (isset($this->encryptdata['CF']) and !empty($this->encryptdata['CF'])) { + if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) { $out .= ' /CF <<'; $out .= ' /'.$this->encryptdata['StmF'].' <<'; $out .= ' /Type /CryptFilter'; - if (isset($this->encryptdata['CF']['CFM']) and !empty($this->encryptdata['CF']['CFM'])) { + if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) { // The method used $out .= ' /CFM /'.$this->encryptdata['CF']['CFM']; if ($this->encryptdata['pubkey']) { @@ -14249,7 +10590,7 @@ class TCPDF { $out .= ' <'.$rec.'>'; } $out .= ' ]'; - if (isset($this->encryptdata['CF']['EncryptMetadata']) and (!$this->encryptdata['CF']['EncryptMetadata'])) { + if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { $out .= ' /EncryptMetadata false'; } else { $out .= ' /EncryptMetadata true'; @@ -14258,13 +10599,13 @@ class TCPDF { } else { $out .= ' /CFM /None'; } - if (isset($this->encryptdata['CF']['AuthEvent']) and !empty($this->encryptdata['CF']['AuthEvent'])) { + if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) { // The event to be used to trigger the authorization that is required to access encryption keys used by this filter. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent']; } else { $out .= ' /AuthEvent /DocOpen'; } - if (isset($this->encryptdata['CF']['Length']) and !empty($this->encryptdata['CF']['Length'])) { + if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) { // The bit length of the encryption key. $out .= ' /Length '.$this->encryptdata['CF']['Length']; } @@ -14274,14 +10615,14 @@ class TCPDF { $out .= ' /StmF /'.$this->encryptdata['StmF']; // The name of the crypt filter that shall be used when decrypting all strings in the document. $out .= ' /StrF /'.$this->encryptdata['StrF']; - if (isset($this->encryptdata['EFF']) and !empty($this->encryptdata['EFF'])) { + if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) { // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier. $out .= ' /EFF /'.$this->encryptdata['']; } } // Additional encryption dictionary entries for the standard security handler if ($this->encryptdata['pubkey']) { - if (($this->encryptdata['V'] < 4) and isset($this->encryptdata['Recipients']) and !empty($this->encryptdata['Recipients'])) { + if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) { $out .= ' /Recipients ['; foreach ($this->encryptdata['Recipients'] as $rec) { $out .= ' <'.$rec.'>'; @@ -14292,9 +10633,9 @@ class TCPDF { $out .= ' /R'; if ($this->encryptdata['V'] == 5) { // AES-256 $out .= ' 5'; - $out .= ' /OE ('.$this->_escape($this->encryptdata['OE']).')'; - $out .= ' /UE ('.$this->_escape($this->encryptdata['UE']).')'; - $out .= ' /Perms ('.$this->_escape($this->encryptdata['perms']).')'; + $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')'; + $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')'; + $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')'; } elseif ($this->encryptdata['V'] == 4) { // AES-128 $out .= ' 4'; } elseif ($this->encryptdata['V'] < 2) { // RC-40 @@ -14302,10 +10643,10 @@ class TCPDF { } else { // RC-128 $out .= ' 3'; } - $out .= ' /O ('.$this->_escape($this->encryptdata['O']).')'; - $out .= ' /U ('.$this->_escape($this->encryptdata['U']).')'; + $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')'; + $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')'; $out .= ' /P '.$this->encryptdata['P']; - if (isset($this->encryptdata['EncryptMetadata']) and (!$this->encryptdata['EncryptMetadata'])) { + if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) { $out .= ' /EncryptMetadata false'; } else { $out .= ' /EncryptMetadata true'; @@ -14316,84 +10657,6 @@ class TCPDF { $this->_out($out); } - /** - * Returns the input text encrypted using RC4 algorithm and the specified key. - * RC4 is the standard encryption algorithm used in PDF format - * @param $key (string) encryption key - * @param $text (String) input text to be encrypted - * @return String encrypted text - * @protected - * @since 2.0.000 (2008-01-02) - * @author Klemen Vodopivec, Nicola Asuni - */ - protected function _RC4($key, $text) { - if (function_exists('mcrypt_decrypt') and ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) { - // try to use mcrypt function if exist - return $out; - } - if ($this->last_enc_key != $key) { - $k = str_repeat($key, ((256 / strlen($key)) + 1)); - $rc4 = range(0, 255); - $j = 0; - for ($i = 0; $i < 256; ++$i) { - $t = $rc4[$i]; - $j = ($j + $t + ord($k[$i])) % 256; - $rc4[$i] = $rc4[$j]; - $rc4[$j] = $t; - } - $this->last_enc_key = $key; - $this->last_enc_key_c = $rc4; - } else { - $rc4 = $this->last_enc_key_c; - } - $len = strlen($text); - $a = 0; - $b = 0; - $out = ''; - for ($i = 0; $i < $len; ++$i) { - $a = ($a + 1) % 256; - $t = $rc4[$a]; - $b = ($b + $t) % 256; - $rc4[$a] = $rc4[$b]; - $rc4[$b] = $t; - $k = $rc4[($rc4[$a] + $rc4[$b]) % 256]; - $out .= chr(ord($text[$i]) ^ $k); - } - return $out; - } - - /** - * Returns the input text exrypted using AES algorithm and the specified key. - * This method requires mcrypt. - * @param $key (string) encryption key - * @param $text (String) input text to be encrypted - * @return String encrypted text - * @protected - * @author Nicola Asuni - * @since 5.0.005 (2010-05-11) - */ - protected function _AES($key, $text) { - // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0) - $padding = 16 - (strlen($text) % 16); - $text .= str_repeat(chr($padding), $padding); - $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); - $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); - $text = $iv.$text; - return $text; - } - - /** - * Encrypts a string using MD5 and returns it's value as a binary string. - * @param $str (string) input string - * @return String MD5 encrypted binary string - * @protected - * @since 2.0.000 (2008-01-02) - * @author Klemen Vodopivec - */ - protected function _md5_16($str) { - return pack('H*', md5($str)); - } - /** * Compute U value (used for encryption) * @return string U value @@ -14403,22 +10666,22 @@ class TCPDF { */ protected function _Uvalue() { if ($this->encryptdata['mode'] == 0) { // RC4-40 - return $this->_RC4($this->encryptdata['key'], $this->enc_padding); + return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c); } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128 - $tmp = $this->_md5_16($this->enc_padding.$this->encryptdata['fileid']); - $enc = $this->_RC4($this->encryptdata['key'], $tmp); + $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']); + $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c); $len = strlen($tmp); for ($i = 1; $i <= 19; ++$i) { $ek = ''; for ($j = 0; $j < $len; ++$j) { $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i); } - $enc = $this->_RC4($ek, $enc); + $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c); } $enc .= str_repeat("\x00", 16); return substr($enc, 0, 32); } elseif ($this->encryptdata['mode'] == 3) { // AES-256 - $seed = $this->_md5_16($this->getRandomSeed()); + $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed()); // User Validation Salt $this->encryptdata['UVS'] = substr($seed, 0, 8); // User Key Salt @@ -14436,8 +10699,7 @@ class TCPDF { */ protected function _UEvalue() { $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true); - $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); - return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv); + return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']); } /** @@ -14449,14 +10711,14 @@ class TCPDF { */ protected function _Ovalue() { if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128 - $tmp = $this->_md5_16($this->encryptdata['owner_password']); + $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']); if ($this->encryptdata['mode'] > 0) { for ($i = 0; $i < 50; ++$i) { - $tmp = $this->_md5_16($tmp); + $tmp = TCPDF_STATIC::_md5_16($tmp); } } $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8)); - $enc = $this->_RC4($owner_key, $this->encryptdata['user_password']); + $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c); if ($this->encryptdata['mode'] > 0) { $len = strlen($owner_key); for ($i = 1; $i <= 19; ++$i) { @@ -14464,12 +10726,12 @@ class TCPDF { for ($j = 0; $j < $len; ++$j) { $ek .= chr(ord($owner_key[$j]) ^ $i); } - $enc = $this->_RC4($ek, $enc); + $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c); } } return $enc; } elseif ($this->encryptdata['mode'] == 3) { // AES-256 - $seed = $this->_md5_16($this->getRandomSeed()); + $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed()); // Owner Validation Salt $this->encryptdata['OVS'] = substr($seed, 0, 8); // Owner Key Salt @@ -14487,8 +10749,7 @@ class TCPDF { */ protected function _OEvalue() { $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true); - $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); - return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv); + return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']); } /** @@ -14501,9 +10762,9 @@ class TCPDF { */ protected function _fixAES256Password($password) { $psw = ''; // password to be returned - $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl); + $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont); foreach ($psw_array as $c) { - $psw .= $this->unichr($c); + $psw .= TCPDF_FONTS::unichr($c, $this->isunicode); } return substr($psw, 0, 127); } @@ -14519,7 +10780,7 @@ class TCPDF { if (!$this->encryptdata['pubkey']) { // standard mode if ($this->encryptdata['mode'] == 3) { // AES-256 // generate 256 bit random key - $this->encryptdata['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen); + $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen); // truncate passwords $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']); $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']); @@ -14534,30 +10795,29 @@ class TCPDF { // Compute P value $this->encryptdata['P'] = $this->encryptdata['protection']; // Computing the encryption dictionary's Perms (permissions) value - $perms = $this->getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3 + $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3 $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7 - if (isset($this->encryptdata['CF']['EncryptMetadata']) and (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8 + if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8 $perms .= 'F'; } else { $perms .= 'T'; } $perms .= 'adb'; // bytes 9-11 $perms .= 'nick'; // bytes 12-15 - $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)); - $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv); + $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms); } else { // RC4-40, RC4-128, AES-128 // Pad passwords - $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].$this->enc_padding, 0, 32); - $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].$this->enc_padding, 0, 32); + $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32); + $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32); // Compute O value $this->encryptdata['O'] = $this->_Ovalue(); // get default permissions (reverse byte order) - $permissions = $this->getEncPermissionsString($this->encryptdata['protection']); + $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // Compute encryption key - $tmp = $this->_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']); + $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']); if ($this->encryptdata['mode'] > 0) { for ($i = 0; $i < 50; ++$i) { - $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen)); + $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen)); } } $this->encryptdata['key'] = substr($tmp, 0, $keybytelen); @@ -14568,36 +10828,34 @@ class TCPDF { } } else { // Public-Key mode // random 20-byte seed - $seed = sha1($this->getRandomSeed(), true); + $seed = sha1(TCPDF_STATIC::getRandomSeed(), true); $recipient_bytes = ''; foreach ($this->encryptdata['pubkeys'] as $pubkey) { // for each public certificate if (isset($pubkey['p'])) { - $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']); + $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']); } else { $pkprotection = $this->encryptdata['protection']; } // get default permissions (reverse byte order) - $pkpermissions = $this->getEncPermissionsString($pkprotection); + $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection); // envelope data $envelope = $seed.$pkpermissions; // write the envelope data to a temporary file - $tempkeyfile = tempnam(K_PATH_CACHE, 'tmpkey_'); - $f = fopen($tempkeyfile, 'wb'); + $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id); + $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb'); if (!$f) { $this->Error('Unable to create temporary key file: '.$tempkeyfile); } $envelope_length = strlen($envelope); fwrite($f, $envelope, $envelope_length); fclose($f); - $tempencfile = tempnam(K_PATH_CACHE, 'tmpenc_'); + $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id); if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) { $this->Error('Unable to encrypt the file: '.$tempkeyfile); } - unlink($tempkeyfile); // read encryption signature $signature = file_get_contents($tempencfile, false, null, $envelope_length); - unlink($tempencfile); // extract signature $signature = substr($signature, strpos($signature, 'Content-Disposition')); $tmparr = explode("\n\n", $signature); @@ -14621,44 +10879,6 @@ class TCPDF { } } - /** - * Return the premission code used on encryption (P value). - * @param $permissions (Array) the set of permissions (specify the ones you want to block). - * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit. - * @protected - * @since 5.0.005 (2010-05-12) - * @author Nicola Asuni - */ - protected function getUserPermissionCode($permissions, $mode=0) { - $options = array( - 'owner' => 2, // bit 2 -- inverted logic: cleared by default - 'print' => 4, // bit 3 - 'modify' => 8, // bit 4 - 'copy' => 16, // bit 5 - 'annot-forms' => 32, // bit 6 - 'fill-forms' => 256, // bit 9 - 'extract' => 512, // bit 10 - 'assemble' => 1024,// bit 11 - 'print-high' => 2048 // bit 12 - ); - $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100) - foreach ($permissions as $permission) { - if (!isset($options[$permission])) { - $this->Error('Incorrect permission: '.$permission); - } - if (($mode > 0) or ($options[$permission] <= 32)) { - // set only valid permissions - if ($options[$permission] == 2) { - // the logic for bit 2 is inverted (cleared by default) - $protection += $options[$permission]; - } else { - $protection -= $options[$permission]; - } - } - } - return $protection; - } - /** * Set document protection * Remark: the protection against modification is for people who have the full Acrobat product. @@ -14668,7 +10888,7 @@ class TCPDF { * @param $user_pass (String) user password. Empty by default. * @param $owner_pass (String) owner password. If not specified, a random value is used. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit. - * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../tcpdf.crt', 'p' => array('print'))) + * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print'))) * @public * @since 2.0.000 (2008-01-02) * @author Nicola Asuni @@ -14678,8 +10898,8 @@ class TCPDF { // encryption is not allowed in PDF/A mode return; } - $this->encryptdata['protection'] = $this->getUserPermissionCode($permissions, $mode); - if (($pubkeys !== null) and (is_array($pubkeys))) { + $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode); + if (($pubkeys !== null) AND (is_array($pubkeys))) { // public-key mode $this->encryptdata['pubkeys'] = $pubkeys; if ($mode == 0) { @@ -14689,7 +10909,7 @@ class TCPDF { if (!function_exists('openssl_pkcs7_encrypt')) { $this->Error('Public-Key Security requires openssl library.'); } - // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec) + // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec) $this->encryptdata['pubkey'] = true; $this->encryptdata['Filter'] = 'Adobe.PubSec'; $this->encryptdata['StmF'] = 'DefaultCryptFilter'; @@ -14702,19 +10922,22 @@ class TCPDF { $this->encryptdata['StrF'] = 'StdCF'; } if ($mode > 1) { // AES - if (!extension_loaded('mcrypt')) { - $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).'); + if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) { + $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).'); } - if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) { + if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) { + $this->Error('AES encryption requires openssl/aes-256-cbc cypher.'); + } + if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) { $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.'); } - if (($mode == 3) and !function_exists('hash')) { + if (($mode == 3) AND !function_exists('hash')) { // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).'); } } if ($owner_pass === null) { - $owner_pass = md5($this->getRandomSeed()); + $owner_pass = md5(TCPDF_STATIC::getRandomSeed()); } $this->encryptdata['user_password'] = $user_pass; $this->encryptdata['owner_password'] = $owner_pass; @@ -14760,66 +10983,10 @@ class TCPDF { } } $this->encrypted = true; - $this->encryptdata['fileid'] = $this->convertHexStringToString($this->file_id); + $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id); $this->_generateencryptionkey(); } - /** - * Convert hexadecimal string to string - * @param $bs (string) byte-string to convert - * @return String - * @protected - * @since 5.0.005 (2010-05-12) - * @author Nicola Asuni - */ - protected function convertHexStringToString($bs) { - $string = ''; // string to be returned - $bslength = strlen($bs); - if (($bslength % 2) != 0) { - // padding - $bs .= '0'; - ++$bslength; - } - for ($i = 0; $i < $bslength; $i += 2) { - $string .= chr(hexdec($bs[$i].$bs[($i + 1)])); - } - return $string; - } - - /** - * Convert string to hexadecimal string (byte string) - * @param $s (string) string to convert - * @return byte string - * @protected - * @since 5.0.010 (2010-05-17) - * @author Nicola Asuni - */ - protected function convertStringToHexString($s) { - $bs = ''; - $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); - foreach ($chars as $c) { - $bs .= sprintf('%02s', dechex(ord($c))); - } - return $bs; - } - - /** - * Convert encryption P value to a string of bytes, low-order byte first. - * @param $protection (string) 32bit encryption permission value (P value) - * @return String - * @protected - * @since 5.0.005 (2010-05-12) - * @author Nicola Asuni - */ - protected function getEncPermissionsString($protection) { - $binprot = sprintf('%032b', $protection); - $str = chr(bindec(substr($binprot, 24, 8))); - $str .= chr(bindec(substr($binprot, 16, 8))); - $str .= chr(bindec(substr($binprot, 8, 8))); - $str .= chr(bindec(substr($binprot, 0, 8))); - return $str; - } - // END OF ENCRYPTION FUNCTIONS ------------------------- // START TRANSFORMATIONS SECTION ----------------------- @@ -14833,7 +11000,10 @@ class TCPDF { * @see StartTransform(), StopTransform() */ public function StartTransform() { - $this->_out('q'); + if ($this->state != 2) { + return; + } + $this->_outSaveGraphicsState(); if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']); @@ -14853,7 +11023,10 @@ class TCPDF { * @see StartTransform(), StopTransform() */ public function StopTransform() { - $this->_out('Q'); + if ($this->state != 2) { + return; + } + $this->_outRestoreGraphicsState(); if (isset($this->transfmatrix[$this->transfmatrix_key])) { array_pop($this->transfmatrix[$this->transfmatrix_key]); --$this->transfmatrix_key; @@ -14921,7 +11094,7 @@ class TCPDF { if ($y === '') { $y = $this->y; } - if (($s_x == 0) or ($s_y == 0)) { + if (($s_x == 0) OR ($s_y == 0)) { $this->Error('Please do not use values equal to zero for scaling'); } $y = ($this->h - $y) * $this->k; @@ -15104,7 +11277,7 @@ class TCPDF { if ($y === '') { $y = $this->y; } - if (($angle_x <= -90) or ($angle_x >= 90) or ($angle_y <= -90) or ($angle_y >= 90)) { + if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) { $this->Error('Please use values between -90 and +90 degrees for Skewing.'); } $x *= $this->k; @@ -15129,6 +11302,9 @@ class TCPDF { * @see StartTransform(), StopTransform() */ protected function Transform($tm) { + if ($this->state != 2) { + return; + } $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); // add tranformation matrix $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]); @@ -15161,7 +11337,7 @@ class TCPDF { //Set line width $this->LineWidth = $width; $this->linestyleWidth = sprintf('%F w', ($width * $this->k)); - if ($this->page > 0) { + if ($this->state == 2) { $this->_out($this->linestyleWidth); } } @@ -15193,7 +11369,7 @@ class TCPDF { * 1 off, 2 on, 1 off, ... *
      • phase (integer): Modifier on the dash pattern which is used to shift * the point at which the pattern starts.
      • - *
      • color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).
      • + *
      • color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName).
      • *
      * @param $ret (boolean) if true do not send the command. * @return string the PDF command @@ -15240,7 +11416,7 @@ class TCPDF { $dash_string .= sprintf('%F', $v); } } - if (!isset($style['phase']) or !$style['dash']) { + if (!isset($style['phase']) OR !$style['dash']) { $style['phase'] = 0; } $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']); @@ -15249,7 +11425,7 @@ class TCPDF { if (isset($style['color'])) { $s .= $this->SetDrawColorArray($style['color'], true).' '; } - if (!$ret) { + if (!$ret AND ($this->state == 2)) { $this->_out($s); } return $s; @@ -15263,7 +11439,9 @@ class TCPDF { * @since 2.1.000 (2008-01-08) */ protected function _outPoint($x, $y) { - $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k))); + if ($this->state == 2) { + $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k))); + } } /** @@ -15275,7 +11453,9 @@ class TCPDF { * @since 2.1.000 (2008-01-08) */ protected function _outLine($x, $y) { - $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k))); + if ($this->state == 2) { + $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k))); + } } /** @@ -15289,11 +11469,13 @@ class TCPDF { * @since 2.1.000 (2008-01-08) */ protected function _outRect($x, $y, $w, $h, $op) { - $this->_out(sprintf('%F %F %F %F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); + if ($this->state == 2) { + $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op)); + } } /** - * Append a cubic B�zier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the B�zier control points. + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the Bezier control points. * The new current point shall be (x3, y3). * @param $x1 (float) Abscissa of control point 1. * @param $y1 (float) Ordinate of control point 1. @@ -15305,11 +11487,13 @@ class TCPDF { * @since 2.1.000 (2008-01-08) */ protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) { - $this->_out(sprintf('%F %F %F %F %F %F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); + if ($this->state == 2) { + $this->_out(sprintf('%F %F %F %F %F %F c', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k))); + } } /** - * Append a cubic B�zier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the B�zier control points. + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bezier control points. * The new current point shall be (x3, y3). * @param $x2 (float) Abscissa of control point 2. * @param $y2 (float) Ordinate of control point 2. @@ -15319,11 +11503,13 @@ class TCPDF { * @since 4.9.019 (2010-04-26) */ protected function _outCurveV($x2, $y2, $x3, $y3) { - $this->_out(sprintf('%F %F %F %F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); + if ($this->state == 2) { + $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k))); + } } /** - * Append a cubic B�zier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the B�zier control points. + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bezier control points. * The new current point shall be (x3, y3). * @param $x1 (float) Abscissa of control point 1. * @param $y1 (float) Ordinate of control point 1. @@ -15333,7 +11519,9 @@ class TCPDF { * @since 2.1.000 (2008-01-08) */ protected function _outCurveY($x1, $y1, $x3, $y3) { - $this->_out(sprintf('%F %F %F %F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); + if ($this->state == 2) { + $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k))); + } } /** @@ -15348,6 +11536,9 @@ class TCPDF { * @see SetLineWidth(), SetDrawColor(), SetLineStyle() */ public function Line($x1, $y1, $x2, $y2, $style=array()) { + if ($this->state != 2) { + return; + } if (is_array($style)) { $this->SetLineStyle($style); } @@ -15368,26 +11559,41 @@ class TCPDF { *
    • all: Line style of all borders. Array like for SetLineStyle().
    • *
    • L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().
    • *
    - * If a key is not present or is null, not draws the border. Default value: default line style (empty array). - * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @public * @since 1.0 * @see SetLineStyle() */ public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) and !empty($fill_color)) { + if ($this->state != 2) { + return; + } + if (empty($style)) { + $style = 'S'; + } + if (!(strpos($style, 'F') === false) AND !empty($fill_color)) { + // set background color $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); - if ((!$border_style) or (isset($border_style['all']))) { - if (isset($border_style['all']) and $border_style['all']) { + if (!empty($border_style)) { + if (isset($border_style['all']) AND !empty($border_style['all'])) { + //set global style for border $this->SetLineStyle($border_style['all']); $border_style = array(); + } else { + // remove stroke operator from style + $opnostroke = array('S' => '', 'D' => '', 's' => '', 'd' => '', 'B' => 'F', 'FD' => 'F', 'DF' => 'F', 'B*' => 'F*', 'F*D' => 'F*', 'DF*' => 'F*', 'b' => 'f', 'fd' => 'f', 'df' => 'f', 'b*' => 'f*', 'f*d' => 'f*', 'df*' => 'f*' ); + if (isset($opnostroke[$style])) { + $style = $opnostroke[$style]; + } } } - $this->_outRect($x, $y, $w, $h, $op); - if ($border_style) { + if (!empty($style)) { + $op = TCPDF_STATIC::getPathPaintOperator($style); + $this->_outRect($x, $y, $w, $h, $op); + } + if (!empty($border_style)) { $border_style2 = array(); foreach ($border_style as $line => $value) { $length = strlen($line); @@ -15396,16 +11602,16 @@ class TCPDF { } } $border_style = $border_style2; - if (isset($border_style['L']) and $border_style['L']) { + if (isset($border_style['L']) AND $border_style['L']) { $this->Line($x, $y, $x, $y + $h, $border_style['L']); } - if (isset($border_style['T']) and $border_style['T']) { + if (isset($border_style['T']) AND $border_style['T']) { $this->Line($x, $y, $x + $w, $y, $border_style['T']); } - if (isset($border_style['R']) and $border_style['R']) { + if (isset($border_style['R']) AND $border_style['R']) { $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']); } - if (isset($border_style['B']) and $border_style['B']) { + if (isset($border_style['B']) AND $border_style['B']) { $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']); } } @@ -15425,16 +11631,19 @@ class TCPDF { * @param $y3 (float) Ordinate of end point. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @public * @see SetLineStyle() * @since 2.1.000 (2008-01-08) */ public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) and isset($fill_color)) { + if ($this->state != 2) { + return; + } + if (!(false === strpos($style, 'F')) AND isset($fill_color)) { $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($line_style) { $this->SetLineStyle($line_style); } @@ -15452,16 +11661,19 @@ class TCPDF { * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3). * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @public * @see SetLineStyle() * @since 3.0008 (2008-05-12) */ public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) { - if (!(false === strpos($style, 'F')) and isset($fill_color)) { + if ($this->state != 2) { + return; + } + if (!(false === strpos($style, 'F')) AND isset($fill_color)) { $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($op == 'f') { $line_style = array(); } @@ -15488,20 +11700,23 @@ class TCPDF { * @param $afinish: (float) Angle finish of draw line. Default value: 360. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse. * @author Nicola Asuni * @public * @since 2.1.000 (2008-01-08) */ public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) { - if ($this->empty_string($ry) or ($ry == 0)) { + if ($this->state != 2) { + return; + } + if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) { $ry = $rx; } - if (!(false === strpos($style, 'F')) and isset($fill_color)) { + if (!(false === strpos($style, 'F')) AND isset($fill_color)) { $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($op == 'f') { $line_style = array(); } @@ -15533,6 +11748,9 @@ class TCPDF { * @since 4.9.019 (2010-04-26) */ protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) { + if (($rx <= 0) OR ($ry < 0)) { + return; + } $k = $this->k; if ($nc < 2) { $nc = 2; @@ -15561,10 +11779,10 @@ class TCPDF { if ($af < 0) { $af += (2 * M_PI); } - if ($ccw and ($as > $af)) { + if ($ccw AND ($as > $af)) { // reverse rotation $as -= (2 * M_PI); - } elseif (!$ccw and ($as < $af)) { + } elseif (!$ccw AND ($as < $af)) { // reverse rotation $af -= (2 * M_PI); } @@ -15674,7 +11892,7 @@ class TCPDF { *
  • 0 to ($np - 1): Line style of each line. Array like for SetLineStyle().
  • *
* If a key is not present or is null, not draws the line. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @since 4.8.003 (2009-09-15) * @public */ @@ -15692,12 +11910,15 @@ class TCPDF { *
  • 0 to ($np - 1): Line style of each line. Array like for SetLineStyle().
  • * * If a key is not present or is null, not draws the line. Default value is default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @param $closed (boolean) if true the polygon is closes, otherwise will remain open * @public * @since 2.1.000 (2008-01-08) */ public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) { + if ($this->state != 2) { + return; + } $nc = count($p); // number of coordinates $np = $nc / 2; // number of points if ($closed) { @@ -15711,10 +11932,10 @@ class TCPDF { } $nc += 4; } - if (!(false === strpos($style, 'F')) and isset($fill_color)) { + if (!(false === strpos($style, 'F')) AND isset($fill_color)) { $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($op == 'f') { $line_style = array(); } @@ -15881,7 +12102,7 @@ class TCPDF { * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111"). * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @public * @since 2.1.000 (2008-01-08) */ @@ -15900,21 +12121,24 @@ class TCPDF { * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111"). * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array). - * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array). + * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array). * @public * @since 4.9.019 (2010-04-22) */ public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) { - if (($round_corner == '0000') or (($rx == $ry) and ($rx == 0))) { + if ($this->state != 2) { + return; + } + if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) { // Not rounded $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color); return; } // Rounded - if (!(false === strpos($style, 'F')) and isset($fill_color)) { + if (!(false === strpos($style, 'F')) AND isset($fill_color)) { $this->SetFillColorArray($fill_color); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($op == 'f') { $border_style = array(); } @@ -16024,637 +12248,12 @@ class TCPDF { // END GRAPHIC FUNCTIONS SECTION ----------------------- - // BIDIRECTIONAL TEXT SECTION -------------------------- - - /** - * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). - * @param $str (string) string to manipulate. - * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF) - * @param $forcertl (bool) if true forces RTL text direction - * @return string - * @protected - * @author Nicola Asuni - * @since 2.1.000 (2008-01-08) - */ - protected function utf8StrRev($str, $setbom=false, $forcertl=false) { - return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl); - } - - /** - * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). - * @param $arr (array) array of unicode values. - * @param $str (string) string to manipulate (or empty value). - * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF) - * @param $forcertl (bool) if true forces RTL text direction - * @return string - * @protected - * @author Nicola Asuni - * @since 4.9.000 (2010-03-27) - */ - protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) { - return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom); - } - - /** - * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). - * @param $ta (array) array of characters composing the string. - * @param $str (string) string to process - * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR - * @return array of unicode chars - * @author Nicola Asuni - * @protected - * @since 2.4.000 (2008-03-06) - */ - protected function utf8Bidi($ta, $str='', $forcertl=false) { - // paragraph embedding level - $pel = 0; - // max level - $maxlevel = 0; - if ($this->empty_string($str)) { - // create string from array - $str = $this->UTF8ArrSubString($ta); - } - // check if string contains arabic text - if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $str)) { - $arabic = true; - } else { - $arabic = false; - } - // check if string contains RTL text - if (!($forcertl or $arabic or preg_match($this->unicode->uni_RE_PATTERN_RTL, $str))) { - return $ta; - } - - // get number of chars - $numchars = count($ta); - - if ($forcertl == 'R') { - $pel = 1; - } elseif ($forcertl == 'L') { - $pel = 0; - } else { - // P2. In each paragraph, find the first character of type L, AL, or R. - // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero. - for ($i=0; $i < $numchars; ++$i) { - $type = $this->unicode->uni_type[$ta[$i]]; - if ($type == 'L') { - $pel = 0; - break; - } elseif (($type == 'AL') or ($type == 'R')) { - $pel = 1; - break; - } - } - } - - // Current Embedding Level - $cel = $pel; - // directional override status - $dos = 'N'; - $remember = array(); - // start-of-level-run - $sor = $pel % 2 ? 'R' : 'L'; - $eor = $sor; - - // Array of characters data - $chardata = array(); - - // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase. - // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached. - for ($i=0; $i < $numchars; ++$i) { - if ($ta[$i] == $this->unicode->uni_RLE) { - // X2. With each RLE, compute the least greater odd embedding level. - // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral. - // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status. - $next_level = $cel + ($cel % 2) + 1; - if ($next_level < 62) { - $remember[] = array('num' => $this->unicode->uni_RLE, 'cel' => $cel, 'dos' => $dos); - $cel = $next_level; - $dos = 'N'; - $sor = $eor; - $eor = $cel % 2 ? 'R' : 'L'; - } - } elseif ($ta[$i] == $this->unicode->uni_LRE) { - // X3. With each LRE, compute the least greater even embedding level. - // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral. - // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status. - $next_level = $cel + 2 - ($cel % 2); - if ($next_level < 62) { - $remember[] = array('num' => $this->unicode->uni_LRE, 'cel' => $cel, 'dos' => $dos); - $cel = $next_level; - $dos = 'N'; - $sor = $eor; - $eor = $cel % 2 ? 'R' : 'L'; - } - } elseif ($ta[$i] == $this->unicode->uni_RLO) { - // X4. With each RLO, compute the least greater odd embedding level. - // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left. - // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status. - $next_level = $cel + ($cel % 2) + 1; - if ($next_level < 62) { - $remember[] = array('num' => $this->unicode->uni_RLO, 'cel' => $cel, 'dos' => $dos); - $cel = $next_level; - $dos = 'R'; - $sor = $eor; - $eor = $cel % 2 ? 'R' : 'L'; - } - } elseif ($ta[$i] == $this->unicode->uni_LRO) { - // X5. With each LRO, compute the least greater even embedding level. - // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right. - // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status. - $next_level = $cel + 2 - ($cel % 2); - if ($next_level < 62) { - $remember[] = array('num' => $this->unicode->uni_LRO, 'cel' => $cel, 'dos' => $dos); - $cel = $next_level; - $dos = 'L'; - $sor = $eor; - $eor = $cel % 2 ? 'R' : 'L'; - } - } elseif ($ta[$i] == $this->unicode->uni_PDF) { - // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override. - if (count($remember)) { - $last = count($remember) - 1; - if (($remember[$last]['num'] == $this->unicode->uni_RLE) or - ($remember[$last]['num'] == $this->unicode->uni_LRE) or - ($remember[$last]['num'] == $this->unicode->uni_RLO) or - ($remember[$last]['num'] == $this->unicode->uni_LRO)) { - $match = array_pop($remember); - $cel = $match['cel']; - $dos = $match['dos']; - $sor = $eor; - $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L'; - } - } - } elseif (($ta[$i] != $this->unicode->uni_RLE) and - ($ta[$i] != $this->unicode->uni_LRE) and - ($ta[$i] != $this->unicode->uni_RLO) and - ($ta[$i] != $this->unicode->uni_LRO) and - ($ta[$i] != $this->unicode->uni_PDF)) { - // X6. For all types besides RLE, LRE, RLO, LRO, and PDF: - // a. Set the level of the current character to the current embedding level. - // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status. - if ($dos != 'N') { - $chardir = $dos; - } else { - if (isset($this->unicode->uni_type[$ta[$i]])) { - $chardir = $this->unicode->uni_type[$ta[$i]]; - } else { - $chardir = 'L'; - } - } - // stores string characters and other information - $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor); - } - } // end for each char - - // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding. - // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes. - // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L. - - // 3.3.3 Resolving Weak Types - // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used. - // Nonspacing marks are now resolved based on the previous characters. - $numchars = count($chardata); - - // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor. - $prevlevel = -1; // track level changes - $levcount = 0; // counts consecutive chars at the same level - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['type'] == 'NSM') { - if ($levcount) { - $chardata[$i]['type'] = $chardata[$i]['sor']; - } elseif ($i > 0) { - $chardata[$i]['type'] = $chardata[($i-1)]['type']; - } - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['char'] == 'EN') { - for ($j=$levcount; $j >= 0; $j--) { - if ($chardata[$j]['type'] == 'AL') { - $chardata[$i]['type'] = 'AN'; - } elseif (($chardata[$j]['type'] == 'L') or ($chardata[$j]['type'] == 'R')) { - break; - } - } - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // W3. Change all ALs to R. - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['type'] == 'AL') { - $chardata[$i]['type'] = 'R'; - } - } - - // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if (($levcount > 0) and (($i+1) < $numchars) and ($chardata[($i+1)]['level'] == $prevlevel)) { - if (($chardata[$i]['type'] == 'ES') and ($chardata[($i-1)]['type'] == 'EN') and ($chardata[($i+1)]['type'] == 'EN')) { - $chardata[$i]['type'] = 'EN'; - } elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i-1)]['type'] == 'EN') and ($chardata[($i+1)]['type'] == 'EN')) { - $chardata[$i]['type'] = 'EN'; - } elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i-1)]['type'] == 'AN') and ($chardata[($i+1)]['type'] == 'AN')) { - $chardata[$i]['type'] = 'AN'; - } - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['type'] == 'ET') { - if (($levcount > 0) and ($chardata[($i-1)]['type'] == 'EN')) { - $chardata[$i]['type'] = 'EN'; - } else { - $j = $i+1; - while (($j < $numchars) and ($chardata[$j]['level'] == $prevlevel)) { - if ($chardata[$j]['type'] == 'EN') { - $chardata[$i]['type'] = 'EN'; - break; - } elseif ($chardata[$j]['type'] != 'ET') { - break; - } - ++$j; - } - } - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // W6. Otherwise, separators and terminators change to Other Neutral. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if (($chardata[$i]['type'] == 'ET') or ($chardata[$i]['type'] == 'ES') or ($chardata[$i]['type'] == 'CS')) { - $chardata[$i]['type'] = 'ON'; - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['char'] == 'EN') { - for ($j=$levcount; $j >= 0; $j--) { - if ($chardata[$j]['type'] == 'L') { - $chardata[$i]['type'] = 'L'; - } elseif ($chardata[$j]['type'] == 'R') { - break; - } - } - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries. - $prevlevel = -1; - $levcount = 0; - for ($i=0; $i < $numchars; ++$i) { - if (($levcount > 0) and (($i+1) < $numchars) and ($chardata[($i+1)]['level'] == $prevlevel)) { - if (($chardata[$i]['type'] == 'N') and ($chardata[($i-1)]['type'] == 'L') and ($chardata[($i+1)]['type'] == 'L')) { - $chardata[$i]['type'] = 'L'; - } elseif (($chardata[$i]['type'] == 'N') and - (($chardata[($i-1)]['type'] == 'R') or ($chardata[($i-1)]['type'] == 'EN') or ($chardata[($i-1)]['type'] == 'AN')) and - (($chardata[($i+1)]['type'] == 'R') or ($chardata[($i+1)]['type'] == 'EN') or ($chardata[($i+1)]['type'] == 'AN'))) { - $chardata[$i]['type'] = 'R'; - } elseif ($chardata[$i]['type'] == 'N') { - // N2. Any remaining neutrals take the embedding direction - $chardata[$i]['type'] = $chardata[$i]['sor']; - } - } elseif (($levcount == 0) and (($i+1) < $numchars) and ($chardata[($i+1)]['level'] == $prevlevel)) { - // first char - if (($chardata[$i]['type'] == 'N') and ($chardata[$i]['sor'] == 'L') and ($chardata[($i+1)]['type'] == 'L')) { - $chardata[$i]['type'] = 'L'; - } elseif (($chardata[$i]['type'] == 'N') and - (($chardata[$i]['sor'] == 'R') or ($chardata[$i]['sor'] == 'EN') or ($chardata[$i]['sor'] == 'AN')) and - (($chardata[($i+1)]['type'] == 'R') or ($chardata[($i+1)]['type'] == 'EN') or ($chardata[($i+1)]['type'] == 'AN'))) { - $chardata[$i]['type'] = 'R'; - } elseif ($chardata[$i]['type'] == 'N') { - // N2. Any remaining neutrals take the embedding direction - $chardata[$i]['type'] = $chardata[$i]['sor']; - } - } elseif (($levcount > 0) and ((($i+1) == $numchars) or (($i+1) < $numchars) and ($chardata[($i+1)]['level'] != $prevlevel))) { - //last char - if (($chardata[$i]['type'] == 'N') and ($chardata[($i-1)]['type'] == 'L') and ($chardata[$i]['eor'] == 'L')) { - $chardata[$i]['type'] = 'L'; - } elseif (($chardata[$i]['type'] == 'N') and - (($chardata[($i-1)]['type'] == 'R') or ($chardata[($i-1)]['type'] == 'EN') or ($chardata[($i-1)]['type'] == 'AN')) and - (($chardata[$i]['eor'] == 'R') or ($chardata[$i]['eor'] == 'EN') or ($chardata[$i]['eor'] == 'AN'))) { - $chardata[$i]['type'] = 'R'; - } elseif ($chardata[$i]['type'] == 'N') { - // N2. Any remaining neutrals take the embedding direction - $chardata[$i]['type'] = $chardata[$i]['sor']; - } - } elseif ($chardata[$i]['type'] == 'N') { - // N2. Any remaining neutrals take the embedding direction - $chardata[$i]['type'] = $chardata[$i]['sor']; - } - if ($chardata[$i]['level'] != $prevlevel) { - $levcount = 0; - } else { - ++$levcount; - } - $prevlevel = $chardata[$i]['level']; - } - - // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels. - // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level. - for ($i=0; $i < $numchars; ++$i) { - $odd = $chardata[$i]['level'] % 2; - if ($odd) { - if (($chardata[$i]['type'] == 'L') or ($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN')) { - $chardata[$i]['level'] += 1; - } - } else { - if ($chardata[$i]['type'] == 'R') { - $chardata[$i]['level'] += 1; - } elseif (($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN')) { - $chardata[$i]['level'] += 2; - } - } - $maxlevel = max($chardata[$i]['level'],$maxlevel); - } - - // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level: - // 1. Segment separators, - // 2. Paragraph separators, - // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and - // 4. Any sequence of white space characters at the end of the line. - for ($i=0; $i < $numchars; ++$i) { - if (($chardata[$i]['type'] == 'B') or ($chardata[$i]['type'] == 'S')) { - $chardata[$i]['level'] = $pel; - } elseif ($chardata[$i]['type'] == 'WS') { - $j = $i+1; - while ($j < $numchars) { - if ((($chardata[$j]['type'] == 'B') or ($chardata[$j]['type'] == 'S')) or - (($j == ($numchars-1)) and ($chardata[$j]['type'] == 'WS'))) { - $chardata[$i]['level'] = $pel; - break; - } elseif ($chardata[$j]['type'] != 'WS') { - break; - } - ++$j; - } - } - } - - // Arabic Shaping - // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run. - if ($arabic) { - $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688); - $alfletter = array(1570,1571,1573,1575); - $chardata2 = $chardata; - $laaletter = false; - $charAL = array(); - $x = 0; - for ($i=0; $i < $numchars; ++$i) { - if (($this->unicode->uni_type[$chardata[$i]['char']] == 'AL') or ($chardata[$i]['char'] == 32) or ($chardata[$i]['char'] == 8204)) { - $charAL[$x] = $chardata[$i]; - $charAL[$x]['i'] = $i; - $chardata[$i]['x'] = $x; - ++$x; - } - } - $numAL = $x; - for ($i=0; $i < $numchars; ++$i) { - $thischar = $chardata[$i]; - if ($i > 0) { - $prevchar = $chardata[($i-1)]; - } else { - $prevchar = false; - } - if (($i+1) < $numchars) { - $nextchar = $chardata[($i+1)]; - } else { - $nextchar = false; - } - if ($this->unicode->uni_type[$thischar['char']] == 'AL') { - $x = $thischar['x']; - if ($x > 0) { - $prevchar = $charAL[($x-1)]; - } else { - $prevchar = false; - } - if (($x+1) < $numAL) { - $nextchar = $charAL[($x+1)]; - } else { - $nextchar = false; - } - // if laa letter - if (($prevchar !== false) and ($prevchar['char'] == 1604) and (in_array($thischar['char'], $alfletter))) { - $arabicarr = $this->unicode->uni_laa_array; - $laaletter = true; - if ($x > 1) { - $prevchar = $charAL[($x-2)]; - } else { - $prevchar = false; - } - } else { - $arabicarr = $this->unicode->uni_arabicsubst; - $laaletter = false; - } - if (($prevchar !== false) and ($nextchar !== false) and - (($this->unicode->uni_type[$prevchar['char']] == 'AL') or ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) and - (($this->unicode->uni_type[$nextchar['char']] == 'AL') or ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) and - ($prevchar['type'] == $thischar['type']) and - ($nextchar['type'] == $thischar['type']) and - ($nextchar['char'] != 1567)) { - if (in_array($prevchar['char'], $endedletter)) { - if (isset($arabicarr[$thischar['char']][2])) { - // initial - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2]; - } - } else { - if (isset($arabicarr[$thischar['char']][3])) { - // medial - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3]; - } - } - } elseif (($nextchar !== false) and - (($this->unicode->uni_type[$nextchar['char']] == 'AL') or ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) and - ($nextchar['type'] == $thischar['type']) and - ($nextchar['char'] != 1567)) { - if (isset($arabicarr[$chardata[$i]['char']][2])) { - // initial - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2]; - } - } elseif ((($prevchar !== false) and - (($this->unicode->uni_type[$prevchar['char']] == 'AL') or ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) and - ($prevchar['type'] == $thischar['type'])) or - (($nextchar !== false) and ($nextchar['char'] == 1567))) { - // final - if (($i > 1) and ($thischar['char'] == 1607) and - ($chardata[$i-1]['char'] == 1604) and - ($chardata[$i-2]['char'] == 1604)) { - //Allah Word - // mark characters to delete with false - $chardata2[$i-2]['char'] = false; - $chardata2[$i-1]['char'] = false; - $chardata2[$i]['char'] = 65010; - } else { - if (($prevchar !== false) and in_array($prevchar['char'], $endedletter)) { - if (isset($arabicarr[$thischar['char']][0])) { - // isolated - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0]; - } - } else { - if (isset($arabicarr[$thischar['char']][1])) { - // final - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1]; - } - } - } - } elseif (isset($arabicarr[$thischar['char']][0])) { - // isolated - $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0]; - } - // if laa letter - if ($laaletter) { - // mark characters to delete with false - $chardata2[($charAL[($x-1)]['i'])]['char'] = false; - } - } // end if AL (Arabic Letter) - } // end for each char - /* - * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced. - * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner. - */ - for ($i = 0; $i < ($numchars-1); ++$i) { - if (($chardata2[$i]['char'] == 1617) and (isset($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])]))) { - // check if the subtitution font is defined on current font - if (isset($this->CurrentFont['cw'][($this->unicode->uni_diacritics[($chardata2[$i+1]['char'])])])) { - $chardata2[$i]['char'] = false; - $chardata2[$i+1]['char'] = $this->unicode->uni_diacritics[($chardata2[$i+1]['char'])]; - } - } - } - // remove marked characters - foreach ($chardata2 as $key => $value) { - if ($value['char'] === false) { - unset($chardata2[$key]); - } - } - $chardata = array_values($chardata2); - $numchars = count($chardata); - unset($chardata2); - unset($arabicarr); - unset($laaletter); - unset($charAL); - } - - // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher. - for ($j=$maxlevel; $j > 0; $j--) { - $ordarray = array(); - $revarr = array(); - $onlevel = false; - for ($i=0; $i < $numchars; ++$i) { - if ($chardata[$i]['level'] >= $j) { - $onlevel = true; - if (isset($this->unicode->uni_mirror[$chardata[$i]['char']])) { - // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true. - $chardata[$i]['char'] = $this->unicode->uni_mirror[$chardata[$i]['char']]; - } - $revarr[] = $chardata[$i]; - } else { - if ($onlevel) { - $revarr = array_reverse($revarr); - $ordarray = array_merge($ordarray, $revarr); - $revarr = array(); - $onlevel = false; - } - $ordarray[] = $chardata[$i]; - } - } - if ($onlevel) { - $revarr = array_reverse($revarr); - $ordarray = array_merge($ordarray, $revarr); - } - $chardata = $ordarray; - } - - $ordarray = array(); - for ($i=0; $i < $numchars; ++$i) { - $ordarray[] = $chardata[$i]['char']; - // store char values for subsetting - $this->CurrentFont['subsetchars'][$chardata[$i]['char']] = true; - } - // update font subsetchars - $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']); - return $ordarray; - } - - // END OF BIDIRECTIONAL TEXT SECTION ------------------- - - /** - * Encode a name object. - * @param $name (string) Name object to encode. - * @return (string) Encoded name object. - * @protected - * @author Nicola Asuni - * @since 5.9.097 (2011-06-23) - */ - protected function encodeNameObject($name) { - $escname = ''; - $length = strlen($name); - for ($i = 0; $i < $length; ++$i) { - $chr = $name[$i]; - if (preg_match('/[0-9a-zA-Z]/', $chr) == 1) { - $escname .= $chr; - } else { - $escname .= sprintf('#%02X', ord($chr)); - } - } - return $escname; - } - /** * Add a Named Destination. * NOTE: destination names are unique, so only last entry will be saved. * @param $name (string) Destination name. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;). - * @param $page (int) Target page number (leave empty for current page). + * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;). * @return (string) Stripped named destination identifier or false in case of error. * @public @@ -16663,8 +12262,8 @@ class TCPDF { */ public function setDestination($name, $y=-1, $page='', $x=-1) { // remove unsupported characters - $name = $this->encodeNameObject($name); - if ($this->empty_string($name)) { + $name = TCPDF_STATIC::encodeNameObject($name); + if (TCPDF_STATIC::empty_string($name)) { return false; } if ($y == -1) { @@ -16681,13 +12280,19 @@ class TCPDF { } elseif ($x > $this->w) { $x = $this->w; } + $fixed = false; + if (!empty($page) AND (substr($page, 0, 1) == '*')) { + $page = intval(substr($page, 1)); + // this page number will not be changed when moving/add/deleting pages + $fixed = true; + } if (empty($page)) { $page = $this->PageNo(); if (empty($page)) { return; } } - $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page); + $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed); return $name; } @@ -16703,9 +12308,9 @@ class TCPDF { } /** - * Create a javascript PDF string. + * Insert Named Destinations. * @protected - * @author Johannes G�ntert, Nicola Asuni + * @author Johannes G\FCntert, Nicola Asuni * @since 5.9.098 (2011-06-23) */ protected function _putdests() { @@ -16727,13 +12332,15 @@ class TCPDF { * @param $txt (string) Bookmark description. * @param $level (int) Bookmark level (minimum value is 0). * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;). - * @param $page (int) Target page number (leave empty for current page). + * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic. * @param $color (array) RGB color array (values from 0 to 255). + * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;). + * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name). * @public */ - public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0)) { - $this->Bookmark($txt, $level, $y, $page, $style, $color); + public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') { + $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link); } /** @@ -16741,15 +12348,15 @@ class TCPDF { * @param $txt (string) Bookmark description. * @param $level (int) Bookmark level (minimum value is 0). * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;). - * @param $page (int) Target page number (leave empty for current page). + * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic. * @param $color (array) RGB color array (values from 0 to 255). * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;). + * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name). * @public - * @author Olivier Plathey, Nicola Asuni * @since 2.1.002 (2008-02-12) */ - public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1) { + public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') { if ($level < 0) { $level = 0; } @@ -16776,13 +12383,20 @@ class TCPDF { } elseif ($x > $this->w) { $x = $this->w; } + $fixed = false; + $pageAsString = (string) $page; + if ($pageAsString && $pageAsString[0] == '*') { + $page = intval(substr($page, 1)); + // this page number will not be changed when moving/add/deleting pages + $fixed = true; + } if (empty($page)) { $page = $this->PageNo(); if (empty($page)) { return; } } - $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color); + $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link); } /** @@ -16830,7 +12444,7 @@ class TCPDF { } else { $this->outlines[$i]['parent'] = $nb; } - if (($o['l'] <= $level) and ($i > 0)) { + if (($o['l'] <= $level) AND ($i > 0)) { //Set prev and next pointers $prev = $lru[$o['l']]; $this->outlines[$prev]['next'] = $i; @@ -16864,7 +12478,34 @@ class TCPDF { if (isset($o['last'])) { $out .= ' /Last '.($n + $o['last']).' 0 R'; } - if (isset($this->page_obj_id[($o['p'])])) { + if (isset($o['u']) AND !empty($o['u'])) { + // link + if (is_string($o['u'])) { + if ($o['u'][0] == '#') { + // internal destination + $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1)); + } elseif ($o['u'][0] == '%') { + // embedded PDF file + $filename = basename(substr($o['u'], 1)); + $out .= ' /A <embeddedfiles[$filename]['a'].' >> >>'; + } elseif ($o['u'][0] == '*') { + // embedded generic file + $filename = basename(substr($o['u'], 1)); + $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});'; + $out .= ' /A <_textstring($jsa, $oid).'>>'; + } else { + // external URI link + $out .= ' /A <_datastring($this->unhtmlentities($o['u']), $oid).'>>'; + } + } elseif (isset($this->links[$o['u']])) { + // internal link ID + $l = $this->links[$o['u']]; + if (isset($this->page_obj_id[($l['p'])])) { + $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k))); + } + } + } elseif (isset($this->page_obj_id[($o['p'])])) { + // link to a page $out .= ' '.sprintf('/Dest [%u 0 R /XYZ %F %F null]', $this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k))); } // set font style @@ -16881,7 +12522,7 @@ class TCPDF { } $out .= sprintf(' /F %d', $style); // set bookmark color - if (isset($o['c']) and is_array($o['c']) and (count($o['c']) == 3)) { + if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) { $color = array_values($o['c']); $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255)); } else { @@ -16904,7 +12545,7 @@ class TCPDF { * Adds a javascript * @param $script (string) Javascript code * @public - * @author Johannes G�ntert, Nicola Asuni + * @author Johannes G\FCntert, Nicola Asuni * @since 2.1.002 (2008-02-12) */ public function IncludeJS($script) { @@ -16933,11 +12574,11 @@ class TCPDF { /** * Create a javascript PDF string. * @protected - * @author Johannes G�ntert, Nicola Asuni + * @author Johannes G\FCntert, Nicola Asuni * @since 2.1.002 (2008-02-12) */ protected function _putjavascript() { - if ($this->pdfa_mode or (empty($this->javascript) and empty($this->js_objects))) { + if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) { return; } if (strpos($this->javascript, 'this.addField') > 0) { @@ -16950,21 +12591,19 @@ class TCPDF { $jsb = "getField('tcpdfdocsaved').value='saved';"; $this->javascript = $jsa."\n".$this->javascript."\n".$jsb; } - $this->n_js = $this->_newobj(); - $out = ' << /Names ['; + // name tree for javascript + $this->n_js = '<< /Names ['; if (!empty($this->javascript)) { - $out .= ' (EmbeddedJS) '.($this->n + 1).' 0 R'; + $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R'; } if (!empty($this->js_objects)) { foreach ($this->js_objects as $key => $val) { if ($val['onload']) { - $out .= ' (JS'.$key.') '.$key.' 0 R'; + $this->n_js .= ' (JS'.$key.') '.$key.' 0 R'; } } } - $out .= ' ] >>'; - $out .= "\n".'endobj'; - $this->_out($out); + $this->n_js .= ' ] >>'; // default Javascript object if (!empty($this->javascript)) { $obj_id = $this->_newobj(); @@ -16983,24 +12622,6 @@ class TCPDF { } } - /** - * Convert color to javascript color. - * @param $color (string) color name or "#RRGGBB" - * @protected - * @author Denis Van Nuffelen, Nicola Asuni - * @since 2.1.002 (2008-02-12) - */ - protected function _JScolor($color) { - static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray'); - if (substr($color,0,1) == '#') { - return sprintf("['RGB',%F,%F,%F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255); - } - if (!in_array($color,$aColors)) { - $this->Error('Invalid color: '.$color); - } - return 'color.'.$color; - } - /** * Adds a javascript form field. * @param $type (string) field type @@ -17023,9 +12644,9 @@ class TCPDF { $k = $this->k; $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n"; $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n"; - while (list($key, $val) = each($prop)) { + foreach($prop as $key => $val) { if (strcmp(substr($key, -5), 'Color') == 0) { - $val = $this->_JScolor($val); + $val = TCPDF_COLORS::_JScolor($val); } else { $val = "'".$val."'"; } @@ -17041,372 +12662,7 @@ class TCPDF { // --- FORM FIELDS ----------------------------------------------------- - /** - * Convert JavaScript form fields properties array to Annotation Properties array. - * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference. - * @return array of annotation properties - * @protected - * @author Nicola Asuni - * @since 4.8.000 (2009-09-06) - */ - protected function getAnnotOptFromJSProp($prop) { - if (isset($prop['aopt']) and is_array($prop['aopt'])) { - // the annotation options area lready defined - return $prop['aopt']; - } - $opt = array(); // value to be returned - // alignment: Controls how the text is laid out within the text field. - if (isset($prop['alignment'])) { - switch ($prop['alignment']) { - case 'left': { - $opt['q'] = 0; - break; - } - case 'center': { - $opt['q'] = 1; - break; - } - case 'right': { - $opt['q'] = 2; - break; - } - default: { - $opt['q'] = ($this->rtl)?2:0; - break; - } - } - } - // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle. - if (isset($prop['lineWidth'])) { - $linewidth = intval($prop['lineWidth']); - } else { - $linewidth = 1; - } - // borderStyle: The border style for a field. - if (isset($prop['borderStyle'])) { - switch ($prop['borderStyle']) { - case 'border.d': - case 'dashed': { - $opt['border'] = array(0, 0, $linewidth, array(3, 2)); - $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2)); - break; - } - case 'border.b': - case 'beveled': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'B'); - break; - } - case 'border.i': - case 'inset': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'I'); - break; - } - case 'border.u': - case 'underline': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'U'); - break; - } - case 'border.s': - case 'solid': { - $opt['border'] = array(0, 0, $linewidth); - $opt['bs'] = array('w'=>$linewidth, 's'=>'S'); - break; - } - default: { - break; - } - } - } - if (isset($prop['border']) and is_array($prop['border'])) { - $opt['border'] = $prop['border']; - } - if (!isset($opt['mk'])) { - $opt['mk'] = array(); - } - if (!isset($opt['mk']['if'])) { - $opt['mk']['if'] = array(); - } - $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. - if (isset($prop['buttonAlignX'])) { - $opt['mk']['if']['a'][0] = $prop['buttonAlignX']; - } - // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon. - if (isset($prop['buttonAlignY'])) { - $opt['mk']['if']['a'][1] = $prop['buttonAlignY']; - } - // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field. - if (isset($prop['buttonFitBounds']) and ($prop['buttonFitBounds'] == 'true')) { - $opt['mk']['if']['fb'] = true; - } - // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face. - if (isset($prop['buttonScaleHow'])) { - switch ($prop['buttonScaleHow']) { - case 'scaleHow.proportional': { - $opt['mk']['if']['s'] = 'P'; - break; - } - case 'scaleHow.anamorphic': { - $opt['mk']['if']['s'] = 'A'; - break; - } - } - } - // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face. - if (isset($prop['buttonScaleWhen'])) { - switch ($prop['buttonScaleWhen']) { - case 'scaleWhen.always': { - $opt['mk']['if']['sw'] = 'A'; - break; - } - case 'scaleWhen.never': { - $opt['mk']['if']['sw'] = 'N'; - break; - } - case 'scaleWhen.tooBig': { - $opt['mk']['if']['sw'] = 'B'; - break; - } - case 'scaleWhen.tooSmall': { - $opt['mk']['if']['sw'] = 'S'; - break; - } - } - } - // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face. - if (isset($prop['buttonPosition'])) { - switch ($prop['buttonPosition']) { - case 0: - case 'position.textOnly': { - $opt['mk']['tp'] = 0; - break; - } - case 1: - case 'position.iconOnly': { - $opt['mk']['tp'] = 1; - break; - } - case 2: - case 'position.iconTextV': { - $opt['mk']['tp'] = 2; - break; - } - case 3: - case 'position.textIconV': { - $opt['mk']['tp'] = 3; - break; - } - case 4: - case 'position.iconTextH': { - $opt['mk']['tp'] = 4; - break; - } - case 5: - case 'position.textIconH': { - $opt['mk']['tp'] = 5; - break; - } - case 6: - case 'position.overlay': { - $opt['mk']['tp'] = 6; - break; - } - } - } - // fillColor: Specifies the background color for a field. - if (isset($prop['fillColor'])) { - if (is_array($prop['fillColor'])) { - $opt['mk']['bg'] = $prop['fillColor']; - } else { - $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']); - } - } - // 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 (is_array($prop['strokeColor'])) { - $opt['mk']['bc'] = $prop['strokeColor']; - } else { - $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']); - } - } - // rotation: The rotation of a widget in counterclockwise increments. - if (isset($prop['rotation'])) { - $opt['mk']['r'] = $prop['rotation']; - } - // charLimit: Limits the number of characters that a user can type into a text field. - if (isset($prop['charLimit'])) { - $opt['maxlen'] = intval($prop['charLimit']); - } - if (!isset($ff)) { - $ff = 0; // default value - } - // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. - if (isset($prop['readonly']) and ($prop['readonly'] == 'true')) { - $ff += 1 << 0; - } - // required: Specifies whether a field requires a value. - if (isset($prop['required']) and ($prop['required'] == 'true')) { - $ff += 1 << 1; - } - // multiline: Controls how text is wrapped within the field. - if (isset($prop['multiline']) and ($prop['multiline'] == 'true')) { - $ff += 1 << 12; - } - // password: Specifies whether the field should display asterisks when data is entered in the field. - if (isset($prop['password']) and ($prop['password'] == 'true')) { - $ff += 1 << 13; - } - // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect. - if (isset($prop['NoToggleToOff']) and ($prop['NoToggleToOff'] == 'true')) { - $ff += 1 << 14; - } - // Radio: If set, the field is a set of radio buttons. - if (isset($prop['Radio']) and ($prop['Radio'] == 'true')) { - $ff += 1 << 15; - } - // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value. - if (isset($prop['Pushbutton']) and ($prop['Pushbutton'] == 'true')) { - $ff += 1 << 16; - } - // Combo: If set, the field is a combo box; if clear, the field is a list box. - if (isset($prop['Combo']) and ($prop['Combo'] == 'true')) { - $ff += 1 << 17; - } - // editable: Controls whether a combo box is editable. - if (isset($prop['editable']) and ($prop['editable'] == 'true')) { - $ff += 1 << 18; - } - // Sort: If set, the field's option items shall be sorted alphabetically. - if (isset($prop['Sort']) and ($prop['Sort'] == 'true')) { - $ff += 1 << 19; - } - // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection). - if (isset($prop['fileSelect']) and ($prop['fileSelect'] == 'true')) { - $ff += 1 << 20; - } - // multipleSelection: If true, indicates that a list box allows a multiple selection of items. - if (isset($prop['multipleSelection']) and ($prop['multipleSelection'] == 'true')) { - $ff += 1 << 21; - } - // doNotSpellCheck: If true, spell checking is not performed on this editable text field. - if (isset($prop['doNotSpellCheck']) and ($prop['doNotSpellCheck'] == 'true')) { - $ff += 1 << 22; - } - // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field. - if (isset($prop['doNotScroll']) and ($prop['doNotScroll'] == 'true')) { - $ff += 1 << 23; - } - // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set. - if (isset($prop['comb']) and ($prop['comb'] == 'true')) { - $ff += 1 << 24; - } - // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons. - if (isset($prop['radiosInUnison']) and ($prop['radiosInUnison'] == 'true')) { - $ff += 1 << 25; - } - // richText: If true, the field allows rich text formatting. - if (isset($prop['richText']) and ($prop['richText'] == 'true')) { - $ff += 1 << 25; - } - // commitOnSelChange: Controls whether a field value is committed after a selection change. - if (isset($prop['commitOnSelChange']) and ($prop['commitOnSelChange'] == 'true')) { - $ff += 1 << 26; - } - $opt['ff'] = $ff; - // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset. - if (isset($prop['defaultValue'])) { - $opt['dv'] = $prop['defaultValue']; - } - $f = 4; // default value for annotation flags - // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. - if (isset($prop['readonly']) and ($prop['readonly'] == 'true')) { - $f += 1 << 6; - } - // display: Controls whether the field is hidden or visible on screen and in print. - if (isset($prop['display'])) { - if ($prop['display'] == 'display.visible') { - // - } elseif ($prop['display'] == 'display.hidden') { - $f += 1 << 1; - } elseif ($prop['display'] == 'display.noPrint') { - $f -= 1 << 2; - } elseif ($prop['display'] == 'display.noView') { - $f += 1 << 5; - } - } - $opt['f'] = $f; - // currentValueIndices: Reads and writes single or multiple values of a list box or combo box. - if (isset($prop['currentValueIndices']) and is_array($prop['currentValueIndices'])) { - $opt['i'] = $prop['currentValueIndices']; - } - // value: The value of the field data that the user has entered. - if (isset($prop['value'])) { - if (is_array($prop['value'])) { - $opt['opt'] = array(); - foreach ($prop['value'] as $key => $optval) { - // exportValues: An array of strings representing the export values for the field. - if (isset($prop['exportValues'][$key])) { - $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]); - } else { - $opt['opt'][$key] = $prop['value'][$key]; - } - } - } else { - $opt['v'] = $prop['value']; - } - } - // richValue: This property specifies the text contents and formatting of a rich text field. - if (isset($prop['richValue'])) { - $opt['rv'] = $prop['richValue']; - } - // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded). - if (isset($prop['submitName'])) { - $opt['tm'] = $prop['submitName']; - } - // name: Fully qualified field name. - if (isset($prop['name'])) { - $opt['t'] = $prop['name']; - } - // userName: The user name (short description string) of the field. - if (isset($prop['userName'])) { - $opt['tu'] = $prop['userName']; - } - // highlight: Defines how a button reacts when a user clicks it. - if (isset($prop['highlight'])) { - switch ($prop['highlight']) { - case 'none': - case 'highlight.n': { - $opt['h'] = 'N'; - break; - } - case 'invert': - case 'highlight.i': { - $opt['h'] = 'i'; - break; - } - case 'push': - case 'highlight.p': { - $opt['h'] = 'P'; - break; - } - case 'outline': - case 'highlight.o': { - $opt['h'] = 'O'; - break; - } - } - } - // Unsupported options: - // - calcOrderIndex: Changes the calculation order of fields in the document. - // - delay: Delays the redrawing of a field's appearance. - // - defaultStyle: This property defines the default style attributes for the form field. - // - style: Allows the user to set the glyph style of a check box or radio button. - // - textColor, textFont, textSize - return $opt; - } + /** * Set default properties for form fields. @@ -17460,7 +12716,7 @@ class TCPDF { // get default style $prop = array_merge($this->getFormDefaultProp(), $prop); // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); // set default appearance stream $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); @@ -17469,13 +12725,34 @@ class TCPDF { $popt['ap'] = array(); $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' '; $text = ''; - if (isset($prop['value']) and !empty($prop['value'])) { + if (isset($prop['value']) AND !empty($prop['value'])) { $text = $prop['value']; - } elseif (isset($opt['v']) and !empty($opt['v'])) { + } elseif (isset($opt['v']) AND !empty($opt['v'])) { $text = $opt['v']; } $tmpid = $this->startTemplate($w, $h, false); - $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false); + $align = ''; + if (isset($popt['q'])) { + switch ($popt['q']) { + case 0: { + $align = 'L'; + break; + } + case 1: { + $align = 'C'; + break; + } + case 2: { + $align = 'R'; + break; + } + default: { + $align = ''; + break; + } + } + } + $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false); $this->endTemplate(); --$this->n; $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata']; @@ -17532,7 +12809,7 @@ class TCPDF { /** * Creates a RadioButton field. * @param $name (string) Field name. - * @param $w (int) Width or the radio button. + * @param $w (int) Width of the radio button. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference. * @param $onvalue (string) Value to be returned if selected. @@ -17557,7 +12834,7 @@ class TCPDF { $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop); return; } - if ($this->empty_string($onvalue)) { + if (TCPDF_STATIC::empty_string($onvalue)) { $onvalue = 'On'; } if ($checked) { @@ -17592,7 +12869,7 @@ class TCPDF { $prop['Radio'] = 'true'; $prop['borderStyle'] = 'inset'; // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); // set additional default options $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i']; $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor); @@ -17600,9 +12877,10 @@ class TCPDF { // build appearance stream $popt['ap'] = array(); $popt['ap']['n'] = array(); + $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k); $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k); - $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); + $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy); + $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy); if (!isset($popt['mk'])) { $popt['mk'] = array(); } @@ -17671,7 +12949,7 @@ class TCPDF { // get default style $prop = array_merge($this->getFormDefaultProp(), $prop); // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); // set additional default values $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); @@ -17758,7 +13036,7 @@ class TCPDF { $prop = array_merge($this->getFormDefaultProp(), $prop); $prop['Combo'] = true; // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); // set additional default options $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); @@ -17839,7 +13117,7 @@ class TCPDF { $prop = array_merge($this->getFormDefaultProp(), $prop); $prop['borderStyle'] = 'inset'; // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); // set additional default options $font = 'zapfdingbats'; if ($this->pdfa_mode) { @@ -17854,17 +13132,17 @@ class TCPDF { // build appearance stream $popt['ap'] = array(); $popt['ap']['n'] = array(); - $fy = ((($tmpfont['desc']['Ascent'] + $tmpfont['desc']['Descent']) * $this->FontSizePt) / (1000 * $this->k)); + $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k); $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k); - $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); - $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, 0, $fy); + $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy); + $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q', $this->TextColor, $tmpfont['i'], $this->FontSizePt, $fx, $fy); // merge options $opt = array_merge($popt, $opt); // set remaining annotation data $opt['Subtype'] = 'Widget'; $opt['ft'] = 'Btn'; $opt['t'] = $name; - if ($this->empty_string($onvalue)) { + if (TCPDF_STATIC::empty_string($onvalue)) { $onvalue = 'Yes'; } $opt['opt'] = array($onvalue); @@ -17922,7 +13200,7 @@ class TCPDF { $prop['highlight'] = 'push'; $prop['display'] = 'display.noPrint'; // get annotation data - $popt = $this->getAnnotOptFromJSProp($prop); + $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl); $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i']; $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor); $popt['da'] = $fontstyle; @@ -17948,7 +13226,7 @@ class TCPDF { $popt['mk'] = array(); } $ann_obj_id = ($this->n + 1); - if (!empty($action) and !is_array($action)) { + if (!empty($action) AND !is_array($action)) { $ann_obj_id = ($this->n + 2); } $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id); @@ -17966,21 +13244,21 @@ class TCPDF { // form action options as on section 12.7.5 of PDF32000_2008. $opt['aa'] = '/D <<'; $bmode = array('SubmitForm', 'ResetForm', 'ImportData'); - foreach ($action as $key => $val) { - if (($key == 'S') and in_array($val, $bmode)) { + foreach ($action AS $key => $val) { + if (($key == 'S') AND in_array($val, $bmode)) { $opt['aa'] .= ' /S /'.$val; - } elseif (($key == 'F') and (!empty($val))) { + } elseif (($key == 'F') AND (!empty($val))) { $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id); - } elseif (($key == 'Fields') and is_array($val) and !empty($val)) { + } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) { $opt['aa'] .= ' /Fields ['; - foreach ($val as $field) { + foreach ($val AS $field) { $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id); } $opt['aa'] .= ']'; } elseif (($key == 'Flags')) { $ff = 0; if (is_array($val)) { - foreach ($val as $flag) { + foreach ($val AS $flag) { switch ($flag) { case 'Include/Exclude': { $ff += 1 << 0; @@ -18067,7 +13345,7 @@ class TCPDF { * @since 4.6.008 (2009-05-07) */ protected function _putsignature() { - if ((!$this->sign) or (!isset($this->signature_data['cert_type']))) { + if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) { return; } $sigobjid = ($this->sig_obj_id + 1); @@ -18075,58 +13353,60 @@ class TCPDF { $out .= '<< /Type /Sig'; $out .= ' /Filter /Adobe.PPKLite'; $out .= ' /SubFilter /adbe.pkcs7.detached'; - $out .= ' '.$this->byterange_string; + $out .= ' '.TCPDF_STATIC::$byterange_string; $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>'; - $out .= ' /Reference ['; // array of signature reference dictionaries - $out .= ' << /Type /SigRef'; - if ($this->signature_data['cert_type'] > 0) { - $out .= ' /TransformMethod /DocMDP'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /P '.$this->signature_data['cert_type']; - $out .= ' /V /1.2'; - } else { - $out .= ' /TransformMethod /UR3'; - $out .= ' /TransformParams <<'; - $out .= ' /Type /TransformParams'; - $out .= ' /V /2.2'; - if (!$this->empty_string($this->ur['document'])) { - $out .= ' /Document['.$this->ur['document'].']'; - } - if (!$this->empty_string($this->ur['form'])) { - $out .= ' /Form['.$this->ur['form'].']'; - } - if (!$this->empty_string($this->ur['signature'])) { - $out .= ' /Signature['.$this->ur['signature'].']'; - } - if (!$this->empty_string($this->ur['annots'])) { - $out .= ' /Annots['.$this->ur['annots'].']'; - } - if (!$this->empty_string($this->ur['ef'])) { - $out .= ' /EF['.$this->ur['ef'].']'; - } - if (!$this->empty_string($this->ur['formex'])) { - $out .= ' /FormEX['.$this->ur['formex'].']'; + if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) { + $out .= ' /Reference ['; // array of signature reference dictionaries + $out .= ' << /Type /SigRef'; + if ($this->signature_data['cert_type'] > 0) { + $out .= ' /TransformMethod /DocMDP'; + $out .= ' /TransformParams <<'; + $out .= ' /Type /TransformParams'; + $out .= ' /P '.$this->signature_data['cert_type']; + $out .= ' /V /1.2'; + } else { + $out .= ' /TransformMethod /UR3'; + $out .= ' /TransformParams <<'; + $out .= ' /Type /TransformParams'; + $out .= ' /V /2.2'; + if (!TCPDF_STATIC::empty_string($this->ur['document'])) { + $out .= ' /Document['.$this->ur['document'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['form'])) { + $out .= ' /Form['.$this->ur['form'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['signature'])) { + $out .= ' /Signature['.$this->ur['signature'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['annots'])) { + $out .= ' /Annots['.$this->ur['annots'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['ef'])) { + $out .= ' /EF['.$this->ur['ef'].']'; + } + if (!TCPDF_STATIC::empty_string($this->ur['formex'])) { + $out .= ' /FormEX['.$this->ur['formex'].']'; + } } + $out .= ' >>'; // close TransformParams + // optional digest data (values must be calculated and replaced later) + //$out .= ' /Data ********** 0 R'; + //$out .= ' /DigestMethod/MD5'; + //$out .= ' /DigestLocation[********** 34]'; + //$out .= ' /DigestValue<********************************>'; + $out .= ' >>'; + $out .= ' ]'; // end of reference } - $out .= ' >>'; // close TransformParams - // optional digest data (values must be calculated and replaced later) - //$out .= ' /Data ********** 0 R'; - //$out .= ' /DigestMethod/MD5'; - //$out .= ' /DigestLocation[********** 34]'; - //$out .= ' /DigestValue<********************************>'; - $out .= ' >>'; - $out .= ' ]'; // end of reference - if (isset($this->signature_data['info']['Name']) and !$this->empty_string($this->signature_data['info']['Name'])) { + if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) { $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid); } - if (isset($this->signature_data['info']['Location']) and !$this->empty_string($this->signature_data['info']['Location'])) { + if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) { $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid); } - if (isset($this->signature_data['info']['Reason']) and !$this->empty_string($this->signature_data['info']['Reason'])) { + if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) { $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid); } - if (isset($this->signature_data['info']['ContactInfo']) and !$this->empty_string($this->signature_data['info']['ContactInfo'])) { + if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) { $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid); } $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp); @@ -18184,11 +13464,12 @@ class TCPDF { * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used. * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo. + * @param $approval (string) Enable approval signature eg. for PDF incremental update * @public * @author Nicola Asuni * @since 4.6.005 (2009-04-24) */ - public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) { + public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') { // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12 // to convert pfx certificate to pem: openssl @@ -18199,8 +13480,7 @@ class TCPDF { ++$this->n; // signature object ($this->sig_obj_id + 1) $this->signature_data = array(); if (strlen($signing_cert) == 0) { - $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt'; - $private_key_password = 'tcpdfdemo'; + $this->Error('Please provide a certificate file and password!'); } if (strlen($private_key) == 0) { $private_key = $signing_cert; @@ -18211,6 +13491,7 @@ class TCPDF { $this->signature_data['extracerts'] = $extracerts; $this->signature_data['cert_type'] = $cert_type; $this->signature_data['info'] = $info; + $this->signature_data['approval'] = $approval; } /** @@ -18220,12 +13501,13 @@ class TCPDF { * @param $w (float) Width of the signature area. * @param $h (float) Height of the signature area. * @param $page (int) option page number (if < 0 the current page is used). + * @param $name (string) Name of the signature. * @public * @author Nicola Asuni * @since 5.3.011 (2010-06-17) */ - public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) { - $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page); + public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') { + $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name); } /** @@ -18235,13 +13517,14 @@ class TCPDF { * @param $w (float) Width of the signature area. * @param $h (float) Height of the signature area. * @param $page (int) option page number (if < 0 the current page is used). + * @param $name (string) Name of the signature. * @public * @author Nicola Asuni * @since 5.9.101 (2011-07-06) */ - public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) { + public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') { ++$this->n; - $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page); + $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name); } /** @@ -18251,18 +13534,24 @@ class TCPDF { * @param $w (float) Width of the signature area. * @param $h (float) Height of the signature area. * @param $page (int) option page number (if < 0 the current page is used). + * @param $name (string) Name of the signature. * @return (array) Array defining page and rectangle coordinates of signature appearance. * @protected * @author Nicola Asuni * @since 5.9.101 (2011-07-06) */ - protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1) { + protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') { $sigapp = array(); - if (($page < 1) or ($page > $this->numpages)) { + if (($page < 1) OR ($page > $this->numpages)) { $sigapp['page'] = $this->page; } else { $sigapp['page'] = intval($page); } + if (empty($name)) { + $sigapp['name'] = 'Signature'; + } else { + $sigapp['name'] = $name; + } $a = $x * $this->k; $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k); $c = $w * $this->k; @@ -18271,6 +13560,54 @@ class TCPDF { return $sigapp; } + /** + * Enable document timestamping (requires the OpenSSL Library). + * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded. + * Use with digital signature only! + * @param $tsa_host (string) Time Stamping Authority (TSA) server (prefixed with 'https://') + * @param $tsa_username (string) Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional) + * @param $tsa_password (string) Specifies the password for TSA authorization (optional) + * @param $tsa_cert (string) Specifies the location of TSA certificate for authorization (optional for cURL) + * @public + * @author Richard Stockinger + * @since 6.0.090 (2014-06-16) + */ + public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') { + $this->tsa_data = array(); + if (!function_exists('curl_init')) { + $this->Error('Please enable cURL PHP extension!'); + } + if (strlen($tsa_host) == 0) { + $this->Error('Please specify the host of Time Stamping Authority (TSA)!'); + } + $this->tsa_data['tsa_host'] = $tsa_host; + if (is_file($tsa_username)) { + $this->tsa_data['tsa_auth'] = $tsa_username; + } else { + $this->tsa_data['tsa_username'] = $tsa_username; + } + $this->tsa_data['tsa_password'] = $tsa_password; + $this->tsa_data['tsa_cert'] = $tsa_cert; + $this->tsa_timestamp = true; + } + + /** + * NOT YET IMPLEMENTED + * Request TSA for a timestamp + * @param $signature (string) Digital signature as binary string + * @return (string) Timestamped digital signature + * @protected + * @author Richard Stockinger + * @since 6.0.090 (2014-06-16) + */ + protected function applyTSA($signature) { + if (!$this->tsa_timestamp) { + return $signature; + } + //@TODO: implement this feature + return $signature; + } + /** * Create a new page group. * NOTE: call this function before calling AddPage() @@ -18285,24 +13622,6 @@ class TCPDF { $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1; } - /** - * This method is DEPRECATED and doesn't have any effect. - * Please remove any reference to this method. - * @param $s (string) Empty parameter. - * @deprecated deprecated since version 5.9.089 (2011-06-13) - * @public - */ - public function AliasNbPages($s='') {} - - /** - * This method is DEPRECATED and doesn't have any effect. - * Please remove any reference to this method. - * @param $s (string) Empty parameter. - * @deprecated deprecated since version 5.9.089 (2011-06-13) - * @public - */ - public function AliasNumPage($s='') {} - /** * Set the starting page number. * @param $num (int) Starting page number. @@ -18322,11 +13641,16 @@ class TCPDF { */ public function getAliasRightShift() { // calculate aproximatively the ratio between widths of aliases and replacements. - $ref = '{'.$this->alias_right_shift.'}{'.$this->alias_tot_pages.'}{'.$this->alias_num_page.'}'; + $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}'; $rep = str_repeat(' ', $this->GetNumChars($ref)); - $wdiff = max(1, ($this->GetStringWidth($ref) / $this->GetStringWidth($rep))); + $wrep = $this->GetStringWidth($rep); + if ($wrep > 0) { + $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep)); + } else { + $wdiff = 1; + } $sdiff = sprintf('%F', $wdiff); - $alias = $this->alias_right_shift.$sdiff.'}'; + $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}'; if ($this->isUnicodeFont()) { $alias = '{'.$alias; } @@ -18343,9 +13667,9 @@ class TCPDF { */ public function getAliasNbPages() { if ($this->isUnicodeFont()) { - return '{'.$this->alias_tot_pages.'}'; + return '{'.TCPDF_STATIC::$alias_tot_pages.'}'; } - return $this->alias_tot_pages; + return TCPDF_STATIC::$alias_tot_pages; } /** @@ -18358,9 +13682,9 @@ class TCPDF { */ public function getAliasNumPage() { if ($this->isUnicodeFont()) { - return '{'.$this->alias_num_page.'}'; + return '{'.TCPDF_STATIC::$alias_num_page.'}'; } - return $this->alias_num_page; + return TCPDF_STATIC::$alias_num_page; } /** @@ -18373,9 +13697,9 @@ class TCPDF { */ public function getPageGroupAlias() { if ($this->isUnicodeFont()) { - return '{'.$this->alias_group_tot_pages.'}'; + return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}'; } - return $this->alias_group_tot_pages; + return TCPDF_STATIC::$alias_group_tot_pages; } /** @@ -18388,9 +13712,9 @@ class TCPDF { */ public function getPageNumGroupAlias() { if ($this->isUnicodeFont()) { - return '{'.$this->alias_group_num_page.'}'; + return '{'.TCPDF_STATIC::$alias_group_num_page.'}'; } - return $this->alias_group_num_page; + return TCPDF_STATIC::$alias_group_num_page; } /** @@ -18410,30 +13734,7 @@ class TCPDF { * @see PaneNo(), formatPageNumber() */ public function getGroupPageNoFormatted() { - return $this->formatPageNumber($this->getGroupPageNo()); - } - - /** - * Format the page numbers. - * This method can be overriden for custom formats. - * @param $num (int) page number - * @protected - * @since 4.2.005 (2008-11-06) - */ - protected function formatPageNumber($num) { - return number_format((float)$num, 0, '', '.'); - } - - /** - * Format the page numbers on the Table Of Content. - * This method can be overriden for custom formats. - * @param $num (int) page number - * @protected - * @since 4.5.001 (2009-01-04) - * @see addTOC(), addHTMLTOC() - */ - protected function formatTOCPageNumber($num) { - return number_format((float)$num, 0, '', '.'); + return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo()); } /** @@ -18443,7 +13744,7 @@ class TCPDF { * @see PaneNo(), formatPageNumber() */ public function PageNoFormatted() { - return $this->formatPageNumber($this->PageNo()); + return TCPDF_STATIC::formatPageNumber($this->PageNo()); } /** @@ -18460,7 +13761,9 @@ class TCPDF { $out = '<< /Type /OCG'; $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']); $out .= ' /Usage <<'; - $out .= ' /Print <>'; + if (isset($layer['print']) AND ($layer['print'] !== NULL)) { + $out .= ' /Print <>'; + } $out .= ' /View <>'; $out .= ' >> >>'; $out .= "\n".'endobj'; @@ -18471,19 +13774,23 @@ class TCPDF { /** * Start a new pdf layer. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name. - * @param $print (boolean) Set to true to print this layer. + * @param $print (boolean|null) Set to TRUE to print this layer, FALSE to not print and NULL to not set this option * @param $view (boolean) Set to true to view this layer. + * @param $lock (boolean) If true lock the layer * @public * @since 5.9.102 (2011-07-13) */ - public function startLayer($name='', $print=true, $view=true) { + public function startLayer($name='', $print=true, $view=true, $lock=true) { + if ($this->state != 2) { + return; + } $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1)); if (empty($name)) { $name = $layer; } else { $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name); } - $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view); + $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock); $this->openMarkedContent = true; $this->_out('/OC /'.$layer.' BDC'); } @@ -18494,6 +13801,9 @@ class TCPDF { * @since 5.9.102 (2011-07-13) */ public function endLayer() { + if ($this->state != 2) { + return; + } if ($this->openMarkedContent) { // close existing open marked-content layer $this->_out('EMC'); @@ -18510,6 +13820,9 @@ class TCPDF { * @since 3.0.000 (2008-03-27) */ public function setVisibility($v) { + if ($this->state != 2) { + return; + } $this->endLayer(); switch($v) { case 'print': { @@ -18571,7 +13884,7 @@ class TCPDF { * @since 3.0.000 (2008-03-27) */ protected function setExtGState($gs) { - if ($this->pdfa_mode) { + if ($this->pdfa_mode OR ($this->state != 2)) { // transparency is not allowed in PDF/A mode return; } @@ -18613,14 +13926,17 @@ class TCPDF { * @since 5.9.152 (2012-03-23) */ public function setOverprint($stroking=true, $nonstroking='', $mode=0) { + if ($this->state != 2) { + return; + } $stroking = $stroking ? true : false; - if ($this->empty_string($nonstroking)) { + if (TCPDF_STATIC::empty_string($nonstroking)) { // default value if not set $nonstroking = $stroking; } else { $nonstroking = $nonstroking ? true : false; } - if (($mode != 0) and ($mode != 1)) { + if (($mode != 0) AND ($mode != 1)) { $mode = 0; } $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode); @@ -18654,7 +13970,7 @@ class TCPDF { return; } $stroking = floatval($stroking); - if ($this->empty_string($nonstroking)) { + if (TCPDF_STATIC::empty_string($nonstroking)) { // default value if not set $nonstroking = $stroking; } else { @@ -18691,7 +14007,7 @@ class TCPDF { * @since 3.0.000 (2008-03-27) */ public function setJPEGQuality($quality) { - if (($quality < 1) or ($quality > 100)) { + if (($quality < 1) OR ($quality > 100)) { $quality = 75; } $this->jpeg_quality = intval($quality); @@ -18733,7 +14049,7 @@ class TCPDF { * @since 3.1.000 (2008-06-09) */ public function setPDFVersion($version='1.7') { - if ($this->pdfa_mode) { + if ($this->pdfa_mode && $this->pdfa_version == 1 ) { // PDF/A mode $this->PDFVersion = '1.4'; } else { @@ -18762,14 +14078,30 @@ class TCPDF { * @param $h (float) height of the rectangle. * @param $transition (boolean) if true prints tcolor transitions to white. * @param $vertical (boolean) if true prints bar vertically. - * @param $colors (string) colors to print, one letter per color separated by comma (for example 'A,W,R,G,B,C,M,Y,K'): A=black, W=white, R=red, G=green, B=blue, C=cyan, M=magenta, Y=yellow, K=black. + * @param $colors (string) colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, = name of the spot color to print. * @author Nicola Asuni * @since 4.9.000 (2010-03-26) * @public */ public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') { + if (strpos($colors, 'ALLSPOT') !== false) { + // expand spot colors + $spot_colors = ''; + foreach ($this->spot_colors as $spot_color_name => $v) { + $spot_colors .= ','.$spot_color_name; + } + if (!empty($spot_colors)) { + $spot_colors = substr($spot_colors, 1); + $colors = str_replace('ALLSPOT', $spot_colors, $colors); + } else { + $colors = str_replace('ALLSPOT', 'NONE', $colors); + } + } $bars = explode(',', $colors); $numbars = count($bars); // number of bars to print + if ($numbars <= 0) { + return; + } // set bar measures if ($vertical) { $coords = array(0, 0, 0, 1); @@ -18789,67 +14121,93 @@ class TCPDF { foreach ($bars as $col) { switch ($col) { // set transition colors - case 'A': { // BLACK + case 'A': { // BLACK (GRAYSCALE) $col_a = array(255); $col_b = array(0); break; } - case 'W': { // WHITE + case 'W': { // WHITE (GRAYSCALE) $col_a = array(0); $col_b = array(255); break; } - case 'R': { // R + case 'R': { // RED (RGB) $col_a = array(255,255,255); $col_b = array(255,0,0); break; } - case 'G': { // G + case 'G': { // GREEN (RGB) $col_a = array(255,255,255); $col_b = array(0,255,0); break; } - case 'B': { // B + case 'B': { // BLUE (RGB) $col_a = array(255,255,255); $col_b = array(0,0,255); break; } - case 'C': { // C + case 'C': { // CYAN (CMYK) $col_a = array(0,0,0,0); $col_b = array(100,0,0,0); break; } - case 'M': { // M + case 'M': { // MAGENTA (CMYK) $col_a = array(0,0,0,0); $col_b = array(0,100,0,0); break; } - case 'Y': { // Y + case 'Y': { // YELLOW (CMYK) $col_a = array(0,0,0,0); $col_b = array(0,0,100,0); break; } - case 'K': { // K + case 'K': { // KEY - BLACK (CMYK) $col_a = array(0,0,0,0); $col_b = array(0,0,0,100); break; } - default: { // GRAY - $col_a = array(255); - $col_b = array(0); + case 'RGB': { // BLACK REGISTRATION (RGB) + $col_a = array(255,255,255); + $col_b = array(0,0,0); + break; + } + case 'CMYK': { // BLACK REGISTRATION (CMYK) + $col_a = array(0,0,0,0); + $col_b = array(100,100,100,100); + break; + } + case 'ALL': { // SPOT COLOR REGISTRATION + $col_a = array(0,0,0,0,'None'); + $col_b = array(100,100,100,100,'All'); + break; + } + case 'NONE': { // SKIP THIS COLOR + $col_a = array(0,0,0,0,'None'); + $col_b = array(0,0,0,0,'None'); + break; + } + default: { // SPECIFIC SPOT COLOR NAME + $col_a = array(0,0,0,0,'None'); + $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors); + if ($col_b === false) { + // in case of error defaults to the registration color + $col_b = array(100,100,100,100,'All'); + } break; } } - if ($transition) { - // color gradient - $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords); - } else { - // color rectangle - $this->SetFillColorArray($col_b); - $this->Rect($xb, $yb, $wb, $hb, 'F', array()); + if ($col != 'NONE') { + if ($transition) { + // color gradient + $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords); + } else { + $this->SetFillColorArray($col_b); + // colored rectangle + $this->Rect($xb, $yb, $wb, $hb, 'F', array()); + } + $xb += $xd; + $yb += $yd; } - $xb += $xd; - $yb += $yd; } } @@ -18860,12 +14218,12 @@ class TCPDF { * @param $w (float) width of the crop mark. * @param $h (float) height of the crop mark. * @param $type (string) type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT. - * @param $color (array) crop mark color (default black). + * @param $color (array) crop mark color (default spot registration color). * @author Nicola Asuni * @since 4.9.000 (2010-03-26) * @public */ - public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(0,0,0)) { + public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) { $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color)); $type = strtoupper($type); $type = preg_replace('/[^A-Z\-\,]*/', '', $type); @@ -18930,30 +14288,70 @@ class TCPDF { * @param $y (float) ordinate of the registration mark center. * @param $r (float) radius of the crop mark. * @param $double (boolean) if true print two concentric crop marks. - * @param $cola (array) crop mark color (default black). - * @param $colb (array) second crop mark color. + * @param $cola (array) crop mark color (default spot registration color 'All'). + * @param $colb (array) second crop mark color (default spot registration color 'None'). * @author Nicola Asuni * @since 4.9.000 (2010-03-26) * @public */ - public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) { - $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola); + public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) { + $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola); $this->SetFillColorArray($cola); $this->PieSector($x, $y, $r, 90, 180, 'F'); $this->PieSector($x, $y, $r, 270, 360, 'F'); $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8); if ($double) { - $r2 = $r * 0.5; + $ri = $r * 0.5; $this->SetFillColorArray($colb); - $this->PieSector($x, $y, $r2, 90, 180, 'F'); - $this->PieSector($x, $y, $r2, 270, 360, 'F'); + $this->PieSector($x, $y, $ri, 90, 180, 'F'); + $this->PieSector($x, $y, $ri, 270, 360, 'F'); $this->SetFillColorArray($cola); - $this->PieSector($x, $y, $r2, 0, 90, 'F'); - $this->PieSector($x, $y, $r2, 180, 270, 'F'); - $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8); + $this->PieSector($x, $y, $ri, 0, 90, 'F'); + $this->PieSector($x, $y, $ri, 180, 270, 'F'); + $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8); } } + /** + * Paints a CMYK registration mark + * @param $x (float) abscissa of the registration mark center. + * @param $y (float) ordinate of the registration mark center. + * @param $r (float) radius of the crop mark. + * @author Nicola Asuni + * @since 6.0.038 (2013-09-30) + * @public + */ + public function registrationMarkCMYK($x, $y, $r) { + // line width + $lw = max((0.5 / $this->k),($r / 8)); + // internal radius + $ri = ($r * 0.6); + // external radius + $re = ($r * 1.3); + // Cyan + $this->SetFillColorArray(array(100,0,0,0)); + $this->PieSector($x, $y, $ri, 270, 360, 'F'); + // Magenta + $this->SetFillColorArray(array(0,100,0,0)); + $this->PieSector($x, $y, $ri, 0, 90, 'F'); + // Yellow + $this->SetFillColorArray(array(0,0,100,0)); + $this->PieSector($x, $y, $ri, 90, 180, 'F'); + // Key - black + $this->SetFillColorArray(array(0,0,0,100)); + $this->PieSector($x, $y, $ri, 180, 270, 'F'); + // registration color + $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All')); + $this->SetFillColorArray(array(100,100,100,100,'All')); + // external circle + $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8); + // cross lines + $this->Line($x, ($y - $re), $x, ($y - $ri)); + $this->Line($x, ($y + $ri), $x, ($y + $re)); + $this->Line(($x - $re), $y, ($x - $ri), $y); + $this->Line(($x + $ri), $y, ($x + $re), $y); + } + /** * Paints a linear colour gradient. * @param $x (float) abscissa of the top left corner of the rectangle. @@ -18963,7 +14361,7 @@ class TCPDF { * @param $col1 (array) first color (Grayscale, RGB or CMYK components). * @param $col2 (array) second color (Grayscale, RGB or CMYK components). * @param $coords (array) array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0). - * @author Andreas W�rmser, Nicola Asuni + * @author Andreas W\FCrmser, Nicola Asuni * @since 3.1.000 (2008-06-09) * @public */ @@ -18981,7 +14379,7 @@ class TCPDF { * @param $col1 (array) first color (Grayscale, RGB or CMYK components). * @param $col2 (array) second color (Grayscale, RGB or CMYK components). * @param $coords (array) array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined. - * @author Andreas W�rmser, Nicola Asuni + * @author Andreas W\FCrmser, Nicola Asuni * @since 3.1.000 (2008-06-09) * @public */ @@ -19004,12 +14402,12 @@ class TCPDF { * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0 * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1 * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts. - * @author Andreas W�rmser, Nicola Asuni + * @author Andreas W\FCrmser, Nicola Asuni * @since 3.1.000 (2008-06-09) * @public */ public function CoonsPatchMesh($x, $y, $w, $h, $col1=array(), $col2=array(), $col3=array(), $col4=array(), $coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33), $coords_min=0, $coords_max=1, $antialias=false) { - if ($this->pdfa_mode) { + if ($this->pdfa_mode OR ($this->state != 2)) { return; } $this->Clip($x, $y, $w, $h); @@ -19083,7 +14481,7 @@ class TCPDF { //paint the gradient $this->_out('/Sh'.$n.' sh'); //restore previous Graphic State - $this->_out('Q'); + $this->_outRestoreGraphicsState(); if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n]; @@ -19096,11 +14494,14 @@ class TCPDF { * @param $y (float) ordinate of the top left corner of the rectangle. * @param $w (float) width of the rectangle. * @param $h (float) height of the rectangle. - * @author Andreas W�rmser, Nicola Asuni + * @author Andreas W\FCrmser, Nicola Asuni * @since 3.1.000 (2008-06-09) * @protected */ protected function Clip($x, $y, $w, $h) { + if ($this->state != 2) { + return; + } if ($this->rtl) { $x = $this->w - $x - $w; } @@ -19125,7 +14526,7 @@ class TCPDF { * @public */ public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) { - if ($this->pdfa_mode) { + if ($this->pdfa_mode OR ($this->state != 2)) { return; } $n = count($this->gradients) + 1; @@ -19139,6 +14540,7 @@ class TCPDF { $numcolspace = count($stops[0]['color']); $bcolor = array_values($background); switch($numcolspace) { + case 5: // SPOT case 4: { // CMYK $this->gradients[$n]['colspace'] = 'DeviceCMYK'; if (!empty($background)) { @@ -19153,7 +14555,7 @@ class TCPDF { } break; } - case 1: { // Gray scale + case 1: { // GRAY SCALE $this->gradients[$n]['colspace'] = 'DeviceGray'; if (!empty($background)) { $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255); @@ -19180,7 +14582,7 @@ class TCPDF { } if (isset($stop['opacity'])) { $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity']; - if ((!$this->pdfa_mode) and ($stop['opacity'] < 1)) { + if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) { $this->gradients[$n]['transparency'] = true; } } else { @@ -19195,6 +14597,7 @@ class TCPDF { // set colors $color = array_values($stop['color']); switch($numcolspace) { + case 5: // SPOT case 4: { // CMYK $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100); break; @@ -19203,7 +14606,7 @@ class TCPDF { $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255); break; } - case 1: { // Gray scale + case 1: { // GRAY SCALE $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255); break; } @@ -19216,7 +14619,7 @@ class TCPDF { //paint the gradient $this->_out('/Sh'.$n.' sh'); //restore previous Graphic State - $this->_out('Q'); + $this->_outRestoreGraphicsState(); if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n]; @@ -19235,7 +14638,7 @@ class TCPDF { } $idt = count($this->gradients); //index for transparency gradients foreach ($this->gradients as $id => $grad) { - if (($grad['type'] == 2) or ($grad['type'] == 3)) { + if (($grad['type'] == 2) OR ($grad['type'] == 3)) { $fc = $this->_newobj(); $out = '<<'; $out .= ' /FunctionType 3'; @@ -19271,7 +14674,7 @@ class TCPDF { $out .= "\n".'endobj'; $this->_out($out); } - // set transparency fuctions + // set transparency functions if ($grad['transparency']) { $ft = $this->_newobj(); $out = '<<'; @@ -19311,10 +14714,10 @@ class TCPDF { } else { $out .= ' /ColorSpace /DeviceRGB'; } - if (isset($grad['background']) and !empty($grad['background'])) { + if (isset($grad['background']) AND !empty($grad['background'])) { $out .= ' /Background ['.$grad['background'].']'; } - if (isset($grad['antialias']) and ($grad['antialias'] === true)) { + if (isset($grad['antialias']) AND ($grad['antialias'] === true)) { $out .= ' /AntiAlias true'; } if ($grad['type'] == 2) { @@ -19443,10 +14846,13 @@ class TCPDF { * @public */ public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) { + if ($this->state != 2) { + return; + } if ($this->rtl) { $xc = ($this->w - $xc); } - $op = $this->getPathPaintOperator($style); + $op = TCPDF_STATIC::getPathPaintOperator($style); if ($op == 'f') { $line_style = array(); } @@ -19484,7 +14890,10 @@ class TCPDF { * @public */ public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) { - if ($this->rasterize_vector_images and ($w > 0) and ($h > 0)) { + if ($this->state != 2) { + return; + } + if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) { // convert EPS to raster image using GD or ImageMagick libraries return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage); } @@ -19497,12 +14906,12 @@ class TCPDF { // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); $k = $this->k; - if ($file{0} === '@') { // image from string + if ($file[0] === '@') { // image from string $data = substr($file, 1); } else { // EPS/AI file - $data = file_get_contents($file); + $data = TCPDF_STATIC::fileGetContents($file); } - if ($data === false) { + if ($data === FALSE) { $this->Error('EPS file not found: '.$file); } $regs = array(); @@ -19546,7 +14955,7 @@ class TCPDF { $data = substr($data, 0, $end); } // calculate image width and height on document - if (($w <= 0) and ($h <= 0)) { + if (($w <= 0) AND ($h <= 0)) { $w = ($x2 - $x1) / $k; $h = ($y2 - $y1) / $k; } elseif ($w <= 0) { @@ -19610,7 +15019,7 @@ class TCPDF { $cnt = count($lines); for ($i=0; $i < $cnt; ++$i) { $line = $lines[$i]; - if (($line == '') or ($line{0} == '%')) { + if (($line == '') OR ($line[0] == '%')) { continue; } $len = strlen($line); @@ -19629,7 +15038,7 @@ class TCPDF { $chunks = explode(' ', $line); $cmd = trim(array_pop($chunks)); // RGB - if (($cmd == 'Xa') or ($cmd == 'XA')) { + if (($cmd == 'Xa') OR ($cmd == 'XA')) { $b = array_pop($chunks); $g = array_pop($chunks); $r = array_pop($chunks); @@ -19645,9 +15054,9 @@ class TCPDF { case 'L': { // skip values outside bounding box foreach ($chunks as $key => $val) { - if ((($key % 2) == 0) and (($val < $x1) or ($val > $x2))) { + if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) { $skip = true; - } elseif ((($key % 2) != 0) and (($val < $y1) or ($val > $y2))) { + } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) { $skip = true; } } @@ -19729,7 +15138,7 @@ class TCPDF { $isU = false; $max = min(($i + 5), $cnt); for ($j = ($i + 1); $j < $max; ++$j) { - $isU = ($isU or (($lines[$j] == 'U') or ($lines[$j] == '*U'))); + $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U'))); } if ($isU) { $this->_out('f*'); @@ -19816,7 +15225,7 @@ class TCPDF { /** * Print a Linear Barcode. * @param $code (string) code to print - * @param $type (string) type of barcode (see barcodes.php for supported formats). + * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats). * @param $x (int) x position in user units (empty string = current x position) * @param $y (int) y position in user units (empty string = current y position) * @param $w (int) width in user units (empty string = remaining page width) @@ -19843,19 +15252,22 @@ class TCPDF { * @since 3.1.000 (2008-06-09) * @public */ - public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') { - if ($this->empty_string(trim($code))) { + public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style=array(), $align='') { + if (TCPDF_STATIC::empty_string(trim($code))) { return; } - require_once(dirname(__FILE__).'/barcodes.php'); + require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php'); // save current graphic settings $gvars = $this->getGraphicVars(); // create new barcode object $barcodeobj = new TCPDFBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) or empty($arrcode) or ($arrcode['maxw'] == 0)) { + if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) { $this->Error('Error in 1D barcode string'); } + if ($arrcode['maxh'] <= 0) { + $arrcode['maxh'] = 1; + } // set default values if (!isset($style['position'])) { $style['position'] = ''; @@ -19876,7 +15288,7 @@ class TCPDF { $style['stretch'] = false; } if (!isset($style['stretch'])) { - if (($w === '') or ($w <= 0)) { + if (($w === '') OR ($w <= 0)) { $style['stretch'] = false; } else { $style['stretch'] = true; @@ -19895,7 +15307,7 @@ class TCPDF { if (!isset($style['text'])) { $style['text'] = false; } - if ($style['text'] and isset($style['font'])) { + if ($style['text'] AND isset($style['font'])) { if (isset($style['fontsize'])) { $fontsize = $style['fontsize']; } @@ -19912,7 +15324,7 @@ class TCPDF { } // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); - if (($w === '') or ($w <= 0)) { + if (($w === '') OR ($w <= 0)) { if ($this->rtl) { $w = $x - $this->lMargin; } else { @@ -19948,17 +15360,17 @@ class TCPDF { if ($style['stretch']) { $xres = $max_xres; } else { - if ($this->empty_string($xres)) { + if (TCPDF_STATIC::empty_string($xres)) { $xres = (0.141 * $this->k); // default bar width = 0.4 mm } if ($xres > $max_xres) { // correct xres to fit on $w $xres = $max_xres; } - if ((isset($style['padding']) and ($style['padding'] === 'auto')) - or (isset($style['hpadding']) and ($style['hpadding'] === 'auto'))) { + if ((isset($style['padding']) AND ($style['padding'] === 'auto')) + OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) { $hpadding = 10 * $xres; - if (isset($style['vpadding']) and ($style['vpadding'] === 'auto')) { + if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) { $vpadding = ($hpadding / 2); } } @@ -19994,9 +15406,9 @@ class TCPDF { } } } - $text_height = ($this->cell_height_ratio * $fontsize / $this->k); + $text_height = $this->getCellHeight($fontsize / $this->k); // height - if (($h === '') or ($h <= 0)) { + if (($h === '') OR ($h <= 0)) { // set default height $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height; } @@ -20005,7 +15417,7 @@ class TCPDF { // try to reduce font or padding to fit barcode on available height if ($text_height > $h) { $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio)); - $text_height = ($this->cell_height_ratio * $fontsize / $this->k); + $text_height = $this->getCellHeight($fontsize / $this->k); $this->SetFont($style['font'], '', $fontsize); } if ($vpadding > 0) { @@ -20085,7 +15497,7 @@ class TCPDF { } // print text if ($style['text']) { - if (isset($style['label']) and !$this->empty_string($style['label'])) { + if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) { $label = $style['label']; } else { $label = $code; @@ -20134,65 +15546,10 @@ class TCPDF { $this->endlinex = $this->img_rb_x; } - /** - * This function is DEPRECATED, please use the new write1DBarcode() function. - * @param $x (int) x position in user units - * @param $y (int) y position in user units - * @param $w (int) width in user units - * @param $h (int) height position in user units - * @param $type (string) type of barcode - * @param $style (string) barcode style - * @param $font (string) font for text - * @param $xres (int) x resolution - * @param $code (string) code to print - * @deprecated deprecated since version 3.1.000 (2008-06-10) - * @public - * @see write1DBarcode() - */ - public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) { - // convert old settings for the new write1DBarcode() function. - $xres = 1 / $xres; - $newstyle = array( - 'position' => '', - 'align' => '', - 'stretch' => false, - 'fitwidth' => false, - 'cellfitalign' => '', - 'border' => false, - 'padding' => 0, - 'fgcolor' => array(0,0,0), - 'bgcolor' => false, - 'text' => true, - 'font' => $font, - 'fontsize' => 8, - 'stretchtext' => 4 - ); - if ($style & 1) { - $newstyle['border'] = true; - } - if ($style & 2) { - $newstyle['bgcolor'] = false; - } - if ($style & 4) { - $newstyle['position'] = 'C'; - } elseif ($style & 8) { - $newstyle['position'] = 'L'; - } elseif ($style & 16) { - $newstyle['position'] = 'R'; - } - if ($style & 128) { - $newstyle['text'] = true; - } - if ($style & 256) { - $newstyle['stretchtext'] = 4; - } - $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, ''); - } - /** * Print 2D Barcode. * @param $code (string) code to print - * @param $type (string) type of barcode (see 2dbarcodes.php for supported formats). + * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats). * @param $x (int) x position in user units * @param $y (int) y position in user units * @param $w (int) width in user units @@ -20206,25 +15563,24 @@ class TCPDF { *
  • int $style['module_height'] height of a single module in points
  • *
  • array $style['fgcolor'] color array for bars and text
  • *
  • mixed $style['bgcolor'] color array for background or false for transparent
  • - *
  • string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch
  • $style['module_width'] width of a single module in points
  • - *
  • $style['module_height'] height of a single module in points
  • + *
  • string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch
  • * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:
    • T: top-right for LTR or top-left for RTL
    • M: middle-right for LTR or middle-left for RTL
    • B: bottom-right for LTR or bottom-left for RTL
    • N: next line
    * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio * @author Nicola Asuni * @since 4.5.037 (2009-04-07) * @public */ - public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) { - if ($this->empty_string(trim($code))) { + public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style=array(), $align='', $distort=false) { + if (TCPDF_STATIC::empty_string(trim($code))) { return; } - require_once(dirname(__FILE__).'/2dbarcodes.php'); + require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php'); // save current graphic settings $gvars = $this->getGraphicVars(); // create new barcode object $barcodeobj = new TCPDF2DBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); - if (($arrcode === false) or empty($arrcode) or !isset($arrcode['num_rows']) or ($arrcode['num_rows'] == 0) or !isset($arrcode['num_cols']) or ($arrcode['num_cols'] == 0)) { + if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) { $this->Error('Error in 2D barcode string'); } // set default values @@ -20276,10 +15632,13 @@ class TCPDF { // number of barcode columns and rows $rows = $arrcode['num_rows']; $cols = $arrcode['num_cols']; + if (($rows <= 0) || ($cols <= 0)){ + $this->Error('Error in 2D barcode string'); + } // module width and height $mw = $style['module_width']; $mh = $style['module_height']; - if (($mw == 0) or ($mh == 0)) { + if (($mw <= 0) OR ($mh <= 0)) { $this->Error('Error in 2D barcode string'); } // get max dimensions @@ -20299,7 +15658,7 @@ class TCPDF { $maxh = $maxw * $ratioHW; } } - // set maximum dimesions + // set maximum dimensions if ($w > $maxw) { $w = $maxw; } @@ -20307,12 +15666,12 @@ class TCPDF { $h = $maxh; } // set dimensions - if ((($w === '') or ($w <= 0)) and (($h === '') or ($h <= 0))) { + if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) { $w = ($cols + $hpad) * ($mw / $this->k); $h = ($rows + $vpad) * ($mh / $this->k); - } elseif (($w === '') or ($w <= 0)) { + } elseif (($w === '') OR ($w <= 0)) { $w = $h * $ratioWH; - } elseif (($h === '') or ($h <= 0)) { + } elseif (($h === '') OR ($h <= 0)) { $h = $w * $ratioHW; } // barcode size (excluding padding) @@ -20528,389 +15887,7 @@ class TCPDF { * @see setHtmlVSpace() */ public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') { - // configure parameters for HTML Tidy - if ($tidy_options === '') { - $tidy_options = array( - 'clean' => 1, - 'drop-empty-paras' => 0, - 'drop-proprietary-attributes' => 1, - 'fix-backslash' => 1, - 'hide-comments' => 1, - 'join-styles' => 1, - 'lower-literals' => 1, - 'merge-divs' => 1, - 'merge-spans' => 1, - 'output-xhtml' => 1, - 'word-2000' => 1, - 'wrap' => 0, - 'output-bom' => 0, - //'char-encoding' => 'utf8', - //'input-encoding' => 'utf8', - //'output-encoding' => 'utf8' - ); - } - // clean up the HTML code - $tidy = tidy_parse_string($html, $tidy_options); - // fix the HTML - $tidy->cleanRepair(); - // get the CSS part - $tidy_head = tidy_get_head($tidy); - $css = $tidy_head->value; - $css = preg_replace('/]+)>/ims', ''; - // get the body part - $tidy_body = tidy_get_body($tidy); - $html = $tidy_body->value; - // fix some self-closing tags - $html = str_replace('
    ', '
    ', $html); - // remove some empty tag blocks - $html = preg_replace('/]*)><\/div>/', '', $html); - $html = preg_replace('/]*)><\/p>/', '', $html); - if ($tagvs !== '') { - // set vertical space for some XHTML tags - $this->setHtmlVSpace($tagvs); - } - // return the cleaned XHTML code + CSS - return $css.$html; - } - - /** - * Extracts the CSS properties from a CSS string. - * @param $cssdata (string) string containing CSS definitions. - * @return An array where the keys are the CSS selectors and the values are the CSS properties. - * @author Nicola Asuni - * @since 5.1.000 (2010-05-25) - * @protected - */ - protected function extractCSSproperties($cssdata) { - if (empty($cssdata)) { - return array(); - } - // remove comments - $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata); - // remove newlines and multiple spaces - $cssdata = preg_replace('/[\s]+/', ' ', $cssdata); - // remove some spaces - $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata); - // remove empty blocks - $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata); - // replace media type parenthesis - $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1�', $cssdata); - $cssdata = preg_replace('/\}\}/si', '}�', $cssdata); - // trim string - $cssdata = trim($cssdata); - // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv) - $cssblocks = array(); - $matches = array(); - if (preg_match_all('/@media[\s]+([^\�]*)�([^�]*)�/i', $cssdata, $matches) > 0) { - foreach ($matches[1] as $key => $type) { - $cssblocks[$type] = $matches[2][$key]; - } - // remove media blocks - $cssdata = preg_replace('/@media[\s]+([^\�]*)�([^�]*)�/i', '', $cssdata); - } - // keep 'all' and 'print' media, other media types are discarded - if (isset($cssblocks['all']) and !empty($cssblocks['all'])) { - $cssdata .= $cssblocks['all']; - } - if (isset($cssblocks['print']) and !empty($cssblocks['print'])) { - $cssdata .= $cssblocks['print']; - } - // reset css blocks array - $cssblocks = array(); - $matches = array(); - // explode css data string into array - if (substr($cssdata, -1) == '}') { - // remove last parethesis - $cssdata = substr($cssdata, 0, -1); - } - $matches = explode('}', $cssdata); - foreach ($matches as $key => $block) { - // index 0 contains the CSS selector, index 1 contains CSS properties - $cssblocks[$key] = explode('{', $block); - if (!isset($cssblocks[$key][1])) { - // remove empty definitions - unset($cssblocks[$key]); - } - } - // split groups of selectors (comma-separated list of selectors) - foreach ($cssblocks as $key => $block) { - if (strpos($block[0], ',') > 0) { - $selectors = explode(',', $block[0]); - foreach ($selectors as $sel) { - $cssblocks[] = array(0 => trim($sel), 1 => $block[1]); - } - unset($cssblocks[$key]); - } - } - // covert array to selector => properties - $cssdata = array(); - foreach ($cssblocks as $block) { - $selector = $block[0]; - // calculate selector's specificity - $matches = array(); - $a = 0; // the declaration is not from is a 'style' attribute - $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('/[\:]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('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements - $specificity = $a.$b.$c.$d; - // add specificity to the beginning of the selector - $cssdata[$specificity.' '.$selector] = $block[1]; - } - // sort selectors alphabetically to account for specificity - ksort($cssdata, SORT_STRING); - // return array - return $cssdata; - } - - /** - * Returns true if the CSS selector is valid for the selected HTML tag - * @param $dom (array) array of HTML tags and properties - * @param $key (int) key of the current HTML tag - * @param $selector (string) CSS selector string - * @return true if the selector is valid, false otherwise - * @protected - * @since 5.1.000 (2010-05-25) - */ - protected function isValidCSSSelectorForTag($dom, $key, $selector) { - $valid = false; // value to be returned - $tag = $dom[$key]['value']; - $class = array(); - if (isset($dom[$key]['attribute']['class']) and !empty($dom[$key]['attribute']['class'])) { - $class = explode(' ', strtolower($dom[$key]['attribute']['class'])); - } - $id = ''; - if (isset($dom[$key]['attribute']['id']) and !empty($dom[$key]['attribute']['id'])) { - $id = strtolower($dom[$key]['attribute']['id']); - } - $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector); - $matches = array(); - 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]); - $operator = $parentop[0]; - $offset = $parentop[1]; - $lasttag = array_pop($matches[2]); - $lasttag = strtolower(trim($lasttag[0])); - if (($lasttag == '*') or ($lasttag == $tag)) { - // the last element on selector is our tag or 'any tag' - $attrib = array_pop($matches[3]); - $attrib = strtolower(trim($attrib[0])); - if (!empty($attrib)) { - // check if matches class, id, attribute, pseudo-class or pseudo-element - switch ($attrib{0}) { - case '.': { // class - if (in_array(substr($attrib, 1), $class)) { - $valid = true; - } - break; - } - case '#': { // ID - if (substr($attrib, 1) == $id) { - $valid = true; - } - break; - } - case '[': { // attribute - $attrmatch = array(); - if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) { - $att = strtolower($attrmatch[1]); - $val = $attrmatch[3]; - if (isset($dom[$key]['attribute'][$att])) { - switch ($attrmatch[2]) { - case '=': { - if ($dom[$key]['attribute'][$att] == $val) { - $valid = true; - } - break; - } - case '~=': { - if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) { - $valid = true; - } - break; - } - case '^=': { - if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) { - $valid = true; - } - break; - } - case '$=': { - if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) { - $valid = true; - } - break; - } - case '*=': { - if (strpos($dom[$key]['attribute'][$att], $val) !== false) { - $valid = true; - } - break; - } - case '|=': { - if ($dom[$key]['attribute'][$att] == $val) { - $valid = true; - } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) { - $valid = true; - } - break; - } - default: { - $valid = true; - } - } - } - } - break; - } - case ':': { // pseudo-class or pseudo-element - if ($attrib{1} == ':') { // pseudo-element - // pseudo-elements are not supported! - // (::first-line, ::first-letter, ::before, ::after) - } else { // pseudo-class - // pseudo-classes are not supported! - // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked) - } - break; - } - } // end of switch - } else { - $valid = true; - } - if ($valid and ($offset > 0)) { - $valid = false; - // check remaining selector part - $selector = substr($selector, 0, $offset); - switch ($operator) { - case ' ': { // descendant of an element - while ($dom[$key]['parent'] > 0) { - if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) { - $valid = true; - break; - } else { - $key = $dom[$key]['parent']; - } - } - break; - } - case '>': { // child of an element - $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector); - break; - } - case '+': { // immediately preceded by an element - for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { - if ($dom[$i]['tag'] and $dom[$i]['opening']) { - $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector); - break; - } - } - break; - } - case '~': { // preceded by an element - for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { - if ($dom[$i]['tag'] and $dom[$i]['opening']) { - if ($this->isValidCSSSelectorForTag($dom, $i, $selector)) { - break; - } - } - } - break; - } - } - } - } - } - return $valid; - } - - /** - * Returns the styles array that apply for the selected HTML tag. - * @param $dom (array) array of HTML tags and properties - * @param $key (int) key of the current HTML tag - * @param $css (array) array of CSS properties - * @return array containing CSS properties - * @protected - * @since 5.1.000 (2010-05-25) - */ - protected function getCSSdataArray($dom, $key, $css) { - $cssarray = array(); // style to be returned - // get parent CSS selectors - $selectors = array(); - if (isset($dom[($dom[$key]['parent'])]['csssel'])) { - $selectors = $dom[($dom[$key]['parent'])]['csssel']; - } - // get all styles that apply - foreach($css as $selector => $style) { - $pos = strpos($selector, ' '); - // get specificity - $specificity = substr($selector, 0, $pos); - // remove specificity - $selector = substr($selector, $pos); - // check if this selector apply to current tag - if ($this->isValidCSSSelectorForTag($dom, $key, $selector)) { - if (!in_array($selector, $selectors)) { - // add style if not already added on parent selector - $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style); - $selectors[] = $selector; - } - } - } - if (isset($dom[$key]['attribute']['style'])) { - // attach inline style (latest properties have high priority) - $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']); - } - // order the css array to account for specificity - $cssordered = array(); - foreach ($cssarray as $key => $val) { - $skey = sprintf('%04d', $key); - $cssordered[$val['s'].'_'.$skey] = $val; - } - // sort selectors alphabetically to account for specificity - ksort($cssordered, SORT_STRING); - return array($selectors, $cssordered); - } - - /** - * Compact CSS data array into single string. - * @param $css (array) array of CSS properties - * @return string containing merged CSS properties - * @protected - * @since 5.9.070 (2011-04-19) - */ - protected function getTagStyleFromCSSarray($css) { - $tagstyle = ''; // value to be returned - foreach ($css as $style) { - // split single css commands - $csscmds = explode(';', $style['c']); - foreach ($csscmds as $cmd) { - if (!empty($cmd)) { - $pos = strpos($cmd, ':'); - if ($pos !== false) { - $cmd = substr($cmd, 0, ($pos + 1)); - if (strpos($tagstyle, $cmd) !== false) { - // remove duplicate commands (last commands have high priority) - $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle); - } - } - } - } - $tagstyle .= ';'.$style['c']; - } - // remove multiple semicolons - $tagstyle = preg_replace('/[;]+/', ';', $tagstyle); - return $tagstyle; + return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces); } /** @@ -21015,7 +15992,7 @@ class TCPDF { return array(); } $border['width'] = $this->getCSSBorderWidth($width); - $border['color'] = $this->convertHTMLColorToDec($color); + $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors); return $border; } @@ -21241,11 +16218,11 @@ class TCPDF { break; } case 'wider': { - $val = $parent + 10; + $val = ($parent + 10); break; } case 'narrower': { - $val = $parent - 10; + $val = ($parent - 10); break; } case 'inherit': { @@ -21263,6 +16240,62 @@ class TCPDF { return $val; } + /** + * Convert HTML string containing font size value to points + * @param $val (string) String containing font size value and unit. + * @param $refsize (float) Reference font size in points. + * @param $parent_size (float) Parent font size in points. + * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt). + * @return float value in points + * @public + */ + public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') { + $refsize = TCPDF_FONTS::getFontRefSize($refsize); + $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize); + switch ($val) { + case 'xx-small': { + $size = ($refsize - 4); + break; + } + case 'x-small': { + $size = ($refsize - 3); + break; + } + case 'small': { + $size = ($refsize - 2); + break; + } + case 'medium': { + $size = $refsize; + break; + } + case 'large': { + $size = ($refsize + 2); + break; + } + case 'x-large': { + $size = ($refsize + 4); + break; + } + case 'xx-large': { + $size = ($refsize + 6); + break; + } + case 'smaller': { + $size = ($parent_size - 3); + break; + } + case 'larger': { + $size = ($parent_size + 3); + break; + } + default: { + $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true); + } + } + return $size; + } + /** * Returns the HTML DOM array. * @param $html (string) html code @@ -21277,7 +16310,7 @@ class TCPDF { $matches = array(); if (preg_match_all('/([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) { if (isset($matches[1][0])) { - $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0]))); + $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true)); } $html = preg_replace('/(.*?)<\/cssarray>/isU', '', $html); } @@ -21291,12 +16324,14 @@ class TCPDF { preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type); // get 'all' and 'print' media, other media types are discarded // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv) - if (empty($type) or (isset($type[1]) and (($type[1] == 'all') or ($type[1] == 'print')))) { + if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) { $type = array(); if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) { // read CSS data file - $cssdata = file_get_contents(trim($type[1])); - $css = array_merge($css, $this->extractCSSproperties($cssdata)); + $cssdata = TCPDF_STATIC::fileGetContents(trim($type[1])); + if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) { + $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata)); + } } } } @@ -21310,14 +16345,14 @@ class TCPDF { preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type); // get 'all' and 'print' media, other media types are discarded // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv) - if (empty($type) or (isset($type[1]) and (($type[1] == 'all') or ($type[1] == 'print')))) { + if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) { $cssdata = $matches[2][$key]; - $css = array_merge($css, $this->extractCSSproperties($cssdata)); + $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata)); } } } // create a special tag to contain the CSS array (used for table content) - $csstagarray = ''.htmlentities(serialize($css)).''; + $csstagarray = ''.htmlentities(json_encode($css)).''; // remove head and style blocks $html = preg_replace('/]*)>(.*?)<\/head>/siU', '', $html); $html = preg_replace('/]*)>([^\<]*)<\/style>/isU', '', $html); @@ -21334,7 +16369,7 @@ class TCPDF { $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\"); $html = strtr($html, $repTable); $offset = 0; - while (($offset < strlen($html)) and ($pos = strpos($html, '', $offset)) !== false) { + while (($offset < strlen($html)) AND ($pos = strpos($html, '', $offset)) !== false) { $html_a = substr($html, 0, $offset); $html_b = substr($html, $offset, ($pos - $offset + 6)); while (preg_match("']*)>(.*?)\n(.*?)'si", $html_b)) { @@ -21349,7 +16384,7 @@ class TCPDF { $offset = strlen($html_a.$html_b); } $offset = 0; - while (($offset < strlen($html)) and ($pos = strpos($html, '', $offset)) !== false) { + while (($offset < strlen($html)) AND ($pos = strpos($html, '', $offset)) !== false) { $html_a = substr($html, 0, $offset); $html_b = substr($html, $offset, ($pos - $offset + 11)); while (preg_match("']*)>(.*?)\n(.*?)'si", $html_b)) { @@ -21363,7 +16398,7 @@ class TCPDF { $html = preg_replace('/([\s]*)', $html); $offset = 0; - while (($offset < strlen($html)) and ($pos = strpos($html, '', $offset)) !== false) { + while (($offset < strlen($html)) AND ($pos = strpos($html, '', $offset)) !== false) { $html_a = substr($html, 0, $offset); $html_b = substr($html, $offset, ($pos - $offset + 9)); while (preg_match("']*)>(.*?)'si", $html_b)) { @@ -21402,6 +16437,8 @@ class TCPDF { $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space // trim string $html = $this->stringTrim($html); + // fix br tag after li + $html = preg_replace('/
  • ]*)>/', '
  • ', $html); // fix first image tag alignment $html = preg_replace('/^
    rtl?'rtl':'ltr'; $thead = false; // true when we are inside the THEAD tag @@ -21455,7 +16493,7 @@ class TCPDF { $tagname = strtolower($tag[1]); // check if we are inside a table header if ($tagname == 'thead') { - if ($element{0} == '/') { + if ($element[0] == '/') { $thead = false; } else { $thead = true; @@ -21470,7 +16508,7 @@ class TCPDF { } else { $dom[$key]['block'] = false; } - if ($element{0} == '/') { + if ($element[0] == '/') { // *** closing html tag $dom[$key]['opening'] = false; $dom[$key]['parent'] = end($level); @@ -21489,18 +16527,19 @@ class TCPDF { $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor']; $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor']; $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align']; + $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform']; $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir']; if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) { $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype']; } // set the number of columns in table tag - if (($dom[$key]['value'] == 'tr') and (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) { + if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) { $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols']; } - if (($dom[$key]['value'] == 'td') or ($dom[$key]['value'] == 'th')) { + if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) { $dom[($dom[$key]['parent'])]['content'] = $csstagarray; for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) { - $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']]; + $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]); } $key = $i; // mark nested tables @@ -21510,8 +16549,8 @@ class TCPDF { $dom[($dom[$key]['parent'])]['content'] = str_replace('', '', $dom[($dom[$key]['parent'])]['content']); } // store header rows on a new table - if (($dom[$key]['value'] == 'tr') and ($dom[($dom[$key]['parent'])]['thead'] === true)) { - if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) { + if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) { + if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) { $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']]; } for ($i = $dom[$key]['parent']; $i <= $key; ++$i) { @@ -21523,7 +16562,7 @@ class TCPDF { // header elements must be always contained in a single page $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true'; } - if (($dom[$key]['value'] == 'table') and (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) { + if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) { // remove the nobr attributes from the table header $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']); $dom[($dom[$key]['parent'])]['thead'] .= ''; @@ -21532,7 +16571,7 @@ class TCPDF { // *** opening or self-closing html tag $dom[$key]['opening'] = true; $dom[$key]['parent'] = end($level); - if ((substr($element, -1, 1) == '/') or (in_array($dom[$key]['value'], $selfclosingtags))) { + if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) { // self-closing tag $dom[$key]['self'] = true; } else { @@ -21560,29 +16599,30 @@ class TCPDF { $dom[$key]['align'] = $dom[$parentkey]['align']; $dom[$key]['listtype'] = $dom[$parentkey]['listtype']; $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent']; + $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform']; $dom[$key]['border'] = array(); $dom[$key]['dir'] = $dom[$parentkey]['dir']; } // get attributes preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER); $dom[$key]['attribute'] = array(); // reset attribute array - while (list($id, $name) = each($attr_array[1])) { - $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id]; - } + foreach($attr_array[1] as $id => $name) { + $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id]; + } if (!empty($css)) { // merge CSS style to current style - list($dom[$key]['csssel'], $dom[$key]['cssdata']) = $this->getCSSdataArray($dom, $key, $css); - $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSSarray($dom[$key]['cssdata']); + list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css); + $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']); } // split style attributes - if (isset($dom[$key]['attribute']['style']) and !empty($dom[$key]['attribute']['style'])) { + if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) { // get style attributes preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER); $dom[$key]['style'] = array(); // reset style attribute array - while (list($id, $name) = each($style_array[1])) { - // in case of duplicate attribute the last replace the previous - $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]); - } + foreach($style_array[1] as $id => $name) { + // in case of duplicate attribute the last replace the previous + $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]); + } // --- get some style attributes --- // text direction if (isset($dom[$key]['style']['direction'])) { @@ -21610,52 +16650,14 @@ class TCPDF { $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent']; } } + // text-transform + if (isset($dom[$key]['style']['text-transform'])) { + $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform']; + } // font size if (isset($dom[$key]['style']['font-size'])) { $fsize = trim($dom[$key]['style']['font-size']); - switch ($fsize) { - // absolute-size - case 'xx-small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4; - break; - } - case 'x-small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3; - break; - } - case 'small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2; - break; - } - case 'medium': { - $dom[$key]['fontsize'] = $dom[0]['fontsize']; - break; - } - case 'large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2; - break; - } - case 'x-large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4; - break; - } - case 'xx-large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6; - break; - } - // relative-size - case 'smaller': { - $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3; - break; - } - case 'larger': { - $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3; - break; - } - default: { - $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true); - } - } + $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt'); } // font-stretch if (isset($dom[$key]['style']['font-stretch'])) { @@ -21665,7 +16667,7 @@ class TCPDF { if (isset($dom[$key]['style']['letter-spacing'])) { $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']); } - // line-height + // line-height (internally is the cell height ratio) if (isset($dom[$key]['style']['line-height'])) { $lineheight = trim($dom[$key]['style']['line-height']); switch ($lineheight) { @@ -21674,50 +16676,61 @@ class TCPDF { $dom[$key]['line-height'] = $dom[0]['line-height']; break; } + case 'inherit': { + $dom[$key]['line-height'] = $dom[$parentkey]['line-height']; + } default: { if (is_numeric($lineheight)) { - $lineheight = $lineheight * 100; + // convert to percentage of font height + $lineheight = ($lineheight * 100).'%'; } $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true); + if (substr($lineheight, -1) !== '%') { + if ($dom[$key]['fontsize'] <= 0) { + $dom[$key]['line-height'] = 1; + } else { + $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']); + } + } } } } // font style if (isset($dom[$key]['style']['font-weight'])) { - if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') { + if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') { if (strpos($dom[$key]['fontstyle'], 'B') !== false) { $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']); } - } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') { + } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') { $dom[$key]['fontstyle'] .= 'B'; } } - if (isset($dom[$key]['style']['font-style']) and (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) { + if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) { $dom[$key]['fontstyle'] .= 'I'; } // font color - if (isset($dom[$key]['style']['color']) and (!$this->empty_string($dom[$key]['style']['color']))) { - $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']); + if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) { + $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors); } elseif ($dom[$key]['value'] == 'a') { $dom[$key]['fgcolor'] = $this->htmlLinkColorArray; } // background color - if (isset($dom[$key]['style']['background-color']) and (!$this->empty_string($dom[$key]['style']['background-color']))) { - $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']); + if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) { + $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors); } // text-decoration if (isset($dom[$key]['style']['text-decoration'])) { $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration'])); foreach ($decors as $dec) { $dec = trim($dec); - if (!$this->empty_string($dec)) { - if ($dec{0} == 'u') { + if (!TCPDF_STATIC::empty_string($dec)) { + if ($dec[0] == 'u') { // underline $dom[$key]['fontstyle'] .= 'U'; - } elseif ($dec{0} == 'l') { - // line-trough + } elseif ($dec[0] == 'l') { + // line-through $dom[$key]['fontstyle'] .= 'D'; - } elseif ($dec{0} == 'o') { + } elseif ($dec[0] == 'o') { // overline $dom[$key]['fontstyle'] .= 'O'; } @@ -21736,7 +16749,7 @@ class TCPDF { } // check for text alignment if (isset($dom[$key]['style']['text-align'])) { - $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0}); + $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]); } // check for CSS border properties if (isset($dom[$key]['style']['border'])) { @@ -21748,16 +16761,16 @@ class TCPDF { if (isset($dom[$key]['style']['border-color'])) { $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color'])); if (isset($brd_colors[3])) { - $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]); + $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors); } if (isset($brd_colors[1])) { - $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]); + $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors); } if (isset($brd_colors[0])) { - $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]); + $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors); } if (isset($brd_colors[2])) { - $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]); + $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors); } } if (isset($dom[$key]['style']['border-width'])) { @@ -21777,7 +16790,7 @@ class TCPDF { } if (isset($dom[$key]['style']['border-style'])) { $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style'])); - if (isset($brd_styles[3]) and ($brd_styles[3]!='none')) { + if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) { $dom[$key]['border']['L']['cap'] = 'square'; $dom[$key]['border']['L']['join'] = 'miter'; $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]); @@ -21819,7 +16832,7 @@ class TCPDF { } } if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) { - $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color']); + $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors); } if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) { $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']); @@ -21858,7 +16871,7 @@ class TCPDF { $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']); } // page-break-inside - if (isset($dom[$key]['style']['page-break-inside']) and ($dom[$key]['style']['page-break-inside'] == 'avoid')) { + if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) { $dom[$key]['attribute']['nobr'] = 'true'; } // page-break-before @@ -21885,7 +16898,7 @@ class TCPDF { if (isset($dom[$key]['attribute']['display'])) { $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none'); } - if (isset($dom[$key]['attribute']['border']) and ($dom[$key]['attribute']['border'] != 0)) { + if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) { $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black'); if (!empty($borderstyle)) { $dom[$key]['border']['LTRB'] = $borderstyle; @@ -21900,9 +16913,9 @@ class TCPDF { // font size if (isset($dom[$key]['attribute']['size'])) { if ($key > 0) { - if ($dom[$key]['attribute']['size']{0} == '+') { + if ($dom[$key]['attribute']['size'][0] == '+') { $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1)); - } elseif ($dom[$key]['attribute']['size']{0} == '-') { + } elseif ($dom[$key]['attribute']['size'][0] == '-') { $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1)); } else { $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']); @@ -21913,41 +16926,41 @@ class TCPDF { } } // force natural alignment for lists - if ((($dom[$key]['value'] == 'ul') or ($dom[$key]['value'] == 'ol') or ($dom[$key]['value'] == 'dl')) - and (!isset($dom[$key]['align']) or $this->empty_string($dom[$key]['align']) or ($dom[$key]['align'] != 'J'))) { + if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl')) + AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) { if ($this->rtl) { $dom[$key]['align'] = 'R'; } else { $dom[$key]['align'] = 'L'; } } - if (($dom[$key]['value'] == 'small') or ($dom[$key]['value'] == 'sup') or ($dom[$key]['value'] == 'sub')) { - if (!isset($dom[$key]['attribute']['size']) and !isset($dom[$key]['style']['font-size'])) { + if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) { + if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) { $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO; } } - if (($dom[$key]['value'] == 'strong') or ($dom[$key]['value'] == 'b')) { + if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) { $dom[$key]['fontstyle'] .= 'B'; } - if (($dom[$key]['value'] == 'em') or ($dom[$key]['value'] == 'i')) { + if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) { $dom[$key]['fontstyle'] .= 'I'; } if ($dom[$key]['value'] == 'u') { $dom[$key]['fontstyle'] .= 'U'; } - if (($dom[$key]['value'] == 'del') or ($dom[$key]['value'] == 's') or ($dom[$key]['value'] == 'strike')) { + if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) { $dom[$key]['fontstyle'] .= 'D'; } - if (!isset($dom[$key]['style']['text-decoration']) and ($dom[$key]['value'] == 'a')) { + if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) { $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle; } - if (($dom[$key]['value'] == 'pre') or ($dom[$key]['value'] == 'tt')) { + if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) { $dom[$key]['fontname'] = $this->default_monospaced_font; } - if (($dom[$key]['value']{0} == 'h') and (intval($dom[$key]['value']{1}) > 0) and (intval($dom[$key]['value']{1}) < 7)) { + if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) { // headings h1, h2, h3, h4, h5, h6 - if (!isset($dom[$key]['attribute']['size']) and !isset($dom[$key]['style']['font-size'])) { - $headsize = (4 - intval($dom[$key]['value']{1})) * 2; + if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) { + $headsize = (4 - intval($dom[$key]['value'][1])) * 2; $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize; } if (!isset($dom[$key]['style']['font-weight'])) { @@ -21972,7 +16985,7 @@ class TCPDF { array_push($dom[($dom[$key]['parent'])]['trids'], $key); } } - if (($dom[$key]['value'] == 'th') or ($dom[$key]['value'] == 'td')) { + if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) { if (isset($dom[$key]['attribute']['colspan'])) { $colspan = intval($dom[$key]['attribute']['colspan']); } else { @@ -21986,18 +16999,18 @@ class TCPDF { $dom[$key]['dir'] = $dom[$key]['attribute']['dir']; } // set foreground color attribute - if (isset($dom[$key]['attribute']['color']) and (!$this->empty_string($dom[$key]['attribute']['color']))) { - $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']); - } elseif (!isset($dom[$key]['style']['color']) and ($dom[$key]['value'] == 'a')) { + if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) { + $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors); + } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) { $dom[$key]['fgcolor'] = $this->htmlLinkColorArray; } // set background color attribute - if (isset($dom[$key]['attribute']['bgcolor']) and (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) { - $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']); + if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) { + $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors); } // set stroke color attribute - if (isset($dom[$key]['attribute']['strokecolor']) and (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) { - $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']); + if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) { + $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors); } // check for width attribute if (isset($dom[$key]['attribute']['width'])) { @@ -22008,8 +17021,8 @@ class TCPDF { $dom[$key]['height'] = $dom[$key]['attribute']['height']; } // check for text alignment - if (isset($dom[$key]['attribute']['align']) and (!$this->empty_string($dom[$key]['attribute']['align'])) and ($dom[$key]['value'] !== 'img')) { - $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0}); + if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) { + $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]); } // check for text rendering mode (the following attributes do not exist in HTML) if (isset($dom[$key]['attribute']['stroke'])) { @@ -22037,10 +17050,33 @@ class TCPDF { // text $dom[$key]['tag'] = false; $dom[$key]['block'] = false; - //$element = str_replace(' ', $this->unichr(160), $element); - $dom[$key]['value'] = stripslashes($this->unhtmlentities($element)); $dom[$key]['parent'] = end($level); $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir']; + if (!empty($dom[$dom[$key]['parent']]['text-transform'])) { + // text-transform for unicode requires mb_convert_case (Multibyte String Functions) + if (function_exists('mb_convert_case')) { + $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER); + if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) { + $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding); + } + } elseif (!$this->isunicode) { + switch ($dom[$dom[$key]['parent']]['text-transform']) { + case 'capitalize': { + $element = ucwords(strtolower($element)); + break; + } + case 'uppercase': { + $element = strtoupper($element); + break; + } + case 'lowercase': { + $element = strtolower($element); + break; + } + } + } + } + $dom[$key]['value'] = stripslashes($this->unhtmlentities($element)); } ++$elkey; ++$key; @@ -22063,10 +17099,49 @@ class TCPDF { return $spacestr; } + /** + * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance. + * @param $data (string) serialized data + * @return string + * @public static + */ + protected function getHashForTCPDFtagParams($data) { + return md5(strlen($data).$this->file_id.$data); + } + + /** + * Serialize an array of parameters to be used with TCPDF tag in HTML code. + * @param $data (array) parameters array + * @return string containing serialized data + * @public static + */ + public function serializeTCPDFtagParameters($data) { + $encoded = urlencode(json_encode($data)); + return $this->getHashForTCPDFtagParams($encoded).$encoded; + } + + /** + * Unserialize parameters to be used with TCPDF tag in HTML code. + * @param $data (string) serialized data + * @return array containing unserialized data + * @protected static + */ + protected function unserializeTCPDFtagParameters($data) { + $hash = substr($data, 0, 32); + $encoded = substr($data, 32); + if ($hash != $this->getHashForTCPDFtagParams($encoded)) { + $this->Error('Invalid parameters'); + } + return json_decode(urldecode($encoded), true); + } + /** * Prints a cell (rectangular area) with optional borders, background color and html text string. * The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.
    * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. + * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting. + * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul + * NOTE: all the HTML attributes must be enclosed in double-quote. * @param $w (float) Cell width. If 0, the cell extends up to the right margin. * @param $h (float) Cell minimum height. The cell extends automatically if needed. * @param $x (float) upper-left corner X coordinate @@ -22090,6 +17165,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * Allows to preserve some HTML formatting (limited support).
    * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting. * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul + * NOTE: all the HTML attributes must be enclosed in double-quote. * @param $html (string) text to display * @param $ln (boolean) if true add a new line after text (default = true) * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false). @@ -22161,10 +17237,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($cell) { if ($this->rtl) { $this->x -= $this->cell_padding['R']; - $this->lMargin += $this->cell_padding['R']; + $this->lMargin += $this->cell_padding['L']; } else { $this->x += $this->cell_padding['L']; - $this->rMargin += $this->cell_padding['L']; + $this->rMargin += $this->cell_padding['R']; } } if ($this->customlistindent >= 0) { @@ -22183,51 +17259,45 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->listordered = array(); $this->listcount = array(); $this->lispacer = ''; - if (($this->empty_string($this->lasth)) or ($reseth)) { + if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) { // reset row height $this->resetLastH(); } $dom = $this->getHtmlDomArray($html); $maxel = count($dom); $key = 0; - $hidden_node_key = -1; while ($key < $maxel) { - if ($dom[$key]['tag']) { - if ($dom[$key]['opening']) { - if (($hidden_node_key <= 0) and $dom[$key]['hide']) { - // store the node key - $hidden_node_key = $key; + if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) { + // store the node key + $hidden_node_key = $key; + if ($dom[$key]['self']) { + // skip just this self-closing tag + ++$key; + } else { + // skip this and all children tags + while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) { + // skip hidden objects + ++$key; } - } elseif (($hidden_node_key > 0) and ($dom[$key]['parent'] == $hidden_node_key)) { - // we have reached the closing tag of the hidden node - $hidden_node_key = 0; + ++$key; } } - if ($hidden_node_key >= 0) { - // skip this node - ++$key; - if ($hidden_node_key == 0) { - // reset hidden mode - $hidden_node_key = -1; - } - continue; - } - if ($dom[$key]['tag'] and isset($dom[$key]['attribute']['pagebreak'])) { + if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) { // check for pagebreak - if (($dom[$key]['attribute']['pagebreak'] == 'true') or ($dom[$key]['attribute']['pagebreak'] == 'left') or ($dom[$key]['attribute']['pagebreak'] == 'right')) { + if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); $this->htmlvspace = ($this->PageBreakTrigger + 1); } - if ((($dom[$key]['attribute']['pagebreak'] == 'left') and (((!$this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) - or (($dom[$key]['attribute']['pagebreak'] == 'right') and (((!$this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0))))) { + if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0)))) + OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); $this->htmlvspace = ($this->PageBreakTrigger + 1); } } - if ($dom[$key]['tag'] and $dom[$key]['opening'] and isset($dom[$key]['attribute']['nobr']) and ($dom[$key]['attribute']['nobr'] == 'true')) { - if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) and ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) { + if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) { + if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) { $dom[$key]['attribute']['nobr'] = false; } else { // store current object @@ -22277,13 +17347,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } // print THEAD block - if (($dom[$key]['value'] == 'tr') and isset($dom[$key]['thead']) and $dom[$key]['thead']) { - if (isset($dom[$key]['parent']) and isset($dom[$dom[$key]['parent']]['thead']) and !$this->empty_string($dom[$dom[$key]['parent']]['thead'])) { + if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) { + if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) { $this->inthead = true; // print table header (thead) $this->writeHTML($this->thead, false, false, false, false, ''); // check if we are on a new page or on a new column - if (($this->y < $this->start_transaction_y) or ($this->checkPageBreak($this->lasth, '', false))) { + if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) { // we are on a new page or on a new column and the total object height is less than the available vertical space. // restore previous object $this->rollbackTransaction(true); @@ -22296,7 +17366,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->thead = ''; // add a page (or trig AcceptPageBreak() for multicolumn mode) $pre_y = $this->y; - if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) and ($this->y < $pre_y)) { + if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) { // fix for multicolumn mode $startliney = $this->y; } @@ -22323,30 +17393,30 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } // move $key index forward to skip THEAD block - while (($key < $maxel) and (!( - ($dom[$key]['tag'] and $dom[$key]['opening'] and ($dom[$key]['value'] == 'tr') and (!isset($dom[$key]['thead']) or !$dom[$key]['thead'])) - or ($dom[$key]['tag'] and (!$dom[$key]['opening']) and ($dom[$key]['value'] == 'table'))))) { + while ( ($key < $maxel) AND (!( + ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead'])) + OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) { ++$key; } } - if ($dom[$key]['tag'] or ($key == 0)) { - if ((($dom[$key]['value'] == 'table') or ($dom[$key]['value'] == 'tr')) and (isset($dom[$key]['align']))) { + if ($dom[$key]['tag'] OR ($key == 0)) { + if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) { $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L'; } // vertically align image in line - if ((!$this->newline) and ($dom[$key]['value'] == 'img') and (isset($dom[$key]['height'])) and ($dom[$key]['height'] > 0)) { + if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) { // get image height - $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px'); + $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px'); $autolinebreak = false; - if (isset($dom[$key]['width']) and ($dom[$key]['width'] > 0)) { - $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false); + if (!empty($dom[$key]['width'])) { + $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false); if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R'])) - and ((($this->rtl) and (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L']))) - or ((!$this->rtl) and (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) { + AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L']))) + OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) { // add automatic line break $autolinebreak = true; $this->Ln('', $cell); - if ((!$dom[($key-1)]['tag']) and ($dom[($key-1)]['value'] == ' ')) { + if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) { // go back to evaluate this line break --$key; } @@ -22356,7 +17426,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($this->inPageBody()) { $pre_y = $this->y; // check for page break - if ((!$this->checkPageBreak($imgh)) and ($this->y < $pre_y)) { + if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) { // fix for multicolumn mode $startliney = $this->y; } @@ -22405,27 +17475,29 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $startliney = $this->y; $this->newline = false; } - $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh; + $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh); $minstartliney = min($this->y, $minstartliney); - $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio)); + $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k)); } - } elseif (isset($dom[$key]['fontname']) or isset($dom[$key]['fontstyle']) or isset($dom[$key]['fontsize']) or isset($dom[$key]['line-height'])) { + } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) { // account for different font size $pfontname = $curfontname; $pfontstyle = $curfontstyle; $pfontsize = $curfontsize; - $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname; - $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle; - $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize; + $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname); + $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle); + $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize); $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize); $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize); - if (($fontname != $curfontname) or ($fontstyle != $curfontstyle) or ($fontsize != $curfontsize) - or ($this->cell_height_ratio != $dom[$key]['line-height']) - or ($dom[$key]['tag'] and $dom[$key]['opening'] and ($dom[$key]['value'] == 'li'))) { - if (($key < ($maxel - 1)) and ( - ($dom[$key]['tag'] and $dom[$key]['opening'] and ($dom[$key]['value'] == 'li')) - or ($this->cell_height_ratio != $dom[$key]['line-height']) - or (!$this->newline and is_numeric($fontsize) and is_numeric($curfontsize) and ($fontsize >= 0) and ($curfontsize >= 0) and ($fontsize != $curfontsize)) + if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize) + OR ($this->cell_height_ratio != $dom[$key]['line-height']) + OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) { + if (($key < ($maxel - 1)) AND ( + ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) + OR ($this->cell_height_ratio != $dom[$key]['line-height']) + OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) + AND ($fontsize >= 0) AND ($curfontsize >= 0) + AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname))) )) { if ($this->page > $startlinepage) { // fix lines splitted over two pages @@ -22471,17 +17543,17 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $dom[$key]['line-height'] = $this->cell_height_ratio; } if (!$dom[$key]['block']) { - if (!(isset($dom[($key + 1)]) and $dom[($key + 1)]['tag'] and (!$dom[($key + 1)]['opening']) and ($dom[($key + 1)]['value'] != 'li') and $dom[$key]['tag'] and (!$dom[$key]['opening']))) { + if (!(isset($dom[($key + 1)]) AND $dom[($key + 1)]['tag'] AND (!$dom[($key + 1)]['opening']) AND ($dom[($key + 1)]['value'] != 'li') AND $dom[$key]['tag'] AND (!$dom[$key]['opening']))) { $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2; } - if (($dom[$key]['value'] != 'sup') and ($dom[$key]['value'] != 'sub')) { + if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) { $current_line_align_data = array($key, $minstartliney, $maxbottomliney); - if (isset($line_align_data) and (($line_align_data[0] == ($key - 1)) or (($line_align_data[0] == ($key - 2)) and (isset($dom[($key - 1)])) and (preg_match('/^([\s]+)$/', $dom[($key - 1)]['value']) > 0)))) { + if (isset($line_align_data) AND (($line_align_data[0] == ($key - 1)) OR (($line_align_data[0] == ($key - 2)) AND (isset($dom[($key - 1)])) AND (preg_match('/^([\s]+)$/', $dom[($key - 1)]['value']) > 0)))) { $minstartliney = min($this->y, $line_align_data[1]); - $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $line_align_data[2]); + $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]); } else { $minstartliney = min($this->y, $minstartliney); - $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney); + $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney); } $line_align_data = $current_line_align_data; } @@ -22504,44 +17576,44 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0); $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3); $this->setTextRenderingMode($textstroke, $textfill, $textclip); - if (isset($dom[$key]['font-stretch']) and ($dom[$key]['font-stretch'] !== false)) { + if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) { $this->setFontStretching($dom[$key]['font-stretch']); } - if (isset($dom[$key]['letter-spacing']) and ($dom[$key]['letter-spacing'] !== false)) { + if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) { $this->setFontSpacing($dom[$key]['letter-spacing']); } - if (($plalign == 'J') and $dom[$key]['block']) { + if (($plalign == 'J') AND $dom[$key]['block']) { $plalign = ''; } // get current position on page buffer $curpos = $this->pagelen[$startlinepage]; - if (isset($dom[$key]['bgcolor']) and ($dom[$key]['bgcolor'] !== false)) { + if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) { $this->SetFillColorArray($dom[$key]['bgcolor']); $wfill = true; } else { $wfill = $fill | false; } - if (isset($dom[$key]['fgcolor']) and ($dom[$key]['fgcolor'] !== false)) { + if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) { $this->SetTextColorArray($dom[$key]['fgcolor']); } - if (isset($dom[$key]['strokecolor']) and ($dom[$key]['strokecolor'] !== false)) { + if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) { $this->SetDrawColorArray($dom[$key]['strokecolor']); } if (isset($dom[$key]['align'])) { $lalign = $dom[$key]['align']; } - if ($this->empty_string($lalign)) { + if (TCPDF_STATIC::empty_string($lalign)) { $lalign = $align; } } // align lines - if ($this->newline and (strlen($dom[$key]['value']) > 0) and ($dom[$key]['value'] != 'td') and ($dom[$key]['value'] != 'th')) { + if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) { $newline = true; $fontaligned = false; // we are at the beginning of a new line if (isset($startlinex)) { $yshift = ($minstartliney - $startliney); - if (($yshift > 0) or ($this->page > $startlinepage)) { + if (($yshift > 0) OR ($this->page > $startlinepage)) { $yshift = 0; } $t_x = 0; @@ -22564,12 +17636,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } else { $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos); - if (isset($opentagpos) and isset($this->footerlen[$startlinepage]) and (!$this->InFooter)) { + if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; $midpos = min($opentagpos, $this->footerpos[$startlinepage]); } elseif (isset($opentagpos)) { $midpos = $opentagpos; - } elseif (isset($this->footerlen[$startlinepage]) and (!$this->InFooter)) { + } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; $midpos = $this->footerpos[$startlinepage]; } else { @@ -22583,10 +17655,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $pend = ''; } } - if ((isset($plalign) and ((($plalign == 'C') or ($plalign == 'J') or (($plalign == 'R') and (!$this->rtl)) or (($plalign == 'L') and ($this->rtl)))))) { + if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) { // calculate shifting amount $tw = $w; - if (($plalign == 'J') and $this->isRTLTextDir() and ($this->num_columns > 1)) { + if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) { $tw += $this->cell_padding['R']; } if ($this->lMargin != $prevlMargin) { @@ -22599,14 +17671,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $no = 0; // number of spaces on a line contained on a single block if ($this->isRTLTextDir()) { // RTL // remove left space if exist - $pos1 = $this->revstrpos($pmid, '[('); + $pos1 = TCPDF_STATIC::revstrpos($pmid, '[('); if ($pos1 > 0) { $pos1 = intval($pos1); if ($this->isUnicodeFont()) { - $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32))); + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32))); $spacelen = 2; } else { - $pos2 = intval($this->revstrpos($pmid, '[('.chr(32))); + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32))); $spacelen = 1; } if ($pos1 == $pos2) { @@ -22620,14 +17692,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } else { // LTR // remove right space if exist - $pos1 = $this->revstrpos($pmid, ')]'); + $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]'); if ($pos1 > 0) { $pos1 = intval($pos1); if ($this->isUnicodeFont()) { - $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2; + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2; $spacelen = 2; } else { - $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1; + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1; $spacelen = 1; } if ($pos1 == $pos2) { @@ -22649,7 +17721,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } elseif ($plalign == 'L') { // left alignment on RTL document $t_x = -$mdiff; - } elseif (($plalign == 'J') and ($plalign == $lalign)) { + } elseif (($plalign == 'J') AND ($plalign == $lalign)) { // Justification if ($this->isRTLTextDir()) { // align text on the left @@ -22679,6 +17751,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // calculate additional space to add to each existing space $spacewidth = ($mdiff / ($ns - $no)) * $this->k; + if ($this->FontSize <= 0) { + $this->FontSize = 1; + } $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize; if ($this->font_spacing != 0) { // fixed spacing mode @@ -22695,14 +17770,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($this->isRTLTextDir()) { $textpos = $this->wPt; } - global $spacew; while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) { // check if we are inside a string section '[( ... )]' $stroffset = strpos($pmid, '[(', $offset); - if (($stroffset !== false) and ($stroffset <= $strpiece[2][1])) { + if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) { // set offset to the end of string section $offset = strpos($pmid, ')]', $stroffset); - while (($offset !== false) and ($pmid[($offset - 1)] == '\\')) { + while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) { $offset = strpos($pmid, ')]', ($offset + 1)); } if ($offset === false) { @@ -22716,22 +17790,25 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $spacew = ($spacewidth * $ns); } $offset = $strpiece[2][1] + strlen($strpiece[2][0]); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); - $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q'); - if ((($epsposbeg > 0) and ($epsposend > 0) and ($offset > $epsposbeg) and ($offset < $epsposend)) - or (($epsposbeg === false) and ($epsposend > 0) and ($offset < $epsposend))) { - // shift EPS images - $trx = sprintf('1 0 0 1 %F 0 cm', $spacew); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); - $pmid_b = substr($pmid, 0, $epsposbeg); - $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); - $pmid_e = substr($pmid, $epsposend); - $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; - $offset = $epsposend; - continue; - + $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset); + if ($epsposend !== null) { + $epsposend += strlen($this->epsmarker.'Q'); + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); + if ($epsposbeg === null) { + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); + $prev_epsposbeg = $epsposbeg; + } + if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) { + // shift EPS images + $trx = sprintf('1 0 0 1 %F 0 cm', $spacew); + $pmid_b = substr($pmid, 0, $epsposbeg); + $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); + $pmid_e = substr($pmid, $epsposend); + $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; + $offset = $epsposend; + continue; + } } - $prev_epsposbeg = $epsposbeg; $currentxpos = 0; // shift blocks of code switch ($strpiece[2][0]) { @@ -22741,9 +17818,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'l': { // get current X position preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); + if (!isset($xmatches[1])) { + break; + } $currentxpos = $xmatches[1]; $textpos = $currentxpos; - if (($strcount <= $maxkk) and ($strpiece[2][0] == 'Td')) { + if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) { $ns = $lnstring[3][$strcount]; if ($this->isRTLTextDir()) { $spacew = ($spacewidth * ($nsmax - $ns)); @@ -22751,21 +17831,24 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: ++$strcount; } // justify block - $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', - create_function('$matches', 'global $spacew; - $newx = sprintf("%F",(floatval($matches[1]) + $spacew)); - return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1); + if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) { + $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4]; + $pmid = str_replace($pmatch[0], $newpmid, $pmid); + unset($pmatch, $newpmid); + } break; } case 're': { // justify block - if (!$this->empty_string($this->lispacer)) { + if (!TCPDF_STATIC::empty_string($this->lispacer)) { $this->lispacer = ''; - continue; + break; } preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches); + if (!isset($xmatches[1])) { + break; + } $currentxpos = $xmatches[1]; - global $x_diff, $w_diff; $x_diff = 0; $w_diff = 0; if ($this->isRTLTextDir()) { // RTL @@ -22793,24 +17876,31 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } } - $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', - create_function('$matches', 'global $x_diff, $w_diff; - $newx = sprintf("%F",(floatval($matches[1]) + $x_diff)); - $neww = sprintf("%F",(floatval($matches[3]) + $w_diff)); - return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1); + if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) { + $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff)); + $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff)); + $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6]; + $pmid = str_replace($pmatch[0], $newpmid, $pmid); + unset($pmatch, $newpmid, $newx, $neww); + } break; } case 'c': { // get current X position preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $xmatches); + if (!isset($xmatches[1])) { + break; + } $currentxpos = $xmatches[1]; // justify block - $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', - create_function('$matches', 'global $spacew; - $newx1 = sprintf("%F",(floatval($matches[1]) + $spacew)); - $newx2 = sprintf("%F",(floatval($matches[3]) + $spacew)); - $newx3 = sprintf("%F",(floatval($matches[5]) + $spacew)); - return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1); + if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $pmatch) == 1) { + $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew)); + $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew)); + $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew)); + $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8]; + $pmid = str_replace($pmatch[0], $newpmid, $pmid); + unset($pmatch, $newpmid, $newx1, $newx2, $newx3); + } break; } } @@ -22820,7 +17910,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($this->inxobj) { // we are inside an XObject template foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) { - if (($pac['y'] >= $minstartliney) and (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) and (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { + if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { if ($cxpos > $lmpos) { $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k); $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k); @@ -22832,7 +17922,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } elseif (isset($this->PageAnnots[$this->page])) { foreach ($this->PageAnnots[$this->page] as $pak => $pac) { - if (($pac['y'] >= $minstartliney) and (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) and (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { + if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { if ($cxpos > $lmpos) { $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k); $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k); @@ -22853,15 +17943,24 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // word spacing is affected by stretching $spacew /= ($this->font_stretching / 100); } - $pmidtemp = $pmid; // escape special characters - $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp); - $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp); - $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x", - create_function('$matches', 'global $spacew; - $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]); - $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]); - return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%F", $spacew)." (", $matches[1]).")]";'), $pmidtemp); + $pos = 0; + $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid); + $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid); + if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) { + foreach($pamatch[0] as $pk => $pmatch) { + $replace = $pamatch[1][$pk]; + $replace = str_replace('#!#OP#!#', '(', $replace); + $replace = str_replace('#!#CP#!#', ')', $replace); + $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]'; + $pos = strpos($pmid, $pmatch, $pos); + if ($pos !== FALSE) { + $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch)); + } + ++$pos; + } + unset($pamatch); + } if ($this->inxobj) { // we are inside an XObject template $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend; @@ -22888,7 +17987,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } // end of J } // end if $startlinex - if (($t_x != 0) or ($yshift < 0)) { + if (($t_x != 0) OR ($yshift < 0)) { // shift the line $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k)); $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n"; @@ -22927,10 +18026,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $startliney -= (($this->FontSizePt / 0.7) / $this->k); } else { $minstartliney = $startliney; - $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)); + $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k)); } $startlinepage = $this->page; - if (isset($endlinepos) and (!$pbrk)) { + if (isset($endlinepos) AND (!$pbrk)) { $startlinepos = $endlinepos; } else { if ($this->inxobj) { @@ -22954,9 +18053,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $pask = 0; } - if (!($dom[$key]['tag'] and !$dom[$key]['opening'] and ($dom[$key]['value'] == 'table') - and (isset($this->emptypagemrk[$this->page])) - and ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) { + if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table') + AND (isset($this->emptypagemrk[$this->page])) + AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) { $this->SetFont($fontname, $fontstyle, $fontsize); if ($wfill) { $this->SetFillColorArray($this->bgcolor); @@ -22969,12 +18068,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($dom[$key]['tag']) { if ($dom[$key]['opening']) { // get text indentation (if any) - if (isset($dom[$key]['text-indent']) and $dom[$key]['block']) { + if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) { $this->textindent = $dom[$key]['text-indent']; $this->newline = true; } // table - if ($dom[$key]['value'] == 'table') { + if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) { // available page width if ($this->rtl) { $wtmp = $this->x - $this->lMargin; @@ -23018,7 +18117,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $colid = 0; } // table cell - if (($dom[$key]['value'] == 'td') or ($dom[$key]['value'] == 'th')) { + if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) { $trid = $dom[$key]['parent']; $table_el = $dom[$trid]['parent']; if (!isset($dom[$table_el]['cols'])) { @@ -23026,10 +18125,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // store border info $tdborder = 0; - if (isset($dom[$key]['border']) and !empty($dom[$key]['border'])) { + if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) { $tdborder = $dom[$key]['border']; } - $colspan = $dom[$key]['attribute']['colspan']; + $colspan = intval($dom[$key]['attribute']['colspan']); + if ($colspan <= 0) { + $colspan = 1; + } $old_cell_padding = $this->cell_padding; if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) { $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px'); @@ -23047,13 +18149,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $cellh = 0; } if (isset($dom[$key]['content'])) { - $cell_content = stripslashes($dom[$key]['content']); + $cell_content = $dom[$key]['content']; } else { $cell_content = ' '; } $tagtype = $dom[$key]['value']; $parentid = $key; - while (($key < $maxel) and (!(($dom[$key]['tag']) and (!$dom[$key]['opening']) and ($dom[$key]['value'] == $tagtype) and ($dom[$key]['parent'] == $parentid)))) { + while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) { // move $key index forward ++$key; } @@ -23095,30 +18197,30 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $rsendx = $trwsp['endx']; // account for margin changes if ($trwsp['startpage'] < $this->page) { - if (($this->rtl) and ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) { $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']); $rsstartx -= $dl; $rsendx -= $dl; - } elseif ((!$this->rtl) and ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) { $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']); $rsstartx += $dl; $rsendx += $dl; } } if (($trwsp['rowspan'] > 0) - and ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps)) - and ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps)) - and (($trwsp['starty'] < ($this->y - $this->feps)) or ($trwsp['startpage'] < $this->page) or ($trwsp['startcolumn'] < $this->current_column))) { + AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps)) + AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps)) + AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) { // set the starting X position of the current cell $this->x = $rsendx + $cellspacingx; // increment column indicator $colid += $trwsp['colspan']; if (($trwsp['rowspan'] == 1) - and (isset($dom[$trid]['endy'])) - and (isset($dom[$trid]['endpage'])) - and (isset($dom[$trid]['endcolumn'])) - and ($trwsp['endpage'] == $dom[$trid]['endpage']) - and ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) { + AND (isset($dom[$trid]['endy'])) + AND (isset($dom[$trid]['endpage'])) + AND (isset($dom[$trid]['endcolumn'])) + AND ($trwsp['endpage'] == $dom[$trid]['endpage']) + AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) { // set ending Y position for row $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']); $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy']; @@ -23140,7 +18242,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // inherit column width $cellw = 0; for ($i = 0; $i < $colspan; ++$i) { - $cellw += $table_colwidths[($colid + $i)]; + $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0); } } $cellw += (($colspan - 1) * $cellspacing['H']); @@ -23155,11 +18257,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1); } // push background colors - if (isset($dom[$parentid]['bgcolor']) and ($dom[$parentid]['bgcolor'] !== false)) { + if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) { $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor']; } // store border info - if (isset($tdborder) and !empty($tdborder)) { + if (isset($tdborder) AND !empty($tdborder)) { $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder; } $prevLastH = $this->lasth; @@ -23181,9 +18283,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // update the end of row position if ($rowspan <= 1) { if (isset($dom[$trid]['endy'])) { - if (($this->page == $dom[$trid]['endpage']) and ($this->current_column == $dom[$trid]['endcolumn'])) { + if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) { $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']); - } elseif (($this->page > $dom[$trid]['endpage']) or ($this->current_column > $dom[$trid]['endcolumn'])) { + } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) { $dom[$trid]['endy'] = $this->y; } } else { @@ -23211,9 +18313,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) { if ($trwsp['rowspan'] > 0) { if (isset($dom[$trid]['endpage'])) { - if (($trwsp['endpage'] == $dom[$trid]['endpage']) and ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) { + if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) { $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']); - } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) or ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) { + } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) { $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy']; $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage']; $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn']; @@ -23255,25 +18357,28 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } elseif (strlen($dom[$key]['value']) > 0) { // print list-item - if (!$this->empty_string($this->lispacer) and ($this->lispacer != '^')) { + if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) { $this->SetFont($pfontname, $pfontstyle, $pfontsize); $this->resetLastH(); $minstartliney = $this->y; - $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio)); - $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize); + $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize)); + if (is_numeric($pfontsize) AND ($pfontsize > 0)) { + $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize); + } $this->SetFont($curfontname, $curfontstyle, $curfontsize); $this->resetLastH(); - if (is_numeric($pfontsize) and ($pfontsize > 0) and is_numeric($curfontsize) and ($curfontsize > 0) and ($pfontsize != $curfontsize)) { + if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) { $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize); $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize); - $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2; + $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2; $minstartliney = min($this->y, $minstartliney); - $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney); + $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney); } } // text $this->htmlvspace = 0; - if ((!$this->premode) and $this->isRTLTextDir()) { + $isRTLString = preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $dom[$key]['value']) || preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $dom[$key]['value']); + if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) { // reverse spaces order $lsp = ''; // left spaces $rsp = ''; // right spaces @@ -23288,7 +18393,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($newline) { if (!$this->premode) { $prelen = strlen($dom[$key]['value']); - if ($this->isRTLTextDir()) { + if ($this->isRTLTextDir() AND !$isRTLString) { // right trim except non-breaking space $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']); } else { @@ -23296,7 +18401,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']); } $postlen = strlen($dom[$key]['value']); - if (($postlen == 0) and ($prelen > 0)) { + if (($postlen == 0) AND ($prelen > 0)) { $dom[$key]['trimmed_space'] = true; } } @@ -23313,16 +18418,16 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $this->x += $this->textindent; } - if (!isset($dom[$key]['trimmed_space']) or !$dom[$key]['trimmed_space']) { + if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) { $strlinelen = $this->GetStringWidth($dom[$key]['value']); - if (!empty($this->HREF) and (isset($this->HREF['url']))) { + if (!empty($this->HREF) AND (isset($this->HREF['url']))) { // HTML Link $hrefcolor = ''; - if (isset($dom[($dom[$key]['parent'])]['fgcolor']) and ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) { + if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) { $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor']; } $hrefstyle = -1; - if (isset($dom[($dom[$key]['parent'])]['fontstyle']) and ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) { + if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) { $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle']; } $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true); @@ -23333,7 +18438,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $cwa = ($this->w - $this->rMargin - $this->x); } - if (($strlinelen < $cwa) and (isset($dom[($key + 1)])) and ($dom[($key + 1)]['tag']) and (!$dom[($key + 1)]['block'])) { + if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) { // check the next text blocks for continuity $nkey = ($key + 1); $write_block = true; @@ -23341,7 +18446,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $tmp_fontname = $this->FontFamily; $tmp_fontstyle = $this->FontStyle; $tmp_fontsize = $this->FontSizePt; - while ($write_block and isset($dom[$nkey])) { + while ($write_block AND isset($dom[$nkey])) { if ($dom[$nkey]['tag']) { if ($dom[$nkey]['block']) { // end of block @@ -23352,8 +18457,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt; $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']); } else { - $nextstr = preg_split('/'.$this->re_space['p'].'+/'.$this->re_space['m'], $dom[$nkey]['value']); - if (isset($nextstr[0]) and $same_textdir) { + $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']); + if (isset($nextstr[0]) AND $same_textdir) { $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize); if (isset($nextstr[1])) { $write_block = false; @@ -23363,9 +18468,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: ++$nkey; } } - if (($wadj > 0) and (($strlinelen + $wadj) >= $cwa)) { + if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) { $wadj = 0; - $nextstr = preg_split('/'.$this->re_space['p'].'/'.$this->re_space['m'], $dom[$key]['value']); + $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']); $numblks = count($nextstr); if ($numblks > 1) { // try to split on blank spaces @@ -23376,7 +18481,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } // check for reversed text direction - if (($wadj > 0) and (($this->rtl and ($this->tmprtl === 'L')) or (!$this->rtl and ($this->tmprtl === 'R')))) { + if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) { // LTR text on RTL direction or RTL text on LTR direction $reverse_dir = true; $this->rtl = !$this->rtl; @@ -23391,7 +18496,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // ****** write only until the end of the line and get the rest ****** $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj); // restore default direction - if ($reverse_dir and ($wadj == 0)) { + if ($reverse_dir AND ($wadj == 0)) { $this->x = $xws; $this->rtl = !$this->rtl; $reverse_dir = false; @@ -23432,9 +18537,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } ++$key; - if (isset($dom[$key]['tag']) and $dom[$key]['tag'] and (!isset($dom[$key]['opening']) or !$dom[$key]['opening']) and isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) and ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) { + if (isset($dom[$key]['tag']) AND $dom[$key]['tag'] AND (!isset($dom[$key]['opening']) OR !$dom[$key]['opening']) AND isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) { // check if we are on a new page or on a new column - if ((!$undo) and (($this->y < $this->start_transaction_y) or (($dom[$key]['value'] == 'tr') and ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) { + if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) { // we are on a new page or on a new column and the total object height is less than the available vertical space. // restore previous object $this->rollbackTransaction(true); @@ -23442,9 +18547,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($this_method_vars as $vkey => $vval) { $$vkey = $vval; } + if (!empty($dom[$key]['thead'])) { + $this->inthead = true; + } // add a page (or trig AcceptPageBreak() for multicolumn mode) $pre_y = $this->y; - if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) and ($this->y < $pre_y)) { + if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) { $startliney = $this->y; } $undo = true; // avoid infinite loop @@ -23456,7 +18564,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // align the last line if (isset($startlinex)) { $yshift = ($minstartliney - $startliney); - if (($yshift > 0) or ($this->page > $startlinepage)) { + if (($yshift > 0) OR ($this->page > $startlinepage)) { $yshift = 0; } $t_x = 0; @@ -23479,12 +18587,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } else { $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos); - if (isset($opentagpos) and isset($this->footerlen[$startlinepage]) and (!$this->InFooter)) { + if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; $midpos = min($opentagpos, $this->footerpos[$startlinepage]); } elseif (isset($opentagpos)) { $midpos = $opentagpos; - } elseif (isset($this->footerlen[$startlinepage]) and (!$this->InFooter)) { + } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; $midpos = $this->footerpos[$startlinepage]; } else { @@ -23498,7 +18606,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $pend = ''; } } - if ((isset($plalign) and ((($plalign == 'C') or (($plalign == 'R') and (!$this->rtl)) or (($plalign == 'L') and ($this->rtl)))))) { + if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) { // calculate shifting amount $tw = $w; if ($this->lMargin != $prevlMargin) { @@ -23511,14 +18619,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $no = 0; // number of spaces on a line contained on a single block if ($this->isRTLTextDir()) { // RTL // remove left space if exist - $pos1 = $this->revstrpos($pmid, '[('); + $pos1 = TCPDF_STATIC::revstrpos($pmid, '[('); if ($pos1 > 0) { $pos1 = intval($pos1); if ($this->isUnicodeFont()) { - $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32))); + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32))); $spacelen = 2; } else { - $pos2 = intval($this->revstrpos($pmid, '[('.chr(32))); + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32))); $spacelen = 1; } if ($pos1 == $pos2) { @@ -23532,14 +18640,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } else { // LTR // remove right space if exist - $pos1 = $this->revstrpos($pmid, ')]'); + $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]'); if ($pos1 > 0) { $pos1 = intval($pos1); if ($this->isUnicodeFont()) { - $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) + 2; + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2; $spacelen = 2; } else { - $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) + 1; + $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1; $spacelen = 1; } if ($pos1 == $pos2) { @@ -23563,7 +18671,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $t_x = -$mdiff; } } // end if startlinex - if (($t_x != 0) or ($yshift < 0)) { + if (($t_x != 0) OR ($yshift < 0)) { // shift the line $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k)); $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n"; @@ -23607,9 +18715,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->listordered = $prev_listordered; $this->listcount = $prev_listcount; $this->lispacer = $prev_lispacer; - if ($ln and (!($cell and ($dom[$key-1]['value'] == 'table')))) { + if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) { $this->Ln($this->lasth); - if ($this->y < $maxbottomliney) { + if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) { $this->y = $maxbottomliney; } } @@ -23638,32 +18746,55 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $hbz = 0; // distance from y to line bottom $hb = 0; // vertical space between block tags // calculate vertical space for block tags - if (isset($this->tagvspaces[$tag['value']][0]['h']) and ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) { + if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) { $cur_h = $this->tagvspaces[$tag['value']][0]['h']; } elseif (isset($tag['fontsize'])) { - $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio; + $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k); } else { - $cur_h = $this->FontSize * $this->cell_height_ratio; + $cur_h = $this->getCellHeight($this->FontSize); } if (isset($this->tagvspaces[$tag['value']][0]['n'])) { - $n = $this->tagvspaces[$tag['value']][0]['n']; + $on = $this->tagvspaces[$tag['value']][0]['n']; } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) { - $n = 0.6; + $on = 0.6; } else { - $n = 1; + $on = 1; } - if ((!isset($this->tagvspaces[$tag['value']])) and (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br')))) { + if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) { $hb = 0; } else { - $hb = ($n * $cur_h); + $hb = ($on * $cur_h); } - if (($this->htmlvspace <= 0) and ($n > 0)) { + if (($this->htmlvspace <= 0) AND ($on > 0)) { if (isset($parent['fontsize'])) { $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio); } else { - $hbz = $this->FontSize * $this->cell_height_ratio; + $hbz = $this->getCellHeight($this->FontSize); } } + if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) { + // fix vertical space after table + $hbz = 0; + } + // closing vertical space + $hbc = 0; + if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) { + $pre_h = $this->tagvspaces[$tag['value']][1]['h']; + } elseif (isset($parent['fontsize'])) { + $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k); + } else { + $pre_h = $this->getCellHeight($this->FontSize); + } + if (isset($this->tagvspaces[$tag['value']][1]['n'])) { + $cn = $this->tagvspaces[$tag['value']][1]['n']; + } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) { + $cn = 0.6; + } else { + $cn = 1; + } + if (isset($this->tagvspaces[$tag['value']][1])) { + $hbc = ($cn * $pre_h); + } } // Opening tag switch($tag['value']) { @@ -23671,18 +18802,20 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $cp = 0; $cs = 0; $dom[$key]['rowspans'] = array(); - if (!isset($dom[$key]['attribute']['nested']) or ($dom[$key]['attribute']['nested'] != 'true')) { + if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) { + $this->htmlvspace = 0; // set table header - if (!$this->empty_string($dom[$key]['thead'])) { + if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) { // set table header $this->thead = $dom[$key]['thead']; - if (!isset($this->theadMargins) or (empty($this->theadMargins))) { + if (!isset($this->theadMargins) OR (empty($this->theadMargins))) { $this->theadMargins = array(); $this->theadMargins['cell_padding'] = $this->cell_padding; $this->theadMargins['lmargin'] = $this->lMargin; $this->theadMargins['rmargin'] = $this->rMargin; $this->theadMargins['page'] = $this->page; $this->theadMargins['cell'] = $cell; + $this->theadMargins['gvars'] = $this->getGraphicVars(); } } } @@ -23700,7 +18833,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $cs = $tag['border-spacing']['V']; } $prev_y = $this->y; - if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) or ($this->y < $prev_y)) { + if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) { $this->inthead = true; // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); @@ -23713,19 +18846,19 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'hr': { - if ((isset($tag['height'])) and ($tag['height'] != '')) { + if ((isset($tag['height'])) AND ($tag['height'] != '')) { $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px'); } else { $hrHeight = $this->GetLineWidth(); } - $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag); + $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag); $x = $this->GetX(); $y = $this->GetY(); $wtmp = $this->w - $this->lMargin - $this->rMargin; if ($cell) { $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']); } - if ((isset($tag['width'])) and ($tag['width'] != '')) { + if ((isset($tag['width'])) AND ($tag['width'] != '')) { $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px'); } else { $hrWidth = $wtmp; @@ -23734,7 +18867,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->SetLineWidth($hrHeight); $this->Line($x, $y, $x + $hrWidth, $y); $this->SetLineWidth($prevlinewidth); - $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)])); + $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)])); break; } case 'a': { @@ -23744,121 +18877,122 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'img': { - if (isset($tag['attribute']['src'])) { - if ($tag['attribute']['src']{0} === '@') { - // data stream - $tag['attribute']['src'] = '@'.base64_decode(substr($tag['attribute']['src'], 1)); - $type = ''; - } else { - // check for images without protocol - if (preg_match('%^/{2}%', $tag['attribute']['src'])) { - $tag['attribute']['src'] = 'http:'.$tag['attribute']['src']; - } - /* PrestaShop - // replace relative path with real server path - if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { - $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']); - if (($findroot === false) OR ($findroot > 1)) { - if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') { - $tag['attribute']['src'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$tag['attribute']['src']; - } else { - $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src']; - } + if (empty($tag['attribute']['src'])) { + break; + } + $imgsrc = $tag['attribute']['src']; + if ($imgsrc[0] === '@') { + // data stream + $imgsrc = '@'.base64_decode(substr($imgsrc, 1)); + $type = ''; + } else { + if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { + // fix image path + $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']); + if (($findroot === false) OR ($findroot > 1)) { + if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') { + $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc; + } else { + $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc; } - }*/ - $tag['attribute']['src'] = htmlspecialchars_decode(urldecode($tag['attribute']['src'])); - $type = $this->getImageFileType($tag['attribute']['src']); - $testscrtype = @parse_url($tag['attribute']['src']); - if (!isset($testscrtype['query']) or empty($testscrtype['query'])) { + } + $imgsrc = urldecode($imgsrc); + $testscrtype = @parse_url($imgsrc); + if (empty($testscrtype['query'])) { // convert URL to server path - $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']); + $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc); + } elseif (preg_match('|^https?://|', $imgsrc) !== 1) { + // convert URL to server path + $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc); } } - if (!isset($tag['width'])) { - $tag['width'] = 0; + // get image type + $type = TCPDF_IMAGES::getImageFileType($imgsrc); + } + if (!isset($tag['width'])) { + $tag['width'] = 0; + } + if (!isset($tag['height'])) { + $tag['height'] = 0; + } + //if (!isset($tag['attribute']['align'])) { + // the only alignment supported is "bottom" + // further development is required for other modes. + $tag['attribute']['align'] = 'bottom'; + //} + switch($tag['attribute']['align']) { + case 'top': { + $align = 'T'; + break; } - if (!isset($tag['height'])) { - $tag['height'] = 0; + case 'middle': { + $align = 'M'; + break; } - //if (!isset($tag['attribute']['align'])) { - // the only alignment supported is "bottom" - // further development is required for other modes. - $tag['attribute']['align'] = 'bottom'; - //} - switch($tag['attribute']['align']) { - case 'top': { - $align = 'T'; - break; - } - case 'middle': { - $align = 'M'; - break; - } - case 'bottom': { - $align = 'B'; - break; - } - default: { - $align = 'B'; - break; - } + case 'bottom': { + $align = 'B'; + break; } - $prevy = $this->y; - $xpos = $this->x; - $imglink = ''; - if (isset($this->HREF['url']) and !$this->empty_string($this->HREF['url'])) { - $imglink = $this->HREF['url']; - if ($imglink{0} == '#') { - // convert url to internal link - $lnkdata = explode(',', $imglink); - if (isset($lnkdata[0])) { - $page = intval(substr($lnkdata[0], 1)); - if (empty($page) or ($page <= 0)) { - $page = $this->page; - } - if (isset($lnkdata[1]) and (strlen($lnkdata[1]) > 0)) { - $lnky = floatval($lnkdata[1]); - } else { - $lnky = 0; - } - $imglink = $this->AddLink(); - $this->SetLink($imglink, $lnky, $page); + default: { + $align = 'B'; + break; + } + } + $prevy = $this->y; + $xpos = $this->x; + $imglink = ''; + if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) { + $imglink = $this->HREF['url']; + if ($imglink[0] == '#') { + // convert url to internal link + $lnkdata = explode(',', $imglink); + if (isset($lnkdata[0])) { + $page = intval(substr($lnkdata[0], 1)); + if (empty($page) OR ($page <= 0)) { + $page = $this->page; } + if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) { + $lnky = floatval($lnkdata[1]); + } else { + $lnky = 0; + } + $imglink = $this->AddLink(); + $this->SetLink($imglink, $lnky, $page); } } - $border = 0; - if (isset($tag['border']) and !empty($tag['border'])) { - // currently only support 1 (frame) or a combination of 'LTRB' - $border = $tag['border']; + } + $border = 0; + if (isset($tag['border']) AND !empty($tag['border'])) { + // currently only support 1 (frame) or a combination of 'LTRB' + $border = $tag['border']; + } + $iw = ''; + if (isset($tag['width'])) { + $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false); + } + $ih = ''; + if (isset($tag['height'])) { + $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false); + } + if (($type == 'eps') OR ($type == 'ai')) { + $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true); + } elseif ($type == 'svg') { + $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true); + } else { + $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true); + } + switch($align) { + case 'T': { + $this->y = $prevy; + break; } - $iw = ''; - if (isset($tag['width'])) { - $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false); + case 'M': { + $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2); + break; } - $ih = ''; - if (isset($tag['height'])) { - $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false); - } - if (($type == 'eps') or ($type == 'ai')) { - $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true); - } elseif ($type == 'svg') { - $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true); - } else { - $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true); - } - switch($align) { - case 'T': { - $this->y = $prevy; - break; - } - case 'M': { - $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ; - break; - } - case 'B': { - $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k); - break; - } + case 'B': { + $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio)); + break; } } break; @@ -23922,11 +19056,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } if ($this->listordered[$this->listnum]) { // ordered item - if (isset($parent['attribute']['type']) and !$this->empty_string($parent['attribute']['type'])) { + if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) { $this->lispacer = $parent['attribute']['type']; - } elseif (isset($parent['listtype']) and !$this->empty_string($parent['listtype'])) { + } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) { $this->lispacer = $parent['listtype']; - } elseif (isset($this->lisymbol) and !$this->empty_string($this->lisymbol)) { + } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) { $this->lispacer = $this->lisymbol; } else { $this->lispacer = '#'; @@ -23937,11 +19071,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } else { // unordered item - if (isset($parent['attribute']['type']) and !$this->empty_string($parent['attribute']['type'])) { + if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) { $this->lispacer = $parent['attribute']['type']; - } elseif (isset($parent['listtype']) and !$this->empty_string($parent['listtype'])) { + } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) { $this->lispacer = $parent['listtype']; - } elseif (isset($this->lisymbol) and !$this->empty_string($this->lisymbol)) { + } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) { $this->lispacer = $this->lisymbol; } else { $this->lispacer = '!'; @@ -23998,7 +19132,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($tag['attribute']['action'])) { $this->form_action = $tag['attribute']['action']; } else { - $this->form_action = K_PATH_URL.$_SERVER['SCRIPT_NAME']; + $this->Error('Please explicitly set action attribute path!'); } if (isset($tag['attribute']['enctype'])) { $this->form_enctype = $tag['attribute']['enctype']; @@ -24013,29 +19147,29 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'input': { - if (isset($tag['attribute']['name']) and !$this->empty_string($tag['attribute']['name'])) { + if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) { $name = $tag['attribute']['name']; } else { break; } $prop = array(); $opt = array(); - if (isset($tag['attribute']['readonly']) and !$this->empty_string($tag['attribute']['readonly'])) { + if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) { $prop['readonly'] = true; } - if (isset($tag['attribute']['value']) and !$this->empty_string($tag['attribute']['value'])) { + if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) { $value = $tag['attribute']['value']; } - if (isset($tag['attribute']['maxlength']) and !$this->empty_string($tag['attribute']['maxlength'])) { + if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) { $opt['maxlen'] = intval($tag['attribute']['maxlength']); } - $h = $this->FontSize * $this->cell_height_ratio; - if (isset($tag['attribute']['size']) and !$this->empty_string($tag['attribute']['size'])) { + $h = $this->getCellHeight($this->FontSize); + if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) { $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2; } else { $w = $h; } - if (isset($tag['attribute']['checked']) and (($tag['attribute']['checked'] == 'checked') or ($tag['attribute']['checked'] == 'true'))) { + if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) { $checked = true; } else { $checked = false; @@ -24138,14 +19272,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } case 'image': { // THIS TYPE MUST BE FIXED - if (isset($tag['attribute']['src']) and !$this->empty_string($tag['attribute']['src'])) { + if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) { $img = $tag['attribute']['src']; } else { break; } $value = 'img'; //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false)); - if (isset($tag['attribute']['onclick']) and !empty($tag['attribute']['onclick'])) { + if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) { $jsaction = $tag['attribute']['onclick']; } else { $jsaction = ''; @@ -24160,7 +19294,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $w = $this->GetStringWidth($value) * 1.5; $h *= 1.6; $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255)); - if (isset($tag['attribute']['onclick']) and !empty($tag['attribute']['onclick'])) { + if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) { $jsaction = $tag['attribute']['onclick']; } else { $jsaction = ''; @@ -24174,24 +19308,24 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'textarea': { $prop = array(); $opt = array(); - if (isset($tag['attribute']['readonly']) and !$this->empty_string($tag['attribute']['readonly'])) { + if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) { $prop['readonly'] = true; } - if (isset($tag['attribute']['name']) and !$this->empty_string($tag['attribute']['name'])) { + if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) { $name = $tag['attribute']['name']; } else { break; } - if (isset($tag['attribute']['value']) and !$this->empty_string($tag['attribute']['value'])) { + if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) { $opt['v'] = $tag['attribute']['value']; } - if (isset($tag['attribute']['cols']) and !$this->empty_string($tag['attribute']['cols'])) { + if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) { $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2; } else { $w = 40; } - if (isset($tag['attribute']['rows']) and !$this->empty_string($tag['attribute']['rows'])) { - $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio; + if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) { + $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize); } else { $h = 10; } @@ -24200,19 +19334,19 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'select': { - $h = $this->FontSize * $this->cell_height_ratio; - if (isset($tag['attribute']['size']) and !$this->empty_string($tag['attribute']['size'])) { + $h = $this->getCellHeight($this->FontSize); + if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) { $h *= ($tag['attribute']['size'] + 1); } $prop = array(); $opt = array(); - if (isset($tag['attribute']['name']) and !$this->empty_string($tag['attribute']['name'])) { + if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) { $name = $tag['attribute']['name']; } else { break; } $w = 0; - if (isset($tag['attribute']['opt']) and !$this->empty_string($tag['attribute']['opt'])) { + if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) { $options = explode('#!NwL!#', $tag['attribute']['opt']); $values = array(); foreach ($options as $val) { @@ -24229,7 +19363,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } $w *= 2; - if (isset($tag['attribute']['multiple']) and ($tag['attribute']['multiple']='multiple')) { + if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) { $prop['multipleSelection'] = 'true'; $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false); } else { @@ -24238,13 +19372,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'tcpdf': { - if (defined('K_TCPDF_CALLS_IN_HTML') and (K_TCPDF_CALLS_IN_HTML === true)) { + if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) { // Special tag used to call TCPDF methods if (isset($tag['attribute']['method'])) { $tcpdf_method = $tag['attribute']['method']; if (method_exists($this, $tcpdf_method)) { - if (isset($tag['attribute']['params']) and (!empty($tag['attribute']['params']))) { - $params = unserialize(urldecode($tag['attribute']['params'])); + if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) { + $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']); call_user_func_array(array($this, $tcpdf_method), $params); } else { $this->$tcpdf_method(); @@ -24265,15 +19399,15 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // set border $dom[$key]['borderposition'] = $this->getBorderStartPosition(); } - if ($dom[$key]['self'] and isset($dom[$key]['attribute']['pagebreakafter'])) { + if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) { $pba = $dom[$key]['attribute']['pagebreakafter']; // check for pagebreak - if (($pba == 'true') or ($pba == 'left') or ($pba == 'right')) { + if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); } - if ((($pba == 'left') and (((!$this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) - or (($pba == 'right') and (((!$this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0))))) { + if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0)))) + OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); } @@ -24293,7 +19427,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) { $tag = $dom[$key]; $parent = $dom[($dom[$key]['parent'])]; - $lasttag = ((!isset($dom[($key + 1)])) or ((!isset($dom[($key + 2)])) and ($dom[($key + 1)]['value'] == 'marker'))); + $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker'))); $in_table_head = false; // maximum x position (used to draw borders) if ($this->rtl) { @@ -24305,27 +19439,27 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $hbz = 0; // distance from y to line bottom $hb = 0; // vertical space between block tags // calculate vertical space for block tags - if (isset($this->tagvspaces[$tag['value']][1]['h']) and ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) { + if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) { $pre_h = $this->tagvspaces[$tag['value']][1]['h']; } elseif (isset($parent['fontsize'])) { - $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio); + $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k); } else { - $pre_h = $this->FontSize * $this->cell_height_ratio; + $pre_h = $this->getCellHeight($this->FontSize); } if (isset($this->tagvspaces[$tag['value']][1]['n'])) { - $n = $this->tagvspaces[$tag['value']][1]['n']; + $cn = $this->tagvspaces[$tag['value']][1]['n']; } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) { - $n = 0.6; + $cn = 0.6; } else { - $n = 1; + $cn = 1; } - if ((!isset($this->tagvspaces[$tag['value']])) and ($tag['value'] == 'div')) { + if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) { $hb = 0; } else { - $hb = ($n * $pre_h); + $hb = ($cn * $pre_h); } if ($maxbottomliney > $this->PageBreakTrigger) { - $hbz = ($this->FontSize * $this->cell_height_ratio); + $hbz = $this->getCellHeight($this->FontSize); } elseif ($this->y < $maxbottomliney) { $hbz = ($maxbottomliney - $this->y); } @@ -24351,9 +19485,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) { $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1; if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) { - if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) and ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) { + if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) { $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']); - } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) or ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) { + } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) { $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy']; $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage']; $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn']; @@ -24380,11 +19514,23 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } } + $prev_page = $this->page; $this->setPage($dom[($dom[$key]['parent'])]['endpage']); if ($this->num_columns > 1) { - $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']); + if (($prev_page < $this->page) + AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1))) + OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) { + // page jump + $this->selectColumn(0); + $dom[($dom[$key]['parent'])]['endcolumn'] = 0; + $dom[($dom[$key]['parent'])]['endy'] = $this->y; + } else { + $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']); + $this->y = $dom[($dom[$key]['parent'])]['endy']; + } + } else { + $this->y = $dom[($dom[$key]['parent'])]['endy']; } - $this->y = $dom[($dom[$key]['parent'])]['endy']; if (isset($dom[$table_el]['attribute']['cellspacing'])) { $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px'); } elseif (isset($dom[$table_el]['border-spacing'])) { @@ -24396,9 +19542,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // account for booklet mode if ($this->page > $parent['startpage']) { - if (($this->rtl) and ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) { $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']); - } elseif ((!$this->rtl) and ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) { $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']); } } @@ -24411,7 +19557,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'table': { $table_el = $parent; // set default border - if (isset($table_el['attribute']['border']) and ($table_el['attribute']['border'] > 0)) { + if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) { // set default border $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0))); } else { @@ -24423,21 +19569,21 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // update row-spanned cells if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { - if ($trwsp['trid'] == $trkey) { - $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1; - } - if (isset($prevtrkey) and ($trwsp['trid'] == $prevtrkey) and ($trwsp['mrowspan'] >= 0)) { + if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) { $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey; } + if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) { + $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1; + } } } - if (isset($prevtrkey) and ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) { + if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) { $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm']; $dom[$prevtrkey]['endy'] = $pgendy; // update row-spanned cells if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { - if (($trwsp['trid'] == $trkey) and ($trwsp['mrowspan'] > 1) and ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) { + if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) { $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy; $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1; } @@ -24458,7 +19604,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // for each cell on the row foreach ($parent['cellpos'] as $k => $cellpos) { - if (isset($cellpos['rowspanid']) and ($cellpos['rowspanid'] >= 0)) { + if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) { $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx']; $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx']; $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy']; @@ -24479,7 +19625,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($cellpos['border'])) { $border = $cellpos['border']; } - if (isset($cellpos['bgcolor']) and ($cellpos['bgcolor']) !== false) { + if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) { $this->SetFillColorArray($cellpos['bgcolor']); $fill = true; } else { @@ -24490,9 +19636,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $starty = $y; $w = abs($cellpos['endx'] - $cellpos['startx']); // get border modes - $border_start = $this->getBorderMode($border, $position='start'); - $border_end = $this->getBorderMode($border, $position='end'); - $border_middle = $this->getBorderMode($border, $position='middle'); + $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell); + $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell); + $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell); // design borders around HTML cells. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page $ccode = ''; @@ -24504,9 +19650,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // account for margin changes if ($page > $startpage) { - if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); } } @@ -24608,7 +19754,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n"; } // end for each column } - if ($cborder or $fill) { + if (!empty($cborder) OR !empty($fill)) { $offsetlen = strlen($ccode); // draw border and fill if ($this->inxobj) { @@ -24630,13 +19776,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (end($this->transfmrk[$this->page]) !== false) { $pagemarkkey = key($this->transfmrk[$this->page]); $pagemark = $this->transfmrk[$this->page][$pagemarkkey]; - $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen; } elseif ($this->InFooter) { $pagemark = $this->footerpos[$this->page]; - $this->footerpos[$this->page] += $offsetlen; } else { $pagemark = $this->intmrk[$this->page]; - $this->intmrk[$this->page] += $offsetlen; } $pagebuff = $this->getPageBuffer($this->page); $pstart = substr($pagebuff, 0, $pagemark); @@ -24656,9 +19799,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->Ln(0, $cell); $this->x = $parent['startx']; if ($endpage > $startpage) { - if (($this->rtl) and ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) { $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) and ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) { $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']); } } @@ -24667,9 +19810,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->cell_padding = $table_el['old_cell_padding']; // reset row height $this->resetLastH(); - if (($this->page == ($this->numpages - 1)) and ($this->pageopen[$this->numpages])) { + if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) { $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]); - if (($plendiff > 0) and ($plendiff < 60)) { + if (($plendiff > 0) AND ($plendiff < 60)) { $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff); if (substr($pagediff, 0, 5) == 'BT /F') { // the difference is only a font setting @@ -24685,7 +19828,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // restore top margin $this->tMargin = $this->theadMargins['top']; } - if (!isset($table_el['attribute']['nested']) or ($table_el['attribute']['nested'] != 'true')) { + if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) { // reset main table header $this->thead = ''; $this->theadMargins = array(); @@ -24696,7 +19839,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'a': { - $this->HREF = ''; + $this->HREF = array(); break; } case 'sup': { @@ -24805,12 +19948,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) { $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter']; // check for pagebreak - if (($pba == 'true') or ($pba == 'left') or ($pba == 'right')) { + if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); } - if ((($pba == 'left') and (((!$this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) - or (($pba == 'right') and (((!$this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0))))) { + if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0)))) + OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) { // add a page (or trig AcceptPageBreak() for multicolumn mode) $this->checkPageBreak($this->PageBreakTrigger + 1); } @@ -24881,21 +20024,21 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $border = 0; $fill = false; $this->lasth = 0; - if (isset($tag['border']) and !empty($tag['border'])) { + if (isset($tag['border']) AND !empty($tag['border'])) { // get border style $border = $tag['border']; - if (!$this->empty_string($this->thead) and (!$this->inthead)) { + if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) { // border for table header - $border = $this->getBorderMode($border, $position='middle'); + $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell); } } - if (isset($tag['bgcolor']) and ($tag['bgcolor'] !== false)) { + if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) { // get background color $old_bgcolor = $this->bgcolor; $this->SetFillColorArray($tag['bgcolor']); $fill = true; } - if (!$border and !$fill) { + if (!$border AND !$fill) { // nothing to draw return; } @@ -24907,7 +20050,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $cellspacing = array('H' => 0, 'V' => 0); } - if (($tag['value'] != 'table') and (is_array($border)) and (!empty($border))) { + if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) { // draw the border externally respect the sqare edge. $border['mode'] = 'ext'; } @@ -24940,9 +20083,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->num_columns = 1; } // get border modes - $border_start = $this->getBorderMode($border, $position='start'); - $border_end = $this->getBorderMode($border, $position='end'); - $border_middle = $this->getBorderMode($border, $position='middle'); + $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell); + $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell); + $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell); // temporary disable page regions $temp_page_regions = $this->page_regions; $this->page_regions = array(); @@ -24957,9 +20100,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // account for margin changes if ($page > $startpage) { - if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { + if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { + } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); } } @@ -25019,7 +20162,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n"; } // end for each column } - if ($cborder or $fill) { + if ($cborder OR $fill) { $offsetlen = strlen($ccode); // draw border and fill if ($this->inxobj) { @@ -25040,17 +20183,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (end($this->transfmrk[$this->page]) !== false) { $pagemarkkey = key($this->transfmrk[$this->page]); $pagemark = $this->transfmrk[$this->page][$pagemarkkey]; - $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen; } elseif ($this->InFooter) { $pagemark = $this->footerpos[$this->page]; - $this->footerpos[$this->page] += $offsetlen; } else { $pagemark = $this->intmrk[$this->page]; - $this->intmrk[$this->page] += $offsetlen; } $pagebuff = $this->getPageBuffer($this->page); - $pstart = substr($pagebuff, 0, $this->bordermrk[$this->page]); - $pend = substr($pagebuff, $this->bordermrk[$this->page]); + $pstart = substr($pagebuff, 0, $pagemark); + $pend = substr($pagebuff, $pagemark); $this->setPageBuffer($this->page, $pstart.$ccode.$pend); $this->bordermrk[$this->page] += $offsetlen; $this->cntmrk[$this->page] += $offsetlen; @@ -25082,32 +20222,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return; } $symbol = strtolower($symbol); - switch ($symbol) { - case '!' : - case '#' : - case 'disc' : - case 'circle' : - case 'square' : - case '1': - case 'decimal': - case 'decimal-leading-zero': - case 'i': - case 'lower-roman': - case 'I': - case 'upper-roman': - case 'a': - case 'lower-alpha': - case 'lower-latin': - case 'A': - case 'upper-alpha': - case 'upper-latin': - case 'lower-greek': { - $this->lisymbol = $symbol; - break; - } - default : { - $this->lisymbol = ''; - } + $valid_symbols = array('!', '#', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek'); + if (in_array($symbol, $valid_symbols)) { + $this->lisymbol = $symbol; + } else { + $this->lisymbol = ''; } } @@ -25197,10 +20316,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: /** * Convert HTML string containing value and unit of measure to user's units or points. - * @param $htmlval (string) string containing values and unit - * @param $refsize (string) reference value in points - * @param $defaultunit (string) default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt). - * @param $points (boolean) if true returns points, otherwise returns value in user's units + * @param $htmlval (string) String containing values and unit. + * @param $refsize (string) Reference value in points. + * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt). + * @param $points (boolean) If true returns points, otherwise returns value in user's units. * @return float value in user's unit or point if $points=true * @public * @since 4.4.004 (2008-12-10) @@ -25210,9 +20329,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $retval = 0; $value = 0; $unit = 'px'; - $k = $this->k; if ($points) { $k = 1; + } else { + $k = $this->k; } if (in_array($defaultunit, $supportedunits)) { $unit = $defaultunit; @@ -25240,107 +20360,46 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // height of lower case 'x' (about half the font-size) case 'ex': { - $retval = $value * ($refsize / 2); + $retval = ($value * ($refsize / 2)); break; } // absolute-size case 'in': { - $retval = ($value * $this->dpi) / $k; + $retval = (($value * $this->dpi) / $k); break; } // centimeters case 'cm': { - $retval = ($value / 2.54 * $this->dpi) / $k; + $retval = (($value / 2.54 * $this->dpi) / $k); break; } // millimeters case 'mm': { - $retval = ($value / 25.4 * $this->dpi) / $k; + $retval = (($value / 25.4 * $this->dpi) / $k); break; } // one pica is 12 points case 'pc': { - $retval = ($value * 12) / $k; + $retval = (($value * 12) / $k); break; } // points case 'pt': { - $retval = $value / $k; + $retval = ($value / $k); break; } // pixels case 'px': { $retval = $this->pixelsToUnits($value); + if ($points) { + $retval *= $this->k; + } break; } } return $retval; } - /** - * Returns the Roman representation of an integer number - * @param $number (int) number to convert - * @return string roman representation of the specified number - * @since 4.4.004 (2008-12-10) - * @public - */ - public function intToRoman($number) { - $roman = ''; - while ($number >= 1000) { - $roman .= 'M'; - $number -= 1000; - } - while ($number >= 900) { - $roman .= 'CM'; - $number -= 900; - } - while ($number >= 500) { - $roman .= 'D'; - $number -= 500; - } - while ($number >= 400) { - $roman .= 'CD'; - $number -= 400; - } - while ($number >= 100) { - $roman .= 'C'; - $number -= 100; - } - while ($number >= 90) { - $roman .= 'XC'; - $number -= 90; - } - while ($number >= 50) { - $roman .= 'L'; - $number -= 50; - } - while ($number >= 40) { - $roman .= 'XL'; - $number -= 40; - } - while ($number >= 10) { - $roman .= 'X'; - $number -= 10; - } - while ($number >= 9) { - $roman .= 'IX'; - $number -= 9; - } - while ($number >= 5) { - $roman .= 'V'; - $number -= 5; - } - while ($number >= 4) { - $roman .= 'IV'; - $number -= 4; - } - while ($number >= 1) { - $roman .= 'I'; - --$number; - } - return $roman; - } - /** * Output an HTML list bullet or ordered item symbol * @param $listdepth (int) list nesting level @@ -25350,6 +20409,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.4.004 (2008-12-10) */ protected function putHtmlListBullet($listdepth, $listtype='', $size=10) { + if ($this->state != 2) { + return; + } $size /= $this->k; $fill = ''; $bgcolor = $this->bgcolor; @@ -25458,12 +20520,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } case 'i': case 'lower-roman': { - $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum])); + $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum])); break; } case 'I': case 'upper-roman': { - $textitem = $this->intToRoman($this->listcount[$this->listnum]); + $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]); break; } case 'a': @@ -25479,7 +20541,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } case 'lower-greek': { - $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1); + $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode); break; } /* @@ -25513,11 +20575,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $textitem = $this->listcount[$this->listnum]; } } - if (!$this->empty_string($textitem)) { + if (!TCPDF_STATIC::empty_string($textitem)) { // Check whether we need a new page or new column $prev_y = $this->y; - $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']; - if ($this->checkPageBreak($h) or ($this->y < $prev_y)) { + $h = $this->getCellHeight($this->FontSize); + if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) { $tmpx = $this->x; } // print ordered item @@ -25610,6 +20672,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.2.010 (2008-11-14) */ protected function setGraphicVars($gvars, $extended=false) { + if ($this->state != 2) { + return; + } $this->FontFamily = $gvars['FontFamily']; $this->FontStyle = $gvars['FontStyle']; $this->FontSizePt = $gvars['FontSizePt']; @@ -25661,60 +20726,25 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->num_columns = $gvars['num_columns']; } $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.''); - if (!$this->empty_string($this->FontFamily)) { + if (!TCPDF_STATIC::empty_string($this->FontFamily)) { $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt); } } /** - * Returns a temporary filename for caching object on filesystem. - * @param $name (string) prefix to add to filename - * @return string filename. - * @since 4.5.000 (2008-12-31) + * Outputs the "save graphics state" operator 'q' * @protected */ - protected function getObjFilename($name) { - return tempnam(K_PATH_CACHE, $name.'_'); + protected function _outSaveGraphicsState() { + $this->_out('q'); } /** - * Writes data to a temporary file on filesystem. - * @param $filename (string) file name - * @param $data (mixed) data to write on file - * @param $append (boolean) if true append data, false replace. - * @since 4.5.000 (2008-12-31) + * Outputs the "restore graphics state" operator 'Q' * @protected */ - protected function writeDiskCache($filename, $data, $append=false) { - if ($append) { - $fmode = 'ab+'; - } else { - $fmode = 'wb+'; - } - $f = @fopen($filename, $fmode); - if (!$f) { - $this->Error('Unable to write cache file: '.$filename); - } else { - fwrite($f, $data); - fclose($f); - } - // update file length (needed for transactions) - if (!isset($this->cache_file_length['_'.$filename])) { - $this->cache_file_length['_'.$filename] = strlen($data); - } else { - $this->cache_file_length['_'.$filename] += strlen($data); - } - } - - /** - * Read data from a temporary file on filesystem. - * @param $filename (string) file name - * @return mixed retrieved data - * @since 4.5.000 (2008-12-31) - * @protected - */ - protected function readDiskCache($filename) { - return file_get_contents($filename); + protected function _outRestoreGraphicsState() { + $this->_out('Q'); } /** @@ -25725,14 +20755,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: */ protected function setBuffer($data) { $this->bufferlen += strlen($data); - if ($this->diskcache) { - if (!isset($this->buffer) or $this->empty_string($this->buffer)) { - $this->buffer = $this->getObjFilename('buffer'); - } - $this->writeDiskCache($this->buffer, $data, true); - } else { - $this->buffer .= $data; - } + $this->buffer .= $data; } /** @@ -25743,14 +20766,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: */ protected function replaceBuffer($data) { $this->bufferlen = strlen($data); - if ($this->diskcache) { - if (!isset($this->buffer) or $this->empty_string($this->buffer)) { - $this->buffer = $this->getObjFilename('buffer'); - } - $this->writeDiskCache($this->buffer, $data, false); - } else { - $this->buffer = $data; - } + $this->buffer = $data; } /** @@ -25760,11 +20776,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2009-01-02) */ protected function getBuffer() { - if ($this->diskcache) { - return $this->readDiskCache($this->buffer); - } else { - return $this->buffer; - } + return $this->buffer; } /** @@ -25776,19 +20788,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2008-12-31) */ protected function setPageBuffer($page, $data, $append=false) { - if ($this->diskcache) { - if (!isset($this->pages[$page])) { - $this->pages[$page] = $this->getObjFilename('page'.$page); - } - $this->writeDiskCache($this->pages[$page], $data, $append); + if ($append) { + $this->pages[$page] .= $data; } else { - if ($append) { - $this->pages[$page] .= $data; - } else { - $this->pages[$page] = $data; - } + $this->pages[$page] = $data; } - if ($append and isset($this->pagelen[$page])) { + if ($append AND isset($this->pagelen[$page])) { $this->pagelen[$page] += strlen($data); } else { $this->pagelen[$page] = strlen($data); @@ -25803,9 +20808,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2008-12-31) */ protected function getPageBuffer($page) { - if ($this->diskcache) { - return $this->readDiskCache($this->pages[$page]); - } elseif (isset($this->pages[$page])) { + if (isset($this->pages[$page])) { return $this->pages[$page]; } return false; @@ -25815,22 +20818,18 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * Set image buffer content. * @param $image (string) image key * @param $data (array) image data + * @return int image index number * @protected * @since 4.5.000 (2008-12-31) */ protected function setImageBuffer($image, $data) { - if ($this->diskcache) { - if (!isset($this->images[$image])) { - $this->images[$image] = $this->getObjFilename('image'.$image); - } - $this->writeDiskCache($this->images[$image], serialize($data)); - } else { - $this->images[$image] = $data; - } - if (!in_array($image, $this->imagekeys)) { - $this->imagekeys[] = $image; + if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) { + $this->imagekeys[$this->numimages] = $image; + $data['i'] = $this->numimages; ++$this->numimages; } + $this->images[$image] = $data; + return $data['i']; } /** @@ -25845,13 +20844,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (!isset($this->images[$image])) { $this->setImageBuffer($image, array()); } - if ($this->diskcache) { - $tmpimg = $this->getImageBuffer($image); - $tmpimg[$key] = $data; - $this->writeDiskCache($this->images[$image], serialize($tmpimg)); - } else { - $this->images[$image][$key] = $data; - } + $this->images[$image][$key] = $data; } /** @@ -25862,9 +20855,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2008-12-31) */ protected function getImageBuffer($image) { - if ($this->diskcache and isset($this->images[$image])) { - return unserialize($this->readDiskCache($this->images[$image])); - } elseif (isset($this->images[$image])) { + if (isset($this->images[$image])) { return $this->images[$image]; } return false; @@ -25878,14 +20869,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2009-01-02) */ protected function setFontBuffer($font, $data) { - if ($this->diskcache) { - if (!isset($this->fonts[$font])) { - $this->fonts[$font] = $this->getObjFilename('font'); - } - $this->writeDiskCache($this->fonts[$font], serialize($data)); - } else { - $this->fonts[$font] = $data; - } + $this->fonts[$font] = $data; if (!in_array($font, $this->fontkeys)) { $this->fontkeys[] = $font; // store object ID for current font @@ -25907,13 +20891,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (!isset($this->fonts[$font])) { $this->setFontBuffer($font, array()); } - if ($this->diskcache) { - $tmpfont = $this->getFontBuffer($font); - $tmpfont[$key] = $data; - $this->writeDiskCache($this->fonts[$font], serialize($tmpfont)); - } else { - $this->fonts[$font][$key] = $data; - } + $this->fonts[$font][$key] = $data; } /** @@ -25924,9 +20902,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2009-01-02) */ protected function getFontBuffer($font) { - if ($this->diskcache and isset($this->fonts[$font])) { - return unserialize($this->readDiskCache($this->fonts[$font])); - } elseif (isset($this->fonts[$font])) { + if (isset($this->fonts[$font])) { return $this->fonts[$font]; } return false; @@ -25941,7 +20917,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.5.000 (2009-01-02) */ public function movePage($frompage, $topage) { - if (($frompage > $this->numpages) or ($frompage <= $topage)) { + if (($frompage > $this->numpages) OR ($frompage <= $topage)) { return false; } if ($frompage == $this->page) { @@ -25968,15 +20944,15 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($this->PageAnnots[$frompage])) { $tmpannots = $this->PageAnnots[$frompage]; } - if (isset($this->newpagegroup) and !empty($this->newpagegroup)) { + if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) { for ($i = $frompage; $i > $topage; --$i) { - if (isset($this->newpagegroup[$i]) and (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) { + if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) { --$this->pagegroups[$this->newpagegroup[$i]]; break; } } for ($i = $topage; $i > 0; --$i) { - if (isset($this->newpagegroup[$i]) and (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) { + if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) { ++$this->pagegroups[$this->newpagegroup[$i]]; break; } @@ -26050,47 +21026,55 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // adjust outlines $tmpoutlines = $this->outlines; foreach ($tmpoutlines as $key => $outline) { - if (($outline['p'] >= $topage) and ($outline['p'] < $frompage)) { - $this->outlines[$key]['p'] = ($outline['p'] + 1); - } elseif ($outline['p'] == $frompage) { - $this->outlines[$key]['p'] = $topage; + if (!$outline['f']) { + if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) { + $this->outlines[$key]['p'] = ($outline['p'] + 1); + } elseif ($outline['p'] == $frompage) { + $this->outlines[$key]['p'] = $topage; + } } } // adjust dests $tmpdests = $this->dests; foreach ($tmpdests as $key => $dest) { - if (($dest['p'] >= $topage) and ($dest['p'] < $frompage)) { - $this->dests[$key]['p'] = ($dest['p'] + 1); - } elseif ($dest['p'] == $frompage) { - $this->dests[$key]['p'] = $topage; + if (!$dest['f']) { + if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) { + $this->dests[$key]['p'] = ($dest['p'] + 1); + } elseif ($dest['p'] == $frompage) { + $this->dests[$key]['p'] = $topage; + } } } // adjust links $tmplinks = $this->links; foreach ($tmplinks as $key => $link) { - if (($link[0] >= $topage) and ($link[0] < $frompage)) { - $this->links[$key][0] = ($link[0] + 1); - } elseif ($link[0] == $frompage) { - $this->links[$key][0] = $topage; + if (!$link['f']) { + if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) { + $this->links[$key]['p'] = ($link['p'] + 1); + } elseif ($link['p'] == $frompage) { + $this->links[$key]['p'] = $topage; + } } } // adjust javascript - $tmpjavascript = $this->javascript; - global $jfrompage, $jtopage; $jfrompage = $frompage; $jtopage = $topage; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jfrompage, $jtopage; - $pagenum = intval($matches[3]) + 1; - if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) { - $newpage = ($pagenum + 1); - } elseif ($pagenum == $jfrompage) { - $newpage = $jtopage; - } else { - $newpage = $pagenum; + if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) { + foreach($pamatch[0] as $pk => $pmatch) { + $pagenum = intval($pamatch[3][$pk]) + 1; + if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) { + $newpage = ($pagenum + 1); + } elseif ($pagenum == $jfrompage) { + $newpage = $jtopage; + } else { + $newpage = $pagenum; + } + --$newpage; + $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage; + $this->javascript = str_replace($pmatch, $newjs, $this->javascript); } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); + unset($pamatch); + } // return to last page $this->lastPage(true); return true; @@ -26104,7 +21088,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 4.6.004 (2009-04-23) */ public function deletePage($page) { - if (($page < 1) or ($page > $this->numpages)) { + if (($page < 1) OR ($page > $this->numpages)) { return false; } // delete current page @@ -26132,9 +21116,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($this->PageAnnots[$page])) { unset($this->PageAnnots[$page]); } - if (isset($this->newpagegroup) and !empty($this->newpagegroup)) { + if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) { for ($i = $page; $i > 0; --$i) { - if (isset($this->newpagegroup[$i]) and (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) { + if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) { --$this->pagegroups[$this->newpagegroup[$i]]; break; } @@ -26231,48 +21215,58 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // adjust outlines $tmpoutlines = $this->outlines; foreach ($tmpoutlines as $key => $outline) { - if ($outline['p'] > $page) { - $this->outlines[$key]['p'] = $outline['p'] - 1; - } elseif ($outline['p'] == $page) { - unset($this->outlines[$key]); + if (!$outline['f']) { + if ($outline['p'] > $page) { + $this->outlines[$key]['p'] = $outline['p'] - 1; + } elseif ($outline['p'] == $page) { + unset($this->outlines[$key]); + } } } // adjust dests $tmpdests = $this->dests; foreach ($tmpdests as $key => $dest) { - if ($dest['p'] > $page) { - $this->dests[$key]['p'] = $dest['p'] - 1; - } elseif ($dest['p'] == $page) { - unset($this->dests[$key]); + if (!$dest['f']) { + if ($dest['p'] > $page) { + $this->dests[$key]['p'] = $dest['p'] - 1; + } elseif ($dest['p'] == $page) { + unset($this->dests[$key]); + } } } // adjust links $tmplinks = $this->links; foreach ($tmplinks as $key => $link) { - if ($link[0] > $page) { - $this->links[$key][0] = $link[0] - 1; - } elseif ($link[0] == $page) { - unset($this->links[$key]); + if (!$link['f']) { + if ($link['p'] > $page) { + $this->links[$key]['p'] = $link['p'] - 1; + } elseif ($link['p'] == $page) { + unset($this->links[$key]); + } } } // adjust javascript - $tmpjavascript = $this->javascript; - global $jpage; $jpage = $page; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jpage; - $pagenum = intval($matches[3]) + 1; - if ($pagenum >= $jpage) { - $newpage = ($pagenum - 1); - } elseif ($pagenum == $jpage) { - $newpage = 1; - } else { - $newpage = $pagenum; + if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) { + foreach($pamatch[0] as $pk => $pmatch) { + $pagenum = intval($pamatch[3][$pk]) + 1; + if ($pagenum >= $jpage) { + $newpage = ($pagenum - 1); + } elseif ($pagenum == $jpage) { + $newpage = 1; + } else { + $newpage = $pagenum; + } + --$newpage; + $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage; + $this->javascript = str_replace($pmatch, $newjs, $this->javascript); } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); + unset($pamatch); + } // return to last page - $this->lastPage(true); + if ($this->numpages > 0) { + $this->lastPage(true); + } return true; } @@ -26288,7 +21282,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // default value $page = $this->page; } - if (($page < 1) or ($page > $this->numpages)) { + if (($page < 1) OR ($page > $this->numpages)) { return false; } // close the last page @@ -26321,21 +21315,21 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1; $this->currpagegroup = $this->newpagegroup[$this->page]; $this->pagegroups[$this->currpagegroup] = 1; - } elseif (isset($this->currpagegroup) and ($this->currpagegroup > 0)) { + } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) { ++$this->pagegroups[$this->currpagegroup]; } // copy outlines $tmpoutlines = $this->outlines; foreach ($tmpoutlines as $key => $outline) { if ($outline['p'] == $page) { - $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']); + $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 'f' => $outline['f'], 's' => $outline['s'], 'c' => $outline['c']); } } // copy links $tmplinks = $this->links; foreach ($tmplinks as $key => $link) { - if ($link[0] == $page) { - $this->links[] = array($this->page, $link[1]); + if ($link['p'] == $page) { + $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']); } } // return to last page @@ -26374,13 +21368,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $page_fill_start = false; $page_fill_end = false; $current_column = $this->current_column; - if ($this->empty_string($numbersfont)) { + if (TCPDF_STATIC::empty_string($numbersfont)) { $numbersfont = $this->default_monospaced_font; } - if ($this->empty_string($filler)) { + if (TCPDF_STATIC::empty_string($filler)) { $filler = ' '; } - if ($this->empty_string($page)) { + if (TCPDF_STATIC::empty_string($page)) { $gap = ' '; } else { $gap = ''; @@ -26393,7 +21387,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $maxpage = 0; //used for pages on attached documents foreach ($this->outlines as $key => $outline) { // check for extra pages (used for attachments) - if (($this->page > $page_first) and ($outline['p'] >= $this->numpages)) { + if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) { $outline['p'] += ($this->page - $page_first); } if ($this->rtl) { @@ -26410,9 +21404,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } $this->SetTextColorArray($outline['c']); // check for page break - $this->checkPageBreak((2 * $this->FontSize * $this->cell_height_ratio)); + $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize)); // set margins and X position - if (($this->page == $current_page) and ($this->current_column == $current_column)) { + if (($this->page == $current_page) AND ($this->current_column == $current_column)) { $this->lMargin = $lmargin; $this->rMargin = $rmargin; } else { @@ -26452,7 +21446,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $tw = $this->w - $this->rMargin - $this->x; } $this->SetFont($numbersfont, $fontstyle, $fontsize); - if ($this->empty_string($page)) { + if (TCPDF_STATIC::empty_string($page)) { $pagenum = $outline['p']; } else { // placemark to be replaced with the correct number @@ -26463,7 +21457,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $maxpage = max($maxpage, $outline['p']); } $fw = ($tw - $this->GetStringWidth($pagenum.$filler)); - $numfills = floor($fw / $this->GetStringWidth($filler)); + $wfiller = $this->GetStringWidth($filler); + if ($wfiller > 0) { + $numfills = floor($fw / $wfiller); + } else { + $numfills = 0; + } if ($numfills > 0) { $rowfill = str_repeat($filler, $numfills); } else { @@ -26482,8 +21481,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // account for booklet mode if ($this->booklet) { // check if a blank page is required before TOC - $page_fill_start = ((($page_first % 2) == 0) xor (($page % 2) == 0)); - $page_fill_end = (!((($numpages % 2) == 0) xor ($page_fill_start))); + $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0)); + $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start))); if ($page_fill_start) { // add a page at the end (to be moved before TOC) $this->addPage(); @@ -26498,7 +21497,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } $maxpage = max($maxpage, $page_last); - if (!$this->empty_string($page)) { + if (!TCPDF_STATIC::empty_string($page)) { for ($p = $page_first; $p <= $page_last; ++$p) { // get page data $temppage = $this->getPageBuffer($p); @@ -26508,20 +21507,20 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // get page number aliases $pnalias = $this->getInternalPageNumberAliases($a); // calculate replacement number - if (($n >= $page) and ($n <= $this->numpages)) { + if (($n >= $page) AND ($n <= $this->numpages)) { $np = $n + $numpages; } else { $np = $n; } - $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1)); - $nu = $this->UTF8ToUTF16BE($na, false); + $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1)); + $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont); // replace aliases with numbers foreach ($pnalias['u'] as $u) { $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' ')))); if ($this->rtl) { - $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill); + $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont); } else { - $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu; + $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu; } $temppage = str_replace($u, $nr, $temppage); } @@ -26591,12 +21590,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($this->outlines as $key => $outline) { // get HTML template $row = $templates[$outline['l']]; - if ($this->empty_string($page)) { + if (TCPDF_STATIC::empty_string($page)) { $pagenum = $outline['p']; } else { // placemark to be replaced with the correct number $pagenum = '{#'.($outline['p']).'}'; - if ($templates['F'.$outline['l']]) { + if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) { $pagenum = '{'.$pagenum.'}'; } $maxpage = max($maxpage, $outline['p']); @@ -26618,8 +21617,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // account for booklet mode if ($this->booklet) { // check if a blank page is required before TOC - $page_fill_start = ((($page_first % 2) == 0) xor (($page % 2) == 0)); - $page_fill_end = (!((($numpages % 2) == 0) xor ($page_fill_start))); + $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0)); + $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start))); if ($page_fill_start) { // add a page at the end (to be moved before TOC) $this->addPage(); @@ -26634,7 +21633,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } $maxpage = max($maxpage, $page_last); - if (!$this->empty_string($page)) { + if (!TCPDF_STATIC::empty_string($page)) { for ($p = $page_first; $p <= $page_last; ++$p) { // get page data $temppage = $this->getPageBuffer($p); @@ -26649,16 +21648,16 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $np = $n; } - $na = $this->formatTOCPageNumber(($this->starting_page_number + $np - 1)); - $nu = $this->UTF8ToUTF16BE($na, false); + $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1)); + $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont); // replace aliases with numbers foreach ($pnalias['u'] as $u) { if ($correct_align) { $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' '))); if ($this->rtl) { - $nr = $nu.$this->UTF8ToUTF16BE(' '.$sfill); + $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont); } else { - $nr = $this->UTF8ToUTF16BE($sfill.' ').$nu; + $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu; } } else { $nr = $nu; @@ -26707,7 +21706,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->start_transaction_page = $this->page; $this->start_transaction_y = $this->y; // clone current object - $this->objcopy = $this->objclone($this); + $this->objcopy = TCPDF_STATIC::objclone($this); } /** @@ -26731,14 +21730,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: */ public function rollbackTransaction($self=false) { if (isset($this->objcopy)) { - if (isset($this->objcopy->diskcache) and $this->objcopy->diskcache) { - // truncate files to previous values - foreach ($this->objcopy->cache_file_length as $file => $length) { - $file = substr($file, 1); - $handle = fopen($file, 'r+'); - ftruncate($handle, $length); - } - } $this->_destroy(true, true); if ($self) { $objvars = get_object_vars($this->objcopy); @@ -26751,44 +21742,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $this; } - /** - * Creates a copy of a class object - * @param $object (object) class object to be cloned - * @return cloned object - * @public - * @since 4.5.029 (2009-03-19) - */ - public function objclone($object) { - return @clone($object); - } - - /** - * Determine whether a string is empty. - * @param $str (string) string to be checked - * @return boolean true if string is empty - * @public - * @since 4.5.044 (2009-04-16) - */ - public function empty_string($str) { - return (is_null($str) or (is_string($str) and (strlen($str) == 0))); - } - - /** - * Find position of last occurrence of a substring in a string - * @param $haystack (string) The string to search in. - * @param $needle (string) substring to search. - * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string. - * @return Returns the position where the needle exists. Returns FALSE if the needle was not found. - * @public - * @since 4.8.038 (2010-03-13) - */ - public function revstrpos($haystack, $needle, $offset = 0) { - $length = strlen($haystack); - $offset = ($offset > 0)?($length - $offset):abs($offset); - $pos = strpos(strrev($haystack), strrev($needle), $offset); - return ($pos === false)?false:($length - $pos - strlen($needle)); - } - // --- MULTI COLUMNS METHODS ----------------------- /** @@ -26807,10 +21760,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { // maximum column width $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols; - if (($width == 0) or ($width > $maxwidth)) { + if (($width == 0) OR ($width > $maxwidth)) { $width = $maxwidth; } - if ($this->empty_string($y)) { + if (TCPDF_STATIC::empty_string($y)) { $y = $this->y; } // space between columns @@ -26875,7 +21828,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->y = $this->tMargin; } // Avoid to write table headers more than once - if (($this->page > $this->maxselcol['page']) or (($this->page == $this->maxselcol['page']) and ($col > $this->maxselcol['column']))) { + if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) { $enable_thead = true; $this->maxselcol['page'] = $this->page; $this->maxselcol['column'] = $col; @@ -26906,7 +21859,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // fix for HTML mode $this->newline = true; // print HTML table header (if any) - if ((!$this->empty_string($this->thead)) and (!$this->inthead)) { + if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) { if ($enable_thead) { // print table header $this->writeHTML($this->thead, false, false, false, false, ''); @@ -26951,17 +21904,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $this->num_columns; } - /** - * Serialize an array of parameters to be used with TCPDF tag in HTML code. - * @param $pararray (array) parameters array - * @return sting containing serialized data - * @public - * @since 4.9.006 (2010-04-02) - */ - public function serializeTCPDFtagParameters($pararray) { - return urlencode(serialize($pararray)); - } - /** * Set Text rendering mode. * @param $stroke (int) outline size in user units (0 = disable). @@ -27041,7 +21983,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $this->txtshadow['depth_h'] = 0; } - if (isset($params['color']) and ($params['color'] !== false) and is_array($params['color'])) { + if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) { $this->txtshadow['color'] = $params['color']; } else { $this->txtshadow['color'] = $this->strokecolor; @@ -27051,12 +21993,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $this->txtshadow['opacity'] = 1; } - if (isset($params['blend_mode']) and in_array($params['blend_mode'], array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) { + if (isset($params['blend_mode']) AND in_array($params['blend_mode'], array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) { $this->txtshadow['blend_mode'] = $params['blend_mode']; } else { $this->txtshadow['blend_mode'] = 'Normal'; } - if ((($this->txtshadow['depth_w'] == 0) and ($this->txtshadow['depth_h'] == 0)) or ($this->txtshadow['opacity'] == 0)) { + if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) { $this->txtshadow['enabled'] = false; } } @@ -27075,10 +22017,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * Returns an array of chars containing soft hyphens. * @param $word (array) array of chars * @param $patterns (array) Array of hypenation patterns. - * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm. + * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens. - * @param $charmin (int) Minimum word length to apply the hyphenation algoritm. + * @param $charmin (int) Minimum word length to apply the hyphenation algorithm. * @param $charmax (int) Maximum length of broken piece of word. * @return array text with soft hyphens * @author Nicola Asuni @@ -27091,7 +22033,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($numchars <= $charmin) { return $word; } - $word_string = $this->UTF8ArrSubString($word); + $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode); // some words will be returned as-is $pattern = '/^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/'; if (preg_match($pattern, $word_string) > 0) { @@ -27104,30 +22046,33 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $word; } if (isset($dictionary[$word_string])) { - return $this->UTF8StringToArray($dictionary[$word_string]); + return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont); } - // suround word with '_' characters - $tmpword = array_merge(array(95), $word, array(95)); + // surround word with '_' characters + $tmpword = array_merge(array(46), $word, array(46)); $tmpnumchars = $numchars + 2; - $maxpos = $tmpnumchars - $charmin; + $maxpos = $tmpnumchars - 1; for ($pos = 0; $pos < $maxpos; ++$pos) { $imax = min(($tmpnumchars - $pos), $charmax); - for ($i = $charmin; $i <= $imax; ++$i) { - $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i)); + for ($i = 1; $i <= $imax; ++$i) { + $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode)); if (isset($patterns[$subword])) { - $pattern = $this->UTF8StringToArray($patterns[$subword]); + $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont); $pattern_length = count($pattern); $digits = 1; for ($j = 0; $j < $pattern_length; ++$j) { - // check if $pattern[$j] is a number - if (($pattern[$j] >= 48) and ($pattern[$j] <= 57)) { + // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid) + if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) { if ($j == 0) { $zero = $pos - 1; } else { $zero = $pos + $j - $digits; } - if (!isset($hyphenword[$zero]) or ($hyphenword[$zero] != $pattern[$j])) { - $hyphenword[$zero] = $this->unichr($pattern[$j]); + // get hyphenation level + $level = ($pattern[$j] - 48); + // if two levels from two different patterns match at the same point, the higher one is selected. + if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) { + $hyphenword[$zero] = $level; } ++$digits; } @@ -27138,7 +22083,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $inserted = 0; $maxpos = $numchars - $rightmin; for ($i = $leftmin; $i <= $maxpos; ++$i) { - if (isset($hyphenword[$i]) and (($hyphenword[$i] % 2) != 0)) { + // only odd levels indicate allowed hyphenation points + if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) { // 173 = soft hyphen character array_splice($word, $i + $inserted, 0, 173); ++$inserted; @@ -27147,47 +22093,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $word; } - /** - * Returns an array of hyphenation patterns. - * @param $file (string) TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - * @return array of hyphenation patterns - * @author Nicola Asuni - * @since 4.9.012 (2010-04-12) - * @public - */ - public function getHyphenPatternsFromTEX($file) { - // TEX patterns are available at: - // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - $data = file_get_contents($file); - $patterns = array(); - // remove comments - $data = preg_replace('/\%[^\n]*/', '', $data); - // extract the patterns part - preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); - $data = trim(substr($matches[0], 10, -1)); - // extract each pattern - $patterns_array = preg_split('/[\s]+/', $data); - // create new language array of patterns - $patterns = array(); - foreach($patterns_array as $val) { - if (!$this->empty_string($val)) { - $val = trim($val); - $val = str_replace('\'', '\\\'', $val); - $key = preg_replace('/[0-9]+/', '', $val); - $patterns[$key] = $val; - } - } - return $patterns; - } - /** * Returns text with soft hyphens. * @param $text (string) text to process * @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ - * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm. + * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens. - * @param $charmin (int) Minimum word length to apply the hyphenation algoritm. + * @param $charmin (int) Minimum word length to apply the hyphenation algorithm. * @param $charmax (int) Maximum length of broken piece of word. * @return array text with soft hyphens * @author Nicola Asuni @@ -27199,19 +22112,20 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $word = array(); // last word $txtarr = array(); // text to be returned $intag = false; // true if we are inside an HTML tag + $skip = false; // true to skip hyphenation if (!is_array($patterns)) { - $patterns = $this->getHyphenPatternsFromTEX($patterns); + $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns); } // get array of characters - $unichars = $this->UTF8StringToArray($text); + $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont); // for each char foreach ($unichars as $char) { - if ((!$intag) and $this->unicode->uni_type[$char] == 'L') { + if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') { // letter character $word[] = $char; } else { // other type of character - if (!$this->empty_string($word)) { + if (!TCPDF_STATIC::empty_string($word)) { // hypenate the word $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax)); $word = array(); @@ -27220,18 +22134,35 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (chr($char) == '<') { // we are inside an HTML tag $intag = true; - } elseif ($intag and (chr($char) == '>')) { + } elseif ($intag AND (chr($char) == '>')) { // end of HTML tag $intag = false; + // check for style tag + $expected = array(115, 116, 121, 108, 101); // = 'style' + $current = array_slice($txtarr, -6, 5); // last 5 chars + $compare = array_diff($expected, $current); + if (empty($compare)) { + // check if it is a closing tag + $expected = array(47); // = '/' + $current = array_slice($txtarr, -7, 1); + $compare = array_diff($expected, $current); + if (empty($compare)) { + // closing style tag + $skip = false; + } else { + // opening style tag + $skip = true; + } + } } } } - if (!$this->empty_string($word)) { + if (!TCPDF_STATIC::empty_string($word)) { // hypenate the word $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax)); } // convert char array to string and return - return $this->UTF8ArrSubString($txtarr); + return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode); } /** @@ -27244,97 +22175,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->rasterize_vector_images = $mode; } - /** - * Get the Path-Painting Operators. - * @param $style (string) Style of rendering. Possible values are: - *
      - *
    • S or D: Stroke the path.
    • - *
    • s or d: Close and stroke the path.
    • - *
    • f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.
    • - *
    • f* or F*: Fill the path, using the even-odd rule to determine the region to fill.
    • - *
    • B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.
    • - *
    • B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.
    • - *
    • b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.
    • - *
    • b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.
    • - *
    • CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.
    • - *
    • CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path
    • - *
    • n: End the path object without filling or stroking it.
    • - *
    - * @param $default (string) default style - * @author Nicola Asuni - * @since 5.0.000 (2010-04-30) - * @protected - */ - protected function getPathPaintOperator($style, $default='S') { - $op = ''; - switch($style) { - case 'S': - case 'D': { - $op = 'S'; - break; - } - case 's': - case 'd': { - $op = 's'; - break; - } - case 'f': - case 'F': { - $op = 'f'; - break; - } - case 'f*': - case 'F*': { - $op = 'f*'; - break; - } - case 'B': - case 'FD': - case 'DF': { - $op = 'B'; - break; - } - case 'B*': - case 'F*D': - case 'DF*': { - $op = 'B*'; - break; - } - case 'b': - case 'fd': - case 'df': { - $op = 'b'; - break; - } - case 'b*': - case 'f*d': - case 'df*': { - $op = 'b*'; - break; - } - case 'CNZ': { - $op = 'W n'; - break; - } - case 'CEO': { - $op = 'W* n'; - break; - } - case 'n': { - $op = 'n'; - break; - } - default: { - if (!empty($default)) { - $op = $this->getPathPaintOperator($default, ''); - } else { - $op = ''; - } - } - } - return $op; - } - /** * Enable or disable default option for font subsetting. * @param $enable (boolean) if true enable font subsetting by default. @@ -27410,7 +22250,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @since 5.8.002 (2010-08-14) */ public function isUnicodeFont() { - return (($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0')); + return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')); } /** @@ -27423,12 +22263,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: */ public function getFontFamilyName($fontfamily) { // remove spaces and symbols - $fontfamily = preg_replace('/[^a-z0-9\,]/', '', strtolower($fontfamily)); + $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily)); // extract all font names $fontslist = preg_split('/[,]/', $fontfamily); // find first valid font name foreach ($fontslist as $font) { // replace font variations + $font = preg_replace('/regular$/', '', $font); $font = preg_replace('/italic$/', 'I', $font); $font = preg_replace('/oblique$/', 'I', $font); $font = preg_replace('/bold([I]?)$/', 'B\\1', $font); @@ -27442,7 +22283,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $pattern[] = '/^monospace/'; $replacement[] = 'courier'; $font = preg_replace($pattern, $replacement, $font); - if (in_array(strtolower($font), $this->fontlist) or in_array($font, $this->fontkeys)) { + if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) { return $font; } } @@ -27492,10 +22333,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->num_columns = 1; $this->current_column = 0; $this->SetAutoPageBreak(false); - if (($w === '') or ($w <= 0)) { + if (($w === '') OR ($w <= 0)) { $w = $this->w - $this->lMargin - $this->rMargin; } - if (($h === '') or ($h <= 0)) { + if (($h === '') OR ($h <= 0)) { $h = $this->h - $this->tMargin - $this->bMargin; } $this->xobjects[$this->xobjid]['x'] = 0; @@ -27559,6 +22400,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @see startTemplate(), endTemplate() */ public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) { + if ($this->state != 2) { + return; + } if (!isset($this->xobjects[$id])) { $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!'); } @@ -27581,9 +22425,15 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // check page for no-write regions and adapt page margins if necessary list($x, $y) = $this->checkPageRegions($h, $x, $y); $ow = $this->xobjects[$id]['w']; + if ($ow <= 0) { + $ow = 1; + } $oh = $this->xobjects[$id]['h']; + if ($oh <= 0) { + $oh = 1; + } // calculate template width and height on document - if (($w <= 0) and ($h <= 0)) { + if (($w <= 0) AND ($h <= 0)) { $w = $ow; $h = $oh; } elseif ($w <= 0) { @@ -27622,8 +22472,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // print XObject Template + Transformation matrix $this->StartTransform(); // translate and scale - $sx = ($w / $this->xobjects[$id]['w']); - $sy = ($h / $this->xobjects[$id]['h']); + $sx = ($w / $ow); + $sy = ($h / $oh); $tm = array(); $tm[0] = $sx; $tm[1] = 0; @@ -27639,10 +22489,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (!empty($this->xobjects[$id]['annotations'])) { foreach ($this->xobjects[$id]['annotations'] as $annot) { // transform original coordinates - $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k))); + $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k))); $ax = ($coordlt[4] / $this->k); $ay = ($this->h - $h - ($coordlt[5] / $this->k)); - $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k))); + $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k))); $aw = ($coordrb[4] / $this->k) - $ax; $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay; $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']); @@ -27763,12 +22613,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @see setPageRegions(), getPageRegions() */ public function addPageRegion($region) { - if (!isset($region['page']) or empty($region['page'])) { + if (!isset($region['page']) OR empty($region['page'])) { $region['page'] = $this->page; } - if (isset($region['xt']) and isset($region['xb']) and ($region['xt'] > 0) and ($region['xb'] > 0) - and isset($region['yt']) and isset($region['yb']) and ($region['yt'] >= 0) and ($region['yt'] < $region['yb']) - and isset($region['side']) and (($region['side'] == 'L') or ($region['side'] == 'R'))) { + if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0) + AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb']) + AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) { $this->page_regions[] = $region; } } @@ -27807,12 +22657,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($y === '') { $y = $this->y; } - if (empty($this->page_regions)) { + if (!$this->check_page_regions OR empty($this->page_regions)) { // no page regions defined return array($x, $y); } if (empty($h)) { - $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B']; + $h = $this->getCellHeight($this->FontSize); } // check for page break if ($this->checkPageBreak($h, $y)) { @@ -27822,22 +22672,22 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } if ($this->num_columns > 1) { if ($this->rtl) { - $this->lMargin = $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']; + $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']); } else { - $this->rMargin = $this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']; + $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']); } } else { if ($this->rtl) { - $this->lMargin = $this->original_lMargin; + $this->lMargin = max($this->clMargin, $this->original_lMargin); } else { - $this->rMargin = $this->original_rMargin; + $this->rMargin = max($this->crMargin, $this->original_rMargin); } } // adjust coordinates and page margins foreach ($this->page_regions as $regid => $regdata) { if ($regdata['page'] == $this->page) { // check region boundaries - if (($y > ($regdata['yt'] - $h)) and ($y <= $regdata['yb'])) { + if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) { // Y is inside the region $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient $yt = max($y, $regdata['yt']); @@ -27849,7 +22699,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($this->lMargin < $new_margin) { if ($this->rtl) { // adjust left page margin - $this->lMargin = $new_margin; + $this->lMargin = max(0, $new_margin); } if ($x < $new_margin) { // adjust x position @@ -27865,7 +22715,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (($this->w - $this->rMargin) > $new_margin) { if (!$this->rtl) { // adjust right page margin - $this->rMargin = ($this->w - $new_margin); + $this->rMargin = max(0, ($this->w - $new_margin)); } if ($x > $new_margin) { // adjust x position @@ -27903,18 +22753,32 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @public */ public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) { - if ($this->rasterize_vector_images and ($w > 0) and ($h > 0)) { + if ($this->state != 2) { + return; + } + // reset SVG vars + $this->svggradients = array(); + $this->svggradientid = 0; + $this->svgdefsmode = false; + $this->svgdefs = array(); + $this->svgclipmode = false; + $this->svgclippaths = array(); + $this->svgcliptm = array(); + $this->svgclipid = 0; + $this->svgtext = ''; + $this->svgtextmode = array(); + if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) { // convert SVG to raster image using GD or ImageMagick libraries return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false); } - if ($file{0} === '@') { // image from string + if ($file[0] === '@') { // image from string $this->svgdir = ''; $svgdata = substr($file, 1); } else { // SVG file $this->svgdir = dirname($file); - $svgdata = file_get_contents($file); + $svgdata = TCPDF_STATIC::fileGetContents($file); } - if ($svgdata === false) { + if ($svgdata === FALSE) { $this->Error('SVG file not found: '.$file); } if ($x === '') { @@ -27935,7 +22799,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $regs = array(); // get original image width and height preg_match('/]*)>/si', $svgdata, $regs); - if (isset($regs[1]) and !empty($regs[1])) { + if (isset($regs[1]) AND !empty($regs[1])) { $tmp = array(); if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) { $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false); @@ -27987,8 +22851,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } } + if ($ow <= 0) { + $ow = 1; + } + if ($oh <= 0) { + $oh = 1; + } // calculate image width and height on document - if (($w <= 0) and ($h <= 0)) { + if (($w <= 0) AND ($h <= 0)) { // convert image size to document unit $w = $ow; $h = $oh; @@ -28034,7 +22904,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // store SVG position and scale factors $svgoffset_x = ($ximg - $ox) * $this->k; $svgoffset_y = -($y - $oy) * $this->k; - if (isset($view_box[2]) and ($view_box[2] > 0) and ($view_box[3] > 0)) { + if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) { $ow = $view_box[2]; $oh = $view_box[3]; } else { @@ -28110,7 +22980,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // save the current graphic state $this->_out('q'.$this->epsmarker); // set initial clipping mask - $this->Rect($x, $y, $w, $h, 'CNZ', array(), array()); + $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array()); // scale and translate $e = $ox * $this->k * (1 - $svgscale_x); $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y); @@ -28196,121 +23066,6 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->cell_padding = $cell_padding; } - /** - * Get the tranformation matrix from SVG transform attribute - * @param $attribute (string) transformation - * @return array of transformations - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function getSVGTransformMatrix($attribute) { - // identity matrix - $tm = array(1, 0, 0, 1, 0, 0); - $transform = array(); - if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { - foreach ($transform as $key => $data) { - if (!empty($data[2])) { - $a = 1; - $b = 0; - $c = 0; - $d = 1; - $e = 0; - $f = 0; - $regs = array(); - switch ($data[1]) { - 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)) { - $a = $regs[1]; - $b = $regs[2]; - $c = $regs[3]; - $d = $regs[4]; - $e = $regs[5]; - $f = $regs[6]; - } - break; - } - case 'translate': { - if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $e = $regs[1]; - $f = $regs[2]; - } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $e = $regs[1]; - } - break; - } - case 'scale': { - if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $a = $regs[1]; - $d = $regs[2]; - } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $a = $regs[1]; - $d = $a; - } - break; - } - case 'rotate': { - if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { - $ang = deg2rad($regs[1]); - $x = $regs[2]; - $y = $regs[3]; - $a = cos($ang); - $b = sin($ang); - $c = -$b; - $d = $a; - $e = ($x * (1 - $a)) - ($y * $c); - $f = ($y * (1 - $d)) - ($x * $b); - } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $ang = deg2rad($regs[1]); - $a = cos($ang); - $b = sin($ang); - $c = -$b; - $d = $a; - $e = 0; - $f = 0; - } - break; - } - case 'skewX': { - if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $c = tan(deg2rad($regs[1])); - } - break; - } - case 'skewY': { - if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { - $b = tan(deg2rad($regs[1])); - } - break; - } - } - $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f)); - } - } - } - return $tm; - } - - /** - * Get the product of two SVG tranformation matrices - * @param $ta (array) first SVG tranformation matrix - * @param $tb (array) second SVG tranformation matrix - * @return transformation array - * @author Nicola Asuni - * @since 5.0.000 (2010-05-02) - * @protected - */ - protected function getTransformationMatrixProduct($ta, $tb) { - $tm = array(); - $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); - $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); - $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); - $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]); - $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4]; - $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5]; - return $tm; - } - /** * Convert SVG transformation matrix to PDF. * @param $tm (array) original SVG transformation matrix @@ -28358,8 +23113,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @protected */ protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) { + if ($this->state != 2) { + return; + } $objstyle = ''; - $minlen = (0.01 / $this->k); // minimum acceptable length (3 point) + $minlen = (0.01 / $this->k); // minimum acceptable length if (!isset($svgstyle['opacity'])) { return $objstyle; } @@ -28376,10 +23134,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false); } // color - $fill_color = $this->convertHTMLColorToDec($svgstyle['color']); + $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors); $this->SetFillColorArray($fill_color); // text color - $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']); + $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors); $this->SetTextColorArray($text_color); // clip if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) { @@ -28408,6 +23166,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $newgradient = $this->svggradients[$gradient['xref']]; $newgradient['coords'] = $gradient['coords']; $newgradient['mode'] = $gradient['mode']; + $newgradient['type'] = $gradient['type']; $newgradient['gradientUnits'] = $gradient['gradientUnits']; if (isset($gradient['gradientTransform'])) { $newgradient['gradientTransform'] = $gradient['gradientTransform']; @@ -28415,38 +23174,38 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $gradient = $newgradient; } //save current Graphic State - $this->_out('q'); + $this->_outSaveGraphicsState(); //set clipping area - if (!empty($clip_function) and method_exists($this, $clip_function)) { + if (!empty($clip_function) AND method_exists($this, $clip_function)) { $bbox = call_user_func_array(array($this, $clip_function), $clip_params); - if (is_array($bbox) and (count($bbox) == 4)) { + if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) { list($x, $y, $w, $h) = $bbox; } } if ($gradient['mode'] == 'measure') { - if (isset($gradient['gradientTransform']) and !empty($gradient['gradientTransform'])) { + if (!isset($gradient['coords'][4])) { + $gradient['coords'][4] = 0.5; + } + if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) { $gtm = $gradient['gradientTransform']; // apply transformation matrix $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4]; $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5]; $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4]; $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5]; - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2)); - } + $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2)); $gradient['coords'][0] = $xa; $gradient['coords'][1] = $ya; $gradient['coords'][2] = $xb; $gradient['coords'][3] = $yb; + $gradient['coords'][4] = $r; } // convert SVG coordinates to user units $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false); $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false); $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false); $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false); - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false); - } + $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false); if ($w <= $minlen) { $w = $minlen; } @@ -28466,9 +23225,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h); $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w); $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h); - if (isset($gradient['coords'][4])) { - $gradient['coords'][4] /= $w; - } + $gradient['coords'][4] /= $w; } elseif ($gradient['mode'] == 'percentage') { foreach($gradient['coords'] as $key => $val) { $gradient['coords'][$key] = (intval($val) / 100); @@ -28479,7 +23236,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } } } - if (($gradient['type'] == 2) and ($gradient['coords'][0] == $gradient['coords'][2]) and ($gradient['coords'][1] == $gradient['coords'][3])) { + if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) { // single color (no shading) $gradient['coords'][0] = 1; $gradient['coords'][1] = 0; @@ -28491,18 +23248,20 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $gradient['coords'][1] = $gradient['coords'][3]; $gradient['coords'][3] = $tmp; // set transformation map for gradient + $cy = ($this->h - $y); if ($gradient['type'] == 3) { // circular gradient - $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h)); - $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($w * $this->k), ($x * $this->k), ($cy * $this->k))); + $cy -= ($gradient['coords'][1] * ($w + $h)); + $h = $w = max($w, $h); } else { - $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), (($this->h - ($y + $h)) * $this->k))); + $cy -= $h; } + $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k))); if (count($gradient['stops']) > 1) { $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false); } } elseif ($svgstyle['fill'] != 'none') { - $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']); + $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors); if ($svgstyle['fill-opacity'] != 1) { $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false); } @@ -28517,14 +23276,16 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($svgstyle['stroke'] != 'none') { if ($svgstyle['stroke-opacity'] != 1) { $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false); + } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) { + $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false); } $stroke_style = array( - 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']), + 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors), 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false), 'cap' => $svgstyle['stroke-linecap'], 'join' => $svgstyle['stroke-linejoin'] ); - if (isset($svgstyle['stroke-dasharray']) and !empty($svgstyle['stroke-dasharray']) and ($svgstyle['stroke-dasharray'] != 'none')) { + if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) { $stroke_style['dash'] = $svgstyle['stroke-dasharray']; } $this->SetLineStyle($stroke_style); @@ -28571,7 +23332,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $font_stretch = $svgstyle['font-stretch']; $font_spacing = $svgstyle['letter-spacing']; } - $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k; + $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit); $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']); $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']); switch ($font_style) { @@ -28595,6 +23356,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $font_style .= 'B'; break; } + case 'normal': { + if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) { + $font_family = substr($font_family, 0, -2).'I'; + } elseif (substr($font_family, -1) == 'B') { + $font_family = substr($font_family, 0, -1); + } + break; + } } switch ($svgstyle['text-decoration']) { case 'underline': { @@ -28639,8 +23408,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @protected */ protected function SVGPath($d, $style='') { + if ($this->state != 2) { + return; + } // set fill/stroke style - $op = $this->getPathPaintOperator($style, ''); + $op = TCPDF_STATIC::getPathPaintOperator($style, ''); if (empty($op)) { return; } @@ -28657,6 +23429,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $xmax = 0; $ymin = 2147483647; $ymax = 0; + $xinitial = 0; + $yinitial = 0; $relcoord = false; $minlen = (0.01 / $this->k); // minimum acceptable length (3 point) $firstcmd = true; // used to print first point @@ -28682,7 +23456,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($rawparams as $ck => $cp) { $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false); if (abs($params[$ck]) < $minlen) { - // aproximate little values to zero + // approximate little values to zero $params[$ck] = 0; } } @@ -28697,10 +23471,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $x = $cp + $xoffset; } else { $y = $cp + $yoffset; - if ($firstcmd or (abs($x0 - $x) >= $minlen) or (abs($y0 - $y) >= $minlen)) { + if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { if ($ck == 1) { $this->_outPoint($x, $y); $firstcmd = false; + $xinitial = $x; + $yinitial = $y; } else { $this->_outLine($x, $y); } @@ -28725,7 +23501,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $x = $cp + $xoffset; } else { $y = $cp + $yoffset; - if ((abs($x0 - $x) >= $minlen) or (abs($y0 - $y) >= $minlen)) { + if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { $this->_outLine($x, $y); $x0 = $x; $y0 = $y; @@ -28745,7 +23521,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'H': { // horizontal lineto foreach ($params as $ck => $cp) { $x = $cp + $xoffset; - if ((abs($x0 - $x) >= $minlen) or (abs($y0 - $y) >= $minlen)) { + if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { $this->_outLine($x, $y); $x0 = $x; $y0 = $y; @@ -28761,7 +23537,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'V': { // vertical lineto foreach ($params as $ck => $cp) { $y = $cp + $yoffset; - if ((abs($x0 - $x) >= $minlen) or (abs($y0 - $y) >= $minlen)) { + if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) { $this->_outLine($x, $y); $x0 = $x; $y0 = $y; @@ -28801,7 +23577,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: foreach ($params as $ck => $cp) { $params[$ck] = $cp; if ((($ck + 1) % 4) == 0) { - if (($key > 0) and ((strtoupper($paths[($key - 1)][1]) == 'C') or (strtoupper($paths[($key - 1)][1]) == 'S'))) { + if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) { $x1 = (2 * $x) - $x2; $y1 = (2 * $y) - $y2; } else { @@ -28825,7 +23601,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } break; } - case 'Q': { // quadratic B�zier curveto + case 'Q': { // quadratic Bezier curveto foreach ($params as $ck => $cp) { $params[$ck] = $cp; if ((($ck + 1) % 4) == 0) { @@ -28851,11 +23627,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } break; } - case 'T': { // shorthand/smooth quadratic B�zier curveto + case 'T': { // shorthand/smooth quadratic Bezier curveto foreach ($params as $ck => $cp) { $params[$ck] = $cp; if (($ck % 2) != 0) { - if (($key > 0) and ((strtoupper($paths[($key - 1)][1]) == 'Q') or (strtoupper($paths[($key - 1)][1]) == 'T'))) { + if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) { $x1 = (2 * $x) - $x1; $y1 = (2 * $y) - $y1; } else { @@ -28888,15 +23664,15 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ((($ck + 1) % 7) == 0) { $x0 = $x; $y0 = $y; - $rx = abs($params[($ck - 6)]); - $ry = abs($params[($ck - 5)]); + $rx = max(abs($params[($ck - 6)]), .000000001); + $ry = max(abs($params[($ck - 5)]), .000000001); $ang = -$rawparams[($ck - 4)]; $angle = deg2rad($ang); $fa = $rawparams[($ck - 3)]; // large-arc-flag $fs = $rawparams[($ck - 2)]; // sweep-flag $x = $params[($ck - 1)] + $xoffset; $y = $params[$ck] + $yoffset; - if ((abs($x0 - $x) < $minlen) and (abs($y0 - $y) < $minlen)) { + if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) { // endpoints are almost identical $xmin = min($xmin, $x); $ymin = min($ymin, $y); @@ -28935,15 +23711,15 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2); $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2); // get angles - $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry)); - $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry)); - if (($fs == 0) and ($dang > 0)) { + $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry)); + $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry)); + if (($fs == 0) AND ($dang > 0)) { $dang -= (2 * M_PI); - } elseif (($fs == 1) and ($dang < 0)) { + } elseif (($fs == 1) AND ($dang < 0)) { $dang += (2 * M_PI); } $angf = $angs - $dang; - if ((($fs == 0) and ($angs > $angf)) or (($fs == 1) and ($angs < $angf))) { + if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) { // reverse angles $tmp = $angs; $angs = $angf; @@ -28952,12 +23728,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $angs = round(rad2deg($angs), 6); $angf = round(rad2deg($angf), 6); // covent angles to positive values - if (($angs < 0) and ($angf < 0)) { + if (($angs < 0) AND ($angf < 0)) { $angs += 360; $angf += 360; } $pie = false; - if (($key == 0) and (isset($paths[($key + 1)][1])) and (trim($paths[($key + 1)][1]) == 'z')) { + if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) { $pie = true; } list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true); @@ -28976,6 +23752,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } case 'Z': { $this->_out('h'); + $x = $x0 = $xinitial; + $y = $y0 = $yinitial; break; } } @@ -28988,27 +23766,16 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } /** - * Returns the angle in radiants between two vectors - * @param $x1 (int) X coordinate of first vector point - * @param $y1 (int) Y coordinate of first vector point - * @param $x2 (int) X coordinate of second vector point - * @param $y2 (int) Y coordinate of second vector point - * @author Nicola Asuni - * @since 5.0.000 (2010-05-04) + * Return the tag name without the namespace + * @param $name (string) Tag name * @protected */ - protected function getVectorsAngle($x1, $y1, $x2, $y2) { - $dprod = ($x1 * $x2) + ($y1 * $y2); - $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); - $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); - $angle = acos($dprod / ($dist1 * $dist2)); - if (is_nan($angle)) { - $angle = M_PI; + protected function removeTagNamespace($name) { + if(strpos($name, ':') !== false) { + $parts = explode(':', $name); + return $parts[(sizeof($parts) - 1)]; } - if ((($x1 * $y2) - ($x2 * $y1)) < 0) { - $angle *= -1; - } - return $angle; + return $name; } /** @@ -29022,16 +23789,26 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @protected */ protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) { + $name = $this->removeTagNamespace($name); // check if we are in clip mode if ($this->svgclipmode) { $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]); return; } - if ($this->svgdefsmode and !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) { - if (!isset($attribs['id'])) { - $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1); + if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) { + if (isset($attribs['id'])) { + $attribs['child_elements'] = array(); + $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs); + return; + } + if (end($this->svgdefs) !== FALSE) { + $last_svgdefs_id = key($this->svgdefs); + if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) { + $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1); + $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs); + return; + } } - $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs); return; } $clipping = false; @@ -29040,32 +23817,32 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $clipping = true; } // get styling properties - $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style + $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style $svgstyle = $this->svgstyles[0]; // set default style - if ($clipping and !isset($attribs['fill']) and (!isset($attribs['style']) or (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) { + if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) { // default fill attribute for clipping $attribs['fill'] = 'none'; } - if (isset($attribs['style']) and !$this->empty_string($attribs['style'])) { + if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) { // fix style for regular expression $attribs['style'] = ';'.$attribs['style']; } foreach ($prev_svgstyle as $key => $val) { - if (in_array($key, $this->svginheritprop)) { + if (in_array($key, TCPDF_IMAGES::$svginheritprop)) { // inherit previous value $svgstyle[$key] = $val; } - if (isset($attribs[$key]) and !$this->empty_string($attribs[$key])) { + if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) { // specific attribute settings if ($attribs[$key] == 'inherit') { $svgstyle[$key] = $val; } else { $svgstyle[$key] = $attribs[$key]; } - } elseif (isset($attribs['style']) and !$this->empty_string($attribs['style'])) { + } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) { // CSS style syntax $attrval = array(); - if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) and isset($attrval[1])) { + if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) { if ($attrval[1] == 'inherit') { $svgstyle[$key] = $val; } else { @@ -29078,15 +23855,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (!empty($ctm)) { $tm = $ctm; } else { - //$tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix']; $tm = array(1,0,0,1,0,0); } - if (isset($attribs['transform']) and !empty($attribs['transform'])) { - $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform'])); + if (isset($attribs['transform']) AND !empty($attribs['transform'])) { + $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform'])); } $svgstyle['transfmatrix'] = $tm; $invisible = false; - if (($svgstyle['visibility'] == 'hidden') or ($svgstyle['visibility'] == 'collapse') or ($svgstyle['display'] == 'none')) { + if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) { // the current graphics element is invisible (nothing is painted) $invisible = true; } @@ -29112,12 +23888,91 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } case 'svg': { // start of SVG object + if(++$this->svg_tag_depth <= 1) { + break; + } + // inner SVG + array_push($this->svgstyles, $svgstyle); + $this->StartTransform(); + $svgX = (isset($attribs['x'])?$attribs['x']:0); + $svgY = (isset($attribs['y'])?$attribs['y']:0); + $svgW = (isset($attribs['width'])?$attribs['width']:0); + $svgH = (isset($attribs['height'])?$attribs['height']:0); + // set x, y position using transform matrix + $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY)); + $this->SVGTransform($tm); + // set clipping for width and height + $x = 0; + $y = 0; + $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w); + $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h); + // draw clipping rect + $this->Rect($x, $y, $w, $h, 'CNZ', array(), array()); + // parse viewbox, calculate extra transformation matrix + if (isset($attribs['viewBox'])) { + $tmp = array(); + preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp); + $tmp = $tmp[0]; + if (sizeof($tmp) == 4) { + $vx = $tmp[0]; + $vy = $tmp[1]; + $vw = $tmp[2]; + $vh = $tmp[3]; + // get aspect ratio + $tmp = array(); + $aspectX = 'xMid'; + $aspectY = 'YMid'; + $fit = 'meet'; + if (isset($attribs['preserveAspectRatio'])) { + if($attribs['preserveAspectRatio'] == 'none') { + $fit = 'none'; + } else { + preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp); + $tmp = $tmp[0]; + if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) { + $aspectX = substr($tmp[0], 0, 4); + $aspectY = substr($tmp[0], 4, 4); + $fit = $tmp[1]; + } + } + } + $wr = ($svgW / $vw); + $hr = ($svgH / $vh); + $ax = $ay = 0; + if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) { + if ($aspectX == 'xMax') { + $ax = (($vw * ($wr / $hr)) - $vw); + } + if ($aspectX == 'xMid') { + $ax = ((($vw * ($wr / $hr)) - $vw) / 2); + } + $wr = $hr; + } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) { + if ($aspectY == 'YMax') { + $ay = (($vh * ($hr / $wr)) - $vh); + } + if ($aspectY == 'YMid') { + $ay = ((($vh * ($hr / $wr)) - $vh) / 2); + } + $hr = $wr; + } + $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY)); + $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm); + $this->SVGTransform($tm); + } + } + $this->setSVGStyles($svgstyle, $prev_svgstyle); break; } case 'g': { // group together related graphics elements array_push($this->svgstyles, $svgstyle); $this->StartTransform(); + $x = (isset($attribs['x'])?$attribs['x']:0); + $y = (isset($attribs['y'])?$attribs['y']:0); + $w = 1;//(isset($attribs['width'])?$attribs['width']:1); + $h = 1;//(isset($attribs['height'])?$attribs['height']:1); + $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y)); $this->SVGTransform($tm); $this->setSVGStyles($svgstyle, $prev_svgstyle); break; @@ -29139,11 +23994,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox'; } //$attribs['spreadMethod'] - if (((!isset($attribs['x1'])) and (!isset($attribs['y1'])) and (!isset($attribs['x2'])) and (!isset($attribs['y2']))) - or ((isset($attribs['x1']) and (substr($attribs['x1'], -1) == '%')) - or (isset($attribs['y1']) and (substr($attribs['y1'], -1) == '%')) - or (isset($attribs['x2']) and (substr($attribs['x2'], -1) == '%')) - or (isset($attribs['y2']) and (substr($attribs['y2'], -1) == '%')))) { + if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2']))) + OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%')) + OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%')) + OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%')) + OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) { $this->svggradients[$this->svggradientid]['mode'] = 'percentage'; } else { $this->svggradients[$this->svggradientid]['mode'] = 'measure'; @@ -29153,10 +24008,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $x2 = (isset($attribs['x2'])?$attribs['x2']:'100'); $y2 = (isset($attribs['y2'])?$attribs['y2']:'0'); if (isset($attribs['gradientTransform'])) { - $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']); + $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']); } $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2); - if (isset($attribs['xlink:href']) and !empty($attribs['xlink:href'])) { + if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) { // gradient is defined on another place $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1); } @@ -29179,10 +24034,12 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox'; } //$attribs['spreadMethod'] - if (((!isset($attribs['cx'])) and (!isset($attribs['cy']))) - or ((isset($attribs['cx']) and (substr($attribs['cx'], -1) == '%')) - or (isset($attribs['cy']) and (substr($attribs['cy'], -1) == '%')))) { + if (((!isset($attribs['cx'])) AND (!isset($attribs['cy']))) + OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%')) + OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) { $this->svggradients[$this->svggradientid]['mode'] = 'percentage'; + } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) { + $this->svggradients[$this->svggradientid]['mode'] = 'ratio'; } else { $this->svggradients[$this->svggradientid]['mode'] = 'measure'; } @@ -29192,10 +24049,10 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy); $r = (isset($attribs['r']) ? $attribs['r'] : 0.5); if (isset($attribs['gradientTransform'])) { - $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']); + $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']); } $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r); - if (isset($attribs['xlink:href']) and !empty($attribs['xlink:href'])) { + if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) { // gradient is defined on another place $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1); } @@ -29204,14 +24061,14 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: case 'stop': { // gradient stops if (substr($attribs['offset'], -1) == '%') { - $offset = floatval(substr($attribs['offset'], -1)) / 100; + $offset = floatval(substr($attribs['offset'], 0, -1)) / 100; } else { $offset = floatval($attribs['offset']); if ($offset > 1) { $offset /= 100; } } - $stop_color = isset($svgstyle['stop-color'])?$this->convertHTMLColorToDec($svgstyle['stop-color']):'black'; + $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black'; $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1; $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity); break; @@ -29224,13 +24081,18 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($attribs['d'])) { $d = trim($attribs['d']); if (!empty($d)) { + $x = (isset($attribs['x'])?$attribs['x']:0); + $y = (isset($attribs['y'])?$attribs['y']:0); + $w = (isset($attribs['width'])?$attribs['width']:1); + $h = (isset($attribs['height'])?$attribs['height']:1); + $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y)); if ($clipping) { $this->SVGTransform($tm); $this->SVGPath($d, 'CNZ'); } else { $this->StartTransform(); $this->SVGTransform($tm); - $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ')); + $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ')); if (!empty($obstyle)) { $this->SVGPath($d, $obstyle); } @@ -29399,7 +24261,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if ($invisible) { break; } - if (!isset($attribs['xlink:href']) or empty($attribs['xlink:href'])) { + if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) { break; } $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0); @@ -29416,13 +24278,13 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $img = '@'.base64_decode(substr($img, strlen($m[0]))); } else { // fix image path - if (!$this->empty_string($this->svgdir) and (($img{0} == '.') or (basename($img) == $img))) { + if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) { // replace relative path with full server path $img = $this->svgdir.'/'.$img; } - if (($img[0] == '/') and !empty($_SERVER['DOCUMENT_ROOT']) and ($_SERVER['DOCUMENT_ROOT'] != '/')) { + if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']); - if (($findroot === false) or ($findroot > 1)) { + if (($findroot === false) OR ($findroot > 1)) { if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') { $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img; } else { @@ -29432,12 +24294,45 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } $img = urldecode($img); $testscrtype = @parse_url($img); - if (!isset($testscrtype['query']) or empty($testscrtype['query'])) { + if (empty($testscrtype['query'])) { // convert URL to server path $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img); + } elseif (preg_match('|^https?://|', $img) !== 1) { + // convert server path to URL + $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img); } } - $this->Image($img, $x, $y, $w, $h); + // get image type + $imgtype = TCPDF_IMAGES::getImageFileType($img); + if (($imgtype == 'eps') OR ($imgtype == 'ai')) { + $this->ImageEps($img, $x, $y, $w, $h); + } elseif ($imgtype == 'svg') { + // store SVG vars + $svggradients = $this->svggradients; + $svggradientid = $this->svggradientid; + $svgdefsmode = $this->svgdefsmode; + $svgdefs = $this->svgdefs; + $svgclipmode = $this->svgclipmode; + $svgclippaths = $this->svgclippaths; + $svgcliptm = $this->svgcliptm; + $svgclipid = $this->svgclipid; + $svgtext = $this->svgtext; + $svgtextmode = $this->svgtextmode; + $this->ImageSVG($img, $x, $y, $w, $h); + // restore SVG vars + $this->svggradients = $svggradients; + $this->svggradientid = $svggradientid; + $this->svgdefsmode = $svgdefsmode; + $this->svgdefs = $svgdefs; + $this->svgclipmode = $svgclipmode; + $this->svgclippaths = $svgclippaths; + $this->svgcliptm = $svgcliptm; + $this->svgclipid = $svgclipid; + $this->svgtext = $svgtext; + $this->svgtextmode = $svgtextmode; + } else { + $this->Image($img, $x, $y, $w, $h); + } $this->StopTransform(); } break; @@ -29445,6 +24340,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: // text case 'text': case 'tspan': { + if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) { + // @TODO: unsupported feature + } // only basic support - advanced features must be implemented $this->svgtextmode['invisible'] = $invisible; if ($invisible) { @@ -29458,6 +24356,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $x = 0; } + if (isset($attribs['dx'])) { + $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false); + } if (isset($attribs['y'])) { $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false); } elseif ($name == 'tspan') { @@ -29465,6 +24366,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $y = 0; } + if (isset($attribs['dy'])) { + $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false); + } $svgstyle['text-color'] = $svgstyle['fill']; $this->svgtext = ''; if (isset($svgstyle['text-anchor'])) { @@ -29481,7 +24385,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } else { $this->svgtextmode['rtl'] = false; } - if (isset($svgstyle['stroke']) and ($svgstyle['stroke'] != 'none') and isset($svgstyle['stroke-width']) and ($svgstyle['stroke-width'] > 0)) { + if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) { $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false); } else { $this->svgtextmode['stroke'] = false; @@ -29495,7 +24399,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: } // use case 'use': { - if (isset($attribs['xlink:href']) and !empty($attribs['xlink:href'])) { + if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) { $svgdefid = substr($attribs['xlink:href'], 1); if (isset($this->svgdefs[$svgdefid])) { $use = $this->svgdefs[$svgdefid]; @@ -29505,8 +24409,22 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: if (isset($attribs['id'])) { unset($attribs['id']); } - $attribs = array_merge($attribs, $use['attribs']); + if (isset($use['attribs']['x']) AND isset($attribs['x'])) { + $attribs['x'] += $use['attribs']['x']; + } + if (isset($use['attribs']['y']) AND isset($attribs['y'])) { + $attribs['y'] += $use['attribs']['y']; + } + if (empty($attribs['style'])) { + $attribs['style'] = ''; + } + if (!empty($use['attribs']['style'])) { + // merge styles + $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']); + } + $attribs = array_merge($use['attribs'], $attribs); $this->startSVGElementHandler($parser, $use['name'], $attribs); + return; } } break; @@ -29515,6 +24433,21 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: break; } } // end of switch + // process child elements + if (!empty($attribs['child_elements'])) { + $child_elements = $attribs['child_elements']; + unset($attribs['child_elements']); + foreach($child_elements as $child_element) { + if (empty($child_element['attribs']['closing_tag'])) { + $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']); + } else { + if (isset($child_element['attribs']['content'])) { + $this->svgtext = $child_element['attribs']['content']; + } + $this->endSVGElementHandler('child-tag', $child_element['name']); + } + } + } } /** @@ -29526,6 +24459,25 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: * @protected */ protected function endSVGElementHandler($parser, $name) { + $name = $this->removeTagNamespace($name); + if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {; + if (end($this->svgdefs) !== FALSE) { + $last_svgdefs_id = key($this->svgdefs); + if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) { + foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) { + if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) { + $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext)); + return; + } + } + if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) { + $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext)); + return; + } + } + } + return; + } switch($name) { case 'defs': { $this->svgdefsmode = false; @@ -29536,6 +24488,11 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->svgclipmode = false; break; } + case 'svg': { + if (--$this->svg_tag_depth <= 0) { + break; + } + } case 'g': { // ungroup: remove last style from array array_pop($this->svgstyles); @@ -29577,6 +24534,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $tmpx = $this->x; $tmpy = $this->y; } + // print the text $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T'); if ($name == 'text') { // restore coordinates @@ -29588,7 +24546,9 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $this->textstrokewidth = $textstrokewidth; $this->svgtext = ''; $this->StopTransform(); - array_pop($this->svgstyles); + if (!$this->svgdefsmode) { + array_pop($this->svgstyles); + } break; } default: { @@ -29616,4 +24576,3 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: //============================================================+ // END OF FILE //============================================================+ - diff --git a/tools/tcpdf/tcpdf_autoconfig.php b/tools/tcpdf/tcpdf_autoconfig.php new file mode 100644 index 000000000..6ec9ce83b --- /dev/null +++ b/tools/tcpdf/tcpdf_autoconfig.php @@ -0,0 +1,241 @@ +. +// +// See LICENSE.TXT file for more information. +// ------------------------------------------------------------------- +// +// Description : Try to automatically configure some TCPDF +// constants if not defined. +// +//============================================================+ + +/** + * @file + * Try to automatically configure some TCPDF constants if not defined. + * @package com.tecnick.tcpdf + * @version 1.1.1 + */ + +// DOCUMENT_ROOT fix for IIS Webserver +if ((!isset($_SERVER['DOCUMENT_ROOT'])) OR (empty($_SERVER['DOCUMENT_ROOT']))) { + if(isset($_SERVER['SCRIPT_FILENAME'])) { + $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']))); + } elseif(isset($_SERVER['PATH_TRANSLATED'])) { + $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF']))); + } else { + // define here your DOCUMENT_ROOT path if the previous fails (e.g. '/var/www') + $_SERVER['DOCUMENT_ROOT'] = '/'; + } +} +$_SERVER['DOCUMENT_ROOT'] = str_replace('//', '/', $_SERVER['DOCUMENT_ROOT']); +if (substr($_SERVER['DOCUMENT_ROOT'], -1) != '/') { + $_SERVER['DOCUMENT_ROOT'] .= '/'; +} + +// Load main configuration file only if the K_TCPDF_EXTERNAL_CONFIG constant is set to false. +if (!defined('K_TCPDF_EXTERNAL_CONFIG') OR !K_TCPDF_EXTERNAL_CONFIG) { + // define a list of default config files in order of priority + $tcpdf_config_files = array(dirname(__FILE__).'/config/tcpdf_config.php', '/etc/php-tcpdf/tcpdf_config.php', '/etc/tcpdf/tcpdf_config.php', '/etc/tcpdf_config.php'); + foreach ($tcpdf_config_files as $tcpdf_config) { + if (@file_exists($tcpdf_config) AND is_readable($tcpdf_config)) { + require_once($tcpdf_config); + break; + } + } +} + +if (!defined('K_PATH_MAIN')) { + define ('K_PATH_MAIN', dirname(__FILE__).'/'); +} + +if (!defined('K_PATH_FONTS')) { + define ('K_PATH_FONTS', K_PATH_MAIN.'fonts/'); +} + +if (!defined('K_PATH_URL')) { + $k_path_url = K_PATH_MAIN; // default value for console mode + if (isset($_SERVER['HTTP_HOST']) AND (!empty($_SERVER['HTTP_HOST']))) { + if(isset($_SERVER['HTTPS']) AND (!empty($_SERVER['HTTPS'])) AND (strtolower($_SERVER['HTTPS']) != 'off')) { + $k_path_url = 'https://'; + } else { + $k_path_url = 'http://'; + } + $k_path_url .= $_SERVER['HTTP_HOST']; + $k_path_url .= str_replace( '\\', '/', substr(K_PATH_MAIN, (strlen($_SERVER['DOCUMENT_ROOT']) - 1))); + } + define ('K_PATH_URL', $k_path_url); +} + +if (!defined('K_PATH_IMAGES')) { + $tcpdf_images_dirs = array(K_PATH_MAIN.'examples/images/', K_PATH_MAIN.'images/', '/usr/share/doc/php-tcpdf/examples/images/', '/usr/share/doc/tcpdf/examples/images/', '/usr/share/doc/php/tcpdf/examples/images/', '/var/www/tcpdf/images/', '/var/www/html/tcpdf/images/', '/usr/local/apache2/htdocs/tcpdf/images/', K_PATH_MAIN); + foreach ($tcpdf_images_dirs as $tcpdf_images_path) { + if (@file_exists($tcpdf_images_path)) { + define ('K_PATH_IMAGES', $tcpdf_images_path); + break; + } + } +} + +if (!defined('PDF_HEADER_LOGO')) { + $tcpdf_header_logo = ''; + if (@file_exists(K_PATH_IMAGES.'tcpdf_logo.jpg')) { + $tcpdf_header_logo = 'tcpdf_logo.jpg'; + } + define ('PDF_HEADER_LOGO', $tcpdf_header_logo); +} + +if (!defined('PDF_HEADER_LOGO_WIDTH')) { + if (!empty($tcpdf_header_logo)) { + define ('PDF_HEADER_LOGO_WIDTH', 30); + } else { + define ('PDF_HEADER_LOGO_WIDTH', 0); + } +} + +if (!defined('K_PATH_CACHE')) { + $K_PATH_CACHE = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); + if (substr($K_PATH_CACHE, -1) != '/') { + $K_PATH_CACHE .= '/'; + } + define ('K_PATH_CACHE', $K_PATH_CACHE); +} + +if (!defined('K_BLANK_IMAGE')) { + define ('K_BLANK_IMAGE', '_blank.png'); +} + +if (!defined('PDF_PAGE_FORMAT')) { + define ('PDF_PAGE_FORMAT', 'A4'); +} + +if (!defined('PDF_PAGE_ORIENTATION')) { + define ('PDF_PAGE_ORIENTATION', 'P'); +} + +if (!defined('PDF_CREATOR')) { + define ('PDF_CREATOR', 'TCPDF'); +} + +if (!defined('PDF_AUTHOR')) { + define ('PDF_AUTHOR', 'TCPDF'); +} + +if (!defined('PDF_HEADER_TITLE')) { + define ('PDF_HEADER_TITLE', 'TCPDF Example'); +} + +if (!defined('PDF_HEADER_STRING')) { + define ('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org"); +} + +if (!defined('PDF_UNIT')) { + define ('PDF_UNIT', 'mm'); +} + +if (!defined('PDF_MARGIN_HEADER')) { + define ('PDF_MARGIN_HEADER', 5); +} + +if (!defined('PDF_MARGIN_FOOTER')) { + define ('PDF_MARGIN_FOOTER', 10); +} + +if (!defined('PDF_MARGIN_TOP')) { + define ('PDF_MARGIN_TOP', 27); +} + +if (!defined('PDF_MARGIN_BOTTOM')) { + define ('PDF_MARGIN_BOTTOM', 25); +} + +if (!defined('PDF_MARGIN_LEFT')) { + define ('PDF_MARGIN_LEFT', 15); +} + +if (!defined('PDF_MARGIN_RIGHT')) { + define ('PDF_MARGIN_RIGHT', 15); +} + +if (!defined('PDF_FONT_NAME_MAIN')) { + define ('PDF_FONT_NAME_MAIN', 'helvetica'); +} + +if (!defined('PDF_FONT_SIZE_MAIN')) { + define ('PDF_FONT_SIZE_MAIN', 10); +} + +if (!defined('PDF_FONT_NAME_DATA')) { + define ('PDF_FONT_NAME_DATA', 'helvetica'); +} + +if (!defined('PDF_FONT_SIZE_DATA')) { + define ('PDF_FONT_SIZE_DATA', 8); +} + +if (!defined('PDF_FONT_MONOSPACED')) { + define ('PDF_FONT_MONOSPACED', 'courier'); +} + +if (!defined('PDF_IMAGE_SCALE_RATIO')) { + define ('PDF_IMAGE_SCALE_RATIO', 1.25); +} + +if (!defined('HEAD_MAGNIFICATION')) { + define('HEAD_MAGNIFICATION', 1.1); +} + +if (!defined('K_CELL_HEIGHT_RATIO')) { + define('K_CELL_HEIGHT_RATIO', 1.25); +} + +if (!defined('K_TITLE_MAGNIFICATION')) { + define('K_TITLE_MAGNIFICATION', 1.3); +} + +if (!defined('K_SMALL_RATIO')) { + define('K_SMALL_RATIO', 2/3); +} + +if (!defined('K_THAI_TOPCHARS')) { + define('K_THAI_TOPCHARS', true); +} + +if (!defined('K_TCPDF_CALLS_IN_HTML')) { + define('K_TCPDF_CALLS_IN_HTML', false); +} + +if (!defined('K_TCPDF_THROW_EXCEPTION_ERROR')) { + define('K_TCPDF_THROW_EXCEPTION_ERROR', false); +} + +if (!defined('K_TIMEZONE')) { + define('K_TIMEZONE', @date_default_timezone_get()); +} + +//============================================================+ +// END OF FILE +//============================================================+ diff --git a/tools/tcpdf/barcodes.php b/tools/tcpdf/tcpdf_barcodes_1d.php similarity index 90% rename from tools/tcpdf/barcodes.php rename to tools/tcpdf/tcpdf_barcodes_1d.php index 04e7dd1c6..78bfc5b5b 100644 --- a/tools/tcpdf/barcodes.php +++ b/tools/tcpdf/tcpdf_barcodes_1d.php @@ -1,13 +1,13 @@ * @package com.tecnick.tcpdf - * @version 1.0.024 + * @version 1.0.027 * @author Nicola Asuni */ class TCPDFBarcode { @@ -67,7 +67,7 @@ class TCPDFBarcode { *
  • $arrcode['bcode'][$k]['h'] bar height in units.
  • *
  • $arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)
  • * @param $code (string) code to print - * @param $type (string) type of barcode:
    • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
    • C39+ : CODE 39 with checksum
    • C39E : CODE 39 EXTENDED
    • C39E+ : CODE 39 EXTENDED + CHECKSUM
    • C93 : CODE 93 - USS-93
    • S25 : Standard 2 of 5
    • S25+ : Standard 2 of 5 + CHECKSUM
    • I25 : Interleaved 2 of 5
    • I25+ : Interleaved 2 of 5 + CHECKSUM
    • C128 : CODE 128
    • C128A : CODE 128 A
    • C128B : CODE 128 B
    • C128C : CODE 128 C
    • EAN2 : 2-Digits UPC-Based Extention
    • EAN5 : 5-Digits UPC-Based Extention
    • EAN8 : EAN 8
    • EAN13 : EAN 13
    • UPCA : UPC-A
    • UPCE : UPC-E
    • MSI : MSI (Variation of Plessey code)
    • MSI+ : MSI + CHECKSUM (modulo 11)
    • POSTNET : POSTNET
    • PLANET : PLANET
    • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
    • KIX : KIX (Klant index - Customer index)
    • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
    • CODABAR : CODABAR
    • CODE11 : CODE 11
    • PHARMA : PHARMACODE
    • PHARMA2T : PHARMACODE TWO-TRACKS
    + * @param $type (string) type of barcode:
    • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
    • C39+ : CODE 39 with checksum
    • C39E : CODE 39 EXTENDED
    • C39E+ : CODE 39 EXTENDED + CHECKSUM
    • C93 : CODE 93 - USS-93
    • S25 : Standard 2 of 5
    • S25+ : Standard 2 of 5 + CHECKSUM
    • I25 : Interleaved 2 of 5
    • I25+ : Interleaved 2 of 5 + CHECKSUM
    • C128 : CODE 128
    • C128A : CODE 128 A
    • C128B : CODE 128 B
    • C128C : CODE 128 C
    • EAN2 : 2-Digits UPC-Based Extension
    • EAN5 : 5-Digits UPC-Based Extension
    • EAN8 : EAN 8
    • EAN13 : EAN 13
    • UPCA : UPC-A
    • UPCE : UPC-E
    • MSI : MSI (Variation of Plessey code)
    • MSI+ : MSI + CHECKSUM (modulo 11)
    • POSTNET : POSTNET
    • PLANET : PLANET
    • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
    • KIX : KIX (Klant index - Customer index)
    • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
    • CODABAR : CODABAR
    • CODE11 : CODE 11
    • PHARMA : PHARMACODE
    • PHARMA2T : PHARMACODE TWO-TRACKS
    * @public */ public function __construct($code, $type) { @@ -162,6 +162,25 @@ class TCPDFBarcode { return $html; } + /** + * Send a PNG image representation of barcode (requires GD or Imagick library). + * @param $w (int) Width of a single bar element in pixels. + * @param $h (int) Height of a single bar element in pixels. + * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent). + * @public + */ + public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) { + $data = $this->getBarcodePngData($w, $h, $color); + // send headers + header('Content-Type: image/png'); + header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 + header('Pragma: public'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + //header('Content-Length: '.strlen($data)); + echo $data; + } + /** * Return a PNG image representation of barcode (requires GD or Imagick library). * @param $w (int) Width of a single bar element in pixels. @@ -170,7 +189,7 @@ class TCPDFBarcode { * @return image or false in case of error. * @public */ - public function getBarcodePNG($w=2, $h=30, $color=array(0, 0, 0)) { + public function getBarcodePngData($w=2, $h=30, $color=array(0,0,0)) { // calculate image size $width = ($this->barcode_array['maxw'] * $w); $height = $h; @@ -208,25 +227,22 @@ class TCPDFBarcode { } $x += $bw; } - // send headers - header('Content-Type: image/png'); - header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); if ($imagick) { $png->drawimage($bar); - echo $png; + return $png; } else { + ob_start(); imagepng($png); + $imagedata = ob_get_clean(); imagedestroy($png); + return $imagedata; } } /** * Set the barcode. * @param $code (string) code to print - * @param $type (string) type of barcode:
    • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
    • C39+ : CODE 39 with checksum
    • C39E : CODE 39 EXTENDED
    • C39E+ : CODE 39 EXTENDED + CHECKSUM
    • C93 : CODE 93 - USS-93
    • S25 : Standard 2 of 5
    • S25+ : Standard 2 of 5 + CHECKSUM
    • I25 : Interleaved 2 of 5
    • I25+ : Interleaved 2 of 5 + CHECKSUM
    • C128 : CODE 128
    • C128A : CODE 128 A
    • C128B : CODE 128 B
    • C128C : CODE 128 C
    • EAN2 : 2-Digits UPC-Based Extention
    • EAN5 : 5-Digits UPC-Based Extention
    • EAN8 : EAN 8
    • EAN13 : EAN 13
    • UPCA : UPC-A
    • UPCE : UPC-E
    • MSI : MSI (Variation of Plessey code)
    • MSI+ : MSI + CHECKSUM (modulo 11)
    • POSTNET : POSTNET
    • PLANET : PLANET
    • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
    • KIX : KIX (Klant index - Customer index)
    • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
    • CODABAR : CODABAR
    • CODE11 : CODE 11
    • PHARMA : PHARMACODE
    • PHARMA2T : PHARMACODE TWO-TRACKS
    + * @param $type (string) type of barcode:
    • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
    • C39+ : CODE 39 with checksum
    • C39E : CODE 39 EXTENDED
    • C39E+ : CODE 39 EXTENDED + CHECKSUM
    • C93 : CODE 93 - USS-93
    • S25 : Standard 2 of 5
    • S25+ : Standard 2 of 5 + CHECKSUM
    • I25 : Interleaved 2 of 5
    • I25+ : Interleaved 2 of 5 + CHECKSUM
    • C128 : CODE 128
    • C128A : CODE 128 A
    • C128B : CODE 128 B
    • C128C : CODE 128 C
    • EAN2 : 2-Digits UPC-Based Extension
    • EAN5 : 5-Digits UPC-Based Extension
    • EAN8 : EAN 8
    • EAN13 : EAN 13
    • UPCA : UPC-A
    • UPCE : UPC-E
    • MSI : MSI (Variation of Plessey code)
    • MSI+ : MSI + CHECKSUM (modulo 11)
    • POSTNET : POSTNET
    • PLANET : PLANET
    • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
    • KIX : KIX (Klant index - Customer index)
    • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
    • IMBPRE: Pre-processed Intelligent Mail Barcode - Onecode - USPS-B-3200, using only F,A,D,T letters
    • CODABAR : CODABAR
    • CODE11 : CODE 11
    • PHARMA : PHARMACODE
    • PHARMA2T : PHARMACODE TWO-TRACKS
    * @return array barcode array * @public */ @@ -284,11 +300,11 @@ class TCPDFBarcode { $arrcode = $this->barcode_c128($code, 'C'); break; } - case 'EAN2': { // 2-Digits UPC-Based Extention + case 'EAN2': { // 2-Digits UPC-Based Extension $arrcode = $this->barcode_eanext($code, 2); break; } - case 'EAN5': { // 5-Digits UPC-Based Extention + case 'EAN5': { // 5-Digits UPC-Based Extension $arrcode = $this->barcode_eanext($code, 5); break; } @@ -336,6 +352,10 @@ class TCPDFBarcode { $arrcode = $this->barcode_imb($code); break; } + case 'IMBPRE': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200- pre-processed + $arrcode = $this->barcode_imb_pre($code); + break; + } case 'CODABAR': { // CODABAR $arrcode = $this->barcode_codabar($code); break; @@ -433,7 +453,7 @@ class TCPDFBarcode { $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { - $char = $code{$i}; + $char = $code[$i]; if(!isset($chr[$char])) { // invalid character return false; @@ -444,7 +464,7 @@ class TCPDFBarcode { } else { $t = false; // space } - $w = $chr[$char]{$j}; + $w = $chr[$char][$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; @@ -500,10 +520,10 @@ class TCPDFBarcode { $code_ext = ''; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { - if (ord($code{$i}) > 127) { + if (ord($code[$i]) > 127) { return false; } - $code_ext .= $encode[$code{$i}]; + $code_ext .= $encode[$code[$i]]; } return $code_ext; } @@ -523,7 +543,7 @@ class TCPDFBarcode { $sum = 0; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { - $k = array_keys($chars, $code{$i}); + $k = array_keys($chars, $code[$i]); $sum += $k[0]; } $j = ($sum % 43); @@ -623,10 +643,10 @@ class TCPDFBarcode { $code_ext = ''; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { - if (ord($code{$i}) > 127) { + if (ord($code[$i]) > 127) { return false; } - $code_ext .= $encode[$code{$i}]; + $code_ext .= $encode[$code[$i]]; } // checksum $code_ext .= $this->checksum_code93($code_ext); @@ -636,7 +656,7 @@ class TCPDFBarcode { $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { - $char = ord($code{$i}); + $char = ord($code[$i]); if(!isset($chr[$char])) { // invalid character return false; @@ -647,7 +667,7 @@ class TCPDFBarcode { } else { $t = false; // space } - $w = $chr[$char]{$j}; + $w = $chr[$char][$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; @@ -679,7 +699,7 @@ class TCPDFBarcode { $p = 1; $check = 0; for ($i = ($len - 1); $i >= 0; --$i) { - $k = array_keys($chars, $code{$i}); + $k = array_keys($chars, $code[$i]); $check += ($k[0] * $p); ++$p; if ($p > 20) { @@ -693,7 +713,7 @@ class TCPDFBarcode { $p = 1; $check = 0; for ($i = $len; $i >= 0; --$i) { - $k = array_keys($chars, $code{$i}); + $k = array_keys($chars, $code[$i]); $check += ($k[0] * $p); ++$p; if ($p > 15) { @@ -718,11 +738,11 @@ class TCPDFBarcode { $len = strlen($code); $sum = 0; for ($i = 0; $i < $len; $i+=2) { - $sum += $code{$i}; + $sum += $code[$i]; } $sum *= 3; for ($i = 1; $i < $len; $i+=2) { - $sum += ($code{$i}); + $sum += ($code[$i]); } $r = $sum % 10; if($r > 0) { @@ -763,7 +783,7 @@ class TCPDFBarcode { $p = 2; $check = 0; for ($i = ($clen - 1); $i >= 0; --$i) { - $check += (hexdec($code{$i}) * $p); + $check += (hexdec($code[$i]) * $p); ++$p; if ($p > 7) { $p = 2; @@ -778,7 +798,7 @@ class TCPDFBarcode { $seq = '110'; // left guard $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { - $digit = $code{$i}; + $digit = $code[$i]; if (!isset($chr[$digit])) { // invalid character return false; @@ -821,7 +841,7 @@ class TCPDFBarcode { $seq = '11011010'; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { - $digit = $code{$i}; + $digit = $code[$i]; if (!isset($chr[$digit])) { // invalid character return false; @@ -847,8 +867,8 @@ class TCPDFBarcode { $k = 0; for ($i = 0; $i < $len; ++$i) { $w += 1; - if (($i == ($len - 1)) or (($i < ($len - 1)) and ($seq{$i} != $seq{($i+1)}))) { - if ($seq{$i} == '1') { + if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq[$i] != $seq[($i+1)]))) { + if ($seq[$i] == '1') { $t = true; // bar } else { $t = false; // space @@ -899,9 +919,9 @@ class TCPDFBarcode { $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; $i = ($i + 2)) { - $char_bar = $code{$i}; - $char_space = $code{$i+1}; - if((!isset($chr[$char_bar])) or (!isset($chr[$char_space]))) { + $char_bar = $code[$i]; + $char_space = $code[$i+1]; + if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) { // invalid character return false; } @@ -909,7 +929,7 @@ class TCPDFBarcode { $seq = ''; $chrlen = strlen($chr[$char_bar]); for ($s = 0; $s < $chrlen; $s++){ - $seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s}; + $seq .= $chr[$char_bar][$s] . $chr[$char_space][$s]; } $seqlen = strlen($seq); for ($j = 0; $j < $seqlen; ++$j) { @@ -918,7 +938,7 @@ class TCPDFBarcode { } else { $t = false; // space } - $w = $seq{$j}; + $w = $seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; @@ -1059,17 +1079,17 @@ class TCPDFBarcode { $fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100); // array of symbols $code_data = array(); - // lenght of the code + // length of the code $len = strlen($code); switch(strtoupper($type)) { case 'A': { // MODE A $startid = 103; for ($i = 0; $i < $len; ++$i) { - $char = $code{$i}; + $char = $code[$i]; $char_id = ord($char); - if (($char_id >= 241) and ($char_id <= 244)) { + if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_a[$char_id]; - } elseif (($char_id >= 0) and ($char_id <= 95)) { + } elseif (($char_id >= 0) AND ($char_id <= 95)) { $code_data[] = strpos($keys_a, $char); } else { return false; @@ -1080,11 +1100,11 @@ class TCPDFBarcode { case 'B': { // MODE B $startid = 104; for ($i = 0; $i < $len; ++$i) { - $char = $code{$i}; + $char = $code[$i]; $char_id = ord($char); - if (($char_id >= 241) and ($char_id <= 244)) { + if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_b[$char_id]; - } elseif (($char_id >= 32) and ($char_id <= 127)) { + } elseif (($char_id >= 32) AND ($char_id <= 127)) { $code_data[] = strpos($keys_b, $char); } else { return false; @@ -1094,7 +1114,7 @@ class TCPDFBarcode { } case 'C': { // MODE C $startid = 105; - if (ord($code{0}) == 241) { + if (ord($code[0]) == 241) { $code_data[] = 102; $code = substr($code, 1); --$len; @@ -1104,7 +1124,7 @@ class TCPDFBarcode { return false; } for ($i = 0; $i < $len; $i+=2) { - $chrnum = $code{$i}.$code{$i+1}; + $chrnum = $code[$i].$code[$i+1]; if (preg_match('/([0-9]{2})/', $chrnum) > 0) { $code_data[] = intval($chrnum); } else { @@ -1119,7 +1139,7 @@ class TCPDFBarcode { // get numeric sequences (if any) $numseq = array(); preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE); - if (isset($numseq[1]) and !empty($numseq[1])) { + if (isset($numseq[1]) AND !empty($numseq[1])) { $end_offset = 0; foreach ($numseq[1] as $val) { $offset = $val[1]; @@ -1150,7 +1170,7 @@ class TCPDFBarcode { if ($key == 0) { $startid = 103; } elseif ($sequence[($key - 1)][0] != 'A') { - if (($seq[2] == 1) and ($key > 0) and ($sequence[($key - 1)][0] == 'B') and (!isset($sequence[($key - 1)][3]))) { + if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (!isset($sequence[($key - 1)][3]))) { // single character shift $code_data[] = 98; // mark shift @@ -1160,9 +1180,9 @@ class TCPDFBarcode { } } for ($i = 0; $i < $seq[2]; ++$i) { - $char = $seq[1]{$i}; + $char = $seq[1][$i]; $char_id = ord($char); - if (($char_id >= 241) and ($char_id <= 244)) { + if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_a[$char_id]; } else { $code_data[] = strpos($keys_a, $char); @@ -1172,8 +1192,8 @@ class TCPDFBarcode { } case 'B': { if ($key == 0) { - $tmpchr = ord($seq[1]{0}); - if (($seq[2] == 1) and ($tmpchr >= 241) and ($tmpchr <= 244) and isset($sequence[($key + 1)]) and ($sequence[($key + 1)][0] != 'B')) { + $tmpchr = ord($seq[1][0]); + if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) { switch ($sequence[($key + 1)][0]) { case 'A': { $startid = 103; @@ -1193,7 +1213,7 @@ class TCPDFBarcode { $startid = 104; } } elseif ($sequence[($key - 1)][0] != 'B') { - if (($seq[2] == 1) and ($key > 0) and ($sequence[($key - 1)][0] == 'A') and (!isset($sequence[($key - 1)][3]))) { + if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (!isset($sequence[($key - 1)][3]))) { // single character shift $code_data[] = 98; // mark shift @@ -1203,9 +1223,9 @@ class TCPDFBarcode { } } for ($i = 0; $i < $seq[2]; ++$i) { - $char = $seq[1]{$i}; + $char = $seq[1][$i]; $char_id = ord($char); - if (($char_id >= 241) and ($char_id <= 244)) { + if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_b[$char_id]; } else { $code_data[] = strpos($keys_b, $char); @@ -1220,7 +1240,7 @@ class TCPDFBarcode { $code_data[] = 99; } for ($i = 0; $i < $seq[2]; $i+=2) { - $chrnum = $seq[1]{$i}.$seq[1]{$i+1}; + $chrnum = $seq[1][$i].$seq[1][$i+1]; $code_data[] = intval($chrnum); } break; @@ -1251,7 +1271,7 @@ class TCPDFBarcode { } else { $t = false; // space } - $w = $seq{$j}; + $w = $seq[$j]; $bararray['bcode'][] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; } @@ -1271,7 +1291,7 @@ class TCPDFBarcode { // get A sequences (if any) $numseq = array(); preg_match_all('/([\0-\31])/', $code, $numseq, PREG_OFFSET_CAPTURE); - if (isset($numseq[1]) and !empty($numseq[1])) { + if (isset($numseq[1]) AND !empty($numseq[1])) { $end_offset = 0; foreach ($numseq[1] as $val) { $offset = $val[1]; @@ -1317,14 +1337,14 @@ class TCPDFBarcode { // calculate check digit $sum_a = 0; for ($i = 1; $i < $data_len; $i+=2) { - $sum_a += $code{$i}; + $sum_a += $code[$i]; } if ($len > 12) { $sum_a *= 3; } $sum_b = 0; for ($i = 0; $i < $data_len; $i+=2) { - $sum_b += ($code{$i}); + $sum_b += ($code[$i]); } if ($len < 13) { $sum_b *= 3; @@ -1336,7 +1356,7 @@ class TCPDFBarcode { if ($code_len == $data_len) { // add check digit $code .= $r; - } elseif ($r !== intval($code{$data_len})) { + } elseif ($r !== intval($code[$data_len])) { // wrong checkdigit return false; } @@ -1348,7 +1368,7 @@ class TCPDFBarcode { if ($upce) { // convert UPC-A to UPC-E $tmp = substr($code, 4, 3); - if (($tmp == '000') or ($tmp == '100') or ($tmp == '200')) { + if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) { // manufacturer code ends in 000, 100, or 200 $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1); } else { @@ -1445,27 +1465,27 @@ class TCPDFBarcode { $seq = '101'; // left guard bar if ($upce) { $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $p = $upce_parities[$code{1}][$r]; + $p = $upce_parities[$code[1]][$r]; for ($i = 0; $i < 6; ++$i) { - $seq .= $codes[$p[$i]][$upce_code{$i}]; + $seq .= $codes[$p[$i]][$upce_code[$i]]; } $seq .= '010101'; // right guard bar } else { $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $half_len = ceil($len / 2); + $half_len = intval(ceil($len / 2)); if ($len == 8) { for ($i = 0; $i < $half_len; ++$i) { - $seq .= $codes['A'][(string)$code{(int)$i}]; + $seq .= $codes['A'][$code[$i]]; } } else { - $p = $parities[$code{0}]; + $p = $parities[$code[0]]; for ($i = 1; $i < $half_len; ++$i) { - $seq .= $codes[$p[$i-1]][(string)$code{(int)$i}]; + $seq .= $codes[$p[$i-1]][$code[$i]]; } } $seq .= '01010'; // center guard bar for ($i = $half_len; $i < $len; ++$i) { - $seq .= $codes['C'][(string)$code{(int)$i}]; + $seq .= $codes['C'][$code[$i]]; } $seq .= '101'; // right guard bar } @@ -1473,8 +1493,8 @@ class TCPDFBarcode { $w = 0; for ($i = 0; $i < $clen; ++$i) { $w += 1; - if (($i == ($clen - 1)) or (($i < ($clen - 1)) and ($seq{$i} != $seq{($i+1)}))) { - if ($seq{$i} == '1') { + if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq[$i] != $seq[$i+1]))) { + if ($seq[$i] == '1') { $t = true; // bar } else { $t = false; // space @@ -1489,7 +1509,7 @@ class TCPDFBarcode { } /** - * UPC-Based Extentions + * UPC-Based Extensions * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers * 5-Digit Ext.: Used to mark suggested retail price of books * @param $code (string) code to represent. @@ -1504,7 +1524,7 @@ class TCPDFBarcode { if ($len == 2) { $r = $code % 4; } elseif ($len == 5) { - $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3})); + $r = (3 * ($code[0] + $code[2] + $code[4])) + (9 * ($code[1] + $code[3])); $r %= 10; } else { return false; @@ -1555,10 +1575,10 @@ class TCPDFBarcode { ); $p = $parities[$len][$r]; $seq = '1011'; // left guard bar - $seq .= $codes[$p[0]][$code{0}]; + $seq .= $codes[$p[0]][$code[0]]; for ($i = 1; $i < $len; ++$i) { $seq .= '01'; // separator - $seq .= $codes[$p[$i]][$code{$i}]; + $seq .= $codes[$p[$i]][$code[$i]]; } $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); @@ -1573,32 +1593,32 @@ class TCPDFBarcode { * @protected */ protected function barcode_postnet($code, $planet=false) { - // bar lenght + // bar length if ($planet) { - $barlen = array( - 0 => array(1,1,2,2,2), - 1 => array(2,2,2,1,1), - 2 => array(2,2,1,2,1), - 3 => array(2,2,1,1,2), - 4 => array(2,1,2,2,1), - 5 => array(2,1,2,1,2), - 6 => array(2,1,1,2,2), - 7 => array(1,2,2,2,1), - 8 => array(1,2,2,1,2), - 9 => array(1,2,1,2,2) + $barlen = Array( + 0 => Array(1,1,2,2,2), + 1 => Array(2,2,2,1,1), + 2 => Array(2,2,1,2,1), + 3 => Array(2,2,1,1,2), + 4 => Array(2,1,2,2,1), + 5 => Array(2,1,2,1,2), + 6 => Array(2,1,1,2,2), + 7 => Array(1,2,2,2,1), + 8 => Array(1,2,2,1,2), + 9 => Array(1,2,1,2,2) ); } else { - $barlen = array( - 0 => array(2,2,1,1,1), - 1 => array(1,1,1,2,2), - 2 => array(1,1,2,1,2), - 3 => array(1,1,2,2,1), - 4 => array(1,2,1,1,2), - 5 => array(1,2,1,2,1), - 6 => array(1,2,2,1,1), - 7 => array(2,1,1,1,2), - 8 => array(2,1,1,2,1), - 9 => array(2,1,2,1,1) + $barlen = Array( + 0 => Array(2,2,1,1,1), + 1 => Array(1,1,1,2,2), + 2 => Array(1,1,2,1,2), + 3 => Array(1,1,2,2,1), + 4 => Array(1,2,1,1,2), + 5 => Array(1,2,1,2,1), + 6 => Array(1,2,2,1,1), + 7 => Array(2,1,1,1,2), + 8 => Array(2,1,1,2,1), + 9 => Array(2,1,2,1,1) ); } $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); @@ -1609,7 +1629,7 @@ class TCPDFBarcode { // calculate checksum $sum = 0; for ($i = 0; $i < $len; ++$i) { - $sum += intval($code{$i}); + $sum += intval($code[$i]); } $chkd = ($sum % 10); if($chkd > 0) { @@ -1623,7 +1643,7 @@ class TCPDFBarcode { $bararray['maxw'] += 2; for ($i = 0; $i < $len; ++$i) { for ($j = 0; $j < 5; ++$j) { - $h = $barlen[$code{$i}][$j]; + $h = $barlen[$code[$i]][$j]; $p = floor(1 / $h); $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); @@ -1736,12 +1756,12 @@ class TCPDFBarcode { $row = 0; $col = 0; for ($i = 0; $i < $len; ++$i) { - $row += $checktable[$code{$i}][0]; - $col += $checktable[$code{$i}][1]; + $row += $checktable[$code[$i]][0]; + $col += $checktable[$code[$i]][1]; } $row %= 6; $col %= 6; - $chk = array_keys($checktable, array($row, $col)); + $chk = array_keys($checktable, array($row,$col)); $code .= $chk[0]; ++$len; } @@ -1754,7 +1774,7 @@ class TCPDFBarcode { } for ($i = 0; $i < $len; ++$i) { for ($j = 0; $j < 4; ++$j) { - switch ($barmode[$code{$i}][$j]) { + switch ($barmode[$code[$i]][$j]) { case 1: { $p = 0; $h = 2; @@ -1826,17 +1846,17 @@ class TCPDFBarcode { $code = 'A'.strtoupper($code).'A'; $len = strlen($code); for ($i = 0; $i < $len; ++$i) { - if (!isset($chr[$code{$i}])) { + if (!isset($chr[$code[$i]])) { return false; } - $seq = $chr[$code{$i}]; + $seq = $chr[$code[$i]]; for ($j = 0; $j < 8; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } - $w = $seq{$j}; + $w = $seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; @@ -1876,7 +1896,7 @@ class TCPDFBarcode { $p = 1; $check = 0; for ($i = ($len - 1); $i >= 0; --$i) { - $digit = $code{$i}; + $digit = $code[$i]; if ($digit == '-') { $dval = 10; } else { @@ -1898,7 +1918,7 @@ class TCPDFBarcode { $p = 1; $check = 0; for ($i = $len; $i >= 0; --$i) { - $digit = $code{$i}; + $digit = $code[$i]; if ($digit == '-') { $dval = 10; } else { @@ -1917,17 +1937,17 @@ class TCPDFBarcode { $code = 'S'.$code.'S'; $len += 3; for ($i = 0; $i < $len; ++$i) { - if (!isset($chr[$code{$i}])) { + if (!isset($chr[$code[$i]])) { return false; } - $seq = $chr[$code{$i}]; + $seq = $chr[$code[$i]]; for ($j = 0; $j < 6; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } - $w = $seq{$j}; + $w = $seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; @@ -1996,7 +2016,7 @@ class TCPDFBarcode { $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); $len = strlen($seq); for ($i = 0; $i < $len; ++$i) { - switch ($seq{$i}) { + switch ($seq[$i]) { case '1': { $p = 1; $h = 1; @@ -2022,7 +2042,6 @@ class TCPDFBarcode { return $bararray; } - /** * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 * (requires PHP bcmath extension) @@ -2068,9 +2087,9 @@ class TCPDFBarcode { } } $binary_code = bcmul($binary_code, 10); - $binary_code = bcadd($binary_code, $tracking_number{0}); + $binary_code = bcadd($binary_code, $tracking_number[0]); $binary_code = bcmul($binary_code, 5); - $binary_code = bcadd($binary_code, $tracking_number{1}); + $binary_code = bcadd($binary_code, $tracking_number[1]); $binary_code .= substr($tracking_number, 2, 18); // convert to hexadecimal $binary_code = $this->dec_to_hex($binary_code); @@ -2124,7 +2143,7 @@ class TCPDFBarcode { for ($i = 0; $i < 65; ++$i) { $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0); $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0); - if ($asc and $dsc) { + if ($asc AND $dsc) { // full bar (F) $p = 0; $h = 3; @@ -2150,6 +2169,57 @@ class TCPDFBarcode { return $bararray; } + /** + * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 + * + * @param $code (string) pre-formatted IMB barcode (65 chars "FADT") + * @return array barcode representation. + * @protected + */ + protected function barcode_imb_pre($code) { + if (!preg_match('/^[fadtFADT]{65}$/', $code) == 1) { + return false; + } + $characters = str_split(strtolower($code), 1); + // build bars + $k = 0; + $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); + for ($i = 0; $i < 65; ++$i) { + switch($characters[$i]) { + case 'f': { + // full bar + $p = 0; + $h = 3; + break; + } + case 'a': { + // ascender + $p = 0; + $h = 2; + break; + } + case 'd': { + // descender + $p = 1; + $h = 2; + break; + } + case 't': { + // tracker (short) + $p = 1; + $h = 1; + break; + } + } + $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); + $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); + $bararray['maxw'] += 2; + } + unset($bararray['bcode'][($k - 1)]); + --$bararray['maxw']; + return $bararray; + } + /** * Convert large integer number to hexadecimal representation. * (requires PHP bcmath extension) @@ -2185,7 +2255,7 @@ class TCPDFBarcode { $bitval = 1; $len = strlen($hex); for($pos = ($len - 1); $pos >= 0; --$pos) { - $dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval)); + $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval)); $bitval = bcmul($bitval, 16); } return $dec; @@ -2285,4 +2355,3 @@ class TCPDFBarcode { //============================================================+ // END OF FILE //============================================================+ - diff --git a/tools/tcpdf/tcpdf_barcodes_2d.php b/tools/tcpdf/tcpdf_barcodes_2d.php new file mode 100644 index 000000000..13e236552 --- /dev/null +++ b/tools/tcpdf/tcpdf_barcodes_2d.php @@ -0,0 +1,349 @@ +. +// +// See LICENSE.TXT file for more information. +// ------------------------------------------------------------------- +// +// Description : PHP class to creates array representations for +// 2D barcodes to be used with TCPDF. +// +//============================================================+ + +/** + * @file + * PHP class to creates array representations for 2D barcodes to be used with TCPDF. + * @package com.tecnick.tcpdf + * @author Nicola Asuni + * @version 1.0.015 + */ + +/** + * @class TCPDF2DBarcode + * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org). + * @package com.tecnick.tcpdf + * @version 1.0.015 + * @author Nicola Asuni + */ +class TCPDF2DBarcode { + + /** + * Array representation of barcode. + * @protected + */ + protected $barcode_array = false; + + /** + * This is the class constructor. + * Return an array representations for 2D barcodes:
      + *
    • $arrcode['code'] code to be printed on text label
    • + *
    • $arrcode['num_rows'] required number of rows
    • + *
    • $arrcode['num_cols'] required number of columns
    • + *
    • $arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)
    + * @param $code (string) code to print + * @param $type (string) type of barcode:
    • DATAMATRIX : Datamatrix (ISO/IEC 16022)
    • PDF417 : PDF417 (ISO/IEC 15438:2006)
    • PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
    • QRCODE : QRcode Low error correction
    • QRCODE,L : QRcode Low error correction
    • QRCODE,M : QRcode Medium error correction
    • QRCODE,Q : QRcode Better error correction
    • QRCODE,H : QR-CODE Best error correction
    • RAW: raw mode - comma-separad list of array rows
    • RAW2: raw mode - array rows are surrounded by square parenthesis.
    • TEST : Test matrix
    + */ + public function __construct($code, $type) { + $this->setBarcode($code, $type); + } + + /** + * Return an array representations of barcode. + * @return array + */ + public function getBarcodeArray() { + return $this->barcode_array; + } + + /** + * Send barcode as SVG image object to the standard output. + * @param $w (int) Width of a single rectangle element in user units. + * @param $h (int) Height of a single rectangle element in user units. + * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). + * @public + */ + public function getBarcodeSVG($w=3, $h=3, $color='black') { + // send headers + $code = $this->getBarcodeSVGcode($w, $h, $color); + header('Content-Type: application/svg+xml'); + header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 + header('Pragma: public'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); + //header('Content-Length: '.strlen($code)); + echo $code; + } + + /** + * Return a SVG string representation of barcode. + * @param $w (int) Width of a single rectangle element in user units. + * @param $h (int) Height of a single rectangle element in user units. + * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). + * @return string SVG code. + * @public + */ + public function getBarcodeSVGcode($w=3, $h=3, $color='black') { + // replace table for special characters + $repstr = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); + $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n"; + $svg .= ''."\n"; + $svg .= ''."\n"; + $svg .= "\t".''.strtr($this->barcode_array['code'], $repstr).''."\n"; + $svg .= "\t".''."\n"; + // print barcode elements + $y = 0; + // for each row + for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { + $x = 0; + // for each column + for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { + if ($this->barcode_array['bcode'][$r][$c] == 1) { + // draw a single barcode cell + $svg .= "\t\t".''."\n"; + } + $x += $w; + } + $y += $h; + } + $svg .= "\t".''."\n"; + $svg .= ''."\n"; + return $svg; + } + + /** + * Return an HTML representation of barcode. + * @param $w (int) Width of a single rectangle element in pixels. + * @param $h (int) Height of a single rectangle element in pixels. + * @param $color (string) Foreground color for bar elements (background is transparent). + * @return string HTML code. + * @public + */ + public function getBarcodeHTML($w=10, $h=10, $color='black') { + $html = '
    '."\n"; + // print barcode elements + $y = 0; + // for each row + for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { + $x = 0; + // for each column + for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { + if ($this->barcode_array['bcode'][$r][$c] == 1) { + // draw a single barcode cell + $html .= '
     
    '."\n"; + } + $x += $w; + } + $y += $h; + } + $html .= '
    '."\n"; + return $html; + } + + /** + * Send a PNG image representation of barcode (requires GD or Imagick library). + * @param $w (int) Width of a single rectangle element in pixels. + * @param $h (int) Height of a single rectangle element in pixels. + * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent). + * @public + */ + public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) { + $data = $this->getBarcodePngData($w, $h, $color); + // send headers + header('Content-Type: image/png'); + header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 + header('Pragma: public'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + //header('Content-Length: '.strlen($data)); + echo $data; + + } + + /** + * Return a PNG image representation of barcode (requires GD or Imagick library). + * @param $w (int) Width of a single rectangle element in pixels. + * @param $h (int) Height of a single rectangle element in pixels. + * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent). + * @return image or false in case of error. + * @public + */ + public function getBarcodePngData($w=3, $h=3, $color=array(0,0,0)) { + // calculate image size + $width = ($this->barcode_array['num_cols'] * $w); + $height = ($this->barcode_array['num_rows'] * $h); + if (function_exists('imagecreate')) { + // GD library + $imagick = false; + $png = imagecreate($width, $height); + $bgcol = imagecolorallocate($png, 255, 255, 255); + imagecolortransparent($png, $bgcol); + $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]); + } elseif (extension_loaded('imagick')) { + $imagick = true; + $bgcol = new imagickpixel('rgb(255,255,255'); + $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')'); + $png = new Imagick(); + $png->newImage($width, $height, 'none', 'png'); + $bar = new imagickdraw(); + $bar->setfillcolor($fgcol); + } else { + return false; + } + // print barcode elements + $y = 0; + // for each row + for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { + $x = 0; + // for each column + for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { + if ($this->barcode_array['bcode'][$r][$c] == 1) { + // draw a single barcode cell + if ($imagick) { + $bar->rectangle($x, $y, ($x + $w - 1), ($y + $h - 1)); + } else { + imagefilledrectangle($png, $x, $y, ($x + $w - 1), ($y + $h - 1), $fgcol); + } + } + $x += $w; + } + $y += $h; + } + if ($imagick) { + $png->drawimage($bar); + return $png; + } else { + ob_start(); + imagepng($png); + $imagedata = ob_get_clean(); + imagedestroy($png); + return $imagedata; + } + } + + /** + * Set the barcode. + * @param $code (string) code to print + * @param $type (string) type of barcode:
    • DATAMATRIX : Datamatrix (ISO/IEC 16022)
    • PDF417 : PDF417 (ISO/IEC 15438:2006)
    • PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
    • QRCODE : QRcode Low error correction
    • QRCODE,L : QRcode Low error correction
    • QRCODE,M : QRcode Medium error correction
    • QRCODE,Q : QRcode Better error correction
    • QRCODE,H : QR-CODE Best error correction
    • RAW: raw mode - comma-separad list of array rows
    • RAW2: raw mode - array rows are surrounded by square parenthesis.
    • TEST : Test matrix
    + * @return array + */ + public function setBarcode($code, $type) { + $mode = explode(',', $type); + $qrtype = strtoupper($mode[0]); + switch ($qrtype) { + case 'DATAMATRIX': { // DATAMATRIX (ISO/IEC 16022) + require_once(dirname(__FILE__).'/include/barcodes/datamatrix.php'); + $qrcode = new Datamatrix($code); + $this->barcode_array = $qrcode->getBarcodeArray(); + $this->barcode_array['code'] = $code; + break; + } + case 'PDF417': { // PDF417 (ISO/IEC 15438:2006) + require_once(dirname(__FILE__).'/include/barcodes/pdf417.php'); + if (!isset($mode[1]) OR ($mode[1] === '')) { + $aspectratio = 2; // default aspect ratio (width / height) + } else { + $aspectratio = floatval($mode[1]); + } + if (!isset($mode[2]) OR ($mode[2] === '')) { + $ecl = -1; // default error correction level (auto) + } else { + $ecl = intval($mode[2]); + } + // set macro block + $macro = array(); + if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) { + $macro['segment_total'] = intval($mode[3]); + $macro['segment_index'] = intval($mode[4]); + $macro['file_id'] = strtr($mode[5], "\xff", ','); + for ($i = 0; $i < 7; ++$i) { + $o = $i + 6; + if (isset($mode[$o]) AND ($mode[$o] !== '')) { + // add option + $macro['option_'.$i] = strtr($mode[$o], "\xff", ','); + } + } + } + $qrcode = new PDF417($code, $ecl, $aspectratio, $macro); + $this->barcode_array = $qrcode->getBarcodeArray(); + $this->barcode_array['code'] = $code; + break; + } + case 'QRCODE': { // QR-CODE + require_once(dirname(__FILE__).'/include/barcodes/qrcode.php'); + if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) { + $mode[1] = 'L'; // Ddefault: Low error correction + } + $qrcode = new QRcode($code, strtoupper($mode[1])); + $this->barcode_array = $qrcode->getBarcodeArray(); + $this->barcode_array['code'] = $code; + break; + } + case 'RAW': + case 'RAW2': { // RAW MODE + // remove spaces + $code = preg_replace('/[\s]*/si', '', $code); + if (strlen($code) < 3) { + break; + } + if ($qrtype == 'RAW') { + // comma-separated rows + $rows = explode(',', $code); + } else { // RAW2 + // rows enclosed in square parentheses + $code = substr($code, 1, -1); + $rows = explode('][', $code); + } + $this->barcode_array['num_rows'] = count($rows); + $this->barcode_array['num_cols'] = strlen($rows[0]); + $this->barcode_array['bcode'] = array(); + foreach ($rows as $r) { + $this->barcode_array['bcode'][] = str_split($r, 1); + } + $this->barcode_array['code'] = $code; + break; + } + case 'TEST': { // TEST MODE + $this->barcode_array['num_rows'] = 5; + $this->barcode_array['num_cols'] = 15; + $this->barcode_array['bcode'] = array( + array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1), + array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0), + array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0), + array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0), + array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0)); + $this->barcode_array['code'] = $code; + break; + } + default: { + $this->barcode_array = false; + } + } + } +} // end of class + +//============================================================+ +// END OF FILE +//============================================================+ diff --git a/tools/tcpdf/tcpdf_import.php b/tools/tcpdf/tcpdf_import.php new file mode 100644 index 000000000..09d726ba0 --- /dev/null +++ b/tools/tcpdf/tcpdf_import.php @@ -0,0 +1,104 @@ +. +// +// See LICENSE.TXT file for more information. +// ------------------------------------------------------------------- +// +// Description : This is a PHP class extension of the TCPDF library to +// import existing PDF documents. +// +//============================================================+ + +/** + * @file + * !!! THIS CLASS IS UNDER DEVELOPMENT !!! + * This is a PHP class extension of the TCPDF (http://www.tcpdf.org) library to import existing PDF documents.
    + * @package com.tecnick.tcpdf + * @author Nicola Asuni + * @version 1.0.001 + */ + +// include the TCPDF class +require_once(dirname(__FILE__).'/tcpdf.php'); +// include PDF parser class +require_once(dirname(__FILE__).'/tcpdf_parser.php'); + +/** + * @class TCPDF_IMPORT + * !!! THIS CLASS IS UNDER DEVELOPMENT !!! + * PHP class extension of the TCPDF (http://www.tcpdf.org) library to import existing PDF documents.
    + * @package com.tecnick.tcpdf + * @brief PHP class extension of the TCPDF library to import existing PDF documents. + * @version 1.0.001 + * @author Nicola Asuni - info@tecnick.com + */ +class TCPDF_IMPORT extends TCPDF { + + /** + * Import an existing PDF document + * @param $filename (string) Filename of the PDF document to import. + * @return true in case of success, false otherwise + * @public + * @since 1.0.000 (2011-05-24) + */ + public function importPDF($filename) { + // load document + $rawdata = file_get_contents($filename); + if ($rawdata === false) { + $this->Error('Unable to get the content of the file: '.$filename); + } + // configuration parameters for parser + $cfg = array( + 'die_for_errors' => false, + 'ignore_filter_decoding_errors' => true, + 'ignore_missing_filter_decoders' => true, + ); + try { + // parse PDF data + $pdf = new TCPDF_PARSER($rawdata, $cfg); + } catch (Exception $e) { + die($e->getMessage()); + } + // get the parsed data + $data = $pdf->getParsedData(); + // release some memory + unset($rawdata); + + // ... + + + print_r($data); // DEBUG + + + unset($pdf); + } + +} // END OF CLASS + +//============================================================+ +// END OF FILE +//============================================================+ diff --git a/tools/tcpdf/tcpdf_parser.php b/tools/tcpdf/tcpdf_parser.php index dc6d16ab7..bd3d719c7 100644 --- a/tools/tcpdf/tcpdf_parser.php +++ b/tools/tcpdf/tcpdf_parser.php @@ -1,13 +1,13 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 1.0.001 + * @version 1.0.15 */ // include class for decoding filters -require_once(dirname(__FILE__).'/tcpdf_filters.php'); +require_once(dirname(__FILE__).'/include/tcpdf_filters.php'); /** * @class TCPDF_PARSER * This is a PHP class for parsing PDF documents.
    * @package com.tecnick.tcpdf * @brief This is a PHP class for parsing PDF documents.. - * @version 1.0.001 + * @version 1.0.15 * @author Nicola Asuni - info@tecnick.com */ class TCPDF_PARSER { @@ -77,29 +77,49 @@ class TCPDF_PARSER { */ private $FilterDecoders; + /** + * Array of configuration parameters. + * @private + */ + private $cfg = array( + 'die_for_errors' => false, + 'ignore_filter_decoding_errors' => true, + 'ignore_missing_filter_decoders' => true, + ); + // ----------------------------------------------------------------------------- /** * Parse a PDF document an return an array of objects. * @param $data (string) PDF data to parse. + * @param $cfg (array) Array of configuration parameters: + * 'die_for_errors' : if true termitate the program execution in case of error, otherwise thows an exception; + * 'ignore_filter_decoding_errors' : if true ignore filter decoding errors; + * 'ignore_missing_filter_decoders' : if true ignore missing filter decoding errors. * @public * @since 1.0.000 (2011-05-24) */ - public function __construct($data) { + public function __construct($data, $cfg=array()) { if (empty($data)) { $this->Error('Empty PDF data.'); } - $this->pdfdata = $data; + // find the pdf header starting position + if (($trimpos = strpos($data, '%PDF-')) === FALSE) { + $this->Error('Invalid PDF data: missing %PDF header.'); + } + // get PDF content string + $this->pdfdata = substr($data, $trimpos); // get length $pdflen = strlen($this->pdfdata); - // initialize class for decoding filters - $this->FilterDecoders = new TCPDF_FILTERS(); + // set configuration parameters + $this->setConfig($cfg); // get xref and trailer data $this->xref = $this->getXrefData(); // parse all document objects $this->objects = array(); foreach ($this->xref['xref'] as $obj => $offset) { - if (!isset($this->objects[$obj])) { + if (!isset($this->objects[$obj]) AND ($offset > 0)) { + // decode objects with positive offset $this->objects[$obj] = $this->getIndirectObject($obj, $offset, true); } } @@ -108,6 +128,26 @@ class TCPDF_PARSER { $this->pdfdata = ''; } + /** + * Set the configuration parameters. + * @param $cfg (array) Array of configuration parameters: + * 'die_for_errors' : if true termitate the program execution in case of error, otherwise thows an exception; + * 'ignore_filter_decoding_errors' : if true ignore filter decoding errors; + * 'ignore_missing_filter_decoders' : if true ignore missing filter decoding errors. + * @public + */ + protected function setConfig($cfg) { + if (isset($cfg['die_for_errors'])) { + $this->cfg['die_for_errors'] = !!$cfg['die_for_errors']; + } + if (isset($cfg['ignore_filter_decoding_errors'])) { + $this->cfg['ignore_filter_decoding_errors'] = !!$cfg['ignore_filter_decoding_errors']; + } + if (isset($cfg['ignore_missing_filter_decoders'])) { + $this->cfg['ignore_missing_filter_decoders'] = !!$cfg['ignore_missing_filter_decoders']; + } + } + /** * Return an array of parsed PDF document objects. * @return (array) Array of parsed PDF document objects. @@ -119,7 +159,7 @@ class TCPDF_PARSER { } /** - * Get xref (cross-reference table) and trailer data from PDF document data. + * Get Cross-Reference (xref) table and trailer data from PDF document data. * @param $offset (int) xref offset (if know). * @param $xref (array) previous xref array (if any). * @return Array containing xref and trailer data. @@ -134,24 +174,53 @@ class TCPDF_PARSER { } $matches = array_pop($matches); $startxref = $matches[1]; - } else { - // get the first xref at the specified offset - if (preg_match('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) == 0) { - $this->Error('Unable to find startxref'); - } + } elseif (strpos($this->pdfdata, 'xref', $offset) == $offset) { + // Already pointing at the xref table + $startxref = $offset; + } elseif (preg_match('/([0-9]+[\s][0-9]+[\s]obj)/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) { + // Cross-Reference Stream object + $startxref = $offset; + } elseif (preg_match('/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset)) { + // startxref found $startxref = $matches[1][0]; + } else { + $this->Error('Unable to find startxref'); } // check xref position - if (strpos($this->pdfdata, 'xref', $startxref) != $startxref) { + if (strpos($this->pdfdata, 'xref', $startxref) == $startxref) { + // Cross-Reference + $xref = $this->decodeXref($startxref, $xref); + } else { + // Cross-Reference Stream + $xref = $this->decodeXrefStream($startxref, $xref); + } + if (empty($xref)) { $this->Error('Unable to find xref'); } - // extract xref data (object indexes and offsets) - $xoffset = $startxref + 5; + return $xref; + } + + /** + * Decode the Cross-Reference section + * @param $startxref (int) Offset at which the xref section starts (position of the 'xref' keyword). + * @param $xref (array) Previous xref array (if any). + * @return Array containing xref and trailer data. + * @protected + * @since 1.0.000 (2011-06-20) + */ + protected function decodeXref($startxref, $xref=array()) { + $startxref += 4; // 4 is the length of the word 'xref' + // skip initial white space chars: \x00 null (NUL), \x09 horizontal tab (HT), \x0A line feed (LF), \x0C form feed (FF), \x0D carriage return (CR), \x20 space (SP) + $offset = $startxref + strspn($this->pdfdata, "\x00\x09\x0a\x0c\x0d\x20", $startxref); // initialize object number $obj_num = 0; - $offset = $xoffset; - while (preg_match('/^([0-9]+)[\s]([0-9]+)[\s]?([nf]?)/im', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) { - $offset = (strlen($matches[0][0]) + $matches[0][1]); + // search for cross-reference entries or subsection + while (preg_match('/([0-9]+)[\x20]([0-9]+)[\x20]?([nf]?)(\r\n|[\x20]?[\r\n])/', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) { + if ($matches[0][1] != $offset) { + // we are on another section + break; + } + $offset += strlen($matches[0][0]); if ($matches[3][0] == 'n') { // create unique object index: [object number]_[generation number] $index = $obj_num.'_'.intval($matches[2][0]); @@ -161,19 +230,17 @@ class TCPDF_PARSER { $xref['xref'][$index] = intval($matches[1][0]); } ++$obj_num; - $offset += 2; } elseif ($matches[3][0] == 'f') { ++$obj_num; - $offset += 2; } else { // object number (index) $obj_num = intval($matches[1][0]); } } // get trailer data - if (preg_match('/trailer[\s]*<<(.*)>>[\s]*[\r\n]+startxref[\s]*[\r\n]+/isU', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $xoffset) > 0) { + if (preg_match('/trailer[\s]*<<(.*)>>/isU', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) { $trailer_data = $matches[1][0]; - if (!isset($xref['trailer'])) { + if (!isset($xref['trailer']) OR empty($xref['trailer'])) { // get only the last updated version $xref['trailer'] = array(); // parse trailer_data @@ -205,6 +272,221 @@ class TCPDF_PARSER { return $xref; } + /** + * Decode the Cross-Reference Stream section + * @param $startxref (int) Offset at which the xref section starts. + * @param $xref (array) Previous xref array (if any). + * @return Array containing xref and trailer data. + * @protected + * @since 1.0.003 (2013-03-16) + */ + protected function decodeXrefStream($startxref, $xref=array()) { + // try to read Cross-Reference Stream + $xrefobj = $this->getRawObject($startxref); + $xrefcrs = $this->getIndirectObject($xrefobj[1], $startxref, true); + if (!isset($xref['trailer']) OR empty($xref['trailer'])) { + // get only the last updated version + $xref['trailer'] = array(); + $filltrailer = true; + } else { + $filltrailer = false; + } + if (!isset($xref['xref'])) { + $xref['xref'] = array(); + } + $valid_crs = false; + $columns = 0; + $sarr = $xrefcrs[0][1]; + if (!is_array($sarr)) { + $sarr = array(); + } + foreach ($sarr as $k => $v) { + if (($v[0] == '/') AND ($v[1] == 'Type') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == '/') AND ($sarr[($k +1)][1] == 'XRef'))) { + $valid_crs = true; + } elseif (($v[0] == '/') AND ($v[1] == 'Index') AND (isset($sarr[($k +1)]))) { + // first object number in the subsection + $index_first = intval($sarr[($k +1)][1][0][1]); + // number of entries in the subsection + $index_entries = intval($sarr[($k +1)][1][1][1]); + } elseif (($v[0] == '/') AND ($v[1] == 'Prev') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'numeric'))) { + // get previous xref offset + $prevxref = intval($sarr[($k +1)][1]); + } elseif (($v[0] == '/') AND ($v[1] == 'W') AND (isset($sarr[($k +1)]))) { + // number of bytes (in the decoded stream) of the corresponding field + $wb = array(); + $wb[0] = intval($sarr[($k +1)][1][0][1]); + $wb[1] = intval($sarr[($k +1)][1][1][1]); + $wb[2] = intval($sarr[($k +1)][1][2][1]); + } elseif (($v[0] == '/') AND ($v[1] == 'DecodeParms') AND (isset($sarr[($k +1)][1]))) { + $decpar = $sarr[($k +1)][1]; + foreach ($decpar as $kdc => $vdc) { + if (($vdc[0] == '/') AND ($vdc[1] == 'Columns') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) { + $columns = intval($decpar[($kdc +1)][1]); + } elseif (($vdc[0] == '/') AND ($vdc[1] == 'Predictor') AND (isset($decpar[($kdc +1)]) AND ($decpar[($kdc +1)][0] == 'numeric'))) { + $predictor = intval($decpar[($kdc +1)][1]); + } + } + } elseif ($filltrailer) { + if (($v[0] == '/') AND ($v[1] == 'Size') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'numeric'))) { + $xref['trailer']['size'] = $sarr[($k +1)][1]; + } elseif (($v[0] == '/') AND ($v[1] == 'Root') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'objref'))) { + $xref['trailer']['root'] = $sarr[($k +1)][1]; + } elseif (($v[0] == '/') AND ($v[1] == 'Info') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'objref'))) { + $xref['trailer']['info'] = $sarr[($k +1)][1]; + } elseif (($v[0] == '/') AND ($v[1] == 'Encrypt') AND (isset($sarr[($k +1)]) AND ($sarr[($k +1)][0] == 'objref'))) { + $xref['trailer']['encrypt'] = $sarr[($k +1)][1]; + } elseif (($v[0] == '/') AND ($v[1] == 'ID') AND (isset($sarr[($k +1)]))) { + $xref['trailer']['id'] = array(); + $xref['trailer']['id'][0] = $sarr[($k +1)][1][0][1]; + $xref['trailer']['id'][1] = $sarr[($k +1)][1][1][1]; + } + } + } + // decode data + if ($valid_crs AND isset($xrefcrs[1][3][0])) { + // number of bytes in a row + $rowlen = ($columns + 1); + // convert the stream into an array of integers + $sdata = unpack('C*', $xrefcrs[1][3][0]); + // split the rows + $sdata = array_chunk($sdata, $rowlen); + // initialize decoded array + $ddata = array(); + // initialize first row with zeros + $prev_row = array_fill (0, $rowlen, 0); + // for each row apply PNG unpredictor + foreach ($sdata as $k => $row) { + // initialize new row + $ddata[$k] = array(); + // get PNG predictor value + $predictor = (10 + $row[0]); + // for each byte on the row + for ($i=1; $i<=$columns; ++$i) { + // new index + $j = ($i - 1); + $row_up = $prev_row[$j]; + if ($i == 1) { + $row_left = 0; + $row_upleft = 0; + } else { + $row_left = $row[($i - 1)]; + $row_upleft = $prev_row[($j - 1)]; + } + switch ($predictor) { + case 10: { // PNG prediction (on encoding, PNG None on all rows) + $ddata[$k][$j] = $row[$i]; + break; + } + case 11: { // PNG prediction (on encoding, PNG Sub on all rows) + $ddata[$k][$j] = (($row[$i] + $row_left) & 0xff); + break; + } + case 12: { // PNG prediction (on encoding, PNG Up on all rows) + $ddata[$k][$j] = (($row[$i] + $row_up) & 0xff); + break; + } + case 13: { // PNG prediction (on encoding, PNG Average on all rows) + $ddata[$k][$j] = (($row[$i] + (($row_left + $row_up) / 2)) & 0xff); + break; + } + case 14: { // PNG prediction (on encoding, PNG Paeth on all rows) + // initial estimate + $p = ($row_left + $row_up - $row_upleft); + // distances + $pa = abs($p - $row_left); + $pb = abs($p - $row_up); + $pc = abs($p - $row_upleft); + $pmin = min($pa, $pb, $pc); + // return minimum distance + switch ($pmin) { + case $pa: { + $ddata[$k][$j] = (($row[$i] + $row_left) & 0xff); + break; + } + case $pb: { + $ddata[$k][$j] = (($row[$i] + $row_up) & 0xff); + break; + } + case $pc: { + $ddata[$k][$j] = (($row[$i] + $row_upleft) & 0xff); + break; + } + } + break; + } + default: { // PNG prediction (on encoding, PNG optimum) + $this->Error('Unknown PNG predictor'); + break; + } + } + } + $prev_row = $ddata[$k]; + } // end for each row + // complete decoding + $sdata = array(); + // for every row + foreach ($ddata as $k => $row) { + // initialize new row + $sdata[$k] = array(0, 0, 0); + if ($wb[0] == 0) { + // default type field + $sdata[$k][0] = 1; + } + $i = 0; // count bytes in the row + // for every column + for ($c = 0; $c < 3; ++$c) { + // for every byte on the column + for ($b = 0; $b < $wb[$c]; ++$b) { + if (isset($row[$i])) { + $sdata[$k][$c] += ($row[$i] << (($wb[$c] - 1 - $b) * 8)); + } + ++$i; + } + } + } + $ddata = array(); + // fill xref + if (isset($index_first)) { + $obj_num = $index_first; + } else { + $obj_num = 0; + } + foreach ($sdata as $k => $row) { + switch ($row[0]) { + case 0: { // (f) linked list of free objects + break; + } + case 1: { // (n) objects that are in use but are not compressed + // create unique object index: [object number]_[generation number] + $index = $obj_num.'_'.$row[2]; + // check if object already exist + if (!isset($xref['xref'][$index])) { + // store object offset position + $xref['xref'][$index] = $row[1]; + } + break; + } + case 2: { // compressed objects + // $row[1] = object number of the object stream in which this object is stored + // $row[2] = index of this object within the object stream + $index = $row[1].'_0_'.$row[2]; + $xref['xref'][$index] = -1; + break; + } + default: { // null objects + break; + } + } + ++$obj_num; + } + } // end decoding data + if (isset($prevxref)) { + // get previous xref + $xref = $this->getXrefData($prevxref, $xref); + } + return $xref; + } + /** * Get object type, raw value and offset to next object * @param $offset (int) Object offset. @@ -218,7 +500,7 @@ class TCPDF_PARSER { // skip initial white space chars: \x00 null (NUL), \x09 horizontal tab (HT), \x0A line feed (LF), \x0C form feed (FF), \x0D carriage return (CR), \x20 space (SP) $offset += strspn($this->pdfdata, "\x00\x09\x0a\x0c\x0d\x20", $offset); // get first char - $char = $this->pdfdata{$offset}; + $char = $this->pdfdata[$offset]; // get object type switch ($char) { case '%': { // \x25 PERCENT SIGN @@ -226,7 +508,7 @@ class TCPDF_PARSER { $next = strcspn($this->pdfdata, "\r\n", $offset); if ($next > 0) { $offset += $next; - return $this->getRawObject($this->pdfdata, $offset); + return $this->getRawObject($offset); } break; } @@ -249,10 +531,10 @@ class TCPDF_PARSER { if ($char == '(') { $open_bracket = 1; while ($open_bracket > 0) { - if (!isset($this->pdfdata{$strpos})) { + if (!isset($this->pdfdata[$strpos])) { break; } - $ch = $this->pdfdata{$strpos}; + $ch = $this->pdfdata[$strpos]; switch ($ch) { case '\\': { // REVERSE SOLIDUS (5Ch) (Backslash) // skip next character @@ -296,7 +578,7 @@ class TCPDF_PARSER { } case '<': // \x3C LESS-THAN SIGN case '>': { // \x3E GREATER-THAN SIGN - if (isset($this->pdfdata{($offset + 1)}) and ($this->pdfdata{($offset + 1)} == $char)) { + if (isset($this->pdfdata[($offset + 1)]) AND ($this->pdfdata[($offset + 1)] == $char)) { // dictionary object $objtype = $char.$char; $offset += 2; @@ -316,10 +598,13 @@ class TCPDF_PARSER { // hexadecimal string object $objtype = $char; ++$offset; - if (($char == '<') and (preg_match('/^([0-9A-Fa-f]+)[>]/iU', substr($this->pdfdata, $offset), $matches) == 1)) { - $objval = $matches[1]; + if (($char == '<') AND (preg_match('/^([0-9A-Fa-f\x09\x0a\x0c\x0d\x20]+)>/iU', substr($this->pdfdata, $offset), $matches) == 1)) { + // remove white space characters + $objval = strtr($matches[1], "\x09\x0a\x0c\x0d\x20", ''); $offset += strlen($matches[0]); - } + } elseif (($endpos = strpos($this->pdfdata, '>', $offset)) !== FALSE) { + $offset = $endpos + 1; + } } break; } @@ -347,9 +632,12 @@ class TCPDF_PARSER { // start stream object $objtype = 'stream'; $offset += 6; - if (preg_match('/^[\r\n]+(.*)[\r\n]*endstream/isU', substr($this->pdfdata, $offset), $matches) == 1) { - $objval = $matches[1]; + if (preg_match('/^([\r]?[\n])/isU', substr($this->pdfdata, $offset), $matches) == 1) { $offset += strlen($matches[0]); + if (preg_match('/(endstream)[\x09\x0a\x0c\x0d\x20]/isU', substr($this->pdfdata, $offset), $matches, PREG_OFFSET_CAPTURE) == 1) { + $objval = substr($this->pdfdata, $offset, $matches[0][1]); + $offset += $matches[1][1]; + } } } elseif (substr($this->pdfdata, $offset, 9) == 'endstream') { // end stream object @@ -357,14 +645,14 @@ class TCPDF_PARSER { $offset += 9; } elseif (preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+R/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) { // indirect object reference - $objtype = 'ojbref'; + $objtype = 'objref'; $offset += strlen($matches[0]); $objval = intval($matches[1]).'_'.intval($matches[2]); } elseif (preg_match('/^([0-9]+)[\s]+([0-9]+)[\s]+obj/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) { // object start - $objtype = 'ojb'; + $objtype = 'obj'; $objval = intval($matches[1]).'_'.intval($matches[2]); - $offset += strlen($matches[0]); + $offset += strlen ($matches[0]); } elseif (($numlen = strspn($this->pdfdata, '+-.0123456789', $offset)) > 0) { // numeric object $objtype = 'numeric'; @@ -388,11 +676,13 @@ class TCPDF_PARSER { */ protected function getIndirectObject($obj_ref, $offset=0, $decoding=true) { $obj = explode('_', $obj_ref); - if (($obj === false) or (count($obj) != 2)) { + if (($obj === false) OR (count($obj) != 2)) { $this->Error('Invalid object reference: '.$obj); return; } $objref = $obj[0].' '.$obj[1].' obj'; + // ignore leading zeros + $offset += strspn($this->pdfdata, '0', $offset); if (strpos($this->pdfdata, $objref, $offset) != $offset) { // an indirect reference to an undefined object shall be considered a reference to the null object return array('null', 'null', $offset); @@ -403,16 +693,17 @@ class TCPDF_PARSER { $objdata = array(); $i = 0; // object main index do { - // get element + $oldoffset = $offset; + // get element $element = $this->getRawObject($offset); $offset = $element[2]; // decode stream using stream's dictionary information - if ($decoding and ($element[0] == 'stream') and (isset($objdata[($i - 1)][0])) and ($objdata[($i - 1)][0] == '<<')) { - $element[3] = $this->decodeStream($objdata[($i - 1)][1], substr($element[1], 1)); + if ($decoding AND ($element[0] == 'stream') AND (isset($objdata[($i - 1)][0])) AND ($objdata[($i - 1)][0] == '<<')) { + $element[3] = $this->decodeStream($objdata[($i - 1)][1], $element[1]); } $objdata[$i] = $element; ++$i; - } while ($element[0] != 'endobj'); + } while (($element[0] != 'endobj') AND ($offset != $oldoffset)); // remove closing delimiter array_pop($objdata); // return raw object content @@ -450,19 +741,22 @@ class TCPDF_PARSER { * @since 1.0.000 (2011-06-22) */ protected function decodeStream($sdic, $stream) { - // get stream lenght and filters + // get stream length and filters $slength = strlen($stream); + if ($slength <= 0) { + return array('', array()); + } $filters = array(); foreach ($sdic as $k => $v) { if ($v[0] == '/') { - if (($v[1] == 'Length') and (isset($sdic[($k + 1)])) and ($sdic[($k + 1)][0] == 'numeric')) { - // get declared stream lenght + if (($v[1] == 'Length') AND (isset($sdic[($k + 1)])) AND ($sdic[($k + 1)][0] == 'numeric')) { + // get declared stream length $declength = intval($sdic[($k + 1)][1]); if ($declength < $slength) { $stream = substr($stream, 0, $declength); $slength = $declength; } - } elseif (($v[1] == 'Filter') and (isset($sdic[($k + 1)]))) { + } elseif (($v[1] == 'Filter') AND (isset($sdic[($k + 1)]))) { // resolve indirect object $objval = $this->getObjectVal($sdic[($k + 1)]); if ($objval[0] == '/') { @@ -482,8 +776,16 @@ class TCPDF_PARSER { // decode the stream $remaining_filters = array(); foreach ($filters as $filter) { - if (in_array($filter, $this->FilterDecoders->getAvailableFilters())) { - $stream = $this->FilterDecoders->decodeFilter($filter, $stream); + if (in_array($filter, TCPDF_FILTERS::getAvailableFilters())) { + try { + $stream = TCPDF_FILTERS::decodeFilter($filter, $stream); + } catch (Exception $e) { + $emsg = $e->getMessage(); + if ((($emsg[0] == '~') AND !$this->cfg['ignore_missing_filter_decoders']) + OR (($emsg[0] != '~') AND !$this->cfg['ignore_filter_decoding_errors'])) { + $this->Error($e->getMessage()); + } + } } else { // add missing filter to array $remaining_filters[] = $filter; @@ -493,14 +795,17 @@ class TCPDF_PARSER { } /** - * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. + * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true. * @param $msg (string) The error message * @public * @since 1.0.000 (2011-05-23) */ public function Error($msg) { - // exit program and print error - die('TCPDF_PARSER ERROR: '.$msg); + if ($this->cfg['die_for_errors']) { + die('TCPDF_PARSER ERROR: '.$msg); + } else { + throw new Exception('TCPDF_PARSER ERROR: '.$msg); + } } } // END OF TCPDF_PARSER CLASS @@ -508,4 +813,3 @@ class TCPDF_PARSER { //============================================================+ // END OF FILE //============================================================+ - diff --git a/tools/tcpdf/tools/.htaccess b/tools/tcpdf/tools/.htaccess new file mode 100644 index 000000000..8d2f25636 --- /dev/null +++ b/tools/tcpdf/tools/.htaccess @@ -0,0 +1 @@ +deny from all diff --git a/tools/tcpdf/tools/convert_fonts_examples.txt b/tools/tcpdf/tools/convert_fonts_examples.txt new file mode 100644 index 000000000..d5f8a4eae --- /dev/null +++ b/tools/tcpdf/tools/convert_fonts_examples.txt @@ -0,0 +1,28 @@ +./tcpdf_addfont.php -b -t Type1 -f 4 -e symbol -i pdfasymbol.pfb +./tcpdf_addfont.php -b -t Type1 -f 4 -i pdfazapfdingbats.pfb +./tcpdf_addfont.php -b -t Type1 -f 32 -e cp1252 -i pdfatimes.pfb,pdfatimesb.pfb,pdfahelvetica.pfb,pdfahelveticab.pfb +./tcpdf_addfont.php -b -t Type1 -f 33 -e cp1252 -i pdfacourier.pfb,pdfacourierb.pfb +./tcpdf_addfont.php -b -t Type1 -f 96 -e cp1252 -i pdfahelveticabi.pfb,pdfahelveticai.pfb,pdfatimesi.pfb,pdfatimesbi.pfb +./tcpdf_addfont.php -b -t Type1 -f 97 -e cp1252 -i pdfacourieri.pfb,pdfacourierbi.pfb + + +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 32 -i DejaVuSans.ttf,DejaVuSans-Bold.ttf,DejaVuSansCondensed.ttf,DejaVuSansCondensed-Bold.ttf,DejaVuSans-ExtraLight.ttf,DejaVuSerif.ttf,DejaVuSerif-Bold.ttf,DejaVuSerifCondensed.ttf,DejaVuSerifCondensed-Bold.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 33 -i DejaVuSansMono.ttf,DejaVuSansMono-Bold.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 96 -i DejaVuSans-BoldOblique.ttf,DejaVuSansCondensed-BoldOblique.ttf,DejaVuSansCondensed-Oblique.ttf,DejaVuSerifCondensed-BoldItalic.ttf,DejaVuSerifCondensed-Italic.ttf,DejaVuSerif-Italic.ttf,DejaVuSerif-BoldItalic.ttf,DejaVuSans-Oblique.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 97 -i DejaVuSansMono-BoldOblique.ttf,DejaVuSansMono-Oblique.ttf + + + +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 32 -i FreeSans.ttf,FreeSansBold.ttf,FreeSerif.ttf,FreeSerifBold.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 33 -i FreeMono.ttf,FreeMonoBold.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 96 -i FreeSansBoldOblique.ttf,FreeSansOblique.ttf,FreeSerifBoldItalic.ttf,FreeSerifItalic.ttf +./tcpdf_addfont.php -b -t TrueTypeUnicode -f 97 -i FreeMonoBoldOblique.ttf,FreeMonoOblique.ttf + + +./tcpdf_addfont.php -b -t TrueTypeUnicode -i aeAlArabiya.ttf,aeFurat.ttf + + +./tcpdf_addfont.php -b -t CID0JP -f 32 -i cid0jp.ttf +./tcpdf_addfont.php -b -t CID0KR -f 32 -i cid0kr.ttf +./tcpdf_addfont.php -b -t CID0CS -f 32 -i cid0cs.ttf +./tcpdf_addfont.php -b -t CID0CT -f 32 -i cid0ct.ttf diff --git a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/index.php b/tools/tcpdf/tools/index.php similarity index 60% rename from tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/index.php rename to tools/tcpdf/tools/index.php index 9a99a8662..aca71cfae 100644 --- a/tools/htmlpurifier/standalone/HTMLPurifier/ConfigSchema/Builder/index.php +++ b/tools/tcpdf/tools/index.php @@ -1,35 +1,35 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; + +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../'); +exit; diff --git a/tools/tcpdf/tools/tcpdf_addfont.php b/tools/tcpdf/tools/tcpdf_addfont.php new file mode 100755 index 000000000..2937c7564 --- /dev/null +++ b/tools/tcpdf/tools/tcpdf_addfont.php @@ -0,0 +1,269 @@ +#!/usr/bin/env php +. +// +// See LICENSE.TXT file for more information. +// ------------------------------------------------------------------- +// +// Description : This is a command line script to generate TCPDF fonts. +// +//============================================================+ + +/** + * @file + * This is a command line script to generate TCPDF fonts.
    + * @package com.tecnick.tcpdf + * @version 1.0.000 + */ + +if (php_sapi_name() != 'cli') { + echo 'You need to run this command from console.'; + exit(1); +} + +$tcpdf_include_dirs = array(realpath(dirname(__FILE__).'/../tcpdf.php'), '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', '/var/www/tcpdf/tcpdf.php', '/var/www/html/tcpdf/tcpdf.php', '/usr/local/apache2/htdocs/tcpdf/tcpdf.php'); +foreach ($tcpdf_include_dirs as $tcpdf_include_path) { + if (@file_exists($tcpdf_include_path)) { + require_once($tcpdf_include_path); + break; + } +} + +/** + * Display help guide for this command. + */ +function showHelp() { + $help = <<'', 'enc'=>'', 'flags'=>32, 'outpath'=>K_PATH_FONTS, 'platid'=>3, 'encid'=>1, 'addcbbox'=>false, 'link'=>false); + +// short input options +$sopt = ''; +$sopt .= 't:'; +$sopt .= 'e:'; +$sopt .= 'f:'; +$sopt .= 'o:'; +$sopt .= 'p:'; +$sopt .= 'n:'; +$sopt .= 'b'; +$sopt .= 'l'; +$sopt .= 'i:'; +$sopt .= 'h'; + +// long input options +$lopt = array(); +$lopt[] = 'type:'; +$lopt[] = 'enc:'; +$lopt[] = 'flags:'; +$lopt[] = 'outpath:'; +$lopt[] = 'platid:'; +$lopt[] = 'encid:'; +$lopt[] = 'addcbbox'; +$lopt[] = 'link'; +$lopt[] = 'fonts:'; +$lopt[] = 'help'; + +// parse input options +$inopt = getopt($sopt, $lopt); + +// import options (with some sanitization) +foreach ($inopt as $opt => $val) { + switch ($opt) { + case 't': + case 'type': { + if (in_array($val, array('TrueTypeUnicode', 'TrueType', 'Type1', 'CID0JP', 'CID0KR', 'CID0CS', 'CID0CT'))) { + $options['type'] = $val; + } + break; + } + case 'e': + case 'enc': { + $options['enc'] = $val; + break; + } + case 'f': + case 'flags': { + $options['flags'] = intval($val); + break; + } + case 'o': + case 'outpath': { + $options['outpath'] = realpath($val); + if (substr($options['outpath'], -1) != '/') { + $options['outpath'] .= '/'; + } + break; + } + case 'p': + case 'platid': { + $options['platid'] = min(max(1, intval($val)), 3); + break; + } + case 'n': + case 'encid': { + $options['encid'] = min(max(0, intval($val)), 10); + break; + } + case 'b': + case 'addcbbox': { + $options['addcbbox'] = true; + break; + } + case 'l': + case 'link': { + $options['link'] = true; + break; + } + case 'i': + case 'fonts': { + $options['fonts'] = explode(',', $val); + break; + } + case 'h': + case 'help': + default: { + showHelp(); + break; + } + } // end of switch +} // end of while loop + +if (empty($options['fonts'])) { + echo "ERROR: missing input fonts (try --help for usage)\n\n"; + exit(2); +} + +// check the output path +if (!is_dir($options['outpath']) OR !is_writable($options['outpath'])) { + echo "ERROR: Can't write to ".$options['outpath']."\n\n"; + exit(3); +} + +echo "\n>>> Converting fonts for TCPDF:\n"; + +echo '*** Output dir set to '.$options['outpath']."\n"; + +// check if there are conversion errors +$errors = false; + +foreach ($options['fonts'] as $font) { + $fontfile = realpath($font); + $fontname = TCPDF_FONTS::addTTFfont($fontfile, $options['type'], $options['enc'], $options['flags'], $options['outpath'], $options['platid'], $options['encid'], $options['addcbbox'], $options['link']); + if ($fontname === false) { + $errors = true; + echo "--- ERROR: can't add ".$font."\n"; + } else { + echo "+++ OK : ".$fontfile.' added as '.$fontname."\n"; + } +} + +if ($errors) { + echo "--- Process completed with ERRORS!\n\n"; + exit(4); +} + +echo ">>> Process successfully completed!\n\n"; +exit(0); + +//============================================================+ +// END OF FILE +//============================================================+