rejetto forum

true statement showing false

raybob · 11 · 5771

0 Members and 1 Guest are viewing this topic.

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
I may be doing something wrong but in the [folder] section, there's a little issue.

If I put in %number-folders% and {.add|{.count|folder level.}|1.}, in the lowest folder row the numbers will be the same, looking something like this:



And yet, when I put in the statement {.=|%number-folders%|{.add|{.count|folder level.}|1.}.} it always comes out false even in a row where the two numbers are equal.
« Last Edit: June 22, 2011, 08:07:52 PM by raybob95 »


Offline r][m

  • Tireless poster
  • ****
    • Posts: 347
    • View Profile

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Well the original problem still exists I just found an alternative.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i was passing by in a rush and just asked.
now i worked on it and finally understood why it doesn't work.

%number-folders% (and some other symbols) is translated to a number only AFTER the scripting of every file/folder is executed.
this is not actually necessary, and i think i can change it so to solve such problems without side effects.
Sadly i cannot do it right now because i recently changed my hard disk and have to reinstall some things.
I will put this in the to-do list.

I doubt the %sequential% solved your problem.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
It is not absolutely necessary to change whatever it is about %number-folders%, it work fine

this variable gives the total of folders (%number-folders%) of the current directory and is défined at the end of the search process of all items (%number%)

it's same with links (%number-links%) and files (%number-files%)

A possibility is to obtain directly the available information with my mod (exist since build 186):

Quote
 procedure handleItem(f:Tfile);
....

  addArray(md.table, [
   '%item-index%', inttostr(if_(type_='file',numberFiles)+if_(type_='link',numberLinks)+if_(type_='folder',numberFolders)),  //add by mars
    '%item-number%', inttostr(numberFiles+numberLinks+numberFolders), //add by mars replace usage of limited %sequential%

    '%item-type%', type_
  ]);

  s:=xtpl(s, nonPerc);
  md.f:=f;
  tryApplyMacrosAndSymbols(s, md, FALSE);
  fast.append(s);
  end; // handleItem


%item-number% / %number%      index of an element of all items

Other :
[folder=file=link]
%item-index% / {.switch|%type%|;|folder|%number-folders%|link|%number-links%|file|%number-files%.}

it's possible to use the next lines after corrected a bug in parser.lib
[folder=file=link]
%item-index% / %number-%item-type%s%

to avoid bug:
Quote
 procedure handleSymbols();
....
    newS:=cb(s, NIL, cbData);
    if s = newS then begin dec(e); continue; end; //we have to restart parser from the last % of %text% when text is not in the list else recurse not working
....
end;



« Last Edit: July 03, 2011, 07:20:03 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
@mars, i don't think you understood what's behind the problem reported.
1. I think your suggestion doesn't solve the problem, indeed.
Did you try to use {.=|%item-number%|%number-folders%.} ?
Of course this test makes sense only if they are all folders, but let it be, just for the sake of the test.
Let me know the result, i'm interested.

2. your suggestion doesn't let the user count only the folders, in case he needs to (that's only when the "folders before" is disabled)

3. It's not exactly a bug, it's just a limit, but it's ok if we can get more things to work with a small change.
The question is: with the change you suggested, will we have some side effects, like correct templates that stop working?
At the moment i cannot test myself, because Windows7 64bit is preventing me from installing Turbo Delphi. I'm working on it.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
The question is: with the change you suggested, will we have some side effects, like correct templates that stop working?

There is already a security which was introduced in parser.lib again infinite loop with the constant MAX_RECUR_LEVEL = 50;
 and this line
    if alreadyRecurredOn(s) then continue; // the user probably didn't meant to create an infinite loop


Quote
2. your suggestion doesn't let the user count only the folders, in case he needs to (that's only when the "folders before" is disabled)

it's will be good to have his full template, i believe that we miss some elements to be able to estimate completely his problem
Quote
1. I think your suggestion doesn't solve the problem, indeed.
Did you try to use {.=|%item-number%|%number-folders%.} ?
Of course this test makes sense only if they are all folders, but let it be, just for the sake of the test.
Let me know the result, i'm interested.

