{LISTNEWSLETTERS} For listing archived news letters

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

{LISTNEWSLETTERS} For listing archived news letters

Post by JensZ »

Hi!

I wanted to be able to show archived newsletters on my site, so I created a replacement tag to do it. It is very simple and does not yet work for text-based newsletters, but you're welcome to enhance it further.

First of all I needed to specify that a newsletter is archived. I used the existing database column newsletter_trashed. I made the following changes in message.newsletter.tmpl.php right at the beginning:

Code: Select all

// changed by jens
$sql = "SELECT * FROM ".DB_PREPEND."phpwcms_newsletter WHERE newsletter_trashed in (0,1) ORDER BY newsletter_changed DESC;";
if($result = mysql_query($sql, $db) or die("error while listing newsletters")) {
	while($row = mysql_fetch_assoc($result)) {
	
		echo "<tr".( ($row_count % 2) ? " bgcolor=\"#F3F5F8\"" : "" ).">\n<td width=\"25\">";
		echo '<img src="img/symbole/newsletter_little_icon.gif" width="25" height="17"></td>'."\n";
		echo '<td width="463" class="dir"><a href="phpwcms.php?do=messages&p=3&s='.$row["newsletter_id"];  // changed by jens
		echo '"><strong>'.html_specialchars($row["newsletter_subject"])."</strong></a></td>\n".'<td width="50" align="right">'; // changed by jens
		
		// added by jens
		$archimg = ($row["newsletter_trashed"] == 0 ? "img/button/active_11x11_0.gif" : "img/button/active_11x11_1.gif");
		$archact = ($row["newsletter_trashed"] == 0 ? 1 : 0);
		$archtitle = ($row["newsletter_trashed"] == 0 ? "Archive newsletter" : "Unarchive newsletter");
		echo '<a href="phpwcms.php?do=messages&p=3&s='.$row["newsletter_id"].'&archive=' . $archact;
		echo '" title="'.$archtitle.'"><img src="'.$archimg.'" width="11" height="11" border="0"></a>';
		echo '<img src="img/leer.gif" width="2" height="1">';
		// ----
This adds an icon to toggle the newsletter as archived/not archived.

Next, I added the following code to the same file to write the changes to the database when the form is submitted:

Code: Select all

// added by jens
	if(isset($_GET["archive"])) 
	{
		$sql  = "UPDATE ".DB_PREPEND."phpwcms_newsletter SET newsletter_trashed=" . intval($_GET["archive"]);
		$sql .= " WHERE newsletter_id=" . intval($_GET["s"]) . " LIMIT 1;";
		mysql_query($sql, $db) or die("error while archiving newsletter: " . mysql_error());
		header("Location: ".PHPWCMS_URL."phpwcms.php?do=messages&p=3");
		exit();
	}
	// ----
This code goes just below the following code block:

Code: Select all

if(!empty($_GET["del"]) && intval($_GET["del"]) == $newsletter["newsletter_id"]) {
	
		//delete newsletter now
		$sql  = "UPDATE ".DB_PREPEND."phpwcms_newsletter SET newsletter_trashed=9 ";
		$sql .= "WHERE newsletter_id=".intval($_GET["del"])." LIMIT 1;";
		mysql_query($sql, $db) or die("error while deleting newsletter");
		header("Location: ".PHPWCMS_URL."phpwcms.php?do=messages&p=3");
		exit();
	}


Then, I wrote some code for the {LISTNEWSLETTERS} replacement tag to be able to show it on the site. Save the following code as listnewsletters.php and place it in phpwcms_template\inc_script\frontend_render:

Code: Select all

<?php
// AUTHOR: Jens Zetterström
// DESCRIPTION: Lists all available newsletters
// USAGE: {LISTNEWSLETTERS}
$lang_reader = "Reader";

function show_newsletter_list()
{
	$rs = "";
	
	$query = 
	"SELECT 	newsletter_id,
				newsletter_subject,
				UNIX_TIMESTAMP(newsletter_changed) AS newsletter_changed,
				newsletter_vars
	FROM " . DB_PREPEND . "phpwcms_newsletter
	WHERE newsletter_trashed = 1
	ORDER BY newsletter_changed DESC";
	
	$list_rs = mysql_query($query, $GLOBALS["db"]) or die ("Error in query:<br> $query <br><br>" . mysql_error());
	
	if(mysql_num_rows($list_rs))
	{
		while($row = mysql_fetch_assoc($list_rs))
		{
			$rs .= date("Y-m-d", $row["newsletter_changed"]) . "&nbsp;&nbsp;&nbsp;";
			$rs .= "<a href=\"" . $_SERVER["REQUEST_URI"] . "&nlid=" . $row["newsletter_id"] . "\">" . $row["newsletter_subject"] . "</a>&nbsp;<br/>\n";
		}
	}	
	
	return $rs;
}

if( ! ( strpos($content["all"],'{LISTNEWSLETTERS}')===false ) ) 
{
	if(isset($_GET["nlid"]))
	{
		$query = 
		"SELECT 	newsletter_id,
					newsletter_subject,
					UNIX_TIMESTAMP(newsletter_changed) AS newsletter_changed,
					newsletter_vars
		FROM " . DB_PREPEND . "phpwcms_newsletter
		WHERE newsletter_id = " . $_GET["nlid"] . "
		ORDER BY newsletter_changed DESC";
		
		$list_rs = mysql_query($query, $GLOBALS["db"]) or die ("Error in query:<br> $query <br><br>" . mysql_error());
		
		if(mysql_num_rows($list_rs))
		{
			$row = mysql_fetch_assoc($list_rs);
			$newsletter = unserialize($row['newsletter_vars']);
			
			if(strlen($newsletter["html"]) > 0)
			{
				$newsletter["html"] = preg_replace('/###RECIPIENT_NAME###/ei', $lang_reader , $newsletter["html"]);
				$newsletter["html"] = preg_replace('/###SITE_URL###/ei', "\$GLOBALS[\"phpwcms\"][\"site\"]", $newsletter["html"]);
				$newsletter["html"] = preg_replace('/###DELETE_LINK###/ei', "", $newsletter["html"]);
				$newsletter["html"] = preg_replace('/###VERIFY_LINK###/ei', "", $newsletter["html"]);
				$newsletter["html"] = preg_replace('/###RECIPIENT_EMAIL###/ei', "your_email@domain.com", $newsletter["html"]);
				$content["all"] = $newsletter["html"];
			}
			else
			{
				// TODO: fix text newsletters
				$newsletter["text"] = preg_replace('/###RECIPIENT_NAME###/ei', $lang_reader , $newsletter["text"]);
				$newsletter["text"] = preg_replace('/###SITE_URL###/ei', "\$GLOBALS[\"phpwcms\"][\"site\"]", $newsletter["text"]);
				$newsletter["text"] = preg_replace('/###DELETE_LINK###/ei', "", $newsletter["text"]);
				$newsletter["text"] = preg_replace('/###VERIFY_LINK###/ei', "", $newsletter["text"]);
				$newsletter["text"] = preg_replace('/###RECIPIENT_EMAIL###/ei', "your_email@domain.com", $newsletter["text"]);
				//$content["main"] = htmlentities(nl2br($newsletter["text"]));
			}
			
			return;
			// TODO: open window with newsletter instead
		}
	}
	else
	{
		$content["all"] = preg_replace('/\{LISTNEWSLETTERS\}/ei', "show_newsletter_list()" , $content["all"]);
	}
}
?>
As I stated earlier, it's a very simple list of archived newsletters that could be enhanced visually. The newsletter should probably also be displayed in a popup instead. Anyway, I hope you can use it.

Cheers,

Jens
Last edited by JensZ on Thu 9. Jun 2005, 13:15, edited 1 time in total.
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi JensZ

Cool, you seem very productive! First the result thing, then the enhanced calendar, now this, wow!
Your contribution is much appreciated (by me anyway) :D
Brans is gonna be happy for his mods :wink:
Keep it up, good job!
Cheers
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Thanks Kosse,

Well, it's just some simple code with tricks to get some stuff on the site the way I need them. Anyway, I hope it proves useful for other phpwcms webmasters. It'll take some time before the sports result reporting module will be ready to be shared as it is quite extensive and way too messy at the moment.

Cheers,

Jens
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hi
could you add your REPTAG on
--...--

thanks
TriP
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

This Rep Tag is really awesome 8)
I just wish now to get it to work with URL REWRITE...
I have the feeling that the "Crux of the Biscut" resides here at line 29:

Code: Select all

			$rs .= "<a href=\"" . $_SERVER["REQUEST_URI"] . "&nlid=" . $row["newsletter_id"] . "\">" . $row["newsletter_subject"] . "</a>&nbsp;<br/>\n";
just don't know how to edit it.... :roll:
Anyone would have a quick edit for this...? :? :wink:

Cheers,

Yves
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

What's url rewrite?
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi Jensz,

url rewrite is an Apache function (settings in .htacess file ) that allows you to rewrite the URL for example instead of having /index.php?id=37,0,0,1,0,0 (a page that is... say your contact page) you have /contact.ptml or contact.shtml or contact.html

Cheers
dernier_recours
Posts: 66
Joined: Mon 2. May 2005, 17:33
Location: Canada
Contact:

Post by dernier_recours »

In sent news letters, for 1.2.6-dev, I obtain:

Code: Select all

Parse error: parse error, unexpected $ in /var/www/devel2/include/inc_tmpl/message.newsletter.tmpl.php on line 377
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

dernier_recours wrote:In sent news letters, for 1.2.6-dev, I obtain:

Code: Select all

Parse error: parse error, unexpected $ in /var/www/devel2/include/inc_tmpl/message.newsletter.tmpl.php on line 377
Hmmm Dernier_Recours: you must be talking about send not sent :roll: :wink:
I don't se any sent option. :roll:
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
dernier_recours
Posts: 66
Joined: Mon 2. May 2005, 17:33
Location: Canada
Contact:

Post by dernier_recours »

I'm talking about the link that appears at the top of the MESSAGE section. The link is called "newsletter".

Cheers,

dr

Image
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

dernier_recours wrote:In sent news letters, for 1.2.6-dev, I obtain:

Code: Select all

Parse error: parse error, unexpected $ in /var/www/devel2/include/inc_tmpl/message.newsletter.tmpl.php on line 377
hmmm... Line 377 ?
Are you sure you have the latest file ?
I can only see 351 lines in the latest
message.newsletter.tmpl.php file :roll:

Cheers,
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

StudioZ wrote: I can only see 351 lines in the latest
message.newsletter.tmpl.php file :roll:

Cheers,
LOL :twisted: But what about... "AFTER the MOD" ? :wink:

@dernier_recours
Why not POST here... that range of lines... from your "edited" file ?
Jakim José
Posts: 77
Joined: Fri 18. Feb 2005, 18:55
Location: Portugal/Aveiro

Post by Jakim José »

It's to function?
IbnSaeed
Posts: 37
Joined: Thu 1. Dec 2005, 17:48
Location: UAE

Post by IbnSaeed »

dernier_recours wrote:In sent news letters, for 1.2.6-dev, I obtain:

Code: Select all

Parse error: parse error, unexpected $ in /var/www/devel2/include/inc_tmpl/message.newsletter.tmpl.php on line 377

The error message is caused because the first code is missing 2 closing tags.


Add the following code in file
"\include\inc_tmpl\message.newsletter.tmpl

Code: Select all

<?php
// changed by jens 
$sql = "SELECT * FROM ".DB_PREPEND."phpwcms_newsletter WHERE newsletter_trashed in (0,1) ORDER BY newsletter_changed DESC;"; 
if($result = mysql_query($sql, $db) or die("error while listing newsletters")) { 
   while($row = mysql_fetch_assoc($result)) { 
    
      echo "<tr".( ($row_count % 2) ? " bgcolor="#F3F5F8"" : "" ).">\n<td width="25">"; 
      echo '<img src="img/symbole/newsletter_little_icon.gif" width="25" height="17"></td>'."\n"; 
      echo '<td width="463" class="dir"><a href="phpwcms.php?do=messages&p=3&s='.$row["newsletter_id"];  // changed by jens 
      echo '"><strong>'.html_specialchars($row["newsletter_subject"])."</strong></a></td>\n".'<td width="50" align="right">'; // changed by jens 
     
      // added by jens 
      $archimg = ($row["newsletter_trashed"] == 0 ? "img/button/active_11x11_0.gif" : "img/button/active_11x11_1.gif"); 
      $archact = ($row["newsletter_trashed"] == 0 ? 1 : 0); 
      $archtitle = ($row["newsletter_trashed"] == 0 ? "Archive newsletter" : "Unarchive newsletter"); 
      echo '<a href="phpwcms.php?do=messages&p=3&s='.$row["newsletter_id"].'&archive=' . $archact; 
      echo '" title="'.$archtitle.'"><img src="'.$archimg.'" width="11" height="11" border="0"></a>'; 
      echo '<img src="img/leer.gif" width="2" height="1">'; 
      // ----
    }
  }
?>	


AFTER the code below

Code: Select all

if(!isset($_GET["s"])) { 
// check if subscription should be edited
?>
<table width="538" border="0" cellpadding="0" cellspacing="0">
	<tr><td colspan="3" class="title"><?php echo $BL['be_subnav_msg_newslettersend'] ?></td></tr>
	<tr><td colspan="3"><img src="img/leer.gif" width="1" height="5"></td></tr>
	<tr><td colspan="3" bgcolor="#92A1AF"><img src="img/leer.gif" width="1" height="1"></td></tr>
dernier_recours
Posts: 66
Joined: Mon 2. May 2005, 17:33
Location: Canada
Contact:

Post by dernier_recours »

Thanks!
Post Reply