[mod] link to view an online version of the message

3rd party code for phpList

Re: [mod] link to view an online version of the message

Postby Dragonrider » 1:29pm, Thu 02 Feb, 2012

barrancoguillaume wrote:Hi all,
I used the solution given by harty83 on 2.10.17 version and I get the link on my messages.
But when I click on it, I have this error message (in white on a red background) :
Code: Select all
Database error 1064 while doing query You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where messageid = 8 and uniqid = "91ce873d2ef07e6f075aeb14d1e3d020" order by mod' at line 1

It's the only thing I have on the page.

I put a track of the query in vm.php and saw that the variable $GLOBALS["tables"]["messageview"] isn't pass to the query so I have an empty from clause.
I looked on the database but I haven't found a table that look like the one vm.php is searching for (a table with the fields data, messageid and uniqid).

Did someone find the solution ?

Thanks by advance


Possible solution here, Item 1B, certainly error 1064 fix anyway.
My sites:- http://wharfedalefestival.co.uk, http://ilkleygardeners.org.uk, http://emergencyaid.net, http://dragonrider.co.uk
Latest phpList version is now 3.0.12 (3 February 2015) and requires a minimum of MySQL 5.0 and PHP 5.3.x
Dragonrider
Moderator
 
Posts: 3460
Joined: 6:58am, Sun 02 Jul, 2006
Location: Ilkley, West Yorkshire, United Kingdom

Re: [mod] link to view an online version of the message

Postby barrancoguillaume » 1:55pm, Thu 02 Feb, 2012

Thank you Dragonrider,
I found the solution : I was confusing two tips : the one by harty83 and another from here : viewtopic.php?f=7&t=23417
I jut took the last and it worked !
barrancoguillaume
phpLister
 
Posts: 6
Joined: 1:16pm, Wed 01 Feb, 2012

Re: [mod] link to view an online version of the message [2]

Postby solmar » 5:45pm, Thu 23 Aug, 2012

The code by nachotronics works great but has a problem that I didn't tackle when I posted on February 2011.

[quote="solmar"]Adding two cents to the code below by nachotronics, that we chose for our on line newsletter display.
PHPlist 2.11.5[/quote]

An incremental filename, based on PHPlist's "messageid", allows anyone to browse all static versions by just adding +1/-1 to the link. Not a big issue, senders might be glad that unexpected users can see their messages. But I find it unprofessional.

So I:
- Created a file uniquecode.php that generates a random variable, adds it to the session.
- Had it loaded in sendemaillib.php, only once per send process.
- Added a line to nachotronics' code so the variable is read from the session, only if we need it.
- Used the variable instead of messageid to name/link the static file.

Using include_once and the session, the variable does not change during the sending process, so we have a functional substitute of messageid.

Putting the edited code here and in Mantis. Hope the useful "online version" feature enters PHPlist right from the next version!

1/5 - In config.php
[code]
## turn on option to create a link in each email to a static copy of the message in case users have a hard time viewing message
$generate_static = 1;
[/code]

2/5 - In sendemaillib.php, right at the beginning, after the call to accesscheck.php

[code]
include_once dirname(__FILE__).'/uniquecode.php';
[/code]

3/5 - Also in sendemaillib.php,
Edit between rows "# some readers fail when it doesn't" and "$htmlmessage = '<body>'.$htmlmessage.'</body>';"
Replace "[web path to file directory]" with the real value.

[code]
# some readers fail when it doesn't
if (!preg_match("#<body.*</body>#ims",$htmlmessage)) {
if ($GLOBALS["generate_static"] == 1){
$uniquecode = $_SESSION['uniquecode'];
$htmlmessagestatic = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>'.$messageid["subject"].'</title><body><div align="center" style="color:#003366; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold;">Newsletter sent on '.date("j-m-Y").'
</div>'.$htmlmessage.'</body>';
$htmlmessage = '<body><div style="TEXT-ALIGN: center; PADDING-BOTTOM: 0px; LINE-HEIGHT: 22px; MARGIN: 0px 0px 12px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; FONT-FAMILY: Arial, sans-serif; COLOR: #666666; FONT-SIZE: 12px; PADDING-TOP: 0px" align="center">If you cannot see the message, <a href="http://www.'.getConfig("domain").'/[web path to file directory]/'.$uniquecode.'.html">see in the browser</a>.<br /></div>'.$htmlmessage.'</body>';
} else {
$htmlmessage = '<body>'.$htmlmessage.'</body>';
}
}
[/code]

