| Server IP : 162.214.74.102 / Your IP : 216.73.217.103 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_apps/regional/application/plugins/module_cms/models/ |
Upload File : |
<?php
include_once __DIR__ . "/../../../autoload/My_Model.php";
include_once __DIR__ . "/../factories/ImageFactory.php";
class ImageModel extends My_Model
{
/**
* @var string
*/
public $table = 'module_cms_image';
/**
* @var string $uploadDir
*/
protected $uploadDir;
/**
* @var Uploader $uploader
*/
protected $uploader;
/**
* @var $_L
*/
protected $_L;
public function __construct($_L = null)
{
$this->_L = $_L;
$this->uploadDir = "application/plugins/module_cms/assets/imgs/uploads/";
$this->uploader = new Uploader();
$this->uploader->setDir($this->uploadDir);
$this->uploader->sameName(false);
$this->uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif'));
}
public function upload()
{
if ($this->uploader->uploadFile('file')) {
$uploaded = $this->uploadDir . $this->uploader->getUploadName();
$msg = $this->_L['Uploaded Successfully'];
$file = $uploaded;
$success = true;
$imgCreated = $this->createImage(['path' => $uploaded]);
$imageId = $imgCreated->id;
list($width, $height, $type, $attr) = getimagesize($uploaded);
$image = new Image();
$image->source_path = $this->uploadDir . $uploaded;
$image->target_path = $this->uploadDir . $uploaded;
//verifica se precisa redimensionar
if ($width > $height && $width > 800) {
$image->resize(800);
} else if ($height > $width && $height > 800) {
$image->resize(null, 800);
}
} else {
$file = '';
$msg = $this->uploader->getMessage();
$success = false;
$imageId = 0;
}
return [
'id' => $imageId,
'msg' => $msg,
'file' => $file,
'filelink' => $file,
'success' => $success,
];
}
/**
* @param array $data
* @return bool|ORM
*/
public function createImage($data)
{
$image = self::create();
ImageFactory::create($data, $image, true);
$image->save();
return $image;
}
/**
* @param array $data
* @param ORM $image
* @return bool|ORM
*/
public function updateImage($data, $image)
{
ORM::for_table($this->table)->create($image);
ImageFactory::create($data, $image);
$image->save();
return $image;
}
/**
* @return bool|ORM
*/
public function deleteImage()
{
$id = _post('id');
$image = $this->getOne($id);
if ($image) {
$image->delete();
unlink($image->path);
$msg = $this->_L['CMS_Image_Deleted_Successfully'];
$status = 'OK';
} else {
$msg = $this->_L['CMS_Not_found'];
$status = 'ERROR';
}
return [
'status' => $status,
'msg' => $msg,
];
}
}