__construct();} /** * PHP 5 Constructor */ function __construct() { register_activation_hook(__FILE__,array(&$this,'positionyourself_install')); if (is_admin()) { add_action("admin_head", array(&$this, "add_admin_css")); add_action("admin_menu", array(&$this, "add_admin_pages")); add_action("init", array(&$this, "add_admin_scripts")); } $this->adminOptions = $this->getAdminOptions(); $py_locale = get_locale(); $py_mofile = dirname(__FILE__) . "/languages/position_yourself-".$py_locale.".mo"; load_textdomain("position_yourself", $py_mofile); } /** * Retrieves the options from the database. * @return array */ function getAdminOptions() { $adminOptions = array( "pyKeywords" => "", "pyCompetitors" => "", "pyRegion" => "be", "pyLanguage" => "nl", "pyMeta" => "", "pyPageRank" => "no", "pyNumResults" => 30 ); $savedOptions = get_option($this->adminOptionsName); if (!empty($savedOptions)) { foreach ($savedOptions as $key => $option) { $adminOptions[$key] = $option; } } update_option($this->adminOptionsName, $adminOptions); return $adminOptions; } /** * Saves the Position Yourself options to the database. * @return */ function saveAdminOptions() { update_option($this->adminOptionsName, $this->adminOptions); } /** * Adds Position Yourself to admin menu. * @return */ function add_admin_pages() { add_menu_page( __('Position Yourself','position_yourself'), __('Position Yourself','position_yourself'), 10, __FILE__, array(&$this,"output_positioner") ); add_submenu_page( __FILE__, __('Manage keywords','position_yourself'), __('Manage keywords','position_yourself'), 10, "manage_keywords", array(&$this,"manage_keywords") ); add_submenu_page( __FILE__, __('Manage options','position_yourself'), __('Manage options','position_yourself'), 10, "manage_options", array(&$this,"manage_options") ); add_submenu_page( __FILE__, __("Track positions",'position_yourself'), __("Track positions",'position_yourself'), 10, "manage_keyword_tracking", array(&$this,"manage_keyword_tracking") ); } /** * Outputs the sourcecode for the admin page. * @return */ function output_positioner() { global $wpdb; ?>

adminOptions["pyKeywords"] ) { $tmpKeywords = $this->adminOptions["pyKeywords"]; if ( preg_match("/,/", $tmpKeywords) ) $pyKeywords = preg_split('/,/', $tmpKeywords, -1, PREG_SPLIT_NO_EMPTY); else array_push($pyKeywords, $tmpKeywords); $pyKeywords = pyTrimArray($pyKeywords); $pyNumKw = count($pyKeywords); } else { $pyNumKw = 0; } if ( 0 != $pyNumKw ) { $action = attribute_escape($_GET["action"]); if ( "run" == $action ) { // start timer timer_start(); // start buffering the output for later ob_start(); // set parameters from options $pyRegion = $this->adminOptions["pyRegion"]; $pyLanguage = $this->adminOptions["pyLanguage"]; $pyMeta = ( isset($this->adminOptions["pyMeta"]) && '' != $this->adminOptions["pyMeta"] ) ? "&meta=restrict%3D".$this->adminOptions["pyMeta"] : ""; $pyPageRank = $this->adminOptions["pyPageRank"]; $pyNumResults = $this->adminOptions["pyNumResults"]; // domains $pyDomain = get_option('siteurl'); // competitors $tmpCompetitors = $this->adminOptions["pyCompetitors"]; //$tmpCompetitors = "http://en.wikipedia.org,http://www.google.be,http://www.queromedia.be"; if ( preg_match("/,/", $tmpCompetitors) ) $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY); else array_push($pyCompetitors, $tmpCompetitors); $pyCompetitors = pyTrimArray($pyCompetitors); // total number of matches $pyTotalMatches = 0; $oriKeywords = $pyKeywords; $positioner = new Positioner(); $positioner->start = date('d-m-Y, H:i:s'); $positioner->region = $pyRegion; $positioner->language = $pyLanguage; $positioner->meta = $pyMeta; $positioner->num_results = $pyNumResults; // Start if ( '' == $pyKeywords ) { $this->error(__('You have not yet added any keywords.','position_yourself')); exit(); } if ( count($pyKeywords) > 0 ) { // begin foreach foreach ( (array) $pyKeywords as $tmpKeyword ) { //echo "

$tmpKeyword

"; $query = new GoogleQuery($tmpKeyword, $pyRegion, $pyLanguage, $pyNumResults); // get own matches $query->set_results(); $query->find_matches($query->results, $pyDomain); $query->find_top_position(); // get competitor matches if (count($pyCompetitors) > 0 ) { foreach ( (array)$pyCompetitors as $tmpCompetitor ) { if ($tmpCompetitor) $competitor_matches[$tmpCompetitor] = $query->find_matches($query->results, $tmpCompetitor); } $query->competitors = (array)$competitor_matches; } $positioner->queries[] = $query; $timeOut = (int)((rand()%4) + 1); $this->sleepr($timeOut); } } $positioner->end = date('d-m-Y, H:i:s'); $job_id = $this->process_results($positioner); if ($job_id != 0) { $job_url = get_option('siteurl').'/wp-admin/admin.php?page=manage_keyword_tracking&job_id='.$job_id; echo "
\n"; printf(__('Your keywords have been successfully positioned! Click here for the detailed report.','position_yourself'), $job_url); echo "
\n"; } else { $this->error(__("Your keywords could not be positioned. Please try again.",'position_yourself')); } } else { $jobdatasql = "SELECT ID FROM ".$wpdb->prefix."py_jobs ORDER BY ID DESC LIMIT 1"; $most_recent_job = $wpdb->get_var($jobdatasql); $counter = 0; $position_url = get_option('siteurl') .'/wp-admin/admin.php?page='.plugin_basename( dirname( __FILE__ )).'/position_yourself.php&action=run'; $track_positions_url = get_option('siteurl') . '/wp-admin/admin.php?page=manage_keyword_tracking'; ?>

Position me. Afterwards you can view your detailed report under the Track positions page.','position_yourself'), $position_url, $track_positions_url); ?>

Position me','position_yourself'), $position_url); ?>

prefix."py_jobs_data WHERE job_id = ".$most_recent_job." AND type = 'own' AND keyword = '".$tmpKeyword."'"; $last_top_position = $wpdb->get_var($last_top_position_sql); if ($row_class == '') $row_class = 'alternate'; else $row_class = ''; ?>

Position me','position_yourself'), $position_url); ?>

Modify keywords','position_yourself'), $position_url); ?>

adminOptions["pyKeywords"] = $pyKeywords; $this->saveAdminOptions(); $message_id = ( !empty($this->adminOptions) ) ? 3: 5; } else { $message_id = 0; } $submit_text = __('Save keywords »','position_yourself'); $messages[1] = __('Keywords added.','position_yourself'); $messages[2] = __('Keywords deleted.','position_yourself'); $messages[3] = __('Keywords updated.','position_yourself'); $messages[4] = __('Keywords not added.','position_yourself'); $messages[5] = __('Keywords not updated.','position_yourself'); $pyKeywords = $this->adminOptions["pyKeywords"]; if ( '' != $pyKeywords ) { $pyNumKw = count(explode(",",$pyKeywords)); $pyKeywords = explode(",",$pyKeywords); $pyKeywordstr = ''; foreach ( (array) $pyKeywords as $pyKeyword ) { $pyKeywordstr .= trim($pyKeyword)."\n"; } $pyKeywordsstr = substr($pyKeywordstr,-1,2); } else { $pyNumKw = 0; $pyKeywords = ''; } ?>

modify you keywords you want to track.','position_yourself'), $modify_kw_url); ?>

Modify keywords','position_yourself'), $modify_kw_url) ?>

adminOptions["pyKeywords"]; if ( '' != $pyKeywords ) { $pyNumKw = count(explode(',',$pyKeywords)); $pyKeywords = explode(',',$pyKeywords); } else { $pyNumKw = 0; $pyKeywords = array(); } if ( 0 != $pyNumKw ) { // show list of keywords $counter = 0; ?>

Modify keywords','position_yourself'), $modify_kw_url) ?>

0) { $this->adminOptions["pyCompetitors"] = implode(",", $tmpCompetitors); } else { $this->adminOptions["pyCompetitors"] = ''; } $this->adminOptions["pyRegion"] = $pyRegion; $this->adminOptions["pyLanguage"] = $pyLanguage; $this->adminOptions["pyMeta"] = $pyMeta; $this->adminOptions["pyPageRank"] = $pyPageRank; $this->adminOptions["pyNumResults"] = $pyNumResults; $this->saveAdminOptions(); $message_id = (!empty($this->adminOptions)) ? 3 : 5; $tmpCompetitors = array(); } else { $message_id = 0; } $submit_text = __('Save options »','position_yourself'); $messages[1] = __('Options added.','position_yourself'); $messages[2] = __('Options deleted.','position_yourself'); $messages[3] = __('Options updated.','position_yourself'); $messages[4] = __('Options not added.','position_yourself'); $messages[5] = __('Options not updated.','position_yourself'); ?>

