protected function get_data($url) { if (is_file($this->config['BasePath'] . Url::normalizeUrl($url))) { $url = $this->config['BasePath'] . Url::normalizeUrl($url); try { $data = File::get_content($url); } catch (Exception $ex) { } } else { if (is_file($this->config['BasePath'] . $url)) { $data = File::get_content($this->config['BasePath'] . $url); } else { $data = File::get_content($url); } } return $data; }
public function removeImports($data, $cssUrl) { $sBaseUrl = dirname($cssUrl) . '/'; $config = $this->config; $config['css_url'] = $cssUrl; $self = $this; return preg_replace_callback('/@import url\\(([^)]+)\\)(;?)/', function ($aMatches) use($sBaseUrl, $config, $self) { $url = Url::normalizeUrl(str_replace(array('"', '\''), '', trim($aMatches[1]))); return $self::removeImports($self->fixUrl(File::get_content($url), $url), $url); }, $data); }
/** * @param HtmlHeaders $htmlHeaders */ private function organizeJS($htmlHeaders) { $htmlContent = $this->DOMHtml->getContent(); $regex = '/<script((?:.)*?)>(.*?)<\\/script>/smix'; $config = $this->config; $self = $this; $content = preg_replace_callback($regex, function ($script) use($htmlHeaders, $config, $self) { $regex_tribb = '/(\\S+)=["\']((?:.(?!["\']\\s+(?:\\S+)=|[>"\']))+.)["\']/'; preg_match_all($regex_tribb, $script[1], $matches); if (isset($matches[1]) && isset($matches[2])) { foreach ($matches[1] as $k => $key) { if (trim($key) == 'src') { $v = File::url_decode(trim($matches[2][$k])); } else { $v = trim($matches[2][$k]); } $attributes[trim($key)] = $v; } } if ($attributes['type'] == 'text/javascript' || !$attributes['type']) { if ($attributes['src']) { $htmlHeaders->addJs($attributes); return; } elseif ($config['JavascriptIntegrateInline'] && $config['JavascriptIntegrate']) { $attributes['value'] = isset($script[2]) ? $script[2] : ''; if (!$self->jsAwaysInline($attributes['value'])) { $self->addJsInline($htmlHeaders, $attributes); return; } else { return $script[0]; /** * @todo Adjust to work fine with document.write */ /* $id = md5($script[0]); $attributes['value'] = str_replace('document.write(', 'replace_text("' . $id . '",', $attributes['value']); $self->addJsInline($htmlHeaders, $attributes); $replace = '<script type="text/javascript" id="' . $id . '">'; $replace .= 'var elem = document.getElementById("' . $id . '");'; $replace .= 'elem.addEventListener("' . $id . '", function (event) {'; $replace .= 'document.write(event.detail);'; $replace .= '});'; $replace .= '</script>'; return $replace; */ } } else { return $script[0]; } } else { return $script[0]; } }, $htmlContent); $this->DOMHtml->setContent($content ?: $htmlContent); }