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.112.1
Your Ip: 216.73.216.223
User: mjbynoyq (1574) | Group: mjbynoyq (1570)
Safe Mode: OFF
Disable Function:
NONE

name : placeholder-extractor.php
<?php


/**
 * @deprecated
 *
 * Class Brizy_Content_PlaceholderExtractor
 */
class Brizy_Content_PlaceholderExtractor
{

    /**
     * @var Brizy_Content_Providers_AbstractProvider
     */
    private $provider;


    /**
     * BrizyPro_Content_PlaceholderExtractor constructor.
     *
     * @param Brizy_Content_Providers_AbstractProvider $provider
     */
    public function __construct($provider)
    {
        $this->provider = $provider;
    }

    private static function getPlaceholderRegexExpression()
    {
        return "/(?<placeholder>{{\s*(?<placeholderName>.+?)(?<attributes>(?:\s+)((?:\w+\s*=\s*(?:'|\"|\&quot;|\&apos;)(?:.[^\"']*|)(?:'|\"|\&quot;|\&apos;)\s*)*))?}}(?:(?<content>.*?){{\s*end_(\g{placeholderName})\s*}})?)/ims";;
    }

    public static function stripPlaceholders($content)
    {
        $expression = self::getPlaceholderRegexExpression();
        return preg_replace($expression, '', $content);
    }

    /**
     * @param $content
     *
     * @return array
     */
    public function extract($content)
    {

        $placeholders = array();
        $expression = self::getPlaceholderRegexExpression();

        $matches = array();

        preg_match_all($expression, $content, $matches);

        if (count($matches['placeholder']) == 0) {
            return array($placeholders, $content);
        }

        foreach ($matches['placeholder'] as $i => $name) {

            $hasPlaceholder = $this->provider->getPlaceholder($matches['placeholderName'][$i]);

            // ignore unknown placeholders
            if (!$hasPlaceholder) {
                continue;
            }

	        $placeholder = new \BrizyPlaceholders\ContentPlaceholder(
		        $matches['placeholderName'][$i],
		        $matches['placeholder'][$i],
		        $this->getPlaceholderAttributes($matches['attributes'][$i]),
		        $matches['content'][$i]
	        );

	        $placeholders[] = $placeholder;

            $pos = strpos($content, $placeholder->getPlaceholder());

            $length = strlen($placeholder->getPlaceholder());

            if ($pos !== false) {
                $content = substr_replace($content, $placeholder->getUid(), $pos, $length);
            }
        }
        return array($placeholders, $content);
    }

    /**
     * Split the attributs from attribute string
     *
     * @param $attributeString
     *
     * @return array
     */
    private function getPlaceholderAttributes($attributeString)
    {
        $attrString = trim($attributeString);
        $attrMatches = array();
        $attributes = array();
        preg_match_all("/(\w+)\s*=\s*(?<quote>'|\"|\&quot;|\&apos;)(.*?)(\g{quote})/mi", $attrString, $attrMatches);

        if (isset($attrMatches[0]) && is_array($attrMatches[0])) {
            foreach ($attrMatches[1] as $i => $name) {
                $attributes[$name] = $attrMatches[3][$i];
            }
        }

        return $attributes;
    }

}
© 2025 XylotrechusZ