'',), $atts, 'aha_key' ) ); if (isset($_POST) && !empty($_POST)) { $nonce = sanitize_key($_POST['_ajax_nonce']); if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) die ( 'Access denied..'); } $id = isset($_POST['id']) ? sanitize_text_field($_POST['id']) : $id; global $wpdb; $prefix = $wpdb->prefix ; $_SESSION['guest_data'] = array(); require dirname (dirname( __FILE__ ) ) . '/functions/aha_curl_function.php'; $Curl = new Aha_curl_function; $books_data= $Curl->aha_active_key($id) ; $settings = $Curl->aha_settings($id) ; $user_ip = $Curl->aha_getUserIP(); if(isset($_POST['email'])){ $email = sanitize_email($_POST['email'] ); } if(isset($email) AND $email != NULL) { $aha_url ='https://www.ahathat.com/plugin-setup/login'; $datap = wp_unslash($_POST); $responseData = $Curl->aha_login($books_data->api_key , json_encode($datap),esc_url_raw($aha_url)); $user_data = json_decode($responseData); if($user_data[0] != 'error') { if(session_id() == '' || !isset($_SESSION)) { session_start(); } $_SESSION['user_data'] = array(); $_SESSION['user_data'] = $user_data[0] ; } } if(isset($_POST['logout'])){ unset($_SESSION['user_data']);} $session_name = (isset($_POST['session_name']) ? sanitize_text_field($_POST['session_name']) : (isset($_SESSION['user_data']->name ) ? sanitize_text_field($_SESSION['user_data']->name) :'')); $categories = json_decode($settings->categories); //$book_id = $books_data->book_id ; $end_book = $settings->end_of_aha; $book_id = $categories[0]; $action = (isset($_POST['action']) ? sanitize_text_field($_POST['action']) : NULL ); if(isset($_POST['tweets'])) { $aha_post_tweets = sanitize_text_field($_POST['tweets']); $ahas = "AND `order_no` = '".$aha_post_tweets."'" ; $ip_address = $wpdb->get_results("SELECT * FROM `".$prefix."aha_order` WHERE `ip_address` = '".$user_ip."' AND `w_id` = '".$id."' LIMIT 1") ; if(empty($ip_address)) { $wpdb->insert($prefix.'aha_order', array( 'ip_address' => $user_ip, 'order_no' => $aha_post_tweets, 'w_id' => $id, 'share_limit' => 1 )); }else{ $share_limit = $ip_address[0]->share_limit + 1; $table = $prefix.'aha_order'; $wpdb->query( $wpdb->prepare( "UPDATE {$table} SET order_no = '%d' , share_limit = '%d' WHERE ip_address = '%d' AND w_id = '%d'", $aha_post_tweets, $share_limit, $user_ip,$id ) // $wpdb->prepare ); // $wpdb->query } }else{ $ahas ='ORDER BY RAND()'; if( $action == NULL && $settings->shows == 1 ) { $ahas = "AND `order_no` = 1" ; $ip_address = $wpdb->get_results("SELECT * FROM `".$prefix."aha_order` WHERE `ip_address` = '".$user_ip."' AND `w_id` = '".$id."' LIMIT 1") ; if(!empty($ip_address)) { $ahas = "AND `order_no` = ".$ip_address[0]->order_no ; } }else if($action == NULL && $settings->shows == 2) { $ahas ='ORDER BY `order_no` DESC'; $ip_address = $wpdb->get_results("SELECT * FROM `".$prefix."aha_order` WHERE `ip_address` = '".$user_ip."' AND `w_id` = '".$id."' LIMIT 1") ; if(!empty($ip_address)) { $ahas = "AND `order_no` = ".$ip_address[0]->order_no ; } } } if($book_id != '' OR $end_book == '1' OR $end_book == '2'){ if($end_book == '0') { $book_id = $categories[0]; $all_book_share = $Curl->aha_all_book_share($books_data->api_key , $book_id ,$ahas) ; $aha_data = json_decode($all_book_share); $book_aha = $aha_data->aha; $bookData = $aha_data->bookData; $author_detail = $aha_data->author; $total_order = $aha_data->aha_total[0]->total; $aname = $author_detail[0]->name; foreach($author_detail as $data) { $aname .= $data->name.' '; } if(!empty($book_aha)) { $aha_tweet = $book_aha[0]->aha; $book_id= $bookData[0]->id; } }else { if(!empty($categories)) { $rand_keys = array_rand($categories, 1); $librarie_aha = $Curl->aha_librarie_aha($books_data->api_key,$categories[$rand_keys],$end_book) ; $aha_data = json_decode($librarie_aha); $book_aha = $aha_data->aha; $bookData = $aha_data->bookData; $author_detail = $aha_data->author; $total_order = $aha_data->aha_total[0]->total; $aname = $author_detail[0]->name; foreach($author_detail as $data) { $aname .= $data->name.' '; } if(!empty($book_aha)) { $aha_tweet = $book_aha[0]->aha; $book_id= $bookData[0]->id; } } } if(!empty($book_aha)) { $tweetText = htmlspecialchars_decode( $aha_tweet ); $tweetText1 = $tweetText; $tt = str_replace("#","#",$tweetText); $tt = str_replace("@","@",$tt); $tt = str_replace("@","@",$tt); $tt = str_replace('"','"',$tt); $tt = str_replace("'","´",$tt); $tweetText2 = urlencode($tweetText); if(substr($tweetText2,0,1)=="#") { $tweetText2 = substr($tweetText2, 1); } $ct = mb_strlen($tweetText); } $resultz = $wpdb->get_results( 'SELECT * FROM '.$prefix.'aha_api WHERE id='.$id); if(!empty($resultz)) { $key = ($resultz[0]->api_key != '' ? $resultz[0]->api_key : '' ); } $color = $wpdb->get_results( "SELECT * FROM ".$prefix."aha_color WHERE id_wid = '".$id."' AND active = '1' " ); $size = $wpdb->get_results( "SELECT * FROM ".$prefix."aha_color WHERE id_wid = '".$id."' AND active_s = '1' " ); if($color != NULL){ ?>