Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skito committed Oct 12, 2023
1 parent eedb6b8 commit 97e752a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
9 changes: 6 additions & 3 deletions src/Core/FEPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static function PreviewSkin()
http_response_code(200);
$atmf = \ATMF\GetEngine();

$fields = [];

$_POST = array_map('stripslashes_deep', $_POST);
$widget = $_POST['widget'] ?? '';
$templateJson = $_POST['template'] ?? '';
Expand All @@ -33,11 +35,12 @@ public static function PreviewSkin()
if ($widget == 'events')
$fields['fields'][] = 'entase_book'; // Append booking button at the end
}
else die('Empty template.');

//echo '[entase_events fields="'.implode(',', $fields).'"]';exit;
echo '<html><head>';
wp_head();
echo '</head><body>';
echo '</head><body class="entase-skin-preview">';

$fieldsStr = implode(',', $fields['fields']);
$metaStr = implode(',', $fields['meta']);
Expand All @@ -46,12 +49,12 @@ public static function PreviewSkin()
if ($widget == 'events')
{
$atmf->__('$_template_preview', $atmf->RendTemplate('Widgets/Events_Custom', true));
echo do_shortcode('[entase_events status="0,1" fields="'.$fieldsStr.'" metafields="'.$metaStr.'"]');
echo do_shortcode('[entase_events limit="1" status="0,1" fields="'.$fieldsStr.'" metafields="'.$metaStr.'"]');
}
else if ($widget == 'productions')
{
$atmf->__('$_template_preview', $atmf->RendTemplate('Widgets/Productions_Custom', true));
echo do_shortcode('[entase_productions fields="'.$fieldsStr.'" metafields="'.$metaStr.'" multisource_image="'.$multiSourceImgStr.'"]');
echo do_shortcode('[entase_productions limit="1" fields="'.$fieldsStr.'" metafields="'.$metaStr.'" multisource_image="'.$multiSourceImgStr.'"]');
}

wp_footer();
Expand Down
63 changes: 35 additions & 28 deletions src/Utilities/Skins.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ class Skins
public static function BuildTemplateSource($template)
{
$src = '';
foreach ($template as $element)
if (is_array($template))
{
if (!is_object($element))
$element = (object)$element;

if ($element->type == 'field')
{
if (isset($element->meta) && !is_object($element->meta))
$element->meta = (object)$element->meta;

$key = $element->name == 'meta_key' ? 'meta_'.$element->meta->key : $element->name;
$src .= '\{#if $item.'.$key.'}<div class="event_'.$key.'">\{$item.'.$key.'}</div>\{#endif}';
}
elseif ($element->type == 'group')
foreach ($template as $element)
{
$classAddon = trim($element->cssClass) != '' ? ' class="'.$element->cssClass.'"' : '';
$src .= '<div'.$classAddon.'>'.self::BuildTemplateSource($element->elements).'</div>';
if (!is_object($element))
$element = (object)$element;

if ($element->type == 'field')
{
if (isset($element->meta) && !is_object($element->meta))
$element->meta = (object)$element->meta;

$key = $element->name == 'meta_key' ? 'meta_'.$element->meta->key : $element->name;
$src .= '\{#if $item.'.$key.'}<div class="event_'.$key.'">\{$item.'.$key.'}</div>\{#endif}';
}
elseif ($element->type == 'group')
{
$classAddon = trim($element->cssClass) != '' ? ' class="'.$element->cssClass.'"' : '';
$src .= '<div'.$classAddon.'>'.self::BuildTemplateSource($element->elements).'</div>';
}
}
}

Expand All @@ -36,23 +39,27 @@ public static function ExtractTemplateFields($template)
'fields' => [],
'meta' => []
];
foreach ($template as $element)

if (is_array($template))
{
if ($element->type == 'field')
foreach ($template as $element)
{
if ($element->name == 'meta_key')
if ($element->type == 'field')
{
$key = $element->meta->key ?? '';
$context = $element->meta->context ?? '';
$fields['meta'][] = $key.':'.$context;
if ($element->name == 'meta_key')
{
$key = $element->meta->key ?? '';
$context = $element->meta->context ?? '';
$fields['meta'][] = $key.':'.$context;
}
else $fields['fields'][] = $element->name;
}
elseif ($element->type == 'group')
{
$nested = self::ExtractTemplateFields($element->elements);
$fields['fields'] = array_merge($fields['fields'], $nested['fields']);
$fields['meta'] = array_merge($fields['meta'], $nested['meta']);
}
else $fields['fields'][] = $element->name;
}
elseif ($element->type == 'group')
{
$nested = self::ExtractTemplateFields($element->elements);
$fields['fields'] = array_merge($fields['fields'], $nested['fields']);
$fields['meta'] = array_merge($fields['meta'], $nested['meta']);
}
}

Expand Down

0 comments on commit 97e752a

Please sign in to comment.