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('/') ) ); } } 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-options'); delete_option('affiliate-power-version'); delete_option('affiliate-power-premium'); } static public function init() { //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); } } 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 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']); //$ap_art = (int)$_POST['ap_art']; //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_nonce.'~'.$new_target_url; 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 = url_to_postid($source_url); if ($post_id == 0 && $source_url == home_url('/')) $post_id = -1; //-1 = Homepage $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': $target_url = preg_replace('/bid=([0-9]+)\-([0-9]+)/', 'bid=${1}-${2}-'.$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; } } ?>