1); update_option('affiliate-power-options', $options); } $sql = 'CREATE TABLE '.$wpdb->prefix.'ap_transaction ( ap_transactionID bigint(20) unsigned NOT NULL AUTO_INCREMENT, network varchar(32) NOT NULL, TransactionId_network varchar(128) NOT NULL, Date datetime NOT NULL, SubId int(10) unsigned NOT NULL, ProgramId int(10) unsigned NOT NULL, ProgramTitle varchar(1024) NOT NULL, Transaction char(1) NOT NULL, Price float unsigned NOT NULL, Commission float NOT NULL, Confirmed float NOT NULL, CheckDate datetime NOT NULL, TransactionStatus varchar(64) NOT NULL, PRIMARY KEY (ap_transactionID), UNIQUE KEY uniIdNetwork (TransactionId_network,network), KEY SubId (SubId), KEY TransactionStatus (TransactionStatus), KEY ProgramId (ProgramId), KEY network (network), KEY Date (Date) );'; dbDelta($sql); $sql = 'CREATE TABLE '.$wpdb->prefix.'ap_clickout ( ap_clickoutID bigint(20) unsigned NOT NULL AUTO_INCREMENT, ap_visitID bigint(20) unsigned NOT NULL, clickout_datetime datetime NOT NULL, postID bigint(20) signed NOT NULL, source_url varchar(512) NOT NULL, target_url varchar(512) NOT NULL, PRIMARY KEY (ap_clickoutID) )AUTO_INCREMENT=1000001;'; dbDelta($sql); //version pre 0.7.0? update homepage postIDs $version = get_option('affiliate-power-version', '0.0.0'); if (version_compare($version, '0.7.0', '<')) { $wpdb->query( $wpdb->prepare(' UPDATE '.$wpdb->prefix.'ap_clickout SET postID = -1 WHERE source_url = %s', home_url('/') ) ); } //meta options for infotext etc. $meta_options = get_option('affiliate-power-meta-options'); if (!$meta_options) $meta_options = array(); if (!isset($meta_options['installstamp']) || $meta_options['installstamp'] == '') $meta_options['installstamp'] = date('U'); $user = wp_get_current_user(); $first_name = ($user->user_firstname != '') ? $user->user_firstname : $user->user_login; //register infotexts $meta_options['infotext'] = sprintf( __('

New: Affiliate Power Newsletter

As a subscriber to the Affiliate Power Newsletter you get tips and news about Affiliate Marketing once a month.

Just check your data and click Subscribe.

You can always unsubscribe from the Newsletter and I will not give your Email to anyone else.

Hide this message

', 'affiliate-power'), $first_name, $user->user_email ); $meta_options['infotext30'] = sprintf( __('

Hey %s, do you like Affiliate Power?

You are using Affiliate Power for more than 30 days now.

If you like the plugin, a positive review on wordpress.org would be great.

You can also share the plugin in your favorite social networks.



Hide this message', 'affiliate-power'), $first_name ); $meta_options['infotext60'] = sprintf( __('

Affiliate Power Newsletter

You are using Affiliate Power for more than 60 days now. I am glad, that you like the plugin that much. How about a Newsletter to further increase your Affiliate income? As a subscriber to the Affiliate Power Newsletter you get tips and news about Affiliate Marketing once a month.

Just check your data and click Subscribe.

You can always unsubscribe from the Newsletter and I will not give your Email to anyone else.

Hide this message

', 'affiliate-power'), $first_name, $user->user_email ); $meta_options['infotext90'] = sprintf( __('

Your opinion about Affiliate Power

Hey %s, you are using Affiliate Power for 3 months now. What do you think about the plugin?






Hide this message

', 'affiliate-power'), $first_name, $first_name, $user->user_email ); $meta_options['infotext120'] = sprintf( __('

Earn money with Affiliate Power!

Hey %s, you are using Affiliate Power for more than 120 days now. I am glad, that you like the plugin that much.

Would you like to recommend the the plugin to others? With the Affiliate Program you earn awesome 30%% for each sale of the Premium version. Click the link below.

