| 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 |
protected $pwa = false; |
| 13 |
|
| 14 |
private $hideTitleBar = false; |
| 15 |
|
| 16 |
protected $builders = true; |
| 17 |
|
| 18 |
protected $filter_field_name = null; |
| 19 |
|
| 20 |
protected $filter_field_value = null; |
| 21 |
|
| 22 |
protected $shortcode_args = array(); |
| 23 |
|
| 24 |
public function __construct( $args = array() ) { |
| 25 |
if ( isset( $args['feedback'] ) ) { |
| 26 |
$this->feedback = true === $args['feedback'] || 'true' === $args['feedback']; |
| 27 |
} |
| 28 |
if ( isset( $args['fullscreen'] ) ) { |
| 29 |
$this->fullscreen = true === $args['fullscreen'] || 'true' === $args['fullscreen']; |
| 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 |
} |
| 37 |
if ( isset( $args['filter_field_name'] ) ) { |
| 38 |
$this->filter_field_name = WPDA_API_Core::sanitize_db_identifier( $args['filter_field_name'] ); |
| 39 |
} |
| 40 |
if ( isset( $args['filter_field_value'] ) ) { |
| 41 |
$this->filter_field_value = sanitize_text_field( $args['filter_field_value'] ); |
| 42 |
} |
| 43 |
wp_enqueue_style( 'wpda_apps' ); |
| 44 |
wp_enqueue_media(); |
| 45 |
} |
| 46 |
|
| 47 |
protected function add_client( $entry_point, $app_id = null ) { |
| 48 |
$mainjs = "{$entry_point}-" . WPDA::get_option( WPDA::OPTION_WPDA_CLIENT_VERSION ) . '.js'; |
| 49 |
$script_path = plugin_dir_url( __DIR__ ) . "../assets/dist/"; |
| 50 |
$script_url = esc_url( "{$script_path}{$mainjs}" ); |
| 51 |
$app_site = wpda_freemius()->get_site(); |
| 52 |
unset($app_site->public_key); |
| 53 |
unset($app_site->secret_key); |
| 54 |
$app_licenses = wpda_freemius()->get_available_premium_licenses(); |
| 55 |
if ( is_array( $app_licenses ) ) { |
| 56 |
for ($i = 0; $i < count( $app_licenses ); $i++) { |
| 57 |
unset($app_licenses[$i]->secret_key); |
| 58 |
} |
| 59 |
} |
| 60 |
// phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript -- loading module |
| 61 |
?> |
| 62 |
|
| 63 |
<script> |
| 64 |
if (!window.PP_APP_CONFIG) { |
| 65 |
window.PP_APP_CONFIG = { |
| 66 |
appDebug: <?php |
| 67 |
echo ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ? 'true' : 'false' ); |
| 68 |
?>, |
| 69 |
appLocales: "<?php |
| 70 |
echo esc_url( $script_path ) . 'locales/'; |
| 71 |
?>", |
| 72 |
appSite: <?php |
| 73 |
echo json_encode( $app_site, true ); |
| 74 |
?>, |
| 75 |
appLicenses: <?php |
| 76 |
echo json_encode( array( |
| 77 |
'license' => $app_licenses, |
| 78 |
'local' => wpda_freemius()->can_use_premium_code__premium_only(), |
| 79 |
), true ); |
| 80 |
?>, |
| 81 |
appTarget: "<?php |
| 82 |
echo ( is_admin() ? 'backend' : 'frontend' ); |
| 83 |
?>", |
| 84 |
appIp: "<?php |
| 85 |
echo ( isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : '' ); |
| 86 |
?>", |
| 87 |
appUser: "<?php |
| 88 |
echo esc_attr( WPDA::get_current_user_login() ); |
| 89 |
?>", |
| 90 |
appRoles: <?php |
| 91 |
echo ( false === $this->builders ? json_encode( array() ) : json_encode( WPDA::get_current_user_roles() ) ); |
| 92 |
?>, |
| 93 |
appLogin: <?php |
| 94 |
echo ( 'anonymous' !== WPDA::get_current_user_login() ? 'true' : 'false' ); |
| 95 |
?>, |
| 96 |
appVars: <?php |
| 97 |
// phpcs:disable WordPress.Security.NonceVerification.Missing |
| 98 |
echo json_encode( $_POST, true ); |
| 99 |
// phpcs:enable WordPress.Security.NonceVerification.Missing |
| 100 |
?>, |
| 101 |
} |
| 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 |
?> |
| 126 |
</script> |
| 127 |
|
| 128 |
<script type="module" src="<?php |
| 129 |
echo esc_attr( $script_url ); |
| 130 |
?>"></script> |
| 131 |
|
| 132 |
<?php |
| 133 |
// phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 134 |
} |
| 135 |
|
| 136 |
protected function send_feedback() { |
| 137 |
return $this->feedback; |
| 138 |
} |
| 139 |
|
| 140 |
protected function show_feedback( $feedback ) { |
| 141 |
?> |
| 142 |
<div style="padding: 30px 0"> |
| 143 |
<div style="font-weight: normal; margin-bottom: 5px"> |
| 144 |
WP Data Access error in shortcode <?php |
| 145 |
echo esc_attr( $this->get_shortcode_from_class() ); |
| 146 |
?>: |
| 147 |
</div> |
| 148 |
|
| 149 |
<div style="font-weight: bold; color: #d32f2f"> |
| 150 |
<?php |
| 151 |
echo esc_html( $feedback ); |
| 152 |
?> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
<?php |
| 156 |
} |
| 157 |
|
| 158 |
private function get_shortcode_from_class() { |
| 159 |
if ( strpos( get_class( $this ), 'WPDA_App_Container' ) !== false ) { |
| 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'; |
| 165 |
} |
| 166 |
return ''; |
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|