Skip to content

Commit

Permalink
Merge pull request #107 from devsagency/dev
Browse files Browse the repository at this point in the history
Release 4.7.2
  • Loading branch information
philippebeck authored Apr 23, 2021
2 parents f0be5af + 45e5edf commit 5a36a9d
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 76 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devsagency/pam",
"version": "4.7.1",
"version": "4.7.2",
"type": "library",
"description": "Php Adaptive Microframework",
"keywords": [
Expand Down
7 changes: 5 additions & 2 deletions core/Controller/Globals/CookieManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public function getCookieVar(string $var)
* @param int $expire
* @return mixed|void
*/
public function createCookie(string $name, string $value = "", int $expire = 0)
{
public function createCookie(
string $name,
string $value = "",
int $expire = 0
) {
if ($expire === 0) {
$expire = time() + 3600;
}
Expand Down
23 changes: 18 additions & 5 deletions core/Controller/Globals/FilesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function setFileExtension()
break;

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

} catch (Exception $e) {
Expand All @@ -106,18 +108,29 @@ public function setFileExtension()
* @param string|null $fileName
* @return mixed|string
*/
public function uploadFile(string $fileDir, string $fileName = null, int $fileSize = 50000000)
{
public function uploadFile(
string $fileDir,
string $fileName = null,
int $fileSize = 50000000
) {
try {
if (!isset($this->file["error"]) || is_array($this->file["error"])) {
if (
!isset($this->file["error"])
|| is_array($this->file["error"])
) {
throw new Exception("Invalid parameters...");
}

if ($this->file["size"] > $fileSize) {
throw new Exception("Exceeded filesize limit...");
}

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

Expand Down
50 changes: 38 additions & 12 deletions core/Controller/Service/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function inputImage(string $img)
break;

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

return $imgInput;
Expand All @@ -70,8 +72,11 @@ public function inputImage(string $img)
* @param string $imgDest
* @return bool|string
*/
public function outputImage($imgSrc, int $imgType, string $imgDest)
{
public function outputImage(
$imgSrc,
int $imgType,
string $imgDest
) {
try {
switch ($imgType) {
case IMAGETYPE_BMP:
Expand All @@ -95,7 +100,9 @@ public function outputImage($imgSrc, int $imgType, string $imgDest)
break;

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

return $imgOutput;
Expand All @@ -112,8 +119,11 @@ public function outputImage($imgSrc, int $imgType, string $imgDest)
* @param string $imgDest
* @return bool|string
*/
public function convertImage(string $imgSrc, string $imgType, string $imgDest)
{
public function convertImage(
string $imgSrc,
string $imgType,
string $imgDest
) {
try {
switch ($imgType) {
case ".bmp":
Expand All @@ -138,10 +148,16 @@ public function convertImage(string $imgSrc, string $imgType, string $imgDest)
break;

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

return $this->outputImage($this->inputImage($imgSrc), $imgType, $imgDest);
return $this->outputImage(
$this->inputImage($imgSrc),
$imgType,
$imgDest
);

} catch (Exception $e) {

Expand All @@ -155,14 +171,24 @@ public function convertImage(string $imgSrc, string $imgType, string $imgDest)
* @param string|null $thumbnail
* @return bool|string
*/
public function makeThumbnail(string $img, int $width = 300, string $thumbnail = null)
{
public function makeThumbnail(
string $img,
int $width = 300,
string $thumbnail = null
) {
if ($thumbnail === null) {
$thumbnail = $img;
}

$imgScaled = imagescale($this->inputImage($img), $width);
$imgScaled = imagescale(
$this->inputImage($img),
$width
);

return $this->outputImage($imgScaled, $this->getImageType($img), $thumbnail);
return $this->outputImage(
$imgScaled,
$this->getImageType($img),
$thumbnail
);
}
}
5 changes: 4 additions & 1 deletion core/Controller/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public function sendMessage(array $mail)
$message = (new Swift_Message())
->setSubject($mail["subject"])
->setFrom([MAIL_FROM => MAIL_USERNAME])
->setTo([MAIL_TO => MAIL_USERNAME, $mail["email"] => $mail["name"]])
->setTo(
[MAIL_TO => MAIL_USERNAME,
$mail["email"] => $mail["name"]]
)
->setBody($mail["message"])
;

Expand Down
25 changes: 19 additions & 6 deletions core/Controller/Service/SecurityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ public function checkRecaptcha(string $response)
$recaptcha = new ReCaptcha(RECAPTCHA_TOKEN);

$result = $recaptcha
->setExpectedHostname($this->getServer()->getServerVar("SERVER_NAME"))
->verify($response, $this->getServer()->getServerVar("REMOTE_ADDR"));
->setExpectedHostname(
$this->getServer()->getServerVar("SERVER_NAME")
)
->verify(
$response,
$this->getServer()->getServerVar("REMOTE_ADDR")
);

return $result->isSuccess();
}
Expand All @@ -35,12 +40,18 @@ public function checkIsAdmin()
$isAdmin = false;

if (isset($session["user"]["admin"])) {
if ($this->getSession()->getUserVar("admin") === true || $this->getSession()->getUserVar("admin") === 1) {
if (
$this->getSession()->getUserVar("admin") === true
|| $this->getSession()->getUserVar("admin") === 1
) {
$isAdmin = true;
}

} elseif (isset($session["user"]["role"])) {
if ($this->getSession()->getUserVar("role") === 1 || $this->getSession()->getUserVar("role") === "admin") {
if (
$this->getSession()->getUserVar("role") === 1
|| $this->getSession()->getUserVar("role") === "admin"
) {
$isAdmin = true;
}

Expand All @@ -51,8 +62,10 @@ public function checkIsAdmin()
}

if ($isAdmin === false) {
$this->getSession()->createAlert("You must be logged in as Admin to access to the administration", "black");

$this->getSession()->createAlert(
"You must be logged in as Admin to access to the administration",
"black"
);
}

return $isAdmin;
Expand Down
Loading

0 comments on commit 5a36a9d

Please sign in to comment.