parse minify callback
@access protected
@param $m array
@return string
@since 3.0
@package Gcs\Framework\Core\Template
181029
protected function _parseMinifyCallback($m) {
        if (Config::config()['user']['output']['minify']) {
            $m[1] = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $m[1]);
            $m[1] = str_replace(["\t", '  ', '    ', '    '], '', $m[1]);
        }

        return $m[1];
    }
965858
public static function minify($expr)
	{
		$old     = $expr;
		$strings = [];

		// Trim the surrounding whitespace then temporarily remove literal strings
		$expr = preg_replace_callback(
			'/"[^"]*"|\'[^\']*\'/',
			function ($m) use (&$strings)
			{
				$uniqid = '(' . sha1(uniqid()) . ')';
				$strings[$uniqid] = $m[0];

				return $uniqid;
			},
			trim($expr)
		);

		if (preg_match('/[\'"]/', $expr))
		{
			throw new RuntimeException("Cannot parse XPath expression '" . $old . "'");
		}

		// Normalize whitespace to a single space
		$expr = preg_replace('/\\s+/', ' ', $expr);

		// Remove the space between a non-word character and a word character
		$expr = preg_replace('/([-a-z_0-9]) ([^-a-z_0-9])/i', '$1$2', $expr);
		$expr = preg_replace('/([^-a-z_0-9]) ([-a-z_0-9])/i', '$1$2', $expr);

		// Remove the space between two non-word characters as long as they're not two -
		$expr = preg_replace('/(?!- -)([^-a-z_0-9]) ([^-a-z_0-9])/i', '$1$2', $expr);

		// Remove the space between a - and a word character, as long as there's a space before -
		$expr = preg_replace('/ - ([a-z_0-9])/i', ' -$1', $expr);

		// Remove the spaces between a number and the div operator and the next token
		$expr = preg_replace('/((?:^|[ \\(])\\d+) div ?/', '$1div', $expr);

		// Remove the space between the div operator the next token
		$expr = preg_replace('/([^-a-z_0-9]div) (?=[$0-9@])/', '$1', $expr);

		// Restore the literals
		$expr = strtr($expr, $strings);

		return $expr;
	}
827753
protected function doShortcodeTag($m)
    {
        // allow [[foo]] syntax for escaping a tag
        if ($m[1] == '[' && $m[6] == ']') {
            return substr($m[0], 1, -1);
        }

        $tag = $m[2];
        $attr = $this->parseAttributes($m[3]);

        $callback = $this->_shortcodes[$tag]['callback'];
        $config = $this->_shortcodes[$tag]['config'];

        $attr = ArrayHelper::merge($config, $attr);
        $content = isset($m[5]) ? $m[5] : null;

        $attr['content'] = $content;
        $this->addToPool($tag);
        return $m[1] . call_user_func($callback, $attr, $content, $tag) . $m[6];
    }
455840
public function minifyAssetsAction ()
    {
        $request = $this->getRequest();
        $siteID = $request->getPost('siteId');
        /** @var \MelisFront\Service\MinifyAssetsService $minifyAssets */
        $minifyAssets = $this->getServiceLocator()->get('MinifyAssets');
        $result = $minifyAssets->minifyAssets($siteID);

        $title = 'Compiling assets';

        /**
         * modify a little the result
         */
        $success = true;
        $message = '';
        if(!empty($result['results'])){
            foreach($result['results'] as $key => $val){
                if(!$val['success']){
                    $success = false;
                    $message = $val['message'];
                }
            }
        }

        return new JsonModel(array(
            'title' => $title,
            'message' => wordwrap($message, 20, "\n", true),
            'success' => $success,
        ));
    }
478407
protected function _parseUrlCallbackNormal($m) {
        if (isset($m[3])) {
            $vars = explode(',', $m[3]);
        }
        else {
            $vars = [];
        }

        $array = 'array(';

        foreach ($vars as $val) {
            $array .= '' . $val . ',';
        }

        $array = trim($array, ',') . ')';

        return [$m[2], $array];
    }
