<?php
/**
 * The template for displaying the footer.
 *
 * Contains the closing of the #content div and all content after
 *
 * @package daisy
 */

?>
	
    <!-- Footer
    ====================================-->
    <div class="container">
        <div id="tf-footer">			
		<?php if( !get_theme_mod('footer_hide_logo') ) { ?>	
				<div class="text-center">
					<a href="<?php echo esc_url(home_url()) ?>">
					<?php if( get_theme_mod('footer_logo') ) { ?>
					<img class="img-responsive logo" src="<?php echo esc_url(get_theme_mod('footer_logo')) ?>" alt="" />
					<?php } else { ?>
					<img  class="img-responsive logo" src="<?php echo get_template_directory_uri() ?>/img/logo.png" alt="" />
					<?php } ?>
				</a>
				</div>			<?php } ?>
			<?php if( get_theme_mod('footer_hide_instagram') ) { ?>
            <div class="widget-instagram">
                <div class="title"><?php echo esc_html( get_theme_mod('footer_instagram_title') ) ?></div>
                <div class="widget-wrap">
					
                    <div id="instaphotos" class="owl-carousel owl-theme">
						<?php
						//returns a big old hunk of JSON from a non-private IG account page.
						function scrape_insta($username) {
							$username = strtolower( $username );
							$username = str_replace( '@', '', $username );
							$remote = wp_remote_get( 'http://instagram.com/'.trim( $username ) );
							$shards = explode( 'window._sharedData = ', $remote['body'] );
							$insta_json = explode( ';</script>', $shards[1] );
							$insta_array = json_decode( $insta_json[0], TRUE );
							//var_dump($insta_array);
							return $insta_array;
						}
						//Supply a username
						$my_account = get_theme_mod('footer_instagram_user');
						$count = get_theme_mod('footer_instagram_number_photo') ? absint( get_theme_mod('footer_instagram_number_photo')) : 12;
						//Do the deed
						if($my_account && $my_account != ''){
						$results_array = scrape_insta($my_account);
						//An example of where to go from there
						if($results_array){
							$images  = $results_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
							$i = 0; 
							foreach ($images as $image): 
								
								if($count == $i){ break;}
								$i++;
								$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['thumbnail_src'] );
								$link = 'https://instagram.com/p/' . $image['code'];
								
								echo '<div class="item">';
									echo '<a target="_blank" href="'. $link .'">';
										echo '<img class="img-responsive" alt="" src="'. $image['thumbnail_src'] .'" />';
										echo '<div class="nancy_thumbnail_overlay"></div>';
									echo '</a>';
									
								echo '</div>';
								
							endforeach;
						}
						}
						?>
					</div>
                </div>
            </div>
			<?php } ?>
        </div><!-- End Container -->
    </div>
    <div class="container">
		<nav class="bottom-footer">
			<a href="#top-header" class="scroll top"><i class="fa fa-long-arrow-up"></i></a>
			<p class="copyright-txt"><?php echo get_theme_mod('footer_copyright') ?></p>
		</nav>
	</div>
	<?php wp_footer(); ?>
	</div>
	</div><!--end wrapper-->
	
	<?php
		/*	
		$wrapper = get_theme_mod('rst_wrapper_layout') ? get_theme_mod('rst_wrapper_layout') : 1;
		if( $wrapper == '1' ){
			echo '</div>';
		}
		*/
	?>
</body>
</html>
