Author Topic: Abnormality with special:begin  (Read 2586 times)

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Abnormality with special:begin
« on: September 25, 2009, 09:36:13 AM »
this update is necessary to prevent a bug with getpage()

inside the section [special:begin] it is possible to add some text which is include to the web page

[special:begin]
this line will be displayed on the browser
....

*****************************************************************************
procedure Tmainfrm.getPage(sectionName:string; data:TconnData; f:Tfile=NIL; tpl2use:Ttpl=NIL);
....
  data.conn.reply.mode:=HRM_REPLY;
  if sectionName = 'ban' then data.conn.reply.mode:=HRM_DENY;
  if sectionName = 'deny' then data.conn.reply.mode:=HRM_DENY;
  if sectionName = 'not found' then data.conn.reply.mode:=HRM_NOT_FOUND;
  if sectionName = 'unauthorized' then data.conn.reply.mode:=HRM_UNAUTHORIZED;
  if sectionName = 'overload' then data.conn.reply.mode:=HRM_OVERLOAD;
  if sectionName = 'max contemp downloads' then data.conn.reply.mode:=HRM_OVERLOAD;

  md.cd:=data;
  md.tpl:=tpl2use;
  md.folder:=f;
  md.f:=NIL;
  md.archiveAvailable:=FALSE;

 section:=tpl2use.getSection(sectionName);
  if section = NIL then exit;

  s:=tpl2use['special:begin'];
  tryApplyMacrosAndSymbols(s, md, FALSE);

  s:=trim(s)+section.txt;


  if data.conn.reply.mode <> HRM_REPLY then
    s:=xtpl(tpl2use['error-page'], ['%content%', section.txt]);  // in error page do not include the special:begin text

  tryApplyMacrosAndSymbols(s, md);

  data.conn.reply.body:=xtpl(s, [
    '\n', CRLF,
    '%build-time%', floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3)
  ]);
  if section.nolog then data.dontLog:=TRUE;
  compressReply(data);
finally
  if not externalTpl then
    tpl2use.free
  end
end; // getPage

« Last Edit: October 03, 2009, 08:35:23 AM by Mars »

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
special:begin
« Reply #1 on: September 29, 2009, 11:55:49 PM »
> in error page do not include the special:begin text

why not?
« Last Edit: September 29, 2009, 11:58:19 PM by rejetto »

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
special:begin
« Reply #2 on: September 30, 2009, 04:18:44 AM »
if [special:begin] is not automatically included in error page, i would have to call it from there or duplicate code.

I think, normally most of the code included in special:begin is used on all 'mainpages'.
your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Abnormality with special:begin
« Reply #3 on: October 01, 2009, 12:51:05 PM »
if [special:begin] is not automatically included in error page, i would have to call it from there or duplicate code.


The section is always included but it is the text which she can produce who will not be shown. To convince itself it is enough to add what words between the macro of the section

Quote
[special:begin]
{.comment|one special:begin has been lanched.}
This text will be shown in the beginning of web page, even in the section error, regrettably.
{.invalid macro.}

The bug is due to the fact that the text produced by the section special:begin is included in the web page before the tag  < html >,  for landing in this problem I see only a solution which is the following one :
  --> Put the resultat of the section special:begin in a variable %special-begin%

It is then enough to add this variable after the tag < head > or wherever it is necessary, so we are not any more dependent on the systematic addition of the text produced by the section special:string. It does not prevent the section from being executed correctly every time, it is enough to place a macro ' add to log ' there to convince itself.


Code: [Select]
<html>
   <head>
     %special-begin%
   ...
   </head>
   <body>
    ...
    %special-begin%               [color=red]//  No, no , section [special:begin] is not executed second time !![/color]
    ...
<html>


update:
Quote
function Tmainfrm.getFolderPage
replace the line:
  
Code: [Select]
[color=brown] result:=trim(result)+diffTpl[''];[/color]
Code: [Select]
with those lines:
   [color=blue]addArray(md.table, ['%special-begin%', result]);[/color]   [color=green]//add by mars[/color]
   [color=blue]result:= diffTpl[''];[/color]  [color=green]//mod by mars[/color]


procedure Tmainfrm.getPage
replace the lines:
Code: [Select]
[color=brown]  s:=tpl2use['special:begin'];
  tryApplyMacrosAndSymbols(s, md, FALSE);

  section:=tpl2use.getSection(sectionName);
  if section = NIL then exit;
  s:=trim(s)+section.txt;[/color]
with those lines:
Code: [Select]
 [color=green]//moved by mars : with an empty section return a result is not necessary[/color]
[color=blue]  section:=tpl2use.getSection(sectionName);
  if section = NIL then exit;[/color]

[color=black]  s:=tpl2use['special:begin'];
  tryApplyMacrosAndSymbols(s, md, FALSE);[/color]

[color=blue]  addArray(md.table, ['%special-begin%', s]);[/color]   [color=green]//add by mars[/color]
  [color=blue]s:=section.txt;[/color]   [color=green]//mod by mars[/color]
