sNews Forum

Previous sNews versions => sNews 1.4 Final => Mods and Addons => Topic started by: Keyrocks on October 25, 2006, 05:28:03 pm

Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on October 25, 2006, 05:28:03 pm
This addon uses a printit.php file to convert an article in sNews 1.5 or 1.4 into a print-friendly page, ready-to-print. There are three variables to configure in the file:
- whether or not to strip images from the print page,
- the base (root) URL for your site,
- and the name of your site to be printed in the "Source" line in the print page footer.
All content displayed by the center function statement in your index.php file is included in the printable page by wrapping the function in a pair of tags used within the printit.php file. These tags can be used to wrap any content on other pages as well. All directions for use of this addon are provided in the top comments area of this file.

Just copy and paste the following into a new php file and save it as printit.php in your site's root directory, then follow the directions in the file.
Code: [Select]
<?php
/* ------ printit.php ----------------------------------------------------------
 This file originated as phprint.php, MikeNew.Net, www.mikenew.net/contact.asp
 Modded for use with sNews 1.5 and 1.4 by keyrocks, Oct. 22/06
 Note: As of this date, www.mikenew.net no longer exists.
--------------------------------------------------------------------------------
This script makes your pages printer friendly, with error handling.
Optionally, it will strip images as well. (Instructions for that below)
--------------
Installation
--------------
  1. Save this script in the root of the site.
  2. Wrap the content you want included in the print version of
     your html page in between the following tags:
       <!-- content -->
       your content in here
       <!-- content //-->
  3. Place a link to this file (phprint.php) on the same html page,
     preferably just outside the printed content, like this:
     <a href="/printit.php">Printable Version</a>
     - You could replace the text-link with a printer icon/image in your images
       folder, like this:
       <a href="printit.php"><img src="images/print.png" alt="Print This Page" title="Print This Page"></a>

  4. Set the variables in the next section.
================================================================================ */

/* Strip images from the printable output - leave as "yes".
   Include images in the printable output - change to "no".  */
$stripImages "yes";
/* Set the base domain name of your site, without trailing slash if necessary,
   to fix any relative image and link problems.  */
$baseURL="http://localhost/sNews15/";
// Set the the name of your site, to be printed in the print page footer line.
$sitename="Snews 1.5.27 Default RC2";

/* Finished. No more changes. Upload it and test from your home page.
   (The page containing the two tags and a link to this script)
=========================================================================== */

$startingpoint "<!-- content -->";
$endingpoint "<!-- content //-->";
// let's turn off any ugly errors for a sec so we can use our own if necessary...
error_reporting(0);
// $read = fopen($_SERVER['HTTP_REFERER'], "rb") ... this line may work better if you're using NT, or even FreeBSD
$read fopen($_SERVER['HTTP_REFERER'], "r") or die ("
<font face=\"Verdana\">Sorry! There is no access to this file directly. You
must follow a link. 

Please click your browser's back button. </font>"
);
// 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 
"
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" >
<head>
<!-- Meta Data -->
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<meta http-equiv=\"content-language\" content=\"en\" />
<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />
<meta http-equiv=\"Content-Language\" content=\"English\" />
<!-- Robots -->
<meta name=\"robots\" content=\"NOINDEX, NOFOLLOW\" />
<style type=\"text/css\">
input ,textarea ,select, label{
display: none }
body { font: 85% Arial, Sans-Serif; }
</style>"
;
echo 
"<base href=\"$baseURL\" />";

echo 
"<script type=\"text/javascript\">
/*<![CDATA[*/
<!--
// Do print the page
if (typeof(window.print) != 'undefined') {
window.print();
}
//-->
/*]]>*/
</script> "
;
echo 
"<title>Print : $baseURL </title></head><body onclick=\"window.close()\"> ";
echo 
$PHPrint;
echo 
"<hr/>Source: $sitename";
echo 
"</body></html>";
flush ();
?>
A Demo Test:I don't have a 1.5 site online yet but you can see how cleanly this addon works at http://snews.ca (http://snews.ca) by just clicking the printer icon on any page... it's in the top right corner of the main content area.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: harry on October 29, 2006, 02:29:42 am
Thanks, looks like a great mod.

