diff options
author | Andres Rey <[email protected]> | 2018-12-24 10:23:42 -0300 |
---|---|---|
committer | GitHub <[email protected]> | 2018-12-24 10:23:42 -0300 |
commit | 09cb03f3f9ce9f8c4193f4240f68d460fe085a63 (patch) | |
tree | 1bbf7641fcb93cee80ba873bce90a4bc9e3229f5 /src | |
parent | 4327b730cb9a827a71dfa35a8eaf9062a1a481e7 (diff) | |
parent | baf3a68f1736238e8270ceec83822ee3a1f923a3 (diff) |
Merge pull request #75 from maludecks/sitename-feature
Add getSiteName feature
Diffstat (limited to 'src')
-rw-r--r-- | src/Readability.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/Readability.php b/src/Readability.php index 8c55e69..313b0ba 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -57,6 +57,13 @@ class Readability protected $author = null; /** + * Website name. + * + * @var string|null + */ + protected $siteName = null; + + /** * Direction of the text. * * @var string|null @@ -287,10 +294,10 @@ class Readability $values = []; // property is a space-separated list of values - $propertyPattern = '/\s*(dc|dcterm|og|twitter)\s*:\s*(author|creator|description|title|image)(?!:)\s*/i'; + $propertyPattern = '/\s*(dc|dcterm|og|twitter)\s*:\s*(author|creator|description|title|image|site_name)(?!:)\s*/i'; // name is a single value - $namePattern = '/^\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\s*[\.:]\s*)?(author|creator|description|title|image)(?!:)\s*$/i'; + $namePattern = '/^\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\s*[\.:]\s*)?(author|creator|description|title|image|site_name)(?!:)\s*$/i'; // Find description tags. foreach ($this->dom->getElementsByTagName('meta') as $meta) { @@ -332,7 +339,6 @@ class Readability * 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 */ - $key = current(array_intersect([ 'dc:title', 'dcterm:title', @@ -378,6 +384,12 @@ class Readability ], array_keys($values))); $this->setImage(isset($values[$key]) ? $values[$key] : null); + + $key = current(array_intersect([ + 'og:site_name' + ], array_keys($values))); + + $this->setSiteName(isset($values[$key]) ? $values[$key] : null); } /** @@ -1757,6 +1769,22 @@ class Readability } /** + * @return string|null + */ + public function getSiteName() + { + return $this->siteName; + } + + /** + * @param string $siteName + */ + protected function setSiteName($siteName) + { + $this->siteName = $siteName; + } + + /** * @return null|string */ public function getDirection() |