├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── readability.php └── src ├── Facades └── Readability.php ├── Readability.php └── ReadabilityServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-readability` will be documented in this file. 4 | 5 | ## v1.0.3 - 2024-05-07 6 | 7 | ### What's Changed 8 | 9 | * Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 by @dependabot in https://github.com/The-3Labs-Team/laravel-readability/pull/7 10 | 11 | **Full Changelog**: https://github.com/The-3Labs-Team/laravel-readability/compare/v1.0.2...v1.0.3 12 | 13 | ## v1.0.2 - 2024-03-02 14 | 15 | ### What's Changed 16 | 17 | * Add test coverage by @murdercode in https://github.com/The-3Labs-Team/laravel-readability/pull/3 18 | * Add tests for direction by @murdercode in https://github.com/The-3Labs-Team/laravel-readability/pull/4 19 | 20 | **Full Changelog**: https://github.com/The-3Labs-Team/laravel-readability/compare/v1.0.1...v1.0.2 21 | 22 | ## v1.0.1 - 2024-03-01 23 | 24 | ### What's Changed 25 | 26 | * Remove scaffolding by @murdercode in https://github.com/The-3Labs-Team/laravel-readability/pull/2 27 | 28 | ### New Contributors 29 | 30 | * @murdercode made their first contribution in https://github.com/The-3Labs-Team/laravel-readability/pull/2 31 | 32 | **Full Changelog**: https://github.com/The-3Labs-Team/laravel-readability/compare/v1.0.0...v1.0.1 33 | 34 | ## v1.0.0 - 2024-03-01 35 | 36 | ### What's Changed 37 | 38 | * Bump ramsey/composer-install from 2 to 3 by @dependabot in https://github.com/The-3Labs-Team/laravel-readability/pull/1 39 | 40 | ### New Contributors 41 | 42 | * @dependabot made their first contribution in https://github.com/The-3Labs-Team/laravel-readability/pull/1 43 | 44 | **Full Changelog**: https://github.com/The-3Labs-Team/laravel-readability/commits/v1.0.0 45 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) The 3Labs Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Logo Laravel Readability

2 | 3 | # Laravel Readability 4 | 5 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/the-3labs-team/laravel-readability.svg?style=flat-square)](https://packagist.org/packages/the-3labs-team/laravel-readability) 6 | [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/the-3labs-team/laravel-readability/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/the-3labs-team/laravel-readability/actions?query=workflow%3Arun-tests+branch%3Amain) 7 | [![Github PHPStan](https://img.shields.io/github/actions/workflow/status/the-3labs-team/laravel-readability/phpstan.yml?branch=main&label=phpstan&style=flat-square)](https://github.com/the-3labs-team/laravel-readability/actions?query=workflow%3Aphpstan+branch%3Amain) 8 | [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/the-3labs-team/laravel-readability/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/the-3labs-team/laravel-readability/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) 9 | [![Maintainability](https://api.codeclimate.com/v1/badges/0fcf8cc60952fcc6d286/maintainability)](https://codeclimate.com/github/The-3Labs-Team/laravel-readability/maintainability) 10 | [![Test Coverage](https://api.codeclimate.com/v1/badges/0fcf8cc60952fcc6d286/test_coverage)](https://codeclimate.com/github/The-3Labs-Team/laravel-readability/test_coverage) 11 | ![License Mit](https://img.shields.io/github/license/murdercode/laravel-shortcode-plus) 12 | [![Total Downloads](https://img.shields.io/packagist/dt/the-3labs-team/laravel-readability.svg?style=flat-square)](https://packagist.org/packages/the-3labs-team/laravel-readability) 13 | 14 | This package is a Laravel wrapper for [readability.php](https://github.com/fivefilters/readability.php). It provides a 15 | simple way to extract the main content from a webpage. 16 | 17 | ## Installation 18 | 19 | You can install the package via composer: 20 | 21 | ```bash 22 | composer require the-3labs-team/laravel-readability 23 | ``` 24 | 25 | Since it uses the readability.php package, you will need the following PHP extensions: 26 | 27 | ```bash 28 | $ sudo apt-get install php7.4-xml php7.4-mbstring 29 | ``` 30 | 31 | Please change the version according to your PHP version. 32 | 33 | ## Usage 34 | 35 | ```php 36 | $html = '...'; 37 | $parsed = Readability::parse($html); 38 | $title = $parsed->getTitle(); 39 | ``` 40 | 41 | You can use the same methods as the original package. Please refer to 42 | the [readability.php documentation](https://github.com/fivefilters/readability.php). 43 | 44 | ```php 45 | $html = '...'; 46 | $parsed = Readability::parse($html); 47 | 48 | $title = $parsed->getTitle(); 49 | $content = $parsed->getContent(); 50 | $excerpt = $parsed->getExcerpt(); 51 | $author = $parsed->getAuthor(); 52 | $direction = $parsed->getDirection(); 53 | $image = $parsed->getImage(); 54 | $images = $parsed->getImages(); 55 | ``` 56 | 57 | ## Testing 58 | 59 | ```bash 60 | composer test 61 | ``` 62 | 63 | ## Changelog 64 | 65 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 66 | 67 | ## Contributing 68 | 69 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 70 | 71 | ## Security Vulnerabilities 72 | 73 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 74 | 75 | ## Credits 76 | 77 | - [Stefano Novelli](https://github.com/murdercode) 78 | - [All Contributors](../../contributors) 79 | 80 | ## License 81 | 82 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 83 | 84 | ## Sponsor 85 | 86 |
87 | 88 | Tom's Hardware - Notizie, recensioni, guide all'acquisto e approfondimenti per tutti gli appassionati di computer, smartphone, videogiochi, film, serie tv, gadget e non solo 89 | 90 | 91 | Spaziogames - Tutto sul mondo dei videogiochi. Troverai tantissime anteprime, recensioni, notizie dei giochi per tutte le console, PC, iPhone e Android. 92 | 93 |
94 | 95 | Cpop - News, recensioni, guide su fumetto, cinema & serie TV, gioco da tavolo e di ruolo e collezionismo. Tutto quello di cui hai bisogno per rimanere aggiornato sul mondo della cultura pop 96 | 97 | 98 | Data4Biz - Sito dedicato alla trasformazione digitale del business 99 | 100 |
101 | 102 | SOS Home & Garden - Realtà dedicata a 360 gradi ai settori della casa e del giardino. 103 | 104 | 105 | Techradar - Le ultime notizie e recensioni dal mondo della tecnologia, su computer, sistemi per la casa, gadget e altro. 106 | 107 |
108 | 109 | Aibay - Scopri AiBay, il leader delle notizie sull'intelligenza artificiale. Resta aggiornato sulle ultime innovazioni, ricerche e tendenze del mondo AI con approfondimenti, interviste esclusive e analisi dettagliate. 110 | 111 | 112 | Coinlabs - Notizie, analisi approfondite, guide e opinioni aggiornate sul mondo delle criptovalute, blockchain e finanza 113 | 114 | 115 |
116 | 117 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "the-3labs-team/laravel-readability", 3 | "description": "Laravel Readability is a supercharged PHP client that makes it easy to extract and manipulate the main content of a web page.", 4 | "keywords": [ 5 | "The-3Labs-Team", 6 | "laravel", 7 | "laravel-readability" 8 | ], 9 | "homepage": "https://github.com/the-3labs-team/laravel-readability", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Stefano Novelli", 14 | "email": "murdercode@gmail.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.1", 20 | "fivefilters/readability.php": "^3.1", 21 | "spatie/laravel-package-tools": "^1.14.0" 22 | }, 23 | "require-dev": { 24 | "laravel/pint": "^1.0", 25 | "nunomaduro/collision": "^7.0", 26 | "larastan/larastan": "^2.0.1", 27 | "orchestra/testbench": "^8.0", 28 | "pestphp/pest": "^2.20", 29 | "pestphp/pest-plugin-arch": "^2.5", 30 | "pestphp/pest-plugin-laravel": "^2.0", 31 | "phpstan/extension-installer": "^1.1", 32 | "phpstan/phpstan-deprecation-rules": "^1.0", 33 | "phpstan/phpstan-phpunit": "^1.0" 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "The3LabsTeam\\Readability\\": "src/", 38 | "The3LabsTeam\\Readability\\Database\\Factories\\": "database/factories/", 39 | "fiveFilters\\Readability\\": "vendor/fivefilters/readability.php/src/" 40 | } 41 | }, 42 | "autoload-dev": { 43 | "psr-4": { 44 | "The3LabsTeam\\Readability\\Tests\\": "tests/", 45 | "Workbench\\App\\": "workbench/app/" 46 | } 47 | }, 48 | "scripts": { 49 | "post-autoload-dump": "@composer run prepare", 50 | "clear": "@php vendor/bin/testbench package:purge-laravel-readability --ansi", 51 | "prepare": "@php vendor/bin/testbench package:discover --ansi", 52 | "build": [ 53 | "@composer run prepare", 54 | "@php vendor/bin/testbench workbench:build --ansi" 55 | ], 56 | "start": [ 57 | "Composer\\Config::disableProcessTimeout", 58 | "@composer run build", 59 | "@php vendor/bin/testbench serve" 60 | ], 61 | "analyse": "vendor/bin/phpstan analyse", 62 | "test": "vendor/bin/pest", 63 | "test-coverage": "vendor/bin/pest --coverage", 64 | "format": "vendor/bin/pint" 65 | }, 66 | "config": { 67 | "sort-packages": true, 68 | "allow-plugins": { 69 | "pestphp/pest-plugin": true, 70 | "phpstan/extension-installer": true 71 | } 72 | }, 73 | "extra": { 74 | "laravel": { 75 | "providers": [ 76 | "The3LabsTeam\\Readability\\ReadabilityServiceProvider" 77 | ], 78 | "aliases": { 79 | "Readability": "The3LabsTeam\\Readability\\Facades\\Readability" 80 | } 81 | } 82 | }, 83 | "minimum-stability": "dev", 84 | "prefer-stable": true 85 | } 86 | -------------------------------------------------------------------------------- /config/readability.php: -------------------------------------------------------------------------------- 1 | content = new FFReadability(new Configuration()); 22 | try { 23 | $this->content->parse($content); 24 | } catch (ParseException $e) { 25 | $this->content = null; 26 | error_log('Cannot parse: '.$e->getMessage()); 27 | throw new Exception('Cannot parse: '.$e->getMessage()); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | /** 34 | * Return the title of the content 35 | * 36 | * @throws Exception 37 | */ 38 | public function getTitle(): string 39 | { 40 | $this->checkContent(); 41 | 42 | return $this->content->getTitle(); 43 | } 44 | 45 | /** 46 | * Return the excerpt of the content 47 | * 48 | * @throws Exception 49 | */ 50 | public function getExcerpt(): ?string 51 | { 52 | $this->checkContent(); 53 | 54 | return $this->content->getExcerpt(); 55 | } 56 | 57 | /** 58 | * Return the author of the content 59 | * 60 | * @throws Exception 61 | */ 62 | public function getAuthor(): string 63 | { 64 | $this->checkContent(); 65 | 66 | return $this->content->getAuthor(); 67 | } 68 | 69 | /** 70 | * Return the image of the content 71 | * 72 | * @throws Exception 73 | */ 74 | public function getImage(): string 75 | { 76 | $this->checkContent(); 77 | $image = $this->content->getImage(); 78 | 79 | return $image ?? ''; 80 | } 81 | 82 | /** 83 | * Return the images of the content 84 | * 85 | * @throws Exception 86 | */ 87 | public function getImages(): array 88 | { 89 | $this->checkContent(); 90 | 91 | return $this->content->getImages(); 92 | } 93 | 94 | /** 95 | * Return the content 96 | */ 97 | public function getContent(): string 98 | { 99 | $this->checkContent(); 100 | 101 | return $this->content->getContent(); 102 | } 103 | 104 | /** 105 | * Return the direction 106 | * 107 | * @throws Exception 108 | */ 109 | public function getDirection(): string 110 | { 111 | $this->checkContent(); 112 | 113 | return $this->content->getDirection(); 114 | } 115 | 116 | /** 117 | * Check if the content is parsed 118 | * 119 | * @throws Exception 120 | */ 121 | private function checkContent(): void 122 | { 123 | if ($this->content === null) { 124 | throw new Exception('Content is null. Did you forget to call parse()?'); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/ReadabilityServiceProvider.php: -------------------------------------------------------------------------------- 1 | name('laravel-readability'); 19 | } 20 | } 21 | --------------------------------------------------------------------------------