197 lines
7.0 KiB
PHP
197 lines
7.0 KiB
PHP
<?php
|
|
|
|
// inclusione del file contenente la classe
|
|
require_once "./include.php";
|
|
require_once "./myDropBoxObj.php";
|
|
|
|
use PHPImageWorkshop\ImageWorkshop;
|
|
|
|
require_once 'PHPImageWorkshop/ImageWorkshop.php'; // Be sure of the path to the class
|
|
//include "./SimpleImage.php";
|
|
|
|
$app->get('/photo/publish/:imageID', function ($imageID) use ($app) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$query = "update immagini set published = 1, published_date = NOW() where id = " . $imageID;
|
|
|
|
$mysqlconnetion->insertRecord($query);
|
|
$mysqlconnetion->disconnetti();
|
|
});
|
|
|
|
$app->get('/photo/set_cover/:imageID', function ($imageID) use ($app) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$query = "select id_ricette from immagini where id = " . $imageID;
|
|
$retObj = $mysqlconnetion->queryToObject($query, false);
|
|
|
|
$query = "update immagini set bCover = 0 where id_ricette = " . $retObj["id_ricette"];
|
|
$mysqlconnetion->insertRecord($query);
|
|
|
|
$query = "update immagini set bCover = 1 where id = " . $imageID;
|
|
$mysqlconnetion->insertRecord($query);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
});
|
|
|
|
$app->delete('/photo/:imageID', function ($imageID) use ($app,$dirRicetteDropBox) {
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$query = "select id_ricette, type_format from immagini where id = " . $imageID;
|
|
$retObj = $mysqlconnetion->queryToObject($query, false);
|
|
|
|
$ext = "";
|
|
if ($retObj["type_format"] == "image/jpeg") {
|
|
$ext = "jpeg";
|
|
} else if ($retObj["type_format"] == "image/png") {
|
|
$ext = "png";
|
|
}
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
|
|
$imageFileName = $imageID . "_medium_ricetta." . $ext;
|
|
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
|
|
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
|
|
$query = "delete from immagini where id = " . $imageID;
|
|
$mysqlconnetion->executeQuery($query);
|
|
$mysqlconnetion->disconnetti();
|
|
});
|
|
|
|
$app->post('/photo', function () use ($app, $dirRicetteDropBox) {
|
|
$idRicette = $app->request()->post('ricetta_id');
|
|
$profileID = $app->request()->post('keyStore');
|
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
// istanza della classe
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconneti on->connetti();
|
|
$query = "insert into immagini(id_ricette, type_format, from_profile_id, uploaded_date, bCover) " .
|
|
"values(" . $idRicette . ", '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
|
"', '" . $profileID . "', NOW(), 0)";
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
$ext = image_type_to_extension(exif_imagetype($tmpFileName), FALSE);
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
|
$imageFileName = $newID . "_full_ricetta." . $ext;
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$full_link = resizeImage($dropBoxObj, $layer, 640, dirname($tmpFileName), $imageFileName, $folder);
|
|
|
|
$imageMediumFileName = $newID . "_medium_ricetta." . $ext;
|
|
|
|
$medium_link = resizeImage($dropBoxObj, $layer, 320, dirname($tmpFileName), $imageMediumFileName, $folder);
|
|
|
|
$thumbFileName = $newID . "_thumb_ricetta." . $ext;
|
|
|
|
$thumb_link = makeThumbImage($dropBoxObj, $layer, 80, dirname($tmpFileName), $thumbFileName, $folder);
|
|
|
|
$query = "update immagini set thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."'" .
|
|
" where id=" . $newID;
|
|
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
echo $newID;
|
|
});
|
|
|
|
$app->put('/photo/:imageID', function ($imageID) use ($app, $dirRicetteDropBox) {
|
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
// istanza della classe
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconneti on->connetti();
|
|
|
|
$folder = $dirRicetteDropBox . "/" . $imageID;
|
|
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
|
|
$full_link = resizeImage($dropBoxObj, $layer, 640, dirname($tmpFileName), $imageFileName, $folder);
|
|
|
|
$imageMediumFileName = $imageID . "_medium_ricetta." . $ext;
|
|
|
|
$medium_link = resizeImage($dropBoxObj, $layer, 320, dirname($tmpFileName), $imageMediumFileName, $folder);
|
|
|
|
$thumbFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
|
|
$thumb_link = makeThumbImage($dropBoxObj, $layer, 80, dirname($tmpFileName), $thumbFileName, $folder);
|
|
|
|
$query = "update immagini set (type_format = '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
|
"', thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."' )" .
|
|
" where id=" . $imageID;
|
|
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
return $newID;
|
|
});
|
|
|
|
$app->get('/photo/fixLink', function () use ($app, $dirRicetteDropBox) {
|
|
ini_set('max_execution_time', 3000);
|
|
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$retObj2 = $mysqlconnetion->queryToObject("select type_format, id, id_ricette, thumb_link, medium_link, full_link from immagini where published = 1");
|
|
|
|
|
|
foreach ($retObj2 as $retObj) {
|
|
|
|
$imageID = $retObj["id"];
|
|
|
|
$ext = "";
|
|
if ($retObj["type_format"] == "image/jpeg") {
|
|
$ext = "jpeg";
|
|
} else if ($retObj["type_format"] == "image/png") {
|
|
$ext = "png";
|
|
}
|
|
|
|
$full_link = $retObj["full_link"];
|
|
|
|
if($full_link == ""){
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
|
|
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$full_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
}
|
|
|
|
$medium_link = $retObj["medium_link"];
|
|
|
|
if($medium_link == ""){
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
|
|
$imageFileName = $imageID . "_medium_ricetta." . $ext;
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$medium_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
}
|
|
|
|
$thumb_link = $retObj["thumb_link"];
|
|
|
|
if($thumb_link == ""){
|
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
|
|
$imageFileName = $imageID . "_thumb_ricetta.png";
|
|
|
|
$dropBoxObj = new myDropBox();
|
|
|
|
$thumb_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
}
|
|
|
|
$query = "update immagini set thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."'" .
|
|
" where id=" . $imageID;
|
|
|
|
$newID = $mysqlconnetion->insertRecord($query);
|
|
}
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
}); |