예제 #1
0
 function parse_shortcode()
 {
     $this->check_nonce();
     $this->init_page();
     // added for some plugins to make LE a page
     global $wp_query;
     $wp_query->is_page = true;
     // end
     define('OP_AJAX_SHORTCODE', true);
     $GLOBALS['OP_LIVEEDITOR_DEPTH'] = isset($_POST['depth']) && $_POST['depth'] == 1 ? 1 : 0;
     $GLOBALS['OP_ADD_ELEMENT_ROWS'] = false;
     $GLOBALS['OP_LIVEEDITOR_FONT_STR'] = array();
     $GLOBALS['OP_LIVEEDITOR_DISABLE_NEW'] = false;
     //$GLOBALS['OP_DONE_TOP_LEVEL'] = false;
     require_once OP_ASSETS . 'live_editor.php';
     $sc = isset($_POST['shortcode']) ? $_POST['shortcode'] : $_GET['shortcode'];
     $sc = op_fix_embed_url_shortcodes(stripslashes($sc));
     // Popup needs to be handled differently
     $op_popup_present = false;
     // removing new line before shortcode entered in content
     $sc = str_replace(array("\n[", "\r[", "\r\n[", "\n\r["), array("[", "[", "[", "["), $sc);
     if (strpos($sc, '[op_popup ') !== false || strpos($sc, '[op_popup_elements]') !== false) {
         $op_popup_present = true;
     }
     // if ( strpos($sc, '[op_popup_button]') !== false && strpos($sc, '[op_popup ') === false) {
     //     if ( strpos($sc, '[op_popup_elements]') === false ) {
     //         $op_popup_present = true;
     //     } else {
     //         $sc = str_replace('[op_popup_elements]', '', $sc);
     //         $sc = str_replace('[/op_popup_elements]', '', $sc);
     //     }
     // } else {
     //     $sc = str_replace('[op_popup_elements]', '', $sc);
     //     $sc = str_replace('[/op_popup_elements]', '', $sc);
     // }
     if (preg_match('/' . op_shortcode_regex('op_liveeditor_elements') . '/s', $sc, $matches) || $op_popup_present) {
         if ($GLOBALS['OP_LIVEEDITOR_DEPTH'] === 1) {
             // EDIT ELEMENT
             $GLOBALS['OP_ADD_ELEMENT_ROWS'] = true;
             if (!$op_popup_present) {
                 $processed = op_process_content_filter($sc, true);
             }
             if ($op_popup_present) {
                 // [op_popup_elements] shortcode is present here
                 $new_popup_elements = '';
                 preg_match_all('/\\[op_popup_content_element[ d|\\]].*?\\[\\/op_popup_content_element\\]/is', $sc, $popup_elements);
                 foreach ($popup_elements[0] as $popup_element) {
                     $popup_element_sc = $popup_element;
                     $popup_element = str_replace('[op_popup_content_element]', '[op_liveeditor_element][op_popup_content_element]', $popup_element);
                     $popup_element = str_replace('[/op_popup_content_element]', '[/op_popup_content_element][/op_liveeditor_element]', $popup_element);
                     $popup_element = op_process_content_filter('[op_liveeditor_elements]' . $popup_element . '[/op_liveeditor_elements]', true);
                     $popup_element = str_replace('###OP_POPUP_CONTENT_CHILDREN###', $popup_element_sc, $popup_element);
                     $popup_element = str_replace('[op_popup_content_element]', '', $popup_element);
                     $popup_element = str_replace('[/op_popup_content_element]', '', $popup_element);
                     $new_popup_elements .= $popup_element;
                 }
                 $new_popup_elements = str_replace('$', '\\$', $new_popup_elements);
                 $processed = preg_replace('/\\[op_popup_elements[ d|\\]].*?\\[\\/op_popup_elements\\]/is', $new_popup_elements, $sc);
                 // $processed = str_replace('[op_popup_button]', '<div class="op-popup-button ' . $popup_button_class . '">', $processed);
                 // $processed = str_replace('[/op_popup_button]', '</div>', $processed);
                 $processed .= op_process_content_filter('[op_liveeditor_elements][/op_liveeditor_elements]', true);
             }
             $processed = '<h1>' . __('Content LiveEditor', OP_SN) . '</h1><div class="epicbox-actual-content">' . $processed . '<a href="#add_element" class="add-new-element"><img src="' . OP_IMG . '/live_editor/add_new.png" alt="' . esc_attr__('Add Element', OP_SN) . '"><span>' . __('Add Element', OP_SN) . '</span></a></div><div class="op-insert-button cf"><button type="submit" class="editor-button"><span>' . __('Update', OP_SN) . '</span></button></div>';
             if ($op_popup_present) {
                 $processed .= '<div class="op-hidden op_popup_element_present"><textarea class="op-le-child-shortcode" name="shortcode[]">' . $sc . '</textarea></div>';
             }
         } else {
             // UPDATE ELEMENT
             $GLOBALS['OP_LIVEEDITOR_DISABLE_NEW'] = true;
             $child_data = op_page_parse_child_elements($matches[0]);
             $processed = do_shortcode(str_replace($matches[0], '#OP_CHILD_ELEMENTS#', $sc));
             $GLOBALS['OP_LIVEEDITOR_DEPTH'] = 1;
             $child_html = '';
             $child_element_nr = 0;
             preg_match_all('/(<div class="row.*>)(.*)\\[\\/op_liveeditor_element\\]/isU', $child_data['liveeditorElements'], $child_rows_result);
             foreach ($child_rows_result[2] as $result_row) {
                 $result_row = $result_row . '[/op_liveeditor_element]';
                 $child_html .= $child_rows_result[1][$child_element_nr] . op_process_content_filter($result_row, true) . '</div>';
                 $child_element_nr += 1;
             }
             // preg_match_all('/(<div class="row.*>)(.*)<\/div>/isU', $child_data['liveeditorElements'], $child_rows_result);
             // foreach($child_rows_result[2] as $result_row) {
             //     $child_html .= $child_rows_result[1][$child_element_nr] . op_process_content_filter($result_row) . '</div>';
             //     $child_element_nr += 1;
             // }
             /**
              * At the end of child elements "add element" button must
              * be inserted, which is done by parsing [op_liveeditor_elements] shortcode
              */
             $child_html .= op_process_content_filter('[op_liveeditor_elements][/op_liveeditor_elements]', true);
             $child_html = op_process_asset_content($child_html) . '<div class="op-hidden"><textarea class="op-le-child-shortcode" name="shortcode[]">' . op_attr(shortcode_unautop($matches[0])) . '</textarea></div>';
             /*
              * $ needs to be escaped
              */
             $child_html = str_replace('$', '\\$', $child_html);
             $processed = preg_replace(array('{<p[^>]*>\\s*#OP_CHILD_ELEMENTS#\\s*<\\/p>}i', '{#OP_CHILD_ELEMENTS#}i'), $child_html, $processed);
             if ($op_popup_present) {
                 $new_popup_elements = '';
                 $new_popup_elements_sc = '';
                 // Parse op_popup_content
                 preg_match_all('/\\[op_popup_content_element[ d|\\]].*?\\[\\/op_popup_content_element\\]/is', $sc, $popup_elements);
                 foreach ($popup_elements[0] as $popup_element) {
                     $new_popup_elements_sc .= $popup_element;
                     $popup_element = str_replace('[op_popup_content_element]', '[op_liveeditor_element]', $popup_element);
                     $popup_element = str_replace('[/op_popup_content_element]', '[/op_liveeditor_element]', $popup_element);
                     $popup_element = op_process_content_filter($popup_element, true);
                     $new_popup_elements .= $popup_element;
                 }
                 $new_popup_elements = '<div class="op-popup-content">' . $new_popup_elements . '</div>';
                 $new_popup_elements .= op_process_content_filter('[op_liveeditor_elements][/op_liveeditor_elements]', true);
                 $new_popup_elements = str_replace('$', '\\$', $new_popup_elements);
                 $processed = preg_replace('/\\[op_popup_content[ d|\\]].*?\\[\\/op_popup_content\\]/is', $new_popup_elements, $sc);
                 // Parse op_popup_button
                 preg_match_all('/\\[op_popup_button\\].*?\\[\\/op_popup_button\\]/is', str_replace('$', '\\$', $sc), $new_popup_button);
                 $new_popup_button = $new_popup_button[0][0];
                 $new_popup_button = str_replace('[op_popup_button]', '', $new_popup_button);
                 $new_popup_button = str_replace('[/op_popup_button]', '', $new_popup_button);
                 $new_popup_button = op_process_content_filter($new_popup_button, true);
                 $new_popup_button = '<div class="op-popup-button ' . $popup_button_class . '">' . $new_popup_button . '</div>';
                 $processed = op_process_content_filter($processed, true);
                 $new_popup_button = str_replace('$', '\\$', $new_popup_button);
                 $processed = preg_replace('/\\[op_popup_button\\].*?\\[\\/op_popup_button\\]/is', $new_popup_button, $processed);
                 // $processed = str_replace('[op_popup_button]', '<div class="op-popup-button ' . $popup_button_class . '">', $processed);
                 // $processed = str_replace('[/op_popup_button]', '</div>', $processed);
                 $processed .= '<div class="op-hidden op_popup_element_present"><textarea class="op-le-child-shortcode" name="shortcode[]">' . op_attr(shortcode_unautop('[op_popup_elements]' . $new_popup_elements_sc . '[/op_popup_elements]')) . '</textarea></div>';
             }
         }
     } else {
         // $processed = apply_filters('the_content', $sc);
         $processed = op_process_content_filter($sc, true);
     }
     $output = array('output' => $processed, 'js' => OptimizePress_Default_Assets::_print_front_scripts(true), 'check' => OptimizePress_Default_Assets::_check_function(), 'font' => OptimizePress_Default_Assets::_get_font());
     if (isset($GLOBALS['OP_PARSED_SHORTCODE']) && !empty($GLOBALS['OP_PARSED_SHORTCODE'])) {
         $output['shortcode'] = $GLOBALS['OP_PARSED_SHORTCODE'];
     }
     echo json_encode($output);
     exit;
 }
