[add-on] Archive Messages

3rd party code for phpList

Still not working

Postby cevic » 11:38am, Tue 25 Jul, 2006

Thanks H2B2. I followed the installation instrutions at the top of the script but I still get DB connection problems.

The only main difference between the instructions and my setup is that I've got PHPlist intalled in the root of

http://mailing.bippie.com/

which means that I don't have either a 'phplist' folder or a 'lists' folder. Do you think that references to other files, including the config file, are ok?

include("/config/config.php");
require_once dirname(__FILE__).'/admin/commonlib/lib/magic_quotes.php';

(I should think they are, but maybe I'm wrong)
cevic
phpLister
 
Posts: 5
Joined: 11:50am, Mon 24 Jul, 2006

Re: Still not working

Postby H2B2 » 9:03pm, Tue 25 Jul, 2006

cevic wrote:include("/config/config.php");

Not sure. But you could try this:
Code: Select all
include("config/config.php");

If you use archive.php version 1.1, you should also change the paths for the other includes in the same way, i.e. removing the leading slash (/), assuming this is your directory structure:
your_install_in_root/admin/
your_install_in_root/config/

Hmm, installing phplist in a subdomain. Interesting idea. Did you have to do anything special in your setup to do that? Just curious. I might give it a try.
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Still having the same problem

Postby cevic » 9:20am, Wed 26 Jul, 2006

Thanks H2B2! I still have the same problem. Actually I've tried all sorts of combinations: dot slash, starting slash, no slash and I get nothing ...

If I use a starting slash in line 10:

include("/config/config.php");

Then the whole page is rendered and I get a "Could not select database."

If I use:

include("./config/config.php");

or if I harcode all the DB data (host, name, user, password) then I get a:

"Could not retrieve requested information."

and the full page is not rendered.

So I think that the problem is in the script and not just the way I refer to the config file.

Do you know who wrote the script? Maybe I can ask that person to give me a clue on how to make it work.

The subdomain thing is easy if you have control over your domain records.

Thanks again!
cevic
phpLister
 
Posts: 5
Joined: 11:50am, Mon 24 Jul, 2006

Re: Still having the same problem

Postby H2B2 » 7:34pm, Wed 26 Jul, 2006

cevic wrote:"Could not retrieve requested information."

Yes, this would suggest that config.php was in fact found, so the path must be alright.

I would than suggest to take another look at your command line.
Supposing you want to display all newsletters from listID "4" and supposing you would use (subscribe page)layout "2" for displaying the header and footer of your newslette, you would -in your case- use this commandline in your browser (or in a hyperlink):
Code: Select all
http://www.subdomain.yoursite.com/archive.php?listID=4&layoutID=2


cevic wrote:Do you know who wrote the script? Maybe I can ask that person to give me a clue on how to make it work.
I know that apart from the person mentioned in the script header, Jfriesen and Zappu have contributed to archive.php. Some others might have too. Check this thread.
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Postby cevic » 8:49am, Fri 28 Jul, 2006

Yes, I did that already:

http://mailing.bippie.com/archive.php?l ... layoutID=6

(both existing list and layout with archived messages)

but I only get the "Could not retrieve requested information."

I'm thinking I might just give up since I don't see a solution.
cevic
phpLister
 
Posts: 5
Joined: 11:50am, Mon 24 Jul, 2006

Postby sanjay92 » 6:51pm, Fri 04 Aug, 2006

Does anybody know, how to show archive messages in HTML template ? HTML template which was used in sending newsletter.
sanjay92
PL Nut
 
Posts: 17
Joined: 8:31pm, Thu 13 Apr, 2006

Postby H2B2 » 8:44pm, Tue 08 Aug, 2006

sanjay92 wrote:Does anybody know, how to show archive messages in HTML template ? HTML template which was used in sending newsletter.

If you are using the archive.php ver. 1.1 which includes Zappu's modifications, keep in mind that the layout of the archived newsletters is not based on the phplist templates but on the layout of the the subscribe pages. So given that you can create several subscribe page layouts and that each subscribe page layout has an ID number, you can use this solution:
Create a new subscribe page which has a header and footer that matches your newsletter template's header and footer. Use the ID number of that subscribe page layout in your command line, e.g.:
http://www.yoursite.com/phplist/lists/a ... layoutID=3
Remember that the sole use of this new subscribe page is that it matches your newsletter layout. Do not use it for real subscriptions, unless you actually want that.

Another way would be to hack Zappu's code and get the template's layout instead of the subscribe page's layout from the database. If someone manages to do that, please post it here. :D
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Update: archive.php ver. 1.2

Postby H2B2 » 3:41pm, Wed 09 Aug, 2006

Just a minor update:
- cleaned up some redundant code
- added some comments to help with configuration

Code: Select all
<?php  // April 2005 -> PHP (4>=5) PHPlist
/*
* @version $Id: archive.php, v.1.2, 9/08/2006
* @package Contribution to PHPlist 2.10.2
* This is an adapted version that includes Zappu's modifications
* and has been tested with PHPlist 2.10.2.
* Changes in ver. 1.2:
* - cleaned up some redundant code
* - added some comments to help with configuration
********************************************************************
* INSTALLATION:
* FTP this file to your phplist/lists/ directory
* The path info assumes archive.php is placed in the directory
* phplist/lists/
* In that case you must INCLUDE archive.php in the .htaccess file.
*
* USE with this command line:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1
* where: listID is the list you want to display, and LayoutID is the
* Layout you want to use.
* Note that this is the layout of one of your subscribe pages. It is NOT
* the layout of your newsletter template (wich would have been more logical).
* So if necessary, create subscribe pages which only use is that they match the
* header and footer of your newsletter template. Anyway, that was my solution.
* Enjoy! H2B2.
*
********************************************************************
* Previous version info:
* @version $Id: archive.php, v.1.0, 04/09/2005, kalan
* @package Contribution to PHPlist 2.9.3
* @copyright (C) 2005 solutions_PHP, www.solutionsphp.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* support thread: http://www.phplist.com/forums/viewtopic.php?t=1501
********************************************************************
*/


// Include the common configurations for data host, user, password, name.
include("./config/config.php");

// These lines are for Zappu's mod
### I am not sure if all includes are needed, but it works ###
require_once dirname(__FILE__).'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/dutch.inc"; #HW: change this to the language file you use
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";


// Print the head section of our document using Zappu's mod ....
$data = PageData($_GET['layoutID']);

// print('<title>'.$GLOBALS["strForwardTitle"].'</title>');
print('<title>Your Custom Title here </title>');
print($data["header"]);

// Data query 
define("__QUERY__","select * from phplist_message,phplist_list,phplist_listmessage where phplist_list.id=".$_GET['listID']." and phplist_list.id=phplist_listmessage.listid and phplist_message.id=phplist_listmessage.messageid and phplist_list.active=1");

// Decide whether to show a list of titles or show a specific message ....
if(!isset($_GET['x'])){

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              if($RS = mysql_query(__QUERY__, $DB)){

               
                  while($_ROW = mysql_fetch_assoc($RS)){

                 // Print the selected newsletter...
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters. In my case I use layoutID=3 for displaying
                 // the newsletter itself. I still use the command line layoutID
                 // to display the listing of newsletters, which in my case is
                 // layoutID=1

                 // Original code to print the selected newsletter:
                      printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$_GET['listID']."&layoutID=".$_GET['layoutID']."'>%s</a><br /><em>Sent: %s</em><br /><br />",

                 // Alternative code to print the selected newsletter
                 // with a predefined layoutID:
                     //  printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$_GET['listID']."&layoutID=3' target=_blank>%s</a><br /><em>Sent: %s</em><br /><br />",

                      stripslashes($_ROW['name']),$_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);

                  }
                 
                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>No entries were found in the archive.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }

                 
                  mysql_free_result($RS);
                  mysql_close($DB);


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);
                 
                  print("<h2>Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }
 
}else{

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              $_QUERY = sprintf("select * from phplist_message where id=%s",$_GET['x']);

              if($RS = mysql_query($_QUERY, $DB)){

                  $_ROW = mysql_fetch_assoc($RS);
                 
                 
                 // Re-print the list of selected newsletters after clicking on
                 // the archive link in the header of a displayed newsletter
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters.

                 // Original code to re-print the list of selected newsletters:
                       printf("<div align='left'><br /><a href=./%s?listID=".$_GET['listID']."&layoutID=".$_GET['layoutID'].">&laquo; Archive</a></div>".

                 // Alternative code to re-print the list of selected newsletters
                 // with a predefined layoutID:
                   // printf("<div align='left'>&nbsp;&nbsp;<a href=./%s?listID=".$_GET['listID']."&layoutID=1>&laquo; <b>Archive</b></a></div>".

                        // "<h1 align='center'>%s</h1>".
                        // "<br>Sent: %s</em><hr /><br />".
                         "<br /><div align='left'>%s%s</div>",
                         basename($_SERVER['PHP_SELF']),
                        // $_ROW['subject'],
                        // $_ROW['sent'],
                         $_ROW['message'],
                         $_ROW['footer']);
                         

                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>Could not retrieve the selected message.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }


                  mysql_free_result($RS);
                  mysql_close($DB);


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);

                  print("<h2>Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }

}

