Skip to:
Content

bbPress.org

Ticket #2303: forums-template-tags.patch

File forums-template-tags.patch, 13.9 KB (added by alex-ye, 13 years ago)

First Draft Patch

  • template-tags.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \includes\forums
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    14431443 * @param int $forum_id Optional. Forum id
    14441444 *
    14451445 * @param int $forum_id Optional. Forum id
    1446  * @uses bbp_is_forum_closed() To check if the forum is closed or not
     1446 * @param bool $check_ancestors Check if the ancestors are open (only
     1447 *                               if they're a category)
     1448 * @uses bbp_get_forum_id() To get the forum ID
     1449 * @uses bbp_is_forum_status_id() To check the forum status
    14471450 * @return bool Whether the forum is open or not
    14481451 */
    1449 function bbp_is_forum_open( $forum_id = 0 ) {
    1450         return !bbp_is_forum_closed( $forum_id );
    1451 }
     1452function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
    14521453
    1453         /**
    1454          * Is the forum closed?
    1455          *
    1456          * @since bbPress (r2746)
    1457          *
    1458          * @param int $forum_id Optional. Forum id
    1459          * @param bool $check_ancestors Check if the ancestors are closed (only
    1460          *                               if they're a category)
    1461          * @uses bbp_get_forum_status() To get the forum status
    1462          * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1463          * @uses bbp_is_forum_category() To check if the forum is a category
    1464          * @uses bbp_is_forum_closed() To check if the forum is closed
    1465          * @return bool True if closed, false if not
    1466          */
    1467         function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
     1454        // Get the forum ID
     1455        $forum_id = bbp_get_forum_id( $forum_id );
    14681456
    1469                 $forum_id = bbp_get_forum_id( $forum_id );
    1470                 $retval    = ( bbp_get_closed_status_id() == bbp_get_forum_status( $forum_id ) );
     1457        // Check if the forum all all of it's ancestors are open
     1458        $retval   = bbp_is_forum_status_id( $forum_id, bbp_get_closed_status_id(), $check_ancestors );
    14711459
    1472                 if ( !empty( $check_ancestors ) ) {
    1473                         $ancestors = bbp_get_forum_ancestors( $forum_id );
     1460        return (bool) apply_filters( 'bbp_is_forum_open', (bool) $retval, $forum_id, $check_ancestors );
     1461}
    14741462
    1475                         foreach ( (array) $ancestors as $ancestor ) {
    1476                                 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
    1477                                         $retval = true;
    1478                                 }
    1479                         }
    1480                 }
     1463/**
     1464 * Is the forum closed?
     1465 *
     1466 * @since bbPress (r2746)
     1467 *
     1468 * @param int $forum_id Optional. Forum id
     1469 * @param bool $check_ancestors Check if the ancestors are closed (only
     1470 *                               if they're a category)
     1471 * @uses bbp_get_forum_id() To get the forum ID
     1472 * @uses bbp_is_forum_status_id() To check the forum status
     1473 * @return bool True if closed, false if not
     1474 */
     1475function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
    14811476
    1482                 return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
    1483         }
     1477        // Get the forum ID
     1478        $forum_id = bbp_get_forum_id( $forum_id );
    14841479
     1480        // Check if the forum or one of it's ancestors is closed
     1481        $retval   = bbp_is_forum_status_id( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' );
     1482
     1483        return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
     1484}
     1485       
    14851486/**
    1486  * Is the forum public?
     1487 * Check the forum status ID
    14871488 *
    1488  * @since bbPress (r2997)
     1489 * @since bbPress (rX)
    14891490 *
    14901491 * @param int $forum_id Optional. Forum id
    1491  * @param bool $check_ancestors Check if the ancestors are public (only if
    1492  *                               they're a category)
    1493  * @uses get_post_meta() To get the forum public meta
     1492 * @param bool $status_name The forum status name to check
     1493 * @param bool $check_ancestors Check if the forum ancestors
     1494 * @param string $operator The logical operation to perform.
     1495 *      'OR' means only one forum from the tree needs to match;
     1496 *      'AND' means all forums must match. The default is 'AND'. 
     1497 * @uses bbp_get_forum_id() To get the forum ID
     1498 * @uses bbp_get_forum_status() To get the forum status ID
    14941499 * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1495  * @uses bbp_is_forum_category() To check if the forum is a category
    1496  * @uses bbp_is_forum_closed() To check if the forum is closed
    1497  * @return bool True if closed, false if not
     1500 * @uses bbp_is_forum_category() To check the forum type
     1501 * @return bool True if match, false if not
    14981502 */
    1499 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
     1503function bbp_is_forum_status_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
    15001504
    1501         $forum_id   = bbp_get_forum_id( $forum_id );
    1502         $visibility = bbp_get_forum_visibility( $forum_id );
     1505        $count        = 0;
     1506        $retval       = false;
     1507        $operator     = strtoupper( $operator );
     1508        $forum_id     = bbp_get_forum_id( $forum_id );
     1509        $forum_status = bbp_get_forum_status( $forum_id );               
     1510 
     1511        if ( $status_name == $forum_status ){
     1512                $retval = true;
     1513                $count++;
     1514        }
    15031515
    1504         // If post status is public, return true
    1505         $retval = ( bbp_get_public_status_id() == $visibility );
    1506 
    1507         // Check ancestors and inherit their privacy setting for display
    15081516        if ( !empty( $check_ancestors ) ) {
    1509                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    15101517
    1511                 foreach ( (array) $ancestors as $ancestor ) {
    1512                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
    1513                                 $retval = true;
    1514                         }
    1515                 }
     1518                switch( $operator ) {
     1519                   
     1520                    default:
     1521                    case 'AND':
     1522                        $check_ancestors = ( $count > 0 );
     1523                        break;
     1524
     1525                    case 'OR':
     1526                        $check_ancestors = ( $count < 1 );
     1527                        break;
     1528
     1529                }
     1530               
     1531                if ( $check_ancestors ) {
     1532
     1533                        // Loop through the forum ancestors
     1534                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1535
     1536                                // Check the post type
     1537                                if ( bbp_is_forum_category( $ancestor ) ) {
     1538
     1539                                        // Check the ancestor forum status
     1540                                        $retval = bbp_is_forum_status_id( $ancestor, $status_name, false );
     1541
     1542                                        if ( $retval )
     1543                                            $count++;
     1544
     1545                                }
     1546
     1547                                // Break when it reach the max count
     1548                                if ( $operator == 'OR' && $count >= 1 )
     1549                                        break;
     1550
     1551                        }
     1552               
     1553                }
     1554               
    15161555        }
    15171556
     1557        return (bool) apply_filters( 'bbp_is_forum_status_id', (bool) $retval, $forum_id, $status_name, $check_ancestors, $operator );
     1558}
     1559
     1560/**
     1561 * Is the forum public?
     1562 *
     1563 * @since bbPress (r2997)
     1564 *
     1565 * @param int $forum_id Optional. Forum id
     1566 * @param bool $check_ancestors Check if the ancestors are public
     1567 * @uses bbp_get_forum_id() To get the forum ID
     1568 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1569 * @return bool True if public, false if not
     1570 */
     1571function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
     1572
     1573        // Get the forum ID
     1574        $forum_id = bbp_get_forum_id( $forum_id );
     1575
     1576        // Check if the forum and all of it's ancestors are public
     1577        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors );
     1578       
    15181579        return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
    15191580}
    15201581
     
    15241585 * @since bbPress (r2746)
    15251586 *
    15261587 * @param int $forum_id Optional. Forum id
    1527  * @param bool $check_ancestors Check if the ancestors are private (only if
    1528  *                               they're a category)
    1529  * @uses get_post_meta() To get the forum private meta
    1530  * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1531  * @uses bbp_is_forum_category() To check if the forum is a category
    1532  * @uses bbp_is_forum_closed() To check if the forum is closed
    1533  * @return bool True if closed, false if not
     1588 * @param bool $check_ancestors Check if the ancestors are private
     1589 * @uses bbp_get_forum_id() To get the forum ID
     1590 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1591 * @return bool True if private, false if not
    15341592 */
    15351593function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
    15361594
    1537         $forum_id   = bbp_get_forum_id( $forum_id );
    1538         $visibility = bbp_get_forum_visibility( $forum_id );
     1595        // Get the forum ID
     1596        $forum_id = bbp_get_forum_id( $forum_id );
    15391597
    1540         // If post status is private, return true
    1541         $retval = ( bbp_get_private_status_id() == $visibility );
     1598        // Check if the forum or one of it's ancestors is private
     1599        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' );
    15421600
    1543         // Check ancestors and inherit their privacy setting for display
    1544         if ( !empty( $check_ancestors ) ) {
    1545                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    1546 
    1547                 foreach ( (array) $ancestors as $ancestor ) {
    1548                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
    1549                                 $retval = true;
    1550                         }
    1551                 }
    1552         }
    1553 
    15541601        return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
    15551602}
    15561603
     
    15621609 * @param int $forum_id Optional. Forum id
    15631610 * @param bool $check_ancestors Check if the ancestors are private (only if
    15641611 *                               they're a category)
    1565  * @uses get_post_meta() To get the forum private meta
    1566  * @uses bbp_get_forum_ancestors() To get the forum ancestors
    1567  * @uses bbp_is_forum_category() To check if the forum is a category
    1568  * @uses bbp_is_forum_closed() To check if the forum is closed
    1569  * @return bool True if closed, false if not
     1612 * @uses bbp_get_forum_id() To get the forum ID
     1613 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1614 * @return bool True if hidden, false if not
    15701615 */
    15711616function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
    15721617
    1573         $forum_id   = bbp_get_forum_id( $forum_id );
    1574         $visibility = bbp_get_forum_visibility( $forum_id );
     1618        // Get the forum ID
     1619        $forum_id = bbp_get_forum_id( $forum_id );
    15751620
    1576         // If post status is private, return true
    1577         $retval = ( bbp_get_hidden_status_id() == $visibility );
     1621        // Check if the forum or one of it's ancestors is hidden
     1622        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' );
    15781623
    1579         // Check ancestors and inherit their privacy setting for display
     1624        return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1625}
     1626       
     1627/**
     1628 * Check the forum visibility ID
     1629 *
     1630 * @since bbPress (rX)
     1631 *
     1632 * @param int $forum_id Optional. Forum id
     1633 * @param bool $status_name The post status name to check
     1634 * @param bool $check_ancestors Check the forum ancestors
     1635 * @param string $operator The logical operation to perform.
     1636 *      'OR' means only one forum from the tree needs to match;
     1637 *      'AND' means all forums must match. The default is 'AND'. 
     1638 * @uses bbp_get_forum_id() To get the forum ID
     1639 * @uses bbp_get_forum_visibility() To get the forum visibility
     1640 * @uses bbp_get_forum_ancestors() To get the forum ancestors
     1641 * @uses bbp_is_forum() To check the post type
     1642 * @return bool True if match, false if not
     1643 */
     1644function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
     1645
     1646        $count      = 0;
     1647        $retval     = false;
     1648        $operator   = strtoupper( $operator );
     1649        $forum_id   = bbp_get_forum_id( $forum_id );
     1650        $visibility = bbp_get_forum_visibility( $forum_id );               
     1651 
     1652        if ( $status_name == $visibility ){
     1653                $retval = true;
     1654                $count++;
     1655        }
     1656                       
    15801657        if ( !empty( $check_ancestors ) ) {
    1581                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    15821658
    1583                 foreach ( (array) $ancestors as $ancestor ) {
    1584                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
    1585                                 $retval = true;
    1586                         }
    1587                 }
     1659                switch( $operator ) {
     1660                   
     1661                    default:
     1662                    case 'AND':
     1663                        $check_ancestors = ( $count > 0 );
     1664                        break;
     1665
     1666                    case 'OR':
     1667                        $check_ancestors = ( $count < 1 );
     1668                        break;
     1669
     1670                }
     1671               
     1672                if ( $check_ancestors ) {
     1673
     1674                        // Loop through the forum ancestors
     1675                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1676
     1677                                // Check the post type
     1678                                if ( bbp_is_forum( $ancestor ) ) {
     1679
     1680                                        // Check the forum visibility
     1681                                        $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false );
     1682
     1683                                        if ( $retval )
     1684                                            $count++;
     1685
     1686                                }
     1687
     1688                                // Break when it reach the max count
     1689                                if ( $operator == 'OR' && $count >= 1 )
     1690                                        break;
     1691
     1692                        }
     1693               
     1694                }
     1695               
    15881696        }
    15891697
    1590         return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1698        return (bool) apply_filters( 'bbp_is_forum_visibility_id', (bool) $retval, $forum_id, $status_name, $check_ancestors, $operator );
    15911699}
    15921700
    15931701/**