public static function record_click() { if (isset($_REQUEST[WPAM_PluginConfig::$RefKey]) && !empty($_REQUEST[WPAM_PluginConfig::$RefKey])) { //this is the old tracking code (deprecated). This will be removed once the new tracking system is functional. global $wpdb; $strRefKey = trim(strip_tags($_REQUEST[WPAM_PluginConfig::$RefKey])); $aff_id = ""; if (is_numeric($strRefKey)) { //wpam_refkey contains affiliate ID. If a record is found save it $query = "SELECT * FROM " . WPAM_AFFILIATES_TBL . " WHERE affiliateId = %d"; $affiliate = $wpdb->get_row($wpdb->prepare($query, $strRefKey)); if ($affiliate != null && $affiliate->status == "active") { $aff_id = $strRefKey; } } else { if (is_email($strRefKey)) { //wpam_refkey contains email. Find the ID associated with that email and save it $query = "SELECT * FROM " . WPAM_AFFILIATES_TBL . " WHERE email = %s"; $affiliate = $wpdb->get_row($wpdb->prepare($query, $strRefKey)); if ($affiliate != null && $affiliate->status == "active") { $aff_id = $affiliate->affiliateId; } } else { //TODO start - wpam_refkey contains long tracking key. Find affiliate ID from it and save it. This block of code will just be here for backwards compatibilty $refKey = new WPAM_Tracking_TrackingKey(); $refKey->unpack($strRefKey); $db = new WPAM_Data_DataAccess(); $affiliateRepos = $db->getAffiliateRepository(); $affiliateId = $affiliateRepos->getAffiliateIdFromRefKey($refKey->getAffiliateRefKey()); if ($affiliateId === NULL) { } else { $aff_id = $affiliateId; } } } //TODO end if (!empty($aff_id)) { $cookie_life_time = wpam_get_cookie_life_time(); setcookie('wpam_id', $aff_id, $cookie_life_time, "/", COOKIE_DOMAIN); } } //this will be the new affiliate link. A click will be tracked when wpam_id is present in the URL if (isset($_REQUEST[WPAM_PluginConfig::$wpam_id]) && !empty($_REQUEST[WPAM_PluginConfig::$wpam_id])) { $aff_id = trim(strip_tags($_REQUEST[WPAM_PluginConfig::$wpam_id])); $cookie_life_time = wpam_get_cookie_life_time(); setcookie('wpam_id', $aff_id, $cookie_life_time, "/", COOKIE_DOMAIN); $args = array(); $args['dateCreated'] = date("Y-m-d H:i:s", time()); $args['sourceAffiliateId'] = $aff_id; $args['trackingKey'] = uniqid(); //save a unique ID to avoid error $args['sourceCreativeId'] = ''; // remove this column from the click tracking menu in the settings $args['referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $args['affiliateSubCode'] = ''; WPAM_Click_Tracking::insert_click_data($args); } }
function to_refkey($token) { $binConverter = new WPAM_Util_BinConverter(); $testRefKey = new WPAM_Tracking_TrackingKey(); $testRefKey->unpack($token); $refkey = $binConverter->binToString($testRefKey->getAffiliateRefKey()); var_dump($testRefKey); var_dump($refkey); var_dump($binConverter->binToString($binConverter->binToString($testRefKey->getAffiliateRefKey()))); return $refkey; }
public function handleImpression($request) { $strRefKey = NULL; if (isset($request[WPAM_PluginConfig::$RefKey])) { $strRefKey = $request[WPAM_PluginConfig::$RefKey]; } else { throw new Exception(__('no refkey in request.', 'wpam')); } $refKey = new WPAM_Tracking_TrackingKey(); $refKey->unpack($strRefKey); $db = new WPAM_Data_DataAccess(); $affiliateRepos = $db->getAffiliateRepository(); $affiliateId = $affiliateRepos->getAffiliateIdFromRefKey($refKey->getAffiliateRefKey()); if ($affiliateId === NULL) { throw new Exception(__('invalid refkey data: ', 'wpam') . $strRefKey); } $impressionModel = new WPAM_Data_Models_ImpressionModel(); $impressionModel->dateCreated = time(); $impressionModel->sourceAffiliateId = $affiliateId; $impressionModel->sourceCreativeId = $refKey->getCreativeId(); $impressionModel->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL; if (isset($request['wpam_affiliateSubCode'])) { $impressionModel->affiliateSubCode = $request['wpam_affiliateSubCode']; } $db->getImpressionRepository()->insert($impressionModel); }