836460
protected function _parseLangCallBackNoEcho($m) {
        $a = explode(':', $m[2]); //we separate the two sections

        if ($m[1] == ':') {
            $type = '';
        }
        else {
            $type = ', \Gcs\Framework\Core\Lang\Lang::USE_TPL';
        }

        if (isset($a[1])) {
            if (!preg_match('#\$#', $a[0])) {
                return '$this->useLang(\'' . trim($a[0]) . '\',array(' . trim($a[1]) . ')' . $type . ')';
            }
            else {
                return '$this->useLang(' . trim($a[0]) . ',array(' . trim($a[1]) . ')' . $type . ')';
            }
        }
        else {
            if (!preg_match('#\$#', $a[0])) {
                return '$this->useLang(\'' . trim($a[0]) . '\',array()' . $type . ')';
            }
            else {
                return '$this->useLang(' . trim($a[0]) . ',array()' . $type . ')';
            }
        }
    }
1326113
public function process(MinifyContext $context)
    {
        Collection::make($this->redundantAttributes)->each(function ($attributes, $element) use (&$context) {
            Collection::make($attributes)->each(function ($value, $attribute) use ($element, &$context) {
                $contents = preg_replace_callback(
                    '/
                        '.$element.'                    # Match the given element
                        ((?!\s*'.$attribute.'\s*=).)*   # Match everything except the given attribute
                        (
                            \s*'.$attribute.'\s*        # Match the attribute
                            =\s*                        # Match the equals sign
                            (["\']?)                    # Match the opening quotes
                            \s*'.$value.'\s*            # Match the value
                            \3?                         # Match the captured opening quotes again
                            \s*
                        )
                    /xis',
                    function ($match) {
                        return $this->removeAttribute($match[0], $match[2]);
                    }, $context->getContents());

                $context->setContents($contents);
            });
        });

        return $context;
    }
1163360
protected function minify($code)
    {
        $pattern = (string) '!/\*[^*]*\*+([^/][^*]*\*+)*/!';

        $minified = preg_replace('/^\\s+/m', '', $code);

        $minified = preg_replace($pattern, '', $minified);

        $minified = preg_replace('/( )?}( )?/', '}', $minified);

        $minified = preg_replace('/( )?{( )?/', '{', $minified);

        $minified = preg_replace('/( )?:( )?/', ':', $minified);

        $minified = preg_replace('/( )?;( )?/', ';', $minified);

        $minified = preg_replace('/( )?,( )?/', ',', $minified);

        return $minified;
    }
522754
private static function checkSize(Meta $m)
    {
        if ($m->getSize()) {
            $length = strlen($m->getValue());
            if ($m->getType() === "varchar" && $length > $m->getSize())
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "char" && $length > 1)
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "tinytext" && ($length > 255 || $length > $m->getSize()))
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "text" && ($length > 65535 || $length > $m->getSize()))
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "mediumtext" && ($length > 16777215 || $length > $m->getSize()))
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "longtext" && ($length > 4294967295 || $length > $m->getSize()))
                $m->setError("tamanho máximo de caracteres excedido. Max {$m->getSize()}");

            elseif ($m->getType() === "tinyint" && ($m->getValue() > self::intLength($m->getSize()) || $m->getValue() > self::intLength(8)))
                $m->setError("numero excedeu seu limite. Max " . self::intLength($m->getSize()));

            elseif ($m->getType() === "smallint" && ($m->getValue() > self::intLength($m->getSize()) || $m->getValue() > self::intLength(16)))
                $m->setError("numero excedeu seu limite. Max " . self::intLength($m->getSize()));

            elseif ($m->getType() === "mediumint" && ($m->getValue() > self::intLength($m->getSize()) || $m->getValue() > self::intLength(24)))
                $m->setError("numero excedeu seu limite. Max " . self::intLength($m->getSize()));

            elseif ($m->getType() === "int" && !in_array($m->getKey(), ["extend", "extend_add", "list", "list_mult", "selecao", "selecao_mult", "checkbox_rel", "extend_mult", "checkbox_mult"]) && ($m->getValue() > self::intLength($m->getSize()) || $m->getValue() > self::intLength(32)))
                $m->setError("numero excedeu seu limite. Max " . self::intLength($m->getSize()));

            elseif ($m->getType() === "bigint" && ($m->getValue() > self::intLength($m->getSize()) || $m->getValue() > self::intLength(64)))
                $m->setError("numero excedeu seu limite. Max " . self::intLength($m->getSize()));
        }
    }
