示例#1
0
 public static function createLogo($company_id = 0, $layout_id = 0, $filename = '', $img_path = '', $type = 'theme', $common_descr_object = 'Customer_logo')
 {
     $company_id = (int) $company_id;
     $layout_id = (int) $layout_id;
     $logo_id = db_query("INSERT INTO ?:logos ?e", array('layout_id' => $layout_id, 'company_id' => $company_id, 'type' => $type));
     $image_data = array('name' => $filename, 'path' => $img_path, 'params' => array('keep_origins' => true));
     if (!file_exists($img_path) || filesize($img_path) === 0) {
         return false;
     }
     $img_id = fn_update_image($image_data, 0, 'logos');
     $image_link_data = array('object_id' => $logo_id, 'object_type' => 'logos', 'image_id' => $img_id);
     foreach (db_get_fields("SELECT lang_code FROM ?:languages") as $lang_code) {
         $descr = db_get_field("SELECT description FROM ?:common_descriptions WHERE object_id= ?i AND lang_code = ?s AND object_holder = ?s", $company_id, $lang_code, $common_descr_object);
         if (!empty($descr)) {
             db_query("REPLACE INTO ?:common_descriptions (object_id, description, lang_code, object_holder) VALUES (?i, ?s, ?s, 'images')", $img_id, $descr, $lang_code);
         }
     }
     return db_query("INSERT INTO ?:images_links ?e", $image_link_data);
 }