It makes no sense of use {.=|%item-number%|%number-folders%.}, truth syntax to be used as I suggest him(it) in the modification is {.=|%item-index%|%number-folders%.}, but only if you accept the update

%item-number% must be used with %number%



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
0. i didn't mean specifically infinite loops, but any unwanted side effect
1. whatever. did you try it? i don't think it works, %item-index% or %item-number%.
because the comparison is made at stage where %item-index% is translated but %number-folders% is not.
so the first one is translated to a number, while the second one is left as %number-folders%.
the comparison result is necessarily false.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
found  as solution to translate  %item-index%, %number-folders%, %number-files%, %number-links% at same stage

this answer your question: "Did you try to use {.=|%item-number%|%number-folders%.} ?"
   NOW WORKING:
Code: [Select]
function Tmainfrm.getFolderPage(folder:Tfile; cd:TconnData; otpl:Tobject):string;
// we pass the Tpl parameter as Tobject because symbol Ttpl is not defined yet

var
  baseurl, list, fileTpl, folderTpl, linkTpl: string;
  table: TStringDynArray;
  ofsRelItemUrl, ofsRelUrl, numberFiles, numberFolders, numberLinks: integer;
  indexFiles, indexFolders, indexLinks: integer;
  img_file: boolean;
  totalBytes: int64;
  fast: TfastStringAppend;
  buildTime: Tdatetime;
  listing: TfileListing;
  diffTpl: Ttpl;
  isDMbrowser: boolean;
  hasher: Thasher;
  fullEncode, recur, oneAccessible: boolean;
  md: TmacroData;

  procedure applySequential();
  const
    PATTERN = '%sequential%';
  var
    idx, p: integer;
    idxS: string;
  begin
  idx:=0;
  p:=1;
    repeat
    p:=ipos(PATTERN, result, p);
    if p = 0 then exit;
    inc(idx);
    idxS:=intToStr(idx);
    delete(result, p, length(PATTERN)-length(idxS));
    move(idxS[1], result[p], length(idxS));
    until false;
  end; // applySequential

  procedure handleItem(f:Tfile);
  var
    type_, s, url, fingerprint, itemFolder: string;
    nonPerc: TStringDynArray;
  begin
  if not f.isLink and ansiContainsStr(f.resource, '?') then exit; // unicode filename?   //mod by mars

  if f.size > 0 then inc(totalBytes, f.size);

  // build up the symbols table
  md.table:=NIL;
  nonPerc:=NIL;
  if f.icon >= 0 then
    begin
    s:='~img'+intToStr(f.icon);
    addArray(nonPerc, ['~img_folder', s, '~img_link', s]);
    end;
  if f.isFile() then
    if img_file and (useSystemIconsChk.checked or (f.icon >= 0)) then
      addArray(nonPerc, ['~img_file', '~img'+intToStr(f.getSystemIcon())]);

  if recur or (itemFolder = '') then
    itemFolder:=optUTF8(diffTpl, f.getFolder());
  if recur then
    url:=substr(itemFolder, ofsRelItemUrl)
  else
    url:='';
  addArray(md.table, [
    '%item-folder%', itemFolder,
    '%item-relative-folder%', url
  ]);

  if not f.accessFor(cd) then
    s:=diffTpl['protected']
  else
    begin
    s:='';
    if f.isFileOrFolder() then
      oneAccessible:=TRUE;
    end;
  addArray(md.table, [
    '%protected%', s
  ]);

  // url building
  fingerprint:='';
  if fingerprintsChk.checked and f.isFile() then
    begin
    s:=loadMD5for(f.resource);
    if s = '' then s:=hasher.getHashFor(f.resource);
    if s > '' then fingerprint:='#!md5!'+s;
    end;
  if f.isLink() then
    begin
    url:=f.resource;
    s:=url;
    end
  else
    if pwdInPagesChk.Checked and (cd.usr > '') then
      begin
      if encodePwdUrlChk.checked then s:=totallyEncoded(cd.pwd)
      else s:=encodeURL(cd.pwd);
      s:=f.fullURL( encodeURL(cd.usr)+':'+s, getSafeHost(cd) )+fingerprint;
      url:=s
      end
    else
      begin
      if recur then
        s:=copy(f.url(fullEncode), ofsRelUrl, MAXINT)+fingerprint
      else
        s:=f.relativeURL(fullEncode)+fingerprint;
      url:=baseurl+s;
      end;
  if not f.isLink() then
    begin
    s:=macroQuote(s);
    url:=macroQuote(url);
    end;
  addArray(md.table, [
    '%item-url%', s,
    '%item-full-url%', url
  ]);

  // select appropriate template
  if f.isLink() then
    begin
    s:=linkTpl;
    inc(indexLinks);
    type_:='link';
    end
  else if f.isFolder() then
    begin
    s:=folderTpl;
    inc(indexFolders);
    type_:='folder';
   end
  else
    begin
    s:=diffTpl.getTxtByExt(ExtractFileExt(f.name));
    if s = '' then s:=fileTpl;
    inc(indexFiles);
    type_:='file';
    end;

  addArray(md.table, [
    '%number-files%', intToStr(numberFiles),
    '%number-folders%', intToStr(numberFolders),
    '%number-links%', intToStr(numberlinks),
    '%number%', inttostr(numberFiles+numberFolders+numberlinks),
    '%item-index%', inttostr(if_(type_='file',indexFiles)+if_(type_='link',indexLinks)+if_(type_='folder',indexFolders)),  //add by mars
    '%item-number%', inttostr(indexFiles+indexLinks+indexFolders),  //add by mars replace usage of limited %sequential%
    '%item-type%', type_
  ]);

  s:=xtpl(s, nonPerc);
  md.f:=f;
  tryApplyMacrosAndSymbols(s, md, FALSE);
  fast.append(s);
  end; // handleItem

