Exemple #1
0
function mg_add_item_to_builder()
{
    include_once MG_DIR . '/functions.php';
    $tt_path = MG_TT_URL;
    if (!isset($_POST['item_id'])) {
        die('data is missing');
    }
    $item_id = addslashes($_POST['item_id']);
    $mobile_mode = isset($_POST['mg_mobile']) && $_POST['mg_mobile'] ? true : false;
    $items_data = mg_grid_builder_items_data(array($item_id));
    foreach ($items_data as $item) {
        $w_sizes = mg_sizes();
        $h_sizes = mg_sizes();
        $mw_sizes = mg_mobile_sizes();
        $mh_sizes = mg_mobile_sizes();
        $item_w = '1_4';
        $item_h = '1_4';
        $mobile_w = '1_2';
        $mobile_h = '1_3';
        // add height == auto if type != inline slider or inline video
        if (!in_array($item['type'], array('inl_slider', 'inl_video', 'spacer'))) {
            $h_sizes[] = 'auto';
            $mh_sizes[] = 'auto';
        }
        // featured image
        $img_id = get_post_thumbnail_id($item_id);
        // item thumb
        if (in_array($item['type'], array('inl_slider', 'inl_video', 'inl_text', 'spacer'))) {
            $item_thumb = '<img src="' . MG_URL . '/img/type_icons/' . $item['type'] . '.png" height="19" width="19" class="thumb" alt="" />';
        } else {
            $item_thumb = '<img src="' . mg_thumb_src($img_id, 19, 19) . '" class="thumb" alt="" />';
        }
        // size classes
        $w_class = $mobile_mode ? $mobile_w : $item_w;
        $h_class = $mobile_mode ? $mobile_h : $item_h;
        // item type
        $item_type = get_post_type($item['id']) == 'product' ? 'WooCommerce' : mg_item_types($item['type']);
        echo '
		<li class="mg_box mg_' . $item['type'] . '_type col' . $w_class . ' row' . $h_class . '" id="box_' . mt_rand() . $item['id'] . '" mg-width="' . $item_w . '" mg-height="' . $item_h . '"  mg-m-width="' . $mobile_w . '" mg-m-height="' . $mobile_h . '">
		  <input type="hidden" name="grid_items[]" value="' . $item['id'] . '" />
		  <div class="handler" id="boxlabel" name="' . $item['id'] . '">
		  	  <div class="del_item"></div>
			  <a href="' . get_admin_url() . 'post.php?post=' . $item['id'] . '&action=edit" class="edit_item" target="_blank" title="' . __('edit item', 'mg_ml') . '"></a>
			  <h3>
			    ' . $item_thumb . '
			  	' . strip_tags($item['title']) . '
			  </h3>
			  <p style="padding-top: 6px;">' . $item_type . '</p>
			  <p class="mg_builder_standard_sizes">';
        // choose the width
        echo __('Width', 'mg_ml') . ' <select name="items_w[]" value="" class="select_w mg_items_sizes_dd">';
        foreach ($w_sizes as $size) {
            $size == $item_w ? $sel = 'selected="selected"' : ($sel = '');
            echo '<option value="' . $size . '" ' . $sel . '>' . str_replace('_', '/', $size) . '</option>';
        }
        echo '</select> <br/>  ' . __('Height', 'mg_ml') . ' <select class="select_h mg_items_sizes_dd">';
        foreach ($h_sizes as $size) {
            $size == $item_h ? $sel = 'selected="selected"' : ($sel = '');
            echo '<option value="' . $size . '" ' . $sel . '>' . str_replace('_', '/', $size) . '</option>';
        }
        echo '</select></p>
			  <p class="mg_builder_mobile_sizes">';
        echo __('Width', 'mg_ml') . ' <select name="items_w[]" value="" class="select_m_w mg_items_sizes_dd">';
        foreach ($mw_sizes as $size) {
            $size == $mobile_w ? $sel = 'selected="selected"' : ($sel = '');
            echo '<option value="' . $size . '" ' . $sel . '>' . str_replace('_', '/', $size) . '</option>';
        }
        echo '</select> <br/>  ' . __('Height', 'mg_ml') . ' <select class="select_m_h mg_items_sizes_dd">';
        foreach ($mh_sizes as $size) {
            $size == $mobile_h ? $sel = 'selected="selected"' : ($sel = '');
            echo '<option value="' . $size . '" ' . $sel . '>' . str_replace('_', '/', $size) . '</option>';
        }
        echo '</select></p>
	  
		  </div>
		</li>';
    }
    die;
}
function mg_update_grids_location()
{
    if (!get_option('mg_v3_update')) {
        include_once MG_DIR . '/functions.php';
        $grids = get_terms('mg_grids', 'hide_empty=0');
        foreach ($grids as $grid) {
            $items = get_option('mg_grid_' . $grid->term_id . '_items');
            $w = get_option('mg_grid_' . $grid->term_id . '_items_width');
            $h = get_option('mg_grid_' . $grid->term_id . '_items_height');
            $cats = get_option('mg_grid_' . $grid->term_id . '_cats');
            // create description array
            $arr = array('items' => array(), 'cats' => $cats);
            if (is_array($items)) {
                for ($a = 0; $a < count($items); $a++) {
                    if (!$w) {
                        $cell_w = get_post_meta($items[$a], 'mg_width', true);
                        $cell_h = get_post_meta($items[$a], 'mg_height', true);
                    } else {
                        $cell_w = $w[$a];
                        $cell_h = $h[$a];
                    }
                    $arr['items'][] = array('id' => $items[$a], 'w' => $cell_w, 'h' => $cell_h, 'm_w' => in_array($cell_w, mg_mobile_sizes()) ? $cell_w : '1_2', 'm_h' => in_array($cell_h, mg_mobile_sizes()) || $cell_h == 'auto' ? $cell_h : '1_3');
                }
            }
            wp_update_term($grid->term_id, 'mg_grids', array('description' => serialize($arr)));
        }
        update_option('mg_v3_update', 1);
    }
}