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:
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
[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>
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