| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Wordpress Extension |
| 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 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Extension_E2pdf_Wordpress extends Model_E2pdf_Model { |
| 17 |
|
| 18 |
private $options; |
| 19 |
private $info = array( |
| 20 |
'key' => 'wordpress', |
| 21 |
'title' => 'WordPress' |
| 22 |
); |
| 23 |
|
| 24 |
function __construct() { |
| 25 |
parent::__construct(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Get info about extension |
| 30 |
* |
| 31 |
* @param string $key - Key to get assigned extension info value |
| 32 |
* |
| 33 |
* @return array|string - Extension Key and Title or Assigned extension info value |
| 34 |
*/ |
| 35 |
public function info($key = false) { |
| 36 |
if ($key && isset($this->info[$key])) { |
| 37 |
return $this->info[$key]; |
| 38 |
} else { |
| 39 |
return array( |
| 40 |
$this->info['key'] => $this->info['title'] |
| 41 |
); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Check if needed plugin active |
| 47 |
* |
| 48 |
* @return bool - Activated/Not Activated plugin |
| 49 |
*/ |
| 50 |
public function active() { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Set option |
| 56 |
* |
| 57 |
* @param string $attr - Key of option |
| 58 |
* @param string $value - Value of option |
| 59 |
* |
| 60 |
* @return bool - Status of setting option |
| 61 |
*/ |
| 62 |
public function set($key, $value) { |
| 63 |
if (!isset($this->options)) { |
| 64 |
$this->options = new stdClass(); |
| 65 |
} |
| 66 |
|
| 67 |
$this->options->$key = $value; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Get option by key |
| 72 |
* |
| 73 |
* @param string $key - Key to get assigned option value |
| 74 |
* |
| 75 |
* @return mixed |
| 76 |
*/ |
| 77 |
public function get($key) { |
| 78 |
if (isset($this->options->$key)) { |
| 79 |
$value = $this->options->$key; |
| 80 |
return $value; |
| 81 |
} elseif ($key == 'args') { |
| 82 |
return array(); |
| 83 |
} else { |
| 84 |
return false; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Get items to work with |
| 90 |
* |
| 91 |
* @return array() - List of available items |
| 92 |
*/ |
| 93 |
public function items() { |
| 94 |
$content = array(); |
| 95 |
|
| 96 |
$items = get_post_types(array('public' => true), 'names'); |
| 97 |
|
| 98 |
foreach ($items as $item) { |
| 99 |
if ($item != 'attachment') { |
| 100 |
$content[] = $this->item($item); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
return $content; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Get entries for export |
| 109 |
* |
| 110 |
* @param string $item - Item |
| 111 |
* @param string $name - Entries names |
| 112 |
* |
| 113 |
* @return array() - Entries list |
| 114 |
*/ |
| 115 |
public function datasets($item = false, $name = false) { |
| 116 |
|
| 117 |
$datasets = array(); |
| 118 |
|
| 119 |
if ($item) { |
| 120 |
$datasets_tmp = get_posts( |
| 121 |
array( |
| 122 |
'post_type' => $item, |
| 123 |
'numberposts' => -1, |
| 124 |
'post_status' => array( |
| 125 |
'publish', |
| 126 |
'private' |
| 127 |
) |
| 128 |
)); |
| 129 |
|
| 130 |
if ($datasets_tmp) { |
| 131 |
foreach ($datasets_tmp as $key => $dataset) { |
| 132 |
$this->set('item', $item); |
| 133 |
$this->set('dataset', $dataset->ID); |
| 134 |
|
| 135 |
$dataset_title = $this->render($name); |
| 136 |
if (!$dataset_title) { |
| 137 |
$dataset_title = isset($dataset->post_title) && $dataset->post_title ? $dataset->post_title : $dataset->ID; |
| 138 |
} |
| 139 |
$datasets[] = array( |
| 140 |
'key' => $dataset->ID, |
| 141 |
'value' => $dataset_title |
| 142 |
); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
return $datasets; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Get dataset |
| 152 |
* |
| 153 |
* @param int $dataset - Dataset ID |
| 154 |
* |
| 155 |
* @return object - Dataset |
| 156 |
*/ |
| 157 |
public function dataset($dataset = false) { |
| 158 |
|
| 159 |
$dataset = (int) $dataset; |
| 160 |
|
| 161 |
if (!$dataset) { |
| 162 |
return; |
| 163 |
} |
| 164 |
|
| 165 |
$data = new stdClass(); |
| 166 |
$data->url = $this->helper->get_url(array('post' => $dataset, 'action' => 'edit'), 'post.php?'); |
| 167 |
|
| 168 |
return $data; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Get item |
| 173 |
* |
| 174 |
* @param string $item - Item |
| 175 |
* |
| 176 |
* @return object - Item |
| 177 |
*/ |
| 178 |
public function item($item = false) { |
| 179 |
|
| 180 |
if (!$item && $this->get('item')) { |
| 181 |
$item = $this->get('item'); |
| 182 |
} |
| 183 |
|
| 184 |
$form = new stdClass(); |
| 185 |
$post = get_post_type_object($item); |
| 186 |
if ($post) { |
| 187 |
$form->id = $item; |
| 188 |
$form->name = $post->label ? $post->label : $item; |
| 189 |
$form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?'); |
| 190 |
} else { |
| 191 |
$form->id = ''; |
| 192 |
$form->name = ''; |
| 193 |
$form->url = 'javascript:void(0);'; |
| 194 |
} |
| 195 |
|
| 196 |
return $form; |
| 197 |
} |
| 198 |
|
| 199 |
public function load_filters() { |
| 200 |
add_filter('the_content', array($this, 'filter_content'), 10, 2); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Render value according to content |
| 205 |
* |
| 206 |
* @param string $value - Content |
| 207 |
* @param string $type - Type of rendering value |
| 208 |
* @param array $field - Field details |
| 209 |
* |
| 210 |
* @return string - Fully rendered value |
| 211 |
*/ |
| 212 |
public function render($value, $type = false, $field = array()) { |
| 213 |
|
| 214 |
$value = $this->render_shortcodes($value, $type, $field); |
| 215 |
$value = $this->strip_shortcodes($value); |
| 216 |
|
| 217 |
if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) { |
| 218 |
$option = $this->render($field['properties']['option']); |
| 219 |
$options = explode(', ', $value); |
| 220 |
$option_options = explode(', ', $option); |
| 221 |
if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) { |
| 222 |
return $option; |
| 223 |
} else { |
| 224 |
return ""; |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
if ($type === 'value') { |
| 229 |
$value = $this->convert_shortcodes($value, true); |
| 230 |
} |
| 231 |
|
| 232 |
return $value; |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* Render shortcodes which available in this extension |
| 237 |
* |
| 238 |
* @param string $value - Content |
| 239 |
* @param string $type - Type of rendering value |
| 240 |
* @param array $field - Field details |
| 241 |
* |
| 242 |
* @return string - Value with rendered shortcodes |
| 243 |
*/ |
| 244 |
public function render_shortcodes($value, $type = false, $field = array()) { |
| 245 |
|
| 246 |
$dataset = $this->get('dataset'); |
| 247 |
$item = $this->get('item'); |
| 248 |
$args = $this->get('args'); |
| 249 |
$user_id = $this->get('user_id'); |
| 250 |
$template_id = $this->get('template_id') ? $this->get('template_id') : '0'; |
| 251 |
$element_id = isset($field['element_id']) ? $field['element_id'] : '0'; |
| 252 |
|
| 253 |
if ($this->verify()) { |
| 254 |
|
| 255 |
$args = apply_filters('e2pdf_extension_render_shortcodes_args', $args, $element_id, $template_id, $item, $dataset); |
| 256 |
|
| 257 |
$post = get_post($dataset); |
| 258 |
|
| 259 |
$wordpress_shortcodes = array( |
| 260 |
'id', |
| 261 |
'post_author', |
| 262 |
'post_date', |
| 263 |
'post_date_gmt', |
| 264 |
'post_content', |
| 265 |
'post_title', |
| 266 |
'post_excerpt', |
| 267 |
'post_status', |
| 268 |
'comment_status', |
| 269 |
'ping_status', |
| 270 |
'post_password', |
| 271 |
'post_name', |
| 272 |
'to_ping', |
| 273 |
'pinged', |
| 274 |
'post_modified', |
| 275 |
'post_modified_gmt', |
| 276 |
'post_content_filtered', |
| 277 |
'post_parent', |
| 278 |
'guid', |
| 279 |
'menu_order', |
| 280 |
'post_type', |
| 281 |
'post_mime_type', |
| 282 |
'comment_count', |
| 283 |
'filter' |
| 284 |
); |
| 285 |
|
| 286 |
if (false !== strpos($value, '[')) { |
| 287 |
|
| 288 |
$shortcode_tags = array( |
| 289 |
'meta', |
| 290 |
'e2pdf-wp', |
| 291 |
'e2pdf-content', |
| 292 |
'e2pdf-user', |
| 293 |
'e2pdf-arg' |
| 294 |
); |
| 295 |
|
| 296 |
$shortcode_tags = array_merge($shortcode_tags, $wordpress_shortcodes); |
| 297 |
|
| 298 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); |
| 299 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 300 |
|
| 301 |
if (!empty($tagnames)) { |
| 302 |
$pattern = get_shortcode_regex($tagnames); |
| 303 |
|
| 304 |
preg_match_all("/$pattern/", $value, $shortcodes); |
| 305 |
|
| 306 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 307 |
$shortcode = array(); |
| 308 |
$shortcode[1] = $shortcodes[1][$key]; |
| 309 |
$shortcode[2] = $shortcodes[2][$key]; |
| 310 |
$shortcode[3] = $shortcodes[3][$key]; |
| 311 |
$shortcode[4] = $shortcodes[4][$key]; |
| 312 |
$shortcode[5] = $shortcodes[5][$key]; |
| 313 |
$shortcode[6] = $shortcodes[6][$key]; |
| 314 |
|
| 315 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 316 |
|
| 317 |
if ($shortcode[2] === 'e2pdf-content') { |
| 318 |
if (!isset($atts['id']) && isset($post->ID) && $post->ID) { |
| 319 |
$shortcode[3] .= " id=\"" . $post->ID . "\""; |
| 320 |
$value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]", $value); |
| 321 |
} |
| 322 |
} else if ($shortcode[2] === 'e2pdf-user') { |
| 323 |
if (!isset($atts['id']) && $user_id) { |
| 324 |
$shortcode[3] .= " id=\"" . $user_id . "\""; |
| 325 |
$value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]", $value); |
| 326 |
} |
| 327 |
} else if ($shortcode['2'] === 'meta' || $shortcode['2'] == 'e2pdf-wp') { |
| 328 |
if (!isset($atts['id']) && isset($post->ID) && $post->ID) { |
| 329 |
$shortcode[3] .= " id=\"" . $post->ID . "\""; |
| 330 |
} |
| 331 |
if ($shortcode['2'] === 'meta') { |
| 332 |
$shortcode[3] .= " meta=\"true\""; |
| 333 |
} |
| 334 |
$value = str_replace($shortcode_value, "[e2pdf-wp" . $shortcode['3'] . "]", $value); |
| 335 |
} elseif (in_array($shortcode[2], $wordpress_shortcodes)) { |
| 336 |
if (!isset($atts['id']) && isset($post->ID) && $post->ID) { |
| 337 |
$shortcode[3] .= " id=\"" . $post->ID . "\""; |
| 338 |
} |
| 339 |
$shortcode[3] .= " key=\"" . $shortcode[2] . "\""; |
| 340 |
$value = str_replace($shortcode_value, "[e2pdf-wp" . $shortcode['3'] . "]", $value); |
| 341 |
} elseif ($shortcode['2'] == 'e2pdf-arg') { |
| 342 |
if (isset($atts['key']) && isset($args[$atts['key']])) { |
| 343 |
$sub_value = $this->strip_shortcodes($args[$atts['key']]); |
| 344 |
$value = str_replace($shortcode_value, $sub_value, $value); |
| 345 |
} else { |
| 346 |
$value = str_replace($shortcode_value, '', $value); |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
$shortcode_tags = array( |
| 353 |
'e2pdf-format-number', |
| 354 |
'e2pdf-format-date', |
| 355 |
'e2pdf-format-output', |
| 356 |
); |
| 357 |
$shortcode_tags = apply_filters('e2pdf_extension_render_shortcodes_tags', $shortcode_tags); |
| 358 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); |
| 359 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 360 |
|
| 361 |
if (!empty($tagnames)) { |
| 362 |
|
| 363 |
$pattern = get_shortcode_regex($tagnames); |
| 364 |
preg_match_all("/$pattern/", $value, $shortcodes); |
| 365 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 366 |
$shortcode = array(); |
| 367 |
$shortcode[1] = $shortcodes[1][$key]; |
| 368 |
$shortcode[2] = $shortcodes[2][$key]; |
| 369 |
$shortcode[3] = $shortcodes[3][$key]; |
| 370 |
$shortcode[4] = $shortcodes[4][$key]; |
| 371 |
$shortcode[5] = $shortcodes[5][$key]; |
| 372 |
$shortcode[6] = $shortcodes[6][$key]; |
| 373 |
|
| 374 |
if (isset($shortcode['5'])) { |
| 375 |
if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { |
| 376 |
$sub_value = $this->render($shortcode['5'], $type); |
| 377 |
} else { |
| 378 |
$sub_value = $this->render($shortcode['5'], $type, $field); |
| 379 |
} |
| 380 |
$value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value); |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
$value = do_shortcode($value); |
| 387 |
|
| 388 |
if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { |
| 389 |
$esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false; |
| 390 |
if ($esig) { |
| 391 |
//process e-signature |
| 392 |
$value = ""; |
| 393 |
} else { |
| 394 |
if (!$this->helper->load('image')->get_image($value)) { |
| 395 |
$value = $this->strip_shortcodes($value); |
| 396 |
if ( |
| 397 |
$value && |
| 398 |
trim($value) != "" && |
| 399 |
extension_loaded('gd') && |
| 400 |
function_exists('imagettftext') |
| 401 |
) { |
| 402 |
if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { |
| 403 |
$penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']); |
| 404 |
} else { |
| 405 |
$penColour = array(0x14, 0x53, 0x94); |
| 406 |
} |
| 407 |
|
| 408 |
$default_options = array( |
| 409 |
'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), |
| 410 |
'bgColour' => 'transparent', |
| 411 |
'penColour' => $penColour |
| 412 |
); |
| 413 |
|
| 414 |
$options = array(); |
| 415 |
$options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id); |
| 416 |
$options = array_merge($default_options, $options); |
| 417 |
|
| 418 |
$model_e2pdf_font = new Model_E2pdf_Font(); |
| 419 |
|
| 420 |
$font = false; |
| 421 |
if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { |
| 422 |
$font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); |
| 423 |
} |
| 424 |
if (!$font) { |
| 425 |
$font = $model_e2pdf_font->get_font_path('Noto Sans'); |
| 426 |
} |
| 427 |
|
| 428 |
$size = 150; |
| 429 |
if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { |
| 430 |
$size = $field['properties']['text_font_size']; |
| 431 |
} |
| 432 |
|
| 433 |
$model_e2pdf_signature = new Model_E2pdf_Signature(); |
| 434 |
$value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); |
| 435 |
} else { |
| 436 |
$value = ""; |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
} else { |
| 441 |
$value = $this->convert_shortcodes($value); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
return $value; |
| 446 |
} |
| 447 |
|
| 448 |
public function filter_custom_shortcodes() { |
| 449 |
|
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* Strip unused shortcodes |
| 454 |
* |
| 455 |
* @param string $value - Content |
| 456 |
* |
| 457 |
* @return string - Value with removed unused shortcodes |
| 458 |
*/ |
| 459 |
public function strip_shortcodes($value) { |
| 460 |
$value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); |
| 461 |
return $value; |
| 462 |
} |
| 463 |
|
| 464 |
public function convert_shortcodes($value, $to = false) { |
| 465 |
if ($value) { |
| 466 |
if ($to) { |
| 467 |
$value = str_replace("[", "[", $value); |
| 468 |
} else { |
| 469 |
$value = str_replace("[", "[", $value); |
| 470 |
} |
| 471 |
} |
| 472 |
return $value; |
| 473 |
} |
| 474 |
|
| 475 |
public function auto() { |
| 476 |
$response = array(); |
| 477 |
$elements = array(); |
| 478 |
|
| 479 |
$post = $this->get('item'); |
| 480 |
|
| 481 |
$elements[] = array( |
| 482 |
'type' => 'e2pdf-html', |
| 483 |
'block' => true, |
| 484 |
'properties' => array( |
| 485 |
'top' => '20', |
| 486 |
'left' => '20', |
| 487 |
'right' => '20', |
| 488 |
'width' => '100%', |
| 489 |
'height' => 'auto', |
| 490 |
'value' => "<h1>[post_title]</h1>", |
| 491 |
) |
| 492 |
); |
| 493 |
|
| 494 |
$elements[] = array( |
| 495 |
'type' => 'e2pdf-html', |
| 496 |
'block' => true, |
| 497 |
'properties' => array( |
| 498 |
'top' => '20', |
| 499 |
'left' => '20', |
| 500 |
'right' => '20', |
| 501 |
'width' => '100%', |
| 502 |
'height' => 'auto', |
| 503 |
'value' => __("Post name", 'e2pdf') . ": [post_name]", |
| 504 |
) |
| 505 |
); |
| 506 |
|
| 507 |
$elements[] = array( |
| 508 |
'type' => 'e2pdf-html', |
| 509 |
'block' => true, |
| 510 |
'properties' => array( |
| 511 |
'top' => '20', |
| 512 |
'left' => '20', |
| 513 |
'right' => '20', |
| 514 |
'width' => '100%', |
| 515 |
'height' => 'auto', |
| 516 |
'value' => __("Post type", 'e2pdf') . ": [post_type]", |
| 517 |
) |
| 518 |
); |
| 519 |
|
| 520 |
|
| 521 |
$elements[] = array( |
| 522 |
'type' => 'e2pdf-html', |
| 523 |
'block' => true, |
| 524 |
'properties' => array( |
| 525 |
'top' => '20', |
| 526 |
'left' => '20', |
| 527 |
'right' => '20', |
| 528 |
'width' => '100%', |
| 529 |
'height' => 'auto', |
| 530 |
'value' => __("ID", 'e2pdf') . ": [id]", |
| 531 |
) |
| 532 |
); |
| 533 |
|
| 534 |
$elements[] = array( |
| 535 |
'type' => 'e2pdf-html', |
| 536 |
'block' => true, |
| 537 |
'properties' => array( |
| 538 |
'top' => '20', |
| 539 |
'left' => '20', |
| 540 |
'right' => '20', |
| 541 |
'width' => '100%', |
| 542 |
'height' => 'auto', |
| 543 |
'value' => __("Author", 'e2pdf') . ": [post_author]", |
| 544 |
) |
| 545 |
); |
| 546 |
|
| 547 |
$elements[] = array( |
| 548 |
'type' => 'e2pdf-html', |
| 549 |
'block' => true, |
| 550 |
'properties' => array( |
| 551 |
'top' => '20', |
| 552 |
'left' => '20', |
| 553 |
'right' => '20', |
| 554 |
'width' => '100%', |
| 555 |
'height' => '300', |
| 556 |
'value' => "[post_content]", |
| 557 |
'dynamic_height' => '1', |
| 558 |
) |
| 559 |
); |
| 560 |
|
| 561 |
$elements[] = array( |
| 562 |
'type' => 'e2pdf-html', |
| 563 |
'block' => true, |
| 564 |
'properties' => array( |
| 565 |
'top' => '20', |
| 566 |
'left' => '20', |
| 567 |
'right' => '20', |
| 568 |
'width' => '100%', |
| 569 |
'height' => 'auto', |
| 570 |
'value' => __("Created", 'e2pdf') . ": [post_date]", |
| 571 |
) |
| 572 |
); |
| 573 |
|
| 574 |
$elements[] = array( |
| 575 |
'type' => 'e2pdf-html', |
| 576 |
'block' => true, |
| 577 |
'properties' => array( |
| 578 |
'top' => '20', |
| 579 |
'left' => '20', |
| 580 |
'right' => '20', |
| 581 |
'width' => '100%', |
| 582 |
'height' => 'auto', |
| 583 |
'value' => __("Modified", 'e2pdf') . ": [post_modified]", |
| 584 |
) |
| 585 |
); |
| 586 |
|
| 587 |
$response['page'] = array( |
| 588 |
'bottom' => '20', |
| 589 |
'top' => '20', |
| 590 |
'left' => '20', |
| 591 |
'right' => '20' |
| 592 |
); |
| 593 |
|
| 594 |
$response['elements'] = $elements; |
| 595 |
return $response; |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* Search and update shortcodes for this extension inside content |
| 600 |
* Auto set of dataset id |
| 601 |
* |
| 602 |
* @param string $content - Content |
| 603 |
* |
| 604 |
* @return string - Content with updated shortcodes |
| 605 |
*/ |
| 606 |
public function filter_content($content) { |
| 607 |
global $post; |
| 608 |
|
| 609 |
if (false === strpos($content, '[')) { |
| 610 |
return $content; |
| 611 |
} |
| 612 |
|
| 613 |
$shortcode_tags = array( |
| 614 |
'e2pdf-download', |
| 615 |
'e2pdf-view' |
| 616 |
); |
| 617 |
|
| 618 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 619 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 620 |
|
| 621 |
if (!empty($tagnames)) { |
| 622 |
$pattern = get_shortcode_regex($tagnames); |
| 623 |
|
| 624 |
preg_match_all("/$pattern/", $content, $shortcodes); |
| 625 |
|
| 626 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 627 |
|
| 628 |
wp_reset_postdata(); |
| 629 |
|
| 630 |
$shortcode = array(); |
| 631 |
$shortcode[1] = $shortcodes[1][$key]; |
| 632 |
$shortcode[2] = $shortcodes[2][$key]; |
| 633 |
$shortcode[3] = $shortcodes[3][$key]; |
| 634 |
$shortcode[4] = $shortcodes[4][$key]; |
| 635 |
$shortcode[5] = $shortcodes[5][$key]; |
| 636 |
$shortcode[6] = $shortcodes[6][$key]; |
| 637 |
|
| 638 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 639 |
|
| 640 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 641 |
$template = new Model_E2pdf_Template(); |
| 642 |
$template->load($atts['id']); |
| 643 |
if ($template->get('extension') === 'wordpress') { |
| 644 |
if (isset($post->ID)) { |
| 645 |
$dataset = $post->ID; |
| 646 |
$atts['dataset'] = $dataset; |
| 647 |
$shortcode[3] .= " dataset=\"{$dataset}\""; |
| 648 |
} |
| 649 |
} |
| 650 |
} |
| 651 |
$content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
return $content; |
| 656 |
} |
| 657 |
|
| 658 |
public function verify() { |
| 659 |
$item = $this->get('item'); |
| 660 |
$dataset = $this->get('dataset'); |
| 661 |
|
| 662 |
if ($item && $dataset && get_post($dataset) && $item == get_post_type($dataset)) { |
| 663 |
return true; |
| 664 |
} |
| 665 |
|
| 666 |
return false; |
| 667 |
} |
| 668 |
|
| 669 |
public function visual_mapper() { |
| 670 |
|
| 671 |
$vc = "<h3>Wordpress</h3>"; |
| 672 |
$vc .= "<div class='e2pdf-grid'>"; |
| 673 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("ID", "e2pdf"), 'id')}</div>"; |
| 674 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Author", "e2pdf"), 'post_author')}</div>"; |
| 675 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Date", "e2pdf"), 'post_date')}</div>"; |
| 676 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Date (GMT)", "e2pdf"), 'post_date_gmt')}</div>"; |
| 677 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Content", "e2pdf"), 'post_content')}</div>"; |
| 678 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Title", "e2pdf"), 'post_title')}</div>"; |
| 679 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Excerpt", "e2pdf"), 'post_excerpt')}</div>"; |
| 680 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Status", "e2pdf"), 'post_status')}</div>"; |
| 681 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comment Status", "e2pdf"), 'comment_status')}</div>"; |
| 682 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping Status", "e2pdf"), 'ping_status')}</div>"; |
| 683 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Post Password", "e2pdf"), 'post_password')}</div>"; |
| 684 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Post Name", "e2pdf"), 'post_name')}</div>"; |
| 685 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("To Ping", "e2pdf"), 'to_ping')}</div>"; |
| 686 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping", "e2pdf"), 'pinged')}</div>"; |
| 687 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Modified Date", "e2pdf"), 'post_modified')}</div>"; |
| 688 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Modified Date (GMT)", "e2pdf"), 'post_modified_gmt')}</div>"; |
| 689 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Filtered Content", "e2pdf"), 'post_content_filtered')}</div>"; |
| 690 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Parent ID", "e2pdf"), 'post_parent')}</div>"; |
| 691 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("GUID", "e2pdf"), 'guid')}</div>"; |
| 692 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Menu Order", "e2pdf"), 'menu_order')}</div>"; |
| 693 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Type", "e2pdf"), 'post_type')}</div>"; |
| 694 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Mime Type", "e2pdf"), 'post_mime_type')}</div>"; |
| 695 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comments Count", "e2pdf"), 'comment_count')}</div>"; |
| 696 |
$vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Filter", "e2pdf"), 'filter')}</div>"; |
| 697 |
$vc .= "</div>"; |
| 698 |
return $vc; |
| 699 |
} |
| 700 |
|
| 701 |
private function get_vm_element($name, $id) { |
| 702 |
$element = "<div>"; |
| 703 |
$element .= "<label>{$name}:</label>"; |
| 704 |
$element .= "<input type='text' name='[{$id}]' value='[{$id}]' class='e2pdf-w100'>"; |
| 705 |
$element .= "</div>"; |
| 706 |
return $element; |
| 707 |
} |
| 708 |
|
| 709 |
} |
| 710 |
|