summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (lxpbuetow.webde.local) <paul.buetow@1und1.de>2013-09-23 18:06:35 +0200
committerPaul Buetow (lxpbuetow.webde.local) <paul.buetow@1und1.de>2013-09-23 18:06:35 +0200
commitc2ba808bc98b8c6a614b8af5a6b681f81f8c8220 (patch)
tree0edd6a40f504d52d29d3af677404c0d096e2be0d
parent421406d424ae7f6cd41dbafc8da9c371fb3107a4 (diff)
parent1b9b7434445e84eef29ccfda9a80b54c19343df5 (diff)
quick commit
-rw-r--r--COPYING28
-rw-r--r--Makefile29
-rw-r--r--README73
-rw-r--r--TODO7
-rw-r--r--Xerl.pm88
-rw-r--r--Xerl/Base.pm135
-rw-r--r--Xerl/Main/Global.pm96
-rw-r--r--Xerl/Page/Configure.pm171
-rw-r--r--Xerl/Page/Content.pm225
-rw-r--r--Xerl/Page/Document.pm75
-rw-r--r--Xerl/Page/Menu.pm131
-rw-r--r--Xerl/Page/Parameter.pm70
-rw-r--r--Xerl/Page/Request.pm70
-rw-r--r--Xerl/Page/Rules.pm95
-rw-r--r--Xerl/Page/Templates.pm241
-rw-r--r--Xerl/Tools/FileIO.pm188
-rw-r--r--Xerl/XML/Element.pm111
-rw-r--r--Xerl/XML/Reader.pm163
-rwxr-xr-xindex.fpl21
-rwxr-xr-xindex.pl18
-rw-r--r--paul.buetow.org/content/99.Imprint.xml150
-rw-r--r--xerl.conf23
22 files changed, 2136 insertions, 72 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..bf161b3
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,28 @@
+# Xerl (c) 2005-2009,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of P. B. Labs nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..757c3fc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,29 @@
+all:
+replace:
+ for i in index.pl Xerl.pm xerl.conf; \
+ do \
+ sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" $$i && mv -f .tmp $$i; \
+ done
+ find ./Xerl -name '*.pm' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.pl' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.log' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ find ./Xerl -name '*.xml' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+ chmod 755 index.pl
+perltidy:
+ find . -name \*.fpl | xargs perltidy -i=2 -b
+ find . -name \*.pl | xargs perltidy -i=2 -b
+ find . -name \*.pm | xargs perltidy -i=2 -b
+ find . -name \*.bak | xargs rm -f
+todo:
+ grep -R TODO . | grep -v Makefile | grep -v .git
+warn:
+ perl index.pl 2> warnings
+ less warnings
+ rm -f warnings
+kb:
+ find . -name '*.pm' -exec du -hs {} \; | awk 'BEGIN{kb=0}{kb+=$$1}END{print kb}'
diff --git a/README b/README
new file mode 100644
index 0000000..b9257fc
--- /dev/null
+++ b/README
@@ -0,0 +1,73 @@
+STYLEGUIDE:
+
+Always do:
+
+Pragmatic modules ALWAYS to use in ALL packages:
+
+use strict;
+use warnings;
+
+Only for packages for including package UNIVERSAL definitions
+
+use Xerl::Page::Base;
+
+Object oriented coding style
+
+Always use method prototypes if possible
+
+sub foo($;$) { .... }
+
+Explicit object typing if possible
+
+my Class::Name::Here $foo = Class::Name::Here->new();
+
+If no real ret val, set undef; explicitly
+
+sub foo() {
+ # Do some stuff
+...
+# Set explicit undef ret value
+return undef;
+}
+
+Private subs use _ as its prefix and are called only from the current package.
+
+package Xerl::Foo::Bla;
+.
+.
+
+sub _iamprivate($) {
+my Xerl::Foo:Bla $self = $_[0];
+.
+.
+}
+
+sub iampublic($) {
+my Xerl::Foo:Bla $self = $_[0];
+$self->_iamprivate();
+return undef;
+}
+
+Static subs (not OOP) are in CAPITAL letters.
+
+sub IAMSTATIC($) {
+print shift;
+return 'Hello World';
+}
+
+sub iamdynamic($) {
+my Xerl::Foo:Bla $self = $_[0];
+return Xerl::Foo::Bla::IAMSTATIC( $self->get_somevalue() );
+}
+
+Static private subs start with _ and are written in CAPITAL letters
+
+sub _IAMSTATICPRIVATE() {
+.
+.
+}
+
+Use Pidy to automaically restyle the code! (make perltidy)
+
+Mark things which are still to do with TODO: at any place in the source
+tree. (Can be searched for using 'make todo').
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..c8feee7
--- /dev/null
+++ b/TODO
@@ -0,0 +1,7 @@
+Hint: Run 'make todo' to see everything in every file what is to do!
+
+TODO: - Documentation of all features/options
+TODO: - Fix XML bug
+TODO: - Use Template Tool Kit
+TODO: - Use X?HTML5 by default
+TODO: - Support a Debian package
diff --git a/Xerl.pm b/Xerl.pm
new file mode 100644
index 0000000..c8d816a
--- /dev/null
+++ b/Xerl.pm
@@ -0,0 +1,88 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl;
+
+use strict;
+use warnings;
+
+use CGI::Carp 'fatalsToBrowser';
+use Time::HiRes 'gettimeofday';
+
+use Xerl::Base;
+use Xerl::Main::Global;
+use Xerl::Page::Configure;
+use Xerl::Page::Document;
+use Xerl::Page::Parameter;
+use Xerl::Page::Request;
+use Xerl::Page::Templates;
+
+sub run($) {
+ my Xerl $self = $_[0];
+ my $time = [gettimeofday];
+
+ my Xerl::Page::Request $request =
+ Xerl::Page::Request->new( request => $ENV{REQUEST_URI} );
+
+ $request->parse();
+ my Xerl::Page::Configure $config =
+ Xerl::Page::Configure->new( config => $self->get_config(), %$request );
+
+ $config->parse();
+ return undef if $config->finish_request_exists();
+
+ $config->defaults();
+
+ my Xerl::Page::Parameter $parameter =
+ Xerl::Page::Parameter->new( config => $config );
+
+ $parameter->parse();
+ return undef if $config->finish_request_exists();
+
+ if ( $config->document_exists() ) {
+ my Xerl::Page::Document $document =
+ Xerl::Page::Document->new( config => $config );
+
+ $document->parse();
+ return undef if $config->finish_request_exists();
+
+ }
+ else {
+ my Xerl::Page::Templates $templates =
+ Xerl::Page::Templates->new( config => $config );
+
+ $templates->parse();
+ return undef if $config->finish_request_exists();
+ $templates->print($time);
+ }
+
+ return undef;
+}
+
+1;
diff --git a/Xerl/Base.pm b/Xerl/Base.pm
new file mode 100644
index 0000000..589e325
--- /dev/null
+++ b/Xerl/Base.pm
@@ -0,0 +1,135 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package UNIVERSAL;
+
+use strict;
+use warnings;
+
+sub new ($;) {
+ my $self = shift;
+
+ bless {@_} => $self;
+}
+
+sub setval($$$) {
+ my UNIVERSAL $self = $_[0];
+
+ $self->{ $_[1] } = $_[2];
+
+ return undef;
+}
+
+sub getval($$) {
+ my UNIVERSAL $self = $_[0];
+
+ return defined $self->{ $_[1] } ? $self->{ $_[1] } : '';
+}
+
+sub exists($$) {
+ my UNIVERSAL $self = $_[0];
+
+ return exists $self->{ $_[1] } ? 1 : 0;
+}
+
+sub AUTOLOAD {
+ my UNIVERSAL $self = $_[0];
+ my $auto = our $AUTOLOAD;
+ return $self if $auto =~ /DESTROY/;
+
+ if ( $auto =~ /.*::set_(.+)$/ ) {
+ $self->{$1} = $_[1];
+
+ }
+ elsif ( $auto =~ /.*::get_(.+)_ref$/ ) {
+ return defined $self->{$1} ? \$self->{$1} : [''];
+
+ }
+ elsif ( $auto =~ /.*::get_(.+)$/ ) {
+ return defined $self->{$1} ? $self->{$1} : '';
+
+ }
+ elsif ( $auto =~ /.*::undef_(.+)$/ ) {
+ return '' unless defined $self->{$1};
+
+ my $retval = $self->{$1};
+ undef $self->{$1};
+ return $retval;
+
+ }
+ elsif ( $auto =~ /.*::append_(.+)$/ ) {
+ if ( defined $self->{$1} ) {
+ $self->{$1} .= $_[1];
+
+ }
+ else {
+ $self->{$1} = $_[1];
+ }
+
+ }
+ elsif ( $auto =~ /.*::push_(.+)$/ ) {
+ if ( exists $self->{$1} ) {
+ push @{ $self->{$1} }, $_[1];
+
+ }
+ else {
+ $self->{$1} = [ $_[1] ];
+ }
+
+ }
+ elsif ( $auto =~ /.*::first_(.+)$/ ) {
+ return exists $self->{$1} ? ${ $self->{$1} }[0] : '';
+
+ }
+ elsif ( $auto =~ /.*::(.+)_exists$/ ) {
+ return exists $self->{$1} ? 1 : 0;
+
+ }
+ elsif ( $auto =~ /.*::(.+)_length$/ ) {
+ return ( ref $self->{$1} eq 'ARRAY' ) ? scalar @{ $self->{$1} } : 0;
+
+ }
+ elsif ( $auto =~ /.*::(.+)_isset$/ ) {
+ return exists $self->{$1} ? $self->{ $_[0] } : 0;
+
+ }
+ elsif ( $auto =~ /.*::debug$/ ) {
+ print "DEBUG: @_\n";
+ return undef;
+
+ }
+ else {
+ print "$auto is not a method of $self or UNIVERSAL\n";
+ }
+
+ return $self;
+}
+
+1;
+
diff --git a/Xerl/Main/Global.pm b/Xerl/Main/Global.pm
new file mode 100644
index 0000000..f70ef6d
--- /dev/null
+++ b/Xerl/Main/Global.pm
@@ -0,0 +1,96 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Main::Global;
+
+sub SHUTDOWN {
+ exit 0;
+
+ # Never reach this point
+ return undef;
+}
+
+sub DEBUG {
+ print 'Debug::', @_, "\n";
+
+ return undef;
+}
+
+sub ERROR {
+ print "Content-Type: text/plain\n\nXerl runtime error: ",
+ join( ' ', time, @_ );
+
+ Xerl::Main::Global::SHUTDOWN();
+
+ # Never reach this point
+ return undef;
+}
+
+sub PLAIN {
+ print "Content-Type: text/plain\n\n";
+
+ DEBUG(@_) if @_;
+
+ return undef;
+}
+
+sub REDIRECT ($) {
+ my $location = shift;
+ print "Status: 301 Moved Permanantly\n";
+ print "Location: $location\n\n";
+ return undef;
+}
+
+sub _HTTP_DESCR ($;$) {
+ my ( $status, $infomsg ) = @_;
+
+ $infomsg //= '';
+
+ if ( $status == 404 ) {
+ "Status: 404 Not Found $infomsg\015\012\n\n"
+
+ }
+ else {
+ "Status: 405 Method not allowed $infomsg\015\012\n\n";
+ }
+}
+
+sub HTTP {
+ my $descr = _HTTP_DESCR(shift);
+ print $descr;
+ local $, = ' ';
+ print $descr;
+
+ Xerl::Main::Global::SHUTDOWN();
+
+ # Never reach this point
+ return undef;
+}
+
+1;
diff --git a/Xerl/Page/Configure.pm b/Xerl/Page/Configure.pm
new file mode 100644
index 0000000..1a9ecde
--- /dev/null
+++ b/Xerl/Page/Configure.pm
@@ -0,0 +1,171 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Configure;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::Tools::FileIO;
+use Xerl::XML::Element;
+
+sub parse($) {
+ my Xerl::Page::Configure $self = $_[0];
+
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $self->get_config() );
+
+ if ( -1 == $file->fslurp() ) {
+ $self->set_finish_request(1);
+ return undef;
+ }
+
+ my $re = qr/^(.+?) *=(.+?) *\n?$/;
+
+ for ( @{ $file->get_array() } ) {
+ next if /^ *#/;
+
+ $self->setval( $1, $self->eval($2) ) if $_ =~ $re;
+ }
+
+ return $self;
+}
+
+sub defaults($) {
+ my Xerl::Page::Configure $self = $_[0];
+
+ $self->set_proto('https') if exists $ENV{HTTPS};
+
+ $self->set_site( $self->get_defaultcontent() )
+ unless $self->site_exists();
+
+ $self->set_nsite( $self->get_site() =~ /^(?:\d*\.)?(.*)/ );
+
+ $self->set_template( $self->get_defaulttemplate() )
+ unless $self->template_exists();
+
+ $self->set_style( $self->get_defaultstyle() )
+ unless $self->style_exists();
+
+ $self->set_proto( $self->get_defaultproto() )
+ unless $self->proto_exists();
+
+ $self->set_host( lc $ENV{HTTP_HOST} )
+ unless $self->host_exists();
+
+ unless ( -d $self->get_hostroot() . $self->get_host() ) {
+ my $redirect = $self->get_hostroot() . 'redirect:' . $self->get_host();
+ if ( -f $redirect ) {
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $redirect );
+ $file->fslurp();
+ my $location = $file->shift();
+ Xerl::Main::Global::REDIRECT($location);
+ $self->set_finish_request(1);
+ }
+ my $alias = $self->get_hostroot() . 'alias:' . $self->get_host();
+ if ( -f $alias ) {
+ my Xerl::Tools::FileIO $file =
+ Xerl::Tools::FileIO->new( 'path' => $alias );
+ $file->fslurp();
+ $self->set_host( $file->shift() );
+ }
+ }
+
+ $self->set_outputformat( $self->get_defaultoutputformat() )
+ unless $self->outputformat_exists();
+
+ if ( $self->format_exists() ) {
+ $self->set_outputformat( $self->get_format() );
+ $self->set_template( $self->get_format() );
+ $self->set_site( $self->get_format() );
+ $self->set_nocache(1)
+ if $self->get_format() =~ /\.feed$/;
+ }
+
+ $self->set_host( $self->getval( $self->get_host() ) )
+ if $self->exists( $self->get_host() );
+
+ $self->set_host( $self->getval( $self->get_host() ) )
+ if $self->exists( $self->get_host() );
+
+ my $request_subdir = $self->get_request_subdir();
+ $self->set_hostpath(
+ $self->get_hostroot() . $self->get_host() . $request_subdir . "/" );
+
+ $self->set_defaulthostpath(
+ $self->get_hostroot() . $self->get_defaulthost() . '/' );
+
+ $self->set_cachepath(
+ $self->get_cacheroot() . $self->get_host() . $request_subdir . '/' );
+
+ $self->set_htdocspath( $self->get_hostpath() . 'htdocs/' );
+
+ $self->set_templatespath( $self->get_hostpath() . 'templates/' );
+
+ $self->set_contentpath( $self->get_hostpath() . 'content/' );
+
+ # $self->set_ipv6( $ENV{REMOTE_ADDR} =~ /:/ ? 1 : 0 );
+
+ return undef;
+}
+
+sub eval($$) {
+ my Xerl::Page::Configure $self = $_[0];
+ my $val = $_[1];
+
+ $val =~ s/^!(.+)/`$1`/eo;
+ return $val;
+}
+
+sub insertxmlvars($$) {
+ my Xerl::Page::Configure $self = $_[0];
+ my Xerl::XML::Element $element = $_[1];
+
+ $element = $element->starttag('variables');
+
+ return $self
+ unless defined $element
+ or $element->get_array() eq 'ARRAY';
+
+ my $text;
+ for ( @{ $element->get_array() } ) {
+ $text = $_->get_text();
+ chomp $text;
+
+ $text =~ s/%%(.*?)%%/$self->getval($1)/eg;
+ $self->setval( $_->get_name(), $text );
+ }
+
+ return $self;
+}
+
+1;
+
diff --git a/Xerl/Page/Content.pm b/Xerl/Page/Content.pm
new file mode 100644
index 0000000..d9d7d34
--- /dev/null
+++ b/Xerl/Page/Content.pm
@@ -0,0 +1,225 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Content;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+
+use Xerl::XML::Reader;
+use Xerl::XML::Element;
+use Xerl::Page::Rules;
+use Xerl::Page::Configure;
+
+sub parse($) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my Xerl::XML::Reader $xmlcontent = Xerl::XML::Reader->new(
+ path => $config->get_templatepath(),
+ config => $config
+ );
+
+ if ( -1 == $xmlcontent->open() ) {
+ $config->set_finish_request(1);
+ return undef;
+ }
+
+ $xmlcontent->parse();
+
+ my Xerl::Page::Rules $rules = Xerl::Page::Rules->new( config => $config );
+ $rules->parse( $config->get_xmlconfigrootobj() )
+ unless $config->exists('noparse');
+
+ $config->insertxmlvars( $config->get_xmlconfigrootobj() );
+ $self->insertrules( $rules, $xmlcontent->get_root() );
+
+ return undef;
+}
+
+sub insertrules($$$$) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Rules $rules = $_[1];
+ my Xerl::XML::Element $element = $_[2];
+
+ # Start inserting rules at <content>
+ $element = $element->starttag('content');
+
+ # If there is no <content>-tag, dont use a rule!
+ return unless defined $element;
+
+ my @content;
+ my $params = $element->get_params();
+
+ unshift @content, "Content-Type: $params->{type}\n\n"
+ if ref $params eq 'HASH' and exists $params->{type};
+
+ push @content, $self->_insertrules( $rules, $element );
+ $self->set_content( \@content );
+
+ return undef;
+}
+
+sub _insertrules($$$) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Rules $rules = $_[1];
+ my Xerl::XML::Element $element = $_[2];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my $nonewlines = 0;
+
+ #$element->print();
+ #
+ # Don't interate through the XML childs if we have a leaf node.
+ return () unless ref $element->get_array() eq 'ARRAY';
+ my ( $name, $rule, @content, $text, $params );
+
+ for my $succ ( @{ $element->get_array() } ) {
+ $name = $succ->get_name();
+ $text = $succ->get_text();
+ $params = $succ->get_params();
+
+ # Remove leading and ending whitespaces, also ending newlines.
+ $text =~ s/^ *(.*)( |\n)*$/$1/g;
+ unless ( ref( $rule = $rules->getval($name) ) eq 'ARRAY' ) {
+ if ( lc $name eq 'noop' ) {
+ if ( ref $succ->get_array() eq 'ARRAY' ) {
+ push @content, $self->_insertrules( $rules, $succ );
+
+ }
+ else {
+ push @content, "$text\n";
+ }
+
+ }
+ elsif ( lc $name eq 'tag' ) {
+ push @content, "<$text>\n";
+
+ }
+ elsif ( lc $name eq 'perl' ) {
+
+ # Perl content will be interpreted by Xerl::Page::Templates::print later
+ push @content, '<perl>', $text, '</perl>';
+
+ }
+ elsif ( lc $name eq 'navigation' ) {
+ my $menus = $config->get_menuobj()->get_array();
+
+ if ( ref $menus eq 'ARRAY' ) {
+ push @content, $self->_insertrules( $rules, $_ ) for @$menus;
+ }
+
+ }
+ else {
+
+ # No rule available, use the tag unmodified!
+ $name =~ s/^=//o; # Remove the leading =
+ if ( $succ->get_single() ) {
+ push @content, "<$name" . ( $succ->params_str() || '' ) . " />\n"
+
+ }
+ else {
+ push @content,
+ "<$name" . ( $succ->params_str() || '' ) . '>',
+ $self->_insertrules( $rules, $succ ), $text, "</$name>\n";
+ }
+ }
+
+ }
+ else {
+
+ # Get a local copy of lrule, because orule may be modified.
+ # And then insert special vars if required:
+ # @@text@@ => Text content of the current tag.
+
+ my $ruleparams = $rule->[2];
+ $nonewlines = 1 if exists $ruleparams->{nonewlines};
+
+ my ( $orule, $crule ) = ( $rule->[0], $rule->[1] );
+
+ $self->_insert_special_vars( $rules, $succ, \$orule );
+ $self->_insert_special_vars( $rules, $succ, \$crule );
+ chomp $orule;
+
+ # Parse for known tag params.
+ if ( ref $params eq 'HASH' ) {
+ Xerl::Page::Templates::PARSELINE( $config, '%%', \$text );
+
+ # <tag basename='yes'>path/to/file.bla</tag> => <tag>file.bla</tag>
+ $text =~ s#.*/(.*)$#$1# if lc $params->{basename} eq 'yes';
+
+ # <tag cut='?'>foo.bar.tld?options</tag> => <tag>?options</tag>
+ if ( exists $params->{cut} ) {
+ my $cut = quotemeta $params->{cut};
+ $text =~ s/.*$cut(.*)$/$1/o;
+ }
+
+ $text .= $params->{addback}
+ if exists $params->{addback};
+ $text = $params->{addfront} . $text
+ if exists $params->{addfront};
+ }
+
+ my $oadd =
+ exists $ruleparams->{addfront}
+ ? '<' . $ruleparams->{addfront}
+ : '';
+
+ my $cadd =
+ exists $ruleparams->{addback} ? $ruleparams->{addback} . '>' : '';
+
+ push @content, $orule, $oadd, $self->_insertrules( $rules, $succ ),
+ $text, $cadd, $crule;
+ }
+ }
+
+ return $nonewlines ? map { s/\n/ /go; $_ } @content : @content;
+}
+
+sub _insert_special_vars($$$$) {
+ my Xerl::Page::Content $self = $_[0];
+ my Xerl::Page::Rules $rules = $_[1];
+ my Xerl::XML::Element $element = $_[2];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my $rtext = $_[3];
+
+ $$rtext =~ s/@\@text\@\@/$_=$element->get_text();chomp;$_/geo;
+ $$rtext =~ s/@\@ln\@\@//go;
+
+ if ( $$rtext =~ /@\@(.*?)\@\@/ ) {
+ my $params = $element->get_params();
+ return unless ref $params eq 'HASH';
+ $$rtext =~ s/@\@(.*?)\@\@/$params->{$1}||''/geo;
+ }
+
+ return undef;
+}
+
+1;
diff --git a/Xerl/Page/Document.pm b/Xerl/Page/Document.pm
new file mode 100644
index 0000000..afc4da3
--- /dev/null
+++ b/Xerl/Page/Document.pm
@@ -0,0 +1,75 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Document;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::Main::Global;
+use Xerl::Page::Configure;
+use Xerl::Tools::FileIO;
+
+sub parse($) {
+ my Xerl::Page::Document $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ return undef unless $config->document_exists();
+
+ my $document = $config->get_document();
+ my ($filename) = $document =~ m#([^/]+)$#;
+ my ($postfix) = $document =~ /\.(.+)$/;
+ my $path;
+
+ print 'Content-Type: ';
+ print $config->getval( 'ctype.' . lc($postfix) ), "\n";
+ print "Content-Disposition: attachment; filename=\"$filename\"\n\n";
+
+ $path = $config->get_hostpath() . "/htdocs/$document";
+ unless ( -f $path ) {
+ $path =
+ $config->get_hostroot()
+ . $config->get_defaulthost()
+ . "/htdocs/$document";
+ }
+
+ my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new( path => $path );
+
+ if ( -1 == $io->fslurp() ) {
+ $config->set_finish_request(1);
+ }
+ else {
+ $io->print();
+ }
+
+ return undef;
+}
+
+1;
diff --git a/Xerl/Page/Menu.pm b/Xerl/Page/Menu.pm
new file mode 100644
index 0000000..3bd158b
--- /dev/null
+++ b/Xerl/Page/Menu.pm
@@ -0,0 +1,131 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Menu;
+
+use strict;
+use warnings;
+
+use Xerl::Page::Configure;
+use Xerl::Tools::FileIO;
+use Xerl::XML::Element;
+
+sub generate($;$) {
+ my Xerl::Page::Menu $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my @site = split /\//, $config->get_site();
+ my @compare = @site;
+ my $site = pop @site;
+
+ my ( $content, $siteadd ) = ( 'content/', '' );
+
+ my Xerl::XML::Element $menuelem =
+ $self->get_menu( $content, $siteadd, shift @compare );
+
+ $self->push_array($menuelem)
+ if $menuelem->first_array()->array_length() > 1;
+
+ for my $s (@site) {
+ $content .= "$s.sub/";
+ $siteadd .= "$s/";
+ $menuelem = $self->get_menu( $content, $siteadd, shift @compare );
+ $self->push_array($menuelem)
+ if $menuelem->first_array()->array_length() > 1;
+ }
+
+ return undef;
+}
+
+sub get_menu($$$$) {
+ my Xerl::Page::Menu $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my ( $content, $siteadd, $compare ) = ( @_[ 1 ... 2 ], lc $_[3] );
+ my $issubsection = $content =~ m{\.sub/$};
+ my $pattern = qr/\.(?:xml)|(?:sub)$/;
+
+ my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new(
+ path => $config->get_hostpath() . $content,
+ basename => 1,
+ );
+
+ unless ( $io->exists() ) {
+ Xerl::Main::Global::REDIRECT( $config->get_404() );
+ $config->set_finish_request(1);
+ }
+
+ $io->dslurp();
+ my $dir = $io->get_array();
+
+ my ( @prec, @dir );
+ map {
+ if (/^\d+\..+\./) { push @prec, $_ }
+ else { push @dir, $_ }
+ }
+ grep {
+ $_ !~ /^home\.xml$/i
+ && $_ !~ /\.feed\.xml$/i
+ && $_ !~ /\.hide\.xml$/i
+ } @$dir;
+
+ my Xerl::XML::Element $root = Xerl::XML::Element->new();
+ my Xerl::XML::Element $menu = Xerl::XML::Element->new();
+
+ $menu->set_name('menu');
+
+ for ( $issubsection ? ( @dir, @prec ) : ( 'home.xml', @dir, @prec ) ) {
+ my ($site) = /(.*)$pattern/o;
+
+ $site =~ s#\.$#/home#o;
+ $site =~ s/^\d+\.//;
+
+ my $linkname = $site;
+ $linkname =~ s/(?:\d+\.)?(.)/\U$1/o;
+ $compare .= '/' if $linkname =~ s#(.*/)[^/]+$#$1#;
+
+ my Xerl::XML::Element $item = Xerl::XML::Element->new(
+ params => { link => "?site=$siteadd$site" },
+ text => $linkname
+ );
+
+ $compare =~ s/^(\d+\.)//;
+ $item->set_name(
+ lc $linkname eq lc $compare ? 'activemenuitem' : 'menuitem' );
+
+ $item->set_prev($menu);
+ $menu->push_array($item);
+ }
+
+ $root->push_array($menu);
+ $menu->set_prev($root);
+
+ return $root;
+}
+
+1;
diff --git a/Xerl/Page/Parameter.pm b/Xerl/Page/Parameter.pm
new file mode 100644
index 0000000..ba0a6cd
--- /dev/null
+++ b/Xerl/Page/Parameter.pm
@@ -0,0 +1,70 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Parameter;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::Main::Global;
+use Xerl::Page::Configure;
+use Xerl::Tools::FileIO;
+
+sub parse($) {
+ my Xerl::Page::Parameter $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ print "Content-Type: text/plain\n\n"
+ if $config->plain_exists();
+
+ if ( $config->href_exists() ) {
+ print "Location: ", $config->get_href(), "\n\n";
+ $config->set_finish_request(1);
+ }
+ elsif ( $config->env_exists() ) {
+ print "Content-Type: text/plain\n\n";
+ print "$_=", $ENV{$_}, "\n" for keys %ENV;
+ $config->set_finish_request(1);
+ }
+
+ if ( $config->devel_exists() ) {
+ $config->set_nocache(1);
+ }
+
+ if ( $config->conf_exists() ) {
+ print "Content-Type: text/plain\n\n";
+ print "$_=", $config->{$_}, "\n" for keys %$config;
+ $config->set_finish_request(1);
+ }
+
+ return $self;
+}
+
+1;
diff --git a/Xerl/Page/Request.pm b/Xerl/Page/Request.pm
new file mode 100644
index 0000000..11106ec
--- /dev/null
+++ b/Xerl/Page/Request.pm
@@ -0,0 +1,70 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Request;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+
+sub parse($) {
+ my Xerl::Page::Request $self = $_[0];
+ my $request = $self->get_request();
+
+ # Secure it!
+ $request =~ s#/\.\.##g;
+
+ # Remove last /
+ $request =~ s#/$##;
+
+ my $request_subdir = $request;
+ $request_subdir =~ s#/\?.*##;
+ $self->set_request_subdir($request_subdir);
+
+ # List context returns $1
+ ($_) = $request =~ /\?(.+)/;
+
+ return $self unless defined;
+
+ my $params = '';
+ for ( split /&/ ) {
+
+ # List context uses ($1,$2) as method args
+ $self->setval(/(.+?)=(.+)/);
+ $params .= "&amp;$1=$2" if $1 ne 'site';
+ }
+
+ $self->set_params($params);
+
+ return undef;
+}
+
+1;
+
diff --git a/Xerl/Page/Rules.pm b/Xerl/Page/Rules.pm
new file mode 100644
index 0000000..3895f4e
--- /dev/null
+++ b/Xerl/Page/Rules.pm
@@ -0,0 +1,95 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Rules;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::XML::Element;
+use Xerl::Page::Configure;
+
+sub parse($) {
+ my Xerl::Page::Rules $self = $_[0];
+ my Xerl::XML::Element $element = $_[1];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ $element = $element->starttag2( 'rules', $config->get_outputformat() );
+ return unless defined $element;
+
+ # Open and close rules:
+ my ( $orule, $crule );
+
+ # For all available rules in config.xml
+ for my $rule ( @{ $element->get_array() } ) {
+ my $params = $rule->get_params();
+
+ $orule = $rule->get_text();
+ chomp $orule;
+
+ $orule =~ s/\[/</go;
+ $orule =~ s/\]/>/go;
+
+ unless (
+ ref $params eq 'HASH'
+ && ( lc $params->{end} eq 'yes'
+ || lc $params->{start} eq 'yes' )
+ )
+ {
+ $crule = join '><', reverse split /> *</, $orule;
+ $crule = "<$crule>";
+ $crule =~ s/<</</go;
+ $crule =~ s/>>/>/go;
+ $crule =~ s/</<\//go;
+ $crule =~ s/\n//go;
+ $crule =~ s/ .+?>/>/go;
+ $crule .= "\n";
+
+ }
+ else {
+ if ( lc $$params{start} eq 'yes' ) {
+ $crule = '';
+
+ }
+ else {
+ $crule = $orule;
+ $orule = '';
+ }
+ $crule .= "\n";
+ }
+
+ $params = {} unless ref $params eq 'HASH';
+ $self->setval( $rule->get_name(), [ "$orule\n", $crule, $params ] );
+ }
+
+ return undef;
+}
+
+1;
diff --git a/Xerl/Page/Templates.pm b/Xerl/Page/Templates.pm
new file mode 100644
index 0000000..e018682
--- /dev/null
+++ b/Xerl/Page/Templates.pm
@@ -0,0 +1,241 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Page::Templates;
+
+use strict;
+use warnings;
+
+use Time::HiRes 'tv_interval';
+use Digest::MD5;
+
+use Xerl::Base;
+use Xerl::Page::Configure;
+use Xerl::Page::Content;
+use Xerl::Page::Menu;
+use Xerl::Tools::FileIO;
+
+use constant RECURSIVE => 1;
+
+sub parse($) {
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my $site = $config->get_site();
+
+ my $subpath = $site;
+ if ( $site =~ s#^.*/(.*)$#$1#o ) {
+ $subpath =~ s#/[^/]+$#/#;
+ $subpath =~ s#/#.sub/#go;
+
+ }
+ else {
+ $subpath = '';
+ }
+
+ my $cachefile =
+ $config->get_template() . ';'
+ . $config->get_outputformat() . ';'
+ . $site
+ . ( $config->noparse_exists() ? '.noparse' : '' )
+ . '.cache';
+
+ my $cachepath = $config->get_cachepath() . $subpath;
+
+ if ( -f $cachepath . $cachefile
+ && ( $config->usecache_exists() or not $config->nocache_exists() ) )
+ {
+
+ my Xerl::Tools::FileIO $io =
+ Xerl::Tools::FileIO->new( path => $cachepath . $cachefile );
+
+ if ( -1 == $io->fslurp() ) {
+ $config->set_finish_request(1);
+ return undef;
+ }
+
+ $self->set_array( $io->get_array() );
+
+ }
+ else {
+ my $xmlconfigpath = $config->get_hostpath() . 'config.xml';
+
+ $xmlconfigpath = $config->get_defaulthostpath() . 'config.xml'
+ unless -f $xmlconfigpath;
+
+ my Xerl::XML::Reader $xmlconfigreader =
+ Xerl::XML::Reader->new( path => $xmlconfigpath, config => $config );
+
+ if ( -1 == $xmlconfigreader->open() ) {
+ $config->set_finish_request(1);
+ return undef;
+ }
+
+ $xmlconfigreader->parse();
+ $config->set_xmlconfigrootobj( $xmlconfigreader->get_root() );
+
+ my Xerl::Page::Menu $menu = Xerl::Page::Menu->new( config => $config );
+
+ $menu->generate();
+ $config->set_menuobj($menu);
+
+ if ( $site =~ /^(\d+)\./ ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath$site.xml" );
+ }
+ elsif ( -f $config->get_hostpath() . "content/$subpath$site.xml" ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath$site.xml" );
+ }
+
+ # Hidden files
+ elsif ( -f $config->get_hostpath() . "content/$subpath.$site.xml" ) {
+ $config->set_templatepath(
+ $config->get_hostpath() . "content/$subpath.$site.xml" );
+ }
+ else {
+ my $glob = $config->get_hostpath() . "content/$subpath*.$site.xml";
+ eval "(\$glob) = sort <$glob>;";
+ $config->set_templatepath($glob);
+ }
+
+ my Xerl::Page::Content $bodycontent =
+ Xerl::Page::Content->new( config => $config );
+
+ $bodycontent->parse();
+
+ my $templatepath =
+ $config->get_hostpath() . "templates/" . $config->get_template() . '.xml';
+
+ $templatepath =
+ $config->get_defaulthostpath()
+ . "templates/"
+ . $config->get_template() . '.xml'
+ unless -f $templatepath;
+
+ $config->set_templatepath($templatepath);
+
+ my Xerl::Page::Content $templatecontent =
+ Xerl::Page::Content->new( config => $config );
+
+ $templatecontent->parse();
+
+ $self->set_array( $templatecontent->get_content() );
+ $config->set_content( $bodycontent->get_content() );
+ $self->parsetemplate( '%%', RECURSIVE );
+
+ my Xerl::Tools::FileIO $io = Xerl::Tools::FileIO->new(
+ path => $cachepath,
+ filename => $cachefile,
+ array => $self->get_array(),
+ );
+
+ $io->fwrite();
+ }
+
+ $self->parsetemplate('$$'); # Parsing dynamic vars.
+ return undef;
+}
+
+sub parsetemplate($$;$) {
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+ my $deepnesslevel = $_[2] || 0;
+
+ return $self if $deepnesslevel == 100;
+
+ my ( $sep, $foundflag ) = quotemeta $_[1];
+
+ PARSELINE( $config, $sep, \$_, \$foundflag ) for @{ $self->get_array() };
+
+ return $self->parsetemplate( $_[1], $deepnesslevel + 1 )
+ if defined $deepnesslevel > 0 and $foundflag;
+
+ return undef;
+}
+
+# Static sub
+sub PARSELINE($$$;$) {
+ my Xerl::Page::Configure $config = $_[0];
+ my ( $sep, $line, $foundflag ) = @_[ 1 .. 3 ];
+
+ $$line =~ s/$sep(!)?(.+?)$sep/
+ defined $1 ? `$2` :
+ (ref $config->getval($2) eq 'ARRAY')
+ ? join '', @{$config->getval($2)} :
+ $config->getval($2)/eg and $$foundflag = 1;
+
+ return undef;
+}
+
+sub print($;$) {
+ my Xerl::Page::Templates $self = $_[0];
+ my Xerl::Page::Configure $config = $self->get_config();
+
+ my ( $code, $flag ) = ( '', 0 );
+ my $time = $_[1];
+ my $hflag = 1;
+
+ for my $line ( @{ $self->get_array() } ) {
+ if ( $hflag == 1 && $config->exists('noparse') ) {
+ $line =~ s#^Content-Type.*#Content-Type: text/plain#i;
+ $hflag = 0;
+ }
+ $line =~ s/ +/ /g;
+ redo if !$flag and $line =~ s/<perl>((?:.|\n)*?)<\/perl>/eval $1/ego;
+
+ if ( !$flag and $line =~ s/<perl>(.*)$//o ) {
+ $code .= $1;
+ $flag = 1;
+
+ }
+ elsif ( $line =~ s/^(.*?)<\/perl>/eval $code.$1/eo ) {
+ ( $code, $flag ) = ( '', 0 );
+ redo;
+
+ }
+ elsif ($flag) {
+ $line =~ s/^(.*\n)$//o;
+ $code .= $1;
+ next;
+ }
+
+ my $time = defined $time ? sprintf '%1.4f', tv_interval($time) : '';
+
+ $line =~ s/!!TIME!!/$time/ge;
+ $line =~ s/!!LT!!/</g;
+ $line =~ s/!!GT!!/>/g;
+ $line =~ s#!!URL\((.+?)\)!!#<a href="$1">$1</a>#g;
+ print $line;
+ }
+
+ return undef;
+}
+
+1;
diff --git a/Xerl/Tools/FileIO.pm b/Xerl/Tools/FileIO.pm
new file mode 100644
index 0000000..72239ee
--- /dev/null
+++ b/Xerl/Tools/FileIO.pm
@@ -0,0 +1,188 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::Tools::FileIO;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::Main::Global;
+
+sub dslurp($;$) {
+ my Xerl::Tools::FileIO $self = $_[0];
+
+ my $path = $self->get_path();
+
+ $path .= '/' unless $path =~ /\/$/;
+ opendir my $dir, $path or Xerl::Main::Global::ERROR( $!, $path, caller() );
+
+ my @dir = sort
+ map { $path . $_ }
+ grep { /^[^\.]/o } readdir($dir);
+
+ @dir = map { s#.*/([^/]+\..+)$#$1#o; $_ } @dir
+ if $self->basename_exists();
+
+ closedir $dir;
+ $self->set_array( \@dir );
+
+ return undef;
+}
+
+sub fslurp($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ my $path = SECUREPATH( $self->get_path() );
+
+ unless ( -f $path ) {
+ Xerl::Main::Global::HTTP( 404, "Not found: $path" );
+ return -1;
+ }
+
+ open my $file, $path or Xerl::Main::Global::ERROR( $!, $path, caller() );
+ flock $file, 2;
+
+ my @slurp = <$file>;
+
+ flock $file, 3;
+ close $file;
+
+ $self->set_array( \@slurp );
+
+ return 0;
+}
+
+sub exists($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ my $path = SECUREPATH( $self->get_path() );
+
+ return -e $path;
+}
+
+sub fwrite($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ $self->_fwrite(0);
+
+ return undef;
+}
+
+sub fwriteappend($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+
+ $self->_fwrite(1);
+
+ return undef;
+}
+
+sub _fwrite($;$) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ my $append = $_[1];
+
+ my ( $path, $filename ) =
+ ( SECUREPATH( $self->get_path() ), SECUREPATH( $self->get_filename() ) );
+
+ my $path_ = '';
+ for ( split /\//, $path ) {
+ $path_ .= $_ . '/';
+ mkdir $path_
+ or Xerl::Main::Global::ERROR( $!, $path_, caller() )
+ unless -d $path_;
+ }
+
+ my $f;
+ if ( $append == 0 ) {
+ open $f, ">$path$filename"
+ or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() );
+
+ }
+ else {
+ open $f, ">>$path$filename"
+ or Xerl::Main::Global::ERROR( $!, $path . $filename, caller() );
+ }
+
+ flock $f, 2;
+ print $f @{ $self->get_array() };
+ flock $f, 3;
+ close $f;
+
+ return undef;
+}
+
+sub print($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+
+ print @{ $self->get_array() };
+
+ return undef;
+}
+
+sub reverse_array($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+
+ my @array = reverse @{ $self->get_array() };
+ $self->set_array( \@array );
+
+ return undef;
+}
+
+sub merge($$) {
+ my Xerl::Tools::FileIO( $self, $other ) = @_;
+
+ my @merged = ( @{ $self->get_array() }, @{ $other->get_array() } );
+ my Xerl::Tools::FileIO $fio = Xerl::Tools::FileIO->new();
+
+ $fio->set_array( \@merged );
+ return $fio;
+}
+
+sub shift($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ chomp( my $shift = shift @{ $self->get_array() } );
+
+ return $shift;
+}
+
+sub pop($) {
+ my Xerl::Tools::FileIO $self = $_[0];
+ chomp( my $pop = pop @{ $self->get_array() } );
+
+ return $pop;
+}
+
+use overload '+' => \&merge;
+
+sub SECUREPATH($) {
+ my $path = $_[0];
+
+ $path =~ s/\.\.+\/?//g;
+
+ return $path;
+}
+
+1;
diff --git a/Xerl/XML/Element.pm b/Xerl/XML/Element.pm
new file mode 100644
index 0000000..ba94807
--- /dev/null
+++ b/Xerl/XML/Element.pm
@@ -0,0 +1,111 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::XML::Element;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+
+sub starttag($$) {
+ my Xerl::XML::Element $self = $_[0];
+ my ( $name, $temp ) = ( $_[1], undef );
+
+ return $self if $self->get_name() eq $name;
+ return undef if ref $self->get_array() ne 'ARRAY';
+
+ for ( @{ $self->get_array() } ) {
+ $temp = $_->starttag($name);
+ return $temp if defined $temp;
+ }
+
+ return undef;
+}
+
+sub starttag2($$$) {
+ my Xerl::XML::Element $self = $_[0];
+ my ( $name, $after ) = @_[ 1 ... 2 ];
+
+ my Xerl::XML::Element $element = $self->starttag($name);
+ return $element->starttag($after) if defined $element;
+
+ return undef;
+}
+
+sub params_str($) {
+ my Xerl::XML::Element $self = $_[0];
+ my $params = $self->get_params();
+
+ return if $params eq '';
+
+ return join '', map { " $_=\"" . $params->{$_} . '"' } keys %$params;
+}
+
+# Only for testing
+sub print($) {
+ my Xerl::XML::Element $self = $_[0];
+ print $self. "::print(\$)\n";
+
+ my $sub;
+ $sub = sub {
+ my ( $element, $spaceing ) = @_;
+ my $spaces = ' ' x $spaceing;
+
+ print $spaces, '<', $element->get_name(), ">\n";
+ print "$spaces [$_=", _no_newline( $$element{$_} ), "]\n"
+ for keys %$element;
+
+ #if ($element->exists('params')) {
+ if ( $element->params_exists() ) {
+ print "$spaces Params:\n";
+ while ( my ( $key, $val ) = each %{ $element->get_params() } ) {
+ print "$spaces $key=$val\n";
+ }
+ }
+
+ return unless ref $element->get_array() eq 'ARRAY';
+ $sub->( $_, $spaceing + 1 ) for @{ $element->get_array() };
+ };
+
+ $sub->( $self, 0 );
+ print $self. "::print(\$)::END\n";
+
+ return undef;
+}
+
+sub _no_newline($) {
+ my $line = $_[0];
+
+ $line =~ s/\n//g;
+
+ return $line;
+}
+
+1;
diff --git a/Xerl/XML/Reader.pm b/Xerl/XML/Reader.pm
new file mode 100644
index 0000000..3605c04
--- /dev/null
+++ b/Xerl/XML/Reader.pm
@@ -0,0 +1,163 @@
+# Xerl (c) 2005-2011,2013 Dipl.-Inform. (FH) Paul C. Buetow
+#
+# E-Mail: xerl@dev.buetow.org WWW: http://xerl.buetow.org
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of buetow.org nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED Paul C. Buetow ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT Paul C. Buetow BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+package Xerl::XML::Reader;
+
+use strict;
+use warnings;
+
+use Xerl::Base;
+use Xerl::XML::Element;
+
+sub open($) {
+ my Xerl::XML::Reader $self = $_[0];
+
+ my Xerl::Tools::FileIO $xmlfile =
+ Xerl::Tools::FileIO->new( path => $self->get_path() );
+
+ return -1 if -1 == $xmlfile->fslurp();
+ $self->set_array( $xmlfile->get_array() );
+
+ return 0;
+}
+
+sub parse($) {
+ my Xerl::XML::Reader $self = $_[0];
+
+ my $rarray = $self->get_array();
+ return $self unless ref $rarray eq 'ARRAY';
+
+ my Xerl::XML::Element $element = Xerl::XML::Element->new();
+ my Xerl::XML::Element( $root, $next, $prev, $insert );
+
+ # Prove and remove XML Header.
+ Xerl::Main::Global::ERROR( 'No valid XML header', caller() )
+ unless $rarray->[0] =~ s/<\?xml .*?version.+?\?>//io;
+
+ my ( $newlineadd, $linecount, $notrim ) = ( 0, 0, 0 );
+
+ #for my $line (@$rarray) {
+ for my $line (@$rarray) {
+ $newlineadd = 1 if length $line == 1 and $linecount > 3;
+ ++$linecount;
+
+ $line =~ s/\\</!!LT!!/g;
+ $line =~ s/\\>/!!GT!!/g;
+
+ # Allow <tag />
+ my $is_single_tag = $line =~ s#<([^/].+?)( (.*?))? ?/ *>#<$1 $3></$1>#o;
+
+ my $flag = 0;
+
+ do {
+
+ # Open XML tag
+ if ( $line =~ s#<([^/].+?)( (.*?))? *>##o ) {
+ my ( $name, $params ) = ( $1, $3 );
+ $flag = 1;
+
+ my $DEBUG = $name =~ /^=/ ? 1 : 0;
+ $self->debug($name, $params) if $DEBUG;
+
+ # Ignore XML comments
+ next if $name =~ /^!--/o;
+
+
+ $next = Xerl::XML::Element->new();
+ $next->set_name($name);
+ $next->set_prev($element);
+ $next->set_single($is_single_tag);
+
+ $next->print() if $DEBUG;
+
+ # Handle tag parameters
+ if ( defined $params ) {
+ my %params = $params =~ /
+ (?: ( [^\s]+? ) \s*=\s* (
+ (?: '(?:.|(?:\\'))*?' ) |
+ (?: "(?:.|(?:\\"))*?" ) |
+ (?: [^\s]+ ) ) )
+ /gox;
+
+ # Remove " and '
+ $params{$_} =~ s/^(?:"|')|(?:"|')$//go for keys %params;
+ $next->set_params( \%params );
+ $notrim = 1 if exists $params{notrim};
+ }
+
+ $element->push_array($next);
+
+ $root = $element unless defined $root;
+ $element = $next;
+ $insert = $element;
+
+ redo;
+ }
+
+ # Close XML tag
+ if ( $line =~ s#<(/.+?)>##o ) {
+ $flag = 1;
+
+ #print "XML::<$1>\n";
+
+ $insert = $element;
+ $prev = $element->get_prev();
+ $element = $prev if defined $prev;
+ $notrim = 0 if $notrim;
+
+ redo;
+ }
+
+ # XML text
+ if ( defined $insert
+ and $line =~ s/^( *)(.+?) *$/$notrim ? $1.$2 : $2/oe )
+ {
+
+ if ($newlineadd) {
+ $insert->append_text("\n");
+ $newlineadd = 0;
+ }
+
+ $line =~ s/!!LT!!/</g;
+ $line =~ s/!!GT!!/>/g;
+
+ $insert->append_text($line);
+ }
+ } while ( $flag == 1 );
+ }
+
+ $root->set_name('root');
+
+ # $root->print();
+ $self->set_root($root);
+
+ return undef;
+}
+
+1;
diff --git a/index.fpl b/index.fpl
new file mode 100755
index 0000000..d13cd6f
--- /dev/null
+++ b/index.fpl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Xerl;
+
+use FCGI;
+use Socket;
+use Sys::Hostname;
+
+my $host = hostname();
+my $config =
+ -e "xerldev-$host.conf"
+ ? "xerldev-$host.conf"
+ : ( -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' );
+
+while ( FCGI::accept >= 0 ) {
+ my Xerl $xerl = Xerl->new( config => $config );
+ $xerl->run();
+}
diff --git a/index.pl b/index.pl
new file mode 100755
index 0000000..1846180
--- /dev/null
+++ b/index.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Xerl;
+
+use Socket;
+use Sys::Hostname;
+
+my $host = hostname();
+my $config =
+ -e "xerldev-$host.conf"
+ ? "xerldev-$host.conf"
+ : ( -e "xerl-$host.conf" ? "xerl-$host.conf" : 'config.conf' );
+
+my Xerl $xerl = Xerl->new( config => $config );
+$xerl->run();
diff --git a/paul.buetow.org/content/99.Imprint.xml b/paul.buetow.org/content/99.Imprint.xml
index c7f6c6c..c1c69b7 100644
--- a/paul.buetow.org/content/99.Imprint.xml
+++ b/paul.buetow.org/content/99.Imprint.xml
@@ -1,75 +1,81 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<content>
- <pagetitle>Imprint</pagetitle>
- <text>
- <noop>In case you have work for me or have any other comments to pass, please choose your contact method...</noop>
- <enumeration>
- <enumitem>
- <noop>
- <strong>Address / Snail Mail:</strong>
- </noop>
- <newline />
- <noop>Dipl.-Inform. (FH) Paul C. B&uuml;tow</noop>
- <newline />
- <noop>Schneidem&uuml;hler Stra&szlig;e 12c</noop>
- <newline />
- <noop>D-76139 Karlsruhe-Waldstadt</noop>
- <newline />
- <noop>Germany / Deutschland</noop>
- <newline />
- <newline />
- </enumitem>
- <enumitem>
- <noop>
- <strong>Mailing Lists:</strong>
- </noop>
- <newline />
- <hyperlink>http://lists.buetow.org</hyperlink>
- <newline />
- <newline />
- </enumitem>
- <enumitem>
- <noop>
- <strong>Ticket and Mail:</strong>
- </noop>
- <newline />
- <noop>Ticket system:</noop>
- <javascript>
- // Anti-Spam
- function strrev(str) {
- if (!str) return '';
- var revstr = '';
- for (var i = str.length-1; i>=0; i--)
- revstr += str.charAt(i)
- return revstr;
- }
- var array = new Array('gro', '.', 'woteub', '@', 'tseuqer');
- for (var i = array.length - 1; i >= 0; --i) {
- document.write(strrev(array[i]));
- }
- </javascript>
- <newline />
- <newline />
- <noop>Mail:</noop>
- <javascript>
- // Anti-Spam
- function strrev(str) {
- if (!str) return '';
- var revstr = '';
- for (var i = str.length-1; i>=0; i--)
- revstr += str.charAt(i)
- return revstr;
- }
- var array = new Array('gro', '.', 'woteub', '@', 'luap');
- for (var i = array.length - 1; i >= 0; --i) {
- document.write(strrev(array[i]));
- }
- </javascript>
- <newline />
- <noop>GPG/PGP public key ID: 0x37EC5C1D </noop>
- <newline />
- <newline />
- </enumitem>
- </enumeration>
- </text>
+ <pagetitle>Imprint</pagetitle>
+ <text>
+ <noop>In case you have work for me or have any other comments to pass, please choose your contact method...</noop>
+ <enumeration>
+ <enumitem>
+ <noop>
+ <strong>Address / Snail Mail:</strong>
+ </noop>
+ <newline />
+ <noop>Dipl.-Inform. (FH) Paul C. B&uuml;tow</noop>
+ <newline />
+ <noop>Schneidem&uuml;hler Stra&szlig;e 12c</noop>
+ <newline />
+ <noop>D-76139 Karlsruhe-Waldstadt</noop>
+ <newline />
+ <noop>Germany / Deutschland</noop>
+ <newline />
+ <newline />
+ </enumitem>
+ <enumitem>
+ <noop>
+ <strong>Jabber/XMPP:</strong>
+ </noop>
+ <newline />
+ <javascript>
+ // Anti-Spam
+ function strrev(str) {
+ if (!str) return '';
+ var revstr = '';
+ for (var i = str.length-1; i>=0; i--)
+ revstr += str.charAt(i)
+ return revstr;
+ }
+ var array = new Array('gro', '.', 'woteub', '@', 'luap');
+ for (var i = array.length - 1; i >= 0; --i) {
+ document.write(strrev(array[i]));
+ }
+ </javascript>
+ <newline />
+ <noop>GPG/PGP public key ID: 0x37EC5C1D </noop>
+ <newline />
+ <newline />
+ </enumitem>
+ <enumitem>
+ <noop>
+ <strong>Mail:</strong>
+ </noop>
+ <newline />
+ <javascript>
+ // Anti-Spam
+ function strrev(str) {
+ if (!str) return '';
+ var revstr = '';
+ for (var i = str.length-1; i>=0; i--)
+ revstr += str.charAt(i)
+ return revstr;
+ }
+ var array = new Array('gro', '.', 'woteub', '@', 'luap');
+ for (var i = array.length - 1; i >= 0; --i) {
+ document.write(strrev(array[i]));
+ }
+ </javascript>
+ <newline />
+ <noop>GPG/PGP public key ID: 0x37EC5C1D </noop>
+ <newline />
+ <newline />
+ </enumitem>
+ <enumitem>
+ <noop>
+ <strong>Mailing Lists:</strong>
+ </noop>
+ <newline />
+ <hyperlink>http://lists.buetow.org</hyperlink>
+ <newline />
+ <newline />
+ </enumitem>
+ </enumeration>
+ </text>
</content>
diff --git a/xerl.conf b/xerl.conf
new file mode 100644
index 0000000..5873c22
--- /dev/null
+++ b/xerl.conf
@@ -0,0 +1,23 @@
+# TODO: Allow comments behind the options!
+# defaultproto will be used if not ENV(HTTPS)==on
+#nocache=defined
+#nocache=1
+cacheroot=/usr/local/www/xerlcache/
+ctype.asc=text/plain
+ctype.css=text/css
+ctype.jpg=image/jpg
+ctype.pdf=application/pdf
+ctype.png=image/png
+ctype.txt=text/plain
+ctype.xml=text/plain
+defaultcontent=home
+defaulthost=default
+defaultoutputformat=xhtml
+defaultproto=http
+defaultstyle=default.css
+defaulttemplate=xhtml
+dslvpnrouter.buetow.org=vpndslrouter.buetow.org
+hidesubhome=1
+hostroot=/usr/local/www/xerlhosts/branches/stable/hosts/
+hyperion.buetow.org=ssl.buetow.org
+404=http://www.buetow.org