/** * @param string $text * * @return string */ public function rewriteInternalUri($text) { $rootDir = str_replace('/', '\\/', $this->appPath->getWebRoot()); $host = $this->request->getServer()->get('HTTP_HOST'); $pattern = '/<a([^>]+)href="(http(s?):\\/\\/' . $host . ')?(' . $rootDir . ')?(index\\.php)?(\\/?)((?i:[a-z\\d_\\-]+\\/){2,})"/i'; return preg_replace_callback($pattern, [$this, "rewriteInternalUriCallback"], $text); }
/** * If the language has been changed, set a cookie with the new default language and force a page reload */ public function onLanguageChange() { if ($this->request->getPost()->has('lang')) { setcookie('ACP3_INSTALLER_LANG', $this->request->getPost()->get('lang', ''), time() + 3600, '/'); $this->redirect->temporary($this->request->getFullPath())->send(); exit; } }
/** * Redirect to an other URLs * * @param string $path * @param int $statusCode * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ protected function createRedirectResponse($path, $statusCode) { $path = $this->router->route($path, true); if ($this->request->isXmlHttpRequest() === true) { return $this->createAjaxRedirectResponse($path); } return new SymfonyRedirectResponse($path, $statusCode); }
/** * @return string */ protected function addElementFromMinifier() { $minifyJs = ''; if (!$this->request->isXmlHttpRequest()) { $minifyJs = '<script type="text/javascript" src="' . $this->minifier->getURI() . '"></script>' . "\n"; } return $minifyJs; }
/** * @return string */ public function getDetails() { if ($this->details === null) { $pageTitle = $this->stringFormatter->makeStringUrlSafe($this->title->getPageTitle()); $this->details = $this->request->getModule() . '-' . $this->request->getController() . '-' . $pageTitle; } return $this->details; }
/** * Sets a redirect messages and redirects to the given internal path * * @param int|bool $success * @param string $text * @param string|null $path * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ public function setMessage($success, $text, $path = null) { $this->sessionHandler->set('redirect_message', ['success' => is_int($success) ? true : (bool) $success, 'text' => $text]); // If no path has been given, guess it automatically if ($path === null) { $path = $this->request->getModuleAndController(); } return $this->redirect->temporary($path); }
/** * @param \ACP3\Core\Breadcrumb\Title $title */ private function addPageTitlePostfix(Title $title) { if ($this->request->getModule() !== 'acp') { if (!empty($title->getPageTitlePostfix())) { $title->setPageTitlePostfix($title->getPageTitlePostfix() . $title->getPageTitleSeparator() . $this->translator->t('acp', 'acp')); } else { $title->setPageTitlePostfix($this->translator->t('acp', 'acp')); } } }
/** * Erzeugt das Captchafeld für das Template * * @param integer $captchaLength * @param string $formFieldId * @param bool $inputOnly * @param string $path * * @return string */ public function captcha($captchaLength = self::CAPTCHA_DEFAULT_LENGTH, $formFieldId = self::CAPTCHA_DEFAULT_INPUT_ID, $inputOnly = false, $path = '') { if ($this->user->isAuthenticated() === false) { $path = sha1($this->router->route(empty($path) === true ? $this->request->getQuery() : $path)); $this->sessionHandler->set('captcha_' . $path, $this->secureHelper->salt($captchaLength)); $this->view->assign('captcha', ['width' => $captchaLength * 25, 'id' => $formFieldId, 'height' => 30, 'input_only' => $inputOnly, 'path' => $path]); return $this->view->fetchTemplate('Captcha/Partials/captcha.tpl'); } return ''; }
/** * @inheritdoc */ public function authenticate() { $userData = 0; if ($this->sessionHandler->has(AuthenticationModel::AUTH_NAME)) { $userData = $this->sessionHandler->get(AuthenticationModel::AUTH_NAME, []); } elseif ($this->request->getCookies()->has(AuthenticationModel::AUTH_NAME)) { list($userId, $token) = explode('|', $this->request->getCookies()->get(AuthenticationModel::AUTH_NAME, '')); $userData = $this->verifyCredentials($userId, $token); } $this->authenticationModel->authenticate($userData); }
/** * Selektion eines Eintrages in einem Dropdown-Menü * * @param string $formFieldName * @param mixed $defaultValue * @param string|integer|array $currentValue * @param string $htmlAttribute * * @return string */ public function selectEntry($formFieldName, $defaultValue, $currentValue = '', $htmlAttribute = '') { $htmlAttribute = $this->buildHtmlAttribute($htmlAttribute); $currentValue = $this->request->getPost()->get($formFieldName, $currentValue); if (is_array($currentValue) === false && $currentValue == $defaultValue) { return $htmlAttribute; } elseif (is_array($currentValue) === true && in_array($defaultValue, $currentValue)) { return $htmlAttribute; } return ''; }
/** * @return array */ protected function buildPageCssClasses() { $pieces = [$this->pageCssClasses->getModule(), $this->pageCssClasses->getControllerAction()]; if ($this->request->getArea() === Core\Controller\AreaEnum::AREA_ADMIN) { $pieces[] = 'in-admin'; } elseif ($this->request->isHomepage() === true) { $pieces[] = 'is-homepage'; } else { $pieces[] = $this->pageCssClasses->getDetails(); } return $pieces; }
/** * Removes the form token from the session * * @param string $token */ public function unsetFormToken($token = '') { $tokenName = Core\Session\SessionHandlerInterface::XSRF_TOKEN_NAME; if (empty($token) && $this->request->getPost()->has($tokenName)) { $token = $this->request->getPost()->get($tokenName, ''); } if (!empty($token)) { $sessionToken = $this->sessionHandler->get($tokenName); if (!empty($sessionToken)) { $this->sessionHandler->remove($tokenName); } } }
/** * Returns the SEO form fields * * @param string $path * * @return array */ public function formFields($path = '') { if (!empty($path)) { $path .= !preg_match('/\\/$/', $path) ? '/' : ''; $alias = $this->request->getPost()->get('alias', $this->aliases->getUriAlias($path, true)); $keywords = $this->request->getPost()->get('seo_keywords', $this->metaStatements->getKeywords($path)); $description = $this->request->getPost()->get('seo_description', $this->metaStatements->getDescription($path)); $robots = $this->metaStatements->getSeoInformation($path, 'robots', 0); } else { $alias = $keywords = $description = ''; $robots = 0; } return ['alias' => $alias, 'keywords' => $keywords, 'description' => $description, 'robots' => $this->formsHelper->choicesGenerator('seo_robots', $this->getRobotsChoicesGeneratorValues(), $robots)]; }
/** * @return string */ protected function getCookieDomain() { if (strpos($this->request->getServer()->get('HTTP_HOST'), '.') !== false) { return $this->request->getServer()->get('HTTP_HOST', ''); } return ''; }
/** * Sets the breadcrumb steps cache for frontend action requests */ protected function buildBreadcrumbCacheForFrontend() { if (empty($this->steps)) { $this->append($this->translator->t($this->request->getModule(), $this->request->getModule()), $this->request->getModule()); $this->appendControllerActionBreadcrumbs(); } $this->breadcrumbCache = $this->steps; }
/** * @param string $menu * * @return int */ protected function selectMenuItem($menu) { if ($this->request->getArea() !== Core\Controller\AreaEnum::AREA_ADMIN) { $in = [$this->request->getQuery(), $this->request->getUriWithoutPages(), $this->request->getFullPath(), $this->request->getModuleAndController(), $this->request->getModule()]; return $this->menuItemRepository->getLeftIdByUris($menu, $in); } return 0; }
/** * @param string $name * @param string $value * @param bool $showTime * * @return string */ protected function fetchSimpleDatePickerValue($name, $value, $showTime) { if ($this->request->getPost()->has($name)) { return $this->request->getPost()->get($name, ''); } elseif ($this->dateValidationRule->isValid($value) === true) { return $this->date->format($value, $this->getDateFormat($showTime)); } return $this->date->format('now', $this->getDateFormat($showTime), false); }
/** * @return array */ private function prepareRequestData() { $entries = []; if (is_array($this->request->getPost()->get('entries')) === true) { $entries = $this->request->getPost()->get('entries'); } elseif ((bool) preg_match('/^((\\d+)\\|)*(\\d+)$/', $this->request->getParameters()->get('entries')) === true) { $entries = explode('|', $this->request->getParameters()->get('entries')); } return $entries; }
/** * @param string $path * @param bool $isAbsolute * @param bool $forceSecure * * @return string */ protected function addUriPrefix($path, $isAbsolute, $forceSecure) { $prefix = ''; if ($isAbsolute === true || $forceSecure === true) { $prefix .= $forceSecure === true ? 'https://' : $this->request->getScheme() . '://'; $prefix .= $this->request->getHost(); } $prefix .= $this->useModRewrite($path) ? $this->appPath->getWebRoot() : $this->appPath->getPhpSelf() . '/'; return $prefix; }
/** * @inheritdoc */ public function route($path, $absolute = false, $forceSecure = false) { $path = $path . (!preg_match('/\\/$/', $path) ? '/' : ''); $pathArray = preg_split('=/=', $path, -1, PREG_SPLIT_NO_EMPTY); if (isset($pathArray[1]) === false) { $path .= 'index/'; } if (isset($pathArray[2]) === false) { $path .= 'index/'; } $prefix = ''; // Append the current hostname to the URL if ($absolute === true) { $prefix .= $forceSecure === true ? 'https://' : $this->request->getScheme() . '://'; $prefix .= $this->request->getHost(); } $prefix .= $this->appPath->getPhpSelf() . '/'; return $prefix . $path; }
/** * @inheritdoc */ public function destroy($sessionId) { $this->secureSession(); if ($this->request->getCookies()->has(self::SESSION_NAME)) { $cookie = new Cookie(self::SESSION_NAME, '', (new \DateTime())->modify('-3600 seconds'), $this->appPath->getWebRoot(), null, $this->request->getSymfonyRequest()->isSecure()); $this->response->headers->setCookie($cookie); } // Delete the session from the database $this->db->getConnection()->delete($this->db->getPrefix() . 'sessions', ['session_id' => $sessionId]); return true; }
/** * Returns the SEO robots setting for the current page * * @return string */ public function getPageRobotsSetting() { $robots = $this->getRobotsSetting($this->request->getUriWithoutPages()); if (empty($robots)) { $robots = $this->getRobotsSetting($this->request->getFullPath()); } if (empty($robots)) { $robots = $this->getRobotsSetting($this->request->getModule()); } return strtolower(!empty($robots) ? $robots : $this->getRobotsSetting()); }
/** * @param bool $customUris * @param array|string $page * @param int $pageNumber * @param int $currentIndex * * @return bool */ protected function isCurrentPage($customUris, $page, $pageNumber, $currentIndex) { if ($customUris === true) { if (is_array($page) === true && $page['uri'] === $this->router->route($this->request->getQuery()) || $this->router->route($this->request->getQuery()) === $this->router->route($this->request->getFullPath()) && $currentIndex == 0) { return true; } } elseif ($this->integerValidationRule->isValid($this->request->getParameters()->get('page')) === false && $currentIndex === 0 || $this->request->getParameters()->get('page') === $pageNumber) { return true; } return false; }
/** * Listet alle Kategorien eines Moduls auf * * @param string $module * @param string $categoryId * @param boolean $categoryCreate * @param string $formFieldName * @param string $customText * * @return array */ public function categoriesList($module, $categoryId = '', $categoryCreate = false, $formFieldName = 'cat', $customText = '') { $categories = []; $categories['custom_text'] = !empty($customText) ? $customText : $this->translator->t('system', 'pls_select'); $categories['name'] = $formFieldName; $categories['categories'] = $this->categoriesCache->getCache($module); $cData = count($categories['categories']); for ($i = 0; $i < $cData; ++$i) { $categories['categories'][$i]['selected'] = $this->formsHelper->selectEntry($formFieldName, $categories['categories'][$i]['id'], $categoryId); } if ($categoryCreate === true && $this->acl->hasPermission('admin/categories/index/create') === true) { $categories['create']['name'] = $formFieldName . '_create'; $categories['create']['value'] = $this->request->getPost()->get('create', ['name' => ''])['name']; } return $categories; }
private function setLanguage() { $cookieLocale = $this->request->getCookies()->get('ACP3_INSTALLER_LANG', ''); if (!preg_match('=/=', $cookieLocale) && is_file($this->appPath->getInstallerModulesDir() . 'Install/Resources/i18n/' . $cookieLocale . '.xml') === true) { $language = $cookieLocale; } else { $language = 'en_US'; // Fallback language foreach ($this->request->getUserAgent()->parseAcceptLanguage() as $locale => $val) { $locale = str_replace('-', '_', $locale); if ($this->translator->languagePackExists($locale) === true) { $language = $locale; break; } } } $this->translator->setLocale($language); }
/** * @return array */ public function render() { if ($this->totalResults > $this->resultsPerPage) { $areaPrefix = $this->request->getArea() === AreaEnum::AREA_ADMIN ? 'acp/' : ''; $link = $this->router->route($areaPrefix . $this->request->getUriWithoutPages()); $this->currentPage = (int) $this->request->getParameters()->get('page', 1); $this->totalPages = (int) ceil($this->totalResults / $this->resultsPerPage); $this->setMetaStatements(); $range = $this->calculateRange(); $this->showFirstPageLink($link, $range); $this->showPreviousPageLink($link); for ($i = (int) $range['start']; $i <= $range['end']; ++$i) { $this->pagination[] = $this->buildPageNumber($i, $link . ($i > 1 ? 'page_' . $i . '/' : '') . $this->urlFragment, '', $this->currentPage === $i); } $this->showNextPageLink($link); $this->showLastPageLink($link, $range); } return $this->pagination; }
/** * @param string $emailAddress * @param string $hash * * @return bool */ protected function sendDoubleOptInEmail($emailAddress, $hash) { $url = $this->router->route('newsletter/index/activate/hash_' . $hash, true); $systemSettings = $this->config->getSettings(\ACP3\Modules\ACP3\System\Installer\Schema::MODULE_NAME); $settings = $this->config->getSettings(Schema::MODULE_NAME); $subject = $this->translator->t('newsletter', 'subscribe_mail_subject', ['%title%' => $systemSettings['site_title']]); $body = $this->translator->t('newsletter', 'subscribe_mail_body', ['{host}' => $this->request->getHost()]) . "\n\n"; $from = ['email' => $settings['mail'], 'name' => $systemSettings['site_title']]; $this->mailer->reset()->setFrom($from)->setSubject($subject)->setMailSignature($settings['mailsig']); if ($settings['html'] == 1) { $this->mailer->setTemplate('newsletter/layout.email.tpl'); $body .= '<a href="' . $url . '">' . $url . '<a>'; $this->mailer->setHtmlBody($this->stringFormatter->nl2p($body)); } else { $body .= $url; $this->mailer->setBody($body); } $this->mailer->setRecipients($emailAddress); return $this->mailer->send(); }
/** * @return bool */ private function uriAliasExists() { return $this->aliases->uriAliasExists($this->request->getQuery()) === true && $this->request->getPathInfo() !== $this->aliases->getUriAlias($this->request->getQuery()) . '/'; }
/** * Checks, whether the maintenance mode is active * * @param \ACP3\Core\Http\RequestInterface $request * * @return bool */ private function isMaintenanceModeEnabled(RequestInterface $request) { return (bool) $this->systemSettings['maintenance_mode'] === true && $request->getArea() !== AreaEnum::AREA_ADMIN && strpos($request->getQuery(), 'users/index/login/') !== 0; }
/** * @param Core\Http\RequestInterface $request * @param bool $allModules * @return \Symfony\Component\DependencyInjection\ContainerBuilder */ public function updateServiceContainer(Core\Http\RequestInterface $request, $allModules = false) { return Core\DependencyInjection\ServiceContainerBuilder::create($this->appPath, $request->getSymfonyRequest(), $this->environment, $allModules); }