Hi,
I am using a pgn4web to add a chessboard to forum. I've added a custom BBC code to include this chess board (per this instructions: http://code.google.com/p/pgn4web/wiki/User_Notes_simplemachines). However, the board would not display when Previewed. Works fine when post is submitted, just the Preview doesn't work.
Whose fault is it: chessboard software or Custom BBC mod or SMF?
Does anyone have any idea?
Thanks.
I expect that it is probably the fault of the custom BBC mod... it's probably not set to parse the preview page, but does parse on the normal message view.
I would suggest asking on the mod support topic.
You might also contact the author of the wiki article.
I noticed that if I add manualy the code to Sub.php then tag "pgn" works in Preview mode too, here it is:
array(
'tag' => 'pgn',
'type' => 'unparsed_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', 'global $txt; $data = strtr($data, array(\'<br />\' => \'\', \'"\' => \'"\')); $tag[\'content\'] = \'<iframe height="400" width="920" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://my.ip.address/pgn4web-2.46/board.html?a=f&delay=1000&l=f&pieceFont=alpha&pieceSize=30&squareSize=40&lch=EFF4EC&dch=C6CEC3&bbch=000000&hch=DAF4D7&sb=t&showHeader=t&showMoves=t&textMargin=20&fhch=000000&fontHeaderSize=80pct&fmch=000000&fvch=800000&fcch=396184&hmch=C6CEC3&fontMovesSize=80pct&fontCommentsSize=80pct&sc=t&scosl=f&bch=F0F0F0&highlightMode=border&framePadding=20&horizontalLayout=t&fh=board&fw=page&pt=\' . $data . \'">\' . $txt[\'pgn_no_iframe\'] . \'</iframe>\';'),
),
And here is the mod code that somehow doesn't work in Preview mode:
// Add custom BBCode
if (!empty($modSettings['customBBCode_count']))
{
// Find all the tags.
$count = $modSettings['customBBCode_count'];
for ($i = 1; $count; $i++)
{
if (isset($modSettings['customBBCode_tag_' . $i]))
{
$tags[$i] = $modSettings['customBBCode_tag_' . $i];
$count--;
}
}
foreach ($tags as $i => $tag)
{
if (!empty($tag) && !empty($modSettings['customBBCode_enable_' . $i]))
{
// Tag parsing starts here. Start with the name.
$custom_code = array('tag' => $tag);
// Set block level.
if (!empty($modSettings['customBBCode_block_level_' . $i]))
$custom_code['block_level'] = true;
// Set trim.
if (!empty($modSettings['customBBCode_trim_' . $i]))
{
if ($modSettings['customBBCode_trim_' . $i] == 1)
$custom_code['trim'] = 'inside';
else
$custom_code['trim'] = 'outside';
}
// Check tag type so we don't have to do it again.
if (!empty($modSettings['customBBCode_type_' . $i]))
$tag_type = $modSettings['customBBCode_type_' . $i];
else
$tag_type = 0;
// Find the type and parsing.
if ($tag_type == 2) // At the top because it never uses parsing.
{
$custom_code['type'] = 'closed';
if (!empty($modSettings['customBBCode_text_' . $i]))
$custom_code['content'] = $modSettings['customBBCode_text_' . $i];
}
elseif (empty($modSettings['customBBCode_parse_' . $i])) // No parsing.
{
if ($tag_type == 1)
$custom_code['type'] = 'unparsed_equals_content';
else
$custom_code['type'] = 'unparsed_content';
if (!empty($modSettings['customBBCode_text_' . $i]))
$custom_code['content'] = $modSettings['customBBCode_text_' . $i];
}
else // It parses.
{
if ($tag_type == 1)
if ($modSettings['customBBCode_parse_' . $i] == 1)
$custom_code['type'] = 'unparsed_equals';
else
$custom_code['type'] = 'parsed_equals';
if (!empty($modSettings['customBBCode_before_' . $i]))
$custom_code['before'] = $modSettings['customBBCode_before_' . $i];
if (!empty($modSettings['customBBCode_after_' . $i]))
$custom_code['after'] = $modSettings['customBBCode_after_' . $i];
}
// Add it to the standard tags.
$codes[] = $custom_code;
}
}
}
I have added the following HTML for the tag via mod (and I chose "no parsing", "no trim", "no block level"):
<script type='text/javascript'> var pgn4webPath = "/pgn4web"; var pgn4webTextareaIdNum; if (pgn4webTextareaIdNum === undefined) { pgn4webTextareaIdNum = 1; } pgn4webTextareaId = "pgn4web_" + pgn4webTextareaIdNum++; document.write("<textarea id='" + pgn4webTextareaId +"' style='display: none;'>"); </script>{content}</textarea> <script type='text/javascript'> document.getElementById(pgn4webTextareaId).value = document.getElementById(pgn4webTextareaId).value.replace(/<\s*br\s*\/>/gi, ' '); height = 400; multiGamesRegexp = /\s*\[\s*\w+\s*"[^"]*"\s*\]\s*[^\s\[\]]+[\s\S]*\[\s*\w+\s*"[^"]*"\s*\]\s*/m; if (multiGamesRegexp.test(document.getElementById(pgn4webTextareaId).value)) { height += 34; } document.write("<iframe src='" + pgn4webPath + "/board.html?a=f&d=1000&ss=40&ps=30&pf=d&lch=EFF4EC&dch=C6CEC3&bbch=000000&hm=b&hch=DAF4D7&cbcs=UJuI&ctcs=BoVy&hd=j&md=f&tm=13&commentsDisplay=newline&fhch=000000&bd=s&fhs=14&fmch=000000&fcch=396184&hmch=C6CEC3&fvch=800000&bch=F0F0F0&fms=14&fcs=m&cd=i&bcs=WdSO&fp=20&hl=t&fh=b&fw=p&pi=" + pgn4webTextareaId + "' frameborder=0 width=100% height=" + height + " scrolling='no' marginheight='0' marginwidth='0'>your web browser and/or your host do not support iframes as required to display the chessboard</iframe>"); </script>
Does this show why Preview works in the first case, and not with mod?
I think some debugging would be required to figure this out.
The custom BBCode did not work with the BBCode mode? You had to hard-code it into parse_bbc to make it work?
When you attempt to preview a chessboard, do you see any errors in your SMF error log?
If not, the javascript code is probably a good place to start debugging. You can work line by line through that code. This will be a big pain since you have hard-coded the javascript into parse_bbc. The first thing to check would be whether that javascript works at all, simply by putting in a line to pop up a message box. After that -- it is just a slog through the javascript code to find out where you get unexpected values.
Sound like fun?
I just updated forum to 2.0.7 (was usiong 1.1.x).
Preview still doesn't work.
Nothing in the error log.
How do I know does it even get parsed in the Preview mode?
Is the custom BBC mod even supported on 2.0.x?
(and if you are on 2.0.x, why are youi posting in the 1.1.x support section? :) )
I figured the "Preview" doesn't work in Firefox, but it works in IE 11. So could it be a browser problem after all?
Is there a Firefox setting I could change to make it work?
In case I use firebug to debug, what should I look for?