[pmwiki-users] Great pagelist question...

The Editor editor at fast.st
Wed Aug 30 07:44:14 CDT 2006

Hi Pm

Before giving you the information you requested I do have one
suggestion first.  Would it be possible to modify the pagelist script
so that any text surrounded by some special character (in my example
below, "^") would process the markup table for the enclosed text
immediately (or even a specific part of it) as it is iterated? For
example, inserting a line (I'm guessing around line 353) that says
something like the following (in common English):

if (line contains "^") PRR(substr(1st ^, 2nd ^, line));

Then in the pagelist format you could use below. Just a thought. If it
would cause too many problems (divs, tables, etc), is there some way
you could set it so it only processes a certain section of the markup
table?  ie from # $[phrase] substitutions to # {$var} substitutions?
That's all I really need--for both the directive and the page

^(:data {=$FullName} :)^
* [[{=$FullName}|^{$DataValue}^]]

For something like this I don't even mind hacking my core, though it
might be better to make this a core feature so others could use also.

After thinking about it more though, parameterizing $DataValue may be
the best way to go, though I'm not sure exactly what you mean by it.
I take it you are saying we can somehow set the page variables as an
array based on Group.Name.  (Actually this is a MUCH better--as it
allows much greater flexibility).

Here's the way the (:data Group.Name:) markup works:  (I included the
actual function below).

1).  It retrieves the page contents from Data-Group.Name, a specially
constructed wiki page.
2).  It parses the page contents to return a series of field="value"; pairs.
3).  It sets page variables for each of these pairs so {$field}
returns "value" in the page.
4).  Since it is processed just before the page variables, they are
all changed in the page immediately thereafter.

Now the problem as I see it is this:  when the pagelist is processed
it first returns something like this, and then sends it to PRR:

(:data Group.Page1 :)
* [[{$FullName1}|{$DataValue}]]
(:data Group.Page2 :)
* [[{$FullName2}|{$DataValue}]]
(:data Group.Page3 :)
* [[{=$FullName3}|{$DataValue}]]

When sent to PRR, it runs the (:data:) markup three times, resetting
$DataValue each time, and then it replaces all three instances of the
page variable with it's current value.  At least that seems to be the
exact results I'm getting.

To fix it, by parameterize {$DataValue} you are suggesting we add some
kind of array to the page variables based on Group.Name. Maybe all it
would take is putting a flag in the (:data:) markup like the following

(:data =Group.Page:)

Then in the function add near beginning
if ($l begins with =) set parameter flag, strip off =  // so only used
when needed

Then at end of function,
if parameter flag, set page variables parameterized
else set page variables normal way.

If I'm on the right track, then the pagelist template might look
something like the following

(:data ={=$FullName} :)
* [[ {=$FullName} | {$DataValue[{$FullName}]} ]]   // can you put one
page var in another?

I'm just trying to think this through. I'm open to any suggestion you
have to offer.  Thanks for taking the time to read this and for your
help.  I pasted the entire function below with extra commenting.


(:data Group.Name:)
# Directive to retrieve data from another page
Markup('fastdata', '<{$var}', '/\(:data(.*?):\)/ei', "ReadData('$1')");

# Function called by directive to retrieve form data
function ReadData($l) {
	global $WorkDir, $FmtPV, $pagename;
	$passcode = "";  // allows an optional required passcode to read data
	if (($passcode == "") and ($l == "")) $l = " " . $pagename;  // allows (:data:)
	if (($passcode != "") and (substr($l,
strlen($l)-strlen($passcode)-1)) != "|$passcode") return "data access
	if ($passcode != "") $l = substr($l, 0, strlen($l)-strlen($passcode)-1);
	$r1 = array('%',"\n");
	$r2 = array('%25','%0a');
    $datapage = "Data-" . substr($l, 1);  // sets the real data retrieval page
	if (substr($datapage, -2, 2) == ".*") {   //special case (Group.*)
for certain uses
		$name = explode(".", $pagename);
		$datapage = substr($datapage,0,strlen($datapage)-1) . $name[1];
	if (PageExists("$datapage")) {
		$dr = fopen("$WorkDir/$datapage", "rb");
		$pc = fread($dr, filesize("$WorkDir/$datapage"));  // pc = page content
		$dc = explode("(:comment data:) %0a%0a", $pc);  // dc = data content
		$db = explode(" %0a%0a", $dc[1]);  // db = data bits  :)
		$i = 0;
		while ($i < count($db)-1) {  // can't recall why didn't use foreach...
			$dv = explode ("=", $db[$i]); // separates field from value
			$value = stripslashes("$dv[1]");
			$value = str_replace($r2, $r1, $value);
			$FmtPV["$$dv[0]"] = $value;  // sets page variables
			$i = $i + 1;
	return "data not found";

On 8/29/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Tue, Aug 29, 2006 at 04:35:11PM -0400, The Editor wrote:
> > Thanks PM!  That did give me some results.  Apologize for the dumb
> > mistake.  But evidently, the markup table is run after the entire
> > pagelist is constructed.  What I really need is to be able to
> > reprocess it for each item in the pagelist.
> Can't do it.  Divs, lists, and tables wouldn't work, since any
> such things would be closed after processing each item.
> > {$DataValue} is a Page Variable set when the (:data:) directive is
> > run.  With the forum end on there, the last data value is returned for
> > every item in the list.  What I really want is the data value specific
> > for each item in the list.
> Then you have to have {$DataValue} be able to work on a per-page
> basis.  In particular, $FmtPV['$DataValue'] needs to obtain its
> data based on the values in the $page array or based on $group + $name.
> Send me the excerpt that is getting the value for {$DataValue}
> now, and I'll see if I can parameterize it.
> Pm
> > On 8/29/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> > >On Tue, Aug 29, 2006 at 03:36:45PM -0400, The Editor wrote:
> > >> I have a great pagelist question.
> > >>
> > >> When creating the FAST Data project I had one idea in mind that I was
> > >> hoping would be possible.  Now that I'm well into application of the
> > >> recipe I finally came up to this question.
> > >>
> > >> How is it possible to do something like the following in a pagelist
> > >template
> > >>
> > >> [[#forum]]
> > >> (:data {=$FullName} :)
> > >> * [[{=$FullName}|{=$DataValue}]]
> > >> [[#forum]]
> > >>
> > >> The data directive is normally processed before pagelists are done
> > >> (just before page variables actually), so I guess there would have to
> > >> be someway to call the markup table in the pagelist.
> > >
> > >Pagelist already calls the markup table, once for each entry
> > >in the list.  But you probably want [[#forumend]] for the second
> > >anchor.
> > >
> > >Beyond that, I can't really say what will happen because I don't
> > >understand or know the definition of {$DataValue}.
> > >
> > >Pm
> > >
> >

More information about the pmwiki-users mailing list