HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/fickanzeiger/models/PhotoModel.php
<?php
/**
 * Arfooo
 * 
 * @package    Arfooo
 * @copyright  Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en)
 *             by Guillaume Hocine (c) 2007 - 2010
 *             http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en)
 * @author     Guillaume Hocine & Adrian Galewski
 * @license    http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons
 */


class PhotoModel extends Model
{
    protected $primaryKey = "photoId";

    function getFields()
    {
        return $this->fields;
    }

    function getItemPhotos($itemId)
    {
        $c = new Criteria();
        $c->add("itemId", $itemId);
        $c->addOrder("photoId");

        return $this->findAll($c, "photoId, src, altText");
    }

    function getSitePhotosCount($itemId, $tempId = null)
    {
        $c = new Criteria();

        if ($tempId) {
            $c->add("tempId", $tempId);
        } else {
            $c->add("itemId", $itemId);
        }

        return $this->getCount($c);
    }

    function deleteFileIfExists($filePath)
    {
        if (file_exists($filePath)) {
            unlink($filePath);
        }
    }

    function deleteSitePhotoFiles($src)
    {
        if (empty($src)) {
            return;
        }

        $dirPath = Config::get("SITES_THUMBS_PATH") . UploadedFile::fileNameToPath($src);

        $this->deleteFileIfExists($dirPath . "s" . $src);
        $this->deleteFileIfExists($dirPath . "m" . $src);
        $this->deleteFileIfExists($dirPath . "n" . $src);
        $this->deleteFileIfExists($dirPath . $src);
    }
    
    function removeExpiredTempPhotos()
    {
        $c = new Criteria();
        $c->add('tempId IS NOT NULL');
        $c->add('addDate < DATE_SUB(NOW(), INTERVAL 24 HOUR)');
        
        $photos = $this->findAll($c, 'photoId, src', true);
        
        foreach ($photos as $photo) {
            $photo->del(false);
        }
    }
}

class PhotoRecord extends ModelRecord
{
    function deletePhotoFiles()
    {
        Model::factoryInstance("photo")->deleteSitePhotoFiles($this->src);
    }

    function del($updateItemPhotos = true)
    {
        $this->deletePhotoFiles();
        parent::del();

        if ($updateItemPhotos && $this->itemId) {
            Model::factoryInstance("site")->findByPk($this->itemId)->updatePhotos();
        }
    }

    function save()
    {
        parent::save();

        if ($this->itemId) {
            Model::factoryInstance("site")->findByPk($this->itemId)->updatePhotos();
        }
        
        if (rand(1, 10) <= 1) {
            Model::factoryInstance("photo")->removeExpiredTempPhotos();
        }
    }
}