Skip to content

Commit

Permalink
Merge pull request #76 from philippebeck/dev
Browse files Browse the repository at this point in the history
Release 3.3.2
  • Loading branch information
philippebeck authored Jun 11, 2020
2 parents 7e18b88 + e720da2 commit b77b951
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 39 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "philippebeck/pam",
"version": "3.3.1",
"version": "3.3.2",
"type": "library",
"description": "Php Approachable Microframework",
"keywords": [
Expand Down Expand Up @@ -37,7 +37,7 @@
"ext-exif": "*"
},
"require-dev": {
"tracy/tracy": "^2.7.2"
"tracy/tracy": "^2.7.5"
},
"config": {
"platform": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 45 additions & 36 deletions core/Controller/Globals/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public function getFileVar(string $var)
return $this->file[$var];
}

/**
* @param string $fileDir
* @param string|null $fileName
* @return string
*/
public function setFileName(string $fileDir, string $fileName = null)
{
if ($fileName === null) {

return $fileDir . $this->file["name"];
}

return $fileDir . $fileName . $this->setFileExtension();
}

/**
* @return string
*/
Expand All @@ -57,20 +72,21 @@ public function setFileExtension()
try {
switch ($this->file["type"]) {
case "image/jpeg":
$fileExt = ".jpg";
return ".jpg";
break;

case "image/png":
$fileExt = ".png";
return ".png";
break;

case "image/gif":
$fileExt = ".gif";
return ".gif";
break;

default:
throw new Exception("Image Type not Set...");
throw new Exception("The File Type : " . $this->file["type"] . " is not accepted...");
}

return $fileExt;

} catch (Exception $e) {

return $e->getMessage();
Expand All @@ -84,12 +100,6 @@ public function setFileExtension()
*/
public function uploadFile(string $fileDir, string $fileName = null, int $fileSize = 50000000)
{
if ($fileName === null) {
$dest = $fileDir . $this->file["name"];
} else {
$dest = $fileDir . $fileName . $this->setFileExtension();
}

try {
if (!isset($this->file["error"]) || is_array($this->file["error"])) {
throw new Exception("Invalid parameters...");
Expand All @@ -99,7 +109,7 @@ public function uploadFile(string $fileDir, string $fileName = null, int $fileSi
throw new Exception("Exceeded filesize limit...");
}

if (!move_uploaded_file($this->file["tmp_name"], $dest)) {
if (!move_uploaded_file($this->file["tmp_name"], $this->setFileName($fileDir, $fileName))) {
throw new Exception("Failed to move uploaded file...");
}

Expand All @@ -126,29 +136,29 @@ public function getImageType(string $img)
}

/**
* @param int $imgType
* @param string $imgSrc
* @param string $img
* @return false|resource|string
*/
public function createImage(int $imgType, string $imgSrc)
public function createImage(string $img)
{
try {
switch ($imgType) {
switch ($this->getImageType($img)) {
case IMAGETYPE_JPEG:
$imgCreated = imagecreatefromjpeg($imgSrc);
return imagecreatefromjpeg($img);
break;

case IMAGETYPE_PNG:
$imgCreated = imagecreatefrompng($imgSrc);
return imagecreatefrompng($img);
break;

case IMAGETYPE_GIF:
$imgCreated = imagecreatefromgif($imgSrc);
return imagecreatefromgif($img);
break;

default:
throw new Exception("Image Type not accepted to Create the Image...");
}

return $imgCreated;

} catch (Exception $e) {

return $e->getMessage();
Expand All @@ -166,42 +176,41 @@ public function outputImage(int $imgType, $imgSrc, string $imgDest)
try {
switch ($imgType) {
case IMAGETYPE_JPEG:
$isOutput = imagejpeg($imgSrc, $imgDest);
return imagejpeg($imgSrc, $imgDest);
break;

case IMAGETYPE_PNG:
$isOutput = imagepng($imgSrc, $imgDest);
return imagepng($imgSrc, $imgDest);
break;

case IMAGETYPE_GIF:
$isOutput = imagegif($imgSrc, $imgDest);
return imagegif($imgSrc, $imgDest);
break;

default:
throw new Exception("Image Type not accepted to Output the Image...");
}

return $isOutput;

} catch (Exception $e) {

return $e->getMessage();
}
}

/**
* @param string $imgSrc
* @param int $tnWidth
* @param string|null $imgDest
* @param string $img
* @param int $width
* @param string|null $thumbnail
* @return bool|string
*/
public function makeThumbnail(string $imgSrc, int $tnWidth = 300, string $thumbnail = null)
public function makeThumbnail(string $img, int $width = 300, string $thumbnail = null)
{
if ($thumbnail === null) {
$thumbnail = $imgSrc;
$thumbnail = $img;
}

$imgType = $this->getImageType($imgSrc);
$imgCreated = $this->createImage($imgType, $imgSrc);
$imgScaled = imagescale($imgCreated, $tnWidth);
$imgScaled = imagescale($this->createImage($img), $width);

return $this->outputImage($imgType, $imgScaled, $thumbnail);
return $this->outputImage($this->getImageType($img), $imgScaled, $thumbnail);
}
}
16 changes: 16 additions & 0 deletions core/Controller/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ public function cleanString(string $string, bool $isLow = true)
return $string;
}

/**
* @param array $array
* @param string $key
* @return array
*/
public function getArrayElements(array $array, string $key = "category")
{
$elements = [];

foreach ($array as $element) {
$elements[$element[$key]][] = $element;
}

return $elements;
}

/**
* @param string $page
* @param array $params
Expand Down

0 comments on commit b77b951

Please sign in to comment.