kalimeromk/rssfeed
Composer 安装命令:
composer require kalimeromk/rssfeed
包简介
Full-Text RSS extraction package for Laravel - converts partial RSS feeds to full content
README 文档
README
A comprehensive RSS feed processing package for Laravel that extracts full-text content from RSS/Atom feeds. This package ports the powerful Full-Text RSS functionality from the original FiveFilters project to Laravel.
✨ Features
- 📰 Full-Text Extraction - Converts partial RSS feeds to complete articles
- 🤖 Readability Algorithm - Automatically detects main content using the Arc90 Readability algorithm
- 🌐 Site Configs - 1679+ site-specific configurations for better extraction
- 🖼️ Image Processing - Extracts and saves images with Spatie Media Library support
- 🔍 Language Detection - Automatically detects article language
- 🧹 HTML Sanitization - XSS filtering and inline style removal
- 📄 Multi-Page Support - Handles articles split across multiple pages
- 📝 Multiple Output Formats - RSS 2.0, Atom, and JSON Feed formats
- 🔐 Security - API key validation, domain whitelist/blacklist
- 💾 Caching - Built-in cache support via Laravel Cache
- ⚡ Modern PHP - Type-safe with PHP 8.0+ features
📦 Installation
composer require kalimeromk/rssfeed
Publish Configuration
php artisan vendor:publish --tag=config
Publish Site Configs (Optional)
php artisan vendor:publish --tag=site-configs
⚙️ Configuration
The configuration file is located at config/rssfeed.php:
return [ // Enable/disable the service 'enabled' => true, // Security settings 'key_required' => false, 'api_keys' => [], 'allowed_hosts' => [], 'blocked_hosts' => [], // Feature toggles 'singlepage_enabled' => true, 'multipage_enabled' => true, 'caching_enabled' => false, 'xss_filter_enabled' => false, 'detect_language' => true, // Cache settings 'cache_time' => 10, // minutes // HTML parser settings 'html_parser' => 'html5php', // or 'libxml' ];
🚀 Usage
Basic RSS Feed Parsing
use RssFeed; // Parse RSS feed $feed = RssFeed::RssFeeds('https://example.com/feed.xml'); // Get feed items foreach ($feed->get_items() as $item) { echo $item->get_title(); echo $item->get_description(); }
Full-Text Content Extraction
use Kalimeromk\Rssfeed\FullTextExtractor; $extractor = app(FullTextExtractor::class); // Extract from URL $result = $extractor->extract('https://example.com/article'); if ($result['success']) { echo $result['title']; echo $result['content']; echo $result['author']; echo $result['language']; } // Extract from HTML string $result = $extractor->extractFromHtml($html, 'https://example.com/article');
Process Feed with Full Content
use RssFeed; $items = RssFeed::parseRssFeeds('https://example.com/feed.xml'); foreach ($items as $item) { echo $item['title']; echo $item['content']; // Full article content echo $item['author']; echo $item['language']; }
Clean Text Extraction (No HTML)
$items = RssFeed::parseRssFeedsClean('https://example.com/feed.xml'); foreach ($items as $item) { echo $item['content']; // Plain text, no HTML }
Generate Feed Output
use Kalimeromk\Rssfeed\Services\FeedOutputService; $outputService = app(FeedOutputService::class); // RSS 2.0 $rss = $outputService->toRss($feedData); // Atom $atom = $outputService->toAtom($feedData); // JSON Feed $json = $outputService->toJson($feedData);
Image Handling
// Extract images from feed item $images = RssFeed::extractImagesFromItem($item); // Save images to storage $savedImages = RssFeed::saveImagesToStorage($images, $model);
HTML Sanitization
use Kalimeromk\Rssfeed\Services\HtmlSanitizerService; $sanitizer = app(HtmlSanitizerService::class); // Basic sanitization $clean = $sanitizer->sanitize($html); // Remove inline styles $noStyles = $sanitizer->sanitizeWithoutStyles($html); // Strip all HTML $text = $sanitizer->stripAllTags($html);
🔧 Advanced Usage
Custom Site Configuration
Create custom extraction rules in site_config/custom/{hostname}.txt:
# Example: example.com.txt
body: //article[contains(@class, 'main-content')]
title: //h1
author: //span[@class='author-name']
date: //time[@pubdate]
# Remove unwanted elements
strip_id_or_class: ads,comments,sidebar
strip: //div[@class='donation-form']
Domain-Specific Selectors
Add to config/rssfeed.php:
'content_selectors' => [ 'example.com' => '//div[@class="article-content"]', 'news.example.com' => '//article[contains(@class, "story")]', ],
Content Cleanup Rules
'remove_selectors' => [ '.donation-form', '.share-buttons', '.comments', '.advertisement', ],
🧪 Testing
composer test
📂 Package Structure
src/
├── Extractors/
│ ├── Readability/ # Arc90 Readability port
│ │ ├── Readability.php
│ │ └── JSLikeHTMLElement.php
│ └── ContentExtractor/ # Site config extraction
│ ├── ContentExtractor.php
│ └── SiteConfig.php
├── Handlers/
│ ├── MultiPageHandler.php # Multi-page article handling
│ └── SinglePageHandler.php # Single-page view detection
├── Services/
│ ├── CacheService.php # Laravel cache wrapper
│ ├── FeedOutputService.php # RSS/Atom/JSON generation
│ ├── HtmlSanitizerService.php
│ ├── LanguageDetectionService.php
│ └── SecurityValidator.php
├── FullTextExtractor.php # Main extraction class
├── RssFeed.php # Original RSS functionality
└── RssfeedServiceProvider.php
site_config/
└── standard/ # 1679+ site configurations
🔄 Migration from Original Full-Text RSS
| Original Feature | Laravel Equivalent |
|---|---|
Readability.php |
FullTextExtractor::extract() |
| Site Config files | Same format, copied to site_config/ |
makefulltextfeed.php |
FeedOutputService |
htmLawed |
HtmlSanitizerService (HTMLPurifier) |
Zend_Cache |
CacheService (Laravel Cache) |
📝 License
MIT License - see LICENSE for details.
🙏 Credits
This package is based on the Full-Text RSS project by FiveFilters.org, ported to Laravel with modern PHP practices.
- Original Readability by Arc90 Labs
- Ported to PHP by Keyvan Minoukadeh
- Laravel adaptation by Zorab Shefot Bogoevski
kalimeromk/rssfeed 适用场景与选型建议
kalimeromk/rssfeed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 923 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「feed」 「rss」 「laravel」 「readability」 「full-text」 「content-extraction」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kalimeromk/rssfeed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kalimeromk/rssfeed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kalimeromk/rssfeed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple RSS generator library for PHP 5.5 or later. clone from Bhaktaraz Bhatta ttps://github.com/bhaktaraz/php-rss-generator
Import an RSS-feed into blog
Google Shopping Feed API (with ns problem fixed)
This module is designed to provide a special alerts feed block for Howard University
Alfabank REST API integration
RSS builder for Laravel
统计信息
- 总下载量: 923
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-11