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('/') ) ); } //add and activate infotext $meta_options = get_option('affiliate-power-meta-options'); if (!$meta_options) $meta_options = array(); $meta_options['infotext'] = '

Neu: Geld verdienen mit Affiliate Power!

Mit dem Partnerprogramm von Affiliate Power bekommst du satte 30% Provision für jeden vermittelten Verkauf der Premium-Version.

Alle Infos zum Partnerprogramm

Nicht mehr anzeigen'; $meta_options['hide-infotext'] = 0; 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) { echo '
Affiliate Power

Herzlich Willkommen bei Affiliate Power Premium!

Nochmal Glückwunsch zu der Entscheidung den Blindflug im Affiliate-Marketing zu verlassen und Licht in deine Einnahmen zu bringen. Das Plugin wird von nun an automatisch die neuen Statistiken für alle neuen Sales erstellen. Wenn du das URL-Parameter Tracking verwenden möchtest, solltest du auf der Einstellungsseite die Parameter hinterlegen, die du benutzt.

'; } else { echo '
Affiliate Power

Herzlich Willkommen bei Affiliate Power!

Wie geht es weiter? Zunächst solltest du auf der Einstellungsseite die Daten der Affiliate-Netzwerke hinterlegen, die du benutzt. Dann kannst du deine bisherigen Sales herunterladen und die erste statistische Auswertung vornehmen. Die Auswertung deiner Artikel kann nur für neue Sales erstellt werden. Alle anderen Statistiken funktionieren auch für alte Sales.

'; } 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() { //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); 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; } } ?>