Skip to:
Content

bbPress.org

Ticket #2303: 2303-5.diff

File 2303-5.diff, 11.8 KB (added by netweb, 12 years ago)
  • src/includes/forums/template.php

     
    1616 * Output the unique id of the custom post type for forums
    1717 *
    1818 * @since bbPress (r2857)
     19 *
    1920 * @uses bbp_get_forum_post_type() To get the forum post type
    2021 */
    2122function bbp_forum_post_type() {
     
    447448 * Allow forum rows to have adminstrative actions
    448449 *
    449450 * @since bbPress (r3653)
     451 *
    450452 * @uses do_action()
    451453 * @todo Links and filter
    452454 */
     
    15591561 * Is the forum open?
    15601562 *
    15611563 * @since bbPress (r2746)
    1562  * @param int $forum_id Optional. Forum id
    15631564 *
    15641565 * @param int $forum_id Optional. Forum id
    1565  * @uses bbp_is_forum_closed() To check if the forum is closed or not
     1566 * @param bool $check_ancestors Check if the ancestors are open (only
     1567 *                               if they're a category)
     1568 * @uses bbp_is_forum_closed() To check if the forum is closed
    15661569 * @return bool Whether the forum is open or not
    15671570 */
    1568 function bbp_is_forum_open( $forum_id = 0 ) {
    1569         return !bbp_is_forum_closed( $forum_id );
     1571function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
     1572        return !bbp_is_forum_closed( $forum_id, $check_ancestors );
    15701573}
    15711574
    1572         /**
    1573          * Is the forum closed?
    1574          *
    1575          * @since bbPress (r2746)
    1576          *
    1577          * @param int $forum_id Optional. Forum id
    1578          * @param bool $check_ancestors Check if the ancestors are closed (only
    1579          *                               if they're a category)
    1580          * @uses bbp_get_forum_status() To get the forum status
    1581          * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1582          * @uses bbp_is_forum_category() To check if the forum is a category
    1583          * @uses bbp_is_forum_closed() To check if the forum is closed
    1584          * @return bool True if closed, false if not
    1585          */
    1586         function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
     1575/**
     1576* Is the forum closed?
     1577 *
     1578 * @since bbPress (r2746)
     1579 *
     1580 * @param int $forum_id Optional. Forum id
     1581 * @param bool $check_ancestors Check if the ancestors are closed (only
     1582 *                               if they're a category)
     1583 * @uses bbp_get_forum_id() To get the forum ID
     1584 * @uses bbp_is_forum_status_id() To check the forum status
     1585 * @return bool True if closed, false if not
     1586 */
     1587function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
    15871588
    1588                 $forum_id = bbp_get_forum_id( $forum_id );
    1589                 $retval    = ( bbp_get_closed_status_id() === bbp_get_forum_status( $forum_id ) );
     1589        // Get the forum ID
     1590        $forum_id = bbp_get_forum_id( $forum_id );
    15901591
    1591                 if ( !empty( $check_ancestors ) ) {
    1592                         $ancestors = bbp_get_forum_ancestors( $forum_id );
     1592        // Check if the forum or one of it's ancestors is closed
     1593        $retval   = bbp_is_forum_status_id( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' );
    15931594
    1594                         foreach ( (array) $ancestors as $ancestor ) {
    1595                                 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
    1596                                         $retval = true;
     1595        return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
     1596}
     1597
     1598/**
     1599 * Check the forum status ID
     1600 *
     1601 * @since bbPress (rX)
     1602 *
     1603 * @param bool $status_name The forum status name to check
     1604 * @param bool $check_ancestors Check the forum ancestors
     1605 * @param string $operator The logical operation to perform.
     1606 *      'OR' means only one forum from the tree needs to match;
     1607 *      'AND' means all forums must match. The default is 'AND'.
     1608 * @uses bbp_get_forum_id() To get the forum ID
     1609 * @uses bbp_get_forum_status() To get the forum status
     1610 * @uses bbp_get_forum_ancestors() To get the forum ancestors
     1611 * @uses bbp_is_forum_category() To check the forum type
     1612 * @return bool True if match, false if not
     1613 */
     1614function bbp_is_forum_status_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
     1615
     1616        $count        = 0;
     1617        $retval       = false;
     1618        $operator     = strtoupper( $operator );
     1619        $forum_id     = bbp_get_forum_id( $forum_id );
     1620        $forum_status = bbp_get_forum_status( $forum_id );
     1621
     1622        if ( $status_name == $forum_status ){
     1623                $retval = true;
     1624                $count++;
     1625        }
     1626
     1627        if ( !empty( $check_ancestors ) ) {
     1628                switch( $operator ) {
     1629
     1630                        default:
     1631                        case 'AND':
     1632                                $check_ancestors = ( $count > 0 );
     1633                                break;
     1634
     1635                        case 'OR':
     1636                                $check_ancestors = ( $count < 1 );
     1637                                break;
     1638                }
     1639
     1640                if ( $check_ancestors ) {
     1641
     1642                        // Loop through the forum ancestors
     1643                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1644
     1645                                // Check the post type
     1646                                if ( bbp_is_forum_category( $ancestor ) ) {
     1647
     1648                                        // Check the ancestor forum status
     1649                                        $retval = bbp_is_forum_status_id( $ancestor, $status_name, false );
     1650
     1651                                        if ( $retval )
     1652                                                $count++;
    15971653                                }
     1654
     1655                                // Break when it reach the max count
     1656                                if ( $operator == 'OR' && $count >= 1 )
     1657                                        break;
    15981658                        }
    15991659                }
    1600 
    1601                 return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
    16021660        }
     1661        return (bool) $retval;
     1662}
    16031663
    16041664/**
    16051665 * Is the forum public?
     
    16071667 * @since bbPress (r2997)
    16081668 *
    16091669 * @param int $forum_id Optional. Forum id
    1610  * @param bool $check_ancestors Check if the ancestors are public (only if
    1611  *                               they're a category)
    1612  * @uses get_post_meta() To get the forum public meta
    1613  * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1614  * @uses bbp_is_forum_category() To check if the forum is a category
    1615  * @uses bbp_is_forum_closed() To check if the forum is closed
     1670 * @param bool $check_ancestors Check if the ancestors are public
     1671 * @uses bbp_get_forum_id() To get the forum ID
     1672 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
    16161673 * @return bool True if closed, false if not
    16171674 */
    16181675function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
    16191676
    1620         $forum_id   = bbp_get_forum_id( $forum_id );
    1621         $visibility = bbp_get_forum_visibility( $forum_id );
     1677        // Get the forum ID
     1678        $forum_id = bbp_get_forum_id( $forum_id );
    16221679
    1623         // If post status is public, return true
    1624         $retval = ( bbp_get_public_status_id() === $visibility );
     1680        // Check if the forum and all of it's ancestors are public
     1681        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors );
    16251682
    1626         // Check ancestors and inherit their privacy setting for display
    1627         if ( !empty( $check_ancestors ) ) {
    1628                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    1629 
    1630                 foreach ( (array) $ancestors as $ancestor ) {
    1631                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
    1632                                 $retval = true;
    1633                         }
    1634                 }
    1635         }
    1636 
    16371683        return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
    16381684}
    16391685
     
    16431689 * @since bbPress (r2746)
    16441690 *
    16451691 * @param int $forum_id Optional. Forum id
    1646  * @param bool $check_ancestors Check if the ancestors are private (only if
    1647  *                               they're a category)
    1648  * @uses get_post_meta() To get the forum private meta
    1649  * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1650  * @uses bbp_is_forum_category() To check if the forum is a category
    1651  * @uses bbp_is_forum_closed() To check if the forum is closed
    1652  * @return bool True if closed, false if not
     1692 * @param bool $check_ancestors Check if the ancestors are private
     1693 * @uses bbp_get_forum_id() To get the forum ID
     1694 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1695 * @return bool True if private, false if not
    16531696 */
    16541697function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
    16551698
    1656         $forum_id   = bbp_get_forum_id( $forum_id );
    1657         $visibility = bbp_get_forum_visibility( $forum_id );
     1699        // Get the forum ID
     1700        $forum_id = bbp_get_forum_id( $forum_id );
    16581701
    1659         // If post status is private, return true
    1660         $retval = ( bbp_get_private_status_id() === $visibility );
     1702        // Check if the forum or one of it's ancestors is private
     1703        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' );
    16611704
    1662         // Check ancestors and inherit their privacy setting for display
    1663         if ( !empty( $check_ancestors ) ) {
    1664                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    1665 
    1666                 foreach ( (array) $ancestors as $ancestor ) {
    1667                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
    1668                                 $retval = true;
    1669                         }
    1670                 }
    1671         }
    1672 
    16731705        return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
    16741706}
    16751707
     
    16811713 * @param int $forum_id Optional. Forum id
    16821714 * @param bool $check_ancestors Check if the ancestors are private (only if
    16831715 *                               they're a category)
    1684  * @uses get_post_meta() To get the forum private meta
    1685  * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1686  * @uses bbp_is_forum_category() To check if the forum is a category
    1687  * @uses bbp_is_forum_closed() To check if the forum is closed
    1688  * @return bool True if closed, false if not
     1716 * @uses bbp_get_forum_id() To get the forum ID
     1717 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1718 * @return bool True if hidden, false if not
    16891719 */
    16901720function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
    16911721
     1722        // Get the forum ID
     1723        $forum_id = bbp_get_forum_id( $forum_id );
     1724
     1725        // Check if the forum or one of it's ancestors is hidden
     1726        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' );
     1727
     1728        return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1729}
     1730
     1731/**
     1732 * Check the forum visibility ID
     1733 *
     1734 * @since bbPress (rX)
     1735 *
     1736 * @param int $forum_id Optional. Forum id
     1737 * @param bool $status_name The post status name to check
     1738 * @param bool $check_ancestors Check the forum ancestors
     1739 * @param string $operator The logical operation to perform.
     1740 *      'OR' means only one forum from the tree needs to match;
     1741 *      'AND' means all forums must match. The default is 'AND'.
     1742 * @uses bbp_get_forum_id() To get the forum ID
     1743 * @uses bbp_get_forum_visibility() To get the forum visibility
     1744 * @uses bbp_get_forum_ancestors() To get the forum ancestors
     1745 * @uses bbp_is_forum() To check the post type
     1746 * @return bool True if match, false if not
     1747 */
     1748function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
     1749
     1750        $count      = 0;
     1751        $retval     = false;
     1752        $operator   = strtoupper( $operator );
    16921753        $forum_id   = bbp_get_forum_id( $forum_id );
    16931754        $visibility = bbp_get_forum_visibility( $forum_id );
    16941755
    1695         // If post status is private, return true
    1696         $retval = ( bbp_get_hidden_status_id() === $visibility );
     1756        if ( $status_name == $visibility ){
     1757                $retval = true;
     1758                $count++;
     1759        }
    16971760
    1698         // Check ancestors and inherit their privacy setting for display
    16991761        if ( !empty( $check_ancestors ) ) {
    1700                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    17011762
    1702                 foreach ( (array) $ancestors as $ancestor ) {
    1703                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
    1704                                 $retval = true;
     1763                switch( $operator ) {
     1764
     1765                        default:
     1766                        case 'AND':
     1767                                $check_ancestors = ( $count > 0 );
     1768                                break;
     1769
     1770                        case 'OR':
     1771                                $check_ancestors = ( $count < 1 );
     1772                                break;
     1773                }
     1774
     1775                if ( $check_ancestors ) {
     1776
     1777                        // Loop through the forum ancestors
     1778                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1779
     1780                                // Check the post type
     1781                                if ( bbp_is_forum( $ancestor ) ) {
     1782
     1783                                        // Check the forum visibility
     1784                                        $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false );
     1785
     1786                                        if ( $retval )
     1787                                                $count++;
     1788                                }
     1789
     1790                                // Break when it reach the max count
     1791                                if ( $operator == 'OR' && $count >= 1 )
     1792                                        break;
    17051793                        }
    17061794                }
    17071795        }
    17081796
    1709         return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1797        return (bool) $retval;
    17101798}
    17111799
    17121800/**
     
    22262314
    22272315                return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) );
    22282316        }
    2229        
     2317
    22302318/**
    22312319 * Output checked value of forum subscription
    22322320 *