diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index 983dd87b7..795454fcf 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -337,6 +337,7 @@ class ModuleHandler extends Handler // get type, kind $type = $xml_info->action->{$this->act}->type ?? null; + $class_name = $xml_info->action->{$this->act}->class_name ?? null; $ruleset = $xml_info->action->{$this->act}->ruleset ?? null; $meta_noindex = $xml_info->action->{$this->act}->meta_noindex ?? null; $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; @@ -386,12 +387,19 @@ class ModuleHandler extends Handler $logged_info = Context::get('logged_info'); - // if(type == view, and case for using mobilephone) - if($type == "view" && $this->is_mobile && Context::isInstalled()) + // Create an instance of the requested module and class + if($class_name) + { + $class_fullname = sprintf('Rhymix\\Modules\\%s\\%s', $this->module, $class_name); + if (class_exists($class_fullname)) + { + $oModule = $class_fullname::getInstance(); + } + } + elseif($type == "view" && $this->is_mobile && Context::isInstalled()) { $orig_type = "view"; $type = "mobile"; - // create a module instance $oModule = self::getModuleInstance($this->module, $type, $kind); if(!is_object($oModule) || !method_exists($oModule, $this->act)) { @@ -402,7 +410,6 @@ class ModuleHandler extends Handler } else { - // create a module instance $oModule = self::getModuleInstance($this->module, $type, $kind); } @@ -430,6 +437,7 @@ class ModuleHandler extends Handler $forward = new stdClass(); $forward->module = $module; $forward->type = $xml_info->action->{$this->act}->type; + $forward->class_name = $xml_info->action->{$this->act}->class_name; $forward->ruleset = $xml_info->action->{$this->act}->ruleset; $forward->meta_noindex = $xml_info->action->{$this->act}->meta_noindex; $forward->act = $this->act; @@ -484,7 +492,15 @@ class ModuleHandler extends Handler } } - if($type == "view" && $this->is_mobile) + if($forward->class_name) + { + $class_fullname = sprintf('Rhymix\\Modules\\%s\\%s', $forward->module, $forward->class_name); + if (class_exists($class_fullname)) + { + $oModule = $class_fullname::getInstance(); + } + } + elseif($type == "view" && $this->is_mobile) { $orig_type = "view"; $type = "mobile"; @@ -501,7 +517,7 @@ class ModuleHandler extends Handler { $oModule = self::getModuleInstance($forward->module, $type, $kind); } - + if(!is_object($oModule)) { return self::_createErrorMessage(-1, 'msg_module_is_not_exists', 404); diff --git a/common/framework/parsers/moduleactionparser.php b/common/framework/parsers/moduleactionparser.php index 304851aa5..993127502 100644 --- a/common/framework/parsers/moduleactionparser.php +++ b/common/framework/parsers/moduleactionparser.php @@ -81,6 +81,7 @@ class ModuleActionParser extends BaseParser // Parse permissions. $action_name = trim($action['name']); $action_type = trim($action['type']); + $action_class = trim($action['class']); $permission = trim($action['permission']); $permission_info = (object)['target' => '', 'check_var' => '', 'check_type' => '']; if ($permission) @@ -133,9 +134,27 @@ class ModuleActionParser extends BaseParser } } + // Automatically determine the type for custom classes. + if ($action_class && !$action_type) + { + if (starts_with('disp', $action_name)) + { + $action_type = 'view'; + } + elseif (starts_with('proc', $action_name)) + { + $action_type = 'controller'; + } + else + { + $action_type = 'auto'; + } + } + // Parse other information about this action. $action_info = new \stdClass; $action_info->type = $action_type; + $action_info->class_name = preg_replace('/\\\\+/', '\\\\', $action_class); $action_info->grant = trim($action['grant']) ?: 'guest'; $action_info->permission = $permission_info; $action_info->ruleset = trim($action['ruleset']);