| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | private $feedback = false; |
| 9 | 9 | |
| 10 | 10 | private $fullscreen = false; |
| 11 | 11 | |
| 12 | + protected $pwa = false; | |
| 13 | + | |
| 14 | + private $hideTitleBar = false; | |
| 15 | + | |
| 12 | 16 | protected $builders = true; |
| 13 | 17 | |
| 14 | 18 | protected $filter_field_name = null; |
| 15 | 19 | |
| @@ -14,17 +18,23 @@ | ||
| 14 | 18 | protected $filter_field_name = null; |
| 15 | 19 | |
| 16 | 20 | protected $filter_field_value = null; |
| 17 | 21 | |
| 18 | - protected $shortcode_args = null; | |
| 22 | + protected $shortcode_args = array(); | |
| 19 | 23 | |
| 20 | - public function __construct( $args = array(), $shortcode_args = array() ) { | |
| 24 | + public function __construct( $args = array() ) { | |
| 21 | 25 | if ( isset( $args['feedback'] ) ) { |
| 22 | 26 | $this->feedback = true === $args['feedback'] || 'true' === $args['feedback']; |
| 23 | 27 | } |
| 24 | - if ( isset( $shortcode_args['fullscreen'] ) ) { | |
| 25 | - $this->fullscreen = true === $shortcode_args['fullscreen'] || 'true' === $shortcode_args['fullscreen']; | |
| 28 | + if ( isset( $args['fullscreen'] ) ) { | |
| 29 | + $this->fullscreen = true === $args['fullscreen'] || 'true' === $args['fullscreen']; | |
| 26 | 30 | } |
| 31 | + if ( isset( $args['pwa'] ) ) { | |
| 32 | + $this->pwa = true === $args['pwa'] || 'true' === $args['pwa']; | |
| 33 | + } | |
| 34 | + if ( isset( $args['hidetitlebar'] ) ) { | |
| 35 | + $this->hideTitleBar = true === $args['hidetitlebar'] || 'true' === $args['hidetitlebar']; | |
| 36 | + } | |
| 27 | 37 | if ( isset( $args['filter_field_name'] ) ) { |
| 28 | 38 | $this->filter_field_name = WPDA_API_Core::sanitize_db_identifier( $args['filter_field_name'] ); |
| 29 | 39 | } |
| 30 | 40 | if ( isset( $args['filter_field_value'] ) ) { |
| @@ -29,17 +39,16 @@ | ||
| 29 | 39 | } |
| 30 | 40 | if ( isset( $args['filter_field_value'] ) ) { |
| 31 | 41 | $this->filter_field_value = sanitize_text_field( $args['filter_field_value'] ); |
| 32 | 42 | } |
| 33 | - $this->shortcode_args = $shortcode_args; | |
| 34 | 43 | wp_enqueue_style( 'wpda_apps' ); |
| 35 | 44 | wp_enqueue_media(); |
| 36 | 45 | } |
| 37 | 46 | |
| 38 | - protected function add_client() { | |
| 39 | - $mainjs = 'main-' . WPDA::get_option( WPDA::OPTION_WPDA_CLIENT_VERSION ) . '.js'; | |
| 47 | + protected function add_client( $entry_point, $app_id = null ) { | |
| 48 | + $mainjs = "{$entry_point}-" . WPDA::get_option( WPDA::OPTION_WPDA_CLIENT_VERSION ) . '.js'; | |
| 40 | 49 | $script_path = plugin_dir_url( __DIR__ ) . "../assets/dist/"; |
| 41 | - $script_url = "{$script_path}/{$mainjs}"; | |
| 50 | + $script_url = esc_url( "{$script_path}{$mainjs}" ); | |
| 42 | 51 | $app_site = wpda_freemius()->get_site(); |
| 43 | 52 | unset($app_site->public_key); |
| 44 | 53 | unset($app_site->secret_key); |
| 45 | 54 | $app_licenses = wpda_freemius()->get_available_premium_licenses(); |
| @@ -47,55 +56,82 @@ | ||
| 47 | 56 | for ($i = 0; $i < count( $app_licenses ); $i++) { |
| 48 | 57 | unset($app_licenses[$i]->secret_key); |
| 49 | 58 | } |
| 50 | 59 | } |
| 60 | + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript -- loading module | |
| 51 | 61 | ?> |
| 52 | 62 | |
| 53 | 63 | <script> |
| 54 | - window.PP_APP_CONFIG = { | |
| 55 | - appDebug: <?php | |
| 64 | + if (!window.PP_APP_CONFIG) { | |
| 65 | + window.PP_APP_CONFIG = { | |
| 66 | + appDebug: <?php | |
| 56 | 67 | echo ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ? 'true' : 'false' ); |
| 57 | 68 | ?>, |
| 58 | - appLocales: "<?php | |
| 69 | + appLocales: "<?php | |
| 59 | 70 | echo esc_url( $script_path ) . 'locales/'; |
| 60 | 71 | ?>", |
| 61 | - appSite: <?php | |
| 72 | + appSite: <?php | |
| 62 | 73 | echo json_encode( $app_site, true ); |
| 63 | 74 | ?>, |
| 64 | - appLicenses: <?php | |
| 75 | + appLicenses: <?php | |
| 65 | 76 | echo json_encode( array( |
| 66 | 77 | 'license' => $app_licenses, |
| 67 | 78 | 'local' => wpda_freemius()->can_use_premium_code__premium_only(), |
| 68 | 79 | ), true ); |
| 69 | 80 | ?>, |
| 70 | - appTarget: "<?php | |
| 81 | + appTarget: "<?php | |
| 71 | 82 | echo ( is_admin() ? 'backend' : 'frontend' ); |
| 72 | 83 | ?>", |
| 73 | - appIp: "<?php | |
| 74 | - echo esc_attr( $_SERVER['REMOTE_ADDR'] ); | |
| 84 | + appIp: "<?php | |
| 85 | + echo ( isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : '' ); | |
| 75 | 86 | ?>", |
| 76 | - appUser: "<?php | |
| 87 | + appUser: "<?php | |
| 77 | 88 | echo esc_attr( WPDA::get_current_user_login() ); |
| 78 | 89 | ?>", |
| 79 | - appRoles: <?php | |
| 90 | + appRoles: <?php | |
| 80 | 91 | echo ( false === $this->builders ? json_encode( array() ) : json_encode( WPDA::get_current_user_roles() ) ); |
| 81 | 92 | ?>, |
| 82 | - appLogin: <?php | |
| 93 | + appLogin: <?php | |
| 83 | 94 | echo ( 'anonymous' !== WPDA::get_current_user_login() ? 'true' : 'false' ); |
| 84 | 95 | ?>, |
| 85 | - appVars: <?php | |
| 96 | + appVars: <?php | |
| 97 | + // phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 86 | 98 | echo json_encode( $_POST, true ); |
| 99 | + // phpcs:enable WordPress.Security.NonceVerification.Missing | |
| 87 | 100 | ?>, |
| 88 | - appFullscreen: <?php | |
| 89 | - echo ( $this->fullscreen ? 'true' : 'false' ); | |
| 90 | - ?>, | |
| 101 | + } | |
| 91 | 102 | } |
| 103 | + <?php | |
| 104 | + if ( null !== $app_id ) { | |
| 105 | + // Supporting multiple apps on same page with different settings | |
| 106 | + ?> | |
| 107 | + window.PP_APP_CONFIG[<?php | |
| 108 | + echo esc_attr( $app_id ); | |
| 109 | + ?>] = { | |
| 110 | + appRoles: <?php | |
| 111 | + echo ( false === $this->builders ? json_encode( array() ) : json_encode( WPDA::get_current_user_roles() ) ); | |
| 112 | + ?>, | |
| 113 | + appFullscreen: <?php | |
| 114 | + echo ( $this->fullscreen ? 'true' : 'false' ); | |
| 115 | + ?>, | |
| 116 | + appPwa: <?php | |
| 117 | + echo ( $this->pwa ? 'true' : 'false' ); | |
| 118 | + ?>, | |
| 119 | + hideTitleBar: <?php | |
| 120 | + echo ( $this->hideTitleBar ? 'true' : 'false' ); | |
| 121 | + ?>, | |
| 122 | + } | |
| 123 | + <?php | |
| 124 | + } | |
| 125 | + ?> | |
| 92 | 126 | </script> |
| 127 | + | |
| 93 | 128 | <script type="module" src="<?php |
| 94 | 129 | echo esc_attr( $script_url ); |
| 95 | 130 | ?>"></script> |
| 96 | 131 | |
| 97 | 132 | <?php |
| 133 | + // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 98 | 134 | } |
| 99 | 135 | |
| 100 | 136 | protected function send_feedback() { |
| 101 | 137 | return $this->feedback; |
| @@ -104,9 +140,9 @@ | ||
| 104 | 140 | protected function show_feedback( $feedback ) { |
| 105 | 141 | ?> |
| 106 | 142 | <div style="padding: 30px 0"> |
| 107 | 143 | <div style="font-weight: normal; margin-bottom: 5px"> |
| 108 | - WP Data Access error in shortcode<?php | |
| 144 | + WP Data Access error in shortcode <?php | |
| 109 | 145 | echo esc_attr( $this->get_shortcode_from_class() ); |
| 110 | 146 | ?>: |
| 111 | 147 | </div> |
| 112 | 148 | |
| @@ -120,13 +156,13 @@ | ||
| 120 | 156 | } |
| 121 | 157 | |
| 122 | 158 | private function get_shortcode_from_class() { |
| 123 | 159 | if ( strpos( get_class( $this ), 'WPDA_App_Container' ) !== false ) { |
| 124 | - return ' wpda_app'; | |
| 125 | - } elseif ( strpos( get_class( $this ), 'WPDA_Apps_List' ) !== false ) { | |
| 126 | - return ' wpda_apps'; | |
| 127 | - } elseif ( strpos( get_class( $this ), 'WPDA_Explorer_Container' ) !== false ) { | |
| 128 | - return ' wpda_data_explorer'; | |
| 160 | + return 'wpda_app'; | |
| 161 | + } elseif ( strpos( get_class( $this ), 'WPDA_App_Builder' ) !== false ) { | |
| 162 | + return 'wpda_app_builder'; | |
| 163 | + } elseif ( strpos( get_class( $this ), 'WPDA_Data_Explorer' ) !== false ) { | |
| 164 | + return 'wpda_data_explorer'; | |
| 129 | 165 | } |
| 130 | 166 | return ''; |
| 131 | 167 | } |
| 132 | 168 | |