示例#2
0
function fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id = 0, $object_type = 'product_lists', $object_ids = array(), $update_alt_desc = true, $lang_code = CART_LANGUAGE)
{
    $pair_ids = array();
    if (!empty($pairs_data)) {
        foreach ($pairs_data as $k => $p_data) {
            $data = array();
            $pair_id = !empty($p_data['pair_id']) ? $p_data['pair_id'] : 0;
            $o_id = !empty($object_id) ? $object_id : (!empty($p_data['object_id']) ? $p_data['object_id'] : 0);
            if ($o_id == 0 && !empty($object_ids[$k])) {
                $o_id = $object_ids[$k];
            } elseif (!empty($object_ids) && empty($object_ids[$k])) {
                continue;
            }
            // Check if main pair is exists
            if (empty($pair_id) && !empty($p_data['type']) && $p_data['type'] == 'M') {
                $pair_data = db_get_row("SELECT pair_id, image_id, detailed_id FROM ?:images_links WHERE object_id = ?i AND object_type = ?s AND type = ?s", $o_id, $object_type, $p_data['type']);
                $pair_id = !empty($pair_data['pair_id']) ? $pair_data['pair_id'] : 0;
            } else {
                $pair_data = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id);
                if (empty($pair_data)) {
                    $pair_id = 0;
                }
            }
            // Update detailed image
            if (!empty($detailed[$k]) && !empty($detailed[$k]['size'])) {
                if (fn_get_image_size($detailed[$k]['path'])) {
                    $data['detailed_id'] = fn_update_image($detailed[$k], !empty($pair_data['detailed_id']) ? $pair_data['detailed_id'] : 0, 'detailed');
                }
            }
            // Update icon
            if (!empty($icons[$k]) && !empty($icons[$k]['size'])) {
                if (fn_get_image_size($icons[$k]['path'])) {
                    $data['image_id'] = fn_update_image($icons[$k], !empty($pair_data['image_id']) ? $pair_data['image_id'] : 0, $object_type);
                }
            }
            // Update alt descriptions
            if ((empty($data) && !empty($pair_id) || !empty($data)) && $update_alt_desc == true) {
                $image_ids = array();
                if (!empty($pair_id)) {
                    $image_ids = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id);
                }
                $image_ids = fn_array_merge($image_ids, $data);
                $fields = array('detailed', 'image');
                foreach ($fields as $field) {
                    if (!empty($image_ids[$field . '_id']) && isset($p_data[$field . '_alt'])) {
                        if (!is_array($p_data[$field . '_alt'])) {
                            $_data = array('description' => empty($p_data[$field . '_alt']) ? '' : trim($p_data[$field . '_alt']), 'object_holder' => 'images');
                            // check, if this is new record, create new descriptions for all languages
                            $is_exists = db_get_field('SELECT object_id FROM ?:common_descriptions WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $image_ids[$field . '_id'], $lang_code, 'images');
                            if (!$is_exists) {
                                fn_create_description('common_descriptions', 'object_id', $image_ids[$field . '_id'], $_data);
                            } else {
                                db_query('UPDATE ?:common_descriptions SET ?u WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $_data, $image_ids[$field . '_id'], $lang_code, 'images');
                            }
                        } else {
                            foreach ($p_data[$field . '_alt'] as $lc => $_v) {
                                $_data = array('object_id' => $image_ids[$field . '_id'], 'description' => empty($_v) ? '' : trim($_v), 'lang_code' => $lc, 'object_holder' => 'images');
                                db_query("REPLACE INTO ?:common_descriptions ?e", $_data);
                            }
                        }
                    }
                }
            }
            if (empty($data)) {
                continue;
            }
            // Pair is exists
            $data['position'] = !empty($p_data['position']) ? $p_data['position'] : 0;
            // set data position
            if (!empty($pair_id)) {
                db_query("UPDATE ?:images_links SET ?u WHERE pair_id = ?i", $data, $pair_id);
            } else {
                $data['type'] = $p_data['type'];
                // set link type
                $data['object_id'] = $o_id;
                // assign pair to object
                $data['object_type'] = $object_type;
                $pair_id = db_query("INSERT INTO ?:images_links ?e", $data);
            }
            $pairs_data[$k]['pair_id'] = $pair_id;
            $pair_ids[] = $pair_id;
        }
    }
    fn_set_hook('update_image_pairs', $pair_ids, $icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, $update_alt_desc, $lang_code);
    return $pair_ids;
}
示例#3
0
function fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id = 0, $object_type = 'product_lists', $object_ids = array(), $parent_object_type = '', $parent_object_id = 0, $update_alt_desc = true, $force_create_thumbnail = false, $lang_code = CART_LANGUAGE)
{
    $_otype = !empty($parent_object_type) ? $parent_object_type : $object_type;
    $thumbnail_width = Registry::get("settings.Thumbnails.{$_otype}_thumbnail_width");
    $thumbnail_height = Registry::get("settings.Thumbnails.{$_otype}_thumbnail_height");
    $thumbnail_bg_color = Registry::get('settings.Thumbnails.thumbnail_background_color');
    $pair_ids = $rev_data = array();
    $table = 'images_links';
    $itable = 'images';
    $cond = '';
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        if (!empty($_otype) && !empty($revisions['objects'][$_otype]) && !empty($revisions['objects'][$_otype]['tables'])) {
            $object_data = $revisions['objects'][$_otype];
            if ($object_data['images']) {
                $entry = array($object_data['key'] => !empty($parent_object_id) ? $parent_object_id : $object_id);
                list($revision, $revision_id) = fn_revisions_get_last($_otype, $entry, 0, $table);
                if (!empty($revision_id)) {
                    $table = 'rev_images_links';
                    $itable = 'rev_images';
                    $rev_data = array('revision' => $revision, 'revision_id' => $revision_id);
                    $cond = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
                }
            }
        }
    }
    if (!empty($pairs_data)) {
        foreach ($pairs_data as $k => $p_data) {
            $data = array();
            $pair_id = !empty($p_data['pair_id']) ? $p_data['pair_id'] : 0;
            $o_id = !empty($object_id) ? $object_id : (!empty($p_data['object_id']) ? $p_data['object_id'] : 0);
            if ($o_id == 0 && !empty($object_ids[$k])) {
                $o_id = $object_ids[$k];
            } elseif (!empty($object_ids) && empty($object_ids[$k])) {
                continue;
            }
            // Check if main pair is exists
            if (empty($pair_id) && $p_data['type'] == 'M') {
                $pair_data = db_get_row("SELECT pair_id, image_id, detailed_id FROM ?:{$table} WHERE object_id = ?i AND object_type = ?s AND type = ?s ?p", $o_id, $object_type, $p_data['type'], $cond);
                $pair_id = !empty($pair_data['pair_id']) ? $pair_data['pair_id'] : 0;
            } else {
                $pair_data = db_get_row("SELECT image_id, detailed_id FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
                if (empty($pair_data)) {
                    $pair_id = 0;
                }
            }
            // Update detailed image
            if (!empty($detailed[$k]) && !empty($detailed[$k]['size'])) {
                if (fn_get_image_size($detailed[$k]['path'])) {
                    // Create thumbnail if not exists
                    if ($force_create_thumbnail && empty($icons[$k]) && isset($thumbnail_width) && isset($thumbnail_height)) {
                        fn_create_thumbnail($icons[$k], $detailed[$k], $thumbnail_width, $thumbnail_height, $thumbnail_bg_color);
                    }
                    $data['detailed_id'] = fn_update_image($detailed[$k], !empty($pair_data['detailed_id']) ? $pair_data['detailed_id'] : 0, 'detailed', $rev_data);
                }
            }
            // Update icon
            if (!empty($icons[$k]) && !empty($icons[$k]['size'])) {
                //$tessss = fn_get_image_size($icons[$k]['path']);
                //var_dump($tessss);
                if (fn_get_image_size($icons[$k]['path'])) {
                    if ($force_create_thumbnail && Registry::get('settings.Thumbnails.resize_thumbnail') == 'Y' && isset($thumbnail_width) && isset($thumbnail_height)) {
                        fn_resize_image($icons[$k]['path'], $icons[$k]['path'], $thumbnail_width, $thumbnail_height, true, $thumbnail_bg_color);
                    }
                    $data['image_id'] = fn_update_image($icons[$k], !empty($pair_data['image_id']) ? $pair_data['image_id'] : 0, $object_type, $rev_data);
                }
            }
            // Update alt descriptions
            if ((empty($data) && !empty($pair_id) || !empty($data)) && $update_alt_desc == true) {
                $image_ids = array();
                if (!empty($pair_id)) {
                    $image_ids = db_get_row("SELECT image_id, detailed_id FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
                }
                $image_ids = fn_array_merge($image_ids, $data);
                if (!empty($image_ids['detailed_id'])) {
                    if (!is_array($p_data['detailed_alt'])) {
                        $p_data['detailed_alt'] = array($lang_code => $p_data['detailed_alt']);
                    }
                    foreach ($p_data['detailed_alt'] as $lc => $_v) {
                        fn_update_image_alt_text($image_ids['detailed_id'], $_v, $lc);
                    }
                }
                if (!empty($image_ids['image_id'])) {
                    if (!is_array($p_data['image_alt'])) {
                        $p_data['image_alt'] = array($lang_code => $p_data['image_alt']);
                    }
                    foreach ($p_data['image_alt'] as $lc => $_v) {
                        fn_update_image_alt_text($image_ids['image_id'], $_v, $lc);
                    }
                }
            }
            if (empty($data)) {
                continue;
            }
            if (!empty($revision_id)) {
                $data['revision_id'] = $revision_id;
                $data['revision'] = $revision;
            }
            // Pair is exists
            if (!empty($pair_id)) {
                db_query("UPDATE ?:{$table} SET ?u WHERE pair_id = ?i ?p", $data, $pair_id, $cond);
            } else {
                $data['type'] = $p_data['type'];
                // set link type
                $data['object_id'] = $o_id;
                // assign pair to object
                $data['object_type'] = $object_type;
                $pair_id = db_query("INSERT INTO ?:{$table} ?e", $data);
            }
            $pair_ids[] = $pair_id;
        }
    }
    //var_dump($pair_ids);
    return $pair_ids;
}