TinyButStrong - the PHP Template Engine
Categories > OpenTBS general MsOffice >

error escaping quotes in TBS tags in docx/xlsx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Walter
Date: 2014-07-23
Time: 19:02

error escaping quotes in TBS tags in docx/xlsx

Hello,

I am building some templates using the latest TBS + OpenTBS. So far, almost everything works, except that if I use quotes in tags (for example in IFs) they get expanded by Word/OpenOffice to ' and this is not recognized by TBS parser.
This is an example of such a tag:

[onshow.site_name;if [val]='';then 'all sites';else  [val]]

by looking at XML, this is

[onshow.site_name;if [val]='';then 'all sites';else  [val]]

of course this break things alot.
I've corrected this by modifying the source of OpenTBS 1.9.0.

Moreover the substitution of ' was not applied to xlsx, and it was applied in the wrong places, so

These are the mods:

around line 1719: (add search for "'" )
           // Microsoft Office documents
            $this->OpenXML_MapInit();
            if ($TBS->OtbsConvertApostrophes) {
                $x = array(chr(226) . chr(128) . chr(152), chr(226) . chr(128) . chr(153));
                $x[]='&apos;';// <==== ADDED
            } ...
around line 1757 (added params for searc/replace for xlsx
            elseif ( ($Ext==='xlsx') || ($Ext==='xlsm')) {
                $this->MsExcel_DeleteCalcChain();
                $i = array('br' => false, 'ctype' => $ctype . 'spreadsheetml.sheet', 'pic_path' => 'xl/media/'
                          , 'rpl_what' => $x, 'rpl_with' => '\'' // <== added these two parameters
                          );
around line 690
                           if (($e==='xlsx') && $TBS->OtbsMsExcelConsistent) {
                                $this->MsExcel_DeleteFormulaResults($TBS->Source);
                                $this->MsExcel_ConvertToRelative($TBS->Source);
                                //repeat subst <=== ADDED FROM HERE
                                if (isset($i['rpl_what'])) {
                                // auto replace strings in the loaded file
                                   $TBS->Source = str_replace($i['rpl_what'], $i['rpl_with'], $TBS->Source);
                               }
                                // <== TO HERE

Hope this can help someone
By: Skrol29
Date: 2014-07-23
Time: 19:10

Re: error escaping quotes in TBS tags in docx/xlsx

Hi Walter,

Thank you for sharing this.

I have a trick to not be bothered with quotes replaced by apostrophes in Ms Word : after pressing key Quote (') , I do a [Ctrl]+[Z].
This put back to apostrophe to simple quote.
Does it work for you?
By: Walter
Date: 2014-07-23
Time: 19:14

Re: error escaping quotes in TBS tags in docx/xlsx

Hi Scrol29,
Thanks for replying
I don't use MSWord 9even if we have it), we are on Mac and we prefer OpenOffice. That said, the templates we are using should be editable by virtual anyone, so I'd say it's unsafe to rely on this trick, even if this should work..


BTW thanks for TBS. It's very nice and powerful with OpenTBS. Where can I post a question over Aggregate?
By: Skrol29
Date: 2014-08-02
Time: 12:12

Re: error escaping quotes in TBS tags in docx/xlsx

Did you read the pat of the documentation about apostrophes ?

http://www.tinybutstrong.com/opentbs.php?doc#misc
By: Walter
Date: 2014-08-04
Time: 11:20

Re: error escaping quotes in TBS tags in docx/xlsx

Hi,
I've tried setting             $TBS->OtbsConvertApostrophes = false;
But everything breaks (if I don't implement my modification). Here are some errors..:

a field like this, where I've inputed single quotes..
<w:t>[members3;block=begin;p1=and cr.kind=&apos;R&apos;][members3.name1]

generates a struct like this
PRMLIST Array
(
    [block] => begin
    [p1] => and cr.kind=&apos
    [R&apos] => 1
)
and this SQL..

        and cr.kind=%p1%
        AND cm.checkin_site_id=1

we get

        and cr.kind=&apos
        AND cm.checkin_site_id=1



So I am afraid but, apart from CTRL-Z which, as I wrote, is not a viable solution (if any) I don't seem to get around this problem. Even more than XLSX did not get apostrophes subst at the right pass..
I've put all my code in a neat IF($TBS->OtbsEscapeApostrophes.. ) should you b e interested.

Thanks