base_url), $matches[0]); } // this.params.logoImg&&(e="background-image: url("+this.params.logoImg+")") private function css_import($matches){ return str_replace($matches[2], proxify_url($matches[2], $this->base_url), $matches[0]); } // replace src= and href= private function html_attr($matches){ // could be empty? $url = trim($matches[2]); if(stripos($url, 'data:') === 0 || stripos($url, 'magnet:') === 0 ){ return $matches[0]; } return str_replace($url, proxify_url($url, $this->base_url), $matches[0]); } private function form_action($matches){ // sometimes form action is empty - which means a postback to the current page // $matches[1] holds single or double quote - whichever was used by webmaster // $matches[2] holds form submit URL - can be empty which in that case should be replaced with current URL if(!$matches[2]){ $matches[2] = $this->base_url; } $new_action = proxify_url($matches[2], $this->base_url); // what is form method? $form_post = preg_match('@method=(["\'])post\1@i', $matches[0]) == 1; // take entire form string - find real url and replace it with proxified url $result = str_replace($matches[2], $new_action, $matches[0]); // must be converted to POST otherwise GET form would just start appending name=value pairs to your proxy url if(!$form_post){ // may throw Duplicate Attribute warning but only first method matters $result = str_replace("post->has('convertGET')){ // we don't need this parameter anymore $request->post->remove('convertGET'); // replace all GET parameters with POST data $request->get->replace($request->post->all()); // remove POST data $request->post->clear(); // This is now a GET request $request->setMethod('GET'); $request->prepare(); } } private function meta_refresh($matches){ $url = $matches[2]; return str_replace($url, proxify_url($url, $this->base_url), $matches[0]); } // , <base>, <link>, <style>, <meta>, <script>, <noscript> private function proxify_head($str){ // let's replace page titles with something custom if(Config::get('replace_title')){ $str = preg_replace('/<title[^>]*>(.*?)<\/title>/is', '<title>'.Config::get('replace_title').'', $str); } // base - update base_url contained in href - remove tag entirely //$str = preg_replace_callback('/]*href= // link - replace href with proxified // link rel="shortcut icon" - replace or remove // meta - only interested in http-equiv - replace url refresh // $str = preg_replace_callback('/content=(["\'])\d+\s*;\s*url=(.*?)\1/is', array($this, 'meta_refresh'), $str); return $str; } // The background attribute is not supported in HTML5. Use CSS instead. private function proxify_css($str){ // The HTML5 standard does not require quotes around attribute values. // if {1} is not there then youtube breaks for some reason $str = preg_replace_callback('@[^a-z]{1}url\s*\((?:\'|"|)(.*?)(?:\'|"|)\)@im', array($this, 'css_url'), $str); // https://developer.mozilla.org/en-US/docs/Web/CSS/@import // TODO: what about @import directives that are outside