<?php
    if ( post_password_required() ) :
        echo '<h3 class="comments-header">' . __('Password Protected', 'buddypress') . '</h3>';
        echo '<p class="alert password-protected">' . __('Enter the password to view comments.', 'buddypress') . '</p>';
        return;
    endif;
    
    if ( is_page() && !have_comments() && !comments_open() && !pings_open() )
        return;
    
    if ( have_comments() ) :
        ?>
        
        <div id="comments">
            
            <?php
            /**
             * Only include comments
             */
            
            $numTrackBacks = 0;
            $numComments   = 0;
            
            foreach ( (array)$comments as $comment )
                    if ( 'comment' != get_comment_type() )
                        $numTrackBacks++;
                    else
                        $numComments++;
                        
                    ?>
                    
                    <h3 id="comments">
                        <?php
                        $one_response = __( 'One Response to %2$s' , 'buddypress' );
                        $responses    = __( '%1$s Responses to %2$s' , 'buddypress' );
                        printf( _n( $one_response, $responses, $numComments, 'buddypress' ),
                        number_format_i18n( $numComments ), '<em>' . get_the_title() . '</em>' );
                        ?>
                    </h3>
                    
                    <?php
                    do_action( 'bp_before_blog_comment_list' );
                    ?>
                    
                    <ol class="commentlist">
                        <?php
                        wp_list_comments( array( 'callback' => 'bp_dtheme_blog_comments' ) );
                        ?>
                    </ol><!-- .comment-list -->
                    
                    <?php
                    
                    do_action( 'bp_after_blog_comment_list' );
                    
                    if ( get_option( 'page_comments' ) ) :
                        ?>
                        
                        <div class="comment-navigation paged-navigation">
                            <?php
                            paginate_comments_links();
                            ?>
                        </div>
                        
                        <?php
                    endif;
                    ?>
                    
        </div><!-- #comments -->
        
        <?php
        else :
        
            if ( pings_open() && !comments_open() && is_single() ) :
                ?>
                
                <p class="comments-closed pings-open">
                    <?php
                    printf( __('Comments are closed, but <a href="%1$s" title="Trackback URL for this post">trackbacks</a> and pingbacks are open.', 'buddypress'), trackback_url( '0' ) );
                    ?>
                </p>
                
            <?php
            elseif ( !comments_open() && is_single() ) :
                ?>
                <p class="comments-closed">
                    <?php
                    _e('Comments are closed.', 'buddypress');
                    ?>
                </p>
                
            <?php
            endif;
            
        endif;
        
        if ( comments_open() && xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') :
        
            /**
             * Calculate mood bar color
             */
            $class = calculate_moodbar( get_current_user_id() );
            ?>
            
            <div id="respond">
                
                <div class="comment-avatar-box <?php echo $class; ?>">
                    <div class="author-box av01">
                        <?php
                        if ( bp_loggedin_user_id() ) :
                            ?>
                            <a href="<?php echo bp_loggedin_user_domain() ?>">
                                <?php
                                echo get_avatar( bp_loggedin_user_id(), 50 );
                                ?>
                            </a>
                        <?php
                        else :
                            
                            echo get_avatar( 0, 50 );
                            
                        endif;
                        ?>
                    </div>
                </div>
                
                <div class="comment-content">
                    
                    <h3 id="reply" class="comments-header">
                        <?php
                        comment_form_title( __( 'Leave a Reply', 'buddypress' ), __( 'Leave a Reply to %s', 'buddypress' ), true );
                        ?>
                    </h3>
                    
                    <p id="cancel-comment-reply">
                        <?php
                        cancel_comment_reply_link( __( 'Click here to cancel reply.', 'buddypress' ) );
                        ?>
                    </p>
                    
                    <?php
                    if ( get_option( 'comment_registration' ) && !$user_ID ) :
                        ?>
                        
                        <p class="alert">
                            <?php
                            printf( __('You must be <a href="%1$s" title="Log in">logged in</a> to post a comment.', 'buddypress'), wp_login_url( get_permalink() ) );
                            ?>
                        </p>
                        
                    <?php
                    else :
                    
                        do_action( 'bp_before_blog_comment_form' );
                        ?>
                        
                        <form action="<?php echo site_url( 'wp-comments-post.php' ) ?>" method="post" id="commentform" class="standard-form">
                            
                            <?php
                            if ( !$user_ID ) :
                                
                                $req = get_option( 'require_name_email' );
                                ?>
                                
                                <p class="form-author">
                                    <label for="author"><?php _e('Name', 'buddypress'); ?> <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
                                    <input type="text" class="text-input" name="author" id="author" value="<?php echo $comment_author; ?>" size="40" tabindex="1" />
                                </p>
                                
                                <p class="form-email">
                                    <label for="email"><?php _e('Email', 'buddypress'); ?>  <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
                                    <input type="text" class="text-input" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" />
                                </p>
                                
                                <p class="form-url">
                                    <label for="url"><?php _e('Website', 'buddypress'); ?></label>
                                    <input type="text" class="text-input" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" />
                                </p>
                                
                                <?php
                                endif;
                                ?>
                                
                                <p class="form-textarea">
                                    <?php /*<label for="comment"><?php _e('Comment', 'buddypress'); ?></label> */ ?>
                                    <textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea>
                                </p>
                                
                                <?php do_action( 'bp_blog_comment_form' ) ?>
                                
                                <p class="form-submit">
                                    <input class="submit-comment button" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit', 'buddypress'); ?>" />
                                    <?php comment_id_fields(); ?>
                                </p>
                                
                                <div class="comment-action">
                                    <?php do_action( 'comment_form', $post->ID ); ?>
                                </div>
                                
                            </form>
                            
                    <?php
                    // Ocultamos esto
                    //do_action( 'bp_after_blog_comment_form' )
                    
                endif; ?>
                
            </div><!-- .comment-content -->
            
        </div><!-- #respond -->
        
        <?php
        endif;
        
        if ( $numTrackBacks ) :
            ?>
            <div id="trackbacks">
                
                <span class="title"><?php the_title() ?></span>

                <?php if ( 1 == $numTrackBacks ) : ?>
                    <h3><?php printf( __( '%d Trackback', 'buddypress' ), $numTrackBacks ) ?></h3>
                <?php else : ?>
                    <h3><?php printf( __( '%d Trackbacks', 'buddypress' ), $numTrackBacks ) ?></h3>
                <?php endif; ?>

                <ul id="trackbacklist">
                    <?php foreach ( (array)$comments as $comment ) : ?>

                        <?php if ( get_comment_type() != 'comment' ) : ?>
                            <li><h5><?php comment_author_link() ?></h5><em>on <?php comment_date() ?></em></li>
                          <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php
        endif;
        ?>
