doMinify

@param string $content
@param array  $options

@return bool|string

@throws \Exception
@throws \Throwable
779211
protected function doMinify($content, array $options = [])
	{
		try
		{
			ob_start();
			$content = $this->lock($content);
			$this->minifyDirectToOutput($content . ';', $options);

			// Sometimes there's a leading new line, so we trim that out here.
			$content = ltrim(ob_get_clean());
			$content = $this->unlock($content);

			return $content;
		}
		catch (\Exception $e)
		{
			// without this call things get weird, with partially outputted js.
			ob_end_clean();
			throw $e;
		}
		catch (\Throwable $e)
		{
			// without this call things get weird, with partially outputted js.
			ob_end_clean();
			throw $e;
		}
	}
352837
public function write($content, $options = 448) : void
    {
        $json = json_encode($content, $options) . ($options & JSON_PRETTY_PRINT ? "\n" : '');
        parent::write($json);
    }
831584
public static function purify($content, array $options = [])
    {
        $config = HTMLPurifier_Config::createDefault();

        foreach ($options as $key => $value) {
            $config->set($key, $value);
        }

        if (!file_exists($config->get('Cache.SerializerPath'))) {
            mkdir($config->get('Cache.SerializerPath'));
        }

        $purifier = new HTMLPurifier($config);

        return $purifier->purify($content);
    }
