| @@ -1,14 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * E2pdf Template Model | |
| 5 | - * | |
| 6 | - * @copyright Copyright 2017 https://e2pdf.com | |
| 7 | - * @license GPL v2 | |
| 8 | - * @version 1 | |
| 9 | - * @link https://e2pdf.com | |
| 10 | - * @since 0.00.01 | |
| 4 | + * File: /model/e2pdf-template.php | |
| 5 | + * | |
| 6 | + * @package E2Pdf | |
| 7 | + * @license GPLv3 | |
| 8 | + * @link https://e2pdf.com | |
| 11 | 9 | */ |
| 12 | 10 | if (!defined('ABSPATH')) { |
| 13 | 11 | die('Access denied.'); |
| 14 | 12 | } |
| @@ -14,45 +12,48 @@ | ||
| 14 | 12 | } |
| 15 | 13 | |
| 16 | 14 | class Model_E2pdf_Template extends Model_E2pdf_Model { |
| 17 | 15 | |
| 18 | - private $template = array(); | |
| 19 | - private $extension = null; | |
| 16 | + private $template = []; | |
| 17 | + private $extension; | |
| 20 | 18 | private $table; |
| 21 | 19 | |
| 22 | - /* | |
| 23 | - * On Template init | |
| 24 | - */ | |
| 25 | - | |
| 26 | - function __construct() { | |
| 20 | + public function __construct() { | |
| 27 | 21 | global $wpdb; |
| 28 | 22 | parent::__construct(); |
| 29 | 23 | $this->table = $wpdb->prefix . 'e2pdf_templates'; |
| 30 | 24 | } |
| 31 | 25 | |
| 32 | - /** | |
| 33 | - * Load Template by ID | |
| 34 | - * | |
| 35 | - * @param int $template_id - ID of template | |
| 36 | - */ | |
| 37 | - public function load($template_id, $full = true) { | |
| 26 | + // load | |
| 27 | + public function load($template_id, $full = true, $revision_id = 0) { | |
| 38 | 28 | global $wpdb; |
| 39 | 29 | |
| 40 | 30 | $template = false; |
| 41 | - if ($this->helper->get('cache')) { | |
| 31 | + if ($this->helper->get('cache') && !$revision_id) { | |
| 42 | 32 | $template = wp_cache_get($template_id, 'e2pdf_templates'); |
| 43 | 33 | } |
| 44 | 34 | |
| 45 | 35 | if ($template === false) { |
| 46 | - $template = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$this->get_table()}` WHERE ID = %d", $template_id), ARRAY_A); | |
| 47 | - if ($this->helper->get('cache')) { | |
| 36 | + $this->helper->load('cache')->pre_objects_cache(); | |
| 37 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 38 | + $template = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $this->get_table() . '` WHERE ID = %d', $template_id), ARRAY_A); | |
| 39 | + if ($this->helper->get('cache') && !$revision_id) { | |
| 48 | 40 | wp_cache_set($template_id, $template, 'e2pdf_templates'); |
| 49 | 41 | } |
| 50 | 42 | } |
| 51 | 43 | |
| 44 | + if ($revision_id) { | |
| 45 | + $revision = new Model_E2pdf_Revision(); | |
| 46 | + if ($revision->load($template_id, false, $revision_id)) { | |
| 47 | + $template = array_replace($template, $revision->template()); | |
| 48 | + } else { | |
| 49 | + $template = []; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 52 | 53 | if ($template) { |
| 54 | + $template = apply_filters('e2pdf_load_template', $template, $this); | |
| 53 | 55 | $this->template = $template; |
| 54 | - | |
| 55 | 56 | $extension = new Model_E2pdf_Extension(); |
| 56 | 57 | if ($this->get('extension')) { |
| 57 | 58 | $extension->load($this->get('extension')); |
| 58 | 59 | } |
| @@ -57,31 +58,52 @@ | ||
| 57 | 58 | $extension->load($this->get('extension')); |
| 58 | 59 | } |
| 59 | 60 | if ($this->get('item')) { |
| 60 | 61 | $extension->set('item', $this->get('item')); |
| 62 | + if ($this->get('item') == '-2') { | |
| 63 | + $extension->set('item1', $this->get('item1')); | |
| 64 | + $extension->set('item2', $this->get('item2')); | |
| 65 | + } | |
| 61 | 66 | } |
| 62 | 67 | if ($this->get('ID')) { |
| 63 | 68 | $extension->set('template_id', $this->get('ID')); |
| 64 | 69 | } |
| 70 | + $extension = apply_filters('e2pdf_load_template_extension', $extension, $this); | |
| 65 | 71 | $this->extension = $extension; |
| 66 | - | |
| 67 | 72 | if ($full) { |
| 68 | - $this->set('fonts', unserialize($template['fonts'])); | |
| 73 | + $this->set('fonts', $this->helper->load('convert')->unserialize($template['fonts'])); | |
| 74 | + $this->set('permissions', $this->helper->load('convert')->unserialize($template['permissions'])); | |
| 75 | + $this->set('properties', $this->helper->load('convert')->unserialize($template['properties'])); | |
| 76 | + $this->set('actions', $this->helper->load('convert')->unserialize($template['actions'])); | |
| 69 | 77 | |
| 70 | 78 | $pages = false; |
| 71 | - if ($this->helper->get('cache')) { | |
| 79 | + if ($this->helper->get('cache') && !$revision_id) { | |
| 72 | 80 | $pages = wp_cache_get($this->get('ID'), 'e2pdf_pages'); |
| 73 | 81 | } |
| 74 | - | |
| 75 | 82 | if ($pages === false) { |
| 83 | + $this->helper->load('cache')->pre_objects_cache(); | |
| 76 | 84 | $model_e2pdf_page = new Model_E2pdf_Page(); |
| 77 | - $pages = $model_e2pdf_page->get_pages($this->get('ID')); | |
| 78 | - if ($this->helper->get('cache')) { | |
| 85 | + $pages = $model_e2pdf_page->get_pages($this->get('ID'), $revision_id); | |
| 86 | + if ($this->helper->get('cache') && !$revision_id) { | |
| 79 | 87 | wp_cache_set($this->get('ID'), $pages, 'e2pdf_pages'); |
| 80 | 88 | } |
| 81 | 89 | } |
| 90 | + $this->set('pages', $pages); | |
| 82 | 91 | |
| 83 | - $this->set('pages', $pages); | |
| 92 | + $revisions = false; | |
| 93 | + if ($this->helper->get('cache')) { | |
| 94 | + $revisions = wp_cache_get($this->get('ID'), 'e2pdf_revisions'); | |
| 95 | + } | |
| 96 | + | |
| 97 | + if ($revisions === false) { | |
| 98 | + $this->helper->load('cache')->pre_objects_cache(); | |
| 99 | + $model_e2pdf_revision = new Model_E2pdf_Revision(); | |
| 100 | + $revisions = $model_e2pdf_revision->revisions($this->get('ID')); | |
| 101 | + if ($this->helper->get('cache')) { | |
| 102 | + wp_cache_set($this->get('ID'), $revisions, 'e2pdf_revisions'); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + $this->set('revisions', $revisions); | |
| 84 | 106 | } |
| 85 | 107 | return true; |
| 86 | 108 | } |
| 87 | 109 | return false; |
| @@ -86,51 +108,84 @@ | ||
| 86 | 108 | } |
| 87 | 109 | return false; |
| 88 | 110 | } |
| 89 | 111 | |
| 90 | - /** | |
| 91 | - * Get loaded Template | |
| 92 | - * | |
| 93 | - * @return object | |
| 94 | - */ | |
| 112 | + // template | |
| 95 | 113 | public function template() { |
| 96 | 114 | return $this->template; |
| 97 | 115 | } |
| 98 | 116 | |
| 117 | + // extension | |
| 99 | 118 | public function extension() { |
| 100 | 119 | return $this->extension; |
| 101 | 120 | } |
| 102 | 121 | |
| 103 | - /** | |
| 104 | - * Set Template attribute | |
| 105 | - * | |
| 106 | - * @param string $key - Attribute Key | |
| 107 | - * @param string $value - Attribute Value | |
| 108 | - */ | |
| 122 | + // set | |
| 109 | 123 | public function set($key, $value) { |
| 110 | - $this->template[$key] = $value; | |
| 124 | + switch ($key) { | |
| 125 | + case 'format': | |
| 126 | + if (in_array($value, ['pdf', 'jpg'], true)) { | |
| 127 | + $this->template[$key] = $value; | |
| 128 | + return true; | |
| 129 | + } else { | |
| 130 | + return false; | |
| 131 | + } | |
| 132 | + break; | |
| 133 | + case 'permissions': | |
| 134 | + if (!is_array($value)) { | |
| 135 | + $this->template[$key] = ['printing']; | |
| 136 | + } else { | |
| 137 | + $this->template[$key] = $value; | |
| 138 | + } | |
| 139 | + break; | |
| 140 | + case 'fonts': | |
| 141 | + case 'properties': | |
| 142 | + case 'actions': | |
| 143 | + if (!is_array($value)) { | |
| 144 | + $this->template[$key] = []; | |
| 145 | + } else { | |
| 146 | + $this->template[$key] = $value; | |
| 147 | + } | |
| 148 | + break; | |
| 149 | + default: | |
| 150 | + $this->template[$key] = $value; | |
| 151 | + break; | |
| 152 | + } | |
| 153 | + return true; | |
| 111 | 154 | } |
| 112 | 155 | |
| 113 | - /** | |
| 114 | - * Get Template attribute by Key | |
| 115 | - * | |
| 116 | - * @param string $key - Attribute Key | |
| 117 | - * | |
| 118 | - * @return mixed | |
| 119 | - */ | |
| 120 | - public function get($key) { | |
| 121 | - if (isset($this->template[$key])) { | |
| 122 | - $value = $this->template[$key]; | |
| 156 | + // get | |
| 157 | + public function get($key, $force = false) { | |
| 158 | + if ($force && $this->get('ID')) { | |
| 159 | + global $wpdb; | |
| 160 | + if ($key == 'activated') { | |
| 161 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 162 | + $value = $wpdb->get_var($wpdb->prepare('SELECT `activated` FROM `' . $this->get_table() . '` WHERE ID = %d', $this->get('ID'))); | |
| 163 | + } elseif ($key == 'uid') { | |
| 164 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 165 | + $value = $wpdb->get_var($wpdb->prepare('SELECT `uid` FROM `' . $this->get_table() . '` WHERE ID = %d', $this->get('ID'))); | |
| 166 | + } | |
| 123 | 167 | return $value; |
| 168 | + } elseif (isset($this->template[$key])) { | |
| 169 | + if ($key == 'revisions') { | |
| 170 | + $value = [ | |
| 171 | + '0' => __('Latest', 'e2pdf'), | |
| 172 | + ]; | |
| 173 | + if (is_array($this->template[$key])) { | |
| 174 | + foreach ($this->template[$key] as $revision) { | |
| 175 | + // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 176 | + $value[$revision['revision_id']] = date('d M Y H:i:s', strtotime($revision['updated_at'])); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + } else { | |
| 180 | + $value = $this->template[$key]; | |
| 181 | + } | |
| 182 | + return $value; | |
| 124 | 183 | } else { |
| 125 | - | |
| 126 | 184 | switch ($key) { |
| 127 | - | |
| 128 | 185 | case 'title': |
| 129 | - $value = __("(no title)", 'e2pdf'); | |
| 186 | + $value = __('(no title)', 'e2pdf'); | |
| 130 | 187 | break; |
| 131 | - | |
| 132 | - case 'flatten': | |
| 133 | 188 | case 'width': |
| 134 | 189 | case 'height': |
| 135 | 190 | case 'inline': |
| 136 | 191 | case 'auto': |
| @@ -136,27 +191,54 @@ | ||
| 136 | 191 | case 'auto': |
| 137 | 192 | case 'trash': |
| 138 | 193 | case 'locked': |
| 139 | 194 | case 'activated': |
| 140 | - $value = 0; | |
| 195 | + case 'revision_id': | |
| 196 | + case 'rtl': | |
| 197 | + case 'tab_order': | |
| 198 | + $value = '0'; | |
| 141 | 199 | break; |
| 142 | - | |
| 200 | + case 'flatten': | |
| 143 | 201 | case 'appearance': |
| 144 | - $value = 1; | |
| 202 | + $value = '1'; | |
| 145 | 203 | break; |
| 146 | - | |
| 147 | 204 | case 'compression': |
| 148 | - $value = -1; | |
| 205 | + $value = '-1'; | |
| 149 | 206 | break; |
| 150 | - | |
| 207 | + case 'optimization': | |
| 208 | + $value = '-1'; | |
| 209 | + break; | |
| 151 | 210 | case 'format': |
| 152 | 211 | $value = 'pdf'; |
| 153 | 212 | break; |
| 154 | - | |
| 213 | + case 'resample': | |
| 214 | + $value = '100'; | |
| 215 | + break; | |
| 216 | + case 'text_align': | |
| 217 | + $value = 'left'; | |
| 218 | + break; | |
| 219 | + case 'permissions': | |
| 220 | + $value = [ | |
| 221 | + 'printing', | |
| 222 | + ]; | |
| 223 | + break; | |
| 155 | 224 | case 'fonts': |
| 156 | - $value = array(); | |
| 225 | + case 'properties': | |
| 226 | + case 'actions': | |
| 227 | + case 'pages': | |
| 228 | + case 'revisions': | |
| 229 | + $value = []; | |
| 157 | 230 | break; |
| 158 | - | |
| 231 | + case 'name': | |
| 232 | + case 'savename': | |
| 233 | + $value = '[e2pdf-dataset]'; | |
| 234 | + break; | |
| 235 | + case 'lang_code': | |
| 236 | + $value = 'en-US'; | |
| 237 | + break; | |
| 238 | + case 'font_processor': | |
| 239 | + $value = get_option('e2pdf_font_processor', '0'); | |
| 240 | + break; | |
| 159 | 241 | default: |
| 160 | 242 | $value = ''; |
| 161 | 243 | break; |
| 162 | 244 | } |
| @@ -163,34 +245,37 @@ | ||
| 163 | 245 | return $value; |
| 164 | 246 | } |
| 165 | 247 | } |
| 166 | 248 | |
| 167 | - /** | |
| 168 | - * Get Templates table | |
| 169 | - * | |
| 170 | - * @return string | |
| 171 | - */ | |
| 249 | + // get table | |
| 172 | 250 | public function get_table() { |
| 173 | 251 | return $this->table; |
| 174 | 252 | } |
| 175 | 253 | |
| 176 | - /** | |
| 177 | - * Delete loaded template | |
| 178 | - */ | |
| 254 | + // delete | |
| 179 | 255 | public function delete() { |
| 180 | 256 | global $wpdb; |
| 181 | 257 | if ($this->get('ID')) { |
| 258 | + | |
| 259 | + $revision = new Model_E2pdf_Revision(); | |
| 260 | + foreach ($this->get('revisions') as $revision_id => $revision_name) { | |
| 261 | + if ($revision_id != '0') { | |
| 262 | + $revision->load($this->get('ID'), true, $revision_id); | |
| 263 | + $revision->delete(); | |
| 264 | + } | |
| 265 | + } | |
| 266 | + | |
| 182 | 267 | if ($this->get('pdf')) { |
| 183 | - $pdf_dir = $this->helper->get('pdf_dir') . $this->get('pdf') . "/"; | |
| 268 | + $pdf_dir = $this->helper->get('pdf_dir') . $this->get('pdf') . '/'; | |
| 184 | 269 | $this->helper->delete_dir($pdf_dir); |
| 185 | 270 | } |
| 186 | 271 | |
| 187 | - $tpl_dir = $this->helper->get('tpl_dir') . $this->get('ID') . "/"; | |
| 272 | + $tpl_dir = $this->helper->get('tpl_dir') . $this->get('ID') . '/'; | |
| 188 | 273 | $this->helper->delete_dir($tpl_dir); |
| 189 | 274 | |
| 190 | - $where = array( | |
| 191 | - 'ID' => $this->get('ID') | |
| 192 | - ); | |
| 275 | + $where = [ | |
| 276 | + 'ID' => $this->get('ID'), | |
| 277 | + ]; | |
| 193 | 278 | $wpdb->delete($this->get_table(), $where); |
| 194 | 279 | |
| 195 | 280 | foreach ($this->get('pages') as $page) { |
| 196 | 281 | $model_e2pdf_page = new Model_E2pdf_Page(); |
| @@ -200,104 +285,190 @@ | ||
| 200 | 285 | |
| 201 | 286 | if ($this->helper->get('cache')) { |
| 202 | 287 | wp_cache_delete($this->get('ID'), 'e2pdf_templates'); |
| 203 | 288 | wp_cache_delete($this->get('ID'), 'e2pdf_pages'); |
| 289 | + wp_cache_delete($this->get('ID'), 'e2pdf_revisions'); | |
| 204 | 290 | } |
| 291 | + | |
| 292 | + $translator = $this->helper->load('translator'); | |
| 293 | + if ($translator) { | |
| 294 | + $translator->flush($this->get('ID')); | |
| 295 | + } | |
| 205 | 296 | } |
| 206 | 297 | } |
| 207 | 298 | |
| 208 | - /** | |
| 209 | - * Save template | |
| 210 | - */ | |
| 299 | + // update | |
| 300 | + public function update($keys = []) { | |
| 301 | + global $wpdb; | |
| 302 | + if ($this->get('ID') && !empty($keys)) { | |
| 303 | + $show_errors = false; | |
| 304 | + if ($wpdb->show_errors) { | |
| 305 | + $wpdb->show_errors(false); | |
| 306 | + $show_errors = true; | |
| 307 | + } | |
| 308 | + foreach ($keys as $key) { | |
| 309 | + $template[$key] = $this->get($key); | |
| 310 | + } | |
| 311 | + $where = [ | |
| 312 | + 'ID' => $this->get('ID'), | |
| 313 | + ]; | |
| 314 | + $success = $wpdb->update($this->get_table(), $template, $where); | |
| 315 | + if ($success === false) { | |
| 316 | + $this->helper->load('db')->db_init($wpdb->prefix); | |
| 317 | + $wpdb->update($this->get_table(), $template, $where); | |
| 318 | + } | |
| 319 | + if ($this->helper->get('cache')) { | |
| 320 | + wp_cache_delete($this->get('ID'), 'e2pdf_templates'); | |
| 321 | + } | |
| 322 | + if ($show_errors) { | |
| 323 | + $wpdb->show_errors(); | |
| 324 | + } | |
| 325 | + } | |
| 326 | + } | |
| 327 | + | |
| 328 | + // save | |
| 211 | 329 | public function save($rebuild = false) { |
| 212 | 330 | global $wpdb; |
| 213 | 331 | $template = $this->pre_save(); |
| 332 | + $show_errors = false; | |
| 333 | + if ($wpdb->show_errors) { | |
| 334 | + $wpdb->show_errors(false); | |
| 335 | + $show_errors = true; | |
| 336 | + } | |
| 214 | 337 | |
| 215 | 338 | if ($this->get('ID')) { |
| 216 | - $where = array( | |
| 217 | - 'ID' => $this->get('ID') | |
| 218 | - ); | |
| 219 | - $wpdb->update($this->get_table(), $template, $where); | |
| 339 | + if ($rebuild) { | |
| 340 | + $revision = new Model_E2pdf_Revision(); | |
| 341 | + $revision->revision($this->get('ID')); | |
| 342 | + if (isset($template['pdf']) && $template['pdf'] && ($template['pdf'] == $revision->get('pdf') || $this->get('revision_id'))) { | |
| 343 | + $pdf_name = md5(time()); | |
| 344 | + $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; | |
| 345 | + $pdf_images_dir = $pdf_dir . 'images/'; | |
| 346 | + | |
| 347 | + $this->helper->create_dir($pdf_dir); | |
| 348 | + $this->helper->create_dir($pdf_images_dir); | |
| 349 | + | |
| 350 | + if (file_exists($this->helper->get('pdf_dir') . $template['pdf'] . '/' . $template['pdf'] . '.pdf')) { | |
| 351 | + $images = glob($this->helper->get('pdf_dir') . $template['pdf'] . '/images/*'); | |
| 352 | + foreach ($images as $image) { | |
| 353 | + copy($image, $pdf_images_dir . pathinfo($image, PATHINFO_BASENAME)); | |
| 354 | + } | |
| 355 | + copy($this->helper->get('pdf_dir') . $template['pdf'] . '/' . $template['pdf'] . '.pdf', $this->helper->get('pdf_dir') . $pdf_name . '/' . $pdf_name . '.pdf'); | |
| 356 | + $template['pdf'] = $pdf_name; | |
| 357 | + } | |
| 358 | + } | |
| 359 | + $revision->flush(); | |
| 360 | + } | |
| 361 | + $where = [ | |
| 362 | + 'ID' => $this->get('ID'), | |
| 363 | + ]; | |
| 364 | + $success = $wpdb->update($this->get_table(), $template, $where); | |
| 365 | + if ($success === false) { | |
| 366 | + $this->helper->load('db')->db_init($wpdb->prefix); | |
| 367 | + $wpdb->update($this->get_table(), $template, $where); | |
| 368 | + } | |
| 220 | 369 | } else { |
| 221 | - $wpdb->insert($this->get_table(), $template); | |
| 370 | + if ($this->get('TMP_ID')) { | |
| 371 | + $template['ID'] = $this->get('TMP_ID'); | |
| 372 | + } | |
| 373 | + $success = $wpdb->insert($this->get_table(), $template); | |
| 374 | + if ($success === false) { | |
| 375 | + $this->helper->load('db')->db_init($wpdb->prefix); | |
| 376 | + $wpdb->insert($this->get_table(), $template); | |
| 377 | + } | |
| 222 | 378 | $this->set('ID', $wpdb->insert_id); |
| 223 | 379 | } |
| 224 | 380 | |
| 381 | + if ($show_errors) { | |
| 382 | + $wpdb->show_errors(); | |
| 383 | + } | |
| 384 | + | |
| 225 | 385 | if ($this->get('ID') && $rebuild) { |
| 226 | - $this->flush(); | |
| 227 | - foreach ($this->get('pages') as $page_key => $page_value) { | |
| 228 | - $page = new Model_E2pdf_Page(); | |
| 229 | - foreach ($page_value as $page_value_key => $page_value_value) { | |
| 230 | - $page->set($page_value_key, $page_value_value); | |
| 386 | + | |
| 387 | + $translator = $this->helper->load('translator'); | |
| 388 | + if ($translator) { | |
| 389 | + $translator->update_translation($template['title'], $this->get('ID'), 'title', 'template'); | |
| 390 | + $translator->update_translation($template['dataset_title'], $this->get('ID'), 'dataset_title', 'template'); | |
| 391 | + $translator->update_translation($template['dataset_title1'], $this->get('ID'), 'dataset_title1', 'template'); | |
| 392 | + $translator->update_translation($template['dataset_title2'], $this->get('ID'), 'dataset_title2', 'template'); | |
| 393 | + $translator->update_translation($template['button_title'], $this->get('ID'), 'button_title', 'template'); | |
| 394 | + $translator->update_translation($template['name'], $this->get('ID'), 'name', 'template'); | |
| 395 | + $translator->update_translation($template['savename'], $this->get('ID'), 'savename', 'template'); | |
| 396 | + } | |
| 397 | + | |
| 398 | + foreach ($this->get('pages') as $page_key => $page) { | |
| 399 | + $new_page = new Model_E2pdf_Page(); | |
| 400 | + foreach ($page as $page_set_key => $page_set_value) { | |
| 401 | + $new_page->set($page_set_key, $page_set_value); | |
| 231 | 402 | } |
| 232 | - | |
| 233 | - if (!$page_value['actions']) { | |
| 234 | - $page_actions = array(); | |
| 403 | + if (!isset($page['actions'])) { | |
| 404 | + $page_actions = []; | |
| 235 | 405 | } else { |
| 236 | - $page_actions = $page_value['actions']; | |
| 406 | + $page_actions = $page['actions']; | |
| 237 | 407 | } |
| 238 | - $page->set('actions', $page_actions); | |
| 239 | - | |
| 240 | - $page->set('template_id', $this->get('ID')); | |
| 241 | - $page->set('page_id', $page_key); | |
| 242 | - $page->save(); | |
| 243 | - | |
| 244 | - if (isset($page_value['elements'])) { | |
| 245 | - | |
| 246 | - $this->helper->load('sort')->uasort($page_value['elements'], "sort_by_elementid"); | |
| 247 | - | |
| 248 | - foreach ($page_value['elements'] as $element_key => $element_value) { | |
| 249 | - $element = new Model_E2pdf_Element(); | |
| 250 | - foreach ($element_value as $element_value_key => $element_value_value) { | |
| 251 | - $element->set($element_value_key, $element_value_value); | |
| 408 | + $new_page->set('actions', $page_actions); | |
| 409 | + $new_page->set('template_id', $this->get('ID')); | |
| 410 | + $new_page->set('page_id', $page_key); | |
| 411 | + $new_page->save(); | |
| 412 | + if (!empty($page['elements'])) { | |
| 413 | + foreach ($page['elements'] as $element_key => $element) { | |
| 414 | + $new_element = new Model_E2pdf_Element(); | |
| 415 | + foreach ($element as $element_set_key => $element_set_value) { | |
| 416 | + $new_element->set($element_set_key, $element_set_value); | |
| 417 | + if ($translator) { | |
| 418 | + if ($element_set_key == 'value') { | |
| 419 | + $translator->update_translation($element_set_value, $this->get('ID'), $element['element_id'], $element_set_key); | |
| 420 | + } | |
| 421 | + } | |
| 252 | 422 | } |
| 253 | 423 | |
| 254 | - if (!$element_value['properties']) { | |
| 255 | - $element_properties = array(); | |
| 256 | - } else { | |
| 257 | - $element_properties = $element_value['properties']; | |
| 424 | + if ($translator) { | |
| 425 | + if (!empty($element['properties']['option'])) { | |
| 426 | + $translator->update_translation($element['properties']['option'], $this->get('ID'), $element['element_id'], 'option'); | |
| 427 | + } | |
| 428 | + if (!empty($element['properties']['options'])) { | |
| 429 | + $translator->update_translation($element['properties']['options'], $this->get('ID'), $element['element_id'], 'options'); | |
| 430 | + } | |
| 431 | + if (!empty($element['actions'])) { | |
| 432 | + foreach ($element['actions'] as $action_key => $action) { | |
| 433 | + if ($action['action'] == 'change' && isset($action['property']) && $action['property'] == 'value' && isset($action['change'])) { | |
| 434 | + $translator->update_translation($action['change'], $this->get('ID'), $element['element_id'], 'value_action_' . $action_key . '_change'); | |
| 435 | + } | |
| 436 | + } | |
| 437 | + } | |
| 258 | 438 | } |
| 259 | - $element->set('properties', $element_properties); | |
| 260 | - | |
| 261 | - if (!$element_value['actions']) { | |
| 262 | - $element_actions = array(); | |
| 263 | - } else { | |
| 264 | - $element_actions = $element_value['actions']; | |
| 265 | - } | |
| 266 | - $element->set('actions', $element_actions); | |
| 267 | - $element->set('page_id', $page->get('page_id')); | |
| 268 | - $element->set('template_id', $this->get('ID')); | |
| 269 | - $element->save(); | |
| 439 | + $new_element->set('properties', isset($element['properties']) ? $element['properties'] : []); | |
| 440 | + $new_element->set('actions', isset($element['actions']) ? $element['actions'] : []); | |
| 441 | + $new_element->set('page_id', $new_page->get('page_id')); | |
| 442 | + $new_element->set('template_id', $this->get('ID')); | |
| 443 | + $new_element->save(); | |
| 270 | 444 | } |
| 271 | 445 | } |
| 272 | 446 | } |
| 447 | + if ($translator) { | |
| 448 | + $translator->flush($this->get('ID')); | |
| 449 | + } | |
| 273 | 450 | } |
| 274 | 451 | |
| 275 | 452 | if ($this->helper->get('cache') && $this->get('ID')) { |
| 276 | 453 | wp_cache_delete($this->get('ID'), 'e2pdf_templates'); |
| 277 | 454 | wp_cache_delete($this->get('ID'), 'e2pdf_pages'); |
| 455 | + wp_cache_delete($this->get('ID'), 'e2pdf_revisions'); | |
| 278 | 456 | } |
| 279 | 457 | |
| 280 | 458 | return $this->get('ID'); |
| 281 | 459 | } |
| 282 | 460 | |
| 283 | - /** | |
| 284 | - * Before save template | |
| 285 | - */ | |
| 286 | - public function pre_save() { | |
| 287 | - | |
| 288 | - $fonts = array(); | |
| 461 | + // pre save | |
| 462 | + public function load_fonts() { | |
| 463 | + $fonts = []; | |
| 289 | 464 | $model_e2pdf_font = new Model_E2pdf_Font(); |
| 290 | - | |
| 291 | 465 | $all_fonts = $model_e2pdf_font->get_fonts(); |
| 292 | - | |
| 293 | - $c_font = array_search($this->get('font'), $all_fonts); | |
| 466 | + $c_font = array_search($this->get('font'), $all_fonts, true); | |
| 294 | 467 | if ($c_font) { |
| 295 | 468 | $fonts[$c_font] = $this->get('font'); |
| 296 | 469 | } |
| 297 | - | |
| 298 | - $pages = $this->get('pages'); | |
| 299 | - foreach ($pages as $key => $page) { | |
| 470 | + foreach ($this->get('pages') as $key => $page) { | |
| 300 | 471 | if (!empty($page['elements'])) { |
| 301 | 472 | foreach ($page['elements'] as $element_key => $element) { |
| 302 | 473 | $tmp_fonts = $model_e2pdf_font->get_element_fonts($element, $all_fonts); |
| 303 | 474 | if (!empty($tmp_fonts)) { |
| @@ -306,44 +477,73 @@ | ||
| 306 | 477 | } |
| 307 | 478 | } |
| 308 | 479 | } |
| 309 | 480 | |
| 481 | + if (isset($this->get('properties')['css']) && $this->get('properties')['css']) { | |
| 482 | + $tmp_fonts = $model_e2pdf_font->get_css_fonts($this->get('properties')['css'], $all_fonts); | |
| 483 | + if (!empty($tmp_fonts)) { | |
| 484 | + $fonts = array_merge($fonts, $tmp_fonts); | |
| 485 | + } | |
| 486 | + } | |
| 487 | + | |
| 310 | 488 | $this->set('fonts', $fonts); |
| 489 | + } | |
| 311 | 490 | |
| 312 | - $template = array( | |
| 491 | + // pre save | |
| 492 | + public function pre_save() { | |
| 493 | + $this->load_fonts(); | |
| 494 | + $template = [ | |
| 313 | 495 | 'uid' => $this->get('uid'), |
| 496 | + 'activated' => $this->get('activated'), | |
| 314 | 497 | 'title' => $this->get('title'), |
| 315 | 498 | 'pdf' => $this->get('pdf'), |
| 316 | 499 | 'updated_at' => current_time('mysql', 1), |
| 317 | 500 | 'flatten' => $this->get('flatten'), |
| 501 | + 'tab_order' => $this->get('tab_order'), | |
| 318 | 502 | 'format' => $this->get('format'), |
| 503 | + 'resample' => $this->get('resample'), | |
| 319 | 504 | 'compression' => $this->get('compression'), |
| 505 | + 'optimization' => $this->get('optimization'), | |
| 320 | 506 | 'appearance' => $this->get('appearance'), |
| 321 | 507 | 'width' => $this->get('width'), |
| 322 | 508 | 'height' => $this->get('height'), |
| 323 | 509 | 'extension' => $this->get('extension'), |
| 324 | 510 | 'item' => $this->get('item'), |
| 325 | - 'format' => $this->get('format'), | |
| 511 | + 'item1' => $this->get('item1'), | |
| 512 | + 'item2' => $this->get('item2'), | |
| 326 | 513 | 'dataset_title' => $this->get('dataset_title'), |
| 514 | + 'dataset_title1' => $this->get('dataset_title1'), | |
| 515 | + 'dataset_title2' => $this->get('dataset_title2'), | |
| 327 | 516 | 'button_title' => $this->get('button_title'), |
| 517 | + 'dpdf' => $this->get('dpdf'), | |
| 328 | 518 | 'inline' => $this->get('inline'), |
| 329 | 519 | 'auto' => $this->get('auto'), |
| 520 | + 'rtl' => $this->get('rtl'), | |
| 521 | + 'font_processor' => $this->get('font_processor'), | |
| 330 | 522 | 'name' => $this->get('name'), |
| 523 | + 'savename' => $this->get('savename'), | |
| 331 | 524 | 'password' => $this->get('password'), |
| 525 | + 'owner_password' => $this->get('owner_password'), | |
| 526 | + 'permissions' => serialize($this->get('permissions')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 527 | + 'hooks' => $this->get('hooks'), | |
| 332 | 528 | 'meta_title' => $this->get('meta_title'), |
| 333 | 529 | 'meta_subject' => $this->get('meta_subject'), |
| 334 | 530 | 'meta_author' => $this->get('meta_author'), |
| 335 | 531 | 'meta_keywords' => $this->get('meta_keywords'), |
| 336 | - 'fonts' => serialize($this->get('fonts')), | |
| 532 | + 'lang_code' => $this->get('lang_code'), | |
| 533 | + 'fonts' => serialize($this->get('fonts')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 337 | 534 | 'font' => $this->get('font'), |
| 338 | 535 | 'font_size' => $this->get('font_size'), |
| 339 | 536 | 'font_color' => $this->get('font_color'), |
| 340 | 537 | 'line_height' => $this->get('line_height'), |
| 538 | + 'text_align' => $this->get('text_align'), | |
| 341 | 539 | 'trash' => $this->get('trash'), |
| 342 | 540 | 'locked' => $this->get('locked'), |
| 343 | - 'activated' => $this->get('activated'), | |
| 344 | 541 | 'author' => get_current_user_id(), |
| 345 | - ); | |
| 542 | + 'properties' => serialize($this->get('properties')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 543 | + 'actions' => serialize($this->get('actions')), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 544 | + 'attachments' => $this->get('attachments'), | |
| 545 | + ]; | |
| 346 | 546 | |
| 347 | 547 | if (!$this->get('ID')) { |
| 348 | 548 | $template['created_at'] = current_time('mysql', 1); |
| 349 | 549 | } |
| @@ -350,40 +550,23 @@ | ||
| 350 | 550 | |
| 351 | 551 | return $template; |
| 352 | 552 | } |
| 353 | 553 | |
| 354 | - public function fill($dataset = false, $uid = false) { | |
| 554 | + // fill | |
| 555 | + public function fill() { | |
| 355 | 556 | |
| 356 | - $this->set('dataset', $dataset); | |
| 357 | - $this->extension()->set('dataset', $this->get('dataset')); | |
| 557 | + add_filter('e2pdf_pdf_fill', [$this->helper, '__return_true'], 999); | |
| 558 | + do_action('e2pdf_model_template_fill_pre', $this, $this->extension); | |
| 358 | 559 | |
| 359 | - if ($uid) { | |
| 360 | - $this->extension()->set('uid', $uid); | |
| 361 | - $entry = new Model_E2pdf_Entry(); | |
| 362 | - if ($entry->load_by_uid($uid)) { | |
| 363 | - $uid_params = $entry->get('entry'); | |
| 364 | - if (isset($uid_params['user_id'])) { | |
| 365 | - $this->extension()->set('user_id', $uid_params['user_id']); | |
| 366 | - } | |
| 367 | - if (isset($uid_params['args'])) { | |
| 368 | - $this->extension()->set('args', $uid_params['args']); | |
| 369 | - } | |
| 370 | - } | |
| 371 | - } | |
| 372 | - | |
| 373 | - do_action('e2pdf_model_template_fill_pre', $this, $this->extension()); | |
| 374 | - | |
| 375 | 560 | $action = new Model_E2pdf_Action(); |
| 376 | - $action->load($this->extension()); | |
| 377 | - | |
| 561 | + $action->load($this->extension); | |
| 378 | 562 | $pages = $this->get('pages'); |
| 379 | - | |
| 380 | - $changed_elements = array(); | |
| 563 | + $changed_elements = []; | |
| 381 | 564 | foreach ($pages as $key => $value) { |
| 382 | 565 | $changed_elements = array_merge($changed_elements, $action->process_page_id($value)); |
| 383 | 566 | } |
| 384 | 567 | |
| 385 | - $changed_pages = array(); | |
| 568 | + $changed_pages = []; | |
| 386 | 569 | if (!empty($changed_elements)) { |
| 387 | 570 | foreach ($changed_elements as $element) { |
| 388 | 571 | $changed_pages[$element['page_id']][] = $element; |
| 389 | 572 | } |
| @@ -388,80 +571,145 @@ | ||
| 388 | 571 | $changed_pages[$element['page_id']][] = $element; |
| 389 | 572 | } |
| 390 | 573 | } |
| 391 | 574 | |
| 392 | - foreach ($pages as $key => $value) { | |
| 393 | - | |
| 394 | - if (isset($changed_pages[$value['page_id']])) { | |
| 395 | - $value['elements'] = array_merge($value['elements'], $changed_pages[$value['page_id']]); | |
| 575 | + foreach ($pages as $page_key => $page) { | |
| 576 | + if (isset($changed_pages[$page['page_id']])) { | |
| 577 | + $page['elements'] = array_merge($page['elements'], $changed_pages[$page['page_id']]); | |
| 396 | 578 | } |
| 397 | - | |
| 398 | - $pages[$key] = $value = $action->process_actions($value); | |
| 399 | - | |
| 400 | - if ($value) { | |
| 401 | - if (!empty($value['elements'])) { | |
| 402 | - | |
| 403 | - $this->helper->load('sort')->stable_uasort($value['elements'], "sort_by_zindex"); | |
| 404 | - $pages[$key]['elements'] = $value['elements']; | |
| 405 | - | |
| 406 | - foreach ($value['elements'] as $el_key => $el_value) { | |
| 407 | - if ($el_value['type'] === 'e2pdf-checkbox') { | |
| 408 | - //e2pdf-checkbox render | |
| 409 | - $pages[$key]['elements'][$el_key]['properties']['option'] = $this->extension()->render( | |
| 410 | - $el_value['properties']['option'], false, $el_value | |
| 411 | - ); | |
| 412 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 413 | - $el_value['value'], 'value', $el_value | |
| 414 | - ); | |
| 415 | - } elseif ($el_value['type'] === 'e2pdf-radio') { | |
| 416 | - //e2pdf-radio render | |
| 417 | - $pages[$key]['elements'][$el_key]['properties']['option'] = $this->extension()->render( | |
| 418 | - $el_value['properties']['option'], false, $el_value | |
| 419 | - ); | |
| 420 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 421 | - $el_value['value'], 'value', $el_value | |
| 422 | - ); | |
| 423 | - } elseif ($el_value['type'] === 'e2pdf-select') { | |
| 424 | - //e2pdf-select render | |
| 425 | - $pages[$key]['elements'][$el_key]['properties']['options'] = $this->extension()->render( | |
| 426 | - $el_value['properties']['options'], false, $el_value | |
| 427 | - ); | |
| 428 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 429 | - $el_value['value'], 'value', $el_value | |
| 430 | - ); | |
| 431 | - } elseif ($el_value['type'] === 'e2pdf-html') { | |
| 432 | - //e2pdf-html render | |
| 433 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 434 | - $el_value['value'], 'value', $el_value | |
| 435 | - ); | |
| 436 | - } elseif ($el_value['type'] === 'e2pdf-image') { | |
| 437 | - //e2pdf-image render | |
| 438 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 439 | - $el_value['value'], 'value', $el_value | |
| 440 | - ); | |
| 441 | - } elseif ($el_value['type'] === 'e2pdf-signature') { | |
| 442 | - //e2pdf-signature render | |
| 443 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 444 | - $el_value['value'], 'value', $el_value | |
| 445 | - ); | |
| 446 | - } else { | |
| 447 | - //another e2pdf fields render | |
| 448 | - $pages[$key]['elements'][$el_key]['value'] = $this->extension()->render( | |
| 449 | - $el_value['value'], 'value', $el_value | |
| 450 | - ); | |
| 579 | + // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found | |
| 580 | + $pages[$page_key] = $page = $action->process_actions($page); | |
| 581 | + if (isset($page['hidden']) && $page['hidden']) { | |
| 582 | + $pages[$page_key]['page_id'] = '0'; | |
| 583 | + $pages[$page_key]['elements'] = []; | |
| 584 | + } else { | |
| 585 | + if (!empty($page['elements'])) { | |
| 586 | + $pages[$page_key]['elements'] = $page['elements']; | |
| 587 | + foreach ($page['elements'] as $element_key => $element) { | |
| 588 | + if (isset($element['type'])) { | |
| 589 | + $rendered = isset($element['rendered']) ? $element['rendered'] : false; | |
| 590 | + switch ($element['type']) { | |
| 591 | + case 'e2pdf-checkbox': | |
| 592 | + case 'e2pdf-radio': | |
| 593 | + if (isset($element['properties']['option'])) { | |
| 594 | + $element['properties']['option'] = $this->helper->load('translator')->pre_translate($element['properties']['option'], $element['template_id'], $element['element_id'], 'option'); | |
| 595 | + } | |
| 596 | + $pages[$page_key]['elements'][$element_key]['properties']['option'] = $this->extension()->render( | |
| 597 | + isset($element['properties']['option']) ? $element['properties']['option'] : '' | |
| 598 | + ); | |
| 599 | + if (!$rendered) { | |
| 600 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 601 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 602 | + $element['value'], $element | |
| 603 | + ); | |
| 604 | + } | |
| 605 | + break; | |
| 606 | + case 'e2pdf-select': | |
| 607 | + if (isset($element['properties']['options'])) { | |
| 608 | + $element['properties']['options'] = $this->helper->load('translator')->pre_translate($element['properties']['options'], $element['template_id'], $element['element_id'], 'options'); | |
| 609 | + } | |
| 610 | + $pages[$page_key]['elements'][$element_key]['properties']['options'] = $this->extension()->render( | |
| 611 | + isset($element['properties']['options']) ? $element['properties']['options'] : '' | |
| 612 | + ); | |
| 613 | + if (!$rendered) { | |
| 614 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 615 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 616 | + $element['value'], $element | |
| 617 | + ); | |
| 618 | + } | |
| 619 | + break; | |
| 620 | + case 'e2pdf-html': | |
| 621 | + case 'e2pdf-page-number': | |
| 622 | + if (!$rendered) { | |
| 623 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 624 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('filter')->filter_html_tags( | |
| 625 | + $this->extension()->render( | |
| 626 | + $element['value'], $element | |
| 627 | + ) | |
| 628 | + ); | |
| 629 | + } | |
| 630 | + break; | |
| 631 | + case 'e2pdf-image': | |
| 632 | + case 'e2pdf-signature': | |
| 633 | + if (isset($element['properties']['quality']) && $element['properties']['quality']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf | |
| 634 | + } else { | |
| 635 | + $element['properties']['quality'] = $this->get('optimization'); | |
| 636 | + $pages[$page_key]['elements'][$element_key]['properties']['quality'] = $this->get('optimization'); | |
| 637 | + } | |
| 638 | + if (!$rendered) { | |
| 639 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 640 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 641 | + $element['value'], $element | |
| 642 | + ); | |
| 643 | + } | |
| 644 | + if (!empty($element['properties']['link_url'])) { | |
| 645 | + $pages[$page_key]['elements'][$element_key]['properties']['link_url'] = $this->extension()->render( | |
| 646 | + $element['properties']['link_url'] | |
| 647 | + ); | |
| 648 | + if (!empty($pages[$page_key]['elements'][$element_key]['properties']['link_url']) && !empty($element['properties']['link_type']) && $element['properties']['link_type'] == 'attachment') { | |
| 649 | + $source = $this->helper->load('attachments')->get_file(trim($pages[$page_key]['elements'][$element_key]['properties']['link_url']), $this->extension); | |
| 650 | + if ($source) { | |
| 651 | + $pages[$page_key]['elements'][$element_key]['attachment']['value'] = $source; | |
| 652 | + $pages[$page_key]['elements'][$element_key]['attachment']['name'] = $this->helper->load('attachments')->get_attachment_name($pages[$page_key]['elements'][$element_key]['properties']['link_url'], $this->extension, $element['value']); | |
| 653 | + $pages[$page_key]['elements'][$element_key]['attachment']['description'] = $this->helper->load('attachments')->get_attachment_description($pages[$page_key]['elements'][$element_key]['properties']['link_url'], $this->extension, $element['value']); | |
| 654 | + } | |
| 655 | + } | |
| 656 | + } | |
| 657 | + break; | |
| 658 | + case 'e2pdf-link': | |
| 659 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 660 | + $element['value'], $element | |
| 661 | + ); | |
| 662 | + $pages[$page_key]['elements'][$element_key]['properties']['link_label'] = $this->extension()->render( | |
| 663 | + !empty($element['properties']['link_label']) ? $element['properties']['link_label'] : '' | |
| 664 | + ); | |
| 665 | + if (!empty($pages[$page_key]['elements'][$element_key]['value']) && !empty($element['properties']['link_type']) && $element['properties']['link_type'] == 'attachment') { | |
| 666 | + $source = $this->helper->load('attachments')->get_file(trim($pages[$page_key]['elements'][$element_key]['value']), $this->extension); | |
| 667 | + if ($source) { | |
| 668 | + $pages[$page_key]['elements'][$element_key]['attachment']['value'] = $source; | |
| 669 | + $pages[$page_key]['elements'][$element_key]['attachment']['name'] = $this->helper->load('attachments')->get_attachment_name($pages[$page_key]['elements'][$element_key]['value'], $this->extension, $element['value']); | |
| 670 | + $pages[$page_key]['elements'][$element_key]['attachment']['description'] = $this->helper->load('attachments')->get_attachment_description($pages[$page_key]['elements'][$element_key]['value'], $this->extension, $element['value']); | |
| 671 | + } | |
| 672 | + } | |
| 673 | + break; | |
| 674 | + case 'e2pdf-graph': | |
| 675 | + if (!$rendered) { | |
| 676 | + $chart = 0 === strpos($element['value'], '[frm-graph'); | |
| 677 | + if ($chart) { | |
| 678 | + $element['properties']['chart'] = '1'; | |
| 679 | + $pages[$page_key]['elements'][$element_key]['properties']['chart'] = '1'; | |
| 680 | + } | |
| 681 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 682 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 683 | + $element['value'], $element | |
| 684 | + ); | |
| 685 | + if ($chart) { | |
| 686 | + $data = $this->helper->load('convert')->unserialize($pages[$page_key]['elements'][$element_key]['value']); | |
| 687 | + $pages[$page_key]['elements'][$element_key]['value'] = is_array($data) ? json_encode($data) : ''; | |
| 688 | + } | |
| 689 | + } | |
| 690 | + break; | |
| 691 | + default: | |
| 692 | + if (!$rendered) { | |
| 693 | + $element['value'] = $this->helper->load('translator')->pre_translate($element['value'], $element['template_id'], $element['element_id'], 'value'); | |
| 694 | + $pages[$page_key]['elements'][$element_key]['value'] = $this->extension()->render( | |
| 695 | + $element['value'], $element | |
| 696 | + ); | |
| 697 | + } | |
| 698 | + break; | |
| 699 | + } | |
| 451 | 700 | } |
| 452 | 701 | } |
| 453 | 702 | } |
| 454 | - } else { | |
| 455 | - unset($pages[$key]); | |
| 456 | 703 | } |
| 457 | 704 | } |
| 458 | - | |
| 459 | 705 | $this->set('pages', $pages); |
| 460 | 706 | |
| 461 | - do_action('e2pdf_model_template_fill_after', $this, $this->extension()); | |
| 707 | + do_action('e2pdf_model_template_fill_after', $this, $this->extension); | |
| 708 | + remove_filter('e2pdf_pdf_fill', [$this->helper, '__return_true'], 999); | |
| 462 | 709 | } |
| 463 | 710 | |
| 711 | + // pre render | |
| 464 | 712 | public function pre_render() { |
| 465 | 713 | $pages = $this->get('pages'); |
| 466 | 714 | foreach ($pages as $key => $page) { |
| 467 | 715 | $page = (array) $page; |
| @@ -466,158 +714,205 @@ | ||
| 466 | 714 | foreach ($pages as $key => $page) { |
| 467 | 715 | $page = (array) $page; |
| 468 | 716 | $pages[$key] = $page; |
| 469 | 717 | if (!empty($page['elements'])) { |
| 470 | - foreach ($page['elements'] as $el_key => $el_value) { | |
| 471 | - $el_value = (array) $el_value; | |
| 472 | - $pages[$key]['elements'][$el_key] = $el_value; | |
| 473 | - $esig = isset($el_value['properties']['esig']) && $el_value['properties']['esig'] ? true : false; | |
| 474 | - if ($el_value['type'] == 'e2pdf-image' || ($el_value['type'] == 'e2pdf-signature' && !$esig)) { | |
| 475 | - if ($image = $this->helper->load('image')->get_image($el_value['value'])) { | |
| 476 | - $pages[$key]['elements'][$el_key]['value'] = $image; | |
| 477 | - } else { | |
| 478 | - $pages[$key]['elements'][$el_key]['value'] = ''; | |
| 718 | + foreach ($page['elements'] as $element_key => $element) { | |
| 719 | + $element = (array) $element; | |
| 720 | + $pages[$key]['elements'][$element_key] = $element; | |
| 721 | + if ($element['type'] == 'e2pdf-qrcode' || $element['type'] == 'e2pdf-barcode' || $element['type'] == 'e2pdf-graph') { | |
| 722 | + $pages[$key]['elements'][$element_key]['type'] = 'e2pdf-image'; | |
| 723 | + } elseif ($element['type'] == 'e2pdf-html') { | |
| 724 | + if (!empty($element['properties']['css_style'])) { | |
| 725 | + $pages[$key]['elements'][$element_key]['properties']['css'] = $this->helper->load('properties')->css_style( | |
| 726 | + isset($element['properties']['css']) ? $element['properties']['css'] : '', $element['properties']['css_style'] | |
| 727 | + ); | |
| 479 | 728 | } |
| 480 | 729 | } |
| 481 | 730 | } |
| 482 | 731 | } |
| 732 | + $this->helper->load('sort')->uasort($pages[$key]['elements'], 'sort_by_elementid'); | |
| 733 | + $this->helper->load('sort')->stable_uasort($pages[$key]['elements'], 'sort_by_zindex'); | |
| 483 | 734 | } |
| 484 | - | |
| 485 | 735 | return $pages; |
| 486 | 736 | } |
| 487 | 737 | |
| 488 | - public function convert($pre_save, $type = false) { | |
| 738 | + // render | |
| 739 | + public function render($type = false) { | |
| 489 | 740 | |
| 490 | - $model_e2pdf_convert = new Model_E2pdf_Convert(); | |
| 741 | + $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 491 | 742 | $model_e2pdf_font = new Model_E2pdf_Font(); |
| 492 | 743 | |
| 493 | - if ($pre_save) { | |
| 494 | - $pages = $this->get('pages'); | |
| 495 | - $this->template = $this->pre_save(); | |
| 496 | - $this->set('pages', $pages); | |
| 497 | - $this->set('fonts', unserialize($this->get('fonts'))); | |
| 498 | - } | |
| 499 | - | |
| 500 | - $fonts = array(); | |
| 501 | - if ($this->get('fonts')) { | |
| 502 | - foreach ($this->get('fonts') as $key => $value) { | |
| 503 | - $fonts[] = array( | |
| 504 | - 'name' => $value, | |
| 505 | - 'value' => $model_e2pdf_font->get_font($key) | |
| 506 | - ); | |
| 744 | + $fonts = []; | |
| 745 | + if (get_option('e2pdf_cache_fonts', '1') && $type != 'php') { | |
| 746 | + $cached_fonts = get_option('e2pdf_cached_fonts', []); | |
| 747 | + if ($this->get('fonts')) { | |
| 748 | + $uncached_fonts = []; | |
| 749 | + foreach ($this->get('fonts') as $key => $value) { | |
| 750 | + $md5 = $model_e2pdf_font->get_font($key, true); | |
| 751 | + if ($md5 && in_array($md5, $cached_fonts, true)) { | |
| 752 | + $fonts[] = [ | |
| 753 | + 'name' => $value, | |
| 754 | + 'md5' => $md5, | |
| 755 | + 'cache' => true, | |
| 756 | + ]; | |
| 757 | + } else { | |
| 758 | + $uncached_fonts[] = $md5; | |
| 759 | + $fonts[] = [ | |
| 760 | + 'name' => $value, | |
| 761 | + 'value' => $model_e2pdf_font->get_font($key), | |
| 762 | + 'cache' => true, | |
| 763 | + ]; | |
| 764 | + } | |
| 765 | + } | |
| 766 | + if (!empty($uncached_fonts)) { | |
| 767 | + $model_e2pdf_api->set( | |
| 768 | + [ | |
| 769 | + 'action' => 'cache/fonts', | |
| 770 | + 'data' => [ | |
| 771 | + 'fonts' => $uncached_fonts, | |
| 772 | + ], | |
| 773 | + ] | |
| 774 | + ); | |
| 775 | + $request = $model_e2pdf_api->request(); | |
| 776 | + if (isset($request['fonts']) && is_array($request['fonts'])) { | |
| 777 | + $cached_fonts = array_merge($cached_fonts, $request['fonts']); | |
| 778 | + } | |
| 779 | + update_option('e2pdf_cached_fonts', $cached_fonts); | |
| 780 | + } | |
| 507 | 781 | } |
| 782 | + } else { | |
| 783 | + if ($this->get('fonts')) { | |
| 784 | + foreach ($this->get('fonts') as $key => $value) { | |
| 785 | + $fonts[] = [ | |
| 786 | + 'name' => $value, | |
| 787 | + 'value' => $model_e2pdf_font->get_font($key), | |
| 788 | + ]; | |
| 789 | + } | |
| 790 | + } | |
| 508 | 791 | } |
| 509 | 792 | |
| 510 | 793 | $pages = $this->pre_render(); |
| 511 | 794 | |
| 512 | - $settings = array( | |
| 513 | - 'title' => $this->get_filename(), | |
| 795 | + $settings = [ | |
| 796 | + 'uid' => $this->get('uid'), | |
| 797 | + 'activated' => $this->get('activated'), | |
| 798 | + 'title' => $this->get_name(), | |
| 514 | 799 | 'flatten' => $this->get('flatten'), |
| 800 | + 'tab_order' => $this->get('tab_order'), | |
| 515 | 801 | 'format' => $this->get('format'), |
| 802 | + 'resample' => $this->get('resample'), | |
| 516 | 803 | 'compression' => $this->get('compression'), |
| 517 | 804 | 'appearance' => $this->get('appearance'), |
| 518 | 805 | 'password' => $this->get('password'), |
| 806 | + 'owner_password' => $this->get('owner_password'), | |
| 807 | + 'permissions' => $this->get('permissions'), | |
| 519 | 808 | 'meta_title' => $this->get('meta_title'), |
| 520 | 809 | 'meta_subject' => $this->get('meta_subject'), |
| 521 | 810 | 'meta_author' => $this->get('meta_author'), |
| 522 | 811 | 'meta_keywords' => $this->get('meta_keywords'), |
| 812 | + 'lang_code' => $this->get('lang_code'), | |
| 813 | + 'css' => isset($this->get('properties')['css']) ? $this->get('properties')['css'] : '', | |
| 523 | 814 | 'font' => $this->get('font'), |
| 524 | 815 | 'font_size' => $this->get('font_size'), |
| 525 | 816 | 'font_color' => $this->get('font_color'), |
| 526 | 817 | 'line_height' => $this->get('line_height'), |
| 527 | - 'uid' => $this->get('uid'), | |
| 528 | - 'dataset' => $this->get('dataset'), | |
| 529 | - ); | |
| 818 | + 'text_align' => $this->get('text_align'), | |
| 819 | + 'rtl' => $this->get('rtl'), | |
| 820 | + 'font_processor' => apply_filters('e2pdf_font_processor', $this->get('font_processor'), $this->get('ID')), | |
| 821 | + 'created_at' => $this->get('created_at'), | |
| 822 | + 'updated_at' => $this->get('updated_at'), | |
| 823 | + ]; | |
| 530 | 824 | |
| 531 | - if ($this->get('pdf')) { | |
| 532 | - $pdf = $this->helper->get('pdf_dir') . $this->get('pdf') . "/" . $this->get('pdf') . ".pdf"; | |
| 825 | + if ($this->get('dpdf')) { | |
| 826 | + $dpdf = $this->helper->load('pdf')->get_pdf($this->get('dpdf')); | |
| 827 | + if ($dpdf) { | |
| 828 | + $settings['pdf'] = $dpdf; | |
| 829 | + $settings['dpdf'] = '1'; | |
| 830 | + } | |
| 831 | + } elseif ($this->get('pdf')) { | |
| 832 | + $pdf = $this->helper->get('pdf_dir') . $this->get('pdf') . '/' . $this->get('pdf') . '.pdf'; | |
| 533 | 833 | if (file_exists($pdf)) { |
| 834 | + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 534 | 835 | $settings['pdf'] = base64_encode(file_get_contents($pdf)); |
| 535 | 836 | } |
| 536 | 837 | } |
| 537 | 838 | |
| 538 | - $model_e2pdf_convert->set(array( | |
| 539 | - 'type' => $type, | |
| 540 | - 'data' => array( | |
| 541 | - 'settings' => $settings, | |
| 542 | - 'pages' => $pages, | |
| 543 | - 'fonts' => $fonts | |
| 544 | - ), | |
| 545 | - )); | |
| 839 | + $data = [ | |
| 840 | + 'settings' => $settings, | |
| 841 | + 'pages' => $pages, | |
| 842 | + 'fonts' => $fonts, | |
| 843 | + 'attachments' => $this->helper->load('attachments')->get_attachments($this->get('attachments'), $this->extension), | |
| 844 | + ]; | |
| 546 | 845 | |
| 547 | - return $model_e2pdf_convert->convert(); | |
| 548 | - } | |
| 549 | - | |
| 550 | - public function render($pre_save = false) { | |
| 551 | - $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 552 | - $model_e2pdf_font = new Model_E2pdf_Font(); | |
| 553 | - | |
| 554 | - if ($pre_save) { | |
| 555 | - $pages = $this->get('pages'); | |
| 556 | - $this->template = $this->pre_save(); | |
| 557 | - $this->set('pages', $pages); | |
| 558 | - $this->set('fonts', unserialize($this->get('fonts'))); | |
| 846 | + if ($type == 'php') { | |
| 847 | + $model_e2pdf_convert = new Model_E2pdf_Convert(); | |
| 848 | + $file = '<?php' . PHP_EOL; | |
| 849 | + $file .= 'function e2pdf_template() {' . PHP_EOL; | |
| 850 | + $file .= '$template = [' . PHP_EOL; | |
| 851 | + $file .= $model_e2pdf_convert->toPHP($data); | |
| 852 | + $file .= '];' . PHP_EOL; | |
| 853 | + $file .= 'return $template;' . PHP_EOL; | |
| 854 | + $file .= '}'; | |
| 855 | + if ($file) { | |
| 856 | + $response['file'] = $file; | |
| 857 | + } else { | |
| 858 | + $response['error'] = __('Something went wrong!', 'e2pdf'); | |
| 859 | + } | |
| 860 | + return $response; | |
| 559 | 861 | } |
| 560 | 862 | |
| 561 | - $fonts = array(); | |
| 562 | - if ($this->get('fonts')) { | |
| 563 | - foreach ($this->get('fonts') as $key => $value) { | |
| 564 | - $fonts[] = array( | |
| 565 | - 'name' => $value, | |
| 566 | - 'value' => $model_e2pdf_font->get_font($key) | |
| 567 | - ); | |
| 568 | - } | |
| 863 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode | |
| 864 | + $cached_pdf = md5(json_encode($data)); | |
| 865 | + $request = $this->helper->load('cache')->get_cached_pdf($cached_pdf); | |
| 866 | + if (empty($request['file'])) { | |
| 867 | + $model_e2pdf_api->set( | |
| 868 | + [ | |
| 869 | + 'action' => 'template/build', | |
| 870 | + 'data' => $data, | |
| 871 | + ] | |
| 872 | + ); | |
| 873 | + $request = $model_e2pdf_api->request(); | |
| 569 | 874 | } |
| 570 | 875 | |
| 571 | - $pages = $this->pre_render(); | |
| 572 | - | |
| 573 | - $settings = array( | |
| 574 | - 'title' => $this->get_filename(), | |
| 575 | - 'flatten' => $this->get('flatten'), | |
| 576 | - 'format' => $this->get('format'), | |
| 577 | - 'compression' => $this->get('compression'), | |
| 578 | - 'appearance' => $this->get('appearance'), | |
| 579 | - 'password' => $this->get('password'), | |
| 580 | - 'meta_title' => $this->get('meta_title'), | |
| 581 | - 'meta_subject' => $this->get('meta_subject'), | |
| 582 | - 'meta_author' => $this->get('meta_author'), | |
| 583 | - 'meta_keywords' => $this->get('meta_keywords'), | |
| 584 | - 'font' => $this->get('font'), | |
| 585 | - 'font_size' => $this->get('font_size'), | |
| 586 | - 'font_color' => $this->get('font_color'), | |
| 587 | - 'line_height' => $this->get('line_height'), | |
| 588 | - 'uid' => $this->get('uid'), | |
| 589 | - 'dataset' => $this->get('dataset') | |
| 590 | - ); | |
| 591 | - | |
| 592 | - if ($this->get('pdf')) { | |
| 593 | - $pdf = $this->helper->get('pdf_dir') . $this->get('pdf') . "/" . $this->get('pdf') . ".pdf"; | |
| 594 | - if (file_exists($pdf)) { | |
| 595 | - $settings['pdf'] = base64_encode(file_get_contents($pdf)); | |
| 876 | + if (isset($request['error']) && $request['error'] == 'cache_error') { | |
| 877 | + update_option('e2pdf_cached_fonts', []); | |
| 878 | + $fonts = []; | |
| 879 | + if ($this->get('fonts')) { | |
| 880 | + foreach ($this->get('fonts') as $key => $value) { | |
| 881 | + $fonts[] = [ | |
| 882 | + 'name' => $value, | |
| 883 | + 'value' => $model_e2pdf_font->get_font($key), | |
| 884 | + ]; | |
| 885 | + } | |
| 596 | 886 | } |
| 597 | - } | |
| 598 | - | |
| 599 | - $model_e2pdf_api->set(array( | |
| 600 | - 'action' => 'template/build', | |
| 601 | - 'data' => array( | |
| 887 | + $data = [ | |
| 602 | 888 | 'settings' => $settings, |
| 603 | 889 | 'pages' => $pages, |
| 604 | - 'fonts' => $fonts | |
| 605 | - ), | |
| 606 | - )); | |
| 607 | - | |
| 608 | - $request = $model_e2pdf_api->request(); | |
| 609 | - | |
| 890 | + 'fonts' => $fonts, | |
| 891 | + ]; | |
| 892 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode | |
| 893 | + $cached_pdf = md5(json_encode($data)); | |
| 894 | + $request = $this->helper->load('cache')->get_cached_pdf($cached_pdf); | |
| 895 | + if (empty($request['file'])) { | |
| 896 | + $model_e2pdf_api->set( | |
| 897 | + [ | |
| 898 | + 'action' => 'template/build', | |
| 899 | + 'data' => $data, | |
| 900 | + ] | |
| 901 | + ); | |
| 902 | + $request = $model_e2pdf_api->request(); | |
| 903 | + } | |
| 904 | + } | |
| 905 | + $this->helper->load('cache')->cache_pdf($cached_pdf, $request); | |
| 610 | 906 | return $request; |
| 611 | 907 | } |
| 612 | 908 | |
| 613 | - public function get_filename() { | |
| 909 | + public function get_name() { | |
| 910 | + $name = __('(no title)', 'e2pdf'); | |
| 614 | 911 | if ($this->get('name')) { |
| 615 | 912 | $name = $this->get('name'); |
| 616 | 913 | } elseif ($this->get('title')) { |
| 617 | 914 | $name = $this->get('title'); |
| 618 | - } else { | |
| 619 | - $name = __('(no title)', 'e2pdf'); | |
| 620 | 915 | } |
| 621 | 916 | return $name; |
| 622 | 917 | } |
| 623 | 918 | |
| @@ -624,13 +919,146 @@ | ||
| 624 | 919 | public function flush() { |
| 625 | 920 | if ($this->get('ID')) { |
| 626 | 921 | $model_e2pdf_page = new Model_E2pdf_Page(); |
| 627 | 922 | $pages = $model_e2pdf_page->get_pages($this->get('ID')); |
| 628 | - foreach ($pages as $page_value) { | |
| 629 | - $page = new Model_E2pdf_Page(); | |
| 630 | - $page->load($page_value['page_id'], $page_value['template_id']); | |
| 631 | - $page->delete(); | |
| 923 | + foreach ($pages as $page) { | |
| 924 | + $new_page = new Model_E2pdf_Page(); | |
| 925 | + $new_page->load($page['page_id'], $page['template_id']); | |
| 926 | + $new_page->delete(); | |
| 632 | 927 | } |
| 633 | 928 | } |
| 634 | 929 | } |
| 635 | 930 | |
| 931 | + public function activate() { | |
| 932 | + if ($this->get('ID')) { | |
| 933 | + if ($this->get('activated', true)) { | |
| 934 | + $request = [ | |
| 935 | + 'template_id' => $this->get('ID'), | |
| 936 | + 'template_uid' => $this->get('uid'), | |
| 937 | + ]; | |
| 938 | + } else { | |
| 939 | + $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 940 | + $model_e2pdf_api->set( | |
| 941 | + [ | |
| 942 | + 'action' => 'template/activate', | |
| 943 | + 'data' => [ | |
| 944 | + 'template_id' => $this->get('ID'), | |
| 945 | + 'template_uid' => $this->get('uid'), | |
| 946 | + 'template_title' => $this->get('title'), | |
| 947 | + 'template_extension' => $this->get('extension'), | |
| 948 | + ], | |
| 949 | + ] | |
| 950 | + ); | |
| 951 | + $request = $model_e2pdf_api->request(); | |
| 952 | + if (!isset($request['error'])) { | |
| 953 | + $this->set('activated', '1'); | |
| 954 | + $this->set('uid', $request['template_uid']); | |
| 955 | + $this->update(['activated', 'uid']); | |
| 956 | + } else { | |
| 957 | + $this->set('activated', '0'); | |
| 958 | + $this->update(['activated']); | |
| 959 | + } | |
| 960 | + if ($this->helper->get('cache')) { | |
| 961 | + wp_cache_delete($this->get('ID'), 'e2pdf_templates'); | |
| 962 | + } | |
| 963 | + } | |
| 964 | + } else { | |
| 965 | + $request = [ | |
| 966 | + 'error' => __('Something went wrong!', 'e2pdf'), | |
| 967 | + ]; | |
| 968 | + } | |
| 969 | + return $request; | |
| 970 | + } | |
| 971 | + | |
| 972 | + public function deactivate() { | |
| 973 | + if ($this->get('ID')) { | |
| 974 | + if (!$this->get('activated', true)) { | |
| 975 | + $request = [ | |
| 976 | + 'success' => __('Template Deactivated', 'e2pdf'), | |
| 977 | + ]; | |
| 978 | + } else { | |
| 979 | + $model_e2pdf_api = new Model_E2pdf_Api(); | |
| 980 | + $model_e2pdf_api->set( | |
| 981 | + [ | |
| 982 | + 'action' => 'template/deactivate', | |
| 983 | + 'data' => [ | |
| 984 | + 'template_id' => $this->get('ID'), | |
| 985 | + 'template_uid' => $this->get('uid'), | |
| 986 | + ], | |
| 987 | + ] | |
| 988 | + ); | |
| 989 | + $request = $model_e2pdf_api->request(); | |
| 990 | + if (!isset($request['error'])) { | |
| 991 | + $this->set('activated', '0'); | |
| 992 | + $this->update(['activated']); | |
| 993 | + } | |
| 994 | + if ($this->helper->get('cache')) { | |
| 995 | + wp_cache_delete($this->get('ID'), 'e2pdf_templates'); | |
| 996 | + } | |
| 997 | + } | |
| 998 | + } else { | |
| 999 | + $request = [ | |
| 1000 | + 'error' => __('Something went wrong!', 'e2pdf'), | |
| 1001 | + ]; | |
| 1002 | + } | |
| 1003 | + return $request; | |
| 1004 | + } | |
| 1005 | + | |
| 1006 | + public function patch($key, $value = false, $entry = null, $filter = false) { | |
| 1007 | + if ($value !== false) { | |
| 1008 | + $this->set($key, $filter ? $this->extension()->convert_shortcodes($value, true) : $this->extension()->render($value)); | |
| 1009 | + if ($entry) { | |
| 1010 | + $entry->set_data($key, $this->get($key)); | |
| 1011 | + } | |
| 1012 | + } else { | |
| 1013 | + switch ($key) { | |
| 1014 | + case 'meta_title': | |
| 1015 | + case 'meta_subject': | |
| 1016 | + case 'meta_author': | |
| 1017 | + case 'meta_keywords': | |
| 1018 | + $value = $this->extension()->render( | |
| 1019 | + $this->helper->load('translator')->pre_translate( | |
| 1020 | + $this->get($key), $this->get('ID'), $key, 'template' | |
| 1021 | + ) | |
| 1022 | + ); | |
| 1023 | + $this->set($key, $value); | |
| 1024 | + break; | |
| 1025 | + case 'name': | |
| 1026 | + if ($this->get('name')) { | |
| 1027 | + $value = $this->extension()->render( | |
| 1028 | + $this->helper->load('translator')->pre_translate( | |
| 1029 | + $this->get('name'), $this->get('ID'), 'name', 'template' | |
| 1030 | + ) | |
| 1031 | + ); | |
| 1032 | + } | |
| 1033 | + if (!trim($value) && $this->get('title')) { | |
| 1034 | + $value = $this->extension()->render( | |
| 1035 | + $this->helper->load('translator')->pre_translate( | |
| 1036 | + $this->get('title'), $this->get('ID'), 'title', 'template' | |
| 1037 | + ) | |
| 1038 | + ); | |
| 1039 | + } | |
| 1040 | + if (!trim($value)) { | |
| 1041 | + $value = __('(no title)', 'e2pdf'); | |
| 1042 | + } | |
| 1043 | + $this->set($key, $value); | |
| 1044 | + break; | |
| 1045 | + case 'savename': | |
| 1046 | + if ($this->get('savename')) { | |
| 1047 | + $value = $this->extension()->render( | |
| 1048 | + $this->helper->load('translator')->pre_translate( | |
| 1049 | + $this->get('savename'), $this->get('ID'), 'savename', 'template' | |
| 1050 | + ) | |
| 1051 | + ); | |
| 1052 | + } | |
| 1053 | + if (!trim($value)) { | |
| 1054 | + $value = $this->get('name'); | |
| 1055 | + } | |
| 1056 | + $this->set($key, $value); | |
| 1057 | + break; | |
| 1058 | + default: | |
| 1059 | + $this->set($key, $this->extension()->render($this->get($key))); | |
| 1060 | + break; | |
| 1061 | + } | |
| 1062 | + } | |
| 1063 | + } | |
| 636 | 1064 | } |