| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Filter Model |
| 5 |
* |
| 6 |
* @copyright Copyright 2017 https://e2pdf.com |
| 7 |
* @license GPL v2 |
| 8 |
* @version 1 |
| 9 |
* @link https://e2pdf.com |
| 10 |
* @since 1.06.02 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Model_E2pdf_Filter extends Model_E2pdf_Model { |
| 17 |
|
| 18 |
function __construct() { |
| 19 |
parent::__construct(); |
| 20 |
} |
| 21 |
|
| 22 |
public function pre_filter($content) { |
| 23 |
if (false === strpos($content, '[')) { |
| 24 |
return $content; |
| 25 |
} |
| 26 |
|
| 27 |
$shortcode_tags = array( |
| 28 |
'e2pdf-download', |
| 29 |
'e2pdf-save', |
| 30 |
'e2pdf-view', |
| 31 |
'e2pdf-adobesign', |
| 32 |
'e2pdf-attachment' |
| 33 |
); |
| 34 |
|
| 35 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 36 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 37 |
|
| 38 |
if (!empty($tagnames)) { |
| 39 |
preg_match_all('/(?:(\[))(?>[^][]++|(?R))*\]/', $content, $matches); |
| 40 |
foreach ($matches[0] as $key => $shortcode_value) { |
| 41 |
if (false !== strpos($shortcode_value, 'e2pdf-download') || |
| 42 |
false !== strpos($shortcode_value, 'e2pdf-save') || |
| 43 |
false !== strpos($shortcode_value, 'e2pdf-view') || |
| 44 |
false !== strpos($shortcode_value, 'e2pdf-adobesign') || |
| 45 |
false !== strpos($shortcode_value, 'e2pdf-attachment') |
| 46 |
) { |
| 47 |
$new_shortcode_value = preg_replace('/([\w+\-]+)\=("|\')(.+?)\2/', '${1}=${2}[e2pdf-filter]${3}[/e2pdf-filter]${2}', $shortcode_value); |
| 48 |
$content = str_replace($shortcode_value, $new_shortcode_value, $content); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
return $content; |
| 54 |
} |
| 55 |
|
| 56 |
public function filter($content) { |
| 57 |
|
| 58 |
if (false === strpos($content, '[')) { |
| 59 |
return $content; |
| 60 |
} |
| 61 |
|
| 62 |
$shortcode_tags = array( |
| 63 |
'e2pdf-filter', |
| 64 |
); |
| 65 |
|
| 66 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 67 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 68 |
|
| 69 |
if (!empty($tagnames)) { |
| 70 |
$pattern = get_shortcode_regex($tagnames); |
| 71 |
|
| 72 |
preg_match_all("/$pattern/", $content, $shortcodes); |
| 73 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 74 |
|
| 75 |
$shortcode = array(); |
| 76 |
$shortcode[1] = $shortcodes[1][$key]; |
| 77 |
$shortcode[2] = $shortcodes[2][$key]; |
| 78 |
$shortcode[3] = $shortcodes[3][$key]; |
| 79 |
$shortcode[4] = $shortcodes[4][$key]; |
| 80 |
$shortcode[5] = $shortcodes[5][$key]; |
| 81 |
$shortcode[6] = $shortcodes[6][$key]; |
| 82 |
|
| 83 |
$content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return $content; |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|