| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2Pdf Pdf Helper |
| 5 |
* @copyright Copyright 2017 https://e2pdf.com |
| 6 |
* @license GPLv3 |
| 7 |
* @version 1 |
| 8 |
* @link https://e2pdf.com |
| 9 |
* @since 0.00.01 |
| 10 |
*/ |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
die('Access denied.'); |
| 13 |
} |
| 14 |
|
| 15 |
class Helper_E2pdf_Atts { |
| 16 |
|
| 17 |
private $helper; |
| 18 |
private $atts = []; |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
$this->helper = Helper_E2pdf_Helper::instance(); |
| 22 |
} |
| 23 |
|
| 24 |
// load |
| 25 |
public function load($atts = []) { |
| 26 |
if (is_array($atts)) { |
| 27 |
/* Backward compatiability with old format since 1.13.07 */ |
| 28 |
if (isset($atts['iframe-download'])) { |
| 29 |
$atts['iframe_download'] = $atts['iframe-download']; |
| 30 |
} |
| 31 |
/* Backward compatiability with old format since 1.09.05 */ |
| 32 |
if (isset($atts['button-title'])) { |
| 33 |
$atts['button_title'] = $atts['button-title']; |
| 34 |
} |
| 35 |
|
| 36 |
/* Backward compatiability */ |
| 37 |
if (isset($atts['output'])) { |
| 38 |
if ($atts['output'] === 'url' && isset($atts['esc_url_raw']) && $atts['esc_url_raw']) { |
| 39 |
$atts['output'] = 'url_raw'; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/* Backward compatiablity with old format since 1.29.x */ |
| 44 |
$this->atts = $atts; |
| 45 |
} |
| 46 |
return $this; |
| 47 |
} |
| 48 |
|
| 49 |
public function set($key = '', $value = '') { |
| 50 |
if ($key) { |
| 51 |
$this->atts[$key] = $value; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public function get($key = '', $default = false) { |
| 56 |
if ($key) { |
| 57 |
switch ($key) { |
| 58 |
case 'id': |
| 59 |
return isset($this->atts[$key]) ? (int) $this->atts[$key] : $default; |
| 60 |
case 'inline': |
| 61 |
case 'local': |
| 62 |
case 'preload': |
| 63 |
case 'print': |
| 64 |
case 'wc_product_download': |
| 65 |
case 'iframe_download': |
| 66 |
case 'auto': |
| 67 |
case 'download': |
| 68 |
case 'view': |
| 69 |
case 'attachment': |
| 70 |
case 'zapier': |
| 71 |
case 'create_dir': |
| 72 |
case 'create_index': |
| 73 |
case 'create_htaccess': |
| 74 |
case 'filter': |
| 75 |
case 'single_page_mode': |
| 76 |
if (isset($this->atts[$key])) { |
| 77 |
return in_array(strtolower((string) $this->atts[$key]), ['true', '1'], true) ? '1' : '0'; |
| 78 |
} |
| 79 |
return $default; |
| 80 |
case 'responsive': |
| 81 |
if (isset($this->atts[$key])) { |
| 82 |
return in_array(strtolower((string) $this->atts[$key]), ['1', 'true', 'page'], true) ? strtolower((string) $this->atts[$key]) : '0'; |
| 83 |
} |
| 84 |
return $default; |
| 85 |
case 'disable': |
| 86 |
return !empty($this->atts[$key]) ? explode(',', $this->atts[$key]) : []; |
| 87 |
case 'class': |
| 88 |
return !empty($this->atts[$key]) ? explode(' ', $this->atts[$key]) : []; |
| 89 |
case 'style': |
| 90 |
return !empty($this->atts[$key]) ? explode(';', $this->atts[$key]) : []; |
| 91 |
case 'flatten': |
| 92 |
if (isset($this->atts[$key])) { |
| 93 |
if (in_array((string) $this->atts[$key], ['0', '1', '2'], true)) { |
| 94 |
return $this->atts[$key]; |
| 95 |
} else { |
| 96 |
return in_array(strtolower((string) $this->atts[$key]), ['true', '1'], true) ? '1' : '0'; |
| 97 |
} |
| 98 |
} |
| 99 |
return $default; |
| 100 |
case 'overwrite': |
| 101 |
if (isset($this->atts[$key])) { |
| 102 |
if (in_array((string) $this->atts[$key], ['0', '1', '2'], true)) { |
| 103 |
return $this->atts[$key]; |
| 104 |
} else { |
| 105 |
return in_array(strtolower((string) $this->atts[$key]), ['true', '1'], true) ? '1' : '0'; |
| 106 |
} |
| 107 |
} |
| 108 |
return $default; |
| 109 |
case 'format': |
| 110 |
if (isset($this->atts[$key])) { |
| 111 |
if (in_array(strtolower((string) $this->atts[$key]), ['pdf', 'jpg'], true)) { |
| 112 |
return strtolower($this->atts[$key]); |
| 113 |
} |
| 114 |
} |
| 115 |
return $default; |
| 116 |
case 'arguments': |
| 117 |
$args = []; |
| 118 |
foreach ($this->atts as $att_key => $att_value) { |
| 119 |
if (substr($att_key, 0, 3) === 'arg') { |
| 120 |
$args[$att_key] = $att_value; |
| 121 |
} |
| 122 |
} |
| 123 |
return $args; |
| 124 |
case 'user_id': |
| 125 |
return isset($this->atts[$key]) ? (int) $this->atts[$key] : get_current_user_id(); |
| 126 |
case 'iframe_loader': |
| 127 |
if (isset($this->atts[$key])) { |
| 128 |
$iframe_loader = in_array(strtolower((string) $this->atts[$key]), ['true', '1'], true) ? '1' : '0'; |
| 129 |
return $iframe_loader ? plugins_url('img/loader.gif', $this->helper->get('plugin_file_path')) : 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; |
| 130 |
} |
| 131 |
case 'apply': |
| 132 |
return isset($this->atts[$key]) ? true : false; |
| 133 |
default: |
| 134 |
return isset($this->atts[$key]) ? $this->atts[$key] : $default; |
| 135 |
} |
| 136 |
} |
| 137 |
return $this->atts; |
| 138 |
} |
| 139 |
|
| 140 |
public function button_title($template = null) { |
| 141 |
|
| 142 |
$button_title = __('Download', 'e2pdf'); |
| 143 |
|
| 144 |
if ($template) { |
| 145 |
if ($this->get('button_title') !== false) { |
| 146 |
$button_title = $this->get('filter') ? $template->extension()->convert_shortcodes($this->get('button_title'), true) : $template->extension()->render($this->get('button_title')); |
| 147 |
} elseif ($template->get('button_title')) { |
| 148 |
$button_title = $template->extension()->render( |
| 149 |
$this->helper->load('translator')->pre_translate( |
| 150 |
$template->get('button_title'), $template->get('ID'), 'button_title', 'template' |
| 151 |
) |
| 152 |
); |
| 153 |
} |
| 154 |
} else { |
| 155 |
if ($this->get('button_title') !== false) { |
| 156 |
$button_title = $this->get('button_title'); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
if (false !== strpos($button_title, '<')) { |
| 161 |
$button_title = wp_kses_post( |
| 162 |
$button_title, |
| 163 |
apply_filters( |
| 164 |
'e2pdf_helper_filter_button_title', |
| 165 |
array( |
| 166 |
'img' => array( |
| 167 |
'src' => true, |
| 168 |
'class' => true, |
| 169 |
'style' => true, |
| 170 |
), |
| 171 |
'span' => array( |
| 172 |
'class' => true, |
| 173 |
'style' => true, |
| 174 |
), |
| 175 |
'div' => array( |
| 176 |
'class' => true, |
| 177 |
'style' => true, |
| 178 |
), |
| 179 |
'br' => array( |
| 180 |
'class' => true, |
| 181 |
'style' => true, |
| 182 |
), |
| 183 |
'p' => array( |
| 184 |
'class' => true, |
| 185 |
'style' => true, |
| 186 |
), |
| 187 |
'i' => array( |
| 188 |
'class' => true, |
| 189 |
'style' => true, |
| 190 |
), |
| 191 |
'strong' => array( |
| 192 |
'class' => true, |
| 193 |
'style' => true, |
| 194 |
), |
| 195 |
'b' => array( |
| 196 |
'class' => true, |
| 197 |
'style' => true, |
| 198 |
), |
| 199 |
'em' => array( |
| 200 |
'class' => true, |
| 201 |
'style' => true, |
| 202 |
), |
| 203 |
) |
| 204 |
) |
| 205 |
); |
| 206 |
} |
| 207 |
return $button_title; |
| 208 |
} |
| 209 |
} |
| 210 |
|