Skip to:
Content

bbPress.org

Ticket #2303: forums-template-tags-3.patch

File forums-template-tags-3.patch, 13.2 KB (added by alex-ye, 13 years ago)
  • includes/forums/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.
     
    14401440 * Is the forum open?
    14411441 *
    14421442 * @since bbPress (r2746)
    1443  * @param int $forum_id Optional. Forum id
    14441443 *
    14451444 * @param int $forum_id Optional. Forum id
    1446  * @uses bbp_is_forum_closed() To check if the forum is closed or not
     1445 * @param bool $check_ancestors Check if the ancestors are open (only
     1446 *                               if they're a category)
     1447 * @uses bbp_is_forum_closed() To check if the forum is closed
    14471448 * @return bool Whether the forum is open or not
    14481449 */
    1449 function bbp_is_forum_open( $forum_id = 0 ) {
    1450         return !bbp_is_forum_closed( $forum_id );
     1450function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
     1451        return !bbp_is_forum_closed( $forum_id, $check_ancestors );
    14511452}
    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/**
     1455 * Is the forum closed?
     1456 *
     1457 * @since bbPress (r2746)
     1458 *
     1459 * @param int $forum_id Optional. Forum id
     1460 * @param bool $check_ancestors Check if the ancestors are closed (only
     1461 *                               if they're a category)
     1462 * @uses bbp_get_forum_id() To get the forum ID
     1463 * @uses bbp_is_forum_status_id() To check the forum status
     1464 * @return bool True if closed, false if not
     1465 */
     1466function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
    14681467
    1469                 $forum_id = bbp_get_forum_id( $forum_id );
    1470                 $retval    = ( bbp_get_closed_status_id() == bbp_get_forum_status( $forum_id ) );
     1468        // Get the forum ID
     1469        $forum_id = bbp_get_forum_id( $forum_id );
    14711470
    1472                 if ( !empty( $check_ancestors ) ) {
    1473                         $ancestors = bbp_get_forum_ancestors( $forum_id );
     1471        // Check if the forum or one of it's ancestors is closed
     1472        $retval   = bbp_is_forum_status_id( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' );
    14741473
    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                 }
     1474        return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
     1475}
    14811476
    1482                 return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
    1483         }
    1484 
    14851477/**
    1486  * Is the forum public?
     1478 * Check the forum status ID
    14871479 *
    1488  * @since bbPress (r2997)
     1480 * @since bbPress (rX)
    14891481 *
    14901482 * @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
     1483 * @param bool $status_name The forum status name to check
     1484 * @param bool $check_ancestors Check if the forum ancestors
     1485 * @param string $operator The logical operation to perform.
     1486 *      'OR' means only one forum from the tree needs to match;
     1487 *      'AND' means all forums must match. The default is 'AND'.
     1488 * @uses bbp_get_forum_id() To get the forum ID
     1489 * @uses bbp_get_forum_status() To get the forum status ID
    14941490 * @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
     1491 * @uses bbp_is_forum_category() To check the forum type
     1492 * @return bool True if match, false if not
    14981493 */
    1499 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
     1494function bbp_is_forum_status_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
    15001495
    1501         $forum_id   = bbp_get_forum_id( $forum_id );
    1502         $visibility = bbp_get_forum_visibility( $forum_id );
     1496        $count        = 0;
     1497        $retval       = false;
     1498        $operator     = strtoupper( $operator );
     1499        $forum_id     = bbp_get_forum_id( $forum_id );
     1500        $forum_status = bbp_get_forum_status( $forum_id );
    15031501
    1504         // If post status is public, return true
    1505         $retval = ( bbp_get_public_status_id() == $visibility );
     1502        if ( $status_name == $forum_status ){
     1503                $retval = true;
     1504                $count++;
     1505        }
    15061506
    1507         // Check ancestors and inherit their privacy setting for display
    15081507        if ( !empty( $check_ancestors ) ) {
    1509                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    15101508
    1511                 foreach ( (array) $ancestors as $ancestor ) {
    1512                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
    1513                                 $retval = true;
    1514                         }
    1515                 }
     1509                switch( $operator ) {
     1510
     1511                    default:
     1512                    case 'AND':
     1513                        $check_ancestors = ( $count > 0 );
     1514                        break;
     1515
     1516                    case 'OR':
     1517                        $check_ancestors = ( $count < 1 );
     1518                        break;
     1519
     1520                }
     1521
     1522                if ( $check_ancestors ) {
     1523
     1524                        // Loop through the forum ancestors
     1525                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1526
     1527                                // Check the post type
     1528                                if ( bbp_is_forum_category( $ancestor ) ) {
     1529
     1530                                        // Check the ancestor forum status
     1531                                        $retval = bbp_is_forum_status_id( $ancestor, $status_name, false );
     1532
     1533                                        if ( $retval )
     1534                                            $count++;
     1535
     1536                                }
     1537
     1538                                // Break when it reach the max count
     1539                                if ( $operator == 'OR' && $count >= 1 )
     1540                                        break;
     1541
     1542                        }
     1543
     1544                }
     1545
    15161546        }
    15171547
     1548        return (bool) $retval;
     1549}
     1550
     1551/**
     1552 * Is the forum public?
     1553 *
     1554 * @since bbPress (r2997)
     1555 *
     1556 * @param int $forum_id Optional. Forum id
     1557 * @param bool $check_ancestors Check if the ancestors are public
     1558 * @uses bbp_get_forum_id() To get the forum ID
     1559 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1560 * @return bool True if public, false if not
     1561 */
     1562function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
     1563
     1564        // Get the forum ID
     1565        $forum_id = bbp_get_forum_id( $forum_id );
     1566
     1567        // Check if the forum and all of it's ancestors are public
     1568        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors );
     1569
    15181570        return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
    15191571}
    15201572
     
    15241576 * @since bbPress (r2746)
    15251577 *
    15261578 * @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
     1579 * @param bool $check_ancestors Check if the ancestors are private
     1580 * @uses bbp_get_forum_id() To get the forum ID
     1581 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1582 * @return bool True if private, false if not
    15341583 */
    15351584function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
    15361585
    1537         $forum_id   = bbp_get_forum_id( $forum_id );
    1538         $visibility = bbp_get_forum_visibility( $forum_id );
     1586        // Get the forum ID
     1587        $forum_id = bbp_get_forum_id( $forum_id );
    15391588
    1540         // If post status is private, return true
    1541         $retval = ( bbp_get_private_status_id() == $visibility );
     1589        // Check if the forum or one of it's ancestors is private
     1590        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' );
    15421591
    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 
    15541592        return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
    15551593}
    15561594
     
    15621600 * @param int $forum_id Optional. Forum id
    15631601 * @param bool $check_ancestors Check if the ancestors are private (only if
    15641602 *                               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
     1603 * @uses bbp_get_forum_id() To get the forum ID
     1604 * @uses bbp_is_forum_visibility_id() To check the forum visibility ID
     1605 * @return bool True if hidden, false if not
    15701606 */
    15711607function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
    15721608
     1609        // Get the forum ID
     1610        $forum_id = bbp_get_forum_id( $forum_id );
     1611
     1612        // Check if the forum or one of it's ancestors is hidden
     1613        $retval   = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' );
     1614
     1615        return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1616}
     1617
     1618/**
     1619 * Check the forum visibility ID
     1620 *
     1621 * @since bbPress (rX)
     1622 *
     1623 * @param int $forum_id Optional. Forum id
     1624 * @param bool $status_name The post status name to check
     1625 * @param bool $check_ancestors Check the forum ancestors
     1626 * @param string $operator The logical operation to perform.
     1627 *      'OR' means only one forum from the tree needs to match;
     1628 *      'AND' means all forums must match. The default is 'AND'.
     1629 * @uses bbp_get_forum_id() To get the forum ID
     1630 * @uses bbp_get_forum_visibility() To get the forum visibility
     1631 * @uses bbp_get_forum_ancestors() To get the forum ancestors
     1632 * @uses bbp_is_forum() To check the post type
     1633 * @return bool True if match, false if not
     1634 */
     1635function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
     1636
     1637        $count      = 0;
     1638        $retval     = false;
     1639        $operator   = strtoupper( $operator );
    15731640        $forum_id   = bbp_get_forum_id( $forum_id );
    15741641        $visibility = bbp_get_forum_visibility( $forum_id );
    15751642
    1576         // If post status is private, return true
    1577         $retval = ( bbp_get_hidden_status_id() == $visibility );
     1643        if ( $status_name == $visibility ){
     1644                $retval = true;
     1645                $count++;
     1646        }
    15781647
    1579         // Check ancestors and inherit their privacy setting for display
    15801648        if ( !empty( $check_ancestors ) ) {
    1581                 $ancestors = bbp_get_forum_ancestors( $forum_id );
    15821649
    1583                 foreach ( (array) $ancestors as $ancestor ) {
    1584                         if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
    1585                                 $retval = true;
    1586                         }
    1587                 }
     1650                switch( $operator ) {
     1651
     1652                    default:
     1653                    case 'AND':
     1654                        $check_ancestors = ( $count > 0 );
     1655                        break;
     1656
     1657                    case 'OR':
     1658                        $check_ancestors = ( $count < 1 );
     1659                        break;
     1660
     1661                }
     1662
     1663                if ( $check_ancestors ) {
     1664
     1665                        // Loop through the forum ancestors
     1666                        foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
     1667
     1668                                // Check the post type
     1669                                if ( bbp_is_forum( $ancestor ) ) {
     1670
     1671                                        // Check the forum visibility
     1672                                        $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false );
     1673
     1674                                        if ( $retval )
     1675                                            $count++;
     1676
     1677                                }
     1678
     1679                                // Break when it reach the max count
     1680                                if ( $operator == 'OR' && $count >= 1 )
     1681                                        break;
     1682
     1683                        }
     1684
     1685                }
     1686
    15881687        }
    15891688
    1590         return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1689        return (bool) $retval;
    15911690}
    15921691
    15931692/**