« Last Edit: October 03, 2009, 08:35:42 AM by Mars »

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
special:begin
« Reply #4 on: October 01, 2009, 06:25:37 PM »
Mars:
What you point out about the 'bug' of producing text-output in special:begin to me seems not to be a problem of the error page, it's more a problem on every page of a template: the autor who creates text output before doctype header and outside of html is the problem !

I understand that the special:begin section is used to set or load variables, define some macros, load some files (with more macros to execute and setting more variables) etc., but not to produce direct output.

So i think - and i suppose you mean it so - that no text output should be done in any section (including mainpage and upload) - no matter if this is achieved by hfs or by the templatecreator.
your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Abnormality with special:begin
« Reply #5 on: October 01, 2009, 09:33:54 PM »
Quote
So i think - and i suppose you mean it so - that no text output should be done in any section (including mainpage and upload) - no matter if this is achieved by hfs or by the templatecreator.

 Your post expresses completely my thought, all the impact of the problem, as well as the necessity of such a change.

A simple output text in the section special:begin prevents for example from showing correctly the page 'add progress frame'

To use a macro ( as {.invalid macro.} ) inside the section provokes inevitably an error of the html format.

 ;)
« Last Edit: October 03, 2009, 08:35:56 AM by Mars »

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
special:begin
« Reply #6 on: October 02, 2009, 04:56:08 PM »
what you call a bug, is a designed feature. :P

i knew most people would not need to show the output of [special:begin]
but in such case you can just {.comment| everything you want .}
and, to put the text in %symbol% to place it at your wish, you can

[special:begin]
{.set|special:begin|
all you want
/set.}

then you'll recall the value by {.^special:begin.}, anywhere you like.

in the end: you can solve all problems easily at current time.

BUT/MAIS

if change HFS to discard this text, you'll still be able to save it in a variable, and put it in any place of the page (as shown above).
this change would meet most people needs, and still preserve functionality for those who want.
so, if no one dislikes, i will make this change in next release.

cheers

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Abnormality with special:begin
« Reply #7 on: October 02, 2009, 05:15:21 PM »
this version is a good designed feature, the actual version can generate a bug, and they are supposed to give the same result  in any circumstances. If there was no problem with the current version, I would not have emphatically intervened to make the change which I propose.

I agree on a point with you, it is possible to use the macro {. ^special:begin.} instead of %special-begin%, but you should not use of static variable in that case.

But it asks for a little more lines in delphi, the main thing is that it is functional.

Last update:  ;)

Quote
.....
    freeAndNIL(md.aliases)
  end;
end; // tryApplyMacrosAndSymbols

procedure setVarName( varname, value:string; var list: THashedStringList);   //add by mars
begin
with list do
if IndexOfName(varname) < 0 then
  Add(varname+'='+value)
else Values[varname]:=value;
end;


function Tmainfrm.getFolderPage(folder:Tfile; conn:ThttpConn; otpl:Tobject):string;
// we pass the Tpl parameter as Tobject because symbol Ttpl is not defined yet
var
  baseurl, list, fileTpl, folderTpl, linkTpl: string;
  ....
  result:=diffTpl['special:begin'];
  tryApplyMacrosAndSymbols(result, md, FALSE);
  if result>'' then setVarName('special:begin', result, md.cd.vars);   //add by mars
 // cache these values
  fileTpl:=xtpl(diffTpl['file'], table);
  folderTpl:=xtpl(diffTpl['folder'], table);
  linkTpl:=xtpl(diffTpl['link'], table);
  ...
  result:= diffTpl[''];  //mod by mars
.......
procedure Tmainfrm.getPage
  ...
//moved by mars : with an empty section return a result is not necessary
 section:=tpl2use.getSection(sectionName);
  if section = NIL then exit;


 s:=tpl2use['special:begin'];
  tryApplyMacrosAndSymbols(s, md, FALSE);

  if s>'' then setVarName('special:begin', s, md.cd.vars);   //add by mars

  s:=section.txt;   //mod by mars

  if data.conn.reply.mode <> HRM_REPLY then
    s:=xtpl(tpl2use['error-page'], ['%content%', s]);
....

the bug??

put an unknow macro {.blablabla.} into the section [special:begin] and open one web page ~upload+progress

If with this post last one, I do not manage to convince, then I do not have more than to resign  ;) ( bien sûr, je dis ça pour rire ;D )
« Last Edit: October 03, 2009, 08:36:16 AM by Mars »

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Abnormality with special:begin
« Reply #8 on: October 04, 2009, 10:42:15 PM »
i already agreed, and this kind of problems will disappear.
but i think it's not worthwhile to automatically save the text in the variable.
the very few people who will need it, can just use {.set.} and decide the variable name they like.

Offline bacter

  • Operator
  • Tireless poster
  • *****
  • Posts: 682
    • View Profile
Re: Abnormality with special:begin
« Reply #9 on: October 04, 2009, 10:53:24 PM »
I'am with rejetto: people who needs text trom special:init should set it to a variable with set - and a different name - for 'hygienic' reasons: use significant names, don't create confusion!
your computer has no brain - use your own !

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1890
    • View Profile
Re: Abnormality with special:begin
« Reply #10 on: October 04, 2009, 10:57:42 PM »
oK! i will see later with the build 217 ;)