Skip to:
Content

bbPress.org

Changeset 2770


Ignore:
Timestamp:
01/07/2011 09:25:53 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Introduce forum statistics dashboard widget. Fixes #1438. Props GautamGupta via Google Code-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-admin.php

    r2765 r2770  
    4141
    4242        // Add notice if not using a bbPress theme
    43         add_action( 'admin_notices',               array( $this, 'activation_notice'       )        );
     43        add_action( 'admin_notices',               array( $this, 'activation_notice'          )        );
    4444
    4545        // Add link to settings page
    46         add_filter( 'plugin_action_links',         array( $this, 'add_settings_link'       ), 10, 2 );
     46        add_filter( 'plugin_action_links',         array( $this, 'add_settings_link'          ), 10, 2 );
    4747
    4848        // Add menu item to settings menu
    49         add_action( 'admin_menu',                  array( $this, 'admin_menus'             )        );
     49        add_action( 'admin_menu',                  array( $this, 'admin_menus'                )        );
    5050
    5151        // Add the settings
    52         add_action( 'admin_init',                  array( $this, 'register_admin_settings' )        );
     52        add_action( 'admin_init',                  array( $this, 'register_admin_settings'    )        );
    5353
    5454        // Attach the bbPress admin init action to the WordPress admin init action.
    55         add_action( 'admin_init',                  array( $this, 'init'                    )        );
     55        add_action( 'admin_init',                  array( $this, 'init'                       )        );
    5656
    5757        // Add some general styling to the admin area
    58         add_action( 'admin_head',                  array( $this, 'admin_head'              )        );
     58        add_action( 'admin_head',                  array( $this, 'admin_head'                 )        );
    5959
    6060        // Register bbPress admin style
    61         add_action( 'admin_init',                  array( $this, 'register_admin_style'    )        );
     61        add_action( 'admin_init',                  array( $this, 'register_admin_style'       )        );
     62
     63        // Forums 'Right now' Dashboard widget
     64        add_action( 'wp_dashboard_setup',          array( $this, 'dashboard_widget_right_now' )        );
    6265
    6366        /** User Actions **********************************************/
     
    246249    function init() {
    247250        do_action( 'bbp_admin_init' );
     251    }
     252
     253    /**
     254     * Add the 'Right now in Forums' dashboard widget
     255     *
     256     * @since bbPress (r2770)
     257     *
     258     * @uses wp_add_dashboard_widget() To add the dashboard widget
     259     */
     260    function dashboard_widget_right_now() {
     261        wp_add_dashboard_widget( 'bbp_dashboard_right_now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' );
    248262    }
    249263
     
    457471        <style type="text/css" media="screen">
    458472        /*<![CDATA[*/
     473
     474            /* =bbPress 'Right Now in Forums' Dashboard Widget
     475            -------------------------------------------------------------- */
     476
     477            #bbp_dashboard_right_now p.sub,
     478            #bbp_dashboard_right_now .table, #bbp_dashboard_right_now .versions {
     479                margin: -12px;
     480            }
     481
     482            #bbp_dashboard_right_now .inside {
     483                font-size: 12px;
     484                padding-top: 20px;
     485            }
     486
     487            #bbp_dashboard_right_now p.sub {
     488                font-style: italic;
     489                font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
     490                padding: 5px 10px 15px;
     491                color: #777;
     492                font-size: 13px;
     493                position: absolute;
     494                top: -17px;
     495                left: 15px;
     496            }
     497
     498            #bbp_dashboard_right_now .table {
     499                margin: 0 -9px;
     500                padding: 0 10px;
     501                position: relative;
     502            }
     503
     504            #bbp_dashboard_right_now .table_content {
     505                float: left;
     506                border-top: #ececec 1px solid;
     507                width: 45%;
     508            }
     509
     510            #bbp_dashboard_right_now .table_discussion {
     511                float: right;
     512                border-top: #ececec 1px solid;
     513                width: 45%;
     514            }
     515
     516            #bbp_dashboard_right_now table td {
     517                padding: 3px 0;
     518                white-space: nowrap;
     519            }
     520
     521            #bbp_dashboard_right_now table tr.first td {
     522                border-top: none;
     523            }
     524
     525            #bbp_dashboard_right_now td.b {
     526                padding-right: 6px;
     527                text-align: right;
     528                font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
     529                font-size: 14px;
     530                width: 1%;
     531            }
     532
     533            #bbp_dashboard_right_now td.b a {
     534                font-size: 18px;
     535            }
     536
     537            #bbp_dashboard_right_now td.b a:hover {
     538                color: #d54e21;
     539            }
     540
     541            #bbp_dashboard_right_now .t {
     542                font-size: 12px;
     543                padding-right: 12px;
     544                padding-top: 6px;
     545                color: #777;
     546            }
     547
     548            #bbp_dashboard_right_now .t a {
     549                white-space: nowrap;
     550            }
     551
     552            #bbp_dashboard_right_now .spam {
     553                color: red;
     554            }
     555
     556            #bbp_dashboard_right_now .waiting {
     557                color: #e66f00;
     558            }
     559
     560            #bbp_dashboard_right_now .approved {
     561                color: green;
     562            }
     563
     564            #bbp_dashboard_right_now .versions {
     565                padding: 6px 10px 12px;
     566                clear: both;
     567            }
     568
     569            #bbp_dashboard_right_now .versions .b {
     570                font-weight: bold;
     571            }
     572
     573            #bbp_dashboard_right_now a.button {
     574                float: right;
     575                clear: right;
     576                position: relative;
     577                top: -5px;
     578            }
     579
    459580            #menu-posts-<?php echo $forum_class; ?> .wp-menu-image {
    460581                background: url(<?php echo $menu_icon_url; ?>) no-repeat 0px -32px;
     
    13811502}
    13821503
     1504
     1505/**
     1506 * bbPress Dashboard Right Now Widget
     1507 *
     1508 * Adds a dashboard widget with forum statistics
     1509 *
     1510 * @todo Check for updates and show notice
     1511 *
     1512 * @since bbPress (r2770)
     1513 *
     1514 * @uses bbp_get_statistics() To get the forum statistics
     1515 * @uses current_user_can() To check if the user is capable of doing things
     1516 * @uses get_admin_url() To get the administration url
     1517 * @uses add_query_arg() To add custom args to the url
     1518 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_content_table_end'
     1519 *                    below the content table
     1520 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_table_end'
     1521 *                    below the discussion table
     1522 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_discussion_table_end'
     1523 *                    below the discussion table
     1524 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_end' below the widget
     1525 */
     1526function bbp_dashboard_widget_right_now() {
     1527    global $bbp;
     1528
     1529    // Get the statistics and extract them
     1530    extract( bbp_get_statistics(), EXTR_SKIP ); ?>
     1531
     1532    <div class="table table_content">
     1533
     1534        <p class="sub"><?php _e( 'Content', 'bbpress' ); ?></p>
     1535
     1536        <table>
     1537
     1538            <tr class="first">
     1539
     1540                <?php
     1541                    $num  = $forum_count;
     1542                    $text = _n( 'Forum', 'Forums', $forum_count, 'bbpress' );
     1543                    if ( current_user_can( 'publish_forums' ) ) {
     1544                        $link = add_query_arg( array( 'post_type' => $bbp->forum_id ), get_admin_url( null, 'edit.php' ) );
     1545                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1546                        $text = '<a href="' . $link . '">' . $text . '</a>';
     1547                    }
     1548                ?>
     1549
     1550                <td class="first b b-forums"><?php echo $num; ?></td>
     1551                <td class="t forums"><?php echo $text; ?></td>
     1552
     1553            </tr>
     1554
     1555            <tr>
     1556
     1557                <?php
     1558                    $num  = $topic_count;
     1559                    $text = _n( 'Topic', 'Topics', $topic_count, 'bbpress' );
     1560                    if ( current_user_can( 'publish_topics' ) ) {
     1561                        $link = add_query_arg( array( 'post_type' => $bbp->topic_id ), get_admin_url( null, 'edit.php' ) );
     1562                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1563                        $text = '<a href="' . $link . '">' . $text . '</a>';
     1564                    }
     1565                ?>
     1566
     1567                <td class="first b b-topics"><?php echo $num; ?></td>
     1568                <td class="t topics"><?php echo $text; ?></td>
     1569
     1570            </tr>
     1571
     1572            <tr>
     1573
     1574                <?php
     1575                    $num  = $reply_count;
     1576                    $text = _n( 'Reply', 'Replies', $reply_count, 'bbpress' );
     1577                    if ( current_user_can( 'publish_replies' ) ) {
     1578                        $link = add_query_arg( array( 'post_type' => $bbp->reply_id ), get_admin_url( null, 'edit.php' ) );
     1579                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1580                        $text = '<a href="' . $link . '">' . $text . '</a>';
     1581                    }
     1582                ?>
     1583
     1584                <td class="first b b-replies"><?php echo $num; ?></td>
     1585                <td class="t replies"><?php echo $text; ?></td>
     1586
     1587            </tr>
     1588
     1589            <tr>
     1590
     1591                <?php
     1592                    $num  = $topic_tag_count;
     1593                    $text = _n( 'Topic Tag', 'Topic Tags', $topic_tag_count, 'bbpress' );
     1594                    if ( current_user_can( 'manage_topic_tags' ) ) {
     1595                        $link = add_query_arg( array( 'taxonomy' => $bbp->topic_tag_id, 'post_type' => $bbp->topic_id ), get_admin_url( null, 'edit-tags.php' ) );
     1596                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1597                        $text = '<a href="' . $link . '">' . $text . '</a>';
     1598                    }
     1599                ?>
     1600
     1601                <td class="first b b-topic_tags"><span class="total-count"><?php echo $num; ?></a></td>
     1602                <td class="t topic_tags"><?php echo $text; ?></td>
     1603
     1604            </tr>
     1605
     1606            <?php do_action( 'bbp_dashboard_widget_right_now_content_table_end' ); ?>
     1607
     1608        </table>
     1609
     1610    </div>
     1611
     1612
     1613    <div class="table table_discussion">
     1614
     1615        <p class="sub"><?php _e( 'Discussion', 'bbpress' ); ?></p>
     1616
     1617        <table>
     1618
     1619            <tr class="first">
     1620
     1621                <?php
     1622                    $num  = $user_count;
     1623                    $text = _n( 'User', 'Users', $user_count, 'bbpress' );
     1624                    if ( current_user_can( 'edit_users' ) ) {
     1625                        $link = get_admin_url( null, 'users.php' );
     1626                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1627                        $text = '<a href="' . $link . '">' . $text . '</a>';
     1628                    }
     1629                ?>
     1630
     1631                <td class="b b-users"><span class="total-count"><?php echo $num; ?></a></td>
     1632                <td class="last t users"><?php echo $text; ?></td>
     1633
     1634            </tr>
     1635
     1636            <?php if ( isset( $hidden_topic_count ) ) : ?>
     1637
     1638                <tr>
     1639
     1640                    <?php
     1641                        $num  = $hidden_topic_count;
     1642                        $text = _n( 'Hidden Topic', 'Hidden Topics', $hidden_topic_count, 'bbpress' );
     1643                        $link = add_query_arg( array( 'post_type' => $bbp->topic_id ), get_admin_url( null, 'edit.php' ) );
     1644                        $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $num  . '</a>';
     1645                        $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $text . '</a>';
     1646                    ?>
     1647
     1648                    <td class="b b-hidden-topics"><?php echo $num; ?></td>
     1649                    <td class="last t hidden-replies"><?php echo $text; ?></td>
     1650
     1651                </tr>
     1652
     1653            <?php endif; ?>
     1654
     1655            <?php if ( isset( $hidden_reply_count ) ) : ?>
     1656
     1657                <tr>
     1658
     1659                    <?php
     1660                        $num  = $hidden_reply_count;
     1661                        $text = _n( 'Hidden Reply', 'Hidden Replies', $hidden_reply_count, 'bbpress' );
     1662                        $link = add_query_arg( array( 'post_type' => $bbp->reply_id ), get_admin_url( null, 'edit.php' ) );
     1663                        $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $num  . '</a>';
     1664                        $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $text . '</a>';
     1665                    ?>
     1666
     1667                    <td class="b b-hidden-replies"><?php echo $num; ?></td>
     1668                    <td class="last t hidden-replies"><?php echo $text; ?></td>
     1669
     1670                </tr>
     1671
     1672            <?php endif; ?>
     1673
     1674            <?php if ( isset( $empty_topic_tag_count ) ) : ?>
     1675
     1676                <tr>
     1677
     1678                    <?php
     1679                        $num  = $empty_topic_tag_count;
     1680                        $text = _n( 'Empty Topic Tag', 'Empty Topic Tags', $empty_topic_tag_count, 'bbpress' );
     1681                        $link = add_query_arg( array( 'taxonomy' => $bbp->topic_tag_id, 'post_type' => $bbp->topic_id ), get_admin_url( null, 'edit-tags.php' ) );
     1682                        $num  = '<a href="' . $link . '">' . $num  . '</a>';
     1683                        $text = '<a class="waiting" href="' . $link . '">' . $text . '</a>';
     1684                    ?>
     1685
     1686                    <td class="b b-hidden-topic-tags"><?php echo $num; ?></td>
     1687                    <td class="last t hidden-topic-tags"><?php echo $text; ?></td>
     1688
     1689                </tr>
     1690
     1691            <?php endif; ?>
     1692
     1693            <?php
     1694
     1695            do_action( 'bbp_dashboard_widget_right_now_table_end'            );
     1696            do_action( 'bbp_dashboard_widget_right_now_discussion_table_end' );
     1697
     1698            ?>
     1699
     1700        </table>
     1701
     1702    </div>
     1703
     1704    <?php if ( current_user_can( 'update_plugins' ) ) : ?>
     1705
     1706        <div class="versions">
     1707
     1708            <p>
     1709
     1710                <?php printf( __( 'You are using <span class="b">bbPress %s</span>.', 'bbpress' ), BBP_VERSION ); ?>
     1711
     1712            </p>
     1713
     1714            <br class="clear" />
     1715
     1716        </div>
     1717
     1718    <?php endif; ?>
     1719
     1720    <?php
     1721
     1722    do_action( 'bbp_dashboard_widget_right_now_end' );
     1723}
     1724
    13831725/**
    13841726 * Forum metabox
     
    14541796
    14551797        <hr />
    1456        
     1798
    14571799        <p>
    14581800            <strong class="label"><?php _e( 'Parent:', 'bbpress' ); ?></strong>
Note: See TracChangeset for help on using the changeset viewer.