當前位置: 首頁>>代碼示例>>PHP>>正文


PHP wpsc_get_mimetype函數代碼示例

本文整理匯總了PHP中wpsc_get_mimetype函數的典型用法代碼示例。如果您正苦於以下問題:PHP wpsc_get_mimetype函數的具體用法?PHP wpsc_get_mimetype怎麽用?PHP wpsc_get_mimetype使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了wpsc_get_mimetype函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: wpsc_convert_products_to_posts


//.........這裏部分代碼省略.........
                $post_created = array('original_id' => $product['id'], 'post_id' => $post_id);
                set_transient('wpsc_update_current_product', $post_created, 604800);
            }
            $product_meta_sql = $wpdb->prepare("\n\t\t\t\tSELECT \tIF( ( `custom` != 1\t),\n\t\t\t\t\t\tCONCAT( '_wpsc_', `meta_key` ) ,\n\t\t\t\t\t`meta_key`\n\t\t\t\t\t) AS `meta_key`,\n\t\t\t\t\t`meta_value`\n\t\t\t\tFROM `" . WPSC_TABLE_PRODUCTMETA . "`\n\t\t\t\tWHERE `product_id` = %d\n\t\t\t\tAND `meta_value` != ''", $product['id']);
            $product_meta = $wpdb->get_results($product_meta_sql, ARRAY_A);
            $post_data = array();
            foreach ($product_meta as $k => $pm) {
                if ($pm['meta_value'] == 'om') {
                    $pm['meta_value'] = 1;
                }
                $pm['meta_value'] = maybe_unserialize($pm['meta_value']);
                if (strpos($pm['meta_key'], '_wpsc_') === 0) {
                    $post_data['_wpsc_product_metadata'][$pm['meta_key']] = $pm['meta_value'];
                } else {
                    update_post_meta($post_id, $pm['meta_key'], $pm['meta_value']);
                }
            }
            $post_data['_wpsc_original_id'] = (int) $product['id'];
            $post_data['_wpsc_price'] = (double) $product['price'];
            $post_data['_wpsc_special_price'] = $post_data['_wpsc_price'] - (double) $product['special_price'];
            // special price get stored in a weird way in 3.7.x
            $post_data['_wpsc_stock'] = (double) $product['quantity'];
            $post_data['_wpsc_is_donation'] = $product['donation'];
            $post_data['_wpsc_sku'] = $sku;
            if ((bool) $product['quantity_limited'] != true) {
                $post_data['_wpsc_stock'] = false;
            }
            unset($post_data['_wpsc_limited_stock']);
            $post_data['_wpsc_product_metadata']['is_stock_limited'] = (int) (bool) $product['quantity_limited'];
            // Product Weight
            $post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($product['weight'], $product['weight_unit'], "pound", true);
            $post_data['_wpsc_product_metadata']['weight_unit'] = $product['weight_unit'];
            $post_data['_wpsc_product_metadata']['display_weight_as'] = $product['weight_unit'];
            $post_data['_wpsc_product_metadata']['has_no_shipping'] = (int) (bool) $product['no_shipping'];
            $post_data['_wpsc_product_metadata']['shipping'] = array('local' => $product['pnp'], 'international' => $product['international_pnp']);
            $post_data['_wpsc_product_metadata']['quantity_limited'] = (int) (bool) $product['quantity_limited'];
            $post_data['_wpsc_product_metadata']['special'] = (int) (bool) $product['special'];
            if (isset($post_data['meta'])) {
                $post_data['_wpsc_product_metadata']['notify_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'];
                $post_data['_wpsc_product_metadata']['unpublish_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
            }
            $post_data['_wpsc_product_metadata']['no_shipping'] = (int) (bool) $product['no_shipping'];
            foreach ($post_data as $meta_key => $meta_value) {
                // prefix all meta keys with _wpsc_
                update_post_meta($post_id, $meta_key, $meta_value);
            }
            // get the wordpress upload directory data
            $wp_upload_dir_data = wp_upload_dir();
            $wp_upload_basedir = $wp_upload_dir_data['basedir'];
            $category_ids = array();
            $category_data = $wpdb->get_col("SELECT `category_id` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE `product_id` IN ('{$product['id']}')");
            foreach ($category_data as $old_category_id) {
                $category_ids[] = wpsc_get_meta($old_category_id, 'category_id', 'wpsc_old_category');
            }
            wp_set_product_categories($post_id, $category_ids);
            $product_data = get_post($post_id);
            $image_data_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `product_id` = %d ORDER BY `image_order` ASC", $product['id']);
            $image_data = $wpdb->get_results($image_data_sql, ARRAY_A);
            foreach ((array) $image_data as $image_row) {
                $wpsc_update->check_timeout('</div>');
                // Get the image path info
                $image_pathinfo = pathinfo($image_row['image']);
                // use the path info to clip off the file extension
                $image_name = basename($image_pathinfo['basename'], ".{$image_pathinfo['extension']}");
                // construct the full image path
                $full_image_path = WPSC_IMAGE_DIR . $image_row['image'];
                $attached_file_path = str_replace($wp_upload_basedir . "/", '', $full_image_path);
                $upload_dir = wp_upload_dir();
                $new_path = $upload_dir['path'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
                if (is_file($full_image_path)) {
                    copy($full_image_path, $new_path);
                } else {
                    continue;
                }
                // construct the full image url
                $subdir = $upload_dir['subdir'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
                $subdir = substr($subdir, 1);
                $attachment_id_sql = $wpdb->prepare("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_parent` = %d LIMIT 1", $image_name, $post_id);
                $attachment_id = (int) $wpdb->get_var($attachment_id_sql);
                // get the image MIME type
                $mime_type_data = wpsc_get_mimetype($full_image_path, true);
                if ((int) $attachment_id == 0) {
                    // construct the image data array
                    $image_post_values = array('post_author' => $user_ID, 'post_parent' => $post_id, 'post_date' => $product_data->post_date, 'post_content' => $image_name, 'post_title' => $image_name, 'post_status' => "inherit", 'post_type' => "attachment", 'post_name' => sanitize_title($image_name), 'post_mime_type' => $mime_type_data['mime_type'], 'menu_order' => absint($image_row['image_order']), 'guid' => $new_path);
                    $attachment_id = wp_insert_post($image_post_values);
                }
                update_attached_file($attachment_id, $new_path);
                wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $new_path));
            }
            $i++;
            $progress->update($i);
            set_transient('wpsc_update_product_offset', $i, 604800);
        }
        $offset += $limit;
    }
    //Just throwing the payment gateway update in here because it doesn't really warrant it's own function :)
    $custom_gateways = get_option('custom_gateway_options');
    array_walk($custom_gateways, "wpec_update_gateway");
    update_option('custom_gateway_options', $custom_gateways);
}
開發者ID:ashik968,項目名稱:digiplot,代碼行數:101,代碼來源:updating-functions.php

