Example #1
0
function st_builder_meta_items($name = '', $values = array(), $post = false)
{
    $builder_items = get_page_builder_items();
    $builder_save = $values['builder'];
    if (empty($builder_save) || !is_array($builder_save)) {
        $builder_save = array();
    }
    $builder_name = $name . '[builder]';
    $pd_item_width = array('1_1' => 0, '3_4' => 1, '2_3' => 2, '1_2' => 3, '1_3' => 4, '1_4' => 5);
    ?>
       <div class="stpb_pd_w">
       
       <?php 
    // do not show page builder items  beacase it can not run in shop pages
    if (strtolower($post->post_type) == 'page' && !(get_option('woocommerce_shop_page_id') == $post->ID && $post->ID > 0 && st_is_woocommerce())) {
        ?>
       
       <div class="stbuilder">
             <input type="hidden"  class="builder_pre_name" value="<?php 
        echo $builder_name;
        ?>
" />
            <div class="stbuilder-items">
                <h4 class="sttitle"><?php 
        _e('Add Items', 'smooththemes');
        ?>
</h4>
                <p class="stdesc" ><?php 
        _e('Click "add" to add item to Canvas', 'smooththemes');
        ?>
</p>
                <div class="notifications">
                    <span class="n success"><?php 
        _e("Item Added", 'smooththemes');
        ?>
</span>
                    <span class="n warning"><?php 
        _e("Item removed", 'smooththemes');
        ?>
</span>
                </div>
                <div class="clear"></div>
                <div class="stbuilder-o-items">
                    
                    <?php 
        foreach ($builder_items as $function => $item) {
            ?>
                    <div class="bd-item">
                        <div class="add-btn">
                            <span class="n"><?php 
            echo esc_html($item['title']);
            ?>
</span>
                            <a href="#" class="act-add"><?php 
            echo _e('Add', 'smooththemes');
            ?>
</a>
                        </div><!-- add-btn -->
                        
                        <div class="item-js-options">
                      <?php 
            $w = $item['default_with'];
            if ($w == '') {
                $w = '1_1';
            }
            ?>
                            
                        <div class="obj-item  col_<?php 
            echo $w;
            ?>
" numc="<?php 
            echo $pd_item_width[$w];
            ?>
">
                        <div class="obj-item-inner">
                                    <input type="hidden"  class="group-name builder-with"  group-name="[pbwith]" value="<?php 
            echo $w;
            ?>
" />
                                   <?php 
            if (!$item['block']) {
                ?>
                                    <span class="up">+</span>
                                    <span class="down">-</span>
                                    <?php 
            }
            ?>
                                    <span class="with-info"><?php 
            echo str_replace('_', '/', $w);
            ?>
</span>
                                    <?php 
            if ($item['editable'] !== false) {
                ?>
                                    <span class="pbedit" title="<?php 
                _e('Click here to edit', 'smooththemes');
                ?>
">Edit</span>
                                    <?php 
            }
            ?>
                                    <span class="pbremove" title="<?php 
            _e('Remove', 'smooththemes');
            ?>
"></span>
                                    
                                     <div class="t"><div><?php 
            echo esc_html($item['title']);
            ?>
</div></div>
                             
                                 <div class="obj-js-edit">
                                    <?php 
            if (function_exists($function)) {
                call_user_func($function, $function);
            }
            ?>
                                    
                                    <div class="pb-btns">
                                         <input type="button" value="<?php 
            _e('Save', 'smooththemes');
            ?>
" class="pbdone pbbtn button-primary" />
                                         <input type="button" value="<?php 
            _e('Cancel', 'smooththemes');
            ?>
" class="pbcancel pbbtn button-secondary" />
                                    </div>
                                 </div><!-- obj-js-edit -->
                            </div>
                                
                         </div><!--  /.obj-item  -->

                        </div><!-- item-js-options -->  
                    </div><!-- bd-item -->
                    <?php 
        }
        ?>
                    
                    <div class="clear"></div>
                </div><!-- stbuilder-o-items -->
            </div><!-- stbuilder-items -->
            
            <div class="stbuilder-area-wprap">
            <div class="stbuilder-edit-box" style="display: none;">
            
            </div><!-- stbuilder-edit-box --->
            
            <div class="stbuilder-area row-fluid sortable">
                 <?php 
        foreach ($builder_save as $i => $item) {
            $func = $builder_items[$item['function']];
            $w = $item['pbwith'];
            if ($w == '') {
                $w = '1_1';
            }
            ?>
                 
                 <div class="obj-item  col_<?php 
            echo $w;
            ?>
" numc="<?php 
            echo $pd_item_width[$w];
            ?>
">
                        <div class="obj-item-inner">
                                    <input type="hidden"  class="group-name builder-with"  group-name="[pbwith]" value="<?php 
            echo $w;
            ?>
" />
                                     <?php 
            if (!$func['block']) {
                ?>
                                    <span class="up">+</span>
                                    <span class="down">-</span>
                                    <?php 
            }
            ?>
                                    <span class="with-info"><?php 
            echo str_replace('_', '/', $w);
            ?>
</span>
                                   <?php 
            if ($func['editable'] !== false) {
                ?>
                                    <span class="pbedit" title="<?php 
                _e('Click here to edit', 'smooththemes');
                ?>
">Edit</span>
                                    <?php 
            }
            ?>
                                    <span class="pbremove" title="<?php 
            _e('Remove', 'smooththemes');
            ?>
"></span>
                                     <div class="t"><div><?php 
            echo esc_html($func['title']);
            ?>
</div></div>
                             
                                 <div class="obj-js-edit">
                                    <?php 
            if (function_exists($item['function'])) {
                call_user_func($item['function'], $item['function'], $builder_name, $item);
            }
            ?>
                                    <div class="pb-btns">
                                         <input type="button" value="<?php 
            _e('Save', 'smooththemes');
            ?>
" class="pbdone pbbtn button-primary" />
                                         <input type="button" value="<?php 
            _e('Cancel', 'smooththemes');
            ?>
" class="pbcancel pbbtn button-secondary" />
                                    </div>
                                 </div><!-- obj-js-edit -->
                            </div>
                                
                    </div><!--  /.obj-item  -->

                  <?php 
        }
        ?>
                
            </div><!-- stbuilder-area -->
            </div>
       
       </div><!-- stbuilder -->
       
       <div class="stdive"></div>
       
       <?php 
    }
    ?>
    
    <?php 
}
Example #2
0
    return $class;
}
//  add meta post to post type
add_action('admin_init', 'st_add_support_page_builder', 9, 2);
// Save data froms t_save_page_builder
function st_save_page_builder($post_id)
{
    global $meta_box, $smooththemes_sidebar;
    // verify nonce
    if (!wp_verify_nonce($_POST['st_page_builder_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    $meta_name = '_st_page_builder';
    // save post meta to each box
    $old = get_post_meta($post_id, $meta_name, true);
    $new = $_POST[$meta_name];
    //  $new = apply_filters('st_page_builder_save',$new, $post_id);
    do_action('st_before_page_builder_save', $post_id, $_POST[$meta_name]);
    if (!is_array($new)) {
        $new = (array) $new;
    }
    $str_new = $new;
    $str_new = maybe_serialize($str_new);
    // echo var_dump($new,$str_new); die();
    $str_new = base64_encode($str_new);
    $cache_key = '_st_page_builder_' . $post_id;
    wp_cache_delete($cache_key);
    // remove cache
    update_post_meta($post_id, '_st_page_builder', $str_new);
    do_action('st_after_page_builder_save', $post_id, $_POST[$meta_name]);
    $layout = $new['layout'];
    // save  as a string shortcode
    $builder = $new['builder'];
    if (empty($builder)) {
        $builder = array();
    }
    $rows = array();
    $ri = $i = 0;
    $n = count($builder);
    // $tmp_builder=  $builder;
    while ($i < $n) {
        $wc = $builder[$i]['pbwith'];
        $w = explode('_', $wc);
        $t = intval($w[0]);
        $m = intval($w[1]);
        if ($m > 0 and $t > 0) {
            $c = $t / $m;
        } else {
            $c = 1;
        }
        if ($rows[$ri]['total'] + $c <= 1) {
            $rows[$ri]['total'] += $c;
            $rows[$ri]['cols'][] = $builder[$i];
        } else {
            $ri++;
            $rows[$ri]['total'] += $c;
            $rows[$ri]['cols'][] = $builder[$i];
        }
        $i++;
    }
    // end while
    $string_shortcode = array();
    $builder_items = get_page_builder_items();
    // generate code to display: maybe html or shortcode
    $nr = count($rows);
    $i = 1;
    $row_index = 1;
    foreach ($rows as $row) {
        $rc = ' r-index-' . $row_index;
        $i++;
        $format = "<div class=\"row{$rc}\">\n" . '%1$s' . "\n</div>";
        $str_cols = array();
        foreach ($row['cols'] as $data) {
            $data['site_layout'] = $data['data']['site_layout'] = $layout;
            $data['row_index'] = $data['data']['row_index'] = $row_index;
            $item = $builder_items[$data['function']];
            // $r_functions[$data['function']] = $data['function'];
            if (function_exists($item['generate_func'])) {
                $str_cols[] = "\t<div class=\"" . stpb_column_class($data['pbwith']) . ' ' . $data['function'] . "\">" . call_user_func($item['generate_func'], $data) . "</div>";
            } else {
                $str_cols[] = "\t<div class=\"" . stpb_column_class($data['pbwith']) . "\"> </div>";
            }
        }
        $str_cols = join("\n", $str_cols);
        $str_cols .= '<div class="clear"></div>';
        $string_shortcode[] = sprintf($format, $str_cols);
        $row_index++;
    }
    $string_shortcode = join("\n", $string_shortcode);
    if ($string_shortcode != '') {