TYPO3 CMS  TYPO3_7-6
SoftReferenceHook.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
22  // Token prefix
23  public $tokenID_basePrefix = '';
24 
37  public function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '')
38  {
39  $retVal = false;
40  $this->tokenID_basePrefix = $table . ':' . $uid . ':' . $field . ':' . $structurePath . ':' . $spKey;
41  switch ($spKey) {
42  case 'rtehtmlarea_images':
43  $retVal = $this->findRef_rtehtmlarea_images($content, $spParams);
44  break;
45  default:
46  $retVal = false;
47  }
48  return $retVal;
49  }
50 
59  public function findRef_rtehtmlarea_images($content, $spParams)
60  {
61  $retVal = false;
62  // Start HTML parser and split content by image tag
63  $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Html\HtmlParser::class);
64  $imgTags = $htmlParser->splitTags('img', $content);
65  $elements = [];
66  // Traverse splitted parts
67  foreach ($imgTags as $k => $v) {
68  if ($k % 2) {
69  // Get FAL uid reference
70  $attribs = $htmlParser->get_tag_attributes($v);
71  $fileUid = $attribs[0]['data-htmlarea-file-uid'];
72  // If there is a file uid, continue. Otherwise ignore this img tag.
73  if ($fileUid) {
74  // Initialize the element entry with info text here
75  $tokenID = $this->makeTokenID($k);
76  $elements[$k] = [];
77  $elements[$k]['matchString'] = $v;
78  // Token and substitute value
79  $imgTags[$k] = str_replace('data-htmlarea-file-uid="' . $fileUid . '"', 'data-htmlarea-file-uid="{softref:' . $tokenID . '}"', $imgTags[$k]);
80  $elements[$k]['subst'] = [
81  'type' => 'db',
82  'recordRef' => 'sys_file:' . $fileUid,
83  'tokenID' => $tokenID,
84  'tokenValue' => $fileUid
85  ];
86  }
87  }
88  }
89  // Assemble result array
90  if (!empty($elements)) {
91  $retVal = [
92  'content' => implode('', $imgTags),
93  'elements' => $elements
94  ];
95  }
96  return $retVal;
97  }
98 }
$uid
Definition: server.php:38
findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath='')