$new_txt .= substr($html, 0, $pos) . $base_url_parts['scheme'] . '://' . $base_url_parts['host']; } else { $new_txt .= substr($html, 0, $pos) . $new_base_url; } } else { $new_txt .= substr($html, 0, $pos); } $html = substr($html, $pos); } $html = $new_txt . $html; } return $html; } UNL_Templates::$options['version'] = 4.0; $four_template = UNL_Templates::factory('Fixed'); foreach ($scanned_page->getRegions() as $region) { if ($region instanceof UNL_DWT_Region && $region->type == 'string') { if (in_array($region->name, array('maincontentarea', 'head', 'doctitle'))) { $region->value = removeRelativePaths($region->value, $_GET['u']); } if ($region->name === 'titlegraphic') { $region->value = str_replace(array('<h1>', '</h1>'), array('', ''), $region->value); } if ($region->name === 'contactinfo') { $region->value = preg_replace('/<h3>.*<\\/h3>/', '', $region->value); } $four_template->{$region->name} = $region->value; } } // echo the final HTML echo $four_template;
header('Access-Control-Allow-Headers: X-Requested-With'); if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { exit; } $parts = parse_url($_GET['u']); $clean_url = $parts['scheme'] . '://' . $parts['host'] . $parts['path']; if ($page = @file_get_contents($clean_url)) { $dom = new DOMDocument(); if (!@$dom->loadHTML($page)) { throwError('Bad html'); } $xpath = new DOMXpath($dom); $element = $xpath->query('//*[@id="navigation"]/ul[1]|//*[@id="navigation"]/*/ul[1]'); if ($element->length) { $navigation = simplexml_import_dom($element->item(0)); echo removeRelativePaths($navigation->asXML(), $clean_url); } } else { throwError(); } function removeRelativePaths($html, $base_url) { $needles = array('href="', 'src="', 'background="'); $new_base_url = $base_url; $base_url_parts = parse_url($base_url); if (substr($base_url, -1) != '/') { $path = pathinfo($base_url_parts['path']); $new_base_url = substr($new_base_url, 0, strlen($new_base_url) - strlen($path['basename'])); } foreach ($needles as $needle) { $new_txt = '';