Initial commit: is_searchbar out of the box. v3.0.1
This commit is contained in:
35
is_searchbar/src/Hook/AbstractDisplayHook.php
Normal file
35
is_searchbar/src/Hook/AbstractDisplayHook.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsSearchbar\Hook;
|
||||
|
||||
abstract class AbstractDisplayHook extends AbstractHook
|
||||
{
|
||||
public function execute(array $params): string
|
||||
{
|
||||
if (!$this->shouldBlockBeDisplayed($params)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->assignTemplateVariables($params);
|
||||
|
||||
return $this->module->fetch($this->getTemplateFullPath());
|
||||
}
|
||||
|
||||
protected function assignTemplateVariables(array $params)
|
||||
{
|
||||
}
|
||||
|
||||
protected function shouldBlockBeDisplayed(array $params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTemplateFullPath(): string
|
||||
{
|
||||
return "module:{$this->module->name}/views/templates/hook/{$this->getTemplate()}";
|
||||
}
|
||||
|
||||
abstract protected function getTemplate(): string;
|
||||
}
|
||||
17
is_searchbar/src/Hook/AbstractHook.php
Normal file
17
is_searchbar/src/Hook/AbstractHook.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsSearchbar\Hook;
|
||||
|
||||
abstract class AbstractHook implements HookInterface
|
||||
{
|
||||
protected $module;
|
||||
protected $context;
|
||||
|
||||
public function __construct(\Module $module, \Context $context)
|
||||
{
|
||||
$this->module = $module;
|
||||
$this->context = $context;
|
||||
}
|
||||
}
|
||||
29
is_searchbar/src/Hook/DisplaySearch.php
Normal file
29
is_searchbar/src/Hook/DisplaySearch.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsSearchbar\Hook;
|
||||
|
||||
class DisplaySearch extends AbstractDisplayHook
|
||||
{
|
||||
private const TEMPLATE_FILE = 'is_searchbar.tpl';
|
||||
|
||||
protected function getTemplate(): string
|
||||
{
|
||||
return DisplaySearch::TEMPLATE_FILE;
|
||||
}
|
||||
|
||||
protected function assignTemplateVariables(array $params)
|
||||
{
|
||||
$variables = [
|
||||
'ajax_search_url' => $this->context->link->getModuleLink($this->module->name, 'ajaxSearch'),
|
||||
'search_controller_url' => $this->context->link->getPageLink('search', null, null, null, false, null, true),
|
||||
];
|
||||
|
||||
if (!array_key_exists('search_string', $this->context->smarty->getTemplateVars())) {
|
||||
$variables['search_string'] = '';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign($variables);
|
||||
}
|
||||
}
|
||||
29
is_searchbar/src/Hook/DisplayTop.php
Normal file
29
is_searchbar/src/Hook/DisplayTop.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsSearchbar\Hook;
|
||||
|
||||
class DisplayTop extends AbstractDisplayHook
|
||||
{
|
||||
private const TEMPLATE_FILE = 'is_searchbar.tpl';
|
||||
|
||||
protected function getTemplate(): string
|
||||
{
|
||||
return DisplayTop::TEMPLATE_FILE;
|
||||
}
|
||||
|
||||
protected function assignTemplateVariables(array $params)
|
||||
{
|
||||
$variables = [
|
||||
'ajax_search_url' => $this->context->link->getModuleLink($this->module->name, 'ajaxSearch'),
|
||||
'search_controller_url' => $this->context->link->getPageLink('search', null, null, null, false, null, true),
|
||||
];
|
||||
|
||||
if (!array_key_exists('search_string', $this->context->smarty->getTemplateVars())) {
|
||||
$variables['search_string'] = '';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign($variables);
|
||||
}
|
||||
}
|
||||
10
is_searchbar/src/Hook/HookInterface.php
Normal file
10
is_searchbar/src/Hook/HookInterface.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsSearchbar\Hook;
|
||||
|
||||
interface HookInterface
|
||||
{
|
||||
public function execute(array $params);
|
||||
}
|
||||
11
is_searchbar/src/index.php
Normal file
11
is_searchbar/src/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user