You have a function placed inside another function, so when the outer function is called for a second time, it tries to redefine the inner function again. This is forbidden, and if you check your error log, you will see something like:

  Fatal error: Cannot redeclare UR_exists() (previously declared
  in popbox.php:173) in popbox.php on line 173

Just place the UR_exists(){...} function before or after the PopBox(){...} function.

Petko

On 09/11/2019 10:20, Philippe Krait wrote:
Hi,

I have a very bizarre side effect from a custom markup, and the most
bizarre is that it is a "new" problem in the sense that it has worked
in the past (I can't remember under which PmWiki version it worked
last, though).

The bizarre thing is that when, on a page, I invoke the custom markup
the second time, it prevents the save from working, the page stays
blank and does not reload. I am pretty sure that this is the cause,
because I went to some very old pages with the markup, and the pages
with only one instance of the markup load perfectly, but old pages
with two or more instances of the markup do not load anymore !

I have no idea what might be causing this as I am not that good at
programming and at PHP in particular, but I have copied the code of
the recipe below. My apologies for the probably very badly written
code.

Note that it's based on this:
http://ajaxian.com/archives/popbox-a-javascript-image-magnifier but I
am not sure how it's relevant to the issue... Note that I am using a
very old version of the script, do you think it might be the reason ?

Can anyone please help me solve this mystery ?

Thanks in advance,

Philippe

========================================================

<?php if (!defined('PmWiki')) exit();
/*  Copyright 2010 Philippe Krait (phili...@krait.net)

    This script activates the (:popbox ...:) markup.

    To activate this script, copy it into the cookbook/ directory,
    then add the following line to your local/config.php:

        include_once('cookbook/popbox.php');
*/

# Creates the Markup
#Markup('popbox','fulltext', '/\\(:popbox(\\s.*?)?:\\)/e',
"Keep(PopBox(PSS('$1')))");
Markup_e('popbox','fulltext', '/\\(:popbox(\\s.*?)?:\\)/',
"Keep(PopBox(\$m[1]))");

# Defines where the javascript, css and images are
SDV($popBoxDirUrl,$PubDirUrl."/cookbook/popBox");

