示例#1
0
function motopressCEParseObjectsRecursive($matches, $parseContent = true)
{
    global $motopressCELibrary;
    $regex = '/' . motopressCEGetMPShortcodeRegex() . '/s';
    if (is_array($matches)) {
        if (!empty($matches[5])) {
            $matches[5] = preg_replace('/^<\\/p>(.*)/', '${1}', $matches[5]);
            $matches[5] = preg_replace('/(.*)<p>$/', '${1}', $matches[5]);
        }
        $grid = $motopressCELibrary->getGridObjects();
        $groupObjects = $motopressCELibrary->getGroupObjects();
        $parameters_str = ' ' . MPCEShortcode::$attributes['parameters'];
        $unwrap = '';
        $atts = shortcode_parse_atts($matches[3]);
        $atts = (array) $atts;
        $list = $motopressCELibrary->getObjectsList();
        $parameters = $list[$matches[2]]['parameters'];
        $group = $list[$matches[2]]['group'];
        //set parameters of shortcode
        if (!empty($parameters)) {
            foreach ($parameters as $name => $param) {
                if (array_key_exists($name, $atts)) {
                    //$value = $atts[$name];
                    //$parameters[$name]['value'] = str_replace(array('\'', '"'), array('&#039;', '&quot;'), $value);
                    $value = preg_replace('#^<\\/p>|^<br \\/>|<p>$#', '', $atts[$name]);
                    $parameters[$name]['value'] = htmlentities($value, ENT_QUOTES, 'UTF-8');
                } else {
                    $parameters[$name] = new stdClass();
                }
            }
            $jsonParameters = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($parameters, JSON_UNESCAPED_UNICODE) : motopressCEJsonEncode($parameters);
            $parameters_str = " " . MPCEShortcode::$attributes['parameters'] . "='" . $jsonParameters . "'";
        }
        //set styles
        $styles = array();
        if (!empty(MPCEShortcode::$styles)) {
            foreach (MPCEShortcode::$styles as $name => $value) {
                if (array_key_exists($name, $atts)) {
                    //$value = $atts[$name];
                    //$styles[$name]['value'] = str_replace(array('\'', '"'), array('&#039;', '&quot;'), $value);
                    $value = preg_replace('#^<\\/p>|^<br \\/>|<p>$#', '', $atts[$name]);
                    $styles[$name]['value'] = htmlentities($value, ENT_QUOTES, 'UTF-8');
                } else {
                    $styles[$name] = new stdClass();
                }
            }
            if (!is_array($styles['mp_style_classes'])) {
                if (array_key_exists($matches[2], $motopressCELibrary->deprecatedParameters)) {
                    foreach ($motopressCELibrary->deprecatedParameters[$matches[2]] as $key => $val) {
                        if (array_key_exists($key, $atts)) {
                            if (!is_array($styles['mp_style_classes'])) {
                                $styles['mp_style_classes'] = array();
                                $styles['mp_style_classes']['value'] = '';
                            }
                            if ($matches[2] === MPCEShortcode::PREFIX . 'button') {
                                if ($key === 'color' && $atts[$key] === 'default') {
                                    $className = $val['prefix'] . 'silver';
                                } elseif ($key === 'size') {
                                    $className = $atts[$key] === 'default' ? $val['prefix'] . 'middle' : $val['prefix'] . $atts[$key];
                                    $className .= ' motopress-btn-rounded';
                                } else {
                                    $className = $val['prefix'] . $atts[$key];
                                }
                            } else {
                                $className = $val['prefix'] . $atts[$key];
                            }
                            $styles['mp_style_classes']['value'] .= $styles['mp_style_classes']['value'] === '' ? $className : ' ' . $className;
                        }
                    }
                }
            }
            $jsonStyles = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($styles, JSON_UNESCAPED_UNICODE) : motopressCEJsonEncode($styles);
            $styles_str = " " . MPCEShortcode::$attributes['styles'] . "='" . $jsonStyles . "'";
        }
        // set close-type of shortcode
        if (preg_match('/\\[\\/' . $matches[2] . '\\](?:<br \\/>)?(?:<\\/p>)?$/', $matches[0]) === 1) {
            $endstr = '[/' . $matches[2] . ']';
            $closeType = MPCEObject::ENCLOSED;
        } else {
            $endstr = '';
            $closeType = MPCEObject::SELF_CLOSED;
        }
        //wrap custom code
        $cleanRegex = motopressCEGetMPShortcodeRegex();
        $wrapCustomCodeRegex = '/\\A(?:' . $cleanRegex . ')+\\Z/s';
        if (isset($grid['span']['type']) && $grid['span']['type'] === 'multiple') {
            $spanShortcodes = array_merge($grid['span']['shortcode'], $grid['span']['inner']);
        } else {
            $spanShortcodes = array($grid['span']['shortcode'], $grid['span']['inner']);
        }
        if ($matches[5] !== '' && $matches[5] !== '&nbsp;' && in_array($matches[2], $spanShortcodes) && !preg_match($wrapCustomCodeRegex, $matches[5])) {
            $matches[5] = motopressCEWrapCustomCode($matches[5]);
        }
        // set system marking for "must-unwrap" code
        if ($matches[2] == 'mp_code') {
            if (!empty($matches[3])) {
                $atts = shortcode_parse_atts($matches[3]);
                if (isset($atts['unwrap']) && $atts['unwrap'] === 'true') {
                    $unwrap = ' ' . MPCEShortcode::$attributes['unwrap'] . ' = "true"';
                }
            }
        }
        // Members Widget fix
        if ($matches[2] == 'mp_members_content') {
            if (!empty($matches[3])) {
                $attrs = shortcode_parse_atts($matches[3]);
                if (isset($attrs['members_content'])) {
                    $matches[5] = $attrs['members_content'];
                    unset($attrs['members_content']);
                    $matches[3] = '';
                    foreach ($attrs as $name => $value) {
                        $matches[3] .= ' ' . $name . '="' . $value . '"';
                    }
                }
            }
        }
        $dataContent = '';
        //setting data-motopress-content for all objects except layout
        if (isset($grid['span']['type']) && $grid['span']['type'] === 'multiple') {
            $gridShortcodes = array_merge(array($grid['row']['shortcode'], $grid['row']['inner']), $grid['span']['shortcode'], $grid['span']['inner']);
        } else {
            $gridShortcodes = array($grid['row']['shortcode'], $grid['row']['inner'], $grid['span']['shortcode'], $grid['span']['inner']);
        }
        if (!in_array($matches[2], $gridShortcodes)) {
            $dataContent = motopressCEScreeningDataAttrShortcodes($matches[5]);
        }
        if (in_array($matches[2], $gridShortcodes) || in_array($matches[2], $groupObjects)) {
            return '<div ' . MPCEShortcode::$attributes['closeType'] . '="' . $closeType . '" ' . MPCEShortcode::$attributes['shortcode'] . '="' . $matches[2] . '" ' . MPCEShortcode::$attributes['group'] . '="' . $group . '"' . $parameters_str . $styles_str . ' ' . MPCEShortcode::$attributes['content'] . '="' . htmlentities($dataContent, ENT_QUOTES, 'UTF-8') . '" ' . $unwrap . '>[' . $matches[2] . $matches[3] . ']' . preg_replace_callback($regex, 'motopressCEParseObjectsRecursive', $matches[5]) . $endstr . '</div>';
        } else {
            $matches[5] = MPCEShortcode::unautopMotopressShortcodes($matches[5]);
            return '<div ' . MPCEShortcode::$attributes['closeType'] . '="' . $closeType . '" ' . MPCEShortcode::$attributes['shortcode'] . '="' . $matches[2] . '" ' . MPCEShortcode::$attributes['group'] . '="' . $group . '"' . $parameters_str . $styles_str . ' ' . MPCEShortcode::$attributes['content'] . '="' . htmlentities($dataContent, ENT_QUOTES, 'UTF-8') . '" ' . $unwrap . '>[' . $matches[2] . $matches[3] . ']' . $matches[5] . $endstr . '</div>';
        }
    }
    return preg_replace_callback($regex, 'motopressCEParseObjectsRecursive', $matches);
}
示例#2
0
function motopressCEParseObjectsRecursive($matches)
{
    global $motopressCELibrary;
    $regex = '/' . motopressCEGetMPShortcodeRegex() . '/';
    if (is_array($matches)) {
        $parameters_str = ' ' . MPCEShortcode::$attributes['parameters'];
        $unwrap = '';
        $atts = shortcode_parse_atts($matches[3]);
        $atts = (array) $atts;
        $list = $motopressCELibrary->getObjectsList();
        $parameters = $list[$matches[2]]['parameters'];
        $group = $list[$matches[2]]['group'];
        //set parameters of shortcode
        if (!empty($parameters)) {
            foreach ($parameters as $name => $param) {
                if (array_key_exists($name, $atts)) {
                    //$value = $atts[$name];
                    //$parameters[$name]['value'] = str_replace(array('\'', '"'), array('&#039;', '&quot;'), $value);
                    $value = preg_replace('#^<\\/p>|^<br \\/>|<p>$#', '', $atts[$name]);
                    $parameters[$name]['value'] = htmlentities($value, ENT_QUOTES, 'UTF-8');
                } else {
                    $parameters[$name] = new stdClass();
                }
            }
            $jsonParameters = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($parameters, JSON_UNESCAPED_UNICODE) : motopressCEJsonEncode($parameters);
            $parameters_str = " " . MPCEShortcode::$attributes['parameters'] . "='" . $jsonParameters . "'";
        }
        //set styles
        $styles = array();
        if (!empty(MPCEShortcode::$styles)) {
            foreach (MPCEShortcode::$styles as $name => $value) {
                if (array_key_exists($name, $atts)) {
                    //$value = $atts[$name];
                    //$styles[$name]['value'] = str_replace(array('\'', '"'), array('&#039;', '&quot;'), $value);
                    $value = preg_replace('#^<\\/p>|^<br \\/>|<p>$#', '', $atts[$name]);
                    $styles[$name]['value'] = htmlentities($value, ENT_QUOTES, 'UTF-8');
                } else {
                    $styles[$name] = new stdClass();
                }
            }
            $jsonStyles = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($styles, JSON_UNESCAPED_UNICODE) : motopressCEJsonEncode($styles);
            $styles_str = " " . MPCEShortcode::$attributes['styles'] . "='" . $jsonStyles . "'";
        }
        // set close-type of shortcode
        if (preg_match('/\\[\\/' . $matches[2] . '\\]$/', $matches[0]) === 1) {
            $endstr = '[/' . $matches[2] . ']';
            $closeType = MPCEObject::ENCLOSED;
        } else {
            $endstr = '';
            $closeType = MPCEObject::SELF_CLOSED;
        }
        //wrap custom code
        if (!preg_match($regex, $matches[5]) && $matches[5] !== '' && $matches[5] !== '&nbsp;' && in_array($matches[2], array('mp_row', 'mp_row_inner', 'mp_span', 'mp_span_inner'))) {
            $matches[5] = motopressCEWrapCustomCode($matches[5]);
        }
        // set system marking for "must-unwrap" code
        if ($matches[2] == 'mp_code') {
            if (!empty($matches[3])) {
                $atts = shortcode_parse_atts($matches[3]);
                if ($atts['unwrap'] === 'true') {
                    $unwrap = ' ' . MPCEShortcode::$attributes['unwrap'] . ' = "true"';
                }
            }
        }
        $dataContent = '';
        //setting data-motopress-content for all objects except layout
        if (!in_array($matches[2], array('mp_row', 'mp_row_inner', 'mp_span', 'mp_span_inner'))) {
            $dataContent = motopressCEScreeningDataAttrShortcodes($matches[5]);
        }
        return '<div ' . MPCEShortcode::$attributes['closeType'] . '="' . $closeType . '" ' . MPCEShortcode::$attributes['shortcode'] . '="' . $matches[2] . '" ' . MPCEShortcode::$attributes['group'] . '="' . $group . '"' . $parameters_str . $styles_str . ' ' . MPCEShortcode::$attributes['content'] . '="' . htmlentities($dataContent, ENT_QUOTES, 'UTF-8') . '" ' . $unwrap . '>[' . $matches[2] . $matches[3] . ']' . preg_replace_callback($regex, 'motopressCEParseObjectsRecursive', $matches[5]) . $endstr . '</div>';
    }
    return preg_replace_callback($regex, 'motopressCEParseObjectsRecursive', $matches);
}