print($html);
// Print our document's footer using Zappu's mod ....
// print("<P>".$GLOBALS["PoweredBy"]."</p>");
print($data["footer"]);
?>
Last edited by H2B2 on 2:47pm, Thu 17 Aug, 2006, edited 1 time in total.
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Could not retrieve requested information.

Postby SmileyBri » 6:08am, Thu 17 Aug, 2006

"Could not retrieve requested information."

This would seem to indicate that the paths to the files are in tact. What is the suggested troubleshooting step if this is the output?

Thanks! I look forward to getting this working.

Brian
SmileyBri
phpList newbie
 
Posts: 1
Joined: 6:04am, Thu 17 Aug, 2006

Re: Could not retrieve requested information.

Postby H2B2 » 2:31pm, Thu 17 Aug, 2006

SmileyBri wrote:"Could not retrieve requested information."

This would seem to indicate that the paths to the files are in tact. What is the suggested troubleshooting step if this is the output?

I assume that:
- you have in fact sent messages in your database
- the list these messages belong to is active
- you already tried all the troubleshooting steps mentioned earlier in this thread.

Assuming too that your path is correct, one would think that the query isn't working in your case, as it wasn't in the case of Cevic, and that something needs to be changed to this php/sql query line to get it working for you:
Code: Select all
define("__QUERY__","select * from phplist_message,phplist_list,phplist_listmessage where phplist_list.id=".$_GET['listID']." and phplist_list.id=phplist_listmessage.listid and phplist_message.id=phplist_listmessage.messageid and phplist_list.active=1");

