private function flatten($html) { $multi = MultiCurl::getInstance(); $hdls = array(); foreach (array('js', 'css') as $type) { $hdls[$type] = array(); ${$type} = ''; } /* scripts */ preg_match_all("/<script[^<>]+src=['\"]([^<>'\"]+)['\"][^<>]*>(.*)<\\/script>/i", $html, $scripts); $html = str_replace($scripts[0], '', $html); foreach ($scripts[1] as $url) { $hdl = $this->getCurlHandleForUrl($url); $multi->add($hdl); $hdls['js'][] = (string) $hdl; } /* stylesheets */ preg_match_all("/<link[^<>]+href=['\"]([^<>'\"]+.css)['\"][^<>]*[\\/]*>((<\\/link>)*)/i", $html, $links); // This could do better by checking for the rel attribute... $html = str_replace($links[0], '', $html); foreach ($links[1] as $url) { $hdl = $this->getCurlHandleForUrl($url); $multi->add($hdl); $hdls['css'][] = (string) $hdl; } /* append results */ foreach ($hdls as $key => $ids) { foreach ($ids as $id) { $res = $multi->get($id); if ($res) { ${$key} .= $res; } } } if ($js) { $html = '<script>' . $js . '</script>' . $html; } if ($css) { $html = '<style>' . $css . '</style>' . $html; } return $html; }
public function __construct($key) { $this->key = $key; $this->epiCurl = MultiCurl::getInstance(); }