CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/cwd/usr/local/rvglobalsoft/rvsitebuilder7/auto/RVSInstaller/
Upload File :
Current File : //proc/2/cwd/usr/local/rvglobalsoft/rvsitebuilder7/auto/RVSInstaller/Template.pm

#!/usr/bin/perl
##LICENSE##

package RVSInstaller::Template;

use strict;
#use warnings;
use File::Basename;
use Cwd 'realpath';
use RVSInstaller::Process;
use RVSInstaller::Language;

sub new{
    my $class = shift;
    my %raw_opt = @_;
    my $seft = {
        masterTemplate => 'default.html',
        template => '',
        pageTitle => '',
        subTemplateFolder => '',
        %raw_opt,
    };
    bless($seft, $class);

    return $seft;
}

sub displayTemplate {
    my $self = shift;
    
    my $templateFolder = dirname(realpath(dirname(__FILE__))).'/templates/';
    my $cacheTmplFolder = $templateFolder.'cache/';
    
    if (!-d $cacheTmplFolder) {
        RVSInstaller::Process::mkdirp($cacheTmplFolder);
    }
    
    if ($self->{subTemplateFolder} ne '') {
        $templateFolder .= $self->{subTemplateFolder};
        
        
        if (!-d $cacheTmplFolder.$self->{subTemplateFolder}) {
            RVSInstaller::Process::mkdirp($cacheTmplFolder.$self->{subTemplateFolder});
        }
    }
    my $tmplData = '';
    if (-e $templateFolder.$self->{masterTemplate}) {
        $tmplData = $self->_buildTemplate($templateFolder, $cacheTmplFolder, $self->{masterTemplate});
    }
    
    return $tmplData;
}

sub _buildTemplate($$$) {
    my $self = shift;
    my ($templateFolder, $cacheTmplFolder, $templateFile) = @_;
    
    my @fileName = ();
    (@fileName) = split('\.', $templateFile, 2);
    print STDERR $fileName[0]."\n\n\n\n";
    our $translate = RVSInstaller::Language->new(
        'Path' => '/home/pannawitch/public_html/workspace/rvsubversion/auto/lang',
        'Language' => 'en',
        'GlobalFile' => 'global',
        'GlobalFileType' => 'ini.php',
        'LangFile' => $fileName[0],
        'LangFileType' => 'ini',
    );
    
    my $tmplData = '';
    
    if (-e $templateFolder.$templateFile) {
        if (open(my $readTmplFile, '<', $templateFolder.$templateFile)) {
            #find include template
            foreach my $tmplReadLine (<$readTmplFile>) {
                if ($tmplReadLine =~ m/\{##([a-zA-Z0-9_\-\.]+?.html?)##\}/) {
                    my $file = $1;
                    print STDERR "match include file {##filename.htm##} $file";
                    #call _buildTemplate
                    my $data = $self->_buildTemplate($templateFolder, $cacheTmplFolder, $file);
                    my $line = $tmplReadLine;
                    $line =~ s/\{##([a-zA-Z0-9_\-\.]+?.html?)##\}/$data/;
                    $tmplData .= $line;
                } elsif ($tmplReadLine =~ m/\{##content##\}/) {
                    #match template file {##content##}
                    #call _buildTemplate
                    my $data = $self->_buildTemplate($templateFolder, $cacheTmplFolder, $self->{template});
                    my $line = $tmplReadLine;
                    $line =~ s/\{##content##\}/$data/;
                    $tmplData .= $line;
                } elsif ($tmplReadLine =~ m/\{translate#(.+?)#\}/) {
                    #match translate text {translate#message to translate#}
                    #my $replace = $tmplReadLine;
                    while ($tmplReadLine =~ m/\{translate#(.+?)#\}/g) {
                        my $key = $1;
                        my $data = $translate->TranSlate($key);
                        $tmplReadLine =~ s/\{translate#(.+?)#\}/$data/;
                    }
                    $tmplData .= $tmplReadLine;
                } else {
                    #match other in form of {#xxx#}
                    if ($tmplReadLine =~ m/\{#([a-zA-Z0-9_\-\.]+?)#\}/) {
                        while ($tmplReadLine =~ m/\{#([a-zA-Z0-9_\-\.]+?)#\}/g) {
                            my $key = $1;
                            $tmplReadLine =~ s/\{#([a-zA-Z0-9_\-\.]+?)#\}/$self->{output}->{$key}/ if (defined($self->{output}->{$key}));
                        }
                    }
                    $tmplData .= $tmplReadLine;
                }
            }
            close($readTmplFile);
        }
    }
    
    if ($templateFile eq $self->{masterTemplate}) {
        if (open(my $writeTmplCache, '>', $cacheTmplFolder)) {
            print $writeTmplCache $tmplData;
            close($writeTmplCache);
        }
    }
    
    return $tmplData;
}

1;
__END__

Copyright 2K16 - 2K18 Indonesian Hacker Rulez