initial commit

This commit is contained in:
2024-04-29 13:12:44 +05:45
commit 34887303c5
19300 changed files with 5268802 additions and 0 deletions

View File

@@ -0,0 +1,473 @@
<?php
/**
* Admin Class
*
* Handles the admin functionality
*
* @package Wpos Analytic
* @since 1.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wpos_Anylc_Admin {
function __construct() {
global $wpos_analytics_module;
// Plugin action links
if( ! empty( $wpos_analytics_module ) ) {
foreach ($wpos_analytics_module as $module_key => $module) {
// Filter to add Opt In / Out row
add_filter( 'plugin_action_links_' . $module_key, array($this, 'wpos_anylc_add_action_links'), 10, 4 );
}
}
// Action to remove admin menu
add_action( 'admin_menu', array($this, 'wpos_anylc_remove_admin_menu'), 999 );
// Action to add admin menu
add_action( 'admin_menu', array($this, 'wpos_anylc_register_admin_menu'), 15 );
// Action to redirect plugin / theme on activation
add_action( 'admin_init', array($this, 'wpos_anylc_admin_init_process') );
// Action to show optin notice
add_action( 'admin_notices', array($this, 'wpos_anylc_optin_notice') );
// Action to add Attachment Popup HTML
add_action( 'admin_footer', array($this,'wpos_anylc_optout_popup') );
// Action to perform analytic action
add_action( 'wp_loaded', array($this, 'wpos_anylc_action_process') );
}
/**
* Remove admin menus
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_remove_admin_menu() {
global $menu, $submenu, $wpos_analytics_module;
if( !empty( $wpos_analytics_module ) ) {
foreach ($wpos_analytics_module as $module_key => $module) {
$opt_in_data = wpos_anylc_get_option( $module['anylc_optin'] );
if( !empty( $module['menu'] ) && !isset( $opt_in_data['status'] ) ) {
remove_menu_page( $module['menu'] );
}
}
}
}
/**
* Add menu
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_register_admin_menu() {
global $menu, $submenu, $wpos_analytics_module;
if( !empty( $wpos_analytics_module ) ) {
// WP Menu data
$wpos_menu_data = wp_list_pluck( $menu, 2 );
$anylc_page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : null;
foreach ($wpos_analytics_module as $module_key => $module) {
$opt_in_data = wpos_anylc_get_option( $module['anylc_optin'] );
$optin_status = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : null;
// Offers Page
if( !empty( $module['offers'] ) && $anylc_page == $module['slug'].'-offers' ) {
add_submenu_page( $module['menu'], 'WPOS Offers', '<span style="color:#2ECC71">Premium Offers</span>', 'manage_options', $module['slug'].'-offers', array($this, 'wpos_anylc_offers_html') );
}
// If data is set
if( $optin_status == 1 ) {
continue;
}
// Taking some variables
$menu_args = array();
if( $optin_status === 0 || $optin_status === 2 ) {
// Register admin menu
if( $anylc_page == $module['slug'] ) {
add_submenu_page( $module['menu'], $module['name'].' '.'Opt In', $module['name'].' '.'Opt In', 'manage_options', $module['slug'], array($this, 'wpos_anylc_page_html') );
}
} else {
if( !empty( $wpos_menu_data ) ) {
$orig_menu_pos = array_search( $module['menu'], $wpos_menu_data );
if( $orig_menu_pos !== false ) {
$menu_args = array(
'name' => $menu[ $orig_menu_pos ][0],
'icon' => $menu[ $orig_menu_pos ][6],
'position' => $orig_menu_pos,
);
}
}
// Taking default name and icon
if( empty( $menu_args ) ) {
$menu_args = array(
'name' => $module['name'],
'icon' => false,
'position' => null,
);
}
// Register admin menu
add_menu_page( $menu_args['name'], $menu_args['name'], 'manage_options', $module['slug'], array($this, 'wpos_anylc_page_html'), $menu_args['icon'], $menu_args['position'] );
}
} // End of for each
}
}
/**
* Display Opt in form HTML
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_page_html() {
global $current_user, $wpos_analytics_product;
$anylc_product_name = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
// if no data is set then return
if( ! isset( $wpos_analytics_product[ $anylc_product_name ] ) ) {
return;
}
// Taking soem data
$optin_form_data = wpos_anylc_optin_data();
$analy_product = $wpos_analytics_product[ $anylc_product_name ];
$opt_in_data = wpos_anylc_get_option( $analy_product['anylc_optin'] );
$opt_in = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : null;
$user_name = !empty( $current_user->first_name ) ? $current_user->first_name : '';
$user_name = empty( $user_name ) ? $current_user->nickname : $user_name;
$product_name = $analy_product['name'];
$skip_url = add_query_arg( array( 'page' => $anylc_product_name, 'wpos_anylc_action' => 'skip'), admin_url('admin.php') );
$skip_url = wp_nonce_url( $skip_url, 'wpos_anylc_act' );
require_once WPOS_ANYLC_DIR .'/templates/analytic.php';
}
/**
* Display Offers HTML
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_offers_html() {
global $wpos_analytics_product;
$anylc_product_name = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
$anylc_product_name = str_replace( '-offers', '', $anylc_product_name );
// if no data is set then return
if( ! isset( $wpos_analytics_product[ $anylc_product_name ] ) ) {
return;
}
// Taking soem data
$analy_product = $wpos_analytics_product[ $anylc_product_name ];
$opt_in_data = wpos_anylc_get_option( $analy_product['anylc_optin'] );
$opt_in = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : null;
include_once( WPOS_ANYLC_DIR .'/templates/offers.php' );
}
/**
* Add Action links
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_add_action_links( $actions, $plugin_file, $plugin_data, $context ) {
global $wpos_analytics_module;
// Taking some data
$module_data = !empty( $wpos_analytics_module[ $plugin_file ] ) ? $wpos_analytics_module[ $plugin_file ] : '';
// If analytics module data is there
if( $module_data ) {
$opt_in_data = wpos_anylc_get_option( $module_data['anylc_optin'] );
$opt_in = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : -1;
// If user has opt in
if( $opt_in == 1 ) {
$new_links['wpos_anylc'] = '<a href="#" class="wpos-anylc-opt-out-link" data-id="'.$module_data['id'].'">'.__('Opt Out', 'wpos_analytic').'</a>';
} else {
$opt_in_link = wpos_anylc_optin_url( $module_data, $opt_in );
$new_links['wpos_anylc'] = '<a href="'.esc_url( $opt_in_link ).'" class="wpos-anylc-opt-in-link">'.__('Opt In', 'wpos_analytic').'</a>';
}
$actions = array_merge( $new_links, $actions );
}
return $actions;
}
/**
* Redirect plugin / theme on activation to its opt in menu
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_admin_init_process() {
if( isset( $_GET['message'] ) && 'wpos-anylc-dismiss-notice' == $_GET['message'] && ! empty( $_GET['anylc_id'] )
&& isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'wpos-anylc-dismiss-notice-nonce' )
) {
$anylc_id = sanitize_text_field( $_GET['anylc_id'] );
set_transient( 'wpos_anylc_optin_notice_'.$anylc_id, true, 172800 );
}
// Flush the redirect transient
if( isset( $_GET['anylc_nonce'] ) && wp_verify_nonce( $_GET['anylc_nonce'], 'wpos-anylc-redirect-nonce' ) ) {
update_option( 'wpos_anylc_redirect', '' );
}
// Check if any redirect is set after plugin activation
$redirect = get_option( 'wpos_anylc_redirect' );
if ( $redirect ) {
/**
* Little Tweak to avoid the infinite looping.
*/
parse_str( parse_url( $redirect, PHP_URL_QUERY ), $url_data );
if( ! isset( $url_data['anylc_nonce'] ) || ( isset( $url_data['anylc_nonce'] ) && ! wp_verify_nonce( $_GET['anylc_nonce'], 'wpos-anylc-redirect-nonce' ) ) ) {
$redirect = add_query_arg( array( 'anylc_nonce' => wp_create_nonce( 'wpos-anylc-redirect-nonce' ) ), $redirect );
}
// Redirect to page
wp_safe_redirect( $redirect );
exit;
}
}
/**
* Display Analytic Optin notice
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_optin_notice() {
global $current_screen, $wpos_analytics_module, $wpos_analytics_product;
// Taking some variables
$screen_id = isset( $current_screen->id ) ? $current_screen->id : '';
// Plugin action links
if( $screen_id == 'dashboard' && current_user_can('manage_options') && !empty( $wpos_analytics_module ) ) {
foreach ($wpos_analytics_module as $module_key => $module) {
$anylc_pdt_id = $module['id'];
$notice_transient = get_transient( 'wpos_anylc_optin_notice_'.$anylc_pdt_id );
if( $notice_transient == false ) {
$opt_in_data = wpos_anylc_get_option( $module['anylc_optin'] );
$opt_in = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : -1;
$notice_link = add_query_arg( array( 'message' => 'wpos-anylc-dismiss-notice', 'anylc_id' => $anylc_pdt_id, '_wpnonce' => wp_create_nonce( 'wpos-anylc-dismiss-notice-nonce' ) ), admin_url('index.php') );
// If user has opt in
if( $opt_in == -1 ) {
$anylc_pdt_name = $module['name'];
$anylc_optin_url = wpos_anylc_optin_url( $module, $opt_in );
echo '<div class="updated notice wpos-anylc-notice wpos-anylc-optin-notice">
<p><strong>'.wp_kses_post( $anylc_pdt_name ).'</strong> - We made a few tweaks to the plugin, <a href="'.esc_url( $anylc_optin_url ).'">Opt in to make it Better!</a></p>
<a href="'.esc_url( $notice_link ).'" class="notice-dismiss"></a>
</div>';
}
}
}
} // End of if
if( isset($_GET['message']) && $_GET['message'] == 'optout_success' ) {
echo '<div class="updated notice wpos-anylc-optin-notice is-dismissible">
<p><strong>Sorry to let you go. You are now opted out from the plugin.</strong></p>
</div>';
}
// Process Promotion Data
if( !empty($_GET['message']) && $_GET['message'] == 'wpos_anylc_promotion' && !empty($_GET['wpos_anylc_pdt']) && !empty($_GET['wpos_anylc_promo_pdt']) ) {
$promotion = 1;
$wpos_anylc_promo_pdt = sanitize_text_field( $_GET['wpos_anylc_promo_pdt'] );
$promotion_pdt = explode( ',', $wpos_anylc_promo_pdt );
$anylc_pdt = sanitize_text_field( $_GET['wpos_anylc_pdt'] );
$anylc_pdt_data = isset( $wpos_analytics_product[ $anylc_pdt ] ) ? $wpos_analytics_product[ $anylc_pdt ] : false;
if( !empty($promotion_pdt) ) {
foreach ($promotion_pdt as $pdt_key => $pdt) {
if( isset( $anylc_pdt_data['promotion'][$pdt]['file'] ) ) {
$promotion_pdt_data[] = '<a href="'.$anylc_pdt_data['promotion'][$pdt]['file'].'">'.$anylc_pdt_data['promotion'][$pdt]['name'].'</a>';
}
}
}
if( $promotion_pdt_data ) {
echo '<div class="updated notice wpos-anylc-optin-notice is-dismissible" style="display:block !important;">
<p><strong>Your Download has been started. In case if it is intrupted then download it from here. '.join(' | ', $promotion_pdt_data).'</strong></p>
</div>';
}
}
}
/**
* Analytic Optout Popup HTML
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_optout_popup() {
global $pagenow, $wpos_analytics_module;
if( $pagenow == 'plugins.php' && !empty( $wpos_analytics_module ) ) {
foreach ($wpos_analytics_module as $module_key => $module) {
$opt_in_data = wpos_anylc_get_option( $module['anylc_optin'] );
$opt_in = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : false;
// If user has opt in
if( $opt_in == 1 ) {
// Creating redirect URL
$plugin_status = isset( $_GET['plugin_status'] ) ? sanitize_text_field( $_GET['plugin_status'] ) : false;
$paged = isset( $_GET['paged'] ) ? sanitize_text_field( $_GET['paged'] ) : false;
$s = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : false;
$redirect_url = add_query_arg( array( 'plugin_status' => $plugin_status, 'paged' => $paged, 's' => $s, 'wpos_anylc_pdt' => $module['slug'] ), admin_url( 'plugins.php' ) );
$redirect_url = wp_nonce_url( $redirect_url, 'wpos_anylc_act'.'|'.$module['slug'] );
// Form Data
$optin_form_data = wpos_anylc_optin_data( $module['slug'], $redirect_url );
include( WPOS_ANYLC_DIR .'/templates/optout-popup.php' );
}
}
}
}
/**
* Analytic Action Process
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_action_process() {
// Skip if not admin area
if ( !is_admin() ) {
return false;
}
if( !empty($_GET['wpos_anylc_action']) && isset($_GET['_wpnonce']) ) {
global $wpos_analytics_product;
$anylc_pdt = !empty( $_GET['wpos_anylc_pdt'] ) ? sanitize_text_field( $_GET['wpos_anylc_pdt'] ) : '';
$anylc_pdt = ( ! $anylc_pdt && !empty( $_GET['page'] ) ) ? sanitize_text_field( $_GET['page'] ) : $anylc_pdt;
$anylc_pdt_data = isset( $wpos_analytics_product[ $anylc_pdt ] ) ? $wpos_analytics_product[ $anylc_pdt ] : false;
// If valid product data found
if( $anylc_pdt_data ) {
// Process Optin
if( $_GET['wpos_anylc_action'] == 'optin' ) {
// Verify nonce
if( ! wp_verify_nonce( $_GET['_wpnonce'], 'wpos_anylc_act' ) ) {
wp_die( __('Sorry, Something happened wrong.', 'wpos_analytic'), 'wpos_anylc_err', array('back_link' => true) );
}
$opt_in_data = wpos_anylc_update_option( $anylc_pdt_data['anylc_optin'], array('status' => 1) );
// Redirect to original menu
$redirect_url = wpos_anylc_pdt_url( $anylc_pdt_data, 'offer-promotion' );
if( $redirect_url ) {
wp_redirect( $redirect_url );
exit;
}
}
// Process Skip
if( $_GET['wpos_anylc_action'] == 'skip' ) {
// Verify nonce
if( ! wp_verify_nonce( $_GET['_wpnonce'], 'wpos_anylc_act' ) ) {
wp_die( __('Sorry, Something happened wrong.', 'wpos_analytic'), 'wpos_anylc_err', array('back_link' => true) );
}
$opt_in_data = wpos_anylc_update_option( $anylc_pdt_data['anylc_optin'], array('status' => 2) );
// Redirect to original menu
$redirect_url = wpos_anylc_pdt_url( $anylc_pdt_data, 'offer' );
if( $redirect_url ) {
wp_redirect( $redirect_url );
exit;
}
}
// Process Opt Out
if( $_GET['wpos_anylc_action'] == 'optout' ) {
// Verify nonce
if( ! wp_verify_nonce( $_GET['_wpnonce'], 'wpos_anylc_act'.'|'.$_GET['wpos_anylc_pdt'] ) ) {
wp_die( __('Sorry, Something happened wrong.', 'wpos_analytic'), 'wpos_anylc_err', array('back_link' => true) );
}
$opt_in_data = wpos_anylc_update_option( $anylc_pdt_data['anylc_optin'], array('status' => 0) );
// Redirect with success message
$redirect_url = add_query_arg( array( 'message' => 'optout_success', 'wpos_anylc_action' => false, 'wpos_anylc_pdt' => false, '_wpnonce' => false ) );
if( $redirect_url ) {
wp_redirect( $redirect_url );
exit;
}
}
}
} // End of main if
}
}
$wpos_anylc_admin = new Wpos_Anylc_Admin();

View File

@@ -0,0 +1,65 @@
<?php
/**
* Script Class
*
* Handles the script and style
*
* @package Wpos Analytic
* @since 1.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wpos_Anylc_Script {
function __construct() {
// Action to add style backend
add_action( 'admin_enqueue_scripts', array($this, 'wpos_anylc_admin_script_style') );
}
/**
* Enqueue script for backend
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_admin_script_style( $hook ) {
// Process Promotion Data
if( !empty($_GET['message']) && $_GET['message'] == 'wpos_anylc_promotion' && !empty($_GET['wpos_anylc_pdt']) && !empty($_GET['wpos_anylc_promo_pdt']) ) {
global $wpos_analytics_product;
$promotion = 1;
$wpos_anylc_promo_pdt = sanitize_text_field( $_GET['wpos_anylc_promo_pdt'] );
$promotion_pdt = explode( ',', $wpos_anylc_promo_pdt );
$anylc_pdt = sanitize_text_field( $_GET['wpos_anylc_pdt'] );
$anylc_pdt_data = isset( $wpos_analytics_product[ $anylc_pdt ] ) ? $wpos_analytics_product[ $anylc_pdt ] : false;
if( !empty($promotion_pdt) ) {
foreach ($promotion_pdt as $pdt_key => $pdt) {
if( isset( $anylc_pdt_data['promotion'][$pdt]['file'] ) ) {
$promotion_pdt_data[] = $anylc_pdt_data['promotion'][$pdt]['file'];
}
}
}
}
// Registring admin Style
wp_register_style( 'wpos-anylc-admin-style', WPOS_ANYLC_URL.'assets/css/wpos-anylc-admin.css', null, WPOS_ANYLC_VERSION );
wp_enqueue_style( 'wpos-anylc-admin-style' );
// Registring admin script
wp_register_script( 'wpos-anylc-admin-script', WPOS_ANYLC_URL.'assets/js/wpos-anylc-admin.js', array('jquery'), WPOS_ANYLC_VERSION, true );
wp_localize_script( 'wpos-anylc-admin-script', 'WposAnylc', array(
'promotion' => isset($promotion) ? 1 : 0,
'promotion_pdt' => isset( $promotion_pdt_data ) ? $promotion_pdt_data : 0,
));
wp_enqueue_script( 'wpos-anylc-admin-script' );
}
}
$wpos_anylc_script = new Wpos_Anylc_Script();

View File

@@ -0,0 +1,331 @@
<?php
/**
* Common Functions
*
* @package Wpos Analytic
* @since 1.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Retrieve the translation of $text.
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_text( $text, $echo = false ) {
if( $echo ) {
_e( $text, '' );
} else {
__( $text, '' );
}
}
/**
* Clean variables using sanitize_text_field. Arrays are cleaned recursively.
* Non-scalar values are ignored.
*
* @since 1.0
*/
function wpos_anylc_clean( $var ) {
if ( is_array( $var ) ) {
return array_map( 'wpos_anylc_clean', $var );
} else {
$data = is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
return wp_unslash($data);
}
}
/**
* Check Multidimention Array
*
* @package Wpos Analytic
* @since 1.0
*/
function wpos_anylc_is_multi_arr( $arr ) {
rsort( $arr );
return isset( $arr[0] ) && is_array( $arr[0] );
}
/**
* Get site unique id
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_site_uid() {
$site_uid = get_option( 'wpos_anylc_site_uid' );
// Generate new site id if not exist
if( empty( $site_uid ) ) {
$site_url = untrailingslashit( get_bloginfo('wpurl') );
$site_uid = md5( $site_url . SECURE_AUTH_KEY );
update_option( 'wpos_anylc_site_uid', $site_uid );
}
return $site_uid;
}
/**
* Get Optin Data
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_optin_data( $anylc_pdt = false, $return_url = '' ) {
// Skip if not admin area
if ( !is_admin() ) {
return false;
}
global $current_user, $wpos_analytics_product;
// Takind some data
$theme_data = wp_get_theme();
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : false;
// If product is not passed
if( ! $anylc_pdt ) {
$anylc_pdt = !empty( $_GET['wpos_anylc_pdt'] ) ? sanitize_text_field( $_GET['wpos_anylc_pdt'] ) : '';
$anylc_pdt = ( ! $anylc_pdt && !empty( $_GET['page'] ) ) ? sanitize_text_field( $_GET['page'] ) : $anylc_pdt;
}
// If a valid product is there
if( $anylc_pdt && !empty( $wpos_analytics_product[ $anylc_pdt ] ) ) {
$analy_product = $wpos_analytics_product[ $anylc_pdt ];
if( empty( $return_url ) ) {
$return_url = add_query_arg( array( 'page' => $page ), admin_url('admin.php') );
$return_url = wp_nonce_url( $return_url, 'wpos_anylc_act' );
}
// Getting data according to type
if( $analy_product['type'] == 'theme' ) {
$product_name = $theme_data->get( 'Name' );
$product_version = $theme_data->get( 'Version' );
} else {
if( !function_exists('get_plugin_data') ) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
$plugin_data = get_plugin_data( trailingslashit(WP_PLUGIN_DIR) . $analy_product['file'] );
$product_name = !empty( $plugin_data['Name'] ) ? $plugin_data['Name'] : '';
$product_version = !empty( $plugin_data['Version'] ) ? $plugin_data['Version'] : '';
}
}
$optin_data = array(
'site_url' => untrailingslashit( get_bloginfo('wpurl') ),
'site_name' => get_bloginfo( 'name' ),
'wp_version' => get_bloginfo( 'version' ),
'language' => get_bloginfo( 'language' ),
'is_rtl' => is_rtl() ? 1 : 0,
'php_version' => phpversion(),
'sdk_version' => WPOS_ANYLC_VERSION,
'product_name' => isset( $product_name ) ? $product_name : '',
'product_version' => isset( $product_version ) ? $product_version : '',
'product_id' => !empty( $analy_product['id'] ) ? $analy_product['id'] : 0,
'product_type' => !empty( $analy_product['type'] ) ? $analy_product['type'] : '',
'theme_name' => $theme_data->get( 'Name' ),
'theme_uri' => $theme_data->get( 'ThemeURI' ),
'theme_author' => $theme_data->get( 'Author' ),
'theme_author_uri' => $theme_data->get( 'AuthorURI' ),
'theme_version' => $theme_data->get( 'Version' ),
'user_firstname' => $current_user->user_firstname,
'user_lastname' => $current_user->user_lastname,
'user_nickname' => $current_user->user_nicename,
'user_email' => get_bloginfo( 'admin_email' ),
'ip_address' => wpos_anylc_get_ip_address(),
'site_uid' => wpos_anylc_site_uid(),
'return_url' => $return_url,
);
return $optin_data;
}
/**
* Get IP Address
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_get_ip_address() {
if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { // WPCS: input var ok, CSRF ok.
return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); // WPCS: input var ok, CSRF ok.
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // WPCS: input var ok, CSRF ok.
// Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
// Make sure we always only send through the first IP in the list which should always be the client IP.
return (string) rest_is_ip_address( trim( current( preg_split( '/[,:]/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); // WPCS: input var ok, CSRF ok.
} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // @codingStandardsIgnoreLine
return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // @codingStandardsIgnoreLine
}
return '127.0.0.1';
}
/**
* Get Product Optin Data
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_get_option( $key = '' ) {
$opt_in_data = array();
if( !empty( $key ) ) {
$opt_in_data = get_option( $key );
$opt_in_data = ( !empty($opt_in_data) && is_array($opt_in_data) ) ? $opt_in_data : array();
}
return $opt_in_data;
}
/**
* Get Product Optin Data
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_update_option( $key = '', $data = array() ) {
$opt_in_data = array();
if( !empty( $key ) ) {
$opt_in_data = wpos_anylc_get_option( $key );
if( is_array($data) ) {
$opt_in_data = array_merge( $opt_in_data, $data );
update_option( $key, $opt_in_data );
}
}
return $opt_in_data;
}
/**
* Get Analytic Product Optin URL
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_optin_url( $module_data = '', $optin_status = null ) {
$optin_url = false;
// Optin Status
if( ! isset( $optin_status ) ) {
$opt_in_data = get_option( $module_data['anylc_optin'] );
$optin_status = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : null;
}
if( !empty( $module_data['menu'] ) && !empty( $module_data['slug'] ) ) {
$url_data = parse_url( $module_data['menu'], PHP_URL_QUERY );
$query_data = !empty( $url_data ) ? parse_str( $url_data, $query_arr ) : array();
if( !empty( $query_arr['post_type'] ) && $optin_status >= 0 ) { // If Optin is done and post type menu
$optin_url = add_query_arg( array( 'post_type' => $query_arr['post_type'], 'page' => $module_data['slug'], 'anylc_optin_menu' => true ), admin_url('edit.php') );
} else if( empty( $query_arr['post_type'] ) && $optin_status >= 0 ) { // If Optin is done and simple admin menu
$optin_url = add_query_arg( array( 'page' => $module_data['slug'], 'anylc_optin_menu' => true ), admin_url('admin.php') );
} else {
$optin_url = add_query_arg( array( 'page' => $module_data['slug'] ), admin_url('admin.php') );
}
}
return $optin_url;
}
/**
* Get Analytic Product Opt Out URL
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_optout_url( $module_data = '', $optin_status = null, $redirect_url = false ) {
$opt_out_link = false;
// Optin Status
if( !isset( $optin_status ) ) {
$opt_in_data = get_option( $module_data['anylc_optin'] );
$optin_status = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : null;
}
if( $optin_status == 1 ) {
if( ! $redirect_url ) {
$plugin_status = isset( $_GET['plugin_status'] ) ? sanitize_text_field( $_GET['plugin_status'] ) : false;
$paged = isset( $_GET['paged'] ) ? sanitize_text_field( $_GET['paged'] ) : false;
$s = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : false;
$redirect_url = add_query_arg( array( 'plugin_status' => $plugin_status, 'paged' => $paged, 's' => $s ), admin_url( 'plugins.php' ) );
}
$opt_out_link = add_query_arg( array( 'wpos_anylc_action' => 'optout', 'wpos_anylc_pdt' => $module_data['slug'], 'redirect' => $redirect_url ), $redirect_url );
$opt_out_link = wp_nonce_url( $opt_out_link, 'wpos_anylc_act'.'|'.$module_data['slug'] );
}
return $opt_out_link;
}
/**
* Get Analytic Product URL
*
* @package Wpos Analytic
* @since 1.0.0
*/
function wpos_anylc_pdt_url( $module_data = '', $type = false ) {
$redirect_url = false;
$redirect_page = ! empty( $module_data['redirect_page'] ) ? $module_data['redirect_page'] : $module_data['menu'];
if( ! empty( $redirect_page ) ) {
$pos = strpos( $redirect_page, '?post_type' );
$redirect_url = ( $pos !== false ) ? admin_url( $redirect_page ) : add_query_arg( array( 'page' => $redirect_page ), admin_url('admin.php') );
switch ( $type ) {
case 'promotion':
$promotion = !empty( $_GET['promotion'] ) ? wpos_anylc_clean( $_GET['promotion'] ) : '';
if( !empty( $promotion ) ) {
$promotion = is_array( $promotion ) ? implode( ',', $promotion ) : $promotion;
$redirect_url = add_query_arg( array( 'message' => 'wpos_anylc_promotion', 'wpos_anylc_pdt' => $module_data['slug'], 'wpos_anylc_promo_pdt' => $promotion ), $redirect_url );
}
break;
case 'offer':
if( !empty( $module_data['offers'] ) ) {
$redirect_url = add_query_arg( array( 'page' => $module_data['slug'].'-offers' ), $redirect_url );
}
break;
case 'offer-promotion':
$promotion = !empty( $_GET['promotion'] ) ? wpos_anylc_clean( $_GET['promotion'] ) : '';
if( !empty( $module_data['offers'] ) ) {
$redirect_url = add_query_arg( array( 'page' => $module_data['slug'].'-offers' ), $redirect_url );
}
if( !empty( $promotion ) ) {
$promotion = is_array( $promotion ) ? implode( ',', $promotion ) : $promotion;
$redirect_url = add_query_arg( array( 'message' => 'wpos_anylc_promotion', 'wpos_anylc_pdt' => $module_data['slug'], 'wpos_anylc_promo_pdt' => $promotion ), $redirect_url );
}
break;
}
}
return $redirect_url;
}