PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.41
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.41
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
wp-data-access / WPDataAccess / Data_Apps / WPDA_Container.php

WPDA_Container.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.41, at WPDataAccess/Data_Apps/WPDA_Container.php

157 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Data_Apps;
4
5 use WPDataAccess\API\WPDA_API_Core;
6 use WPDataAccess\WPDA;
7 abstract class WPDA_Container {
8 private $feedback = false;
9
10 private $fullscreen = false;
11
12 private $hideTitleBar = false;
13
14 protected $builders = true;
15
16 protected $filter_field_name = null;
17
18 protected $filter_field_value = null;
19
20 protected $shortcode_args = array();
21
22 public function __construct( $args = array() ) {
23 if ( isset( $args['feedback'] ) ) {
24 $this->feedback = true === $args['feedback'] || 'true' === $args['feedback'];
25 }
26 if ( isset( $args['fullscreen'] ) ) {
27 $this->fullscreen = true === $args['fullscreen'] || 'true' === $args['fullscreen'];
28 }
29 if ( isset( $args['hidetitlebar'] ) ) {
30 $this->hideTitleBar = true === $args['hidetitlebar'] || 'true' === $args['hidetitlebar'];
31 }
32 if ( isset( $args['filter_field_name'] ) ) {
33 $this->filter_field_name = WPDA_API_Core::sanitize_db_identifier( $args['filter_field_name'] );
34 }
35 if ( isset( $args['filter_field_value'] ) ) {
36 $this->filter_field_value = sanitize_text_field( $args['filter_field_value'] );
37 }
38 wp_enqueue_style( 'wpda_apps' );
39 wp_enqueue_media();
40 }
41
42 protected function add_client( $app_id = null ) {
43 $mainjs = 'main-' . WPDA::get_option( WPDA::OPTION_WPDA_CLIENT_VERSION ) . '.js';
44 $script_path = plugin_dir_url( __DIR__ ) . "../assets/dist/";
45 $script_url = "{$script_path}/{$mainjs}";
46 $app_site = wpda_freemius()->get_site();
47 unset($app_site->public_key);
48 unset($app_site->secret_key);
49 $app_licenses = wpda_freemius()->get_available_premium_licenses();
50 if ( is_array( $app_licenses ) ) {
51 for ($i = 0; $i < count( $app_licenses ); $i++) {
52 unset($app_licenses[$i]->secret_key);
53 }
54 }
55 ?>
56
57 <script>
58 if (! window.PP_APP_CONFIG) {
59 window.PP_APP_CONFIG = {
60 appDebug: <?php
61 echo ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ? 'true' : 'false' );
62 ?>,
63 appLocales: "<?php
64 echo esc_url( $script_path ) . 'locales/';
65 ?>",
66 appSite: <?php
67 echo json_encode( $app_site, true );
68 ?>,
69 appLicenses: <?php
70 echo json_encode( array(
71 'license' => $app_licenses,
72 'local' => wpda_freemius()->can_use_premium_code__premium_only(),
73 ), true );
74 ?>,
75 appTarget: "<?php
76 echo ( is_admin() ? 'backend' : 'frontend' );
77 ?>",
78 appIp: "<?php
79 echo esc_attr( $_SERVER['REMOTE_ADDR'] );
80 ?>",
81 appUser: "<?php
82 echo esc_attr( WPDA::get_current_user_login() );
83 ?>",
84 appRoles: <?php
85 echo ( false === $this->builders ? json_encode( array() ) : json_encode( WPDA::get_current_user_roles() ) );
86 ?>,
87 appLogin: <?php
88 echo ( 'anonymous' !== WPDA::get_current_user_login() ? 'true' : 'false' );
89 ?>,
90 appVars: <?php
91 echo json_encode( $_POST, true );
92 ?>,
93 }
94 }
95 <?php
96 if ( null !== $app_id ) {
97 // Supporting multiple apps on same page with different settings
98 ?>
99 window.PP_APP_CONFIG[<?php
100 echo esc_attr( $app_id );
101 ?>] = {
102 appRoles: <?php
103 echo ( false === $this->builders ? json_encode( array() ) : json_encode( WPDA::get_current_user_roles() ) );
104 ?>,
105 appFullscreen: <?php
106 echo ( $this->fullscreen ? 'true' : 'false' );
107 ?>,
108 hideTitleBar: <?php
109 echo ( $this->hideTitleBar ? 'true' : 'false' );
110 ?>,
111 }
112 <?php
113 }
114 ?>
115 </script>
116 <script type="module" src="<?php
117 echo esc_attr( $script_url );
118 ?>"></script>
119
120 <?php
121 }
122
123 protected function send_feedback() {
124 return $this->feedback;
125 }
126
127 protected function show_feedback( $feedback ) {
128 ?>
129 <div style="padding: 30px 0">
130 <div style="font-weight: normal; margin-bottom: 5px">
131 WP Data Access error in shortcode <?php
132 echo esc_attr( $this->get_shortcode_from_class() );
133 ?>:
134 </div>
135
136 <div style="font-weight: bold; color: #d32f2f">
137 <?php
138 echo esc_html( $feedback );
139 ?>
140 </div>
141 </div>
142 <?php
143 }
144
145 private function get_shortcode_from_class() {
146 if ( strpos( get_class( $this ), 'WPDA_App_Container' ) !== false ) {
147 return 'wpda_app';
148 } elseif ( strpos( get_class( $this ), 'WPDA_App_Builder' ) !== false ) {
149 return 'wpda_app_builder';
150 } elseif ( strpos( get_class( $this ), 'WPDA_Data_Explorer' ) !== false ) {
151 return 'wpda_data_explorer';
152 }
153 return '';
154 }
155
156 }
157