/** * 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>'; }
$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-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>'; }
public static function show_traffic_sources_summary() { $total_human_hits = wp_slimstat_db::count_records('id', 'visit_id > 0 AND browser_type <> 1'); $new_visitors = wp_slimstat_db::count_records_having('ip', 'visit_id > 0', 'COUNT(visit_id) = 1'); $new_visitors_rate = $total_human_hits > 0 ? sprintf("%01.2f", 100 * $new_visitors / $total_human_hits) : 0; if (intval($new_visitors_rate) > 99) { $new_visitors_rate = '100'; } ?> <p><?php self::inline_help(__('A request to load a single HTML file. Slimstat logs a "pageview" each time the tracking code is executed.', 'wp-slimstat')); ?> <?php _e('Pageviews', 'wp-slimstat'); ?> <span><?php echo number_format(self::$pageviews, 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__('A referrer (or referring site) is the site that a visitor previously visited before following a link to your site.', 'wp-slimstat')); ?> <?php _e('Unique Referrers', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_records('referer', "referer NOT LIKE '%{$_SERVER['SERVER_NAME']}%'"), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__("Visitors who visited the site by typing the URL directly into their browser. <em>Direct</em> can also refer to the visitors who clicked on the links from their bookmarks/favorites, untagged links within emails, or links from documents that don't include tracking variables.", 'wp-slimstat')); ?> <?php _e('Direct Pageviews', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_records('id', 'resource IS NULL'), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__("Visitors who came to your site via searches on Google or some other search engine.", 'wp-slimstat')); ?> <?php _e('From a search result', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_records('id', "searchterms IS NOT NULL AND referer IS NOT NULL AND referer NOT LIKE '%" . home_url() . "%'"), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__("The first page that a user views during a session. This is also known as the <em>entrance page</em>. For example, if they search for 'Brooklyn Office Space,' and they land on your home page, it gets counted (for that visit) as a landing page.", 'wp-slimstat')); ?> <?php _e('Unique Landing Pages', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_records('resource'), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__("Number of single-page visits to your site over the selected period.", 'wp-slimstat')); ?> <?php _e('Bounce Pages', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_bouncing_pages(), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p> <p><?php self::inline_help(__('Percentage of single-page visits, i.e. visits in which the person left your site from the entrance page.', 'wp-slimstat')); ?> <?php _e('New Visitors Rate', 'wp-slimstat'); ?> <span><?php echo number_format($new_visitors_rate, 2, wp_slimstat_db::$formats['decimal'], wp_slimstat_db::$formats['thousand']); ?> %</span></p> <p><?php self::inline_help(__("Visitors who visited the site in the last 5 minutes coming from a search engine.", 'wp-slimstat')); ?> <?php _e('Currently from search engines', 'wp-slimstat'); ?> <span><?php echo number_format(wp_slimstat_db::count_records('id', "searchterms IS NOT NULL AND referer IS NOT NULL AND referer NOT LIKE '%" . home_url() . "%' AND dt > UNIX_TIMESTAMP()-300", false), 0, '', wp_slimstat_db::$formats['thousand']); ?> </span></p><?php if (defined('DOING_AJAX') && DOING_AJAX) { die; } }
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; }