diff --git a/classes/module/ModuleObject.class.php b/classes/module/ModuleObject.class.php index d9bb9d894..7b39a0bd7 100644 --- a/classes/module/ModuleObject.class.php +++ b/classes/module/ModuleObject.class.php @@ -595,6 +595,100 @@ class ModuleObject extends BaseObject return $this->layout_path; } + /** + * Automatically set layout and template path based on skin settings. + * + * @param string $type 'P' or 'M' + * @param object $config + * @return void + */ + public function setLayoutAndTemplatePaths($type, $config) + { + // Set the layout path. + if ($type === 'P') + { + $layout_srl = $config->layout_srl ?? 0; + if ($layout_srl > 0) + { + $layout_info = LayoutModel::getInstance()->getLayout($layout_srl); + if($layout_info) + { + $this->module_info->layout_srl = $layout_srl; + $this->setLayoutPath($layout_info->path); + } + } + } + else + { + $layout_srl = $config->mlayout_srl ?? 0; + if ($layout_srl == -2) + { + $layout_srl = $config->layout_srl ?: -1; + if ($layout_srl == -1) + { + $layout_srl = LayoutAdminModel::getInstance()->getSiteDefaultLayout('P'); + } + } + elseif ($layout_srl == -1) + { + $layout_srl = LayoutAdminModel::getInstance()->getSiteDefaultLayout('M'); + } + + $layout_info = LayoutModel::getInstance()->getLayout($layout_srl); + if($layout_info) + { + $this->module_info->mlayout_srl = $layout_srl; + $this->setLayoutPath($layout_info->path); + } + } + + // Set the skin path. + if ($type === 'P') + { + $skin = ($config->skin ?? '') ?: 'default'; + if ($skin === '/USE_DEFAULT/') + { + $skin = ModuleModel::getModuleDefaultSkin($this->module, 'P') ?: 'default'; + } + $template_path = sprintf('%sskins/%s', $this->module_path, $skin); + if (!Rhymix\Framework\Storage::isDirectory($template_path)) + { + $template_path = sprintf('%sskins/%s', $this->module_path, 'default'); + } + } + else + { + $mskin = ($config->mskin ?? '') ?: 'default'; + if ($mskin === '/USE_DEFAULT/') + { + $mskin = ModuleModel::getModuleDefaultSkin($this->module, 'M') ?: 'default'; + } + + if($mskin === '/USE_RESPONSIVE/') + { + $skin = ($config->skin ?? '') ?: 'default'; + if ($skin === '/USE_DEFAULT/') + { + $skin = ModuleModel::getModuleDefaultSkin($this->module, 'P') ?: 'default'; + } + $template_path = sprintf('%sskins/%s', $this->module_path, $skin); + if (!Rhymix\Framework\Storage::isDirectory($template_path)) + { + $template_path = sprintf('%sskins/%s', $this->module_path, 'default'); + } + } + else + { + $template_path = sprintf('%sm.skins/%s', $this->module_path, $mskin); + if (!Rhymix\Framework\Storage::isDirectory($template_path)) + { + $template_path = sprintf("%sm.skins/%s/", $this->module_path, 'default'); + } + } + } + $this->setTemplatePath($template_path); + } + /** * excute the member method specified by $act variable * @return bool @@ -641,37 +735,10 @@ class ModuleObject extends BaseObject // Set module skin if(isset($this->module_info->skin) && $this->module_info->module === $this->module && strpos($this->act, 'Admin') === false) { - $skin_type = $is_mobile ? 'M' : 'P'; - $skin_key = $is_mobile ? 'mskin' : 'skin'; - $skin_dir = $is_mobile ? 'm.skins' : 'skins'; - $module_skin = $this->module_info->{$skin_key} ?: '/USE_DEFAULT/'; - $use_default_skin = $this->module_info->{'is_' . $skin_key . '_fix'} === 'N'; - - // Set default skin - if(!$this->getTemplatePath() || $use_default_skin) + if(!$this->getTemplatePath()) { - if($module_skin === '/USE_DEFAULT/') - { - $module_skin = ModuleModel::getModuleDefaultSkin($this->module, $skin_type); - $this->module_info->{$skin_key} = $module_skin; - } - if($module_skin === '/USE_RESPONSIVE/') - { - $skin_dir = 'skins'; - $module_skin = $this->module_info->skin ?: '/USE_DEFAULT/'; - if($module_skin === '/USE_DEFAULT/') - { - $module_skin = ModuleModel::getModuleDefaultSkin($this->module, 'P'); - } - } - if(!is_dir(sprintf('%s%s/%s', $this->module_path, $skin_dir, $module_skin))) - { - $module_skin = 'default'; - } - $this->setTemplatePath(sprintf('%s%s/%s', $this->module_path, $skin_dir, $module_skin)); + $this->setLayoutAndTemplatePaths($is_mobile ? 'M' : 'P', $this->module_info); } - - // Set skin variable ModuleModel::syncSkinInfoToModuleInfo($this->module_info); Context::set('module_info', $this->module_info); } diff --git a/modules/member/member.mobile.php b/modules/member/member.mobile.php index d09c2a150..bd6b7fbc7 100644 --- a/modules/member/member.mobile.php +++ b/modules/member/member.mobile.php @@ -18,25 +18,6 @@ class MemberMobile extends MemberView $oSecurity = new Security(); $oSecurity->encodeHTML('member_config.signupForm..'); - // Set the template path - $mskin = $this->member_config->mskin; - if(!$mskin) - { - $template_path = sprintf('%sm.skins/%s/', $this->module_path, 'default'); - } - elseif($mskin === '/USE_RESPONSIVE/') - { - $template_path = sprintf("%sskins/%s/", $this->module_path, $this->member_config->skin); - if(!is_dir($template_path) || !$this->member_config->skin) - { - $template_path = sprintf("%sskins/%s/", $this->module_path, 'default'); - } - } - else - { - $template_path = sprintf('%sm.skins/%s', $this->module_path, $mskin); - } - // if member_srl exists, set memberInfo $member_srl = Context::get('member_srl'); if($member_srl) @@ -53,15 +34,8 @@ class MemberMobile extends MemberView } } - $this->setTemplatePath($template_path); - - $oLayoutModel = getModel('layout'); - $layout_info = $oLayoutModel->getLayout($this->member_config->mlayout_srl); - if($layout_info) - { - $this->module_info->mlayout_srl = $this->member_config->mlayout_srl; - $this->setLayoutPath($layout_info->path); - } + // Set layout and skin paths + $this->setLayoutAndTemplatePaths('M', $this->member_config); } function dispMemberModifyInfo() diff --git a/modules/member/member.view.php b/modules/member/member.view.php index 684808e47..73fd2728f 100644 --- a/modules/member/member.view.php +++ b/modules/member/member.view.php @@ -21,29 +21,8 @@ class MemberView extends Member $oSecurity = new Security(); $oSecurity->encodeHTML('member_config.signupForm..'); - // Set the skin path - $skin = $this->member_config->skin; - if ($skin) - { - if ($skin === '/USE_DEFAULT/') - { - $skin = 'default'; - } - $template_path = sprintf('%sskins/%s', $this->module_path, $skin); - } - else - { - $template_path = sprintf('%sskins/%s', $this->module_path, 'default'); - } - $this->setTemplatePath($template_path); - - // Set the layout path - $layout_info = LayoutModel::getInstance()->getLayout($this->member_config->layout_srl); - if($layout_info) - { - $this->module_info->layout_srl = $this->member_config->layout_srl; - $this->setLayoutPath($layout_info->path); - } + // Set layout and skin paths + $this->setLayoutAndTemplatePaths('P', $this->member_config); } /**