diff --git a/CHANGELOG.md b/CHANGELOG.md index 70dd958..e9dec48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## Unreleased ### Added - Enable environment variables for setting username (thanks to @niektenhoopen) -- Adding rel noopener and noreferrer properties to links (thanks to @JayBox325) +- Add rel noopener and noreferrer properties to links (thanks to @JayBox325) +- Add full image URL +- Add hasAudio attribute ### Changed - Prevent request storm if no items are cached and the request failed. diff --git a/README.md b/README.md index 2a8f553..e64359d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ To fetch the feed, configured in settings, in your template, just iterate like t ``` twig {% for item in craft.instagram.getFeed() %} - +
{{ item.caption }}
{{ item.likes }} Likes / {{ item.comments }} Comments
@@ -45,6 +45,23 @@ In PHP do: ``` php $feed = InstagramFeed::getInstance()->instagramService->getFeed(); ``` +The function returns an array of posts with the following keys: + +``` php +[ + 'src' => '', # Best available thumbnail + 'thumbnail' = '', # Same as src + 'image' => '', # The original image + 'likes' => 0, # Number of likes + 'comments' => 0, # Number of comments + 'shortcode' => '', # The IG shortcode for the post + 'timestamp' => 0, # Unix timestamp when the picture/ video was taken + 'caption' => '', # The caption of the post + 'isVideo' => false, # If the post is a video + 'hasAudio' => false # If the video has audio + 'video_view_count' => 0, # Number of video views +] +``` You can also get the current configured Instagram account (or hash tag) in your templates: diff --git a/src/services/InstagramService.php b/src/services/InstagramService.php index d74803d..3572e3a 100644 --- a/src/services/InstagramService.php +++ b/src/services/InstagramService.php @@ -288,12 +288,15 @@ private function flattenMediaArray($mediaArray): array foreach ($mediaArray as $media) { $item['src'] = $this->getBestPicture($media['node']['thumbnail_resources']); + $item['thumbnail'] = $item['src']; + $item['image'] = $media['node']['display_url']; $item['likes'] = $media['node']['edge_liked_by']['count']; $item['comments'] = $media['node']['edge_media_to_comment']['count']; $item['shortcode'] = $media['node']['shortcode']; $item['timestamp'] = $media['node']['taken_at_timestamp']; $item['caption'] = $media['node']['edge_media_to_caption']['edges'][0]['node']['text'] ?? ''; $item['isVideo'] = (bool)$media['node']['is_video']; + $item['hasAudio'] = (bool)$media['node']['has_audio']; $item['video_view_count'] = $media['node']['video_view_count'] ?? 0; $items[] = $item; }