/** * Checks if current page is decorated with externalURL pageDec and redirects to external URL if applicable. */ public function run() { /** @var $SMSM SMSManager */ $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager'); $currentPage = $SMSM->getSite()->getCurrentPage(); if ($currentPage instanceof SMSPageDec) { /** @var $currentPage SMSPageDec */ $decoratorTypes = $currentPage->getDecoratorTypes(); if (in_array(self::DECORATOR_TYPE, $decoratorTypes)) { /** * @var $currentPage SMSExternalUrlPageDec * (included in pageDecs) */ $externalURLString = $currentPage->getExternalURL(); $externalURLObject = Url::fromString($externalURLString); $currentURLObject = Url::fromCurrent(); // protection against infinite redirection loops if ($externalURLObject->getHost() != $currentURLObject->getHost() || $externalURLObject->getPath() != $currentURLObject->getPath()) { header('Location: ' . $externalURLString, true, 301); // HTTP status code 301: moved permanently exit; } } } }
/** * Returns a link including the desired params and some standard parts. * * @param string[] $linkParams the desired link params. * @param string $baseURL the desired base url. * * @return string The generated link. * * @author Christian Achatz * @version * Version 0.1, 26.12.2008<br /> */ protected function generateLink($linkParams, $baseURL = null) { if ($baseURL === null) { $baseURL = $this->getRequest()->getRequestUri(); } return LinkGenerator::generateUrl(Url::fromString($baseURL)->mergeQuery($linkParams)); }
public function transformContent() { /* @var $sessionStore UmgtUserSessionStore */ $sessionStore = $this->getServiceObject(UmgtUserSessionStore::class, [], APFService::SERVICE_TYPE_SESSION_SINGLETON); $appIdent = $this->getContext(); $user = $sessionStore->getUser($appIdent); if ($user === null) { $form = $this->getForm('login'); // generate url ourselves to not include the logout action instruction $form->setAction(LinkGenerator::generateUrl(Url::fromCurrent())); if ($form->isSent() && $form->isValid()) { $username = $form->getFormElementByName('username')->getAttribute('value'); $password = $form->getFormElementByName('password')->getAttribute('value'); try { $user = $this->loadUser($username, $password); if ($user === null) { $form->getFormElementByName('username')->markAsInvalid(); $form->getFormElementByName('username')->appendCssClass(AbstractFormValidator::$DEFAULT_MARKER_CLASS); $form->getFormElementByName('password')->markAsInvalid(); $form->getFormElementByName('password')->appendCssClass(AbstractFormValidator::$DEFAULT_MARKER_CLASS); $form->setPlaceHolder('login-error', $this->getTemplate('login-error')->transformTemplate()); $form->transformOnPlace(); } else { // store user $sessionStore->setUser($appIdent, $user); // create auto-login cookie $rememberMe = $form->getFormElementByName('remember-me'); if ($rememberMe->isChecked()) { $this->createAutoLogin($user); } // redirect to target page $urlProvider = $this->getDIServiceObject('APF\\modules\\usermanagement\\biz', 'LoginRedirectUrlProvider'); /* @var $urlProvider UmgtRedirectUrlProvider */ $this->getResponse()->forward(LinkGenerator::generateUrl(Url::fromString($urlProvider->getRedirectUrl()))); } } catch (Exception $e) { $this->getTemplate('system-error')->transformOnPlace(); $l = Singleton::getInstance(Logger::class); /* @var $l Logger */ $l->logEntry('login', 'Login is not possible due to ' . $e, LogEntry::SEVERITY_ERROR); } } elseif ($form->isSent() && !$form->isValid()) { $form->setPlaceHolder('login-error', $this->getTemplate('login-error')->transformTemplate()); $form->transformOnPlace(); } else { $form->transformOnPlace(); } } else { $this->getTemplate('login-ok')->transformOnPlace(); } }
/** * Checks if link is active (=we are already on the target page) or not. * * @return boolean * * @author Werner Liemberger wpublicmail [at] gmail DOT com * @version * Version 0.1, 30.11.2012<br /> */ public function isActive() { $currentUrl = Url::fromCurrent(true); $targetUrl = Url::fromString($this->getAttribute(self::HREF_ATTRIBUTE_NAME)); // ID#201: re-map and sort query parameters to allow parameter mixing $currentQuery = $currentUrl->getQuery(); ksort($currentQuery); $currentUrl->setQuery($currentQuery); $targetQuery = $targetUrl->getQuery(); ksort($targetQuery); $targetUrl->setQuery($targetQuery); if (substr_count(LinkGenerator::generateUrl($currentUrl), LinkGenerator::generateUrl($targetUrl)) > 0) { return true; } return false; }
public function run() { $logout = $this->getInput()->getParameter('logout', 'false'); if ($logout === 'true') { $sessionStore = $this->getServiceObject(UmgtUserSessionStore::class, [], APFService::SERVICE_TYPE_SESSION_SINGLETON); /* @var $sessionStore UmgtUserSessionStore */ $sessionStore->logout($this->getContext()); // delete cookie to avoid re-log-in effects after clicking on log-out $cookie = new Cookie(UmgtAutoLoginAction::AUTO_LOGIN_COOKIE_NAME); $response = $this->getResponse(); $response->setCookie($cookie->delete()); // redirect to target page $urlProvider = $this->getDIServiceObject('APF\\modules\\usermanagement\\biz', 'LogoutRedirectUrlProvider'); /* @var $urlProvider UmgtRedirectUrlProvider */ $response->forward(LinkGenerator::generateUrl(Url::fromString($urlProvider->getRedirectUrl()))); } }
public function transform() { $href = $this->getAttribute(self::HREF_ATTRIBUTE_NAME); if ($href === null) { $url = Url::fromCurrent(true); } else { $url = Url::fromString($href); $this->deleteAttribute(self::HREF_ATTRIBUTE_NAME); } $queryOption = $this->getAttribute(self::QUERY_OPTION_ATTRIBUTE_NAME, self::QUERY_OPTION_OVERWRITE); $this->deleteAttribute(self::QUERY_OPTION_ATTRIBUTE_NAME); $parameters = $this->getUrlParameters(); if ($queryOption === self::QUERY_OPTION_MERGE) { $url->mergeQuery($parameters); } else { $url->setQuery($parameters); } return LinkGenerator::generateUrl($url); }
protected function buildPackageLink($url, $name) { // Generate url if not given $url = $url === null ? Url::fromCurrent(true) : Url::fromString($url); return LinkGenerator::generateActionUrl($url, 'APF\\extensions\\htmlheader', 'JsCss', ['package' => $name . '.' . $this->getTypeIndicator()]); }
/** * Receives information and configures node. * * @param string $target The refresh target. * @param string $time The time to wait until to reload the page. * @param array $additionalParameters Optional. Array of url parameters. */ public function __construct($target, $time, array $additionalParameters = []) { $this->setAttribute('http-equiv', 'refresh'); $link = LinkGenerator::generateUrl(Url::fromString($target)->mergeQuery($additionalParameters)); $this->setAttribute('content', $time . ';URL=' . $link); }
/** * Generates the link to a given page. * * @param int $page The number of the page. * @param string $baseURI The base URI. Default = REQUEST_URI * * @return string The link to the given page. * * @author Daniel Seemaier * @version * Version 0.1, 22.08.2010 */ public function getPageLink($page, $baseURI = null) { $linkParams = [$this->pageUrlParameterName => $page]; if ($this->isDynamicPageSizeActivated()) { $linkParams[$this->countUrlParameterName] = $this->getCountPerPage(); } if ($baseURI === null) { $baseURI = $this->getRequest()->getRequestUri(); } return LinkGenerator::generateUrl(Url::fromString($baseURI)->mergeQuery($linkParams)); }
public function testEncodeRfc3986() { $scheme = new DefaultLinkScheme(true, true, true); $url = Url::fromString('/'); $url->setQuery(['a' => ['x' => '1', 'y' => '2'], 'b' => [0 => '1', 1 => '2']]); $link = $link = LinkGenerator::generateUrl($url, $scheme); $this->assertEquals('/?a%5Bx%5D=1&a%5By%5D=2&b%5B0%5D=1&b%5B1%5D=2', $link); $scheme->setEncodeAmpersands(false); $link = $link = LinkGenerator::generateUrl($url, $scheme); $this->assertEquals('/?a%5Bx%5D=1&a%5By%5D=2&b%5B0%5D=1&b%5B1%5D=2', $link); $url->setQueryParameter('param name', 'param value'); $link = $link = LinkGenerator::generateUrl($url, $scheme); $this->assertEquals('/?a%5Bx%5D=1&a%5By%5D=2&b%5B0%5D=1&b%5B1%5D=2¶m%20name=param%20value', $link); // encodeBlanks=false, encodeRfc3986=true (RFC encoding overwrites blanks encoding, thus "%20" still included) $scheme->setEncodeBlanks(false); $link = $link = LinkGenerator::generateUrl($url, $scheme); $this->assertEquals('/?a%5Bx%5D=1&a%5By%5D=2&b%5B0%5D=1&b%5B1%5D=2¶m%20name=param%20value', $link); // encodeBlanks=false, encodeRfc3986=false $scheme->setEncodeRfc3986(false); $link = $link = LinkGenerator::generateUrl($url, $scheme); $this->assertEquals('/?a[x]=1&a[y]=2&b[0]=1&b[1]=2¶m name=param value', $link); }
/** * Builds a Link for the JsCssInclusion FC-action * * @param string $url Optional url. * @param string $namespace Namespace of file * @param string $filename Name of file * @param bool $fcaction Optional. Create link for FC-Action. * @param string $type Filetype * * @return string elements' link. */ protected function buildFrontcontrollerLink($url, $namespace, $filename, $fcaction, $type) { if ($fcaction === null) { $fcaction = true; } if ($fcaction) { $UrlObj = $url === null ? Url::fromCurrent(true) : Url::fromString($url); return LinkGenerator::generateActionUrl($UrlObj, 'APF\\extensions\\htmlheader', 'JsCss', ['path' => str_replace('\\', '_', $namespace), 'type' => $type, 'file' => $filename]); } else { $namespace = str_replace('\\', '/', $namespace); $url .= substr($url, -1, 1) !== '/' ? '/' : ''; return $url . $namespace . '/' . $filename . '.' . $type; } }
public function transformForm() { $t = Singleton::getInstance(BenchmarkTimer::class); /* @var $t BenchmarkTimer */ $id = '(HtmlFormTag) ' . $this->getObjectId() . '::transformForm()'; $t->start($id); // add action attribute if not set $action = $this->getAttribute(self::ACTION_ATTRIBUTE_NAME); if ($action === null) { $this->setAttribute(self::ACTION_ATTRIBUTE_NAME, $this->getRequest()->getRequestUri()); } // ID#239: always encode action attribute when present to secure custom actions as well as auto-generated ones $this->setAttribute(self::ACTION_ATTRIBUTE_NAME, htmlspecialchars($this->getAttribute(self::ACTION_ATTRIBUTE_NAME), ENT_QUOTES, Registry::retrieve('APF\\core', 'Charset'), false)); // transform the form including all child tags $htmlCode = (string) '<form '; $htmlCode .= $this->getAttributesAsString($this->attributes, $this->attributeWhiteList); $htmlCode .= '>'; // ID#281: add hidden form fields with URL get parameters for GET forms for convenience reasons if ($this->getAttribute(self::METHOD_ATTRIBUTE_NAME) === self::METHOD_GET_VALUE_NAME && $this->getAttribute(self::SUBMIT_ACTION_URL_PARAMS_ATTRIBUTE_NAME) === 'true') { $url = Url::fromString($this->getAttribute(self::ACTION_ATTRIBUTE_NAME)); $queryParams = $url->getQuery(); if (count($queryParams) > 0) { $hiddenFieldMarker = ''; foreach ($queryParams as $name => $value) { $control = $this->createFormElement($this, 'form:hidden', ['name' => $name, 'value' => $value]); $hiddenFieldMarker .= '<' . $control->getObjectId() . ' />'; } // prepend fields to preserve parameter order $this->content = $hiddenFieldMarker . $this->content; } } if (count($this->children) > 0) { foreach ($this->children as &$child) { $childId = '(' . get_class($child) . ') ' . $child->getObjectId() . '::transform()'; $t->start($childId); $this->content = str_replace('<' . $child->getObjectId() . ' />', $child->transform(), $this->content); $t->stop($childId); } } $htmlCode .= $this->content; $htmlCode .= '</form>'; $t->stop($id); return $htmlCode; }
public function getReferrerUrl($absolute = false) { if (isset($_SERVER['HTTP_REFERER'])) { $url = Url::fromString($_SERVER['HTTP_REFERER']); if ($absolute === false) { $url->setScheme(null); $url->setHost(null); $url->setPort(null); } return $url; } throw new UrlFormatException('Empty referrer url cannot be used to create a url representation.'); }
/** * Generates the HTML code of a single bookmark entry. * * @param SocialBookmarkItem $bookmarkEntry Bookmark item. * * @return string HTML code of the applied bookmark entry. * * @author Christian Achatz * @version * Version 0.1, 02.06.2007<br /> * Version 0.2, 07.09.2007<br /> * Version 0.3, 08.09.2007 (Added profiling)<br /> * Version 0.4, 15.04.2008 (Now URL rewriting is respected)<br /> * Version 0.5, 25.05.2008 (Page title is now applied)<br /> * Version 0.6, 21.06.2008 (Replaced APPS__URL_REWRITING with a value from the registry)<br /> */ protected function generateBookmarkEntry(SocialBookmarkItem $bookmarkEntry) { $code = '<a rel="nofollow" href="'; $code .= LinkGenerator::generateUrl(Url::fromString($bookmarkEntry->getServiceBaseUrl())->mergeQuery([$bookmarkEntry->getUrlParamName() => $this->url, $bookmarkEntry->getTitleParamName() => $this->title]), new DefaultLinkScheme(true)); $code .= '" title="'; $code .= $bookmarkEntry->getTitle(); $code .= '" linkrewrite="false"><img src="'; $code .= $this->getMediaUrl($bookmarkEntry->getImageUrl() . '.' . $bookmarkEntry->getImageExt()); $code .= '" alt="'; $code .= $bookmarkEntry->getTitle(); $code .= '" style="width: '; $code .= $this->imageWidth . 'px; height: '; $code .= $this->imageHeight . 'px;" /></a>' . PHP_EOL; return $code; }