Stash::_prep_in_conditionals PHP Метод

_prep_in_conditionals() приватный Метод

Used with the permission of Lodewijk Schutte http://gotolow.com/addons/low-search
private _prep_in_conditionals ( string $tagdata = '' ) : String
$tagdata string
Результат String
    private function _prep_in_conditionals($tagdata = '')
    {
        if (preg_match_all('#' . LD . 'if (([\\w\\-_]+)|((\'|")(.+)\\4)) (NOT)?\\s?IN \\((.*?)\\)' . RD . '#', $tagdata, $matches)) {
            foreach ($matches[0] as $key => $match) {
                $left = $matches[1][$key];
                $operand = $matches[6][$key] ? '!=' : '==';
                $andor = $matches[6][$key] ? ' AND ' : ' OR ';
                $items = preg_replace('/(&(amp;)?)+/', '|', $matches[7][$key]);
                $cond = array();
                foreach (explode('|', $items) as $right) {
                    $tmpl = preg_match('#^(\'|").+\\1$#', $right) ? '%s %s %s' : '%s %s "%s"';
                    $cond[] = sprintf($tmpl, $left, $operand, $right);
                }
                // replace {if var IN (1|2|3)} with {if var == '1' OR var == '2' OR var == '3'}
                $tagdata = str_replace($match, LD . 'if ' . implode($andor, $cond) . RD, $tagdata);
            }
        }
        return $tagdata;
    }