| | |
| | | $this->cache = CacheManager::for('blocks', WEEK_IN_SECONDS); |
| | | add_filter('render_block', [$this, 'render'], 999, 3); |
| | | |
| | | |
| | | add_action('init', [$this, 'registerBlockStyles']); |
| | | } |
| | | |
| | |
| | | */ |
| | | |
| | | |
| | | protected function render_core_button(array $block):string |
| | | public function render_core_button(array $block):string |
| | | { |
| | | preg_match('/href="([^"]*)"/', $block['innerHTML'], $url); |
| | | preg_match('/>([^<]*)<\/a>/', $block['innerHTML'], $label); |
| | |
| | | ); |
| | | } |
| | | |
| | | protected function render_core_buttons(array $block):string |
| | | public function render_core_buttons(array $block):string |
| | | { |
| | | return '<ul'.$this->getClassesAndStyles($block['attrs'], ['buttons','row']).'>'. |
| | | $this->innerBlocks($block).'</ul>'; |
| | | } |
| | | |
| | | protected function render_core_column(array $block):string |
| | | public function render_core_column(array $block):string |
| | | { |
| | | $styles = (array_key_exists('attrs', $block) && |
| | | array_key_exists('width', $block['attrs'])) ? |
| | |
| | | $this->innerBlocks($block).'</div>'; |
| | | } |
| | | |
| | | protected function render_core_columns(array $block):string |
| | | public function render_core_columns(array $block):string |
| | | { |
| | | return '<section'. |
| | | $this->getClassesAndStyles($block['attrs'], ['columns']).'>'. |
| | |
| | | } |
| | | //core_comment_template |
| | | |
| | | protected function render_core_group(array $block):string |
| | | public function render_core_group(array $block):string |
| | | { |
| | | $tag = (array_key_exists('tagName', $block['attrs'])) ? $block['attrs']['tagName'] : 'div'; |
| | | |
| | |
| | | //core_more |
| | | //core_nextpage |
| | | |
| | | protected function render_core_separator(array $block):string |
| | | public function render_core_separator(array $block):string |
| | | { |
| | | return '<hr'.$this->getClassesAndStyles($block['attrs']).'>'; |
| | | } |
| | | |
| | | protected function render_core_spacer(array $block):string |
| | | public function render_core_spacer(array $block):string |
| | | { |
| | | return '<div'.$this->getClassesAndStyles($block['attrs'], ['spacer'], ['height:2rem']). |
| | | ' aria-hidden="true"></div>'; |
| | |
| | | * Media Blocks |
| | | */ |
| | | //core_audio |
| | | protected function render_core_cover(array $block):string |
| | | public function render_core_cover(array $block):string |
| | | { |
| | | |
| | | // Extract block attributes |
| | |
| | | |
| | | // Build classes and styles |
| | | unset($attrs['url']); |
| | | $classes = $this->getClassesAndStyles($attrs, ['cover']); |
| | | $classes = $this->getClassesAndStyles($attrs, ['cover row']); |
| | | |
| | | |
| | | return '<section' . $classes . '>' . |
| | |
| | | |
| | | //core_file |
| | | |
| | | protected function render_core_gallery(array $block):string |
| | | public function render_core_gallery(array $block):string |
| | | { |
| | | return '<ul'.$this->getClassesAndStyles($block['attrs'], ['gallery']).'>'. |
| | | $this->innerBlocks($block,'<li>', '</li>'). |
| | | '</ul>'; |
| | | } |
| | | |
| | | protected function render_core_image(array $block):string |
| | | public function render_core_image(array $block):string |
| | | { |
| | | $ID = $this->imageID('', $block); |
| | | if (!$ID) { |
| | |
| | | $caption.'</figure>'; |
| | | } |
| | | |
| | | protected function render_core_media_text(array $block):string |
| | | public function render_core_media_text(array $block):string |
| | | { |
| | | |
| | | $ID = $this->imageID('', $block); |
| | |
| | | //render_core_details |
| | | //render_core_footnotes |
| | | //render_core_classic |
| | | protected function render_core_heading(array $block):string |
| | | public function render_core_heading(array $block):string |
| | | { |
| | | $level = (array_key_exists('level', $block['attrs'])) ? $block['attrs']['level'] : '2'; |
| | | $content = $this->inside($block); |
| | |
| | | '</h'.$level.'>'; |
| | | } |
| | | |
| | | protected function render_core_list(array $block):string |
| | | public function render_core_list(array $block):string |
| | | { |
| | | $tag = (array_key_exists('ordered', $block['attrs'])) ? 'ol' : 'ul'; |
| | | return '<'.$tag.$this->getClassesAndStyles($block['attrs']).'>'.$this->innerBlocks($block).'</'.$tag.'>'; |
| | | } |
| | | |
| | | // protected function render_core_list_item(array $block):string |
| | | // public function render_core_list_item(array $block):string |
| | | // { |
| | | // return '<li'.$this->getClassesAndStyles($block['attrs']).'>'.$this->inside($block).'</li>'; |
| | | // } |
| | | //render_core_missing |
| | | |
| | | protected function render_core_paragraph(array $block):string |
| | | public function render_core_paragraph(array $block):string |
| | | { |
| | | return '<p'.$this->getClassesAndStyles($block['attrs']).'>'. |
| | | $this->inside($block, 'p'). |
| | | '</p>'; |
| | | } |
| | | protected function render_core_quote(array $block): string |
| | | public function render_core_quote(array $block): string |
| | | { |
| | | $innerHTML = $block['innerHTML']; |
| | | |
| | |
| | | $citeHtml. |
| | | '</blockquote>'; |
| | | } |
| | | protected function render_core_pullquote(array $block): string |
| | | public function render_core_pullquote(array $block): string |
| | | { |
| | | $innerHTML = $block['innerHTML']; |
| | | |
| | |
| | | //core_loginout |
| | | //core_pattern |
| | | |
| | | protected function render_core_site_logo(array $block, string $content):string |
| | | public function render_core_site_logo(array $block, string $content):string |
| | | { |
| | | $open = $close = ''; |
| | | |
| | |
| | | } |
| | | //core_site_title_tagline |
| | | |
| | | protected function render_core_site_title(array $block, string $content):string |
| | | public function render_core_site_title(array $block, string $content):string |
| | | { |
| | | $tag = (array_key_exists('level', $block['attrs'])) ? $block['attrs']['level'] : 1; |
| | | $tag = ($tag == 0) ? 'p' : 'h'.$tag; |
| | |
| | | /** |
| | | * Theme Navigation Blocks |
| | | */ |
| | | protected function render_core_navigation(array $block, string $content):string |
| | | public function render_core_navigation(array $block, string $content):string |
| | | { |
| | | $ID = (array_key_exists('ref', $block['attrs'])) ? $block['attrs']['ref'] : false; |
| | | |
| | |
| | | '</nav>'.$helpmenu; |
| | | } |
| | | |
| | | protected function render_core_navigation_link(array $block):string |
| | | public function render_core_navigation_link(array $block):string |
| | | { |
| | | global $wp; |
| | | $url = (str_starts_with($block['attrs']['url'],'/')) ? |
| | |
| | | return '<li'.$classes.'>'.$linkOpen.$block['attrs']['label'].'</a></li>'; |
| | | } |
| | | |
| | | protected function render_core_navigation_submenu(array $block):string |
| | | public function render_core_navigation_submenu(array $block):string |
| | | { |
| | | global $wp; |
| | | $url = (str_starts_with($block['attrs']['url'],'/')) ? |
| | |
| | | //core_post_author |
| | | //core_post_author_biography |
| | | //core_post_author_name |
| | | protected function render_core_post_content(array $block, string $content = ''):string |
| | | public function render_core_post_content(array $block, string $content = ''):string |
| | | { |
| | | |
| | | $tag = (array_key_exists('tagName', $block['attrs'])) ? |
| | |
| | | |
| | | if ($content == '') { |
| | | global $post; |
| | | |
| | | $block['innerBlocks'] = parse_blocks($post->post_content); |
| | | return $this->innerBlocks($block); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | //core_post_date |
| | | protected function render_core_post_date(array $block):string |
| | | public function render_core_post_date(array $block):string |
| | | { |
| | | $postDate = get_the_date('c'); |
| | | return '<time datetime="'.$postDate.'" itemprop="datePublished"'.$this->getClassesAndStyles($block['attrs']).'>'.get_the_date().'</time>'; |
| | | } |
| | | //core_post_excerpt |
| | | protected function render_core_post_featured_image(array $block):string |
| | | public function render_core_post_featured_image(array $block):string |
| | | { |
| | | global $post; |
| | | $ID = get_post_thumbnail_id($post->ID); |
| | |
| | | //core_post_navigation_link |
| | | //core_post_template |
| | | //core_post_terms |
| | | protected function render_core_post_terms(array $block):string |
| | | public function render_core_post_terms(array $block):string |
| | | { |
| | | $terms = get_the_terms(get_the_ID(), $block['attrs']['term']); |
| | | $out = ''; |
| | |
| | | return $out; |
| | | } |
| | | //core_post_time_to_read |
| | | protected function render_core_post_title(array $block):string |
| | | public function render_core_post_title(array $block):string |
| | | { |
| | | $open = $close = ''; |
| | | if (array_key_exists('isLink', $block['attrs'])) { |
| | |
| | | '</h'.$level.'>'; |
| | | } |
| | | |
| | | protected function render_core_query(array $block, string $content):string |
| | | public function render_core_query(array $block, string $content):string |
| | | { |
| | | |
| | | $queryID = $block['attrs']['queryId']; |
| | | $args = []; |
| | | $inherit = $block['attrs']['inherit']??false; |
| | |
| | | //core_query_pagination_previous |
| | | //core_query_title |
| | | //core_read_more |
| | | protected function render_core_template_part(array $block, string $content):string |
| | | public function render_core_template_part(array $block, string $content):string |
| | | { |
| | | |
| | | $isHeaderTemplate = ( |
| | |
| | | //core_rss |
| | | //core_search |
| | | //core_shortcode |
| | | protected function render_core_social_link(array $block, string $content):string |
| | | public function render_core_social_link(array $block, string $content):string |
| | | { |
| | | $url = $block['attrs']['url']; |
| | | $service = $block['attrs']['service']; |
| | |
| | | } |
| | | return '<li><a href="'.$url.'" target="_blank" rel="nofollow" title="Find us on '.ucfirst($service).'">'.$icon.'<span class="screen-reader-text">Find us on '.ucfirst($service).'</span></a></li>'; |
| | | } |
| | | protected function render_core_social_links(array $block, string $content):string |
| | | public function render_core_social_links(array $block, string $content):string |
| | | { |
| | | return '<ul class="socials">'.$this->innerBlocks($block).'</ul>'; |
| | | } |
| | |
| | | |
| | | // Background URL (for cover, media blocks) |
| | | case 'url': |
| | | jvbDump($value); |
| | | if (!empty($value) && str_starts_with($value, 'http')) { |
| | | $styles[] = 'background-image: url('.$value.')'; |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | new CustomBlocks(); |