All Information about the Affiliate program



Hide this message', 'affiliate-power'), $first_name ); //show infotext only for updating users if ($version != '0.0.0') $meta_options['hide-infotext'] = 0; else $meta_options['hide-infotext'] = 1; update_option('affiliate-power-meta-options', $meta_options); //welcome message when first install or just upgraded to premium $premium = get_option('affiliate-power-premium', false); if ($version == '0.0.0' || $premium == false && AFFILIATE_POWER_PREMIUM == true) add_action( 'admin_notices', array('Affiliate_Power', 'activationMessage') ); } static public function activationMessage() { ob_start(); if (AFFILIATE_POWER_PREMIUM) { printf(__('
Affiliate Power

Welcome to Affiliate Power Premium!

Congratulations again to your decision to shed light on your affiliate income. The plugin will now automatically create the new statistics for all your new sales. IF you want to use the URL-Parameter Tracking, you should enter your parameters on the Settings Page.

', 'affiliate-power'), plugins_url('img/affiliate-power-36.png', __FILE__), admin_url('admin.php?page=affiliate-power-settings')); } else { printf(__('
Affiliate Power

Welcome to Affiliate Power Premium!

Whats next? First, you should enter your Affiliate network data on the Settings Page. Then, you can download your old sales and the plugin will create the first statistics. The article statistic can only be created for new sales. All other statistics also work for old sales.