Just having a bit of trouble on 1.4 where to insert the content tags. Have searched through snews.php with no luck finding where and how to put it.
Any idea how i can achieve this, i just want to print the title and contents of each article.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on October 29, 2006, 02:52:31 pm
Quote from: harry
Thanks, looks like a great mod.
Just having a bit of trouble on 1.4 where to insert the content tags. Have searched through snews.php with no luck finding where and how to put it.
Any idea how i can achieve this, i just want to print the title and contents of each article.
Quote
2. Wrap the content you want included in the print version of your html page in between the following tags:
       <!-- content -->
       your content in here
       <!-- content //-->
Harry - the HTML page we are referring in sNews is the index.php file. This file is the sNews template... really an HTML file that becomes a PHP file once it has been ported to run with sNews. We use "porting" as a way of describing the insertion of PHP statements into the existing HTML code. Each of the PHP statements are wrapped in opening and closing PHP tags like this - <? or <?php and ?>.

To print the title and contents of each article, we put the tags above and below the PHP statement that displays the title and article in the main content area. In sNews 1.4, this statement is <? center(); ?>, since it displays any content generated by the center() function within the snews.php file. So, in your index.php file, locate the center function statement and put the tags before and after it like this:
Quote
<!-- content -->  <? center(); ?>  <!-- content //-->
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: harry on October 29, 2006, 09:58:47 pm
Thanks keyrocks. Don't know why i was looking at snews.php  :rolleyes:

Thanks again for the mod!
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: piXelatedEmpire on November 09, 2006, 05:21:42 am
something I noticed wih this mod...

when I visit http://snews.ca and click on the little printer icon to print a page, the page that is going to be printed appears and then the printer dialogue box appears after a second or two.  The problem is if you click 'cancel' from this printer dialogue box the whole page closes!  It should just make the printer dialogue disappear as opposed to closing the page.

Also, how could you modify this further so that when you click the print button the page that is going to be printed opens in a new window / tab?

cheers
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Mtraker on November 09, 2006, 07:16:31 am
Run ok. I like this addon, thnak you very much.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on November 09, 2006, 04:05:37 pm
Quote from: piXelatedEmpire
something I noticed wih this mod...
[ One ] when I visit http://snews.ca and click on the little printer icon to print a page, the page that is going to be printed appears and then the printer dialogue box appears after a second or two.  The problem is if you click 'cancel' from this printer dialogue box the whole page closes!  It should just make the printer dialogue disappear as opposed to closing the page.

[ Two ] Also, how could you modify this further so that when you click the print button the page that is going to be printed opens in a new window / tab?
cheers
One... This does not happen to me (...in IE6  anyways). If I close the printer dialogue box, it just closes and the browser page still remains visible.

Two... Very simple... you add target="_blank" to your link in the index.php file (as you would to open any link in a new window with html) so it looks like this:
Code: [Select]
<a href="/printit.php" target="_blank">.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 09, 2007, 09:30:18 am
When I click one of the print icons it always has this error:

Sorry! There is no access to this file directly. You must follow a link.

Please click your browser's back button.

I'm using the sNews15-designcriativo package
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: piXelatedEmpire on March 10, 2007, 01:26:07 am
Hi right hosting
This is unrelated to your specific query - but have you updated your sNews package to 1.5.31?
There is a serious exploit in 1.5.30 package that could enable a hacker to gain access to the admin panel and server.
I suggest you upgrade asap if you haven't already :)
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 17, 2007, 02:12:19 pm
yes I'm using the Developers version: 1.5.30 Stable

Well since no one can help me I will have to delete all the print buttons....
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: piXelatedEmpire on March 18, 2007, 06:08:42 am
You really should update to 1.5.31 to avoid your website being open to being exploited.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 18, 2007, 09:40:21 am
The only options I see are:

sNews 1.5.31 [zip] - minimal template * updated
sNews 1.5.30 [zip] - DesignCriativo template  (I already have this)
sNews 1.5.31 [zip] - Mac OS * updated

So if I download the minimal template how would I upgrade the DesignCriativo template?
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on March 18, 2007, 02:36:18 pm
There are only two steps required to update your site from 1.5.30 to 1.5.31. The first is to replace and configure the snews.php file... and the second is to change the username and password values within the settings table in your database. The latter is necessary so that the security features in 1.5.31 will function properly.

STEP ONE
First, download the sNews 1.5.31 ZIP (Minimal) and un-zip it to your hard drive. The next steps all have to do with making some changes in your existing 1.5.30 (DesignCriatavo) site.

