mirror of
https://github.com/j0k3r/php-readability.git
synced 2026-09-27 14:36:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a0f3337a6 | ||
|
|
2dce2879bf | ||
|
|
49ce4233fa | ||
|
|
26c881d864 | ||
|
|
db69fe59a2 | ||
|
|
a78f01f656 | ||
|
|
db4508003b | ||
|
|
15b12ea2d6 | ||
|
|
694f0308fe | ||
|
|
bbe9021fe7 | ||
|
|
9dee4a240d | ||
|
|
eef6d6d456 | ||
|
|
30a577c617 | ||
|
|
70b393a2a3 | ||
|
|
9ab6d0d9e8 | ||
|
|
8712db510e | ||
|
|
422c74f29c | ||
|
|
ed3393a79f | ||
|
|
63cd304dba | ||
|
|
43939f88d9 | ||
|
|
3a7350a8a7 | ||
|
|
4c68cc9f09 | ||
|
|
276684ab6d | ||
|
|
163058aeff | ||
|
|
6427dd7371 | ||
|
|
613a63c062 | ||
|
|
05089bbd03 | ||
|
|
5ac82f3c87 | ||
|
|
85fb92a042 | ||
|
|
f2a43b476c |
@@ -1,20 +1,30 @@
|
||||
<?php
|
||||
|
||||
return Symfony\CS\Config\Config::create()
|
||||
return PhpCsFixer\Config::create()
|
||||
->setUsingCache(true)
|
||||
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
|
||||
// use default SYMFONY_LEVEL and extra fixers:
|
||||
->fixers(array(
|
||||
'concat_with_spaces',
|
||||
'ordered_use',
|
||||
'phpdoc_order',
|
||||
'strict',
|
||||
'strict_param',
|
||||
'long_array_syntax',
|
||||
))
|
||||
->finder(
|
||||
Symfony\CS\Finder\DefaultFinder::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'@Symfony' => true,
|
||||
'@Symfony:risky' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'combine_consecutive_unsets' => true,
|
||||
'heredoc_to_nowdoc' => true,
|
||||
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
|
||||
'no_unreachable_default_argument_value' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_useless_return' => true,
|
||||
'ordered_class_elements' => true,
|
||||
'ordered_imports' => true,
|
||||
'php_unit_strict' => false,
|
||||
'phpdoc_order' => true,
|
||||
// 'psr4' => true,
|
||||
'strict_comparison' => true,
|
||||
'strict_param' => true,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->exclude(['vendor'])
|
||||
->in(__DIR__)
|
||||
->exclude(array('vendor'))
|
||||
)
|
||||
;
|
||||
|
||||
+5
-18
@@ -1,28 +1,21 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3.3
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- nightly
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 7.0
|
||||
- php: 7.2
|
||||
env: CS_FIXER=run
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
- php: nightly
|
||||
|
||||
# faster builds on new travis setup not using sudo
|
||||
sudo: false
|
||||
|
||||
# cache vendor dirs
|
||||
cache:
|
||||
directories:
|
||||
@@ -31,18 +24,12 @@ cache:
|
||||
|
||||
before_install:
|
||||
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
|
||||
# disable TLS for composer because openssl is disabled for PHP 5.3.3 on travis
|
||||
# see: https://blog.travis-ci.com/upcoming_ubuntu_11_10_migration/
|
||||
- if [[ $TRAVIS_PHP_VERSION = 5.3.3 ]]; then composer config -g -- disable-tls true; fi;
|
||||
- if [[ $TRAVIS_PHP_VERSION = 5.3.3 ]]; then composer config -g -- secure-http false; fi;
|
||||
# no version compatible with PHP > 7.1
|
||||
- if [[ $TRAVIS_PHP_VERSION = 7.2.* ]]; then composer remove friendsofphp/php-cs-fixer; fi;
|
||||
|
||||
install:
|
||||
- composer self-update
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-dist --no-interaction
|
||||
- composer install -o --prefer-dist --no-interaction
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
@@ -50,4 +37,4 @@ script:
|
||||
- if [ "$CS_FIXER" = "run" ]; then php vendor/bin/php-cs-fixer fix --verbose --dry-run ; fi;
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
- php vendor/bin/php-coveralls -v -x build/logs/clover.xml
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
[](https://travis-ci.org/j0k3r/php-readability)
|
||||
[](https://coveralls.io/github/j0k3r/php-readability/?branch=master)
|
||||
[](https://packagist.org/packages/j0k3r/php-readability)
|
||||
[](https://packagist.org/packages/j0k3r/php-readability)
|
||||
|
||||
This is an extract of the Readability class from this [full-text-rss](https://github.com/Dither/full-text-rss) fork. It can be defined as a better version of the original [php-readability](https://bitbucket.org/fivefilters/php-readability/overview).
|
||||
|
||||
|
||||
+7
-6
@@ -24,15 +24,16 @@
|
||||
"role": "Developer (original JS version)"
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"php": ">=5.6.0",
|
||||
"ext-mbstring": "*",
|
||||
"psr/log": "^1.0"
|
||||
"psr/log": "^1.0",
|
||||
"electrolinux/php-html5lib": "^0.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"satooshi/php-coveralls": "~0.6",
|
||||
"friendsofphp/php-cs-fixer": "<2",
|
||||
"monolog/monolog": "^1.13",
|
||||
"symfony/phpunit-bridge": "^3.2"
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"friendsofphp/php-cs-fixer": "^2.14",
|
||||
"monolog/monolog": "^1.24",
|
||||
"symfony/phpunit-bridge": "^4.2.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-tidy": "Used to clean up given HTML and to avoid problems with bad HTML structure."
|
||||
|
||||
+21
-16
@@ -45,19 +45,31 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if ($name === 'innerHTML') {
|
||||
if ('innerHTML' !== $name) {
|
||||
$trace = debug_backtrace();
|
||||
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// first, empty the element
|
||||
for ($x = $this->childNodes->length - 1; $x >= 0; --$x) {
|
||||
$this->removeChild($this->childNodes->item($x));
|
||||
}
|
||||
|
||||
// $value holds our new inner HTML
|
||||
if ($value !== '') {
|
||||
$value = trim($value);
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure bad entity won't generate warning
|
||||
$previousError = libxml_use_internal_errors(true);
|
||||
|
||||
$f = $this->ownerDocument->createDocumentFragment();
|
||||
|
||||
// appendXML() expects well-formed markup (XHTML)
|
||||
// @ to suppress PHP warnings
|
||||
$result = @$f->appendXML($value);
|
||||
$result = $f->appendXML($value);
|
||||
if ($result) {
|
||||
if ($f->hasChildNodes()) {
|
||||
$this->appendChild($f);
|
||||
@@ -72,7 +84,7 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
// We use it (and suppress the warning) because an HTML fragment will
|
||||
// be wrapped around <html><body> tags which we don't really want to keep.
|
||||
// Note: despite the warning, if loadHTML succeeds it will return true.
|
||||
$result = @$f->loadHTML('<htmlfragment>' . $value . '</htmlfragment>');
|
||||
$result = $f->loadHTML('<htmlfragment>' . $value . '</htmlfragment>');
|
||||
|
||||
if ($result) {
|
||||
$import = $f->getElementsByTagName('htmlfragment')->item(0);
|
||||
@@ -81,16 +93,11 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
$importedNode = $this->ownerDocument->importNode($child, true);
|
||||
$this->appendChild($importedNode);
|
||||
}
|
||||
} else {
|
||||
// oh well, we tried, we really did. :(
|
||||
// this element is now empty
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$trace = debug_backtrace();
|
||||
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
|
||||
}
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($previousError);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +109,7 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name === 'innerHTML') {
|
||||
if ('innerHTML' === $name) {
|
||||
$inner = '';
|
||||
|
||||
foreach ($this->childNodes as $child) {
|
||||
@@ -114,8 +121,6 @@ class JSLikeHTMLElement extends \DOMElement
|
||||
|
||||
$trace = debug_backtrace();
|
||||
trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
||||
+684
-683
File diff suppressed because it is too large
Load Diff
+37
-21
@@ -6,22 +6,11 @@ use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use Readability\Readability;
|
||||
|
||||
class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
class ReadabilityTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $logHandler;
|
||||
public $logger;
|
||||
|
||||
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
||||
{
|
||||
$readability = new Readability($html, $url, $parser, $useTidy);
|
||||
|
||||
$this->logHandler = new TestHandler();
|
||||
$this->logger = new Logger('test', array($this->logHandler));
|
||||
$readability->setLogger($this->logger);
|
||||
|
||||
return $readability;
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension tidy
|
||||
*/
|
||||
@@ -33,6 +22,15 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('DomDocument', $readability->dom);
|
||||
}
|
||||
|
||||
public function testConstructHtml5Parser()
|
||||
{
|
||||
$readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'html5lib');
|
||||
|
||||
$this->assertEquals('http://0.0.0.0', $readability->url);
|
||||
$this->assertInstanceOf('DomDocument', $readability->dom);
|
||||
$this->assertEquals('<html/>', $readability->original_html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension tidy
|
||||
*/
|
||||
@@ -326,13 +324,6 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertNotContains('This text is also an awesome text and you should know that', $readability->getContent()->innerHTML);
|
||||
}
|
||||
|
||||
// public function testConstructParser()
|
||||
// {
|
||||
// $readability = $this->getReadability('<html/>', 'http://0.0.0.0', 'html5lib');
|
||||
|
||||
// $this->assertEquals('http://0.0.0.0', $readability->url);
|
||||
// }
|
||||
|
||||
// dummy function to be used to the next test
|
||||
public function error2Exception($code, $string, $file, $line, $context)
|
||||
{
|
||||
@@ -343,7 +334,7 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
set_error_handler(array($this, 'error2Exception'), E_ALL | E_STRICT);
|
||||
set_error_handler([$this, 'error2Exception'], E_ALL | E_STRICT);
|
||||
|
||||
$data = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" prefix="og: http://ogp.me/ns#">
|
||||
@@ -443,7 +434,7 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPostFilters()
|
||||
{
|
||||
$readability = $this->getReadability('<div>' . str_repeat('<p>This <b>is</b> the awesome content :)</p>', 7) . '</div>', 'http://0.0.0.0');
|
||||
$readability = $this->getReadability('<div>' . str_repeat('<p>This <strong>is</strong> the awesome content :)</p>', 10) . '</div>', 'http://0.0.0.0');
|
||||
$readability->addPostFilter('!<strong[^>]*>(.*?)</strong>!is', '');
|
||||
|
||||
$res = $readability->init();
|
||||
@@ -477,4 +468,29 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
public function testKeepFootnotes()
|
||||
{
|
||||
// from https://www.schreibdichte.de/blog/feed-aggregator-und-spaeter-lesen-dienst-im-team
|
||||
$html = file_get_contents('tests/fixtures/keepFootnotes.html');
|
||||
|
||||
$readability = $this->getReadability($html, 'http://0.0.0.0');
|
||||
$readability->debug = true;
|
||||
$res = $readability->init();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertContains('<sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>', $readability->getContent()->innerHTML);
|
||||
$this->assertContains('<a href="#fnref1:fnfeed_2" rev="footnote"', $readability->getContent()->innerHTML);
|
||||
}
|
||||
|
||||
private function getReadability($html, $url = null, $parser = 'libxml', $useTidy = true)
|
||||
{
|
||||
$readability = new Readability($html, $url, $parser, $useTidy);
|
||||
|
||||
$this->logHandler = new TestHandler();
|
||||
$this->logger = new Logger('test', [$this->logHandler]);
|
||||
$readability->setLogger($this->logger);
|
||||
|
||||
return $readability;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
<article>
|
||||
|
||||
<h1>Feed-Aggregator und Später-Lesen-Dienst im Team</h1>
|
||||
|
||||
<figure>
|
||||
<img src="https://www.schreibdichte.de/content/1-blog/20170505-feed-aggregator-und-spaeter-lesen-dienst-im-team/workflow.png" alt="Feed-Aggregator und Später-Lesen-Dienst im Team" >
|
||||
</figure>
|
||||
|
||||
<time datetime="2017-05-05T18:40:00+00:00" >05.05.2017</time>
|
||||
|
||||
<p> <span class="tag">Tags:</span>
|
||||
<ul class="tag_list">
|
||||
<li><a href="https://www.schreibdichte.de/blog/tag:Software">Software</a></li>
|
||||
<li><a href="https://www.schreibdichte.de/blog/tag:Web">Web</a></li>
|
||||
<li><a href="https://www.schreibdichte.de/blog/tag:Tools">Tools</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
|
||||
<div class="content">
|
||||
<p>Dank einer Mitteilung <sup id="fnref1:fnfeed_1"><a href="#fn:fnfeed_1" class="footnote-ref">1</a></sup> im OSBN <sup id="fnref1:fnfeed_2"><a href="#fn:fnfeed_2" class="footnote-ref">2</a></sup>, bin ich auf den Feed-Aggregator Miniflux <sup id="fnref1:fnfeed_3"><a href="#fn:fnfeed_3" class="footnote-ref">3</a></sup> aufmerksam geworden. Ich hatte schon lange nach einer Alternative zu Fever <sup id="fnref1:fnfeed_4"><a href="#fn:fnfeed_4" class="footnote-ref">4</a></sup> gesucht, da der Anschein vorlag, dass die Entwicklung nicht mehr weiter ging. Was sich bestätigte.</p>
|
||||
<p>Miniflux ist prima, einfach gehalten und erledigt genau dass, was es machen soll. Zudem wird die Fever-API unterstützt, was bedeutet, dass ich weiterhin meine Feed-Reader nutzen kann, was den Dialog mit Miniflux auf dem Server betrifft. Das ist deshalb interessant, um den Lesestatus oder das Favorisieren von Feeds zentral auf dem Server zu berücksichtigen und nicht lokal. So habe ich sowohl auf dem lokalen Rechner, als auch auf allen mobilen Geräten den gleichen Stand und Status meiner abonnierten Feeds.</p>
|
||||
<p>Für das spätere Lesen von Webseiten, nutze ich seit längerem wallabag <sup id="fnref1:fnfeed_5"><a href="#fn:fnfeed_5" class="footnote-ref">5</a></sup>. Wallabag wird mit Inhalten über den Browser gefüttert. Die Webseiten werden bei der Konservierung von Werbung befreit, damit der reine Text vorliegt. Bilder dagegen nicht und gehen evtl. verloren, wenn es die Quelle mal nicht mehr geben sollte. Ich habe also zwei Orte, an denen Informationen gehalten werden. Miniflux zur Verwaltung von Feed-Nachrichten und Wallabag für Webseiten.</p>
|
||||
<p>Bei einem Update von Miniflux ist mit aufgefallen, dass es nun eine API für Wallabag gibt. Dabei werden alle gespeicherten Feeds von Miniflux an Wallabag übergeben. Eine prima Angelegenheit, da ich jetzt nur noch einen Topf habe, woraus ich meine gesammelten Informationen aus dem Netz entnehme.</p>
|
||||
<p>Miniflux als auch wallabag sind selbst gehostete Web-Applikationen, die auch über den Browser erreichbar sind. Native wallabag-Apps für iOS bzw. Android werden ebenfalls angeboten. Wallabag bietet zusätzlich einen Feed an, um die gesammelten Informationen per Feed-Reader zu lesen. Hierbei drängt sich evtl. die Idee auf, diesen Feed wieder in Miniflux zu abonnieren, da dann zentral alles aus verschiedenen Quellen vorliegt. Hier hätten wir allerdings eine gewisse Redundanz.</p>
|
||||
<p>Ich nutze seit ein paar Monaten Devonthink <sup id="fnref1:fnfeed_6"><a href="#fn:fnfeed_6" class="footnote-ref">6</a></sup> auf dem Mac. Das ist eine lokale Dokumentenverwaltung (DMS), die heute u.a. meine Bücher, Notizen und mein Mail-Archiv verwaltet und ihre Stärke u.a. in der Suche von Informationen hat. Devonthink versteht es auch Feeds zu abonnieren. Für mich war dies der Moment, nun den Feed von wallabag mit all meinen gespeicherten Informationen aus dem Web mit zu integrieren. Ich muss sagen, eine runde Lösung, denn jetzt habe ich für die lokale Suche und das Lesen eine zentrale Stelle.</p>
|
||||
<p>Die Grafik veranschaulicht das Teamplay zwischen Feed-Aggregator Miniflux und wallabag als Später-Lesen-Dienst, zusammengeführt in Devonthink. Ich kenne leider keine Dokumentenverwaltung für Linux oder Windows, die auch Feeds versteht. Wer etwas kennt, bitte melden. Wer zudem etwas zum Thema hören möchte, für dem ist ggf. die Podcast-Folge "Der eigene Workflow" <sup id="fnref1:fnfeed_7"><a href="#fn:fnfeed_7" class="footnote-ref">7</a></sup> interessant.</p>
|
||||
<div class="footnotes">
|
||||
<hr />
|
||||
<ol>
|
||||
<li id="fn:fnfeed_1">
|
||||
<p>Artikel zu Miniflux: <a href="Link"><a href="https://www.robbinaer.info/index.php?post/78">https://www.robbinaer.info/index.php?post/78</a></a> <a href="#fnref1:fnfeed_1" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_2">
|
||||
<p>OSBN: <a href="Link"><a href="https://osbn.de">https://osbn.de</a></a> <a href="#fnref1:fnfeed_2" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_3">
|
||||
<p>Miniflux: <a href="Link"><a href="https://miniflux.net">https://miniflux.net</a></a> <a href="#fnref1:fnfeed_3" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_4">
|
||||
<p>Fever: <a href="Link"><a href="https://feedafever.com">https://feedafever.com</a></a> <a href="#fnref1:fnfeed_4" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_5">
|
||||
<p>wallabag: <a href="Link"><a href="https://wallabag.org/de">https://wallabag.org/de</a></a> <a href="#fnref1:fnfeed_5" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_6">
|
||||
<p>Devonthink: <a href="Link"><a href="http://www.devontechnologies.com/de/produkte/devonthink/ueberblick.html">http://www.devontechnologies.com/de/produkte/devonthink/ueberblick.html</a></a> <a href="#fnref1:fnfeed_6" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
<li id="fn:fnfeed_7">
|
||||
<p>Podcast MacMittwoch: <a href="Link"><a href="https://itunes.apple.com/de/podcast/macmittwoch/id1212750085?mt=2ueberblick.html">https://itunes.apple.com/de/podcast/macmittwoch/id1212750085?mt=2ueberblick.html</a></a> <a href="#fnref1:fnfeed_7" rev="footnote" class="footnote-backref">↩</a></p>
|
||||
</li>
|
||||
</ol>
|
||||
</div></div>
|
||||
|
||||
</article>
|
||||
Reference in New Issue
Block a user