<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// WebSite: http://www.rvglobalsoft.com
// Unauthorized copying is strictly forbidden and may result in severe legal action.
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
//
// =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
// Copyright (c) 2006 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 RV Site Builder.
// 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.
// +---------------------------------------------------------------------------+
// $Id$
// +---------------------------------------------------------------------------+
/**
* RvSiteBuilder config libary
*
* @package RvsLibs
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
if (class_exists('RvsLibs_Config') === false) {
class RvsLibs_Config
{
/**
* Get Admin Owner Config wich config name
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $configName
* @return string ; return null if not found key config name
*/
public static function getOwnerConf($configName)
{
///Debug SGL::logMessage(null, PEAR_LOG_DEBUG);
$oMgr = SGL_Manager::singleton();
$valueConf = null;
switch ($configName) {
case 'AllowExportProject':
/* use CpHandle : witoon , modify CpHandle by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL::logMessage('Error cannot get owner config. ' . $oCp->getMessage(), PEAR_LOG_DEBUG);
SGL_Error::pop();
return false;
}
$valueConf = $oCp->isAllowExportProject();
break;
case 'AllowImportProject':
/* use CpHandle : witoon, modify by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL::logMessage('Error cannot get owner config. ' . $oCp->getMessage(), PEAR_LOG_DEBUG);
SGL_Error::pop();
return false;
}
$valueConf = $oCp->isAllowImportProject();
break;
case 'AllowDIYTemplate':
//$oMgr->conf['Admin']['Owner']['AllowDIYTemplateTryout'] ของ tryout ไม่มีนะครับ
$valueConf = isset($oMgr->conf['Admin']['Owner']['AllowDIYTemplate'])
? $oMgr->conf['Admin']['Owner']['AllowDIYTemplate']
: false;
break;
case 'AllowUserImportTemplate':
//$oMgr->conf['Admin']['Owner']['AllowUserImportTemplateTryout'] ของ tryout ไม่มีนะครับ
$valueConf = isset($oMgr->conf['Admin']['Owner']['AllowUserImportTemplate'])
? $oMgr->conf['Admin']['Owner']['AllowUserImportTemplate']
: false;
break;
}
return $valueConf;
}
/**
* Get value User/Reseller Control List Configulation.
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $username
* @param string $disableToggle
* @param string $enableList
* @param string $disableList
* @param bool $flagTestErrorMode; Flag for test mode error
*
* @return bool; Return TRUE if allow user to access RVSiteBuilder
* , and return FALSE if not allow user access to RVSiteBuilder.
* If have error return raisError
*/
public static function getControlList($username, $disableToggle, $enableList, $disableList, $flagTestErrorMode = false)
{
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL::logMessage($oCp->getMessage(), PEAR_LOG_DEBUG);
SGL_Error::pop();
return false;
}
if ($oCp->isAdmin($username)) {
/// Allow accress if username is root :: BooM
return true;
}
$isEnableStatus = null;
if (is_file($disableToggle)) {
/// Set default is disable :: BooM
$isEnableStatus = false;
$lookupFileConf = $enableList;
SGL::logMessage('rvdebug: Set default is disable:', PEAR_LOG_DEBUG);
} else {
/// Set default is enable :: BooM
$isEnableStatus = true;
$lookupFileConf = $disableList;
SGL::logMessage('rvdebug: Set default is enable:', PEAR_LOG_DEBUG);
}
if (is_file($lookupFileConf) || $flagTestErrorMode === true) {
$aConfList = array();
$aConfList = RvsLibs_File::file($lookupFileConf);
if ( $flagTestErrorMode === true) {
/// Set PEAR ERROR for Test
$aConfList = SGL::raiseError(
RvsLibs_String::translate('The file %FILE not readable.'
, 'vprintf'
, array('FILE' => $lookupFileConf))
);
}
if (SGL::isError($aConfList)) {
return SGL::raiseError(
RvsLibs_String::translate(
'There was a problem reading user/reseller control list configuration file. %ERROR_MESSAGE'
, 'vprintf'
, $aConfList->getMessage()
)
, SGL_ERROR_INVALIDAUTH
, ($flagTestErrorMode === true) ? null : PEAR_ERROR_DIE
);
}
foreach ($aConfList as $line) {
if (RvsLibs_String::trim($line) == $username) {
$isEnableStatus = ($isEnableStatus === true) ? false : true;
}
}
}
SGL::logMessage('rvdebug: isEnableStatus:' . $isEnableStatus, PEAR_LOG_DEBUG);
return $isEnableStatus;
}
/**
* ค่าหาได้ current - ค่าหาได้ config = ค่าที่ส่ง google analytics
* 5 - 0 = 5
* 6 - 5 = 1
* 3 - 6 = -3
* load google config
* project_path/{id}/config/googleAnalyticsConf.ini
*
* [TotalTemplate]
* TotalDiyTemplate=(int)
* TotalImportTemplate=(int)
* [TotalPage]
* TotalNavigationPage=(int)
* TotalInternalPage=(int)
* [TotalComponent]
* GuestBook=(int)
* Blog=(int)
* [TotalWidget]
* FbFanPage=(int)
* googleMap=(int)
*
* @return Ambigous <unknown, object, multitype:, number, string>
*/
public static function getGoogleAnalyticsConfig()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aData = array();
$projectId = SGL_Session::get('rvs_project_id');
$path = REAL_PROJECT_PATH . '/' . $projectId . '/config';
$file = $path . '/googleAnalyticsConf.ini';
if (is_dir($path) == false) {
RvsLibs_System::mkdir(array('-p', '-m', 0755, $path));
}
$aData = (is_file($file)) ? RvsLibs_Config::parse_ini_file($file, true) : $aData;
/*
foreach ($aData as $k => $v) {
SGL::logMessage('== google get == : [' . $k . ']', PEAR_LOG_DEBUG);
foreach ($v as $k2 => $v2) {
SGL::logMessage('== google get == : ' . $k2 . '=' . $v2, PEAR_LOG_DEBUG);
}
}*/
return $aData;
}
public static function setGoogleAnalyticsConfig($aConfig = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$projectId = SGL_Session::get('rvs_project_id');
$path = REAL_PROJECT_PATH . '/' . $projectId . '/config';
$file = $path . '/googleAnalyticsConf.ini';
if (is_dir($path) == false) {
RvsLibs_System::mkdir(array('-p', '-m', 0755, $path));
}
//for viewlog
foreach ($aConfig as $k => $v) {
SGL::logMessage('== google == :[' . $k . ']', PEAR_LOG_DEBUG);
foreach ($v as $k2 => $v2) {
SGL::logMessage('== google == : ' . $k2 . '=' . $v2, PEAR_LOG_DEBUG);
}
}
RvsLibs_Config::writeConfigToIniFile($aConfig, $file);
}
///@TODO : create function for write file config :: Witoon
public static function writeConfigToIniFile($aConfig, $pathConfig)
{
SGL::logMessage($pathConfig, PEAR_LOG_DEBUG);
require_once SGL_LIB_PEAR_DIR . '/Config.php';
$oConfig = new Config();
//fixed PHPMD scan 30/06/2544
$oConfig->parseConfig($aConfig, 'phparray');
$result = $oConfig->writeConfig($pathConfig, 'inifile');
if (SGL::isError($result)) {
return SGL::raiseError('Cannot write file ' . $pathConfig . ' <a href="https://rvglobalsoft.com/tickets/new&deptId=5?_ga=2.227592157.1365248182.1508293919-1065058335.1507620075" target="_blank">(Please Submit Ticket)</a>');
}
return $result;
}
public static function writeConfigToArrayInFile($aConfig, $pathConfig, $arrayName)
{
SGL::logMessage($pathConfig, PEAR_LOG_DEBUG);
require_once SGL_LIB_PEAR_DIR . '/Config.php';
$oConfig = new Config();
$oConfig->parseConfig($aConfig, 'phparray');
$result = $oConfig->writeConfig($pathConfig, 'phparray', array('name' => $arrayName));
if (SGL::isError($result)) {
return SGL::raiseError('Cannot write file ' . $pathConfig);
}
return $result;
}
// TODO :: ติดปัญหาบรรทัดที่มีเครื่องหมาย = อย่างเดียว (คือ ค่า key กับ value เป็นค่าว่าง)
public static function parse_ini_file($file, $process_sections = false)
{
if (is_file($file) === false) {
return SGL::raiseError(
RvsLibs_String::translate(
'File %FILE not found.'
, 'vprintf'
, array('FILE' => $file)
)
);
}
if (is_readable($file) === false) {
return SGL::raiseError(
RvsLibs_String::translate(
'The file %FILE not readable.'
, 'vprintf'
, array('FILE' => $file)
)
);
}
if (RvsLibs_System::function_exists('parse_ini_file') === true) {
return RvsLibs_Config::_parse_ini_file($file, $process_sections);
///parse_ini_file() detech error ไม่ได้ เลยใช้ _parse_ini_file() ไปก่อ
if (parse_ini_file($file, $process_sections) === false) {
return RvsLibs_Config::_parse_ini_file($file, $process_sections);
}
} else {
/// TODO :: ต้องลองเทสดูหลายๆเคส
return RvsLibs_Config::_parse_ini_file($file, $process_sections);
}
}
/**
* credit by: asohn. (asohn@aircanopy.net)
*
* Comments don't have to have an entire line dedicated to them.
* You can put a comment on the same line as a section
* or variable/value declaration and the built-in parse_ini_file() function will omit them.
* This being the case I took the liberty of revising goulven.ch@gmail.com 's parse_ini() function.
* I also added the $process_sections argument to better reflect PHP's built-in parse_ini_file().
* As soon as a semicolon is found in a line everything
* from that position to the end of the line is omitted so as to not become part of the value.
* However, any semicolon found that occurs between a single-quote
* or double-quote will be left alone to become part of the value.
*
*/
public static function _parse_ini_file($file, $process_sections = false) {
$process_sections = ($process_sections !== true) ? false : true;
$ini = RvsLibs_File::file($file);
if (count($ini) == 0) {return array();}
$sections = array();
$values = array();
$result = array();
$globals = array();
$i = 0;
foreach ($ini as $line) {
$line = RvsLibs_String::trim($line);
$line = RvsLibs_String::str_replace("\t", " ", $line);
// Comments
if (!RvsLibs_String::preg_match('/^[a-zA-Z0-9[]/', $line)) {continue;}
// Sections
if ($line{0} == '[') {
$tmp = RvsLibs_String::dbeExplode(']', $line);
$sections[] = RvsLibs_String::trim(RvsLibs_String::dbeSubstr($tmp[0], 1));
$i++;
continue;
}
// Key-value pair
list($key, $value) = RvsLibs_String::dbeExplode('=', $line, 2);
$key = RvsLibs_String::trim($key);
$value = RvsLibs_String::trim($value);
if (strstr($value, ";")) {
$tmp = RvsLibs_String::dbeExplode(';', $value);
if (count($tmp) == 2) {
if ((($value{0} != '"') && ($value{0} != "'")) ||
RvsLibs_String::preg_match('/^".*"\s*;/', $value) || RvsLibs_String::preg_match('/^".*;[^"]*$/', $value) ||
RvsLibs_String::preg_match("/^'.*'\s*;/", $value) || RvsLibs_String::preg_match("/^'.*;[^']*$/", $value) ){
$value = $tmp[0];
}
} else {
if ($value{0} == '"') {
$value = RvsLibs_String::preg_replace('/^"(.*)".*/', '$1', $value);
} elseif ($value{0} == "'") {
$value =RvsLibs_String::preg_replace("/^'(.*)'.*/", '$1', $value);
} else {
$value = $tmp[0];
}
}
}
$value = RvsLibs_String::trim($value);
$value = RvsLibs_String::trim($value, "'\"");
if ($i == 0) {
if (RvsLibs_String::dbeSubstr($line, -1, 2) == '[]') {
$globals[$key][] = $value;
} else {
$globals[$key] = $value;
}
} else {
if (RvsLibs_String::dbeSubstr($line, -1, 2) == '[]') {
$values[$i-1][$key][] = $value;
} else {
$values[$i-1][$key] = $value;
}
}
}
for ($j = 0; $j < $i; $j++) {
if ($process_sections === true) {
$result[$sections[$j]] = isset($values[$j]) ? $values[$j] : '';
} else {
$result[] = isset($values[$j]) ? $values[$j] : '';
}
}
return $result + $globals;
}
public static function isNoLayoutTemplste()
{
//View Checkbox No Layout Template
$oMgr = SGL_Manager::singleton();
return ($oMgr->conf['SiteBuilder']['enableLayoutTemplate'] == 1) ? false : true;
}
public static function autoUpdatePhpSuExecToMainIpConf($phpSuExec, $conf)
{
if (RVS_IS_ADMIN == 1 && isset($conf['SiteBuilder']['modPhpSuExec']) && $conf['SiteBuilder']['modPhpSuExec'] != $phpSuExec) {
$conf['SiteBuilder']['modPhpSuExec'] = sprintf("%s", $phpSuExec);
$c = SGL_Config::singleton();
$c->replace($conf);
$configFile = SGL_VAR_DIR . '/' . SGL_SERVER_NAME . '.conf.php';
if (is_file($configFile)) {
$ok = $c->save($configFile);
if (SGL::isError($ok)) {
SGL::logMessage("**** Cannot save modPhpSuExec to MainIP.con.php", PEAR_LOG_ERR);
SGL_Install_Common::errorPush($ok);
return false;
}
} else {
SGL::logMessage("**** Cannot locate " . $configFile, PEAR_LOG_ERR);
return false;
}
}
SGL::logMessage("**** save phpSuExec to MainIP.conf.php successfull value is " . $phpSuExec, PEAR_LOG_DEBUG);
return true;
}
public static function getHeaderBannerEffect($type)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$projectId = SGL_Session::get('rvs_project_id');
$oTempalteData = RvsLibs_Template::getTemplatesData($projectId, true);
$customCssPath = RvsLibs_Project::getCustomCssPath($projectId, $oTempalteData->template_item_folder);
$HdEffectConfPath = RvsLibs_File::buildPath(array(
$customCssPath, 'effectconf.ini.php'
));
$aEffectConf = (is_file($HdEffectConfPath))
? RvsLibs_Config::parse_ini_file($HdEffectConfPath, true)
: array();
$value = '';
switch ($type) {
case 'effect':
$value = isset($aEffectConf['effect_conf_headerbanner']['effect'])
? $aEffectConf['effect_conf_headerbanner']['effect']
: 'slide';
break;
case 'effecttime':
$value = isset($aEffectConf['effect_conf_headerbanner']['effecttime'])
? $aEffectConf['effect_conf_headerbanner']['effecttime']
: 5;
break;
default:
break;
}
return $value;
}
public static function getMaxHeightHeaderBanner()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aMax = array();
$projectId = SGL_Session::get('rvs_project_id');
$oTempalteData = RvsLibs_Template::getTemplatesData($projectId, true);
if (count($oTempalteData) && isset($oTempalteData->template_item_folder)) {
$customCssPath = RvsLibs_Project::getCustomCssPath ( $projectId, $oTempalteData->template_item_folder );
$pathFileImgHeaderBaner = RvsLibs_File::buildPath ( array (
$customCssPath,
'headerbannner.ini.php'
) );
$aHeaderBanner = RvsLibs_File::getHeaderBannerData ( $pathFileImgHeaderBaner );
if (count ( $aHeaderBanner )) {
foreach ( $aHeaderBanner as $k => $v ) {
$aMax [] = $v ['hd_height'];
}
}
}
return (count($aMax)) ? max($aMax) : 450;
}
public static function getOnDemandTemplate()
{
$ondemand = 1;
if (SGL_Output::isV6Session() == false) {
SGL::logMessage('v5 fixed: onDemand= ' . $ondemand, PEAR_LOG_DEBUG);
return (boolean)$ondemand;
}
$ondemand = SGL_Config::get('on-demand.onDemandTemplate');
if(is_string($ondemand)) {
SGL::logMessage('isString onDemand template: ' . $ondemand, PEAR_LOG_DEBUG);
$ondemand = (boolean)$ondemand;
}
SGL::logMessage('onDemand template: ' . $ondemand, PEAR_LOG_DEBUG);
return $ondemand;
}
public static function getOnDemandTemplateUrl()
{
$urlPreview = SGL_Config::get('on-demand.urlPreview');
if($urlPreview && $urlPreview != ''){
return $urlPreview;
}else{
return 'https://rvtemplate.com';
}
}
public static function getDownloadTemplateUrl()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
return 'http://download.rvglobalsoft.com';
}
public static function getHostnameAPI()
{
$oMgr = SGL_Manager::singleton();
$hostname = (isset($oMgr->conf['DirectAdminAPI']['hostname']))
? $oMgr->conf['DirectAdminAPI']['hostname']
: '127.0.0.1';
SGL::logMessage('=== ' .$hostname, PEAR_LOG_DEBUG);
return $hostname;
}
/**
* case: provider want to skip access domain
* please insert in file
* RVS_ROOT_HOME . '/skipdomainvalidation.txt'
* @param unknown $domain
* @return boolean
*/
public static function skipDomainValidate($domain)
{
$aData = array();
$domain = trim($domain);
$path = RVS_ROOT_HOME . '/.rvsitebuilder/skipdomainvalidation.txt';
if (is_file($path)) {
$aData = RvsLibs_File::file($path);
}
if ((in_array($domain, RvsLibs_String::preg_replace("/\\n/", "", $aData)) === true)) {
SGL::logMessage('rvdebug: skip domain:' . $domain . ' in ' . $path, PEAR_LOG_DEBUG);
return true;
}
return false;
}
/**
* merg array $aData[key1] or $aData[key1][key2]
* โดย เอา array default เป็นหลัก
*
* @param unknown $aDistConfig
* @param unknown $aUserConfig
* @return unknown
*/
public static function mergeConfig($aDistConfig , $aUserConfig)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
foreach ($aDistConfig as $typeKey => $configType) {
if (is_array($configType)) {
foreach ($configType as $configKey=>$config) {
if (isset($aUserConfig[$typeKey][$configKey]) && trim($aUserConfig[$typeKey][$configKey]) != "") {
$aFinalConfig[$typeKey][$configKey] = $aUserConfig[$typeKey][$configKey];
} else {
$aFinalConfig[$typeKey][$configKey] = $aDistConfig[$typeKey][$configKey];
}
}
} else {
if (isset($aUserConfig[$typeKey]) && trim($aUserConfig[$typeKey]) != "") {
$aFinalConfig[$typeKey] = $aUserConfig[$typeKey];
} else {
$aFinalConfig[$typeKey] = $aDistConfig[$typeKey];
}
}
}
return $aFinalConfig;
}
/**
* ใช้เป็น print log infomation
*
* SGL::logMessage(null); //info
* SGL::logMessage(null,PEAR_LOG_DEBUG);
*
* @param unknown $array
* @param string $confName
*/
public static function logMessageInfo($array = array() , $confName = 'start:')
{
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $kk => $vv) {
SGL::logMessage('rvdebug: '. $confName . '[' . $k . '][' . $kk . '] = ' . $vv); //ไม่ใส่ option default info
}
} else {
SGL::logMessage('rvdebug: '. $confName .'['.$k . '] = ' . $v); //ไม่ใส่ option default info
}
}
}
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez