\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
}
// Fetches the given image and encodes it as a MHTM page.
// On the client-side the page is used as is and the
// base64 encoded data is extracted and put into an
// mxImageBundle for storage with the diagram.
else if (isset($_GET["url"]))
{
$url = $_GET["url"];
$img = file_get_contents($url);
// Enables caching of this response
header("Content-Type: text/plain");
header("Cache-Control: private");
header("Expires: Thu, 15 Apr 2030 20:00:00 GMT");
echo "\n";
}
// Returns the MHTML stored in the session.
else if (isset($_GET["PHPSESSID"]))
{
header("Content-Type: text/plain");
// Gets the image from the session and destroys the session (since we do
// not use session cookies there is no need to delete a cookie here).
session_start();
echo $_SESSION["image"];
session_destroy();
}
else
{
header("Content-Type: text/html");
$userAgent = strtoupper(getenv("HTTP_USER_AGENT"));
$dataUrl = strpos($userAgent, "MSIE 6") === false &&
strpos($userAgent, "MSIE 7") === false;
// In a real-world environment the following would be done for each entry
// of the image bundle in an XML file for a diagram.
$name = "myImage";
$data = "R0lGODlhEAAQAMIGAAAAAICAAICAgP//AOzp2O3r2////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAHACwAAAAAEAAQAAADTXi63AowynnAMDfjPUDlnAAJhmeBFxAEloliKltWmiYCQvfVr6lBPB1ggxN1hilaSSASFQpIV5HJBDyHpqK2ejVRm2AAgZCdmCGO9CIBADs";
$mhtml = ($dataUrl) ? "" : "\n".mhtml($name, $data);
$bundle = "bundle.putImage('myImage', 'data:image/png,$data=', 'mhtml:' + window.location.href + '!$name');";
// Replaces the placeholders in the template with the data from above.
// Note: In a production environment you should use a template engine.
$page = file_get_contents("embedimage.html");
$page = str_replace("%mhtml%", $mhtml, $page);
$page = str_replace("%dataUrl%", ($dataUrl) ? "true" : "false", $page);
$page = str_replace("%bundle%", $bundle, $page);
echo $page;
}
// Flushes the compression buffers
if ($compress)
{
ob_end_flush();
ob_end_flush();
}
?>