public static function init($_filters = '') { // Decimal and thousand separators if (wp_slimstat::$options['use_european_separators'] == 'no') { self::$formats['decimal'] = '.'; self::$formats['thousand'] = ','; } // Filters are defined as: browser equals Chrome|country starts_with en if (!is_string($_filters) || empty($_filters)) { $_filters = ''; } // List of supported filters and their friendly names self::$columns_names = array('no_filter_selected_1' => array(' ', 'none'), 'browser' => array(__('Browser', 'wp-slimstat'), 'varchar'), 'country' => array(__('Country Code', 'wp-slimstat'), 'varchar'), 'ip' => array(__('IP Address', 'wp-slimstat'), 'int'), 'searchterms' => array(__('Search Terms', 'wp-slimstat'), 'varchar'), 'language' => array(__('Language Code', 'wp-slimstat'), 'varchar'), 'platform' => array(__('Operating System', 'wp-slimstat'), 'varchar'), 'resource' => array(__('Permalink', 'wp-slimstat'), 'varchar'), 'referer' => array(__('Referer', 'wp-slimstat'), 'varchar'), 'username' => array(__('Visitor\'s Name', 'wp-slimstat'), 'varchar'), 'outbound_resource' => array(__('Outbound Link', 'wp-slimstat'), 'varchar'), 'page_performance' => array(__('Page Speed', 'wp-slimstat'), 'int'), 'no_filter_selected_2' => array(' ', 'none'), 'no_filter_selected_3' => array(__('-- Advanced filters --', 'wp-slimstat'), 'none'), 'plugins' => array(__('Browser Capabilities', 'wp-slimstat'), 'varchar'), 'browser_version' => array(__('Browser Version', 'wp-slimstat'), 'varchar'), 'browser_type' => array(__('Browser Type', 'wp-slimstat'), 'int'), 'user_agent' => array(__('User Agent', 'wp-slimstat'), 'varchar'), 'notes' => array(__('Pageview Attributes', 'wp-slimstat'), 'varchar'), 'server_latency' => array(__('Server Latency', 'wp-slimstat'), 'int'), 'author' => array(__('Post Author', 'wp-slimstat'), 'varchar'), 'category' => array(__('Post Category ID', 'wp-slimstat'), 'varchar'), 'other_ip' => array(__('Originating IP', 'wp-slimstat'), 'int'), 'content_type' => array(__('Resource Content Type', 'wp-slimstat'), 'varchar'), 'content_id' => array(__('Resource ID', 'wp-slimstat'), 'int'), 'screen_width' => array(__('Screen Width', 'wp-slimstat'), 'int'), 'screen_height' => array(__('Screen Height', 'wp-slimstat'), 'int'), 'resolution' => array(__('Viewport Size', 'wp-slimstat'), 'varchar'), 'visit_id' => array(__('Visit ID', 'wp-slimstat'), 'int')); // The following filters will not be displayed in the dropdown self::$all_columns_names = array_merge(array('minute' => array(__('Minute', 'wp-slimstat'), 'int'), 'hour' => array(__('Hour', 'wp-slimstat'), 'int'), 'day' => array(__('Day', 'wp-slimstat'), 'int'), 'month' => array(__('Month', 'wp-slimstat'), 'int'), 'year' => array(__('Year', 'wp-slimstat'), 'int'), 'interval_direction' => array(__('+/-', 'wp-slimstat'), 'int'), 'interval' => array(__('days', 'wp-slimstat'), 'int'), 'interval_hours' => array(__('hours', 'wp-slimstat'), 'int'), 'interval_minutes' => array(__('minutes', 'wp-slimstat'), 'int'), 'dt' => array(__('Unix Timestamp', 'wp-slimstat'), 'int'), 'direction' => array(__('Direction', 'wp-slimstat'), 'varchar'), 'limit_results' => array(__('Limit Results', 'wp-slimstat'), 'int'), 'start_from' => array(__('Start From', 'wp-slimstat'), 'int'), 'strtotime' => array(0, 'int')), self::$columns_names); // Allow third party plugins to add even more column names to the array self::$all_columns_names = apply_filters('slimstat_column_names', self::$all_columns_names); // Hook for the... filters $_filters = apply_filters('slimstat_db_pre_filters', $_filters); // Normalize the input (filters) self::$filters_normalized = self::parse_filters($_filters); // Hook for the array of normalized filters self::$filters_normalized = apply_filters('slimstat_db_filters_normalized', self::$filters_normalized, $_filters); self::$sql_where['columns'] = self::_get_sql_where(self::$filters_normalized['columns']); self::$sql_where['time_range'] = '(dt BETWEEN ' . self::$filters_normalized['utime']['start'] . ' AND ' . self::$filters_normalized['utime']['end'] . ')'; }
public static function init($_filters = '') { // Reset MySQL timezone settings, our dates and times are recorded using WP settings wp_slimstat::$wpdb->query("SET @@session.time_zone = '+00:00'"); date_default_timezone_set('UTC'); // Decimal and thousand separators if (wp_slimstat::$options['use_european_separators'] == 'no') { self::$formats['decimal'] = '.'; self::$formats['thousand'] = ','; } // Use WordPress' settings for date and time format self::$formats['date_format'] = get_option('date_format', 'd-m-Y'); self::$formats['time_format'] = get_option('time_format', 'd-m-Y'); // Filters are defined as: browser equals Chrome|country starts_with en if (!is_string($_filters) || empty($_filters)) { $_filters = ''; } // List of supported filters and their friendly names self::$filter_names = array('no_filter_selected_1' => ' ', 'browser' => __('Browser', 'wp-slimstat'), 'country' => __('Country Code', 'wp-slimstat'), 'ip' => __('IP Address', 'wp-slimstat'), 'searchterms' => __('Search Terms', 'wp-slimstat'), 'language' => __('Language Code', 'wp-slimstat'), 'platform' => __('Operating System', 'wp-slimstat'), 'resource' => __('Permalink', 'wp-slimstat'), 'domain' => __('Domain', 'wp-slimstat'), 'referer' => __('Referer', 'wp-slimstat'), 'user' => __('Visitor\'s Name', 'wp-slimstat'), 'page_performance' => __('Page Speed', 'wp-slimstat'), 'no_filter_selected_2' => ' ', 'no_filter_selected_3' => __('-- Advanced filters --', 'wp-slimstat'), 'plugins' => __('Browser Capabilities', 'wp-slimstat'), 'version' => __('Browser Version', 'wp-slimstat'), 'type' => __('Browser Type', 'wp-slimstat'), 'user_agent' => __('User Agent', 'wp-slimstat'), 'colordepth' => __('Color Depth', 'wp-slimstat'), 'css_version' => __('CSS Version', 'wp-slimstat'), 'notes' => __('Pageview Attributes', 'wp-slimstat'), 'server_latency' => __('Server Latency', 'wp-slimstat'), 'outbound_resource' => __('Outbound Link', 'wp-slimstat'), 'author' => __('Post Author', 'wp-slimstat'), 'category' => __('Post Category ID', 'wp-slimstat'), 'other_ip' => __('Originating IP', 'wp-slimstat'), 'content_type' => __('Resource Content Type', 'wp-slimstat'), 'content_id' => __('Resource ID', 'wp-slimstat'), 'resolution' => __('Screen Resolution', 'wp-slimstat'), 'visit_id' => __('Visit ID', 'wp-slimstat'), 'hour' => __('Hour', 'wp-slimstat'), 'day' => __('Day', 'wp-slimstat'), 'month' => __('Month', 'wp-slimstat'), 'year' => __('Year', 'wp-slimstat'), 'interval' => __('days', 'wp-slimstat'), 'direction' => __('Order Direction', 'wp-slimstat'), 'limit_results' => __('Limit Results', 'wp-slimstat'), 'start_from' => __('Start From', 'wp-slimstat'), 'strtotime' => 0); // Hook for the... filters $_filters = apply_filters('slimstat_db_pre_filters', $_filters); // Normalize the input (filters) self::$filters_normalized = self::parse_filters($_filters); // Hook for the array of normalized filters self::$filters_normalized = apply_filters('slimstat_db_filters_normalized', self::$filters_normalized, $_filters); if (empty(self::$filters_normalized['date']['interval'])) { if (!empty(self::$filters_normalized['date']['hour'])) { self::$filters_normalized['utime']['start'] = mktime(self::$filters_normalized['date']['hour'], 0, 0, !empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n'), !empty(self::$filters_normalized['date']['day']) ? self::$filters_normalized['date']['day'] : date_i18n('j'), !empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')); self::$filters_normalized['utime']['end'] = self::$filters_normalized['utime']['start'] + 3599; self::$filters_normalized['utime']['type'] = 'H'; } else { if (!empty(self::$filters_normalized['date']['day'])) { self::$filters_normalized['utime']['start'] = mktime(0, 0, 0, !empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n'), self::$filters_normalized['date']['day'], !empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')); self::$filters_normalized['utime']['end'] = self::$filters_normalized['utime']['start'] + 86399; self::$filters_normalized['utime']['type'] = 'd'; } else { if (!empty(self::$filters_normalized['date']['year']) && empty(self::$filters_normalized['date']['month'])) { self::$filters_normalized['utime']['start'] = mktime(0, 0, 0, 1, 1, self::$filters_normalized['date']['year']); self::$filters_normalized['utime']['end'] = mktime(0, 0, 0, 1, 1, self::$filters_normalized['date']['year'] + 1) - 1; self::$filters_normalized['utime']['type'] = 'Y'; } else { self::$filters_normalized['utime']['start'] = mktime(0, 0, 0, !empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n'), 1, !empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')); self::$filters_normalized['utime']['end'] = strtotime((!empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')) . '-' . (!empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n')) . '-01 00:00 +1 month UTC') - 1; self::$filters_normalized['utime']['type'] = 'm'; } } } } else { self::$filters_normalized['utime']['type'] = 'interval'; if (self::$filters_normalized['date']['interval'] > 0) { self::$filters_normalized['utime']['start'] = mktime(0, 0, 0, !empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n'), !empty(self::$filters_normalized['date']['day']) ? self::$filters_normalized['date']['day'] : date_i18n('j'), !empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')); self::$filters_normalized['utime']['end'] = strtotime((!empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')) . '-' . (!empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n')) . '-' . (!empty(self::$filters_normalized['date']['day']) ? self::$filters_normalized['date']['day'] : date_i18n('j')) . ' 00:00:00 +' . self::$filters_normalized['date']['interval'] . ' days UTC') - 1; } else { // Swap boundaries, if interval is negative self::$filters_normalized['utime']['start'] = strtotime((!empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')) . '-' . (!empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n')) . '-' . (!empty(self::$filters_normalized['date']['day']) ? self::$filters_normalized['date']['day'] : date_i18n('j')) . ' 00:00:00 ' . (self::$filters_normalized['date']['interval'] + 1) . ' days UTC'); self::$filters_normalized['utime']['end'] = mktime(23, 59, 59, !empty(self::$filters_normalized['date']['month']) ? self::$filters_normalized['date']['month'] : date_i18n('n'), !empty(self::$filters_normalized['date']['day']) ? self::$filters_normalized['date']['day'] : date_i18n('j'), !empty(self::$filters_normalized['date']['year']) ? self::$filters_normalized['date']['year'] : date_i18n('Y')); } } // If end is in the future, set it to now if (self::$filters_normalized['utime']['end'] > date_i18n('U')) { self::$filters_normalized['utime']['end'] = date_i18n('U'); } // If start is after end, set it to first of month if (self::$filters_normalized['utime']['start'] > self::$filters_normalized['utime']['end']) { self::$filters_normalized['utime']['start'] = mktime(0, 0, 0, date_i18n('n', self::$filters_normalized['utime']['end']), 1, date_i18n('Y', self::$filters_normalized['utime']['end'])); self::$filters_normalized['date']['hour'] = self::$filters_normalized['date']['day'] = self::$filters_normalized['date']['month'] = self::$filters_normalized['date']['year'] = 0; } // Now let's translate our filters into SQL clauses self::$sql_filters = array('from' => array('browsers' => '', 'screenres' => '', 'content_info' => '', 'outbound' => '', 'all_tables' => '', 'all_other_tables' => ''), 'where' => '', 'where_time_range' => ' AND (t1.dt BETWEEN ' . self::$filters_normalized['utime']['start'] . ' AND ' . self::$filters_normalized['utime']['end'] . ')'); foreach (self::$filters_normalized['columns'] as $a_filter_column => $a_filter_data) { $a_filter_empty = '0'; // Add-ons can set their own custom filters, which are ignored here if (strpos($a_filter_column, 'addon_') !== false) { continue; } // Some columns are in separate tables, so we need to join them switch (self::get_table_identifier($a_filter_column)) { case 'tb.': self::$sql_filters['from']['browsers'] = "INNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_browsers tb ON t1.browser_id = tb.browser_id"; break; case 'tci.': self::$sql_filters['from']['content_info'] = "INNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_content_info tci ON t1.content_info_id = tci.content_info_id"; break; case 'tss.': self::$sql_filters['from']['screenres'] = "LEFT JOIN {$GLOBALS['wpdb']->base_prefix}slim_screenres tss ON t1.screenres_id = tss.screenres_id"; break; case 'tob.': self::$sql_filters['from']['outbound'] = "LEFT JOIN {$GLOBALS['wpdb']->prefix}slim_outbound tob ON (t1.id = tob.id)"; break; default: } // Some columns require a special treatment switch ($a_filter_column) { case 'ip': case 'other_ip': $a_filter_column = "INET_NTOA({$a_filter_column})"; $a_filter_empty = '0.0.0.0'; break; default: $a_filter_column = self::get_table_identifier($a_filter_column) . $a_filter_column; break; } switch ($a_filter_data[0]) { case 'is_not_equal_to': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} <> %s", $a_filter_data[1]); break; case 'contains': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} LIKE %s", '%' . $a_filter_data[1] . '%'); break; case 'does_not_contain': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} NOT LIKE %s", '%' . $a_filter_data[1] . '%'); break; case 'starts_with': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} LIKE %s", $a_filter_data[1] . '%'); break; case 'ends_with': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} LIKE %s", '%' . $a_filter_data[1]); break; case 'sounds_like': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND SOUNDEX({$a_filter_column}) = SOUNDEX(%s)", $a_filter_data[1]); break; case 'is_empty': self::$sql_filters['where'] .= " AND ({$a_filter_column} = '' OR {$a_filter_column} = '{$a_filter_empty}')"; break; case 'is_not_empty': self::$sql_filters['where'] .= " AND {$a_filter_column} <> '' AND {$a_filter_column} <> '{$a_filter_empty}'"; break; case 'is_greater_than': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} > %s", $a_filter_data[1]); break; case 'is_less_than': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} < %s", $a_filter_data[1]); break; case 'between': $range = explode(',', $a_filter_data[1]); self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} BETWEEN %s AND %s", $range[0], $range[1]); break; case 'matches': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} REGEXP %s", $a_filter_data[1]); break; case 'does_not_match': self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} NOT REGEXP %s", $a_filter_data[1]); break; default: self::$sql_filters['where'] .= $GLOBALS['wpdb']->prepare(" AND {$a_filter_column} = %s", $a_filter_data[1]); } } self::$sql_filters['from']['all_other_tables'] = trim(self::$sql_filters['from']['browsers'] . ' ' . self::$sql_filters['from']['screenres'] . ' ' . self::$sql_filters['from']['content_info'] . ' ' . self::$sql_filters['from']['outbound']); self::$sql_filters['from']['all_tables'] = "{$GLOBALS['wpdb']->prefix}slim_stats t1 " . self::$sql_filters['from']['all_other_tables']; }
$supported_browser_types = array(__('Human', 'wp-slimstat'), __('Bot/Crawler', 'wp-slimstat'), __('Mobile Device', 'wp-slimstat'), __('Syndication Reader', 'wp-slimstat')); $plugin_url = plugins_url('', dirname(__FILE__)); // Set the filters $tables_to_join = 'tb.browser,tb.version,tb.platform,tb.css_version,tb.type,tb.user_agent,tci.content_type,tci.category,tci.author,tci.content_id'; wp_slimstat_db::$filters_normalized['misc']['limit_results'] = wp_slimstat::$options['number_results_raw_data']; if (wp_slimstat::$options['include_outbound_links_right_now'] == 'yes') { $tables_to_join .= ',tob.outbound_domain,tob.outbound_resource'; } // Report Header if (empty($_POST['report_id'])) { wp_slimstat_reports::report_header('slim_p7_02', 'tall'); } // Get the data $results = wp_slimstat_db::get_recent('t1.id', '', $tables_to_join); $count_page_results = count($results); $count_all_results = wp_slimstat_db::count_records('1=1', '*', true, true, $tables_to_join); if ($count_page_results == 0) { echo '<p class="nodata">' . __('No data to display', 'wp-slimstat') . '</p>'; } else { if (wp_slimstat::$options['async_load'] != 'yes' || !empty($_POST['report_id'])) { // Pagination echo wp_slimstat_reports::report_pagination('slim_p7_02', $count_page_results, $count_all_results); // Loop through the results for ($i = 0; $i < $count_page_results; $i++) { $results[$i]['ip'] = long2ip($results[$i]['ip']); $host_by_ip = $results[$i]['ip']; if (wp_slimstat::$options['convert_ip_addresses'] == 'yes') { $gethostbyaddr = gethostbyaddr($results[$i]['ip']); if ($gethostbyaddr != $host_by_ip && !empty($gethostbyaddr)) { $host_by_ip .= ', ' . $gethostbyaddr; }
/** * 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>'; }
public static function fs_url($_filters = '') { // Allow only legitimate requests $request_uri = $_SERVER['REQUEST_URI']; $request_page = 'wp-slim-view-1'; // Are we on the Dashboard? if (empty($_REQUEST['page'])) { $request_uri = str_replace('index.php', 'admin.php', $request_uri); } else { if (array_key_exists($_REQUEST['page'], self::$screens_info)) { $request_page = $_REQUEST['page']; } else { return ''; } } $filtered_url = defined('DOING_AJAX') && DOING_AJAX ? explode('?', $_SERVER["HTTP_REFERER"]) : explode('?', $request_uri); $filtered_url = $filtered_url[0] . '?page=' . $request_page; // Columns $filters_normalized = wp_slimstat_db::parse_filters($_filters, false); if (!empty($filters_normalized['columns'])) { foreach ($filters_normalized['columns'] as $a_key => $a_filter) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode($a_filter[0] . ' ' . $a_filter[1]); } } // Date ranges if (!empty($filters_normalized['date'])) { foreach ($filters_normalized['date'] as $a_key => $a_filter) { if (!empty($a_filter) || $a_filter === 0) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode('equals ' . $a_filter); } } } // Misc filters if (!empty($filters_normalized['misc'])) { foreach ($filters_normalized['misc'] as $a_key => $a_filter) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode('equals ' . $a_filter); } } return $filtered_url; }
<?php // Avoid direct access to this piece of code if (!function_exists('add_action')) { exit(0); } $is_dashboard = empty($_REQUEST['page']) || $_REQUEST['page'] != 'wp-slim-view-1'; // Available icons $supported_browser_icons = array('Android', 'Anonymouse', 'Baiduspider', 'BlackBerry', 'BingBot', 'CFNetwork', 'Chrome', 'Chromium', 'Default Browser', 'Exabot/BiggerBetter', 'FacebookExternalHit', 'FeedBurner', 'Feedfetcher-Google', 'Firefox', 'Internet Archive', 'Googlebot', 'Google Bot', 'Google Feedfetcher', 'Google Web Preview', 'IE', 'IEMobile', 'iPad', 'iPhone', 'iPod Touch', 'Maxthon', 'Mediapartners-Google', 'Microsoft-WebDAV', 'msnbot', 'Mozilla', 'NewsGatorOnline', 'Netscape', 'Nokia', 'Opera', 'Opera Mini', 'Opera Mobi', 'Python', 'PycURL', 'Safari', 'W3C_Validator', 'WordPress', 'Yahoo! Slurp', 'YandexBot'); $supported_os_icons = array('android', 'blackberry os', 'cellos', 'chromeos', 'ios', 'iphone osx', 'java', 'linux', 'macosx', 'rim os', 'symbianos', 'win7', 'win8', 'win8.1', 'winphone7', 'winphone7.5', 'winphone8', 'winphone8.1', 'winvista', 'winxp', 'unknown'); $supported_browser_types = array(__('Human', 'wp-slimstat'), __('Bot/Crawler', 'wp-slimstat'), __('Mobile Device', 'wp-slimstat'), __('Syndication Reader', 'wp-slimstat')); $plugin_url = plugins_url('', dirname(__FILE__)); // Get the data wp_slimstat_db::$debug_message = ''; $all_results = wp_slimstat_db::get_recent(wp_slimstat_reports::$reports_info['slim_p7_02']['callback_args']); $results = array_slice($all_results, wp_slimstat_db::$filters_normalized['misc']['start_from'], wp_slimstat::$options['number_results_raw_data']); // Echo the debug message echo wp_slimstat_db::$debug_message; // Return the results if we are not echoing them (export, email, etc) if (isset($_args['echo']) && $_args['echo'] === false) { return $results; } $count_all_results = count($all_results); $count_page_results = count($results); if ($count_page_results == 0) { echo '<p class="nodata">' . __('No data to display', 'wp-slimstat') . '</p>'; } else { // Pagination echo wp_slimstat_reports::report_pagination($count_page_results, $count_all_results, true, wp_slimstat::$options['number_results_raw_data']); // Show delete button? (only those who can access the settings can see it) $current_user_can_delete = current_user_can(wp_slimstat::$options['capability_can_admin']);
case 'activate-indexes': wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats ADD INDEX {$GLOBALS['wpdb']->prefix}stats_resource_idx(resource(20))"); wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats ADD INDEX {$GLOBALS['wpdb']->prefix}stats_browser_idx(browser(10))"); wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats ADD INDEX {$GLOBALS['wpdb']->prefix}stats_searchterms_idx(searchterms(15))"); wp_slimstat_admin::show_alert_message(__('Congrats! Slimstat is now optimized for <a href="http://www.youtube.com/watch?v=ygE01sOhzz0" target="_blank">ludicrous speed</a>.', 'wp-slimstat'), 'wp-ui-highlight below-h2'); break; case 'deactivate-indexes': wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats DROP INDEX {$GLOBALS['wpdb']->prefix}stats_resource_idx"); wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats DROP INDEX {$GLOBALS['wpdb']->prefix}stats_browser_idx"); wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats DROP INDEX {$GLOBALS['wpdb']->prefix}stats_searchterms_idx"); wp_slimstat_admin::show_alert_message(__('Indexing has been disabled. Enjoy the extra database space!', 'wp-slimstat'), 'wp-ui-highlight below-h2'); break; case 'delete-records': $rows_affected = 0; if (key_exists($_REQUEST['f'], wp_slimstat_db::$columns_names)) { $rows_affected = wp_slimstat::$wpdb->query("\n\t\t\t\t\tDELETE t1.* \n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_stats t1\n\t\t\t\t\tWHERE " . wp_slimstat_db::get_combined_where('', '*', false)); } wp_slimstat_admin::show_alert_message(intval($rows_affected) . ' ' . __('records deleted from your database.', 'wp-slimstat'), 'wp-ui-highlight below-h2'); break; case 'delete-maxmind': @unlink(wp_slimstat::$maxmind_path); wp_slimstat_admin::show_alert_message(__('The geolocation database has been uninstalled from your server.', 'wp-slimstat'), 'wp-ui-highlight below-h2'); break; case 'download-maxmind': $error = wp_slimstat::download_maxmind_database(); if (!empty($error)) { wp_slimstat_admin::show_alert_message($error, 'wp-ui-notification below-h2'); } else { wp_slimstat_admin::show_alert_message(__('The geolocation database has been installed on your server.', 'wp-slimstat'), 'wp-ui-highlight below-h2'); } break;
public static function fs_url($_filters = '', $_view_url = '') { $filtered_url = !empty($_view_url) ? $_view_url : self::$view_url; // Backward compatibility if (is_array($_filters)) { $flat_filters = array(); foreach ($_filters as $a_key => $a_filter_data) { $flat_filters[] = "{$a_key} {$a_filter_data}"; } $_filters = implode('&&&', $flat_filters); } // Columns $filters_normalized = wp_slimstat_db::parse_filters($_filters, false); if (!empty($filters_normalized['columns'])) { foreach ($filters_normalized['columns'] as $a_key => $a_filter) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode($a_filter[0] . ' ' . $a_filter[1]); } } // Date ranges if (!empty($filters_normalized['date'])) { foreach ($filters_normalized['date'] as $a_key => $a_filter) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode('equals ' . $a_filter); } } // Misc filters if (!empty($filters_normalized['misc'])) { foreach ($filters_normalized['misc'] as $a_key => $a_filter) { $filtered_url .= "&fs%5B{$a_key}%5D=" . urlencode('equals ' . $a_filter); } } return $filtered_url; }
/** * 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(); $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('d') . '&&&month equals ' . date('m') . '&&&year equals ' . date('Y') . '&&&interval equals -365'); $count = wp_slimstat_db::count_records(); echo '<a href="' . wp_slimstat_reports::fs_url("resource contains {$parsed_permalink}&&&day equals " . date('d') . '&&&month equals ' . date('m') . '&&&year equals ' . date('Y') . '&&&interval equals -365') . '">' . $count . '</a>'; }
public static function show_report_wrapper($_report_id = 'p0') { $is_ajax = false; if (!empty($_POST['report_id'])) { // Let's make sure the request is coming from the right place check_ajax_referer('meta-box-order', 'security'); $_report_id = $_POST['report_id']; $is_ajax = true; } if (!$is_ajax && (in_array($_report_id, self::$hidden_reports) || wp_slimstat::$options['async_load'] == 'yes')) { return; } // Some boxes need extra information if (in_array($_report_id, array('slim_p1_03', 'slim_p1_08', 'slim_p1_10', 'slim_p1_13', 'slim_p1_17', 'slim_p2_03', 'slim_p2_04', 'slim_p2_05', 'slim_p2_06', 'slim_p2_18', 'slim_p2_19', 'slim_p2_10', 'slim_p3_02', 'slim_p3_04', 'slim_p3_05'))) { $current_pageviews = wp_slimstat_db::count_records(); } switch ($_report_id) { case 'slim_p1_01': case 'slim_p1_03': $chart_data = wp_slimstat_db::get_data_for_chart('COUNT(t1.ip)', 'COUNT(DISTINCT(t1.ip))'); $chart_labels = array(__('Pageviews', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat')); break; case 'slim_p2_01': $chart_data = wp_slimstat_db::get_data_for_chart('COUNT(DISTINCT t1.visit_id)', 'COUNT(DISTINCT t1.ip)', 'AND (tb.type = 0 OR tb.type = 2)'); $chart_labels = array(__('Visits', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat')); break; case 'slim_p3_01': $chart_data = wp_slimstat_db::get_data_for_chart('COUNT(DISTINCT(`domain`))', 'COUNT(DISTINCT(ip))', "AND domain <> '' AND domain <> '{$_SERVER['SERVER_NAME']}'"); $chart_labels = array(__('Domains', 'wp-slimstat'), __('Unique IPs', 'wp-slimstat')); break; case 'slim_p4_01': $sql_from_where = " FROM (SELECT t1.visit_id, count(t1.ip) counthits, MAX(t1.dt) dt FROM [from_tables] WHERE [where_clause] GROUP BY t1.visit_id) AS ts1"; $chart_data = wp_slimstat_db::get_data_for_chart('ROUND(AVG(ts1.counthits),2)', 'MAX(ts1.counthits)', 'AND t1.visit_id > 0', $sql_from_where); $chart_labels = array(__('Avg Pageviews', 'wp-slimstat'), __('Longest visit', 'wp-slimstat')); break; default: } switch ($_report_id) { case 'slim_p1_01': case 'slim_p2_01': case 'slim_p3_01': case 'slim_p4_01': self::show_chart($_report_id, $chart_data, $chart_labels); break; case 'slim_p1_02': self::show_about_wpslimstat($_report_id); break; case 'slim_p1_03': self::show_overview_summary($_report_id, $current_pageviews, $chart_data); break; case 'slim_p1_04': self::show_results('recent', $_report_id, 'user', array('custom_where' => 't1.user <> "" AND t1.dt > ' . (date_i18n('U') - 300), 'use_date_filters' => false)); break; case 'slim_p1_05': case 'slim_p3_08': self::show_spy_view($_report_id); break; case 'slim_p1_06': case 'slim_p3_09': self::show_results('recent', $_report_id, 'searchterms'); break; case 'slim_p1_08': self::show_results('popular', $_report_id, 'resource', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p1_10': case 'slim_p3_05': $self_domain = parse_url(site_url()); $self_domain = $self_domain['host']; //self::show_results('popular_complete', $_report_id, 'domain', array('total_for_percentage' => wp_slimstat_db::count_records('t1.referer <> ""'), 'custom_where' => 't1.domain <> "'.$self_domain.'" AND t1.domain <> ""')); self::show_results('popular', $_report_id, 'referer', array('total_for_percentage' => $current_pageviews, 'custom_where' => 't1.domain <> "' . $self_domain . '" AND t1.domain <> ""')); break; case 'slim_p1_11': // self::show_results('popular_complete', $_report_id, 'user', array('total_for_percentage' => wp_slimstat_db::count_records('t1.user <> ""'))); self::show_results('popular', $_report_id, 'user', array('total_for_percentage' => wp_slimstat_db::count_records('t1.user <> ""'))); break; case 'slim_p1_12': case 'slim_p3_03': case 'slim_p4_14': self::show_results('popular', $_report_id, 'searchterms', array('total_for_percentage' => wp_slimstat_db::count_records('t1.searchterms <> ""'))); break; case 'slim_p1_13': case 'slim_p2_10': case 'slim_p3_04': self::show_results('popular', $_report_id, 'country', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p1_15': self::show_rankings($_report_id); break; case 'slim_p1_17': self::show_results('popular', $_report_id, 'SUBSTRING(t1.language, 1, 2)', array('total_for_percentage' => $current_pageviews, 'as_column' => 'language', 'filter_op' => 'contains')); break; case 'slim_p2_02': self::show_visitors_summary($_report_id, wp_slimstat_db::count_records_having('visit_id > 0', 'ip'), wp_slimstat_db::count_records('t1.visit_id > 0 AND tb.type <> 1', 'visit_id')); break; case 'slim_p2_03': self::show_results('popular', $_report_id, 'language', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p2_04': self::show_results('popular', $_report_id, 'browser', array('total_for_percentage' => $current_pageviews, 'more_columns' => ',tb.version' . (wp_slimstat::$options['show_complete_user_agent_tooltip'] == 'yes' ? ',tb.user_agent' : ''))); break; case 'slim_p2_05': self::show_results('popular', $_report_id, 'ip', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p2_06': self::show_results('popular', $_report_id, 'platform', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p2_07': self::show_results('popular', $_report_id, 'resolution', array('total_for_percentage' => wp_slimstat_db::count_records('tss.resolution <> ""'))); break; case 'slim_p2_09': self::show_plugins($_report_id, wp_slimstat_db::count_records('t1.visit_id > 0 AND tb.type <> 1')); break; case 'slim_p2_12': self::show_visit_duration($_report_id, wp_slimstat_db::count_records('visit_id > 0 AND tb.type <> 1', 'visit_id')); break; case 'slim_p2_13': case 'slim_p3_10': self::show_results('recent', $_report_id, 'country'); break; case 'slim_p2_14': self::show_results('recent', $_report_id, 'resolution', array('join_tables' => 'tss.*')); break; case 'slim_p2_15': self::show_results('recent', $_report_id, 'platform', array('join_tables' => 'tb.*')); break; case 'slim_p2_16': self::show_results('recent', $_report_id, 'browser', array('join_tables' => 'tb.*')); break; case 'slim_p2_17': self::show_results('recent', $_report_id, 'language'); break; case 'slim_p2_18': self::show_results('popular', $_report_id, 'browser', array('total_for_percentage' => $current_pageviews)); break; case 'slim_p2_19': self::show_results('popular', $_report_id, 'CONCAT("p-", SUBSTRING(tb.platform, 1, 3))', array('total_for_percentage' => $current_pageviews, 'as_column' => 'platform')); break; case 'slim_p2_20': self::show_results('recent', $_report_id, 'user', array('custom_where' => 'notes LIKE "%user:%"')); break; case 'slim_p2_21': // self::show_results('popular_complete', $_report_id, 'user', array('total_for_percentage' => wp_slimstat_db::count_records('notes LIKE "%user:%"'), 'custom_where' => 'notes LIKE "%user:%"')); self::show_results('popular', $_report_id, 'user', array('total_for_percentage' => wp_slimstat_db::count_records('notes LIKE "%user:%"'), 'custom_where' => 'notes LIKE "%user:%"')); break; case 'slim_p3_02': self::show_traffic_sources_summary($_report_id, $current_pageviews); break; case 'slim_p3_06': //self::show_results('popular_complete', $_report_id, 'domain', array('total_for_percentage' => wp_slimstat_db::count_records("t1.searchterms <> '' AND t1.domain <> '{$_SERVER['SERVER_NAME']}' AND t1.domain <> ''", 't1.id'), 'custom_where' => "t1.searchterms <> '' AND t1.domain <> '{$_SERVER['SERVER_NAME']}'")); self::show_results('popular', $_report_id, 'domain', array('total_for_percentage' => wp_slimstat_db::count_records("t1.searchterms <> '' AND t1.domain <> '{$_SERVER['SERVER_NAME']}' AND t1.domain <> ''", 't1.id'), 'custom_where' => "t1.searchterms <> '' AND t1.domain <> '{$_SERVER['SERVER_NAME']}'")); break; case 'slim_p3_11': case 'slim_p4_17': self::show_results('popular', $_report_id, 'resource', array('total_for_percentage' => wp_slimstat_db::count_records('t1.domain <> ""'), 'custom_where' => 't1.domain <> ""')); break; case 'slim_p4_02': self::show_results('recent', $_report_id, 'resource', array('custom_where' => 'tci.content_type = "post"')); break; case 'slim_p4_03': self::show_results('recent', $_report_id, 'resource', array('custom_where' => 'tci.content_type <> "404"', 'having_clause' => 'HAVING COUNT(visit_id) = 1')); break; case 'slim_p4_04': self::show_results('recent', $_report_id, 'resource', array('custom_where' => '(t1.resource LIKE "%/feed%" OR t1.resource LIKE "%?feed=%" OR t1.resource LIKE "%&feed=%" OR tci.content_type LIKE "%feed%")')); break; case 'slim_p4_05': self::show_results('recent', $_report_id, 'resource', array('custom_where' => '(t1.resource LIKE "[404]%" OR tci.content_type LIKE "%404%")')); break; case 'slim_p4_06': self::show_results('recent', $_report_id, 'searchterms', array('custom_where' => '(t1.resource = "__l_s__" OR t1.resource = "" OR tci.content_type LIKE "%search%")')); break; case 'slim_p4_07': self::show_results('popular', $_report_id, 'category', array('total_for_percentage' => wp_slimstat_db::count_records('(tci.content_type LIKE "%category%")'), 'custom_where' => '(tci.content_type LIKE "%category%")')); break; case 'slim_p4_08': self::show_spy_view($_report_id, 0); break; case 'slim_p4_10': self::show_spy_view($_report_id, -1); break; case 'slim_p4_11': self::show_results('popular', $_report_id, 'resource', array('total_for_percentage' => wp_slimstat_db::count_records('tci.content_type = "post"'), 'custom_where' => 'tci.content_type = "post"')); break; case 'slim_p4_12': self::show_results('popular', $_report_id, 'resource', array('total_for_percentage' => wp_slimstat_db::count_records('(t1.resource LIKE "%/feed%" OR t1.resource LIKE "%?feed=%" OR t1.resource LIKE "%&feed=%" OR tci.content_type LIKE "%feed%")'), 'custom_where' => '(t1.resource LIKE "%/feed%" OR t1.resource LIKE "%?feed=%" OR t1.resource LIKE "%&feed=%" OR tci.content_type LIKE "%feed%")')); break; case 'slim_p4_13': self::show_results('popular', $_report_id, 'searchterms', array('total_for_percentage' => wp_slimstat_db::count_records('(t1.resource = "__l_s__" OR t1.resource = "" OR tci.content_type LIKE "%search%")'), 'custom_where' => '(t1.resource = "__l_s__" OR t1.resource = "" OR tci.content_type LIKE "%search%")')); break; case 'slim_p4_15': self::show_results('recent', $_report_id, 'resource', array('custom_where' => '(tci.content_type = "category" OR tci.content_type = "tag")', 'join_tables' => 'tci.*')); break; case 'slim_p4_16': self::show_results('popular', $_report_id, 'resource', array('total_for_percentage' => wp_slimstat_db::count_records('(t1.resource LIKE "[404]%" OR tci.content_type LIKE "%404%")'), 'custom_where' => '(t1.resource LIKE "[404]%" OR tci.content_type LIKE "%404%")')); break; case 'slim_p4_18': self::show_results('popular', $_report_id, 'author', array('total_for_percentage' => wp_slimstat_db::count_records('tci.author <> ""'))); break; case 'slim_p4_19': self::show_results('popular', $_report_id, 'category', array('total_for_percentage' => wp_slimstat_db::count_records('(tci.content_type LIKE "%tag%")'), 'custom_where' => '(tci.content_type LIKE "%tag%")', 'more_columns' => ',tci.category')); break; case 'slim_p4_20': self::show_spy_view($_report_id, 1); break; case 'slim_p4_21': self::show_results('popular_outbound', $_report_id, 'resource', array('total_for_percentage' => wp_slimstat_db::count_outbound())); break; case 'slim_p4_22': self::show_your_blog($_report_id); break; case 'slim_p6_01': self::show_world_map($_report_id); break; case 'slim_p7_02': include_once WP_PLUGIN_DIR . "/wp-slimstat/admin/view/right-now.php"; break; default: } if (!empty($_POST['report_id'])) { die; } }
} // Available icons $supported_browser_icons = array('Android', 'Anonymouse', 'Baiduspider', 'BlackBerry', 'BingBot', 'CFNetwork', 'Chrome', 'Chromium', 'Default Browser', 'Exabot/BiggerBetter', 'FacebookExternalHit', 'FeedBurner', 'Feedfetcher-Google', 'Firefox', 'Internet Archive', 'Googlebot', 'Google Bot', 'Google Feedfetcher', 'Google Web Preview', 'IE', 'IEMobile', 'iPad', 'iPhone', 'iPod Touch', 'Maxthon', 'Mediapartners-Google', 'Microsoft-WebDAV', 'msnbot', 'Mozilla', 'NewsGatorOnline', 'Netscape', 'Nokia', 'Opera', 'Opera Mini', 'Opera Mobi', 'Python', 'PycURL', 'Safari', 'W3C_Validator', 'WordPress', 'Yahoo! Slurp', 'YandexBot'); $supported_os_icons = array('android', 'blackberry os', 'cellos', 'chromeos', 'ios', 'iphone osx', 'java', 'linux', 'macosx', 'rim os', 'symbianos', 'win7', 'win8', 'win8.1', 'winphone7', 'winphone7.5', 'winphone8', 'winphone8.1', 'winvista', 'winxp', 'unknown'); $supported_browser_types = array(__('Human', 'wp-slimstat'), __('Bot/Crawler', 'wp-slimstat'), __('Mobile Device', 'wp-slimstat'), __('Syndication Reader', 'wp-slimstat')); $plugin_url = plugins_url('', dirname(__FILE__)); // Set the filters wp_slimstat_db::$filters_normalized['misc']['limit_results'] = wp_slimstat::$options['number_results_raw_data']; // Get the data $results = wp_slimstat_db::get_recent('*'); // Return the results if we are not echoing them (export, email, etc) if (isset($_args['echo']) && $_args['echo'] === false) { return $results; } $count_page_results = count($results); $count_all_results = wp_slimstat_db::count_records(); if ($count_page_results == 0) { echo '<p class="nodata">' . __('No data to display', 'wp-slimstat') . '</p>'; } else { // Pagination echo wp_slimstat_reports::report_pagination($count_page_results, $count_all_results, true); // Show delete button? (only those who can access the settings can see it) $current_user_can_delete = current_user_can(wp_slimstat::$options['capability_can_admin']); $delete_row = ''; // Loop through the results for ($i = 0; $i < $count_page_results; $i++) { $results[$i]['ip'] = long2ip($results[$i]['ip']); $host_by_ip = $results[$i]['ip']; if (wp_slimstat::$options['convert_ip_addresses'] == 'yes') { $gethostbyaddr = gethostbyaddr($results[$i]['ip']); if ($gethostbyaddr != $host_by_ip && !empty($gethostbyaddr)) {
/** * 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('&&&', '&&&', $_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 slim_p4_11() { wp_slimstat_reports::show_results('popular', 'slim_p4_11', 'resource', array('total_for_percentage' => wp_slimstat_db::count_records('tci.content_type = "post"'), 'custom_where' => 'tci.content_type = "post"')); }
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; }
public static function get_top_events() { if (empty(self::$filters_normalized['columns'])) { $from = "{$GLOBALS['wpdb']->prefix}slim_events te"; $where = wp_slimstat_db::get_combined_where('te.type > 1', 'notes'); } else { $from = "{$GLOBALS['wpdb']->prefix}slim_events te INNER JOIN {$GLOBALS['wpdb']->prefix}slim_stats t1 ON te.id = t1.id"; $where = wp_slimstat_db::get_combined_where('te.type > 1', 'notes', true, 't1'); } return self::get_results("\n\t\t\tSELECT te.notes, te.type, COUNT(*) counthits\n\t\t\tFROM {$from}\n\t\t\tWHERE {$where}\n\t\t\tGROUP BY te.notes, te.type\n\t\t\tORDER BY counthits DESC"); }