<?php get_header();

/**
 * DELETE COMMENT
 */
$action = strip_tags($_GET['action']);
$id     = strip_tags($_GET['id']);

// Action delete comment
if ($action == 'deletecomment' && $id) {
    $comm = get_comment($id);
    if ($comm->user_id == bp_loggedin_user_id()) {
        wp_delete_comment($id);
    }
}

locate_template( array( 'leftsidebar.php' ), true );

$meta = get_post_meta($post->ID, '_wp_page_type');
?>

    <div id="content">
        
        <?php
        if ($meta[0] == 'testimonio') {
        ?>
            <div id="iron-encabezado-container">
                <h2 class="iron-encabezado-seccion">
                    <?php echo __('Testimonios','buddypress'); ?>
                </h2>
                <ul class="iron-encabezado-ul">
                    <?php
                    if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') {
                        ?>
                        <li class="iron-encabezado-li">
                            <a class="fancybox-testimonies" class="button" href="<?php echo site_url() .'/testimonies-modal/?action=create'; ?>">
                                <?php _e( 'Crear testimonio', 'buddypress' ) ?>
                            </a>
                        </li>
                    <?php } ?>
                        <li class="iron-encabezado-li">
                        <?php
                        if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') { ?>
                        &middot;&nbsp;
                        <?php } ?>
                        <a href="<?php echo bp_loggedin_user_domain() ?>testimonies">
                            <?php echo  __( 'Todos', 'buddypress' ); ?>
                        </a>
                        </li>
                        <li class="iron-encabezado-li">&middot;&nbsp;
                            <a href="<?php echo bp_loggedin_user_domain() ?>testimonies/?sc=mine">
                                <?php echo  __( 'Mis testimonios', 'buddypress' ); ?>
                            </a>
                        </li>
                </ul>
            </div>
            <?php } else { ?>
            <div id="iron-encabezado-container">
                <h2 class="iron-encabezado-seccion">
                    <?php echo __('Pregunta a todos','buddypress'); ?>
                </h2>
                <ul class="iron-encabezado-ul">
                    <?php
                    if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') {
                    ?>
                        <li class="iron-encabezado-li">
                            <a class="fancybox-preguntatodos" class="button" href="<?php echo site_url() .'/questions-modal/?action=create'; ?>">
                                <?php _e( 'Crear pregunta', 'buddypress' ) ?>
                            </a>
                        </li>
                    <?php } ?>
                        <li class="iron-encabezado-li">
                            <?php
                            if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') {
                            ?>
                            &middot;&nbsp;
                            <?php } ?>
                            <a href="<?php echo bp_loggedin_user_domain() ?>questions">
                                <?php echo  __( 'Todas', 'buddypress' ); ?>
                            </a>
                            </li>
                            <li class="iron-encabezado-li">&middot;&nbsp;
                                <a href="<?php echo bp_loggedin_user_domain() ?>/questions/?sc=mine">
                                    <?php echo  __( 'Mis preguntas', 'buddypress' ); ?>
                                </a>
                            </li>
                </ul>
            </div>
        <?php } ?>
        
        <div class="padder">
            
            <?php do_action( 'bp_before_blog_single_post' ) ?>
            
            <div id="content-top"></div>
            
            <div id="content-middle">
                
                <div id="iron-testimonies-container" class="page">
                    
                    <div class="page" id="blog-single">
                        
                        <?php
                        if (have_posts()) : while (have_posts()) : the_post();
                        
                            /**
                             * Calcular estado de animo
                             */
                            $class = calculate_moodbar( $post->post_author );
                            ?>
                            <div class="item-options">
                                <div class="alignleft">
                                    <?php next_posts_link( __( '&larr; Previous Entries', 'buddypress' ) ) ?>
                                </div>
                                <div class="alignright">
                                    <?php previous_posts_link( __( 'Next Entries &rarr;', 'buddypress' ) ) ?>
                                </div>
                            </div>
                            
                            <div class="post" id="post-<?php the_ID(); ?>">
                                <div class="author-box <?php echo $class; ?>">
                                    <a href="<?php echo bp_core_get_user_domain($post->post_author); ?>">
                                    <?php echo get_avatar( $post->post_author, '50' ); ?>
                                    </a>
                                </div>
                                
                                <div class="post-content">
                                    <p class="post-title">
                                        <a href="<?php echo $post->guid; ?>" title="<?php echo $post->post_title; ?>">
                                            <?php echo str_ireplace($_GET['search'],'<span style="color:#E4611D;">'.$_GET['search'].'</span>',$post->post_title);?>
                                        </a>
                                    </p>
                                    
                                    <p class="post-user">
                                        <?php printf( __( 'por %s', 'buddypress' ), bp_core_get_userlink( $post->post_author ) ) ?>
                                        <span id="mentions">@<?php echo get_userdata( $post->post_author )->user_login ?></span>
                                        
                                        <?php
                                        echo __ (' el ','buddypress') . date ("d/m/Y", strtotime ($post->post_date));
                                        
                                        /**
                                         * Si es el autor mostramos enlaces "Editar" y "Eliminar"
                                         */
                                        if ( get_current_user_id() == $post->post_author ) {
                                            if ($meta[0]=='testimonio') {
                                                echo '&middot;&nbsp;<a class="fancybox-testimonies" style="font-size: 11px;" href="'. site_url() .'/testimonies-modal/?action=update&id='. $post->ID .'">'. __ ('Editar','buddypress') .'</a>'; 
                                                echo '&nbsp;&middot;&nbsp;<a style="font-size: 11px;" href="'. site_url() .'/testimonies/?action=delete&id='. $post->ID .'" onClick="if(!confirm(\''. __ ('Eliminar Testimonio ?','buddypress') .'\')) {return false;}">'. __ ('Eliminar','buddypress') .'</a>';
                                            } else {
                                                echo '&middot;&nbsp;<a class="fancybox-preguntatodos" style="font-size: 11px;" href="'. site_url() .'/questions-modal/?action=update&id='. $post->ID .'">'. __ ('Editar','buddypress') .'</a>';
                                                echo '&nbsp;&middot;&nbsp;<a style="font-size: 11px;" href="'. site_url() .'/questions/?action=delete&id='. $post->ID .'" onClick="if(!confirm(\''. __ ('Eliminar Pregunta ?','buddypress') .'\')) {return false;}">'. __ ('Eliminar','buddypress') .'</a>';
                                            }
                                        } ?>
                                    </p>
                                    
                                    <p class="post-content" style="white-space: pre-line;">
                                        <?php
                                        echo str_ireplace($_GET['search'],'<span style="color:#E4611D;">'.$_GET['search'].'</span>',$post->post_content);?>
                                    </p>
                                    
                                    <p class="postmetadata">
                                        <?php
                                        // Favorite
                                        global $bp;
                                        
                                        $activity_id = bp_activity_get_activity_id(
                                                                                        array(
                                                                                            'user_id'           => $post->author_id,
                                                                                            'type'              => 'new_blog_post',
                                                                                            'component'         => 'blogs',
                                                                                            'item_id'           => 1,
                                                                                            'secondary_item_id' => $post->ID
                                                                                        )
                                                                                    );
                                        
                                        if ( is_user_logged_in() && xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') :
                                            
                                            $my_fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
                                            
                                            bp_has_activities();
                                            
                                            if ( !my_bp_activity_is_favorite($activity_id) ) :
                                            ?>
                                                <a href="<?php my_bp_activity_favorite_link($activity_id) ?>" class="fav" title="<?php _e( 'Me gusta', 'buddypress' ) ?>">
                                                    <?php _e( 'Me gusta', 'buddypress' ) ?>
                                                </a>
                                                <?php
                                                if ($my_fav_count>0) :
                                                ?>
                                                    <span rel="<?php echo get_stylesheet_directory_uri() ?>/_inc/tips.php?id=<?php echo $activity_id; ?>&act=fav" class="cluetip fav-count" style="margin-left: -4px;">(<?php echo $my_fav_count; ?>)</span>
                                                <?php
                                                endif;
                                                
                                            else :
                                            ?>
                                                <a href="<?php my_bp_activity_unfavorite_link($activity_id) ?>" class="unfav" title="<?php _e( 'Ya no me gusta', 'buddypress' ) ?>">
                                                    <?php _e( 'Ya no me gusta', 'buddypress' ) ?>
                                                </a>
                                                
                                                <?php
                                                if ($my_fav_count>0) :
                                                ?>
                                                    <span rel="<?php echo get_stylesheet_directory_uri() ?>/_inc/tips.php?id=<?php echo $activity_id; ?>&act=fav" class="cluetip fav-count">(<?php echo $my_fav_count; ?>)</span>
                                                <?php
                                                endif;
                                                ?>
                                                
                                            <?php
                                            endif;
                                            ?>
                                            
                                        <?php
                                        endif;
                                        ?>
                                        
                                        <span class="comments">
                                            <?php comments_popup_link( __( 'No Comments &#187;', 'buddypress' ), __( '1 Comment &#187;', 'buddypress' ), __( '% Comments &#187;', 'buddypress' ) ); ?>
                                        </span>
                                    </p>
                                </div> <!-- .post-content -->
                            </div>
                            
                        <?php
                        comments_template();
                        
                        endwhile; else:
                        ?>
                            <p>
                                <?php _e( 'Sorry, no posts matched your criteria.', 'buddypress' ) ?>
                            </p>
                            
                        <?php
                        endif;
                        ?>
                    </div> <!-- page -->
                    
                </div> <!-- #iron-testimonies-container -->
                
            </div> <!-- content-middle -->
            
            <div id="content-bottom"></div>
            
            <?php do_action( 'bp_after_blog_single_post' ) ?>
            
        </div><!-- .padder -->
    </div><!-- #content -->
    
<?php
locate_template( array( 'sidebar.php' ), true );

get_footer(); ?>