#!/usr/bin/perl
package RVL::Output;
# WebSite: http://www.rvglobalsoft.com
# Unauthorized copying is strictly forbidden and may result in severe legal action.
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
#
# =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
# This Agreement is a legal contract, which specifies the terms of the license
# and warranty limitation between you and RV Global Soft Co.,Ltd. and RV2Factor Product for RV Global Soft.
# You should carefully read the following terms and conditions before
# installing or using this software. Unless you have a different license
# agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
# indicates your acceptance of the license and warranty limitation terms
# contained in this Agreement. If you do not agree to the terms of this
# Agreement, promptly delete and destroy all copies of the Software.
#
# ===== Grant of License =======
# The Software may only be installed and used on a single host machine.
#
# ===== Disclaimer of Warranty =======
# THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
# WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
# WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE
# AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
# FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE
# ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
# LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
# IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
# CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
# OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
# BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
# NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
# RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
# RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
# BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
# ===============================
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