PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
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 1.08.00 All 73 releases
← All changes | classes/helper/e2pdf-convert.php +89 -72 1.08.00 → 1.32.49 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,15 +43,13 @@
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 */
52 50 public function from_bytes($size) {
53 - $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
51 + $unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
54 52 return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
55 53 }
56 54
57 55 public function to_bytes($size) {
@@ -63,11 +61,18 @@
63 61 return round($size);
64 62 }
65 63 }
66 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 +
67 72 public function to_file_name($file_name = '') {
68 73 if ($file_name) {
69 - $search = array(
74 + $search = [
70 75 '/',
71 76 '\\',
72 77 '"',
73 78 '[',
@@ -77,10 +82,10 @@
77 82 '[',
78 83 ']',
79 84 '&',
80 85 ';',
81 - );
82 - $replace = array(
86 + ];
87 + $replace = [
83 88 '',
84 89 '_',
85 90 '',
86 91 '[',
@@ -89,14 +94,12 @@
89 94 '',
90 95 '[',
91 96 ']',
92 97 '&',
93 - ''
94 - );
95 -
98 + '',
99 + ];
96 100 $file_name = str_replace($search, $replace, $file_name);
97 101 }
98 -
99 102 return $file_name;
100 103 }
101 104
102 105 /*
@@ -109,11 +112,11 @@
109 112 if (is_array($needle)) {
110 113 $pos1 = 0;
111 114 $result = $haystack;
112 115 while (count($needle) > 0) {
113 - $positions = array();
116 + $positions = [];
114 117 foreach ($needle as $from => $to) {
115 - if (( $pos2 = stripos($result, $from, $pos1) ) === FALSE) {
118 + if (($pos2 = stripos($result, $from, $pos1)) === FALSE) {
116 119 unset($needle[$from]);
117 120 } else {
118 121 $positions[$from] = $pos2;
119 122 }
@@ -123,10 +126,10 @@
123 126 }
124 127
125 128 $winner = min($positions);
126 129 $key = array_search($winner, $positions);
127 - $result = ( substr($result, 0, $winner) . $needle[$key] . substr($result, ( $winner + strlen($key))) );
128 - $pos1 = ( $winner + strlen($needle[$key]) );
130 + $result = (substr($result, 0, $winner) . $needle[$key] . substr($result, ($winner + strlen($key))));
131 + $pos1 = ($winner + strlen($needle[$key]));
129 132 }
130 133 return $result;
131 134 } else {
132 135 return $haystack;
@@ -132,17 +135,8 @@
132 135 return $haystack;
133 136 }
134 137 }
135 138
136 - public function to_shortcode_array($value, $fields = array()) {
137 - $list = explode(',', $value);
138 - $data = array();
139 - foreach ($list as $item) {
140 - $data[] = $this->parse_fields($item);
141 - }
142 - return $data;
143 - }
144 -
145 139 public function path_to_url($path = '') {
146 140 $url = str_replace(
147 141 wp_normalize_path(untrailingslashit(ABSPATH)), site_url(), wp_normalize_path($path)
148 142 );
@@ -148,40 +142,32 @@
148 142 );
149 143 return esc_url_raw($url);
150 144 }
151 145
152 - public function preg_replace($pattern = '', $replacement = '', $value = '') {
153 - if ($pattern && $value) {
154 - return preg_replace($pattern, $replacement, $value);
146 + public function unserialize($value) {
147 + /* Compatibility fix with Docket Cache */
148 + if (is_array($value)) {
149 + return $value;
155 150 }
156 - return $value;
151 + if (version_compare(PHP_VERSION, '7.0.0', '<')) {
152 + return @unserialize($value);
153 + } else {
154 + return @unserialize($value, ['allowed_classes' => false]);
155 + }
157 156 }
158 157
159 - public function to_content_key($content_key = false, $value = '') {
158 + public function is_content_key($content_key = false, $value = '') {
160 159 $response = '';
161 -
162 160 if ($content_key) {
163 - $shortcode_tags = array(
164 - 'e2pdf-content'
165 - );
161 + $shortcode_tags = [
162 + 'e2pdf-content',
163 + ];
166 164 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
167 165 $tagnames = array_intersect($shortcode_tags, $matches[1]);
168 -
169 166 if (!empty($tagnames)) {
170 -
171 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
172 -
173 - preg_match_all("/$pattern/", $value, $shortcodes);
174 -
167 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
175 168 foreach ($shortcodes[0] as $key => $shortcode_value) {
176 - $shortcode = array();
177 - $shortcode[1] = $shortcodes[1][$key];
178 - $shortcode[2] = $shortcodes[2][$key];
179 - $shortcode[3] = $shortcodes[3][$key];
180 - $shortcode[4] = $shortcodes[4][$key];
181 - $shortcode[5] = $shortcodes[5][$key];
182 - $shortcode[6] = $shortcodes[6][$key];
183 -
169 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
184 170 $atts = shortcode_parse_atts($shortcode[3]);
185 171 if (isset($atts['key']) && $atts['key'] == $content_key) {
186 172 $response = $shortcode[5];
187 173 }
@@ -187,30 +173,61 @@
187 173 }
188 174 }
189 175 }
190 176 }
177 + return $response;
178 + }
191 179
192 - return $response;
180 + public function is_string_array($value) {
181 + if (!is_array($value)) {
182 + $value = !empty($value) ? (array) $value : [];
183 + }
184 + return $value;
193 185 }
194 186
195 - private function parse_fields($value) {
196 - $data = array();
197 - $fields = explode("|", $value);
198 - foreach ($fields as $field) {
199 - $field_data = explode(":", $field);
200 - $field_key = $field_data['0'];
201 - unset($field_data['0']);
202 - $field_value = implode(":", $field_data);
203 - $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 + }
204 192 }
205 - return $data;
193 + return is_array($value) ? $value : [];
206 194 }
207 195
208 - private function parse_field($field_key, $field_value) {
209 - $keys = array_reverse(explode('_', $field_key));
210 - foreach ($keys as $key) {
211 - $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>';
212 201 }
213 - 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;
214 209 }
215 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 + }
216 233 }