cache = Cache::for('timelines', WEEK_IN_SECONDS)->connect('post');
if (JVB_TESTING){
$this->cache->flush();
}
add_action('init', [ $this, 'registerBlock' ]);
add_action('wp_footer', [$this, 'renderGallery']);
}
public function registerBlock()
{
register_block_type($this->path, [
'render_callback' => [ $this, 'render' ]
]);
}
public function render(array $attributes, string $content, WP_Block $block)
{
global $post;
$registrar = Registrar::getInstance($post->post_type);
if (!$post || !$registrar || !$registrar->hasFeature('is_timeline') ) {
return '';
}
$this->parentID = $post->ID;
$cache = $this->cache->get($this->parentID);
if ($cache) {
return $cache;
}
$this->content = jvbNoBase($post->post_type);
$this->children = get_children([
'post_parent' => $this->parentID,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'ASC',
'fields' => 'ids'
]);
$this->total = count($this->children);
ob_start();
$this->renderBlock();
$content = ob_get_clean();
$this->cache->set($this->parentID, $content);
return $content;
}
protected function renderBlock():void
{
$this->renderHeader();
$this->renderTimeline();
?>
parentID);
$sharedFields = JVB()->routes('content')->getTimelineSharedFields($this->content);
$fields = $meta->getAll($sharedFields);
$extra = $meta->getAll();
?>
Before and After Laser Tattoo Removal:=$this->get_field('post_title', $extra)?>
$value) {
if ($value === '' || $slug === 'person') {
continue;
}
$registrar = Registrar::getInstance($slug);
$taxSlug = jvbCheckBase($slug);
$terms = get_the_terms($this->parentID, $taxSlug);
if ($terms && !is_wp_error($terms)) {
$many = count($terms) > 1;
?>
-
=jvbIcon($registrar->getIcon())?>
'; }
$open = ($many) ? '
- ' : '';
$close = ($many) ? '
' : '';
foreach ($terms as $term) {
$link = get_term_link($term->term_id, $taxSlug);
?>
= $open ?>
=html_entity_decode($term->name)?>
= $close ?>
'; }
?>
get_field('post_content', $extra);
if ($content !== '') {
echo $this->formatContent($content);
}
?>
Before
= jvbFormatImage(get_post_thumbnail_id($this->parentID), 'tiny', 'large', false) ?>
children)) :?>
After =$this->total?> Treatment= $this->total > 1 ? 's' : '' ?>
= jvbFormatImage(get_post_thumbnail_id($this->children[count($this->children)-1]), 'tiny', 'large', false) ?>
';
}
$out .= wptexturize(wp_kses_post( wpautop($content)));
if ($wrap) {
$out .= '';
}
return $out;
}
protected function renderTimeline():void
{
$all = $this->children;
array_unshift($all, $this->parentID);
$uniqueFields = JVB()->routes('content')->getTimelineUniqueFields($this->content);
foreach ($all as $i => $ID) {
$meta = Meta::forPost($ID);
$fields = $meta->getAll($uniqueFields);
$plural = ($i>1) ? 's': '';
$title = ($i === 0) ? 'Before Laser Tattoo Removal' : 'After '.$i.' Treatment'.$plural;
$title = ($i > 0 && !str_contains('Treatment', $fields['post_title'])) ? $fields['post_title'] : $title;
?>
get_field('post_thumbnail', $fields);
if (is_int($img)) {
echo str_replace('
=jvbIcon(jvbLogoIcon())?>= $title?>
get_field('post_date', $fields);
if ($date !== '') {
echo '';
}
echo $this->outputTimelineTax($ID);
$content = $this->get_field('post_content', $fields);
if ($i > 0 && $content !== '') {
echo $this->formatContent($this->get_field('post_content', $fields));
}
?>
';
$registrar = Registrar::getInstance('timeline');
foreach ($timeline as $term) {
$link = get_term_link($term->term_id, BASE.'timeline');
$out .= ''.jvbIcon($registrar->getIcon('hourglass')).html_entity_decode($term->name).' after the treatment';
}
$out .='';
return $out;
}
public function renderGallery():void
{
jvbRenderGallery(true);
}
}