Author Topic: Print code php (phprint.php)  (Read 10049 times)

0 Members and 1 Guest are viewing this topic.

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Print code php (phprint.php)
« on: May 09, 2003, 11:03:35 AM »
This is a print code i found.
(http://www.mikenew.net/download/scripts/phprintCodeDisplay.php)

it should be useful to do some printing, but it doesn't seems to work at my site (www.schoolplaten.com)
Anyone who wants to check the code ? Maybe there is a bug in it , i dont know php well enough to do that myself.

 :arrow: Instructions :
Paste it into a text file, then save that text file as "phprint.php". Upload it. After burying the two tags in your HTML pages, just link to your new script. That's it!

<--------8<--------Start copying below this line------->
Code: [Select]
<?php 

/*PHPrint - This file is phprint.php
Make any Page Printer Friendly! Version 2.0 - 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. (Not likely that it will. Hasn't yet.)
This script will make your pages printer friendly. 
Optionally, it will strip images as well. (Instructions for that below)

// After installation, you can remove text from here down to the next: 8< ---->
// Back up/copy this file first.

1. Save this script in the root of the site for simplicity.
2. Place <!-- startprint --> somewhere in your HTML page 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 phprint.php anywhere on the HTML page (preferably outside the printed content,
like this: <a href="/phprint.php">Print this page</a>
- or however you like, just as long as you link to this script. */

// If you've already tested, you can remove the text from here up to the other: 8< ---->

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

//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 by going to yoursite.com/page.php
// (The page containing the two tags and a link to this script)
// -----------------------------------------------------

$startingpoint "<!-- startprint -->";
$endingpoint "<!-- stopprint -->";
// let's turn off any ugly errors for a sec so we can use our own if necessary...
error_reporting(0);
// $read = fopen($HTTP_REFERER, "rb") ... this line may work better if you're using NT, or even FreeBSD
$read fopen($HTTP_REFERER"r") or die("<br /><font face=\"Verdana\">Sorry! There is no access to this file directly. You must follow a link. <br /><br />Please click your browser's back button. </font><br><br><a href=\"http://miracle2.net/\"><img src=\"http://miracle2.net/i.gif\" alt=\"miracle 2\" border=\"0\"></a>");
// let's turn errors back on so we can debug if necessary
error_reporting(1);

$value "";
while(!
feof($read)){
$value .= fread($read10000); // reduce number to save server load
}
fclose($read);
$startstrpos($value"$startingpoint"); 
$finishstrpos($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 );
$PHPrint stripslashes("$PHPrint"); 

echo 
"<base href=\"$baseURL\">";

echo 
$PHPrint
// Next line is invisible except to SE crawlers, please don't remove. Thanks! :)
echo "<br><a href=\"http://miracle2.net/\"><img src=\"http://miracle2.net/i.gif\" ";
echo 
"alt=\"miracle 2\" border=\"0\"></a>";
echo 
"<br/><br/>This page printed from: $HTTP_REFERER";
flush (); 
?>

<--------8<--------Stop copying above this line ------->

 :roll:
That's it
« Last Edit: April 19, 2005, 02:47:24 AM by V@no »

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Fix for new PHP versions 4.1.0 and up.
« Reply #1 on: May 09, 2003, 11:09:35 AM »
:arrow: This is an upgrade code for PHP version 4.1.0 and up.  :!:
( the one i used )

Code: [Select]
<?php 

/*PHPrint - This file is phprint.php
Make any Page Printer Friendly!
Copyright by MikeNew.Net, Notice must stay intact
************
Legal: MikeNew.Net is not responsible for any damages caused
by use of this script. (Not likely that it will. Hasn't yet.)
This script will make your pages printer friendly. 
Optionally, it will strip images as well. (Instructions for that below)

// After installation, you can remove text from here down to the next: 8< ---->
// Back up/copy this file first.

1. Save this script in the root of the site for simplicity.
2. Place <!-- startprint --> somewhere in your HTML page 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 phprint.php anywhere on the HTML page (preferably outside the printed content,
like this: <a href="/phprint.php">Print this page</a>
- or however you like, just as long as you link to this script. */

// If you've already tested, you can remove the text from here up to the other: 8< ---->

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

//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 by going to yoursite.com/page.php
// (The page containing a the two tags and a link to this script)
// -----------------------------------------------------

$refpage = (phpversion() > "4.1.0") ? $_SERVER[HTTP_REFERER] : $HTTP_SERVER_VARS[HTTP_REFERER];

$startingpoint "<!-- startprint -->";
$endingpoint "<!-- stopprint -->";


// let's turn off any ugly errors for a sec-
error_reporting(0);
// $read = fopen($refpage, "rb") ... may work better if you're using NT and images
$read fopen($refpage"r") or die ("<br />Sorry! There is no access to this file directly. You must follow a link. <br /><br />Please click your browser's back button. <br><a href=\"http://miracle2.net/\"><img src=\"http://miracle2.net/i.gif\" alt=\"miracle 2\" border=\"0\"></a>");
// let's turn errors back on so we can debug if necessary
error_reporting(1);

$value "";
while(!
feof($read)){
$value .= fread($read16000); // reduce number to save server load
}
fclose($read);
$startstrpos($value"$startingpoint"); 
$finishstrpos($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 eregi_replace"</font>"""$PHPrint );
$PHPrint stripslashes("$PHPrint"); 

// 
echo "<base href=\"$baseURL\">";

echo 
$PHPrint
// Next line is invisible output. Nobody will see it except SE crawlers, please don't remove. Thanks! :)
echo "<br><a href=\"http://www.mikenew.net/\"><img src=\"http://www.mikenew.net/images/php.gif\" ";
echo 
"alt=\"site promotion\" width=\"20\" height=\"8\" border=\"0\"></a>";
echo 
"<br/><br/>Page printed from: <br />" $refpage ";

?>


« Last Edit: April 19, 2005, 02:47:41 AM by V@no »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Print code php (phprint.php)
« Reply #2 on: May 09, 2003, 11:24:34 AM »
do u mean it does something like this?:
http://come.no-ip.com/details.php?image_id=7570&page=5#comments
or where do  u want use it?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Print code php (phprint.php)
« Reply #3 on: May 09, 2003, 03:37:46 PM »
I have that script too.  You didn't tell us where you were trying to use it or any other details that could help but based on my experience I have an idea of what might be happening.

If you try to use this script on a category or detail page that has 4images private permissions set, the script won't work.  The reason is because the php print script has no knowledge of the 4images user session.  It runs in a separate process outside of 4images.  Therefore as far as 4images is concerned, it behaves like the visitor is a "not logged" in user.

If you want to solicit more help, you really need to provide more details about what template you're trying to use this in, 4images permissions, etc.  Any details you can think of.  An example URL would really help others help you.

Good luck !

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Print code php (phprint.php)
« Reply #4 on: May 09, 2003, 05:31:33 PM »
you can see that the printing doesn't work ( schoolplaten.com) :wink:

what permissions concerns :

View Category :All
View Image : Registered Users
Download : Registered Users
Upload  : Registered Users
Direct Upload : Administrators  
Vote : All
Send eCard : All
Read Comments : All
Post Comment : Registered Users

Hope this is the information you needed to understand what's going
on...   :?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Print code php (phprint.php)
« Reply #5 on: May 09, 2003, 06:36:22 PM »
Does it work if you change View Image permissions to ALL ?

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
php script
« Reply #6 on: May 23, 2003, 12:14:14 AM »
yes, then the printer-friendly script works correct with no restrictions.

But : can i adjust the size of the pic if it is shown in the phprint script ?

example : you see the original pic at 413 x 585 pix.
You go to the printer friendly page, and there i would like to see it at 1240 x 1758 pix.
Is this possible ???

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Re: Print code php (phprint.php)
« Reply #7 on: October 18, 2005, 08:40:07 AM »
it seems that this script loads the picture again in an extra browser window, to print it from there.
This causes lots of extra bandwidth usage, because my pics are big.
Does anyone know a way to print directly from the 4-images browserwindow ?, so no extra traffic is made.