Skip to content

Commit

Permalink
Fix für #579 (#618)
Browse files Browse the repository at this point in the history
* Fix for #579
* Fix documentation and typos in comments
  • Loading branch information
hhunderter authored Jan 5, 2023
1 parent b581207 commit 7e54e1e
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 153 deletions.
117 changes: 68 additions & 49 deletions application/libraries/Ilch/Design/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Ilch\Design;

use Ilch\Layout\Helper\GetMedia;
use Ilch\Request;
use Ilch\Router;
use Ilch\Translator;
Expand All @@ -24,32 +25,34 @@ abstract class Base
*
* @var string
*/
private $layoutKey;
private $layoutKey = '';

/**
* Box url that will be used
*
* @var string
*/
private $boxUrl;
private $boxUrl = '';

/**
* Base url
*
* @var string
*/
private $baseUrl;
private $baseUrl = '';

/**
* Adds view/layout helper.
*
* @param string $name
* @param string $type
* @param mixed $obj
* @return $this
*/
public function addHelper(string $name, string $type, $obj)
public function addHelper(string $name, string $type, $obj): Base
{
$this->helpers[$type][$name] = $obj;
return $this;
}

/**
Expand Down Expand Up @@ -85,9 +88,9 @@ public function getHelper(string $name, string $type)
private $data = [];

/**
* @var bool
* @var bool|null
*/
private $modRewrite;
private $modRewrite = null;

