'adview_jobbox', 'description' => __('UK\'s latest job ads into your site', 'adview'), ); parent::__construct('AdViewJobbox', 'AdView Jobbox', $widget_ops); add_action( 'wp_ajax_change_page', array( $this, 'widget' ) ); add_action( 'wp_ajax_nopriv_change_page', array( $this, 'widget') ); } public function widget($args, $instance) { $keyword_variable = sanitize_text_field($instance['keyword_var']) ?: 'keyword'; $location_variable = sanitize_text_field($instance['location_var']) ?: 'location'; $input = array( 'publisher_id' => intval($instance['publisher_id']) ?: (intval($_REQUEST['publisher_id']) ?: ''), 'limit' => intval($instance['limit']) ?: (intval($_REQUEST['limit']) ?: 20), 'channel' => sanitize_text_field($instance['channel']) ?: (sanitize_text_field($_REQUEST['channel']) ?: ''), 'keyword' => sanitize_text_field($instance['keyword']) ?: (sanitize_text_field($_REQUEST[$keyword_variable]) ?: ''), 'location' => sanitize_text_field($instance['location']) ?: (sanitize_text_field($_REQUEST[$location_variable]) ?: ''), 'text_color' => sanitize_text_field($instance['text_color']) ?: (sanitize_text_field($_REQUEST['text_color']) ?: ''), 'url_color' => sanitize_text_field($instance['url_color']) ?: (sanitize_text_field($_REQUEST['url_color']) ?: ''), 'page' => intval($_GET['page']) ?: '', ); if (! isset($input['publisher_id']) || ($input['publisher_id'] == 0)) { echo 'Publisher ID is invalid!'; return false; } if (intval($_POST['page'])) { $input['page'] = intval($_POST['page']); echo $this->ajaxData($input); exit; } ?> data($input,$args, $instance); return true; } private function ajaxData($input) { $ajax_query = $this->jobs($input); $ajax_query = '
' . implode('
', $ajax_query) . '
'; return stripslashes($ajax_query); } private function data($input, $args, $instance) { echo '
'; if ($query = $this->jobs($input)) { ?>
' . implode('
', $query) . '
'; ?>
<< >>
'; } private function jobs($input) { $result = array(); if (! $jobs = $this->fetchData($input)) { $result[] = 'There is connection error. Please try later.'; return $result; } if (! $jobs->data) { foreach ($jobs as $key => $error) { $result[] = '' . $error[0] . ''; } return $result; }; foreach ($jobs->data as $job) { $result[] = '' . $job->title . '
' . substr($job->snippet, 0, 80) . '...'; } return $result; } private function fetchData($input) { $json = $this->request($input); $json = json_decode($json); return $json; } private function request($input) { // Set parameters $parameters = array( 'publisher' => $input['publisher_id'], 'channel' => $input['channel'], 'user_ip' => $this->getRealIpAddress(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'keyword' => $input['keyword'], 'location' => $input['location'], 'limit' => $input['limit'], 'page' => $input['page'], 'addon' => 1, ); // Create curl resource $curl = curl_init(); // Set URL curl_setopt($curl, CURLOPT_URL, 'https://adview.online/api/v1/jobs.json' . '?' . http_build_query($parameters)); // Return the transfer as a string curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Drop connection after 10 seconds curl_setopt($curl, CURLOPT_TIMEOUT, 5); // Exec and return the response $response = curl_exec($curl); // Close curl resource curl_close($curl); // Dump the response return $response; } private function getRealIpAddress() { if (! empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } public function form($instance) { ?>

here', 'adview' ) ?>

$keyword variable.', 'adview' ) ?>

$location variable.', 'adview' ) ?>

id="get_field_id( 'logo_checkbox' ); ?>" name="get_field_name( 'logo_checkbox' ); ?>" />