-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from philippebeck/dev
Release 4.2.0
- Loading branch information
Showing
6 changed files
with
138 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Pam\View; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* Class MainExtension | ||
* @package Pam\View | ||
*/ | ||
class MainExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @return array|TwigFunction[] | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return array( | ||
new TwigFunction("url", array($this, "url")), | ||
new TwigFunction("redirect", array($this, "redirect")) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $page | ||
* @param array $params | ||
* @return string | ||
*/ | ||
public function url(string $page, array $params = []) | ||
{ | ||
$params["access"] = $page; | ||
|
||
return "index.php?" . http_build_query($params); | ||
} | ||
|
||
/** | ||
* @param string $page | ||
* @param array $params | ||
*/ | ||
public function redirect(string $page, array $params = []) | ||
{ | ||
header("Location: " . $this->url($page, $params)); | ||
|
||
exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Pam\View; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* Class ServiceExtension | ||
* @package Pam\View | ||
*/ | ||
class ServiceExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var mixed|null | ||
*/ | ||
private $session = null; | ||
|
||
/** | ||
* Service Extension constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->session = filter_var_array($_SESSION); | ||
} | ||
|
||
/** | ||
* @return array|TwigFunction[] | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return array( | ||
new TwigFunction("cleanString", array($this, "cleanString")), | ||
new TwigFunction("checkIsAdmin", array($this, "checkIsAdmin")) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @return string | ||
*/ | ||
public function cleanString(string $string) | ||
{ | ||
$string = str_replace("_", " ", $string); | ||
|
||
return ucwords($string); | ||
} | ||
|
||
public function checkIsAdmin() | ||
{ | ||
$isAdmin = false; | ||
|
||
if (isset($session["user"]["admin"])) { | ||
if ($this->session["admin"] === true || $this->session["admin"] === 1) { | ||
$isAdmin = true; | ||
} | ||
|
||
} elseif (isset($session["user"]["role"])) { | ||
if ($this->session["role"] === 1 || $this->session["role"] === "admin") { | ||
$isAdmin = true; | ||
} | ||
} | ||
|
||
return $isAdmin; | ||
} | ||
} |