diff --git a/common/framework/parsers/AddonInfoParser.php b/common/framework/parsers/AddonInfoParser.php new file mode 100644 index 000000000..3ea9c820f --- /dev/null +++ b/common/framework/parsers/AddonInfoParser.php @@ -0,0 +1,95 @@ +addon_name = $addon_name; + + // Get the XML schema version. + $version = strval($xml['version']) ?: '0.1'; + + // Parse version 0.2 + if ($version === '0.2') + { + $info->title = self::_getChildrenByLang($xml, 'title', $lang); + $info->description = self::_getChildrenByLang($xml, 'description', $lang); + $info->version = trim($xml->version); + $info->date = ($xml->date === 'RX_CORE') ? '' : date('Ymd', strtotime($xml->date . 'T12:00:00Z')); + $info->homepage = trim($xml->homepage); + $info->license = trim($xml->license); + $info->license_link = trim($xml->license['link'] ?? ''); + $info->author = array(); + + foreach ($xml->author as $author) + { + $author_info = new \stdClass; + $author_info->name = self::_getChildrenByLang($author, 'name', $lang); + $author_info->email_address = trim($author['email_address'] ?? ''); + $author_info->homepage = trim($author['link'] ?? ''); + $info->author[] = $author_info; + } + } + + // Parse version 0.1 + else + { + $info->title = self::_getChildrenByLang($xml, 'title', $lang); + $info->description = self::_getChildrenByLang($xml->author, 'description', $lang); + $info->version = trim($xml['version'] ?? ''); + $info->date = date('Ymd', strtotime($xml->author['date'] . 'T12:00:00Z')); + $info->homepage = trim($xml->homepage); + $info->license = trim($xml->license); + $info->license_link = trim($xml->license['link'] ?? ''); + $info->author = array(); + + foreach ($xml->author as $author) + { + $author_info = new \stdClass; + $author_info->name = self::_getChildrenByLang($author, 'name', $lang); + $author_info->email_address = trim($author['email_address']); + $author_info->homepage = trim($author['link'] ?? ''); + $info->author[] = $author_info; + } + } + + // Get extra_vars. + if ($xml->extra_vars) + { + $info->extra_vars = get_object_vars(self::_getExtraVars($xml->extra_vars, $lang)); + } + + // Prepare additional fields that will be filled in later. + $info->is_enabled = (object)['pc' => false, 'mobile' => false]; + $info->xe_run_method = 'run_selected'; + $info->mid_list = []; + + // Return the complete result. + return $info; + } +} diff --git a/common/framework/parsers/BaseParser.php b/common/framework/parsers/BaseParser.php index 1677aa67b..0c1fb111b 100644 --- a/common/framework/parsers/BaseParser.php +++ b/common/framework/parsers/BaseParser.php @@ -10,7 +10,7 @@ abstract class BaseParser /** * Get all attributes of an element as an associative array. * - * @param SimpleXMLElement $element + * @param \SimpleXMLElement $element * @param bool $normalize * @return array */ @@ -31,7 +31,7 @@ abstract class BaseParser /** * Get the string value of an XML attribute after normalizing its name. * - * @param SimpleXMLElement $element + * @param \SimpleXMLElement $element * @param string $name * @return string */ @@ -55,7 +55,7 @@ abstract class BaseParser * A value that is identical to the name of the attribute will be treated as true. * Other values will be passed to toBool() for evaluation. * - * @param SimpleXMLElement $element + * @param \SimpleXMLElement $element * @param string $name * @return bool */ @@ -77,7 +77,7 @@ abstract class BaseParser /** * Get the contents of child elements that match a language. * - * @param SimpleXMLElement $parent + * @param \SimpleXMLElement $parent * @param string $tag_name * @param string $lang * @return string @@ -107,7 +107,7 @@ abstract class BaseParser /** * Parse extra_vars. * - * @param SimpleXMLElement $extra_vars + * @param \SimpleXMLElement $extra_vars * @param string $lang * @return object */ @@ -132,6 +132,10 @@ abstract class BaseParser $item->title = self::_getChildrenByLang($var, 'title', $lang); $item->description = str_replace('\\n', "\n", self::_getChildrenByLang($var, 'description', $lang)); $item->default = trim($var['default']) ?: null; + if (!isset($item->default)) + { + $item->default = self::_getChildrenByLang($var, 'default', $lang); + } $item->value = null; if ($var->options) { diff --git a/modules/addon/addon.admin.controller.php b/modules/addon/addon.admin.controller.php index 7fc7b505b..e6cdb3b2b 100644 --- a/modules/addon/addon.admin.controller.php +++ b/modules/addon/addon.admin.controller.php @@ -197,16 +197,19 @@ class addonAdminController extends addonController */ function procAddonAdminSetupAddon() { - $args = Context::getRequestVars(); - $module = $args->module; - $addon_name = $args->addon_name; - unset($args->module); - unset($args->act); - unset($args->addon_name); - unset($args->body); - unset($args->error_return_url); + $vars = Context::getRequestVars(); + $module = $vars->module; + $addon_name = $vars->addon_name; + $args = new stdClass(); $site_module_info = Context::get('site_module_info'); + $addon_info = AddonAdminModel::getInstance()->getAddonInfoXml($addon_name, $site_module_info->site_srl, 'site'); + foreach ($addon_info->extra_vars as $key => $val) + { + $args->{$key} = $vars->{$key} ?? ''; + } + $args->xe_run_method = $vars->xe_run_method ?? ''; + $args->mid_list = $vars->mid_list ?? []; $output = $this->doSetup($addon_name, $args, $site_module_info->site_srl, 'site'); if(!$output->toBool()) diff --git a/modules/addon/addon.admin.model.php b/modules/addon/addon.admin.model.php index a5bacaa23..61ba824ea 100644 --- a/modules/addon/addon.admin.model.php +++ b/modules/addon/addon.admin.model.php @@ -162,18 +162,14 @@ class addonAdminModel extends addon return; } - // Read the xml file for module skin information + // Read the xml file for addon information $xml_file = sprintf("%sconf/info.xml", FileHandler::getRealpath($addon_path)); - if(!file_exists($xml_file)) + if (!file_exists($xml_file)) { return; } - - $oXmlParser = new XeXmlParser(); - $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file); - $xml_obj = $tmp_xml_obj->addon; - - if(!$xml_obj) + $addon_info = Rhymix\Framework\Parsers\AddonInfoParser::loadXML($xml_file, $addon); + if (!$addon_info) { return; } @@ -190,224 +186,52 @@ class addonAdminModel extends addon $db_args->site_srl = $site_srl; $output = executeQuery('addon.getSiteAddonInfo', $db_args); } - $extra_vals = unserialize($output->data->extra_vars); - $addon_info = new stdClass(); - if($extra_vals->mid_list) + // Add run settings + $extra_vals = isset($output->data->extra_vars) ? unserialize($output->data->extra_vars) : new stdClass; + if (!empty($extra_vals->mid_list)) { $addon_info->mid_list = $extra_vals->mid_list; } - else - { - $addon_info->mid_list = array(); - } - - if($extra_vals->xe_run_method) + if (!empty($extra_vals->xe_run_method)) { $addon_info->xe_run_method = $extra_vals->xe_run_method; } - - // Add information - if($xml_obj->version && $xml_obj->attrs->version == '0.2') + if (isset($output->data) && $output->data->is_used === 'Y') { - // addon format v0.2 - if ($xml_obj->date->body === 'RX_CORE') + $addon_info->is_enabled->pc = true; + } + if (isset($output->data) && $output->data->is_used_m === 'Y') + { + $addon_info->is_enabled->mobile = true; + } + + // Add current settings + foreach ($addon_info->extra_vars ?? [] as $key => $val) + { + if (isset($extra_vals->{$key})) { - $addon_info->date = ''; + if (is_string($extra_vals->{$key}) && str_contains($extra_vals->{$key}, '|@|')) + { + $val->value = explode('|@|', $extra_vals->{$key}); + } + else + { + $val->value = $extra_vals->{$key}; + } } else { - $date_obj = new stdClass(); - sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d); - $addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); + $val->value = $val->default; } - $addon_info->addon_name = $addon; - $addon_info->title = $xml_obj->title->body; - $addon_info->description = trim($xml_obj->description->body); - $addon_info->version = $xml_obj->version->body; - $addon_info->homepage = $xml_obj->link->body; - $addon_info->license = $xml_obj->license->body; - $addon_info->license_link = $xml_obj->license->attrs->link; - if(!is_array($xml_obj->author)) + if ($val->type === 'mid_list' && !is_array($val->value)) { - $author_list = array(); - $author_list[] = $xml_obj->author; - } - else - { - $author_list = $xml_obj->author; + $val->value = isset($val->value) ? [$val->value] : []; } - $addon_info->author = array(); - foreach($author_list as $author) - { - $author_obj = new stdClass(); - $author_obj->name = $author->name->body; - $author_obj->email_address = $author->attrs->email_address; - $author_obj->homepage = $author->attrs->link; - $addon_info->author[] = $author_obj; - } - - // Expand the variable order - if($xml_obj->extra_vars) - { - $extra_var_groups = $xml_obj->extra_vars->group; - if(!$extra_var_groups) - { - $extra_var_groups = $xml_obj->extra_vars; - } - if(!is_array($extra_var_groups)) - { - $extra_var_groups = array($extra_var_groups); - } - - foreach($extra_var_groups as $group) - { - $extra_vars = $group->var; - if(!is_array($group->var)) - { - $extra_vars = array($group->var); - } - - foreach($extra_vars as $key => $val) - { - if(!$val) - { - continue; - } - - $obj = new stdClass(); - if(!$val->attrs) - { - $val->attrs = new stdClass(); - } - if(!$val->attrs->type) - { - $val->attrs->type = 'text'; - } - - $obj->group = $group->title->body; - $obj->name = $val->attrs->name; - $obj->title = $val->title->body; - $obj->type = $val->attrs->type; - $obj->description = $val->description->body; - if($obj->name) - { - $obj->value = $extra_vals->{$obj->name}; - } - if(strpos($obj->value, '|@|') != FALSE) - { - $obj->value = explode('|@|', $obj->value); - } - if($obj->type == 'mid_list' && !is_array($obj->value)) - { - $obj->value = array($obj->value); - } - - // 'Select'type obtained from the option list. - if($val->options && !is_array($val->options)) - { - $val->options = array($val->options); - } - - for($i = 0, $c = countobj($val->options); $i < $c; $i++) - { - $obj->options[$i] = new stdClass(); - $obj->options[$i]->title = $val->options[$i]->title->body; - $obj->options[$i]->value = $val->options[$i]->attrs->value; - } - - $addon_info->extra_vars[] = $obj; - } - } - } } - else - { - // addon format 0.1 - $addon_info = new stdClass(); - $addon_info->addon_name = $addon; - $addon_info->title = $xml_obj->title->body; - $addon_info->description = trim($xml_obj->author->description->body); - $addon_info->version = $xml_obj->attrs->version; - $date_obj = new stdClass(); - sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d); - $addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); - - $author_obj = new stdClass(); - $author_obj->name = $xml_obj->author->name->body; - $author_obj->email_address = $xml_obj->author->attrs->email_address; - $author_obj->homepage = $xml_obj->author->attrs->link; - - $addon_info->author = array(); - $addon_info->author[] = $author_obj; - - if($xml_obj->extra_vars) - { - // Expand the variable order - $extra_var_groups = $xml_obj->extra_vars->group; - if(!$extra_var_groups) - { - $extra_var_groups = $xml_obj->extra_vars; - } - if(!is_array($extra_var_groups)) - { - $extra_var_groups = array($extra_var_groups); - } - foreach($extra_var_groups as $group) - { - $extra_vars = $group->var; - if(!is_array($group->var)) - { - $extra_vars = array($group->var); - } - - $addon_info->extra_vars = array(); - foreach($extra_vars as $key => $val) - { - if(!$val) - { - continue; - } - - $obj = new stdClass(); - - $obj->group = $group->title->body; - $obj->name = $val->attrs->name; - $obj->title = $val->title->body; - $obj->type = $val->type->body ? $val->type->body : 'text'; - $obj->description = $val->description->body; - if($obj->name) - { - $obj->value = $extra_vals->{$obj->name}; - } - if(strpos($obj->value, '|@|') != false) - { - $obj->value = explode('|@|', $obj->value); - } - if($obj->type == 'mid_list' && !is_array($obj->value)) - { - $obj->value = array($obj->value); - } - // 'Select'type obtained from the option list. - if($val->options && !is_array($val->options)) - { - $val->options = array($val->options); - } - - $obj->options = array(); - foreach ($val->options ?? [] as $i => $option) - { - $obj->options[$i]->title = $option->title->body; - $obj->options[$i]->value = $option->value->body; - } - $addon_info->extra_vars[] = $obj; - } - } - } - } return $addon_info; }