mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-22 05:15:29 +09:00
Merge branch 'rhymix:master' into master
Some checks failed
PHP Lint & Codeception / PHP 7.4 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.0 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.1 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.2 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.3 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.4 (push) Has been cancelled
Some checks failed
PHP Lint & Codeception / PHP 7.4 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.0 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.1 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.2 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.3 (push) Has been cancelled
PHP Lint & Codeception / PHP 8.4 (push) Has been cancelled
This commit is contained in:
commit
7fec210203
53 changed files with 1133 additions and 909 deletions
|
|
@ -15,7 +15,7 @@ class Image
|
|||
*/
|
||||
public static function isImage(string $filename): bool
|
||||
{
|
||||
return array_shift(explode('/', MIME::getContentType($filename))) === 'image';
|
||||
return preg_match('!^image/!', MIME::getContentType($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -110,9 +110,10 @@ abstract class BaseParser
|
|||
* @param \SimpleXMLElement $extra_vars
|
||||
* @param string $lang
|
||||
* @param string $type
|
||||
* @param array $options
|
||||
* @return object
|
||||
*/
|
||||
protected static function _getExtraVars(\SimpleXMLElement $extra_vars, string $lang, string $type = ''): \stdClass
|
||||
protected static function _getExtraVars(\SimpleXMLElement $extra_vars, string $lang, string $type = '', array $options = []): \stdClass
|
||||
{
|
||||
$result = new \stdClass;
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ abstract class BaseParser
|
|||
$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, $type);
|
||||
$group_result = self::_getExtraVars($group, $lang, $type, $options);
|
||||
foreach ($group_result as $key => $val)
|
||||
{
|
||||
$result->{$key} = $val;
|
||||
|
|
@ -172,13 +173,36 @@ abstract class BaseParser
|
|||
{
|
||||
$item->default = self::_getChildrenByLang($var, 'default', $lang);
|
||||
}
|
||||
$item->value = null;
|
||||
if ($type === 'skin')
|
||||
{
|
||||
$item->value = trim($var['value'] ?? '') ?: null;
|
||||
if ($item->value && preg_match('/(,|\|@\|)/', $item->value ?? '', $delimiter))
|
||||
{
|
||||
$item->value = explode($delimiter[1], $item->value);
|
||||
}
|
||||
if ($item->type === 'mid_list' && !is_array($item->value))
|
||||
{
|
||||
$item->value = [$item->value];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$item->value = null;
|
||||
}
|
||||
|
||||
// Options
|
||||
if ($var->options)
|
||||
if ($type === 'skin' && $options['version'] === '0.1')
|
||||
{
|
||||
$item->options = array();
|
||||
foreach ($var->options as $option)
|
||||
$xml_options = $var->default ?? null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml_options = $var->options ?? null;
|
||||
}
|
||||
if ($xml_options)
|
||||
{
|
||||
$item->options = [];
|
||||
foreach ($xml_options as $option)
|
||||
{
|
||||
if ($type === 'widget' || $type === 'widgetstyle')
|
||||
{
|
||||
|
|
@ -193,16 +217,58 @@ abstract class BaseParser
|
|||
$item->init_options[$value] = true;
|
||||
}
|
||||
}
|
||||
elseif ($type === 'layout')
|
||||
{
|
||||
$option_item = new \stdClass;
|
||||
if (!empty($option['src']))
|
||||
{
|
||||
$thumbnail_path = $options['layout_path'] . $option['src'];
|
||||
if (file_exists($thumbnail_path))
|
||||
{
|
||||
$option_item->thumbnail = $thumbnail_path;
|
||||
$item->thumbnail_exist = true;
|
||||
}
|
||||
}
|
||||
$title = self::_getChildrenByLang($option, 'title', $lang);
|
||||
$value = trim($option['value'] ?? '');
|
||||
$option_item->val = $title;
|
||||
$item->options[$value] = $option_item;
|
||||
}
|
||||
elseif ($type === 'skin' && $options['version'] === '0.1')
|
||||
{
|
||||
$option_item = new \stdClass;
|
||||
$option_item->title = trim($option);
|
||||
$option_item->value = trim($option);
|
||||
$item->options[] = $option_item; // Numeric keys only
|
||||
}
|
||||
elseif ($type === 'skin' && $options['version'] === '0.2')
|
||||
{
|
||||
$option_item = new \stdClass;
|
||||
$option_item->title = self::_getChildrenByLang($option, 'title', $lang);
|
||||
$option_item->value = trim($option['value'] ?? '');
|
||||
$item->options[] = $option_item; // Numeric keys only
|
||||
}
|
||||
else
|
||||
{
|
||||
$option_item = new \stdClass;
|
||||
$option_item->title = self::_getChildrenByLang($option, 'title', $lang);
|
||||
$option_item->value = trim($option['value'] ?? '') ?: trim($option->value ?? '');
|
||||
$item->options[$option_item->value] = $option_item;
|
||||
$item->options[trim($option_item->value ?? '')] = $option_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
if ($type === 'skin' && $options['version'] === '0.1')
|
||||
{
|
||||
$item->width = intval($var['width'] ?? 0) ?: null;
|
||||
$item->height = intval($var['height'] ?? 0) ?: null;
|
||||
if (isset($item->options) && count($item->options))
|
||||
{
|
||||
$item->default = reset($item->options)->value;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to list of variables
|
||||
if ($type === 'widget' || $type === 'widgetstyle')
|
||||
{
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ class DBQueryParser extends BaseParser
|
|||
$group->conditions = self::_parseConditions($tag);
|
||||
$group->pipe = strtoupper($attribs['pipe'] ?? '') ?: 'AND';
|
||||
$group->ifvar = $attribs['if'] ?? null;
|
||||
$group->not_null = ($attribs['notnull'] ?? false) ? true : false;
|
||||
$result[] = $group;
|
||||
}
|
||||
elseif ($name === 'query')
|
||||
|
|
|
|||
128
common/framework/parsers/LayoutInfoParser.php
Normal file
128
common/framework/parsers/LayoutInfoParser.php
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Parsers;
|
||||
|
||||
/**
|
||||
* Layout (info.xml) parser class for XE compatibility.
|
||||
*/
|
||||
class LayoutInfoParser extends BaseParser
|
||||
{
|
||||
/**
|
||||
* Load an XML file.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $layout_name
|
||||
* @param string $layout_path
|
||||
* @param string $lang
|
||||
* @return ?object
|
||||
*/
|
||||
public static function loadXML(string $filename, string $layout_name, string $layout_path, string $lang = ''): ?object
|
||||
{
|
||||
// Load the XML file.
|
||||
$xml = simplexml_load_string(file_get_contents($filename));
|
||||
if ($xml === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the current language.
|
||||
$lang = $lang ?: (\Context::getLangType() ?: 'en');
|
||||
|
||||
// Initialize the layout definition.
|
||||
$info = new \stdClass;
|
||||
$info->layout = $layout_name;
|
||||
$info->type = trim($xml['type'] ?? '');
|
||||
$info->path = $layout_path;
|
||||
|
||||
// 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) ?: $layout_name;
|
||||
$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->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) ?: $layout_name;
|
||||
$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);
|
||||
$info->license = trim($xml->license);
|
||||
$info->license_link = trim($xml->license['link'] ?? '');
|
||||
$info->author = array();
|
||||
|
||||
$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.
|
||||
$info->extra_var_count = 0;
|
||||
if ($xml->extra_vars)
|
||||
{
|
||||
$info->extra_var = self::_getExtraVars($xml->extra_vars, $lang, 'layout', ['layout_path' => $layout_path]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$info->extra_var = new \stdClass;
|
||||
}
|
||||
|
||||
// Count extra vars.
|
||||
$info->extra_var_count = count(get_object_vars($info->extra_var));
|
||||
|
||||
// Get menus.
|
||||
$info->menu_count = 0;
|
||||
if (isset($xml->menus->menu))
|
||||
{
|
||||
$info->menu = new \stdClass;
|
||||
foreach ($xml->menus->menu as $menu)
|
||||
{
|
||||
$menu_item = new \stdClass;
|
||||
$menu_item->name = trim($menu['name'] ?? '');
|
||||
$menu_item->title = self::_getChildrenByLang($menu, 'title', $lang);
|
||||
$menu_item->maxdepth = intval($menu['maxdepth'] ?? 0);
|
||||
$menu_item->menu_srl = null;
|
||||
$menu_item->xml_file = '';
|
||||
$menu_item->php_file = '';
|
||||
$info->menu->{$menu_item->name} = $menu_item;
|
||||
$info->menu_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$info->menu = null;
|
||||
}
|
||||
$info->menu_name_list = null;
|
||||
|
||||
// Prepare additional fields that will be filled in later.
|
||||
$info->site_srl = 0;
|
||||
$info->layout_srl = 0;
|
||||
$info->layout_title = '';
|
||||
$info->header_script = '';
|
||||
|
||||
// Return the complete result.
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
122
common/framework/parsers/SkinInfoParser.php
Normal file
122
common/framework/parsers/SkinInfoParser.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Parsers;
|
||||
|
||||
/**
|
||||
* Skin (info.xml) parser class for XE compatibility.
|
||||
*/
|
||||
class SkinInfoParser extends BaseParser
|
||||
{
|
||||
/**
|
||||
* Load an XML file.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $skin_name
|
||||
* @param string $skin_path
|
||||
* @param string $lang
|
||||
* @return ?object
|
||||
*/
|
||||
public static function loadXML(string $filename, string $skin_name, string $skin_path, string $lang = ''): ?object
|
||||
{
|
||||
// Load the XML file.
|
||||
$xml = simplexml_load_string(file_get_contents($filename));
|
||||
if ($xml === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the current language.
|
||||
$lang = $lang ?: (\Context::getLangType() ?: 'en');
|
||||
|
||||
// Initialize the layout definition.
|
||||
$info = new \stdClass;
|
||||
$info->skin = $skin_name;
|
||||
$info->path = $skin_path;
|
||||
|
||||
// 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) ?: $skin_name;
|
||||
$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->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) ?: $skin_name;
|
||||
$info->description = self::_getChildrenByLang($xml->maker, 'description', $lang);
|
||||
$info->version = trim($xml['version'] ?? '');
|
||||
$info->date = date('Ymd', strtotime($xml->maker['date'] . 'T12:00:00Z'));
|
||||
$info->homepage = trim($xml->link);
|
||||
$info->license = trim($xml->license);
|
||||
$info->license_link = trim($xml->license['link'] ?? '');
|
||||
$info->author = array();
|
||||
|
||||
$author_info = new \stdClass;
|
||||
$author_info->name = self::_getChildrenByLang($xml->maker, 'name', $lang);
|
||||
$author_info->email_address = trim($xml->maker['email_address']);
|
||||
$author_info->homepage = trim($xml->maker['link'] ?? '');
|
||||
$info->author[] = $author_info;
|
||||
}
|
||||
|
||||
// Get extra_vars.
|
||||
if ($xml->extra_vars)
|
||||
{
|
||||
$info->extra_vars = get_object_vars(self::_getExtraVars($xml->extra_vars, $lang, 'skin', ['version' => $version]));
|
||||
}
|
||||
else
|
||||
{
|
||||
$info->extra_vars = [];
|
||||
}
|
||||
|
||||
// Get colorsets.
|
||||
if ($xml->colorset && $xml->colorset->color)
|
||||
{
|
||||
$info->colorset = [];
|
||||
foreach ($xml->colorset->color as $color)
|
||||
{
|
||||
$color_item = new \stdClass;
|
||||
$color_item->name = trim($color['name'] ?? '');
|
||||
$color_item->title = self::_getChildrenByLang($color, 'title', $lang);
|
||||
$screenshot = trim($color['src'] ?? '');
|
||||
if ($screenshot)
|
||||
{
|
||||
$screenshot = $info->path . $screenshot;
|
||||
}
|
||||
$color_item->screenshot = $screenshot;
|
||||
$info->colorset[] = $color_item;
|
||||
}
|
||||
}
|
||||
|
||||
// Get thumbnail path.
|
||||
if (file_exists($info->path . 'thumbnail.png'))
|
||||
{
|
||||
$info->thumbnail = $info->path . 'thumbnail.png';
|
||||
}
|
||||
else
|
||||
{
|
||||
$info->thumbnail = '';
|
||||
}
|
||||
|
||||
// Return the complete result.
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,4 +10,5 @@ class ConditionGroup
|
|||
public $conditions = array();
|
||||
public $pipe = 'AND';
|
||||
public $ifvar;
|
||||
public $not_null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -580,6 +580,10 @@ class Query extends VariableBase
|
|||
{
|
||||
$result .= ($result === '' ? '' : (' ' . $condition->pipe . ' ')) . '(' . $condition_string . ')';
|
||||
}
|
||||
elseif ($condition->not_null)
|
||||
{
|
||||
throw new \Rhymix\Framework\Exceptions\QueryError('Condition group marked as NOT NULL must contain at least one valid condition');
|
||||
}
|
||||
}
|
||||
|
||||
// Simple condition
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue