Skrol29 / opentbs

With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
http://www.tinybutstrong.com/opentbs.php
69 stars 17 forks source link

Relative paths #2

Closed sstativa closed 1 year ago

sstativa commented 7 years ago

Documentation clearly states that relative paths are supported, however I could make it work.

Quick look inside the code gives me an idea that in fact only absolute paths are supported.

Any plans to path paths relative to template path (or something else)?

Skrol29 commented 7 years ago

Hi, Relative path for what feature ?

sstativa commented 7 years ago

My bad, you are right I forgot to mention the feature. It's about changepic. For our project we have 2 directories, one for templates, another for images. It's very inconvenient to use absolute path to image directory.

Currently, I created a "dirty" hotfix inside TbsPicExternalPath function

        if (!file_exists($FullPath) && $FullPath[0] == '.') {
            $tmpPath = dirname($TBS->_LastFile) . '/' . $FullPath;

            if (file_exists($tmpPath)) {
                $FullPath = $tmpPath;
            }
        }

however it could be nice to have support of relative paths by default.

Skrol29 commented 7 years ago

In this function despite the variable is called $FullPath it actually is a usual path. I mean the file path can be either relative or absolute. OpenTBS support the same path as the PHP function file_exists() since it is the function that is used internally. You can see in the demo package that images are inserted using relative path.

sstativa commented 7 years ago

But file_exists does not support relative paths in full. It supports paths like this /home/ubuntu/templates/../images, but not like this ../images, therefore I append "current dir" in front.

Skrol29 commented 7 years ago

It is true that function file_exists() has not the same search scope as file_get_contents() and fopen(). file_exists() is more restrictive and does not search in the current script directory ( DIR ) nore in the search_path. This is a problem in OpenTBS since file_exists() is used for checks before a file_get_contents(). This bug has a walk around in TinyBuStrong (that is function f_Misc_TryFile).

But in my opinion, the best way to perform a file_exists() with the same scope as a file_get_contents() is to use something like ( @file_get_contents($file, true, null, 0 ,0) === '' ) or similar with (@fopen($f, 'r', true) !== false) .

Whatever, I will double check this problem and fix it in the next version. Thanks a lot !