4/5 - Also in sendemaillib.php, immediately after the above.
Replace "[absolute path to file directory]" with a real value.

[code]
#write to static file here
if ($GLOBALS["generate_static"] == 1){
$static = '[absolute path to file directory]/'.$uniquecode.'.html';
$statichandle = fopen($static, 'w');
fwrite($statichandle, $htmlmessagestatic);
fclose($statichandle);
}
[/code]

5/5 - Create a uniquecode.php file in the /admin directory with the following content:

[code]
<?php

$alphanum = 'abcdefghijklmnopqrstuvwxyz1234567890';
$inc = 1;
while ($inc < 5){
$alphanum = $alphanum.'abcdefghijklmnopqrstuvwxyz1234567890';
$inc++;
}
$uniquecode = substr(str_shuffle($alphanum), 0, 10); // 10 is the amount of letters/numbers selected by variable alphanum';

$_SESSION['uniquecode'] = $uniquecode;

?>
[/code]
solmar
PL Nut
 
Posts: 20
Joined: 5:16pm, Thu 26 Jun, 2008

Re: [mod] link to view an online version of the message

Postby johntrot » 8:31pm, Sat 13 Oct, 2012

[SOLUTION FOUND]
I edited my original post below because I found exactly what I was after in the Forum:
Contributions: Plug-ins, Add-ons, Mods
new mod to view HTML email in browser
by TomAble

I am using 2.10.19 and it is working great!
My appreciation to those who did the coding... Thank You!!

