private function getDateFromParsely() { $dt = null; // JSON-LD $nodes = $this->article()->getRawDoc()->find('script[type="application/ld+json"]'); /* @var $node Element */ foreach ($nodes as $node) { try { $json = json_decode($node->text()); if (isset($json->dateCreated)) { $dt = new \DateTime($json->dateCreated); break; } } catch (\Exception $e) { // Do nothing here in case the node has unrecognizable date information. } } if (!is_null($dt)) { return $dt; } // <meta> tags $nodes = $this->article()->getRawDoc()->find('meta[name="parsely-pub-date"]'); /* @var $node Element */ foreach ($nodes as $node) { try { if ($node->hasAttribute('content')) { $dt = new \DateTime($node->getAttribute('content')); break; } } catch (\Exception $e) { // Do nothing here in case the node has unrecognizable date information. } } if (!is_null($dt)) { return $dt; } // parsely-page $nodes = $this->article()->getRawDoc()->find('meta[name="parsely-page"]'); /* @var $node Element */ foreach ($nodes as $node) { try { if ($node->hasAttribute('content')) { $json = json_decode($node->getAttribute('content')); if (isset($json->pub_date)) { $dt = new \DateTime($json->pub_date); break; } } } catch (\Exception $e) { // Do nothing here in case the node has unrecognizable date information. } } return $dt; }