" />
" />
Notice: Enabling PageRank will take longer.','position_yourself'); ?>

Notice: To remove a competitor from the list, just leave the field empty and save the options.', 'position_yourself'); ?>

adminOptions["pyCompetitors"]) { if ( preg_match("/,/", $tmpCompetitors) ) $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY); else array_push($pyCompetitors, $tmpCompetitors); $pyCompetitors = pyTrimArray($pyCompetitors); $num_competitors = 0; foreach ( (array)$pyCompetitors as $tmpCompetitor ) { $num_competitors++; ?>

Modify options','position_yourself'), $modify_options_url) ?>

adminOptions["pyRegion"]; ?>
adminOptions["pyLanguage"]; ?>
adminOptions["pyMeta"]; ?>
adminOptions["pyPageRank"]; ?>
adminOptions["pyNumResults"]; ?>

adminOptions["pyCompetitors"]) { if ( preg_match("/,/", $tmpCompetitors) ) $pyCompetitors = preg_split('/,/', $tmpCompetitors, -1, PREG_SPLIT_NO_EMPTY); else array_push($pyCompetitors, $tmpCompetitors); $pyCompetitors = pyTrimArray($pyCompetitors); $num_competitors = 0; ?>
message(__("You haven't added any competitors to track.",'position_yourself')); } ?>