/**
* @var \HTMLPurifier_Config default object.
Expand All @@ -104,7 +107,7 @@ public function getHelper(string $name, string $type)
*
* @return \HTMLPurifier
*/
public function getPurifier()
public function getPurifier(): \HTMLPurifier
{
return $this->purifier;
}
Expand Down Expand Up @@ -135,7 +138,7 @@ public function purify(string $content): string
* @param Router $router
* @param string|null $baseUrl
*/
public function __construct(Request $request, Translator $translator, Router $router, $baseUrl = null)
public function __construct(Request $request, Translator $translator, Router $router, ?string $baseUrl = null)
{
$this->request = $request;
$this->translator = $translator;
Expand Down Expand Up @@ -213,7 +216,7 @@ public function get(string $key)
* @param mixed $value
* @return $this
*/
public function set(string $key, $value)
public function set(string $key, $value): Base
{
$this->data[$key] = $value;

Expand All @@ -223,19 +226,22 @@ public function set(string $key, $value)
/**
* Sets view data array.
*
* @param mixed[] $data
* @param array $data
* @return $this
*/
public function setArray($data = [])
public function setArray(array $data = []): Base
{
$this->data = array_merge($this->data, $data);

return $this;
}

/**
* Gets the request object.
*
* @return Request
*/
public function getRequest()
public function getRequest(): Request
{
return $this->request;
}
Expand All @@ -245,7 +251,7 @@ public function getRequest()
*
* @return Router
*/
public function getRouter()
public function getRouter(): Router
{
return $this->router;
}
Expand All @@ -255,17 +261,17 @@ public function getRouter()
*
* @return Translator
*/
public function getTranslator()
public function getTranslator(): Translator
{
return $this->translator;
}

/**
* Gets the user object.
*
* @return \Modules\User\Models\User
* @return \Modules\User\Models\User|null
*/
public function getUser()
public function getUser(): ?\Modules\User\Models\User
{
return \Ilch\Registry::get('user');
}
Expand Down Expand Up @@ -373,10 +379,10 @@ public function getVendorUrl(string $url = ''): string
/**
* Escape the given string.
*
* @param string $string
* @param null|string $string
* @return string
*/
public function escape($string): string
public function escape(?string $string): string
{
return \htmlspecialchars($string ?? '', ENT_QUOTES, 'UTF-8', false);
}
Expand Down Expand Up @@ -477,13 +483,19 @@ public function getHtmlFromBBCode(string $bbcode): string
/**
* Creates a full url for the given parts.
*
* @param array|string $url
* @param string $route
* @param bool $secure
* @param array|string $url
* @param string|null $route
* @param bool $secure
* @return string
*/
public function getUrl($url = [], string $route = null, bool $secure = false): string
public function getUrl($url = [], ?string $route = null, bool $secure = false): string
{
$locale = '';
$config = \Ilch\Registry::get('config');
if ($config->get('multilingual_acp') && $this->layout->getTranslator()->getLocale() != $config->get('content_language')) {
$locale = $this->layout->getTranslator()->getLocale();
}

if ($this->modRewrite === null) {
$config = \Ilch\Registry::get('config');
if ($config !== null) {
Expand All @@ -501,25 +513,32 @@ public function getUrl($url = [], string $route = null, bool $secure = false): s
if (is_array($url)) {
$urlParts = [];

if (isset($url['module'])) {
$urlParts[] = $url['module'];
unset($url['module']);
if (isset($url['module']) && $url['module'] === 'admin' && isset($url['controller']) && $url['controller'] === 'page' && isset($url['action']) && $url['action'] === 'show' && isset($url['id'])) {
$pageMapper = new \Modules\Admin\Mappers\Page();
$page = $pageMapper->getPageByIdLocale((int)$url['id'], $locale);
$urlParts[] = $page->getPerma();
unset($url['module'], $url['controller'], $url['action'], $url['id']);
} else {
$urlParts[] = $this->getRequest()->getModuleName();
}
if (isset($url['module'])) {
$urlParts[] = $url['module'];
unset($url['module']);
} else {
$urlParts[] = $this->getRequest()->getModuleName();
}

if (isset($url['controller'])) {
$urlParts[] = $url['controller'];
unset($url['controller']);
} else {
$urlParts[] = $this->getRequest()->getControllerName();
}
if (isset($url['controller'])) {
$urlParts[] = $url['controller'];
unset($url['controller']);
} else {
$urlParts[] = $this->getRequest()->getControllerName();
}

if (isset($url['action'])) {
$urlParts[] = $url['action'];
unset($url['action']);
} else {
$urlParts[] = $this->getRequest()->getActionName();
if (isset($url['action'])) {
$urlParts[] = $url['action'];
unset($url['action']);
} else {
$urlParts[] = $this->getRequest()->getActionName();
}
}

foreach ($url as $key => $value) {
Expand All @@ -537,7 +556,7 @@ public function getUrl($url = [], string $route = null, bool $secure = false): s

$url = implode('/', $urlParts);

if (($this->getRequest()->isAdmin() && $route === null) || ($route !== null && $route === 'admin')) {
if (($this->getRequest()->isAdmin() && $route === null) || ($route === 'admin')) {
$url = 'admin/' . $url;
$rewrite = false;
}
Expand Down Expand Up @@ -616,12 +635,12 @@ public function getCaptchaField(): string
* Gets the MediaModal.
* Place inside Javascript tag.
*
* @param string $mediaButton Define Media Button by given URL
* @param string $actionButton Define Action Button by given URL
* @param null|string $inputId
* @return \Ilch\Layout\Helper\GetMedia
* @param string|null $mediaButton Define Media Button by given URL
* @param string|null $actionButton Define Action Button by given URL
* @param string|null $inputId
* @return GetMedia
*/
public function getMedia(string $mediaButton = null, string $actionButton = null, $inputId = null): \Ilch\Layout\Helper\GetMedia
public function getMedia(?string $mediaButton = null, ?string $actionButton = null, ?string $inputId = null): \Ilch\Layout\Helper\GetMedia
{
return new \Ilch\Layout\Helper\GetMedia($mediaButton, $actionButton, $inputId);
}
Expand Down Expand Up @@ -714,13 +733,13 @@ public function setBoxUrl(string $boxUrl)
/**
* Gets the dialog.
*
* @param $id
* @param $name
* @param $content
* @param null $submit
* @param string $id
* @param string $name
* @param string $content
* @param mixed $submit
* @return string
*/
public function getDialog($id, $name, $content, $submit = null): string
public function getDialog(string $id, string $name, string $content, $submit = null): string
{
$html = '<div class="modal fade" id="'.$id.'">
<div class="modal-dialog">
Expand Down
Loading

0 comments on commit 7e54e1e

Please sign in to comment.