SDV($HTMLHeaderFmt['popboxjava'] , "<script
src='$popBoxDirUrl/scripts/PopBox.js' type='text/javascript'></script>
<script type='text/javascript'>
popBoxWaitImage.src = '$popBoxDirUrl/images/spinner40.gif';
popBoxRevertImage = '$popBoxDirUrl/images/magminus.gif';
popBoxPopImage = '$popBoxDirUrl/images/magplus.gif';
</script>");

function PopBox($attr) {
$EnablePathInfo = 1;

$attr = preg_replace('/ *([a-zA-Z]=)([^\']\\S*)/',"&\$1\$2",$attr);
$attr = substr($attr,1);
$el = explode("&", $attr);

$Header = "";
$Tailer = "";

$Img =
"http://".$_SERVER['SERVER_NAME']."/pmwiki/uploads/Main/Images/Unknown.jpg";
$ImgPath = "";
$ImgDir =
"http://".$_SERVER['SERVER_NAME']."/pmwiki/uploads/Main/Images";
$ImgType = "";
$ImgName = "";
$ImgFormat = "jpg";

$size = 250;
$title = 'Click to magnify/shrink';
$caption = 'Caption';
$align = '';
# $command = 'onmouseover';
$command = 'onclick';

$startX = "startpos.x";
$startY = "startpos.y";
# The newLeft and newTop parameters are treated by default as
positions relative to the image starting point and can be either a
negative or positive number.
# If either value is a numeric string followed by an upper case "A"
then it is treated as an absolute position, relative to its containing
element (typically the browser window).
# Ex: "200A". If either value is null the image will be centered in
the browser window.
$endX = "null";
$endY = "null";

$startW = "startpos.w";
$startH = "startpos.h";
# If the newWidth value is 0 the full width of the image will be used
up to a maximum of the browser window width.
# If the newWidth value is  null the full size of the image will be
used regardless of the browser window width.
# Passing either 0 or null will still scale the image against the
image height. An integer greater than 0 will not be scaled.
$endW = 0;
# If the newHeight value is 0 the full height of the image will be
used up to a maximum of the browser window height.
# If the newHeight value is  null the full size of the image will be
used regardless of the browser window height.
# Passing either 0 or null will still scale the image against the
image width. An integer greater than 0 will not be scaled.
$endH = 0;

$sM = 100;
$sS = 100;

$RevertBarAbove = "true";
$CaptionBelow = "true";

$Style = "PopBoxImageLarge";

foreach ($el as $k => $v) {
$cpl = explode("=", $v);
switch ($cpl[0]) {
case "A":
case "a":

global $pagename, $UploadUrlFmt, $EnablePathInfo;

$attpage = $pagename;
$path = str_replace(array('"', ' '), array('', '%20'), $cpl[1]);

if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
$attpage = MakePageName($attpage, $match[1]);
$path = $match[2];
}

# if ($EnablePathInfo)
$attpage=str_replace(".", "/", $attpage);

#echo $EnablePathInfo."<br>\n";
#echo $UploadUrlFmt."<br>\n";
#echo $attpage."<br>\n";
#echo $path."<br>\n";

$ImgPath = FmtPageName("$UploadUrlFmt/$attpage/$path", $attpage);
#echo $ImgPath."<br>\n";
break;
case "I":
case "i":
$ImgPath = str_replace(array('"', ' '), array('', '%20'), $cpl[1]);
break;
case "T":
case "t":
$ImgType = str_replace('"', '', $cpl[1]);
break;
case "N":
case "n":
$ImgName = str_replace(array('"', ' '), array('', '%20'), $cpl[1]);
break;
case "F":
case "f":
$ImgFormat = str_replace('"', '', $cpl[1]);
break;
case "S":
case "s":
$size = str_replace('"', '', $cpl[1]);
break;
case "C":
case "c":
$caption = str_replace('"', '', $cpl[1]);
break;
case "P":
case "p":
$assignformat=array( "lfloat" => "lfloat", "rfloat" => "rfloat",
"lframe" => "lfloat frame", "rframe" => "rfloat frame",
"lfloatclear" => "lfloat lclear", "rfloatclear" => "rfloat rclear",
"lframeclear" => "lfloat frame lclear", "rframeclear" => "rfloat frame
rclear", );

switch (str_replace('"', '', $cpl[1])) {
case "left": case "Left": case "LEFT":
case "right": case "Right": case "RIGHT":
$Header = "<div style='text-align: ".strtolower($cpl[1]).";'>";
$Tailer = "</div>";
break;
case "lfloat": case "Lfloat": case "LFloat": case "LFLOAT":
case "rfloat": case "Rfloat": case "RFloat": case "RFLOAT":
case "lfloatclear": case "Lfloatclear": case "LFloatClear": case
"LFLOATCLEAR":
case "rfloatclear": case "Rfloatclear": case "RFloatClear": case
"RFLOATCLEAR":
$Header = "<div class='".$assignformat[strtolower(str_replace('"', '',
$cpl[1]))]."' style='text-align: center;'>";
$Tailer = "</div>";
break;
case "lframe": case "Lframe": case "LFrame": case "LFRAME":
case "rframe": case "Rframe": case "RFrame": case "RFRAME":
case "lframeclear": case "Lframeclear": case "LFrameClear": case
"LFRAMECLEAR":
case "rframeclear": case "Rframeclear": case "RFrameClear": case
"RFRAMECLEAR":
$Header = "<div class='".$assignformat[strtolower(str_replace('"', '',
$cpl[1]))]."' style='text-align: center;'>";
$Tailer = "<br /><strong><em>$caption</em></strong></div>";
break;
case "note": case "Note": case "NOTE":
$Header = "<table class='widenote'><tr><td
class='noteheader'>$caption</td></tr><tr><td>";
$Tailer = "</td></tr></table>";
break;
}
break;
}
}

$ImgPath = "$ImgPath.$ImgFormat";

#echo "Path: |".$ImgPath."|<br>\n";

        function UR_exists($uri) {
            $ch = curl_init($uri);
            curl_setopt($ch, CURLOPT_NOBODY, true);
            curl_exec($ch);
            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);

            return $code == 200;
        }

if (UR_exists($ImgPath)) $Img = $ImgPath;
else $caption = "Unknown Image ! ".$caption;

return "$Header
<img src='$Img' pbsrc='$Img' title='$title' pbCaption='$caption'
$command=' var startPos = GetElementPosition(this);
popBoxRevertBarAbove=$RevertBarAbove;
popBoxCaptionBelow=$CaptionBelow;
PopEx(this, $endX, $endY, $endW, $endH, $sM,\"$Style\");'
alt='' width='".$size."px' $align  />
$Tailer";
}

?>
_______________________________________________
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users

_______________________________________________
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users

Reply via email to