957296
protected function placeholders(MinifyContext $context)
    {
        foreach ($this->placeholders as $placeholder) {
            $placeholder = new $placeholder();
            $context = $placeholder->process($context);
        }

        return $context;
    }
849713
public function minify()
    {
        $cleaned_stack = $this->cleanStack($this->get(), 'path');
        if (!empty($cleaned_stack)) {
            foreach ($cleaned_stack as $i=>$item) {
                if (isset($item['minified']) && true===$item['minified']) {
                    unset($cleaned_stack[$i]);
                }
            }
        }
        if (!empty($cleaned_stack)) {
            $this->addMinified(
                $this->minifyStack($this->extractFromStack($cleaned_stack, 'path'))
            );
        }
        return $this;
    }
1167673
protected function _parseGravatarCallback($m) {
        if (preg_match('#^\$#', $m[1])) {
            foreach ($this->_template->vars as $key => $val) {
                if (substr($m[1], 1, strlen($m[1])) == $key) {
                    $m[1] = preg_replace('`' . $key . '`', $val, $m[1]);
                    $m[1] = substr($m[1], 1, strlen($m[1]));
                }
            }
        }
        if (isset($m[2]) && preg_match('#^\$#', $m[2])) {
            foreach ($this->_template->vars as $key => $val) {
                if (substr($m[2], 1, strlen($m[2])) == $key) {
                    $m[2] = preg_replace('`' . $key . '`', $val, $m[2]);
                    $m[2] = substr($m[2], 1, strlen($m[2]));
                }
            }
        }
        else {
            $m[2] = 100;
        }

        if (preg_match('#\'#', $m[1])) {
            $m[1] = preg_replace('#\'#', '"', $m[1]);

            return '<?php echo \'http://secure.gravatar.com/avatar/\'.md5(' . $m[1] . ').\'?s=' . $m[2] . '&d=identicon\'; ?>';
        }
        else {
            return '<?php echo \'http://secure.gravatar.com/avatar/\'.md5("' . $m[1] . '").\'?s=' . $m[2] . '&d=identicon\'; ?>';
        }
    }
