Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/baraja-core/wordpress-post-feed
Simple PHP API service for download and list of new blog posts from Wordpress RSS.
https://github.com/baraja-core/wordpress-post-feed
api articles feed php rss wordpress wordpress-rss wp
Last synced: about 2 months ago
JSON representation
Simple PHP API service for download and list of new blog posts from Wordpress RSS.
- Host: GitHub
- URL: https://github.com/baraja-core/wordpress-post-feed
- Owner: baraja-core
- License: mit
- Created: 2020-10-29T09:41:07.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-09T20:21:01.000Z (7 months ago)
- Last Synced: 2024-06-09T21:39:29.276Z (7 months ago)
- Topics: api, articles, feed, php, rss, wordpress, wordpress-rss, wp
- Language: PHP
- Homepage: https://php.baraja.cz
- Size: 54.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
Wordpress post feed
===================API service for downloading a list of new blog posts.
The library downloads the feed of posts from Wordpress and provides a simple API for reading them.
Posts from the feed are automatically cached for a set period of time, so they don't have to be downloaded again in each request.
📦 Installation
---------------It's best to use [Composer](https://getcomposer.org) for installation, and you can also find the package on
[Packagist](https://packagist.org/packages/baraja-core/wordpress-post-feed) and
[GitHub](https://github.com/baraja-core/wordpress-post-feed).To install, simply use the command:
```
$ composer require baraja-core/wordpress-post-feed
```You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.
Configuration
-------------If you are installing the package into the Nette Framework, you can simply register the extension:
```yaml
extensions:
wordpressPostFeed: Baraja\WordPressPostFeed\WordpressPostFeedExtension
```However, the extension is not required, as you can create an instance manually:
```php
$feed = new \Baraja\WordPressPostFeed\Feed;
```By default, no dependencies are required. Feed will take care of all dependencies by itself.
How to use
----------Basic usage is simple:
```php
$feed = new \Baraja\WordPressPostFeed\Feed;$posts = $feed->load('https://blog.mycleverminds.cz/feed/');
foreach ($posts as $post) {
echo $post->getTitle();
echo $post->getDescription();
echo $post->getLink();
echo $post->getDate()->format('Y-m-d');
echo $post->getCreator();
echo json_encode($post->getCategories());
echo $post->getMainImageUrl();
}
```The feed will be downloaded automatically, then cached and further requests will be handled instantly straight from the cache.
If you only need to retrieve some posts from the feed, you can use the `limit` and `offset` arguments:
```php
$posts = $feed->load(
url: 'https://blog.mycleverminds.cz/feed/',
limit: 3,
offset: 1,
);
```Posts are automatically cached for the set period (default 2 hours). If the period expires, the cache is automatically invalidated and the next request will have to retrieve the data and rebuild the cache. This retrieval may slow down this request. If you want to handle all requests instantly, the cache for the feed needs to be automatically refreshed by cron.
Cron will call the following method to refresh the cache:
```php
$feed = new \Baraja\WordPressPostFeed\Feed;
$feed->updateCache('https://blog.mycleverminds.cz/feed/');
```Image manipulation
------------------When downloading posts from the feed, images are also automatically downloaded and copied to disk. The image storage is provided by the `\Baraja\WordPressPostFeed\ImageStorage` service, which is automatically registered by the library. The default directory for storing images is `wordpress-post-feed` relative to your `index.php`.
The service provides the following methods:
| Method | Description |
|--------|-------------|
| `save(string $url): void` | Downloads the image from the URL and saves it to disk |
| `getInternalPath(string $url): string` | Returns the absolute path for the internal data store. |
| `getAbsoluteInternalUrl(string $url): string` | Returns the absolute URL to retrieve the image |
| `getRelativeInternalUrl(string $url): string` | Returns the relative URL to retrieve the image |Working with images is also available directly from the `Post` entity via methods:
- `getAbsoluteInternalUrl()`
- `getRelativeInternalUrl()`
- `getMainImageUrl()`📄 License
-----------`baraja-core/wordpress-post-feed` is licensed under the MIT license. See the [LICENSE](https://github.com/baraja-core/template/blob/master/LICENSE) file for more details.