<?php 

get_header();
global $gp_settings, $post, $current_user;
get_currentuserinfo();

?>

<?php 

//$args = "cat=".$gp_settings['cats']."&caller_get_posts=1&orderby=$orderby&order=$order&gdsr_sort=$gdsr_sort&gdsr_order=$gdsr_order&paged=$paged&posts_per_page=-1";
$args = array(
    "cat" => $gp_settings['cats'],
    "ignore_sticky_posts" => 1,
    "orderby" => $orderby,
    "order" => $order,
    "paged" => $paged,
    "posts_per_page" => -1
);

query_posts($args); 
$urls_video = array();
$ids_descartados = array();

if (have_posts()) : 
    while (have_posts()) : 
        the_post(); 
        include('loop-dedication-data.php');
    
        // Usuario actual puede ver la dedicatoria?
        if ($post->post_status == 'private') {
            if (($current_user->ID != $gp_settings['from_user_id']) && ($current_user->ID != $gp_settings['to_user_id'])) {
                $ids_descartados[] = $post->ID;
            }
        }

        if ($theme_homepage_not_repeat_videos) {
            // Si la URL del video ya ha salido en una dedicatoria anterior, me la salto
            if (in_array($gp_settings['video'], $urls_video)) {
                $ids_descartados[] = $post->ID;
            }
        }

        $urls_video[] = $gp_settings['video'];
    endwhile;
endif;

$args = array(
    "cat" => $gp_settings['cats'],
    "ignore_sticky_posts" => 1,
    "orderby" => $orderby,
    "order" => $order,
    "paged" => $paged,
    "posts_per_page" => $gp_settings['posts_per_page'],
    "post__not_in" => $ids_descartados
);

query_posts($args); 
?>

<div id="content"<?php if($gp_settings['dropdown_filter'] == "0") { ?> class="shift-down"<?php } ?>>
    
    <div id="precontent-wrapper">
        <div id="dedicationComments_container" class="columns two first text-left">&nbsp;</div>
        <div id="sidebar-home" class="columns two last text-left">
            <?php dynamic_sidebar('homepage-1'); ?>		                        
        </div>	
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
    
    
    <div class="contentInner">
	<?php if (have_posts()) : while (have_posts()) : the_post(); include('loop-dedication-data.php'); ?>
            <div <?php post_class('post-loop'); ?>>
                    <!--Begin Image-->
                    <?php if(has_post_thumbnail()) { ?>					
                            <div class="post-thumbnail<?php if($gp_settings['image_wrap'] == "Disable") { ?> thumbnail-no-wrap<?php } ?>">
                                    
                                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                            <?php $image = vt_resize(get_post_thumbnail_id(), '', $gp_settings['image_width'], $gp_settings['image_height'], true); ?>
                                            <img width="<?php echo $image['width']; ?>" height="<?php echo $image['height']; ?>" src="<?php echo $image['url']; ?>" alt="<?php if(get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)) { echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true); } else { echo get_the_title(); } ?>" />		
                                    </a>				
                            </div>					
                    <?php } ?>
                    <!--End Image-->

                    <!--Begin Post Text-->
                    <div class="post-text">
                        <h2><a href="<?php the_permalink(); ?>" title="<?php echo $gp_settings['artist_song']; ?>"><?php echo $gp_settings['artist_song_span_short']; ?></a></h2>                            
                        <?php echo $gp_settings['from_flag']; ?><span>FROM: <?php echo $gp_settings['from_user_link']; ?></span>&nbsp;
                        <?php echo $gp_settings['to_flag']; ?>
                        <span>TO: <?php echo $gp_settings['to_user_link']; ?></span>
                    </div>
                    <!--End Post Text-->

            </div>
	<?php endwhile; ?>
        
        <?php 
        if($gp_settings['pagination'] == "0") {
            gp_ajax_pagination(); 
        } else { ?>
            <div class="more-posts">
                <?php 
                    $category_id = get_cat_ID( DEDICATION_CATEGORY_SLUG );
                    $category_link = get_category_link( $category_id );
                ?>                
                <a href="<?php echo esc_url( $category_link ); ?>" class="read-more" title="<?php _e('See More', 'gp_lang'); ?>"><?php _e('See More', 'gp_lang'); ?> &raquo;</a>
            </div>
        <?php } ?>

        <?php if($gp_settings['dropdown_filter'] == "0") { require_once('dropdown-filter.php'); } ?>
	<?php else : ?>	
		<h4><?php _e('Try searching for a different term.', 'gp_lang'); ?></h4>
	<?php endif; ?>
        <?php wp_reset_query(); ?>
    </div>
</div>
	
<?php get_sidebar(); ?>
<?php get_footer(); ?>