var
  i: integer;
begin
result:='';
if (folder = NIL) or not folder.isFolder() then exit;

if macrosLogChk.checked and not appendmacroslog1.checked then
  resetLog();
diffTpl:=Ttpl.create();
folder.lock();
try
  buildTime:=now();
  cd.conn.addHeader('Cache-Control: no-cache, no-store, must-revalidate, max-age=-1');
  recur:=shouldRecur(cd);
  baseurl:=protoColon()+getSafeHost(cd)+folder.url(TRUE);

  if cd.tpl = NIL then
    diffTpl.over:=otpl as Ttpl
  else
    begin
    diffTpl.over:=cd.tpl;
    cd.tpl.over:=otpl as Ttpl;
    end;

  if otpl <> filelistTpl then
    diffTpl.fullText:=optUTF8(diffTpl.over, folder.getRecursiveDiffTplAsStr());

  isDMbrowser:= otpl = dmBrowserTpl;
  fullEncode:=not isDMbrowser;
  ofsRelUrl:=length(folder.url(fullEncode))+1;
  ofsRelItemUrl:=length(optUTF8(diffTpl, folder.pathTill()))+1;
  // pathTill() is '/' for root, and 'just/folder', so we must accordingly consider a starting and trailing '/' for the latter case (bugfix by mars)
  if not folder.isRoot() then
    inc(ofsRelItemUrl, 2);

  fillChar(md, sizeOf(md), 0);
  md.cd:=cd;
  md.tpl:=diffTpl;
  md.folder:=folder;
  md.archiveAvailable:=folder.hasRecursive(FA_ARCHIVABLE) and not folder.isDLforbidden();
  md.hideExt:=folder.hasRecursive(FA_HIDE_EXT);

  result:=diffTpl['special:begin'];
  tryApplyMacrosAndSymbols(result, md, FALSE);

  // cache these values
  fileTpl:=xtpl(diffTpl['file'], table);
  folderTpl:=xtpl(diffTpl['folder'], table);
  linkTpl:=xtpl(diffTpl['link'], table);
  // this may be heavy to calculate, only do it upon request
  img_file:=pos('~img_file', fileTpl) > 0;

  // build %list% based on dir[]
  numberFolders:=0; numberFiles:=0; numberLinks:=0;
  indexLinks:=0; indexFolders:=0; indexFiles:=0;

  totalBytes:=0;
  oneAccessible:=FALSE;
  fast:=TfastStringAppend.Create();
  listing:=TfileListing.create();
  hasher:=Thasher.create();
  hasher.loadFrom(folder.resource);
  try
    listing.fromFolder( folder, cd, recur );
    listing.sort(cd, if_(recur or (otpl = filelistTpl), '?', diffTpl['sort by']) ); // '?' is just a way to cause the sort to fail in case the sort key is not defined by the connection

    for i:=0 to length(listing.dir)-1 do
      if listing.dir[i].isLink() then  inc(numberLinks)
        else if ansiContainsStr(listing.dir[i].resource, '?') then continue
            else if listing.dir[i].isFolder() then inc(numberFolders)
              else inc(numberFiles);

    for i:=0 to length(listing.dir)-1 do
      begin
      application.ProcessMessages();
      if cd.conn.state = HCS_DISCONNECTED then exit;
      cd.lastActivityTime:=now();
      handleItem(listing.dir[i])
      end;
    list:=fast.reset();
  finally
    listing.free;
    fast.free;
    hasher.free;
    end;

  if cd.conn.state = HCS_DISCONNECTED then exit;

  // build final page
  if not oneAccessible then md.archiveAvailable:=FALSE;
  md.table:=toSA([
    '%number-files%', intToStr(numberFiles),
    '%number-folders%', intToStr(numberFolders),
    '%number-links%', intToStr(numberlinks),
    '%number%', inttostr(numberFiles+numberFolders+numberlinks),
    '%upload-link%', if_(accountAllowed(FA_UPLOAD, cd, folder), diffTpl['upload-link']),
    '%files%', if_(list='', diffTpl['nofiles'], diffTpl['files']),
    '%list%',list,
    '%total-bytes%', intToStr(totalBytes),
    '%total-kbytes%', intToStr(totalBytes div KILO),
    '%total-size%', smartsize(totalBytes)
  ]);
  result:=diffTpl[''];
  md.f:=NIL;
  md.afterTheList:=TRUE;
  try tryApplyMacrosAndSymbols(result, md)
  finally md.afterTheList:=FALSE end;
  applySequential();
  // ensure this is the last symbol to be translated
  result:=xtpl(result, [
    '%build-time%', floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3)
  ]);
