PluginProbe ʕ •ᴥ•ʔ
Page Builder by SiteOrigin / 2.34.3
Page Builder by SiteOrigin v2.34.3
2.34.3 2.34.2 2.29.5 2.29.6 2.29.7 2.29.8 2.29.9 2.3 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.31.4 2.31.5 2.31.6 2.31.7 2.31.8 2.32.0 2.32.1 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.34.0 2.34.1 2.4 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 2.4.22 2.4.23 2.4.24 2.4.25 2.4.3 2.4.4 2.4.5 2.4.6 2.4.8 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0 2.8.1 2.8.2 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 trunk 2.10.0 2.10.1 2.10.10 2.10.11 2.10.12 2.10.13 2.10.14 2.10.15 2.10.16 2.10.17 2.10.2 2.10.3 2.10.4 2.10.5 2.10.6 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.12.0 2.12.1 2.12.2 2.12.3 2.12.4 2.12.5 2.12.6 2.13.0 2.13.1 2.13.2 2.14.0 2.14.1 2.14.2 2.14.3 2.15.0 2.15.1 2.15.2 2.15.3 2.16.0 2.16.1 2.16.10 2.16.11 2.16.12 2.16.13 2.16.14 2.16.15 2.16.16 2.16.17 2.16.18 2.16.19 2.16.2 2.16.3 2.16.4 2.16.5 2.16.6 2.16.7 2.16.8 2.16.9 2.17.0 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.19.0 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.21.1 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.26.1 2.26.2 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.10 2.29.11 2.29.12 2.29.13 2.29.14 2.29.15 2.29.16 2.29.17 2.29.18 2.29.19 2.29.2 2.29.20 2.29.21 2.29.22 2.29.3 2.29.4
siteorigin-panels / inc / widget-shortcode.php
siteorigin-panels / inc Last commit date
data 3 years ago installer 3 months ago widgets 3 months ago admin-dashboard.php 2 years ago admin-layouts.php 10 months ago admin-widget-dialog.php 1 year ago admin-widgets-bundle.php 11 months ago admin.php 1 month ago compatibility.php 1 month ago css-builder.php 3 years ago functions.php 3 years ago home.php 3 years ago live-editor.php 2 years ago post-content-filters.php 2 years ago renderer-legacy.php 3 months ago renderer.php 1 month ago revisions.php 3 years ago settings.php 3 months ago sidebars-emulator.php 2 years ago styles-admin.php 11 months ago styles.php 11 months ago widget-shortcode.php 2 years ago
widget-shortcode.php
137 lines
1 <?php
2
3 class SiteOrigin_Panels_Widget_Shortcode {
4 public static $text_widgets = array(
5 'SiteOrigin_Widget_Editor_Widget',
6 'SiteOrigin_Panels_Widgets_Layout',
7 'WP_Widget_Black_Studio_TinyMCE',
8 'WP_Widget_Text',
9 );
10
11 public static function init() {
12 add_shortcode( 'siteorigin_widget', 'SiteOrigin_Panels_Widget_Shortcode::shortcode' );
13 }
14
15 public static function add_filters() {
16 add_filter( 'siteorigin_panels_the_widget_html', 'SiteOrigin_Panels_Widget_Shortcode::widget_html', 10, 4 );
17 }
18
19 public static function remove_filters() {
20 remove_filter( 'siteorigin_panels_the_widget_html', 'SiteOrigin_Panels_Widget_Shortcode::widget_html' );
21 }
22
23 /**
24 * This shortcode just displays a widget based on the given arguments
25 *
26 * @return string
27 */
28 public static function shortcode( $attr, $content ) {
29 $attr = shortcode_atts( array(
30 'class' => false,
31 'id' => '',
32 ), $attr, 'siteorigin_widget' );
33
34 $attr['class'] = html_entity_decode( $attr['class'] );
35 $attr['class'] = apply_filters( 'siteorigin_panels_widget_class', $attr['class'] );
36
37 $the_widget = ! empty( $attr['class'] ) ? SiteOrigin_Panels::get_widget_instance( $attr['class'] ) : null;
38
39 if ( ! empty( $the_widget ) ) {
40 $data = self::decode_data( $content );
41
42 $widget_args = ! empty( $data['args'] ) ? $data['args'] : array();
43 $widget_instance = ! empty( $data['instance'] ) ? $data['instance'] : array();
44
45 $widget_args = self::escape_widget_data( $widget_args );
46 $widget_instance = self::escape_widget_data( $widget_instance );
47
48 $widget_args = wp_parse_args( array(
49 'before_widget' => '',
50 'after_widget' => '',
51 'before_title' => '<h3 class="widget-title">',
52 'after_title' => '</h3>',
53 ), $widget_args );
54
55 ob_start();
56 $the_widget->widget( $widget_args, $widget_instance );
57
58 return ob_get_clean();
59 }
60 }
61
62 public static function escape_widget_data( $data ) {
63 try {
64 $escaped_data = array();
65 foreach ( $data as $key => $value ) {
66 if ( is_array( $value ) ) {
67 $escaped_data[ $key ] = self::escape_widget_data( $value );
68 } else {
69 $escaped_data[ $key ] = esc_html( $value );
70 }
71 }
72 return $escaped_data;
73 } catch (Exception $e) {
74 // There was an error, return empty array.
75 return array();
76 }
77 }
78
79 /**
80 * Get the shortcode for a specific widget
81 *
82 * @return string
83 */
84 public static function get_shortcode( $widget, $args, $instance ) {
85 unset( $instance['panels_info'] );
86
87 $data = array(
88 'instance' => $instance,
89 'args' => $args,
90 );
91
92 // This allows other plugins to implement their own shortcode. For example, to work when Page Builder isn't active
93 $shortcode_name = apply_filters( 'siteorigin_panels_cache_shortcode', 'siteorigin_widget', $widget, $instance, $args );
94
95 $shortcode = '[' . $shortcode_name . ' ';
96 $shortcode .= 'class="' . htmlentities( preg_replace( '/\\\\+/', '\\\\\\\\', get_class( $widget ) ) ) . '"]';
97 $shortcode .= self::encode_data( $data );
98 $shortcode .= '[/' . $shortcode_name . ']';
99
100 return $shortcode;
101 }
102
103 /**
104 * A filter to replace widgets with
105 */
106 public static function widget_html( $html, $widget, $args, $instance ) {
107 if (
108 empty( $GLOBALS['SITEORIGIN_PANELS_POST_CONTENT_RENDER'] ) ||
109 // Don't try create HTML if there already is some
110 ! empty( $html ) ||
111 ! is_object( $widget ) ||
112 // Skip for known text based widgets
113 in_array( get_class( $widget ), self::$text_widgets )
114 ) {
115 return $html;
116 }
117
118 return self::get_shortcode( $widget, $args, $instance );
119 }
120
121 public static function encode_data( $data ) {
122 return '<input type="hidden" value="' . esc_textarea( wp_json_encode( $data, JSON_UNESCAPED_UNICODE ) ) . '" />';
123 }
124
125 public static function decode_data( $string ) {
126 preg_match( '/value="([^"]*)"/', trim( $string ), $matches );
127
128 if ( ! empty( $matches[1] ) ) {
129 $data = json_decode( html_entity_decode( $matches[1], ENT_QUOTES ), true );
130
131 return $data;
132 } else {
133 return array();
134 }
135 }
136 }
137