PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.53
E2Pdf – Export Pdf Tool for WordPress v1.32.53
1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 All 74 releases
← All changes | classes/helper/e2pdf-convert.php +103 -70 1.07.11 → 1.32.53 View file →
@@ -3,9 +3,9 @@
3 3 /**
4 4 * E2pdf Convert Helper
5 5 *
6 6 * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
7 + * @license GPLv3
8 8 * @version 1
9 9 * @link https://e2pdf.com
10 10 * @since 1.01.02
11 11 */
@@ -21,24 +21,24 @@
21 21 $this->helper = Helper_E2pdf_Helper::instance();
22 22 }
23 23
24 24 public function to_hex_color($hex = '') {
25 - $color = array(
26 - 0x00, 0x00, 0x00
27 - );
25 + $color = [
26 + 0x00, 0x00, 0x00,
27 + ];
28 28 $hex = ltrim($hex, '#');
29 29 if (strlen($hex) === 3) {
30 - $color = array(
30 + $color = [
31 31 hexdec(substr($hex, 0, 1)),
32 32 hexdec(substr($hex, 1, 1)),
33 - hexdec(substr($hex, 2, 1))
34 - );
33 + hexdec(substr($hex, 2, 1)),
34 + ];
35 35 } elseif (strlen($hex) === 6) {
36 - $color = array(
36 + $color = [
37 37 hexdec(substr($hex, 0, 2)),
38 38 hexdec(substr($hex, 2, 2)),
39 - hexdec(substr($hex, 4, 2))
40 - );
39 + hexdec(substr($hex, 4, 2)),
40 + ];
41 41 }
42 42 return $color;
43 43 }
44 44
@@ -43,21 +43,36 @@
43 43 }
44 44
45 45 /**
46 46 * Convert from bytes to Human View
47 - *
48 47 * @param int $size - Size in Bytes
49 - *
50 48 * @return string - Converted size
51 49 */
50 + public function from_bytes($size) {
51 + $unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
52 + return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
53 + }
54 +
52 55 public function to_bytes($size) {
53 - $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
54 - return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
56 + $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
57 + $size = preg_replace('/[^0-9\.]/', '', $size);
58 + if ($unit) {
59 + return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
60 + } else {
61 + return round($size);
62 + }
55 63 }
56 64
65 + public function to_file_dir($file_dir = '') {
66 + if ($file_dir) {
67 + $file_dir = str_replace(['\\', './'], ['/', '.'], $file_dir);
68 + }
69 + return $file_dir;
70 + }
71 +
57 72 public function to_file_name($file_name = '') {
58 73 if ($file_name) {
59 - $search = array(
74 + $search = [
60 75 '/',
61 76 '\\',
62 77 '"',
63 78 '[',
@@ -67,10 +82,10 @@
67 82 '[',
68 83 ']',
69 84 '&',
70 85 ';',
71 - );
72 - $replace = array(
86 + ];
87 + $replace = [
73 88 '',
74 89 '_',
75 90 '',
76 91 '[',
@@ -79,14 +94,12 @@
79 94 '',
80 95 '[',
81 96 ']',
82 97 '&',
83 - ''
84 - );
85 -
98 + '',
99 + ];
86 100 $file_name = str_replace($search, $replace, $file_name);
87 101 }
88 -
89 102 return $file_name;
90 103 }
91 104
92 105 /*
@@ -99,11 +112,11 @@
99 112 if (is_array($needle)) {
100 113 $pos1 = 0;
101 114 $result = $haystack;
102 115 while (count($needle) > 0) {
103 - $positions = array();
116 + $positions = [];
104 117 foreach ($needle as $from => $to) {
105 - if (( $pos2 = stripos($result, $from, $pos1) ) === FALSE) {
118 + if (($pos2 = stripos($result, $from, $pos1)) === FALSE) {
106 119 unset($needle[$from]);
107 120 } else {
108 121 $positions[$from] = $pos2;
109 122 }
@@ -113,10 +126,10 @@
113 126 }
114 127
115 128 $winner = min($positions);
116 129 $key = array_search($winner, $positions);
117 - $result = ( substr($result, 0, $winner) . $needle[$key] . substr($result, ( $winner + strlen($key))) );
118 - $pos1 = ( $winner + strlen($needle[$key]) );
130 + $result = (substr($result, 0, $winner) . $needle[$key] . substr($result, ($winner + strlen($key))));
131 + $pos1 = ($winner + strlen($needle[$key]));
119 132 }
120 133 return $result;
121 134 } else {
122 135 return $haystack;
@@ -122,17 +135,8 @@
122 135 return $haystack;
123 136 }
124 137 }
125 138
126 - public function to_shortcode_array($value, $fields = array()) {
127 - $list = explode(',', $value);
128 - $data = array();
129 - foreach ($list as $item) {
130 - $data[] = $this->parse_fields($item);
131 - }
132 - return $data;
133 - }
134 -
135 139 public function path_to_url($path = '') {
136 140 $url = str_replace(
137 141 wp_normalize_path(untrailingslashit(ABSPATH)), site_url(), wp_normalize_path($path)
138 142 );
@@ -138,35 +142,33 @@
138 142 );
139 143 return esc_url_raw($url);
140 144 }
141 145
142 - public function to_content_key($content_key = false, $value = '') {
146 + public function unserialize($value) {
147 + /* Compatibility fix with Docket Cache */
148 + if (is_array($value)) {
149 + return $value;
150 + }
151 + if (version_compare(PHP_VERSION, '7.0.0', '<')) {
152 + return @unserialize($value);
153 + } else {
154 + return @unserialize($value, ['allowed_classes' => false]);
155 + }
156 + }
157 +
158 + public function is_content_key($content_key = false, $value = '') {
143 159 $response = '';
144 -
145 160 if ($content_key) {
146 - $shortcode_tags = array(
147 - 'e2pdf-content'
148 - );
161 + $shortcode_tags = [
162 + 'e2pdf-content',
163 + ];
149 164 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
150 165 $tagnames = array_intersect($shortcode_tags, $matches[1]);
151 -
152 166 if (!empty($tagnames)) {
153 -
154 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
155 -
156 - preg_match_all("/$pattern/", $value, $shortcodes);
157 -
167 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
158 168 foreach ($shortcodes[0] as $key => $shortcode_value) {
159 - $shortcode = array();
160 - $shortcode[1] = $shortcodes[1][$key];
161 - $shortcode[2] = $shortcodes[2][$key];
162 - $shortcode[3] = $shortcodes[3][$key];
163 - $shortcode[4] = $shortcodes[4][$key];
164 - $shortcode[5] = $shortcodes[5][$key];
165 - $shortcode[6] = $shortcodes[6][$key];
166 -
169 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
167 170 $atts = shortcode_parse_atts($shortcode[3]);
168 -
169 171 if (isset($atts['key']) && $atts['key'] == $content_key) {
170 172 $response = $shortcode[5];
171 173 }
172 174 }
@@ -171,30 +173,61 @@
171 173 }
172 174 }
173 175 }
174 176 }
177 + return $response;
178 + }
175 179
176 - return $response;
180 + public function is_string_array($value) {
181 + if (!is_array($value)) {
182 + $value = !empty($value) ? (array) $value : [];
183 + }
184 + return $value;
177 185 }
178 186
179 - private function parse_fields($value) {
180 - $data = array();
181 - $fields = explode("|", $value);
182 - foreach ($fields as $field) {
183 - $field_data = explode(":", $field);
184 - $field_key = $field_data['0'];
185 - unset($field_data['0']);
186 - $field_value = implode(":", $field_data);
187 - $data = array_merge_recursive($data, $this->parse_field($field_key, $field_value));
187 + public function is_unserialized_array($value) {
188 + if (!is_array($value)) {
189 + if (is_serialized($value)) {
190 + $value = $this->unserialize($value);
191 + }
188 192 }
189 - return $data;
193 + return is_array($value) ? $value : [];
190 194 }
191 195
192 - private function parse_field($field_key, $field_value) {
193 - $keys = array_reverse(explode('_', $field_key));
194 - foreach ($keys as $key) {
195 - $field_value = [$key => $field_value];
196 + public function load_html($source, $dom, $form = false) {
197 + libxml_use_internal_errors(true);
198 + $options = defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD') ? LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD : 0;
199 + if ($form && $options) {
200 + $source = '<html>' . $source . '</html>';
196 201 }
197 - return $field_value;
202 + if (function_exists('mb_encode_numericentity')) {
203 + $html = $dom->loadHTML($this->html_entities($source), $options);
204 + } else {
205 + $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source, $options);
206 + }
207 + libxml_clear_errors();
208 + return $html;
198 209 }
199 210
211 + public function html_entities($source) {
212 + if (!function_exists('mb_encode_numericentity')) {
213 + return $source;
214 + }
215 + $map = [
216 + 0x80, 0xFFFF, 0, 0xFFFF,
217 + ];
218 + try {
219 + return mb_encode_numericentity($source, $map, 'UTF-8');
220 + } catch (Exception $e) {
221 + if (function_exists('mb_detect_encoding') && function_exists('mb_detect_order') && function_exists('iconv')) {
222 + $charset = mb_detect_encoding($source, mb_detect_order(), true);
223 + $source = iconv($charset, 'UTF-8//IGNORE', $source);
224 + return mb_encode_numericentity($source, $map, 'UTF-8');
225 + }
226 + return $source;
227 + }
228 + }
229 +
230 + public function html_entities_decode($source) {
231 + return html_entity_decode($source, ENT_QUOTES | ENT_HTML5, 'UTF-8');
232 + }
200 233 }