'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', __( 'Top 10 - Daily Popular Posts', 'top-10' ), 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', __( 'Top 10 - Network Daily Popular Posts', 'top-10' ), 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 Daily 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 = ''; /** * Filters the dashboard widget output * * @since 3.3.0 * * @param string $output Widget output * @param bool $daily Is this a daily widget * @param int $page Page number * @param int $limit Limit of posts * @param bool $widget Is this a widget * @param bool $network Is this network-wide */ return apply_filters( 'tptn_popular_posts_widget_output', $output, $daily, $page, $limit, $widget, $network ); } /** * Widget for Popular Posts. * * @since 3.3.0 */ public static function popular_posts_widget() { echo self::pop_display( false ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Widget for Daily Popular Posts. * * @since 3.3.0 */ public static function popular_posts_widget_daily() { echo self::pop_display( true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Widget for Network Popular Posts. * * @since 4.2.0 */ public static function network_popular_posts_widget() { echo self::pop_display( false, 0, 0, true, true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Widget for Network Daily Popular Posts. * * @since 4.2.0 */ public static function network_popular_posts_widget_daily() { echo self::pop_display( true, 0, 0, true, true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Widget for Views Overview (mini chart). * * @since 4.2.0 */ public static function views_over_time_widget() { global $tptn_freemius; $output = '
'; if ( ! $tptn_freemius->is_paying() ) { $output .= sprintf( '
%s
', esc_html__( 'Upgrade to Top 10 Pro to see your views over time chart here.', 'top-10' ) ); $output .= sprintf( '

%s

', esc_url( $tptn_freemius->get_upgrade_url() ), esc_html__( 'Upgrade to Pro', 'top-10' ) ); } $output .= '
'; /** * Filters the views over time widget content. * * @since 4.2.0 * * @param string $output The widget content. */ $output = apply_filters( 'tptn_views_over_time_widget_content', $output ); echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }