| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use DateTime; |
| | | use DOMDocument; |
| | | use JVBase\Instance; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\LoginManager; |
| | | use JVBase\managers\Login; |
| | | use JVBase\managers\SEO\BreadcrumbManager; |
| | | use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\VideoObject; |
| | | use JVBase\utility\Image; |
| | | use JVBase\utility\Video; |
| | | use WP_Block; |
| | | use WP_Query; |
| | | |
| | |
| | | |
| | | class CustomBlocks |
| | | { |
| | | use Instance; |
| | | protected Cache $cache; |
| | | |
| | | protected static ?WP_Query $currentLoop = null; |
| | |
| | | protected static array $pendingClass = []; |
| | | protected static bool $renderGallery = false; |
| | | |
| | | public function __construct() |
| | | private function __construct() |
| | | { |
| | | $this->cache = Cache::for('blocks', WEEK_IN_SECONDS); |
| | | $this->cache->connect('post')->connect('taxonomy'); |
| | | $this->cache->flush(); |
| | | // $this->cache = Cache::for('blocks', null,WEEK_IN_SECONDS); |
| | | |
| | | add_filter('pre_render_block', [$this, 'prerender'], 10, 3); |
| | | add_filter('render_block', [$this, 'render'], 10, 2); |
| | | |
| | |
| | | protected function checkMethods(?string $content, array $block, ?WP_Block $parent = null, bool $isPrerender = false):?string |
| | | { |
| | | $blockName = $this->sanitizeBlockName($block); |
| | | if (str_starts_with($blockName, 'woocommerce')) { |
| | | return $content; |
| | | } |
| | | |
| | | $base = ($isPrerender) ? 'prerender_' : 'render_'; |
| | | $method = $base.$blockName; |
| | |
| | | $content = $this->$method($block, $content, $parent); |
| | | return $isPrerender ? $this->maybeOutputCustomStyles().$content : $content; |
| | | } elseif (JVB_TESTING && !empty($blockName)) { |
| | | if (!in_array($block['blockName'], $this->getIgnore($isPrerender))) { |
| | | if (!str_starts_with($block['blockName'],'jvb/') && !in_array($block['blockName'], $this->getIgnore($isPrerender))) { |
| | | jvbDump('No method found for '.print_r($block['blockName'], true)); |
| | | } |
| | | } |
| | |
| | | //Ignore for both |
| | | $base = [ |
| | | 'core/null', |
| | | 'core/pattern', |
| | | 'core/list-item', |
| | | 'core/post-content', |
| | | 'jvb/drawer-menu', |
| | |
| | | } |
| | | |
| | | if (array_key_exists('displayLoginAsForm', $attrs) && $attrs['displayLoginAsForm']) { |
| | | LoginManager::getInstance()->setAction($action); |
| | | return LoginManager::getInstance()->renderLoginForm($action, $redirect, '<h2>Login</h2>'); |
| | | Login::getInstance()->setAction($action); |
| | | return Login::getInstance()->renderLoginForm($action, $redirect, '<h2>Login</h2>'); |
| | | |
| | | } |
| | | |