PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.85
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.85
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
← All changes | WPDataAccess/Data_Apps/WPDA_App_Container.php +66 -16 5.5.35 → 5.5.85 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 3 namespace WPDataAccess\Data_Apps {
4 4
5 + use WPDataAccess\API\WPDA_API_Core;
6 + use WPDataAccess\API\WPDA_Apps;
5 7 use WPDataAccess\Plugin_Table_Models\WPDA_App_Apps_Model;
6 8 use WPDataAccess\Plugin_Table_Models\WPDA_App_Model;
7 9 use WPDataAccess\WPDA;
8 10
@@ -9,11 +11,14 @@
9 11 class WPDA_App_Container extends WPDA_Container {
10 12
11 13 private $app_id = '';
12 14
13 - public function __construct( $args = array(), $shortcode_args = array() ) {
15 + public function __construct(
16 + $args = array(),
17 + $shortcode_args = array()
18 + ) {
14 19
15 - parent::__construct( $args, $shortcode_args );
20 + parent::__construct( $args );
16 21
17 22 if ( isset( $args['app_id'] ) ) {
18 23 $this->app_id = $args['app_id'];
19 24 }
@@ -27,13 +32,15 @@
27 32 ) {
28 33 $this->builders = false;
29 34 }
30 35
36 + $this->shortcode_args = $shortcode_args;
37 +
31 38 }
32 39
33 40 private function get_app_metadata( $app_id ) {
34 41
35 - $app = new \WPDataAccess\API\WPDA_Apps();
42 + $app = new WPDA_Apps();
36 43 $response = $app->get_app_meta( $app_id );
37 44
38 45 if (
39 46 isset( $response->data['code'], $response->data['data'] ) &&
@@ -53,13 +60,18 @@
53 60 if ( ! $this->send_feedback() ) {
54 61 return;
55 62 }
56 63
57 - $this->show_feedback( __( 'Invalid app id', 'wp-data-access' ) );
64 + $this->show_feedback( __( 'Not authorized', 'wp-data-access' ) );
58 65 return;
59 66 }
60 67
61 68 if ( ! $this->user_can_access( $app ) ) {
69 + if ( $this->pwa ) {
70 + esc_html_e( 'Not authorized', 'wp-data-access' );
71 + return;
72 + }
73 +
62 74 if ( ! $this->send_feedback() ) {
63 75 return;
64 76 }
65 77
@@ -68,8 +80,9 @@
68 80 }
69 81
70 82 $metadata = array();
71 83 $metadata_master = $this->get_app_metadata( $this->app_id);
84 +
72 85 if ( null !== $metadata_master) {
73 86 $metadata[$this->app_id] = $metadata_master;
74 87 }
75 88
@@ -86,29 +99,65 @@
86 99 }
87 100 }
88 101 }
89 102
103 + $app_type_class = '';
104 + switch ($app[0]['app_type']) {
105 + case '2':
106 + // Map
107 + $app_type_class = 'pp-container-map';
108 + break;
109 + case '3':
110 + // Registration form
111 + $app_type_class = 'pp-container-registration';
112 + break;
113 + case '5':
114 + // Data App
115 + $app_type_class = 'pp-container-apps';
116 + break;
117 + case '6':
118 + // Chart
119 + $app_type_class = 'pp-container-chart';
120 + break;
121 + case '7':
122 + // Chart
123 + $app_type_class = 'pp-container-dashboard';
124 + break;
125 + }
90 126 ?>
91 127
92 128 <div class="wpda-pp-container">
93 129 <div
94 - class="pp-container-app"
95 - data-source="{ 'id': '<?php echo $this->app_id; ?>' }"
130 + class="pp-container-app <?php echo esc_attr( $app_type_class ); ?>"
131 + data-source="{ 'id': '<?php echo esc_attr( $this->app_id ); ?>' }"
96 132
97 133 <?php
98 134 if ( null !== $this->filter_field_name && null !== $this->filter_field_value ) {
99 135 ?>
100 - data-filter_field_name="<?php echo $this->filter_field_name; ?>"
101 - data-filter_field_value="<?php echo $this->filter_field_value; ?>"
136 + data-filter_field_name="<?php echo esc_attr( $this->filter_field_name ); ?>"
137 + data-filter_field_value="<?php echo esc_attr( $this->filter_field_value ); ?>"
102 138 <?php
103 139 }
104 140
105 - if ( 0 < count( $this->shortcode_args ) ) {
106 - ?>
107 - data-shortcode_field_name="<?php echo implode( ',', array_keys( $this->shortcode_args ) ); ?>"
108 - data-shortcode_field_value="<?php echo implode( ',', array_values( $this->shortcode_args ) ); ?>"
109 - <?php
110 - }
141 + if ( 0 < count( $this->shortcode_args ) ) {
142 + $field_names = array();
143 + $field_values = array();
144 + foreach ( $this->shortcode_args as $key => $value ) {
145 + // Sanitize field name
146 + $field_names[] = WPDA_API_Core::sanitize_db_identifier( $key );
147 + // Sanitize field value
148 + $sanitized_value = sanitize_text_field( $value );
149 + $sanitized_value = wp_strip_all_tags( $sanitized_value );
150 + $sanitized_value = str_replace( array( '"', "'", '`' ), '', $sanitized_value );
151 + $sanitized_value = str_replace( array( '<', '>' ), '', $sanitized_value );
152 + $sanitized_value = str_replace( '=', '', $sanitized_value );
153 + $field_values[] = $sanitized_value;
154 + }
155 + ?>
156 + data-shortcode_field_name="<?php echo esc_attr( implode( ',', $field_names) ); ?>"
157 + data-shortcode_field_value="<?php echo esc_attr( implode( ',', $field_values ) ); ?>"
158 + <?php
159 + }
111 160 ?>
112 161 ></div>
113 162 </div>
114 163
@@ -113,8 +162,9 @@
113 162 </div>
114 163
115 164 <?php
116 165 if ( 0 < count( $metadata ) ) {
166 + // Add metadata detail apps to decrease load time
117 167 ?>
118 168 <script>
119 169 <?php
120 170 foreach ( $metadata as $app_id => $data ) {
@@ -131,9 +181,9 @@
131 181 ?>
132 182
133 183 <?php
134 184
135 - $this->add_client( $this->app_id );
185 + $this->add_client('app', $this->app_id );
136 186
137 187 }
138 188
139 189 private function user_can_access( $app ) {
@@ -176,9 +226,9 @@
176 226 ) {
177 227 // Check user login
178 228 $user_login = WPDA::get_current_user_login();
179 229 if ( ! in_array( $user_login, $app_settings['rest_api']['authorized_users'] ) ) {
180 - return false;
230 + return false;
181 231 }
182 232 }
183 233 }
184 234