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.
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Nice formatted Print Page

Post by Goran »

Hi guys,
I've developed/improved a hack to allow your own print solution (with the idea of trip).

Demo: http://www.7dana.com (sorry..very little print icon :roll: )

NOTE:
You can't use this hack with rewrite functionality enabled in phpwcms ...sorry.
This script is an modification of PHPrint 2.1 (Copyright by MikeNew.Net)!

INSTALLATION:
-----------------
1: Save this code to print.php in the root of the site.

Code: Select all

 <?php

/*PHPrint - This file is print.php 
Make any Page Printer Friendly! Version 2.1 - With error handling
Copyright by MikeNew.Net, Notice must stay intact
Any improvements to this script are welcome: www.mikenew.net/contact.asp 
************
Legal: MikeNew.Net is not responsible for any damages caused
by use of this script. (Highly unlikely. Hasn't yet.)
This script will make your pages printer friendly. 
Optionally, it will strip images as well. (Instructions for that below)


***********************************************************
 This script is an modification of PHPrint 2.1 (Copyright by MikeNew.Net)
 by Goran Zajec from www.7dana.com , maded to use with PHPWCMS CMS.
***********************************************************

1.  Save this script in the root of the site for simplicity.
2.  Place <!-- startprint --> somewhere in your PHPWCMS template
    where you consider it to be the start of printer friendly content, 
    and <!-- stopprint --> goes at the end of that same content.
3.  You place a link to print.php anywhere on the PHPWCMS template
    (preferably outside the printed content, like this: 
    <a href="print.php">Print this page</a> or however you like, 
    just as long as you link to this script. */


//The name of your site, without trailing slash?
$site_NAME="My Site"; 

//Path to print_logo image, without trailing slash?
$LOGO_image="img/print_logo.gif"; 

//Do you want to strip images from the printable output?
// If no, change to "no". Otherwise, images are stripped by default.
$stripImages = "no"; 

//What's the base domain name of your site, without trailing slash? 
// Just the domain itself, so we can fix any relative image and link problems.
$baseURL="http://www.yoursite.com"; 


// That's it! No need to go below here. Upload it and test.
// --------------------------------------------------------
// --------------------------------------------------------




echo "<html><head>";
echo "<title>$site_NAME | Print version</title>";
echo "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
echo "<style><!--  body { font-family: Verdana,Arial,Sans-serif; margin: 0px; font-size: 12px; } table { font-size: 12px; background-color: #FFFFFF; } hr { height: 1px; color: #D1D1D1; } .print_table { border: 1px solid #cccccc; padding: 8px; margin: 12px; } .print_bottom { text-align: center; padding: 15px; font-size: 11px; border-top: 1px solid #cccccc;} //--></style>";
echo "</head><body> ";

// Let's turn off direct access without referer page.
if (is_null($HTTP_REFERER)) { 
print "<br><br><p align='center'><strong>Oooops...you can't access PRINT PAGE directly....without referer page!</strong><br><BR>[<a href='$baseURL'> Home Page</a>]</p> \n"; 
} 
else { 

$startingpoint = "<!-- startprint -->"; 
$endingpoint = "<!-- stopprint -->"; 
$read = fopen($HTTP_REFERER, "rb"); 
$value = ""; 
while(!feof($read)){ 
$value .= fread($read, 4096); 
} 
fclose($read); 
$start= strpos($value, "$startingpoint"); 
$finish= strpos($value, "$endingpoint"); 
$length= $finish-$start; 
$value=substr($value, $start, $length); 
function i_denude($variable) 
{ 
return(eregi_replace("<img src=[^>]*>", "", $variable)); 
} 
function i_denudef($variable) 
{ 
return(eregi_replace("<font[^>]*>", "", $variable)); 
} 
$PHPrint = ("$value"); 
if ($stripImages == "yes") { 
$PHPrint = i_denude("$PHPrint"); 
} 
$PHPrint = i_denudef("$PHPrint"); 
$PHPrint = str_replace( "</font>", "", $PHPrint ); 
echo "<table class=print_table width=580 border=0 cellpadding=0 cellspacing=0><tr><td valign=top>"; 
echo "<img src=$LOGO_image alt='$site_NAME' hspace=0 vspace=0 border=0><hr>";
echo $PHPrint; 
echo "<table class=print_bottom width=90% align=center border=0 cellpadding=0 cellspacing=0><tr><td valign=top>";
echo "This article comes from <strong>$site_NAME</strong> site ($baseURL).<br><br>";  
echo "The URL for this article is:<br><a href='$HTTP_REFERER'> $HTTP_REFERER</a><br><br>"; 
echo "<form><input type='button' value='Print this page' onClick='window.print()'></form>";
echo "</td></tr></table>";
echo "</td></tr></table>"; 
echo "<br></body></html>";
flush (); 
} 
?>  
2. Place

Code: Select all

<!-- startprint -->
somewhere in your template where you consider it to be the start of printer friendly content,
and

Code: Select all

<!-- stopprint -->
goes at the end of that same content.


3. Place a link to print.php anywhere on the template (preferably outside the printed content, like this:

Code: Select all

<a href="print.php">Print this page</a> 
or however you like.


4. Open print.php and set up additional parameter(site name, path to print_logo image, ...) .


Thats all, enjoy in the new Print Page look. :)
Last edited by Goran on Sun 26. Sep 2004, 19:33, edited 2 times in total.
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

