You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
cosmopet.ae/wp-content/plugins copy/contactsheets-lite/includes/class-wpsslc-plugin-setting...

354 lines
15 KiB

<?php
/**
* Main ContactsheetsLite\WPSSLC_Google_API namespace.
*
* @since 1.0.0
* @package contactsheets-lite
*/
use ContactsheetsLite\WPSSLC_Google_API_Functions;
/**
* Handle plugin installation upon activation.
*
* @since 1.0.0
*/
class WPSSLC_Plugin_Settings {
/**
* Url for plugin api settings documentation.
*
* @var $doc_sheet_setting .
*/
protected $doc_sheet_setting = 'https://docs.wpsyncsheets.com/wpssc-google-sheets-api-settings/';
/**
* Url for plugin support.
*
* @var $submit_ticket
*/
protected $submit_ticket = 'https://wordpress.org/support/plugin/contactsheets-lite/';
/**
* Instance of class.
*
* @var $instance Instance variable of class.
*/
private static $instance = null;
/**
* Instance of WPSSLC_Google_API_Functions class.
*
* @var $instance_api Instance variable of WPSSLC_Google_API_Functions class.
*/
private static $instance_api = null;
/**
* Primary class constructor.
*
* @since 1.0.0
*/
public function __construct() {
register_activation_hook( WPSSLC_BASE_FILE, array( $this, 'wpsslc_activation' ) );
register_deactivation_hook( WPSSLC_BASE_FILE, array( $this, 'wpsslc_deactivation' ) );
add_action( 'admin_menu', array( $this, 'wpsslc_menu_page' ), 30 );
add_action( 'admin_enqueue_scripts', array( $this, 'wpsslc_load_custom_wp_admin_style' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'wpsslc_selectively_enqueue_admin_script' ) );
add_filter( 'plugin_row_meta', array( $this, 'wpsslc_plugin_row_meta' ), 10, 2 );
$this->wpsslc_google_api();
}
/**
* Main WPSSLC_Plugin_Settings Instance.
*
* @since 1.0.0
*
* @return instance
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Get an instance of WPSSLC_Google_API_Functions class.
*
* @return WPSSLC_Google_API_Functions class instance
*/
public static function wpsslc_google_api() {
if ( null === self::$instance_api ) {
self::$instance_api = new WPSSLC_Google_API_Functions();
}
return self::$instance_api;
}
/**
* WPSSLC Plugin Activation Hook
*/
public function wpsslc_activation() {
update_option( 'active_contactsheets', 1 );
}
/**
* WPSSLC Plugin Deactivation Hook
*/
public function wpsslc_deactivation() {
update_option( 'active_contactsheets', '' );
}
/**
* Register a plugin menu page.
*/
public function wpsslc_menu_page() {
global $admin_page_hooks, $_parent_pages;
if ( ! isset( $admin_page_hooks['wpsyncsheets_lite'] ) ) {
$wpsslc_page = add_menu_page(
esc_attr__( 'WPSyncSheets Lite', 'wpssc' ),
'WPSyncSheets Lite',
'manage_options',
'wpsyncsheets_lite',
'',
WPSSLC_URL . 'assets/images/menu-icon.svg',
90
);
}
add_submenu_page( 'wpsyncsheets_lite', 'WPSyncSheets Lite For Contact Form 7', 'For Contact Form 7', 'manage_options', 'wpsyncsheets-contact-form-7', array( $this, 'wpsslc_plugin_page' ), 1 );
if ( ! isset( $_parent_pages['documentation'] ) ) {
add_submenu_page( 'wpsyncsheets_lite', 'Documentation', '<div class="wpsslc-support">Documentation</div>', 'manage_options', 'documentation', array( $this, 'wpsslc_handle_external_redirects' ), 20 );
}
$this->remove_duplicate_submenu_page();
}
/**
* Documentation and Support Page Link.
*
* Redirect the documentation and support page.
*
* @since 1.0.0
* @access public
*/
public function wpsslc_handle_external_redirects() {
// phpcs:ignore
if ( empty( $_GET['page'] ) ) {
return;
}
// phpcs:ignore
if ( 'documentation' === $_GET['page'] ) {
// phpcs:ignore
wp_redirect( WPSSLC_DOC_MENU_URL );
die;
}
}
/**
* Remove duplicate submenu
* Submenu page hack: Remove the duplicate WPSyncSheets Plugin link on subpages
*/
public function remove_duplicate_submenu_page() {
remove_submenu_page( 'wpsyncsheets_lite', 'wpsyncsheets_lite' );
}
/**
* Enqueue css and js files
*/
public static function wpsslc_load_custom_wp_admin_style() {
// @codingStandardsIgnoreStart.
if ( is_admin() && ( isset( $_GET['page'] ) && ( ( 'wpcf7' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) || ( 'wpsyncsheets-contact-form-7' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) || ( 'wpcf7-new' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) ) ) ) {
// @codingStandardsIgnoreEnd.
wp_enqueue_script( 'wpsslc-admin-setting', WPSSLC_URL . 'assets/js/wpsslc-admin-setting.js', WPSSLC_VERSION, true, false );
wp_localize_script( 'wpsslc-admin-setting', 'ajax_login_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_style( 'wpsslc-admin-setting', WPSSLC_URL . 'assets/css/wpsslc-admin-setting.css', WPSSLC_VERSION, true );
}
}
/**
* Enqueue css and js files
*/
public function wpsslc_selectively_enqueue_admin_script() {
wp_enqueue_script( 'wpsslc-general-script', WPSSLC_URL . 'assets/js/wpsslc-general.js', WPSSLC_VERSION, true, false );
}
/**
* Show row meta on the plugin screen.
*
* @param mixed $wpsslc_links Plugin Row Meta.
* @param mixed $wpsslc_file Plugin Base file.
* @return array
*/
public static function wpsslc_plugin_row_meta( $wpsslc_links, $wpsslc_file ) {
if ( 'contactsheets-lite/wpsyncsheets-lite-contact-form-7.php' === (string) $wpsslc_file ) {
$wpsslc_row_meta = array(
'docs' => '<a href="' . esc_url( WPSSLC_DOCS_LINK ) . '" title="' . esc_attr( __( 'View Documentation', 'wpssc' ) ) . '" target="_blank">' . __( 'View Documentation', 'wpssc' ) . '</a>',
);
return array_merge( $wpsslc_links, $wpsslc_row_meta );
}
return (array) $wpsslc_links;
}
/**
* Pugin settings page
*/
public static function wpsslc_plugin_page() {
$wpsslc_error = '';
// Google API Settings Tab.
if ( isset( $_POST['submit'] ) ) {
if ( isset( $_POST['client_token'] ) ) {
$wpsslc_clienttoken = sanitize_text_field( wp_unslash( $_POST['client_token'] ) );
} else {
$wpsslc_clienttoken = '';
}
if ( isset( $_POST['client_id'] ) && isset( $_POST['client_secret'] ) ) {
$wpsslc_google_settings = array( sanitize_text_field( wp_unslash( $_POST['client_id'] ) ), sanitize_text_field( wp_unslash( $_POST['client_secret'] ) ), $wpsslc_clienttoken );
} else {
$wpsslc_google_settings_value = self::$instance_api->wpsslc_option( 'wpssc_google_settings' );
$wpsslc_google_settings = array( $wpsslc_google_settings_value[0], $wpsslc_google_settings_value[1], $wpsslc_clienttoken );
}
self::$instance_api->wpsslc_update_option( 'wpssc_google_settings', $wpsslc_google_settings );
}
if ( isset( $_POST['revoke'] ) ) {
if ( ! isset( $_POST['wpsslc_api_settings'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wpsslc_api_settings'] ) ), 'save_api_settings' ) ) {
$wpsslc_error = '<strong class="err-msg">' . esc_html__( 'Error: Sorry, your nonce did not verify.', 'wpssc' ) . '</strong>';
} else {
$wpsslc_google_settings = self::$instance_api->wpsslc_option( 'wpssc_google_settings' );
$wpsslc_google_settings[2] = '';
self::$instance_api->wpsslc_update_option( 'wpssc_google_settings', $wpsslc_google_settings );
self::$instance_api->wpsslc_update_option( 'wpssc_google_accessToken', '' );
}
}
$wpsslc_google_settings_value = self::$instance_api->wpsslc_option( 'wpssc_google_settings' );
if ( isset( $wpsslc_google_settings_value[2] ) && ! empty( $wpsslc_google_settings_value[2] ) ) {
if ( ! self::$instance_api->getClient() ) {
$wpsslc_error = self::$instance_api->getClient( 1 );
if ( 'Invalid token format' === (string) $wpsslc_error || 'invalid_grant' === (string) $wpsslc_error ) {
$wpsslc_error = '<div class="error token_error"><p><strong class="err-msg">' . esc_html__( 'Error: Invalid Token - Revoke Token with below settings and try again.', 'wpssc' ) . '</strong></p></div>';
} else {
$wpsslc_error = '<div class="error token_error"><p><strong class="err-msg">Error: ' . $wpsslc_error . '</strong></p></div>';
}
}
}
?>
<!-- .wrap -->
<div class="wpsslc-container gs-form">
<div class="wpsslc-logo-section">
<img src="<?php echo esc_url( WPSSLC_URL . 'assets/images/logo.png' ); ?>">
<sup>V<?php echo esc_html( WPSSLC_VERSION ); ?></sup>
<div class="duc-btn2">
<a target="_blank" href="<?php echo esc_url( WPSSLC_PRO_VERSION_URL ); ?>"><?php echo esc_html( __( 'Pro Version', 'wpssc' ) ); ?></a>
</div>
<div class="duc-btn1">
<a target="_blank" href="<?php echo esc_html( self::instance()->submit_ticket ); ?>"><?php echo esc_html( __( 'Support', 'wpssc' ) ); ?></a>
</div>
<div class="duc-btn">
<a target="_blank" href="<?php echo esc_html( WPSSLC_DOCS_LINK ); ?>"><?php echo esc_html( __( 'Documentation', 'wpssc' ) ); ?></a>
</div>
</div>
<div class="tab">
<button class="tablinks googlesheet" onclick="wpsslctab(event, 'googlesheet')">
<span class="tab-icon"></span>
<?php echo esc_html__( 'Google API', 'wpssc' ); ?> <br><?php echo esc_html__( 'Settings', 'wpssc' ); ?></button>
<button class="tablinks pro-features" onclick="wpsslctab(event, 'pro-features')"> <span class="tab-icon"></span> <?php echo esc_html__( 'Pro Features', 'wpssc' ); ?></button>
</div>
<div class="card wpsslc-googlesheet-box tabcontent" id="googlesheet">
<h2 class="title"><?php echo esc_html( __( 'Google Sheets API Settings', 'wpssc' ) ); ?> </h2>
<p><?php echo esc_html__( 'Create new google APIs with Client ID and Client Secret keys to get an access for the google drive and google sheets. Please follow the documentation, login to your Gmail Account and start with', 'wpssc' ); ?> <a href="<?php echo esc_url( self::instance()->doc_sheet_setting ); ?>" target="_blank"><?php echo esc_html__( 'here', 'wpssc' ); ?>.</a></p>
<br class="clear">
<div class="inside">
<?php
if ( ! empty( $wpsslc_error ) ) {
$allowed_html = wp_kses_allowed_html( 'post' );
echo wp_kses( $wpsslc_error, $allowed_html );
}
?>
<form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wpsyncsheets-contact-form-7' ) ); ?>">
<?php wp_nonce_field( 'save_api_settings', 'wpsslc_api_settings' ); ?>
<div class="wpsslc-form-box">
<p>
<label><?php echo esc_html( __( 'Client Id', 'wpssc' ) ); ?></label>
<input type="text" name="client_id" id="client_id" value="<?php echo isset( $wpsslc_google_settings_value[0] ) ? esc_html( $wpsslc_google_settings_value[0] ) : ''; ?>" placeholder="<?php echo esc_html__( 'Enter Client Id', 'wpssc' ); ?>"
<?php
if ( ! empty( $wpsslc_google_settings_value[0] ) ) {
echo 'readonly';
}
?>
/>
</p>
<p>
<label><?php echo esc_html( __( 'Client Secret', 'wpssc' ) ); ?></label>
<input type="text" name="client_secret" id="client_secret" value="<?php echo isset( $wpsslc_google_settings_value[1] ) ? esc_attr( $wpsslc_google_settings_value[1] ) : ''; ?>" placeholder="<?php echo esc_html__( 'Enter Client Secret', 'wpssc' ); ?>"
<?php
if ( ! empty( $wpsslc_google_settings_value[1] ) ) {
echo 'readonly';
}
?>
/>
</p>
<?php
if ( ! empty( $wpsslc_google_settings_value[0] ) && ! empty( $wpsslc_google_settings_value[1] ) ) {
$token_value = $wpsslc_google_settings_value[2];
if ( empty( $token_value ) && ! isset( $_GET['code'] ) ) {
$auth_url = self::$instance_api->getClient();
?>
<p id="authbtn">
<label><?php echo esc_html( __( 'Client Token', 'wpssc' ) ); ?></label>
<a href="<?php echo esc_url( $auth_url ); ?>" id="authlink" class="button button-secondary" target="_blank"><?php echo esc_html__( 'Click here to generate an authentication token', 'wpssc' ); ?></a>
</p>
<?php
}
$wpsslc_code = '';
if ( isset( $_GET['code'] ) && ! empty( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ) ) {
$wpsslc_code = sanitize_text_field( wp_unslash( $_GET['code'] ) );
}
?>
<p id="authtext"
<?php
if ( ! empty( $token_value ) || ( isset( $_GET['code'] ) && ! empty( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ) ) ) {
?>
class="wpsslc-authtext"
<?php
}
?>
>
<label><?php echo esc_html( __( 'Client Token', 'wpssc' ) ); ?></label>
<input type="text" id="client_token" name="client_token" value="<?php echo $token_value ? esc_html( $token_value ) : esc_html( $wpsslc_code ); ?>" placeholder="<?php echo esc_html__( 'Please enter authentication code', 'wpssc' ); ?>"
<?php
if ( ! empty( $wpsslc_google_settings_value[2] ) ) {
echo 'readonly';
}
?>
/>
</p>
<?php
}
if ( ! empty( $token_value ) ) {
?>
<p>
<label></label>
<input type="submit" name="revoke" id="revoke" value = "<?php echo esc_attr__( 'Revoke Token', 'wpssc' ); ?>" class="button button-secondary"/>
</p>
<?php
}
?>
</div>
<div class="submit-box"> <input type="Submit" name="submit" value="<?php esc_html_e( 'Save', 'wpssc' ); ?>" class="button button-primary" />
<span class="loading-sign">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<?php
if ( ! empty( $token_value ) || ! empty( $wpsslc_google_settings_value[0] ) || ! empty( $wpsslc_google_settings_value[1] ) ) {
?>
<input type="submit" name="reset_settings" id="reset_settings" value = "<?php echo esc_attr__( 'Reset Settings', 'wpssc' ); ?>" class="button button-primary reset_settings"/>
<?php } ?>
</div>
<p id="gs-validation-message"></p>
<?php
$site_url = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '';
$site_url = str_replace( 'www.', '', $site_url );
?>
<table class="copy-url-table" cellpadding="0" cellspacing="0" width="100%" border="0px">
<tr>
<td><?php echo esc_html__( 'Authorized Domain : ', 'wpssc' ); ?></td>
<td><span id="authorized_domain"><?php echo esc_html( $site_url ); ?></span><span class="copy-icon wpsslc-button wpsslc-button-primary" id="a_domain" onclick="wpsslc_copy('authorized_domain','a_domain');">Copy</span></td>
</tr>
<tr>
<td width="22%"><?php echo esc_html__( 'Authorised redirect URIs : ', 'wpssc' ); ?></td>
<td><span id="authorized_uri"><?php echo esc_html( admin_url( 'admin.php?page=wpsyncsheets-contact-form-7' ) ); ?></span><span class="copy-icon wpsslc-button wpsslc-button-primary" onclick="wpsslc_copy('authorized_uri','a_uri');" id="a_uri">Copy</span></td>
</tr>
</table>
</form>
</div>
</div>
<div class="card wpsslc-googlesheet-box" id="pro-features">
<a target="_blank" href="<?php echo esc_url( WPSSLC_PRO_VERSION_URL ); ?>">
<img src="<?php echo esc_url( plugin_dir_url( __DIR__ ) . '/assets/images/pro-features.png' ); ?>" class="pro-features" />
</a>
</div>
</div>
<?php
}
}
new WPSSLC_Plugin_Settings();