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 +122 -17 5.5.22 → 5.5.85 View file →
@@ -1,9 +1,12 @@
1 1 <?php
2 2
3 3 namespace WPDataAccess\Data_Apps {
4 4
5 - use WPDataAccess\Plugin_Table_Models\WPDA_App_Model;
5 + use WPDataAccess\API\WPDA_API_Core;
6 + use WPDataAccess\API\WPDA_Apps;
7 + use WPDataAccess\Plugin_Table_Models\WPDA_App_Apps_Model;
8 + use WPDataAccess\Plugin_Table_Models\WPDA_App_Model;
6 9 use WPDataAccess\WPDA;
7 10
8 11 class WPDA_App_Container extends WPDA_Container {
9 12
@@ -8,11 +11,14 @@
8 11 class WPDA_App_Container extends WPDA_Container {
9 12
10 13 private $app_id = '';
11 14
12 - public function __construct( $args = array(), $shortcode_args = array() ) {
15 + public function __construct(
16 + $args = array(),
17 + $shortcode_args = array()
18 + ) {
13 19
14 - parent::__construct( $args, $shortcode_args );
20 + parent::__construct( $args );
15 21
16 22 if ( isset( $args['app_id'] ) ) {
17 23 $this->app_id = $args['app_id'];
18 24 }
@@ -26,10 +32,28 @@
26 32 ) {
27 33 $this->builders = false;
28 34 }
29 35
36 + $this->shortcode_args = $shortcode_args;
37 +
30 38 }
31 39
40 + private function get_app_metadata( $app_id ) {
41 +
42 + $app = new WPDA_Apps();
43 + $response = $app->get_app_meta( $app_id );
44 +
45 + if (
46 + isset( $response->data['code'], $response->data['data'] ) &&
47 + 'ok' === $response->data['code']
48 + ) {
49 + return $response->data['data'];
50 + }
51 +
52 + return null;
53 +
54 + }
55 +
32 56 public function show() {
33 57
34 58 $app = WPDA_App_Model::get_by_id( $this->app_id );
35 59 if ( false === $app ) {
@@ -36,13 +60,18 @@
36 60 if ( ! $this->send_feedback() ) {
37 61 return;
38 62 }
39 63
40 - $this->show_feedback( __( 'Invalid app id', 'wp-data-access' ) );
64 + $this->show_feedback( __( 'Not authorized', 'wp-data-access' ) );
41 65 return;
42 66 }
43 67
44 68 if ( ! $this->user_can_access( $app ) ) {
69 + if ( $this->pwa ) {
70 + esc_html_e( 'Not authorized', 'wp-data-access' );
71 + return;
72 + }
73 +
45 74 if ( ! $this->send_feedback() ) {
46 75 return;
47 76 }
48 77
@@ -49,36 +78,112 @@
49 78 $this->show_feedback( __( 'Not authorized', 'wp-data-access' ) );
50 79 return;
51 80 }
52 81
82 + $metadata = array();
83 + $metadata_master = $this->get_app_metadata( $this->app_id);
84 +
85 + if ( null !== $metadata_master) {
86 + $metadata[$this->app_id] = $metadata_master;
87 + }
88 +
89 + if ( isset( $app[0]['app_type'] ) && '5' == $app[0]['app_type'] ) {
90 + // Add metadata children
91 + $detail_apps = WPDA_App_Apps_Model::select_all( $this->app_id );
92 + foreach ( $detail_apps as $detail_app ) {
93 + if ( isset( $detail_app['app_id_detail'] ) ) {
94 + $app_id_detail = $detail_app['app_id_detail'];
95 + $metadata_detail = $this->get_app_metadata($app_id_detail);
96 + if (null !== $metadata_detail) {
97 + $metadata[$app_id_detail] = $metadata_detail;
98 + }
99 + }
100 + }
101 + }
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 + }
53 126 ?>
54 127
55 128 <div class="wpda-pp-container">
56 129 <div
57 - class="pp-container-app"
58 - 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 ); ?>' }"
59 132
60 133 <?php
61 134 if ( null !== $this->filter_field_name && null !== $this->filter_field_value ) {
62 135 ?>
63 - data-filter_field_name="<?php echo $this->filter_field_name; ?>"
64 - 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 ); ?>"
65 138 <?php
66 139 }
67 140
68 - if ( 0 < count( $this->shortcode_args ) ) {
69 - ?>
70 - data-shortcode_field_name="<?php echo implode( ',', array_keys( $this->shortcode_args ) ); ?>"
71 - data-shortcode_field_value="<?php echo implode( ',', array_values( $this->shortcode_args ) ); ?>"
72 - <?php
73 - }
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 + }
74 160 ?>
75 161 ></div>
76 162 </div>
77 163
164 + <?php
165 + if ( 0 < count( $metadata ) ) {
166 + // Add metadata detail apps to decrease load time
167 + ?>
168 + <script>
169 + <?php
170 + foreach ( $metadata as $app_id => $data ) {
171 + ?>
172 + window.pp_app_<?php echo esc_attr( $app_id ); ?> = {
173 + metadata: <?php echo json_encode( $data, true ); ?>
174 + }
175 + <?php
176 + }
177 + ?>
178 + </script>
179 + <?php
180 + }
181 + ?>
182 +
78 183 <?php
79 184
80 - $this->add_client();
185 + $this->add_client('app', $this->app_id );
81 186
82 187 }
83 188
84 189 private function user_can_access( $app ) {
@@ -103,9 +208,9 @@
103 208 return false;
104 209 }
105 210
106 211 if (
107 - ! current_user_can( 'manage_options' ) &&
212 + ! WPDA::current_user_is_admin() &&
108 213 'anonymous' !== $app_settings['rest_api']['authorization']
109 214 ) {
110 215 // Check authorization
111 216 // Check user role
@@ -121,9 +226,9 @@
121 226 ) {
122 227 // Check user login
123 228 $user_login = WPDA::get_current_user_login();
124 229 if ( ! in_array( $user_login, $app_settings['rest_api']['authorized_users'] ) ) {
125 - return false;
230 + return false;
126 231 }
127 232 }
128 233 }
129 234