If these assumptions are correct, than these would be the steps you could consider taking to check the validity of the query:
1. First make a full backup of you database
2. Use the online database management tool phpMyAdmin to check whether the default table names of the query are in fact the same as the table names of your database. If not, change the table names in the query to correspond with those of your database.
3. Use phpMyAdmin to test the query: select the phplist database, click on the SQL tab, paste the sql query in the 'Run SQL query/queries on database' window.
Note: For this to work you need to adapt the query to pure SQL first. So the above php/mysql query line would have to be changed to this in the SQL query window:
Code: Select all
select * from phplist_message,phplist_list,phplist_listmessage where phplist_list.id=2 and phplist_list.id=phplist_listmessage.listid and phplist_message.id=phplist_listmessage.messageid and phplist_list.active=1
where _list.id=2 should be changed to correspond with the list ID you are using.

If, in step 3, the database returns the desired list of newsletter/messages, than you just need to adapt the query line in archive.php and it should work. In theory, that is. Hope you will prove me right... :wink: Let me know, as it might help others.
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

A small change

Postby liedekef » 8:12am, Fri 25 Aug, 2006

Hi,

maybe a small improvement: I changed the code a bit to have some newlines between de content and the footer:

$_ROW['message'] . "<br /><br />",
$_ROW['footer']);

instead of just

$_ROW['message'],
$_ROW['footer']);

And while I'm at it: maybe pagination for the archives would be nice, so one only gets a list of eg. 50 messages at a time (instead of eg. the full 300 messages for that list). This should only require a small change in the code (when I find the time today, I'll try to add it)
liedekef
phpList newbie
 
Posts: 2
Joined: 8:07am, Fri 25 Aug, 2006

Archive version with pagination

Postby liedekef » 9:44am, Fri 25 Aug, 2006

Et voila, a change to the archive script to include pagination, see the comments at the top of the script on how to use:

* For pagination: the default pagination is 20, so 20 messages are chown on
* one page. If you want to change this, you can add "&pagerows=xxx" to the
* URL, eg:
* http://www.yoursite.com/phplist/lists/a ... agerows=50

Btw: I also added some simple sanity checks to the _GET variables
Btw2: I changed the layout a bit so the name of the list only gets printed once at the beginning of the message list, instead of before each message

Enjoy, Franky

Code: Select all
<?php  // April 2005 -> PHP (4>=5) PHPlist
/*
* @version $Id: archive.php, v.1.3, 25/08/2006
* @package Contribution to PHPlist 2.10.2
* This is an adapted version that includes Zappu's modifications
* and has been tested with PHPlist 2.10.2.
* Changes in ver. 1.3:
* - added pagination
* - added some sanity checks for _GET variables
********************************************************************
* INSTALLATION:
* FTP this file to your phplist/lists/ directory
* The path info assumes archive.php is placed in the directory
* phplist/lists/
* In that case you must INCLUDE archive.php in the .htaccess file.
*
* USE with this command line:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1
* where: listID is the list you want to display, and LayoutID is the
* Layout you want to use.
* Note that this is the layout of one of your subscribe pages. It is NOT
* the layout of your newsletter template (wich would have been more logical).
* So if necessary, create subscribe pages which only use is that they match the
* header and footer of your newsletter template. Anyway, that was my solution.
* Enjoy, H2B2
*
* For pagination: the default pagination is 20, so 20 messages are chown on
* one page. If you want to change this, you can add "&pagerows=xxx" to the
* URL, eg:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1&pagerows=50
* Enjoy, Franky
********************************************************************
* Previous version info:
* @version $Id: archive.php, v.1.0, 04/09/2005, kalan
* @package Contribution to PHPlist 2.9.3
* @copyright (C) 2005 solutions_PHP, www.solutionsphp.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* support thread: http://www.phplist.com/forums/viewtopic.php?t=1501
********************************************************************
*/


// Include the common configurations for data host, user, password, name.
include("./config/config.php");

// These lines are for Zappu's mod
### I am not sure if all includes are needed, but it works ###
require_once dirname(__FILE__).'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/dutch.inc"; #HW: change this to the language file you use
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";


// Print the head section of our document using Zappu's mod ....
$data = PageData($_GET['layoutID']);

// print('<title>'.$GLOBALS["strForwardTitle"].'</title>');
print('<title>Your Custom Title here </title>');
print($data["header"]);

//some sanitation
if (!(isset($_GET['listID'])) || ($_GET['listID']<1) ) {
   $listID = 2;
} else {
   $listID = intval($_GET['listID']);
}
if (!(isset($_GET['layoutID'])) || ($_GET['layoutID']<1) ) {
   $layoutID = 1;
} else {
   $layoutID = intval($_GET['layoutID']);
}

// Data query
define("__QUERY__","select * from phplist_message,phplist_list,phplist_listmessage where phplist_list.id=".$listID." and phplist_list.id=phplist_listmessage.listid and phplist_message.id=phplist_listmessage.messageid and phplist_list.active=1");

