*
* @copyright (c) 2018, César Maeso (https://superadmin.es)
*/
/**
* Ui class.
*
* @since 0.0.0
*/
class ARGPD_Ui {
/**
* Parent plugin class.
*
* @var string
* @since 0.0.0
*/
protected $plugin = null;
/**
* Parent plugin class.
*
* @var string
* @since 1.3.7
*/
const WP_DATATABLE_VERSION = '1.13.1';
/**
* Constructor.
*
* @since 0.0.0
*
* @param string $plugin Plugin name.
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
$this->register();
$this->hooks();
}
/**
* Initiate our hooks.
*
* @since 0.0.0
*/
public function hooks() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
add_action( 'argpd_settings_tab', array( $this, 'argpd_ajustes_tab' ), 10 );
add_action( 'argpd_settings_tab', array( $this, 'argpd_paginas_tab' ), 10 );
add_action( 'argpd_settings_tab', array( $this, 'argpd_cookies_tab' ), 10 );
add_action( 'argpd_settings_tab', array( $this, 'argpd_ayuda_tab' ), 10 );
add_action( 'argpd_settings_content', array( $this, 'argpd_ajustes_content' ), 10 );
add_action( 'argpd_settings_content', array( $this, 'argpd_paginas_content' ), 10 );
add_action( 'argpd_settings_content', array( $this, 'argpd_cookies_content' ), 10 );
add_action( 'argpd_settings_content', array( $this, 'argpd_ayuda_content' ), 10 );
// ajax scripts.
add_action( 'wp_ajax_argpd_get_states', array( $this, 'argpd_get_states' ) );
add_action( 'wp_ajax_consents_load_data', array( $this, 'ajax_consents_load_data' ) );
add_action( 'wp_ajax_argpd_create_page', array( $this, 'create_page' ) );
// print scripts to the footer.
add_action( 'admin_footer', array( $this, 'admin_scripts' ) );
add_action( 'admin_footer', array( $this, 'change_country' ) );
add_action( 'admin_footer', array( $this, 'toggle_bussines_view' ) );
add_action( 'admin_footer', array( $this, 'update_theme_preview' ) );
// enqueue admin styles and scripts.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
}
/**
* Register styles and scripts.
*
* @since 0.0.0
*/
public function register() {
wp_register_style(
'wp-datatable-style',
$this->plugin->url . 'assets/css/jquery.dataTables.min.css?v=' . $this::WP_DATATABLE_VERSION,
array(),
$this->plugin->version
);
wp_register_script(
'wp-datatable-script',
$this->plugin->url . 'assets/js/jquery.dataTables.min.js?v=' . $this::WP_DATATABLE_VERSION,
array(),
$this->plugin->version
);
}
/**
* Register scripts and Styles.
*
* @param string $hook is the hookname.
* @since 0.0.0
*/
public function enqueue_admin_assets( $hook ) {
// Load assets only on plugin page ?page=argpd-consents.
if ( 'adapta-rgpd_page_argpd-consents' != $hook ) {
return;
}
wp_enqueue_style( 'wp-datatable-style' );
wp_enqueue_script( 'wp-datatable-script' );
}
/**
* Function wp-ajax to create pages
*
* @since 1.0.1
*/
public function create_page() {
check_ajax_referer( 'argpd_create_page', 'security' );
$id = 0;
$page = ! empty( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
switch ( $page ) {
case 'crear-pagina-legal':
$id = $this->plugin->pages->create_legal_page();
break;
case 'crear-pagina-privacidad':
$id = $this->plugin->pages->create_privacy_page();
break;
case 'crear-pagina-cookies':
$id = $this->plugin->pages->create_cookies_page();
break;
case 'create-custom-cookies-page':
$id = $this->plugin->pages->create_custom_cookies_page();
break;
default:
break;
}
echo esc_attr( $id );
wp_die();
}
/**
* Function wp-ajax to echo states
*
* @since 1.0.0
*/
public function change_country() {
?>
plugin->argpd_settings;
?>
plugin->argpd_settings;
$states = $settings->get_states( $country );
?>
plugin->argpd_settings;
$classes = array();
$classes['empresa'] = $settings->get_setting( 'es-empresa' ) ? 'empresa' : 'empresa oculto';
$classes['particular'] = $settings->get_setting( 'es-empresa' ) ? 'particular oculto' : 'particular';
?>
plugin->argpd_settings;
?>
plugin->argpd_settings;
$all_settings = $this->plugin->argpd_settings->get_settings();
?>
plugin->pages->help_tab_view();
echo $this->plugin->pages->disclaimer();
?>
ui_header();
$settings = $this->plugin->argpd_settings;
if ( $settings->get_setting( 'renuncia' ) == 0 ) { return; }
?>
ui_header();
$settings = $this->plugin->argpd_settings;
$all_settings = $this->plugin->argpd_settings->get_settings();
if ( $settings->get_setting( 'renuncia' ) == 0 ) { return; }
?>
ui_footer();
}
/**
* echo addons_ui page
*
* @since 1.3.5
*/
public function consents_ui() {
global $argpd_active_tab;
$argpd_active_tab = ! empty( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'settings';
$this->ui_header();
$settings = $this->plugin->argpd_settings;
$all_settings = $this->plugin->argpd_settings->get_settings();
if ( $settings->get_setting( 'renuncia' ) == 0 ) { return; }
?>
ui_footer();
}
/**
* Echo plugin settings view
*
* @since 1.3.5
*/
public function ui_footer() {
?>
★ Superadmin.es ★
¡Ayuda a mejorar el plugin! Danos tu valoración de ★★★★★ aquí.', 'argpd' ); ?>
plugin->argpd_settings;
if ( $settings->get_setting( 'renuncia' ) == 0 ) {
?>
$plugin_data ) {
if ( strpos( $plugin_path, $name . '/' ) !== false ) {
$data = $plugin_data;
$data['basename'] = $plugin_path;
break;
}
}
}
}
return $data;
}
/**
* Get information regarding used assets
*
* @return bool
*/
public function collect_assets() {
$collection = [];
global $wp_scripts;
$data = $wp_scripts;
foreach ( $data->done as $el ) {
if ( isset( $data->registered[ $el ] ) ) {
if ( 'argpd-cookies-eu-banner' == $el ) {
continue;
}
if ( isset( $data->registered[ $el ]->src ) ) {
$url = $this->prepare_url( $data->registered[ $el ]->src );
$url_short = str_replace( get_home_url(), '', $url );
if ( strpos( $url, plugins_url() ) !== 0 ) {
continue;
}
$clean_url = str_replace( WP_PLUGIN_URL . '/', '', $url );
$url_parts = explode( '/', $clean_url );
$resource_name = ! empty( $url_parts[0] ) ? $url_parts[0] : null;
if ( ! isset( $collection[ $el ] ) ) {
$plugin_data = $this->get_plugin_data( $resource_name );
$collection[ $el ] = [
'url_full' => $url,
'url_short' => $url_short,
'resource_name' => $resource_name,
'script_name' => substr( $url_short, strrpos( $url_short, '/' ) + 1 ),
'title' => $plugin_data['Title'],
'author' => $plugin_data['Author'],
'el' => $el,
];
}
}
}
}
return $collection;
}
/**
* Get shifts data via Ajax.
*
* @since 0.0.0
*/
public function ajax_consents_load_data() {
check_ajax_referer( 'consents_load_data', 'security' );
$settings = $this->plugin->argpd_settings;
$option_store_consents = $settings->get_setting( 'option-store-consents' );
$apikey = $settings->get_setting( 'apikey' );
$jwt_token = "";
if ($option_store_consents && strlen($apikey) > 0 ) {
// get auth
$args = array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json'
),
'body' => json_encode(array('token' => $apikey )),
);
$response = wp_remote_post ("https://superapis.es/legaltech360/api/v1/auth", $args);
if ( is_wp_error( $response ) ) {
wp_die();
} else {
$jwt_token = $response['body'];
}
if ( strlen( $jwt_token ) == 0 ) {
wp_die();
}
// retrieve consents.
$args = array(
'method' => 'GET',
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $jwt_token,
'Origin' => esc_url ( get_site_url() ),
),
);
$url = "https://superapis.es/legaltech360/api/v1/consents/consent";
$filter = trim( sanitize_text_field ( $_REQUEST['filter'] ) );
if ( strlen( $filter ) ) {
$url = sprintf( "%s/%s", $url, $filter );
}
$response = wp_remote_post ($url, $args);
if ( is_wp_error( $response ) ) {
wp_die();
} else {
echo $response['body'];
}
}
wp_die();
}
}