mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 19:42:15 +09:00
Replace widget and widgetstyle XML parsing and caching logic
This commit is contained in:
parent
6727b124cd
commit
278369b70e
4 changed files with 258 additions and 250 deletions
|
|
@ -134,14 +134,14 @@ abstract class BaseParser
|
||||||
$item->group = $group_name;
|
$item->group = $group_name;
|
||||||
|
|
||||||
// id and name
|
// id and name
|
||||||
if ($type === 'widget')
|
if ($type === 'widget' || $type === 'widgetstyle')
|
||||||
{
|
{
|
||||||
$item->id = trim($var['id']) ?: trim($var->id);
|
$item->id = trim($var['id'] ?? '') ?: trim($var->id);
|
||||||
if (!$item->id)
|
if (!$item->id)
|
||||||
{
|
{
|
||||||
$item->id = trim($var['name']);
|
$item->id = trim($var['name'] ?? '');
|
||||||
}
|
}
|
||||||
$item->name = $var->nameself::_getChildrenByLang($var, 'name', $lang);
|
$item->name = self::_getChildrenByLang($var, 'name', $lang);
|
||||||
if (!$item->name)
|
if (!$item->name)
|
||||||
{
|
{
|
||||||
$item->name = self::_getChildrenByLang($var, 'title', $lang);
|
$item->name = self::_getChildrenByLang($var, 'title', $lang);
|
||||||
|
|
@ -149,11 +149,11 @@ abstract class BaseParser
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$item->name = trim($var['name']);
|
$item->name = trim($var['name'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// type
|
// type
|
||||||
$item->type = trim($var['type']);
|
$item->type = trim($var['type'] ?? '');
|
||||||
if (!$item->type)
|
if (!$item->type)
|
||||||
{
|
{
|
||||||
$item->type = trim($var->type) ?: 'text';
|
$item->type = trim($var->type) ?: 'text';
|
||||||
|
|
@ -167,7 +167,7 @@ abstract class BaseParser
|
||||||
// Other common attributes
|
// Other common attributes
|
||||||
$item->title = self::_getChildrenByLang($var, 'title', $lang);
|
$item->title = self::_getChildrenByLang($var, 'title', $lang);
|
||||||
$item->description = str_replace('\\n', "\n", self::_getChildrenByLang($var, 'description', $lang));
|
$item->description = str_replace('\\n', "\n", self::_getChildrenByLang($var, 'description', $lang));
|
||||||
$item->default = trim($var['default']) ?: null;
|
$item->default = trim($var['default'] ?? '') ?: null;
|
||||||
if (!isset($item->default))
|
if (!isset($item->default))
|
||||||
{
|
{
|
||||||
$item->default = self::_getChildrenByLang($var, 'default', $lang);
|
$item->default = self::_getChildrenByLang($var, 'default', $lang);
|
||||||
|
|
@ -180,22 +180,38 @@ abstract class BaseParser
|
||||||
$item->options = array();
|
$item->options = array();
|
||||||
foreach ($var->options as $option)
|
foreach ($var->options as $option)
|
||||||
{
|
{
|
||||||
$option_item = new \stdClass;
|
if ($type === 'widget' || $type === 'widgetstyle')
|
||||||
$option_item->title = self::_getChildrenByLang($option, 'title', $lang);
|
|
||||||
$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;
|
$value = trim($option->value ?? '');
|
||||||
|
$item->options[$value] = self::_getChildrenByLang($option, 'name', $lang);
|
||||||
|
if ($option['default'] === 'true')
|
||||||
|
{
|
||||||
|
$item->default_options[$value] = true;
|
||||||
|
}
|
||||||
|
if ($option['init'] === 'true')
|
||||||
|
{
|
||||||
|
$item->init_options[$value] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($type === 'widget' && $option['init'] === 'true')
|
else
|
||||||
{
|
{
|
||||||
$item->init_options[$option_item->value] = true;
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->{$item->name} = $item;
|
// Add to list of variables
|
||||||
|
if ($type === 'widget' || $type === 'widgetstyle')
|
||||||
|
{
|
||||||
|
$result->{$item->id} = $item;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result->{$item->name} = $item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
96
common/framework/parsers/WidgetInfoParser.php
Normal file
96
common/framework/parsers/WidgetInfoParser.php
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rhymix\Framework\Parsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget (info.xml) parser class for XE compatibility.
|
||||||
|
*/
|
||||||
|
class WidgetInfoParser extends BaseParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Load an XML file.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $widget_name
|
||||||
|
* @param string $lang
|
||||||
|
* @return ?object
|
||||||
|
*/
|
||||||
|
public static function loadXML(string $filename, string $widget_name, 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 widget definition.
|
||||||
|
$info = new \stdClass;
|
||||||
|
$info->widget = $widget_name;
|
||||||
|
$info->path = sprintf('./widgets/%s/', $widget_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->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);
|
||||||
|
$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.
|
||||||
|
if ($xml->extra_vars)
|
||||||
|
{
|
||||||
|
$info->extra_var = self::_getExtraVars($xml->extra_vars, $lang, 'widget');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$info->extra_var = new \stdClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare additional fields that will be filled in later.
|
||||||
|
$info->widget_srl = null;
|
||||||
|
$info->widget_title = null;
|
||||||
|
|
||||||
|
// Return the complete result.
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
}
|
||||||
83
common/framework/parsers/WidgetStyleInfoParser.php
Normal file
83
common/framework/parsers/WidgetStyleInfoParser.php
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rhymix\Framework\Parsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget Style (info.xml) parser class for XE compatibility.
|
||||||
|
*/
|
||||||
|
class WidgetStyleInfoParser extends BaseParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Load an XML file.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $widgetstyle_name
|
||||||
|
* @param string $lang
|
||||||
|
* @return ?object
|
||||||
|
*/
|
||||||
|
public static function loadXML(string $filename, string $widgetstyle_name, 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 widget definition.
|
||||||
|
$info = new \stdClass;
|
||||||
|
$info->widgetStyle = $widgetstyle_name;
|
||||||
|
$info->path = sprintf('./widgetstyles/%s/', $widgetstyle_name);
|
||||||
|
|
||||||
|
// Parse common fields.
|
||||||
|
$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->link);
|
||||||
|
$info->license = trim($xml->license);
|
||||||
|
$info->license_link = trim($xml->license['link'] ?? '');
|
||||||
|
|
||||||
|
// Parse the preview image.
|
||||||
|
$preview_filename = trim($xml->preview ?? 'preview.jpg');
|
||||||
|
$preview_path = sprintf('%s%s', $info->path, $preview_filename);
|
||||||
|
if (file_exists($preview_path))
|
||||||
|
{
|
||||||
|
$info->preview = $preview_path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$info->preview = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the author list.
|
||||||
|
$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_var = self::_getExtraVars($xml->extra_vars, $lang, 'widget');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$info->extra_var = new \stdClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count extra vars.
|
||||||
|
$info->extra_var_count = count(get_object_vars($info->extra_var));
|
||||||
|
|
||||||
|
// Return the complete result.
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -122,147 +122,38 @@ class WidgetModel extends Widget
|
||||||
*/
|
*/
|
||||||
function getWidgetInfo($widget)
|
function getWidgetInfo($widget)
|
||||||
{
|
{
|
||||||
// Get a path of the requested module. Return if not exists.
|
// Check the widget path.
|
||||||
|
$widget = preg_replace('/[^a-zA-Z0-9-_]/', '', $widget);
|
||||||
$widget_path = $this->getWidgetPath($widget);
|
$widget_path = $this->getWidgetPath($widget);
|
||||||
if(!$widget_path) return;
|
if (!$widget_path)
|
||||||
// Read the xml file for module skin information
|
{
|
||||||
$xml_file = sprintf("%sconf/info.xml", $widget_path);
|
return;
|
||||||
if(!file_exists($xml_file)) return;
|
}
|
||||||
// If the problem by comparing the cache file and include the return variable $widget_info
|
|
||||||
$cache_file = sprintf(RX_BASEDIR . 'files/cache/widget/%s.%s.cache.php', $widget, Context::getLangType());
|
// Check the XML file.
|
||||||
|
$xml_file = sprintf("%sconf/info.xml", $widget_path);
|
||||||
if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
|
if (!file_exists($xml_file))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the cache.
|
||||||
|
$xml_mtime = filemtime($xml_file);
|
||||||
|
$cache_key = sprintf('widget_info:%s:%d', $widget, $xml_mtime);
|
||||||
|
$widget_info = Rhymix\Framework\Cache::get($cache_key);
|
||||||
|
if ($widget_info)
|
||||||
{
|
{
|
||||||
@include($cache_file);
|
|
||||||
return $widget_info;
|
return $widget_info;
|
||||||
}
|
}
|
||||||
// If no cache file exists, parse the xml and then return the variable.
|
|
||||||
$tmp_xml_obj = Rhymix\Framework\Parsers\XEXMLParser::loadXMLFile($xml_file);
|
|
||||||
$xml_obj = $tmp_xml_obj->widget ?? null;
|
|
||||||
if(!$xml_obj) return;
|
|
||||||
|
|
||||||
$buff = '$widget_info = new stdClass;';
|
// Parse the XML file and store the result in the cache.
|
||||||
|
$widget_info = Rhymix\Framework\Parsers\WidgetInfoParser::loadXML($xml_file, $widget);
|
||||||
if($xml_obj->version && $xml_obj->attrs->version == '0.2')
|
if (!$widget_info)
|
||||||
{
|
{
|
||||||
// Title of the widget, version
|
return;
|
||||||
$buff .= sprintf('$widget_info->widget = %s;', var_export($widget, true));
|
|
||||||
$buff .= sprintf('$widget_info->path = %s;', var_export($widget_path, true));
|
|
||||||
$buff .= sprintf('$widget_info->title = %s;', var_export($xml_obj->title->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->description = %s;', var_export($xml_obj->description->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->version = %s;', var_export($xml_obj->version->body, true));
|
|
||||||
if($xml_obj->date->body === 'RX_CORE')
|
|
||||||
{
|
|
||||||
$date = '';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$date_obj = new stdClass;
|
|
||||||
sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
}
|
|
||||||
$buff .= sprintf('$widget_info->date = %s;', var_export($date, true));
|
|
||||||
$buff .= sprintf('$widget_info->homepage = %s;', var_export($xml_obj->link->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->license = %s;', var_export($xml_obj->license->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->license_link = %s;', var_export($xml_obj->license->attrs->link, true));
|
|
||||||
$buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
|
|
||||||
$buff .= sprintf('$widget_info->widget_title = $widget_title;');
|
|
||||||
// Author information
|
|
||||||
if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
|
|
||||||
else $author_list = $xml_obj->author;
|
|
||||||
|
|
||||||
for($i=0; $i < count($author_list); $i++)
|
|
||||||
{
|
|
||||||
$buff .= '$widget_info->author['.$i.'] = new stdClass;';
|
|
||||||
$buff .= sprintf('$widget_info->author['.$i.']->name = %s;', var_export($author_list[$i]->name->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->author['.$i.']->email_address = %s;', var_export($author_list[$i]->attrs->email_address, true));
|
|
||||||
$buff .= sprintf('$widget_info->author['.$i.']->homepage = %s;', var_export($author_list[$i]->attrs->link, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Title of the widget, version
|
|
||||||
$buff .= sprintf('$widget_info->widget = %s;', var_export($widget, true));
|
|
||||||
$buff .= sprintf('$widget_info->path = %s;', var_export($widget_path, true));
|
|
||||||
$buff .= sprintf('$widget_info->title = %s;', var_export($xml_obj->title->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->description = %s;', var_export($xml_obj->author->description->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->version = %s;', var_export($xml_obj->attrs->version, true));
|
|
||||||
$date_obj = new stdClass;
|
|
||||||
sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
$buff .= sprintf('$widget_info->date = %s;', var_export($date, true));
|
|
||||||
$buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
|
|
||||||
$buff .= sprintf('$widget_info->widget_title = $widget_title;');
|
|
||||||
// Author information
|
|
||||||
$buff .= '$widget_info->author[0] = new stdClass;';
|
|
||||||
$buff .= sprintf('$widget_info->author[0]->name = %s;', var_export($xml_obj->author->name->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->author[0]->email_address = %s;', var_export($xml_obj->author->attrs->email_address, true));
|
|
||||||
$buff .= sprintf('$widget_info->author[0]->homepage = %s;', var_export($xml_obj->author->attrs->link, true));
|
|
||||||
}
|
|
||||||
// Extra vars (user defined variables to use in a template)
|
|
||||||
$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);
|
|
||||||
|
|
||||||
if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
|
|
||||||
{
|
|
||||||
$extra_var_count = count($extra_vars);
|
|
||||||
|
|
||||||
$buff .= sprintf('$widget_info->extra_var_count = %d;', $extra_var_count);
|
|
||||||
$buff .= '$widget_info->extra_var = $widget_info->extra_var ?? new stdClass;';
|
|
||||||
for($i=0;$i<$extra_var_count;$i++)
|
|
||||||
{
|
|
||||||
unset($var);
|
|
||||||
unset($options);
|
|
||||||
$var = $extra_vars[$i];
|
|
||||||
|
|
||||||
$id = $var->attrs->id?$var->attrs->id:$var->attrs->name;
|
|
||||||
$name = $var->name->body?$var->name->body:$var->title->body;
|
|
||||||
$type = $var->attrs->type?$var->attrs->type:$var->type->body;
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s = new stdClass;', $id);
|
|
||||||
if($type =='filebox')
|
|
||||||
{
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->filter = %s;', $id, var_export($var->type->attrs->filter, true));
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->allow_multiple = %s;', $id, var_export($var->type->attrs->allow_multiple, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->group = %s;', $id, var_export($group->title->body, true));
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->name = %s;', $id, var_export($name, true));
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->type = %s;', $id, var_export($type, true));
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->value = $vars->%s;', $id, $id);
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->description = %s;', $id, var_export($var->description->body, true));
|
|
||||||
|
|
||||||
$options = $var->options;
|
|
||||||
if(!$options) continue;
|
|
||||||
|
|
||||||
if(!is_array($options)) $options = array($options);
|
|
||||||
$options_count = count($options);
|
|
||||||
for($j=0;$j<$options_count;$j++)
|
|
||||||
{
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->options[%s] = %s;', $id, var_export($options[$j]->value->body, true), var_export($options[$j]->name->body, true));
|
|
||||||
|
|
||||||
if($options[$j]->attrs->default && $options[$j]->attrs->default=='true')
|
|
||||||
{
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->default_options[%s] = true;', $id, var_export($options[$j]->value->body, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if($options[$j]->attrs->init && $options[$j]->attrs->init=='true')
|
|
||||||
{
|
|
||||||
$buff .= sprintf('$widget_info->extra_var->%s->init_options[%s] = true;', $id, var_export($options[$j]->value->body, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$buff = '<?php if(!defined("__XE__")) exit(); '.$buff.' ?>';
|
Rhymix\Framework\Cache::set($cache_key, $widget_info);
|
||||||
FileHandler::writeFile($cache_file, $buff);
|
|
||||||
|
|
||||||
if(file_exists($cache_file)) @include($cache_file);
|
|
||||||
return $widget_info;
|
return $widget_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,116 +163,38 @@ class WidgetModel extends Widget
|
||||||
*/
|
*/
|
||||||
function getWidgetStyleInfo($widgetStyle)
|
function getWidgetStyleInfo($widgetStyle)
|
||||||
{
|
{
|
||||||
|
// Check the widget style path.
|
||||||
$widgetStyle = preg_replace('/[^a-zA-Z0-9-_]/', '', $widgetStyle);
|
$widgetStyle = preg_replace('/[^a-zA-Z0-9-_]/', '', $widgetStyle);
|
||||||
$widgetStyle_path = $this->getWidgetStylePath($widgetStyle);
|
$widgetStyle_path = $this->getWidgetStylePath($widgetStyle);
|
||||||
if(!$widgetStyle_path) return;
|
if (!$widgetStyle_path)
|
||||||
$xml_file = sprintf("%sskin.xml", $widgetStyle_path);
|
{
|
||||||
if(!file_exists($xml_file)) return;
|
return;
|
||||||
// If the problem by comparing the cache file and include the return variable $widgetStyle_info
|
}
|
||||||
$cache_file = sprintf(RX_BASEDIR . 'files/cache/widgetstyles/%s.%s.cache.php', $widgetStyle, Context::getLangType());
|
|
||||||
|
// Check the XML file.
|
||||||
if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
|
$xml_file = $widgetStyle_path . 'skin.xml';
|
||||||
|
if (!file_exists($xml_file))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the cache.
|
||||||
|
$xml_mtime = filemtime($xml_file);
|
||||||
|
$cache_key = sprintf('widgetstyle_info:%s:%d', $widgetStyle, $xml_mtime);
|
||||||
|
$widgetStyle_info = Rhymix\Framework\Cache::get($cache_key);
|
||||||
|
if ($widgetStyle_info)
|
||||||
{
|
{
|
||||||
@include($cache_file);
|
|
||||||
return $widgetStyle_info;
|
return $widgetStyle_info;
|
||||||
}
|
}
|
||||||
// If no cache file exists, parse the xml and then return the variable.
|
|
||||||
$tmp_xml_obj = Rhymix\Framework\Parsers\XEXMLParser::loadXMLFile($xml_file);
|
|
||||||
$xml_obj = $tmp_xml_obj->widgetstyle ?? null;
|
|
||||||
if(!$xml_obj) return;
|
|
||||||
|
|
||||||
$buff = array();
|
// Parse the XML file and store the result in the cache.
|
||||||
$buff[] = '<?php if(!defined("__XE__")) exit();';
|
$widgetStyle_info = Rhymix\Framework\Parsers\WidgetStyleInfoParser::loadXML($xml_file, $widgetStyle);
|
||||||
$buff[] = '$widgetStyle_info = new stdClass();';
|
if (!$widgetStyle_info)
|
||||||
|
|
||||||
// Title of the widget, version
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->widgetStyle = %s;', var_export($widgetStyle, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->path = %s;', var_export($widgetStyle_path, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->title = %s;', var_export($xml_obj->title->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->description = %s;', var_export($xml_obj->description->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->version = %s;', var_export($xml_obj->version->body, true));
|
|
||||||
if($xml_obj->date->body === 'RX_CORE')
|
|
||||||
{
|
{
|
||||||
$date = '';
|
return;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$date_obj = new stdClass;
|
|
||||||
sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
|
|
||||||
}
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->date = %s;', var_export($date, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->homepage = %s;', var_export($xml_obj->link->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->license = %s;', var_export($xml_obj->license->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->license_link = %s;', var_export($xml_obj->license->attrs->link, true));
|
|
||||||
|
|
||||||
// preview
|
|
||||||
if(!isset($xml_obj->preview)) $xml_obj->preview = new stdClass;
|
|
||||||
if(!isset($xml_obj->preview->body) || !$xml_obj->preview->body) $xml_obj->preview->body = 'preview.jpg';
|
|
||||||
$preview_file = sprintf("%s%s", $widgetStyle_path,$xml_obj->preview->body);
|
|
||||||
if(file_exists($preview_file)) $buff[] = sprintf('$widgetStyle_info->preview = %s;', var_export($preview_file, true));
|
|
||||||
|
|
||||||
// Author information
|
|
||||||
if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
|
|
||||||
else $author_list = $xml_obj->author;
|
|
||||||
|
|
||||||
foreach($author_list as $idx => $author)
|
|
||||||
{
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->author[%d] = new stdClass();', $idx);
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->author[%d]->name = %s;', $idx, var_export($author->name->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->author[%d]->email_address = %s;', $idx, var_export($author->attrs->email_address, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->author[%d]->homepage = %s;', $idx, var_export($author->attrs->link, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extra vars (user defined variables to use in a template)
|
Rhymix\Framework\Cache::set($cache_key, $widgetStyle_info);
|
||||||
$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);
|
|
||||||
|
|
||||||
$extra_var_count = 0;
|
|
||||||
$buff[] = '$widgetStyle_info->extra_var = $widgetStyle_info->extra_var ?? new stdClass();';
|
|
||||||
foreach($extra_var_groups as $group)
|
|
||||||
{
|
|
||||||
$extra_vars = (!is_array($group->var)) ? array($group->var) : $group->var;
|
|
||||||
|
|
||||||
if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
|
|
||||||
{
|
|
||||||
foreach($extra_vars as $var)
|
|
||||||
{
|
|
||||||
$extra_var_count++;
|
|
||||||
$id = ($var->attrs->id) ? $var->attrs->id : $var->attrs->name;
|
|
||||||
$name = ($var->name->body) ? $var->name->body : $var->title->body;
|
|
||||||
$type = ($var->attrs->type) ? $var->attrs->type : $var->type->body;
|
|
||||||
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s = new stdClass();', $id);
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->group = %s;', $id, var_export($group->title->body, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->name = %s;', $id, var_export($name, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->type = %s;', $id, var_export($type, true));
|
|
||||||
if($type =='filebox')
|
|
||||||
{
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->filter = %s;', $id, var_export($var->attrs->filter, true));
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->allow_multiple = %s;', $id, var_export($var->attrs->allow_multiple, true));
|
|
||||||
}
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->value = $vars->%s;', $id, $id);
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->description = %s;', $id, var_export($var->description->body, true));
|
|
||||||
|
|
||||||
if($var->options)
|
|
||||||
{
|
|
||||||
$var_options = (!is_array($var->options)) ? array($var->options) : $var->options;
|
|
||||||
foreach($var_options as $option_item)
|
|
||||||
{
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var->%s->options[%s] = %s;', $id, var_export($option_item->value->body, true), var_export($option_item->name->body, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$buff[] = sprintf('$widgetStyle_info->extra_var_count = %d;', $extra_var_count);
|
|
||||||
|
|
||||||
FileHandler::writeFile($cache_file, implode(PHP_EOL, $buff));
|
|
||||||
|
|
||||||
if(file_exists($cache_file)) @include($cache_file);
|
|
||||||
|
|
||||||
return $widgetStyle_info;
|
return $widgetStyle_info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue