Exemplo n.º 1
0
function tg_get_instagram($username, $access_token, $items = 8)
{
    if (!empty($username) && !empty($access_token)) {
        $instagram_cache_path = THEMEUPLOAD . '/instagram_' . $username . '_' . $items . '.cache';
        if (file_exists($instagram_cache_path)) {
            $instagram_cache_timer = intval((time() - filemtime($instagram_cache_path)) / 60);
        } else {
            $instagram_cache_timer = 0;
        }
        $photos_arr = array();
        if (!file_exists($instagram_cache_path) or $instagram_cache_timer > 15) {
            require_once get_template_directory() . "/modules/instagram/instagram.php";
            $isg = new instagramPhp($username, $access_token);
            $shots = $isg->getUserMedia(array('count' => $items));
            if ($shots) {
                foreach ($shots->data as $key => $item) {
                    $thumb_url = $item->images->thumbnail->url;
                    $large_url = $item->images->standard_resolution->url;
                    $photos_arr[] = array('thumb_url' => $thumb_url, 'url' => $large_url, 'link' => $item->link);
                }
            }
            if (!empty($photos_arr)) {
                if (file_exists($instagram_cache_path)) {
                    unlink($instagram_cache_path);
                }
                $myFile = $instagram_cache_path;
                $fh = fopen($myFile, 'w') or die("can't open file");
                $stringData = serialize($photos_arr);
                fwrite($fh, $stringData);
                fclose($fh);
            } else {
                $file = file_get_contents($instagram_cache_path, true);
                if (!empty($file)) {
                    $photos_arr = unserialize($file);
                }
            }
        } else {
            $file = file_get_contents($instagram_cache_path, true);
            if (!empty($file)) {
                $photos_arr = unserialize($file);
            }
        }
    } else {
        echo 'Invalid username and access token';
    }
    return $photos_arr;
}
    <?php wp_nav_menu( array('theme_location' => 'main-menu', 'container' => '', 'menu_class' => '', 'menu_id' => '', 'depth' => 2, 'walker' => new jrd_walker() )); ?>
</section>

<?php

  $username = get_field('instagram_username','options');
  $access_token = get_field('instagram_access_token','options');
  $userid = 1986221760;
  $count = '5'; //How many shots do you want?

  //2 - Include the php class
  include('instagram.php');

  //3 - Instanciate
  if(!empty($username) && $username!='yourusername' && !empty($access_token) && $access_token!='youraccesstoken'){
      $isg = new instagramPhp($username,$access_token,$userid); //instanciates the class with the parameters
      $shots = $isg->getUserMedia(array('count'=>$count)); //Get the shots from instagram
  } else {
      echo'Please update your settings to provide a valid username and access token';
  }

?>

<div id="share">
    <div class="wrap">
        <h3><?php the_field('social_small_header'); ?></h3>
        <h2><?php the_field('social_large_header'); ?></h2>
        <div id="instagram">
            <?php if(!empty($shots)){
                //echo $isg->simpleDisplay($shots);
                $i = 1;