Modify options','position_yourself'), $modify_options_url) ?>

prefix."py_jobs WHERE ID = ".$job_id; $job = $wpdb->get_row($jobdatasql); $matchessql = "SELECT ID FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$job->ID." AND position > 0 AND type = 'own'"; $num_matches = 0; $num_matches = count($wpdb->get_results($matchessql)); $kwdatasql = "SELECT * FROM ".$wpdb->prefix."py_jobs_data WHERE job_id = ".$job_id; $keywords = $wpdb->get_results($kwdatasql); $counter = 0; ?>
%d matches.','position_yourself'), $num_matches); ?>
start)); ?>
end)); ?>
.region; ?>
language; ?>
meta; ?>
num_results; ?>
type == 'own' ) { $counter++; ?> type == 'competitor' ) { ?>
keyword); ?> position; ?> result_url; ?>
Competitor: match_url); ?> position; ?> result_url; ?>
prefix."py_jobs ORDER BY ID ASC"; $jobs = $wpdb->get_results($jobsql); // show list of jobs $num_jobs = count($jobs); if ($num_jobs > 0) { $counter = 0; ?> prefix."py_jobs_data WHERE job_id = ".$job->ID." AND position > 0 AND type = 'own'"; $matches = $wpdb->get_results($positionsql); $num_matches = count($matches); if ($num_matches > $prev_num_matches) { $difference = ' + '.(int)($num_matches - $prev_num_matches); $status = 'up'; } elseif ($num_matches == $prev_num_matches) { $difference = 0; $status = 'stable'; } else { $difference = ' - '.(int)($prev_num_matches - $num_matches); $status = 'down'; } $prev_num_matches = $num_matches; $job_url = get_option('siteurl').'/wp-admin/admin.php?page=manage_keyword_tracking&job_id='.$job->ID; if ($status != 'stable') { $status_img = 'Status'; $difference = ''.$difference.''; } else { $status_img = ''; $difference = ''; } if ($row_class == '') $row_class = 'alternate'; else $row_class = ''; ?>
ID; ?> ".date('d-m-Y, h:i:s', strtotime($job->start)).""; ?> region; ?> language; ?> num_results; ?>  
message(__("No jobs have already ran.")); } } ?>
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.")"; $wpdb->show_errors(); $wpdb->query($jobsql); $wpdb->hide_errors(); $job_id = $wpdb->insert_id; // process googlequeries if ( is_array($positioner->queries) ) { foreach ( (array)$positioner->queries as $query ) { // add keyword to DB $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)."')"; $wpdb->show_errors(); $wpdb->query($kwsql); $wpdb->hide_errors(); if ( count($query->competitors) > 0 ) { foreach( (array)$query->competitors as $competitor => $results) { $top = $query->find_top_competitor_position($results); // add keyword to DB $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"])."')"; $wpdb->show_errors(); $wpdb->query($kwsql); $wpdb->hide_errors(); } } } } return $job_id; } return 0; } /** * Load scripts */ function add_admin_scripts() { wp_enqueue_script("fat"); wp_enqueue_script('py_jquery', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/jquery-1.2.3.js', false, '1.2.3'); wp_enqueue_script('tablesorter', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/jquery.tablesorter.min.js', array('py_jquery') , '2.0.3'); wp_enqueue_script('py_scripts', '/wp-content/plugins/'.plugin_basename( dirname( __FILE__ )) .'/js/script.js', false , '1.0'); } /** * Adds a link to the stylesheet to the header */ function add_admin_css() { echo ''; } /** * display functions (error->red / message->yellow / success->green) */ function error($message) { echo "
\n"; echo "

