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