Uname: Linux premium294.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.1.32 [ PHP INFO ] PHP os: Linux
Server Ip: 104.21.96.1
Your Ip: 216.73.216.223
User: mjbynoyq (1574) | Group: mjbynoyq (1570)
Safe Mode: OFF
Disable Function:
NONE

name : global-blocks.php
<?php

use BrizyPlaceholders\ContentPlaceholder;
use BrizyPlaceholders\ContextInterface;

class Brizy_Content_Placeholders_GlobalBlocks extends Brizy_Content_Placeholders_Abstract {

	public function __construct(
		$label, $placeholder, $group = null, $display = Brizy_Content_Placeholders_Abstract::DISPLAY_INLINE, $attrs = []
	) {
		$this->setLabel( $label );
		$this->setPlaceholder( $placeholder );
		$this->setDisplay( $display );
		$this->setGroup( $group );
		$this->setAttributes( $attrs );
	}

	/**
	 * @param ContextInterface $context
	 * @param ContentPlaceholder $placeholder
	 *
	 * @return string
	 * @throws Exception
	 */
	public function getValue( ContextInterface $context, ContentPlaceholder $placeholder ) {
		$position = $placeholder->getAttribute( 'position' ) ?: 'top';

		$template = Brizy_Admin_Templates::getTemplate();
		if ( $template ) {
			$blocks = Brizy_Admin_Blocks_Main::_init()->getMatchingBrizyBlocks( $template->getWpPost() );
		} else {
			$blocks = Brizy_Admin_Blocks_Main::_init()->getMatchingBrizyBlocks( $context->getEntity() );
		}

		$blocks = array_filter( $blocks, function ( Brizy_Editor_Post $block ) use ( $position ) {
			$is_referenced_in_page = Brizy_Admin_Blocks_Main::_init()->isReferencedInPage( $block );

			return $block->getPosition()->getAlign() == $position and ! $is_referenced_in_page;
		} );
		usort( $blocks, function ( $first, $second ) use ( $position ) {
			if ( $position == 'top' ) {
				return $first->getPosition()->getTop() > $second->getPosition()->getTop() ? 1 : - 1;
			} else {
				return $first->getPosition()->getBottom() > $second->getPosition()->getBottom() ? 1 : - 1;
			}
		} );

		return $this->returnBlocksContent( $blocks );
	}

	/**
	 * @param array $blocks
	 *
	 * @return string
	 */
	private function returnBlocksContent( array $blocks ) {

		$content = "";
		foreach ( $blocks as $block ) {
			/**
			 * @var
			 */
			$html    = base64_decode( $block->get_encoded_compiled_html() );
			$content .= <<<HTML
\n<!-- GLOBAL BLOCK [{$block->getWpPostId()}]-->
{$html}
<!-- END GLOBAL BLOCK [{$block->getWpPostId()}]-->
\n
HTML;
		}

		return $content;
	}
}
© 2025 XylotrechusZ