174482
public function process($content, array $options = [])
    {
        $tagNames = array_keys($this->tags);
        $tagNames[] = 'component';
        if (is_string($content)) {
            $found = false;
            foreach ($tagNames as $tagName) {
                if (strpos($content, '<' . $tagName) !== false) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                return $content;
            }
        } elseif (!($content instanceof \IvoPetkov\HTMLServerComponent)) {
            throw new \InvalidArgumentException('');
        }

        $getComponentFileContent = static function($file, $component, $variables) {
            if (is_file($file)) {
                $__componentFile = $file;
                unset($file);
                if (!empty($variables)) {
                    extract($variables, EXTR_SKIP);
                }
                unset($variables);
                ob_start();
                include $__componentFile;
                $content = ob_get_clean();
                return $content;
            } else {
                throw new \Exception('Component file cannot be found (' . $file . ')');
            }
        };

        $getComponentResultHTML = function($component) use (&$getComponentFileContent, $options) {
            $srcAttributeValue = $component->getAttribute('src');
            if ($srcAttributeValue === null) {
                if (isset($this->tags[$component->tagName])) {
                    $srcAttributeValue = $this->tags[$component->tagName];
                } else {
                    throw new \Exception('Component tag name is not defined at ' . (string) $component . '!');
                }
            }
            if ($srcAttributeValue !== null) {
                // todo check alias of alias
                if (isset($this->aliases[$srcAttributeValue])) {
                    $sourceParts = explode(':', $this->aliases[$srcAttributeValue], 2);
                } else {
                    $sourceParts = explode(':', $srcAttributeValue, 2);
                }
                if (isset($sourceParts[0], $sourceParts[1])) {
                    $scheme = $sourceParts[0];
                    if ($scheme === 'data') {
                        if (substr($sourceParts[1], 0, 7) === 'base64,') {
                            return base64_decode(substr($sourceParts[1], 7)); //$this->process(, isset($componentOptions) ? $componentOptions : $options);
                        }
                        throw new \Exception('Components data URI scheme only supports base64 (data:base64,ABCD...)!');
                    } elseif ($scheme === 'file') {
                        return $getComponentFileContent(urldecode($sourceParts[1]), $component, isset($options['variables']) && is_array($options['variables']) ? $options['variables'] : []); //$this->process(isset($componentOptions) ? $componentOptions : $options);
                    }
                    throw new \Exception('Components URI scheme not valid! It must be \'file:\', \'data:\' or an alias.');
                }
                throw new \Exception('Components URI scheme or alias not found at ' . (string) $component . '!');
            }
            throw new \Exception('Component src attribute is missing at ' . (string) $component . '!');
        };

        $disableLevelProcessing = false;
        $domDocument = new HTML5DOMDocument();
        if ($content instanceof \IvoPetkov\HTMLServerComponent) {
            $domDocument->loadHTML($getComponentResultHTML($content), HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
            if (isset($options['recursive']) && $options['recursive'] === false) {
                $disableLevelProcessing = true;
            }
        } else {
            $domDocument->loadHTML($content, HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
        }
        if (!$disableLevelProcessing) {
            $tagsQuerySelector = implode(',', $tagNames);
            for ($level = 0; $level < 1000; $level++) {
                $componentElements = $domDocument->querySelectorAll($tagsQuerySelector);
                if ($componentElements->length === 0) {
                    break;
                }
                $insertHTMLSources = [];
                $list = []; // Save the elements into an array because removeChild() messes up the NodeList
                foreach ($componentElements as $componentElement) {
                    $isInOtherComponentTag = false;
                    $parentNode = $componentElement->parentNode;
                    while ($parentNode !== null && isset($parentNode->tagName)) {
                        if (array_search($parentNode->tagName, $tagNames) !== false) {
                            $isInOtherComponentTag = true;
                            break;
                        }
                        $parentNode = $parentNode->parentNode;
                    }
                    if (!$isInOtherComponentTag) {
                        $list[] = $componentElement;
                    }
                }
                foreach ($list as $i => $componentElement) {
                    $component = $this->makeComponent($componentElement->getAttributes(), $componentElement->innerHTML, $componentElement->tagName);
                    $componentResultHTML = $getComponentResultHTML($component);
                    $isInBodyTag = false;
                    $parentNode = $componentElement->parentNode;
                    while ($parentNode !== null && isset($parentNode->tagName)) {
                        if ($parentNode->tagName === 'body') {
                            $isInBodyTag = true;
                            break;
                        }
                        $parentNode = $parentNode->parentNode;
                    }
                    if ($isInBodyTag) {
                        $insertTargetName = 'html-server-components-compiler-insert-target-' . $i;
                        $componentElement->parentNode->insertBefore($domDocument->createInsertTarget($insertTargetName), $componentElement);
                        $componentElement->parentNode->removeChild($componentElement); // must be before insertHTML because a duplicate elements IDs can occur.
                        $insertHTMLSources[] = ['source' => $componentResultHTML, 'target' => $insertTargetName];
                    } else {
                        $componentElement->parentNode->removeChild($componentElement);
                        $insertHTMLSources[] = ['source' => $componentResultHTML];
                    }
                }
                $domDocument->insertHTMLMulti($insertHTMLSources);
                if (isset($options['recursive']) && $options['recursive'] === false) {
                    break;
                }
            }
        }

        $domDocument->modify(
                HTML5DOMDocument::FIX_MULTIPLE_TITLES |
                HTML5DOMDocument::FIX_DUPLICATE_METATAGS |
                HTML5DOMDocument::FIX_MULTIPLE_HEADS |
                HTML5DOMDocument::FIX_MULTIPLE_BODIES |
                HTML5DOMDocument::OPTIMIZE_HEAD
        );
        return $domDocument->saveHTML();
    }
210649
public function renderToggleButton($content, $options = [])
    {
        if (!isset($options['id'])) {
            $options['id'] = $this->getId() . '-button';
        }

        $this->getView()->registerJs('
        jQuery("#' . $options['id'] . '").on("click", function(event) {
            event.preventDefault();
            jQuery("#' . $this->getId() . '").modal("show");
        });
        ');

        return Elements::button($content, $options);
    }
142934
public function appendTextContent(string $content) : Tag
    {
        if ($this->isVoid) {
            throw new \LogicException('Void elements cannot have any contents.');
        }

        $this->content .= htmlspecialchars($content, ENT_NOQUOTES | ENT_HTML5);

        return $this;
    }
1230848
public function toJson($content, $options = [])
    {
        return collect([$this->_block->name => ['block' => $this->_block->toArray(), 'data' => $this->data($content)]])->toJson();
    }
879287
public function keyword($title, $content, $options=array()){

        $data = array();
        
        $data['title'] = $title;
        $data['content'] = $content;

        $data = array_merge($data, $options);
        $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');

        return $this->request($this->keywordUrl, $data);
    }
593522
public function contentTag($name, $content, array $options = array(), $escape = false)
    {
        if ($content instanceof \Closure) {
            ob_start();
            $ret     = $content();
            $content = ob_get_clean();
            if ($ret !== null) {
                $content = $ret;
            }
        }
        return $this->contentTagString($name, $content, $options, $escape);
    }
1346747
public function appendContent($content)
    {
        if ($this->isVoid) {
            throw new Exception\RuntimeException(
                'Void elements can\'t contain content.'
            );
        }

        $this->content .= $content;

        return $this;
    }
286584
protected function createDOM($content)
    {
        if (!$content) {
            return false;
        }
        $dom = new DOMDocument();
        $dom->loadHTML($content);
        $dom->preserveWhiteSpace = false;

        return $dom;
    }
845731
public function setContent($content)
    {
        if ($this->isVoid) {
            throw new Exception\RuntimeException(
                'Void elements can\'t contain content.'
            );
        }

        $this->content = $content;

        return $this;
    }
375713
public function update(array $content, array $options = [])
    {
        $data = [
            '_id' => $this->id,
            'body' => $content
        ];

        $response = $this->security->getKuzzle()->query(
            $this->security->buildQueryArgs($this->updateActionName),
            $data,
            $options
        );

        $this->setContent($response['result']['_source']);

        return $this;
    }
3016
public function filter($content, array $options = array())
	{
		$itemTemplate = ! empty($options['itemTemplate']) ? (string) $options['itemTemplate'] : '';
		$wrapperTemplate = ! empty($options['wrapperTemplate']) ? (string) $options['wrapperTemplate'] : '';

		$output = '';

		$fileStorage = $this->container['cms.file_storage'];
		/* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */

		foreach ($this->blockProperty->getMetadata() as $metadata) {
			/* @var $metadata \Supra\Package\Cms\Entity\BlockPropertyMetadata */

			$element = $metadata->getReferencedElement();

			if (! $element instanceof ImageReferencedElement
					|| $element->getSizeName() === null) {

				continue;
			}

			$image = $fileStorage->findImage($element->getImageId());

			if ($image === null) {
				continue;
			}

			$previewSize = $image->getImageSize($element->getSizeName());

			if ($previewSize === null) {
				continue;
			}

			$previewUrl = $fileStorage->getWebPath($image, $previewSize);

			$crop = isset($options['fullSizeCrop']) ? (bool) $options['fullSizeCrop'] : true;

			$fullSizeWidth = ! empty($options['fullSizeMaxWidth']) ? (int) $options['fullSizeMaxWidth'] : null;
			$fullSizeHeight = ! empty($options['fullSizeMaxHeight']) ? (int) $options['fullSizeMaxWidth'] : null;

			try {

				list($width, $height) = $this->getFullSizeDimensions($image, $fullSizeWidth, $fullSizeHeight, $crop);
				$fullSizeName = $fileStorage->createResizedImage($image, $width, $height, $crop);

			} catch (FileStorageException $e) {
				$this->container->getLogger()->warn($e->getMessage());
				continue;
			}

			$fullSize = $image->getImageSize($fullSizeName);
			$fullSizeUrl = $fileStorage->getWebPath($image, $fullSize);

			$itemData = array(
				'image' 		=> '<img src="' . $previewUrl . '" alt="' . $element->getAlternateText() . '" />',
				'imageUrl' 		=> $previewUrl,
				'title' 		=> $element->getTitle(),
				'description' 	=> $element->getDescription(),

				'fullSizeUrl' 	=> $fullSizeUrl,
				'fullSizeWidth' => $fullSize->getWidth(),
				'fullSizeHeight' => $fullSize->getHeight(),
			);

			$output .= preg_replace_callback(
				'/{{\s*(image|title|description|fullSizeUrl|fullSizeWidth|fullSizeHeight)\s*}}/',
				function ($matches) use ($itemData) {
					return $itemData[$matches[1]];
				},
				$itemTemplate
			);
		}

		return preg_replace('/{{\s*items\s*}}/', $output, $wrapperTemplate);
	}
53410
public function addOption(string $content, string $value)
    {
        $this->options[] = new Option($content, $value);

        return $this;
    }
905072
public static function well($content, $htmlOptions = array())
    {
        self::addCssClass('well', $htmlOptions);
        $size = TbArray::popValue('size', $htmlOptions);
        if (!empty($size)) {
            self::addCssClass('well-' . $size, $htmlOptions);
        }
        return self::tag('div', $htmlOptions, $content);
    }
933839
public function after($content) {
    if (FALSE === (bool) $this) {
      return $this;
    }
    $me = $this->dom();
    $parent = $this->xparent()->dom();
    $new = $this->_contentToDom($content);
    if (isset($me->nextSibling)) {
      $parent->insertBefore($new, $me->nextSibling);
    }
    else {
      $parent->appendChild($new);
    }
    return $this;
  }