示例2: _wpsc_ajax_upload_product_file

/**
 * Save a downloadable file to a product
 *
 * @since 3.8.9
 * @access private
 *
 * @uses $wpdb                          WordPress database object for use in queries
 * @uses _wpsc_create_ajax_nonce()      Creates nonce for an ajax action
 * @uses wpsc_get_mimetype()            Returns mimetype of file
 * @uses wp_insert_post()               Inserts post to WordPress database
 * @uses wp_nonce_url()                 Retrieve URL with nonce added to URL query.
 * @uses wpsc_convert_bytes()           Formats bytes
 * @uses wpsc_get_extension()           Gets extension of file
 * @uses esc_attr()                     Escapes HTML attributes
 * @uses _x()                           Retrieve translated string with gettext context
 *
 * @return array|WP_Error Response args if successful, WP_Error if otherwise.
 */
function _wpsc_ajax_upload_product_file()
{
    global $wpdb;
    $product_id = absint($_POST["product_id"]);
    $output = '';
    $delete_nonce = _wpsc_create_ajax_nonce('delete_file');
    foreach ($_POST["select_product_file"] as $selected_file) {
        // if we already use this file, there is no point doing anything more.
        $sql = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = 'wpsc-product-file' AND post_title = %s", $selected_file);
        // TODO it's safer to select by post ID, in that case we will use get_posts()
        $file_post_data = $wpdb->get_row($sql, ARRAY_A);
        $selected_file_path = WPSC_FILE_DIR . basename($selected_file);
        $file_url = WPSC_FILE_URL . basename($selected_file);
        $file_size = filesize($selected_file_path);
        if (empty($file_post_data)) {
            $type = wpsc_get_mimetype($selected_file_path);
            $attachment = array('post_mime_type' => $type, 'post_parent' => $product_id, 'post_title' => $selected_file, 'post_content' => '', 'post_type' => "wpsc-product-file", 'post_status' => 'inherit');
            $id = wp_insert_post($attachment);
        } else {
            // already attached
            if ($file_post_data['post_parent'] == $product_id) {
                continue;
            }
            $type = $file_post_data["post_mime_type"];
            $url = $file_post_data["guid"];
            $title = $file_post_data["post_title"];
            $content = $file_post_data["post_content"];
            // Construct the attachment
            $attachment = array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => absint($product_id), 'post_title' => $title, 'post_content' => $content, 'post_type' => "wpsc-product-file", 'post_status' => 'inherit');
            // Save the data
            $id = wp_insert_post($attachment);
        }
        $deletion_url = wp_nonce_url("admin.php?wpsc_admin_action=delete_file&amp;file_name={$attachment['post_title']}&amp;product_id={$product_id}", 'delete_file_' . $attachment['post_title']);
        $output .= '<tr class="wpsc_product_download_row">';
        $output .= '<td style="padding-right: 30px;">' . $attachment['post_title'] . '</td>';
        $output .= '<td>' . wpsc_convert_byte($file_size) . '</td>';
        $output .= '<td>.' . wpsc_get_extension($attachment['post_title']) . '</td>';
        $output .= "<td><a data-file-name='" . esc_attr($attachment['post_title']) . "' data-product-id='" . esc_attr($product_id) . "' data-nonce='" . esc_attr($delete_nonce) . "' class='file_delete_button' href='{$deletion_url}' >" . _x('Delete', 'Digital Download UI row', 'wpsc') . "</a></td>";
        $output .= '<td><a href=' . $file_url . '>' . _x('Download', 'Digital Download UI row', 'wpsc') . '</a></td>';
        $output .= '</tr>';
    }
    return array('content' => $output);
}
開發者ID:dreamteam111,項目名稱:dreamteam,代碼行數:61,代碼來源:ajax.php

