Пример #1
0
 /**
  * Creates a link to a given page with a given link text
  *
  * @param	array	Array of arguments, [0] is the link text, [1] is the (optional) page Id to link to (otherwise TSFE->id), [2] are additional URL parameters, [3] use cache, defaults to FALSE, [4] additional A tag parameters
  * @return	string	complete anchor tag with URL and link text
  */
 public function execute(array $arguments = array())
 {
     $linkText = $arguments[0];
     $additionalParameters = $arguments[2] ? $arguments[2] : '';
     $useCache = $arguments[3] ? TRUE : FALSE;
     $ATagParams = $arguments[4] ? $arguments[4] : '';
     // by default or if no link target is set, link to the current page
     $linkTarget = $GLOBALS['TSFE']->id;
     // if the link target is a number, interprete it as a page ID
     $linkArgument = trim($arguments[1]);
     if (is_numeric($linkArgument)) {
         $linkTarget = intval($linkArgument);
     } elseif (!empty($linkArgument) && is_string($linkArgument)) {
         if (Tx_Solr_Util::isValidTypoScriptPath($linkArgument)) {
             try {
                 $typoscript = Tx_Solr_Util::getTypoScriptObject($linkArgument);
                 $pathExploded = explode('.', $linkArgument);
                 $lastPathSegment = array_pop($pathExploded);
                 $linkTarget = intval($typoscript[$lastPathSegment]);
             } catch (InvalidArgumentException $e) {
                 // ignore exceptions caused by markers, but accept the exception for wrong TS paths
                 if (substr($linkArgument, 0, 3) != '###') {
                     throw $e;
                 }
             }
         } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($linkArgument) || \TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $linkArgument)) {
             // $linkTarget is an URL
             $linkTarget = filter_var($linkArgument, FILTER_SANITIZE_URL);
         }
     }
     $linkConfiguration = array('useCacheHash' => $useCache, 'no_cache' => FALSE, 'parameter' => $linkTarget, 'additionalParams' => $additionalParameters, 'ATagParams' => $ATagParams);
     return $this->contentObject->typoLink($linkText, $linkConfiguration);
 }
Пример #2
0
 /**
  * Resolves a TS path and returns its value
  *
  * @param string $path a TS path, separated with dots
  * @return string
  * @throws InvalidArgumentException
  */
 protected function resolveTypoScriptPath($path, $arguments = NULL)
 {
     $value = '';
     $pathExploded = explode('.', trim($path));
     $lastPathSegment = array_pop($pathExploded);
     $pathBranch = Tx_Solr_Util::getTypoScriptObject($path);
     // generate ts content
     $cObj = $this->getContentObject();
     if (!isset($pathBranch[$lastPathSegment . '.'])) {
         $value = htmlspecialchars($pathBranch[$lastPathSegment]);
     } else {
         if (count($arguments)) {
             $data = array('arguments' => $arguments);
             $numberOfArguments = count($arguments);
             for ($i = 0; $i < $numberOfArguments; $i++) {
                 $data['argument_' . $i] = $arguments[$i];
             }
             $cObj->start($data);
         }
         $value = $cObj->cObjGetSingle($pathBranch[$lastPathSegment], $pathBranch[$lastPathSegment . '.']);
     }
     return $value;
 }
Пример #3
0
 /**
  * Take the link target ID viewhelper argument and try to find a page ID from it.
  *
  * @param string $linkArgument The viewhelper's link target argument
  * @return integer Page ID
  * @throws InvalidArgumentException if an invalid TypoScript path was given
  */
 protected function determinePageId($linkArgument)
 {
     $pageId = $GLOBALS['TSFE']->id;
     if (is_numeric($linkArgument)) {
         // if the link target is a number, interpret it as a page ID
         $pageId = intval($linkArgument);
     } elseif (is_string($linkArgument) && !empty($linkArgument)) {
         // interpret a TypoScript path
         try {
             $typoscript = Tx_Solr_Util::getTypoScriptObject($linkArgument);
             $pathExploded = explode('.', $linkArgument);
             $lastPathSegment = array_pop($pathExploded);
             $pageId = intval($typoscript[$lastPathSegment]);
         } catch (InvalidArgumentException $e) {
             // ignore exceptions caused by markers, but accept the exception for wrong TS paths
             if (substr($linkArgument, 0, 3) != '###') {
                 throw $e;
             }
         }
     }
     return $pageId;
 }