'tptn_dashboard', 'post-date-filter-from' => current_time( 'd M Y' ), 'post-date-filter-to' => current_time( 'd M Y' ), ), admin_url( 'admin.php' ) ), 'tptn-dashboard' ) ); return $items; } /** * Add a better icon for Top 10 At a Glance items. * * @since 4.3.0 */ public function dashboard_glance_styles() { ?> base_prefix . 'top_ten_daily'; $sql = $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT SUM(cntaccess) FROM {$table} WHERE dp_date >= %s AND dp_date <= %s AND blog_id = %d", $from_hour, $to_hour, get_current_blog_id() ); $views = $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared return (int) $views; } /** * Build a Top 10 At a Glance item. * * @since 4.3.0 * * @param int $views Views. * @param string $label Label with a %s placeholder for the formatted count. * @param string $url Link URL. * @return string At a Glance item markup. */ public static function get_glance_item( $views, $label, $url ) { return sprintf( '%2$s', esc_url( $url ), esc_html( sprintf( $label, Helpers::number_format_i18n( $views ) ) ) ); } /** * Function to add the widgets to the Dashboard. * * @since 3.3.0 */ public static function wp_dashboard_setup() { /** * Filter whether to register the dashboard widgets. * * @since 3.3.0 * * @param bool $dashboard_setup Whether to register the dashboard widgets. */ $dashboard_setup = apply_filters( 'tptn_dashboard_setup', true ); if ( $dashboard_setup && ( current_user_can( 'manage_options' ) || \tptn_get_option( 'show_count_non_admins' ) ) ) { // Add the overall popular posts widget. wp_add_dashboard_widget( 'tptn_overall_dashboard', __( 'Top 10 - Overall Popular Posts', 'top-10' ), array( __CLASS__, 'popular_posts_widget' ), array( __CLASS__, 'pop_display' ) ); // Add the daily popular posts widget. wp_add_dashboard_widget( 'tptn_daily_dashboard', /* translators: %s: Custom period label (e.g. Daily, Custom (7 days)). */ sprintf( __( 'Top 10 - %s Popular Posts', 'top-10' ), Helpers::get_daily_range_label( 1 ) ), array( __CLASS__, 'popular_posts_widget_daily' ), array( __CLASS__, 'pop_display' ) ); // Add the mini views overview widget. wp_add_dashboard_widget( 'tptn_views_over_time_dashboard', __( 'Top 10 Views Overview', 'top-10' ), array( __CLASS__, 'views_over_time_widget' ), ); } } /** * Function to add the widgets to the Network Dashboard. * * @since 4.2.0 */ public static function wp_network_dashboard_setup() { /** * Filter whether to register the network dashboard widgets. * * @since 4.2.0 * * @param bool $dashboard_setup Whether to register the network dashboard widgets. */ $dashboard_setup = apply_filters( 'tptn_network_dashboard_setup', true ); if ( $dashboard_setup && current_user_can( 'manage_network' ) ) { // Add the overall popular posts widget. wp_add_dashboard_widget( 'tptn_network_overall_dashboard', __( 'Top 10 - Network Popular Posts', 'top-10' ), array( __CLASS__, 'network_popular_posts_widget' ), array( __CLASS__, 'pop_display' ) ); // Add the daily popular posts widget. wp_add_dashboard_widget( 'tptn_network_daily_dashboard', /* translators: %s: Custom period label (e.g. Daily, Custom (7 days)). */ sprintf( __( 'Top 10 - Network %s Popular Posts', 'top-10' ), Helpers::get_daily_range_label( 1 ) ), array( __CLASS__, 'network_popular_posts_widget_daily' ), array( __CLASS__, 'pop_display' ) ); // Add the mini views overview widget to network dashboard. wp_add_dashboard_widget( 'tptn_network_views_over_time_dashboard', __( 'Top 10 Network Views Overview', 'top-10' ), array( __CLASS__, 'views_over_time_widget' ), ); } } /** * Create the Dashboard Widget and content of the Popular pages * * @since 3.3.0 * * @param bool $daily Switch for Custom Period or Overall popular posts. * @param int $page Which page of the lists are on. * @param int $limit Maximum number of posts per page. * @param bool $widget Is this a WordPress widget. * @param bool $network Whether to show network-wide posts. * @return string Formatted list of popular posts */ public static function pop_display( $daily = false, $page = 0, $limit = 0, $widget = true, $network = false ) { if ( ! $limit ) { $limit = \tptn_get_option( 'limit' ); } $args = array(); $visits = 'total_count'; if ( $daily ) { $args['orderby'] = 'daily_count'; $visits = 'daily_count'; } $statistics_table = new Statistics_Table( $network ); $results = $statistics_table->get_popular_posts( $limit, $page + 1, $args ); $output = '
'; if ( $daily ) { if ( $network ) { $output .= '' . __( 'View all network daily popular posts', 'top-10' ) . ''; } else { $output .= '' . __( 'View all daily popular posts', 'top-10' ) . ''; } } elseif ( $network ) { $output .= '' . __( 'View all network popular posts', 'top-10' ) . ''; } else { $output .= '' . __( 'View all popular posts', 'top-10' ) . ''; } $output .= '
'; $output .= ''; /* translators: 1: Top 10 page link. */ $output .= sprintf( __( 'Popular posts by Top 10 plugin', 'top-10' ), esc_url( 'https://webberzone.com/plugins/top-10/' ) ); $output .= '
'; $output .= '