TYPO3 CMS  TYPO3_6-2
SoftReferenceHook.php
Go to the documentation of this file.
1 <?php
3 
22 
23  // Token prefix
24  public $tokenID_basePrefix = '';
25 
39  public function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '') {
40  $retVal = FALSE;
41  $this->tokenID_basePrefix = $table . ':' . $uid . ':' . $field . ':' . $structurePath . ':' . $spKey;
42  switch ($spKey) {
43  case 'rtehtmlarea_images':
44  $retVal = $this->findRef_rtehtmlarea_images($content, $spParams);
45  break;
46  default:
47  $retVal = FALSE;
48  }
49  return $retVal;
50  }
51 
61  public function findRef_rtehtmlarea_images($content, $spParams) {
62  $retVal = FALSE;
63  // Start HTML parser and split content by image tag
64  $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
65  $imgTags = $htmlParser->splitTags('img', $content);
66  $elements = array();
67  // Traverse splitted parts
68  foreach ($imgTags as $k => $v) {
69  if ($k % 2) {
70  // Get FAL uid reference
71  $attribs = $htmlParser->get_tag_attributes($v);
72  $fileUid = $attribs[0]['data-htmlarea-file-uid'];
73  $fileTable = $attribs[0]['data-htmlarea-file-table'];
74  // If there is a file uid, continue. Otherwise ignore this img tag.
75  if ($fileUid) {
76  // Initialize the element entry with info text here
77  $tokenID = $this->makeTokenID($k);
78  $elements[$k] = array();
79  $elements[$k]['matchString'] = $v;
80  // Token and substitute value
81  $imgTags[$k] = str_replace('data-htmlarea-file-uid="' . $fileUid . '"', 'data-htmlarea-file-uid="{softref:' . $tokenID . '}"', $imgTags[$k]);
82  $elements[$k]['subst'] = array(
83  'type' => 'db',
84  'recordRef' => ($fileTable ?: 'sys_file') . ':' . $fileUid,
85  'tokenID' => $tokenID,
86  'tokenValue' => $fileUid
87  );
88  }
89  }
90  }
91  // Assemble result array
92  if (count($elements)) {
93  $retVal = array(
94  'content' => implode('', $imgTags),
95  'elements' => $elements
96  );
97  }
98  return $retVal;
99  }
100 
101 }
$uid
Definition: server.php:36
findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath='')