- Change the name of your snews.php file to 30_snews.php. This will disable for a while.
- Copy and paste the snews.php file from the 1.5.31 Minimal package into your site's root directory (where 30-snews.php is).
- Copy the database configuration settings from your 30_snews.php file into your new snews.php file.
- Save your changes.

STEP TWO
Now, you need to do a little bit of editing within the settings table in your database. You can do this simple step manually through phpMyAdmin if you have CPanel access to your site's database. Once you have your database visible in phpMyAdmin:
- Click on the settings table in the left side-bar list. Once it appears in the right panel, then click BROWSE from the top menu bar... this will display all the rows in the table.
- Scroll down to the bottom... where the username and password rows are (the last two). In 1.5.30, the username value was the actual username itself, and the password was converted to an encrypted string. In 1.5.31, we now have both values encrypted. So, we need to change (re-set) both of these values with the encrypted string for the word "test", so we can log in with "test | test", then change it to our preferred username and password afterwards.
- In phpMyAdmin, click on the edit link for the username row. Replace the username value in the username field with:
Quote
098f6bcd4621d373cade4e832627b4f6
and click GO to save it. Then, do the same for the password value as well.

Once these two values have been changed in the settings table, you will need to log into your site using test for both the username and password. Once logged in... go to your Settings Admin panel, then scroll down to the bottom and click the Change Username and Password link and expand the panel... change your login information and save it. The next time you log in, you will need to use your new username and password.

If the above seems too confusing, then read through the Readme.htm file that is included with the 1.5.31 package.

One more thing, you might also check and compare the content of your existing .htaccess file with the one that came in the 1.5.31 package, particularly if you had made changes in your existing one previously.

And your site should be running fine. :)
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 19, 2007, 05:30:34 am
It's not working for me, there is parts missing for example there is no "extra_right" function?

Fatal error: Call to undefined function extra_right() ....

Could I just update the old SNews.php with replacing parts that have changed?
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 26, 2007, 03:10:44 am
Can anyone help with my issue? I have waited for about one week now
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: codetwist on March 26, 2007, 08:06:31 am
There is no extra_right() function in snews 1.5.31. Instead of that use function extra().
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Patric Ahlqvist on March 26, 2007, 08:14:40 am
Quote from: right hosting
It's not working for me, there is parts missing for example there is no "extra_right" function?
Fatal error: Call to undefined function extra_right() ....
Could I just update the old SNews.php with replacing parts that have changed?
Nope, that wouldn't do... replacing old snews.php that is. You need to make changes in the DB and for safety reasons go all the way and update the whole shebang... What to do is mentioned in the downloadable read me file...

You should also be aware of the fact that there is a 1.5.41 in the "faggorna", hehe... meaning that 1.5.41 is in the works, and how close to release I don't know, but it is coming... to a theatre near you.
Title: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: right hosting on March 26, 2007, 06:32:02 pm
ok I see, I might just wait for the next release then and update everything then...
Title: Re: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: mfaraklit on February 08, 2010, 12:37:34 pm
I installed this printit mod. But, whenever, i print, it shows " Sorry! There is no access to this file directly. You must follow a link. Please click your browser's back button." whereas i changed 'r' to 'rb'... Can you help me... Is this a server problem?!!
Title: Re: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on February 08, 2010, 03:30:40 pm
I installed this printit mod. But, whenever, i print, it shows " Sorry! There is no access to this file directly. You must follow a link. Please click your browser's back button." whereas i changed 'r' to 'rb'... Can you help me... Is this a server problem?!!

This is a very old mod and it was only done for sNews 1.4 and 1.5.
I've never tried it with a 1.6 or 1.7 package, so I have no idea of whether it would work or not on them, though it might with some careful modding.

Perhaps the problem you are experiencing might be because you missed something in how to use it... which might be because some code in the earlier posts on the first page of this thread was not visible (due to a compatibility issue when we moved our Forums from an older bulleting board system a couple years back). I've gone in and edited those posts so the code now shows... so go back and review the posts on the first page of this thread and see if this helps.  :)
Title: Re: [ADDON] Print Article (sNews 1.4 - 1.5)
Post by: Keyrocks on February 09, 2010, 09:20:14 pm
NOTE: This mod does work OK with sNews 1.7.

It DOES NOT WORK if you are just test-running it offline on your localhost environment (your computer).

I have it installed and working now (as verification) on a 1.7 Demo Here (http://snews.ca/snews17/)... just click the "Print Version" text link above the first article title. It works flawlessly for me when viewing it in IE7 (can't say for other browsers ATM).