aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/PocheReadability.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-09-20 04:36:35 -0700
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-09-20 04:36:35 -0700
commit79026b73a804d1fe3715c3edf5bc2cfb1e56732c (patch)
tree225136afe844ad0b1c3fef443fcea86fe54384e5 /inc/poche/PocheReadability.php
parentc51be6b697da573cdcf0788eb8617130ce5517a4 (diff)
parent6a6c1c1172f3c6167d360a2322335ea91e94a3ff (diff)
downloadwallabag-1.0-beta5.tar.gz
wallabag-1.0-beta5.tar.zst
wallabag-1.0-beta5.zip
Merge pull request #226 from inthepoche/dev1.0-beta5
beta5
Diffstat (limited to 'inc/poche/PocheReadability.php')
-rw-r--r--inc/poche/PocheReadability.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/inc/poche/PocheReadability.php b/inc/poche/PocheReadability.php
new file mode 100644
index 00000000..48ae90d0
--- /dev/null
+++ b/inc/poche/PocheReadability.php
@@ -0,0 +1,46 @@
1<?php
2
3class PocheReadability extends Readability
4{
5 /**
6 * Get the article title as an H1.
7 *
8 * @return DOMElement
9 */
10 protected function getArticleTitle() {
11 $curTitle = '';
12 $origTitle = '';
13
14 try {
15 $curTitle = $origTitle = $this->getInnerText($this->dom->getElementsByTagName('title')->item(0));
16 } catch(Exception $e) {}
17
18 if (preg_match('/ [\|\-] /', $curTitle))
19 {
20 $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle);
21
22 if (count(explode(' ', $curTitle)) < 3) {
23 $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle);
24 }
25 }
26 else if(strlen($curTitle) > 150 || strlen($curTitle) < 15)
27 {
28 $hOnes = $this->dom->getElementsByTagName('h1');
29 if($hOnes->length == 1)
30 {
31 $curTitle = $this->getInnerText($hOnes->item(0));
32 }
33 }
34
35 $curTitle = trim($curTitle);
36
37 if (count(explode(' ', $curTitle)) <= 4) {
38 $curTitle = $origTitle;
39 }
40
41 $articleTitle = $this->dom->createElement('h1');
42 $articleTitle->innerHTML = $curTitle;
43
44 return $articleTitle;
45 }
46} \ No newline at end of file