-------------------------------------------------------------------
With multiple "Lists," I never send to everyone in the db.
When I place the link ( If you're having trouble viewing this, < a = "[domain]/view/view.php">CLICK HERE < a >)
to view the emails online using the edited script from "stuff4toys by Bugabundo" you can cycle back and forth through each email and all of the system "lists" without regard to the fact that you did not receive some of the emails at all.

My question is... how to tie each email link in the template used from phplist that is sent from the program to the specific email in the link. That would allow the members in the db to save each email and view them online later if necessary, but not view the emails they were never sent.

I have the message id, but how do I place it in the link? ... something to do with the email Headers?

Any help would be appreciated!
Thank You
John B
johntrot
PL Geek
 
Posts: 71
Joined: 8:28pm, Fri 01 Apr, 2005

Re: [mod] link to view an online version of the message

Postby ado » 8:35pm, Wed 31 Oct, 2012

Hello,
I modified the original code to do:
If `user` variable is set and is 32 char uniqid from user_user table , the script will display only emails sent to the email associated with the uniqid.
If `user` variable is not 32 char or missing, will dispaly all emails sent to public lists.

Added table prefix variable in mysql query (default is phplist_)
Commented missing header image

I created the page in my /lists/ dir so the require function should work fine in this dir. Otherwise change the location string of config file.
I also added email.php in my .htaccess file in /lists/ dir.

To add uniqid in sent email you add
http://www.example.com/lists/email.php?user=[USERID]
either in html template or in footer.


Hope its useful.

Code: Select all
<?php
/** AUTHOR BUGabundo
 * email: phplist@BUGabundo.net
 * web: http://BrinKadeiraS.BUGabundo.net
 * Date: 3/07/2006
 * Modified by John lange aka Stuff4Toys
 * email: john@stuff4toys.com
 * web: http://www.stuff4toys.com
 * Date: 6/17/2008 on my 52nd Birthday
***** Set Your Own mySQL information in the area just below the comments (it's in your config.php) *****
$hostname_phplist = "host.domain.com";
$database_phplist = "Data_Base_Name";
$username_phplist = "Data_Base_User";
$password_phplist = "Data_Base_Password";
***** Set Path to config.php *****
<?php require_once('lists/config/config.php'); ?>
***** Find this area below and insert your own href and header image info *****
***** Set the image width to suit - Also set the table width to suit *****

// echo '<td><div align="center"><a href="http://www.YourDomain.com/" target="_blank"><img height="97" border="0" width="610" src="http://www.YourDomain.com/images/header.jpg" alt="" /></a></div></td>';
*/

$hostname_phplist = "";
$database_phplist = "";
$username_phplist = "";
$password_phplist = "";
$table_prefixlist = "";


$userid=substr(preg_replace("/[^A-Za-z0-9 ]/", '', $_GET['user']),0,32);


if (strlen($userid)!=32)
   {
      $userid="";
   }

$phplist = mysql_pconnect($hostname_phplist, $username_phplist, $password_phplist) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php require_once('config/config.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 1;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_phplist, $phplist);
if ((isset($userid))and($userid!=''))
   {      
      $query_Recordset1 = "SELECT
                        a.`entered`,
                        (
                           SELECT
                              list.`name`
                           FROM
                              `".$table_prefixlist."listmessage` lm
                              left join `".$table_prefix."list` list on (lm.`listid`=list.`id`)
                           WHERE
                              lm.`messageid`=a.`messageid` limit 1
                        ) as `name`,
                        p.`subject`,
                        p.`message`

                     FROM
                        `".$table_prefix."usermessage` a
                        left join `".$table_prefix."user_user` u on (u.`id`=a.`userid`)
                        left join `".$table_prefix."message` p on (p.`id`=a.`messageid`)
                     WHERE
                        u.`uniqid`='".$userid."'
                     ORDER BY a.entered DESC";
   }
else
   {
      $query_Recordset1 = "SELECT
                        lm.`entered`,
                        li.`name`,
                        (SELECT `subject` FROM `".$table_prefix."message` WHERE `id`=lm.`messageid`) as `subject`,
                        (SELECT `message` FROM `".$table_prefix."message` WHERE `id`=lm.`messageid`) as `message`
                     FROM
                        `".$table_prefix."listmessage` lm
                        left join  `".$table_prefix."list` li on (lm.`listid`=li.`id`)
                     WHERE
                        li.`active`='1'
                      ORDER BY lm.entered DESC";
      
      //$query_Recordset1 = "SELECT p.entered, li.name, p.subject, p.message FROM ".$table_prefix."message p, ".$table_prefix."listmessage l,".$table_prefix."list li WHERE p.id=l.messageid AND l.listid=li.id ORDER BY p.entered DESC, li.name ASC";
   }   
//echo   $query_Recordset1;
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $phplist) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mailinglist</title>
</head>

<body>
<div align="center">Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?>
</div>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="button_first.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="button_prev.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="button_next.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="button_last.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
<?php //} // Set the Table Width to Suit Your Needs - In this case it's the same size as the header image below ?>
<table width="610" cellspacing="0" cellpadding="0" border="1" align="center" id="tabela">
<?php do { ?>
<tr>
<td align="center"><div align="center">Date: <?php echo $row_Recordset1['entered']; ?></div></td>
</tr>
<td align="center"><div align="center">Mail List: <?php echo $row_Recordset1['name']; ?></div></td>
</tr>
<td align="center"><div align="center">Subject: <?php echo $row_Recordset1['subject']; ?></div></td>
</tr>
<tr align="center">
<td><!-- <div align="center"><a href="http://www.YourDomain.com/" target="_blank"><img height="97" border="0" width="610" src="http://www.YourDomain.com/images/header.jpg" alt="" /></a></div>--></td>
</tr>
<td><blockquote>
<p><?php echo $row_Recordset1['message']; ?></p>
</blockquote></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="button_first.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="button_prev.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="button_next.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="button_last.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>

<div align="center">Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?>
</div>
<?php //} // Leave the Copyright info alone unless you make major changes to this file.  If you do make major changes, share them with me! ?>
<div align="center"><font size="1" color="#c0c0c0">Copyright 2008 John at <a href="http://www.Stuff4Toys.Com/" target="_blank"> Stuff4Toys.Com</a> - John Lange</font></div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
ado
phpList newbie
 
Posts: 2
Joined: 5:44pm, Tue 21 Jul, 2009

Previous

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 3 guests