?> <div class="panel" id="tab-gallery"> <?php $thumb_id = get_post_thumbnail_id(); $small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail'); $args = array('post_type' => 'attachment', 'numberposts' => 3, 'post_status' => null, 'post_parent' => $post->ID, 'post__not_in' => array($thumb_id), 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC'); $attachments = get_posts($args); if ($attachments) { echo '<div id="foo" class="product-gallery-thumbnail">' . "\n"; foreach ($attachments as $attachment) { if (get_post_meta($attachment->ID, '_woocommerce_exclude_image', true) == 1) { continue; } $_post =& get_post($attachment->ID); $url = wp_get_attachment_url($_post->ID); $path = get_attached_file($_post->ID); $post_title = esc_attr($_post->post_title); if (file_exists($path)) { $image = wip_resize($path, $url, 80, 80, true); echo '<a href="' . $url . '" title="' . $post_title . '" rel="thumbnails" class="zoom" style="margin-left:15px">'; echo '<img src="' . $image['url'] . '" alt="' . $post_title . '"/></a>'; } } echo '</div>' . "\n"; } else { print '<p class="no_gallery"><em>' . __('No Galleries', 'wip') . '</em></p>'; } ?> </div> </div>
function upload_portfolio($id, $label, $desc = "") { global $post; $value = get_post_meta($post->ID, $id, true); $isThere = false; $imgURL = ""; $video = ""; $portfolios = get_option('bd_portfolio_data'); if (!empty($portfolios)) { if (isset($portfolios[$value])) { foreach ($portfolios as $unique => $port) { if ($unique == $value) { if ($port['type'] == 'image') { if (isset($port['image']) && is_array($port['image'])) { $isThere = true; $uploadPath = wp_upload_dir(); $imageDir = $uploadPath['basedir'] . $port['image']['subdir'] . '/' . $port['image']['image']; $imageUrl = $uploadPath['baseurl'] . $port['image']['subdir'] . '/' . $port['image']['image']; $theThumb = wip_resize($imageDir, $imageUrl, 215, 99999, false); $imgURL = $theThumb['url']; } } elseif ($port['type'] == 'video') { if ($port['video'] != "") { $isThere = true; $video = $port['video']; $vidType = typeOflink($video); } } } } } } ?> <div class="wip-meta-form" id="portfolio_o"> <span class="wip-label"><?php echo $label; ?> </span> <div class="p-preview"<?php if ($isThere) { echo ' style="display:block;"'; } else { echo ' style="display:none;"'; } ?> > <?php if ($imgURL != "") { echo '<img src="' . $imgURL . '" alt="" /><a id="delete_portfolio" href="#" title="delete"></a>'; } ?> <?php if ($video != "") { echo WIPobjectPrint($video, $vidType, '215', '161', 'false') . '<a id="delete_portfolio" href="#" title="delete"></a>'; } ?> </div> <?php if ($desc != "") { ?> <div class="wip-desc"<?php if ($isThere) { echo ' style="display:none;"'; } else { echo ' style="display:block;"'; } ?> ><?php echo $desc; ?> </div><?php } ?> <div id="portfolio-bt-handle"<?php if ($isThere) { echo ' style="display:none;"'; } else { echo ' style="display:block;"'; } ?> > <div id="pp-wip-pp"> <input name="portfolio_button_upload" id="portfolio_button_upload" class="button-primary" type="button" value="<?php esc_attr_e('Select Image', 'wip'); ?> " /> <input type="hidden" name="portfolio_image_nonce" value="<?php echo wp_create_nonce('portfolio_image_nonce'); ?> " /> </div> <span class="or">- OR -</span> <input type="text" name="portfolio-video" id="portfolio-video" value="Enter video URL" onfocus="if (this.value == 'Enter video URL') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter video URL';}" /> <span class="upload_button insert_video">Insert Video</span> <div class="clear"></div> <div class="panel_file_progress"></div> </div> <input name="<?php echo $id; ?> " id="<?php echo $id; ?> " class="portfolio_id" type="hidden" value="<?php if ($value != "") { echo stripslashes($value); } else { echo ""; } ?> " /> <input name="thispostid" class="thispostid" type="hidden" value="<?php echo $post->ID; ?> " /> </div> <?php }
function WIP_slider_frameform($s) { $transt = array('easeInOutQuad', 'easeInOutCubic', 'easeInOutQuart', 'easeInOutQuint', 'easeInOutSine', 'easeInOutExpo', 'easeInOutCirc', 'easeInOutElastic', 'easeInOutBack', 'easeInOutBounce'); ?> <div id="main-slider-form"> <form method="post" action="" enctype="multipart/form-data" class="sliderajax"> <div class="wip-form" id="sliderslider"> <span class="slider-preview"> </span> <input name="<?php echo $s; ?> _slider_image" id="<?php echo $s; ?> _slider_image" class="main_upload_slider button" type="button" value="<?php print __('Select Image', 'wip'); ?> " /> <input type="hidden" name="wip_slider_image" class="main_form_slider" value="" /> <input type="hidden" name="wip_slider_image_name" class="main_form_slider_image_name" value="" /> <input type="hidden" name="wip_slider_image_path" class="main_form_slider_path" value="" /> <input type="hidden" name="wip_slider_image_sub_path" class="main_form_slider_sub_path" value="" /> <input type="hidden" name="main_slider_image_nonce" value="<?php echo wp_create_nonce('main_slider_image_nonce'); ?> " /> <div class="wip-clear"></div> <span class="wip-desc"><?php print __('fix size, 940px by the height of slider container (see Slider Settings tab)', 'wip'); ?> </span> <div class="panel_file_progress"></div> </div> <div class="wip_section_labelonOff"> <h2><span>[ + ]</span><?php print __('Piecemaker 2 Options'); ?> </h2> <div class="wip_labelonOff_jq" style="display:none;"> <div class="wip-form"> <span class="wip-label"><?php print __('.SWF OR video file URL (optional)', 'wip'); ?> </span> <input name="wip_slider_swf" id="wip_slider_swf" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('Please enter full URL, include the "http://"', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Title (required)', 'wip'); ?> </span> <input name="wip_slider_title" id="wip_slider_title" type="text" value="" /> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Pieces', 'wip'); ?> </span> <input name="wip_slider_pc_pieces" id="wip_slider_pc_pieces" type="text" value="9" /> <br/> <span class="wip-desc"><?php print __('Number of pieces to which the image is sliced', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Time', 'wip'); ?> </span> <input name="wip_slider_pc_time" id="wip_slider_pc_time" type="text" value="1.2" /> <br/> <span class="wip-desc"><?php print __('Time for one cube to turn, in second', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Transition', 'wip'); ?> </span> <select name="wip_slider_pc_transition" id="wip_slider_pc_transition"> <?php foreach ($transt as $t) { ?> <option value="<?php echo $t; ?> "><?php echo $t; ?> </option> <?php } ?> </select> <br/> <span class="wip-desc"><?php print __('Transition type', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Delay', 'wip'); ?> </span> <input name="wip_slider_pc_delay" id="wip_slider_pc_delay" type="text" value="0.1" /> <br/> <span class="wip-desc"><?php print __('Delay between the start of one cube to the start of the next cube', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Depth Offset', 'wip'); ?> </span> <input name="wip_slider_pc_depthoffset" id="wip_slider_pc_depthoffset" type="text" value="300" /> <br/> <span class="wip-desc"><?php print __('The offset during transition on the z-axis. Value between 100 and 1000', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Cube Distance', 'wip'); ?> </span> <input name="wip_slider_pc_cubedistance" id="wip_slider_pc_cubedistance" type="text" value="20" /> <br/> <span class="wip-desc"><?php print __('The distance between the cubes during transition. Values between 5 and 50', 'wip'); ?> </span> </div> </div> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Link URL (optional)', 'wip'); ?> </span> <input name="wip_slider_url" id="wip_slider_url" type="text" value="" /> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Description (optional)', 'wip'); ?> </span> <textarea name="wip_slider_desc" id="wip_slider_desc" rows="5" cols="30"></textarea> </div> <br/> <center> <input name="save" class="WIPanel-submit-section add_more_slider" type="submit" value="<?php print __('+ Add Slider Object', 'wip'); ?> " /> <input type="hidden" name="shortname" value="<?php echo $s; ?> " /> </center> <br/> </form> <div class="wip_section_label"><h4><?php print __('Below are slider images you have submited<br/>You can drag and drop the list below to re-order the slider object', 'wip'); ?> </h4></div> <br/> <div id="slider-lists-con"> <ul id="slider-lists"> <?php $get_slider_id = get_option($s . '_slider_id'); $get_slider_det = get_option($s . '_slider_det'); if (!empty($get_slider_id)) { foreach ($get_slider_id as $i => $ids) { $th = ""; $idk = ""; if (array_key_exists($ids, $get_slider_det)) { $idk = $ids; $detforthis = $get_slider_det[$ids]; $uploadPath = wp_upload_dir(); if (isset($detforthis['image'])) { $img_path = $uploadPath['basedir'] . $detforthis['image']['subdir'] . '/' . $detforthis['image']['file_name']; $img_url = $uploadPath['baseurl'] . $detforthis['image']['subdir'] . '/' . $detforthis['image']['file_name']; if (file_exists($img_path)) { $newThumb = wip_resize($img_path, $img_url, 50, 50, true); $th = $newThumb['url']; } } } ?> <li class="slider-data"> <span class="slider-data-in"> <span class="img-slid"><img src="<?php echo $th; ?> " alt="" /></span> <a href="#" class="slider-delete" title="delete"></a> <a href="#" class="slider-edit" title="edit"></a> <input type="hidden" name="_wip_slider_data[]" value="<?php echo $idk; ?> " /> </span> </li> <?php } } else { ?> <li class="no-slider"> <?php print __('No slider image', 'wip'); ?> </li> <?php } ?> </ul> </div> </div> <div id="slider-edit-form"> <form method="post" action="" enctype="multipart/form-data" class="sliderajaxedit"> <div class="wip-form" id="slideredit"> <span class="slider-preview-edit"><img class="slider_up_preview" src="" alt="" /></span> <input name="<?php echo $s; ?> _slider_image_edit" id="<?php echo $s; ?> _slider_image_edit" class="main_upload_slider_edit button" type="button" value="<?php print __('Select Image', 'wip'); ?> " /> <div class="wip-clear"></div> <span class="wip-desc"><?php print __('fix size, 940px by the height of slider container (see Slider Settings tab)<br/>note: once you have upload another image the current image will be deleted', 'wip'); ?> </span> <div class="panel_file_progress"></div> </div> <div class="wip_section_labelonOff"> <h2><span>[ + ]</span><?php print __('Piecemaker 2 Options'); ?> </h2> <div class="wip_labelonOff_jq" style="display:none;"> <div class="wip-form"> <span class="wip-label"><?php print __('.SWF OR video file URL (optional)', 'wip'); ?> </span> <input name="wip_slider_swf_edit" id="wip_slider_swf_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('Please enter full URL, include the "http://"', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Title (required)', 'wip'); ?> </span> <input name="wip_slider_title_edit" id="wip_slider_title_edit" type="text" value="" /> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Pieces', 'wip'); ?> </span> <input name="wip_slider_pc_pieces_edit" id="wip_slider_pc_pieces_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('Number of pieces to which the image is sliced', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Time', 'wip'); ?> </span> <input name="wip_slider_pc_time_edit" id="wip_slider_pc_time_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('Time for one cube to turn, in second', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Transition', 'wip'); ?> </span> <select name="wip_slider_pc_transition_edit" id="wip_slider_pc_transition_edit"> <?php foreach ($transt as $t) { ?> <option value="<?php echo $t; ?> "><?php echo $t; ?> </option> <?php } ?> </select> <br/> <span class="wip-desc"><?php print __('Transition type', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Delay', 'wip'); ?> </span> <input name="wip_slider_pc_delay_edit" id="wip_slider_pc_delay_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('Delay between the start of one cube to the start of the next cube', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Depth Offset', 'wip'); ?> </span> <input name="wip_slider_pc_depthoffset_edit" id="wip_slider_pc_depthoffset_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('The offset during transition on the z-axis. Value between 100 and 1000', 'wip'); ?> </span> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Cube Distance', 'wip'); ?> </span> <input name="wip_slider_pc_cubedistance_edit" id="wip_slider_pc_cubedistance_edit" type="text" value="" /> <br/> <span class="wip-desc"><?php print __('The distance between the cubes during transition. Values between 5 and 50', 'wip'); ?> </span> </div> </div> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Link URL (optional)', 'wip'); ?> </span> <input name="wip_slider_url_edit" id="wip_slider_url_edit" type="text" value="" /> </div> <div class="wip-form"> <span class="wip-label"><?php print __('Description (optional)', 'wip'); ?> </span> <textarea name="wip_slider_desc_edit" id="wip_slider_desc_edit" rows="5" cols="30"></textarea> </div><br/> <center> <input name="save" class="WIPanel-submit-section edit_the_slider" type="submit" value="Update" /> <input name="cancel" id="cancel_slider-edit" class="WIPanel-submit-section" type="reset" value="cancel" /> <input type="hidden" name="editid" id="editid" value="" /> </center> </form> <p> </p> </div> <?php }
function wip_print_autoresize($path, $url, $width, $height, $return_array = false, $default = "") { if (!file_exists($path)) { return $default; } if ($height < 9999) { $imageURL = wip_resize($path, $url, $width, $height, true); } else { $imageURL = wip_resize($path, $url, $width, $height, false); } if (!$return_array) { if (isset($imageURL['url']) && $imageURL['url'] != "") { return $imageURL['url']; } } else { $iURL = isset($imageURL['url']) && $imageURL['url'] != "" ? $imageURL['url'] : ''; $iPath = isset($imageURL['path']) && $imageURL['path'] != "" ? $imageURL['path'] : ''; $ireturn = array('url' => $iURL, 'path' => $iPath); return $ireturn; } return $default; }
function WIPanel_ajax_slider_callback() { global $wpdb; #check the type of form if (isset($_POST['type'])) { $save_type = $_POST['type']; } else { $save_type = null; } #upload new slider image if ($save_type == 'upload') { check_ajax_referer('main_slider_image_nonce'); #grab the data $clickedID = 'main_slider_image_action'; $arr_file_type = wp_check_filetype(basename($_FILES[$clickedID]['name'])); $uploaded_file_type = $arr_file_type['type']; # Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/x-icon'); # if data is an image - upload it if (in_array($uploaded_file_type, $allowed_file_types)) { # override the upload process, WordPress need to detect 'wp_handle_upload' before upload the doc $filename = $_FILES[$clickedID]; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; # upload process... $uploaded_file = wp_handle_upload($filename, $override); $upload_tracking[] = $clickedID; if (isset($uploaded_file['error'])) { $returnError = array("error" => true, "errorText" => $uploaded_file['error']); echo json_encode($returnError); die; } $path_info = wp_upload_dir(); $file_info = pathinfo($uploaded_file['file']); $image_filename = $file_info['filename'] . '.' . $file_info['extension']; $image_url = $uploaded_file['url']; $subdir = $path_info['subdir']; $returnData = array("error" => false, "imgUrl" => $image_url, "path" => $uploaded_file['file'], "subPath" => $subdir, "imageFilename" => $image_filename); echo json_encode($returnData); die; } else { #if error $uploaded_file['error'] = __('Unsupported file type!', 'wip'); } $errorNew = ""; if (!empty($uploaded_file['error'])) { $errorNew = sprintf(__('Upload Error: %1$s', 'wip'), $uploaded_file['error']); } $returnData = array("error" => true, "errorText" => $errorNew); echo json_encode($returnData); die; } elseif ($save_type == 'image_reset') { #if user click "delete image" icon $image_path = ""; if (isset($_POST['data'])) { $image_path = $_POST['data']; if (file_exists($image_path)) { unlink($image_path); } } } elseif ($save_type == 'add_slider') { $p = array(); if (isset($_POST['data'])) { $data = $_POST['data']; #explode them to get each data, check http://php.net/manual/en/function.parse-str.php parse_str($data, $p); } $img = isset($p['wip_slider_image']) ? $p['wip_slider_image'] : ''; $img_name = isset($p['wip_slider_image_name']) ? $p['wip_slider_image_name'] : ''; $imgPath = isset($p['wip_slider_image_path']) ? $p['wip_slider_image_path'] : ''; $img_subdir = isset($p['wip_slider_image_sub_path']) ? $p['wip_slider_image_sub_path'] : ''; $image_det = array("file_name" => $img_name, "subdir" => $img_subdir); $link = esc_attr($p['wip_slider_url']); $desc = esc_textarea($p['wip_slider_desc']); /** get op for piecemaker */ $title = isset($p['wip_slider_title']) ? esc_attr($p['wip_slider_title']) : ''; $swf = isset($p['wip_slider_swf']) ? esc_attr($p['wip_slider_swf']) : ''; $pm_pieces = isset($p['wip_slider_pc_pieces']) ? $p['wip_slider_pc_pieces'] : ''; $pm_time = isset($p['wip_slider_pc_time']) ? $p['wip_slider_pc_time'] : ''; $pm_transition = isset($p['wip_slider_pc_transition']) ? $p['wip_slider_pc_transition'] : ''; $pm_delay = isset($p['wip_slider_pc_delay']) ? $p['wip_slider_pc_delay'] : ''; $pm_depthoffset = isset($p['wip_slider_pc_depthoffset']) ? $p['wip_slider_pc_depthoffset'] : ''; $pm_cubedistance = isset($p['wip_slider_pc_cubedistance']) ? $p['wip_slider_pc_cubedistance'] : ''; $piecemaker = array("title" => $title, "swf" => $swf, "pieces" => $pm_pieces, "time" => $pm_time, "transition" => $pm_transition, "delay" => $pm_delay, "depthoffset" => $pm_depthoffset, "cubedistance" => $pm_cubedistance); $sn = $p['shortname']; $err_r = ""; $error = false; if ($img == "") { $error = true; $err_r = __('Error : Please upload the image!', 'wip'); } $returnData = ""; if ($error) { $returnData = array("error" => true, "errorText" => $err_r); echo json_encode($returnData); die; } else { $newThumb = ""; $unique = intval(time()) . '-WIP-slider'; if (file_exists($imgPath)) { $newThumb = wip_resize($imgPath, $img, 50, 50, true); } $get_slider_id = get_option($sn . '_slider_id'); $get_slider_det = get_option($sn . '_slider_det'); $Sdata = array('id' => $unique, 'image' => $image_det, 'link' => $link, 'desc' => stripslashes($desc), 'piecemaker' => $piecemaker); $Sdata_id = $unique; if (is_array($get_slider_id)) { $dataInsID[] = $Sdata_id; $toInsID = array_merge((array) $get_slider_id, (array) $dataInsID); } else { $toInsID[] = $Sdata_id; } if (is_array($get_slider_det)) { $dataIns[$unique] = $Sdata; $toIns = $get_slider_det + $dataIns; } else { $toIns[$unique] = $Sdata; } update_option($sn . '_slider_det', $toIns); update_option($sn . '_slider_id', $toInsID); $returnData = array("error" => false, "thumb" => $newThumb['url'], "id" => $unique); wip_delete_site_trans(); echo json_encode($returnData); die; } } elseif ($save_type == 'slider_order') { if (isset($_POST['data'])) { $data = $_POST['data']; parse_str($data, $p); } $arrData = $p['dt']; $fns = $p['length']; $sn = $p['shortname']; $usef = ""; for ($i = 0; $i < $fns; $i++) { $usef .= $arrData[$i]; } $files = array(); if (is_array($arrData)) { foreach ($arrData as $k => $l) { if ($l != "") { $files[$l] = $l; } } } $fls = ""; if ($usef == "") { $fls = ""; } else { $fls = $files; } wip_delete_site_trans(); update_option($sn . '_slider_id', $fls); die; } elseif ($save_type == 'take_data') { if (isset($_POST['data'])) { $ids = $_POST['data']; } $get_slider_det = get_option('bd_slider_det'); $returnData = array(); if (!empty($get_slider_det)) { if (array_key_exists($ids, $get_slider_det)) { $taken = $get_slider_det[$ids]; $uploadPath = wp_upload_dir(); if (isset($taken['image'])) { $img_url = $uploadPath['baseurl'] . $taken['image']['subdir'] . '/' . $taken['image']['file_name']; } if (isset($taken['piecemaker'])) { $p = $taken['piecemaker']; $title = isset($p['title']) ? $p['title'] : ''; $swf = isset($p['swf']) ? $p['swf'] : ''; $pm_pieces = isset($p['pieces']) ? $p['pieces'] : ''; $pm_time = isset($p['time']) ? $p['time'] : ''; $pm_transition = isset($p['transition']) ? $p['transition'] : ''; $pm_delay = isset($p['delay']) ? $p['delay'] : ''; $pm_depthoffset = isset($p['depthoffset']) ? $p['depthoffset'] : ''; $pm_cubedistance = isset($p['cubedistance']) ? $p['cubedistance'] : ''; } $returnData = array("id" => $ids, "img" => $img_url, "title" => $title, "pm_swf" => $swf, "pm_pieces" => $pm_pieces, "pm_time" => $pm_time, "pm_transition" => $pm_transition, "pm_delay" => $pm_delay, "pm_depthoffset" => $pm_depthoffset, "pm_cubedistance" => $pm_cubedistance, "link" => $taken['link'], "desc" => $taken['desc']); } } echo json_encode($returnData); die; } elseif ($save_type == 'delete_slider') { if (isset($_POST['data'])) { $id = $_POST['data']; } $get_slider_id = get_option('bd_slider_id'); $get_slider_det = get_option('bd_slider_det'); $uploadPath = wp_upload_dir(); if (!empty($get_slider_det)) { if (array_key_exists($id, $get_slider_det)) { $dataToDelete = $get_slider_det[$id]; if (isset($dataToDelete['image'])) { $oldimage_path = $uploadPath['basedir'] . $dataToDelete['image']['subdir'] . '/' . $dataToDelete['image']['file_name']; $oldimg_url = $uploadPath['baseurl'] . $dataToDelete['image']['subdir'] . '/' . $dataToDelete['image']['file_name']; if (file_exists($oldimage_path)) { $oldThumb = wip_resize($oldimage_path, $oldimg_url, 50, 50, true); $oldthumbnail_path = $oldThumb['path']; unlink($oldimage_path); //delete old image if (file_exists($oldthumbnail_path)) { unlink($oldthumbnail_path); } //delete old thumbnail } } } } if (isset($get_slider_det[$id])) { unset($get_slider_det[$id]); $new_get_slider_det = $get_slider_det; update_option('bd_slider_det', $new_get_slider_det); } foreach ($get_slider_id as $f => $g) { if ($g == $id) { unset($get_slider_id[$f]); $new_get_slider_id = $get_slider_id; update_option('bd_slider_id', $new_get_slider_id); } } wip_delete_site_trans(); die; } elseif ($save_type == 'upload_edit') { check_ajax_referer('main_slider_image_nonce'); $returnData = ""; $imgData = isset($_FILES['image_edit']) ? true : false; $EditId = isset($_POST['sliderId']) ? $_POST['sliderId'] : ''; $error = false; if (!$imgData) { $error = true; } if ($EditId == "") { $error = true; } if ($error) { $returnData = array("error" => true, "errorText" => __('Image or edit id cannot be found!', 'wip')); echo json_encode($returnData); die; } else { $get_slider_det = get_option('bd_slider_det'); #grab the data $arr_file_type = wp_check_filetype(basename($_FILES['image_edit']['name'])); $uploaded_file_type = $arr_file_type['type']; # Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/x-icon'); # if data is an image - upload it if (in_array($uploaded_file_type, $allowed_file_types)) { # override the upload process, WordPress need to detect 'wp_handle_upload' before upload the doc $filename = $_FILES['image_edit']; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; # upload process... $uploaded_file = wp_handle_upload($filename, $override); $upload_tracking[] = 'image_edit'; #get upload path $uploadPath = wp_upload_dir(); $file_info = pathinfo($uploaded_file['file']); $image_filename = $file_info['filename'] . '.' . $file_info['extension']; $subdir = $uploadPath['subdir']; $newImg = $uploaded_file['url']; $newImgPath = $uploaded_file['file']; if (!empty($get_slider_det)) { if (array_key_exists($EditId, $get_slider_det)) { $dataToEdit = $get_slider_det[$EditId]; if (isset($dataToEdit['image'])) { $oldimage_path = $uploadPath['basedir'] . $dataToEdit['image']['subdir'] . '/' . $dataToEdit['image']['file_name']; $oldimg_url = $uploadPath['baseurl'] . $dataToEdit['image']['subdir'] . '/' . $dataToEdit['image']['file_name']; if (file_exists($oldimage_path)) { $oldThumb = wip_resize($oldimage_path, $oldimg_url, 50, 50, true); $oldthumbnail_path = $oldThumb['path']; unlink($oldimage_path); //delete old image unlink($oldthumbnail_path); //delete old thumbnail } } } } } $newThumbs = wip_resize($newImgPath, $newImg, 50, 50, true); $newThumb = $newThumbs['url']; foreach ($get_slider_det as $i => &$box) { if ($i == $EditId) { $box['image']['file_name'] = $image_filename; $box['image']['subdir'] = $subdir; } } unset($box); //update the image data update_option('bd_slider_det', $get_slider_det); $returnData = array("error" => false, "imgUrl" => $newImg, "thumbnail" => $newThumb); wip_delete_site_trans(); echo json_encode($returnData); die; } } elseif ($save_type == 'edit_data_slider') { $returnData = ""; $p = array(); if (isset($_POST['data'])) { $data = $_POST['data']; #explode them to get each data, check http://php.net/manual/en/function.parse-str.php parse_str($data, $p); } $id = isset($p['editid']) ? $p['editid'] : ''; if ($id == "") { $returnData = array("error" => true, "errorText" => __("cannot read the required ID!", "wip")); } else { $get_slider_det = get_option('bd_slider_det'); foreach ($get_slider_det as $i => &$box) { if ($i == $id) { $box['link'] = isset($p['wip_slider_url_edit']) ? $p['wip_slider_url_edit'] : ''; $box['desc'] = isset($p['wip_slider_desc_edit']) ? esc_textarea($p['wip_slider_desc_edit']) : ''; $box['piecemaker']['title'] = isset($p['wip_slider_title_edit']) ? $p['wip_slider_title_edit'] : ''; $box['piecemaker']['swf'] = isset($p['wip_slider_swf_edit']) ? $p['wip_slider_swf_edit'] : ''; $box['piecemaker']['pieces'] = isset($p['wip_slider_pc_pieces_edit']) ? $p['wip_slider_pc_pieces_edit'] : '9'; $box['piecemaker']['time'] = isset($p['wip_slider_pc_time_edit']) ? $p['wip_slider_pc_time_edit'] : '1.2'; $box['piecemaker']['transition'] = isset($p['wip_slider_pc_transition_edit']) ? $p['wip_slider_pc_transition_edit'] : ''; $box['piecemaker']['delay'] = isset($p['wip_slider_pc_delay_edit']) ? $p['wip_slider_pc_delay_edit'] : '0.1'; $box['piecemaker']['depthoffset'] = isset($p['wip_slider_pc_depthoffset_edit']) ? $p['wip_slider_pc_depthoffset_edit'] : '300'; $box['piecemaker']['cubedistance'] = isset($p['wip_slider_pc_cubedistance_edit']) ? $p['wip_slider_pc_cubedistance_edit'] : '20'; } } unset($box); update_option('bd_slider_det', $get_slider_det); wip_delete_site_trans(); $returnData = array("error" => false); } echo json_encode($returnData); } die; }
/** * Save the metabox : portfolio and blog custom post data */ function wip_save_post_metabox($postID, $post) { global $wpdb; if (!$_POST) { return $postID; } if (is_int(wp_is_post_revision($postID))) { return; } if (is_int(wp_is_post_autosave($postID))) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!current_user_can('edit_post', $postID)) { return $postID; } if ('portfolio-item' == $_POST['post_type'] && (isset($_POST['update']) || isset($_POST['save']) || isset($_POST['publish']))) { $op = Portfolio_metabox_option(); foreach ($op as $meta_page) { if (isset($meta_page['id']) && $meta_page['id'] == "_wip_bd_portfolio") { $Portfoliodata = isset($_POST['_wip_bd_portfolio']) ? $_POST['_wip_bd_portfolio'] : ''; $PpreviousValue = get_post_meta($postID, '_wip_bd_portfolio', true); if ($PpreviousValue != "" && $PpreviousValue != $Portfoliodata) { $portfolios = get_option('bd_portfolio_data'); if (!empty($portfolios)) { if (array_key_exists($PpreviousValue, $portfolios)) { $thisPort = $portfolios[$PpreviousValue]; if (isset($thisPort['image']) && is_array($thisPort['image'])) { $uploadPath = wp_upload_dir(); $imageDir = $uploadPath['basedir'] . $thisPort['image']['subdir'] . '/' . $thisPort['image']['image']; $imageUrl = $uploadPath['baseurl'] . $thisPort['image']['subdir'] . '/' . $thisPort['image']['image']; if (file_exists($imageDir)) { $thumbs = wip_resize($imageDir, $imageUrl, 215, 99999, false); if (file_exists($thumbs['path'])) { unlink($thumbs['path']); } unlink($imageDir); } } } unset($portfolios[$PpreviousValue]); update_option('bd_portfolio_data', $portfolios); } } } if (isset($meta_page['id']) && $meta_page['id'] == "_wip_make_featured") { $makeF = isset($_POST['_wip_make_featured']) ? $_POST['_wip_make_featured'] : '0'; $makeF = (bool) $makeF; $sticky = get_option('wip_featured_portfolio'); $countS = count($sticky); if (is_array($sticky) && in_array($postID, $sticky)) { foreach ($sticky as $k => $v) { if ($sticky[$k] == $post_id) { unset($sticky[$k]); } } $newstick = array_values($sticky); if ($countS == "1") { delete_option('wip_featured_portfolio'); } else { update_option('wip_featured_portfolio', $newstick); } } if ($makeF) { if (is_array($sticky)) { $ns[] = $postID; $ss = array_merge((array) $sticky, (array) $ns); } else { $ss[] = $postID; } update_option('wip_featured_portfolio', $ss); } } $data = ""; if (isset($_POST[$meta_page['id']])) { $data = $_POST[$meta_page['id']]; } if (get_post_meta($postID, $meta_page['id']) == "") { add_post_meta($postID, $meta_page['id'], $data, true); } elseif ($data != get_post_meta($postID, $meta_page['id'], true)) { update_post_meta($postID, $meta_page['id'], $data); } elseif ($data == "") { delete_post_meta($postID, $meta_page['id'], get_post_meta($postID, $meta_page['id'], true)); } } /** endforeach */ } else { if ('post' == $_POST['post_type'] && (isset($_POST['update']) || isset($_POST['save']) || isset($_POST['publish']))) { $bop = Blog_metabox_option(); foreach ($bop as $meta_blog) { $data = ""; if (isset($_POST[$meta_blog['id']])) { $data = $_POST[$meta_blog['id']]; } if (get_post_meta($postID, $meta_blog['id']) == "") { add_post_meta($postID, $meta_blog['id'], $data, true); } elseif ($data != get_post_meta($postID, $meta_blog['id'], true)) { update_post_meta($postID, $meta_blog['id'], $data); } elseif ($data == "") { delete_post_meta($postID, $meta_blog['id'], get_post_meta($postID, $meta_blog['id'], true)); } } } } }
function _wip_product_gallery_panel() { global $post, $woocommerce; ?> <div class="panel" id="tab-gallery"> <h2><?php print __('Product Gallery', 'wip'); ?> </h2> <?php $thumb_id = get_post_thumbnail_id(); $small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail'); $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'post__not_in' => array($thumb_id), 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC'); $attachments = get_posts($args); if ($attachments) { echo '<div class="product-gallery-thumbnail">' . "\n"; echo '<ul>' . "\n"; $columns = 6; $loop = 0; foreach ($attachments as $attachment) { if (get_post_meta($attachment->ID, '_woocommerce_exclude_image', true) == 1) { continue; } $loop++; $_post =& get_post($attachment->ID); $url = wp_get_attachment_url($_post->ID); $path = get_attached_file($_post->ID); $post_title = esc_attr($_post->post_title); if (file_exists($path)) { $image = wip_resize($path, $url, 140, 140, true); echo '<li class="normal '; if ($loop == 1 || ($loop - 1) % $columns == 0) { echo ' first'; } if ($loop % $columns == 0) { echo ' last'; } echo '">'; echo '<a href="' . $url . '" title="' . $post_title . '" rel="thumbnails" class="zoom">'; echo '<img src="' . $image['url'] . '" alt="' . $post_title . '"/></a></li>'; } } echo '</ul>' . "\n"; echo '<div class="clear"></div>' . "\n"; echo '</div>' . "\n"; //woocommerce_show_product_thumbnails(); } else { print '<p class="no_gallery"><em>' . __('No Galleries', 'wip') . '</em></p>'; } ?> </div> <?php }
function WIP_post_ajax_callback() { global $wpdb; #check the type of form if ($_POST['type']) { $save_type = $_POST['type']; } else { $save_type = null; } if ($save_type == 'upload_portfolio_image') { check_ajax_referer('portfolio_image_nonce'); $imgData = ''; $returnData = ''; $PortData = get_option('bd_portfolio_data'); $imgData = isset($_FILES['portfolio_image']) ? true : false; if (!$imgData) { $returnData = array("error" => true, "errorText" => __('Image file cannot be read!', 'wip')); echo json_encode($returnData); die; } else { $unique = intval(time()) . '-WIP-portfolio-data'; $curID = $unique; /** ======= break processs ======== */ $arr_file_type = wp_check_filetype(basename($_FILES['portfolio_image']['name'])); $uploaded_file_type = $arr_file_type['type']; # Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/x-icon'); /** ======= break processs ======== */ # if data is an image - upload it if (in_array($uploaded_file_type, $allowed_file_types)) { # override the upload process, WordPress need to detect 'wp_handle_upload' before upload the doc $filename = $_FILES['portfolio_image']; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; # upload process... $uploaded_file = wp_handle_upload($filename, $override); $upload_tracking[] = 'portfolio_image'; $path_info = wp_upload_dir(); $file_info = pathinfo($uploaded_file['file']); $image_filename = $file_info['filename'] . '.' . $file_info['extension']; $imageinfo = array('subdir' => $path_info['subdir'], 'image' => $image_filename); $newThumbs = wip_resize($uploaded_file['file'], $uploaded_file['url'], 215, 99999, false); $newThumb = $newThumbs['url']; $Sdata = array('id' => $curID, 'type' => 'image', 'image' => $imageinfo, 'video' => ''); /** ======= break processs ======== */ if (is_array($PortData)) { $dataIns[$curID] = $Sdata; $toIns = $PortData + $dataIns; } else { $toIns[$curID] = $Sdata; } update_option('bd_portfolio_data', $toIns); #returning into ajax $returnData = array("error" => false, "image" => $newThumb, "ajaxImageId" => $curID); echo json_encode($returnData); die; } else { #if error $uploaded_file['error'] = __('Unsupported file type!', 'wip'); $returnData = array("error" => true, "errorText" => sprintf(__('Upload Error: %1$s', 'wip'), $uploaded_file['error'])); echo json_encode($returnData); die; } } } elseif ($save_type == 'portfolio_reset') { } elseif ($save_type == 'portfolio_video') { $vidData = ''; $returnData = ''; $PortData = get_option('bd_portfolio_data'); if (isset($_POST['data'])) { $vidData = $_POST['data']; } if ($vidData == "" || $vidData == "Enter video URL") { $returnData = array("error" => true, "errorText" => __('Please enter the video URL before click the button!', 'wip')); echo json_encode($returnData); } else { $unique = intval(time()) . '-WIP-portfolio-data'; $curID = $unique; $Sdata = array('id' => $curID, 'type' => 'video', 'image' => '', 'video' => $vidData); /** ======= break processs ======== */ if (is_array($PortData)) { $dataIns[$curID] = $Sdata; $toIns = $PortData + $dataIns; } else { $toIns[$curID] = $Sdata; } /** ======= break processs ======== */ //update the image and thumbnail update_option('bd_portfolio_data', $toIns); #returning into ajax $returnData = array("error" => false, "vid" => $vidData, "ajaxId" => $curID); echo json_encode($returnData); } } die; }