449588
public function min($js)
    {
        $postBody = $this->buildPostBody($js);

        if ($this->maxBytes > 0) {
            $bytes = (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
                ? mb_strlen($postBody, '8bit')
                : strlen($postBody);
            if ($bytes > $this->maxBytes) {
                throw new Minify_JS_ClosureCompiler_Exception(
                    'POST content larger than ' . $this->maxBytes . ' bytes'
                );
            }
        }

        $response = $this->getResponse($postBody);

        if (preg_match('/^Error\(\d\d?\):/', $response)) {
            if (is_callable($this->fallbackMinifier)) {
                // use fallback
                $response = "/* Received errors from Closure Compiler API:\n$response"
                          . "\n(Using fallback minifier)\n*/\n";
                $response .= call_user_func($this->fallbackMinifier, $js);
            } else {
                throw new Minify_JS_ClosureCompiler_Exception($response);
            }
        }

        if ($response === '') {
            $errors = $this->getResponse($this->buildPostBody($js, true));
            throw new Minify_JS_ClosureCompiler_Exception($errors);
        }

        return $response;
    }
685980
protected function _parseIncludeCallback($m) {
        $file = $this->resolve(RESOLVE_TEMPLATE, $m[1]) . '.tpl';

        $content = "";
        if ($this->_template->getFile() != $file) {
            if (file_exists($file)) {
                if (isset($m[4])) //precised time cache
                {
                    $t = new Template($m[1], 'tplInclude_' . $this->_template->getName() . '_' . $m[4] . '_' . Request::instance()->lang . '_' . $this->_includeI . '_', $m[4]);
                }
                else {
                    $t = new Template($m[1], 'tplInclude_' . $this->_template->getName() . '_' . Request::instance()->lang . '_' . $this->_includeI . '_', 0);
                }

                $t->assign($this->_template->vars);
                $t->show(Template::TPL_COMPILE_TO_INCLUDE, Template::TPL_COMPILE_INCLUDE);

                if (file_get_contents($t->getFileCache())) {
                    $content = file_get_contents($t->getFileCache());
                }

                $this->_includeI++;
            }
            else {
                $this->addError('Template "' . $file . '" can\'t be included', __FILE__, __LINE__, ERROR_FATAL);
            }
        }

        return $content;
    }
781988
public function process(MinifyContext $context)
    {
        $booleanAttributes = implode('|', (new HtmlBooleanAttributeRepository())->getAttributes());

        return $context->setContents(preg_replace_callback(
            '/
                \s                          # first match a whitespace which is an indication if its an attribute
                ('.$booleanAttributes.')    # match and capture a boolean attribute
                \s*
                =
                \s*
                ([\'"])?                    # optional to use a quote
                (\1|true|false|([\s>"\']))    # match the boolean attribute name again or true|false
                \2?                         # match the quote again
            /xi', function ($match) {
                if (isset($match[4])) {
                    return ' '.$match[1];
                }

                if ($match[3] == 'false') {
                    return '';
                }

                return ' '.$match[1];
            }, $context->getContents()));
    }
1121454
public function minify($collection) {
		// check final path
		$public_path = $this->f3->get('ASSETS.minify.public_path');
		if (!is_dir($public_path))
			mkdir($public_path,0777,true);
		$type = false;
		$inline_stack = array();
		foreach($collection as $i=>&$asset) {
			$type = $asset['type'];
			if ($asset['origin']=='inline') {
				$slot = $asset['slot'] ?: 'default';
				$inline_stack[$slot][] = $asset['data'];
				unset($collection[$i]);
				unset($asset);
				continue;
			}
			$path = $asset['path'];
			$exclude = $this->f3->get('ASSETS.minify.exclude');
			// skip external files
			if ($asset['origin'] == 'external')
				continue;
			elseif (is_file($path) && (
				(!isset($asset['exclude']) ||
					!in_array('minify',$this->f3->split($asset['exclude']))) &&
				(empty($exclude) || !preg_match('/'.$exclude.'/i',$path)))) {
				// proceed
				$path_parts = pathinfo($path);
				$filename = $path_parts['filename'].'.'
					.substr($this->f3->hash($path),0,5).'.min.'.$type;
				if (!is_file($public_path.$filename) ||
					(filemtime($path)>filemtime($public_path.$filename))) {
					$min = $this->f3->call($this->f3->get('ASSETS.minify.compiler.'.$type),
						[$path_parts['basename'],$path_parts['dirname'].'/']);
					if ($type=='css')
						$min = $this->fixRelativePaths($min,
							$path_parts['dirname'].'/',$public_path);
					$this->f3->write($public_path.$filename,$min);
				}
				$asset['path'] = $public_path.$filename;
			}
			unset($asset);
		}
		if (!empty($inline_stack)) {
			foreach ($inline_stack as $slotGroup=>$inlineData) {
				$data = implode($inlineData);
				if ($this->f3->get('ASSETS.minify.inline')) {
					// this is probably pretty slow
					$hash = $this->f3->hash($data);
					$filename = $hash.'.min.'.$type;
					if (!is_file($public_path.$filename)) {
						$this->f3->write($public_path.$filename,$data);
						$min = \Web::instance()->minify($filename,null,false,
							$public_path);
						$this->f3->write($public_path.$filename,$min);
					}
					$collection[] = array(
						'path'=>$public_path.$filename,
						'type'=>$type,
						'origin'=>'internal',
						'slot'=>$slotGroup,
					);
				} else {
					$collection[] = array(
						'data'=>$data,
						'type'=>$type,
						'origin'=>'inline',
						'slot'=>$slotGroup,
					);
				}
			}
		}
		return $collection;
	}
127544
protected static function _doShortcode($m)
    {
        // allow {{foo}} syntax for escaping a tag
        if ($m[1] == '{' && $m[6] == '}') {
            return substr($m[0], 1, -1);
        }

        $tag = $m[2];
        $atts = static::_parseAttributes($m[3]);
        $listeners = EventDispatcher::instance('Shortcode')
            ->eventManager()
            ->listeners($tag);

        if (!empty($listeners)) {
            $options = [
                'atts' => (array)$atts,
                'content' => null,
                'tag' => $tag
            ];

            if (isset($m[5])) {
                $options['content'] = $m[5];
            }

            $result = EventDispatcher::instance('Shortcode')
                ->triggerArray([$tag, static::cache('context')], $options)
                ->result;

            return $m[1] . $result . $m[6];
        }

        return '';
    }