コード例 #1
0
ファイル: grid.php プロジェクト: roycocup/enclothed
<?php

if (!class_exists('Easy_Instagram_Utils')) {
    _e('Please install the Easy Instagram plugin.', 'Easy_Instagram');
} else {
    $ei_utils = new Easy_Instagram_Utils();
    $kses_author = array('a' => array('href' => array(), 'title' => array(), 'target' => array()));
    $columns = 3;
    $element_padding = 10;
    // px
    $element_margin = 20;
    //px
    $current_column = 0;
    $element_width = 0;
    $style = '';
    // Calculate container width based on number of columns, thumbnail width, margin and padding
    if (!empty($easy_instagram_elements)) {
        $element = $easy_instagram_elements[0];
        $element_width = $element['thumbnail_width'];
        $container_width = $columns * ($element_width + 2 * $element_margin + 2 * $element_padding);
        $container_style = sprintf('width: %dpx;', $container_width);
        $element_style = sprintf('width: %dpx; padding: %dpx; margin: %dpx;', $element_width, $element_padding, $element_margin);
    } else {
        $container_style = '';
        $element_style = '';
    }
    ?>

<div class="easy-instagram-container grid" style='<?php 
    echo esc_attr($container_style);
    ?>
コード例 #2
0
 private function _get_render_elements($instagram_elements, $args)
 {
     $out = '';
     if (empty($instagram_elements)) {
         return $out;
     }
     extract($args);
     $time_text = trim($time_text);
     $time_format = trim($time_format);
     list($thumb_w, $thumb_h) = $this->get_thumb_size_from_params($thumb_size);
     $utils = new Easy_Instagram_Utils();
     $template_elements = array();
     $crt = 0;
     foreach ($instagram_elements as $elem) {
         $current_template_element = array();
         $current_template_element['_link'] = $elem['link'];
         $large_image_url = $elem['standard_resolution']['url'];
         $normal_image_url = $elem['low_resolution']['url'];
         $thumbnail_url = $elem['thumbnail']['url'];
         $instagram_image_original_link = $elem['link'];
         $type = $elem['type'];
         $unique_rel = $elem['unique_rel'];
         $video_url = $video_width = $video_height = '';
         if (isset($elem['video_standard_resolution'])) {
             if (isset($elem['video_standard_resolution']['url'])) {
                 $video_url = $elem['video_standard_resolution']['url'];
             }
             if (isset($elem['video_standard_resolution']['width'])) {
                 $video_width = $elem['video_standard_resolution']['width'];
             }
             if (isset($elem['video_standard_resolution']['height'])) {
                 $video_height = $elem['video_standard_resolution']['height'];
             }
         }
         $video_id = $elem['id'];
         $video_large_image = $elem['standard_resolution']['url'];
         if ('dynamic_thumbnail' == $thumb_size) {
             $dynamic_thumb = 'dynamic_thumbnail';
         }
         if ('dynamic_normal' == $thumb_size) {
             $dynamic_thumb = 'dynamic_normal';
         }
         if ('dynamic_large' == $thumb_size) {
             $dynamic_thumb = 'dynamic_large';
         }
         if ($thumb_w > 0 && $thumb_h > 0) {
             //TODO: generate new thumbnails
             $width = $thumb_w;
             $height = $thumb_h;
             $thumbnail_url = $this->cache->get_custom_thumbnail_url($elem, $width, $height);
         } else {
             $width = $elem['thumbnail']['width'];
             $height = $elem['thumbnail']['height'];
         }
         if (empty($caption_hashtags)) {
             $caption_hashtags = false;
         }
         $caption_text = $utils->get_caption_text($elem, $caption_hashtags, $caption_char_limit);
         $thickbox_caption_text = $utils->get_caption_text($elem, false, 100);
         $current_template_element['type'] = $type;
         $current_template_element['unique_rel'] = $unique_rel;
         $current_template_element['thumbnail_large_link_url'] = $large_image_url;
         $current_template_element['thumbnail_normal_link_url'] = $normal_image_url;
         $current_template_element['thumbnail_click'] = $thumb_click;
         switch ($thumb_click) {
             case 'thickbox':
             case 'colorbox':
                 $current_template_element['thumbnail_link_title'] = $thickbox_caption_text;
                 $current_template_element['thumbnail_link_url'] = $large_image_url;
                 if ('video' == $type) {
                     $current_template_element['video_url'] = $video_url;
                     $current_template_element['video_width'] = $video_width;
                     $current_template_element['video_height'] = $video_height;
                     $current_template_element['video_id'] = $video_id;
                     $current_template_element['video_large_url'] = $video_large_image;
                 }
                 break;
             case 'original':
                 $current_template_element['thumbnail_link_title'] = $caption_text;
                 $current_template_element['thumbnail_link_url'] = $instagram_image_original_link;
                 if ('video' == $type) {
                     $current_template_element['video_url'] = $video_url;
                 }
                 break;
             default:
                 $current_template_element['thumbnail_link_title'] = '';
                 $current_template_element['thumbnail_link_url'] = '';
                 break;
         }
         $current_template_element['thumbnail_url'] = $thumbnail_url;
         $current_template_element['thumbnail_width'] = $width;
         $current_template_element['thumbnail_height'] = $height;
         if (isset($dynamic_thumb)) {
             $current_template_element['dynamic_thumb'] = $dynamic_thumb;
         }
         if (empty($elem['caption_from'])) {
             $current_template_element['author'] = '';
         } else {
             // Make a link only from the user name, not all the 'published by' text
             if (preg_match('/^(.*)%s(.*)$/', $author_text, $matches)) {
                 $published_by = $matches[1] . '<a href="http://instagram.com/' . $elem['user_name'] . '" target="_blank">';
                 $published_by .= 'true' == $author_full_name ? $elem['caption_from'] : $elem['user_name'];
                 $published_by .= '</a>';
                 $published_by .= $matches[2];
             } else {
                 $published_by = $author_text;
             }
             $current_template_element['author'] = $published_by;
         }
         $current_template_element['_author'] = $elem['author'];
         $current_template_element['_likes'] = $elem['likes'];
         if ($caption_char_limit > 0) {
             $current_template_element['thumbnail_caption'] = $caption_text;
         } else {
             $current_template_element['thumbnail_caption'] = '';
         }
         if (is_null($elem['caption_created_time'])) {
             $elem_time = $elem['created_time'];
         } else {
             $elem_time = max(array($elem['caption_created_time'], $elem['created_time']));
         }
         $current_template_element['created_at'] = $elem_time;
         if (empty($time_text)) {
             $current_template_element['created_at_formatted'] = '';
         } else {
             if (preg_match('/^(.*)#T#(.*)$/', $time_text, $matches)) {
                 if ('' != $time_format) {
                     if ('#R#' == $time_format) {
                         // Relative
                         $time_string = $utils->relative_time($elem_time);
                     } else {
                         $time_string = strftime($time_format, $elem_time);
                     }
                 } else {
                     $time_string = '';
                 }
                 $time_string = $matches[1] . $time_string . $matches[2];
             } else {
                 $time_string = $time_text;
                 // No interpolation
             }
             $current_template_element['created_at_formatted'] = $time_string;
         }
         $template_elements[] = $current_template_element;
         $crt++;
         if ($crt >= $limit) {
             break;
         }
     }
     $out = $this->load_template($template, $template_elements);
     return $out;
 }
コード例 #3
0
 function cache_live_data($live_data, $endpoint_id, $endpoint_type, $limit)
 {
     $cache_data = array('cache_timestamp' => time(), 'requested_count' => $limit, 'data' => array());
     $unique_rel = md5($endpoint_type . $endpoint_id);
     $utils = new Easy_Instagram_Utils();
     foreach ($live_data as $elem) {
         list($user_name, $caption_from, $caption_text, $caption_created_time) = $utils->get_usename_caption($elem);
         $cached_elem = array('link' => isset($elem->link) ? $elem->link : '#', 'caption_text' => $caption_text, 'caption_from' => $caption_from, 'created_time' => $elem->created_time, 'caption_created_time' => $caption_created_time, 'user_name' => $user_name, 'type' => $elem->type, 'id' => $elem->id, 'unique_rel' => $unique_rel);
         foreach ($this->default_image_sizes as $image_size) {
             if (isset($elem->images->{$image_size})) {
                 $image_data = $elem->images;
             } else {
                 if (isset($elem->{$image_size})) {
                     $image_data = $elem;
                 } else {
                     break;
                 }
             }
             $cached_elem[$image_size] = array('width' => $image_data->{$image_size}->width, 'height' => $image_data->{$image_size}->height);
             $local_url = $this->save_remote_image($image_data->{$image_size}->url, $image_size);
             if (is_null($local_url)) {
                 $cached_elem[$image_size]['url'] = $image_data->{$image_size}->url;
             } else {
                 $cached_elem[$image_size]['url'] = $local_url;
             }
         }
         if ('video' === $elem->type) {
             $videos = $elem->videos;
             foreach ($this->default_video_sizes as $video_size) {
                 if (isset($videos->{$video_size})) {
                     $cached_elem['video_' . $video_size] = array('width' => $videos->{$video_size}->width, 'height' => $videos->{$video_size}->height);
                     $cached_elem['video_' . $video_size]['url'] = $videos->{$video_size}->url;
                 }
             }
         }
         $cache_data['data'][] = $cached_elem;
     }
     $this->_cache_data($cache_data, $endpoint_id, $endpoint_type);
     return $cache_data;
 }