CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/root/usr/local/rvglobalsoft/rvglobalsoft/lib/RVL/
Upload File :
Current File : //proc/2/root/usr/local/rvglobalsoft/rvglobalsoft/lib/RVL/Output.pm

#!/usr/bin/perl
package RVL::Output;
##LICENSE##
use strict;
use warnings;
use Data::Dumper qw(Dumper);
use Class::Std::Utils;
{
    # class attribute
    my ($props);
    
    sub new {
        my ($class, $opt) = @_;
        my (%hash);
        $hash{ENV} = \%ENV;
        my ($this) = bless( \%hash, $class);
        return $this;
    }
    
=help
 Returns a singleton Registry instance.
=cut
    sub singleton {
        my ($class) = __PACKAGE__;
        if (!defined $RVL::INSTANCE{$class}) {
            $RVL::INSTANCE{$class} = $class->new();
        }
        return $RVL::INSTANCE{$class};
    }

=HEAD2
    HEADER 
=item
   Add header
   Ex: setHeader(-keep_alive => 'timeout=15, max=100');
   See: http://search.cpan.org/dist/CGI/lib/CGI.pm#CALLING_CGI.PM_ROUTINES
=cut
    sub setHeader {
        my ($this, $header) = @_;
        if (RVL::String::array_search($header, @{$this->{aHeaders}}) eq '') {
            push(@{$this->{aHeaders}}, $header);
        }   
    }
=item
    Get header 
=cut
    sub getHeader {
        my ($this) = @_;
        return defined $this->{aHeaders} ? @{$this->{aHeaders}} : ();
    }
    
    sub addCssFile {
        my ($this, $file) = @_;
        if (RVL::String::is_array($file)) {
            foreach my $cssFile (@{$file}) {
                if (RVL::String::array_search($cssFile, $this->{aCssFiles}) eq '') {
                    push(@{$this->{aCssFiles}}, $cssFile);
                }
            }
        } else {
            if (RVL::String::array_search($file, $this->{aCssFiles}) eq '') {
                push(@{$this->{aCssFiles}}, $file);
            }
        }
    }
    
=help
   with array: [%O.makeCssOptimizerLink(["file1.css","file2.css"])%]
   with string: [%O.makeCssOptimizerLink("file1.css,file2.css")%]
=cut
    sub makeCssOptimizerLink
    {
        my ($this) = shift;
        my ($aDefaultThemeFiles) = shift;
        my ($theme) = $this->{theme};
        my (@defaultCssFiles) = ("common.css","tools.css");
        my (@defaultGlobalCssFiles) = ('js/jquery-ui/themes/smoothness/jquery-ui-1.8.15.custom.css');
        
        if ($aDefaultThemeFiles && $aDefaultThemeFiles ne '') {
            if (RVL::String::is_array($aDefaultThemeFiles)) {
                @defaultCssFiles = @{$aDefaultThemeFiles};
            } elsif (RVL::String::is_string($aDefaultThemeFiles)) {
                @defaultCssFiles = split(/,/, $aDefaultThemeFiles);
            }
        }
        
        #PIORITY FOR EDIT JQUERY-UI FOR MODULE
        my ($ref) = '';
        foreach my $link (@defaultGlobalCssFiles) {
            next if($link eq '');
            $link = RVL::Task::SetupConstant::getBaseUrl() . "\/$link";
            $ref .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$link\" />\n";
        }
         
        my (@aCurrentFiles) = $this->{aCssFiles};
        $this->{aCssFiles} = [];
                
        foreach my $file (@defaultCssFiles) {
            my ($filecss) = "themes/$theme/css/$file";
            $this->addCssFile($filecss);
        }
        
        $this->addCssFile(@aCurrentFiles);
        
        foreach my $link (@{$this->{aCssFiles}}) {
        	next if !defined $link;
            next if($link eq '');
            $link = RVL::Task::SetupConstant::getBaseUrl() . "\/$link";
            $ref .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$link\" />\n";
        }
     
        return $ref;
    }

=help
    Push file js
=cut
    sub addJavascriptFile {
        my ($this, $file) = @_;
        if (RVL::String::is_array($file)) {
            foreach my $javascriptFile (@{$file}) {
                if (RVL::String::array_search($javascriptFile, $this->{aJavascriptFiles}) eq '') {
                    push(@{$this->{aJavascriptFiles}}, $javascriptFile);
                }
            }
        } else {
            if (RVL::String::array_search($file, $this->{aJavascriptFiles}) eq '') {
                push(@{$this->{aJavascriptFiles}}, $file);
            }
        }
    }

=help
    Add Js by priority
    with array: [%O.makeJsOptimizerLink(["file1.js","file2.js"])%]
    with string: [%O.makeJsOptimizerLink("file1.js,file2.js")%]
=cut    
    sub makeJsOptimizerLink {
    	
    	my ($this) = shift;
        my ($aJsFiles) = shift;
        my $ref = '';
        my @defaultJsFiles = ("jquery-1.6.2.min.js", "jquery-ui-1.8.15.custom.min.js");
               
        if ($aJsFiles && $aJsFiles ne '') {
            if (RVL::String::is_array($aJsFiles)) {
                @defaultJsFiles = @{$aJsFiles};
            } elsif (RVL::String::is_string($aJsFiles)) {
                @defaultJsFiles = split(/,/, $aJsFiles);
            }
        }
     	
     	my (@aCurrentFiles) = $this->{aJavascriptFiles};
     	$this->{aJavascriptFiles} = [];
     	foreach my $file (@defaultJsFiles) {
     		$file = "js/jquery-ui/$file";
     		$this->addJavascriptFile($file);
        }
        $this->addJavascriptFile(@aCurrentFiles);
     	
     	
     	my $req = RVL::Request::singleton();
        my $moduleName = $req->get("moduleName");
        my $managerName = RVL::Inflector::getManagerNameFromSimplifiedName($req->get("managerName"));
        my $webRoot = RVL::Task::SetupConstant::getWebRoot();
        if (-f "$webRoot/js/RVL/$moduleName/$managerName.js") {
        	$this->addJavascriptFile("js/RVL/$moduleName/" . $managerName . ".js");
        }
     	
     	foreach my $link (@{$this->{aJavascriptFiles}}) {
           next if($link eq '');
           $link = RVL::Task::SetupConstant::getBaseUrl() . "\/$link";
           $ref .= "<script type=\"text/javascript\" src=\"$link\"></script>\n";
        }

        return $ref;
    }
    
    sub makeJsOptimizerLink2 {
    	
    	my ($this) = shift;
        my ($aJsFiles) = shift;
        my $ref = '';
        my @defaultJsFiles = ("jquery-1.6.2.min.js", "jquery-ui-1.8.15.custom.min.js");
               
        if ($aJsFiles && $aJsFiles ne '') {
            if (RVL::String::is_array($aJsFiles)) {
                @defaultJsFiles = @{$aJsFiles};
            } elsif (RVL::String::is_string($aJsFiles)) {
                @defaultJsFiles = split(/,/, $aJsFiles);
            }
        }
     	
     	my (@aCurrentFiles) = $this->{aJavascriptFiles};
     	$this->{aJavascriptFiles} = [];
     	foreach my $file (@defaultJsFiles) {
     		$file = "js/contextmenu/$file";
     		$this->addJavascriptFile($file);
        }
        $this->addJavascriptFile(@aCurrentFiles);
     	
     	foreach my $link (@{$this->{aJavascriptFiles}}) {
           next if($link eq '');
           $link = RVL::Task::SetupConstant::getBaseUrl() . "\/$link";
           $ref .= "<script type=\"text/javascript\" src=\"$link\"></script>\n";
        }

        return $ref;
    }
   
    sub addjQueryEvent {
    	my ($this) = shift;
    }
    
    sub makejQueryEvent {
    	my ($this) = shift;
    }
    
    sub generateSelect {
        my ($this) = shift;
        my ($value) = shift;
        my ($selete) = shift;
        my ($translation) = shift;
        
        my $code = '';
        if (ref $value eq 'HASH') {
             foreach my $k (keys %{$value}) {
                 my ($lang) = (defined $translation && $translation eq 1) ? $this->tr($value->{$k}): $value->{$k};
                 if (defined $selete && $selete eq $k) {
                    $code .= "<option value=\"$k\" selected=\"selected\">$lang</option>\n";
                 } else {
                    $code .= "<option value=\"$k\">$lang</option>\n";
                 }
             }
        } elsif (ref $value eq 'ARRAY') {
            foreach my $k (@{$value}) {
                my ($lang) = (defined $translation && $translation eq 1) ? $this->tr($k): $k;
                if (defined $selete && $selete eq $k) {
                    $code .= "<option value=\"$k\" selected=\"selected\">$lang</option>\n";
                 } else {
                    $code .= "<option value=\"$k\">$lang</option>\n";
                 }
            }
        }
        return $code;
    }
    
    sub tr {
        my ($this) = shift;
        my ($key) = shift;
        my (@aParams) = @_;
        return $this->translate($key, @aParams);
    }
    
    sub translate {
        my ($this) = shift;
        my ($key) = shift;
        my (@aParams) = @_;
        return '' if ($key eq '');
        my ($translate) = RVL::Registry::singleton()->get('translation'); 
        return ${$translate}->translate($key, @aParams);
    }
    
    sub msgGet {
        my ($this) = shift;
        RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
        my ($message) = RVL::Session::get('message');
        my ($messageType) = RVL::Session::get('messageType');
        my ($html) = '';
        if ($message) {
            RVL::Session::remove('message');
            RVL::Session::remove('messageType');
            my ($class) = 'error';
            if ($messageType eq __CONSTANT__::RVL_MESSAGE_INFO) {
                $class = 'info';
            } elsif ($messageType eq __CONSTANT__::RVL_MESSAGE_WARNING) {
                $class = 'warning';
            } elsif ($messageType eq __CONSTANT__::RVL_MESSAGE_SUCCESS) {
                $class = 'success';
            } else {
                $class = 'error';
            }
            $html .= "<p class=\"message-$class\">$message</p>";
        }
        return $html;
    }
    
    sub makeUrl {
        my ($this, $action, $manager, $module) = @_;
        my $req = RVL::Request::singleton();
        my $frontScriptName = RVL::CpHandle::singleton()->getFrontScriptName();
        my $moduleName = (defined $module && $module ne '') ? $module : $req->get("moduleName");
        my $managerName = (defined $manager && $manager ne '') ? $manager : $req->get("managerName");
        # output: site.frontScriptName?/moduleName/managerName/action/actionMapping

        if (!defined $action || $action eq '') {
            return sprintf("%s?/%s/%s", $frontScriptName, $moduleName, $managerName);
        } else {
            return sprintf("%s?/%s/%s/action/%s", $frontScriptName, $moduleName, $managerName, $action);
        }
    }
    
    sub redirect {
        my ($this, $module, $manager, $action) = @_;
        my ($obj) = RVL::Output::singleton();
        my ($url) = $obj->makeUrl($action, $manager, $module);
        RVL::logMessage('redirect URL: ' . $url, __CONSTANT__::RVL_LOG_DEBUG);
        my (@header) = ();
        @header = (
            -X_Powered_By => 'RV Framework http://www.rvglobalsoft.com',
            -location => $url,
        );
        
        foreach my $listOutput ($obj->getHeader()) {
            push(@header, $listOutput);
        }

        print RVL::Session::singleton()->header(@header);
        RVL::Session::singleton()->flush();
        RVL::exit();
    }
    
    sub isAdmin {
        my ($this) = shift;   
        if ($this->isRoot() || $this->isReseller()) {
        	return 1;
        } else {
        	return 0;
        }
    }
    
    sub isRoot {
    	my ($this) = shift;   
    	return RVL::CpHandle::singleton()->isRoot();
    }
    
    sub isReseller {
    	my ($this) = shift;   
    	return RVL::CpHandle::singleton()->isReseller();
    }
    
    sub isUser {
    	my ($this) = shift;   
    	return RVL::CpHandle::singleton()->isUser();
    }
    
    sub getExecutionTime {
        my ($this) = shift;   
    }
    
    sub getQueryCount {
        my ($this) = shift;   
    }
    
    sub getMemoryUsage {
        my ($this) = shift;   
    }
    
    sub dump {
    	my ($this) = shift;   
    	my ($dump) = shift;
        return '<pre>' . Dumper($dump) . '</pre>';
    }
    
    sub fatalErrorsDisplay{
    	my ($this , $html) = @_;
    	print $html;
    }
}
1;

Copyright 2K16 - 2K18 Indonesian Hacker Rulez