Skip to content

Commit

Permalink
feat(code): initial code base commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 11, 2021
1 parent 1594c2d commit b7ceed7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# v1.0.0, 2021-01-11
* Initial release
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ The following dependencies need to be downloaded and installed for Feed Plugin.
|---|---|---|
| enabled | true | true or false to disable the plugin |
| priority | 100 | Feed plugin priority |
| feed | [] | feed specific data |
| feed | [] | Feed specific data |

### Usage

Inside `project/config/plugin/feed/settings.yaml` you may create unlimited feed for you entries.
Inside `project/config/plugins/feed/settings.yaml` you may create unlimited feed for you entries.

Lets create RSS, ATOM and JSON feed for blog collection:

Expand Down Expand Up @@ -78,7 +78,6 @@ You may easily display feed urls from example above in TWIG templates:
<a href="{{ url() }}/blog.json">JSON</a>
```


## LICENSE
[The MIT License (MIT)](https://github.com/flextype-plugins/feed/blob/master/LICENSE.txt)
Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum)
64 changes: 64 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

$feed = flextype('registry')->get('plugins.feed.settings.feed');

if (isset($feed) and count($feed) > 0) {
foreach (flextype('registry')->get('plugins.feed.settings.feed') as $item) {

$cacheID = strings('feed-collection-' . $item['id'])->hash()->toString();

flextype('emitter')->addListener('onEntriesCreate', function () use ($cacheID) {
flextype('cache')->delete($cacheID);
});

flextype('emitter')->addListener('onEntriesDelete', function () use ($cacheID) {
flextype('cache')->delete($cacheID);
});

flextype('emitter')->addListener('onEntriesMove', function () use ($cacheID) {
flextype('cache')->delete($cacheID);
});

flextype('emitter')->addListener('onEntriesCopy', function () use ($cacheID) {
flextype('cache')->delete($cacheID);
});

flextype('emitter')->addListener('onEntriesUpdate', function () use ($cacheID) {
flextype('cache')->delete($cacheID);
});

flextype()->get($item['options']['route'], function (Request $request, Response $response, array $args) use ($item, $cacheID) {

if (flextype('cache')->has($cacheID)) {
$entries = flextype('cache')->get($cacheID);
} else {
$entries = flextype('entries')
->fetch($item['id'], $item['options'])
->sortBy('published_at', 'DESC');

flextype('cache')->set($cacheID, $entries);
}

switch ($item['options']['format']) {
case 'rss':
$response = $response->withHeader('Content-Type', 'application/rss+xml');
$template = 'plugins/feed/templates/feed.rss.html';
break;
case 'atom':
$response = $response->withHeader('Content-Type', 'application/atom+xml');
$template = 'plugins/feed/templates/feed.atom.html';
break;
case 'json':
default:
$response = $response->withHeader('Content-Type', 'application/json');
$template = 'plugins/feed/templates/feed.json.html';
break;
}

return flextype('twig')->render($response, $template, ['entries' => $entries, 'item' => $item]);
});
}
}
19 changes: 19 additions & 0 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Feed
version: 1.0.0
description: Feed plugin for Flextype
author:
name: Sergey Romanenko
email: [email protected]
url: https://flextype.org
homepage: https://github.com/flextype-plugins/feed
documentation: https://github.com/flextype-plugins/feed
changelog: https://github.com/flextype-plugins/feed/blob/master/CHANGELOG.md
bugs: https://github.com/flextype-plugins/feed/issues
icon:
name: map-marked-alt
set: "fontawesome|solid"
license: MIT

dependencies:
flextype: 0.9.15
twig: '>=2.0.0'
3 changes: 3 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enabled: true
priority: 100
feed: []

0 comments on commit b7ceed7

Please sign in to comment.