post_status != 'publish') { $current_post['post_status'] = 'publish'; wp_update_post($current_post); } } aw_update_metadata($MasterPost,'aw_affiliatewire_quick_ignition_split_Running', 'true'); } function aw_affiliatewire_quick_ignition_publish_all(&$MasterPost) { $splitTestData = aw_get_metadata('post',$MasterPost, 'aw_affiliatewire_quick_ignition_split_Children',true); foreach ($splitTestData as $postID) { $post = aw_get_post($postID); $current_post = get_post( $postID, 'ARRAY_A' ); if ($current_post->post_status != 'publish') { $current_post['post_status'] = 'publish'; wp_update_post($current_post); } } aw_update_metadata($MasterPost,'aw_affiliatewire_quick_ignition_split_Running', 'true'); } function aw_affiliatewire_quick_ignition_split_test_run(&$post) { if (isset($_REQUEST['preview']) && $_REQUEST['preview'] == "true") { if (isset($_REQUEST['p']) && $_REQUEST['p'] > 0) { return $post; } } //find out if post is part of a split test $postMaster = aw_get_metadata('post',$post->ID,'aw_affiliatewire_quick_ignition_split_Master',true); $splitTestData = aw_get_metadata('post',$postMaster, 'aw_affiliatewire_quick_ignition_split_Children',true); if ($postMaster > 0) { if (count($splitTestData) > 0) { //make shure we are using the correct database mysql_select_db(DB_NAME); //get split test values $splitTestName = aw_get_metadata('post',$postMaster, 'aw_affiliatewire_quick_ignition_split_TestName',true); //pick one of the split tests to display $choice = (int)aw_affiliatewire_quick_ignition_split_test_choose($splitTestData,$splitTestName); $choicePost = get_post($choice); //return the split test post return $choicePost; } } //return the orginal post return $post; } function aw_affiliatewire_quick_ignition_split_test_run_by_id(&$postID) { if (isset($_REQUEST['preview']) && $_REQUEST['preview'] == "true") { if (isset($_REQUEST['p']) && $_REQUEST['p'] > 0) { return $postID; } } //find out if post is part of a split test $postMaster = aw_get_metadata('post',$postID,'aw_affiliatewire_quick_ignition_split_Master',true); $running = aw_get_metadata('post',reset($splitTestMembers),'aw_affiliatewire_quick_ignition_split_Running',true); $splitTestData = aw_get_metadata('post',$postMaster, 'aw_affiliatewire_quick_ignition_split_Children',true); if ($postMaster > 0) { if (count($splitTestData) > 0) { //make shure we are using the correct database mysql_select_db(DB_NAME); //get split test values $splitTestName = aw_get_metadata('post',$postMaster, 'aw_affiliatewire_quick_ignition_split_TestName',true); //pick one of the split tests to display $choice = (int)aw_affiliatewire_quick_ignition_split_Test_choose($splitTestData,$splitTestName); //return the split test post return $choice; } } //return the orginal post return $postID; } function aw_affiliatewire_quick_ignition_split_test_choose($splitTestMembers, $splitTestName) { if(!isset($_SESSION)) { session_start(); } $choice = -1; $splitMaster = aw_get_metadata('post',reset($splitTestMembers),'aw_affiliatewire_quick_ignition_split_Master',true); $splitClosed = aw_get_metadata('post',$splitMaster,'aw_affiliatewire_quick_ignition_split_Closed',true); $ipChoice = aw_get_metadata('post', $splitMaster,'aw_affiliatewire_quick_ignition_split_IPs', true); foreach ($splitTestMembers as $member) { if (get_post_status($member) != 'publish') { $splitTestMembers = array_diff($splitTestMembers,array($member)); } } if ($splitClosed != '') { return $splitClosed; } $userIP = ip2long($_SERVER['REMOTE_ADDR']); $cookiename = preg_replace('/[^a-zA-Z0-9]/','_',(get_bloginfo('name').$splitTestName)); if (isset($ipChoice[$userIP])) { $choice = $ipChoice[$userIP]; //check if there is already a cookie set } elseif (isset($_COOKIE[$cookiename])) { $choice = (int)$_COOKIE[$cookiename]; //get the choice from the cookie //if no cookie, check if we already set the choice to the session } elseif (isset($_SESSION[$cookiename])) { $choice = (int)$_SESSION[$cookiename]; //get the choice from the session } if ($choice == -1 OR !in_array($choice, $splitTestMembers)) { $count = count($splitTestMembers); $choiceNumber = rand(0,$count-1); //randomly choose one of the posts $choice = $splitTestMembers[$choiceNumber]; //update the count for that choice (number of 'unique' hits $splitTestHits = aw_get_metadata('post',$choice,'aw_affiliatewire_quick_ignition_split_Hits',true); $splitTestHits++; aw_update_metadata($choice,'aw_affiliatewire_quick_ignition_split_Hits',$splitTestHits); //update total hit counter $splitTestTotalHits = aw_get_metadata('post',$splitMaster,'aw_affiliatewire_quick_ignition_split_Total_Hits',true); $splitTestTotalHits++; aw_update_metadata($splitMaster,'aw_affiliatewire_quick_ignition_split_Total_Hits',$splitTestTotalHits); } $ipChoice[$userIP] = $choice; $_SESSION[$cookiename] = $choice; //store the choice as a cookie //store the choice as a cookie $expireDate = time() + (60 * 60 * 24 * 30); // 30 days $cookiePath = '/'; $setcookie = setcookie($cookiename, $choice, $expireDate, $cookiePath); aw_update_metadata($splitMaster,'aw_affiliatewire_quick_ignition_split_IPs', $ipChoice); return $choice; } function aw_affiliatewire_quick_ignition_get_base_tracking_js() { $callbackUrl = aw_get_site_url(); $toReturn = ' '; return $toReturn; } function aw_get_post_status($post_status) { switch ($post_status) { case "publish": $toReturn = "(Published)"; break; case "draft": $toReturn = "(Draft)       "; break; default: $toReturn = "(" . $post_status . ")"; } return $toReturn; } ?>