Update XML parsers for more backward compatibility

This commit is contained in:
Kijin Sung 2025-05-19 20:56:22 +09:00
parent 3f6dbf847d
commit 86118dbf50
3 changed files with 99 additions and 30 deletions

View file

@ -41,7 +41,7 @@ class AddonInfoParser extends BaseParser
$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->homepage = trim($xml->link);
$info->license = trim($xml->license);
$info->license_link = trim($xml->license['link'] ?? '');
$info->author = array();
@ -63,25 +63,22 @@ class AddonInfoParser extends BaseParser
$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->homepage = trim($xml->link);
$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;
}
$author_info = new \stdClass;
$author_info->name = self::_getChildrenByLang($xml->author, 'name', $lang);
$author_info->email_address = trim($xml->author['email_address']);
$author_info->homepage = trim($xml->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));
$info->extra_vars = get_object_vars(self::_getExtraVars($xml->extra_vars, $lang, 'addon'));
}
// Prepare additional fields that will be filled in later.

View file

@ -109,26 +109,62 @@ abstract class BaseParser
*
* @param \SimpleXMLElement $extra_vars
* @param string $lang
* @param string $type
* @return object
*/
protected static function _getExtraVars(\SimpleXMLElement $extra_vars, string $lang): \stdClass
protected static function _getExtraVars(\SimpleXMLElement $extra_vars, string $lang, string $type = ''): \stdClass
{
$result = new \stdClass;
// Recurse into groups.
$group_name = $extra_vars->getName() === 'group' ? self::_getChildrenByLang($extra_vars, 'title', $lang) : null;
foreach ($extra_vars->group ?: [] as $group)
{
$group_result = self::_getExtraVars($group, $lang);
$group_result = self::_getExtraVars($group, $lang, $type);
foreach ($group_result as $key => $val)
{
$result->{$key} = $val;
}
}
// Parse each variable in the group.
foreach ($extra_vars->var ?: [] as $var)
{
$item = new \stdClass;
$item->group = $group_name;
$item->name = trim($var['name']);
$item->type = trim($var['type']) ?: 'text';
// id and name
if ($type === 'widget')
{
$item->id = trim($var['id']) ?: trim($var->id);
if (!$item->id)
{
$item->id = trim($var['name']);
}
$item->name = $var->nameself::_getChildrenByLang($var, 'name', $lang);
if (!$item->name)
{
$item->name = self::_getChildrenByLang($var, 'title', $lang);
}
}
else
{
$item->name = trim($var['name']);
}
// type
$item->type = trim($var['type']);
if (!$item->type)
{
$item->type = trim($var->type) ?: 'text';
}
if ($item->type === 'filebox' && isset($var->type))
{
$item->filter = trim($var->type['filter'] ?? '');
$item->allow_multiple = trim($var->type['allow_multiple'] ?? '');
}
// Other common attributes
$item->title = self::_getChildrenByLang($var, 'title', $lang);
$item->description = str_replace('\\n', "\n", self::_getChildrenByLang($var, 'description', $lang));
$item->default = trim($var['default']) ?: null;
@ -137,6 +173,8 @@ abstract class BaseParser
$item->default = self::_getChildrenByLang($var, 'default', $lang);
}
$item->value = null;
// Options
if ($var->options)
{
$item->options = array();
@ -144,13 +182,22 @@ abstract class BaseParser
{
$option_item = new \stdClass;
$option_item->title = self::_getChildrenByLang($option, 'title', $lang);
$option_item->value = trim($option['value']);
$option_item->value = trim($option['value']) ?: trim($option->value);
$item->options[$option_item->value] = $option_item;
if ($type === 'widget' && $option['default'] === 'true')
{
$item->default_options[$option_item->value] = true;
}
if ($type === 'widget' && $option['init'] === 'true')
{
$item->init_options[$option_item->value] = true;
}
}
}
$result->{$item->name} = $item;
}
return $result;
}
}

View file

@ -31,29 +31,54 @@ class EditorComponentParser extends BaseParser
$info = new \stdClass;
$info->component_name = $component_name;
// Get basic information.
$info->title = self::_getChildrenByLang($xml, 'title', $lang);
$info->description = self::_getChildrenByLang($xml, 'description', $lang);
$info->version = trim($xml->version ?? '');
$info->date = 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();
// Get the XML schema version.
$version = strval($xml['version']) ?: '0.1';
foreach ($xml->author as $author)
// 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 = date('Ymd', strtotime($xml->date . 'T12:00:00Z'));
$info->homepage = trim($xml->link);
$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->link) ?: trim($xml->homepage);
$info->license = trim($xml->license);
$info->license_link = trim($xml->license['link'] ?? '');
$info->author = array();
$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'] ?? '');
$author_info->name = self::_getChildrenByLang($xml->author, 'name', $lang);
$author_info->email_address = trim($xml->author['email_address']);
$author_info->homepage = trim($xml->author['link'] ?? '');
$info->author[] = $author_info;
}
// Get extra_vars.
if ($xml->extra_vars)
{
$info->extra_vars = self::_getExtraVars($xml->extra_vars, $lang);
$info->extra_vars = self::_getExtraVars($xml->extra_vars, $lang, 'editor_component');
}
// Return the complete result.