// maximum 20 rows per page
if (!(isset($_GET['pagerows'])) || ($_GET['pagerows']<1) ) {
   $pagerows = 20;
} else {
   $pagerows = intval($_GET['pagerows']);
}

// if pagenum is not set, or lower then one: set it to page 1
if (!(isset($_GET['pagenum'])) || ($_GET['pagenum']<1) ) {
   $pagenum = 1;
} else {
   $pagenum = intval($_GET['pagenum']);
}

// Decide whether to show a list of titles or show a specific message ....
if(!isset($_GET['x'])){

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              if($tmp_res = mysql_query(__QUERY__, $DB)){
             // find the number of rows returned
             $rows = mysql_num_rows($tmp_res);
        // and tell us the pagenumber of the last page
        $last_page = ceil($rows/$pagerows);
        // let the pagenumber not be larger than the last page
        if ($pagenum > $last_page) {
           $pagenum = $last_page;
        }
        // add a limit statement for the sql
        $query = __QUERY__;
        $query .= ' order by sent DESC limit ' .($pagenum - 1) * $pagerows .',' .$pagerows;
        // print the name of the list here, so it doesn't get printed
        // multiple times for each message
        // we only need to fetch one row to know the name
                  $row = mysql_fetch_assoc($tmp_res);
        printf("<br /><h2>".$row['name']."</h2><br />");

                  mysql_free_result($tmp_res);
         }

              if($RS = mysql_query($query, $DB)){
               
                  while($_ROW = mysql_fetch_assoc($RS)){

                 // Print the selected newsletter...
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters. In my case I use layoutID=3 for displaying
                 // the newsletter itself. I still use the command line layoutID
                 // to display the listing of newsletters, which in my case is
                 // layoutID=1

                 // Original code to print the selected newsletter:
                      //printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum."'>%s</a><br /><em>Sent: %s</em><br /><br />",
                      printf("<a href='%s?x=%s&listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum."'>%s</a><br /><em>Sent: %s</em><br /><br />",

                 // Alternative code to print the selected newsletter
                 // with a predefined layoutID:
                     //  printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$_GET['listID']."&layoutID=3' target=_blank>%s</a><br /><em>Sent: %s</em><br /><br />",

                      //stripslashes($_ROW['name']),$_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);
                      $_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);

                  }
                 
                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>No entries were found in the archive.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }

                  mysql_free_result($RS);
                  mysql_close($DB);

        // the first/previous and next/last links
        echo "<br /><br />";
        if ($pagenum != 1) {
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=1'> <<-First</a> ";
           echo " ";
           $previous = $pagenum-1;
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$previous'> <-Previous</a> ";
        }
        if ($pagenum != $last_page) {
           $next = $pagenum+1;
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$next'> Next-></a> ";
           echo " ";
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$last_page'> Last->></a> ";
        }


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);
                 
                  print("<h2>Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }
 
}else{

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              $_QUERY = sprintf("select * from phplist_message where id=%s",intval($_GET['x']));

              if($RS = mysql_query($_QUERY, $DB)){

                  $_ROW = mysql_fetch_assoc($RS);
                 
                 
                 // Re-print the list of selected newsletters after clicking on
                 // the archive link in the header of a displayed newsletter
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters.

                 // Original code to re-print the list of selected newsletters:
                       printf("<div align='left'><br /><a href=./%s?listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum.">&laquo; Archive</a></div>".

                 // Alternative code to re-print the list of selected newsletters
                 // with a predefined layoutID:
                   // printf("<div align='left'>&nbsp;&nbsp;<a href=./%s?listID=".$_GET['listID']."&layoutID=1>&laquo; <b>Archive</b></a></div>".

                         "<h1 align='center'>%s</h1>".
                        // "<br>Sent: %s</em><hr /><br />".
                         "<br /><div align='left'>%s%s</div>",
                         basename($_SERVER['PHP_SELF']),
                         $_ROW['subject'],
                        // $_ROW['sent'],
                         $_ROW['message'] . "<br /><br />",
                         $_ROW['footer']);
                         

                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>Could not retrieve the selected message.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }


                  mysql_free_result($RS);
                  mysql_close($DB);


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);

                  print("<h2>Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }

}

print($html);
// Print our document's footer using Zappu's mod ....
// print("<P>".$GLOBALS["PoweredBy"]."</p>");
print($data["footer"]);
?>
liedekef
phpList newbie
 
Posts: 2
Joined: 8:07am, Fri 25 Aug, 2006

Re: Archive version with pagination

Postby H2B2 » 8:31pm, Fri 25 Aug, 2006

liedekef wrote:Et voila, a change to the archive script to include pagination, see the comments at the top of the script on how to use:

* For pagination: the default pagination is 20, so 20 messages are chown on
* one page. If you want to change this, you can add "&pagerows=xxx" to the
* URL, eg:
* http://www.yoursite.com/phplist/lists/a ... agerows=50

Btw: I also added some simple sanity checks to the _GET variables
Btw2: I changed the layout a bit so the name of the list only gets printed once at the beginning of the message list, instead of before each message

Enjoy, Franky


Hi Franky,

Very nice additions. I'll try them.

Thanks for sharing!

EDIT: Tried it, and it works perfectly!
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Could not retrieve requested information. patch

Postby mp459 » 6:40pm, Thu 05 Oct, 2006

