Changeset 33962 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 09/09/2015 02:40:53 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r33961 r33962 1678 1678 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author(); 1679 1679 printf( $replytext, $author ); 1680 }1681 }1682 1683 /**1684 * HTML comment list class.1685 *1686 * @uses Walker1687 * @since 2.7.01688 */1689 class Walker_Comment extends Walker {1690 /**1691 * What the class handles.1692 *1693 * @see Walker::$tree_type1694 *1695 * @since 2.7.01696 * @var string1697 */1698 public $tree_type = 'comment';1699 1700 /**1701 * DB fields to use.1702 *1703 * @see Walker::$db_fields1704 *1705 * @since 2.7.01706 * @var array1707 */1708 public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');1709 1710 /**1711 * Start the list before the elements are added.1712 *1713 * @see Walker::start_lvl()1714 *1715 * @since 2.7.01716 *1717 * @global int $comment_depth1718 *1719 * @param string $output Passed by reference. Used to append additional content.1720 * @param int $depth Depth of comment.1721 * @param array $args Uses 'style' argument for type of HTML list.1722 */1723 public function start_lvl( &$output, $depth = 0, $args = array() ) {1724 $GLOBALS['comment_depth'] = $depth + 1;1725 1726 switch ( $args['style'] ) {1727 case 'div':1728 break;1729 case 'ol':1730 $output .= '<ol class="children">' . "\n";1731 break;1732 case 'ul':1733 default:1734 $output .= '<ul class="children">' . "\n";1735 break;1736 }1737 }1738 1739 /**1740 * End the list of items after the elements are added.1741 *1742 * @see Walker::end_lvl()1743 *1744 * @since 2.7.01745 *1746 * @global int $comment_depth1747 *1748 * @param string $output Passed by reference. Used to append additional content.1749 * @param int $depth Depth of comment.1750 * @param array $args Will only append content if style argument value is 'ol' or 'ul'.1751 */1752 public function end_lvl( &$output, $depth = 0, $args = array() ) {1753 $GLOBALS['comment_depth'] = $depth + 1;1754 1755 switch ( $args['style'] ) {1756 case 'div':1757 break;1758 case 'ol':1759 $output .= "</ol><!-- .children -->\n";1760 break;1761 case 'ul':1762 default:1763 $output .= "</ul><!-- .children -->\n";1764 break;1765 }1766 }1767 1768 /**1769 * Traverse elements to create list from elements.1770 *1771 * This function is designed to enhance Walker::display_element() to1772 * display children of higher nesting levels than selected inline on1773 * the highest depth level displayed. This prevents them being orphaned1774 * at the end of the comment list.1775 *1776 * Example: max_depth = 2, with 5 levels of nested content.1777 * 11778 * 1.11779 * 1.1.11780 * 1.1.1.11781 * 1.1.1.1.11782 * 1.1.21783 * 1.1.2.11784 * 21785 * 2.21786 *1787 * @see Walker::display_element()1788 * @see wp_list_comments()1789 *1790 * @since 2.7.01791 *1792 * @param object $element Data object.1793 * @param array $children_elements List of elements to continue traversing.1794 * @param int $max_depth Max depth to traverse.1795 * @param int $depth Depth of current element.1796 * @param array $args An array of arguments.1797 * @param string $output Passed by reference. Used to append additional content.1798 */1799 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {1800 if ( !$element )1801 return;1802 1803 $id_field = $this->db_fields['id'];1804 $id = $element->$id_field;1805 1806 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );1807 1808 // If we're at the max depth, and the current element still has children, loop over those and display them at this level1809 // This is to prevent them being orphaned to the end of the list.1810 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {1811 foreach ( $children_elements[ $id ] as $child )1812 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );1813 1814 unset( $children_elements[ $id ] );1815 }1816 1817 }1818 1819 /**1820 * Start the element output.1821 *1822 * @since 2.7.01823 *1824 * @see Walker::start_el()1825 * @see wp_list_comments()1826 *1827 * @global int $comment_depth1828 * @global object $comment1829 *1830 * @param string $output Passed by reference. Used to append additional content.1831 * @param object $comment Comment data object.1832 * @param int $depth Depth of comment in reference to parents.1833 * @param array $args An array of arguments.1834 */1835 public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {1836 $depth++;1837 $GLOBALS['comment_depth'] = $depth;1838 $GLOBALS['comment'] = $comment;1839 1840 if ( !empty( $args['callback'] ) ) {1841 ob_start();1842 call_user_func( $args['callback'], $comment, $args, $depth );1843 $output .= ob_get_clean();1844 return;1845 }1846 1847 if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {1848 ob_start();1849 $this->ping( $comment, $depth, $args );1850 $output .= ob_get_clean();1851 } elseif ( 'html5' === $args['format'] ) {1852 ob_start();1853 $this->html5_comment( $comment, $depth, $args );1854 $output .= ob_get_clean();1855 } else {1856 ob_start();1857 $this->comment( $comment, $depth, $args );1858 $output .= ob_get_clean();1859 }1860 }1861 1862 /**1863 * Ends the element output, if needed.1864 *1865 * @since 2.7.01866 *1867 * @see Walker::end_el()1868 * @see wp_list_comments()1869 *1870 * @param string $output Passed by reference. Used to append additional content.1871 * @param WP_Comment $comment The comment object. Default current comment.1872 * @param int $depth Depth of comment.1873 * @param array $args An array of arguments.1874 */1875 public function end_el( &$output, $comment, $depth = 0, $args = array() ) {1876 if ( !empty( $args['end-callback'] ) ) {1877 ob_start();1878 call_user_func( $args['end-callback'], $comment, $args, $depth );1879 $output .= ob_get_clean();1880 return;1881 }1882 if ( 'div' == $args['style'] )1883 $output .= "</div><!-- #comment-## -->\n";1884 else1885 $output .= "</li><!-- #comment-## -->\n";1886 }1887 1888 /**1889 * Output a pingback comment.1890 *1891 * @access protected1892 * @since 3.6.01893 *1894 * @see wp_list_comments()1895 *1896 * @param WP_Comment $comment The comment object.1897 * @param int $depth Depth of comment.1898 * @param array $args An array of arguments.1899 */1900 protected function ping( $comment, $depth, $args ) {1901 $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';1902 ?>1903 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>1904 <div class="comment-body">1905 <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>1906 </div>1907 <?php1908 }1909 1910 /**1911 * Output a single comment.1912 *1913 * @access protected1914 * @since 3.6.01915 *1916 * @see wp_list_comments()1917 *1918 * @param object $comment Comment to display.1919 * @param int $depth Depth of comment.1920 * @param array $args An array of arguments.1921 */1922 protected function comment( $comment, $depth, $args ) {1923 if ( 'div' == $args['style'] ) {1924 $tag = 'div';1925 $add_below = 'comment';1926 } else {1927 $tag = 'li';1928 $add_below = 'div-comment';1929 }1930 ?>1931 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>">1932 <?php if ( 'div' != $args['style'] ) : ?>1933 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">1934 <?php endif; ?>1935 <div class="comment-author vcard">1936 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>1937 <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>1938 </div>1939 <?php if ( '0' == $comment->comment_approved ) : ?>1940 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>1941 <br />1942 <?php endif; ?>1943 1944 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">1945 <?php1946 /* translators: 1: comment date, 2: comment time */1947 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );1948 ?>1949 </div>1950 1951 <?php comment_text( get_comment_id(), array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>1952 1953 <?php1954 comment_reply_link( array_merge( $args, array(1955 'add_below' => $add_below,1956 'depth' => $depth,1957 'max_depth' => $args['max_depth'],1958 'before' => '<div class="reply">',1959 'after' => '</div>'1960 ) ) );1961 ?>1962 1963 <?php if ( 'div' != $args['style'] ) : ?>1964 </div>1965 <?php endif; ?>1966 <?php1967 }1968 1969 /**1970 * Output a comment in the HTML5 format.1971 *1972 * @access protected1973 * @since 3.6.01974 *1975 * @see wp_list_comments()1976 *1977 * @param object $comment Comment to display.1978 * @param int $depth Depth of comment.1979 * @param array $args An array of arguments.1980 */1981 protected function html5_comment( $comment, $depth, $args ) {1982 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';1983 ?>1984 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>>1985 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">1986 <footer class="comment-meta">1987 <div class="comment-author vcard">1988 <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>1989 <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>1990 </div><!-- .comment-author -->1991 1992 <div class="comment-metadata">1993 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID, $args ) ); ?>">1994 <time datetime="<?php comment_time( 'c' ); ?>">1995 <?php1996 /* translators: 1: comment date, 2: comment time */1997 printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() );1998 ?>1999 </time>2000 </a>2001 <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>2002 </div><!-- .comment-metadata -->2003 2004 <?php if ( '0' == $comment->comment_approved ) : ?>2005 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>2006 <?php endif; ?>2007 </footer><!-- .comment-meta -->2008 2009 <div class="comment-content">2010 <?php comment_text(); ?>2011 </div><!-- .comment-content -->2012 2013 <?php2014 comment_reply_link( array_merge( $args, array(2015 'add_below' => 'div-comment',2016 'depth' => $depth,2017 'max_depth' => $args['max_depth'],2018 'before' => '<div class="reply">',2019 'after' => '</div>'2020 ) ) );2021 ?>2022 </article><!-- .comment-body -->2023 <?php2024 1680 } 2025 1681 }
Note: See TracChangeset
for help on using the changeset viewer.