/** * Render URL from typolink configuration * * @param string $parameter * @param array $configuration * @return string Rendered page URI */ public function render($parameter = null, $configuration = array()) { $typoLinkConfiguration = array('parameter' => $parameter ? $parameter : $this->contentObject->data['pid']); if (!empty($configuration)) { ArrayUtility::mergeRecursiveWithOverrule($typoLinkConfiguration, $configuration); } return $this->contentObject->typoLink_URL($typoLinkConfiguration); }
/** * Return an URL to the scaled image * * @param string $originalFile uid or path of the file * @param array $imageSize width and height as keys * @return string */ protected function getScaledImagePath($originalFile, $imageSize) { $conf = array('file' => $originalFile, 'file.' => array('height' => $imageSize['height'], 'width' => $imageSize['width'])); $imgUri = $this->cObj->cObjGetSingle('IMG_RESOURCE', $conf); $conf = array('parameter' => $imgUri, 'forceAbsoluteUrl' => 1); return $this->cObj->typoLink_URL($conf); }
/** * Builds the URI, frontend flavour * * @return string The URI * @see buildTypolinkConfiguration() */ public function buildFrontendUri() { $typolinkConfiguration = $this->buildTypolinkConfiguration(); if ($this->createAbsoluteUri === true) { $typolinkConfiguration['forceAbsoluteUrl'] = true; if ($this->absoluteUriScheme !== null) { $typolinkConfiguration['forceAbsoluteUrl.']['scheme'] = $this->absoluteUriScheme; } } $uri = $this->contentObject->typoLink_URL($typolinkConfiguration); return $uri; }
/** * @test */ public function typoLinkCreatesCorrectSecureJumpUrlForFile() { $testData = $this->initializeJumpUrlTestEnvironment(); $fileNameAndPath = PATH_site . 'typo3temp/phpunitJumpUrlTestFile.txt'; file_put_contents($fileNameAndPath, 'Some test data'); $relativeFileNameAndPath = substr($fileNameAndPath, strlen(PATH_site)); $testAddress = $relativeFileNameAndPath; $expectedHash = '1933f3c181db8940acfcd4d16c74643947179948'; $expectedUrl = $testData['absRefPrefix'] . $testData['mainScript'] . '?id=' . $testData['pageId'] . '&type=' . $testData['pageType'] . '&jumpurl=' . rawurlencode($testAddress) . '&juSecure=1&locationData=' . rawurlencode($testData['locationData']) . '&juHash=' . $expectedHash; $generatedUrl = $this->subject->typoLink_URL(array('parameter' => $testAddress, 'jumpurl.' => array('secure' => 1))); $this->assertEquals($expectedUrl, $generatedUrl); GeneralUtility::unlink_tempfile($fileNameAndPath); }
/** * Creates the URL, target and onclick values for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes * This function doesn't care about the url, because if we let the url be redirected, it will be logged in the stat!!! * * @param integer $key Pointer to a key in the $this->menuArr array where the value for that key represents the menu item we are linking to (page record) * @param string $altTarget Alternative target * @param integer $typeOverride Alternative type * @return array Returns an array with A-tag attributes as key/value pairs (HREF, TARGET and onClick) * @access private * @todo Define visibility */ public function link($key, $altTarget = '', $typeOverride = '') { // Mount points: $MP_var = $this->getMPvar($key); $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : ''; // Setting override ID if ($this->mconf['overrideId'] || $this->menuArr[$key]['overrideId']) { $overrideArray = array(); // If a user script returned the value overrideId in the menu array we use that as page id $overrideArray['uid'] = $this->mconf['overrideId'] ?: $this->menuArr[$key]['overrideId']; $overrideArray['alias'] = ''; // Clear MP parameters since ID was changed. $MP_params = ''; } else { $overrideArray = ''; } // Setting main target: if ($altTarget) { $mainTarget = $altTarget; } elseif ($this->mconf['target.']) { $mainTarget = $this->parent_cObj->stdWrap($this->mconf['target'], $this->mconf['target.']); } else { $mainTarget = $this->mconf['target']; } // Creating link: if ($this->mconf['collapse'] && $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key))) { $thePage = $this->sys_page->getPage($this->menuArr[$key]['pid']); $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', $overrideArray, $this->mconf['addParams'] . $MP_params . $this->menuArr[$key]['_ADD_GETVARS'], $typeOverride); } else { $LD = $this->menuTypoLink($this->menuArr[$key], $mainTarget, '', '', $overrideArray, $this->mconf['addParams'] . $MP_params . $this->I['val']['additionalParams'] . $this->menuArr[$key]['_ADD_GETVARS'], $typeOverride); } // Override URL if using "External URL" as doktype with a valid e-mail address: if ($this->menuArr[$key]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK && $this->menuArr[$key]['urltype'] == 3 && GeneralUtility::validEmail($this->menuArr[$key]['url'])) { // Create mailto-link using \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::typolink (concerning spamProtectEmailAddresses): $LD['totalURL'] = $this->parent_cObj->typoLink_URL(array('parameter' => $this->menuArr[$key]['url'])); $LD['target'] = ''; } // Override url if current page is a shortcut $shortcut = NULL; if ($this->menuArr[$key]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT && $this->menuArr[$key]['shortcut_mode'] != \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) { $menuItem = $this->determineOriginalShortcutPage($this->menuArr[$key]); try { $shortcut = $GLOBALS['TSFE']->getPageShortcut($menuItem['shortcut'], $menuItem['shortcut_mode'], $menuItem['uid'], 20, array(), TRUE); } catch (\Exception $ex) { } if (!is_array($shortcut)) { return array(); } // Only setting url, not target $LD['totalURL'] = $this->parent_cObj->typoLink_URL(array('parameter' => $shortcut['uid'], 'additionalParams' => $this->mconf['addParams'] . $MP_params . $this->I['val']['additionalParams'] . $menuItem['_ADD_GETVARS'], 'linkAccessRestrictedPages' => $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE')); } if ($shortcut) { $pageData = $shortcut; $pageData['_SHORTCUT_PAGE_UID'] = $this->menuArr[$key]['uid']; } else { $pageData = $this->menuArr[$key]; } // Manipulation in case of access restricted pages: $this->changeLinksForAccessRestrictedPages($LD, $pageData, $mainTarget, $typeOverride); // Overriding URL / Target if set to do so: if ($this->menuArr[$key]['_OVERRIDE_HREF']) { $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF']; if ($this->menuArr[$key]['_OVERRIDE_TARGET']) { $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET']; } } // OnClick open in windows. $onClick = ''; if ($this->mconf['JSWindow']) { $conf = $this->mconf['JSWindow.']; $url = $LD['totalURL']; $LD['totalURL'] = '#'; $onClick = 'openPic(\'' . $GLOBALS['TSFE']->baseUrlWrap($url) . '\',\'' . ($conf['newWindow'] ? md5($url) : 'theNewPage') . '\',\'' . $conf['params'] . '\'); return false;'; $GLOBALS['TSFE']->setJS('openPic'); } // look for type and popup // following settings are valid in field target: // 230 will add type=230 to the link // 230 500x600 will add type=230 to the link and open in popup window with 500x600 pixels // 230 _blank will add type=230 to the link and open with target "_blank" // 230x450:resizable=0,location=1 will open in popup window with 500x600 pixels with settings "resizable=0,location=1" $matches = array(); $targetIsType = $LD['target'] && MathUtility::canBeInterpretedAsInteger($LD['target']) ? (int) $LD['target'] : FALSE; if (preg_match('/([0-9]+[\\s])?(([0-9]+)x([0-9]+))?(:.+)?/s', $LD['target'], $matches) || $targetIsType) { // has type? if ((int) $matches[1] || $targetIsType) { $LD['totalURL'] = $this->parent_cObj->URLqMark($LD['totalURL'], '&type=' . ($targetIsType ?: (int) $matches[1])); $LD['target'] = $targetIsType ? '' : trim(substr($LD['target'], strlen($matches[1]) + 1)); } // Open in popup window? if ($matches[3] && $matches[4]) { $JSparamWH = 'width=' . $matches[3] . ',height=' . $matches[4] . ($matches[5] ? ',' . substr($matches[5], 1) : ''); $onClick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue($GLOBALS['TSFE']->baseUrlWrap($LD['totalURL'])) . ',\'FEopenLink\',\'' . $JSparamWH . '\');vHWin.focus();return false;'; $LD['target'] = ''; } } // out: $list = array(); // Added this check: What it does is to enter the baseUrl (if set, which it should for "realurl" based sites) // as URL if the calculated value is empty. The problem is that no link is generated with a blank URL // and blank URLs might appear when the realurl encoding is used and a link to the frontpage is generated. $list['HREF'] = strlen($LD['totalURL']) ? $LD['totalURL'] : $GLOBALS['TSFE']->baseUrl; $list['TARGET'] = $LD['target']; $list['onClick'] = $onClick; return $list; }
/** * Resolves the URL of an file * * @param $media * * @return null|string */ protected function retrieveMediaUrl($media) { $returnValue = NULL; if (class_exists('TYPO3\\CMS\\Mediace\\MediaWizard\\MediaWizardProviderManager')) { // 7.2 $mediaWizard = \TYPO3\CMS\Mediace\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media); } elseif (class_exists('TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProviderManager')) { // before 7.2 $mediaWizard = \TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::getValidMediaWizardProvider($media); } else { throw new \Exception('You are running TYPO3 > CMS 7.2. Please install the mediace extension', 12367238462384.0); } // Get the path relative to the page currently outputted if (substr($media, 0, 5) === "file:") { $fileUid = substr($media, 5); if (MathUtility::canBeInterpretedAsInteger($fileUid)) { $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid); if ($fileObject instanceof FileInterface) { $returnValue = $fileObject->getPublicUrl(); } } } elseif (is_file(PATH_site . $media)) { $returnValue = $GLOBALS['TSFE']->tmpl->getFileName($media); } elseif ($mediaWizard !== NULL) { $cObj = new ContentObjectRenderer(); $returnValue = $cObj->typoLink_URL(array('parameter' => $mediaWizard->rewriteUrl($media))); } elseif (GeneralUtility::isValidUrl($media)) { $returnValue = $media; } return $returnValue; }