Categories > TBS next version >

Bug in GetBlockSource / KeepDefTags?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Rudy
Date: 2010-04-28
Time: 10:51

Bug in GetBlockSource / KeepDefTags?

Hello,

I found an odd behaviour with the TBS-Method GetBlockSource. First, the documentation is incomplete/wrong for this function the first Parameter is not mentioned in the Syntax: http://tinybutstrong.com/manual.php#php_getblocksource - that's a minor issue (but it cost me some time to figure out :))

Anyways, there seems to be a bug with the second parameter "KeepDefTags" when not in array mode.

function _debug($var) {
  $var = is_array($var) ? htmlspecialchars(print_r($var, true)) : htmlspecialchars($var);
  echo '<pre>'.$var.'</pre>';
}

$tbs->Source = '<html><body><div><span>[testblock;block=div]</span></div></body><html>';
_debug($tbs->GetBlockSource('testblock', false, false, false)); //<-- wrong result ?
_debug($tbs->GetBlockSource('testblock', false, true, false));
_debug($tbs->GetBlockSource('testblock', true, false, false));
_debug($tbs->GetBlockSource('testblock', true, true, false));

Result:
<div><span>[testblock;block=div]</span></div>

<div><span>[testblock;block=div]</span></div>

Array
(
    [1] => <div><span></span></div>
)

Array
(
    [1] => <div><span>[testblock;block=div]</span></div>
)

Expected:

<div><span></span></div>

<div><span>[testblock;block=div]</span></div>

Array
(
    [1] => <div><span></span></div>
)

Array
(
    [1] => <div><span>[testblock;block=div]</span></div>
)

TBS Version used is 3.5.3 / 2010-04-12 (PHP5). I have to work around that by putting the block definition between html-comments in the source which of course then remain visible in the code.

Best regards
Rudy
By: Skrol29
Date: 2010-05-02
Time: 00:20

Re: Bug in GetBlockSource / KeepDefTags?

Hi Rudy,

Thank for reporting this bug.

I've updated the manual in order to have the correct argument names.

I can reproduce your bug too. The bug is that TBS returns directly a substring of the template when argument AsArray is set to false.
I'll fix that for the next version. If you need the code to fix it now in your source, just ask.

Regards,
By: Rudy
Date: 2010-05-02
Time: 09:51

Re: Bug in GetBlockSource / KeepDefTags?

Hi Skrol,

it's not that bad, one has just to use comments around the block definition along with "comm", then it will work when it's fixed in the new version, for now the block definitions are visible in the code but not to the common user.

If that's not acceptable, one could use
$blocksource = @reset($tbs->getBlockSource('blockname', true, false, false));
which gives the right result for single blocks or simply perform a str_replace on the source.

Bye