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 = "http://auth.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 "
".$url."
"; print "
";
			print_r ($args);
			print "
"; print "
";
			print_r ($_SESSION);
			print "
"; } return $response['body']; } else { print "error in APWTRemoteGet {APWT154}"; print $url."
"; print_r ($response->errors); exit; } } function APWTCookieSessionHandler() { //formerly cookiesessionhandler if (isset($_SESSION['PHPSESSID'])) { $cookie = new WP_Http_Cookie( 'PHPSESSID' ); $cookie->name = 'PHPSESSID'; $cookie->value = $_SESSION['PHPSESSID']; $cookie->expires = mktime( 0, 0, 0, date('m'), date('d') + 7, date('Y') ); // expires in 7 days $cookie->path = '/'; $cookie->domain = ''; $cookies[] = $cookie; $args = array( 'cookies' => $cookies ); return $args; } } function APWT_enqueue_scripts() { wp_register_script('APWTajax', plugins_url( '/js/apwt-leadbox.js', dirname(__FILE__) ), array(), '1', 'all' ); wp_enqueue_script( 'APWTajax'); wp_localize_script( 'APWTajax', 'APWTajaxurl', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script('jquery'); } class APWTLeadBox extends WP_Widget { public function __construct() { add_action( 'wp_ajax_nopriv_APWTLeadBox', array(&$this,'submit')); add_action( 'wp_ajax_APWTLeadBox', array(&$this,'submit')); $widget_ops = array( 'classname' => 'APWTLeadBox', 'description' => 'Display your AllProWebTools Leadsbox', ); parent::__construct( 'APWTLeadBox', 'AllProWebTools LeadBox', $widget_ops ); } function form($instance) { //get a title variable defined by the user $instance = wp_parse_args( (array) $instance, array( 'APWTLeadBoxID' => '' ) ); $APWTLeadBoxID = $instance['APWTLeadBoxID']; //get the ids for the lead box $thisurl = "/wordpress/wpapi.php?action=leadboxids&".APWTLBAPIAuth(); $thereturn = APWTRemoteGet($thisurl); $leadboxes = explode("-|-",$thereturn); array_pop($leadboxes); foreach ($leadboxes as $val) { $pieces = explode("-*-",$val); $newarray[$pieces[0]] = $pieces[1]; } $APWTLeadBoxID = empty($instance['APWTLeadBoxID']) ? ' ' : apply_filters('widget_title', $instance['APWTLeadBoxID']); $thisfieldid = sanitize_text_field($this->get_field_id('APWTLeadBoxID')); $thisfieldname = sanitize_text_field($this->get_field_name('APWTLeadBoxID')); ?>

0) { $thisurl = "/wordpress/wpapi.php?action=getleadbox&leadboxid=".$APWTLeadBoxID."&".APWTLBAPIAuth(); $thereturn = APWTRemoteGet($thisurl); error_log("widget Response: " . $before_title . $thereturn . $after_title); // echo $before_title . $thereturn . $after_title; echo $thereturn; } else { echo "

No Leadbox defined

"; } // echo $after_widget; } public static function submit() { if (isset($_REQUEST['apwtleadbox'])) { $query = http_build_query($_REQUEST['apwtvalues']); $thisurl = "/wordpress/wpapi.php?action=submitleadbox&".$query."&".APWTLBAPIAuth(); $thereturn = APWTRemoteGet($thisurl); echo $thereturn; } die(0); } } //end class extend APWTLeadBox