[44] | 1 | <?php
|
---|
| 2 | /*
|
---|
| 3 | Plugin Name: Position Yourself
|
---|
| 4 | Plugin URI: http://www.queromediashare.com/wordpress-plugins/google-positioner-wordpress-plugin
|
---|
| 5 | Description: Gets matches from Google results for your keywords
|
---|
| 6 | Author: Kim Kennof
|
---|
| 7 | Version: 1.2
|
---|
| 8 | Author URI: http://www.queromediashare.com
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | /*
|
---|
| 12 | ----------------------------------------------------------------------------
|
---|
| 13 | Copyright 2007 Kim Kennof (email : kim.kennof@queromedia.com)
|
---|
| 14 | ----------------------------------------------------------------------------
|
---|
| 15 | This program is free software; you can redistribute it and/or modify
|
---|
| 16 | it under the terms of the GNU General Public License as published by
|
---|
| 17 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 18 | (at your option) any later version.
|
---|
| 19 |
|
---|
| 20 | This program is distributed in the hope that it will be useful,
|
---|
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 23 | GNU General Public License for more details.
|
---|
| 24 |
|
---|
| 25 | You should have received a copy of the GNU General Public License
|
---|
| 26 | along with this program; if not, write to the Free Software
|
---|
| 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 28 | ----------------------------------------------------------------------------
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | if (!class_exists('positionyourself')) {
|
---|
| 32 | class positionyourself {
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * @var string The name the options are saved under in the database.
|
---|
| 36 | */
|
---|
| 37 | var $adminOptionsName = "positionyourself_options";
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * PHP 4 Compatible Constructor
|
---|
| 41 | */
|
---|
| 42 | function positionyourself() {$this->__construct();}
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * PHP 5 Constructor
|
---|
| 46 | */
|
---|
| 47 | function __construct() {
|
---|
| 48 |
|
---|
| 49 | register_activation_hook(__FILE__,array(&$this,'positionyourself_install'));
|
---|
| 50 |
|
---|
| 51 | if (is_admin()) {
|
---|
| 52 | add_action("admin_head", array(&$this, "add_admin_css"));
|
---|
| 53 | add_action("admin_menu", array(&$this, "add_admin_pages"));
|
---|
| 54 | add_action("init", array(&$this, "add_admin_scripts"));
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | $this->adminOptions = $this->getAdminOptions();
|
---|
| 58 |
|
---|
| 59 | $py_locale = get_locale();
|
---|
| 60 | $py_mofile = dirname(__FILE__) . "/languages/position_yourself-".$py_locale.".mo";
|
---|
| 61 | load_textdomain("position_yourself", $py_mofile);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * Retrieves the options from the database.
|
---|
| 66 | * @return array
|
---|
| 67 | */
|
---|
| 68 | function getAdminOptions() {
|
---|
| 69 | $adminOptions = array( "pyKeywords" => "",
|
---|
| 70 | "pyCompetitors" => "",
|
---|
| 71 | "pyRegion" => "be",
|
---|
| 72 | "pyLanguage" => "nl",
|
---|
| 73 | "pyMeta" => "",
|
---|
| 74 | "pyPageRank" => "no",
|
---|
| 75 | "pyNumResults" => 30
|
---|
| 76 | );
|
---|
| 77 |
|
---|
| 78 | $savedOptions = get_option($this->adminOptionsName);
|
---|
| 79 |
|
---|
| 80 | if (!empty($savedOptions)) {
|
---|
| 81 | foreach ($savedOptions as $key => $option) {
|
---|
| 82 | $adminOptions[$key] = $option;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | update_option($this->adminOptionsName, $adminOptions);
|
---|
| 86 | return $adminOptions;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
| 92 | * Saves the Position Yourself options to the database.
|
---|
| 93 | * @return
|
---|
| 94 | */
|
---|
| 95 | function saveAdminOptions() {
|
---|
| 96 | update_option($this->adminOptionsName, $this->adminOptions);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * Adds Position Yourself to admin menu.
|
---|
| 101 | * @return
|
---|
| 102 | */
|
---|
| 103 | function add_admin_pages() {
|
---|
| 104 | add_menu_page( __('Position Yourself','position_yourself'),
|
---|
| 105 | __('Position Yourself','position_yourself'),
|
---|
| 106 | 10,
|
---|
| 107 | __FILE__,
|
---|
| 108 | array(&$this,"output_positioner")
|
---|
| 109 | );
|
---|
| 110 |
|
---|
| 111 | add_submenu_page( __FILE__,
|
---|
| 112 | __('Manage keywords','position_yourself'),
|
---|
| 113 | __('Manage keywords','position_yourself'),
|
---|
| 114 | 10,
|
---|
| 115 | "manage_keywords",
|
---|
| 116 | array(&$this,"manage_keywords")
|
---|
| 117 | );
|
---|
| 118 | add_submenu_page( __FILE__,
|
---|
| 119 | __('Manage options','position_yourself'),
|
---|
| 120 | __('Manage options','position_yourself'),
|
---|
| 121 | 10,
|
---|
| 122 | "manage_options",
|
---|
| 123 | array(&$this,"manage_options")
|
---|
| 124 | );
|
---|
| 125 | add_submenu_page( __FILE__,
|
---|
| 126 | __("Track positions",'position_yourself'),
|
---|
| 127 | __("Track positions",'position_yourself'),
|
---|
| 128 | 10,
|
---|
| 129 | "manage_keyword_tracking",
|
---|
| 130 | array(&$this,"manage_keyword_tracking")
|
---|
| 131 | );
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /**
|
---|
| 135 | * Outputs the sourcecode for the admin page.
|
---|
| 136 | * @return
|
---|
| 137 | */
|
---|
| 138 | function output_positioner() {
|
---|
| 139 | global $wpdb;
|
---|
| 140 | ?>
|
---|
| 141 | <div class="wrap">
|
---|
| 142 | <h2><?php _e('Positioner','position_yourself'); ?></h2>
|
---|
| 143 | <h3><?php _e('Your keywords','position_yourself'); ?></h3>
|
---|
| 144 | <?php
|
---|
| 145 | // arrays
|
---|
| 146 | $pyKeywords = array();
|
---|
| 147 | $pyDomain = '';
|
---|
| 148 | $pyCompetitors = array();
|
---|
| 149 | $pyPositions = array();
|
---|
| 150 | $pyResults = array();
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | if ( $this->adminOptions["pyKeywords"] ) {
|
---|
| 154 | $tmpKeywords = $this->adminOptions["pyKeywords"];
|
---|
| 155 |
|
---|
| 156 | if ( preg_match("/,/", $tmpKeywords) )
|
---|
| 157 | $pyKeywords = preg_split('/,/', $tmpKeywords, -1, PREG_SPLIT_NO_EMPTY);
|
---|
| 158 | else
|
---|
| 159 | array_push($pyKeywords, $tmpKeywords);
|
---|
| 160 |
|
---|
| 161 | $pyKeywords = pyTrimArray($pyKeywords);
|
---|
| 162 |
|
---|
| 163 | $pyNumKw = count($pyKeywords);
|
---|
| 164 | } else {
|
---|
| 165 | $pyNumKw = 0;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | if ( 0 != $pyNumKw ) {
|
---|
| 169 |
|
---|
| 170 | $action = attribute_escape($_GET["action"]);
|
---|
| 171 |
|
---|
| 172 | if ( "run" == $action ) {
|
---|
| 173 |
|
---|
| 174 | // start timer
|
---|
| 175 | timer_start();
|
---|
| 176 | // start buffering the output for later
|
---|
| 177 | ob_start();
|
---|
| 178 | // set parameters from options
|
---|
| 179 | $pyRegion = $this->adminOptions["pyRegion"];
|
---|
| 180 | $pyLanguage = $this->adminOptions["pyLanguage"];
|
---|
| 181 | $pyMeta = ( isset($this->adminOptions["pyMeta"]) && '' != $this->adminOptions["pyMeta"] ) ? "&meta=restrict%3D".$this->adminOptions["pyMeta"] : "";
|
---|
| 182 | $pyPageRank = $this->adminOptions["pyPageRank"];
|
---|
| 183 | $pyNumResults = $this->adminOptions["pyNumResults"];
|
---|
| 184 |
|
---|
| 185 | // domains
|
---|
| 186 | $pyDomain = get_option('siteurl');
|
---|
| 187 |
|
---|
| 188 | // competitors
|
---|
| 189 |
|
---|
| 190 | $tmpCompetitors = $this->adminOptions["pyCompetitors"];
|
---|
| 191 | //$tmpCompetitors = "http://en.wikipedia.org,http://www.google.be,http://www.queromedia.be";
|
---|
| 192 |
|
---|
| 193 | if ( preg_match("/,/", $tmpCompetitors) )
|
---|
| 194 | $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY);
|
---|
| 195 | else
|
---|
| 196 | array_push($pyCompetitors, $tmpCompetitors);
|
---|
| 197 | $pyCompetitors = pyTrimArray($pyCompetitors);
|
---|
| 198 |
|
---|
| 199 | // total number of matches
|
---|
| 200 | $pyTotalMatches = 0;
|
---|
| 201 | $oriKeywords = $pyKeywords;
|
---|
| 202 |
|
---|
| 203 | $positioner = new Positioner();
|
---|
| 204 | $positioner->start = date('d-m-Y, H:i:s');
|
---|
| 205 | $positioner->region = $pyRegion;
|
---|
| 206 | $positioner->language = $pyLanguage;
|
---|
| 207 | $positioner->meta = $pyMeta;
|
---|
| 208 | $positioner->num_results = $pyNumResults;
|
---|
| 209 |
|
---|
| 210 | // Start
|
---|
| 211 | if ( '' == $pyKeywords ) {
|
---|
| 212 | $this->error(__('You have not yet added any keywords.','position_yourself'));
|
---|
| 213 | exit();
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | if ( count($pyKeywords) > 0 ) {
|
---|
| 218 | // begin foreach
|
---|
| 219 | foreach ( (array) $pyKeywords as $tmpKeyword ) {
|
---|
| 220 | //echo "<h1>$tmpKeyword</h1>";
|
---|
| 221 | $query = new GoogleQuery($tmpKeyword, $pyRegion, $pyLanguage, $pyNumResults);
|
---|
| 222 | // get own matches
|
---|
| 223 | $query->set_results();
|
---|
| 224 | $query->find_matches($query->results, $pyDomain);
|
---|
| 225 | $query->find_top_position();
|
---|
| 226 | // get competitor matches
|
---|
| 227 | if (count($pyCompetitors) > 0 ) {
|
---|
| 228 | foreach ( (array)$pyCompetitors as $tmpCompetitor ) {
|
---|
| 229 | if ($tmpCompetitor)
|
---|
| 230 | $competitor_matches[$tmpCompetitor] = $query->find_matches($query->results, $tmpCompetitor);
|
---|
| 231 | }
|
---|
| 232 | $query->competitors = (array)$competitor_matches;
|
---|
| 233 | }
|
---|
| 234 | $positioner->queries[] = $query;
|
---|
| 235 |
|
---|
| 236 | $timeOut = (int)((rand()%4) + 1);
|
---|
| 237 | $this->sleepr($timeOut);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 | $positioner->end = date('d-m-Y, H:i:s');
|
---|
| 241 |
|
---|
| 242 | $job_id = $this->process_results($positioner);
|
---|
| 243 | if ($job_id != 0) {
|
---|
| 244 | $job_url = get_option('siteurl').'/wp-admin/admin.php?page=manage_keyword_tracking&job_id='.$job_id;
|
---|
| 245 |
|
---|
| 246 | echo "<div class=\"message\">\n";
|
---|
| 247 | printf(__('Your keywords have been successfully positioned! <a href="%s">Click here for the detailed report.</a>','position_yourself'), $job_url);
|
---|
| 248 | echo "</div>\n";
|
---|
| 249 |
|
---|
| 250 | } else {
|
---|
| 251 | $this->error(__("Your keywords could not be positioned. Please try again.",'position_yourself'));
|
---|
| 252 | }
|
---|
| 253 | } else {
|
---|
| 254 | $jobdatasql = "SELECT ID FROM ".$wpdb->prefix."py_jobs ORDER BY ID DESC LIMIT 1";
|
---|
| 255 | $most_recent_job = $wpdb->get_var($jobdatasql);
|
---|
| 256 |
|
---|
| 257 | $counter = 0;
|
---|
| 258 | $position_url = get_option('siteurl') .'/wp-admin/admin.php?page='.plugin_basename( dirname( __FILE__ )).'/position_yourself.php&action=run';
|
---|
| 259 | $track_positions_url = get_option('siteurl') . '/wp-admin/admin.php?page=manage_keyword_tracking';
|
---|
| 260 |
|
---|
| 261 | ?>
|
---|
| 262 | <p><?php printf(__('You can get the position of your website for your keywords by pressing <a href="%s">Position me</a>. Afterwards you can view your detailed report under the <a href="%s">Track positions</a> page.','position_yourself'), $position_url, $track_positions_url); ?></p>
|
---|
| 263 | <p><?php printf(__('<a href="%s" class="button">Position me</a>','position_yourself'), $position_url); ?></p>
|
---|
| 264 | <table class="widefat" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 265 | <thead>
|
---|
| 266 | <tr>
|
---|
| 267 | <th scope="col" style="text-align: center" width="30"><?php echo "#"; ?></th>
|
---|
| 268 | <th scope="col"><?php _e("Keyword",'position_yourself'); ?></th>
|
---|
| 269 | <th scope="col"><?php _e("Last position",'position_yourself'); ?></th>
|
---|
| 270 | </tr>
|
---|
| 271 | </thead>
|
---|
| 272 | <tbody id="the-list">
|
---|
| 273 | <?php
|
---|
| 274 | foreach( (array) $pyKeywords as $tmpKeyword ) {
|
---|
| 275 | $counter++;
|
---|
| 276 | $tmpKeyword = trim($tmpKeyword);
|
---|
| 277 | $last_top_position_sql = "SELECT position FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$most_recent_job." AND type = 'own' AND keyword = '".$tmpKeyword."'";
|
---|
| 278 | $last_top_position = $wpdb->get_var($last_top_position_sql);
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 | if ($row_class == '')
|
---|
| 282 | $row_class = 'alternate';
|
---|
| 283 | else
|
---|
| 284 | $row_class = '';
|
---|
| 285 | ?>
|
---|
| 286 | <tr class="<?php echo $row_class; ?>">
|
---|
| 287 | <th scope="row" style="text-align: center"><?php echo $counter; ?></th>
|
---|
| 288 | <td><?php echo htmlspecialchars($tmpKeyword); ?></td>
|
---|
| 289 | <td><?php echo $last_top_position; ?></td>
|
---|
| 290 | </tr>
|
---|
| 291 | <?php
|
---|
| 292 | }
|
---|
| 293 | ?>
|
---|
| 294 | </tbody>
|
---|
| 295 | </table>
|
---|
| 296 | <p><?php printf(__('<a href="%s" class="button">Position me</a>','position_yourself'), $position_url); ?></p>
|
---|
| 297 | <?php
|
---|
| 298 |
|
---|
| 299 | }
|
---|
| 300 | } else { ?>
|
---|
| 301 | <p><?php _e('You have not yet added any keywords.','position_yourself'); ?></p>
|
---|
| 302 | <?php
|
---|
| 303 | // Modify keywords link
|
---|
| 304 | $position_url = get_option('siteurl') . '/wp-admin/admin.php?page=manage_keywords&action=modify';
|
---|
| 305 | ?>
|
---|
| 306 | <p><?php printf(__('<a href="%s" class="button">Modify keywords</a>','position_yourself'), $position_url); ?></p>
|
---|
| 307 | <?php
|
---|
| 308 | } ?>
|
---|
| 309 | </div>
|
---|
| 310 | <?php
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /**
|
---|
| 314 | * Outputs the HTML for the keyword-management sub page.
|
---|
| 315 | */
|
---|
| 316 | function manage_keywords() {
|
---|
| 317 | global $wpdb;
|
---|
| 318 | ?>
|
---|
| 319 | <div class="wrap">
|
---|
| 320 | <h2><?php _e('Manage your keywords','position_yourself'); ?></h2>
|
---|
| 321 | <?php
|
---|
| 322 | if ( isset($_GET["action"]) && "modify" == attribute_escape($_GET["action"]) ) {
|
---|
| 323 | if ( isset($_POST["submit"]) ) {
|
---|
| 324 | $pyKeywords = stripslashes($_POST["keywords"]);
|
---|
| 325 |
|
---|
| 326 | $pyKeywords = trim($pyKeywords,"\n");
|
---|
| 327 | $pyKeywords = trim($pyKeywords);
|
---|
| 328 | $pyKeywords = explode("\n",$pyKeywords);
|
---|
| 329 | $pyKeywords = pyTrimArray($pyKeywords);
|
---|
| 330 | $pyKeywords = implode(", ",$pyKeywords);
|
---|
| 331 | $this->adminOptions["pyKeywords"] = $pyKeywords;
|
---|
| 332 | $this->saveAdminOptions();
|
---|
| 333 | $message_id = ( !empty($this->adminOptions) ) ? 3: 5;
|
---|
| 334 | } else {
|
---|
| 335 | $message_id = 0;
|
---|
| 336 | }
|
---|
| 337 | $submit_text = __('Save keywords »','position_yourself');
|
---|
| 338 |
|
---|
| 339 | $messages[1] = __('Keywords added.','position_yourself');
|
---|
| 340 | $messages[2] = __('Keywords deleted.','position_yourself');
|
---|
| 341 | $messages[3] = __('Keywords updated.','position_yourself');
|
---|
| 342 | $messages[4] = __('Keywords not added.','position_yourself');
|
---|
| 343 | $messages[5] = __('Keywords not updated.','position_yourself');
|
---|
| 344 |
|
---|
| 345 | $pyKeywords = $this->adminOptions["pyKeywords"];
|
---|
| 346 |
|
---|
| 347 | if ( '' != $pyKeywords ) {
|
---|
| 348 | $pyNumKw = count(explode(",",$pyKeywords));
|
---|
| 349 | $pyKeywords = explode(",",$pyKeywords);
|
---|
| 350 | $pyKeywordstr = '';
|
---|
| 351 |
|
---|
| 352 | foreach ( (array) $pyKeywords as $pyKeyword ) {
|
---|
| 353 | $pyKeywordstr .= trim($pyKeyword)."\n";
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | $pyKeywordsstr = substr($pyKeywordstr,-1,2);
|
---|
| 357 | } else {
|
---|
| 358 | $pyNumKw = 0;
|
---|
| 359 | $pyKeywords = '';
|
---|
| 360 | }
|
---|
| 361 | ?>
|
---|
| 362 | <h3><?php _e('Add your keywords','position_yourself'); ?></h3>
|
---|
| 363 | <p><?php _e('Enter the keywords you want to track. Use a new line for each keyword.','position_yourself'); ?></p>
|
---|
| 364 | <?php if ( isset($message_id) && 0 != $message_id ) : ?>
|
---|
| 365 | <div id="message" class="updated fade"><p><?php echo $messages[$message_id]; ?></p></div>
|
---|
| 366 | <?php endif; ?>
|
---|
| 367 |
|
---|
| 368 | <form method="post" action="admin.php?page=manage_keywords&action=modify">
|
---|
| 369 | <p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
|
---|
| 370 | <table class="options" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 371 | <tr>
|
---|
| 372 | <th width="33%" scope="row" valign="top"><label for="keywords"><?php _e("Keywords",'position_yourself'); ?></label></th>
|
---|
| 373 | <td width="67%"><textarea name="keywords" cols="80" rows="50" id="keywords"><?php echo $pyKeywordstr; ?></textarea></td>
|
---|
| 374 | </tr>
|
---|
| 375 | </table>
|
---|
| 376 | <p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
|
---|
| 377 | </form>
|
---|
| 378 | <?php
|
---|
| 379 | }
|
---|
| 380 | else
|
---|
| 381 | {
|
---|
| 382 | // Modify keywords link
|
---|
| 383 | $modify_kw_url = get_option('siteurl') . '/wp-admin/admin.php?page=manage_keywords&action=modify';
|
---|
| 384 | ?>
|
---|
| 385 | <h3><?php _e('Your keywords','position_yourself'); ?></h3>
|
---|
| 386 | <p><?php printf(__('On this page you can <a href="%s">modify</a> you keywords you want to track.','position_yourself'), $modify_kw_url); ?></p>
|
---|
| 387 | <p><?php printf(__('<a href="%s" class="button">Modify keywords</a>','position_yourself'), $modify_kw_url) ?></p>
|
---|
| 388 | <?php
|
---|
| 389 | $pyKeywords = $this->adminOptions["pyKeywords"];
|
---|
| 390 |
|
---|
| 391 | if ( '' != $pyKeywords )
|
---|
| 392 | {
|
---|
| 393 | $pyNumKw = count(explode(',',$pyKeywords));
|
---|
| 394 | $pyKeywords = explode(',',$pyKeywords);
|
---|
| 395 | }
|
---|
| 396 | else
|
---|
| 397 | {
|
---|
| 398 | $pyNumKw = 0;
|
---|
| 399 | $pyKeywords = array();
|
---|
| 400 | }
|
---|
| 401 | if ( 0 != $pyNumKw )
|
---|
| 402 | {
|
---|
| 403 | // show list of keywords
|
---|
| 404 | $counter = 0;
|
---|
| 405 | ?>
|
---|
| 406 | <table class="widefat" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 407 | <thead>
|
---|
| 408 | <tr>
|
---|
| 409 | <th scope="col" style="text-align: center" width="30"><?php echo "#"; ?></th>
|
---|
| 410 | <th scope="col"><?php _e("Keyword",'position_yourself'); ?></th>
|
---|
| 411 | </tr>
|
---|
| 412 | </thead>
|
---|
| 413 | <tbody id="the-list">
|
---|
| 414 | <?php
|
---|
| 415 | foreach ( (array) $pyKeywords as $pyKeyword )
|
---|
| 416 | {
|
---|
| 417 | $counter++;
|
---|
| 418 | if ($row_class == '')
|
---|
| 419 | $row_class = 'alternate';
|
---|
| 420 | else
|
---|
| 421 | $row_class = '';
|
---|
| 422 | ?>
|
---|
| 423 | <tr class="<?php echo $row_class; ?>">
|
---|
| 424 | <th scope="row" style="text-align: center"><?php echo $counter; ?></td>
|
---|
| 425 | <td><?php echo htmlspecialchars(trim($pyKeyword)); ?></td>
|
---|
| 426 | </tr>
|
---|
| 427 | <?php
|
---|
| 428 | }
|
---|
| 429 | ?>
|
---|
| 430 | </tbody>
|
---|
| 431 | </table>
|
---|
| 432 | <?php
|
---|
| 433 | }
|
---|
| 434 | else
|
---|
| 435 | {
|
---|
| 436 | ?>
|
---|
| 437 | <p><?php _e("You have not yet added any keywords.",'position_yourself'); ?></p>
|
---|
| 438 | <?php
|
---|
| 439 | }
|
---|
| 440 | ?>
|
---|
| 441 | <p><?php printf(__('<a href="%s" class="button">Modify keywords</a>','position_yourself'), $modify_kw_url) ?></p>
|
---|
| 442 | <?php
|
---|
| 443 | }
|
---|
| 444 | ?>
|
---|
| 445 | </div>
|
---|
| 446 | <?php
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | /**
|
---|
| 450 | * Outputs the HTML for the google-options-management sub page.
|
---|
| 451 | */
|
---|
| 452 | function manage_options() {
|
---|
| 453 | global $wpdb;
|
---|
| 454 | ?>
|
---|
| 455 | <div class="wrap">
|
---|
| 456 | <h2><?php _e("Manage Positioner Options",'position_yourself'); ?></h2>
|
---|
| 457 | <?php
|
---|
| 458 | if ( isset($_GET["action"]) && "modify" == attribute_escape($_GET["action"]) ) {
|
---|
| 459 | if ( isset($_POST["submit"]) ) {
|
---|
| 460 |
|
---|
| 461 | $pyRegion = $_POST["pyRegion"];
|
---|
| 462 | $pyLanguage = $_POST["pyLanguage"];
|
---|
| 463 | $pyMeta = $_POST["pyMeta"];
|
---|
| 464 | $pyPageRank = $_POST["pyPageRank"];
|
---|
| 465 | $pyNumResults = (int)($_POST["pyNumResults"]);
|
---|
| 466 | $pyCompetitors = (array)($_POST["pyCompetitor"]);
|
---|
| 467 | $tmpCompetitors = array();
|
---|
| 468 |
|
---|
| 469 | foreach ( $pyCompetitors as $tmpCompetitor ) {
|
---|
| 470 | if ( trim($tmpCompetitor) !='')
|
---|
| 471 | $tmpCompetitors[] = $tmpCompetitor;
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if (count($tmpCompetitors) > 0) {
|
---|
| 475 | $this->adminOptions["pyCompetitors"] = implode(",", $tmpCompetitors);
|
---|
| 476 | } else {
|
---|
| 477 | $this->adminOptions["pyCompetitors"] = '';
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | $this->adminOptions["pyRegion"] = $pyRegion;
|
---|
| 481 | $this->adminOptions["pyLanguage"] = $pyLanguage;
|
---|
| 482 | $this->adminOptions["pyMeta"] = $pyMeta;
|
---|
| 483 | $this->adminOptions["pyPageRank"] = $pyPageRank;
|
---|
| 484 | $this->adminOptions["pyNumResults"] = $pyNumResults;
|
---|
| 485 |
|
---|
| 486 | $this->saveAdminOptions();
|
---|
| 487 | $message_id = (!empty($this->adminOptions)) ? 3 : 5;
|
---|
| 488 |
|
---|
| 489 | $tmpCompetitors = array();
|
---|
| 490 | } else {
|
---|
| 491 | $message_id = 0;
|
---|
| 492 | }
|
---|
| 493 | $submit_text = __('Save options »','position_yourself');
|
---|
| 494 |
|
---|
| 495 | $messages[1] = __('Options added.','position_yourself');
|
---|
| 496 | $messages[2] = __('Options deleted.','position_yourself');
|
---|
| 497 | $messages[3] = __('Options updated.','position_yourself');
|
---|
| 498 | $messages[4] = __('Options not added.','position_yourself');
|
---|
| 499 | $messages[5] = __('Options not updated.','position_yourself');
|
---|
| 500 | ?>
|
---|
| 501 |
|
---|
| 502 | <?php if ( isset($message_id) && 0 != $message_id ) : ?>
|
---|
| 503 | <div id="message" class="updated fade"><p><?php echo $messages[$message_id]; ?></p></div>
|
---|
| 504 | <?php endif; ?>
|
---|
| 505 |
|
---|
| 506 | <form method="post" action="admin.php?page=manage_options&action=modify">
|
---|
| 507 | <h3><?php _e('Google options','position_yourself'); ?></h3>
|
---|
| 508 | <table class="form-table" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 509 | <tr>
|
---|
| 510 | <th width="30%" scope="row" valign="top"><label for="pyRegion"><?php _e("Region",'position_yourself'); ?></label></th>
|
---|
| 511 | <td><input type="text" name="pyRegion" id="pyRegion" value="<?php echo $this->adminOptions["pyRegion"]; ?>" /></td>
|
---|
| 512 | </tr>
|
---|
| 513 | <tr>
|
---|
| 514 | <th width="30%" scope="row" valign="top"><label for="pyLanguage"><?php _e("Language",'position_yourself'); ?></label></th>
|
---|
| 515 | <td>
|
---|
| 516 | <select name="pyLanguage">
|
---|
| 517 | <option value="nl"<?php if ( "nl" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('Dutch','position_yourself'); ?></option>
|
---|
| 518 | <option value="fr"<?php if ( "fr" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('French','position_yourself'); ?></option>
|
---|
| 519 | <option value="en"<?php if ( "en" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('English','position_yourself'); ?></option>
|
---|
| 520 | <option value="de"<?php if ( "de" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('German','position_yourself'); ?></option>
|
---|
| 521 | <option value="it"<?php if ( "it" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('Italian','position_yourself'); ?></option>
|
---|
| 522 | <option value="es"<?php if ( "es" == $this->adminOptions["pyLanguage"] ) echo " selected=\"selected\""; ?>><?php _e('Spanish','position_yourself'); ?></option>
|
---|
| 523 | </select>
|
---|
| 524 | </td>
|
---|
| 525 | </tr>
|
---|
| 526 | <tr>
|
---|
| 527 | <th width="30%" scope="row" valign="top"><label for="pyMeta"><?php _e("Meta",'position_yourself'); ?></label></th>
|
---|
| 528 | <td><input type="text" name="pyMeta" id="pyMeta" class="wide" value="<?php echo $this->adminOptions["pyMeta"]; ?>" /></td>
|
---|
| 529 | </tr>
|
---|
| 530 | <tr>
|
---|
| 531 | <th width="30%" scope="row" valign="top"><label for="pyPageRank"><?php _e("PageRank",'position_yourself'); ?></label></th>
|
---|
| 532 | <td>
|
---|
| 533 | <select name="pyPageRank" id="pyPageRank">
|
---|
| 534 | <option value="no"<?php if ( "no" == $this->adminOptions["pyPageRank"] ) echo " selected=\"selected\""; ?>><?php _e('No','position_yourself'); ?></option>
|
---|
| 535 | <option value="yes"<?php if ( "yes" == $this->adminOptions["pyPageRank"] ) echo " selected=\"selected\""; ?>><?php _e('Yes','position_yourself'); ?></option>
|
---|
| 536 | </select>
|
---|
| 537 | <span class="sublabel"><?php _e('<strong>Notice:</strong> Enabling PageRank will take longer.','position_yourself'); ?></span>
|
---|
| 538 | </td>
|
---|
| 539 | </tr>
|
---|
| 540 | <tr>
|
---|
| 541 | <th width="30%" scope="row" valign="top"><label for="pyNumResults"><?php _e('Number of results','position_yourself'); ?></label></th>
|
---|
| 542 | <td>
|
---|
| 543 | <select name="pyNumResults" id="pyNumResults">
|
---|
| 544 | <option value="10"<?php if ( "10" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>10</option>
|
---|
| 545 | <option value="20"<?php if ( "20" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>20</option>
|
---|
| 546 | <option value="30"<?php if ( "30" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>30</option>
|
---|
| 547 | <option value="40"<?php if ( "40" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>40</option>
|
---|
| 548 | <option value="50"<?php if ( "50" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>50</option>
|
---|
| 549 | <option value="60"<?php if ( "60" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>60</option>
|
---|
| 550 | <option value="70"<?php if ( "70" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>70</option>
|
---|
| 551 | <option value="80"<?php if ( "80" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>80</option>
|
---|
| 552 | <option value="90"<?php if ( "90" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>90</option>
|
---|
| 553 | <option value="100"<?php if ( "100" == $this->adminOptions["pyNumResults"] ) echo " selected=\"selected\""; ?>>100</option>
|
---|
| 554 | </select></td>
|
---|
| 555 | </tr>
|
---|
| 556 | </table>
|
---|
| 557 |
|
---|
| 558 | <h3><?php _e('Competitors','position_yourself'); ?></h3>
|
---|
| 559 | <p><?php _e('<strong>Notice:</strong> To remove a competitor from the list, just leave the field empty and save the options.', 'position_yourself'); ?></p>
|
---|
| 560 | <p id="new_field_link"><a href="javascript:void(0)" onclick="addNewCompetitorField2();"><?php _e('Add competitor','position_yourself'); ?></a></p>
|
---|
| 561 | <table id="competitor-list" class="form-table" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 562 | <?php
|
---|
| 563 | $tmpCompetitors = '';
|
---|
| 564 | $pyCompetitors = array();
|
---|
| 565 |
|
---|
| 566 | if ($tmpCompetitors = $this->adminOptions["pyCompetitors"]) {
|
---|
| 567 | if ( preg_match("/,/", $tmpCompetitors) )
|
---|
| 568 | $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY);
|
---|
| 569 | else
|
---|
| 570 | array_push($pyCompetitors, $tmpCompetitors);
|
---|
| 571 |
|
---|
| 572 | $pyCompetitors = pyTrimArray($pyCompetitors);
|
---|
| 573 |
|
---|
| 574 | $num_competitors = 0;
|
---|
| 575 | foreach ( (array)$pyCompetitors as $tmpCompetitor ) {
|
---|
| 576 | $num_competitors++;
|
---|
| 577 | ?>
|
---|
| 578 | <tr>
|
---|
| 579 | <th width="30%" scope="row" valign="top"><label for="pyCompetitor[]"><?php _e('Competitor','position_yourself'); ?></label></th>
|
---|
| 580 | <td><input name="pyCompetitor[]" type="text" class="wide" value="<?php echo $tmpCompetitor; ?>" /></td>
|
---|
| 581 | </tr>
|
---|
| 582 |
|
---|
| 583 | <?php
|
---|
| 584 | }
|
---|
| 585 | } else {
|
---|
| 586 | ?>
|
---|
| 587 | <tr>
|
---|
| 588 | <th width="30%" scope="row" valign="top"><label for="pyCompetitor[]"><?php _e('Competitor','position_yourself'); ?></label></th>
|
---|
| 589 | <td><input name="pyCompetitor[]" class="wide" type="text" value="" /></td>
|
---|
| 590 | </tr>
|
---|
| 591 | <?php
|
---|
| 592 | }
|
---|
| 593 | ?>
|
---|
| 594 | </table>
|
---|
| 595 | <p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
|
---|
| 596 | </form>
|
---|
| 597 | <?php
|
---|
| 598 | } else {
|
---|
| 599 | // Modify google options link
|
---|
| 600 | $modify_options_url = get_option('siteurl') . '/wp-admin/admin.php?page=manage_options&action=modify';
|
---|
| 601 | ?>
|
---|
| 602 | <p><?php printf(__('<a href="%s" class="button">Modify options</a>','position_yourself'), $modify_options_url) ?></p>
|
---|
| 603 |
|
---|
| 604 | <h3><?php _e('Google options','position_yourself'); ?></h3>
|
---|
| 605 | <table class="form-table" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 606 | <tr>
|
---|
| 607 | <th width="33%" scope="row" valign="top"><?php _e("Region",'position_yourself'); ?></th>
|
---|
| 608 | <td width="67%"><?php echo $this->adminOptions["pyRegion"]; ?></td>
|
---|
| 609 | </tr>
|
---|
| 610 | <tr>
|
---|
| 611 | <th width="33%" scope="row" valign="top"><?php _e("Language",'position_yourself'); ?></th>
|
---|
| 612 | <td width="67%"><?php echo $this->adminOptions["pyLanguage"]; ?></td>
|
---|
| 613 | </tr>
|
---|
| 614 | <tr>
|
---|
| 615 | <th width="33%" scope="row" valign="top"><?php _e("Meta",'position_yourself'); ?></th>
|
---|
| 616 | <td width="67%"><?php echo $this->adminOptions["pyMeta"]; ?></td>
|
---|
| 617 | </tr>
|
---|
| 618 | <tr>
|
---|
| 619 | <th width="33%" scope="row" valign="top"><?php _e("PageRank",'position_yourself'); ?></th>
|
---|
| 620 | <td width="67%"><?php echo $this->adminOptions["pyPageRank"]; ?></td>
|
---|
| 621 | </tr>
|
---|
| 622 | <tr>
|
---|
| 623 | <th width="33%" scope="row" valign="top"><?php _e("Number of results",'position_yourself'); ?></th>
|
---|
| 624 | <td width="67%"><?php echo $this->adminOptions["pyNumResults"]; ?></td>
|
---|
| 625 | </tr>
|
---|
| 626 | </table>
|
---|
| 627 | <h3><?php _e('Competitors','position_yourself'); ?></h3>
|
---|
| 628 | <?php
|
---|
| 629 | $pyCompetitors = array();
|
---|
| 630 | $tmpCompetitors = '';
|
---|
| 631 | if ($tmpCompetitors = $this->adminOptions["pyCompetitors"]) {
|
---|
| 632 | if ( preg_match("/,/", $tmpCompetitors) )
|
---|
| 633 | $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY);
|
---|
| 634 | else
|
---|
| 635 | array_push($pyCompetitors, $tmpCompetitors);
|
---|
| 636 |
|
---|
| 637 | $pyCompetitors = pyTrimArray($pyCompetitors);
|
---|
| 638 | $num_competitors = 0;
|
---|
| 639 | ?>
|
---|
| 640 | <table id="competitor-list" class="form-table" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 641 | <?php
|
---|
| 642 | foreach ( (array)$pyCompetitors as $tmpCompetitor ) {
|
---|
| 643 | $num_competitors++;
|
---|
| 644 | ?>
|
---|
| 645 | <tr>
|
---|
| 646 | <th width="33%" scope="row" valign="top"><?php printf(__('Competitor %s:','position_yourself'), $num_competitors); ?></th>
|
---|
| 647 | <td width="67%"><?php echo $tmpCompetitor; ?></td>
|
---|
| 648 | </tr>
|
---|
| 649 | <?php
|
---|
| 650 | }
|
---|
| 651 | ?>
|
---|
| 652 | </table>
|
---|
| 653 | <?php
|
---|
| 654 | } else {
|
---|
| 655 | $this->message(__("You haven't added any competitors to track.",'position_yourself'));
|
---|
| 656 | }
|
---|
| 657 | ?>
|
---|
| 658 | <p><?php printf(__('<a href="%s" class="button">Modify options</a>','position_yourself'), $modify_options_url) ?></p>
|
---|
| 659 | <?php
|
---|
| 660 | }
|
---|
| 661 | ?>
|
---|
| 662 | </div>
|
---|
| 663 | <?php
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | /**
|
---|
| 667 | * Outputs the HTML for the keyword-tracking-management sub page.
|
---|
| 668 | */
|
---|
| 669 | function manage_keyword_tracking() {
|
---|
| 670 | global $wpdb;
|
---|
| 671 | ?>
|
---|
| 672 | <div class="wrap">
|
---|
| 673 | <h2><?php _e('Keyword tracking','position_yourself'); ?></h2>
|
---|
| 674 | <h3><?php _e('Keep track of your keywords','position_yourself'); ?></h3>
|
---|
| 675 | <?php
|
---|
| 676 |
|
---|
| 677 | if(isset($_GET["job_id"])) {
|
---|
| 678 | $job_id = attribute_escape($_GET["job_id"]);
|
---|
| 679 | $jobdatasql = "SELECT * FROM ".$wpdb->prefix."py_jobs WHERE ID = ".$job_id;
|
---|
| 680 | $job = $wpdb->get_row($jobdatasql);
|
---|
| 681 |
|
---|
| 682 | $matchessql = "SELECT ID FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$job->ID." AND position > 0 AND type = 'own'";
|
---|
| 683 | $num_matches = 0;
|
---|
| 684 | $num_matches = count($wpdb->get_results($matchessql));
|
---|
| 685 |
|
---|
| 686 | $kwdatasql = "SELECT * FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$job_id;
|
---|
| 687 | $keywords = $wpdb->get_results($kwdatasql);
|
---|
| 688 |
|
---|
| 689 | $counter = 0;
|
---|
| 690 | ?>
|
---|
| 691 | <table class="widefat" width="100%" border="0" cellspacing="0" cellpadding="0">
|
---|
| 692 | <tr>
|
---|
| 693 | <td colspan="2" scope="row" style="text-align: left;"><?php printf(__('Positioning found <span class="big">%d</span> matches.','position_yourself'), $num_matches); ?></td>
|
---|
| 694 | </tr>
|
---|
| 695 | <tr>
|
---|
| 696 | <td colspan="2" scope="row" style="height: 20px; text-align: left;"></td>
|
---|
| 697 | </tr>
|
---|
| 698 | <tr>
|
---|
| 699 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Started','position_yourself'); ?></th>
|
---|
| 700 | <td><?php echo date('d-m-Y, H:i:s', strtotime($job->start)); ?></td>
|
---|
| 701 | </tr>
|
---|
| 702 | <tr>
|
---|
| 703 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Ended','position_yourself'); ?></th>
|
---|
| 704 | <td><?php echo date('d-m-Y, H:i:s', strtotime($job->end)); ?></td>
|
---|
| 705 | </tr>
|
---|
| 706 | <tr>
|
---|
| 707 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Google Region','position_yourself'); ?></th>
|
---|
| 708 | <td>.<?php echo $job->region; ?></td>
|
---|
| 709 | </tr>
|
---|
| 710 | <tr>
|
---|
| 711 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Google Language','position_yourself'); ?></th>
|
---|
| 712 | <td><?php echo $job->language; ?></td>
|
---|
| 713 | </tr>
|
---|
| 714 | <tr>
|
---|
| 715 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Google Options','position_yourself'); ?></th>
|
---|
| 716 | <td><?php echo $job->meta; ?></td>
|
---|
| 717 | </tr>
|
---|
| 718 | <tr>
|
---|
| 719 | <th scope="row" style="width: 30%; text-align: left;"><?php _e('Google Number of results','position_yourself'); ?></th>
|
---|
| 720 | <td><?php echo $job->num_results; ?></td>
|
---|
| 721 | </tr>
|
---|
| 722 | </table>
|
---|
| 723 |
|
---|
| 724 | <table class="widefat" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 725 | <thead>
|
---|
| 726 | <tr>
|
---|
| 727 | <th scope="col" style="width: 30px; text-align: center"><?php echo "#"; ?></th>
|
---|
| 728 | <th scope="col"><?php _e("Keyword",'position_yourself'); ?></th>
|
---|
| 729 | <th scope="col"><?php _e("Position",'position_yourself'); ?></th>
|
---|
| 730 | <th scope="col"><?php _e("Result page",'position_yourself'); ?></th>
|
---|
| 731 | </tr>
|
---|
| 732 | </thead>
|
---|
| 733 | <tbody>
|
---|
| 734 | <?php
|
---|
| 735 | $site_url = get_option('siteurl');
|
---|
| 736 |
|
---|
| 737 | foreach ( (array) $keywords as $keyword ) {
|
---|
| 738 |
|
---|
| 739 | if ( $keyword->type == 'own' ) {
|
---|
| 740 | $counter++;
|
---|
| 741 | ?>
|
---|
| 742 | <tr>
|
---|
| 743 | <th scope="row" style="text-align: center"><?php echo $counter; ?></th>
|
---|
| 744 | <td><span class="keyword"><?php echo htmlspecialchars($keyword->keyword); ?></span></td>
|
---|
| 745 | <td style="text-align: left"><span class="position"><?php echo $keyword->position; ?></span></td>
|
---|
| 746 | <td style="text-align: left"><?php echo $keyword->result_url; ?></td>
|
---|
| 747 | </tr>
|
---|
| 748 | <?php
|
---|
| 749 | } elseif ( $keyword->type == 'competitor' ) {
|
---|
| 750 | ?>
|
---|
| 751 | <tr>
|
---|
| 752 | <th scope="row" style="text-align: center"></th>
|
---|
| 753 | <td><img src="<?php echo $site_url; ?>/wp-content/plugins/<?php plugin_basename( dirname( __FILE__ )) ?>/images/joinbottom.gif" alt="Competitor: " align="absbottom" /> <?php echo htmlspecialchars($keyword->match_url); ?></td>
|
---|
| 754 | <td style="text-align: left"><span class="position"><?php echo $keyword->position; ?></span></td>
|
---|
| 755 | <td style="text-align: left"><?php echo $keyword->result_url; ?></td>
|
---|
| 756 | </tr>
|
---|
| 757 | <?php
|
---|
| 758 | }
|
---|
| 759 | }
|
---|
| 760 | ?>
|
---|
| 761 | </tbody>
|
---|
| 762 | </table>
|
---|
| 763 | <?php
|
---|
| 764 | } else {
|
---|
| 765 | $jobsql = "SELECT * FROM ".$wpdb->prefix."py_jobs ORDER BY ID ASC";
|
---|
| 766 | $jobs = $wpdb->get_results($jobsql);
|
---|
| 767 | // show list of jobs
|
---|
| 768 | $num_jobs = count($jobs);
|
---|
| 769 | if ($num_jobs > 0) {
|
---|
| 770 | $counter = 0;
|
---|
| 771 | ?>
|
---|
| 772 | <table id="tracking-results" class="widefat" width="100%" cellspacing="2" cellpadding="5">
|
---|
| 773 | <thead>
|
---|
| 774 | <tr>
|
---|
| 775 | <th scope="col" style="text-align: center" width="30"><?php _e("ID",'position_yourself'); ?></th>
|
---|
| 776 | <th scope="col"><?php _e("Date-Time",'position_yourself'); ?></th>
|
---|
| 777 | <th scope="col"><?php _e("Region",'position_yourself'); ?></th>
|
---|
| 778 | <th scope="col"><?php _e("Language",'position_yourself'); ?></th>
|
---|
| 779 | <th scope="col"><?php _e("Number of results",'position_yourself'); ?></th>
|
---|
| 780 | <th scope="col"><?php _e("Matches",'position_yourself'); ?></th>
|
---|
| 781 | </tr>
|
---|
| 782 | </thead>
|
---|
| 783 | <tbody>
|
---|
| 784 | <?php
|
---|
| 785 | foreach ( (array) $jobs as $job ) {
|
---|
| 786 | $num_matches = 0;
|
---|
| 787 | $difference = 0;
|
---|
| 788 | $status = '';
|
---|
| 789 | //pyPre($job);
|
---|
| 790 | $positionsql = "SELECT ID FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$job->ID." AND position > 0 AND type = 'own'";
|
---|
| 791 | $matches = $wpdb->get_results($positionsql);
|
---|
| 792 | $num_matches = count($matches);
|
---|
| 793 |
|
---|
| 794 | if ($num_matches > $prev_num_matches) {
|
---|
| 795 | $difference = ' + '.(int)($num_matches - $prev_num_matches);
|
---|
| 796 | $status = 'up';
|
---|
| 797 | } elseif ($num_matches == $prev_num_matches) {
|
---|
| 798 | $difference = 0;
|
---|
| 799 | $status = 'stable';
|
---|
| 800 | } else {
|
---|
| 801 | $difference = ' - '.(int)($prev_num_matches - $num_matches);
|
---|
| 802 | $status = 'down';
|
---|
| 803 | }
|
---|
| 804 | $prev_num_matches = $num_matches;
|
---|
| 805 |
|
---|
| 806 | $job_url = get_option('siteurl').'/wp-admin/admin.php?page=manage_keyword_tracking&job_id='.$job->ID;
|
---|
| 807 |
|
---|
| 808 | if ($status != 'stable') {
|
---|
| 809 | $status_img = '<img src="'.get_option('siteurl').'/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/images/arrow_'.$status.'.png" alt="Status" />';
|
---|
| 810 | $difference = '<span class="small">'.$difference.'</span>';
|
---|
| 811 | } else {
|
---|
| 812 | $status_img = '';
|
---|
| 813 | $difference = '';
|
---|
| 814 | }
|
---|
| 815 |
|
---|
| 816 | if ($row_class == '')
|
---|
| 817 | $row_class = 'alternate';
|
---|
| 818 | else
|
---|
| 819 | $row_class = '';
|
---|
| 820 | ?>
|
---|
| 821 | <tr class="<?php echo $row_class; ?>">
|
---|
| 822 | <th scope="row" style="text-align: center"><?php echo $job->ID; ?></th>
|
---|
| 823 | <td><?php echo "<a href=\"".$job_url."\" title=\"".__("Get more information about this job.",'position_yourself')."\">".date('d-m-Y, h:i:s', strtotime($job->start))."</a>"; ?></td>
|
---|
| 824 | <td><?php echo $job->region; ?></td>
|
---|
| 825 | <td><?php echo $job->language; ?></td>
|
---|
| 826 | <td><?php echo $job->num_results; ?></td>
|
---|
| 827 | <td><?php echo $num_matches; ?> <?php echo $status_img.$difference; ?></td>
|
---|
| 828 | </tr>
|
---|
| 829 | <?php
|
---|
| 830 | }
|
---|
| 831 | ?>
|
---|
| 832 | </tbody>
|
---|
| 833 | </table>
|
---|
| 834 | <script language="javascript" type="text/javascript">
|
---|
| 835 | $(document).ready(function() {
|
---|
| 836 | $("#tracking-results").tablesorter( {sortList: [[0,1]]} );
|
---|
| 837 | });
|
---|
| 838 | </script>
|
---|
| 839 | <?php
|
---|
| 840 | } else {
|
---|
| 841 | $this->message(__("No jobs have already ran."));
|
---|
| 842 | }
|
---|
| 843 | }
|
---|
| 844 | ?>
|
---|
| 845 | </div>
|
---|
| 846 | <?php
|
---|
| 847 | }
|
---|
| 848 |
|
---|
| 849 | /**
|
---|
| 850 | * Put positioning results in DB
|
---|
| 851 | */
|
---|
| 852 | function process_results($positioner) {
|
---|
| 853 | global $wpdb;
|
---|
| 854 |
|
---|
| 855 | if ($positioner) {
|
---|
| 856 | // add new job to DB
|
---|
| 857 | $jobsql = "INSERT INTO ".$wpdb->prefix."py_jobs (start, end, region, language, meta, num_results) VALUES ('".date('Y-m-d H:i:s', strtotime($positioner->start))."', '".date('Y-m-d H:i:s', strtotime($positioner->end))."', '".$wpdb->escape($positioner->region)."', '".$wpdb->escape($positioner->language)."', '".$wpdb->escape($positioner->meta)."', ".$positioner->num_results.")";
|
---|
| 858 |
|
---|
| 859 | $wpdb->show_errors();
|
---|
| 860 | $wpdb->query($jobsql);
|
---|
| 861 | $wpdb->hide_errors();
|
---|
| 862 | $job_id = $wpdb->insert_id;
|
---|
| 863 |
|
---|
| 864 | // process googlequeries
|
---|
| 865 | if ( is_array($positioner->queries) ) {
|
---|
| 866 | foreach ( (array)$positioner->queries as $query ) {
|
---|
| 867 |
|
---|
| 868 | // add keyword to DB
|
---|
| 869 | $kwsql = "INSERT INTO ".$wpdb->prefix."py_jobs_data (job_id, keyword, position, type, match_url, result_url) VALUES (".$job_id.", '".$wpdb->escape($query->keyword)."', ".$query->top_position.", 'own', '".$wpdb->escape(get_option('siteurl'))."', '".$wpdb->escape($query->top_url)."')";
|
---|
| 870 |
|
---|
| 871 | $wpdb->show_errors();
|
---|
| 872 | $wpdb->query($kwsql);
|
---|
| 873 | $wpdb->hide_errors();
|
---|
| 874 |
|
---|
| 875 | if ( count($query->competitors) > 0 ) {
|
---|
| 876 | foreach( (array)$query->competitors as $competitor => $results) {
|
---|
| 877 |
|
---|
| 878 | $top = $query->find_top_competitor_position($results);
|
---|
| 879 |
|
---|
| 880 | // add keyword to DB
|
---|
| 881 | $kwsql = "INSERT INTO ".$wpdb->prefix."py_jobs_data (job_id, keyword, position, type, match_url, result_url) VALUES (".$job_id.", '".$wpdb->escape($query->keyword)."', ".$top["position"].", 'competitor', '".$wpdb->escape($competitor)."', '".$wpdb->escape($top["url"])."')";
|
---|
| 882 |
|
---|
| 883 | $wpdb->show_errors();
|
---|
| 884 | $wpdb->query($kwsql);
|
---|
| 885 | $wpdb->hide_errors();
|
---|
| 886 | }
|
---|
| 887 | }
|
---|
| 888 | }
|
---|
| 889 | }
|
---|
| 890 | return $job_id;
|
---|
| 891 | }
|
---|
| 892 | return 0;
|
---|
| 893 | }
|
---|
| 894 |
|
---|
| 895 | /**
|
---|
| 896 | * Load scripts
|
---|
| 897 | */
|
---|
| 898 | function add_admin_scripts() {
|
---|
| 899 | wp_enqueue_script("fat");
|
---|
| 900 | wp_enqueue_script('py_jquery', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/jquery-1.2.3.js', false, '1.2.3');
|
---|
| 901 | wp_enqueue_script('tablesorter', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/jquery.tablesorter.min.js', array('py_jquery') , '2.0.3');
|
---|
| 902 | wp_enqueue_script('py_scripts', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/script.js', false , '1.0');
|
---|
| 903 | }
|
---|
| 904 |
|
---|
| 905 | /**
|
---|
| 906 | * Adds a link to the stylesheet to the header
|
---|
| 907 | */
|
---|
| 908 | function add_admin_css() {
|
---|
| 909 | echo '<link rel="stylesheet" href="'.get_bloginfo('url').'/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/css/style.css" type="text/css" media="screen" />';
|
---|
| 910 | }
|
---|
| 911 |
|
---|
| 912 |
|
---|
| 913 |
|
---|
| 914 | /**
|
---|
| 915 | * display functions (error->red / message->yellow / success->green)
|
---|
| 916 | */
|
---|
| 917 | function error($message) {
|
---|
| 918 | echo "<div class=\"error\">\n";
|
---|
| 919 | echo "<p>".$message."</p>\n";
|
---|
| 920 | echo "</div>\n";
|
---|
| 921 | }
|
---|
| 922 | function message($message) {
|
---|
| 923 | echo "<div class=\"message\">\n";
|
---|
| 924 | echo "<p>".$message."</p>\n";
|
---|
| 925 | echo "</div>\n";
|
---|
| 926 | }
|
---|
| 927 | function success($message) {
|
---|
| 928 | echo "<div class=\"success\">\n";
|
---|
| 929 | echo "<p>".$message."</p>\n";
|
---|
| 930 | echo "</div>\n";
|
---|
| 931 | }
|
---|
| 932 |
|
---|
| 933 | /**
|
---|
| 934 | * Delays script execution for x.xx number of seconds.
|
---|
| 935 | */
|
---|
| 936 | function sleepr($seconds) {
|
---|
| 937 | usleep(floor($seconds*1000000));
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | /**
|
---|
| 941 | * Install function
|
---|
| 942 | */
|
---|
| 943 | function positionyourself_install() {
|
---|
| 944 | global $wpdb;
|
---|
| 945 |
|
---|
| 946 |
|
---|
| 947 | // only run installation if not installed
|
---|
| 948 | $py_jobs_data = $wpdb->get_var("SHOW TABLES LIKE `".$wpdb->prefix."py_jobs_data`");
|
---|
| 949 | $py_jobs = $wpdb->get_var("SHOW TABLES LIKE `".$wpdb->prefix."py_jobs`");
|
---|
| 950 |
|
---|
| 951 | if( $py_jobs_data != $wpdb->prefix."py_jobs_data" || $py_jobs != $wpdb->prefix."py_jobs") {
|
---|
| 952 |
|
---|
| 953 | require_once(ABSPATH . "wp-admin/upgrade-functions.php");
|
---|
| 954 | // create keyword table
|
---|
| 955 | $structure_keywords = "CREATE TABLE `".$wpdb->prefix."py_jobs_data` (
|
---|
| 956 | `ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
---|
| 957 | `job_id` BIGINT NOT NULL ,
|
---|
| 958 | `keyword` VARCHAR( 255 ) NOT NULL ,
|
---|
| 959 | `position` INT NOT NULL DEFAULT '0',
|
---|
| 960 | `type` ENUM( 'own', 'competitor' ) NOT NULL ,
|
---|
| 961 | `match_url` VARCHAR( 255 ) NOT NULL ,
|
---|
| 962 | `result_url` TEXT NOT NULL
|
---|
| 963 | );";
|
---|
| 964 | // add keyword table to DB
|
---|
| 965 | dbDelta($structure_keywords);
|
---|
| 966 | // create jobs table
|
---|
| 967 | $structure_jobs = "CREATE TABLE `".$wpdb->prefix."py_jobs` (
|
---|
| 968 | `ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
---|
| 969 | `start` DATETIME NOT NULL ,
|
---|
| 970 | `end` DATETIME NOT NULL ,
|
---|
| 971 | `region` VARCHAR( 10 ) NOT NULL DEFAULT 'com',
|
---|
| 972 | `language` VARCHAR( 10 ) NOT NULL DEFAULT 'en',
|
---|
| 973 | `meta` VARCHAR( 255 ) NOT NULL ,
|
---|
| 974 | `num_results` INT NOT NULL DEFAULT '30'
|
---|
| 975 | );";
|
---|
| 976 | // add jobs table to DB
|
---|
| 977 | dbDelta($structure_jobs);
|
---|
| 978 |
|
---|
| 979 | }
|
---|
| 980 |
|
---|
| 981 | $plugin_db_version = "1.2";
|
---|
| 982 | $installed_ver = get_option( "position_yourself_db_version" );
|
---|
| 983 | // Only run installation if previous version installed
|
---|
| 984 | if ($installed_ver === false || $installed_ver != $plugin_db_version) {
|
---|
| 985 | // add a database version number for future upgrade purposes
|
---|
| 986 | update_option("position_yourself_db_version", $plugin_db_version);
|
---|
| 987 | }
|
---|
| 988 | }
|
---|
| 989 | }
|
---|
| 990 | }
|
---|
| 991 |
|
---|
| 992 | include(ABSPATH.'wp-includes/class-snoopy.php');
|
---|
| 993 | //instantiate the class
|
---|
| 994 | if (class_exists('positionyourself') && class_exists('Snoopy')) {
|
---|
| 995 | include(dirname(__FILE__).'/includes/classes.php');
|
---|
| 996 | include(dirname(__FILE__).'/includes/functions.php');
|
---|
| 997 | $snoopy = new Snoopy;
|
---|
| 998 | $positionyourself = new positionyourself();
|
---|
| 999 | }
|
---|
| 1000 | ?> |
---|