false, 'status' => 'error', 'message' => 'Missing required fields' ]; wp_send_json($responseJSON); wp_die(); } $leadbox_id = sanitize_text_field($_POST['apwtvalues']['boxid']); if (isset($_REQUEST['apwtleadbox'])) { $query = http_build_query($_REQUEST['apwtvalues']); $query.= '&APWTboxid='.$leadbox_id; $thisurl = "/wordpress/wpapi.php?action=submitleadbox&".$query."&".APWTLBAPIAuth(); $thereturn = APWTRemoteGet($thisurl); error_log("apwt_submit_leadbox thisurl:".$thisurl); error_log("apwt_submit_leadbox response:".$thereturn); echo $thereturn; wp_die(); if ($thereturn) { wp_send_json_success(['message' => $thereturn]); } else { $responseJSON = [ 'success' => false, 'status' => 'error', 'message' => 'API request failed2' ]; wp_send_json($responseJSON); } } wp_die(); } function apwt_get_leadbox_html() { $leadbox_id = isset($_REQUEST['leadbox_id']) ? sanitize_text_field($_REQUEST['leadbox_id']) : ''; if (empty($leadbox_id)) { wp_send_json_error('Missing Leadbox ID'); wp_die(); } $widget = new APWTLeadBox(); ob_start(); $widget->widget([], ['APWTLeadBoxID' => $leadbox_id]); $html = ob_get_clean(); error_log("apwt_get_leadbox_html Response: " . $html); wp_send_json_success(['html' => $html]); wp_die(); } function APWTStaticBoxes() { error_log("Entered APWTStaticBoxes."); $thisurl = "/wordpress/wpapi.php?action=leadboxids&" . APWTLBAPIAuth(); $thereturn = APWTRemoteGet($thisurl); error_log("APWTGetLeadBoxesJSON API Response: " . print_r($thereturn, true)); if (empty($thereturn)) { wp_send_json_error(['message' => 'No data received from API', 'response' => $thereturn]); } $leadboxes = explode("-|-", $thereturn); array_pop($leadboxes); $newarray = []; foreach ($leadboxes as $val) { $pieces = explode("-*-", $val); if (count($pieces) == 2 && is_numeric($pieces[0]) && $pieces[0] > 0) { $newarray[] = [ 'value' => intval($pieces[0]), 'label' => sanitize_text_field($pieces[1]) ]; } } if (empty($newarray)) { error_log("APWTGetLeadBoxesJSON Parsed Result: No valid leadboxes found."); wp_send_json_error(['message' => 'No valid leadboxes found', 'raw_response' => $thereturn]); } error_log("APWTGetLeadBoxesJSON Parsed Result: " . print_r($newarray, true)); wp_send_json($newarray); } function APWTLBAPIAuth() { //formerly APIAuth $apikey = get_option("APWTAPIKEY"); $apiauth = get_option("APWTAPIAUTH"); $apwtver = get_option("APWT_THIS_VERSION"); if ($apwtver == '') { print "lost APWT_THIS_VERSION"; return; } if ( ($apiauth == '') || ($apikey == '') ) { print "The AllProWebTools plugin has not been configured. Please enter API Credential in wp-admin under 'AllProWebTools'."; exit; } return "apwtpluginversion=".$apwtver."&apikey=".get_option("APWTAPIKEY")."&apiauth=".get_option("APWTAPIAUTH"); } function APWTLBGetUrl() { //formerly APWTGetUrl $thisurl = "https://auth3.allprowebtools.com/listener/installinfo.php?".APWTLBAPIAuth(); $thereturn = wp_remote_get($thisurl); if ($thereturn['body'] == 'API credentials not found') { print $thereturn['body']; exit; } return $thereturn['body']; } function APWTLeadBoxActivate() { //http://wordpress.org/support/topic/how-do-i-create-a-new-page-with-the-plugin-im-building $APWTThisVersion = APWT_plugin_get_version(); update_option("APWT_THIS_VERSION", $APWTThisVersion); } function APWTLeadBoxDeactivate() { //nothing here } function APWTRemoteGet($url) { //formerly apwt_remote_get if (empty($_SESSION['serverurl'])) { $_SESSION['serverurl'] = APWTLBGetUrl(); } if (empty($_SESSION['serverurl'])) { print "unable to contact auth server"; exit; } $debug = 0; $args = APWTCookieSessionHandler() ?? []; $args['timeout'] = 120; $url .= '&siteurl='.$_SERVER['HTTP_HOST'].'&ip='.$_SERVER["REMOTE_ADDR"]; $url = "https:".$_SESSION['serverurl'].$url; //in an attempt to debug leadbox slowness, we tried using direct curl instead of wp_remote_get() to improve response times //we later found another issue related to L30 that improved the leadbox slowness - JAB 2017.05.11 //$ch = curl_init($url); //$response = curl_exec($ch); $response = wp_remote_get($url, $args); if (empty($response->errors)) { //no errors found if ($debug > 0) { print "
"; print_r ($args); print ""; print "
"; print_r ($_SESSION); print ""; } return $response['body']; } else { print "error in APWTRemoteGet {APWT154}"; print $url."