MarkupGenerator.php in Heartbeat 8
File
modules/statusmessage/src/MarkupGenerator.php
View source
<?php
namespace Drupal\statusmessage;
use GuzzleHttp\Client;
use Embed\Embed;
use Drupal\statusmessage\TemplateCreator;
class MarkupGenerator implements Parser {
public $match;
public $parsedMarkup;
protected $httpClient;
public function validateUrl($text) {
preg_match_all('#\\bhttps?://[^,\\s()<>]+(?:\\([\\w\\d]+\\)|([^,[:punct:]\\s]|/))#', $text, $this->match);
return $this->match;
}
public function parseMarkup($url) {
$url = strpos($url, 'http') ? 'http://' . $url : $url;
$url = !is_array($url) ? $url : array_values($url)[0];
$this->parsedMarkup = Embed::create($url);
return true;
}
public function generatePreview() {
if (!$this->parsedMarkup) {
return null;
}
$templateCreator = new TemplateCreator();
$templateCreator
->generateTitle($this->parsedMarkup->title);
$templateCreator
->generateDescription($this->parsedMarkup->description);
$templateCreator
->generateImage($this->parsedMarkup->image);
return $templateCreator
->getPreview();
}
public function getImages() {
return $this->parsedMarkup->images;
}
public function getImage() {
return $this->parsedMarkup->image;
}
public function getTitle() {
return $this->parsedMarkup->title;
}
public function getDescription() {
return $this->parsedMarkup->description;
}
public function getTags() {
return $this->parsedMarkup->tags;
}
}