예제 #1
0
function fn_clone_image_pairs($target_object_id, $object_id, $object_type, $lang_code = CART_LANGUAGE)
{
    // Get all pairs
    $pair_data = db_get_hash_array("SELECT pair_id, image_id, detailed_id, type FROM ?:images_links WHERE object_id = ?i AND object_type = ?s", 'pair_id', $object_id, $object_type);
    if (empty($pair_data)) {
        return false;
    }
    $icons = $detailed = $pairs_data = array();
    foreach ($pair_data as $pair_id => $p_data) {
        if (!empty($p_data['image_id'])) {
            $icons[$pair_id] = fn_get_image($p_data['image_id'], $object_type, $lang_code, true);
            if (!empty($icons[$pair_id])) {
                $p_data['image_alt'] = empty($icons[$pair_id]['alt']) ? '' : $icons[$pair_id]['alt'];
                $tmp_name = fn_create_temp_file();
                Storage::instance('images')->export($icons[$pair_id]['relative_path'], $tmp_name);
                $name = fn_basename($icons[$pair_id]['image_path']);
                $icons[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        if (!empty($p_data['detailed_id'])) {
            $detailed[$pair_id] = fn_get_image($p_data['detailed_id'], 'detailed', $lang_code, true);
            if (!empty($detailed[$pair_id])) {
                $p_data['detailed_alt'] = empty($detailed[$pair_id]['alt']) ? '' : $detailed[$pair_id]['alt'];
                $tmp_name = fn_create_temp_file();
                Storage::instance('images')->export($detailed[$pair_id]['relative_path'], $tmp_name);
                $name = fn_basename($detailed[$pair_id]['image_path']);
                $detailed[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        $pairs_data = array($pair_id => array('type' => $p_data['type'], 'image_alt' => !empty($p_data['image_alt']) ? $p_data['image_alt'] : '', 'detailed_alt' => !empty($p_data['detailed_alt']) ? $p_data['detailed_alt'] : ''));
        fn_update_image_pairs($icons, $detailed, $pairs_data, $target_object_id, $object_type, array(), true, $lang_code);
    }
}
예제 #2
0
function fn_clone_image_pairs($target_object_id, $object_id, $object_type, $action = null, $parent_object_id = 0, $parent_object_type = '', $rev_data = array(), $lang_code = CART_LANGUAGE)
{
    $table = 'images_links';
    $itable = 'images';
    $cond = '';
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        if (!empty($rev_data)) {
            $cond = db_quote(" AND revision = ?s AND revision_id = ?i", $rev_data['revision'], $rev_data['revision_id']);
            $table = 'rev_images_links';
            $itable = 'rev_images';
        }
    }
    // Get all pairs
    $pair_data = db_get_hash_array("SELECT pair_id, image_id, detailed_id, type FROM ?:{$table} WHERE object_id = ?i AND object_type = ?s ?p", 'pair_id', $object_id, $object_type, $cond);
    if (empty($pair_data)) {
        return false;
    }
    $icons = $detailed = $pairs_data = array();
    foreach ($pair_data as $pair_id => $p_data) {
        if (!empty($p_data['image_id'])) {
            $icons[$pair_id] = fn_get_image($p_data['image_id'], $object_type, $rev_data, $lang_code);
            if (!empty($icons[$pair_id])) {
                $p_data['image_alt'] = empty($icons[$pair_id]['alt']) ? '' : $icons[$pair_id]['alt'];
                // Image is stored on the filesystem
                if (empty($icons[$pair_id]['image'])) {
                    $path = str_replace(Registry::get('config.images_path'), DIR_IMAGES, $icons[$pair_id]['image_path']);
                    $icons[$pair_id]['image'] = fn_get_contents($path);
                    $name = ($action === null ? $target_object_id . '_' : '') . basename($path);
                } else {
                    $name = ($action === null ? $target_object_id . '_' : '') . $object_type . '_image';
                }
                $tmp_name = tempnam(DIR_COMPILED, 'image_clone');
                fn_put_contents($tmp_name, $icons[$pair_id]['image']);
                $icons[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        if (!empty($p_data['detailed_id'])) {
            $detailed[$pair_id] = fn_get_image($p_data['detailed_id'], 'detailed', $rev_data, $lang_code);
            if (!empty($detailed[$pair_id])) {
                $p_data['detailed_alt'] = empty($detailed[$pair_id]['alt']) ? '' : $detailed[$pair_id]['alt'];
                // Image is stored on the filesystem
                if (empty($detailed[$pair_id]['image'])) {
                    $path = str_replace(Registry::get('config.images_path'), DIR_IMAGES, $detailed[$pair_id]['image_path']);
                    $detailed[$pair_id]['image'] = fn_get_contents($path);
                    $name = ($action === null ? $target_object_id . '_' : '') . basename($path);
                } else {
                    $name = ($action === null ? $target_object_id . '_' : '') . '_detailed_image';
                }
                $tmp_name = tempnam(DIR_COMPILED, 'detailed_clone');
                fn_put_contents($tmp_name, $detailed[$pair_id]['image']);
                $detailed[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        $pairs_data = array($pair_id => array('type' => $p_data['type'], 'image_alt' => !empty($p_data['image_alt']) ? $p_data['image_alt'] : '', 'detailed_alt' => !empty($p_data['detailed_alt']) ? $p_data['detailed_alt'] : ''));
        if ($action == 'publish') {
            Registry::set('revisions.working', true);
        }
        fn_update_image_pairs($icons, $detailed, $pairs_data, $target_object_id, $object_type, array(), $parent_object_type, $parent_object_id, true, false, $lang_code);
        if ($action == 'publish') {
            Registry::set('revisions.working', false);
        }
    }
}
예제 #3
0
 /**
  * Save uploaded logo and favicon and return array of their urls
  * @return Array of Strings
  */
 private static function _saveUploadedLogos()
 {
     $logo_names = array('logo', 'favicon');
     $options = array();
     foreach ($logo_names as $logo_name) {
         $pair_ids = fn_attach_image_pairs($logo_name, 'twg_logos');
         if (!empty($pair_ids)) {
             $image_id = TwigmoImage::getImageId(array('pair_id' => reset($pair_ids), 'object_type' => 'twg_logos'));
             $image_data = fn_get_image($image_id, 'twg_logos');
             $options[$logo_name . '_url'] = $image_data['http_image_path'];
         }
     }
     return $options;
 }
예제 #4
0
파일: vimg.php 프로젝트: shyaken/maoy.palt
function fn_find_valid_image_path($image_pair, $object_type, $get_flash, $lang_code)
{
    if (isset($image_pair['icon']['absolute_path']) && is_file($image_pair['icon']['absolute_path'])) {
        if (!$get_flash && isset($image_pair['icon']['is_flash']) && $image_pair['icon']['is_flash']) {
            // We don't need Flash at all -- no need to crawl images any more.
            return false;
        } else {
            return $image_pair['icon']['image_path'];
        }
    }
    // Try to get the product's image.
    if (!empty($image_pair['image_id'])) {
        $image = fn_get_image($image_pair['image_id'], $object_type, 0, $lang_code);
        if (isset($image['absolute_path']) && is_file($image['absolute_path'])) {
            if (!$get_flash && isset($image['is_flash']) && $image['is_flash']) {
                return false;
            }
            return $image['image_path'];
        }
    }
    // If everything above failed, try to generate the thumbnail.
    if (!empty($image_pair['detailed_id'])) {
        $image = fn_get_image($image_pair['detailed_id'], 'detailed', 0, $lang_code);
        if (isset($image['absolute_path']) && is_file($image['absolute_path'])) {
            if (isset($image['is_flash']) && $image['is_flash']) {
                if ($get_flash) {
                    // No need to call fn_generate_thumbnail()
                    return $image['image_path'];
                } else {
                    return false;
                }
            }
            $image = fn_generate_thumbnail($image['image_path'], Registry::get('settings.Thumbnails.product_details_thumbnail_width'), Registry::get('settings.Thumbnails.product_details_thumbnail_height'), false);
            if (!empty($image)) {
                return $image;
            }
        }
    }
    return false;
}
예제 #5
0
function fn_get_order_info($order_id, $native_language = false, $format_info = true, $get_edp_files = false, $skip_static_values = false)
{
    if (!empty($order_id)) {
        $condition = fn_get_company_condition();
        $order = db_get_row("SELECT * FROM ?:orders WHERE ?:orders.order_id = ?i {$condition}", $order_id);
        if (empty($order)) {
            return false;
        }
        $lang_code = $native_language == true ? $order['lang_code'] : CART_LANGUAGE;
        $order['payment_method'] = fn_get_payment_method_data($order['payment_id'], $lang_code);
        if (!empty($order)) {
            // Get additional profile fields
            $additional_fields = db_get_hash_single_array("SELECT field_id, value FROM ?:profile_fields_data WHERE object_id = ?i AND object_type = 'O'", array('field_id', 'value'), $order_id);
            $order['fields'] = $additional_fields;
            $order['items'] = db_get_hash_array("SELECT ?:order_details.*, ?:product_descriptions.product, ?:product_descriptions.short_description FROM ?:order_details LEFT JOIN ?:product_descriptions ON ?:order_details.product_id = ?:product_descriptions.product_id AND ?:product_descriptions.lang_code = ?s WHERE ?:order_details.order_id = ?i ORDER BY ?:product_descriptions.product", 'item_id', $lang_code, $order_id);
            $order['promotions'] = unserialize($order['promotions']);
            if (!empty($order['promotions'])) {
                // collect additional data
                $params = array('promotion_id' => array_keys($order['promotions']));
                list($promotions) = fn_get_promotions($params);
                foreach ($promotions as $pr_id => $p) {
                    $order['promotions'][$pr_id]['name'] = $p['name'];
                    $order['promotions'][$pr_id]['short_description'] = $p['short_description'];
                }
            }
            // Get additional data
            $additional_data = db_get_hash_single_array("SELECT type, data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $order_id);
            $order['taxes'] = array();
            $order['tax_subtotal'] = 0;
            $order['display_shipping_cost'] = $order['shipping_cost'];
            // Replace country, state and title values with their descriptions
            fn_add_user_data_descriptions($order, $lang_code);
            $order['need_shipping'] = false;
            $deps = array();
            // Get shipments common information
            if (Registry::get('settings.General.use_shipments') == 'Y') {
                $order['shipment_ids'] = db_get_fields('SELECT sh.shipment_id FROM ?:shipments AS sh LEFT JOIN ?:shipment_items AS s_items ON (sh.shipment_id = s_items.shipment_id) WHERE s_items.order_id = ?i GROUP BY s_items.shipment_id', $order_id);
                $_products = db_get_array("SELECT item_id, SUM(amount) AS amount FROM ?:shipment_items WHERE order_id = ?i GROUP BY item_id", $order_id);
                $shipped_products = array();
                if (!empty($_products)) {
                    foreach ($_products as $_product) {
                        $shipped_products[$_product['item_id']] = $_product['amount'];
                    }
                }
                unset($_products);
            }
            foreach ($order['items'] as $k => $v) {
                //Check for product existance
                if (empty($v['product'])) {
                    $order['items'][$k]['deleted_product'] = true;
                }
                $order['items'][$k]['discount'] = 0;
                $v['extra'] = @unserialize($v['extra']);
                if ($skip_static_values == false && !empty($v['extra']['product'])) {
                    $order['items'][$k]['product'] = $v['extra']['product'];
                    preg_match("/\\[(.*?)\\]/", $v['extra']['product'], $resmath);
                    $order['items'][$k]['art'] = $resmath[1];
                }
                $order['items'][$k]['company_id'] = empty($v['extra']['company_id']) ? 0 : $v['extra']['company_id'];
                if (!empty($v['extra']['discount']) && floatval($v['extra']['discount'])) {
                    $order['items'][$k]['discount'] = $v['extra']['discount'];
                    $order['use_discount'] = true;
                }
                if (!empty($v['extra']['promotions'])) {
                    $order['items'][$k]['promotions'] = $v['extra']['promotions'];
                }
                if (isset($v['extra']['base_price'])) {
                    $order['items'][$k]['base_price'] = floatval($v['extra']['base_price']);
                } else {
                    $order['items'][$k]['base_price'] = $v['price'];
                }
                $order['items'][$k]['original_price'] = $order['items'][$k]['base_price'];
                // Form hash key for this product
                $order['items'][$k]['cart_id'] = $v['item_id'];
                $deps['P_' . $order['items'][$k]['cart_id']] = $k;
                //$order['items'][$k]['sklad'] = fn_numsklad($order['items'][$k]['product']);
                // Unserialize and collect product options information
                if (!empty($v['extra']['product_options'])) {
                    if ($format_info == true) {
                        $order['items'][$k]['product_options'] = $skip_static_values == false && !empty($v['extra']['product_options_value']) ? $v['extra']['product_options_value'] : fn_get_selected_product_options_info($v['extra']['product_options'], $lang_code);
                    }
                    if (empty($v['extra']['stored_price'])) {
                        // apply modifiers if this is not the custom price
                        $order['items'][$k]['original_price'] = fn_apply_options_modifiers($v['extra']['product_options'], $order['items'][$k]['base_price'], 'P', $skip_static_values == false && !empty($v['extra']['product_options_value']) ? $v['extra']['product_options_value'] : array());
                    }
                }
                $img = db_get_field("SELECT cscart_images.image_path FROM cscart_images_links LEFT \nJOIN cscart_images ON cscart_images_links.image_id = cscart_images.image_id  \nWHERE cscart_images_links.object_id = ?i", $order['items'][$k]['product_id']);
                $imgid = db_get_field("SELECT cscart_images_links.image_id FROM cscart_images_links  \nWHERE cscart_images_links.object_id = ?i", $order['items'][$k]['product_id']);
                $order['items'][$k]['extra'] = $v['extra'];
                $order['items'][$k]['img'] = fn_get_image($imgid, "product");
                $order['items'][$k]['tax_value'] = 0;
                $order['items'][$k]['display_subtotal'] = $order['items'][$k]['subtotal'] = $v['price'] * $v['amount'];
                $order['items'][$k]['display_per_subtotal'] = $order['items'][$k]['original_price'] * $v['amount'];
                // Get information about edp
                if ($get_edp_files == true && $order['items'][$k]['extra']['is_edp'] == 'Y') {
                    $order['items'][$k]['files'] = db_get_array("SELECT ?:product_files.file_id, ?:product_files.activation_type, ?:product_files.max_downloads, ?:product_file_descriptions.file_name, ?:product_file_ekeys.active, ?:product_file_ekeys.downloads, ?:product_file_ekeys.ekey, ?:product_file_ekeys.ttl FROM ?:product_files LEFT JOIN ?:product_file_descriptions ON ?:product_file_descriptions.file_id = ?:product_files.file_id AND ?:product_file_descriptions.lang_code = ?s LEFT JOIN ?:product_file_ekeys ON ?:product_file_ekeys.file_id = ?:product_files.file_id AND ?:product_file_ekeys.order_id = ?i WHERE ?:product_files.product_id = ?i", $lang_code, $order_id, $v['product_id']);
                }
                // Get shipments information
                if (Registry::get('settings.General.use_shipments') == 'Y') {
                    if (isset($shipped_products[$k])) {
                        $order['items'][$k]['shipped_amount'] = $shipped_products[$k];
                        $order['items'][$k]['shipment_amount'] = $v['amount'] - $shipped_products[$k];
                    } else {
                        $order['items'][$k]['shipped_amount'] = 0;
                        $order['items'][$k]['shipment_amount'] = $v['amount'];
                    }
                    if ($order['items'][$k]['shipped_amount'] < $order['items'][$k]['amount']) {
                        $order['need_shipment'] = true;
                    }
                }
                // Check if the order needs the shipping method
                if (!($v['extra']['is_edp'] == 'Y' && (!isset($v['extra']['edp_shipping']) || $v['extra']['edp_shipping'] != 'Y'))) {
                    $order['need_shipping'] = true;
                }
            }
            if (fn_check_suppliers_functionality()) {
                $order['companies'] = fn_get_products_companies($order['items']);
                $order['have_suppliers'] = fn_check_companies_have_suppliers($order['companies']);
            }
            // Unserialize and collect taxes information
            if (!empty($additional_data['T'])) {
                $order['taxes'] = unserialize($additional_data['T']);
                if (is_array($order['taxes'])) {
                    foreach ($order['taxes'] as $tax_id => $tax_data) {
                        foreach ($tax_data['applies'] as $_id => $value) {
                            if (strpos($_id, 'P_') !== false && isset($deps[$_id])) {
                                $order['items'][$deps[$_id]]['tax_value'] += $value;
                                if ($tax_data['price_includes_tax'] != 'Y') {
                                    $order['items'][$deps[$_id]]['subtotal'] += $value;
                                    $order['items'][$deps[$_id]]['display_subtotal'] += Registry::get('settings.Appearance.cart_prices_w_taxes') == 'Y' ? $value : 0;
                                    $order['tax_subtotal'] += $value;
                                }
                            }
                            if (strpos($_id, 'S_') !== false && Registry::get('settings.Appearance.cart_prices_w_taxes') == 'Y') {
                                if ($tax_data['price_includes_tax'] != 'Y') {
                                    $order['display_shipping_cost'] += $value;
                                }
                            }
                        }
                    }
                } else {
                    $order['taxes'] = array();
                }
            }
            if (!empty($additional_data['C'])) {
                $order['coupons'] = unserialize($additional_data['C']);
            }
            if (!empty($additional_data['R'])) {
                $order['secondary_currency'] = unserialize($additional_data['R']);
            }
            // Recalculate subtotal
            $order['subtotal'] = $order['display_subtotal'] = 0;
            foreach ($order['items'] as $v) {
                $order['subtotal'] += $v['subtotal'];
                $order['display_per_subtotal'] += $v['display_per_subtotal'];
                $order['display_subtotal'] += $v['display_subtotal'];
            }
            // Unserialize and collect payment information
            if (!empty($additional_data['P'])) {
                $order['payment_info'] = unserialize(fn_decrypt_text($additional_data['P']));
            }
            if (empty($order['payment_info']) || !is_array($order['payment_info'])) {
                $order['payment_info'] = array();
            }
            // Get shipping information
            if (!empty($additional_data['L'])) {
                $order['shipping'] = unserialize($additional_data['L']);
            }
            $order['doc_ids'] = db_get_hash_single_array("SELECT type, doc_id FROM ?:order_docs WHERE order_id = ?i", array('type', 'doc_id'), $order_id);
        }
        fn_set_hook('get_order_info', $order, $additional_data);
        //echo $_SERVER['REMOTE_ADDR'];
        if ($_SERVER['REMOTE_ADDR'] == "188.123.241.2") {
            //	echo ;
        }
        $order['subtotal_discount'] = $order['subtotal_discount'] == "0.00" ? $order['discount'] : $order['subtotal_discount'];
        $metro = db_get_field("SELECT description FROM cscart_profile_field_descriptions WHERE object_type = 'V' AND object_id = ?i", $order['fields'][44]);
        //$firma = db_get_field("SELECT description FROM cscart_profile_field_descriptions WHERE object_type = 'V' AND object_id = ?i", $order['fields'][65]);
        $q = "SELECT value FROM cscart_profile_fields_data  WHERE  object_id =" . $order_id . " AND field_id = 65";
        $vals = db_get_array($q);
        //var_dump($vals);
        //$firma = db_get_field("SELECT value FROM cscart_profile_fields_data WHERE  object_id = ?i", $order['fields'][65]);
        $order['metro'] = $metro;
        $order['firma'] = $vals[0]["value"];
        return $order;
    }
    return false;
}