[pmwiki-devel] Strange keywords and description behavior...

The Editor editor at fast.st
Thu Apr 5 09:22:21 CDT 2007


On 4/5/07, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Thu, Apr 05, 2007 at 08:14:20AM -0400, The Editor wrote:
> > Second post.  Quite strange...
>
> While we do indeed invite people to re-post questions that haven't
> received an answer, it would probably be good etiquette to wait at
> least 24 hours (and 36 or 48 hours is probably better) for an answer
> before reposting...

Oops.  Didn't realize my first post was so recent.  Guess I'm spoiled.
Or just impatient.  Sorry.  : )

> > [Fourteen hours earlier] The Editor <editor at fast.st> wrote:
> > > I'm noticing some rather buggy behavior after all with the new ZAP
> > > attr extensions.  Can't explain.
> > > ...
> > > Heres' the critical two lines....
> > >
> > > if (strpos($newpage[text], "(:$attr ")) $newpage['text'] =
> > > preg_replace('/\\(\\:'.$attr.'(.*?)\\:\\)/s', "(:$attr $value:)",
> > > $newpage['text']);
> > > else $newpage['text'] = $newpage['text'] . "\n(:$attr $value:)";
>
> I think the error must be somewhere other than these lines of code.
>
>  - if the page source begins with "(:$attr ", then strpos(...) will
>   return zero, the "if" condition will fail, and a second copy
>   will get added to the list.  When using strpos() to test existence
>   of a substring, always check the return value against "false".

Fixed.  But it's not the problem as the code is farther down the page.

>  - The quotes are missing around "text" in "$newpage[text]"

Why would I want quotes here?

>  - You probably don't want the /s option on the preg_replace pattern,
>   as this causes .*? to match newlines.

Ok.  Still don't understand all the flags perfectly.  Thanks.

>  - Because there's no required space in the preg_match pattern,
>   it will replace anything beginning with "(:$attr".  For example,
>   (:zap attr_title:) would end up replacing anything that
>   begins with "(:title", including (:titlespaced:), (:titledict:),
>   (:titlexyz:), etc.

Oh, good point.

>  - The colons in the preg_replace pattern don't need backslashes
>   (although it shouldn't hurt).

Since I can remember, I just escape anything questionable...  : )

> But none of these would seem to explain the results you're seeing,
> which is why I think the error has to be somewhere other than these
> lines of code.

Ok, I reposted the whole functon below.  Again, as far as I can tell,
the changes are made to the page code exactly as desired.  But when
the page updates, PmWiki is not making the changes properly to the
page attributes.  My guess is it is because ZAP is running this
routine three times, once for each attribute, and perhaps some page
cache or something is confusing PmWiki.

Basically the function is called everytime ZAP encounters a field like

(:zap attr_title="My title":)
(:zap attr_keywords="Good, Bad, Ugly":)
(:zap attr_description="This is my page.":)

keywords always doubles, triples, things.  Description always throws
%0a's in (breaking input markup).  I've tried changing the order of
the commands to see if it was a 1st, 2nd, 3rd problem but no change.
Title works fine wherever!

function ZAPXattr($value, $field) {
	global $m, $ZAParray;
	$value = trim($value);
	$attr = substr($field, strpos($field, "_") + 1);
	$oldpage = ReadPage($ZAParray['datapage']);
	$newpage = $oldpage;
	if ((CondAuth($ZAParray['datapage'], "attr")) && (substr($attr, 0, 6)
== 'passwd')) {
		$newpage[$attr] = $value;
		$m .= "Passwords have been updated. ";
		UpdatePage($ZAParray['datapage'], $oldpage, $newpage);
		return $value;
		}
    if (($attr == 'title') || ($attr == 'keywords') || ($attr ==
'description')) {
		if (strpos($newpage[text], "(:$attr ") == false) $newpage['text'] =
preg_replace('/\\(:'.$attr.' (.*?):\\)/s', "(:$attr $value:)",
$newpage['text']);
		else $newpage['text'] = $newpage['text'] . "\n(:$attr $value:)";
		$m .= "Page information has been updated. ";
		UpdatePage($ZAParray['datapage'], $oldpage, $newpage);
		return $value;
		}
	$m .= "Page attributes could not be reset. ";
	return $value;
	}

Here's the ZAPform for what it's worth.

(:messages:)
(:zapform:)
(:input text title "{(attr title)}":)
(:input text keywords "{(attr keywords)}":)
(:input text description "{(attr description)}":)
(:zap attr_description="{description}":)
(:zap attr_keywords="{keywords}":)
(:zap attr_title="{title}":)
(:input submit:)
(:zapend:)

||Title:       ||{(attr title)}
||Keywords:    ||{(attr keywords)}
||Description: ||{(attr description)}

I would post the {( )} markup code, but I don't think the problem is
there. It's basically reporting what's actually there in the page
text.  IE:

ctime=1175593257
description={description}%0a{description}%0a{description}
host=127.0.0.1
keywords=2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
name=Test.Attr

etc.

Oh, if you continue resaving, the problem compounds geometrically!
Very strange.

Cheers,
Dan



More information about the pmwiki-devel mailing list