-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f1366
commit 92f9c51
Showing
10 changed files
with
138 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Instagram Feed Changelog | ||
|
||
## 1.0.0 - 2019-04-06 | ||
### Added | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
# Instagram feed plugin for Craft CMS 3.x | ||
|
||
A really basic Twig extension for CraftCMS (Craft3.x) that helps you get your instagram feed data | ||
![Icon](resources/instagram.png) | ||
|
||
A plugin for Craft CMS that helps you get your Instagram feed data. | ||
|
||
## Background | ||
|
||
If you want to add your (or someone else) Instagram feed on your site, you can use this plugin to fetch and cache the feed. It returns the image source, the number of likes and comments and the shortcode of the posts. | ||
|
||
This only works with **public** profiles. | ||
|
||
## Requirements | ||
|
||
This plugin requires Craft CMS 3.0.0 or later. | ||
* Craft CMS >= 3.0.0 | ||
|
||
## Installation | ||
|
||
To install the plugin, follow these instructions. | ||
Open your terminal and go to your Craft project: | ||
|
||
``` shell | ||
cd /path/to/project | ||
composer require codemonauts/codemonauts/craft-instagram-feed | ||
``` | ||
|
||
In the control panel, go to Settings → Plugins and click the “install” button for *Instagram feed*. Then you will be redirected to the settings page, where you can enter the username of the Instagram account you want to fetch. | ||
|
||
## Usage | ||
|
||
1. Open your terminal and go to your Craft project: | ||
To fetch the feed in your template, just iterate like this: | ||
|
||
cd /path/to/project | ||
``` twig | ||
{% for item in craft.instagram.getFeed() %} | ||
<a href="https://www.instagram.com/p/{{ item.shortcode }}/" target="_blank"> | ||
<img src="{{ item.src }}" alt="" /> | ||
</a> | ||
<p>{{ item.likes }} Likes / {{ item.comments }} Comments</p> | ||
{% endfor %} | ||
``` | ||
|
||
2. Then tell composer to load the plugin: | ||
In PHP do: | ||
|
||
composer require https://github.com/codemonauts/craft-instagram-feed | ||
``` php | ||
$feed = InstagramFeed::getInstance()->instagramService->getFeed(); | ||
``` | ||
|
||
3. In the control panel, go to Settings → Plugins and click the “install” button for Instragram Feed. | ||
## Caching | ||
|
||
The feed will be cached for 1 month but will be checked and updated evey 6 hours. If the update fails, the cached feed is used and the update stops for 15 minutes before checking again. | ||
|
||
Brought to you by [Codemonauts](https://codemonauts.com) | ||
With ❤ by [codemonauts](https://codemonauts.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
{ | ||
"name": "codemonauts/craft-instagram-feed", | ||
"description": "Craft 3 plugin to receive instragram feed data as variable in templates.", | ||
"version": "1.0.0", | ||
"type": "craft-plugin", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin" | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"codemonauts\\instagramfeed\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Codemonauts", | ||
"homepage": "https://www.codemonauts.com" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0" | ||
}, | ||
"support": { | ||
"docs": "https://github.com/codemonauts/craft-instagram-feed/blob/master/README.md", | ||
"issues": "https://github.com/codemonauts/craft-instagram-feed/issues" | ||
}, | ||
"extra": { | ||
"handle": "instagramfeed", | ||
"name": "Instagram Feed", | ||
"developer": "codemonauts", | ||
"developerUrl": "https://codemonauts.com", | ||
"hasCpSection": false, | ||
"hasSettings": false, | ||
"class": "codemonauts\\instagramfeed\\InstagramFeed" | ||
"name": "codemonauts/craft-instagram-feed", | ||
"description": "Craft CMS plugin to receive Instragram feed data as variable in templates.", | ||
"version": "1.0.0", | ||
"type": "craft-plugin", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"instagram" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "codemonauts", | ||
"homepage": "https://codemonauts.com" | ||
} | ||
} | ||
], | ||
"support": { | ||
"source": "https://github.com/codemonauts/craft-instagram-feed", | ||
"docs": "https://github.com/codemonauts/craft-instagram-feed/blob/master/README.md", | ||
"issues": "https://github.com/codemonauts/craft-instagram-feed/issues" | ||
}, | ||
"require": { | ||
"craftcms/cms": "^3.0.0", | ||
"ext-json": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"codemonauts\\instagramfeed\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"handle": "instagramfeed", | ||
"class": "codemonauts\\instagramfeed\\InstagramFeed", | ||
"name": "Instagram Feed", | ||
"description": "Receive Instagram feed data as variable in templates.", | ||
"hasCpSection": false, | ||
"hasSettings": false | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,69 @@ | ||
<?php | ||
/** | ||
* Craft3 Instagram Feed plugin for Craft CMS 3.x | ||
* | ||
* @link https://www.codemonauts.com | ||
* @copyright Copyright (c) 2019 Codemonauts | ||
*/ | ||
|
||
namespace codemonauts\instagramfeed; | ||
|
||
use codemonauts\instagramfeed\models\Settings; | ||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\helpers\UrlHelper; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
use craft\web\twig\variables\CraftVariable; | ||
|
||
use yii\base\Event; | ||
|
||
use codemonauts\instagramfeed\services\InstagramService; | ||
use codemonauts\instagramfeed\variables\InstagramFeedVariable; | ||
|
||
|
||
class InstagramFeed extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
public $hasCpSettings = true; | ||
public $schemaVersion = '0.1'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
$this->setComponents([ | ||
'instagramService' => InstagramService::class, | ||
]); | ||
|
||
Event::on( | ||
Plugins::class, | ||
Plugins::EVENT_AFTER_INSTALL_PLUGIN, | ||
function(PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
} | ||
} | ||
); | ||
|
||
Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function(Event $event) { | ||
$variable = $event->sender; | ||
$variable->set('instagram', InstagramFeedVariable::class); | ||
}); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'instagramfeed', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
public function afterInstall () | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function afterInstall() | ||
{ | ||
parent::afterInstall(); | ||
|
||
if (Craft::$app->getRequest()->getIsConsoleRequest()) | ||
if (Craft::$app->getRequest()->getIsConsoleRequest()) { | ||
return; | ||
} | ||
|
||
Craft::$app->getResponse()->redirect( | ||
UrlHelper::cpUrl('settings/plugins/instagramfeed') | ||
)->send(); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function createSettingsModel() | ||
{ | ||
return new \codemonauts\instagramfeed\models\Settings(); | ||
return new Settings(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function settingsHtml() | ||
{ | ||
return Craft::$app->getView()->renderTemplate( | ||
'instagramfeed/settings', | ||
['settings' => $this->getSettings()] | ||
return Craft::$app->getView()->renderTemplate('instagramfeed/settings', [ | ||
'settings' => $this->getSettings() | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.