function wpsc_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version, $wpsc_page_titles;
    $table_name = $wpdb->prefix . "wpsc_product_list";
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") !== $table_name) {
        // Table doesn't exist
        add_option('wpsc_purchaselogs_fixed', true);
    }
    // the only consistent and reliable way to detect whether this is a fresh install is by checking
    // whether WPSC_TABLE_CART_CONTENTS exists. This is an unfortunate hack, but we can do away with
    // it in 3.9 as we'll drop support for 3.7.x then
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WPSC_TABLE_CART_CONTENTS . "'") != WPSC_TABLE_CART_CONTENTS) {
        add_option('wpsc_db_version', WPSC_DB_VERSION, '', 'no');
    }
    // run the create or update code here.
    wpsc_create_or_update_tables();
    wpsc_create_upload_directories();
    // All code to add new database tables and columns must be above here
    $wpsc_version = get_option('wpsc_version', 0);
    $wpsc_minor_version = get_option('wpsc_minor_version', 0);
    if ($wpsc_version === false) {
        add_option('wpsc_version', WPSC_VERSION, '', 'no');
    } else {
        update_option('wpsc_version', WPSC_VERSION);
    }
    if ($wpsc_minor_version === false) {
        add_option('wpsc_minor_version', WPSC_MINOR_VERSION, '', 'no');
    } else {
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    if (version_compare($wpsc_version, '3.8', '<')) {
        update_option('wpsc_needs_update', true);
    } else {
        update_option('wpsc_needs_update', false);
    }
    if ('' == get_option('show_subcatsprods_in_cat')) {
        update_option('show_subcatsprods_in_cat', 0);
    }
    if ('' == get_option('wpsc_share_this')) {
        update_option('wpsc_share_this', 0);
    }
    if ('' == get_option('wpsc_crop_thumbnails')) {
        update_option('wpsc_crop_thumbnails', 0);
    }
    if ('' == get_option('wpsc_products_per_page')) {
        update_option('wpsc_products_per_page', 0);
    }
    if ('' == get_option('wpsc_force_ssl')) {
        update_option('wpsc_force_ssl', 0);
    }
    if ('' == get_option('use_pagination')) {
        update_option('use_pagination', 0);
    }
    if ('' == get_option('hide_name_link')) {
        update_option('hide_name_link', 0);
    }
    if ('' == get_option('wpsc_enable_comments')) {
        update_option('wpsc_enable_comments', 0);
    }
    if ('' == get_option('multi_add')) {
        update_option('multi_add', 1);
    }
    if ('' == get_option('hide_addtocart_button')) {
        update_option('hide_addtocart_button', 0);
    }
    if ('' == get_option('wpsc_addtocart_or_buynow')) {
        update_option('wpsc_addtocart_or_buynow', 0);
    }
    add_option('show_thumbnails', 1, '', 'no');
    add_option('show_thumbnails_thickbox', 1, '', 'no');
    require_once WPSC_FILE_PATH . '/wpsc-core/wpsc-functions.php';
    require_once WPSC_FILE_PATH . '/wpsc-includes/wpsc-theme-engine-bootstrap.php';
    if (!_wpsc_maybe_activate_theme_engine_v2()) {
        add_option('product_list_url', '', '', 'no');
        add_option('shopping_cart_url', '', '', 'no');
        add_option('checkout_url', '', '', 'no');
        add_option('transact_url', '', '', 'no');
        /*
         * This part creates the pages and automatically puts their URLs into the options page.
         * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
         */
        $post_date = date("Y-m-d H:i:s");
        $post_date_gmt = gmdate("Y-m-d H:i:s");
        $pages = array('products-page' => array('name' => 'products-page', 'title' => __('Products Page', 'wpsc'), 'tag' => '[productspage]', 'option' => 'product_list_url'), 'checkout' => array('name' => 'checkout', 'title' => __('Checkout', 'wpsc'), 'tag' => '[shoppingcart]', 'option' => 'shopping_cart_url'), 'transaction-results' => array('name' => 'transaction-results', 'title' => __('Transaction Results', 'wpsc'), 'tag' => '[transactionresults]', 'option' => 'transact_url'), 'your-account' => array('name' => 'your-account', 'title' => __('Your Account', 'wpsc'), 'tag' => '[userlog]', 'option' => 'user_account_url'));
        //indicator. if we will create any new pages we need to flush.. :)
        $newpages = false;
        //get products page id. if there's no products page then create one
        $products_page_id = $wpdb->get_var("SELECT id FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $pages['products-page']['tag'] . "%'\tAND `post_type` != 'revision'");
        if (empty($products_page_id)) {
            $products_page_id = wp_insert_post(array('post_title' => $pages['products-page']['title'], 'post_type' => 'page', 'post_name' => $pages['products-page']['name'], 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => $pages['products-page']['tag'], 'post_status' => 'publish', 'post_author' => 1, 'menu_order' => 0));
            $newpages = true;
        }
        update_option($pages['products-page']['option'], _get_page_link($products_page_id));
        //done. products page created. no we can unset products page data and create all other pages.
        //unset products page
        unset($pages['products-page']);
        //create other pages
        foreach ((array) $pages as $page) {
            //check if page exists and get it's ID
            $page_id = $wpdb->get_var("SELECT id FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%'\tAND `post_type` != 'revision'");
            //if there's no page - create
            if (empty($page_id)) {
                $page_id = wp_insert_post(array('post_title' => $page['title'], 'post_type' => 'page', 'post_name' => $page['name'], 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => $page['tag'], 'post_status' => 'publish', 'post_author' => 1, 'menu_order' => 0, 'post_parent' => $products_page_id));
                $newpages = true;
            }
            //update option
            update_option($page['option'], get_permalink($page_id));
            //also if this is shopping_cart, then update checkout url option
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($page_id));
            }
        }
        //if we have created any new pages, then flush... do we need to do this? probably should be removed
        if ($newpages) {
            wp_cache_delete('all_page_ids', 'pages');
            wpsc_update_permalink_slugs();
        }
    }
    add_option('payment_gateway', '', '', 'no');
    $default_payment_gateways_names = array('chronopay' => '', 'wpsc_merchant_paypal_express' => '', 'wpsc_merchant_paypal_pro' => '', 'wpsc_merchant_paypal_standard' => '');
    $existing_payment_gateways_names = get_option('payment_gateway_names');
    $new_payment_gatewats_name = array_merge($default_payment_gateways_names, (array) $existing_payment_gateways_names);
    update_option('payment_gateway_names', $new_payment_gatewats_name);
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', '', 'no');
    } else {
        add_option('cart_location', '1', '', 'no');
    }
    add_option('currency_type', '156', '', 'no');
    add_option('currency_sign_location', '3', '', 'no');
    add_option('gst_rate', '1', '', 'no');
    add_option('max_downloads', '1', '', 'no');
    add_option('display_pnp', '1', '', 'no');
    add_option('display_specials', '1', '', 'no');
    add_option('do_not_use_shipping', '1', '', 'no');
    add_option('postage_and_packaging', '0', '', 'no');
    add_option('shipwire', '0', '', 'no');
    add_option('shipwire_test_server', '0', '', 'no');
    add_option('purch_log_email', '', '', 'no');
    add_option('return_email', '', '', 'no');
    add_option('terms_and_conditions', '', '', 'no');
    add_option('default_brand', 'none', '', 'no');
    add_option('wpsc_default_category', 'all', '', 'no');
    add_option('product_view', 'default', "", 'no');
    add_option('add_plustax', 'default', "", '1');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    // PayPal options
    add_option('paypal_business', '', '', 'no');
    add_option('paypal_url', '', '', 'no');
    add_option('paypal_ipn', '1', '', 'no');
    add_option('paypal_multiple_business', '', '', 'no');
    add_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    add_option('product_ratings', '0', '', 'no');
    add_option('wpsc_email_receipt', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page. All prices include tax and postage and packaging where applicable.
You ordered these items:
%product_list%%total_shipping%%total_price%', 'wpsc'), '', 'no');
    add_option('wpsc_email_admin', __('%product_list%%total_shipping%%total_price%', 'wpsc'), '', 'no');
    add_option('wpsc_selected_theme', 'default', '', 'no');
    add_option('product_image_height', 148);
    add_option('product_image_width', 148);
    add_option('category_image_height', 148);
    add_option('category_image_width', 148);
    add_option('single_view_image_height', 148);
    add_option('single_view_image_width', 148);
    add_option('wpsc_gallery_image_height', 31);
    add_option('wpsc_gallery_image_width', 31);
    add_option('wpsc_thousands_separator', ',');
    add_option('wpsc_decimal_separator', '.');
    add_option('custom_gateway_options', array('wpsc_merchant_testmode'), '', 'no');
    add_option('wpsc_category_url_cache', array(), '', 'no');
    // add in some default tax settings
    add_option('wpec_taxes_inprice', 'exclusive');
    add_option('wpec_taxes_product', 'replace');
    add_option('wpec_taxes_logic', 'billing');
    wpsc_product_files_htaccess();
    // Product categories, temporarily register them to create first default category if none exist
    // @todo: investigate those require once lines and move them to right place (not from here, but from their original location, which seems to be wrong, since i cant access wpsc_register_post_types and wpsc_update_categorymeta here) - Vales <*****@*****.**>
    wpsc_core_load_page_titles();
    wpsc_register_post_types();
    $category_list = get_terms('wpsc_product_category', 'hide_empty=0&parent=0');
    if (count($category_list) == 0) {
        require_once WPSC_FILE_PATH . '/wpsc-includes/meta.functions.php';
        $new_category = wp_insert_term(__('Product Category', 'wpsc'), 'wpsc_product_category', "parent=0");
        $category_id = $new_category['term_id'];
        $term = get_term_by('id', $new_category['term_id'], 'wpsc_product_category');
        $url_name = $term->slug;
        wpsc_update_categorymeta($category_id, 'nice-name', $url_name);
        wpsc_update_categorymeta($category_id, 'description', __("This is a description", 'wpsc'));
        wpsc_update_categorymeta($category_id, 'image', '');
        wpsc_update_categorymeta($category_id, 'fee', '0');
        wpsc_update_categorymeta($category_id, 'active', '1');
        wpsc_update_categorymeta($category_id, 'order', '0');
    }
    flush_rewrite_rules(false);
    wpsc_theme_engine_v2_activate();
}
Example #2
0
function wpsc_create_upload_directories()
{
    $wpsc_files_directory = WP_CONTENT_DIR . '/uploads/wpsc/';
    if (!is_dir(WP_CONTENT_DIR . '/uploads')) {
        @mkdir(WP_CONTENT_DIR . '/uploads', 0775);
    }
    if (!is_dir($wpsc_files_directory)) {
        @mkdir($wpsc_files_directory, 0775);
    }
    if (!is_dir(WPSC_FILE_DIR)) {
        @mkdir(WPSC_FILE_DIR, 0775);
        wpsc_product_files_htaccess();
    }
    if (!is_dir(WPSC_PREVIEW_DIR)) {
        @mkdir(WPSC_PREVIEW_DIR, 0775);
    }
    if (!is_dir(WPSC_IMAGE_DIR)) {
        @mkdir(WPSC_IMAGE_DIR, 0775);
    }
    if (!is_dir(WPSC_THUMBNAIL_DIR)) {
        @mkdir(WPSC_THUMBNAIL_DIR, 0775);
    }
    if (!is_dir(WPSC_CATEGORY_DIR)) {
        @mkdir(WPSC_CATEGORY_DIR, 0775);
    }
    if (!is_dir(WPSC_USER_UPLOADS_DIR)) {
        @mkdir(WPSC_USER_UPLOADS_DIR, 0775);
    }
    $wpsc_file_directory = ABSPATH . get_option('upload_path') . '/wpsc/';
    if (is_dir($wpsc_file_directory)) {
        // sort the permissions out in case they are not already sorted out.
        @chmod(ABSPATH . get_option('upload_path'), 0775);
        @chmod($wpsc_file_directory, 0775);
        @chmod(WPSC_FILE_DIR, 0775);
        @chmod(WPSC_PREVIEW_DIR, 0775);
        @chmod(WPSC_IMAGE_DIR, 0775);
        @chmod(WPSC_CATEGORY_DIR, 0775);
        @chmod(WPSC_USER_UPLOADS_DIR, 0775);
    }
}
Example #3
0
function wpsc_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version;
    $table_name = $wpdb->prefix . "wpsc_product_list";
    $first_install = false;
    $result = mysql_list_tables(DB_NAME);
    $tables = array();
    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    if (!in_array($table_name, $tables)) {
        $first_install = true;
        add_option('wpsc_purchaselogs_fixed', true);
    }
    if (get_option('wpsc_version') == null) {
        add_option('wpsc_version', WPSC_VERSION, 'wpsc_version', 'yes');
    }
    // run the create or update code here.
    wpsc_create_or_update_tables();
    wpsc_create_upload_directories();
    /* all code to add new database tables and columns must be above here */
    if (get_option('wpsc_version') < WPSC_VERSION || get_option('wpsc_version') == WPSC_VERSION && get_option('wpsc_minor_version') < WPSC_MINOR_VERSION) {
        update_option('wpsc_version', WPSC_VERSION);
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    $add_initial_category = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`;", ARRAY_A);
    if ($add_initial_category[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (1, 'Categories', 'Product Categories', '1', '1')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (2, 'Brands', 'Product Brands', '1', '0')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('1', '" . TXT_WPSC_EXAMPLECATEGORY . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('2', '" . TXT_WPSC_EXAMPLEBRAND . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
    }
    $purchase_statuses_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PURCHASE_STATUSES . "`", ARRAY_A);
    if ($purchase_statuses_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PURCHASE_STATUSES . "` (`name` , `active` , `colour` ) \n    VALUES\n    ('" . TXT_WPSC_RECEIVED . "', '1', ''),\n    ('" . TXT_WPSC_ACCEPTED_PAYMENT . "', '1', ''),\n    ('" . TXT_WPSC_JOB_DISPATCHED . "', '1', ''),\n    ('" . TXT_WPSC_PROCESSED . "', '1', '');");
    }
    $check_category_assoc = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`;", ARRAY_A);
    if ($check_category_assoc[0]['count'] == 0) {
        $sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `active`=1";
        $product_list = $wpdb->get_results($sql, ARRAY_A);
        foreach ((array) $product_list as $product) {
            $results = $wpdb->query("INSERT INTO `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` (`product_id` , `category_id` ) VALUES ('" . $product['id'] . "', '" . $product['category'] . "');");
        }
    }
    add_option('show_thumbnails', 1, TXT_WPSC_SHOWTHUMBNAILS, "yes");
    add_option('product_image_width', '', TXT_WPSC_PRODUCTIMAGEWIDTH, 'yes');
    add_option('product_image_height', '', TXT_WPSC_PRODUCTIMAGEHEIGHT, 'yes');
    add_option('category_image_width', '', TXT_WPSC_CATEGORYIMAGEWIDTH, 'yes');
    add_option('category_image_height', '', TXT_WPSC_CATEGORYIMAGEHEIGHT, 'yes');
    add_option('product_list_url', '', TXT_WPSC_PRODUCTLISTURL, 'yes');
    add_option('shopping_cart_url', '', TXT_WPSC_SHOPPINGCARTURL, 'yes');
    add_option('checkout_url', '', TXT_WPSC_CHECKOUTURL, 'yes');
    add_option('transact_url', '', TXT_WPSC_TRANSACTURL, 'yes');
    add_option('payment_gateway', '', TXT_WPSC_PAYMENTGATEWAY, 'yes');
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    add_option('currency_type', '156', TXT_WPSC_CURRENCYTYPE, 'yes');
    add_option('currency_sign_location', '3', TXT_WPSC_CURRENCYSIGNLOCATION, 'yes');
    add_option('gst_rate', '1', TXT_WPSC_GSTRATE, 'yes');
    add_option('max_downloads', '1', TXT_WPSC_MAXDOWNLOADS, 'yes');
    add_option('display_pnp', '1', TXT_WPSC_DISPLAYPNP, 'yes');
    add_option('display_specials', '1', TXT_WPSC_DISPLAYSPECIALS, 'yes');
    add_option('do_not_use_shipping', '0', 'do_not_use_shipping', 'yes');
    add_option('postage_and_packaging', '0', TXT_WPSC_POSTAGEAND_PACKAGING, 'yes');
    add_option('purch_log_email', '', TXT_WPSC_PURCHLOGEMAIL, 'yes');
    add_option('return_email', '', TXT_WPSC_RETURNEMAIL, 'yes');
    add_option('terms_and_conditions', '', TXT_WPSC_TERMSANDCONDITIONS, 'yes');
    add_option('google_key', 'none', TXT_WPSC_GOOGLEMECHANTKEY, 'yes');
    add_option('google_id', 'none', TXT_WPSC_GOOGLEMECHANTID, 'yes');
    add_option('default_brand', 'none', TXT_WPSC_DEFAULTBRAND, 'yes');
    add_option('wpsc_default_category', 'all', TXT_WPSC_DEFAULTCATEGORY, 'yes');
    add_option('product_view', 'default', "", 'yes');
    add_option('add_plustax', 'default', "", '1');
    add_option('nzshpcrt_first_load', '0', "", 'yes');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    /* PayPal options */
    add_option('paypal_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    add_option('paypal_url', '', TXT_WPSC_PAYPALURL, 'yes');
    add_option('paypal_ipn', '1', TXT_WPSC_PAYPALURL, 'yes');
    //update_option('paypal_url', "https://www.sandbox.paypal.com/xclick");
    add_option('paypal_multiple_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    if (get_option('paypal_multiple_url') == null) {
        add_option('paypal_multiple_url', TXT_WPSC_PAYPALURL, 'yes');
        update_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    }
    add_option('product_ratings', '0', TXT_WPSC_SHOWPRODUCTRATINGS, 'yes');
    add_option('wpsc_email_receipt', TXT_WPSC_DEFAULT_PURCHASE_RECEIPT, 'yes');
    add_option('wpsc_email_admin', TXT_WPSC_DEFAULT_PURCHASE_REPORT, 'yes');
    if (get_option('wpsc_selected_theme') == '') {
        add_option('wpsc_selected_theme', 'default', 'Selected Theme', 'yes');
        update_option('wpsc_selected_theme', "default");
    }
    if (!get_option('product_image_height')) {
        update_option('product_image_height', '96');
        update_option('product_image_width', '96');
    }
    if (!get_option('category_image_height')) {
        update_option('category_image_height', '96');
        update_option('category_image_width', '96');
    }
    if (!get_option('single_view_image_height')) {
        update_option('single_view_image_height', '128');
        update_option('single_view_image_width', '128');
    }
    if (!get_option('wpsc_gallery_image_height')) {
        update_option('wpsc_gallery_image_height', '96');
        update_option('wpsc_gallery_image_width', '96');
    }
    if (!is_array(get_option('custom_gateway_options'))) {
        update_option('custom_gateway_options', array('testmode'));
    }
    add_option("wpsc_category_url_cache", array(), '', 'yes');
    wpsc_product_files_htaccess();
    /*
     * This part creates the pages and automatically puts their URLs into the options page.
     * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
     */
    $post_date = date("Y-m-d H:i:s");
    $post_date_gmt = gmdate("Y-m-d H:i:s");
    $num = 0;
    $pages[$num]['name'] = 'products-page';
    $pages[$num]['title'] = TXT_WPSC_PRODUCTSPAGE;
    $pages[$num]['tag'] = '[productspage]';
    $pages[$num]['option'] = 'product_list_url';
    $num++;
    $pages[$num]['name'] = 'checkout';
    $pages[$num]['title'] = TXT_WPSC_CHECKOUT;
    $pages[$num]['tag'] = '[shoppingcart]';
    $pages[$num]['option'] = 'shopping_cart_url';
    //   $num++;
    //   $pages[$num]['name'] = 'enter-details';
    //   $pages[$num]['title'] = TXT_WPSC_ENTERDETAILS;
    //   $pages[$num]['tag'] = '[checkout]';
    //   $pages[2$num]['option'] = 'checkout_url';
    $num++;
    $pages[$num]['name'] = 'transaction-results';
    $pages[$num]['title'] = TXT_WPSC_TRANSACTIONRESULTS;
    $pages[$num]['tag'] = '[transactionresults]';
    $pages[$num]['option'] = 'transact_url';
    $num++;
    $pages[$num]['name'] = 'your-account';
    $pages[$num]['title'] = TXT_WPSC_YOUR_ACCOUNT;
    $pages[$num]['tag'] = '[userlog]';
    $pages[$num]['option'] = 'user_account_url';
    $newpages = false;
    $i = 0;
    $post_parent = 0;
    foreach ($pages as $page) {
        $check_page = $wpdb->get_row("SELECT * FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%'  AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A);
        if ($check_page == null) {
            if ($i == 0) {
                $post_parent = 0;
            } else {
                $post_parent = $first_id;
            }
            if ($wp_version >= 2.1) {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_type)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'publish', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0', 'page')";
            } else {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'static', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0')";
            }
            $wpdb->query($sql);
            $post_id = $wpdb->insert_id;
            if ($i == 0) {
                $first_id = $post_id;
            }
            $wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_id) . "' WHERE ID = '{$post_id}'");
            update_option($page['option'], get_permalink($post_id));
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($post_id));
            }
            $newpages = true;
            $i++;
        }
    }
    if ($newpages == true) {
        wp_cache_delete('all_page_ids', 'pages');
        $wp_rewrite->flush_rules();
    }
    /* adds nice names for permalinks for products */
    $check_product_names = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_LIST . "`.`id`, `" . WPSC_TABLE_PRODUCT_LIST . "`.`name`, `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LEFT JOIN `" . WPSC_TABLE_PRODUCTMETA . "` ON `" . WPSC_TABLE_PRODUCT_LIST . "`.`id` = `" . WPSC_TABLE_PRODUCTMETA . "`.`product_id` WHERE (`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` IN ('url_name') AND  `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_value` IN (''))  OR ISNULL(`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key`)", ARRAY_A);
    if ($check_product_names != null) {
        foreach ((array) $check_product_names as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            if (get_product_meta($datarow['id'], 'url_name') != false) {
                $current_url_name = get_product_meta($datarow['id'], 'url_name');
                if ($current_url_name != $url_name) {
                    $url_name .= $extension_number;
                    update_product_meta($datarow['id'], 'url_name', $url_name);
                }
            } else {
                $url_name .= $extension_number;
                add_product_meta($datarow['id'], 'url_name', $url_name, true);
            }
        }
    }
    /* adds nice names for permalinks for categories */
    $check_category_names = $wpdb->get_results("SELECT DISTINCT `nice-name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` IN ('') AND `active` IN ('1')");
    if ($check_category_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` SET `nice-name` = '{$url_name}' WHERE `id` = '" . $datarow['id'] . "' LIMIT 1 ;");
        }
        $wp_rewrite->flush_rules();
    }
    /* Moves images to thumbnails directory */
    // this code should no longer be needed, as most people will be using a sufficiently new version
    $image_dir = WPSC_FILE_PATH . "/images/";
    $product_images = WPSC_IMAGE_DIR;
    $product_thumbnails = WPSC_THUMBNAIL_DIR;
    if (!is_dir($product_thumbnails)) {
        @mkdir($product_thumbnails, 0775);
    }
    $product_list = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `image` != ''", ARRAY_A);
    foreach ((array) $product_list as $product) {
        if (!glob($product_thumbnails . $product['image'])) {
            $new_filename = $product['id'] . "_" . $product['image'];
            if (file_exists($image_dir . $product['image'])) {
                copy($image_dir . $product['image'], $product_thumbnails . $new_filename);
                if (file_exists($product_images . $product['image'])) {
                    copy($product_images . $product['image'], $product_images . $new_filename);
                }
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
            } else {
                $imagedir = $product_thumbnails;
                $name = $new_filename;
                $new_image_path = $product_images . $product['image'];
                $imagepath = $product['image'];
                $height = get_option('product_image_height');
                $width = get_option('product_image_width');
                if (file_exists($product_images . $product['image'])) {
                    include "extra_image_processing.php";
                    copy($product_images . $product['image'], $product_images . $new_filename);
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
                }
            }
        }
    }
    // */
}
Example #4
0
function wpsc_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version;
    $table_name = $wpdb->prefix . "wpsc_product_list";
    $first_install = false;
    $result = mysql_list_tables(DB_NAME);
    $tables = array();
    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    if (!in_array($table_name, $tables)) {
        $first_install = true;
        add_option('wpsc_purchaselogs_fixed', true);
    }
    if (get_option('wpsc_version') == null) {
        add_option('wpsc_version', WPSC_VERSION, 'wpsc_version', 'yes');
    }
    // run the create or update code here.
    wpsc_create_or_update_tables();
    wpsc_create_upload_directories();
    if (!wp_get_schedule("wpsc_hourly_cron_tasks")) {
        wp_schedule_event(time(), 'hourly', 'wpsc_hourly_cron_tasks');
    }
    if (!wp_get_schedule("wpsc_daily_cron_tasks")) {
        wp_schedule_event(time(), 'daily', 'wpsc_daily_cron_tasks');
    }
    //wp_get_schedule( $hook, $args )
    /* all code to add new database tables and columns must be above here */
    if (get_option('wpsc_version') < WPSC_VERSION || get_option('wpsc_version') == WPSC_VERSION && get_option('wpsc_minor_version') < WPSC_MINOR_VERSION) {
        update_option('wpsc_version', WPSC_VERSION);
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    $add_initial_category = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`;", ARRAY_A);
    if ($add_initial_category[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (1, 'Categories', 'Product Categories', '1', '1')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (2, 'Brands', 'Product Brands', '1', '0')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('1', '" . __('Example category', 'wpsc') . "', '" . __('Example details', 'wpsc') . "', '1');");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('2', '" . __('Example Brand', 'wpsc') . "', '" . __('Example details', 'wpsc') . "', '1');");
    }
    $purchase_statuses_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PURCHASE_STATUSES . "`", ARRAY_A);
    if ($purchase_statuses_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PURCHASE_STATUSES . "` (`name` , `active` , `colour` ) \r\n    VALUES\r\n    ('" . __('Order Received', 'wpsc') . "', '1', ''),\r\n    ('" . __('Accepted Payment', 'wpsc') . "', '1', ''),\r\n    ('" . __('Job Dispatched', 'wpsc') . "', '1', ''),\r\n    ('" . __('Closed Order', 'wpsc') . "', '1', '');");
    }
    $check_category_assoc = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`;", ARRAY_A);
    if ($check_category_assoc[0]['count'] == 0) {
        $sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `active`=1";
        $product_list = $wpdb->get_results($sql, ARRAY_A);
        foreach ((array) $product_list as $product) {
            $results = $wpdb->query("INSERT INTO `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` (`product_id` , `category_id` ) VALUES ('" . $product['id'] . "', '" . $product['category'] . "');");
        }
    }
    add_option('show_thumbnails', 1, __('Show Thumbnails', 'wpsc'), "yes");
    add_option('product_image_width', '', __('product image width', 'wpsc'), 'yes');
    add_option('product_image_height', '', __('product image height', 'wpsc'), 'yes');
    add_option('category_image_width', '', __('product group image width', 'wpsc'), 'yes');
    add_option('category_image_height', '', __('product group image height', 'wpsc'), 'yes');
    add_option('product_list_url', '', __('The location of the product list', 'wpsc'), 'yes');
    add_option('shopping_cart_url', '', __('The location of the shopping cart', 'wpsc'), 'yes');
    add_option('checkout_url', '', __('The location of the checkout page', 'wpsc'), 'yes');
    add_option('transact_url', '', __('The location of the transaction detail page', 'wpsc'), 'yes');
    add_option('payment_gateway', '', __('The payment gateway to use', 'wpsc'), 'yes');
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', __('Cart Location', 'wpsc'), 'yes');
    } else {
        add_option('cart_location', '1', __('Cart Location', 'wpsc'), 'yes');
    }
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', __('Cart Location', 'wpsc'), 'yes');
    } else {
        add_option('cart_location', '1', __('Cart Location', 'wpsc'), 'yes');
    }
    //add_option('show_categorybrands', '0', __('Display categories or brands or both', 'wpsc'), 'yes');
    add_option('currency_type', '156', __('Currency type', 'wpsc'), 'yes');
    add_option('currency_sign_location', '3', __('Currency sign location', 'wpsc'), 'yes');
    add_option('gst_rate', '1', __('the GST rate', 'wpsc'), 'yes');
    add_option('max_downloads', '1', __('the download limit', 'wpsc'), 'yes');
    add_option('display_pnp', '1', __('Display or hide postage and packaging', 'wpsc'), 'yes');
    add_option('display_specials', '1', __('Display or hide specials on the sidebar', 'wpsc'), 'yes');
    add_option('do_not_use_shipping', '1', 'do_not_use_shipping', 'no');
    add_option('postage_and_packaging', '0', __('Default postage and packaging', 'wpsc'), 'yes');
    add_option('purch_log_email', '', __('Email address that purchase log is sent to', 'wpsc'), 'yes');
    add_option('return_email', '', __('Email address that purchase reports are sent from', 'wpsc'), 'yes');
    add_option('terms_and_conditions', '', __('Checkout terms and conditions', 'wpsc'), 'yes');
    add_option('google_key', 'none', __('Google Merchant Key', 'wpsc'), 'yes');
    add_option('google_id', 'none', __('Google Merchant ID', 'wpsc'), 'yes');
    add_option('default_brand', 'none', __('Default Brand', 'wpsc'), 'yes');
    add_option('wpsc_default_category', 'all', __('Select what product group you want to display on the products page', 'wpsc'), 'yes');
    add_option('product_view', 'default', "", 'yes');
    add_option('add_plustax', 'default', "", '1');
    add_option('nzshpcrt_first_load', '0', "", 'yes');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    //add_option('show_categorybrands', '0', __('Display categories or brands or both', 'wpsc'), 'yes');
    /* PayPal options */
    add_option('paypal_business', '', __('paypal business', 'wpsc'), 'yes');
    add_option('paypal_url', '', __('paypal url', 'wpsc'), 'yes');
    add_option('paypal_ipn', '1', __('paypal url', 'wpsc'), 'yes');
    //update_option('paypal_url', "https://www.sandbox.paypal.com/xclick");
    add_option('paypal_multiple_business', '', __('paypal business', 'wpsc'), 'yes');
    if (get_option('paypal_multiple_url') == null) {
        add_option('paypal_multiple_url', __('paypal url', 'wpsc'), 'yes');
        update_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    }
    add_option('product_ratings', '0', __('Show Product Ratings', 'wpsc'), 'yes');
    add_option('wpsc_email_receipt', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
    add_option('wpsc_email_admin', __('%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
    if (get_option('wpsc_selected_theme') == '') {
        add_option('wpsc_selected_theme', 'default', 'Selected Theme', 'yes');
        update_option('wpsc_selected_theme', "default");
    }
    if (!get_option('product_image_height')) {
        update_option('product_image_height', '96');
        update_option('product_image_width', '96');
    }
    if (!get_option('category_image_height')) {
        update_option('category_image_height', '96');
        update_option('category_image_width', '96');
    }
    if (!get_option('single_view_image_height')) {
        update_option('single_view_image_height', '128');
        update_option('single_view_image_width', '128');
    }
    if (!get_option('wpsc_gallery_image_height')) {
        update_option('wpsc_gallery_image_height', '96');
        update_option('wpsc_gallery_image_width', '96');
    }
    if (!is_array(get_option('custom_gateway_options'))) {
        update_option('custom_gateway_options', array('testmode'));
    }
    add_option("wpsc_category_url_cache", array(), '', 'yes');
    wpsc_product_files_htaccess();
    /*
     * This part creates the pages and automatically puts their URLs into the options page.
     * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
     */
    $post_date = date("Y-m-d H:i:s");
    $post_date_gmt = gmdate("Y-m-d H:i:s");
    $num = 0;
    $pages[$num]['name'] = 'products-page';
    $pages[$num]['title'] = __('Products Page', 'wpsc');
    $pages[$num]['tag'] = '[productspage]';
    $pages[$num]['option'] = 'product_list_url';
    $num++;
    $pages[$num]['name'] = 'checkout';
    $pages[$num]['title'] = __('Checkout', 'wpsc');
    $pages[$num]['tag'] = '[shoppingcart]';
    $pages[$num]['option'] = 'shopping_cart_url';
    //   $num++;
    //   $pages[$num]['name'] = 'enter-details';
    //   $pages[$num]['title'] = __('Enter Your Details', 'wpsc');
    //   $pages[$num]['tag'] = '[checkout]';
    //   $pages[2$num]['option'] = 'checkout_url';
    $num++;
    $pages[$num]['name'] = 'transaction-results';
    $pages[$num]['title'] = __('Transaction Results', 'wpsc');
    $pages[$num]['tag'] = '[transactionresults]';
    $pages[$num]['option'] = 'transact_url';
    $num++;
    $pages[$num]['name'] = 'your-account';
    $pages[$num]['title'] = __('Your Account', 'wpsc');
    $pages[$num]['tag'] = '[userlog]';
    $pages[$num]['option'] = 'user_account_url';
    $newpages = false;
    $i = 0;
    $post_parent = 0;
    foreach ($pages as $page) {
        $check_page = $wpdb->get_row("SELECT * FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%'  AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A);
        if ($check_page == null) {
            if ($i == 0) {
                $post_parent = 0;
            } else {
                $post_parent = $first_id;
            }
            if ($wp_version >= 2.1) {
                $sql = "INSERT INTO " . $wpdb->posts . "\r\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_type)\r\n        VALUES\r\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'publish', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0', 'page')";
            } else {
                $sql = "INSERT INTO " . $wpdb->posts . "\r\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order)\r\n        VALUES\r\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'static', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0')";
            }
            $wpdb->query($sql);
            $post_id = $wpdb->insert_id;
            if ($i == 0) {
                $first_id = $post_id;
            }
            $wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_id) . "' WHERE ID = '{$post_id}'");
            update_option($page['option'], get_permalink($post_id));
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($post_id));
            }
            $newpages = true;
            $i++;
        }
    }
    if ($newpages == true) {
        wp_cache_delete('all_page_ids', 'pages');
        $wp_rewrite->flush_rules();
    }
    /* adds nice names for permalinks for products */
    $check_product_names = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_LIST . "`.`id`, `" . WPSC_TABLE_PRODUCT_LIST . "`.`name`, `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LEFT JOIN `" . WPSC_TABLE_PRODUCTMETA . "` ON `" . WPSC_TABLE_PRODUCT_LIST . "`.`id` = `" . WPSC_TABLE_PRODUCTMETA . "`.`product_id` WHERE (`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` IN ('url_name') AND  `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_value` IN (''))  OR ISNULL(`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key`)", ARRAY_A);
    if ($check_product_names != null) {
        foreach ((array) $check_product_names as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            if (get_product_meta($datarow['id'], 'url_name') != false) {
                $current_url_name = get_product_meta($datarow['id'], 'url_name');
                if ($current_url_name != $url_name) {
                    $url_name .= $extension_number;
                    update_product_meta($datarow['id'], 'url_name', $url_name);
                }
            } else {
                $url_name .= $extension_number;
                add_product_meta($datarow['id'], 'url_name', $url_name, true);
            }
        }
    }
    /* adds nice names for permalinks for categories */
    $check_category_names = $wpdb->get_results("SELECT DISTINCT `nice-name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` IN ('') AND `active` IN ('1')");
    if ($check_category_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` SET `nice-name` = '{$url_name}' WHERE `id` = '" . $datarow['id'] . "' LIMIT 1 ;");
        }
        $wp_rewrite->flush_rules();
    }
    /* Moves images to thumbnails directory */
    // this code should no longer be needed, as most people will be using a sufficiently new version
    $image_dir = WPSC_FILE_PATH . "/images/";
    $product_images = WPSC_IMAGE_DIR;
    $product_thumbnails = WPSC_THUMBNAIL_DIR;
    if (!is_dir($product_thumbnails)) {
        @mkdir($product_thumbnails, 0775);
    }
    $product_list = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `image` != ''", ARRAY_A);
    foreach ((array) $product_list as $product) {
        if (!glob($product_thumbnails . $product['image'])) {
            $new_filename = $product['id'] . "_" . $product['image'];
            if (file_exists($image_dir . $product['image'])) {
                copy($image_dir . $product['image'], $product_thumbnails . $new_filename);
                if (file_exists($product_images . $product['image'])) {
                    copy($product_images . $product['image'], $product_images . $new_filename);
                }
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
            } else {
                $imagedir = $product_thumbnails;
                $name = $new_filename;
                $new_image_path = $product_images . $product['image'];
                $imagepath = $product['image'];
                $height = get_option('product_image_height');
                $width = get_option('product_image_width');
                if (file_exists($product_images . $product['image'])) {
                    include "extra_image_processing.php";
                    copy($product_images . $product['image'], $product_images . $new_filename);
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
                }
            }
        }
    }
    // */
}