You are here

class MarkupGenerator in Heartbeat 8

Class MarkupGenerator.

@package Drupal\statusmessage

Hierarchy

Expanded class hierarchy of MarkupGenerator

3 files declare their use of MarkupGenerator
HeartbeatCommentForm.php in src/Form/HeartbeatCommentForm.php
StatusForm.php in modules/statusmessage/src/Form/StatusForm.php
StatusPreviewController.php in modules/statusmessage/src/Controller/StatusPreviewController.php
1 string reference to 'MarkupGenerator'
statusmessage.services.yml in modules/statusmessage/statusmessage.services.yml
modules/statusmessage/statusmessage.services.yml
1 service uses MarkupGenerator
markupgenerator in modules/statusmessage/statusmessage.services.yml
Drupal\statusmessage\MarkupGenerator

File

modules/statusmessage/src/MarkupGenerator.php, line 13

Namespace

Drupal\statusmessage
View source
class MarkupGenerator implements Parser {
  public $match;
  public $parsedMarkup;

  /**
   * GuzzleHttp\Client definition.
   *
   * @var \GuzzleHttp\Client
   */
  protected $httpClient;

  /**
   * Constructs a new MarkupGenerator object.
   */

  //  public function __construct(Client $http_client) {
  //    $this->httpClient = $http_client;
  //  }

  /**
   * @param $url
   * @return mixed
   */
  public function validateUrl($text) {
    preg_match_all('#\\bhttps?://[^,\\s()<>]+(?:\\([\\w\\d]+\\)|([^,[:punct:]\\s]|/))#', $text, $this->match);
    return $this->match;
  }

  /**
   * @param $url
   * @return mixed
   */
  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;
  }

  /**
   * @param $url
   * @return mixed
   */
  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();
  }

  /**
   * @return mixed
   */
  public function getImages() {
    return $this->parsedMarkup->images;
  }

  /**
   * @return mixed
   */
  public function getImage() {
    return $this->parsedMarkup->image;
  }

  /**
   * @return mixed
   */
  public function getTitle() {
    return $this->parsedMarkup->title;
  }

  /**
   * @return mixed
   */
  public function getDescription() {
    return $this->parsedMarkup->description;
  }

  /**
   * @return mixed
   */
  public function getTags() {
    return $this->parsedMarkup->tags;
  }

}

Members