rejetto forum

some changes and corrected bugs

Mars · 6 · 5045

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
In aid of rejetto, this topic contains several parts which are dependent downstream

1) An error with %parent-folder%, spaces are codified while with %folder%, they are not it: 
The corrective is:

Quote
    else if name = '%parent-folder%' then
      result:=md.folder.getFolder()        //mod by mars
//     result:=md.folder.parentURL()
    else if name = '%folder-name%' then

2) I discovered some errors of exceptions concerning uploaded and downloaded files, which led me to spend two full days between modifications of main.pas and results  more than functional

When we upload a file, the directory of destination is already known  'md.folder' , no temp folder is needed.

with the correct folder It is possible to find the missing information.


Both variables %item-folder% and %item-url% are defined in the procedure handleitem which is not accessible here, I thus have of to add them for reasons of homogeneity.

an example to test the correct event is
Quote
[upload completed=download completed]
{.set|print|upload is finish with %item-name%
folder : %folder%
folder-resource : %folder-resource%
url : %url%
parent-folder : %parent-folder%
item-url : %item-url%
item-folder : %item-folder%
.}
{.add to log|{.^print.}.}


and it is possible to change the back link into the section [upload-results]
<a href="." target='_parent' class='big'><img src="/~img14"> {.!Back to the folder.}</a>
to
<a href="%url%" class='big'><img src="/~img14"> {.!Back to the folder url.}</a>



Quote
  function runEventScript(event:string; table:array of string):string; overload;
  var
    sa: TStringDynArray;
    md: TmacroData;
  begin
  result:=trim(eventScripts[event]);
  if result = '' then exit;
  sa:=NIL;
  addArray(sa, table);
  fillchar(md, sizeOf(md), 0);
  md.cd:=data;
  try
    if assigned(data.f) then // a file has been uploaded
      // we must encapsulate it in a Tfile to expose file properties to the script. we don't need to cache the object because we need it only once.
      begin
      md.f:=Tfile.createTemp(getFilename(data.f^));
 //    md.folder:=Tfile.createTemp(extractFilePath(md.f.resource));     //disabled by mars
      md.folder:=findfileByURL(decodeURL(md.cd.conn.request.url));  // we must create it here, because getParent() won't work   
      md.f.node:=md.folder.node;
      addArray(sa, [
        '%item-folder%', md.f.getFolder(),
        '%item-url%', md.folder.url()+md.f.name
      ]);

      end
    else if assigned(f) then
      md.f:=f
    else if assigned(data.lastFile) then
      begin

      md.f:=data.lastFile;
      md.folder:=findfileByURL(md.f.getFolder());
      addArray(sa, [
        '%item-folder%', md.f.getFolder(),
        '%item-url%', md.folder.url()+md.f.name
      ]);
      end;


    if assigned(md.f) and (md.folder = NIL) then
      md.folder:=md.f.getParent();
    tryApplyMacrosAndSymbols(result, md, sa);

  finally
    if assigned(data.f) then
      begin
      freeAndNIL(md.f);
 //      freeAndNIL(md.folder);    //disabled by mars
      end;
    end;
  end; // runEventScript
« Last Edit: April 11, 2009, 11:07:58 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
1. %parent-folder%, although the misleading name, is the parent version of %encoded-folder%, not of %folder%.
the documentation is clear enough about it.

it is actually not very useful. when i made it i didn't know the browsers support "..", and this doesn't need encoding.
it's here mainly for backward compatibility.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
2.
i noticed that, before the script event, HE_POST_FILE already used findFileByURL().
so i now cache this value in data.lastFile and re-use it.

to make %item-url% working i prefer adding it to cbMacros()

    else if name = '%item-url%' then
      result:=optUTF8(md.tpl, md.f.url())
 
and it will work automatically because of the line
md.f.node:=md.folder.node;
this is a more generic solution, that may be useful in other cases.

personally i prefer "." in place of "%url%". it's quicker to type, and doesn't require server CPU. 
target='_parent' is needed in the default template in case frames are used.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
by the way, this made me notice that there are several memory leaks.
next build will fix all i could find.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
1. %parent-folder%, although the misleading name, is the parent version of %encoded-folder%, not of %folder%.
the documentation is clear enough about it.

%parent-folder% can be likened to a version limited by %up%.

The only problem it is because it is encoded while it should have the same shape as %folder% or then be called %encoded-parent-folder%

To have the possibility of a variable supplying the url of the parent of a folder is not to displease, it is just enough to restore to him its glory

We can so use it in multiple cases as

<a class='big' href=".."><img src="/~img14"> {.!UP.}</a>
or
<a class='big' href="%parent-folder%"><img src="/~img14"> {.!UP.}</a>

{.if| {.%folder% != / .} | <a class='big' href=".."><img src="/~img14"> {.!UP.}</a> .}
replaced by
{.if| %parent-folder% | <a class='big' href=".."><img src="/~img14"> {.!UP.}</a> .}


I believe that this last argument is self-important to add in conformance with the topic

APROUVED BY THE BOSS

;D


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
{.if| {.%folder% != / .} | <a class='big' href=".."><img src="/~img14"> {.!UP.}</a> .}
replaced by
{.if| %parent-folder% | <a class='big' href=".."><img src="/~img14"> {.!UP.}</a> .}

nice :)