示例3: wpsc_item_reassign_file

/**
 * wpsc_item_reassign_file function
 *
 * @param integer product ID
 * @param string the selected file name;
 */
function wpsc_item_reassign_file($product_id, $selected_files)
{
    global $wpdb;
    $product_file_list = array();
    // initialise $idhash to null to prevent issues with undefined variables and error logs
    $idhash = null;
    $args = array('post_type' => 'wpsc-product-file', 'post_parent' => $product_id, 'numberposts' => -1, 'post_status' => 'any');
    $attached_files = (array) get_posts($args);
    foreach ($attached_files as $key => $attached_file) {
        $attached_files_by_file[$attached_file->post_title] = $attached_files[$key];
    }
    /* if we are editing, grab the current file and ID hash */
    if (!$selected_files) {
        // unlikely that anyone will ever upload a file called .none., so its the value used to signify clearing the product association
        return null;
    }
    foreach ($selected_files as $selected_file) {
        // if we already use this file, there is no point doing anything more.
        $file_is_attached = false;
        $selected_file_path = WPSC_FILE_DIR . basename($selected_file);
        if (isset($attached_files_by_file[$selected_file])) {
            $file_is_attached = true;
        }
        if ($file_is_attached == false) {
            $type = wpsc_get_mimetype($selected_file_path);
            $attachment = array('post_mime_type' => $type, 'post_parent' => $product_id, 'post_title' => $selected_file, 'post_content' => '', 'post_type' => "wpsc-product-file", 'post_status' => 'inherit');
            wp_insert_post($attachment);
        } else {
            $product_post_values = array('ID' => $attached_files_by_file[$selected_file]->ID, 'post_status' => 'inherit');
            wp_update_post($product_post_values);
        }
    }
    foreach ($attached_files as $attached_file) {
        if (!in_array($attached_file->post_title, $selected_files)) {
            $product_post_values = array('ID' => $attached_file->ID, 'post_status' => 'draft');
            wp_update_post($product_post_values);
        }
    }
    return $fileid;
}
開發者ID:nikitanaumov,項目名稱:WP-e-Commerce,代碼行數:46,代碼來源:product-functions.php

示例4: wpsc_item_add_preview_file

/**
 * wpsc_item_add_preview_file function 
 *
 * @param integer product ID
 * @param array the preview file array from $_FILES
 */
