You are here

public function HtmlAssetInliner::getCompletePage in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8 src/Context/HtmlAssetInliner.php \Drupal\tmgmt_smartling\Context\HtmlAssetInliner::getCompletePage()
  2. 8.2 src/Context/HtmlAssetInliner.php \Drupal\tmgmt_smartling\Context\HtmlAssetInliner::getCompletePage()
  3. 8.3 src/Context/HtmlAssetInliner.php \Drupal\tmgmt_smartling\Context\HtmlAssetInliner::getCompletePage()

Gets complete page data and returns generated string

Parameters

string $url - url to retrieve:

string $cookie - cookie for authorization:

bool $keepjs - whether to keep javascript:

bool $compress - whether to remove extra whitespaces:

array $settings:

bool $debug:

Return value

string|void

Throws

\Exception - throws an exception if provided url isn't in proper format

File

src/Context/HtmlAssetInliner.php, line 60

Class

HtmlAssetInliner

Namespace

Drupal\tmgmt_smartling\Context

Code

public function getCompletePage($url, $cookie = '', $keepjs = TRUE, $compress = FALSE, array $settings = [], $debug = FALSE) {

  # validate the URL
  if (!filter_var($url, FILTER_VALIDATE_URL)) {
    throw new \Exception('Invalid URL. Make sure to specify http(s) part.');
  }
  if (empty($url)) {
    if ($debug) {
      Drupal::logger('tmgmt_smartling_context_debug')
        ->info('Url is missing.');
    }
    return self::$uriMissingError;
  }
  if (!$cookie) {
    if ($debug) {
      Drupal::logger('tmgmt_smartling_context_debug')
        ->info('Auth error.');
    }
    return self::$authError;
  }
  $this->url = $url;
  $this->cookie = $cookie;
  $this->html = $this
    ->getUrlContents($this->url, 0, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10', $settings, $debug);
  if (strlen($this->html) <= 300) {
    if ($debug) {
      Drupal::logger('tmgmt_smartling_context_debug')
        ->info('Response is too small.');
    }
    return '';
  }
  return $compress ? $this
    ->compress($this->html) : $this->html;
}