Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2

Author Topic: [ADDON] Print Article (sNews 1.4 - 1.5)  (Read 10483 times)

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[ADDON] Print Article (sNews 1.4 - 1.5)
« 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 by just clicking the printer icon on any page... it's in the top right corner of the main content area.
« Last Edit: December 01, 2007, 02:08:09 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

harry

  • Newbie
  • *
  • Karma: 1
  • Posts: 37
    • http://www.thebusinesscardshop.net/order/
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #1 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.

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #2 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 //-->
« Last Edit: February 08, 2010, 03:32:01 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

harry

  • Newbie
  • *
  • Karma: 1
  • Posts: 37
    • http://www.thebusinesscardshop.net/order/
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #3 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!

piXelatedEmpire

  • MIA
  • Thread Moderator
  • ULTIMATE member
  • *****
  • Karma: 37
  • Posts: 1454
  • currently MIA
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #4 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
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

Mtraker

  • Newbie
  • *
  • Karma: 0
  • Posts: 14
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #5 on: November 09, 2006, 07:16:31 AM »

Run ok. I like this addon, thnak you very much.
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #6 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">.
« Last Edit: February 08, 2010, 03:32:29 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

right hosting

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #7 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
Logged

piXelatedEmpire

  • MIA
  • Thread Moderator
  • ULTIMATE member
  • *****
  • Karma: 37
  • Posts: 1454
  • currently MIA
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #8 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 :)
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

right hosting

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #9 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....
Logged

piXelatedEmpire

  • MIA
  • Thread Moderator
  • ULTIMATE member
  • *****
  • Karma: 37
  • Posts: 1454
  • currently MIA
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #10 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.
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

right hosting

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #11 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?
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #12 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. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

right hosting

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #13 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?
Logged

right hosting

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[ADDON] Print Article (sNews 1.4 - 1.5)
« Reply #14 on: March 26, 2007, 03:10:44 AM »

Can anyone help with my issue? I have waited for about one week now
Logged
Pages: [1] 2