Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are not deleted when deleting a page #109

Open
SeditioCMS opened this issue Dec 10, 2024 · 1 comment
Open

Images are not deleted when deleting a page #109

SeditioCMS opened this issue Dec 10, 2024 · 1 comment

Comments

@SeditioCMS
Copy link

When we delete a page, the images in pfs, datas/users, datas/resize and datas/thumbs are not deleted, they need to be deleted when the page is deleted.

If these images are not deleted, they take up unnecessary space on the web.

@SeditioCMS
Copy link
Author

SeditioCMS commented Dec 10, 2024

To fix this find below page.edit.inc.php
$sql1 = sed_sql_query("SELECT page_cat, page_state, page_ownerid FROM $db_pages WHERE page_id='$id' LIMIT 1");

Replace with below.
$sql1 = sed_sql_query("SELECT page_cat, page_state, page_ownerid, page_thumb FROM $db_pages WHERE page_id='$id' LIMIT 1");

Find below
$id2 = "p".$id;

Add Below

// ---------- Page thumb
$page_thumbs_array = array();

if (!empty($row1['page_thumb'])) {
    // Sondaki gereksiz ";" işaretini kaldır
    $page_thumbs_array = rtrim($row1['page_thumb']);
    if ($page_thumbs_array[mb_strlen($page_thumbs_array) - 1] == ';') {
        $page_thumbs_array = mb_substr($page_thumbs_array, 0, -1);
    }

    // ";" ile ayrılmış dosyaları diziye çevir
    $page_thumbs_array = explode(";", $page_thumbs_array);

    if (count($page_thumbs_array) > 0) {
        foreach ($page_thumbs_array as $thumb) {
            // Desteklenen resim uzantılarını kontrol et
            $valid_extensions = array('jpg', 'jpeg', 'png', 'gif', 'webp');
            $extension = pathinfo($thumb, PATHINFO_EXTENSION);
            $basename = pathinfo($thumb, PATHINFO_FILENAME); // Uzantıdan önceki dosya adı

            if (in_array(strtolower($extension), $valid_extensions)) {
                // Orijinal dosya adını "resize800x480" ekleyerek oluştur
                $resized_thumb = $basename . ".resize800x480." . $extension;

                // Klasör yollarını belirle
                $paths = array(
                    "datas/users/" . $thumb,
                    "datas/thumbs/" . $thumb,
                    "datas/resized/" . $resized_thumb, // Resized uzantılı dosya
                );

                // Dosya yollarını kontrol ederek sil
                foreach ($paths as $path) {
                    if (file_exists($path)) {
                        if (!unlink($path)) {
                            error_log("Dosya silinemedi: " . $path);
                        }
                    } /*else {
                        error_log("Dosya bulunamadı: " . $path);
                    }*/
                }
            } else {
                error_log("Geçersiz dosya uzantısı: " . $thumb);
            }
			$sql = sed_sql_query("DELETE FROM $db_pfs WHERE pfs_file='$thumb'");
        }
    }
}

save close.

With this process, we will delete the pages in the directory and the images that were not deleted.

Important Note: Traces of deleted files remain in PFS.

Edit: Added cleaning of PFS leftovers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant