<?php
if (class_exists('RvsLibs_Component_Delete') === false) {
class RvsLibs_Component_Delete
{
}
}
if (class_exists('RvsLibs_Component_Set') === false) {
class RvsLibs_Component_Set extends RvsLibs_Component_Delete
{
/**
* setConnectCompoDB
*
* $aDB[UserName] = xxx
* $aDB[Password] =xxx
* $aDB[DatabaseName] =xxx
*
* $projectId = $input->project_id
*
* @param <array> $aDB
* @param <string> $projectId
* @param <string> $testPath : This paramiter use for unit test only.
*/
public static function setDBInfoOfCompoDB($aDB, $projectId, $testPath = null)
{
SGL::logMessage("setCompoDB", PEAR_LOG_DEBUG);
$aDBConfig = array();
$projectPath = (is_null($testPath) === true)
? REAL_PROJECT_PATH
: $testPath;
$fileCompoDBConf = RvsLibs_File::buildPath(
array($projectPath, $projectId, 'compoDBConnect.ini.php')
);
if (is_file($fileCompoDBConf)) {
$aDBConfig = RvsLibs_Config::parse_ini_file($fileCompoDBConf,true);
}
$aDBConfig = array_merge($aDBConfig, $aDB);
$result = RvsLibs_Config::writeConfigToIniFile($aDBConfig, $fileCompoDBConf);
if (SGL::isError($result) === true) {
return SGL::raiseError($result->getMessage());
}
RvsLibs_File::makeIniUnreadable($fileCompoDBConf);
return true;
}
//component
function deleteUserComponentConfigByProjectPageIdAndUsrId($projectPageId, $rvs_usr_id)
{
//echo 'delete rvs_user_component_config';
$oMgr = SGL_Manager::singleton();
$query = sprintf("
DELETE
%s as uc
FROM
%s as uc
, %s as pa
, %s as pl
WHERE
uc.rvs_project_page_id = pa.project_page_id
AND pa.project_page_id = pl.project_page_id
AND pa.rvs_usr_id = %s
AND uc.rvs_project_page_id = %s
"
, $oMgr->conf['table']['rvs_user_component_config']
, $oMgr->conf['table']['rvs_user_component_config']
, $oMgr->conf['table']['rvs_project_page']
, $oMgr->conf['table']['rvs_project_layout_page']
, RvsLibs_String::quoteSmart($rvs_usr_id)
, RvsLibs_String::quoteSmart($projectPageId)
);
$result = $oMgr->dbh->query($query);
return $result;
}
}
}
if (class_exists('RvsLibs_Component_Get') === false) {
class RvsLibs_Component_Get extends RvsLibs_Component_Set
{
/**
* Selete all component data from table 'rvs_component' and 'rvs_component_config'
* by rvs_component_id
*
* @param $componentId
* @return array $oComponent
*/
function getComponentName($componentId=null)
{
///
$oComRegis = RvsLibs_ComponentRegistry::singleton();
$oComponent = $oComRegis->getOne($componentId);
if (isset($oComponent) && count($oComponent) <= 1) {
$oComponent = DaoFactory::Component()->findAllDataByComponentId($componentId, 'getrowobj');
$oComRegis->setOne($oComponent, $componentId);
}
return ($oComponent) ? $oComponent : array();
}
/**
* Select component data by OwnerId
*
* @param $rvsOwnerId
* @param $fetchMode
* @return array $aComponent
*/
function getComponentDataByOwnerID($rvsOwnerId = null, $fetchMode = 'getarray')
{
$oComRegis = RvsLibs_ComponentRegistry::singleton();
$aComponent = $oComRegis->get();
if (count($aComponent) == 0) {
$aComponent = DaoFactory::Component()->findOwnerComponentData($rvsOwnerId, $fetchMode);
$oComRegis->set($aComponent);
}
return (count($aComponent)) ? $aComponent : array();
}
/**
* get component data where componentId , ownerId
* config_value 'active' for Online_Form GuestBook Photo_Album
* config_value 'isAdminActiveKey' for Adsnews
*
* @param string $componentId
* @param string $ownerId
*/
function getComponentData($componentId, $ownerId=null)
{
$ownerId = (is_null($ownerId) || ($ownerId == ''))
? RvsLibs_User::getOwnerId()
: $ownerId;
$oComRegis = RvsLibs_ComponentRegistry::singleton();
$aComponent = $oComRegis->getOne($componentId);
if (isset($aComponent) && count($aComponent) <= 1) {
$aComponent = DaoFactory::Component()->findComponentDataByComponentIdOrOwnerId($componentId, $ownerId);
$oComRegis->setOne($aComponent, $componentId);
}
return (count($aComponent)) ? $aComponent : array();
}
/**
* get DB data in file compoDBConnect.ini form project path
* @param <string> $projectID
* @param <string> $testPath : This paramiter use for unit test only.
*
* Ex: Get Path = home/{user}/.rvsitebuilder/projects/{project_id}/compoDBConnect.ini
* @return <array> DB Data
*/
function getDBInfoOfCompoDB($projectID, $testPath = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aDB = array();
/*//ตรงนี้ถ้าเช็ค ว่าเป็น component db ก็จะทำให้โปรเจคที่ไม่ใช่ blog
* จะเพิ่ม component db ไม่ได้ เพราะมันยังไม่มี component db
* มันก็จะ return เป็น array เปล่าออกไปอย่างเดียว
$isCompoDB = RvsLibs_Project::isPublishCompoDB($projectID);
if ($isCompoDB === false) {
echo '55555555';exit;
return $aDB;
}
*/
$projectPath = is_null($testPath) === true
? REAL_PROJECT_PATH
: $testPath;
$fileCompoDBConf = RvsLibs_File::buildPath(
array($projectPath, $projectID, 'compoDBConnect.ini.php')
);
if (is_file($fileCompoDBConf)) {
$aDB = RvsLibs_Config::parse_ini_file($fileCompoDBConf,true);
$aDB['protocol'] = RvsLibs_DB::getDBProtocol($aDB['HostName']);
} else {
return SGL::raiseError(
RvsLibs_String::translate(
'Cannot get DB info Becurse file %FILE not found.'
, 'vprintf'
, array('FILE' => $fileCompoDBConf
, 'DATABASEURL' => SGL_Output::makeUrl(null, 'CreateDBforComponent', 'sitebuilder')
)
)
);
}
return $aDB;
}
/**
* function get Component DB
*
* @author Siwakorn Induang
* @param <string> $userID
* @param <string> $projectID
* @param <string> $ownerID
* @return <array>
*/
function getComponentUserDB($projectID, $userID=null,$ownerID=null,$withComponentAndUserFramework=true)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aUserCompoDB = array();
$userID = is_null($ownerID) === true ? RvsLibs_User::getUserId() : $userID;
$ownerID = is_null($ownerID) === true ? RvsLibs_User::getOwnerId() : $ownerID;
/// Find project and component data by project id and usr id and owner id :: BooM
$aUserCompoDBData = DaoFactory::Component()->findComponentAndProjectDataByProjectIdAndUsrIdAndOwnerId($projectID, $userID, $ownerID, 'getarray');
/// Find Component in intenalpage :: Witoon
$aInternalCompo = DaoFactory::Component()->findComponentOnInternalPage($projectID, $userID, $ownerID, 'getarray');
require_once RvsLibs_File::buildPath(
array(SGL_MOD_DIR, 'sitebuilder', 'classes', 'ComponentControl.php')
);
$oCompo = ComponentControl::singleton();
$aDataAllComponentConf = $oCompo->getAllComponentConf();
if (count($aUserCompoDBData) > 0) {
foreach ($aUserCompoDBData as $k => $v) {
$componentName = $v['component_name'];
$isUseDb = (isset($aDataAllComponentConf[$componentName]['use_db']))
? $aDataAllComponentConf[$componentName]['use_db']
: false;
///$aDataAllComponentConf[$componentName]['use_db'] is string 'true'
if ($isUseDb == 'true' || $isUseDb === true || $isUseDb == 1 || $isUseDb == '1') {
$aUserCompoDB[$v['component_name']] = $v['component_name'];
}
}
}
if (count($aInternalCompo) > 0) {
foreach ($aInternalCompo as $k => $v) {
$componentName = $v['component_name'];
$isUseDb = (isset($aDataAllComponentConf[$componentName]['use_db']))
? $aDataAllComponentConf[$componentName]['use_db']
: false;
///$aDataAllComponentConf[$componentName]['use_db'] is string 'true'
if ($isUseDb == 'true' || $isUseDb === true || $isUseDb == 1 || $isUseDb == '1') {
$aUserCompoDB[$v['component_name']] = $v['component_name'];
}
}
}
// Start sort ComponentAndUserFramework to first array only
$aUserCompoDBSort = array();
if (count($aUserCompoDB) > 0) {
if (in_array('ComponentAndUserFramework', $aUserCompoDB)) {
$aUserCompoDBSort['ComponentAndUserFramework'] = 'ComponentAndUserFramework';
}
/*
foreach ($aUserCompoDB as $k => $v) {
if ($k == 'ComponentAndUserFramework') {
$aUserCompoDBSort[$k] = $v;
}
}*/
foreach ($aUserCompoDB as $k => $v) {
if ($k != 'ComponentAndUserFramework') {
$aUserCompoDBSort[$k] = $v;
}
}
if ($withComponentAndUserFramework === false && isset($aUserCompoDBSort['ComponentAndUserFramework'])) {
unset($aUserCompoDBSort['ComponentAndUserFramework']);
}
return $aUserCompoDBSort;
}
// End sort
}
/**
* return component_name
* match by page_data
*@author witoon,apiruk
*
* @param unknown_type $pageId
* @param unknown_type $componentId
* @param unknown_type $defaultComponentNameFromPageName
* @param unknown_type $formTemplateId
* @param unknown_type $pageData
* @param unknown_type $projectId
* @return unknown
*/
function getCompanentNameByPageData($pageId, $componentId, $defaultComponentNameFromPageName, $formTemplateId, $pageData, $projectId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$isBlog = RvsLibs_Component::isBlog($projectId);
$homePageId = RvsLibs_Project::getLessPriority($projectId);
if (preg_match("/<img\s*id\s*=\s*\"\s*onlineform_/i", $pageData) || $formTemplateId != "") {
$companentName = 'Online_Form';
} elseif (preg_match("/<\?php\s*include\s*\"albums_" . $pageId . ".php\"/i", $pageData)) {
$companentName = 'Photo_Album';
} elseif (preg_match("/<\?php\s*include\s*\"scripts\/guestbook_" . $pageId . "\/index.php\"/i", $pageData)) {
$companentName = 'GuestBook';
} elseif ($isBlog && $homePageId == $pageId) {
// the first page is Blog only
$companentName = 'Blog';
} elseif ($defaultComponentNameFromPageName) {
// the last case return componentConf[pageName]
// pageName=Newsletter, pageName=Blog,pageName=Faq
$companentName = $defaultComponentNameFromPageName;
} else {
// cannot find compnent name return 0
$companentName = 0;
}
//fix update component_id by database:apiruk
$res = RvsLibs_Component::getComponentName($componentId);
$companentName = (isset($res->component_name)) ? $res->component_name : $companentName;
//fix update component_id by database:apiruk
return $companentName;
}
function loadComponentConfig($userId, $componentName, &$config)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$res = DaoFactory::Component()->findComponentConfigByComponentNameAndOwnerUsrID($componentName, $userId, 'getarray');
//optimize:pharadol
for ($i = 0, $max = sizeof($res); $i < $max; $i++) {
$config[$res[$i]['component_config']] = $res[$i]['component_value'];
}
return $config;
}
function writeDBConfig($aDBConf=array(), $projectId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if ($projectId == null) {
return false;
}
return RvsLibs_Component::setDBInfoOfCompoDB($aDBConf, $projectId);
}
function getAllComponentData($rvsOwnerUsrId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//fixed PHPMD scan 30/06/2544
$aComponent = DaoFactory::Component()->findComponentDataByComponentIdOrOwnerId(null, $rvsOwnerUsrId, 'getassoc');
if ($aComponent) {
return $aComponent;
}
}
/**
* return component_id select from componentName and ownerId
*@author witoon,apiruk
*
* @param unknown_type $componentName
* @param unknown_type $ownerId
* @return unknown
*/
function getComponentIdByComponentName($componentName, $ownerId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aComponent = DaoFactory::Component()->findComponentByOwnerIdAndComponantName($ownerId, $componentName, $fecthMode = 'getone');
if (count($aComponent)) {
return $aComponent;
}
}
/**
* @param $projectId
* @param $ModuleName = 'ComponentAndUserFramework'
* @return unknown_type
*/
function getModulesConfSetting($projectId, $ModuleName)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$fileCompoModules = RvsLibs_File::buildPath(array(REAL_PROJECT_PATH, $projectId, 'scripts', $ModuleName, 'setting.ini.php'));
// optimize :nipaporn
return (is_file($fileCompoModules))
? RvsLibs_Config::parse_ini_file($fileCompoModules,true)
: array();
}
/**
* Get this user can usage Blog Component
*
* @param <string> $rvsOwnerId; Owner ID
* @return <bool> $blogActive;
*/
function getComponentActive($rvsOwnerId = '', $componentName = '')
{
SGL::logMessage('L: ' . __LINE__ . ' : input owner id = ' . $rvsOwnerId, PEAR_LOG_DEBUG);
/// Active Blog if CPMODE not is tryout and RVSlieBuilder license is PRO :: BooM
/* modify CpHendle by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
return SGL::raiseError(RvsLibs_String::translate('CpWaring %MESSAGE', 'vprintf', array('MESSAGE' => $oCp->getMessage())));
}
$componentActive = (RvsLibs_License::getSitebuilderLicense() == 'pro' && $oCp->isNotTryout() === true)
? true
: false;
switch ($componentActive)
{
case true:
/// Validate owner compenent configuration
if ( RvsLibs_Component::isOwnerAllowComponent($rvsOwnerId, $componentName) === false) {
$componentActive = false;
}
break;
case false:
SGL::logMessage('L: ' . __LINE__ . ' : Not active '.$componentName, PEAR_LOG_DEBUG);
break;
};
return $componentActive;
}
/**
* getTryoutActive - Check disable user list tryout.
* - Data list disable user tryout from file $ownerHome / .rvsitebuilder / tryoutdisableuser.txt.
* - Manage disable user tryout from TryoutUserControlMgr.php
*
* @return Boolean $tryoutActive : RETURN TRUE if not file tryoutdisableuser.txt
* , or $userName don't have list name tryout disable user.
* , Show display button 'Create Tryout'
* : RETURN FALSE if $userName have list name tryout disable user
* , Disable display button 'Create Tryout'
*/
function getTryoutActive($ownerHome, $userName)
{
SGL::logMessage('L: ' . __LINE__ , PEAR_LOG_DEBUG);
$tryoutActive = false;
$aEnableUsrList = array();
$fileTryoutEnableUsr = RvsLibs_File::buildPath(array($ownerHome, '.rvsitebuilder', 'tryoutenableuser.txt'));
if (is_file($fileTryoutEnableUsr) === true) {
$aEnableUsrList = RvsLibs_File::file($fileTryoutEnableUsr);
if (SGL::isError($aEnableUsrList) === true) {
$aEnableUsrList = array();
SGL_Error::pop();
}
$tryoutActive = (in_array($userName, RvsLibs_String::preg_replace("/\\n/", "", $aEnableUsrList)) === true)
? true
: false;
}
return $tryoutActive;
}
}
}
if (class_exists('RvsLibs_Component_Validate') === false) {
class RvsLibs_Component_Validate extends RvsLibs_Component_Get
{
function isNonePageContent($componentName, $aDefaultComponent)
{
if (RvsLibs_Util::validateTrue($aDefaultComponent[$componentName]['show_pagestructure']) === true
&& RvsLibs_Util::validateTrue($aDefaultComponent[$componentName]['nonePageContent']) === true) {
return true;
}
return false;
}
/**
* validate component manager is active in sitebuilder/classes , sitebuilderpro/classes
* load sitebuilder/data/rvs_component.ini
* load sitebuilderpro/data/rvs_component.ini
*
* @param string $componentName
* @return boolean true/false
*/
function isComponentMangerActiveByDefaultConf($componentName)
{
require_once RvsLibs_File::buildPath(
array(SGL_MOD_DIR, 'sitebuilder', 'classes', 'ComponentControl.php')
);
$oCompo = ComponentControl::singleton();
$aDataAllComponentConf = $oCompo->getAllComponentConf();
// optimize :nipaporn
return (isset($aDataAllComponentConf[$componentName]))
? true :
false;
}
/**
* Validate Block Componect can usage
* @author BooM
*
* @return <number>; error code
* Error Code
* 0: can usage
* 1: cannot usage in tryout mode.
* 2: cannot usage because license NOT support.
* 3: cannot usage because your owner is disable.
*/
function isDisableBlogComponent()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
/* modify CpHandle by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
return $oCp;
/*
return SGL::raiseError(RvsLibs_String::translate('CpWaring %MESSAGE', 'vprintf', array('MESSAGE' => $oCp->getMessage())));
*/
}
return $oCp->isDisableBlogComponent();
}
/*
public function _isDisableBlogComponent($aTestOption = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$license = isset($aTestOption['license'])
? $aTestOption['license']
: RvsLibs_License::getSitebuilderLicense();
$isOwnerAllowComponent = isset($aTestOption['isOwnerAllowBlog'])
? $aTestOption['isOwnerAllowBlog']
: RvsLibs_Component::isOwnerAllowComponent(RvsLibs_User::getOwnerId(), 'Blog');
if (strtolower($license) != 'pro') {
return 2;
} elseif ($isOwnerAllowComponent === false) {
return 3;
} else {
return 0;
}
}
*/
/**
* validate convert charset file dataAsRaw.txt
*
* @param string $projectRealPageId - Project real page id component
* @return phpcode
*
*/
function getValidateConvertFileComponentCode($projectRealPageId)
{
//TODO validate Convert file component code
$code = '<?php
/**
* validate convert charset Guestbook file data/dataAsRaw.txt
*/
if (is_file(dirname(__FILE__) . "/scripts/rvslib/convertCharset/convertCharsetToUtf8.php")) {
include(dirname(__FILE__) . "/scripts/rvslib/convertCharset/convertCharsetToUtf8.php");
$pathProject = dirname(__FILE__);
$fileName = dirname(__FILE__) . "/scripts/guestbook_" . "' . $projectRealPageId . '" . "/data/dataAsRaw.txt";
$outCharset = "UTF-8//IGNORE";
convertCharsetToUtf8::doIconvFileProject($pathProject, $fileName, $outCharset);
}
?>';
return $code;
}
/**
* Call this function by c{ComponentName}UserMgr::publishHtmlHeader($componentName)
* return phpcode include file rvsManageComponent.ph
*
* @param string $companetName
* @return phpcode
*/
function getValidateManageComponentCode($companetName)
{
$code = '<?php
/**
* validateManageComponent($input = component name)
*/
if ( is_file( dirname(__FILE__) . "/scripts/rvslib/component/rvsManageComponent.php") ) {
include( dirname(__FILE__) . "/scripts/rvslib/component/rvsManageComponent.php");
rvsManageComponent::validateManageComponent(\'' . $companetName . '\');
} elseif ( is_file( dirname(dirname(__FILE__)) . "/.rvsitebuilder/rvsManageComponent.php") ) {
include( dirname(dirname(__FILE__)) . "/.rvsitebuilder/rvsManageComponent.php");
rvsManageComponent::validateManageComponent(\'' . $companetName . '\');
}
?>';
return $code;
}
function getValidateComponentMemberPage($pageId, $componentName)
{
$res = DaoFactory::ProjectPage()->findProjectPageIsmemberByProjectPageId($pageId,1,'getrow');
$isMember = (count($res) > 0) ? 1 : 0;
$ckMember = '';
if ($isMember == 1) {
$ckMember = <<<EOF
<?
if (class_exists('SGL_Session')) {
if (!SGL_Session::getUid()) {
\$aUrl = array(
'managerName' => 'memberpage',
'moduleName' => 'default',
'page' => urlencode('$componentName'),
'pageId' => '$pageId'
);
SGL_HTTP::redirect(\$aUrl);
}
}
?>
EOF;
}
return $ckMember;
}
function isComponent($componentId) {
$rvsOwnerUsrId = RvsLibs_User::getOwnerId();
$aComponentID = RvsLibs_Component::getAllComponentData($rvsOwnerUsrId);
if (is_null($componentId) === false || $componentId != '') {
if (in_array($componentId,array_keys($aComponentID)) === true) return true;
}
return false;
}
function isComponentDB($project_id=null, $rvs_usr_id=null, $owner_id=null, $unsetComponentAndUserFramework=true)
{
/*
$license = RvsLibs_License::getSitebuilderLicense();
$license = RvsLibs_String::strtolower($license);
//export pro import to pro
if ($license == 'lite') {
return false;
}
*/
if (is_null($project_id)) {
$project_id = RvsLibs_Project::getProjectId();
}
//Start check is member page return true
$isMember = RvsLibs_Component::isMemberPage($project_id);
if ($isMember == true) {
return true;
}
//End check is member page return true
$aCompoDB = RvsLibs_Component::getComponentUserDB($project_id, $rvs_usr_id, $owner_id);
if (SGL::isError($aCompoDB) === true) {
SGL_Error::pop();
return false;
}
if ($unsetComponentAndUserFramework === true && isset($aCompoDB['ComponentAndUserFramework'])) {
unset($aCompoDB['ComponentAndUserFramework']);
}
return (count($aCompoDB)) ? true : false;
}
function isMemberPage($project_id)
{
/*
//find ismember by project
$aProjectInfo = RvsLibs_Project::getProjectInfoData($project_id);
if (!isset($aProjectInfo[0]->project_info_id) || empty($aProjectInfo[0]->project_info_id)) {
return false;
}
$project_info_id = $aProjectInfo[0]->project_info_id;
$aData = DaoFactory::Project()->findIsMemberPageByProjectInfoId($project_info_id, 1, 'getrow');
if (count($aData) > 0) {
return true;
}
*/
//find ismember by project page : find ismember by mainpage
$aDataPage = DaoFactory::ProjectLayoutPage()->findIsMemberPageByProjectId($project_id, 1, 'getall');
if (count($aDataPage) > 0) {
return true;
}
////find ismember by project page : find ismember by internalpage
$aDataPageinternal = DaoFactory::ProjectPage()->findInternalPageIsmemberByProject($project_id, 1, 'getall');
if (count($aDataPageinternal) > 0) {
return true;
}
//ถ้า project ไม่ได้ setmember เลย
return false;
}
function isMemberAllPage($project_id)
{
$aProjectInfo = RvsLibs_Project::getProjectInfoData($project_id);
$project_info_id = $aProjectInfo[0]->project_info_id;
//find ismember by project
$aData = DaoFactory::Project()->findIsMemberPageByProjectInfoId($project_info_id, 1, 'getrow');
if (count($aData) > 0) {
return 1;
}
return 0;
}
}
}
if (class_exists('RvsLibs_Component') === false) {
class RvsLibs_Component extends RvsLibs_Component_Validate
{
public static function getComponentMenu($componentName, $isSystem, $menuName, $fileSys = null)
{
//Start rvsitebuilder5 list component usr
$oMainComponent = MainComponent::singleton();
if(empty($input)) {
$input = new stdClass();
}
$input->component_name = $componentName;
$fileSys = ($isSystem == '1') ? true : false;
//Start rvsitebuilder5 user : duangdao.k
if(empty($aComponentMenuUser[$componentName])) {
$aComponentMenuUser[$componentName] = new stdClass();
}
$aComponentMenuUser[$componentName]->menuCode = $oMainComponent->showUserComponentMenu($input, $fileSys, $menuName);
//$input->aComponentMenuUser[$componentName]->pageData = $aComponentManagerment[$k];
$aComponentMenuUser[$componentName]->menuname = RvsLibs_Component::_getMenuName($input->component_name, $isSystem);
//End rvsitebuilder5 user
return $aComponentMenuUser;
}
public static function _getMenuName($componentName, $isSystem)
{
if ($componentName == 'ComponentAndUserFramework' && $isSystem == '1') {
return RvsLibs_String::translate('system');
} else {
return RvsLibs_String::translate('User');
//return RvsLibs_String::translate($componentName);
}
}
/**
* configBlogTrue
* make config file allow blog
* @param $pathFile string $pathFile
* @return true
*/
public static function configBlogTrue($pathFile)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if (!is_file($pathFile)) {
$handle = RvsLibs_File::fopen($pathFile,'w');
if (SGL::isError($handle) === true) {
return $handle;
}
RvsLibs_File::fwrite($handle, $pathFile);
RvsLibs_File::fclose($handle);
/*$fileSet = fopen($pathFile, 'w');
fwrite($fileSet, $pathFile);
fclose($fileSet);*/
}
return true;
}
public static function publishHtmlInsideHead($componentId, $pageId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$codeComponentInsideHead = '';
$res = RvsLibs_Component::getComponentName($componentId);
$oMainComponent = MainComponent::singleton();
if (isset($res->component_name)
&& RvsLibs_Component::isComponentMangerActiveByDefaultConf($res->component_name)) {
$oComponent = $oMainComponent->callComponentUser($res->component_name);
$aSendToComponent = array(
'project_page_id' => $pageId,
);
$codeComponentInsideHead = $oComponent->publishHtmlInsideHead($aSendToComponent);
}
return $codeComponentInsideHead;
}
public static function updateComponentCss($projectId, $rvsUsrId, $publishPath, $action)
{
SGL::logMessage(null, PEAR_LOG_ERR);
if ($action == 1) {
require_once RvsLibs_File::buildPath(
array(SGL_MOD_DIR, 'sitebuilder', 'classes', 'PublishSiteDBMgr.php')
);
$oPublishDb = new PublishSiteDBMgr();
if ($oPublishDb->get('isResponsiveTemplate')) {
$defaultCss = 'layout.css';
} else {
$defaultCss = 'style.css';
}
$strCss = "";
$cssCodeStatic = $oPublishDb->updateComponentStatic($projectId, $rvsUsrId, $userThemePath = "");
$cssCodeDynamic = $oPublishDb->updateComponentDynamicCss($projectId, $rvsUsrId, $userThemePath = "");
$cssPathFile = $publishPath . '/' . $defaultCss;
$aOriginalCss = (is_file($cssPathFile)) ? RvsLibs_File::file($cssPathFile) : array();
foreach ($aOriginalCss as $line) {
$strCss .= $line;
}
$handle = fopen($cssPathFile, 'w');
fwrite($handle, $strCss . "\n" . $cssCodeStatic . "\n" . $cssCodeDynamic);
fclose($handle);
}
}
/**
* get project page is component missing
* and auto fix component_id
*@author witton,apiruk
*
* @param unknown_type $projectId
* @param unknown_type $usrId
* @param unknown_type $ownerId
*/
public static function autofixComponentId($projectId, $usrId, $ownerId)
{
require_once RvsLibs_File::buildPath(
array(SGL_MOD_DIR, 'sitebuilder', 'classes', 'ComponentControl.php'));
$oComponect = ComponentControl::singleton();
$aComponentConf = $oComponect->getAllComponentConf();
// get project page is component missing
$aComponentIdMissing = RvsLibs_Project::getProjectPageIsComponentIdMissing($projectId, $usrId, $ownerId);
$isBlog = RvsLibs_Component::isBlog($projectId);
if (count($aComponentIdMissing)) {
foreach ($aComponentIdMissing as $key => $value) {
$internalPageId = (isset($value->internal_page_id) && $value->internal_page_id != '') ? true : false;
if ($value->page_name == 'ComponentAndUserFramework' && $value->page_data == '') {
//Delete page ComponentAndUserFramework
if ($isBlog) {
$componentId = RvsLibs_Component::getComponentIdByComponentName('ComponentAndUserFramework', $ownerId);
RvsLibs_Component::autoUpdateRvsComponentId($value->project_page_id, $projectId, $usrId, $componentId, $internalPageId);
} else {
DaoFactory::OutSuggestion()->deleteLayoutPageOutSeggestionByusrIdAndProjectId($value->project_page_id);
RvsLibs_Component::deleteUserComponentConfigByProjectPageIdAndUsrId($value->project_page_id, $usrId);
DaoFactory::ProjectPage()->deleteProjectPageByprojectIpageIdAndProjectIdAndUsrId($projectId, $usrId, $value->project_page_id);
DaoFactory::ProjectLayoutPage()->deleteProjectLayoutByProjectPageIdAndUsrIdAndProjectId($value->project_page_id, $usrId, $projectId);
}
} else {
//update component id
$defaultComponentNameFromPageName = (isset($aComponentConf[RvsLibs_String::trim($value->page_name)])) ? RvsLibs_String::trim($value->page_name) : 0;
$componentName = RvsLibs_Component::getCompanentNameByPageData($value->project_page_id, $value->rvs_component_id, $defaultComponentNameFromPageName, $value->form_template_id, $value->page_data, $projectId);
$componentId = RvsLibs_Component::getComponentIdByComponentName($componentName, $ownerId);
RvsLibs_Component::autoUpdateRvsComponentId($value->project_page_id, $projectId, $usrId, $componentId, $internalPageId);
}
}
}
return true;
}
/**
* Check The Project is Blog.
*
* @param string $projectId
* @return boolean
*/
public static function isBlog($projectId)
{
//optimize :nipaporn
return (is_file(REAL_PROJECT_PATH . '/' . $projectId . '/.Blog.ini.php'))
? true
: false;
}
/**
* If rvs_component is incorrect run Auto update rvs_component_id
*@author apiruk
*
* @param string $pageId
* @param string $rvsUsrId
* @param string $currentComponentId
*/
public static function autoUpdateRvsComponentId($pageId, $projectId, $rvsUsrId, $currentComponentId, $internalPageId = false)
{
$oMgr = SGL_Manager::singleton();
$currentComponentId = ($currentComponentId) ? $currentComponentId : 0;
$res1 = DaoFactory::ProjectPage()->updateRvsComponentIdByProjectIdAndUsrIdAndProjectPageId($pageId, $rvsUsrId, $projectId, $currentComponentId, $internalPageId);
$res2 = DaoFactory::ProjectPage()->updateRvsuserComponent($pageId, $rvsUsrId, $projectId, $currentComponentId, $internalPageId);
}
/**
* Validate ownet is allow to usage component
*
* @param <string> $ownerID
* @param <string> $conponentName
* @return <bool> $active
*/
public static function isOwnerAllowComponent($ownerID ='', $conponentName = '')
{
$active = true;
$aComponentData = RvsLibs_Component::getComponentData(null, $ownerID);
$oComRegis = RvsLibs_ComponentRegistry::singleton();
$aData = $oComRegis->getOne($conponentName);
if (count($aData) == 0) {
$cid = $aComponent = DaoFactory::Component()->findComponentByOwnerIdAndComponantName($ownerID, $conponentName, 'getone');
if (isset($aComponentData[$cid]) && RvsLibs_Util::validateTrue($aComponentData[$cid]->component_value) === false) {
$active = false;
}
if (RvsLibs_Component::isComponentMangerActiveByDefaultConf($conponentName) === false) {
$active = false;
}
$oComRegis->setOne($aData,$conponentName);
}
//SGL::logMessage('ABC:' . $conponentName . ':active=' . $active, PEAR_LOG_DEBUG);
return $active;
}
//component
public static function checkImageMagic()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$haveImageMagic = '';
if ( file_exists('/usr/bin/convert') ) {
$which = '/usr/bin/convert';
} elseif (file_exists('/usr/local/bin/convert')) {
$which = '/usr/local/bin/convert';
} else {
$which = '';
}
$which = str_replace("\n",'',$which);
if (is_file($which)) {
$perm = ( int ) RvsLibs_String::dbeSubstr(sprintf('%o', fileperms($which)), -3);
} else {
$perm = '';
}
if ($perm == '') {
$haveImageMagic = 'no';
}
return $haveImageMagic;
}
/**
* addComponentHeaderFooter
*
* This function will query db for add component header and footer into $aPageData before parsing
*/
//compon
public static function addComponentHeaderFooter($aPageData)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//START CompoDB
require_once('ComponentControl.php');
$rvsOwnerId = RvsLibs_User::getOwnerId();
$oCompo = ComponentControl::singleton();
$aDataAllComponentConf = $oCompo->getAllComponentConf();
//END CompoDB
foreach ($aPageData as $key=>$value) {
if ($aPageData[$key]->rvs_component_id != '0') {
// get ProjectPageID, Header, Footer
$projectPageId = (isset($aPageData[$key]->project_page_id)) ? $aPageData[$key]->project_page_id : null;
$res = DaoFactory::Component()->findComponentHeaderFooterByProjectPageId($projectPageId, 'getrow');
$headerData = (isset($res['header'])) ? $res['header'] : "";
$footerData = (isset($res['footer'])) ? $res['footer'] : "";
$aPageData[$key]->page_data = $headerData . "\n" . $aPageData[$key]->page_data . "\n" . $footerData;
//START CompoDB
$componentId = $aPageData[$key]->rvs_component_id;
$aComponentData = RvsLibs_Component::getComponentData($componentId, $rvsOwnerId);
$componentName = (isset($aComponentData[$componentId]->component_name)) ? $aComponentData[$componentId]->component_name : null;
if (isset($aDataAllComponentConf[$componentName])) {
$aPageData[$key]->component_name = $componentName;
$aPageData[$key]->component_modules_name = $aDataAllComponentConf[$componentName]['scriptPath'];
$aPageData[$key]->use_db = (isset($aDataAllComponentConf[$componentName]['use_db'])) ? $aDataAllComponentConf[$componentName]['use_db'] : 0;
}
}
}
return $aPageData;
}
}
}
if (class_exists('RvsLibs_ComponentRegistry') === false) {
class RvsLibs_ComponentRegistry
{
protected $aComponent = array();
protected $aComponentAll = array();
function RvsLibs_ComponentRegistry($autoLoad = false)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
}
public static function singleton($autoLoad = true)
{
static $instance;
if (!isset($instance)) {
$class = __CLASS__;
$instance = new $class($autoLoad);
}
return $instance;
}
/**
* call get to return data
* @return unknown_type
*/
function getOne($index = '')
{
if ($index != '') {
return (isset($this->aComponent[$index]))
? $this->aComponent[$index]
: array();
} else {
return (isset($this->aComponent['all']) && $this->aComponent['all'] != '')
? $this->aComponent['all']
: array();
}
}
/**
* call to set data
* @param $aSetCompoConf
* @return unknown_type
*/
function setOne($aSetCompoData, $index = '')
{
if (!isset($this->aComponent[$index]) && $index != '') {
$this->aComponent[$index] = $aSetCompoData;
} else {
$this->aComponent['all'] = $aSetCompoData;
}
}
/**
* call get to return data
* @return unknown_type
*/
function get()
{
return $this->aComponentAll;
}
/**
* call to set data
* @param $aSetCompoConf
* @return unknown_type
*/
function set($aSetCompoConf)
{
$this->aComponentAll = $aSetCompoConf;
}
/**
* call reset to clear data
* @return unknown_type
*/
function reset()
{
$this->aComponent = array();
$this->aComponentAll = array();
}
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez