Compresses a string.

@param string $content The content to compress
@param string $type    The type of content, either "js" or "css"
@param array  $options An indexed array of additional options

@return string The compressed content
354686
protected function compress($content, $type, $options = array())
    {
        $commandline =array($this->javaPath);

        if (null !== $this->stackSize) {
            array_push($commandline, '-Xss'.$this->stackSize);
        }

        array_push($commandline, '-jar', $this->jarPath);

        foreach ($options as $option) {
            array_push($commandline, $option);
        }

        if (null !== $this->charset) {
            array_push($commandline, '--charset', $this->charset);
        }

        if (null !== $this->lineBreak) {
            array_push($commandline, '--line-break', $this->lineBreak);
        }

        // input and output files
        $tempDir = FilesystemUtils::getTemporaryDirectory();
        $input = tempnam($tempDir, 'assetic_yui_input');
        $output = tempnam($tempDir, 'assetic_yui_output');
        file_put_contents($input, $content);
        array_push($commandline, '-o', $output, '--type', $type, $input);

        $proc = new Process(implode(' ', $commandline));
        $code = $proc->run();
        unlink($input);

        if (0 !== $code) {
            if (file_exists($output)) {
                unlink($output);
            }

            throw FilterException::fromProcess($proc)->setInput($content);
        }

        if (!file_exists($output)) {
            throw new \RuntimeException('Error creating output file.');
        }

        $retval = file_get_contents($output);
        unlink($output);

        return $retval;
    }
660012
public function createTask(string $content, array $options = [])
    {
        if ('' === $content) {
            return false;
        }

        unset($options['content']);
        $data   = $this->prepareRequestData(array_merge(['content' => $content], $options));
        $result = $this->post('tasks', $data);

        $status = $result->getStatusCode();
        if (200 === $status) {
            return json_decode($result->getBody()->getContents());
        }

        return false;
    }
299228
public function uploadByContent($content, $type = '', $option = [])
    {
        // 临时文件
        $tmp_file = Common::tmpFile('upload');
        file_put_contents($tmp_file, $content);
        
        // 上传完删除文件
        $this->onDone = function ($data) {
            @unlink($data['path']);
        };
        
        return $this->uploadByPath($tmp_file, $type, $option);
    }
717254
protected function encode($content)
    {
        $jsonEncodeOptions = [];

        // Here is a place, where any available JSON encoding options, that
        // deal with users' requirements to JSON response formatting and
        // structure, can be conveniently applied to tweak the output.

        if ($this->isJsonPrettyPrintEnabled()) {
            $jsonEncodeOptions[] = JSON_PRETTY_PRINT;
        }

        $encodedString = $this->performJsonEncoding($content, $jsonEncodeOptions);

        if ($this->isCustomIndentStyleRequired()) {
            $encodedString = $this->indentPrettyPrintedJson(
                $encodedString,
                $this->options['indent_style']
            );
        }

        return $encodedString;
    }
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();
    }
12621
protected function _getTypeOutput(array $options, $url, $type)
    {
        $type = Str::low($type);
        if ($type === 'css') {
            return $this->_getCssOutput($options, $url);
        }

        return $this->_getScriptOutput($options, $url);
    }
6181
public function addMessage($type, $content)
	{
		if($this->session->has('Cfmessage')) {
			$messages = $this->session->get('Cfmessage', []);
		}
		
		$messages[] = [
			'content' => $content,
			'type' => $type,
		];
		
		$this->session->set('Cfmessage', $messages);
	}
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);
    }
368824
final protected function header(string $content, string $type = null)
    {
        Response::header($content, $type);
    }
267426
protected function renderTextareaWidget($content, array $options = [])
    {
        $options = array_replace([
            'html' => false,
        ], $options);

        return $this->renderBlock('show_widget_textarea', [
            'content' => $content,
            'options' => $options,
        ]);
    }
1323210
public function append($filename,$content,$type=''){
        if(is_file($filename)){
            $content =  $this->read($filename,$type).$content;
        }
        return $this->put($filename,$content,$type);
    }
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);
    }
417948
public function addMessage($type, $content)
	{
		if(isset($_SESSION[$this->sessionKey])) {
			$messages = $_SESSION[$this->sessionKey];
		}
		
		$messages[] = [
			'content' => $content,
			'type' => $type,
		];
		
		$_SESSION[$this->sessionKey] = $messages;
	}
1005256
public function serialize($content, array $options = [])
    {
        $node = $content->getResourceNode();

        if (!empty($node)) {
            $serialized = $this->resourceContentSerializer->serialize($node, $options);
        } else {
            $serialized = [
                'type' => 'text/html',
                'data' => $content->getData(),
            ];
        }

        return $serialized;
    }
491595
public function render($content, $type = '')
    {
        // Check variables
        $this->checkContent($content);
        if (!$type) {
            if ($this->defaultType !== false) {
                $type = $this->defaultType;
            }
        }
        $this->setType($type);

        // Render html
        return $this->renderElement($content);
    }
464465
protected function renderNumberWidget($content, array $options = [])
    {
        $options = array_merge([
            'precision' => 2,
            'append' => '',
        ], $options);

        return $this->renderBlock('show_widget_simple', [
            'content' => trim(sprintf('%s %s', number_format($content, $options['precision'], ',', ' '), $options['append']))
        ]);
    }
1270001
public function setBuffer($content, $options = array())
	{
		// The following code is just for backward compatibility.
		if (func_num_args() > 1 && !is_array($options))
		{
			$args = func_get_args();
			$options = array();
			$options['type'] = $args[1];
			$options['name'] = (isset($args[2])) ? $args[2] : null;
		}

		parent::$_buffer[$options['type']][$options['name']] = $content;

		return $this;
	}