PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.05.03
E2Pdf – Export Pdf Tool for WordPress v1.05.03
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 1.08.06 All 72 releases
e2pdf / classes / helper / e2pdf-convert.php

e2pdf-convert.php in E2Pdf – Export Pdf Tool for WordPress 1.05.03, at classes/helper/e2pdf-convert.php

123 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Convert Helper
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 1.01.02
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Helper_E2pdf_Convert {
17
18 public function to_hex_color($hex = '') {
19 $color = array(
20 0x00, 0x00, 0x00
21 );
22 $hex = ltrim($hex, '#');
23 if (strlen($hex) === 3) {
24 $color = array(
25 hexdec(substr($hex, 0, 1)),
26 hexdec(substr($hex, 1, 1)),
27 hexdec(substr($hex, 2, 1))
28 );
29 } elseif (strlen($hex) === 6) {
30 $color = array(
31 hexdec(substr($hex, 0, 2)),
32 hexdec(substr($hex, 2, 2)),
33 hexdec(substr($hex, 4, 2))
34 );
35 }
36 return $color;
37 }
38
39 /**
40 * Convert from bytes to Human View
41 *
42 * @param int $size - Size in Bytes
43 *
44 * @return string - Converted size
45 */
46 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];
49 }
50
51 /*
52 stritr - case insensitive version of strtr
53 Author: Alexander Peev
54 Posted in PHP.NET
55 */
56
57 public function stritr($haystack, $needle) {
58 if (is_array($needle)) {
59 $pos1 = 0;
60 $result = $haystack;
61 while (count($needle) > 0) {
62 $positions = array();
63 foreach ($needle as $from => $to) {
64 if (( $pos2 = stripos($result, $from, $pos1) ) === FALSE) {
65 unset($needle[$from]);
66 } else {
67 $positions[$from] = $pos2;
68 }
69 }
70 if (count($needle) <= 0) {
71 break;
72 }
73
74 $winner = min($positions);
75 $key = array_search($winner, $positions);
76 $result = ( substr($result, 0, $winner) . $needle[$key] . substr($result, ( $winner + strlen($key))) );
77 $pos1 = ( $winner + strlen($needle[$key]) );
78 }
79 return $result;
80 } else {
81 return $haystack;
82 }
83 }
84
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 public function path_to_url($path = '') {
95 $url = str_replace(
96 wp_normalize_path(untrailingslashit(ABSPATH)), site_url(), wp_normalize_path($path)
97 );
98 return esc_url_raw($url);
99 }
100
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));
110 }
111 return $data;
112 }
113
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];
118 }
119 return $field_value;
120 }
121
122 }
123