function wpsc_item_add_preview_file($product_id, $preview_file)
{
    global $wpdb;
    $current_file_id = $wpdb->get_var("SELECT `file` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$product_id}' LIMIT 1");
    $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='{$current_file_id}' LIMIT 1", ARRAY_A);
    if (apply_filters('wpsc_filter_file', $preview_file['tmp_name'])) {
        //echo "test?";
        if (function_exists("make_mp3_preview")) {
            if ($mimetype == "audio/mpeg" && !isset($preview_file['tmp_name'])) {
                // if we can generate a preview file, generate it (most can't due to sox being rare on servers and sox with MP3 support being even rarer), thus this needs to be enabled by editing code
                make_mp3_preview(WPSC_FILE_DIR . $idhash, WPSC_PREVIEW_DIR . $idhash . ".mp3");
                $preview_filepath = WPSC_PREVIEW_DIR . $idhash . ".mp3";
            } else {
                if (file_exists($preview_file['tmp_name'])) {
                    $preview_filename = basename($preview_file['name']);
                    $preview_mimetype = wpsc_get_mimetype($preview_file['tmp_name']);
                    copy($preview_file['tmp_name'], WPSC_PREVIEW_DIR . $preview_filename);
                    $preview_filepath = WPSC_PREVIEW_DIR . $preview_filename;
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_FILES . "` SET `preview` = '" . $wpdb->escape($preview_filename) . "', `preview_mimetype` = '" . $preview_mimetype . "' WHERE `id` = '{$file_data['id']}' LIMIT 1");
                    //exit("UPDATE `".WPSC_TABLE_PRODUCT_FILES."` SET `preview` = '".$wpdb->escape($preview_filename)."', `preview_mimetype` = '".$preview_mimetype."' WHERE `id` = '{$file_data['id']}' LIMIT 1");
                }
            }
            $stat = stat(dirname($preview_filepath));
            $perms = $stat['mode'] & 0666;
            @chmod($preview_filepath, $perms);
        }
        //exit("<pre>".print_r($preview_file,true)."</pre>");
        return $fileid;
    } else {
        return $selected_files;
    }
}
開發者ID:BGCX261,項目名稱:zombie-craft-svn-to-git,代碼行數:38,代碼來源:product-functions.php

示例5: old_wpsc_item_reassign_file

function old_wpsc_item_reassign_file($selected_product_file, $mode = 'add')
{
    global $wpdb;
    // initialise $idhash to null to prevent issues with undefined variables and error logs
    $idhash = null;
    if ($mode == 'edit') {
        /* if we are editing, grab the current file and ID hash */
        $product_id = (int) $_POST['prodid'];
        if ($selected_product_file == '.none.') {
            // unlikely that anyone will ever upload a file called .none., so its the value used to signify clearing the product association
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `file` = '0' WHERE `id` = '{$product_id}' LIMIT 1");
            return null;
        }
        // if we already use this file, there is no point doing anything more.
        $current_fileid = $wpdb->get_var("SELECT `file` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A);
        if ($current_fileid > 0) {
            $current_file_data = $wpdb->get_row("SELECT `id`,`idhash` FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id` = '{$current_fileid}' LIMIT 1", ARRAY_A);
            if (basename($selected_product_file) == $file_data['idhash']) {
                return $current_fileid;
            }
        }
    }
    $selected_product_file = basename($selected_product_file);
    if (file_exists(WPSC_FILE_DIR . $selected_product_file)) {
        $timestamp = time();
        $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `idhash` IN('" . $wpdb->escape($selected_product_file) . "') LIMIT 1", ARRAY_A);
        $fileid = (int) $file_data['id'];
        if ($fileid < 1) {
            // if the file does not have a database row, add one.
            $mimetype = wpsc_get_mimetype(WPSC_FILE_DIR . $selected_product_file);
            $filename = $idhash = $selected_product_file;
            $timestamp = time();
            $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_FILES . "` ( `filename`  , `mimetype` , `idhash` , `date` ) VALUES ( '{$filename}', '{$mimetype}', '{$idhash}', '{$timestamp}');");
            $fileid = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `date` = '{$timestamp}' AND `filename` IN ('{$filename}')");
        }
        if ($mode == 'edit') {
            //if we are editing, update the file ID in the product row, this cannot be done for add because the row does not exist yet.
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `file` = '{$fileid}' WHERE `id` = '{$product_id}' LIMIT 1");
        }
    }
    return $fileid;
}
開發者ID:BGCX261,項目名稱:zombie-craft-svn-to-git,代碼行數:42,代碼來源:processing.functions.php

