mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Reimplement skin XML parser
This commit is contained in:
parent
07e3298eb1
commit
b849c597bc
3 changed files with 184 additions and 236 deletions
|
|
@ -1019,245 +1019,23 @@ class ModuleModel extends Module
|
|||
public static function loadSkinInfo($path, $skin, $dir = 'skins')
|
||||
{
|
||||
// Read xml file having skin information
|
||||
if(substr($path,-1)!='/') $path .= '/';
|
||||
if(!preg_match('/^[a-zA-Z0-9_-]+$/', $skin ?? ''))
|
||||
if (!str_ends_with($path, '/'))
|
||||
{
|
||||
return;
|
||||
$path .= '/';
|
||||
}
|
||||
$skin_xml_file = sprintf("%s%s/%s/skin.xml", $path, $dir, $skin);
|
||||
if(!file_exists($skin_xml_file))
|
||||
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $skin ?? ''))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create XmlParser object
|
||||
$_xml_obj = Rhymix\Framework\Parsers\XEXMLParser::loadXMLFile($skin_xml_file);
|
||||
// Return if no skin information is
|
||||
if(!$_xml_obj->skin) return;
|
||||
$xml_obj = $_xml_obj->skin;
|
||||
// Skin Name
|
||||
$skin_info = new stdClass();
|
||||
$skin_info->title = $xml_obj->title->body;
|
||||
$skin_info->author = array();
|
||||
$skin_info->extra_vars = array();
|
||||
$skin_info->colorset = array();
|
||||
// Author information
|
||||
if($xml_obj->version && $xml_obj->attrs->version == '0.2')
|
||||
$skin_path = sprintf("%s%s/%s/", $path, $dir, $skin);
|
||||
$skin_xml_file = $skin_path . 'skin.xml';
|
||||
if (!file_exists($skin_xml_file))
|
||||
{
|
||||
// skin format v0.2
|
||||
$date_obj = (object)array('y' => 0, 'm' => 0, 'd' => 0);
|
||||
sscanf($xml_obj->date->body ?? null, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
|
||||
$skin_info->version = $xml_obj->version->body ?? null;
|
||||
$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
|
||||
$skin_info->homepage = $xml_obj->link->body ?? null;
|
||||
$skin_info->license = $xml_obj->license->body ?? null;
|
||||
$skin_info->license_link = $xml_obj->license->attrs->link ?? null;
|
||||
$skin_info->description = $xml_obj->description->body ?? null;
|
||||
|
||||
if(!is_array($xml_obj->author ?? null)) $author_list = array($xml_obj->author);
|
||||
else $author_list = $xml_obj->author;
|
||||
|
||||
foreach($author_list as $author)
|
||||
{
|
||||
$author_obj = new stdClass();
|
||||
$author_obj->name = $author->name->body ?? null;
|
||||
$author_obj->email_address = $author->attrs->email_address ?? null;
|
||||
$author_obj->homepage = $author->attrs->link ?? null;
|
||||
$skin_info->author[] = $author_obj;
|
||||
}
|
||||
// List extra vars
|
||||
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(!$extra_vars)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!is_array($group->var))
|
||||
{
|
||||
$extra_vars = array($group->var);
|
||||
}
|
||||
|
||||
foreach($extra_vars as $key => $val)
|
||||
{
|
||||
$obj = new stdClass;
|
||||
$obj->group = $group->title->body ?? null;
|
||||
$obj->name = $val->attrs->name ?? null;
|
||||
$obj->title = $val->title->body ?? null;
|
||||
$obj->type = ($val->attrs->type ?? null) ?: 'text';
|
||||
$obj->description = $val->description->body ?? null;
|
||||
$obj->value = $val->attrs->value ?? null;
|
||||
$obj->default = $val->attrs->default ?? null;
|
||||
|
||||
if(preg_match('/,|\|@\|/', $obj->value ?? '', $delimiter) && $delimiter[0])
|
||||
{
|
||||
$obj->value = explode($delimiter[0], $obj->value);
|
||||
}
|
||||
if($obj->type == 'mid_list' && !is_array($obj->value))
|
||||
{
|
||||
$obj->value = array($obj->value);
|
||||
}
|
||||
|
||||
// Get an option list from 'select'type
|
||||
if(is_array($val->options))
|
||||
{
|
||||
$option_count = count($val->options);
|
||||
|
||||
for($i = 0; $i < $option_count; $i++)
|
||||
{
|
||||
$obj->options[$i] = new stdClass();
|
||||
$obj->options[$i]->title = $val->options[$i]->title->body ?? null;
|
||||
$obj->options[$i]->value = $val->options[$i]->attrs->value ?? null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj->options[0] = new stdClass();
|
||||
$obj->options[0]->title = $val->options->title->body ?? null;
|
||||
$obj->options[0]->value = $val->options->attrs->value ?? null;
|
||||
}
|
||||
|
||||
$skin_info->extra_vars[] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// skin format v0.1
|
||||
$date_obj = (object)array('y' => 0, 'm' => 0, 'd' => 0);
|
||||
if (isset($xml_obj->maker->attrs->date))
|
||||
{
|
||||
sscanf($xml_obj->maker->attrs->date, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
|
||||
}
|
||||
|
||||
$skin_info->version = $xml_obj->version->body ?? null;
|
||||
$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
|
||||
$skin_info->homepage = $xml_obj->link->body ?? null;
|
||||
$skin_info->license = $xml_obj->license->body ?? null;
|
||||
$skin_info->license_link = $xml_obj->license->attrs->link ?? null;
|
||||
$skin_info->description = $xml_obj->maker->description->body ?? null;
|
||||
|
||||
$skin_info->author[0] = new stdClass();
|
||||
$skin_info->author[0]->name = $xml_obj->maker->name->body ?? null;
|
||||
$skin_info->author[0]->email_address = $xml_obj->maker->attrs->email_address ?? null;
|
||||
$skin_info->author[0]->homepage = $xml_obj->maker->attrs->link ?? null;
|
||||
// Variables used in the skin
|
||||
$extra_var_groups = $xml_obj->extra_vars->group ?? null;
|
||||
if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars ?? null;
|
||||
if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
|
||||
|
||||
foreach($extra_var_groups as $group)
|
||||
{
|
||||
$extra_vars = $group->var ?? null;
|
||||
|
||||
if($extra_vars)
|
||||
{
|
||||
if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
|
||||
|
||||
foreach($extra_vars as $var)
|
||||
{
|
||||
$options = array();
|
||||
|
||||
$group = $group->title->body;
|
||||
$name = $var->attrs->name;
|
||||
$type = $var->attrs->type;
|
||||
$title = $var->title->body;
|
||||
$description = $var->description->body;
|
||||
// Get an option list from 'select'type.
|
||||
if(is_array($var->default))
|
||||
{
|
||||
$option_count = count($var->default);
|
||||
|
||||
for($i = 0; $i < $option_count; $i++)
|
||||
{
|
||||
$options[$i] = new stdClass();
|
||||
$options[$i]->title = $var->default[$i]->body;
|
||||
$options[$i]->value = $var->default[$i]->body;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$options[0] = new stdClass();
|
||||
$options[0]->title = $var->default->body;
|
||||
$options[0]->value = $var->default->body;
|
||||
}
|
||||
|
||||
$width = $var->attrs->width;
|
||||
$height = $var->attrs->height;
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->group = $group;
|
||||
$obj->title = $title;
|
||||
$obj->description = $description;
|
||||
$obj->name = $name;
|
||||
$obj->type = $type;
|
||||
$obj->options = $options;
|
||||
$obj->width = $width;
|
||||
$obj->height = $height;
|
||||
$obj->default = $options[0]->value;
|
||||
|
||||
$skin_info->extra_vars[] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// colorset
|
||||
$colorset = $xml_obj->colorset->color ?? null;
|
||||
if($colorset)
|
||||
{
|
||||
if(!is_array($colorset)) $colorset = array($colorset);
|
||||
|
||||
foreach($colorset as $color)
|
||||
{
|
||||
$name = $color->attrs->name;
|
||||
$title = $color->title->body;
|
||||
$screenshot = $color->attrs->src;
|
||||
if($screenshot)
|
||||
{
|
||||
$screenshot = sprintf("%s%s/%s/%s", $path, $dir, $skin, $screenshot);
|
||||
if(!file_exists($screenshot)) $screenshot = "";
|
||||
}
|
||||
else $screenshot = "";
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->name = $name;
|
||||
$obj->title = $title;
|
||||
$obj->screenshot = $screenshot;
|
||||
$skin_info->colorset[] = $obj;
|
||||
}
|
||||
}
|
||||
// Menu type (settings for layout)
|
||||
if($xml_obj->menus->menu ?? null)
|
||||
{
|
||||
$menus = $xml_obj->menus->menu;
|
||||
if(!is_array($menus)) $menus = array($menus);
|
||||
|
||||
$menu_count = count($menus);
|
||||
$skin_info->menu_count = $menu_count;
|
||||
for($i=0;$i<$menu_count;$i++)
|
||||
{
|
||||
unset($obj);
|
||||
|
||||
$obj->name = $menus[$i]->attrs->name;
|
||||
if($menus[$i]->attrs->default == "true") $obj->default = true;
|
||||
$obj->title = $menus[$i]->title->body;
|
||||
$obj->maxdepth = $menus[$i]->maxdepth->body;
|
||||
|
||||
$skin_info->menu->{$obj->name} = $obj;
|
||||
}
|
||||
}
|
||||
|
||||
$thumbnail = sprintf("%s%s/%s/thumbnail.png", $path, $dir, $skin);
|
||||
$skin_info->thumbnail = (file_exists($thumbnail))?$thumbnail:null;
|
||||
$skin_info = Rhymix\Framework\Parsers\SkinInfoParser::loadXML($skin_xml_file, $skin, $skin_path);
|
||||
return $skin_info;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue