1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

Merge branch 'create-content-meta-tags' of https://github.com/james-geiger/BookStack into james-geiger-create-content-meta-tags

This commit is contained in:
Dan Brown
2021-06-23 20:11:07 +01:00
7 changed files with 59 additions and 0 deletions

View File

@@ -367,4 +367,18 @@ class PageContent
$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
return $doc;
}
/**
* Retrieve first image in page content and return the source URL.
*/
public function fetchFirstImage()
{
$htmlContent = $this->page->html;
$dom = new \DomDocument();
$dom->loadHTML($htmlContent);
$images = $dom->getElementsByTagName('img');
return $images->length > 0 ? $images[0]->getAttribute('src') : null;
}
}