Registers block function to be used in templates

@param string $block       name of template block
@param string $block_impl  PHP function to register
@param bool   $cacheable
@param mixed  $cache_attrs
974891
public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
    {
        $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
    }
529215
public function addBlock(ExecutionBlockInterface $block): int
    {
        if ($block instanceof ProcedureBlockInterface) {
            $index = $this->serializeProcedure($block);
        } elseif ($block instanceof IfExpressionInterface) {
            $index = $this->serializeIfExpression($block);
        } elseif ($block instanceof AndExpressionInterface) {
            $index = $this->serializeAndExpression($block);
        } elseif ($block instanceof OrExpressionInterface) {
            $index = $this->serializeOrExpression($block);
        } else {
            // unknown execution block type
            throw new UnknownExecutionBlockType();
        }

        return $index;
    }
437583
protected function compileKeyframeBlock(Block $block, $selectors)
    {
        $env = $this->pushEnv($block);

        $envs = $this->compactEnv($env);

        $this->env = $this->extractEnv(array_filter($envs, function (Environment $e) {
            return ! isset($e->block->selectors);
        }));

        $this->scope = $this->makeOutputBlock($block->type, $selectors);
        $this->scope->depth = 1;
        $this->scope->parent->children[] = $this->scope;

        $this->compileChildrenNoReturn($block->children, $this->scope);

        $this->scope = $this->scope->parent;
        $this->env   = $this->extractEnv($envs);

        $this->popEnv();
    }
1327067
private function createCmsBlock($blockData)
    {
        // Check if template filename exists
        $filename = $blockData['filename'];
        $template = $this->getTemplatePath('blocks') . $filename;
        // phpcs:ignore
        if (!file_exists($template)) {
            return;
        }

        // Remove filename from data
        unset($blockData['filename']);

        // Fetch template content
        // phpcs:ignore
        $templateContent = @file_get_contents($template);

        $data = [
            'stores'    => [0],
            'is_active' => 1,
        ];

        // Find title
        if (preg_match('/<!--@title\s*(.*?)\s*@-->/u', $templateContent, $matches)) {
            $data['title'] = $matches[1];
            $templateContent = str_replace($matches[0], '', $templateContent);
        }

        // Remove comment lines
        $content = preg_replace('#\{\*.*\*\}#suU', '', $templateContent);
        $content = trim($content);
        $data['content'] = $content;

        $block = $this->blockFactory->create();
        $block = $block->load($blockData['identifier'], 'identifier');

        if ($block->getId()) {
            $data['block_id'] = $block->getId();
        }

        $data['identifier'] = $blockData['identifier'];
        $block->addData($data);
        $this->blockRepository->save($block);
    }
1029440
private function renderBlock(array $blockNames, $cacheKey, array $context)
    {
        $template = $blockName = null;

        $themes = $this->defaultThemes;
        if (isset($this->themes[$cacheKey])) {
            $themes = array_merge($this->themes[$cacheKey], $this->defaultThemes);
        }

        // Search the template for first block available
        foreach ($blockNames as $name) {
            if ($template = $this->getTemplateForBlock($name, $themes)) {
                $blockName = $name;
                break;
            }
        }

        // Throw if no matching blocks are found
        if (empty($template)) {
            throw new \RuntimeException(sprintf(
                "Block%s %s not found in table themes (%s)",
                count($blockNames) > 1 ? 's' : '', implode(', ', $blockNames), implode(', ', $this->defaultThemes)
            ));
        }

        return $template->renderBlock($blockName, $context);
    }
1232615
public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
    {
        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
            throw new Exception('Multiple plugins of different types can not share the same name');
        }
        $this->plugins[$name] = array(
            'type'     => self::SMARTY_BLOCK,
            'callback' => $callback
        );
    }
855821
@SideOnly(Side.CLIENT)
	public static void registerBlockRenderer(Block block, IBlockRenderer renderer)
	{
		clientRegistry.blockRenderers.put(checkNotNull(block), checkNotNull(renderer));
		Item item = Item.getItemFromBlock(block);
		if (item != null)
			clientRegistry.itemRenderers.put(item, renderer);
	}
