Documentation TYPO3 par Ameos

class.t3lib_softrefproc.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2003-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the Typo3 project. The Typo3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00097 require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
00098 
00116 class t3lib_softrefproc {
00117 
00118                 // external configuration
00119         var $fileAdminDir = 'fileadmin';
00120 
00121 
00122                 // Internal:
00123         var $tokenID_basePrefix = '';
00124 
00137         function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath='')  {
00138 
00139                 $this->tokenID_basePrefix = $table.':'.$uid.':'.$field.':'.$structurePath.':'.$spKey;
00140 
00141                 switch($spKey)  {
00142                         case 'notify':  // Simple notification
00143                                 $resultArray = array(
00144                                         'elements' => array(
00145                                                 array(
00146                                                         'matchString' => $content
00147                                                 )
00148                                         )
00149                                 );
00150                                 return $resultArray;
00151                         break;
00152                         case 'substitute':
00153                                 $tokenID = $this->makeTokenID();
00154                                 $resultArray = array(
00155                                         'content' => '{softref:'.$tokenID.'}',
00156                                         'elements' => array(
00157                                                 array(
00158                                                         'matchString' => $content,
00159                                                         'subst' => array(
00160                                                                 'type' => 'string',
00161                                                                 'tokenID' => $tokenID,
00162                                                                 'tokenValue' => $content
00163                                                         )
00164                                                 )
00165                                         )
00166                                 );
00167                                 return $resultArray;
00168                         break;
00169                         case 'images':
00170                                 return $this->findRef_images($content, $spParams);
00171                         break;
00172                         case 'typolink':
00173                                 return $this->findRef_typolink($content, $spParams);
00174                         break;
00175                         case 'typolink_tag':
00176                                 return $this->findRef_typolink_tag($content, $spParams);
00177                         break;
00178                         case 'ext_fileref':
00179                                 return $this->findRef_extension_fileref($content, $spParams);
00180                         break;
00181                         case 'TStemplate':
00182                                 return $this->findRef_TStemplate($content, $spParams);
00183                         break;
00184                         case 'TSconfig':
00185                                 return $this->findRef_TSconfig($content, $spParams);
00186                         break;
00187                         case 'email':
00188                                 return $this->findRef_email($content, $spParams);
00189                         break;
00190                         case 'url':
00191                                 return $this->findRef_url($content, $spParams);
00192                         break;
00193                         default:
00194                                 return FALSE;
00195                         break;
00196                 }
00197         }
00198 
00209         function findRef_images($content, $spParams)    {
00210 
00211                         // Start HTML parser and split content by image tag:
00212                 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
00213                 $splitContent = $htmlParser->splitTags('img',$content);
00214                 $elements = array();
00215 
00216                         // Traverse splitted parts:
00217                 foreach($splitContent as $k => $v)      {
00218                         if ($k%2)       {
00219 
00220                                         // Get file reference:
00221                                 $attribs = $htmlParser->get_tag_attributes($v);
00222                                 $srcRef = t3lib_div::htmlspecialchars_decode($attribs[0]['src']);
00223                                 $pI = pathinfo($srcRef);
00224 
00225                                         // If it looks like a local image, continue. Otherwise ignore it.
00226                                 $absPath = t3lib_div::getFileAbsFileName(PATH_site.$srcRef);
00227                                 if (!$pI['scheme'] && !$pI['query'] && $absPath && $srcRef!=='clear.gif')       {
00228 
00229                                                 // Initialize the element entry with info text here:
00230                                         $tokenID = $this->makeTokenID($k);
00231                                         $elements[$k] = array();
00232                                         $elements[$k]['matchString'] = $v;
00233 
00234                                                 // If the image seems to be from fileadmin/ folder or an RTE image, then proceed to set up substitution token:
00235                                         if (t3lib_div::isFirstPartOfStr($srcRef,$this->fileAdminDir.'/') || (t3lib_div::isFirstPartOfStr($srcRef,'uploads/') && ereg('^RTEmagicC_',basename($srcRef)))) {
00236                                                         // Token and substitute value:
00237                                                 if (strstr($splitContent[$k], $attribs[0]['src']))      {       // Make sure the value we work on is found and will get substituted in the content (Very important that the src-value is not DeHSC'ed)
00238                                                         $splitContent[$k] = str_replace($attribs[0]['src'], '{softref:'.$tokenID.'}', $splitContent[$k]);       // Substitute value with token (this is not be an exact method if the value is in there twice, but we assume it will not)
00239                                                         $elements[$k]['subst'] = array(
00240                                                                 'type' => 'file',
00241                                                                 'relFileName' => $srcRef,
00242                                                                 'tokenID' => $tokenID,
00243                                                                 'tokenValue' => $attribs[0]['src'],
00244                                                         );
00245                                                         if (!@is_file($absPath))        {       // Finally, notice if the file does not exist.
00246                                                                 $elements[$k]['error'] = 'File does not exist!';
00247                                                         }
00248                                                 } else {
00249                                                         $elements[$k]['error'] = 'Could not substitute image source with token!';
00250                                                 }
00251                                         }
00252                                 }
00253                         }
00254                 }
00255 
00256                         // Return result:
00257                 if (count($elements))   {
00258                         $resultArray = array(
00259                                 'content' => implode('', $splitContent),
00260                                 'elements' => $elements
00261                         );
00262 
00263                         return $resultArray;
00264                 }
00265         }
00266 
00276         function findRef_typolink($content, $spParams)  {
00277 
00278                         // First, split the input string by a comma if the "linkList" parameter is set.
00279                         // An example: the link field for images in content elements of type "textpic" or "image". This field CAN be configured to define a link per image, separated by comma.
00280                 if (is_array($spParams) && in_array('linkList',$spParams))      {
00281                         $linkElement = explode(',', $content);  // Preserving whitespace on purpose.
00282                 } else {
00283                         $linkElement = array($content); // If only one element, just set in this array to make it easy below.
00284                 }
00285 
00286                         // Traverse the links now:
00287                 $elements = array();
00288                 foreach($linkElement as $k => $typolinkValue)   {
00289                         $tLP = $this->getTypoLinkParts($typolinkValue);
00290                         $linkElement[$k] = $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k);
00291                 }
00292 
00293                         // Return output:
00294                 if (count($elements))   {
00295                         $resultArray = array(
00296                                 'content' => implode(',', $linkElement),
00297                                 'elements' => $elements
00298                         );
00299 
00300                         return $resultArray;
00301                 }
00302         }
00303 
00313         function findRef_typolink_tag($content, $spParams)      {
00314 
00315                         // Parse string for special TYPO3 <link> tag:
00316                 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
00317                 $linkTags = $htmlParser->splitTags('link',$content);
00318 
00319                         // Traverse result:
00320                 $elements = array();
00321                 foreach($linkTags as $k => $foundValue) {
00322                         if ($k%2)       {
00323                                 $typolinkValue = eregi_replace('<LINK[[:space:]]+','',substr($foundValue,0,-1));
00324                                 $tLP = $this->getTypoLinkParts($typolinkValue);
00325                                 $linkTags[$k] = '<LINK '.$this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k).'>';
00326                         }
00327                 }
00328 
00329                         // Return output:
00330                 if (count($elements))   {
00331                         $resultArray = array(
00332                                 'content' => implode('', $linkTags),
00333                                 'elements' => $elements
00334                         );
00335 
00336                         return $resultArray;
00337                 }
00338         }
00339 
00348         function findRef_TStemplate($content, $spParams)        {
00349                 $elements = array();
00350 
00351                         // First, try to find images and links:
00352                 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
00353                 $splitContent = $htmlParser->splitTags('img,a,form', $content);
00354 
00355                         // Traverse splitted parts:
00356                 foreach($splitContent as $k => $v)      {
00357                         if ($k%2)       {
00358 
00359                                 $attribs = $htmlParser->get_tag_attributes($v);
00360 
00361                                 $attributeName = '';
00362                                 switch($htmlParser->getFirstTagName($v))        {
00363                                         case 'img':
00364                                                 $attributeName = 'src';
00365                                         break;
00366                                         case 'a':
00367                                                 $attributeName = 'href';
00368                                         break;
00369                                         case 'form':
00370                                                 $attributeName = 'action';
00371                                         break;
00372                                 }
00373 
00374                                         // Get file reference:
00375                                 if (isset($attribs[0][$attributeName])) {
00376                                         $srcRef = t3lib_div::htmlspecialchars_decode($attribs[0][$attributeName]);
00377 
00378                                                 // Set entry:
00379                                         $tokenID = $this->makeTokenID($k);
00380                                         $elements[$k] = array();
00381                                         $elements[$k]['matchString'] = $v;
00382 
00383                                                 // OK, if it looks like a local file from fileadmin/, include it:
00384                                         $pI = pathinfo($srcRef);
00385                                         $absPath = t3lib_div::getFileAbsFileName(PATH_site.$srcRef);
00386                                         if (t3lib_div::isFirstPartOfStr($srcRef,$this->fileAdminDir.'/') && !$pI['query'] && $absPath)  {
00387 
00388                                                         // Token and substitute value:
00389                                                 if (strstr($splitContent[$k], $attribs[0][$attributeName]))     {       // Very important that the src-value is not DeHSC'ed
00390                                                         $splitContent[$k] = str_replace($attribs[0][$attributeName], '{softref:'.$tokenID.'}', $splitContent[$k]);
00391                                                         $elements[$k]['subst'] = array(
00392                                                                 'type' => 'file',
00393                                                                 'relFileName' => $srcRef,
00394                                                                 'tokenID' => $tokenID,
00395                                                                 'tokenValue' => $attribs[0][$attributeName],
00396                                                         );
00397                                                         if (!@is_file($absPath))        {
00398                                                                 $elements[$k]['error'] = 'File does not exist!';
00399                                                         }
00400                                                 } else {
00401                                                         $elements[$k]['error'] = 'Could not substitute attribute ('.$attributeName.') value with token!';
00402                                                 }
00403                                         }
00404                                 }
00405                         }
00406                 }
00407                 $content = implode('', $splitContent);
00408 
00409                         // Process free fileadmin/ references as well:
00410                 $content = $this->fileadminReferences($content, $elements);
00411 
00412                         // Return output:
00413                 if (count($elements))   {
00414                         $resultArray = array(
00415                                 'content' => $content,
00416                                 'elements' => $elements
00417                         );
00418                         return $resultArray;
00419                 }
00420         }
00421 
00430         function findRef_TSconfig($content, $spParams)  {
00431                 $elements = array();
00432 
00433                         // Process free fileadmin/ references from TSconfig
00434                 $content = $this->fileadminReferences($content, $elements);
00435 
00436                         // Return output:
00437                 if (count($elements))   {
00438                         $resultArray = array(
00439                                 'content' => $content,
00440                                 'elements' => $elements
00441                         );
00442                         return $resultArray;
00443                 }
00444         }
00445 
00453         function findRef_email($content, $spParams)     {
00454                 $resultArray = array();
00455 
00456                         // email:
00457                 $parts = preg_split("/([^[:alnum:]]+)([A-Za-z0-9\._-]+[@][A-Za-z0-9\._-]+[\.].[A-Za-z0-9]+)/", ' '.$content.' ',10000, PREG_SPLIT_DELIM_CAPTURE);
00458                 foreach($parts as $idx => $value)       {
00459                         if ($idx%3 == 2)        {
00460 
00461                                 $tokenID = $this->makeTokenID($idx);
00462                                 $elements[$idx] = array();
00463                                 $elements[$idx]['matchString'] = $value;
00464 
00465                                 if (is_array($spParams) && in_array('subst',$spParams)) {
00466                                         $parts[$idx] = '{softref:'.$tokenID.'}';
00467                                         $elements[$idx]['subst'] = array(
00468                                                 'type' => 'string',
00469                                                 'tokenID' => $tokenID,
00470                                                 'tokenValue' => $value,
00471                                         );
00472                                 }
00473                         }
00474                 }
00475 
00476                         // Return output:
00477                 if (count($elements))   {
00478                         $resultArray = array(
00479                                 'content' => substr(implode('',$parts),1,-1),
00480                                 'elements' => $elements
00481                         );
00482                         return $resultArray;
00483                 }
00484         }
00485 
00493         function findRef_url($content, $spParams)       {
00494                 $resultArray = array();
00495 
00496                         // Fileadmin files:
00497                 $parts = preg_split("/([^[:alnum:]\"']+)((http|ftp):\/\/[^[:space:]\"'<>]*)([[:space:]])/", ' '.$content.' ',10000, PREG_SPLIT_DELIM_CAPTURE);
00498 
00499                 foreach($parts as $idx => $value)       {
00500                         if ($idx%5 == 3)        { unset($parts[$idx]); }
00501                         if ($idx%5 == 2)        {
00502 
00503                                 $tokenID = $this->makeTokenID($idx);
00504                                 $elements[$idx] = array();
00505                                 $elements[$idx]['matchString'] = $value;
00506 
00507                                 if (is_array($spParams) && in_array('subst',$spParams)) {
00508                                         $parts[$idx] = '{softref:'.$tokenID.'}';
00509                                         $elements[$idx]['subst'] = array(
00510                                                 'type' => 'string',
00511                                                 'tokenID' => $tokenID,
00512                                                 'tokenValue' => $value,
00513                                         );
00514                                 }
00515                         }
00516                 }
00517 
00518                         // Return output:
00519                 if (count($elements))   {
00520                         $resultArray = array(
00521                                 'content' => substr(implode('',$parts),1,-1),
00522                                 'elements' => $elements
00523                         );
00524                         return $resultArray;
00525                 }
00526         }
00527 
00535         function findRef_extension_fileref($content, $spParams) {
00536                 $resultArray = array();
00537 
00538                         // Fileadmin files:
00539                 $parts = preg_split("/([^[:alnum:]\"']+)(EXT:[[:alnum:]_]+\/[^[:space:]\"',]*)/", ' '.$content.' ',10000, PREG_SPLIT_DELIM_CAPTURE);
00540 
00541                 foreach($parts as $idx => $value)       {
00542                         if ($idx%3 == 2)        {
00543 
00544                                 $tokenID = $this->makeTokenID($idx);
00545                                 $elements[$idx] = array();
00546                                 $elements[$idx]['matchString'] = $value;
00547                         }
00548                 }
00549 
00550                         // Return output:
00551                 if (count($elements))   {
00552                         $resultArray = array(
00553                                 'content' => substr(implode('',$parts),1,-1),
00554                                 'elements' => $elements
00555                         );
00556                         return $resultArray;
00557                 }
00558         }
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573         /*************************
00574          *
00575          * Helper functions
00576          *
00577          *************************/
00578 
00587         function fileadminReferences($content, &$elements)      {
00588 
00589                         // Fileadmin files are found
00590                 $parts = preg_split("/([^[:alnum:]]+)(".$this->fileAdminDir."\/[^[:space:]\"'<>]*)/", ' '.$content.' ',10000, PREG_SPLIT_DELIM_CAPTURE);
00591 
00592                         // Traverse files:
00593                 foreach($parts as $idx => $value)       {
00594                         if ($idx%3 == 2)        {
00595 
00596                                         // when file is found, set up an entry for the element:
00597                                 $tokenID = $this->makeTokenID('fileadminReferences:'.$idx);
00598                                 $elements['fileadminReferences.'.$idx] = array();
00599                                 $elements['fileadminReferences.'.$idx]['matchString'] = $value;
00600                                 $elements['fileadminReferences.'.$idx]['subst'] = array(
00601                                         'type' => 'file',
00602                                         'relFileName' => $value,
00603                                         'tokenID' => $tokenID,
00604                                         'tokenValue' => $value,
00605                                 );
00606                                 $parts[$idx] = '{softref:'.$tokenID.'}';
00607 
00608                                         // Check if the file actually exists:
00609                                 $absPath = t3lib_div::getFileAbsFileName(PATH_site.$value);
00610                                 if (!@is_file($absPath))        {
00611                                         $elements['fileadminReferences.'.$idx]['error'] = 'File does not exist!';
00612                                 }
00613                         }
00614                 }
00615 #debug($parts);
00616                         // Implode the content again, removing prefixed and trailing white space:
00617                 return substr(implode('',$parts),1,-1);
00618         }
00619 
00630         function getTypoLinkParts($typolinkValue)       {
00631                 $finalTagParts = array();
00632 
00633                         // Split by space into link / target / class
00634                 list($link_param, $browserTarget, $cssClass) = t3lib_div::trimExplode(' ',$typolinkValue,1);
00635                 if (strlen($browserTarget))     $finalTagParts['target'] = $browserTarget;
00636                 if (strlen($cssClass))  $finalTagParts['class'] = $cssClass;
00637 
00638                         // Parse URL:
00639                 $pU = parse_url($link_param);
00640 
00641                         // Detecting the kind of reference:
00642                 if(strstr($link_param,'@') && !$pU['scheme'])   {               // If it's a mail address:
00643                         $link_param = eregi_replace('^mailto:','',$link_param);
00644 
00645                         $finalTagParts['LINK_TYPE'] = 'mailto';
00646                         $finalTagParts['url'] = trim($link_param);
00647                 } else {
00648                         $isLocalFile = 0;
00649                         $fileChar = intval(strpos($link_param, '/'));
00650                         $urlChar = intval(strpos($link_param, '.'));
00651 
00652                                 // Detects if a file is found in site-root (or is a 'virtual' simulateStaticDocument file!) and if so it will be treated like a normal file.
00653                         list($rootFileDat) = explode('?',rawurldecode($link_param));
00654                         $containsSlash = strstr($rootFileDat,'/');
00655                         $rFD_fI = pathinfo($rootFileDat);
00656                         if (trim($rootFileDat) && !$containsSlash && (@is_file(PATH_site.$rootFileDat) || t3lib_div::inList('php,html,htm',strtolower($rFD_fI['extension']))))  {
00657                                 $isLocalFile = 1;
00658                         } elseif ($containsSlash)       {
00659                                 $isLocalFile = 2;               // Adding this so realurl directories are linked right (non-existing).
00660                         }
00661 
00662                         if($pU['scheme'] || ($isLocalFile!=1 && $urlChar && (!$containsSlash || $urlChar<$fileChar)))   {       // url (external): If doubleSlash or if a '.' comes before a '/'.
00663                                 $finalTagParts['LINK_TYPE'] = 'url';
00664                                 $finalTagParts['url'] = $link_param;
00665                         } elseif ($containsSlash || $isLocalFile)       {       // file (internal)
00666                                 $splitLinkParam = explode('?', $link_param);
00667                                 if (@file_exists(rawurldecode($splitLinkParam[0])) || $isLocalFile)     {
00668                                         $finalTagParts['LINK_TYPE'] = 'file';
00669                                         $finalTagParts['filepath'] = rawurldecode($splitLinkParam[0]);
00670                                         $finalTagParts['query'] = $splitLinkParam[1];
00671                                 }
00672                         } else {        // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to definition in $TCA!)
00673                                 $finalTagParts['LINK_TYPE'] = 'page';
00674 
00675                                 $link_params_parts = explode('#',$link_param);
00676                                 $link_param = trim($link_params_parts[0]);              // Link-data del
00677 
00678                                 if (strlen($link_params_parts[1]))      {
00679                                         $finalTagParts['anchor'] = trim($link_params_parts[1]);
00680                                 }
00681 
00682                                         // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/? pair
00683                                 $pairParts = t3lib_div::trimExplode(',',$link_param);
00684                                 if (count($pairParts)>1)        {
00685                                         $link_param = $pairParts[0];
00686                                         $finalTagParts['type'] = $pairParts[1];         // Overruling 'type'
00687                                 }
00688 
00689                                         // Checking if the id-parameter is an alias.
00690                                 if (strlen($link_param))        {
00691                                         if (!t3lib_div::testInt($link_param))   {
00692                                                 $finalTagParts['alias'] = $link_param;
00693                                                 $link_param = $this->getPageIdFromAlias($link_param);
00694                                         }
00695 
00696                                         $finalTagParts['page_id'] = intval($link_param);
00697                                 }
00698                         }
00699                 }
00700 
00701                 return $finalTagParts;
00702         }
00703 
00714         function setTypoLinkPartsElement($tLP, &$elements, $content, $idx)      {
00715 
00716                         // Initialize, set basic values. In any case a link will be shown
00717                 $tokenID = $this->makeTokenID('setTypoLinkPartsElement:'.$idx);
00718                 $elements[$tokenID.':'.$idx] = array();
00719                 $elements[$tokenID.':'.$idx]['matchString'] = $content;
00720 
00721                         // Based on link type, maybe do more:
00722                 switch ((string)$tLP['LINK_TYPE'])      {
00723                         case 'mailto':
00724                                         // Mail addresses can be substituted manually:
00725                                 $elements[$tokenID.':'.$idx]['subst'] = array(
00726                                         'type' => 'string',
00727                                         'tokenID' => $tokenID,
00728                                         'tokenValue' => $tLP['url'],
00729                                 );
00730                                         // Output content will be the token instead:
00731                                 $content = '{softref:'.$tokenID.'}';
00732                         break;
00733                         case 'url':
00734                                         // Nothing done, only for informational purposes. So return content right away:
00735                                 return $content;
00736                         break;
00737                         case 'file':
00738                                         // Process files found in fileadmin directory:
00739                                 if (!$tLP['query'])     {       // We will not process files which has a query added to it. That will look like a script we don't want to move.
00740                                         if (t3lib_div::isFirstPartOfStr($tLP['filepath'],$this->fileAdminDir.'/'))      {       // File must be inside fileadmin/
00741 
00742                                                         // Set up the basic token and token value for the relative file:
00743                                                 $elements[$tokenID.':'.$idx]['subst'] = array(
00744                                                         'type' => 'file',
00745                                                         'relFileName' => $tLP['filepath'],
00746                                                         'tokenID' => $tokenID,
00747                                                         'tokenValue' => $tLP['filepath'],
00748                                                 );
00749 
00750                                                         // Depending on whether the file exists or not we will set the
00751                                                 $absPath = t3lib_div::getFileAbsFileName(PATH_site.$tLP['filepath']);
00752                                                 if (!@is_file($absPath))        {
00753                                                         $elements[$tokenID.':'.$idx]['error'] = 'File does not exist!';
00754                                                 }
00755 
00756                                                         // Output content will be the token instead
00757                                                 $content = '{softref:'.$tokenID.'}';
00758                                         } else return $content;
00759                                 } else return $content;
00760                         break;
00761                         case 'page':
00762                                         // Rebuild page reference typolink part:
00763                                 $content = '';
00764 
00765                                         // Set page id:
00766                                 if ($tLP['page_id'])    {
00767                                         $content.= '{softref:'.$tokenID.'}';
00768                                         $elements[$tokenID.':'.$idx]['subst'] = array(
00769                                                 'type' => 'db',
00770                                                 'recordRef' => 'pages:'.$tLP['page_id'],
00771                                                 'tokenID' => $tokenID,
00772                                                 'tokenValue' => $tLP['alias'] ? $tLP['alias'] : $tLP['page_id'],        // Set page alias if that was used.
00773                                         );
00774                                 }
00775 
00776                                         // Add type if applicable
00777                                 if (strlen($tLP['type']))       {
00778                                         $content.= ','.$tLP['type'];
00779                                 }
00780 
00781                                         // Add anchor if applicable
00782                                 if (strlen($tLP['anchor']))     {
00783                                         if (t3lib_div::testInt($tLP['anchor'])) {       // Anchor is assumed to point to a content elements:
00784                                                         // Initialize a new entry because we have a new relation:
00785                                                 $newTokenID = $this->makeTokenID('setTypoLinkPartsElement:anchor:'.$idx);
00786                                                 $elements[$newTokenID.':'.$idx] = array();
00787                                                 $elements[$newTokenID.':'.$idx]['matchString'] = 'Anchor Content Element: '.$tLP['anchor'];
00788 
00789                                                 $content.= '#{softref:'.$newTokenID.'}';
00790                                                 $elements[$newTokenID.':'.$idx]['subst'] = array(
00791                                                         'type' => 'db',
00792                                                         'recordRef' => 'tt_content:'.$tLP['anchor'],
00793                                                         'tokenID' => $newTokenID,
00794                                                         'tokenValue' => $tLP['anchor'],
00795                                                 );
00796                                         } else {        // Anchor is a hardcoded string
00797                                                 $content.= '#'.$tLP['type'];
00798                                         }
00799                                 }
00800                         break;
00801                         default:
00802                                 $elements[$tokenID.':'.$idx]['error'] = 'Couldn\t decide typolink mode.';
00803                                 return $content;
00804                         break;
00805                 }
00806 
00807                         // Finally, for all entries that was rebuild with tokens, add target and class in the end:
00808                 if (strlen($content) && strlen($tLP['target'])) {
00809                         $content.= ' '.$tLP['target'];
00810                         if (strlen($tLP['class']))      {
00811                                 $content.= ' '.$tLP['class'];
00812                         }
00813                 }
00814 
00815                         // Return rebuilt typolink value:
00816                 return $content;
00817         }
00818 
00825         function getPageIdFromAlias($link_param)        {
00826                 $pRec = t3lib_BEfunc::getRecordsByField('pages','alias',$link_param);
00827 
00828                 return $pRec[0]['uid'];
00829         }
00830 
00837         function makeTokenID($index='') {
00838                 return md5($this->tokenID_basePrefix.':'.$index);
00839         }
00840 }
00841 
00842 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_softrefproc.php'])       {
00843         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_softrefproc.php']);
00844 }
00845 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6