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 +153 -42 1.04.07 → 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 */
@@ -14,25 +14,31 @@
14 14 }
15 15
16 16 class Helper_E2pdf_Convert {
17 17
18 + private $helper;
19 +
20 + public function __construct() {
21 + $this->helper = Helper_E2pdf_Helper::instance();
22 + }
23 +
18 24 public function to_hex_color($hex = '') {
19 - $color = array(
20 - 0x00, 0x00, 0x00
21 - );
25 + $color = [
26 + 0x00, 0x00, 0x00,
27 + ];
22 28 $hex = ltrim($hex, '#');
23 29 if (strlen($hex) === 3) {
24 - $color = array(
30 + $color = [
25 31 hexdec(substr($hex, 0, 1)),
26 32 hexdec(substr($hex, 1, 1)),
27 - hexdec(substr($hex, 2, 1))
28 - );
33 + hexdec(substr($hex, 2, 1)),
34 + ];
29 35 } elseif (strlen($hex) === 6) {
30 - $color = array(
36 + $color = [
31 37 hexdec(substr($hex, 0, 2)),
32 38 hexdec(substr($hex, 2, 2)),
33 - hexdec(substr($hex, 4, 2))
34 - );
39 + hexdec(substr($hex, 4, 2)),
40 + ];
35 41 }
36 42 return $color;
37 43 }
38 44
@@ -37,18 +43,66 @@
37 43 }
38 44
39 45 /**
40 46 * Convert from bytes to Human View
41 - *
42 47 * @param int $size - Size in Bytes
43 - *
44 48 * @return string - Converted size
45 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 +
46 55 public function to_bytes($size) {
47 - $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
48 - 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 + }
49 63 }
50 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 +
72 + public function to_file_name($file_name = '') {
73 + if ($file_name) {
74 + $search = [
75 + '/',
76 + '\\',
77 + '"',
78 + '[',
79 + ']',
80 + ''',
81 + '"',
82 + '[',
83 + ']',
84 + '&',
85 + ';',
86 + ];
87 + $replace = [
88 + '',
89 + '_',
90 + '',
91 + '[',
92 + ']',
93 + '\'',
94 + '',
95 + '[',
96 + ']',
97 + '&',
98 + '',
99 + ];
100 + $file_name = str_replace($search, $replace, $file_name);
101 + }
102 + return $file_name;
103 + }
104 +
51 105 /*
52 106 stritr - case insensitive version of strtr
53 107 Author: Alexander Peev
54 108 Posted in PHP.NET
@@ -58,11 +112,11 @@
58 112 if (is_array($needle)) {
59 113 $pos1 = 0;
60 114 $result = $haystack;
61 115 while (count($needle) > 0) {
62 - $positions = array();
116 + $positions = [];
63 117 foreach ($needle as $from => $to) {
64 - if (( $pos2 = stripos($result, $from, $pos1) ) === FALSE) {
118 + if (($pos2 = stripos($result, $from, $pos1)) === FALSE) {
65 119 unset($needle[$from]);
66 120 } else {
67 121 $positions[$from] = $pos2;
68 122 }
@@ -72,10 +126,10 @@
72 126 }
73 127
74 128 $winner = min($positions);
75 129 $key = array_search($winner, $positions);
76 - $result = ( substr($result, 0, $winner) . $needle[$key] . substr($result, ( $winner + strlen($key))) );
77 - $pos1 = ( $winner + strlen($needle[$key]) );
130 + $result = (substr($result, 0, $winner) . $needle[$key] . substr($result, ($winner + strlen($key))));
131 + $pos1 = ($winner + strlen($needle[$key]));
78 132 }
79 133 return $result;
80 134 } else {
81 135 return $haystack;
@@ -81,17 +135,8 @@
81 135 return $haystack;
82 136 }
83 137 }
84 138
85 - public function to_shortcode_array($value, $fields = array()) {
86 - $list = explode(',', $value);
87 - $data = array();
88 - foreach ($list as $item) {
89 - $data[] = $this->parse_fields($item);
90 - }
91 - return $data;
92 - }
93 -
94 139 public function path_to_url($path = '') {
95 140 $url = str_replace(
96 141 wp_normalize_path(untrailingslashit(ABSPATH)), site_url(), wp_normalize_path($path)
97 142 );
@@ -97,26 +142,92 @@
97 142 );
98 143 return esc_url_raw($url);
99 144 }
100 145
101 - private function parse_fields($value) {
102 - $data = array();
103 - $fields = explode("|", $value);
104 - foreach ($fields as $field) {
105 - $field_data = explode(":", $field);
106 - $field_key = $field_data['0'];
107 - unset($field_data['0']);
108 - $field_value = implode(":", $field_data);
109 - $data = array_merge_recursive($data, $this->parse_field($field_key, $field_value));
146 + public function unserialize($value) {
147 + /* Compatibility fix with Docket Cache */
148 + if (is_array($value)) {
149 + return $value;
110 150 }
111 - return $data;
151 + if (version_compare(PHP_VERSION, '7.0.0', '<')) {
152 + return @unserialize($value);
153 + } else {
154 + return @unserialize($value, ['allowed_classes' => false]);
155 + }
112 156 }
113 157
114 - private function parse_field($field_key, $field_value) {
115 - $keys = array_reverse(explode('_', $field_key));
116 - foreach ($keys as $key) {
117 - $field_value = [$key => $field_value];
158 + public function is_content_key($content_key = false, $value = '') {
159 + $response = '';
160 + if ($content_key) {
161 + $shortcode_tags = [
162 + 'e2pdf-content',
163 + ];
164 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
165 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
166 + if (!empty($tagnames)) {
167 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
168 + foreach ($shortcodes[0] as $key => $shortcode_value) {
169 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
170 + $atts = shortcode_parse_atts($shortcode[3]);
171 + if (isset($atts['key']) && $atts['key'] == $content_key) {
172 + $response = $shortcode[5];
173 + }
174 + }
175 + }
118 176 }
119 - return $field_value;
177 + return $response;
120 178 }
121 179
180 + public function is_string_array($value) {
181 + if (!is_array($value)) {
182 + $value = !empty($value) ? (array) $value : [];
183 + }
184 + return $value;
185 + }
186 +
187 + public function is_unserialized_array($value) {
188 + if (!is_array($value)) {
189 + if (is_serialized($value)) {
190 + $value = $this->unserialize($value);
191 + }
192 + }
193 + return is_array($value) ? $value : [];
194 + }
195 +
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>';
201 + }
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;
209 + }
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 + }
122 233 }