function wp_statistics_editor_meta_box($post) { // If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason. if (($is_visible = wp_statistics_is_wp_widget_visible('wp_statistics_editor_meta_box', $post->post_type)) !== true) { echo $is_visible; return; } // If the post isn't published yet, don't output the stats as they take too much memory and CPU to compute for no reason. if ($post->post_status != 'publish' && $post->post_status != 'private') { _e('This post is not yet published.', 'wp_statistics'); return; } include_once dirname(__FILE__) . '/includes/log/widgets/page.php'; wp_statistics_load_widget_css_and_scripts(); wp_statistics_generate_page_postbox_content(null, $post->ID, 20, __('Hits in the last 20 days', 'wp_statistics')); }
function wp_statistics_dashboard_inline_javascript() { $screen = get_current_screen(); if( 'dashboard' != $screen->id ) { return; } wp_statistics_load_widget_css_and_scripts(); $loading_img = '<div style="width: 100%; text-align: center;"><img src=" ' . plugins_url('wp-statistics/assets/images/') . 'ajax-loading.gif" alt="' . __( 'Reloading...', 'wp_statistics' ) . '"></div>'; $new_buttons = '</button><button class="handlediv button-link wps-refresh" type="button" id="{{refreshid}}">' . wp_statistics_icons( 'dashicons-update' ) . '</button><button class="handlediv button-link wps-more" type="button" id="{{moreid}}">' . wp_statistics_icons( 'dashicons-migrate' ) . '</button>'; $new_button = '</button><button class="handlediv button-link wps-refresh" type="button" id="{{refreshid}}">' . wp_statistics_icons( 'dashicons-update' ) . '</button>'; $admin_url = get_admin_url() . "/admin.php?page="; $page_urls = array(); $page_urls['wp-statistics-browsers-widget_more_button'] = $admin_url . WP_STATISTICS_BROWSERS_PAGE; $page_urls['wp-statistics-countries-widget_more_button'] = $admin_url . WP_STATISTICS_COUNTRIES_PAGE; $page_urls['wp-statistics-exclusions-widget_more_button'] = $admin_url . WP_STATISTICS_EXCLUSIONS_PAGE; $page_urls['wp-statistics-hits-widget_more_button'] = $admin_url . WP_STATISTICS_HITS_PAGE; $page_urls['wp-statistics-online-widget_more_button'] = $admin_url . WP_STATISTICS_ONLINE_PAGE; $page_urls['wp-statistics-pages-widget_more_button'] = $admin_url . WP_STATISTICS_PAGES_PAGE; $page_urls['wp-statistics-referring-widget_more_button'] = $admin_url . WP_STATISTICS_REFERRERS_PAGE; $page_urls['wp-statistics-search-widget_more_button'] = $admin_url . WP_STATISTICS_SEARCHES_PAGE; $page_urls['wp-statistics-words-widget_more_button'] = $admin_url . WP_STATISTICS_WORDS_PAGE; $page_urls['wp-statistics-top-visitors-widget_more_button'] = $admin_url . WP_STATISTICS_TOP_VISITORS_PAGE; $page_urls['wp-statistics-visitors-widget_more_button'] = $admin_url . WP_STATISTICS_VISITORS_PAGE; $page_urls['wp-statistics-quickstats-widget_more_button'] = $admin_url . WP_STATISTICS_OVERVIEW_PAGE; ?> <script type="text/javascript"> var wp_statistics_destinations = <?php echo json_encode( $page_urls ); ?>; var wp_statistics_loading_image = '<?php echo $loading_img; ?>' function wp_statistics_wait_for_postboxes() { if( ! jQuery('#show-settings-link').is( ':visible') ) { setTimeout( wp_statistics_wait_for_postboxes, 500 ); } jQuery('.wps-refresh').unbind('click').on('click', wp_statistics_refresh_widget ); jQuery('.wps-more').unbind('click').on('click', wp_statistics_goto_more ); jQuery('.hide-postbox-tog').on('click', wp_statistics_refresh_on_toggle_widget ); } jQuery(document).ready(function(){ // Add the "more" and "refresh" buttons. jQuery('.postbox').each( function () { var temp = jQuery( this ); var temp_id = temp.attr( 'id' ); if( temp_id.substr( 0, 14 ) != 'wp-statistics-' ) { return; } var temp_html = temp.html(); if( temp_id == 'wp-statistics-summary-widget' ) { new_text = '<?php echo $new_button;?>'; new_text = new_text.replace( '{{refreshid}}', temp_id + '_refresh_button' ); temp_html = temp_html.replace( '</button>', new_text ); } else { new_text = '<?php echo $new_buttons;?>'; new_text = new_text.replace( '{{refreshid}}', temp_id + '_refresh_button' ); new_text = new_text.replace( '{{moreid}}', temp_id + '_more_button' ); temp_html = temp_html.replace( '</button>', new_text ); } temp.html( temp_html ); }); // We have use a timeout here because we don't now what order this code will run in comparison to the postbox code. // Any timeout value should work as the timeout won't run until the rest of the javascript as run through once. setTimeout( wp_statistics_wait_for_postboxes, 100 ); }); </script> <?php }
function wp_statistics_top_visitors_widget() { global $WP_Statistics; // If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason. if (($is_visible = wp_statistics_is_wp_widget_visible('wp-statistics-top-visitors-widget', 'dashboard')) !== true) { echo $is_visible; return; } // Load the css we use for the statistics pages. wp_statistics_load_widget_css_and_scripts(); // Include the summary widget, we're just going to use the content for the the users online and visit/visitor totals. $ISOCountryCode = $WP_Statistics->get_country_codes(); include_once dirname(__FILE__) . "/includes/log/widgets/top.visitors.php"; wp_statistics_generate_top_visitors_postbox_content($ISOCountryCode, 'today', 10, true); }
function wp_statistics_editor_inline_javascript() { $screen = get_current_screen(); if ('post' != $screen->id && 'page' != $screen->id) { return; } wp_statistics_load_widget_css_and_scripts(); $loading_img = '<div style="width: 100%; text-align: center;"><img src=" ' . plugins_url('wp-statistics/assets/images/') . 'ajax-loading.gif" alt="' . __('Reloading...', 'wp_statistics') . '"></div>'; $new_buttons = '</button><button class="handlediv button-link wps-refresh" type="button" id="{{refreshid}}">' . wp_statistics_icons('dashicons-update') . '</button><button class="handlediv button-link wps-more" type="button" id="{{moreid}}">' . wp_statistics_icons('dashicons-migrate') . '</button>'; $new_button = '</button><button class="handlediv button-link wps-refresh" type="button" id="{{refreshid}}">' . wp_statistics_icons('dashicons-update') . '</button>'; $admin_url = get_admin_url() . "/admin.php?page="; $page_urls = array(); $page_urls['wp_statistics_editor_meta_box_more_button'] = $admin_url . WP_STATISTICS_PAGES_PAGE . '&page-id='; ?> <script type="text/javascript"> var wp_statistics_destinations = <?php echo json_encode($page_urls); ?> ; var wp_statistics_loading_image = '<?php echo $loading_img; ?> ' function wp_statistics_wait_for_postboxes() { if( ! jQuery('#show-settings-link').is( ':visible') ) { setTimeout( wp_statistics_wait_for_postboxes, 500 ); } jQuery('.wps-refresh').unbind('click').on('click', wp_statistics_refresh_widget ); jQuery('.wps-more').unbind('click').on('click', wp_statistics_goto_more ); jQuery('.hide-postbox-tog').on('click', wp_statistics_refresh_on_toggle_widget ); } jQuery(document).ready(function(){ // Add the "more" and "refresh" buttons. jQuery('.postbox').each( function () { var temp = jQuery( this ); var temp_id = temp.attr( 'id' ); if( temp_id == 'wp_statistics_editor_meta_box' ) { var temp_html = temp.html(); new_text = '<?php echo $new_buttons; ?> '; new_text = new_text.replace( '{{refreshid}}', temp_id + '_refresh_button' ); new_text = new_text.replace( '{{moreid}}', temp_id + '_more_button' ); temp_html = temp_html.replace( '</button>', new_text ); temp.html( temp_html ); } }); // We have use a timeout here because we don't now what order this code will run in comparison to the postbox code. // Any timeout value should work as the timeout won't run until the rest of the javascript as run through once. setTimeout( wp_statistics_wait_for_postboxes, 100 ); }); </script> <?php }