* @link https://www.oxidmodule.com */ declare(strict_types=1); namespace D3\StageMarker\Application\Model; use OxidEsales\Eshop\Core\Base; use OxidEsales\Eshop\Core\Registry; class StageMarker extends Base { /** * @param string $output * * @return string */ public function addStageMarker(string $output) :string { if ($this->stageBarIsActive()) { $re = $this->getRegexPattern(); $subst = '$1'.$this->getMarkerHtml(); $output = preg_replace($re, $subst, $output); } return $output; } /** * @return bool */ protected function stageBarIsActive(): bool { return ( $this->stageBarIsActiveInFrontend() || $this->stageBarIsActiveInBackend()); } /** * @return bool */ protected function stageBarIsActiveInFrontend(): bool { return false === $this->isAdmin() && Registry::getConfig()->getConfigParam('d3stagemarker_showinfrontend'); } /** * @return bool */ protected function stageBarIsActiveInBackend(): bool { return true === $this->isAdmin() && Registry::getConfig()->getConfigParam('d3stagemarker_showinbackend') && in_array($this->getClassItemKey(), $this->getBackendClassItemKeys()); } /** * @return string */ public function getClassItemKey(): string { return Registry::getConfig()->getActiveView()->getClassKey().':'. Registry::getRequest()->getRequestEscapedParameter('item'); } /** * @return string[] */ protected function getBackendClassItemKeys(): array { return [ 'login:', 'navigation:header.tpl' ]; } /** * @return string */ protected function getRegexPattern(): string { return '/(<\s*body.*?>)/m'; } /** * @return string */ public function getMarkerHtml(): string { return '