Download the PHP package baraja-core/wordpress-post-feed without Composer

On this page you can find all versions of the php package baraja-core/wordpress-post-feed. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wordpress-post-feed

BRJ logo
BRJ organisation

WordPress Post Feed

A lightweight PHP library for fetching, parsing, and caching WordPress RSS feeds with automatic image handling.

The library provides a simple API to download blog posts from any WordPress RSS feed, automatically caches the content to minimize network requests, and handles image downloading and local storage for improved performance and reliability.

:sparkles: Key Features

:building_construction: Architecture Overview

The library consists of four main components that work together to provide a complete feed management solution:

:package: Components

Component Description
Feed Main service responsible for downloading, parsing, and caching RSS feeds. Orchestrates the entire feed retrieval process.
Post Data entity representing a single blog post with all its properties and image URL helpers.
ImageStorage Service for downloading, validating, and storing images locally. Provides URL generation for stored images.
WordpressPostFeedExtension Nette DI extension for seamless framework integration with full configuration support.

:package: Installation

It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.

To install, simply use the command:

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.

Requirements

:gear: Configuration

Standalone Usage

The library works out of the box without any configuration:

By default, the Feed service will:

Nette Framework Integration

If you are installing the package into the Nette Framework, register the extension in your configuration:

Advanced Configuration

The extension supports the following configuration options:

Option Type Default Description
expirationTime string '2 hours' Cache expiration time in human-readable format
imageStoragePath string null Absolute filesystem path for storing images
imageRelativeStoragePath string 'wordpress-post-feed' Relative URL path for accessing stored images

:rocket: Basic Usage

Loading Posts from a Feed

The feed will be downloaded automatically, then cached and further requests will be handled instantly straight from the cache.

Pagination with Limit and Offset

If you only need to retrieve some posts from the feed, use the limit and offset arguments:

Parameter Type Default Description
url string required The URL of the WordPress RSS feed
limit int|null null Maximum number of posts to return (null = all)
offset int 0 Number of posts to skip from the beginning

Post Entity Methods

The Post entity provides the following methods:

Method Return Type Description
getTitle() string Returns the post title (HTML tags stripped)
getDescription() string Returns the post description/excerpt
getLink() string Returns the permalink to the original post
getDate() DateTimeImmutable Returns the publication date
getCreator() string\|null Returns the author name
getCategories() array<int, string> Returns an array of category names
getMainImageUrl() string\|null Returns the original external image URL
getAbsoluteInternalUrl() string\|null Returns the absolute URL to locally stored image
getRelativeInternalUrl() string\|null Returns the relative URL to locally stored image

:floppy_disk: Caching System

How Caching Works

Posts are automatically cached for the set period (default 2 hours). The caching system operates on two levels:

  1. Raw feed caching - The downloaded XML feed is cached to avoid repeated HTTP requests
  2. Parsed post caching - The parsed Post objects are cached separately for each limit/offset combination

When the cache expires, the next request will:

  1. Download the fresh feed
  2. Parse all posts
  3. Store images locally
  4. Update the cache

Cache Management

Manual Cache Update

If you want to refresh the cache before expiration (e.g., via cron job):

This is useful for ensuring all requests are served from cache instantly, even after expiration.

Clear All Cache

To completely clear the feed cache:

Recommended Cron Setup

For production environments, it's recommended to set up a cron job that refreshes the cache periodically:

This ensures that user requests are always served from cache and never have to wait for feed downloads.

:framed_picture: Image Manipulation

When downloading posts from the feed, images are automatically downloaded and copied to disk. The image storage is provided by the \Baraja\WordPressPostFeed\ImageStorage service, which is automatically registered by the library.

Default Storage Location

The default directory for storing images is wordpress-post-feed relative to your index.php (web root).

ImageStorage Service Methods

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 filesystem path for the image
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 from Posts

Working with images is also available directly from the Post entity:

Supported Image Formats

The library validates downloaded images and supports the following formats:

Format Constant
JPEG ImageStorage::JPEG
PNG ImageStorage::PNG
GIF ImageStorage::GIF
WebP ImageStorage::WEBP
BMP ImageStorage::BMP

If a downloaded file is not a valid image of these types, a RuntimeException is thrown to prevent potential security issues.

Image Naming Strategy

Images are stored with a deterministic naming scheme to prevent collisions and ensure readability:

  1. A 7-character MD5 hash prefix is generated from the URL
  2. The original filename is sanitized (webalized) and truncated to 64 characters
  3. Files are organized into subdirectories based on WordPress date structure (YYYY-MM) or URL hash

Example: https://blog.example.com/wp-content/uploads/2024/03/my-image.jpg becomes:

:hammer_and_wrench: Advanced Usage

Custom Cache Storage

You can provide your own cache storage implementation:

Custom Image Storage Location

Custom Expiration Time

Supported time formats include: '1 hour', '30 minutes', '2 days', etc.

Dependency Injection in Nette

When using the Nette Framework, you can inject the services directly:

:warning: Error Handling

The library handles errors gracefully:

Example of handling errors:

:bust_in_silhouette: Author

Jan Barasek

:page_facing_up: License

baraja-core/wordpress-post-feed is licensed under the MIT license. See the LICENSE file for more details.


All versions of wordpress-post-feed with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
baraja-core/url Version ^1.0
nette/di Version ^3.0
nette/caching Version ^3.0
ext-curl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package baraja-core/wordpress-post-feed contains the following files

Loading the files please wait ...