Guest User

Untitled

a guest
Jul 3rd, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.57 KB | None | 0 0
  1. <?php
  2.  
  3. function get_comment_author( $comment_ID = 0 ) {
  4.     $comment = get_comment( $comment_ID );
  5.     if ( empty($comment->comment_author) ) {
  6.         if (!empty($comment->user_id)){
  7.             $user=get_userdata($comment->user_id);
  8.             $author=$user->user_login;
  9.         } else {
  10.             $author = __('Anonymous');
  11.         }
  12.     } else {
  13.         $author = $comment->comment_author;
  14.     }
  15.     return apply_filters('get_comment_author', $author);
  16. }
  17.  
  18. function comment_author( $comment_ID = 0 ) {
  19.     $author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
  20.     echo $author;
  21. }
  22.  
  23. function get_comment_author_email( $comment_ID = 0 ) {
  24.     $comment = get_comment( $comment_ID );
  25.     return apply_filters('get_comment_author_email', $comment->comment_author_email);
  26. }
  27.  
  28. function comment_author_email( $comment_ID = 0 ) {
  29.     echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
  30. }
  31.  
  32. function comment_author_email_link($linktext='', $before='', $after='') {
  33.     if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
  34.         echo $link;
  35. }
  36.  
  37. function get_comment_author_email_link($linktext='', $before='', $after='') {
  38.     global $comment;
  39.     $email = apply_filters('comment_email', $comment->comment_author_email);
  40.     if ((!empty($email)) && ($email != '@')) {
  41.     $display = ($linktext != '') ? $linktext : $email;
  42.         $return  = $before;
  43.         $return .= "<a href='mailto:$email'>$display</a>";
  44.         $return .= $after;
  45.         return $return;
  46.     } else {
  47.         return '';
  48.     }
  49. }
  50.  
  51. function get_comment_author_link( $comment_ID = 0 ) {
  52.     /** @todo Only call these functions when they are needed. Include in if... else blocks */
  53.     $url    = get_comment_author_url( $comment_ID );
  54.     $author = get_comment_author( $comment_ID );
  55.  
  56.     if ( empty( $url ) || 'http://' == $url )
  57.         $return = $author;
  58.     else
  59.         $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
  60.     return apply_filters('get_comment_author_link', $return);
  61. }
  62.  
  63. function comment_author_link( $comment_ID = 0 ) {
  64.     echo get_comment_author_link( $comment_ID );
  65. }
  66.  
  67. function get_comment_author_IP( $comment_ID = 0 ) {
  68.     $comment = get_comment( $comment_ID );
  69.     return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
  70. }
  71.  
  72. function comment_author_IP( $comment_ID = 0 ) {
  73.     echo get_comment_author_IP( $comment_ID );
  74. }
  75.  
  76. function get_comment_author_url( $comment_ID = 0 ) {
  77.     $comment = get_comment( $comment_ID );
  78.     $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
  79.     $url = esc_url( $url, array('http', 'https') );
  80.     return apply_filters('get_comment_author_url', $url);
  81. }
  82.  
  83. function comment_author_url( $comment_ID = 0 ) {
  84.     echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
  85. }
  86.  
  87. function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  88.     $url = get_comment_author_url();
  89.     $display = ($linktext != '') ? $linktext : $url;
  90.     $display = str_replace( 'http://www.', '', $display );
  91.     $display = str_replace( 'http://', '', $display );
  92.     if ( '/' == substr($display, -1) )
  93.         $display = substr($display, 0, -1);
  94.     $return = "$before<a href='$url' rel='external'>$display</a>$after";
  95.     return apply_filters('get_comment_author_url_link', $return);
  96. }
  97.  
  98. function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  99.     echo get_comment_author_url_link( $linktext, $before, $after );
  100. }
  101.  
  102. function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
  103.     // Separates classes with a single space, collates classes for comment DIV
  104.     $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
  105.     if ( $echo)
  106.         echo $class;
  107.     else
  108.         return $class;
  109. }
  110.  
  111.  
  112. function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
  113.     global $comment_alt, $comment_depth, $comment_thread_alt;
  114.  
  115.     $comment = get_comment($comment_id);
  116.  
  117.     $classes = array();
  118.  
  119.     // Get the comment type (comment, trackback),
  120.     $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
  121.  
  122.     // If the comment author has an id (registered), then print the log in name
  123.     if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  124.         // For all registered users, 'byuser'
  125.         $classes[] = 'byuser';
  126.         $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
  127.         // For comment authors who are the author of the post
  128.         if ( $post = get_post($post_id) ) {
  129.             if ( $comment->user_id === $post->post_author )
  130.                 $classes[] = 'bypostauthor';
  131.         }
  132.     }
  133.  
  134.     if ( empty($comment_alt) )
  135.         $comment_alt = 0;
  136.     if ( empty($comment_depth) )
  137.         $comment_depth = 1;
  138.     if ( empty($comment_thread_alt) )
  139.         $comment_thread_alt = 0;
  140.  
  141.     if ( $comment_alt % 2 ) {
  142.         $classes[] = 'odd';
  143.         $classes[] = 'alt';
  144.     } else {
  145.         $classes[] = 'even';
  146.     }
  147.  
  148.     $comment_alt++;
  149.  
  150.     // Alt for top-level comments
  151.     if ( 1 == $comment_depth ) {
  152.         if ( $comment_thread_alt % 2 ) {
  153.             $classes[] = 'thread-odd';
  154.             $classes[] = 'thread-alt';
  155.         } else {
  156.             $classes[] = 'thread-even';
  157.         }
  158.         $comment_thread_alt++;
  159.     }
  160.  
  161.     $classes[] = "depth-$comment_depth";
  162.  
  163.     if ( !empty($class) ) {
  164.         if ( !is_array( $class ) )
  165.             $class = preg_split('#\s+#', $class);
  166.         $classes = array_merge($classes, $class);
  167.     }
  168.  
  169.     $classes = array_map('esc_attr', $classes);
  170.  
  171.     return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
  172. }
  173.  
  174. function get_comment_date( $d = '', $comment_ID = 0 ) {
  175.     $comment = get_comment( $comment_ID );
  176.     if ( '' == $d )
  177.         $date = mysql2date(get_option('date_format'), $comment->comment_date);
  178.     else
  179.         $date = mysql2date($d, $comment->comment_date);
  180.     return apply_filters('get_comment_date', $date, $d);
  181. }
  182.  
  183. function comment_date( $d = '', $comment_ID = 0 ) {
  184.     echo get_comment_date( $d, $comment_ID );
  185. }
  186. function get_comment_excerpt( $comment_ID = 0 ) {
  187.     $comment = get_comment( $comment_ID );
  188.     $comment_text = strip_tags($comment->comment_content);
  189.     $blah = explode(' ', $comment_text);
  190.     if (count($blah) > 20) {
  191.         $k = 20;
  192.         $use_dotdotdot = 1;
  193.     } else {
  194.         $k = count($blah);
  195.         $use_dotdotdot = 0;
  196.     }
  197.     $excerpt = '';
  198.     for ($i=0; $i<$k; $i++) {
  199.         $excerpt .= $blah[$i] . ' ';
  200.     }
  201.     $excerpt .= ($use_dotdotdot) ? '...' : '';
  202.     return apply_filters('get_comment_excerpt', $excerpt);
  203. }
  204.  
  205. function comment_excerpt( $comment_ID = 0 ) {
  206.     echo apply_filters('comment_excerpt', get_comment_excerpt($comment_ID) );
  207. }
  208.  
  209. function get_comment_ID() {
  210.     global $comment;
  211.     return apply_filters('get_comment_ID', $comment->comment_ID);
  212. }
  213.  
  214. function comment_ID() {
  215.     echo get_comment_ID();
  216. }
  217.  
  218.  
  219. function get_comment_link( $comment = null, $args = array() ) {
  220.     global $wp_rewrite, $in_comment_loop;
  221.  
  222.     $comment = get_comment($comment);
  223.  
  224.     // Backwards compat
  225.     if ( !is_array($args) ) {
  226.         $page = $args;
  227.         $args = array();
  228.         $args['page'] = $page;
  229.     }
  230.  
  231.     $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
  232.     $args = wp_parse_args( $args, $defaults );
  233.  
  234.     if ( '' === $args['per_page'] && get_option('page_comments') )
  235.         $args['per_page'] = get_option('comments_per_page');
  236.  
  237.     if ( empty($args['per_page']) ) {
  238.         $args['per_page'] = 0;
  239.         $args['page'] = 0;
  240.     }
  241.  
  242.     if ( $args['per_page'] ) {
  243.         if ( '' == $args['page'] )
  244.             $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
  245.  
  246.         if ( $wp_rewrite->using_permalinks() )
  247.             $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
  248.         else
  249.             $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
  250.     } else {
  251.         $link = get_permalink( $comment->comment_post_ID );
  252.     }
  253.  
  254.     return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args );
  255. }
  256.  
  257.  
  258. function get_comments_link($post_id = 0) {
  259.     return get_permalink($post_id) . '#comments';
  260. }
  261.  
  262.  
  263. function comments_link( $deprecated = '', $deprecated_2 = '' ) {
  264.     if ( !empty( $deprecated ) )
  265.         _deprecated_argument( __FUNCTION__, '0.72' );
  266.     if ( !empty( $deprecated_2 ) )
  267.         _deprecated_argument( __FUNCTION__, '1.3' );
  268.     echo get_comments_link();
  269. }
  270.  
  271. function get_comments_number( $post_id = 0 ) {
  272.     $post_id = absint( $post_id );
  273.  
  274.     if ( !$post_id )
  275.         $post_id = get_the_ID();
  276.  
  277.     $post = get_post($post_id);
  278.     if ( ! isset($post->comment_count) )
  279.         $count = 0;
  280.     else
  281.         $count = $post->comment_count;
  282.  
  283.     return apply_filters('get_comments_number', $count, $post_id);
  284. }
  285.  
  286. function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
  287.     if ( !empty( $deprecated ) )
  288.         _deprecated_argument( __FUNCTION__, '1.3' );
  289.  
  290.     $number = get_comments_number();
  291.  
  292.     if ( $number > 1 )
  293.         $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
  294.     elseif ( $number == 0 )
  295.         $output = ( false === $zero ) ? __('No Comments') : $zero;
  296.     else // must be one
  297.         $output = ( false === $one ) ? __('1 Comment') : $one;
  298.  
  299.     echo apply_filters('comments_number', $output, $number);
  300. }
  301.  
  302. function get_comment_text( $comment_ID = 0 ) {
  303.     $comment = get_comment( $comment_ID );
  304.     return apply_filters( 'get_comment_text', $comment->comment_content, $comment );
  305. }
  306.  
  307. function comment_text( $comment_ID = 0 ) {
  308.     $comment = get_comment( $comment_ID );
  309.     echo apply_filters( 'comment_text', get_comment_text( $comment_ID ), $comment );
  310. }
  311.  
  312. function get_comment_time( $d = '', $gmt = false, $translate = true ) {
  313.     global $comment;
  314.     $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  315.     if ( '' == $d )
  316.         $date = mysql2date(get_option('time_format'), $comment_date, $translate);
  317.     else
  318.         $date = mysql2date($d, $comment_date, $translate);
  319.     return apply_filters('get_comment_time', $date, $d, $gmt, $translate);
  320. }
  321.  
  322.  
  323. function comment_time( $d = '' ) {
  324.     echo get_comment_time($d);
  325. }
  326.  
  327. function get_comment_type( $comment_ID = 0 ) {
  328.     $comment = get_comment( $comment_ID );
  329.     if ( '' == $comment->comment_type )
  330.         $comment->comment_type = 'comment';
  331.  
  332.     return apply_filters('get_comment_type', $comment->comment_type);
  333. }
  334.  
  335.  
  336. function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) {
  337.     if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
  338.     if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
  339.     if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
  340.     $type = get_comment_type();
  341.     switch( $type ) {
  342.         case 'trackback' :
  343.             echo $trackbacktxt;
  344.             break;
  345.         case 'pingback' :
  346.             echo $pingbacktxt;
  347.             break;
  348.         default :
  349.             echo $commenttxt;
  350.     }
  351. }
  352.  
  353.  
  354. function get_trackback_url() {
  355.     if ( '' != get_option('permalink_structure') ) {
  356.         $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
  357.     } else {
  358.         $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
  359.     }
  360.     return apply_filters('trackback_url', $tb_url);
  361. }
  362.  
  363. function trackback_url( $deprecated_echo = true ) {
  364.     if ( $deprecated_echo !== true )
  365.         _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
  366.     if ( $deprecated_echo )
  367.         echo get_trackback_url();
  368.     else
  369.         return get_trackback_url();
  370. }
  371.  
  372.  
  373. function trackback_rdf( $deprecated = '' ) {
  374.     if ( !empty( $deprecated ) )
  375.         _deprecated_argument( __FUNCTION__, '2.5' );
  376.  
  377.     if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
  378.         return;
  379.  
  380.     echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  381.             xmlns:dc="http://purl.org/dc/elements/1.1/"
  382.             xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  383.         <rdf:Description rdf:about="';
  384.     the_permalink();
  385.     echo '"'."\n";
  386.     echo '    dc:identifier="';
  387.     the_permalink();
  388.     echo '"'."\n";
  389.     echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
  390.     echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
  391.     echo '</rdf:RDF>';
  392. }
  393.  
  394. function comments_open( $post_id = null ) {
  395.  
  396.     $_post = get_post($post_id);
  397.  
  398.     $open = ( 'open' == $_post->comment_status );
  399.     return apply_filters( 'comments_open', $open, $post_id );
  400. }
  401.  
  402. function pings_open( $post_id = null ) {
  403.  
  404.     $_post = get_post($post_id);
  405.  
  406.     $open = ( 'open' == $_post->ping_status );
  407.     return apply_filters( 'pings_open', $open, $post_id );
  408. }
  409.  
  410.  
  411. function wp_comment_form_unfiltered_html_nonce() {
  412.     $post = get_post();
  413.     $post_id = $post ? $post->ID : 0;
  414.  
  415.     if ( current_user_can( 'unfiltered_html' ) ) {
  416.         wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
  417.         echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  418.     }
  419. }
  420.  
  421. function comments_template( $file = '/comments.php', $separate_comments = false ) {
  422.     global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  423.  
  424.     if ( !(is_single() || is_page() || $withcomments) || empty($post) )
  425.         return;
  426.  
  427.     if ( empty($file) )
  428.         $file = '/comments.php';
  429.  
  430.     $req = get_option('require_name_email');
  431.  
  432.     /**
  433.      * Comment author information fetched from the comment cookies.
  434.      *
  435.      * @uses wp_get_current_commenter()
  436.      */
  437.     $commenter = wp_get_current_commenter();
  438.  
  439.     /**
  440.      * The name of the current comment author escaped for use in attributes.
  441.      */
  442.     $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
  443.  
  444.     /**
  445.      * The email address of the current comment author escaped for use in attributes.
  446.      */
  447.     $comment_author_email = $commenter['comment_author_email'];  // Escaped by sanitize_comment_cookies()
  448.  
  449.     /**
  450.      * The url of the current comment author escaped for use in attributes.
  451.      */
  452.     $comment_author_url = esc_url($commenter['comment_author_url']);
  453.  
  454.     /** @todo Use API instead of SELECTs. */
  455.     if ( $user_ID) {
  456.         $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt", $post->ID, $user_ID));
  457.     } else if ( empty($comment_author) ) {
  458.         $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
  459.     } else {
  460.         $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
  461.     }
  462.  
  463.     // keep $comments for legacy's sake
  464.     $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
  465.     $comments = &$wp_query->comments;
  466.     $wp_query->comment_count = count($wp_query->comments);
  467.     update_comment_cache($wp_query->comments);
  468.  
  469.     if ( $separate_comments ) {
  470.         $wp_query->comments_by_type = separate_comments($comments);
  471.         $comments_by_type = &$wp_query->comments_by_type;
  472.     }
  473.  
  474.     $overridden_cpage = false;
  475.     if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
  476.         set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
  477.         $overridden_cpage = true;
  478.     }
  479.  
  480.     if ( !defined('COMMENTS_TEMPLATE') )
  481.         define('COMMENTS_TEMPLATE', true);
  482.  
  483.     $include = apply_filters('comments_template', STYLESHEETPATH . $file );
  484.     if ( file_exists( $include ) )
  485.         require( $include );
  486.     elseif ( file_exists( TEMPLATEPATH . $file ) )
  487.         require( TEMPLATEPATH . $file );
  488.     else // Backward compat code will be removed in a future release
  489.         require( ABSPATH . WPINC . '/theme-compat/comments.php');
  490. }
  491.  
  492.  
  493. function comments_popup_script($width=400, $height=400, $file='') {
  494.     global $wpcommentspopupfile, $wpcommentsjavascript;
  495.  
  496.     if (empty ($file)) {
  497.         $wpcommentspopupfile = '';  // Use the index.
  498.     } else {
  499.         $wpcommentspopupfile = $file;
  500.     }
  501.  
  502.     $wpcommentsjavascript = 1;
  503.     $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n    window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";
  504.     echo $javascript;
  505. }
  506.  
  507. function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  508.     global $wpcommentspopupfile, $wpcommentsjavascript;
  509.  
  510.     $id = get_the_ID();
  511.  
  512.     if ( false === $zero ) $zero = __( 'No Comments' );
  513.     if ( false === $one ) $one = __( '1 Comment' );
  514.     if ( false === $more ) $more = __( '% Comments' );
  515.     if ( false === $none ) $none = __( 'Comments Off' );
  516.  
  517.     $number = get_comments_number( $id );
  518.  
  519.     if ( 0 == $number && !comments_open() && !pings_open() ) {
  520.         echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
  521.         return;
  522.     }
  523.  
  524.     if ( post_password_required() ) {
  525.         echo __('Enter your password to view comments.');
  526.         return;
  527.     }
  528.  
  529.     echo '<a href="';
  530.     if ( $wpcommentsjavascript ) {
  531.         if ( empty( $wpcommentspopupfile ) )
  532.             $home = home_url();
  533.         else
  534.             $home = get_option('siteurl');
  535.         echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
  536.         echo '" onclick="wpopen(this.href); return false"';
  537.     } else { // if comments_popup_script() is not in the template, display simple comment link
  538.         if ( 0 == $number )
  539.             echo get_permalink() . '#respond';
  540.         else
  541.             comments_link();
  542.         echo '"';
  543.     }
  544.  
  545.     if ( !empty( $css_class ) ) {
  546.         echo ' class="'.$css_class.'" ';
  547.     }
  548.     $title = the_title_attribute( array('echo' => 0 ) );
  549.  
  550.     echo apply_filters( 'comments_popup_link_attributes', '' );
  551.  
  552.     echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
  553.     comments_number( $zero, $one, $more );
  554.     echo '</a>';
  555. }
  556.  
  557. function get_comment_reply_link($args = array(), $comment = null, $post = null) {
  558.     global $user_ID;
  559.  
  560.     $defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
  561.         'login_text' => __('Log in to Reply'), 'depth' => 0, 'before' => '', 'after' => '');
  562.  
  563.     $args = wp_parse_args($args, $defaults);
  564.  
  565.     if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
  566.         return;
  567.  
  568.     extract($args, EXTR_SKIP);
  569.  
  570.     $comment = get_comment($comment);
  571.     if ( empty($post) )
  572.         $post = $comment->comment_post_ID;
  573.     $post = get_post($post);
  574.  
  575.     if ( !comments_open($post->ID) )
  576.         return false;
  577.  
  578.     $link = '';
  579.  
  580.     if ( get_option('comment_registration') && !$user_ID )
  581.         $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
  582.     else
  583.         $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  584.     return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
  585. }
  586.  
  587. function comment_reply_link($args = array(), $comment = null, $post = null) {
  588.     echo get_comment_reply_link($args, $comment, $post);
  589. }
  590.  
  591. function get_post_reply_link($args = array(), $post = null) {
  592.     global $user_ID;
  593.  
  594.     $defaults = array('add_below' => 'post', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'),
  595.         'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => '');
  596.  
  597.     $args = wp_parse_args($args, $defaults);
  598.     extract($args, EXTR_SKIP);
  599.     $post = get_post($post);
  600.  
  601.     if ( !comments_open($post->ID) )
  602.         return false;
  603.  
  604.     if ( get_option('comment_registration') && !$user_ID ) {
  605.         $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
  606.     } else {
  607.         $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  608.     }
  609.     return apply_filters('post_comments_link', $before . $link . $after, $post);
  610. }
  611.  
  612.  
  613. function post_reply_link($args = array(), $post = null) {
  614.     echo get_post_reply_link($args, $post);
  615. }
  616.  
  617. function get_cancel_comment_reply_link($text = '') {
  618.     if ( empty($text) )
  619.         $text = __('Click here to cancel reply.');
  620.  
  621.     $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
  622.     $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
  623.     return apply_filters('cancel_comment_reply_link', '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text);
  624. }
  625.  
  626.  
  627. function cancel_comment_reply_link($text = '') {
  628.     echo get_cancel_comment_reply_link($text);
  629. }
  630.  
  631.  
  632. function get_comment_id_fields( $id = 0 ) {
  633.     if ( empty( $id ) )
  634.         $id = get_the_ID();
  635.  
  636.     $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  637.     $result  = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
  638.     $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
  639.     return apply_filters('comment_id_fields', $result, $id, $replytoid);
  640. }
  641.  
  642. function comment_id_fields( $id = 0 ) {
  643.     echo get_comment_id_fields( $id );
  644. }
  645.  
  646. function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
  647.     global $comment;
  648.  
  649.     if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
  650.     if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
  651.  
  652.     $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  653.  
  654.     if ( 0 == $replytoid )
  655.         echo $noreplytext;
  656.     else {
  657.         $comment = get_comment($replytoid);
  658.         $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
  659.         printf( $replytext, $author );
  660.     }
  661. }
  662.  
  663.  
  664. class Walker_Comment extends Walker {
  665.  
  666.     var $tree_type = 'comment';
  667.     var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
  668.  
  669.     function start_lvl( &$output, $depth = 0, $args = array() ) {
  670.         $GLOBALS['comment_depth'] = $depth + 1;
  671.  
  672.         switch ( $args['style'] ) {
  673.             case 'div':
  674.                 break;
  675.             case 'ol':
  676.                 echo "<ol class='children'>\n";
  677.                 break;
  678.             default:
  679.             case 'ul':
  680.                 echo "<ul class='children'>\n";
  681.                 break;
  682.         }
  683.     }
  684.  
  685.    
  686.     function end_lvl( &$output, $depth = 0, $args = array() ) {
  687.         $GLOBALS['comment_depth'] = $depth + 1;
  688.  
  689.         switch ( $args['style'] ) {
  690.             case 'div':
  691.                 break;
  692.             case 'ol':
  693.                 echo "</ol>\n";
  694.                 break;
  695.             default:
  696.             case 'ul':
  697.                 echo "</ul>\n";
  698.                 break;
  699.         }
  700.     }
  701.  
  702.  
  703.     function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
  704.  
  705.         if ( !$element )
  706.             return;
  707.  
  708.         $id_field = $this->db_fields['id'];
  709.         $id = $element->$id_field;
  710.  
  711.         parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  712.  
  713.         // If we're at the max depth, and the current element still has children, loop over those and display them at this level
  714.         // This is to prevent them being orphaned to the end of the list.
  715.         if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
  716.             foreach ( $children_elements[ $id ] as $child )
  717.                 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
  718.  
  719.             unset( $children_elements[ $id ] );
  720.         }
  721.  
  722.     }
  723.  
  724.     function start_el( &$output, $comment, $depth, $args, $id = 0 ) {
  725.         $depth++;
  726.         $GLOBALS['comment_depth'] = $depth;
  727.         $GLOBALS['comment'] = $comment;
  728.  
  729.         if ( !empty($args['callback']) ) {
  730.             call_user_func($args['callback'], $comment, $args, $depth);
  731.             return;
  732.         }
  733.  
  734.         extract($args, EXTR_SKIP);
  735.  
  736.         if ( 'div' == $args['style'] ) {
  737.             $tag = 'div';
  738.             $add_below = 'comment';
  739.         } else {
  740.             $tag = 'li';
  741.             $add_below = 'div-comment';
  742.         }
  743. ?>
  744.         <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
  745.         <?php if ( 'div' != $args['style'] ) : ?>
  746.         <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
  747.         <?php endif; ?>
  748.         <div class="comment-author vcard">
  749.         <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  750.         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  751.         </div>
  752. <?php if ($comment->comment_approved == '0') : ?>
  753.         <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
  754.         <br />
  755. <?php endif; ?>
  756.  
  757.         <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
  758.             <?php
  759.                 /* translators: 1: date, 2: time */
  760.                 printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
  761.             ?>
  762.         </div>
  763.  
  764.         <?php comment_text() ?>
  765.  
  766.         <div class="reply">
  767.         <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  768.         </div>
  769.         <?php if ( 'div' != $args['style'] ) : ?>
  770.         </div>
  771.         <?php endif; ?>
  772. <?php
  773.     }
  774.  
  775.     function end_el(&$output, $comment, $depth = 0, $args = array() ) {
  776.         if ( !empty($args['end-callback']) ) {
  777.             call_user_func($args['end-callback'], $comment, $args, $depth);
  778.             return;
  779.         }
  780.         if ( 'div' == $args['style'] )
  781.             echo "</div>\n";
  782.         else
  783.             echo "</li>\n";
  784.     }
  785.  
  786. }
  787.  
  788. function wp_list_comments($args = array(), $comments = null ) {
  789.     global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  790.  
  791.     $in_comment_loop = true;
  792.  
  793.     $comment_alt = $comment_thread_alt = 0;
  794.     $comment_depth = 1;
  795.  
  796.     $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
  797.         'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
  798.  
  799.     $r = wp_parse_args( $args, $defaults );
  800.  
  801.     // Figure out what comments we'll be looping through ($_comments)
  802.     if ( null !== $comments ) {
  803.         $comments = (array) $comments;
  804.         if ( empty($comments) )
  805.             return;
  806.         if ( 'all' != $r['type'] ) {
  807.             $comments_by_type = separate_comments($comments);
  808.             if ( empty($comments_by_type[$r['type']]) )
  809.                 return;
  810.             $_comments = $comments_by_type[$r['type']];
  811.         } else {
  812.             $_comments = $comments;
  813.         }
  814.     } else {
  815.         if ( empty($wp_query->comments) )
  816.             return;
  817.         if ( 'all' != $r['type'] ) {
  818.             if ( empty($wp_query->comments_by_type) )
  819.                 $wp_query->comments_by_type = separate_comments($wp_query->comments);
  820.             if ( empty($wp_query->comments_by_type[$r['type']]) )
  821.                 return;
  822.             $_comments = $wp_query->comments_by_type[$r['type']];
  823.         } else {
  824.             $_comments = $wp_query->comments;
  825.         }
  826.     }
  827.  
  828.     if ( '' === $r['per_page'] && get_option('page_comments') )
  829.         $r['per_page'] = get_query_var('comments_per_page');
  830.  
  831.     if ( empty($r['per_page']) ) {
  832.         $r['per_page'] = 0;
  833.         $r['page'] = 0;
  834.     }
  835.  
  836.     if ( '' === $r['max_depth'] ) {
  837.         if ( get_option('thread_comments') )
  838.             $r['max_depth'] = get_option('thread_comments_depth');
  839.         else
  840.             $r['max_depth'] = -1;
  841.     }
  842.  
  843.     if ( '' === $r['page'] ) {
  844.         if ( empty($overridden_cpage) ) {
  845.             $r['page'] = get_query_var('cpage');
  846.         } else {
  847.             $threaded = ( -1 != $r['max_depth'] );
  848.             $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
  849.             set_query_var( 'cpage', $r['page'] );
  850.         }
  851.     }
  852.     // Validation check
  853.     $r['page'] = intval($r['page']);
  854.     if ( 0 == $r['page'] && 0 != $r['per_page'] )
  855.         $r['page'] = 1;
  856.  
  857.     if ( null === $r['reverse_top_level'] )
  858.         $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
  859.  
  860.     extract( $r, EXTR_SKIP );
  861.  
  862.     if ( empty($walker) )
  863.         $walker = new Walker_Comment;
  864.  
  865.     $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
  866.     $wp_query->max_num_comment_pages = $walker->max_pages;
  867.  
  868.     $in_comment_loop = false;
  869. }
  870. function comment_form( $args = array(), $post_id = null ) {
  871.     global $id;
  872.  
  873.     if ( null === $post_id )
  874.         $post_id = $id;
  875.     else
  876.         $id = $post_id;
  877.  
  878.     $commenter = wp_get_current_commenter();
  879.     $user = wp_get_current_user();
  880.     $user_identity = $user->exists() ? $user->display_name : '';
  881.  
  882.     $req = get_option( 'require_name_email' );
  883.     $aria_req = ( $req ? " aria-required='true'" : '' );
  884.     $fields =  array(
  885.         'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  886.                     '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  887.         'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  888.                     '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  889.         'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
  890.                     '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  891.     );
  892.  
  893.     $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
  894.     $defaults = array(
  895.         'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
  896.         'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
  897.         'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
  898.         'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
  899.         'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
  900.         'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
  901.         'id_form'              => 'commentform',
  902.         'id_submit'            => 'submit',
  903.         'title_reply'          => __( 'Leave a Reply' ),
  904.         'title_reply_to'       => __( 'Leave a Reply to %s' ),
  905.         'cancel_reply_link'    => __( 'Cancel reply' ),
  906.         'label_submit'         => __( 'Post Comment' ),
  907.     );
  908.  
  909.     $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  910.  
  911.     ?>
  912.         <?php if ( comments_open( $post_id ) ) : ?>
  913.             <?php do_action( 'comment_form_before' ); ?>
  914.             <div id="respond">
  915.                 <h3 id="reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
  916.                 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
  917.                     <?php echo $args['must_log_in']; ?>
  918.                     <?php do_action( 'comment_form_must_log_in_after' ); ?>
  919.                 <?php else : ?>
  920.                     <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
  921.                         <?php do_action( 'comment_form_top' ); ?>
  922.                         <?php if ( is_user_logged_in() ) : ?>
  923.                             <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
  924.                             <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
  925.                         <?php else : ?>
  926.                             <?php echo $args['comment_notes_before']; ?>
  927.                             <?php
  928.                             do_action( 'comment_form_before_fields' );
  929.                             foreach ( (array) $args['fields'] as $name => $field ) {
  930.                                 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
  931.                             }
  932.                             do_action( 'comment_form_after_fields' );
  933.                             ?>
  934.                         <?php endif; ?>
  935.                         <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
  936.                         <?php echo $args['comment_notes_after']; ?>
  937.                         <p class="form-submit">
  938.                             <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
  939.                             <?php comment_id_fields( $post_id ); ?>
  940.                         </p>
  941.                         <?php do_action( 'comment_form', $post_id ); ?>
  942.                     </form>
  943.                 <?php endif; ?>
  944.             </div><!-- #respond -->
  945.             <?php do_action( 'comment_form_after' ); ?>
  946.         <?php else : ?>
  947.             <?php do_action( 'comment_form_comments_closed' ); ?>
  948.         <?php endif; ?>
  949.     <?php
  950. }
Advertisement
Add Comment
Please, Sign In to add comment