示例6: wpsc_item_process_file

 // 		}
 // 	}
 /* handle editing file uploads here */
 if (!empty($_FILES['file']['name'])) {
     $fileid = wpsc_item_process_file('edit');
     $file = $fileid;
 } else {
     if ($_POST['select_product_file'] != '') {
         $fileid = wpsc_item_reassign_file($_POST['select_product_file'], 'edit');
         $file = $fileid;
     }
 }
 if (file_exists($_FILES['preview_file']['tmp_name'])) {
     $fileid = $wpdb->get_var("SELECT `file` FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$id}' LIMIT 1");
     copy($_FILES['preview_file']['tmp_name'], WPSC_PREVIEW_DIR . basename($_FILES['preview_file']['name']));
     $mimetype = wpsc_get_mimetype(WPSC_PREVIEW_DIR . basename($_FILES['preview_file']['name']));
     $wpdb->query("UPDATE `" . $wpdb->prefix . "product_files` SET `preview` = '" . $wpdb->escape(basename($_FILES['preview_file']['name'])) . "', `preview_mimetype` = '" . $mimetype . "' WHERE `id` = '{$fileid}' LIMIT 1");
 }
 /* Handle new image uploads here */
 $image = wpsc_item_process_image();
 if (is_numeric($_POST['prodid'])) {
     if (($_POST['image_resize'] == 1 || $_POST['image_resize'] == 2) && $image == '') {
         /*  resize the image if directed to do so and no new image is supplied  */
         $image_data = $wpdb->get_row("SELECT `id`,`image` FROM `" . $wpdb->prefix . "product_list` WHERE `id`=" . $_POST['prodid'] . " LIMIT 1", ARRAY_A);
         // prevent images from being replaced by those from other products
         $check_multiple_use = $wpdb->get_var("SELECT COUNT(`image`) AS `count` FROM `" . $wpdb->prefix . "product_list` WHERE `image`='" . $image_data['image'] . "'");
         if ($check_multiple_use > 1) {
             $new_filename = $image_data['id'] . "_" . $image_data['image'];
             if (file_exists(WPSC_THUMBNAIL_DIR . $image_data['image']) && $image_data['image'] != null) {
                 copy(WPSC_THUMBNAIL_DIR . $image_data['image'], WPSC_THUMBNAIL_DIR . $new_filename);
             }
開發者ID:alx,項目名稱:barceloneta,代碼行數:31,代碼來源:display-items.php

示例7: save_provided_file

 /**
  * user provided file method
  * @access public
  * @param string shipping method
  * @return boolean true on sucess, false on failure
  */
 function save_provided_file($file_data)
 {
     global $wpdb;
     $accepted_file_types['mime'][] = 'image/jpeg';
     $accepted_file_types['mime'][] = 'image/gif';
     $accepted_file_types['mime'][] = 'image/png';
     $accepted_file_types['mime'][] = 'image/pjpeg';
     // Added for IE compatibility
     $accepted_file_types['mime'][] = 'image/x-png';
     // Added for IE compatibility
     //$accepted_file_types['mime'][] = 'image/svg+xml';
     $accepted_file_types['ext'][] = 'jpeg';
     $accepted_file_types['ext'][] = 'jpg';
     $accepted_file_types['ext'][] = 'gif';
     $accepted_file_types['ext'][] = 'png';
     //$accepted_file_types['ext'][] = 'svg';
     $can_have_uploaded_image = get_product_meta($this->product_id, 'can_have_uploaded_image');
     if ($can_have_uploaded_image == 'on') {
         $mime_type_data = wpsc_get_mimetype($file_data['tmp_name'], true);
         $name_parts = explode('.', basename($file_data['name']));
         $extension = array_pop($name_parts);
         if ($mime_type_data['is_reliable'] == true) {
             $mime_type = $mime_type_data['mime_type'];
         } else {
             // if we can't use what PHP provides us with, we have to trust the user as there aren't really any other choices.
             $mime_type = $file_data['type'];
         }
         //echo( "<pre>".print_r($mime_type_data,true)."</pre>" );
         //exit( "<pre>".print_r($file_data,true)."</pre>" );
         if ((array_search($mime_type, $accepted_file_types['mime']) !== false || get_option('wpsc_check_mime_types') == 1) && array_search($extension, $accepted_file_types['ext']) !== false) {
             if (is_file(WPSC_USER_UPLOADS_DIR . $file_data['name'])) {
                 $name_parts = explode('.', basename($file_data['name']));
                 $extension = array_pop($name_parts);
                 $name_base = implode('.', $name_parts);
                 $file_data['name'] = null;
                 $num = 2;
                 //  loop till we find a free file name, first time I get to do a do loop in yonks
                 do {
                     $test_name = "{$name_base}-{$num}.{$extension}";
                     if (!file_exists(WPSC_USER_UPLOADS_DIR . $test_name)) {
                         $file_data['name'] = $test_name;
                     }
                     $num++;
                 } while ($file_data['name'] == null);
             }
             //exit($file_data['name']);
             $unique_id = sha1(uniqid(rand(),  true));
             if (move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR . $file_data['name'])) {
                 $this->custom_file = array('file_name' => $file_data['name'], 'mime_type' => $mime_type, "unique_id" => $unique_id);
             }
         }
     }
 }
開發者ID:alx,項目名稱:SBek-Arak,代碼行數:59,代碼來源:cart.class.php

示例8: nzshpcrt_submit_checkout


//.........這裏部分代碼省略.........
                        case TXT_WPSC_COUNTRY:
                            $bad_input_message .= TXT_WPSC_PLEASESELECTCOUNTRY . "";
                            break;
                            //             case TXT_WPSC_COUPON:
                            //             $bad_input_message .= TXT_WPSC_COUPON_DOESNT_EXIST . "";
                            //             break;
                        //             case TXT_WPSC_COUPON:
                        //             $bad_input_message .= TXT_WPSC_COUPON_DOESNT_EXIST . "";
                        //             break;
                        default:
                            $bad_input_message .= TXT_WPSC_PLEASEENTERAVALID . " " . strtolower($form_data['name']) . ".";
                            break;
                    }
                    $bad_input_message .= "\n\r";
                }
            }
        }
        // this here section handles uploading files specified by the user for products
        $accepted_file_types['mime'][] = 'image/jpeg';
        $accepted_file_types['mime'][] = 'image/gif';
        $accepted_file_types['mime'][] = 'image/png';
        $accepted_file_types['ext'][] = 'jpeg';
        $accepted_file_types['ext'][] = 'jpg';
        $accepted_file_types['ext'][] = 'gif';
        $accepted_file_types['ext'][] = 'png';
        foreach ($_SESSION['nzshpcrt_cart'] as $key => $item) {
            $can_have_uploaded_image = get_product_meta($item->product_id, 'can_have_uploaded_image', true);
            if ($can_have_uploaded_image[0] == 'on') {
                $file_data['name'] = basename($_FILES['uploaded_image']['name'][$key]);
                $file_data['type'] = $_FILES['uploaded_image']['type'][$key];
                $file_data['tmp_name'] = $_FILES['uploaded_image']['tmp_name'][$key];
                $file_data['error'] = $_FILES['uploaded_image']['error'][$key];
                $file_data['size'] = $_FILES['uploaded_image']['size'][$key];
                $mime_type_data = wpsc_get_mimetype($file_data['tmp_name'], true);
                $name_parts = explode('.', basename($file_data['name']));
                $extension = array_pop($name_parts);
                echo $extension . "<br />";
                if ($mime_type_data['is_reliable'] == true) {
                    $mime_type = $mime_type_data['mime_type'];
                } else {
                    // if we can't use what PHP provides us with, we have to trust the user as there aren't really any other choices.
                    $mime_type = $file_data['type'];
                }
                if (array_search($mime_type, $accepted_file_types['mime']) !== false && array_search($extension, $accepted_file_types['ext']) !== false) {
                    if (is_file(WPSC_USER_UPLOADS_DIR . $file_data['name'])) {
                        $name_parts = explode('.', basename($file_data['name']));
                        $extension = array_pop($name_parts);
                        $name_base = implode('.', $name_parts);
                        $file_data['name'] = null;
                        $num = 2;
                        //  loop till we find a free file name, first time I get to do a do loop in yonks
                        do {
                            $test_name = "{$name_base}-{$num}.{$extension}";
                            if (!file_exists(WPSC_USER_UPLOADS_DIR . $test_name)) {
                                $file_data['name'] = $test_name;
                            }
                            $num++;
                        } while ($file_data['name'] == null);
                    }
                    //exit($file_data['name']);
                    if (move_uploaded_file($file_data['tmp_name'], WPSC_USER_UPLOADS_DIR . $file_data['name'])) {
                        $_SESSION['nzshpcrt_cart'][$key]->file_data = array('file_name' => $file_data['name'], 'mime_type' => $mime_type);
                    }
                }
            }
        }
