Goose\Modules\Extractors\PublishDateExtractor::getDateFromSchemaOrg PHP Метод

getDateFromSchemaOrg() приватный Метод

Checks HTML tags (e.g. ,
См. также: https://schema.org/datePublished
private getDateFromSchemaOrg ( ) : DateTime | null
Результат DateTime | null
    private function getDateFromSchemaOrg()
    {
        $dt = null;
        // Check for HTML tags (<meta>, <time>, etc.)
        $nodes = $this->article()->getRawDoc()->find('*[itemprop="datePublished"]');
        /* @var $node Element */
        foreach ($nodes as $node) {
            try {
                if ($node->hasAttribute('datetime')) {
                    $dt = new \DateTime($node->getAttribute('datetime'));
                    break;
                }
                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;
        }
        // Check for 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->datePublished)) {
                    $dt = new \DateTime($json->datePublished);
                    break;
                }
            } catch (\Exception $e) {
                // Do nothing here in case the node has unrecognizable date information.
            }
        }
        return $dt;
    }