diff options
Diffstat (limited to 'src/Readability.php')
-rw-r--r-- | src/Readability.php | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/Readability.php b/src/Readability.php index 5d6c78e..506a478 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -327,14 +327,13 @@ class Readability // get title /* * This is a very convoluted way of extracting the first matching key of the $values array - * against a set of options. First you define the target keys, flip it, intersect them (discarding the - * target keys without a match), then reversing it (because array_intersect_key reverses the original array) and - * finally get the item. + * against a set of options. * * This could be easily replaced with an ugly set of isset($values['key']) or a bunch of ??s. * Will probably replace it with ??s after dropping support of PHP5.6 */ - $this->setTitle(current(array_reverse(array_intersect_key($values, array_flip([ + + $key = current(array_intersect_key([ 'dc:title', 'dcterm:title', 'og:title', @@ -342,21 +341,25 @@ class Readability 'weibo:webpage:title', 'title', 'twitter:title' - ]))))); + ], array_keys($values))); + + $this->setTitle(isset($values[$key]) ? $values[$key] : null); if (!$this->getTitle()) { $this->setTitle($this->getArticleTitle()); } // get author - $this->setAuthor(current(array_reverse(array_intersect_key($values, array_flip([ + $key = current(array_intersect_key([ 'dc:creator', 'dcterm:creator', 'author' - ]))))); + ], array_keys($values))); + + $this->setAuthor(isset($values[$key]) ? $values[$key] : null); // get description - $this->setExcerpt(current(array_reverse(array_intersect_key($values, array_flip([ + $key = current(array_intersect_key([ 'dc:description', 'dcterm:description', 'og:description', @@ -364,13 +367,17 @@ class Readability 'weibo:webpage:description', 'description', 'twitter:description' - ]))))); + ], array_keys($values))); + + $this->setExcerpt(isset($values[$key]) ? $values[$key] : null); // get main image - $this->setImage(current(array_reverse(array_intersect_key($values, array_flip([ + $key = current(array_intersect_key([ 'og:image', 'twitter:image' - ]))))); + ], array_keys($values))); + + $this->setImage(isset($values[$key]) ? $values[$key] : null); } /** |