開發者ID:alx,項目名稱:barceloneta,代碼行數:67,代碼來源:submit_checkout_function.php

示例9: prod_upload

function prod_upload()
{
    global $wpdb;
    $product_id = absint($_POST["product_id"]);
    foreach ($_POST["select_product_file"] as $selected_file) {
        // if we already use this file, there is no point doing anything more.
        $sql = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = 'wpsc-product-file' AND post_title = %s", $selected_file);
        // TODO it's safer to select by post ID, in that case we will use get_posts()
        $file_post_data = $wpdb->get_row($sql, ARRAY_A);
        $selected_file_path = WPSC_FILE_DIR . basename($selected_file);
        if (isset($attached_files_by_file[$selected_file])) {
            $file_is_attached = true;
        }
        //if(is_file($selected_file_path)) {
        if (empty($file_post_data)) {
            $type = wpsc_get_mimetype($selected_file_path);
            $attachment = array('post_mime_type' => $type, 'post_parent' => $product_id, 'post_title' => $selected_file, 'post_content' => '', 'post_type' => "wpsc-product-file", 'post_status' => 'inherit');
            $id = wp_insert_post($attachment);
        } else {
            $type = $file_post_data["post_mime_type"];
            $url = $file_post_data["guid"];
            $title = $file_post_data["post_title"];
            $content = $file_post_data["post_content"];
            // Construct the attachment
            $attachment = array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => absint($product_id), 'post_title' => $title, 'post_content' => $content, 'post_type' => "wpsc-product-file", 'post_status' => 'inherit');
            // Save the data
            $id = wp_insert_post($attachment);
        }
        //}
        echo "{$id}\n";
    }
}
開發者ID:hornet9,項目名稱:Morato,代碼行數:32,代碼來源:ajax-and-init.php

