text_domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); if ( class_exists( 'WC_Integration' ) ) { include_once 'includes/class-wc-afs-analytics.php'; add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) ); } /* if (class_exists( 'WC_AFS_Analytics' ) ) { } */ } function admin_menu() { add_submenu_page('options-general.php', __('AFS Analytics Plugin',$this->text_domain), __('AFS Analytics Settings',$this->text_domain), 'manage_options', __FILE__, array($this, 'plugin_menu')); add_menu_page('AFS Analytics Dashboad', 'AFS Analytics', 'manage_options', "afsanalytics", array($this, 'redirect_afs'), 'dashicons-chart-bar', '2.68'); add_submenu_page( 'afsanalytics', __('Dashboard',$this->text_domain), __('Dashboard',$this->text_domain), 'manage_options','afsanalyticsredirect_afs',array($this, 'redirect_afs')); add_submenu_page( 'afsanalytics', __('Right now',$this->text_domain), __('Right now',$this->text_domain), 'manage_options','afsanalytics_rightnow',array($this, 'afs_rightnow')); add_submenu_page( 'afsanalytics', __('Last Visitors',$this->text_domain), __('Last Visitors',$this->text_domain), 'manage_options','afsanalytics_lastvisitors',array($this, 'afs_lastvisitors')); add_submenu_page( 'afsanalytics', __('Heatmaps',$this->text_domain), __('Heatmaps',$this->text_domain), 'manage_options','afsanalytics_heatmaps',array($this, 'afs_heatmaps')); add_submenu_page( 'afsanalytics', __('Keyword position checker',$this->text_domain), __('Keyword position checker',$this->text_domain), 'manage_options','afsanalytics_keywordchecker',array($this, 'afs_keywordchecker')); add_submenu_page( 'afsanalytics', __('PDF Reports',$this->text_domain), __('PDF Reports',$this->text_domain), 'manage_options','afsanalytics_pdf',array($this, 'afs_pdf')); add_submenu_page( 'afsanalytics', __('Manage access keys',$this->text_domain), __('Manage access keys',$this->text_domain), 'manage_options','afsanalytics_keys',array($this, 'afs_keys')); add_submenu_page( 'afsanalytics', __('Your account',$this->text_domain), __('Your account',$this->text_domain), 'manage_options','afsanalytics_profile',array($this, 'afs_profile')); add_submenu_page( 'afsanalytics', __('Manage Website(s)',$this->text_domain), __('Manage Website(s)',$this->text_domain), 'manage_options','afsanalytics_options',array($this, 'afs_options')); add_submenu_page( 'afsanalytics', __('Forgotten password',$this->text_domain), __('Forgotten password',$this->text_domain), 'manage_options','afsanalytics_password',array($this, 'afs_password')); add_submenu_page( 'afsanalytics', __('Upgrade to Premium',$this->text_domain), __('Upgrade to Premium',$this->text_domain), 'manage_options','afsanalytics_upgrade',array($this, 'afs_upgrade')); add_submenu_page( 'afsanalytics', __('Online Help',$this->text_domain), __('Online Help',$this->text_domain), 'manage_options','afsanalytics_help',array($this, 'afs_help')); add_submenu_page( 'afsanalytics', __('Contact Us',$this->text_domain), __('Contact Us',$this->text_domain), 'manage_options','afsanalytics_contact',array($this, 'afs_contact')); add_submenu_page( 'afsanalytics', __('Plugin settings',$this->text_domain), __('Plugin settings',$this->text_domain), 'manage_options','afsanalytics_settings',array($this, 'plugin_menu')); } function get_admin_scripts() { //wp_deregister_script('jquery'); //wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true); if ( is_admin()) { wp_register_script( 'afsanalytics_jquery', plugins_url('/js/afsanalytics.js', __FILE__), array( 'jquery' ),NULL,true); wp_register_style( 'afsanalytics_css', plugins_url('/css/afsanalytics.css', __FILE__), false, '1.0.0', false); wp_enqueue_style('afsanalytics_css'); wp_enqueue_script('afsanalytics_jquery'); } } function wp_loggin() { $code=""; if ( is_user_logged_in() ) { if (!isset($_COOKIE["afslogged"])) { $code .="aa('set','visitor.logged','1');\n"; $code.="var d = new Date();\n"; $code.="d.setTime(d.getTime() +(3600*1000));\n"; $code.="var expires = 'expires='+ d.toUTCString();\n"; $code.="document.cookie='afslogged=1;'+expires+';path=/';\n"; } } return($code); } function wp_setuser() { $code="var vdata=new Object();\n"; if ( is_user_logged_in() ) { if (!isset($_COOKIE["afssetuser"])) { $current_user=wp_get_current_user(); $code .="vdata.job='update';\n"; $code .="vdata.wpid=".$current_user->ID.";\n"; $roles = $current_user->roles; $role = array_shift( $roles ); if (!empty($role)) $code .="vdata.role='$role';\n"; if (!empty($current_user->user_login)) $code .="vdata.username='".$current_user->user_login."';\n"; if (!empty($current_user->user_email)) $code .="vdata.email='".$current_user->user_email."';\n"; if (!empty($current_user->user_firstname)) $code .="vdata.firstname='".$current_user->user_firstname."';\n"; if (!empty($current_user->user_lastname))$code .="vdata.lastname='".$current_user->user_lastname."';\n"; if (!empty($current_user->display_name)) $code .="vdata.displayedname='".$current_user->display_name."';\n"; $code.="var ol= Object.keys(vdata).length;\n"; //$code.="console.log('vdata->',ol);\n"; $code.="if (ol>2){\n"; $code .="aa('set','visitor',vdata);\n"; $code .="aa('send','visitor');\n"; $code.="var d = new Date();\n"; $code.="d.setTime(d.getTime() +((3600*12)*1000));\n"; $code.="var expires = 'expires='+ d.toUTCString();\n"; $code.="document.cookie = 'afssetuser=1;'+expires+';path=/';\n"; $code.="}\n"; } } return($code); } function admin_tracking() { $this->get_admin_scripts(); $admin_pages_tracking= get_option("afs_admin_pages_tracking"); if ( $admin_pages_tracking==1) $this->wp_head(); } function wp_head() { //echo stripcslashes(get_option('afs_code')); //print "\n"; //$instance= WC_AFS_Analytics::get_instance(); //$instance->hello(); $afs_account = stripcslashes(get_option('afs_account')); $afs_server = ""; if ($afs_account > 99999) $afs_server = '1'; if ($afs_account > 199999) $afs_server = '2'; if ($afs_account > 299999) $afs_server = '3'; if ($afs_account > 399999) $afs_server = '4'; if ($afs_account > 499999) $afs_server = '5'; if ($afs_account > 599999) $afs_server = '6'; if ($afs_account > 699999) $afs_server = '7'; if ($afs_account > 799999) $afs_server = '8'; if ($afs_account > 899999) $afs_server = '9'; if ($afs_account > 999999) $afs_server = '10'; global $post; $postID = get_the_ID(); $trackerflag=0; if (!isset($trackername)) { $flagid=0; if (is_home()) { $trackername = get_bloginfo('name'); $trackerflag=1; } else { if (is_attachment ($postID)==false && is_page ($postID)==false && is_single ($postID)==false) { $trackerflag=0; } else { if (isset($post->ID)) { $postID = $post->ID; $trackername = get_post_meta($postID, "afstrackername", true); if (empty($trackername)) $trackername = $post->post_title;} $trackerflag=1; } } } if (empty($trackername)) { if (is_home()) $trackername="Home"; else $trackerflag=0; } if ( $trackerflag==1) { $trackername = stripslashes($trackername); if (strpos($trackername, '|') !== FALSE) $trackername = strstr($trackername, '|'); $trackername = addslashes($trackername); $trackername = trim($trackername); } //if (is_home()) $trackername="Home"; $autotrack_all= intval(get_option('afs_autotrack_all')); $autotrack_outbound= intval(get_option('afs_autotrack_outbound')); $autotrack_inside= intval(get_option('afs_autotrack_inside')); $autotrack_download= intval(get_option('afs_autotrack_download')); $autotrack_video= intval(get_option('afs_autotrack_video')); $autotrack_iframe= intval(get_option('afs_autotrack_iframe')); $user_logged_tracking= intval(get_option('afs_user_logged_tracking')); $ip_setting= intval(get_option('afs_ip_setting')); $cookie_setting= intval(get_option('afs_cookie_setting')); $localization_setting= intval(get_option('afs_localization_setting')); $user_consent=intval(get_option('afs_user_consent')); $cookie_setting= intval(get_option('afs_cookie_setting')); $afs_code ="\n"; $afs_code .="\n"; $afs_code .="\n"; print $afs_code; //$this->WC_AFS->hello(); } function account_ok($account) { if (empty($account) || intval($account)==0) { print "
"; print "

"; _e('You have to define the plugin settings!',$this->text_domain); print "

"; print "
"; print "\n\n"; return(-1); } return(0); } function build_redirectionpage( $text, $url) { $account = get_option('afs_account'); if ($this->account_ok($account)==-1) return; $accesskey= get_option('afs_accesskey'); $faccess=0; print "
"; print "

"; _e('Please be patient, AFS Analytics is loading ...',$this->text_domain); print "

"; print "
"; print "

"; if (empty($accesskey)==true || $accesskey=="none" || $accesskey=="NULL" || $accesskey=="null" || $accesskey=="NONE") { print "$text"; } else { print "$text"; $faccess=1; } print "

"; print "\n\n"; } function redirect_afs() { $this->build_redirectionpage("AFS Analytics dashboard","dashboard.php"); } function afs_rightnow() { $this->build_redirectionpage("Right Now","rightnow.php"); } function afs_lastvisitors() { $this->build_redirectionpage("Last Visitors","lastvisitors.php"); } function afs_heatmaps() { $this->build_redirectionpage("Heatmaps","heatmaps.php"); } function afs_keywordchecker() { $this->build_redirectionpage("keyword position checker","keywords_monitoring.php"); } function afs_pdf() { $this->build_redirectionpage("PDF Reports","edpdf.php"); } function afs_go($url) { print "
"; print "

"; _e('Please be patient, AFS Analytics is loading ...',$this->text_domain); print "

"; print "
"; print "\n\n"; } function afs_keys() { $this->afs_go("https://www.afsanalytics.com/accesskeys.php"); } function afs_profile() { $this->afs_go("https://www.afsanalytics.com/edprofile.php"); } function afs_options() { $this->afs_go("https://www.afsanalytics.com/edaccounts.php"); } function afs_password() { $this->afs_go("https://www.afsanalytics.com?lostpass=1"); } function afs_upgrade() { $this->afs_go("https://www.afsanalytics.com/pricing.php"); } function afs_help() { $this->afs_go("https://www.afsanalytics.com/articles/web-statistics-reports/"); } function afs_contact() { $this->afs_go("https://www.afsanalytics.com/contact.html"); } function add_trackerfield() { global $post; $postID = get_the_ID(); if ($postID!=false) { $trackername = stripslashes(get_post_meta($postID, "afstrackername", true)); print "
"; print ""; _e('AFS Analytics tracker name',$this->text_domain); //print ":  $postID"; print ": "; print "text_domain); print "\" value=\"$trackername\"/>"; print "
"; } } function save_trackerfield() { global $post; $postID=get_the_ID(); if ($postID!=false) { if (isset($_POST['afstrackername'])) $tracker = sanitize_text_field($_POST['afstrackername']); else if (isset($_POST['post_title'])) $tracker = sanitize_text_field($_POST['post_title']); if (empty($tracker)) $tracker = $post->post_title; if (empty($tracker) && is_front_page()==true) $tracker ="Home"; if (empty($tracker) && is_home()==true) $tracker ="Home"; if (!empty($tracker)) { if (!add_post_meta($postID, 'afstrackername', $tracker, true)) { update_post_meta($postID, 'afstrackername', esc_sql($tracker)); } } } } function plugin_menu() { $message = null; $message_updated = __("Data Saved!","afs"); $message_empty = __("Error: AFS website ID number must be a 8 digits! ","afs"); // update options if (!empty($_POST)) { $message = $message_updated; if (isset($_POST['afs_account'])) { $accountstr=sanitize_text_field($_POST['afs_account']); $accountstr=trim($accountstr); if (strcasecmp($accountstr,"NULL")==0) update_option('afs_account',""); else { $num=intval($accountstr); if ($num==0) $message = $message_empty; else { $accountstr=sprintf("%08d",$num); update_option('afs_account',$accountstr); $message = $message_updated; } } } if (isset($_POST['afs_accesskey'])) { $accesskey=sanitize_key($_POST['afs_accesskey']); $accesskey=trim($accesskey); $accesskey=strtoupper($accesskey); if (strcasecmp($accountstr,"NULL")==0) update_option('afs_accesskey',""); else update_option('afs_accesskey', $accesskey); } if (isset($_POST['admin_pages_tracking'])) update_option( 'afs_admin_pages_tracking',intval($_POST['admin_pages_tracking'])); if (isset($_POST['user_logged_tracking'])) update_option( 'afs_user_logged_tracking',intval($_POST['user_logged_tracking'])); if (isset($_POST['autotrack_all'])) update_option('afs_autotrack_all',intval($_POST['autotrack_all'])); if (isset($_POST['autotrack_outbound'])) update_option('afs_autotrack_outbound',intval($_POST['autotrack_outbound'])); if (isset($_POST['autotrack_inside'])) update_option('afs_autotrack_inside',intval($_POST['autotrack_inside'])); if (isset($_POST['autotrack_download'])) update_option('afs_autotrack_download',intval($_POST['autotrack_download'])); if (isset($_POST['autotrack_video'])) update_option('afs_autotrack_video',intval($_POST['autotrack_video'])); if (isset($_POST['autotrack_iframe'])) update_option('afs_autotrack_iframe',intval($_POST['autotrack_iframe'])); if (isset($_POST['cookie_setting'])) update_option( 'afs_cookie_setting',intval($_POST['cookie_setting'])); if (isset($_POST['ip_setting'])) update_option( 'afs_ip_setting',intval($_POST['ip_setting'])); if (isset($_POST['user_consent'])) update_option( 'afs_user_consent',intval($_POST['user_consent'])); if (isset($_POST['localization_setting'])) update_option( 'afs_localization_setting',intval($_POST['localization_setting'])); if (isset($_POST['woocommerce_usertracking'])) update_option( 'afs_woocommerce_usertracking',intval($_POST['woocommerce_usertracking'])); wp_cache_flush(); } ?>

