Пример #1
0
function fn_delete_image($image_id, $pair_id, $object_type = 'product')
{
    if (AREA == 'A' && fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id') && $object_type == 'category') {
        return false;
    }
    $_image_file = db_get_field("SELECT image_path FROM ?:images WHERE image_id = ?i", $image_id);
    if (empty($_image_file)) {
        return false;
    }
    fn_set_hook('delete_image_pre', $image_id, $pair_id, $object_type);
    db_query("UPDATE ?:images_links SET " . ($object_type == 'detailed' ? 'detailed_id' : 'image_id') . " = '0' WHERE pair_id = ?i", $pair_id);
    $_ids = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id);
    if (empty($_ids['image_id']) && empty($_ids['detailed_id'])) {
        db_query("DELETE FROM ?:images_links WHERE pair_id = ?i", $pair_id);
    }
    if (fn_get_count_image_link($image_id) == 0) {
        $img_id_subdir = floor($image_id / MAX_FILES_IN_DIR);
        $_image_file = $object_type . '/' . $img_id_subdir . '/' . $_image_file;
        Storage::instance('images')->delete($_image_file);
        db_query("DELETE FROM ?:images WHERE image_id = ?i", $image_id);
        db_query("DELETE FROM ?:common_descriptions WHERE object_id = ?i AND object_holder = 'images'", $image_id);
        // Clear all existing thumbnails
        fn_delete_image_thumbnails($_image_file);
    }
    fn_set_hook('delete_image', $image_id, $pair_id, $object_type, $_image_file);
    return true;
}
Пример #2
0
/**
 * Delete watermarked images before deleteing image pair
 *
 * @param int $image_id Image identifier
 * @param int $pair_id Pair identifier
 * @param string $object_type Object type
 * @param string $image_file Deleted image file
 * @return boolean Always true
 */
function fn_watermarks_delete_image(&$image_id, &$pair_id, &$object_type, &$image_file)
{
    $dir = WATERMARKS_DIR_NAME;
    if (fn_allowed_for('ULTIMATE')) {
        $dir = 'watermarked/*/';
    }
    fn_delete_image_thumbnails($image_file, $dir);
    return true;
}