TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AccessibilityLinkController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Controller;
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 {
25  public $prefixId = 'AccessibilityLinkController';
26 
30  public $scriptRelPath = 'Classes/Controller/AccessibilityLinkController.php';
31 
35  public $extKey = 'rtehtmlarea';
36 
40  public $conf = [];
41 
47  public $cObj;
48 
57  public function removeAccessibilityIcon($content, $conf)
58  {
59  // If the link was not rendered
60  if (substr($content, 0, 3) !== '<a ' && substr($content, 0, 5) === '<img ') {
61  // Let's remove the accessibility icon, if there is one
62  $matches = [];
63  if (preg_match('/^<img .*>/', $content, $matches) === 1) {
65  if ($attributes['src']) {
66  // Get RTE Configconfiguration
67  $pageTSConfig = $this->frontendController->getPagesTSconfig();
68  if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
69  $classesAnchorConfiguration = $pageTSConfig['RTE.']['classesAnchor.'];
70  if (is_array($classesAnchorConfiguration)) {
71  // Make the url of the source relative
72  $siteUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
73  if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($attributes['src'], $siteUrl)) {
74  $attributes['src'] = substr($attributes['src'], strlen($siteUrl));
75  }
76  // Lookup the RTE.classesAnchor array
77  foreach ($classesAnchorConfiguration as $item => $conf) {
78  if ($conf['image']) {
79  $imagePath = $this->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image']))));
80  if ($attributes['src'] === $imagePath) {
81  // If found, remove the img tag and break
82  $content = substr($content, strlen($matches[0]));
83  break;
84  }
85  }
86  }
87  }
88  }
89  }
90  }
91  }
92  return $content;
93  }
94  /*
95  * Returns the full name of a file referenced in Page TSConfig
96  */
97  protected function getFullFileName($filename)
98  {
99  if (strpos($filename, 'EXT:') === 0) {
100  list($extKey, $local) = explode('/', substr($filename, 4), 2);
101  $newFilename = '';
102  if ((string)$extKey !== '' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
104  }
105  } elseif ($filename[0] !== '/') {
106  $newFilename = $filename;
107  } else {
108  $newFilename = substr($filename, 1);
109  }
110  return \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($newFilename);
111  }
112 }
static isFirstPartOfStr($str, $partStr)