\n"; ?>
text_domain);?>
text_domain); print " "; _e('Click here',$this->text_domain); print " "; _e('to get your website ID',$this->text_domain); print ".
"; _e('2 - Type your Website ID into the Website ID field',$this->text_domain); print ".
"; _e("3 - Click on 'Update' button","afs"); print ".
"; _e(' AFS Analytics code will be inserted into the header',$this->text_domain); print ".
"; ?>
AFS Analytics Settings
text_domain) ?>
  
Reset
Contact-us',$this->text_domain);?>   AFS Analytics',$this->text_domain);?>   DataSense',$this->text_domain);?>
\n"; print " jQuery(function() {\n"; print " switchTab($_POST[screen]);\n"; print " });\n"; print "\n"; } } } // plugin_menu } // Another_WordPress_Tracker_Plugin $_awtp_plugin = new AFS_Analytics_Plugin(); add_action('plugins_loaded', array($_awtp_plugin,'init')); add_option("afs_account", null, '', 'yes'); add_option("afs_accesskey", 'none','', 'yes'); add_option("afs_autotrack_all", '2','', 'yes'); add_option("afs_autotrack_outbound", '2','', 'yes'); add_option("afs_autotrack_inside", '2','', 'yes'); add_option("afs_autotrack_download", '2','', 'yes'); add_option("afs_autotrack_video", '2','', 'yes'); add_option("afs_autotrack_iframe", '2','', 'yes'); add_option("afs_admin_pages_tracking", '1', '', 'yes'); add_option("afs_user_logged_tracking", '1', '', 'yes'); add_option("afs_cookie_setting", '0', '', 'yes'); add_option("afs_ip_setting", '0', '', 'yes'); add_option("afs_user_consent", '0', '', 'yes'); add_option("afs_localization_setting", '0', '', 'yes'); if ( class_exists( 'WC_Integration' ) ) add_option("afs_woocommerce_usertracking", '1', '', 'yes'); add_action('wp_head', array($_awtp_plugin, 'wp_head')); add_action('admin_enqueue_scripts', array($_awtp_plugin, 'admin_tracking')); add_action('edit_form_after_title', array($_awtp_plugin, 'add_trackerfield')); add_action('save_post', array($_awtp_plugin, 'save_trackerfield')); add_action('admin_menu', array($_awtp_plugin, 'admin_menu')); endif; ?>