• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wpsc_get_mimetype函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wpsc_get_option函数代码示例发布时间:2022-05-23
下一篇:
PHP wpsc_get_meta函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap