IMPORTANT!

'; echo '

You have to setup the country of your Google searches first before you continue.
Click here to set the default search country.

'; } } /* * Create custom post type */ public function create_post_type() { $labels = array( 'name' => _x( 'Keywords', 'post type general name' ), 'singular_name' => _x( 'Keyword', 'post type singular name' ), 'add_new' => _x( 'Add New', 'keyword' ), 'add_new_item' => __( 'Add New keyword' ), 'edit_item' => __( 'Edit keyword' ), 'new_item' => __( 'New keyword' ), 'all_items' => __( 'All keywords' ), 'view_item' => __( 'View keyword' ), 'search_items' => __( 'Search keywords' ), 'not_found' => __( 'No keywords found' ), 'not_found_in_trash' => __( 'No keywords found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Keywords' ); $args = array( 'labels' => $labels, 'description' => 'Show keywords ranking in Google', 'public' => true, 'menu_position' => 88, 'supports' => array( 'title'), 'has_archive' => true, 'menu_icon' => 'dashicons-admin-site', ); register_post_type('rankchecker', $args); } /* * Register menu item for plugin */ public function register_menu_item() { add_menu_page( 'Rank Checker', 'Rank Checker', 'manage_options', 'rank_checker', array($this, 'show_ranking'), 'dashicons-admin-site', 89); } // Show ranking of keywords & process public function show_ranking($hidecheck) { // Set global $wpdb for sql connection global $wpdb; $post = array("post_status" => "publish"); wp_insert_post($post); // Get options from options page $options = get_option('rankchecker_settings'); // Show table with contents echo '

Welcome to the Advanced Rank Checker

'; echo '

You can use this system to check your keywords ranking. You can check each keyword once a day.

'; echo '

Did you not add keywords yet?  Click here to start

'; echo '
'; echo '
'; echo ''; echo ''; if (!$hidecheck == true) { echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; if(!$hidecheck == true) { echo ''; } echo ''; // SQL query to get all posts where meta_key is rankchecker $sql = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE 'rankchecker' ORDER BY meta_id DESC"); $ids = array(); // Get current time $datetimenow = time() + 2*60*60; // Set counter for plussign button $count = 0; // Loop through postmeta foreach ($sql as $row) { // Meta value in $meta_value $meta_value = unserialize($row->meta_value); if(in_array($row->post_id, $ids)) { } else { $positions = array(); // Push id to array so it displays only once array_push($ids, $row->post_id); // Get second last position results for keywords $sql2 = $wpdb->get_results("SELECT meta_value FROM (SELECT * FROM $wpdb->postmeta ORDER BY meta_id DESC) sub WHERE post_id LIKE $row->post_id AND meta_key LIKE 'rankchecker' ORDER BY meta_id DESC LIMIT 3"); foreach($sql2 as $test) { $meta_value_info = unserialize($test->meta_value); if($meta_value_info['position'] == 'Not checked yet') { continue; } $positions[] = $meta_value_info['position']; } if(count($positions) > 1) { $position_total = $positions[1] - $positions[0]; } if(empty($positions)) { $position_total = 0; } if($positions[0] == 'Not in top 100') { $position_total = 100 - $positions[1]; } if($positions[1] == 'Not in top 100') { $position_total = 100 - $positions[0]; } if($positions[1] == '') { $position_total = 100 - $positions[0]; } // Set sign and color based on result if ($positions[0] > $positions[1]) { $sign = ""; $color = "red"; } else { $sign = "+"; $color = "green"; } if($positions[1] == '' || $positions[1] == 'Not in top 100') { $sign = "+"; $color = "green"; } if($positions[0] == 'Not in top 100' && $positions[1] < 100) { $color = "red"; $sign = "-"; } if($positions[0] == 'Not in top 100' && $positions[1] == 'Not in top 100') { $color = "black"; } if($position_total == 0) { $color = "black"; } echo ''; if(!$hidecheck == true) { echo ''; } echo ''; echo ''; echo ''; echo ''; if ($meta_value['date'] == 'Not checked yet') { echo ''; } else { echo ''; } // Set values for time check $timeleft = $datetimenow - $meta_value['date']; $day = 24*60*60; $timeleft_total = $day - $timeleft; // check whether 24 hours has passed if(!$hidecheck == true) { if($timeleft > $day) { echo ''; } else { echo ''; } } $count++; echo ''; echo ''; if (!$hidecheck == true) { ?> get_results("SELECT meta_value FROM $wpdb->postmeta WHERE $row->post_id LIKE post_id AND meta_key LIKE 'rankchecker' ORDER BY meta_id DESC"); array_shift($sql_all_results); foreach($sql_all_results as $result) { $meta_results = unserialize($result->meta_value); if($meta_results['position'] == 'Not checked yet') { continue; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } } ?> '; echo ''; $rankchecker_options = new rankchecker_options(); $countries = $rankchecker_options->countries(); // Form process if ($_POST['submit']) { ?>
Loading…
countries(); for($i=0;$i<$total_to_search;$i+=$hits_per_page) { // Curl $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, "http://www.google.".$countries[$options['rankchecker_select_field_0']]."/search?as_q=$query". "&num=$hits_per_page&hl=en&ie=UTF-8&btnG=Google+Search". "&as_epq=&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=". "&as_qdr=all&as_nlo=&as_nhi=&as_occt=any&as_dt=i". "&as_sitesearch=&safe=images&start=$i"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $var = curl_exec($ch); curl_close($ch); // split the page code by "

"); break; } if ($position > '99') { add_post_meta( $_POST['keyword_id'], 'rankchecker', array( 'keyword' => $searchquery, 'position' => 'Not in top 100', 'date' => $datetimenow, 'country' => $countries[$options['rankchecker_select_field_0']], )); echo(""); break; } } } else { echo '
It seems like you checked the Google results too many times. Please try again in an hour! If this error keeps showing, please contact your webhosting master. Your IP may be blocked by the Google Search System.
'; break; } } } else { echo 'Something went wrong, please try again.'; } } } // Add postmeta on new post public function addpostmeta($post_id) { // Get post of lastest created post $post = get_post($post_id); // Get options from options page $options = get_option('rankchecker_settings'); // Countries $rankchecker_options = new rankchecker_options(); $countries = $rankchecker_options->countries(); // Get all posts where post-type is rankchecker $all_posts = get_posts($args); if(count($all_posts) > 1) { // Unset first element because that is the new post we just created unset($all_posts[0]); } // Sort elements again so it starts at 0 $all_posts = array_values($all_posts); // Loop through posts to check if the post_title already exists foreach($all_posts as $rows) { if($rows->post_title == $post->post_title && count($all_posts) > 1) { wp_delete_post($post_id); ?> $post->post_title, 'position' => 'Not checked yet', 'date' => 'Not checked yet', 'country' => $countries[$options['rankchecker_select_field_0']], )); } } } } $rankchecker = new rankchecker(); $options = get_option('rankchecker_settings'); if ($options['rankchecker_checkbox_field_1'] == 1) { require_once 'rankchecker_dashboard.php'; } require_once 'rankchecker_options.php';

#KeywordGoogle RankingCountryLast checkedCheck
'; echo ''; echo ''.$row->post_id.''.$meta_value['keyword'].''.$meta_value['position'].' ('.$sign.$position_total.') '.$meta_value['country'].''.$meta_value['date'].''.date('d/m/Y H:i:s', $meta_value['date']).'
'.date("H", $timeleft_total).' hours left
'.$meta_results['keyword'].''.$meta_results['position'].''.$meta_results['country'].''.date('d/m/Y H:i:s', $meta_results['date']).'