/**
  * Adds a new column to the Posts management panel
  */
 public static function add_post_column($_column_name, $_post_id)
 {
     if ('wp-slimstat' != $_column_name) {
         return;
     }
     include_once dirname(__FILE__) . '/view/wp-slimstat-reports.php';
     wp_slimstat_reports::init();
     if (wp_slimstat::$options['posts_column_day_interval'] == 0) {
         wp_slimstat::$options['posts_column_day_interval'] = 30;
     }
     $parsed_permalink = parse_url(get_permalink($_post_id));
     $parsed_permalink = $parsed_permalink['path'] . (!empty($parsed_permalink['query']) ? '?' . $parsed_permalink['query'] : '');
     wp_slimstat_db::init('resource contains ' . $parsed_permalink . '&&&hour equals 0&&&day equals ' . date_i18n('d') . '&&&month equals ' . date_i18n('m') . '&&&year equals ' . date_i18n('Y') . '&&&interval equals ' . wp_slimstat::$options['posts_column_day_interval'] . '&&&interval_direction equals minus');
     if (wp_slimstat::$options['posts_column_pageviews'] == 'yes') {
         $count = wp_slimstat_db::count_records();
     } else {
         $count = wp_slimstat_db::count_records('ip', '1=1');
     }
     echo '<a href="' . wp_slimstat_reports::fs_url("resource contains {$parsed_permalink}&&&day equals " . date_i18n('d') . '&&&month equals ' . date_i18n('m') . '&&&year equals ' . date_i18n('Y') . '&&&interval equals ' . wp_slimstat::$options['posts_column_day_interval'] . '&&interval_direction equals minus') . '">' . $count . '</a>';
 }
 /**
  * Initalize class properties
  */
 public static function init()
 {
     self::$screens_info = array('wp-slim-view-1' => __('Real-Time Log', 'wp-slimstat'), 'wp-slim-view-2' => __('Overview', 'wp-slimstat'), 'wp-slim-view-3' => __('Audience', 'wp-slimstat'), 'wp-slim-view-4' => __('Site Analysis', 'wp-slimstat'), 'wp-slim-view-5' => __('Traffic Sources', 'wp-slimstat'), 'wp-slim-view-6' => __('Map Overlay', 'wp-slimstat'));
     // Filters use the following format: browser equals Firefox&&&country contains gb
     $filters = array();
     if (!empty($_REQUEST['fs']) && is_array($_REQUEST['fs'])) {
         foreach ($_REQUEST['fs'] as $a_request_filter_name => $a_request_filter_value) {
             $filters[] = "{$a_request_filter_name} {$a_request_filter_value}";
         }
     }
     // Fields and drop downs
     if (!empty($_POST['f']) && !empty($_POST['o'])) {
         $filters[] = "{$_POST['f']} {$_POST['o']} " . (isset($_POST['v']) ? $_POST['v'] : '');
     }
     foreach (array('minute', 'hour', 'day', 'month', 'year', 'interval_direction', 'interval', 'interval_hours', 'interval_minutes') as $a_date_time_filter_name) {
         if (!empty($_POST[$a_date_time_filter_name])) {
             $filters[] = "{$a_date_time_filter_name} equals {$_POST[$a_date_time_filter_name]}";
         }
     }
     // Hidden Filters
     if (wp_slimstat::$options['restrict_authors_view'] == 'yes' && !current_user_can('manage_options')) {
         $filters[] = 'author equals ' . $GLOBALS['current_user']->user_login;
         self::$hidden_filters['author'] = 1;
     }
     if (!empty($filters)) {
         $filters = implode('&&&', $filters);
     }
     // Include and initialize the API to interact with the database
     include_once 'wp-slimstat-db.php';
     wp_slimstat_db::init($filters);
     // Retrieve data that will be used by multiple reports
     self::$pageviews = wp_slimstat_db::count_records();
     // Define all the reports
     //
     // Parameters
     // - title : report name
     // - callback : function to use to render the report
     // - callback_args : parameters to pass to the function
     // - classes : determine the look and feel of this report ( tall, normal, wide, hidden )
     // - screens : where should the report appear ( wp-slim-view-1, .., wp-slim-view-4, dashboard, raw ). If 'raw' is used, it means that this report can return an array of rows for other uses ( export, email, etc )
     // - tooltip : contextual help to be displayed on hover
     $chart_tooltip = '<strong>' . __('Chart controls', 'wp-slimstat') . '</strong><ul><li>' . __('Use your mouse wheel to zoom in and out', 'wp-slimstat') . '</li><li>' . __('While zooming in, drag the chart to move to a different area', 'wp-slimstat') . '</li><li>' . __('Double click on an empty region to reset the zoom level', 'wp-slimstat') . '</li></ul>';
     self::$reports_info = array('slim_p7_02' => array('title' => __('Activity', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_activity_log'), 'callback_args' => array('type' => 'recent', 'columns' => 'id', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('full-width', 'tall'), 'screens' => array('wp-slim-view-1', 'raw'), 'tooltip' => __('Color codes', 'wp-slimstat') . '</strong><p><span class="little-color-box is-search-engine"></span> ' . __('From search result page', 'wp-slimstat') . '</p><p><span class="little-color-box is-known-visitor"></span> ' . __('Known Visitor', 'wp-slimstat') . '</p><p><span class="little-color-box is-known-user"></span> ' . __('Known Users', 'wp-slimstat') . '</p><p><span class="little-color-box is-direct"></span> ' . __('Other Humans', 'wp-slimstat') . '</p><p><span class="little-color-box"></span> ' . __('Bot or Crawler', 'wp-slimstat') . '</p>'), 'slim_p1_01' => array('title' => __('Pageviews', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_chart'), 'callback_args' => array('chart_data' => wp_slimstat_db::get_data_for_chart('COUNT(ip)', 'COUNT(DISTINCT(ip))'), 'chart_labels' => array(__('Pageviews', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat'))), 'classes' => array('wide', 'chart'), 'screens' => array('wp-slim-view-2', 'dashboard'), 'tooltip' => $chart_tooltip), 'slim_p1_02' => array('title' => __('About Slimstat', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_about_wpslimstat'), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-2')), 'slim_p1_03' => array('title' => __('At a Glance', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_overview_summary'), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'dashboard')), 'slim_p1_04' => array('title' => __('Currently Online', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'username', 'where' => 'dt > ' . (date_i18n('U') - 300), 'use_date_filters' => false, 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'dashboard', 'raw'), 'tooltip' => __('When visitors leave a comment on your blog, WordPress assigns them a cookie. Slimstat leverages this information to identify returning visitors. Please note that visitors also include registered users.', 'wp-slimstat')), 'slim_p1_06' => array('title' => __('Recent Search Terms', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'searchterms', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'wp-slim-view-5', 'raw'), 'tooltip' => __('Keywords used by your visitors to find your website on a search engine.', 'wp-slimstat')), 'slim_p1_08' => array('title' => __('Top Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'SUBSTRING_INDEX(resource, "' . (!get_option('permalink_structure') ? '&' : '?') . '", 1)', 'as_column' => 'resource', 'filter_op' => 'contains', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'dashboard', 'raw'), 'tooltip' => __('Here a "page" is not just a WordPress page type, but any web page on your website, including posts, products, categories, and so on.', 'wp-slimstat')), 'slim_p1_10' => array('title' => __('Top Traffic Sources', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'referer', 'where' => 'referer NOT LIKE "%' . home_url() . '%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'wp-slim-view-5', 'dashboard', 'raw')), 'slim_p1_11' => array('title' => __('Top Known Visitors', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'username', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-2', 'dashboard', 'raw')), 'slim_p1_12' => array('title' => __('Top Search Terms', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'searchterms', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2', 'wp-slim-view-4', 'wp-slim-view-5', 'dashboard', 'raw')), 'slim_p1_13' => array('title' => __('Top Countries', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'country', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-2', 'wp-slim-view-3', 'wp-slim-view-5', 'dashboard', 'raw'), 'tooltip' => __('You can configure Slimstat to ignore a specific Country by setting the corresponding filter under Settings > Slimstat > Filters.', 'wp-slimstat')), 'slim_p1_15' => array('title' => __('Rankings', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_rankings'), 'classes' => array('normal'), 'screens' => array('wp-slim-view-2'), 'tooltip' => __("Slimstat retrieves live information from Alexa, Facebook and Google, to measures your site's rankings. Values are updated every 12 hours. Filters set above don't apply to this report.", 'wp-slimstat')), 'slim_p1_17' => array('title' => __('Top Language Families', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'SUBSTRING(language, 1, 2)', 'as_column' => 'language', 'filter_op' => 'contains', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-2', 'raw')), 'slim_p2_01' => array('title' => __('Human Visits', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_chart'), 'callback_args' => array('chart_data' => wp_slimstat_db::get_data_for_chart('COUNT(DISTINCT visit_id)', 'COUNT(DISTINCT ip)', '(visit_id > 0 AND browser_type <> 1)'), 'chart_labels' => array(__('Visits', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat')), 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('wide', 'chart'), 'screens' => array('wp-slim-view-3'), 'tooltip' => $chart_tooltip), 'slim_p2_02' => array('title' => __('Audience Overview', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_visitors_summary'), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'dashboard'), 'tooltip' => __('Where not otherwise specified, the metrics in this report are referred to human visitors.', 'wp-slimstat')), 'slim_p2_03' => array('title' => __('Top Languages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'language', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_04' => array('title' => __('Top Browsers', 'wp-slimstat', 'dashboard'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'browser, browser_version', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_05' => array('title' => __('Top Service Providers', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'ip', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('wide', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw'), 'tooltip' => __('Internet Service Provider: a company which provides other companies or individuals with access to the Internet. Your DSL or cable internet service is provided to you by your ISP.<br><br>You can ignore specific IP addresses by setting the corresponding filter under Settings > Slimstat > Filters.', 'wp-slimstat')), 'slim_p2_06' => array('title' => __('Top Operating Systems', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'platform', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw'), 'tooltip' => __('Internet Service Provider: a company which provides other companies or individuals with access to the Internet. Your DSL or cable internet service is provided to you by your ISP.<br><br>You can ignore specific IP addresses by setting the corresponding filter under Settings > Slimstat > Filters.', 'wp-slimstat')), 'slim_p2_07' => array('title' => __('Top Screen Resolutions', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'resolution', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'dashboard', 'raw')), 'slim_p2_09' => array('title' => __('Browser Capabilities', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_plugins'), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3')), 'slim_p2_12' => array('title' => __('Visit Duration', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_visit_duration'), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3')), 'slim_p2_13' => array('title' => __('Recent Countries', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'country', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'wp-slim-view-5', 'raw')), 'slim_p2_14' => array('title' => __('Recent Screen Resolutions', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resolution', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_15' => array('title' => __('Recent Operating Systems', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'platform', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_16' => array('title' => __('Recent Browsers', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'browser, browser_version', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_17' => array('title' => __('Recent Languages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'language', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_18' => array('title' => __('Top Browser Families', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'browser', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'raw'), 'tooltip' => __('This report shows you what user agent families (no version considered) are popular among your visitors.', 'wp-slimstat')), 'slim_p2_19' => array('title' => __('Top OS Families', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'CONCAT("p-", SUBSTRING(platform, 1, 3))', 'as_column' => 'platform', 'filter_op' => 'contains', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'raw'), 'tooltip' => __('This report shows you what operating system families (no version considered) are popular among your visitors.', 'wp-slimstat')), 'slim_p2_20' => array('title' => __('Recent Users', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'username', 'where' => 'notes LIKE "%user:%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-3', 'raw')), 'slim_p2_21' => array('title' => __('Top Users', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'username', 'where' => 'notes LIKE "%user:%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-3', 'dashboard', 'raw')), 'slim_p3_01' => array('title' => __('Traffic Sources', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_chart'), 'callback_args' => array('chart_data' => wp_slimstat_db::get_data_for_chart('COUNT(DISTINCT(referer))', 'COUNT(DISTINCT(ip))', '(referer IS NOT NULL AND referer NOT LIKE "%' . home_url() . '%")'), 'chart_labels' => array(__('Domains', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat'))), 'classes' => array('wide', 'chart'), 'screens' => array('wp-slim-view-5'), 'tooltip' => $chart_tooltip), 'slim_p3_02' => array('title' => __('Summary', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_traffic_sources_summary'), 'classes' => array('normal'), 'screens' => array('wp-slim-view-5')), 'slim_p3_06' => array('title' => __('Top Referring Search Engines', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'referer', 'where' => "searchterms IS NOT NULL AND referer NOT LIKE '%" . home_url() . "%'", 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-5', 'dashboard', 'raw')), 'slim_p3_11' => array('title' => __('Recent Exit Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'visit_id', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-5', 'raw')), 'slim_p4_01' => array('title' => __('Recent Outbound Links', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'outbound_resource', 'raw' => array(__CLASS__, 'get_raw_results')), 'callback_raw' => array(__CLASS__, 'get_raw_results'), 'classes' => array('wide'), 'screens' => array('wp-slim-view-4', 'raw'), 'tooltip' => ''), 'slim_p4_02' => array('title' => __('Recent Posts', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => 'content_type = "post"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_03' => array('title' => __('Recent Bounce Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => 'content_type <> "404"', 'having' => 'HAVING COUNT(visit_id) => 1', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw'), 'tooltip' => __('A <em>bounce page</em> is a single-page visit, or visit in which the person left your site from the entrance (landing) page.', 'wp-slimstat')), 'slim_p4_04' => array('title' => __('Recent Feeds', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => '(resource LIKE "%/feed%" OR resource LIKE "%?feed=>%" OR resource LIKE "%&feed=>%" OR content_type LIKE "%feed%")', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_05' => array('title' => __('Recent Pages Not Found', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => '(resource LIKE "[404]%" OR content_type LIKE "%404%")', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_06' => array('title' => __('Recent Internal Searches', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'searchterms', 'where' => 'content_type LIKE "%search%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw'), 'tooltip' => __("Searches performed using WordPress' built-in search functionality.", 'wp-slimstat')), 'slim_p4_07' => array('title' => __('Top Categories', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'category', 'where' => 'content_type LIKE "%category%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'raw'), 'screens' => array('wp-slim-view-4', 'dashboard')), 'slim_p4_09' => array('title' => __('Top Downloads', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'resource', 'where' => 'content_type = "download"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('wide', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw'), 'tooltip' => __('You can configure Slimstat to track specific file extensions as downloads.', 'wp-slimstat')), 'slim_p4_11' => array('title' => __('Top Posts', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'resource', 'where' => 'content_type = "post"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_13' => array('title' => __('Top Internal Searches', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'searchterms', 'where' => 'content_type LIKE "%search%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_15' => array('title' => __('Recent Categories', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => '(content_type => "category" OR content_type => "tag")', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_16' => array('title' => __('Top Pages Not Found', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'resource', 'where' => 'content_type LIKE "%404%"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_18' => array('title' => __('Top Authors', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'author', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal'), 'screens' => array('wp-slim-view-4', 'dashboard', 'raw')), 'slim_p4_19' => array('title' => __('Top Tags', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'category', 'where' => '(content_type LIKE "%tag%")', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_20' => array('title' => __('Recent Downloads', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'recent', 'columns' => 'resource', 'where' => 'content_type = "download"', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('wide', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_21' => array('title' => __('Top Outbound Links', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'outbound_resource', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_22' => array('title' => __('Your Website', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_your_blog'), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4'), 'tooltip' => __('Your content at a glance: posts, comments, pingbacks, etc. Please note that this report is not affected by the filters set here above.', 'wp-slimstat')), 'slim_p4_23' => array('title' => __('Top Bounce Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top', 'columns' => 'resource', 'where' => 'content_type <> "404"', 'having' => 'HAVING COUNT(visit_id) => 1', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_24' => array('title' => __('Top Exit Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top_aggr', 'columns' => 'visit_id', 'outer_select_column' => 'resource', 'aggr_function' => 'MAX', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p4_25' => array('title' => __('Top Entry Pages', 'wp-slimstat'), 'callback' => array(__CLASS__, 'raw_results_to_html'), 'callback_args' => array('type' => 'top_aggr', 'columns' => 'visit_id', 'outer_select_column' => 'resource', 'aggr_function' => 'MIN', 'raw' => array(__CLASS__, 'get_raw_results')), 'classes' => array('normal', 'hidden'), 'screens' => array('wp-slim-view-4', 'raw')), 'slim_p6_01' => array('title' => __('World Map', 'wp-slimstat'), 'callback' => array(__CLASS__, 'show_world_map'), 'classes' => array('tall'), 'screens' => array('wp-slim-view-6'), 'tooltip' => ''));
     // Allow third party tools to manipulate this list here above: please use unique report IDs that don't interfere with built-in ones, if you add your own custom report
     self::$reports_info = apply_filters('slimstat_reports_info', self::$reports_info);
     // Define what reports have been deprecated over time, to remove them from the user's settings
     $deprecated_reports = array('slim_p1_05', 'slim_p1_18', 'slim_p2_10', 'slim_p3_03', 'slim_p3_04', 'slim_p3_05', 'slim_p3_08', 'slim_p3_09', 'slim_p3_10', 'slim_p4_08', 'slim_p4_10', 'slim_p4_12', 'slim_p4_14', 'slim_p4_17');
     // Retrieve this user's list of active reports,
     $user = wp_get_current_user();
     $page_location = wp_slimstat::$options['use_separate_menu'] == 'yes' ? 'slimstat' : 'admin';
     // Do this only if we are in one of our screens (no dashboard!)
     if (!empty($_REQUEST['page']) && strpos($_REQUEST['page'], 'wp-slim-view') !== false) {
         $user_reports = get_user_option("meta-box-order_{$page_location}_page_{$_REQUEST['page']}", $user->ID);
         // If this list is not empty, we rearrange the order of our reports
         if (!empty($user_reports[0])) {
             $user_reports = array_flip(explode(',', $user_reports[0]));
             self::$reports_info = array_intersect_key(array_merge($user_reports, self::$reports_info), $user_reports);
         }
         // Remove deprecated reports
         self::$reports_info = array_diff_key(self::$reports_info, $deprecated_reports);
         $hidden_reports = get_user_option("metaboxhidden_{$page_location}_page_{$_REQUEST['page']}", $user->ID);
         // If this list is not empty, use it instead of the predefined visibility
         if (!empty($hidden_reports) && is_array($hidden_reports)) {
             foreach (self::$reports_info as $a_report_id => $a_report_info) {
                 if (in_array($a_report_id, $hidden_reports)) {
                     if (is_array(self::$reports_info[$a_report_id]['classes']) && !in_array('hidden', $a_report_info['classes'])) {
                         self::$reports_info[$a_report_id]['classes'][] = 'hidden';
                     }
                 } else {
                     if (is_array(self::$reports_info[$a_report_id]['classes'])) {
                         self::$reports_info[$a_report_id]['classes'] = array_diff(self::$reports_info[$a_report_id]['classes'], array('hidden'));
                     }
                 }
             }
         }
     } else {
         foreach (self::$reports_info as $a_report_id => $a_report_info) {
             if (is_array(self::$reports_info[$a_report_id]['classes'])) {
                 self::$reports_info[$a_report_id]['classes'] = array_diff(self::$reports_info[$a_report_id]['classes'], array('hidden'));
             }
         }
     }
 }
 /**
  * Adds a new column to the Posts management panel
  */
 public static function add_post_column($_column_name, $_post_id)
 {
     if ('wp-slimstat' != $_column_name) {
         return;
     }
     include_once dirname(__FILE__) . '/view/wp-slimstat-db.php';
     $parsed_permalink = parse_url(get_permalink($_post_id));
     $parsed_permalink = $parsed_permalink['path'] . (!empty($parsed_permalink['query']) ? '?' . $parsed_permalink['query'] : '');
     wp_slimstat_db::init('resource contains ' . $parsed_permalink . '&&&hour equals 0&&&day equals ' . date_i18n('d') . '&&&month equals ' . date_i18n('m') . '&&&year equals ' . date_i18n('Y') . '&&&interval equals -365');
     $count = wp_slimstat_db::count_records();
     echo '<a href="' . self::fs_url("resource contains {$parsed_permalink}&&&day equals " . date_i18n('d') . '&&&month equals ' . date_i18n('m') . '&&&year equals ' . date_i18n('Y') . '&&&interval equals -365') . '">' . $count . '</a>';
 }
Example #4
0
 /**
  * Initalizes class properties
  */
 public static function init()
 {
     self::$screen_names = array(1 => __('Real-Time Log', 'wp-slimstat'), 2 => __('Overview', 'wp-slimstat'), 3 => __('Audience', 'wp-slimstat'), 4 => __('Site Analysis', 'wp-slimstat'), 5 => __('Traffic Sources', 'wp-slimstat'), 6 => __('Map Overlay', 'wp-slimstat'), 7 => __('Custom Reports', 'wp-slimstat'));
     self::$all_reports_titles = array('slim_p1_01' => __('Pageviews (chart)', 'wp-slimstat'), 'slim_p1_02' => __('About Slimstat', 'wp-slimstat'), 'slim_p1_03' => __('At a Glance', 'wp-slimstat'), 'slim_p1_04' => __('Currently Online', 'wp-slimstat'), 'slim_p1_05' => __('Spy View', 'wp-slimstat'), 'slim_p1_06' => __('Recent Search Terms', 'wp-slimstat'), 'slim_p1_08' => __('Top Pages', 'wp-slimstat'), 'slim_p1_10' => __('Top Traffic Sources', 'wp-slimstat'), 'slim_p1_11' => __('Top Known Visitors', 'wp-slimstat'), 'slim_p1_12' => __('Top Search Terms', 'wp-slimstat'), 'slim_p1_13' => __('Top Countries', 'wp-slimstat'), 'slim_p1_15' => __('Rankings', 'wp-slimstat'), 'slim_p1_17' => __('Top Language Families', 'wp-slimstat'), 'slim_p2_01' => __('Human Visits (chart)', 'wp-slimstat'), 'slim_p2_02' => __('At a Glance', 'wp-slimstat'), 'slim_p2_03' => __('Top Languages', 'wp-slimstat'), 'slim_p2_04' => __('Top Browsers', 'wp-slimstat'), 'slim_p2_05' => __('Top Service Providers', 'wp-slimstat'), 'slim_p2_06' => __('Top Operating Systems', 'wp-slimstat'), 'slim_p2_07' => __('Top Screen Resolutions', 'wp-slimstat'), 'slim_p2_09' => __('Browser Capabilities', 'wp-slimstat'), 'slim_p2_10' => __('Top Countries', 'wp-slimstat'), 'slim_p2_12' => __('Visit Duration', 'wp-slimstat'), 'slim_p2_13' => __('Recent Countries', 'wp-slimstat'), 'slim_p2_14' => __('Recent Screen Resolutions', 'wp-slimstat'), 'slim_p2_15' => __('Recent Operating Systems', 'wp-slimstat'), 'slim_p2_16' => __('Recent Browsers', 'wp-slimstat'), 'slim_p2_17' => __('Recent Languages', 'wp-slimstat'), 'slim_p2_18' => __('Top Browser Families', 'wp-slimstat'), 'slim_p2_19' => __('Top OS Families', 'wp-slimstat'), 'slim_p2_20' => __('Recent Users', 'wp-slimstat'), 'slim_p2_21' => __('Top Users', 'wp-slimstat'), 'slim_p3_01' => __('Traffic Sources (chart)', 'wp-slimstat'), 'slim_p3_02' => __('Summary', 'wp-slimstat'), 'slim_p3_03' => __('Top Search Terms', 'wp-slimstat'), 'slim_p3_04' => __('Top Countries', 'wp-slimstat'), 'slim_p3_05' => __('Top Traffic Sources', 'wp-slimstat'), 'slim_p3_06' => __('Top Referring Search Engines', 'wp-slimstat'), 'slim_p3_08' => __('Spy View', 'wp-slimstat'), 'slim_p3_09' => __('Recent Search Terms', 'wp-slimstat'), 'slim_p3_10' => __('Recent Countries', 'wp-slimstat'), 'slim_p3_11' => __('Top Landing Pages', 'wp-slimstat'), 'slim_p4_01' => __('Average Pageviews per Visit (chart)', 'wp-slimstat'), 'slim_p4_02' => __('Recent Posts', 'wp-slimstat'), 'slim_p4_03' => __('Recent Bounce Pages', 'wp-slimstat'), 'slim_p4_04' => __('Recent Feeds', 'wp-slimstat'), 'slim_p4_05' => __('Recent Pages Not Found', 'wp-slimstat'), 'slim_p4_06' => __('Recent Internal Searches', 'wp-slimstat'), 'slim_p4_07' => __('Top Categories', 'wp-slimstat'), 'slim_p4_08' => __('Recent Outbound Links', 'wp-slimstat'), 'slim_p4_10' => __('Recent Events', 'wp-slimstat'), 'slim_p4_11' => __('Top Posts', 'wp-slimstat'), 'slim_p4_12' => __('Top Feeds', 'wp-slimstat'), 'slim_p4_13' => __('Top Internal Searches', 'wp-slimstat'), 'slim_p4_14' => __('Top Search Terms', 'wp-slimstat'), 'slim_p4_15' => __('Recent Categories', 'wp-slimstat'), 'slim_p4_16' => __('Top Pages Not Found', 'wp-slimstat'), 'slim_p4_17' => __('Top Landing Pages', 'wp-slimstat'), 'slim_p4_18' => __('Top Authors', 'wp-slimstat'), 'slim_p4_19' => __('Top Tags', 'wp-slimstat'), 'slim_p4_20' => __('Recent Downloads', 'wp-slimstat'), 'slim_p4_21' => __('Top OutLinks and Downloads', 'wp-slimstat'), 'slim_p4_22' => __('Your Website', 'wp-slimstat'), 'slim_p6_01' => __('World Map', 'wp-slimstat'), 'slim_p7_02' => __('At A Glance', 'wp-slimstat'));
     // TO BE REVIEWED AND CLEANED UP
     self::$meta_report_order_nonce = wp_create_nonce('meta-box-order');
     // Retrieve the order of this tab's panels and which ones are hidden
     $user = wp_get_current_user();
     $page_location = wp_slimstat::$options['use_separate_menu'] == 'yes' ? 'slimstat' : 'admin';
     self::$all_reports_titles = apply_filters('slimstat_report_titles', self::$all_reports_titles);
     if (self::$current_tab != 1) {
         self::$all_reports = get_user_option("meta-box-order_{$page_location}_page_wp-slim-view-" . self::$current_tab, $user->ID);
         self::$all_reports = self::$all_reports === false ? get_user_option("meta-box-order_{$page_location}_page_wp-slimstat", $user->ID) : self::$all_reports;
         // backward compatible with old settings
     }
     self::$all_reports = empty(self::$all_reports) || empty(self::$all_reports[0]) ? array() : explode(',', self::$all_reports[0]);
     $all_existing_reports = array(0 => array(), 1 => array('slim_p7_02'), 2 => array('slim_p1_01', 'slim_p1_02', 'slim_p1_03', 'slim_p1_04', 'slim_p1_11', 'slim_p1_12', 'slim_p1_05', 'slim_p1_08', 'slim_p1_10', 'slim_p1_13', 'slim_p1_15', 'slim_p1_17'), 3 => array('slim_p2_01', 'slim_p2_02', 'slim_p2_03', 'slim_p2_04', 'slim_p2_06', 'slim_p2_05', 'slim_p2_07', 'slim_p2_09', 'slim_p2_10', 'slim_p2_12', 'slim_p2_13', 'slim_p2_14', 'slim_p2_15', 'slim_p2_16', 'slim_p2_17', 'slim_p2_18', 'slim_p2_19', 'slim_p2_20', 'slim_p2_21'), 4 => array('slim_p4_01', 'slim_p4_22', 'slim_p1_06', 'slim_p4_07', 'slim_p4_02', 'slim_p4_03', 'slim_p4_05', 'slim_p4_04', 'slim_p4_06', 'slim_p4_08', 'slim_p4_12', 'slim_p4_13', 'slim_p4_14', 'slim_p4_15', 'slim_p4_16', 'slim_p4_17', 'slim_p4_18', 'slim_p4_11', 'slim_p4_10', 'slim_p4_19', 'slim_p4_20', 'slim_p4_21'), 5 => array('slim_p3_01', 'slim_p3_02', 'slim_p3_03', 'slim_p3_04', 'slim_p3_06', 'slim_p3_05', 'slim_p3_08', 'slim_p3_10', 'slim_p3_09', 'slim_p3_11'), 6 => array('slim_p6_01'), 7 => array());
     // Some boxes are hidden by default
     if (!empty($_GET['page']) && strpos($_GET['page'], 'wp-slim-view-') !== false) {
         self::$hidden_reports = get_user_option("metaboxhidden_{$page_location}_page_wp-slim-view-" . self::$current_tab, $user->ID);
         if (empty(self::$all_reports)) {
             self::$all_reports = $all_existing_reports[self::$current_tab];
         } else {
             self::$all_reports = array_intersect(self::$all_reports, $all_existing_reports[self::$current_tab]);
         }
     } else {
         // the script is being called from the dashboard widgets plugin
         self::$hidden_reports = get_user_option("metaboxhidden_{$page_location}", $user->ID);
     }
     // Default values
     if (self::$hidden_reports === false) {
         switch (self::$current_tab) {
             case 2:
                 self::$hidden_reports = array('slim_p1_02', 'slim_p1_11', 'slim_p1_12', 'slim_p1_13', 'slim_p1_17');
                 break;
             case 3:
                 self::$hidden_reports = array('slim_p2_05', 'slim_p2_07', 'slim_p2_09', 'slim_p2_13', 'slim_p2_14', 'slim_p2_15', 'slim_p2_16', 'slim_p2_17', 'slim_p2_18', 'slim_p2_19', 'slim_p2_20', 'slim_p2_21');
                 break;
             case 4:
                 self::$hidden_reports = array('slim_p4_11', 'slim_p4_12', 'slim_p4_13', 'slim_p4_14', 'slim_p4_15', 'slim_p4_16', 'slim_p4_17');
                 break;
             case 5:
                 self::$hidden_reports = array('slim_p3_09', 'slim_p3_10');
                 break;
             default:
                 self::$hidden_reports = array();
         }
     }
     // END PART TO BE REVIEWED AND CLEANED UP
     // Filters use the following format: browser equals Firefox|country contains gb
     $filters = array();
     if (!empty($_REQUEST['fs']) && is_array($_REQUEST['fs'])) {
         foreach ($_REQUEST['fs'] as $a_request_filter_name => $a_request_filter_value) {
             $filters[] = "{$a_request_filter_name} {$a_request_filter_value}";
         }
     }
     // Fields and drop downs
     if (!empty($_POST['f']) && !empty($_POST['o'])) {
         $filters[] = "{$_POST['f']} {$_POST['o']} " . (isset($_POST['v']) ? $_POST['v'] : '');
     }
     if (!empty($_POST['day'])) {
         $filters[] = "day equals {$_POST['day']}";
     }
     if (!empty($_POST['month'])) {
         $filters[] = "month equals {$_POST['month']}";
     }
     if (!empty($_POST['year'])) {
         $filters[] = "year equals {$_POST['year']}";
     }
     if (!empty($_POST['interval'])) {
         $filters[] = "interval equals {$_POST['interval']}";
     }
     // Hidden Filters
     if (wp_slimstat::$options['restrict_authors_view'] == 'yes' && !current_user_can('manage_options')) {
         $filters[] = 'author equals ' . $GLOBALS['current_user']->user_login;
         self::$hidden_filters['author'] = 1;
     }
     // Allow third-party add-ons to modify filters before they are used
     $filters = apply_filters('slimstat_modify_admin_filters', $filters);
     if (!empty($filters)) {
         $filters = implode('&&&', $filters);
     }
     // Include and initialize the API to interact with the database
     include_once dirname(__FILE__) . '/wp-slimstat-db.php';
     wp_slimstat_db::init($filters);
     // Some of the filters supported by the API do not appear in the dropdown
     self::$dropdown_filter_names = array_diff_key(wp_slimstat_db::$filter_names, array('hour' => 1, 'day' => 1, 'month' => 1, 'year' => 1, 'interval' => 1, 'direction' => 1, 'limit_results' => 1, 'start_from' => 1, 'strtotime' => 1));
     // Default text for the inline help associated to the chart
     self::$chart_tooltip = '<strong>' . __('Chart controls', 'wp-slimstat') . '</strong><ul><li>' . __('Use your mouse wheel to zoom in and out', 'wp-slimstat') . '</li><li>' . __('While zooming in, drag the chart to move to a different area', 'wp-slimstat') . '</li><li>' . __('Double click on an empty region to reset the zoom level', 'wp-slimstat') . '</li>';
     self::$chart_tooltip .= empty(wp_slimstat_db::$filters_normalized['date']['day']) ? '<li>' . __('Click on a data point to display the activity chart for each hour of that day', 'wp-slimstat') . '</li>' : '';
 }
Example #5
0
 /**
  * Retrieves the information from the database
  */
 protected static function _get_results($_attr = array())
 {
     // Optional fields and other variables are defined to avoid PHP warnings
     $join_tables = '';
     $table_identifier = wp_slimstat_db::get_table_identifier($_attr['w']);
     if ($table_identifier != 't1.') {
         $join_tables = $table_identifier . '*,';
     }
     if (!isset($_attr['lf'])) {
         $_attr['lf'] = '';
     }
     if (!isset($_attr['lc'])) {
         $_attr['lc'] = array($_attr['w']);
     } elseif ($_attr['lc'] != '*') {
         $_attr['lc'] = explode(',', $_attr['lc']);
         foreach ($_attr['lc'] as $a_column) {
             $table_identifier = wp_slimstat_db::get_table_identifier($a_column);
             if ($table_identifier != 't1.' && strpos($join_tables, $table_identifier . '*') === false) {
                 $join_tables .= $table_identifier . '*,';
             }
         }
     }
     $join_tables = substr($join_tables, 0, -1);
     if (!isset($_attr['s'])) {
         $_attr['s'] = ', ';
     }
     // Load locales
     load_plugin_textdomain('countries-languages', WP_PLUGIN_DIR . '/wp-slimstat/admin/lang', '/wp-slimstat/lang');
     // If a local translation for countries and languages does not exist, use English
     if (!isset($l10n['countries-languages'])) {
         load_textdomain('countries-languages', WP_PLUGIN_DIR . '/wp-slimstat/admin/lang/countries-languages-en_US.mo');
     }
     $content = '';
     switch ($_attr['f']) {
         // Custom SQL: use the lf param to retrieve the data; no syntax check is done!
         case 'custom':
             if (!empty($_attr['lf'])) {
                 return $GLOBALS['wpdb']->query($_attr['lf']);
             }
             break;
         case 'recent':
         case 'popular':
         case 'count':
         case 'count-all':
             // Avoid PHP warnings in strict mode
             $custom_where = '';
             // Ampersands are encoded as HTML
             $_attr['lf'] = str_replace('&#038;&#038;&#038;', '&&&', $_attr['lf']);
             if (strpos($_attr['lf'], 'WHERE:') !== false) {
                 $custom_where = html_entity_decode(substr($_attr['lf'], 6), ENT_QUOTES, 'UTF-8');
                 $custom_where = str_replace('NOW()', date_i18n('U'), $custom_where);
                 wp_slimstat_db::init();
             } else {
                 wp_slimstat_db::init($_attr['lf']);
             }
             if ($_attr['f'] == 'count') {
                 return wp_slimstat_db::count_records($custom_where, $_attr['w'], true, true, $join_tables);
             }
             if ($_attr['f'] == 'count-all') {
                 return wp_slimstat_db::count_records($custom_where, $_attr['w'], true, false, $join_tables);
             }
             $_attr['f'] = 'get_' . $_attr['f'];
             $results = wp_slimstat_db::$_attr['f'](wp_slimstat_db::get_table_identifier($_attr['w']) . $_attr['w'], $custom_where, $join_tables);
             // Format results
             if (empty($results)) {
                 return $content;
             }
             // What columns to include?
             if ($_attr['lc'] == '*') {
                 $_attr['lc'] = array_keys($results[0]);
             }
             $home_url = get_home_url();
             foreach ($results as $a_result) {
                 $content .= '<li>';
                 foreach ($_attr['lc'] as $id_column => $a_column) {
                     $content .= "<span class='col-{$id_column}'>";
                     switch ($a_column) {
                         case 'post_link':
                             $post_id = url_to_postid(strtok($a_result['resource'], '?'));
                             if ($post_id > 0) {
                                 $content .= "<a href='{$a_result['resource']}'>" . get_the_title($post_id) . '</a>';
                             } else {
                                 $content .= strtok($a_result['resource'], '?');
                             }
                             break;
                         case 'dt':
                             $content .= date_i18n(wp_slimstat_db::$date_time_format, $a_result['dt']);
                             break;
                         case 'hostname':
                             $content .= gethostbyaddr($a_result['ip']);
                             break;
                         case 'ip':
                             $content .= long2ip($a_result['ip']);
                             break;
                         case 'count':
                             $content .= $a_result['counthits'];
                             break;
                         default:
                             $content .= $a_result[$a_column];
                             break;
                     }
                     $content .= $_attr['s'];
                 }
                 $content = substr($content, 0, strrpos($content, $_attr['s'])) . '</li>';
             }
             return "<ul class='slimstat-shortcode {$_attr['f']}-{$_attr['w']}'>{$content}</ul>";
             break;
         default:
     }
 }
 public static function slimstat_shortcode($_attributes = '', $_content = '')
 {
     extract(shortcode_atts(array('f' => '', 'w' => '', 's' => ' ', 'o' => 0), $_attributes));
     $output = $where = '';
     $s = "<span class='slimstat-item-separator'>{$s}</span>";
     // Load the database library
     include_once dirname(__FILE__) . '/admin/view/wp-slimstat-db.php';
     // Load the localization files (for languages, operating systems, etc)
     load_plugin_textdomain('wp-slimstat', WP_PLUGIN_DIR . '/wp-slimstat/admin/lang', '/wp-slimstat/admin/lang');
     // Look for required fields
     if (empty($f) || empty($w)) {
         return '<!-- Slimstat Shortcode Error: missing parameter -->';
     }
     if (strpos($_content, 'WHERE:') !== false) {
         $where = html_entity_decode(str_replace('WHERE:', '', $_content), ENT_QUOTES, 'UTF-8');
         wp_slimstat_db::init();
     } else {
         wp_slimstat_db::init(html_entity_decode($_content, ENT_QUOTES, 'UTF-8'));
     }
     switch ($f) {
         case 'count':
         case 'count-all':
             $output = wp_slimstat_db::count_records($w, $where, strpos($f, 'all') === false) + $o;
             break;
         case 'recent':
         case 'recent-all':
         case 'top':
         case 'top-all':
             $function = 'get_' . str_replace('-all', '', $f);
             if ($w == '*') {
                 $w = 'id';
             }
             $w = wp_slimstat::string_to_array($w);
             // Some columns are 'special' and need be removed from the list
             $w_clean = array_diff($w, array('count', 'hostname', 'post_link', 'dt'));
             // The special value 'post_list' requires the permalink to be generated
             if (in_array('post_link', $w)) {
                 $w_clean[] = 'resource';
             }
             // Retrieve the data
             $results = wp_slimstat_db::$function(implode(', ', $w_clean), $where, '', strpos($f, 'all') === false);
             // No data? No problem!
             if (empty($results)) {
                 return '<!--  Slimstat Shortcode: No Data -->';
             }
             // Are nice permalinks enabled?
             $permalinks_enabled = get_option('permalink_structure');
             // Format results
             $output = array();
             foreach ($results as $result_idx => $a_result) {
                 foreach ($w as $a_column) {
                     $output[$result_idx][$a_column] = "<span class='col-{$a_column}'>";
                     if ($permalinks_enabled) {
                         $a_result['resource'] = strtok($a_result['resource'], '?');
                     }
                     switch ($a_column) {
                         case 'post_link':
                             $post_id = url_to_postid($a_result['resource']);
                             if ($post_id > 0) {
                                 $output[$result_idx][$a_column] .= "<a href='{$a_result['resource']}'>" . get_the_title($post_id) . '</a>';
                             } else {
                                 $output[$result_idx][$a_column] .= $a_result['resource'];
                             }
                             break;
                         case 'dt':
                             $output[$result_idx][$a_column] .= date_i18n(wp_slimstat::$options['date_format'] . ' ' . wp_slimstat::$options['time_format'], $a_result['dt']);
                             break;
                         case 'hostname':
                             $output[$result_idx][$a_column] .= gethostbyaddr($a_result['ip']);
                             break;
                         case 'count':
                             $output[$result_idx][$a_column] .= $a_result['counthits'];
                             break;
                         case 'language':
                             $output[$result_idx][$a_column] .= __('l-' . $a_result[$a_column], 'wp-slimstat');
                             break;
                         case 'platform':
                             $output[$result_idx][$a_column] .= __($a_result[$a_column], 'wp-slimstat');
                         default:
                             $output[$result_idx][$a_column] .= $a_result[$a_column];
                             break;
                     }
                     $output[$result_idx][$a_column] .= '</span>';
                 }
                 $output[$result_idx] = '<li>' . implode($s, $output[$result_idx]) . '</li>';
             }
             $output = '<ul class="slimstat-shortcode ' . $f . implode('-', $w) . '">' . implode('', $output) . '</ul>';
             break;
         default:
             break;
     }
     return $output;
 }