示例10: wpsc_convert_products_to_posts


//.........這裏部分代碼省略.........
                $post_status = "draft";
            }
            //check the product added time with the current time to make sure its not out - this aviods the future post status
            $product_added_time = strtotime($product['date_added']);
            $current_time = time();
            $post_date = $product['date_added'];
            if ((int) $current_time < (int) $product_added_time) {
                $post_date = date("Y-m-d H:i:s");
            }
            $product_post_values = array('post_author' => $user_ID, 'post_date' => $post_date, 'post_content' => $product['description'], 'post_excerpt' => $product['additional_description'], 'post_title' => $product['name'], 'post_status' => $post_status, 'post_type' => "wpsc-product", 'post_name' => sanitize_title($product['name']), 'menu_order' => $product['order']);
            $post_id = wp_insert_post($product_post_values);
        }
        $product_meta = $wpdb->get_results("\n\t\t\tSELECT \tIF( ( `custom` != 1\t),\n\t\t\t\t\tCONCAT( '_wpsc_', `meta_key` ) ,\n\t\t\t\t`meta_key`\n\t\t\t\t) AS `meta_key`,\n\t\t\t\t`meta_value`\n\t\t\tFROM `" . WPSC_TABLE_PRODUCTMETA . "`\n\t\t\tWHERE `product_id` = " . $product['id'] . "\n\t\t\tAND `meta_value` != ''", ARRAY_A);
        $post_data = array();
        foreach ($product_meta as $k => $pm) {
            if ($pm['meta_value'] == 'om') {
                $pm['meta_value'] = 1;
            }
            $pm['meta_value'] = maybe_unserialize($pm['meta_value']);
            if (strpos($pm['meta_key'], '_wpsc_') === 0) {
                $post_data['_wpsc_product_metadata'][$pm['meta_key']] = $pm['meta_value'];
            } else {
                update_post_meta($post_id, $pm['meta_key'], $pm['meta_value']);
            }
        }
        $post_data['_wpsc_original_id'] = (int) $product['id'];
        $post_data['_wpsc_price'] = (double) $product['price'];
        $post_data['_wpsc_special_price'] = (double) $product['special_price'];
        $post_data['_wpsc_stock'] = (double) $product['quantity'];
        $post_data['_wpsc_is_donation'] = $product['donation'];
        $post_data['_wpsc_sku'] = $sku;
        if ((bool) $product['quantity_limited'] != true) {
            $post_data['_wpsc_stock'] = false;
        }
        unset($post_data['_wpsc_limited_stock']);
        $post_data['_wpsc_product_metadata']['is_stock_limited'] = (int) (bool) $product['quantity_limited'];
        // Product Weight
        $post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($product['weight'], $product['weight_unit'], "pound", true);
        $post_data['_wpsc_product_metadata']['weight_unit'] = $product['weight_unit'];
        $post_data['_wpsc_product_metadata']['display_weight_as'] = $product['weight_unit'];
        $post_data['_wpsc_product_metadata']['has_no_shipping'] = (int) (bool) $product['no_shipping'];
        $post_data['_wpsc_product_metadata']['shipping'] = array('local' => $product['pnp'], 'international' => $product['international_pnp']);
        $post_data['_wpsc_product_metadata']['quantity_limited'] = (int) (bool) $product['quantity_limited'];
        $post_data['_wpsc_product_metadata']['special'] = (int) (bool) $product['special'];
        if (isset($post_data['meta'])) {
            $post_data['_wpsc_product_metadata']['unpublish_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
        }
        $post_data['_wpsc_product_metadata']['no_shipping'] = (int) (bool) $product['no_shipping'];
        foreach ($post_data as $meta_key => $meta_value) {
            // prefix all meta keys with _wpsc_
            update_post_meta($post_id, $meta_key, $meta_value);
        }
        // get the wordpress upload directory data
        $wp_upload_dir_data = wp_upload_dir();
        $wp_upload_basedir = $wp_upload_dir_data['basedir'];
        $category_ids = array();
        $category_data = $wpdb->get_col("SELECT `category_id` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE `product_id` IN ('{$product['id']}')");
        foreach ($category_data as $old_category_id) {
            $category_ids[] = wpsc_get_meta($old_category_id, 'category_id', 'wpsc_old_category');
        }
        wp_set_product_categories($post_id, $category_ids);
        $product_data = get_post($post_id);
        $image_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `product_id` IN ('{$product['id']}') ORDER BY `image_order` ASC", ARRAY_A);
        foreach ((array) $image_data as $image_row) {
            // Get the image path info
            $image_pathinfo = pathinfo($image_row['image']);
            // use the path info to clip off the file extension
            $image_name = basename($image_pathinfo['basename'], ".{$image_pathinfo['extension']}");
            // construct the full image path
            $full_image_path = WPSC_IMAGE_DIR . $image_row['image'];
            $attached_file_path = str_replace($wp_upload_basedir . "/", '', $full_image_path);
            $upload_dir = wp_upload_dir();
            $new_path = $upload_dir['path'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
            if (is_file($full_image_path)) {
                copy($full_image_path, $new_path);
            } else {
                continue;
            }
            // construct the full image url
            $subdir = $upload_dir['subdir'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
            $subdir = substr($subdir, 1);
            $attachment_id = (int) $wpdb->get_var("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` IN('{$image_name}') AND `post_parent` IN('{$post_id}') LIMIT 1");
            // get the image MIME type
            $mime_type_data = wpsc_get_mimetype($full_image_path, true);
            if ((int) $attachment_id == 0) {
                // construct the image data array
                $image_post_values = array('post_author' => $user_ID, 'post_parent' => $post_id, 'post_date' => $product_data->post_date, 'post_content' => $image_name, 'post_title' => $image_name, 'post_status' => "inherit", 'post_type' => "attachment", 'post_name' => sanitize_title($image_name), 'post_mime_type' => $mime_type_data['mime_type'], 'menu_order' => absint($image_row['image_order']), 'guid' => $new_path);
                $attachment_id = wp_insert_post($image_post_values);
            }
            $image_size_data = @getimagesize($full_image_path);
            $image_metadata = array('width' => $image_size_data[0], 'height' => $image_size_data[1], 'file' => $subdir);
            update_post_meta($attachment_id, '_wp_attached_file', $subdir);
            update_post_meta($attachment_id, '_wp_attachment_metadata', $image_metadata);
        }
    }
    //Just throwing the payment gateway update in here because it doesn't really warrant it's own function :)
    $custom_gateways = get_option('custom_gateway_options');
    array_walk($custom_gateways, "wpec_update_gateway");
    update_option('custom_gateway_options', $custom_gateways);
}
開發者ID:hornet9,項目名稱:Morato,代碼行數:101,代碼來源:updating-functions.php


注:本文中的wpsc_get_mimetype函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。