[pmwiki-users] Re: newwin with defined size

Joachim Durchholz jo at durchholz.org
Tue Jul 5 15:34:10 CDT 2005


Albi Rebmann wrote:

>> A custom markup could look like the following:
>>
>> Markup('newwin', 'directives', '/\\(:newwin(.*?):\\)/e',
>>        "newwin(PSS('$1'))");
>>
>> function newwin($args) {
>>   $defaults = array('height' => 480, 'width' => 640, 'title' => '',
>>                     'text' => '');
>>   $args = array_merge($defaults, ParseArgs($args));
>>   $link = array_pop($args['']);
 >> [...]
> 
> Thanks very much. But I get some error using it:
> 
> Warning: array_pop(): The argument should be an array in 
> .../local/config.php on line 173

That's probably because you used (:newwin:), without any parameters.

Since it's bad practice to emit PHP errors if the user mistyped the 
markup, I suggest changing the markup so that it will be ignored until 
it has at least one parameter, like so:

 >> Markup('newwin', 'directives', '/\\(:newwin\s+(.+?):\\)/e',
                                               ^^^  ^
 >>        "newwin(PSS('$1'))");

The \s+ requires a nonempty sequence of blank-space character, and the + 
makes the regular expression want at least one character after that 
sequence - the net result is that ParseArgs will find at least one 
parameter and fill $args[''] with at least one array entry.

Note that I strongly advise against popping up windows anyway. It's 
annoying to people who want to open the window in a tab (instead of in a 
new window), for example - the link to the photo would ignore the new 
tab and open a new window anyway. It will also exclude those users who 
have disabled Javascript for security reasons (as Yours Truly has).

If you absolutely must have Javascript, I suggest setting up normal 
links, and let the Javascript replace them with JS links that will open 
the pop-up. This way, the site will remain functional for people who 
don't want or can't have JS while retaining advanced functionality for 
those who have JS.

Regards,
Jo



More information about the pmwiki-users mailing list