Nice formatted Print Page

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Nordlicht
Posts: 160
Joined: Wed 12. Apr 2006, 08:16
Location: Germany, near Hamburg
Contact:

Post by Nordlicht »

777 für print.php hat auch nicht geholfen.
Funktioniert nicht im IE 6 und Opera 9.0x und FF 1.5x
godmd

Post by godmd »

(1) $HTTP_REFERER is empty. You may be able to fill it with $_SERVER['HTTP_REFERER']


(2) You have apache authentication and, say, an .htaccess file in the directory,
for example. Because your site is requesting authentication, you will not be able
to proceed through the phprint.php script.



(3) Look in your php.ini file and see that allow_url_fopen = On

(4) Run "ulimit -a" in a terminal window. Make sure that "open files" is not set to 0 (zero).

Hi you all!

I tried this promising print function but I get this error message:

Code: Select all

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /mnt/kw1/03/398/00000015/htdocs/phpwcms/print.php on line 94
a) rewrite is disabled

b) print.php is in root directory of phpwcms

c) phpinfo says allow_url_fopen = On

d) Replaced all 4 "$HTTP_REFERER" in print.php with "$_SERVER['HTTP_REFERER']" -- but I'm not sure if that was the right thing to do. Is that why I get this error message?

Where exactly do I have to replace the referer? Can anybody help, please?

VG,
Anka
godmd

Post by godmd »

Wow, I just managed to get a wonderful print page thanks to the trial-and-error-method ...

But I still don't know the correct syntax for the http_referer-replacement in this line:

echo "The URL for this article is:<br><a href='HTTP_REFERER'> HTTP_REFERER</a><br><br>";

At the moment the output looks like this:

The URL for this article is:
'HTTP_REFERER'


... which is not quite what I intended ...
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Post by Goran »

Try following code, work fine for me...but take into consideration what Oliver say about this code/script: "..this peace of code is totally nonsense! Often Referrer does not work! And there is a built-in print function."

Code: Select all

<?php
//	START settings
$sitename="My Site";
$logoimage="img/print_logo.gif";
$stripImages = "no";
$homepage="http://localhost";
//	END settings
echo "<html><head>";
echo "<title>$sitename | Print version</title>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
echo "<style>body{font:12px Verdana,Arial,Sans-serif;}div{padding:10px;}.printDiv{border:1px solid #ccc;width:550px;}.printBottom{text-align:center;font-size:11px;border-top:1px solid #ccc;width:90%;}</style>";
echo "</head><body> ";
if (is_null($_SERVER['HTTP_REFERER'])){ print "<h1>Oooops...you can't access PRINT PAGE directly!</h1>[<a href='$homepage'>Home Page</a>]";}
else {
	$startingpoint = "<!-- startprint -->";
	$endingpoint = "<!-- stopprint -->";
	$read = fopen($_SERVER['HTTP_REFERER'], "rb");
	while(!feof($read)){$value .= fread($read, 4096);}
	fclose($read);
	$article = $_SERVER['HTTP_REFERER'];
	$start= strpos($value, "$startingpoint");
	$finish= strpos($value, "$endingpoint");
	$length= $finish-$start;
	$value=substr($value, $start, $length);
	function i_clear($variable)
	{return(eregi_replace("<img src=[^>]*>", "", $variable));}
	function i_clearf($variable)
	{return(eregi_replace("<font[^>]*>", "", $variable));}
	$PHPrint = ("$value");
	if ($stripImages == "yes") {
	$PHPrint = i_clear("$PHPrint");}
	$PHPrint = i_clearf("$PHPrint");
	$PHPrint = str_replace( "</font>", "", $PHPrint );
	echo "<div class='printDiv'><p><img src=$logoimage alt='$sitename' />";
	echo "<div>$PHPrint</div>";
	echo "<div class='printBottom'>";
	echo "This article comes from <strong>$sitename</strong> site.";
	echo "<p>The URL for this article is: <a href='$article'> $article</a></p>";
	echo "<form><input type='button' value='Print this page' onclick='window.print()' /></form>";
	echo "</div></div>";
	echo "</body></html>";
	flush ();
}
?>
godmd

Post by godmd »

Hi Goran,

thanks for your help. I did use this script and I just had difficulties with th eone line showing the page-url. I did get help earlier in another thread but I'll post the line in question here in case anybody is in search for it:

Code: Select all

echo "Der direkte Link zu dieser Seite lautet:<br><a href='".$_SERVER['HTTP_REFERER']."'>". $_SERVER['HTTP_REFERER']."</a><br><br>";
Goran wrote:...but take into consideration what Oliver say about this code/script: "..this peace of code is totally nonsense! Often Referrer does not work! And there is a built-in print function."
:? Yes I read Oliver's remark but he didn't say what to do if you have a client wanting a layout that doesn't fit into the predefined wcms-template so that you have to put the whole layout into the main area (Hauptbereich), did he? Anyway, I tried every possibilty I could find, but only this script is actually working.

Anka
jscholtysik

Post by jscholtysik »

Hi Goran,


I tried also to adjust the referer variable to $_SERVER['HTTP_REFERER'] and now the print.php takes 2 minutes to execute and then I get these errors:
Warning: fopen(http://www.scholtysik.net/) [function.fopen]: failed to open stream: Connection timed out in /www/XXXXXXXX/domain/htdocs/print.php on line 65

Warning: feof(): supplied argument is not a valid stream resource in /www/XXXXXXXX/domain/htdocs/print.php on line 67

Warning: fread(): supplied argument is not a valid stream resource in /www/XXXXXXXX/domain/htdocs/print.php on line 68
These are the line 65-68:

Code: Select all

$read = fopen($_SERVER['HTTP_REFERER'], "rb"); 
$value = ""; 
while(!feof($read)){ 
Is it possible that this is a problem with PHP 5 and fopen/fread?

Unfortunately I can't show you my print.php, because the forum editor always tries to execute the code... :-(


Joachim
Post Reply