package ONO::Render::Simple;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
use ONO::Lib::DateTime::ToolBox;
use ONO::Render;
use ONO::Render::Placeholders;
#: ONO::Render::Simple is an alternative to ONO::Render, used by some internal
#: modules and functions.
#:
#: We do NOT recommend using this module in your own project scripts.
###############################################################################
# RENDER PRE
###############################################################################
sub render_pre {
#: Similar to ONO::Render's render_pre() function.
my (
$self,
$COOKIE,
$META,
) = @_;
my $BASE = &render_base;
if ($COOKIE) {
$COOKIE = "$COOKIE\n";
}
my $MOD;
if ($ENV{'MOD_PERL'}) {
$MOD = qq~/MP~;
}
my $ROBOTS = "index, follow";
if ($ENV{'REQUEST_URI'} =~ m~^/ono/~) {
$ROBOTS = "noindex, nofollow";
}
my $CSSJS = ONO::Render->cssjs($BASE);
print qq~Content-Type: text/html; charset=UTF-8\n$COOKIE\n<!doctype html>\n
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="$ROBOTS">
<meta name="Generator" content="ONO$MOD">
$CSSJS
$META
<meta name="viewport" content="width=device-width, initial-scale=1">
~;
# print ONO::IO->devstation_refresh();
}
###############################################################################
# RENDER - SIMPLE
###############################################################################
sub render_simple {
#: Quick and simple way to close render_pre(). Note that this is NOT meant
#: as an alternative to ONO::Render's render_simple() function.
print qq~
</head>
<body>
$_[1]
<script>onojs_init_post();</script>
</body>
</html>
~;
}
###############################################################################
# RENDER
###############################################################################
sub render {
#: Similar to ONO::Render's render() function.
my (
$self,
$WEB,
$BODY,
) = @_;
my $BASE = &render_base;
$WEB = ONO::Render::Placeholders->parse($WEB);
my $dark_display;
if ($BODY !~ /ono_render_darken/) {
$dark_display = " hide";
}
if ($WEB =~ /ckeditor/i) {
print qq~<script src="/ono/osr/javascript/ckeditor/ckeditor.js"></script>~;
}
$WEB =~ s~##WIKIOPEN##~\[~g;
$WEB =~ s~##WIKICLOSE##~\]~g;
# eliminate weird spaces in links:
$WEB =~ s~(src|href|action)=" /~$1="/~g;
$WEB =~ s~(src|href|action)=' /~$1='/~g;
if ($BASE) {
$WEB =~ s~(src|href|action)="/~$1="$BASE/~g;
$WEB =~ s~='/~='$BASE/~g;
$WEB =~ s~url\('/~url\('$BASE/~g;
$WEB =~ s~onojs_ajax_load\('/~onojs_ajax_load\('$BASE/~g;
$WEB =~ s~="$BASE$BASE/~="$BASE/~g;
$WEB =~ s~='$BASE$BASE/~='$BASE/~g;
}
print qq~</head><body style="background-color:#f6f6f6"$BODY>
<div id="ono_render_darken" class="trans80 ono_render_darken$dark_display"></div>
$WEB
<script>onojs_init_post();</script>
</body>
</html>
~;
}
###############################################################################
# RENDER
###############################################################################
sub render_base {
#: Returns the document root base, which can be an alternative to ONO::IO's
#: base() function. Used by some internal modules and functions.
my $BASE;
if ($ENV{'REQUEST_URI'} =~ m~^/(.*?)/(.*?)/(cgi-bin|ono)/~) {
$BASE = "/$1/$2";
}
if ($ENV{'REQUEST_URI'} =~ m~^/(.*?)/(.*?)/goto/-/~) {
$BASE = "/$1/$2";
}
return $BASE;
}
###############################################################################
# end of script
###############################################################################
1;
__END__