1280256
public function render(AbstractBlock $block, CliRenderer $renderer)
    {
        if (!($block instanceof ListBlock)) {
            throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
        }

        return $renderer->renderBlocks($block->children());
    }
387603
static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
    {
        if (!isset($compiler->_cache['blockNesting'])) {
            $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
                                              $compiler->parser->lex->taglineno);
        }
        $compiler->has_code = true;
        $compiler->suppressNocacheProcessing = true;
        $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true;
        $output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
        return $output;
    }
1078073
public function setBlock($block)
    {
        if (!empty($block) && $block <= 4 && $block !== 0 && !($block < 0)) {
            $this->block = $block;
        }
    }
826467
static function compileParentBlock($compiler, $_name = null)
    {
        // if called by {$smarty.block.parent} we must search the name of enclosing {block}
        if ($_name == null) {
            $stack_count = count($compiler->_tag_stack);
            while (--$stack_count >= 0) {
                if ($compiler->_tag_stack[$stack_count][0] == 'block') {
                    $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
                    break;
                }
            }
        }
        if ($_name == null) {
            $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno);
        }
        if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
            $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno);
        }
        Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent;
        $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
        $compiler->has_code = false;
        return;
    }
677227
public function createBlockTranslation(Block $block, string $locale): void
    {
        $query = $this->connection->createQueryBuilder()
            ->insert('ngbm_block_translation')
            ->values(
                [
                    'block_id' => ':block_id',
                    'status' => ':status',
                    'locale' => ':locale',
                    'parameters' => ':parameters',
                ]
            )
            ->setParameter('block_id', $block->id, Type::INTEGER)
            ->setParameter('status', $block->status, Type::INTEGER)
            ->setParameter('locale', $locale, Type::STRING)
            ->setParameter('parameters', $block->parameters[$locale], Type::JSON_ARRAY);

        $query->execute();
    }
580550
public function render_block(\templatable $block) {
        $data = $block->export_for_template($this);

        return $this->render_from_template('block_rss_client/block', $data);
    }
237203
public function onRegisterFromCache()
    {
        if ($this->isCachingEnabled()) {
            $blockId = $this->getEnvOption('id');
        
            $cacheKeyAssets = ['blockassets', $blockId];
            $cacheKeyAssetBundles = ['blockassetbundles', $blockId];
        
            $assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
            $assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
        
            PhpBlockView::registerToAppView($assets, $assetBundles);
        }
    }
679843
public function includeBlockabale(Block $block)
    {
        $blockable = $block->blockable;
        if (!empty($blockable)) {
            $entityClassName  = (new ReflectionClass($blockable))->getShortName();
            $transformerClass = 'Gzero\\Api\\Transformer\\' . $entityClassName . 'Transformer';
            return $this->item($blockable, new $transformerClass());
        }
        return null;
    }
609468
public function callBlock(string $block = '', ...$params): ?string
    {
        /** @var ModuleBlockInterface|null $module */
        $module = $this->module_service
            ->findByComponent(ModuleBlockInterface::class, $this->tree, Auth::user())
            ->first(static function (ModuleInterface $module) use ($block): bool {
                return $module->name() === $block && $module->name() !== 'html';
            });

        if ($module === null) {
            return '';
        }

        // Build the config array
        $cfg = [];
        foreach ($params as $config) {
            $bits = explode('=', $config);

            if (count($bits) < 2) {
                continue;
            }

            $v       = array_shift($bits);
            $cfg[$v] = implode('=', $bits);
        }

        return $module->getBlock($this->tree, 0, '', $cfg);
    }
772901
protected function putInCache(Block $block, Language $language, $html)
    {
        if ($block->is_cacheable) {
            cache()->tags(['blocks'])->forever('blocks:cache:' . $block->id . ':' . $language->code, $html);
        }
    }