PluginProbe
Visual Composer Website Builder / 45.16.4
Visual Composer Website Builder v45.16.4
45.16.4 45.16.3 45.16.2 45.16.1 45.2-beta.1 45.2-beta.2 45.2.0 45.3-beta.1 45.3.0 45.4-beta.1 45.4.0 45.4.1 45.4.1-beta.2 45.5-beta.1 45.5.0 45.6-beta.1 45.6.0 45.7-beta.1 45.7.0 45.8-beta.1 45.8.0 45.9.0 trunk 45.0 45.0-beta.1 All 42 releases
← All changes | visualcomposer/Modules/Elements/EncodedShortcode/Controller.php +61 -0 45.2-beta.2 → 45.16.4 View file →
@@ -10,14 +10,75 @@
10 10
11 11 use VisualComposer\Framework\Container;
12 12 use VisualComposer\Framework\Illuminate\Support\Module;
13 13 use VisualComposer\Modules\Elements\Traits\AddShortcodeTrait;
14 +use VisualComposer\Helpers\Traits\WpFiltersActions;
14 15
15 16 class Controller extends Container implements Module
16 17 {
17 18 use AddShortcodeTrait;
19 + use WpFiltersActions;
18 20
19 21 public function __construct()
20 22 {
21 23 $this->addShortcode('vcv_encoded_shortcode');
24 +
25 + $this->wpAddFilter('content_save_pre', [$this, 'checkEncodedShortcode']);
26 + }
27 +
28 + /**
29 + * Remove vcv_encoded_shortcode shortcode for users without unfiltered_html capability.
30 + *
31 + * @param string $content
32 + *
33 + * @return string
34 + */
35 + public function checkEncodedShortcode($content)
36 + {
37 + if (current_user_can('unfiltered_html')) {
38 + return $content;
39 + }
40 +
41 + if (strpos($content, 'vcv_encoded_shortcode') === false) {
42 + return $content;
43 + }
44 + $regex = '/' . $this->get_shortcode_regex('vcv_encoded_shortcode') . '/';
45 +
46 + while (preg_match($regex, $content)) {
47 + $content = preg_replace($regex, '', $content);
48 + }
49 +
50 + return $content;
51 + }
52 +
53 + /**
54 + * Get the shortcode regex.
55 + *
56 + * @param string $tagregexp
57 + *
58 + * @return string
59 + */
60 + public function get_shortcode_regex($tagregexp = '')
61 + {
62 + if (0 === strlen($tagregexp)) {
63 + return get_shortcode_regex();
64 + }
65 +
66 + return '\\[' // Opening bracket.
67 + . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]].
68 + . "($tagregexp)" // 2: Shortcode name.
69 + . '(?![\\w\-])' // Not followed by word character or hyphen.
70 + . '(' // 3: Unroll the loop: Inside the opening shortcode tag.
71 + . '[^\\]\\/]*' // Not a closing bracket or forward slash.
72 + . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket.
73 + . '[^\\]\\/]*' // Not a closing bracket or forward slash.
74 + . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag .
75 + . '\\]' // ... and closing bracket.
76 + . '|' . '\\]' // Closing bracket.
77 + . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
78 + . '[^\\[]*+' // Not an opening bracket.
79 + . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
80 + . '[^\\[]*+' // Not an opening bracket.
81 + . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag.
82 + . ')?' . ')' . '(\\]?)';
22 83 }
23 84 }