finally
  folder.unlock();
  diffTpl.free;
  end;
end; // getFolderPage

PS: those lines are necessary for two different places
Code: [Select]
    '%number-files%', intToStr(numberFiles),
    '%number-folders%', intToStr(numberFolders),
    '%number-links%', intToStr(numberlinks),
    '%number%', inttostr(numberFiles+numberFolders+numberlinks),

and the part of tpl

Code: [Select]
[file=folder=link|private]
<tr class='{.if|{.mod|{.count|row.}|2.}|even.}'><td>
%item-number%/%number% {.if |{.=|%item-number%|%number%.}|(last item )|(not last item).} -- %item-index%/{.switch|%item-type%|;|folder|%number-folders%|link|%number-links%|file|%number-files%.}  {.if|{.=|%item-index%|{.switch|%item-type%|;|folder|%number-folders%|link|%number-links%|file|%number-files%.} .}|(last %item-type%)|(not last %item-type%).}
        <input type='checkbox' class='selector' name='selection' value='%item-url%' {.if not|{.or|{.get|can delete.}|{.get|can access.}|{.get|can archive item.}.}|disabled='disabled'.} />
{.if|{.get|is new.}|<span class='flag'>&nbsp;NEW&nbsp;</span>.}
{.if not|{.get|can access.}|<img src='/~img_lock'>.}
<a href="%item-url%"><img src="%item-icon%"> %item-name%</a>
{.if| {.?search.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
{.123 if 2|<div class='comment'>|{.commentNL|%item-comment%.}|</div>.}

[+file]
<td>%item-size%B<td>%item-modified%<td>%item-dl-count%

[+folder]
<td class='nosize'>folder<td>%item-modified%<td>%item-dl-count%

[+link]
<td class='nosize'>link<td colspan='2'>