PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.23
E2Pdf – Export Pdf Tool for WordPress v1.32.23
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-properties.php

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

122 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2Pdf Properties Helper
5 * @copyright Copyright 2017 https://e2pdf.com
6 * @license GPLv3
7 * @version 1
8 * @link https://e2pdf.com
9 * @since 1.08.08
10 */
11 if (!defined('ABSPATH')) {
12 die('Access denied.');
13 }
14
15 class Helper_E2pdf_Properties {
16
17 private $helper;
18
19 public function __construct() {
20 $this->helper = Helper_E2pdf_Helper::instance();
21 }
22
23 public function apply($field = array(), $value = '') {
24 if ($value) {
25 if (isset($field['properties']['nl2br']) && $field['properties']['nl2br']) {
26 $value = nl2br($value);
27 }
28 if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern']) {
29 $value = $this->preg_replace($field['properties']['preg_pattern'], isset($field['properties']['preg_replacement']) ? $field['properties']['preg_replacement'] : '', $value);
30 }
31 if (isset($field['properties']['preg_match_all_pattern']) && $field['properties']['preg_match_all_pattern']) {
32 $value = $this->preg_match_all($field['properties']['preg_match_all_pattern'], isset($field['properties']['preg_match_all_output']) ? $field['properties']['preg_match_all_output'] : '', $value);
33 }
34 if (isset($field['properties']['html_worker']) && $field['properties']['html_worker']) {
35 $value = $this->html_worker($value);
36 }
37 if (isset($field['properties']['preload_img']) && $field['properties']['preload_img'] && false !== stripos($value, '<img')) {
38 $value = preg_replace_callback(
39 '/<img[^>]+src=["\'](http(s|)[^"|^\']+)["\']/',
40 function ($matches) {
41 return str_replace($matches[1], $this->helper->load('image')->get_base64_image($matches[1]), $matches[0]);
42 },
43 $value
44 );
45 }
46 }
47 return $value;
48 }
49
50 public function preg_replace($pattern = '', $replacement = '', $value = '') {
51 if ($pattern && $value) {
52 $value = @preg_replace($pattern, $replacement, $value); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
53 }
54 return $value;
55 }
56
57 public function preg_match_all($pattern = '', $output = '', $value = '') {
58 if ($pattern && $value) {
59 @preg_match_all($pattern, $value, $path_value); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
60 $path_parts = explode('.', $output);
61 $value = '';
62 if (!empty($path_value)) {
63 $found = true;
64 foreach ($path_parts as $path_part) {
65 if (isset($path_value[$path_part])) {
66 $path_value = &$path_value[$path_part];
67 } else {
68 $found = false;
69 break;
70 }
71 }
72 if ($found) {
73 if (is_array($path_value)) {
74 $value = serialize($path_value); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
75 } else {
76 $value = $path_value;
77 }
78 }
79 }
80 }
81 return $value;
82 }
83
84 public function html_worker($value) {
85 if ($value) {
86 $value = preg_replace('#(src|href)(=[\'"])(/)#i', '$1$2' . get_site_url() . '/', $value);
87 }
88 return $value;
89 }
90
91 public function css_styles() {
92 $styles = array(
93 'WordPress' => '
94 .alignleft img {float: left;}
95 .alignright img {float: right;}
96 .wp-block-image {display: inline;}
97 .wp-block-image figure {display: inline;}
98 .has-text-align-left {display: inline;}
99 h1 {font-size: 24px;line-height:26px;}
100 h2 {font-size: 18px;line-height:20px;}
101 h3 {font-size: 14px;line-height:16px;}
102 h4 {font-size: 12px;line-height:14px;}
103 h5 {font-size: 10px;line-height:12px;}
104 h6 {font-size: 8px;line-height:10px;}
105 h1,h2,h3,h4,h5,h6 {margin-bottom:5px;font-weight:bold;}
106 p {margin-bottom:10px;}
107 li {padding-left:5px;margin-bottom:5px;}
108 a {color: #007bff}
109 ',
110 );
111 return apply_filters('e2pdf_helper_properties_css_styles', $styles);
112 }
113
114 public function css_style($value, $css_style = '') {
115 $styles = $this->css_styles();
116 if ($css_style && !empty($styles[$css_style])) {
117 $value = $styles[$css_style] . $value;
118 }
119 return $value;
120 }
121 }
122