All
I, too, was getting the "could not retrieve information" error. After some digging, I noticed the __QUERY__ was looking for tables with the default table_prefix hardcoded:
Code: Select all
define("__QUERY__","select * from phplist_message, etc


edit: If I head read H2B2's note above, I'd have saved myself some digging. :)

I do not have a table_prefix defined: my tables are message, list, etc (as opposed to phplist_message, phplist_list, etc.) I edited a few lines to change two lines:
around line 80, the new code is:
Code: Select all
// Data query
define("__QUERY__","select * from ".$table_prefix."message,".$table_prefix."list,".$table_prefix."listmessage where ".$table_prefix."list.id=".$listID." and ".$table_prefix."list.id=".$table_prefix."listmessage.listid and ".$table_prefix."message.id=".$table_prefix."listmessage.messageid and ".$table_prefix."list.active=1");

and around line 197:
Code: Select all
$_QUERY = sprintf("select * from ".$table_prefix."message where id=%s",intval($_GET['x']));


The full code:
Code: Select all
<php> PHP (4>=5) PHPlist
/*
* @version $Id: archive.php, v.1.4, 05/10/2006
* @package Contribution to PHPlist 2.10.2
* This is an adapted version that includes Zappu's modifications
* and has been tested with PHPlist 2.10.2.
* Changes in ver. 1.4:
* - changed query to include $table_prefix from config.php, rather than
*   use default phplist_ prefix for tables. -mickey
********************************************************************
* INSTALLATION:
* FTP this file to your phplist/lists/ directory
* The path info assumes archive.php is placed in the directory
* phplist/lists/
* In that case you must INCLUDE archive.php in the .htaccess file.
*
* USE with this command line:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1
* where: listID is the list you want to display, and LayoutID is the
* Layout you want to use.
* Note that this is the layout of one of your subscribe pages. It is NOT
* the layout of your newsletter template (wich would have been more logical).
* So if necessary, create subscribe pages which only use is that they match the
* header and footer of your newsletter template. Anyway, that was my solution.
* Enjoy, H2B2
*
* For pagination: the default pagination is 20, so 20 messages are chown on
* one page. If you want to change this, you can add "&pagerows=xxx" to the
* URL, eg:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1&pagerows=50
* Enjoy, Franky
********************************************************************
* Previous version info:
* @version $Id: archive.php, v.1.0, 04/09/2005, kalan
* @package Contribution to PHPlist 2.9.3
* @copyright (C) 2005 solutions_PHP, www.solutionsphp.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* support thread: http://www.phplist.com/forums/viewtopic.php?t=1501
********************************************************************
*/


// Include the common configurations for data host, user, password, name.
//include("./config/config.php");
include_once dirname(__FILE__)."/config/config.php";

// These lines are for Zappu's mod
### I am not sure if all includes are needed, but it works ###
require_once dirname(__FILE__).'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/dutch.inc"; #HW: change this to the language file you use
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";


// Print the head section of our document using Zappu's mod ....
$data = PageData($_GET['layoutID']);

// print('<title>'.$GLOBALS["strForwardTitle"].'</title>');
print('<title>Your Custom Title here </title>');
print($data["header"]);

//some sanitation
if (!(isset($_GET['listID'])) || ($_GET['listID']<1) ) {
   $listID = 2;
} else {
   $listID = intval($_GET['listID']);
}
if (!(isset($_GET['layoutID'])) || ($_GET['layoutID']<1) ) {
   $layoutID = 1;
} else {
   $layoutID = intval($_GET['layoutID']);
}

// Data query
define("__QUERY__","select * from ".$table_prefix."message,".$table_prefix."list,".$table_prefix."listmessage where ".$table_prefix."list.id=".$listID." and ".$table_prefix."list.id=".$table_prefix."listmessage.listid and ".$table_prefix."message.id=".$table_prefix."listmessage.messageid and ".$table_prefix."list.active=1");

// maximum 20 rows per page
if (!(isset($_GET['pagerows'])) || ($_GET['pagerows']<1) ) {
   $pagerows = 20;
} else {
   $pagerows = intval($_GET['pagerows']);
}

