[TASK] Replace all strcmp() calls with ===
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Controller / AccessibilityLinkController.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Remove accessibility icon when no link was rendered
31 *
32 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
33 */
34 class AccessibilityLinkController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
35
36 /**
37 * Same as class name
38 */
39 public $prefixId = 'AccessibilityLinkController';
40
41 /**
42 * Path to this script relative to the extension dir
43 */
44 public $scriptRelPath = 'Classes/Controller/AccessibilityLinkController.php';
45
46 /**
47 * The extension key
48 */
49 public $extKey = 'rtehtmlarea';
50
51 /**
52 * Configuration
53 */
54 public $conf = array();
55
56 /**
57 * cObj object
58 *
59 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
60 */
61 public $cObj;
62
63 /**
64 * Remove accessibility icon when no link was rendered, called from TypoScript
65 *
66 * @param string Content input. Not used, ignore.
67 * @param array TypoScript configuration
68 * @return string HTML output.
69 * @access private
70 */
71 public function removeAccessibilityIcon ($content, $conf) {
72 // If the link was not rendered
73 if (substr($content, 0, 3) !== '<a ' && substr($content, 0, 5) === '<img ') {
74 // Let's remove the accessibility icon, if there is one
75 $matches = array();
76 if (preg_match('/^<img .*>/', $content, $matches) === 1) {
77 $attributes = \TYPO3\CMS\Core\Utility\GeneralUtility::get_tag_attributes($matches[0]);
78 if ($attributes['src']) {
79 // Get RTE Configconfiguration
80 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
81 if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
82 $classesAnchorConfiguration = $pageTSConfig['RTE.']['classesAnchor.'];
83 if (is_array($classesAnchorConfiguration)) {
84 // Make the url of the source relative
85 $siteUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
86 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($attributes['src'], $siteUrl)) {
87 $attributes['src'] = substr($attributes['src'], strlen($siteUrl));
88 }
89 // Lookup the RTE.classesAnchor array
90 foreach ($classesAnchorConfiguration as $item => $conf) {
91 if ($conf['image']) {
92 $imagePath = $this->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image']))));
93 if ($attributes['src'] === $imagePath) {
94 // If found, remove the img tag and break
95 $content = substr($content, strlen($matches[0]));
96 break;
97 }
98 }
99 }
100 }
101 }
102 }
103 }
104 }
105 return $content;
106 }
107 /*
108 * Returns the full name of a file referenced in Page TSConfig
109 */
110 protected function getFullFileName($filename) {
111 if (substr($filename, 0, 4) == 'EXT:') {
112 list($extKey, $local) = explode('/', substr($filename, 4), 2);
113 $newFilename = '';
114 if ((string)$extKey !== '' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
115 $newFilename = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($extKey) . $local;
116 }
117 } elseif (substr($filename, 0, 1) != '/') {
118 $newFilename = $filename;
119 } else {
120 $newFilename = substr($filename, 1);
121 }
122 return \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($newFilename);
123 }
124 }