예제 #2
0
    function parse_shortcode()
    {
        $this->check_nonce();
        $this->init_page();
        define('OP_AJAX_SHORTCODE', true);
        $GLOBALS['OP_LIVEEDITOR_DEPTH'] = isset($_POST['depth']) && $_POST['depth'] == 1 ? 1 : 0;
        $GLOBALS['OP_ADD_ELEMENT_ROWS'] = false;
        $GLOBALS['OP_LIVEEDITOR_FONT_STR'] = array();
        $GLOBALS['OP_LIVEEDITOR_DISABLE_NEW'] = false;
        //$GLOBALS['OP_DONE_TOP_LEVEL'] = false;
        require_once OP_ASSETS . 'live_editor.php';
        $sc = isset($_POST['shortcode']) ? $_POST['shortcode'] : $_GET['shortcode'];
        $sc = op_fix_embed_url_shortcodes(stripslashes($sc));
        if (preg_match('/' . op_shortcode_regex('op_liveeditor_elements') . '/s', $sc, $matches)) {
            if ($GLOBALS['OP_LIVEEDITOR_DEPTH'] === 1) {
                $GLOBALS['OP_ADD_ELEMENT_ROWS'] = true;
                $processed = apply_filters('the_content', $sc);
                $processed = '<h1>' . __('Content LiveEditor', OP_SN) . '</h1><div class="epicbox-actual-content">' . $processed . '<a href="#add_element" class="add-new-element"><img src="' . OP_IMG . '/live_editor/add_new.png" alt="' . __('Add Element', OP_SN) . '"><span>' . __('Add Element', OP_SN) . '</span></a></div>
			<div class="op-insert-button cf">
            	<button type="submit" class="editor-button"><span>' . __('Update', OP_SN) . '</span></button>
            </div>';
            } else {
                $GLOBALS['OP_LIVEEDITOR_DISABLE_NEW'] = true;
                $processed = do_shortcode(str_replace($matches[0], '#OP_CHILD_ELEMENTS#', $sc));
                $GLOBALS['OP_LIVEEDITOR_DEPTH'] = 1;
                $child_html = op_process_asset_content(apply_filters('the_content', $matches[0])) . '<div class="op-hidden"><textarea class="op-le-child-shortcode" name="shortcode[]">' . op_attr(shortcode_unautop($matches[0])) . '</textarea></div>';
                $child_html = str_replace('$', '&#36;', $child_html);
                $processed = preg_replace(array('{<p[^>]*>\\s*#OP_CHILD_ELEMENTS#\\s*<\\/p>}i', '{#OP_CHILD_ELEMENTS#}i'), $child_html, $processed);
                //die($processed);
            }
        } else {
            $processed = apply_filters('the_content', $sc);
        }
        $output = array('output' => $processed, 'js' => OptimizePress_Default_Assets::_print_front_scripts(true), 'check' => OptimizePress_Default_Assets::_check_function());
        if (isset($GLOBALS['OP_PARSED_SHORTCODE']) && !empty($GLOBALS['OP_PARSED_SHORTCODE'])) {
            $output['shortcode'] = $GLOBALS['OP_PARSED_SHORTCODE'];
        }
        echo json_encode($output);
        exit;
    }