web2printer 5";
include("configuration.php");
// start time
$timingStart = "";
// url to filename to process
$urlToPrint = "";
// file content
$content = "";
// host name
$scripthost = "";
// image processing flag
$clearImages = 0;
// array with hyperlinks
$links = Array();
// number of links
$linkCount = 0;
// array with images
$images = Array();
// number of images
$imageCount = 0;
// hyperlink processing flag
$resolveLink = 0;
// send a E-Mail
$email = 0;
// send a E-Mail stage
$stage = 1;
// array with hyperlinks
// array with parsed meta tags
$metaTags = Array();
// number of parsed meta tags
$metaCount = 0;
// copyright string parsed from meta tags
$copyright = "";
// meta tag processing flag
$preserveMetaTags = 0;
// stylsheet name string
// empty or not set: stylsheet informations supressed
// otherwise : stylsheet used for printing
$stylesheet = "";
// page title
$title = "";
// original page
$authentyPage = "";
$urlToPrint = "";
// check setting form web2printer_conf.inc, if not set choose defaults
if (!isset ($pageUrlHeader)) {
$pageUrlHeader = "This page URL:
";
}
if (!isset ($pageXRefURLHeader)) {
$pageXRefURLHeader = "Links:";
}
if (!isset ($pageXRefImages)) {
$pageXRefImages = "Images:";
}
if (!isset ($activeLinks)) {
$activeLinks = 0;
}
if (!isset ($footer)) {
$footer = 1;
}
if ($footer == 2 && !isset ($customFooter)) {
$customFooter = "please define a footer";
}
web2printer (); // initialze
prepare(); // format
($stage == 1)?display():sendMail(); // display or send as e-mail
exit();
function web2printer () {
global $timingStart;
global $clearImages;
global $scripthost;
global $resolveLink;
global $stage;
global $to;
global $from;
global $name;
global $comment;
global $preserveMetaTags;
global $stylesheet;
global $email;
// start from here :-)
$timingStart = explode(' ', microtime());
if (isset ($_GET["page"])) {
$page = $_GET["page"];
// $page = filter_var($_GET["page"], FILTER_SANITIZE_STRING);
}
if (isset ($_GET["img"])) {
$clearImages = $_GET["img"];
// $clearImages = filter_var($_GET["img"], FILTER_VALIDATE_INT);
}
if (isset ($_GET["lnk"])) {
$resolveLink = $_GET["lnk"];
// $resolveLink = filter_var($_GET["lnk"], FILTER_VALIDATE_INT);
}
if (isset ($_GET["tgs"])) {
$preserveMetaTags = $_GET["tgs"];
// $preserveMetaTags = filter_var($_GET["tgs"], FILTER_VALIDATE_INT);
}
if (isset ($_GET["style"])) {
$stylesheet = $_GET["style"];
// $stylesheet = filter_var($_GET["style"], FILTER_VALIDATE_STRING);
}
// Process the filename
// if we nether not have an referer nor an http get -> error
if (!isset ($page)) {
if (isset ($_SERVER["HTTP_REFERER"])) {
$page = $_SERVER["HTTP_REFERER"];
// $page = filter_var($_SERVER["HTTP_REFERER"], FILTER_VALIDATE_URL);
}
else {
if (isset ($_ENV["HTTP_REFERER"])) {
$page = $_ENV["HTTP_REFERER"];
// $page = filter_var($_ENV["HTTP_REFERER"], FILTER_VALIDATE_URL);
}
else {
$page = "";
}
}
//
if ($page != "") {
$page = parse_url($page, PHP_URL_PATH);
}
}
if ( strlen($page) == 0) {
$page = $GLOBALS['defaultPage'];
}
if ($page[0] != '/') {
$page="/".$page;
}
$GLOBALS['urlToPrint'] = apache_getenv('DOCUMENT_ROOT').$page;
}
function get_current () {
global $timingStart;
$stop_time = explode(' ', microtime());
$current = $stop_time[1] - $timingStart[1];
$current += $stop_time[0] - $timingStart[0];
return sprintf("%.6f seconds",$current);
}
// convert an local filename to uri
function makeUrl ($input) {
$retval = "";
$input = strtr ($input, "\\", "/");
$input = str_replace (apache_getenv('DOCUMENT_ROOT'), "", $input);
$tokens = parse_url ($input);
if (isset ($tokens["host"])) {
$retval = $input;
}
else {
$input = str_replace ( apache_getenv('SITE_NAME'), "", $input);
$retval = apache_getenv('SERVER_NAME').(($input{0} == '/')?"":"/").$input;
}
return $retval;
}
// prepare the file content
function prepare () {
global $clearImages;
global $content;
global $resolveLink;
global $preserveMetaTags;
global $stylesheet;
global $email;
global $stage;
global $title;
global $authentyPage;
global $copyright;
if (!is_readable ($GLOBALS['urlToPrint'])) {
die ("could not open:".$GLOBALS['urlToPrint']);
}
$plainFile = file_get_contents ($GLOBALS['urlToPrint']);
if (!isset($plainFile) || $plainFile == "") {
die ("could not read:".$$GLOBALS['urlToPrint']);
}
// preserve title tag
if (preg_match("/(