', 'affiliate-power'), plugins_url('img/affiliate-power-36.png', __FILE__), admin_url('admin.php?page=affiliate-power-settings')); } echo ob_get_clean(); } static public function deactivation() { wp_clear_scheduled_hook('affiliate_power_daily_event'); } static public function uninstall() { global $wpdb; $sql = 'DROP TABLE '.$wpdb->prefix.'ap_transaction;'; $wpdb->query($sql); $sql = 'DROP TABLE '.$wpdb->prefix.'ap_clickout;'; $wpdb->query($sql); delete_option('affiliate-power-meta-options'); delete_option('affiliate-power-options'); delete_option('affiliate-power-version'); delete_option('affiliate-power-premium'); } static public function init() { //load language file $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain( 'affiliate-power', '', $plugin_dir . '/languages/' ); //create tables etc. if user updated the plugin $version = get_option('affiliate-power-version', '0.0.0'); $premium = get_option('affiliate-power-premium', false); if ($version != AFFILIATE_POWER_VERSION || $premium == false && AFFILIATE_POWER_PREMIUM == true) { self::activation(); update_option('affiliate-power-version', AFFILIATE_POWER_VERSION); update_option('affiliate-power-premium', AFFILIATE_POWER_PREMIUM); } //deactivate infotext if (isset($_GET['action']) && $_GET['action'] == 'affiliate-power-hide-infotext') { $meta_options = get_option('affiliate-power-meta-options'); $meta_options['hide-infotext'] = 1; update_option('affiliate-power-meta-options', $meta_options); } } static public function addJs() { wp_enqueue_script('affiliate-power', plugins_url('affiliate-power.js', __FILE__), array('jquery')); wp_localize_script( 'affiliate-power', 'affiliatePower', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } static public function url_to_postid( $url ) { $post_id = url_to_postid( $url ); if ($post_id == 0 && $url == home_url('/')) $post_id = -1; //-1 = Homepage if ( $post_id == 0 ) { // Try custom post types $cpts = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects', 'and' ); // Get path from URL $url_parts = parse_url($url); $path = trim($url_parts['path'], '/'); //path has to be without slashes at start and end // Test against each CPT's rewrite slug foreach ( $cpts as $cpt_name => $cpt ) { $cpt_slug = $cpt->rewrite['slug']; if ( strlen( $path ) > strlen( $cpt_slug ) && substr( $path, 0, strlen( $cpt_slug ) ) == $cpt_slug ) { $slug = substr( $path, strlen( $cpt_slug ) ); $query = new WP_Query( array( 'post_type' => $cpt_name, 'name' => $slug, 'posts_per_page' => 1 )); if ( is_object( $query->post ) ) { $post_id = $query->post->ID; break; } } } } return $post_id; } static public function clickoutAjax() { //ignore bots if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false) die; //sanitize $target_url = esc_url_raw($_POST['target_url']); $source_url = esc_url_raw($_POST['source_url']); //get source and target URLs $arr_target_url = parse_url($target_url); $arr_source_url = parse_url($source_url); $new_target_url = self::saveClickout($source_url, $target_url); echo '~'.$new_target_url; // the ~ just separates the url from any unexpected output (notices etc.) die; } static public function saveClickout($source_url, $target_url) { //is this an affiliate link? $network = false; $affiliate_strings = array( 'adcell' => array('adcell', 'string'), 'affili' => array('webmasterplan.com', 'string'), 'belboon' => array('belboon', 'string'), 'superclix' => array('superclix', 'string'), 'tradedoubler' => array('tradedoubler', 'string'), 'zanox' => array('zanox', 'string'), 'CJ' => array('/click-[0-9]+-[0-9]+/', 'regexp') ); foreach ($affiliate_strings as $affiliate_network => $affiliate_string) { if ( $affiliate_string[1] == 'string' && strpos($target_url, $affiliate_string[0]) !== false || $affiliate_string[1] == 'regexp' && preg_match($affiliate_string[0], $target_url) != 0 //!= 0 matches 0(=no hit) and false(=error) ) { $network = $affiliate_network; break; } } //no affiliate link, ignore if (!$network) { return $target_url; } //save clickout in db and use as subid global $wpdb; $post_id = self::url_to_postid($source_url); $wpdb->insert( $wpdb->prefix.'ap_clickout', array( 'ap_visitID' => 0, 'postID' => $post_id, 'clickout_datetime' => current_time('mysql'), 'source_url' => $source_url, 'target_url' => $target_url ), array ('%d', '%d', '%s', '%s', '%s') ); $subid = $wpdb->insert_id; switch ($network) { case 'adcell': if (strpos($target_url, 'bid=') !== false) $target_url = preg_replace('/bid=([0-9]+)\-([0-9]+)/', 'bid=${1}-${2}-'.$subid, $target_url); elseif (strpos($target_url, 'encodingId') !== false) $target_url = preg_replace('@encodingId/([0-9a-z]+)@', 'encodingId/${1}/subid/'.$subid, $target_url); else $target_url = preg_replace('@slotId/([0-9]+)@', 'slotId/${1}/subid/'.$subid, $target_url); break; case 'affili': if (strpos($target_url, '&diurl=') !== false) $target_url = str_replace('&diurl=', '&subid='.$subid.'&diurl=', $target_url); else $target_url .= '&subid='.$subid; break; case 'belboon': if (strpos($target_url, '/&deeplink=') !== false) $target_url = str_replace('/&deeplink=', '/subid='.$subid.'&deeplink=', $target_url); else $target_url .= '/subid='.$subid; break; case 'CJ': if (strpos($target_url, 'url=') !== false) $target_url = str_replace('url=', 'sid='.$subid.'&url=', $target_url); elseif (strpos($target_url, "?") !== false) $target_url .= '&sid='.$subid; else $target_url .= '?sid='.$subid; break; case 'superclix': if (strpos($target_url, '&page=') !== false) $target_url = str_replace('&page=', '&subid='.$subid.'&page=', $target_url); else $target_url .= '&subid='.$subid; break; case 'tradedoubler': if (strpos($target_url, '&url=') !== false) $target_url = str_replace('&url=', '&epi='.$subid.'&url=', $target_url); elseif (strpos($target_url, 'p=') !== false) $target_url .= '&epi='.$subid; elseif (strpos($target_url, 'url(') !== false) $target_url = str_replace('url(', 'epi('.$subid.')url(', $target_url); else $target_url .= 'epi('.$subid.')'; break; case 'zanox': $target_url .= '&zpar4=[['.$subid.']]'; break; } return $target_url; } } ?>