Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
2828cec8
Commit
2828cec8
authored
20 years ago
by
runemaster
Browse files
Options
Downloads
Patches
Plain Diff
Changes for new templated Who's Online
parent
ea80d7ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web/lib/template.ssjs
+106
-102
106 additions, 102 deletions
web/lib/template.ssjs
with
106 additions
and
102 deletions
web/lib/template.ssjs
+
106
−
102
View file @
2828cec8
/*****************************************************************************/
/* SSJS templating library
*/
/* %%name%% is replaced with the HTML encoded value of template.name
*/
/* ^^name^^ is replaced with the URI encoded value of template.name
*/
/* @@name@@ is replaced with the value if template.name
*/
/*
*/
/* @@name:sname@@ is replaced with the value of template.name.sname
*/
/* (^^ and %% are also supported)
*/
/*
*/
/* @@JS:js_expression@@ is replaced with the return value of js_expression
*/
/* (^^ and %% are also supported)
*/
/*
*/
/* <<REPEAT name>>
*/
/* ... @@name:sname@@ ...
*/
/* <<END REPEAT name>>
*/
/*
*/
/* SSJS templating library
*/
/* %%name%% is replaced with the HTML encoded value of template.name
*/
/* ^^name^^ is replaced with the URI encoded value of template.name
*/
/* @@name@@ is replaced with the value if template.name
*/
/*
*/
/* @@name:sname@@ is replaced with the value of template.name.sname
*/
/* (^^ and %% are also supported)
*/
/*
*/
/* @@JS:js_expression@@ is replaced with the return value of js_expression
*/
/* (^^ and %% are also supported)
*/
/*
*/
/* <<REPEAT name>>
*/
/* ... @@name:sname@@ ...
*/
/* <<END REPEAT name>>
*/
/*
*/
/* Iterates over the array/object template.name and replaces name:sname with */
/* the value of template.name.sname.
*/
/* (^^ and %% are also supported)
*/
/*
*/
/* the value of template.name.sname.
*/
/* (^^ and %% are also supported)
*/
/*
*/
/*****************************************************************************/
/* $Id$ */
template
=
new
Object
;
load
(
"
sbbsdefs.js
"
);
// UFLAG_G
load
(
"
sbbsdefs.js
"
);
// UFLAG_G
load
(
"
../web/lib/html_themes.ssjs
"
);
if
(
http_request
.
virtual_path
==
"
/nodelist.ssjs
"
)
load
(
"
../web/lib/main_nodelist.ssjs
"
);
// Who's Online Listing
load
(
"
../web/lib/leftnav_nodelist.ssjs
"
);
// Left Side Navigation Node Listing
template
.
Theme_CSS_File
=
Themes
[
CurrTheme
].
css
;
function
write_template
(
filename
)
{
var
fname
=
'
../web/templates/
'
+
Themes
[
CurrTheme
].
dir
+
'
/
'
+
filename
;
if
(
!
file_exists
(
fname
))
{
fname
=
'
../web/templates/
'
+
Themes
[
DefaultTheme
].
dir
+
'
/
'
+
filename
;
if
(
!
file_exists
(
fname
))
fname
=
'
../web/templates/
'
+
Themes
[
"
Default
"
].
dir
+
'
/
'
+
filename
;
}
var
inc
=
new
File
(
fname
);
if
(
!
inc
.
open
(
"
r
"
,
true
,
1024
))
{
horrible_error
(
"
!Error
"
+
inc
.
error
+
"
opening template file:
"
+
fname
);
}
var
file
=
''
;
while
(
!
inc
.
eof
)
{
file
=
file
+=
inc
.
read
(
1024
);
}
inc
.
close
();
file
=
file
.
replace
(
/<<REPEAT
(
.*
?)
>>
([\x
00-
\x
ff
]
*
?)
<<END REPEAT
\1
>>/g
,
function
(
matched
,
objname
,
bit
,
offset
,
s
)
{
var
ret
=
''
;
for
(
obj
in
template
[
objname
])
{
ret
+=
parse_regular_bit
(
bit
,
objname
,
template
[
objname
][
obj
]);
}
return
(
ret
);
});
file
=
parse_regular_bit
(
file
,
""
,
template
);
file
=
file
.
replace
(
/
\<\!
-- Magical Synchronet
([\^
%@
])
-code --
\>
/g
,
'
$1
'
);
write
(
file
);
var
fname
=
'
../web/templates/
'
+
Themes
[
CurrTheme
].
dir
+
'
/
'
+
filename
;
if
(
!
file_exists
(
fname
))
{
fname
=
'
../web/templates/
'
+
Themes
[
DefaultTheme
].
dir
+
'
/
'
+
filename
;
if
(
!
file_exists
(
fname
))
fname
=
'
../web/templates/
'
+
Themes
[
"
Default
"
].
dir
+
'
/
'
+
filename
;
}
var
inc
=
new
File
(
fname
);
if
(
!
inc
.
open
(
"
r
"
,
true
,
1024
))
{
horrible_error
(
"
!Error
"
+
inc
.
error
+
"
opening template file:
"
+
fname
);
}
var
file
=
''
;
while
(
!
inc
.
eof
)
{
file
=
file
+=
inc
.
read
(
1024
);
}
inc
.
close
();
file
=
file
.
replace
(
/<<REPEAT
(
.*
?)
>>
([\x
00-
\x
ff
]
*
?)
<<END REPEAT
\1
>>/g
,
function
(
matched
,
objname
,
bit
,
offset
,
s
)
{
var
ret
=
''
;
for
(
obj
in
template
[
objname
])
{
ret
+=
parse_regular_bit
(
bit
,
objname
,
template
[
objname
][
obj
]);
}
return
(
ret
);
});
file
=
parse_regular_bit
(
file
,
""
,
template
);
file
=
file
.
replace
(
/
\<\!
-- Magical Synchronet
([\^
%@
])
-code --
\>
/g
,
'
$1
'
);
write
(
file
);
}
function
parse_regular_bit
(
bit
,
objname
,
obj
)
{
if
(
objname
==
"
JS
"
)
return
(
bit
);
if
(
objname
==
''
)
{
bit
=
bit
.
replace
(
/
([
%^@
])\1([^
^%@
\r\n]
*
?)\:([^
:%^@
\r\n]
*
?)\1\1
/g
,
function
(
matched
,
start
,
objname
,
prop
,
offset
,
s
)
{
var
res
=
matched
;
if
(
template
[
objname
]
!=
undefined
)
res
=
escape_match
(
start
,
template
[
objname
][
prop
]);
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1([^
:^%@
\r\n]
*
?)\1\1
/g
,
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
escape_match
(
start
,
template
[
exp
]);
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1
JS:
([\x
00-
\x
ff
]
*
?)\1\1
/g
,
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
escape_match
(
start
,
eval
(
exp
));
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1(
.*
?)\1\1
/g
,
''
);
}
else
{
bit
=
bit
.
replace
(
new
RegExp
(
'
([%^@])
\\
1
'
+
regex_escape
(
objname
)
+
'
:([^^%@
\r\n
]*?)
\\
1
\\
1
'
,
"
g
"
),
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
matched
;
if
(
obj
[
exp
]
!=
undefined
)
res
=
escape_match
(
start
,
obj
[
exp
]);
return
(
res
);
});
}
return
bit
;
if
(
objname
==
"
JS
"
)
return
(
bit
);
if
(
objname
==
''
)
{
bit
=
bit
.
replace
(
/
([
%^@
])\1([^
^%@
\r\n]
*
?)\:([^
:%^@
\r\n]
*
?)\1\1
/g
,
function
(
matched
,
start
,
objname
,
prop
,
offset
,
s
)
{
var
res
=
matched
;
if
(
template
[
objname
]
!=
undefined
)
res
=
escape_match
(
start
,
template
[
objname
][
prop
]);
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1([^
:^%@
\r\n]
*
?)\1\1
/g
,
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
escape_match
(
start
,
template
[
exp
]);
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1
JS:
([\x
00-
\x
ff
]
*
?)\1\1
/g
,
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
escape_match
(
start
,
eval
(
exp
));
return
(
res
);
});
bit
=
bit
.
replace
(
/
([
%^@
])\1(
.*
?)\1\1
/g
,
''
);
}
else
{
bit
=
bit
.
replace
(
new
RegExp
(
'
([%^@])
\\
1
'
+
regex_escape
(
objname
)
+
'
:([^^%@
\r\n
]*?)
\\
1
\\
1
'
,
"
g
"
),
function
(
matched
,
start
,
exp
,
offset
,
s
)
{
var
res
=
matched
;
if
(
obj
[
exp
]
!=
undefined
)
res
=
escape_match
(
start
,
obj
[
exp
]);
return
(
res
);
});
}
return
bit
;
}
function
escape_match
(
start
,
exp
,
end
)
{
if
(
exp
==
undefined
)
exp
=
''
;
exp
=
exp
.
toString
();
if
(
start
==
"
%
"
)
exp
=
html_encode
(
exp
,
false
,
false
,
false
,
false
);
if
(
start
==
"
^
"
)
exp
=
encodeURIComponent
(
exp
);
exp
=
exp
.
replace
(
/
\@
/g
,
'
<!-- Magical Synchronet @-code -->
'
);
exp
=
exp
.
replace
(
/
\^
/g
,
'
<!-- Magical Synchronet ^-code -->
'
);
exp
=
exp
.
replace
(
/
\%
/g
,
'
<!-- Magical Synchronet %-code -->
'
);
return
(
exp
);
if
(
exp
==
undefined
)
exp
=
''
;
exp
=
exp
.
toString
();
if
(
start
==
"
%
"
)
exp
=
html_encode
(
exp
,
false
,
false
,
false
,
false
);
if
(
start
==
"
^
"
)
exp
=
encodeURIComponent
(
exp
);
exp
=
exp
.
replace
(
/
\@
/g
,
'
<!-- Magical Synchronet @-code -->
'
);
exp
=
exp
.
replace
(
/
\^
/g
,
'
<!-- Magical Synchronet ^-code -->
'
);
exp
=
exp
.
replace
(
/
\%
/g
,
'
<!-- Magical Synchronet %-code -->
'
);
return
(
exp
);
}
function
error
(
message
)
{
template
.
title
=
"
Error
"
;
template
.
err
=
message
;
write_template
(
"
header.inc
"
);
write_template
(
"
error.inc
"
);
write_template
(
"
footer.inc
"
);
exit
();
template
.
title
=
"
Error
"
;
template
.
err
=
message
;
write_template
(
"
header.inc
"
);
write_template
(
"
error.inc
"
);
write_template
(
"
footer.inc
"
);
exit
();
}
function
horrible_error
(
message
)
{
write
(
"
<html><head><title>ERROR</title></head><body><p>
"
+
message
+
"
</p></body></html>
"
);
write
(
"
<html><head><title>ERROR</title></head><body><p>
"
+
message
+
"
</p></body></html>
"
);
exit
();
}
function
regex_escape
(
str
)
{
str
=
str
.
replace
(
/
([\\\^\$\*\+\?\.\(\)\{\}\[\]])
/g
,
"
\\
$1
"
);
return
(
str
);
str
=
str
.
replace
(
/
([\\\^\$\*\+\?\.\(\)\{\}\[\]])
/g
,
"
\\
$1
"
);
return
(
str
);
}
if
(
user
.
number
==
0
)
template
.
user_greeting
=
"
Welcome, Guest.
"
;
template
.
user_greeting
=
"
Welcome, Guest.
"
;
else
if
(
!
(
user
.
security
.
restrictions
&
UFLAG_G
))
template
.
user_greeting
=
"
Welcome,
"
+
user
.
alias
+
"
.<br /> You last visited on
"
+
strftime
(
"
%A, %B %d, %Y
"
,
user
.
stats
.
laston_date
);
else
template
.
user_greeting
=
"
Welcome,
"
+
user
.
alias
+
"
.
"
;
if
(
!
(
user
.
security
.
restrictions
&
UFLAG_G
))
template
.
user_greeting
=
"
Welcome,
"
+
user
.
alias
+
"
.<br /> You last visited on
"
+
strftime
(
"
%A, %B %d, %Y
"
,
user
.
stats
.
laston_date
);
else
template
.
user_greeting
=
"
Welcome,
"
+
user
.
alias
+
"
.
"
;
/* FTP link */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment