| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/backend-accounting.sk/app/modules/gallery/code/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace modules\gallery\code;
/**
* Description of Gallery
*
* @author maros
*/
class GalleryImage extends \app\classes\PDOElement {
/**
* @var Gallery $gallery
*/
private $gallery;
/**
* @var \app\classes\SimpleImage $simpleImage
*/
private $simpleImage;
public function __construct($id, &$gallery, $disabled = false) {
$this->gallery = $gallery;
parent::__construct($id, "gallery_images", array("gallery_id" => $this->gallery->_get("id"), "id" => $id, "state" => $disabled ? \app\constants\State::DELETED : \app\constants\State::ACTIVE), "id", ($disabled ? " state!=:state" : "state=:state") . " AND gallery_id=:gallery_id", false);
$this->simpleImage = new \app\classes\SimpleImage($this->getPath());
}
public function rename($name) {
$path_parts = pathinfo($this->_get("image"));
$fileType = $path_parts["extension"];
$newName = $this->_get("id") . "-" . stringToAddress($name) . "." . $fileType;
$prefix = $this->_get("id") . "-";
if (substr($this->_get("name"), 0, strlen($prefix)) === $prefix) {
$newName = substr($newName, strlen($prefix) - 1);
}
$rename = rename($this->gallery->getMainFolderPath(true) . $this->_get("image"), $this->gallery->getMainFolderPath(true) . $newName);
if ($rename) {
$this->update(array("image" => $newName));
return true;
}
return false;
}
public function getThumbPath($w = 0, $h = 0, $forceRemakeThumb = false) {
if ($w === 0 && $h === 0) {
$w = Gallery::THUMB_WIDTH;
$h = Gallery::THUMB_HEIGHT;
}
return \app\classes\SimpleImage::getThumbPath($this->getPath(), $w, $h, $forceRemakeThumb, $this->gallery->getMainFolderPath(), $this->gallery->getThumbsFolderPath(), Gallery::COMPRESSION_QUALITY);
}
public function getPath($root = false) {
return ($root ? "" : "/") . $this->gallery->getMainFolderPath($root) . $this->_get("image");
}
public function delete() {
parent::delete();
deleteFile($this->getPath(true));
$mainImage = $this->gallery->getMainImage();
if ($mainImage !== NULL) {
if (intval($mainImage->_get("id")) === intval($this->_get("id"))) {
$sort = $this->gallery->getImagesSort();
foreach ($sort as $item) {
if (intval($item["id"]) !== intval($this->_get("id"))) {
$this->gallery->update(array("main_image" => $item["id"]));
break;
}
}
}
}
}
public static function newImage(&$gallery, $name, $image, $description, $state) {
$db = \app\classes\PDODatabase::getInstance();
$db->addRecord("gallery_images", array(
"name" => $name,
"image" => $image,
"description" => $description,
"state" => $state,
"gallery_id" => $gallery->_get("id")
));
$img = new GalleryImage($db->getLastInsertId(), $gallery);
return $img;
}
public function getWidth() {
return $this->simpleImage->getWidth();
}
public function getHeight() {
return $this->simpleImage->getHeight();
}
}