Back to PhocaGalleryFileFolder class

Method cleanThumbsFolder

public static
cleanThumbsFolder
()

Method cleanThumbsFolder - Source code

/*
 * Clear Thumbs folder - if there are files in the thumbs directory but not original files e.g.:
 * phoca_thumbs_l_some.jpg exists in thumbs directory but some.jpg doesn't exists - delete it
 */
public static function cleanThumbsFolder()
{
    //Get folder variables from Helper
    $path = PhocaGalleryPath::getPath();
    // Initialize variables
    $pathOrigImg = $path->image_abs;
    $pathOrigImgServer = str_replace('\\', '/', $path->image_abs);
    // Get the list of files and folders from the given folder
    $fileList = Folder::files($pathOrigImg, '', true, true);
    // Iterate over the files if they exist
    if ($fileList !== false) {
        foreach ($fileList as $file) {
            if (File::exists($file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                //Clean absolute path
                $file = str_replace('\\', '/', Path::clean($file));
                $positions = strpos($file, "phoca_thumb_s_");
                //is there small thumbnail
                $positionm = strpos($file, "phoca_thumb_m_");
                //is there medium thumbnail
                $positionl = strpos($file, "phoca_thumb_l_");
                //is there large thumbnail
                //Clean small thumbnails if original file doesn't exist
                if ($positions === false) {
                } else {
                    $filenameThumbs = $file;
                    //only thumbnails will be listed
                    $fileNameOrigs = str_replace('thumbs/phoca_thumb_s_', '', $file);
                    //get fictive original files
                    //There is Thumbfile but not Originalfile - we delete it
                    if (File::exists($filenameThumbs) && !File::exists($fileNameOrigs)) {
                        File::delete($filenameThumbs);
                    }
                    //  Reverse
                    //  $filenameThumb = PhocaGalleryHelper::getTitleFromFilenameWithExt($file);
                    //	$fileNameOriginal = PhocaGalleryHelper::getTitleFromFilenameWithExt($file);
                    //	$filenameThumb = str_replace ($fileNameOriginal, 'thumbs/phoca_thumb_m_' . $fileNameOriginal, $file);
                }
                //Clean medium thumbnails if original file doesn't exist
                if ($positionm === false) {
                } else {
                    $filenameThumbm = $file;
                    //only thumbnails will be listed
                    $fileNameOrigm = str_replace('thumbs/phoca_thumb_m_', '', $file);
                    //get fictive original files
                    //There is Thumbfile but not Originalfile - we delete it
                    if (File::exists($filenameThumbm) && !File::exists($fileNameOrigm)) {
                        File::delete($filenameThumbm);
                    }
                }
                //Clean large thumbnails if original file doesn't exist
                if ($positionl === false) {
                } else {
                    $filenameThumbl = $file;
                    //only thumbnails will be listed
                    $fileNameOrigl = str_replace('thumbs/phoca_thumb_l_', '', $file);
                    //get fictive original files
                    //There is Thumbfile but not Originalfile - we delete it
                    if (File::exists($filenameThumbl) && !File::exists($fileNameOrigl)) {
                        File::delete($filenameThumbl);
                    }
                }
            }
        }
    }
}