From fd79158917d2aafc75be9bebceef163576b10cef Mon Sep 17 00:00:00 2001 From: Tom Schulze Date: Fri, 21 Oct 2022 17:28:00 +0200 Subject: [PATCH] fix old and unused tag structure --- CHANGELOG.md | 3 ++- composer.json | 2 +- src/parsers/AccountVersion1Parser.php | 6 ++++++ src/parsers/Parser.php | 12 ++++++++++++ src/parsers/TagVersion1Parser.php | 18 +++++++++++++++--- src/parsers/TagVersion2Parser.php | 6 ++++++ src/parsers/TagVersion3Parser.php | 6 ++++++ 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 488fae7..7654217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Release Notes for Instagram Feed Plugin -## Unreleased +## 2.1.0 - 2022-10-21 ### Added - Set referrer in proxy requests. - Set plugin version in proxy requests. +- New tag structure v3. ### Changed diff --git a/composer.json b/composer.json index 49a7e83..71c731f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "codemonauts/craft-instagram-feed", "description": "Craft CMS plugin to receive Instagram feed data as variable in templates.", - "version": "2.0.1", + "version": "2.1.0", "type": "craft-plugin", "keywords": [ "craft", diff --git a/src/parsers/AccountVersion1Parser.php b/src/parsers/AccountVersion1Parser.php index 6cbbe9c..16f8c0f 100644 --- a/src/parsers/AccountVersion1Parser.php +++ b/src/parsers/AccountVersion1Parser.php @@ -4,6 +4,9 @@ class AccountVersion1Parser extends Parser { + /** + * @inheritDoc + */ public function getItems(array $response): array { $items = []; @@ -31,6 +34,9 @@ public function getItems(array $response): array return $items; } + /** + * @inheritDoc + */ protected function getPictureMapping(): array { return [ diff --git a/src/parsers/Parser.php b/src/parsers/Parser.php index 44fd2dc..7ef8c4b 100644 --- a/src/parsers/Parser.php +++ b/src/parsers/Parser.php @@ -4,8 +4,20 @@ abstract class Parser { + /** + * Returns the items from the given response. + * + * @param array $response The response from Instagram. + * + * @return array + */ abstract public function getItems(array $response): array; + /** + * Returns the picture mapping of the structure. + * + * @return array + */ abstract protected function getPictureMapping(): array; /** diff --git a/src/parsers/TagVersion1Parser.php b/src/parsers/TagVersion1Parser.php index 5dc405a..57a17ed 100644 --- a/src/parsers/TagVersion1Parser.php +++ b/src/parsers/TagVersion1Parser.php @@ -4,11 +4,20 @@ class TagVersion1Parser extends Parser { + /** + * @inheritDoc + */ public function getItems(array $response): array { - $itmes = []; + $items = []; - foreach ($mediaArray as $section) { + if (!isset($response['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'])) { + return $items; + } + + $sections = array_slice($response['data']['recent']['sections'], 0, 12); + + foreach ($sections as $section) { foreach ($section['layout_content']['medias'] as $node) { if ((int)$node['media']['media_type'] === 8) { if (!isset($node['media']['carousel_media'][0]['image_versions2'])) { @@ -33,9 +42,12 @@ public function getItems(array $response): array } } - return []; + return $items; } + /** + * @inheritDoc + */ protected function getPictureMapping(): array { return [ diff --git a/src/parsers/TagVersion2Parser.php b/src/parsers/TagVersion2Parser.php index c88de7e..6a1e728 100644 --- a/src/parsers/TagVersion2Parser.php +++ b/src/parsers/TagVersion2Parser.php @@ -4,6 +4,9 @@ class TagVersion2Parser extends Parser { + /** + * @inheritDoc + */ public function getItems(array $response): array { $items = []; @@ -42,6 +45,9 @@ public function getItems(array $response): array return $items; } + /** + * @inheritDoc + */ protected function getPictureMapping(): array { return [ diff --git a/src/parsers/TagVersion3Parser.php b/src/parsers/TagVersion3Parser.php index 847627c..3ddd21f 100644 --- a/src/parsers/TagVersion3Parser.php +++ b/src/parsers/TagVersion3Parser.php @@ -4,6 +4,9 @@ class TagVersion3Parser extends Parser { + /** + * @inheritDoc + */ public function getItems(array $response): array { $items = []; @@ -33,6 +36,9 @@ public function getItems(array $response): array return $items; } + /** + * @inheritDoc + */ protected function getPictureMapping(): array { return [