コード例 #1
0
ファイル: fn.fs.php プロジェクト: diedsmiling/busenika
/**
 * Remove temporary files
 */
function fn_remove_temp_data()
{
    $fs_data = Registry::get('temp_fs_data');
    if (!empty($fs_data)) {
        foreach ($fs_data as $file) {
            fn_delete_file($file);
        }
    }
}
コード例 #2
0
ファイル: fn.images.php プロジェクト: diedsmiling/busenika
function fn_delete_image($image_id, $pair_id, $object_type = 'product', $rev_data = array())
{
    $table = 'images_links';
    $itable = 'images';
    $cond = '';
    $path = DIR_IMAGES . $object_type . '/';
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        $_img_data = db_get_row("SELECT object_type, object_id FROM ?:rev_images_links WHERE pair_id = ?i ORDER BY revision DESC LIMIT 1", $pair_id);
        if (!empty($_img_data['object_type']) && !empty($revisions['objects'][$_img_data['object_type']]) && !empty($revisions['objects'][$_img_data['object_type']]['tables'])) {
            $object_data = $revisions['objects'][$_img_data['object_type']];
            if ($object_data['images']) {
                if (empty($rev_data)) {
                    $entry = array($object_data['key'] => $_img_data['object_id']);
                    list($revision, $revision_id) = fn_revisions_get_last($_img_data['object_type'], $entry, 0, $itable);
                } else {
                    $revision = $rev_data['revision'];
                    $revision_id = $rev_data['revision_id'];
                }
                if (!empty($revision_id)) {
                    $table = 'rev_images_links';
                    $itable = 'rev_images';
                    $cond = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
                    $path = DIR_IMAGES . $object_type . '_rev/';
                }
            }
        }
    }
    $path .= floor($image_id / MAX_FILES_IN_DIR) . "/";
    $_image_file = db_get_field("SELECT image_path FROM ?:{$itable} WHERE image_id = ?i ?p", $image_id, $cond);
    if (!empty($_image_file)) {
        if (!empty($revision_id)) {
            $use_count = db_get_field("SELECT COUNT(image_path) FROM ?:{$itable} WHERE image_id = ?i AND image_path = ?s", $image_id, $_image_file);
            if ($use_count == 1) {
                fn_delete_file($path . $_image_file);
            }
        } else {
            fn_delete_file($path . $_image_file);
        }
    }
    $dir_content = fn_get_dir_contents($path, true, true);
    if (empty($dir_content)) {
        fn_rm($path);
    }
    db_query("DELETE FROM ?:{$itable} WHERE image_id = ?i ?p", $image_id, $cond);
    db_query("DELETE FROM ?:common_descriptions WHERE object_id = ?i AND object_holder = 'images'", $image_id);
    db_query("UPDATE ?:{$table} SET " . ($object_type == 'detailed' ? 'detailed_id' : 'image_id') . " = '0' WHERE pair_id = ?i ?p", $pair_id, $cond);
    $_ids = db_get_row("SELECT image_id, detailed_id FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
    if (empty($_ids['image_id']) && empty($_ids['detailed_id'])) {
        db_query("DELETE FROM ?:{$table} WHERE pair_id = ?i ?p", $pair_id, $cond);
    }
    return true;
}