prefix . "searchmeter"; if ($wpdb->get_var("show tables like '$table_name'") != $table_name) { require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); dbDelta(" CREATE TABLE `{$table_name}` ( `terms` VARCHAR(50) NOT NULL, `date` DATE NOT NULL, `count` INT(11) NOT NULL, `last_hits` INT(11) NOT NULL, PRIMARY KEY (`terms`,`date`) ) CHARACTER SET utf8 COLLATE utf8_general_ci; "); } } function tguy_sm_create_recent_table() { // Create the table if not already there. global $wpdb; $table_name = $wpdb->prefix . "searchmeter_recent"; if ($wpdb->get_var("show tables like '$table_name'") != $table_name) { require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); dbDelta(" CREATE TABLE `{$table_name}` ( `terms` VARCHAR(50) NOT NULL, `datetime` DATETIME NOT NULL, `hits` INT(11) NOT NULL, `details` TEXT NOT NULL, KEY `datetimeindex` (`datetime`) ) CHARACTER SET utf8 COLLATE utf8_general_ci; "); } } //////// Permissions function smcln_sm_can_view_stats() { $options = get_option('tguy_search_meter'); $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability'); if ($view_stats_capability == '') { $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY; } return current_user_can($view_stats_capability); } //////// Dashboard widget add_action('wp_dashboard_setup', 'smcln_sm_dashboard'); // Add the widget to the dashboard function smcln_sm_dashboard() { if (smcln_sm_can_view_stats()) { wp_add_dashboard_widget( 'dashboard_search_meter', __('Search Meter', 'search-meter'), 'smcln_sm_summary'); } } // Render the summary widget function smcln_sm_summary() { ?>

query( "DELETE FROM `{$wpdb->prefix}searchmeter` WHERE `date` < DATE_SUB( CURDATE() , INTERVAL 30 DAY)"); echo "\n"; ?>

' . __('Term', 'search-meter') . ''); echo ' '; printf(__('%s is the number of times the term was searched for.', 'search-meter'), '' . __('Searches', 'search-meter') . ''); echo ' '; printf(__('%s is the number of posts that were returned from the last search for that term.', 'search-meter'), '' . __('Results', 'search-meter') . ''); ?>

' . __('Search Meter Settings', 'search-meter') . '') ?>

' . __('Search Meter home page', 'search-meter') . ''); echo ' '; _e('There you can offer suggestions, request new features or report problems.', 'search-meter'); ?>

get_results( "SELECT `terms`, SUM( `count` ) AS countsum, SUBSTRING( MAX( CONCAT( `date` , ' ', `last_hits` ) ) , 12 ) AS hits FROM `{$wpdb->prefix}searchmeter` WHERE DATE_SUB( CURDATE( ) , INTERVAL $days DAY ) <= `date` GROUP BY `terms` $hits_selector ORDER BY countsum DESC, `terms` ASC LIMIT 20"); if (count($results)) { ?>
terms) ?> countsum ?> hits ?>

' . __('Term', 'search-meter') . ''); echo ' '; printf(__('%s is the number of posts that were returned from the search.', 'search-meter'), '' . __('Results', 'search-meter') . ''); ?>

prefix}searchmeter_recent` ORDER BY `datetime` DESC, `terms` ASC LIMIT $max_lines"; $results = $wpdb->get_results($query); if (count($results)) { ?>
datetime) ?> terms) ?> hits ?> ", htmlspecialchars($result->details)) ?>

' . __('Search Meter Settings', 'search-meter') . ''); ?>

' . __('Search Meter home page', 'search-meter') . ''); echo ' '; _e('There you can offer suggestions, request new features or report problems.', 'search-meter'); ?>

' . __('Settings', 'search-meter') . ''; array_unshift($links, $settings_link); } return $links; } //////// Options page function tguy_sm_options_page() { if (isset($_POST['submitted'])) { check_admin_referer('search-meter-update-options_all'); $options = get_option('tguy_search_meter'); $options['sm_view_stats_capability'] = ($_POST['sm_view_stats_capability']); $sm_filter_words = $_POST['sm_filter_words']; if (get_magic_quotes_gpc()) { $sm_filter_words = stripslashes($sm_filter_words); } $options['sm_filter_words'] = preg_replace('/\\s+/', ' ', trim($sm_filter_words)); $options['sm_ignore_admin_search'] = (bool)tguy_sm_array_value($_POST, 'sm_ignore_admin_search'); $options['sm_details_verbose'] = (bool)tguy_sm_array_value($_POST, 'sm_details_verbose'); $options['sm_disable_donation'] = (bool)tguy_sm_array_value($_POST, 'sm_disable_donation'); update_option('tguy_search_meter', $options); echo '

' . __('Plugin settings saved.', 'search-meter') . '

'; } else if (isset($_POST['tguy_sm_reset'])) { check_admin_referer('search-meter-reset-stats'); tguy_sm_reset_stats(); echo '

' . __('Statistics have been reset.', 'search-meter') . '

'; } $options = get_option('tguy_search_meter'); $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability'); if ($view_stats_capability == '') { $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY; } ?>



' . __('Search Meter Dashboard', 'search-meter') . '') ?>

' . __('Search Meter home page', 'search-meter') . ''); echo ' '; _e('There you can offer suggestions, request new features or report problems.', 'search-meter'); ?>

query("DELETE FROM `{$wpdb->prefix}searchmeter`"); $wpdb->query("DELETE FROM `{$wpdb->prefix}searchmeter_recent`"); } // Service a download request if there is one function tguy_sm_download() { if (isset($_POST['tguy_sm_download_summary'])) { check_admin_referer('search-meter-download'); tguy_sm_download_summary(); } else if (isset($_POST['tguy_sm_download_individual'])) { check_admin_referer('search-meter-download'); tguy_sm_download_individual(); } } function tguy_sm_download_summary() { global $wpdb; $results = $wpdb->get_results( "SELECT `terms`, `count`, `date`, `last_hits` FROM `{$wpdb->prefix}searchmeter` ORDER BY `date` ASC, `terms` ASC"); $results_array = array(array(__('Date', 'search-meter'), __('Search terms', 'search-meter'), __('Searches', 'search-meter'), __('Results', 'search-meter'))); foreach ($results as $result) { $results_array[] = array(tguy_sm_format_utc_as_local('Y-m-d', $result->date), $result->terms, $result->count, $result->last_hits); } /* translators: base filename for downloaded summary - lowercase letters, digits, dashes only */ tguy_sm_download_to_csv($results_array, __('search-summary', 'search-meter')); } function tguy_sm_download_individual() { global $wpdb; $results = $wpdb->get_results( "SELECT `terms`, `datetime`, `hits`, `details` FROM `{$wpdb->prefix}searchmeter_recent` ORDER BY `datetime` ASC"); $results_array = array(array(__('Date', 'search-meter'), __('Search terms', 'search-meter'), __('Results', 'search-meter'), __('Details', 'search-meter'))); foreach ($results as $result) { $results_array[] = array(tguy_sm_format_utc_as_local('Y-m-d H:i:s', $result->datetime), $result->terms, $result->hits, $result->details); } /* translators: base filename for downloaded searches - lowercase letters, digits, dashes only */ tguy_sm_download_to_csv($results_array, __('recent-searches', 'search-meter')); } // Similar to PHP date(), but the timestamp is a string in UTC, and we return a string in Wordpress time zone function tguy_sm_format_utc_as_local($format, $timestamp = 'now') { $tz = get_option('timezone_string'); $datetime = date_create($timestamp, new DateTimeZone('UTC')); if ($tz) { $datetime->setTimezone(new DateTimeZone($tz)); return $datetime->format($format); } else { return gmdate($format, $datetime->getTimestamp() + get_option('gmt_offset') * HOUR_IN_SECONDS); } } function tguy_sm_download_to_csv($array, $filenamebase) { header('Last-Modified: ' . current_time('D, d M Y H:i:s', true) . ' GMT'); header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="'.$filenamebase.'-'.current_time('Ymd-His').'.csv";'); // see http://www.php.net/manual/en/wrappers.php.php#refsect2-wrappers.php-unknown-unknown-unknown-descriptioq $f = fopen('php://output', 'w'); foreach ($array as $line) { fputcsv($f, $line); } exit; } function tguy_sm_show_donation_message() { ?>


Donate button. You can also send Bitcoins to address %s. Thanks! EOS , 'search-meter' ), '1542gqyprvQd7gwvtZZ4x25cPeGWVKg45x') ?>