nice thing goran,

i made it exactly, but i still get the refer page and the oops can't print.

why?

my installation ist not in root of the server, it's like:

"www.mydomain.com/cms/"

How to fix it?

may be can can give my a hint.

I set up in template main section:

Code: Select all

<div class="scroll"><!-- startprint -->{CONTENT}<!-- stopprint --></div>
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Post by Goran »

Cyrano, just checked with phpwcms installation in subfolder and also in subdomain and works perfect...please check your installation again..


Hm...I didn't check with rewrite functionality enabled in phpwcms.. :idea:

I will try right now.
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Post by Goran »

Yes, you can't use this hack with rewrite functionality enabled in phpwcms is ...sorry.. :cry:

Just checked on MikeNew.Net FAQ:
Regarding the error" "There is no direct access to this page. Please click back.... blah blah blah",
there are 4 more additional reasons for unix/linux platforms:

(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).
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Thank you for reply.

I set my rewrite off , but still get the same error.
deleted also the cache...

i get:"Oooops...you can't access PRINT PAGE directly....without referer page!"

i use also a function where i need rewrite on and this works now not as well as before, so the changing are done and recognized.

i put a .htaccess file in the root of phpwcms folder, but still the same.

hmm..?

i set may defaults in print.php to:

name of site "my site"

image print: "picture/print.jpg"

images "no"

and baseURL: "http://www.mydomain.com"

anything wrong?

thank you for further advice.

i have seen your site and the really well working print page - i tried nother way before but will be not well satisfied... so i would like to implement the print hack...
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Post by Goran »

Cyrano, for some reason (unknown for me :cry: )your $HTTP_REFERER is empty...try this....replace $HTTP_REFERER with $_SERVER['HTTP_REFERER'] .

I tryed today on 3 different phpwcms installation and one oscommerce shop on windows server without any problem..
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Hi Goran,

that was it - thank you very much.

i got it working, but i think now it depends on my formatting pages it works not quite as well as your site.

i have often pages with text in tables, so that they will break down with print layout.

i have to experiment a bit.

thank you for your hints.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
jkn
Posts: 58
Joined: Mon 23. Aug 2004, 20:00

Post by jkn »

mmmh! thx for sharing this skript!!! It’s really nice for anyone who use their own templates in main-block!

:)

jkn
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Post by Goran »

cyrano, move css to separate file and experiment a bit;
EXAMPLE:

Code: Select all

echo "<link rel='stylesheet' href='print.css' type='text/css'>";


jkn, thanks... main-block is not important in print formating..just replace rep.-tag"{CONTENT}" with "<!-- startprint --> {CONTENT} <!-- stopprint -->".
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Hi Goran,

yes I'll try a bit - I will do.

My opinion is thta it has to do with the kind I used my text in tables, they are set to a width of 400 px, my main section has a width of 600 px, so i think, the print.php cannot sort this correct.

I'll have a new experiment.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
Gnolen
Posts: 158
Joined: Thu 11. Mar 2004, 11:34

Post by Gnolen »

Is there possible to show the alt-tag when it strips the images? Anyone know how to do this?

Greetings from Gnolen
User avatar
Oliver Georgi
Site Admin
Posts: 9919
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

why that complex? use some lines of code and CSS style print.css and everything works the same. And check file printwindow.php in code snippets folder of phpwcms - or check this:

Code: Select all

[PHP]
if($GLOBALS['aktion'][2] !=0) {
	echo '<script language="JavaScript" type="text/javascript">';
	echo "\n<!--\n";
	echo 'window.print();';
	echo "\n//-->\n";
	echo '</script>';
}
[/PHP]
You can place any part of code/html there if neccessary.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
osinski
Posts: 20
Joined: Tue 15. Feb 2005, 03:54

Very nice work but small problems!!!

Post by osinski »

Very nice work but small problems!!!

After trying the script on my apache server running on my desktop,
everything worked fine but after moving the file to my online server
I had the same problem as cyrano on Sep 26, 2004 15:18.

("Oooops...you can't access PRINT PAGE directly....without referer page!")

Then I replaced $HTTP_REFERER with $_SERVER['HTTP_REFERER'] and it finally worked except the referer page :(

Has anybody got any idea what might be wrong?
d-lexy
Posts: 76
Joined: Fri 22. Oct 2004, 22:59
Location: Toronto, Canada / Tallinn, Estonia

Post by d-lexy »

Tried it, it worked perfectly, I love it!
Goran
Posts: 81
Joined: Thu 27. Nov 2003, 11:43
Location: Zagreb, Croatia
Contact:

Re: Very nice work but small problems!!!

Post by Goran »

osinski wrote:Very nice work but small problems!!!

After trying the script on my apache server running on my desktop,
everything worked fine but after moving the file to my online server
I had the same problem as cyrano on Sep 26, 2004 15:18.

("Oooops...you can't access PRINT PAGE directly....without referer page!")

Then I replaced $HTTP_REFERER with $_SERVER['HTTP_REFERER'] and it finally worked except the referer page :(

Has anybody got any idea what might be wrong?
Do you have rewrite functionality enabled in phpwcms?
Post Reply