function redirect($target) { $target = make_absolute($target); if (session_id()) { session_write_close(); } do_commits(); if (ob_list_handlers()) { ob_clean(); } header("Location: {$target}"); exit; }
function get_links($targetUrl, $depth) { global $urls, $linkFilter, $frameDepth, $actualFrameDepth; if (!$targetUrl) { return; } if ($frameDepth - $depth > $actualFrameDepth) { $actualFrameDepth = $frameDepth - $depth; } $html = file_get_contents($targetUrl); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $bases = $xpath->evaluate("/html/head//base"); if ($bases->length > 0) { $baseItem = $bases->item($bases->length - 1); $base = $baseItem->getAttribute('href'); } else { $base = $targetUrl; } if ($depth > 0) { $frames = $xpath->evaluate("/html/body//iframe"); for ($i = 0; $i < $frames->length; $i++) { $frame = $frames->item($i); $url = make_absolute($frame->getAttribute('src'), $base); if ($url != $targetUrl) { get_links($url, $depth - 1); } } $frames = $xpath->evaluate("/html/body//frame"); for ($i = 0; $i < $frames->length; $i++) { $frame = $frames->item($i); $url = make_absolute($frame->getAttribute('src'), $base); if ($url != $targetUrl) { get_links($url, $depth - 1); } } } $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $absolute = make_absolute($url, $base); if (preg_match("@" . $linkFilter . "@i", parse_url($absolute, PHP_URL_PATH))) { array_push($urls, $absolute); } } }
continue; // skip this and move to next item } //TODO: get text sample for language detection $html = $options->error_message; // keep the original item description $html .= $item->get_description(); } else { $readability->clean($content_block, 'select'); if ($options->rewrite_relative_urls) { $base_url = get_base_url($readability->dom); if (!$base_url) { $base_url = $effective_url; } // rewrite URLs make_absolute($base_url, $content_block); } // footnotes if ($links == 'footnotes' && strpos($effective_url, 'wikipedia.org') === false) { $readability->addFootnotes($content_block); } // normalise $content_block->normalize(); // remove empty text nodes foreach ($content_block->childNodes as $_n) { if ($_n->nodeType === XML_TEXT_NODE && trim($_n->textContent) == '') { $content_block->removeChild($_n); } } // remove nesting: <div><div><div><p>test</p></div></div></div> = <p>test</p> while ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) {
function redirect($target) { $target = make_absolute($target); if ($debug || $stop_redirect) { global $login_id, $anon_ok; echo "debug or stop redirect... {$login_id} {$anon_ok} "; var_dump($target); var_dump($_SERVER); $s = trim(@$_SESSION['flash']); if ($s != "") { $body .= "<p>pending flash: \n"; $body .= h($s); $body .= "</p>\n"; } $body .= "<p>"; $body .= mklink("(dbg=1: click here to finish redirect)", $target); $body .= "</p>\n"; foobar(); pfinish(); } session_write_close(); do_commits(); ob_clean(); header("Location: {$target}"); exit; }