You are here

private function HtmlAssetInliner::embedLocalCss in TMGMT Translator Smartling 8

1 call to HtmlAssetInliner::embedLocalCss()
HtmlAssetInliner::getCompletePage in src/Context/HtmlAssetInliner.php
Gets complete page data and returns generated string

File

src/Context/HtmlAssetInliner.php, line 416

Class

HtmlAssetInliner

Namespace

Drupal\tmgmt_smartling\Context

Code

private function embedLocalCss() {

  //<link rel="stylesheet" href="/sites/default/files/css/css_DImuuvc9S8V88m4n2WP6xWYIYqktcP21urgDq7ksjK8.css?odb4fo" media="all" />

  //<link rel="stylesheet" href="/sites/default/files/css/css_Va4zLdYXDM0x79wYfYIi_RSorpNS_xtrTcNUqq0psQA.css?odb4fo" media="screen" />
  $css = [];
  preg_match_all('/<link rel="stylesheet" href="([^"]+)\\?.*" media="([a-zA-Z0-9]*)" \\/>/iU', $this->html, $css);
  foreach ($css[1] as $id => $filename) {
    if (strpos($filename, '?') !== FALSE) {
      $fil_splt = explode('?', $filename);
      $filename = reset($fil_splt);
    }
    $path = DRUPAL_ROOT . $filename;
    if (!file_exists($path)) {
      continue;
    }
    $file_content = file_get_contents($path);
    $file_content = $this
      ->embedCssImages($file_content, $path);
    $this->html = str_replace($css[0][$id], "<style media='{$css[2][$id]}'>\n {$file_content} \n</style>", $this->html);
  }

  //@import url("/core/assets/vendor/normalize-css/normalize.css?odb4fo");

  //@import url("/core/themes/stable/css/toolbar/toolbar.icons.theme.css?odb4fo");
  $css = [];
  preg_match_all('/@import url\\("([^"]+)"\\);/iU', $this->html, $css);
  foreach ($css[1] as $id => $filename) {
    if (strpos($filename, '?') !== FALSE) {
      $fil_splt = explode('?', $filename);
      $filename = reset($fil_splt);
    }
    $path = DRUPAL_ROOT . $filename;
    if (!file_exists($path)) {
      continue;
    }
    $file_content = file_get_contents($path);
    $file_content = $this
      ->embedCssImages($file_content, $path);
    $this->html = str_replace($css[0][$id], "\n\n {$file_content} \n\n", $this->html);
  }
}