// if pagenum is not set, or lower then one: set it to page 1
if (!(isset($_GET['pagenum'])) || ($_GET['pagenum']<1> $last_page) {
           $pagenum = $last_page;
        }
        // add a limit statement for the sql
        $query = __QUERY__ ;
        $query .= ' order by sent DESC limit ' .($pagenum - 1) * $pagerows .',' .$pagerows;
        // print the name of the list here, so it doesn't get printed
        // multiple times for each message
        // we only need to fetch one row to know the name
                  $row = mysql_fetch_assoc($tmp_res);
        printf("<br><h2>".$row['name']."</h2><br>");

                  mysql_free_result($tmp_res);
         }

              if($RS = mysql_query($query, $DB)){
               
                  while($_ROW = mysql_fetch_assoc($RS)){

                 // Print the selected newsletter...
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters. In my case I use layoutID=3 for displaying
                 // the newsletter itself. I still use the command line layoutID
                 // to display the listing of newsletters, which in my case is
                 // layoutID=1

                 // Original code to print the selected newsletter:
                      //printf("<br><h2>%s</h2><a>%s</a><br><em>Sent: %s</em><br><br>",
                      printf("<a>%s</a><br><em>Sent: %s</em><br><br>",

                 // Alternative code to print the selected newsletter
                 // with a predefined layoutID:
                     //  printf("<br><h2>%s</h2><a>%s</a><br><em>Sent: %s</em><br><br>",

                      //stripslashes($_ROW['name']),$_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);
                      $_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);

                  }
                 
                  if(mysql_num_rows($RS)<=0){
                      print("<br><h2>No entries were found in the archive.</h2><br><br><a>&laquo; Back</a>");
                  }

                  mysql_free_result($RS);
                  mysql_close($DB);

        // the first/previous and next/last links
        echo "<br><br>";
        if ($pagenum != 1) {
           echo " <a> <<-First</a> ";
           echo " ";
           $previous = $pagenum-1;
           echo " <a> <-Previous</a> ";
        }
        if ($pagenum != $last_page) {
           $next = $pagenum+1;
           echo " <a> Next-></a> ";
           echo " ";
           echo " <a> Last->></a> ";
        }


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);
                 
                  print("<h2> Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }
 
}else{

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              $_QUERY = sprintf("select * from ".$table_prefix."message where id=%s",intval($_GET['x']));

              if($RS = mysql_query($_QUERY, $DB)){

                  $_ROW = mysql_fetch_assoc($RS);
                 
                 
                 // Re-print the list of selected newsletters after clicking on
                 // the archive link in the header of a displayed newsletter
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters.

                 // Original code to re-print the list of selected newsletters:
                       printf("<div><br><a>&laquo; Archive</a></div>".

                 // Alternative code to re-print the list of selected newsletters
                 // with a predefined layoutID:
                   // printf("<div>&nbsp;&nbsp;<a>&laquo; <b>Archive</b></a></div>".

                         "<h1>%s</h1>".
                        // "<br>Sent: %s</em><hr><br>".
                         "<br><div>%s%s</div>",
                         basename($_SERVER['PHP_SELF']),
                         $_ROW['subject'],
                        // $_ROW['sent'],
                         $_ROW['message'] . "<br><br>",
                         $_ROW['footer']);
                         

                  if(mysql_num_rows($RS)</h2>


Hope this helps.

-mickey
mp459
PL Nut
 
Posts: 20
Joined: 4:52pm, Thu 14 Sep, 2006
Location: USA/DC

Postby mp459 » 9:16pm, Thu 05 Oct, 2006

OK, sorry to spam the thread with more updates, but I added some more functionality. Now you can include some summary text in your newsletter (In an HTML comment, as stated in the instructions), and it will show up in your archive list. This helps us out because we name our newsletters by Month, and godo luck remembering if some item is in the November 2005 or August 2006 newsletter!
To use it, add this to your newsletter:

Code: Select all
<Summary>
IN THIS ISSUE:
LETTER FROM THE EXECUTIVE DIRECTOR
HOW CAN YOU HELP
TIPS (ACCOUNTING, PR)
LEGAL LESSONS
STRATEGIES FOR SUCCESS
FEATURED PARTNERS, CLIENTS, VOLUNTEERS
</Summary>

The first and last line have to be verbatim wha they are above. The summary text will, of course, change.
Right now, the summary text is presented as preformated text. If you choose to use HTML in your summary text, follow the instructions to remove the preformated text tags.

I hope someone finds this useful :)
Code: Select all
<?php  // April 2005 -> PHP (4>=5) PHPlist
/*
* @version $Id: archive.php, v.1.5, 05/10/2006
* @package Contribution to PHPlist 2.10.2
* This is an adapted version that includes Zappu's modifications
* and has been tested with PHPlist 2.10.2.
* Changes in ver. 1.5:
* - added  summary capability.
********************************************************************
* INSTALLATION:
* FTP this file to your phplist/lists/ directory
* The path info assumes archive.php is placed in the directory
* phplist/lists/
* In that case you must INCLUDE archive.php in the .htaccess file.
*
* USE with this command line:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1
* where: listID is the list you want to display, and LayoutID is the
* Layout you want to use.
* Note that this is the layout of one of your subscribe pages. It is NOT
* the layout of your newsletter template (wich would have been more logical).
* So if necessary, create subscribe pages which only use is that they match the
* header and footer of your newsletter template. Anyway, that was my solution.
* Enjoy, H2B2
*
* For pagination: the default pagination is 20, so 20 messages are chown on
* one page. If you want to change this, you can add "&pagerows=xxx" to the
* URL, eg:
*     http://www.yoursite.com/phplist/lists/archive.php?listID=2&layoutID=1&pagerows=50
* Enjoy, Franky
*******************************************************************
To use summary capability:
Include an area in your newsletter that starts with
<Summary>
and ends with
</Summary>

I enclose this in HTML comment tags <!-- and --> if I don't want
to display the summary in the newsletter.

The main page will display everything between these lines, as <pre>
formatted text.  If you care to include html in your summary, remove the
<pre> tags (printf("<pre">; and printf("</pre>") ).
Note that this is not the most efficient way of doing this, since
the snippet code calls the URL that displays the newsletter, rather
than grabbing it directly from the database.  The snippet script
comes courtesy of phpbuilder, with some changes.
********************************************************************
* Previous version info:
* @version $Id: archive.php, v.1.0, 04/09/2005, kalan
* @package Contribution to PHPlist 2.9.3
* @copyright (C) 2005 solutions_PHP, www.solutionsphp.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* support thread: http://www.phplist.com/forums/viewtopic.php?t=1501
********************************************************************
*/


// Include the common configurations for data host, user, password, name.
//include("./config/config.php");
include_once dirname(__FILE__)."/config/config.php";

// These lines are for Zappu's mod
### I am not sure if all includes are needed, but it works ###
require_once dirname(__FILE__).'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/dutch.inc"; #HW: change this to the language file you use
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";


// Print the head section of our document using Zappu's mod ....
$data = PageData($_GET['layoutID']);

// print('<title>'.$GLOBALS["strForwardTitle"].'</title>');
print('<title>Archives. </title>');
print($data["header"]);

//some sanitation
if (!(isset($_GET['listID'])) || ($_GET['listID']<1) ) {
   $listID = 2;
} else {
   $listID = intval($_GET['listID']);
}
if (!(isset($_GET['layoutID'])) || ($_GET['layoutID']<1) ) {
   $layoutID = 1;
} else {
   $layoutID = intval($_GET['layoutID']);
}

// Data query
define("__QUERY__","select * from ".$table_prefix."message,".$table_prefix."list,".$table_prefix."listmessage where ".$table_prefix."list.id=".$listID." and ".$table_prefix."list.id=".$table_prefix."listmessage.listid and ".$table_prefix."message.id=".$table_prefix."listmessage.messageid and ".$table_prefix."list.active=1");

// maximum 20 rows per page
if (!(isset($_GET['pagerows'])) || ($_GET['pagerows']<1) ) {
   $pagerows = 20;
} else {
   $pagerows = intval($_GET['pagerows']);
}

// if pagenum is not set, or lower then one: set it to page 1
if (!(isset($_GET['pagenum'])) || ($_GET['pagenum']<1) ) {
   $pagenum = 1;
} else {
   $pagenum = intval($_GET['pagenum']);
}

// Decide whether to show a list of titles or show a specific message ....
if(!isset($_GET['x'])){

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){
              if($tmp_res = mysql_query(__QUERY__, $DB)){
             // find the number of rows returned
             $rows = mysql_num_rows($tmp_res);
        // and tell us the pagenumber of the last page
        $last_page = ceil($rows/$pagerows);
        // let the pagenumber not be larger than the last page
        if ($pagenum > $last_page) {
           $pagenum = $last_page;
        }
        // add a limit statement for the sql
        $query = __QUERY__ ;
        $query .= ' order by sent DESC limit ' .($pagenum - 1) * $pagerows .',' .$pagerows;
        // print the name of the list here, so it doesn't get printed
        // multiple times for each message
        // we only need to fetch one row to know the name
                  $row = mysql_fetch_assoc($tmp_res);
//mickey: remove this (this prints the name of the list)
        //printf("<br /><h2>".$row['name']."</h2><br />");
printf("<br /><h2>News Archives.</h2><br />");

                  mysql_free_result($tmp_res);
         }

              if($RS = mysql_query($query, $DB)){
               
                  while($_ROW = mysql_fetch_assoc($RS)){

                 // Print the selected newsletter...
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters. In my case I use layoutID=3 for displaying
                 // the newsletter itself. I still use the command line layoutID
                 // to display the listing of newsletters, which in my case is
                 // layoutID=1

                 // Original code to print the selected newsletter:
                      //printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum."'>%s</a><br /><em>Sent: %s</em><br /><br />",
                      printf("<a href='%s?x=%s&listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum."'>%s</a><br /><em>Sent: %s</em><br /><br />",

                 // Alternative code to print the selected newsletter
                 // with a predefined layoutID:
                     //  printf("<br /><h2>%s</h2><a href='%s?x=%s&listID=".$_GET['listID']."&layoutID=3' target=_blank>%s</a><br /><em>Sent: %s</em><br /><br />",

                      //stripslashes($_ROW['name']),$_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);
                      $_SERVER['PHP_SELF'],$_ROW['messageid'],$_ROW['subject'],$_ROW['sent']);

// mickey: print a snippet of the newsletter
printf("<pre>");
$fromURL="http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?x=".$_ROW['messageid']."&listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum;
$baseURL="http://".$_Server['SERVER_NAME'] ;
  includeFrom( $fromURL,
               $baseURL,
               "<Summary>",
               "</Summary>",
               TRUE );
printf("</pre><br />");

                  }
                 
                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>No entries were found in the archive.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }

                  mysql_free_result($RS);
                  mysql_close($DB);

        // the first/previous and next/last links
        echo "<br /><br />";
        if ($pagenum != 1) {
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=1'> <<-First</a> ";
           echo " ";
           $previous = $pagenum-1;
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$previous'> <-Previous</a> ";
        }
        if ($pagenum != $last_page) {
           $next = $pagenum+1;
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$next'> Next-></a> ";
           echo " ";
           echo " <a href='{$_SERVER['PHP_SELF']}?&listID={$listID}&layoutID={$layoutID}&pagerows={$pagerows}&pagenum=$last_page'> Last->></a> ";
        }


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);
                 
                  print("<h2> Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }
 
}else{

           if($DB = mysql_connect($database_host, $database_user, $database_password)){

             if(mysql_select_db($database_name)){

              $_QUERY = sprintf("select * from ".$table_prefix."message where id=%s",intval($_GET['x']));

              if($RS = mysql_query($_QUERY, $DB)){

                  $_ROW = mysql_fetch_assoc($RS);
                 
                 
                 // Re-print the list of selected newsletters after clicking on
                 // the archive link in the header of a displayed newsletter
                 // Note: the original line of code will take the layoutID from
                 // the command line.
                 // I prefer using the alternative code line where the layoutID
                 // is predefined, because I need the page displaying the
                 // listing of newsletters to be in a different layout than
                 // the newsletters.

                 // Original code to re-print the list of selected newsletters:
                       printf("<div align='left'><br /><a href=./%s?listID=".$listID."&layoutID=".$layoutID."&pagerows=".$pagerows."&pagenum=".$pagenum.">&laquo; Archive</a></div>".

                 // Alternative code to re-print the list of selected newsletters
                 // with a predefined layoutID:
                   // printf("<div align='left'>&nbsp;&nbsp;<a href=./%s?listID=".$_GET['listID']."&layoutID=1>&laquo; <b>Archive</b></a></div>".

                         "<h1 align='center'>%s</h1>".
                        // "<br>Sent: %s</em><hr /><br />".
                         "<br /><div align='left'>%s%s</div>",
                         basename($_SERVER['PHP_SELF']),
                         $_ROW['subject'],
                        // $_ROW['sent'],
                         $_ROW['message'] . "<br /><br />",
                         $_ROW['footer']);
                         

                  if(mysql_num_rows($RS)<=0){
                      print("<br /><h2>Could not retrieve the selected message.</h2><br /><br /><a href='javascript:history.back();'>&laquo; Back</a>");
                  }


                  mysql_free_result($RS);
                  mysql_close($DB);


               }else{

                  mysql_free_result($RS);
                  mysql_close($DB);

                  print("<h2>I Could not retrieve requested information.</h2>");
                  exit(0);

               }
            }else{
                mysql_close($DB);
                print("<h2>Could not select database.</h2>");
            }
         }else{
             print("<h2>Could not connect to database.</h2>");
         }

}

print($html);
// Print our document's footer using Zappu's mod ....
// print("<P>".$GLOBALS["PoweredBy"]."</p>");
print($data["footer"]);

//Mickey: summary snippet functions:

  function addBase( $baseUrl, $code )
  {
        // This is a very naive implementation, it doesn't properly
        // parse the "img" tag, but only looks for the string
        // '<img src="' - if the 'src' element comes somewhere else
        // within the tag, or if the filename it points to isn't
        // in double-quotes, this routine won't catch it.
        // Also this routine is chock full of magic numbers.  Whooop.
    $pCode = $code; $index = 0;
    while( $index < strlen( $code ) )
    {
      $srcPos = strpos( $pCode, "<img src=\"", $index );
      if( $srcPos != false )
      {
        // check for a ":" in the first 7 characters after 'src=', in which
        // case it's already a URL
        $colonStr = strpos( $pCode, ":", $srcPos );
        $subStrLen = $srcPos + 10 - $index; // 10 = size of "<img src="" string.
        echo( substr( $pCode, $index, $subStrLen) );
        $index += $subStrLen;
        if( ($colonStr < 12) || ($colonStr > 16) || ($colonStr === false) )
            // somewhat arbitrary
        {
          // modify the string by adding the $baseUrl
          echo( $baseUrl );
        }
      }
      else
      {
        $subStrLen = strlen( $code ) - $index;
        echo( substr( $pCode, $index, $subStrLen) );
        $index = strlen( $code );
      }
    }
  }

  function report( $message, $report )
  {
    if( $report != FALSE )
      echo( $message );
  }

  function includeFrom( $fromUrl, $baseUrl, $startString, $endString, $report )
  // $fromUrl - URL to read from, e.g. "http://foo.bar.com/index.html"
  // $baseUrl - Base to apply to local resources, e.g. "http://foo.bar.com/"
  // $startString - String before content you want to include
  // $endString - String after content you want to include
  // $report - "FALSE" if you don't want includeFrom() to insert error
  //           reporting into the output; errors will just cause no output
  {
    $fd = fopen( $fromUrl, "r" );

    if( $fd != FALSE )
    {
        $fr = '';
        while ( !feof($fd) ) {
          $fr .= fread( $fd, 8192 );
        }
       fclose( $fd );
      if ($fr) {
        //$start = strpos( $fr, $startString ) + strlen($startString);
        $start = strpos( $fr, $startString ) ;
        $finish = strpos( $fr, $endString ); // - strlen($endString);
       if( ($start != FALSE) && ($finish != FALSE) )
        {
          $start += strlen($startString);
          $length = $finish - $start;
          $code = Substr( $fr, $start, $length );
// if you don't want to get fancy, use echo( $code ) instead of addBase()
          addBase( $baseUrl, $code );
        }
        else
        report( "<! delimiter not found in $fromUrl >", $report );
      }
      else
        report( "<! could not read data from $fromUrl >", $report );
    }
    else
      report( "<! could not open $fromUrl >", $report );
  }

?>


-mickey
mp459
PL Nut
 
Posts: 20
Joined: 4:52pm, Thu 14 Sep, 2006
Location: USA/DC

PreviousNext

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

Who is online

Users browsing this forum: No registered users and 0 guests