".$message."

\n"; echo "
\n"; } function message($message) { echo "
\n"; echo "

".$message."

\n"; echo "
\n"; } function success($message) { echo "
\n"; echo "

".$message."

\n"; echo "
\n"; } /** * Delays script execution for x.xx number of seconds. */ function sleepr($seconds) { usleep(floor($seconds*1000000)); } /** * Install function */ function positionyourself_install() { global $wpdb; // only run installation if not installed $py_jobs_data = $wpdb->get_var("SHOW TABLES LIKE `".$wpdb->prefix."py_jobs_data`"); $py_jobs = $wpdb->get_var("SHOW TABLES LIKE `".$wpdb->prefix."py_jobs`"); if( $py_jobs_data != $wpdb->prefix."py_jobs_data" || $py_jobs != $wpdb->prefix."py_jobs") { require_once(ABSPATH . "wp-admin/upgrade-functions.php"); // create keyword table $structure_keywords = "CREATE TABLE `".$wpdb->prefix."py_jobs_data` ( `ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY , `job_id` BIGINT NOT NULL , `keyword` VARCHAR( 255 ) NOT NULL , `position` INT NOT NULL DEFAULT '0', `type` ENUM( 'own', 'competitor' ) NOT NULL , `match_url` VARCHAR( 255 ) NOT NULL , `result_url` TEXT NOT NULL );"; // add keyword table to DB dbDelta($structure_keywords); // create jobs table $structure_jobs = "CREATE TABLE `".$wpdb->prefix."py_jobs` ( `ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY , `start` DATETIME NOT NULL , `end` DATETIME NOT NULL , `region` VARCHAR( 10 ) NOT NULL DEFAULT 'com', `language` VARCHAR( 10 ) NOT NULL DEFAULT 'en', `meta` VARCHAR( 255 ) NOT NULL , `num_results` INT NOT NULL DEFAULT '30' );"; // add jobs table to DB dbDelta($structure_jobs); } $plugin_db_version = "1.2"; $installed_ver = get_option( "position_yourself_db_version" ); // Only run installation if previous version installed if ($installed_ver === false || $installed_ver != $plugin_db_version) { // add a database version number for future upgrade purposes update_option("position_yourself_db_version", $plugin_db_version); } } } } include(ABSPATH.'wp-includes/class-snoopy.php'); //instantiate the class if (class_exists('positionyourself') && class_exists('Snoopy')) { include(dirname(__FILE__).'/includes/classes.php'); include(dirname(__FILE__).'/includes/functions.php'); $snoopy = new Snoopy; $positionyourself = new positionyourself(); } ?>