<?php

add_theme_support( 'post-thumbnails' );

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

function coldstone_wp_enqueue_scripts()
{
    wp_enqueue_style('coldstone-bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css');
    wp_enqueue_style('coldstone-style.css', get_template_directory_uri() . '/css/style.css');
    wp_enqueue_style('coldstone-samita-style.css', get_template_directory_uri() . '/css/samita_style.css');
    wp_enqueue_style('coldstone-headhesive.css', get_template_directory_uri() . '/css/headhesive.css');
    wp_enqueue_style('coldstone-font-awesome.min.css', get_template_directory_uri() . '/css/font-awesome.min.css');

    wp_enqueue_script('lindel-jquery-1.11.1.min.js', get_template_directory_uri() . '/js/jquery-1.11.1.min.js');
    wp_enqueue_script('lindel-bootstrap.min.js', get_template_directory_uri() . '/js/bootstrap.min.js');
    wp_enqueue_script('lindel-headhesive.js', get_template_directory_uri() . '/js/headhesive.js');
    wp_enqueue_script('lindel-google-maps.js', 'http://maps.google.com/maps/api/js?sensor=true');
    wp_enqueue_script('lindel-gmaps.js', get_template_directory_uri() . '/js/gmaps.js');
}
add_action('wp_enqueue_scripts', 'coldstone_wp_enqueue_scripts');



function coldstone_wp_title($title, $sep)
{
    global $paged, $page;

    if (is_feed()) {
        return $title;
    }

    $title .= get_bloginfo('name');

    $site_description = get_bloginfo('description', 'display');
    if ($site_description && (is_home() || is_front_page())) {
        $title = "$title $sep $site_description";
    }

    if ($paged >= 2 || $page >= 2) {
        $title = "$title $sep " . sprintf( __( 'Page %s', 'aus' ), max( $paged, $page ) );
    }

    return $title;
}
add_filter('wp_title', 'coldstone_wp_title', 10, 2);



function get_home_page_blog_links($atts) {
    $args = array(
        'numberposts' => 3,
        'offset' => 0,
        'category' => 0,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'post_type' => 'post',
        'post_status' => 'publish',
        'suppress_filters' => true
    );

    // $posts = wp_get_recent_posts( $args );
    $posts = get_posts($args);
    $articles = array();

    foreach ($posts AS $post) {
        setup_postdata($post);

        $temp = array();
        $temp['url'] = get_permalink($post->ID);
        $temp['title'] = $post->post_title;

        $articles[] = $temp;
    }

    $newArticles = array_reverse($articles);
    $articles = $newArticles;

    ob_start();
?>
    <div class="blog-content home-blog-footer">
        <div class="blog-top">
            <?php if (isset($articles[0])) { ?>
                <div class="blog-sep left">
                    <div class="bolg-temp-arrow-down left">
                        <a href="<?php echo $articles[0]['url']; ?>"><?php echo $articles[0]['title']; ?></a>
                    </div>
                    <div class="yellow-mark left"></div>
                </div>
            <?php } ?>

            <?php if (isset($articles[2])) { ?>
                <div class="blog-sep right">
                    <div class="bolg-temp-arrow-down right">
                        <a href="<?php echo $articles[2]['url']; ?>"><?php echo $articles[2]['title']; ?></a>
                    </div>
                    <div class="yellow-mark right"></div>
                </div>
            <?php } ?>
        </div>
        <div class="blog-mid-line"></div>
        <div class="blog-bottom">
            <?php if (isset($articles[1])) { ?>
                <div class="blog-sep mid">
                    <div class="yellow-mark mid"></div>
                    &nbsp;
                    <div class="bolg-temp-arrow-up">
                        <a href="<?php echo $articles[1]['url']; ?>"><?php echo $articles[1]['title']; ?></a>
                    </div>
                    &nbsp;
                </div>
            <?php } ?>
        </div>
    </div>
<?php

    $output = ob_get_contents();
    ob_end_clean();

    return $output;
}
add_shortcode('colstone-homepage-blog', 'get_home_page_blog_links');


function get_homepage_instagram_latest_image($atts) {
    $description = array();
    $image = null;
    $return = '';

    $feedUrl = 'http://iconosquare.com/feed/coldstonesfl';
    $feed = file_get_contents($feedUrl);
    preg_match('/<description><!\[CDATA\[(.*?)<\/description>/', $feed, $description);

    if (isset($description[1])) {
        preg_match('/<img src=\'(.*?)\'/', $description[1], $image);

        if (isset($image[1])) {
            $return = '<img src="' . $image[1] . '" alt="" class="img-responsive center-block instagram-img" />';
        }
    }

    return $return;
}
add_shortcode('colstone-homepage-instagram', 'get_homepage_instagram_latest_image');
