Commit d2bc8ef5 authored by Fabian Galinski's avatar Fabian Galinski 😾
Browse files

Merge branch '74compatibility' into 'master'

TYPO3 7.4 compatibility



See merge request !3
parents bec914e6 0edc3eba
This diff is collapsed.
<?php
namespace SGalinski\Tinymce4Rte\Controller;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
use TYPO3\CMS\Recordlist\Controller\ElementBrowserController;
use SGalinski\Tinymce4Rte\BrowseLinks;
/**
* Script class for the Element Browser window.
*/
class BrowseLinksController {
public $mode = 'rte';
class BrowseLinksController extends ElementBrowserController {
/**
* @var string
*/
public $button = 'link';
protected $content = '';
/**
* Initialize language files
* @var BrowseLinks
*/
public function __construct() {
$GLOBALS['LANG']->includeLLFile('EXT:tinymce4_rte/mod3/locallang.xlf');
}
public $browser;
/**
* Main function, rendering the element browser in RTE mode.
*
* @return void
* @todo Define visibility
* Initialize controller
*/
public function main() {
// Setting alternative web browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
$altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
// Clear temporary DB mounts
$tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
if (isset($tmpMount)) {
$GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', (int) $tmpMount);
}
// Set temporary DB mounts
$tempDBmount = (int) $GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint');
if ($tempDBmount) {
$altMountPoints = $tempDBmount;
}
if ($altMountPoints) {
$GLOBALS['BE_USER']->groupData['webmounts'] = implode(
',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints))
);
$GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
}
// Setting alternative file browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
$altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
if ($altMountPoints) {
$altMountPoints = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $altMountPoints);
foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
// @todo: add this feature for FAL and TYPO3 6.2
}
}
// Render type by user function
$browserRendered = FALSE;
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
$browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists(
$browserRenderObj, 'render'
)
) {
if ($browserRenderObj->isValid($this->mode, $this)) {
$this->content .= $browserRenderObj->render($this->mode, $this);
$browserRendered = TRUE;
break;
}
}
}
}
// If type was not rendered, use default rendering functions
if (!$browserRendered) {
$GLOBALS['SOBE']->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'SGalinski\\Tinymce4Rte\\BrowseLinks'
);
$GLOBALS['SOBE']->browser->init();
$modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
list($modData, $store) = $GLOBALS['SOBE']->browser->processSessionData($modData);
$GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
$this->content = $GLOBALS['SOBE']->browser->main_rte();
}
protected function init() {
parent::init();
$lang = $this->getLanguageService();
$lang->includeLLFile('EXT:tinymce4_rte/Resources/Private/Language/locallang_browselinkscontroller.xlf');
$lang->includeLLFile('EXT:tinymce4_rte/Resources/Private/Language/locallang_dialogs.xlf');
$this->mode = 'rte';
}
/**
* Print module content
* Get instance of ElementBrowser
*
* This method shall be overwritten in subclasses
*
* @return void
* @todo Define visibility
* @return ElementBrowser
*/
public function printContent() {
echo $this->content;
protected function getElementBrowserInstance() {
return GeneralUtility::makeInstance(BrowseLinks::class);
}
}
<?php
namespace SGalinski\Tinymce4Rte\Controller;
/**
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
......@@ -15,8 +14,8 @@ namespace SGalinski\Tinymce4Rte\Controller;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Resource;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Resource;
/**
* Render the image attributes and reconstruct magic images, if necessary (and possible)
......@@ -66,27 +65,28 @@ class ImageRenderingController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
* @return string HTML output
*/
public function renderImageAttributes($content = '', $conf) {
$imageAttributes = $this->getImageAttributes();
// It is pretty rare to be in presence of an external image as the default behaviour
// of the RTE is to download the external image and create a local image.
// However, it may happen if the RTE has the flag "disable"
if (!$this->isExternalImage()) {
$fileUid = (int) $imageAttributes['data-htmlarea-file-uid'];
$fileUid = (int)$imageAttributes['data-htmlarea-file-uid'];
if ($fileUid) {
try {
$file = Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
if ($imageAttributes['src'] !== $file->getPublicUrl()) {
// Source file is a processed image
$imageConfiguration = array(
'width' => (int) $imageAttributes['width'],
'height' => (int) $imageAttributes['height']
'width' => (int)$imageAttributes['width'],
'height' => (int)$imageAttributes['height']
);
$processedFile = $this->getMagicImageService()->createMagicImage($file, $imageConfiguration);
$additionalAttributes = array(
'src' => $processedFile->getPublicUrl(),
'title' => $imageAttributes['title'] ? : $file->getProperty('title'),
'alt' => $imageAttributes['alt'] ? : $file->getProperty('alternative'),
'title' => $imageAttributes['title'] ?: $file->getProperty('title'),
'alt' => $imageAttributes['alt'] ?: $file->getProperty('alternative'),
'width' => $processedFile->getProperty('width'),
'height' => $processedFile->getProperty('height'),
);
......@@ -119,12 +119,12 @@ class ImageRenderingController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
protected function getMagicImageService() {
/** @var $magicImageService Resource\Service\MagicImageService */
$magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
$magicImageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Service\MagicImageService::class);
// Get RTE configuration
$pageTSConfig = $this->getFrontendObject()->getPagesTSconfig();
if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
$magicImageService->setMagicImageMaximumDimensions($pageTSConfig['RTE.']);
$pageTSConfig = $this->frontendController->getPagesTSconfig();
if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.']['default.'])) {
$magicImageService->setMagicImageMaximumDimensions($pageTSConfig['RTE.']['default.']);
}
return $magicImageService;
......@@ -146,17 +146,9 @@ class ImageRenderingController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
protected function getLogger() {
/** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
$logManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
$logManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class);
return $logManager->getLogger(get_class($this));
}
/**
* Returns an instance of the Frontend object.
*
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
protected function getFrontendObject() {
return $GLOBALS['TSFE'];
}
}
<?php
namespace SGalinski\Tinymce4Rte\Controller;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
use TYPO3\CMS\Recordlist\Controller\ElementBrowserController;
use SGalinski\Tinymce4Rte\SelectImage;
/**
* Script class for the Element Browser window.
* Script class for the Element Browser window to select images in RTE
*/
class SelectImageController {
public $mode = 'rte';
class SelectImageController extends ElementBrowserController {
/**
* @var string
*/
public $button = 'image';
protected $content = '';
/**
* Initialize language files
* @var SelectImage
*/
public function __construct() {
$GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser.xlf');
$GLOBALS['LANG']->includeLLFile('EXT:tinymce4_rte/mod4/locallang.xlf');
}
public $browser;
/**
* Main function, rendering the element browser in RTE mode.
*
* @return void
* @todo Define visibility
* Initialize controller
*/
public function main() {
// Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
$altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
if ($altMountPoints) {
$altMountPoints = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $altMountPoints);
foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
// @todo: add this feature for FAL and TYPO3 6.2
}
}
// Rendering type by user function
$browserRendered = FALSE;
if (is_array(
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser.php']['browserRendering']
)
) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser.php']['browserRendering'] as $classRef) {
$browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists(
$browserRenderObj, 'render'
)
) {
if ($browserRenderObj->isValid($this->mode, $this)) {
$this->content .= $browserRenderObj->render($this->mode, $this);
$browserRendered = TRUE;
break;
}
}
}
}
// If type was not rendered, use default rendering functions
if (!$browserRendered) {
$GLOBALS['SOBE']->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'SGalinski\\Tinymce4Rte\\SelectImage'
);
$GLOBALS['SOBE']->browser->init();
$modData = $GLOBALS['BE_USER']->getModuleData('select_image.php', 'ses');
list($modData, $store) = $GLOBALS['SOBE']->browser->processSessionData($modData);
$GLOBALS['BE_USER']->pushModuleData('select_image.php', $modData);
$this->content = $GLOBALS['SOBE']->browser->main_rte();
}
protected function init() {
parent::init();
$lang = $this->getLanguageService();
$lang->includeLLFile('EXT:tinymce4_rte/Resources/Private/Language/locallang_selectimagecontroller.xlf');
$lang->includeLLFile('EXT:tinymce4_rte/Resources/Private/Language/locallang_dialogs.xlf');
$this->mode = 'rte';
}
/**
* Print module content
* Get instance of ElementBrowser
*
* This method shall be overwritten in subclasses
*
* @return void
* @todo Define visibility
* @return ElementBrowser
*/
public function printContent() {
echo $this->content;
protected function getElementBrowserInstance() {
return GeneralUtility::makeInstance(SelectImage::class);
}
}
<?php
namespace SGalinski\Tinymce4Rte\Editors;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\Tinymce\Loader;
use TYPO3\CMS\Backend\Form\FormEngine;
use TYPO3\CMS\Backend\Rte\AbstractRte;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* A RTE using TinyMCE
*/
class RteBase extends AbstractRte {
/**
* Indicates that the tinymce is loaded
*
* @var bool
*/
static protected $coreLoaded = FALSE;
/**
* Draws the RTE as a form field or whatever is needed (inserts JavaApplet, creates iframe, renders ....)
* Default is to output the transformed content in a plain textarea field. This mode is great for debugging transformations!
*
* @param FormEngine $parentObject Reference to parent object, which is an instance of the TCEforms.
* @param string $table The table name
* @param string $field The field name
* @param array $row The current row from which field is being rendered
* @param array $PA Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
* @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
* @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
* @param string $RTEtypeVal Record "type" field value.
* @param string $RTErelPath Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
* @param integer $thePidValue PID value of record (true parent page id)
* @return string HTML code for RTE!
*/
public function drawRTE(
FormEngine $parentObject, $table, $field, $row, $PA, $specConf,
$thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue
) {
/** @var PageRenderer $pageRenderer */
$pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
// render the tinymce textarea
$value = $this->transformContent(
'rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue
);
// render RTE field
$editorId = uniqid();
$width = (GeneralUtility::_GP('M') === 'wizard_rte' ? '100%' : '650px');
$code = $this->triggerField($PA['itemFormElName']);
$code .= '<div style="width: ' . $width . '"><textarea id="editor' . $editorId . '" class="tinymce4_rte"
name="' . htmlspecialchars($PA['itemFormElName']) . '"
rows="20" cols="100">' . GeneralUtility::formatForTextarea($value) . '</textarea></div>';
// add the tinymce code and it's configuration
if (!self::$coreLoaded) {
self::$coreLoaded = TRUE;
$userOrPageProperties = BackendUtility::getModTSconfig($thePidValue, 'RTE');
/** @var Loader $tinyMCE */
$tinyMCE = GeneralUtility::makeInstance('SGalinski\\Tinymce\\Loader');
$tinyMCE->loadConfiguration($userOrPageProperties['properties']['default.']['tinymceConfiguration']);
if ($userOrPageProperties['properties']['default.']['contentCSS'] !== '') {
$contentCssFile = GeneralUtility::getFileAbsFileName(
$userOrPageProperties['properties']['default.']['contentCSS']
);
if (is_file($contentCssFile)) {
$contentCssFile = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') .
PathUtility::stripPathSitePrefix($contentCssFile) . '?' . filemtime($contentCssFile);
$tinyMCE->addConfigurationOption('content_css', $contentCssFile);
}
}
$tinyMCE->addConfigurationOption(
'changeMethod', 'function() {
var TBE_EDITOR = window.TBE_EDITOR || null;
if (TBE_EDITOR && TBE_EDITOR.fieldChanged && typeof TBE_EDITOR.fieldChanged === \'function\') {
TBE_EDITOR.fieldChanged();
}
}'
);
$tinyMCE->loadJsViaPageRenderer($pageRenderer, TRUE);
$imageModule = BackendUtility::getModuleUrl('rtehtmlarea_wizard_select_image');
$linkModule = BackendUtility::getModuleUrl('rtehtmlarea_wizard_element_browser');
$pageRenderer->addJsInlineCode(
'RTEbasic',
'window.RTE = window.RTE || {};
window.RTE.linkToImageModule = ' . GeneralUtility::quoteJSvalue($imageModule) . ';
window.RTE.linkToLinkModule = ' . GeneralUtility::quoteJSvalue($linkModule) . ';'
);
}
// calculate the dedicated RTE configuration
$elementParts = preg_replace('/^(TSFE_EDIT\\[data\\]\\[|data\\[)/', '', $PA['itemFormElName']);
$elementParts = preg_replace('/\\]$/', '', $elementParts);
$elementParts = explode('][', $elementParts);
list($typoscriptConfigurationPid, $pid) = BackendUtility::getTSCpid(
trim($elementParts[0]), trim($elementParts[1]), $thePidValue
);
$rteConfiguration = rawurlencode(
$this->getRteConfiguration($specConf, $RTEtypeVal, $pid, $typoscriptConfigurationPid, $elementParts)
);
// add RTE specific configuration data
$languageId = max($row['sys_language_uid'], 0);
$language = ($GLOBALS['LANG']->lang === '' ? 'default' : $GLOBALS['LANG']->lang);
$pageRenderer->addJsInlineCode(
'RTE' . $editorId,
'window.RTE = window.RTE || {};
window.RTE["editor' . $editorId . '"] = {};
window.RTE["editor' . $editorId . '"].rteConfiguration = "' . $rteConfiguration . '";
window.RTE["editor' . $editorId . '"].typo3ContentLanguage = "' . $language . '";
window.RTE["editor' . $editorId . '"].sys_language_content = parseInt(' . $languageId . ');
'
);
return $code;
}
/**
* @param array $configuration
* @param string $typeValue
* @param int $pid
* @param int $typoscriptConfigurationPid
* @param array $elementParts
* @return string
*/
public function getRteConfiguration(
array $configuration, $typeValue, $pid, $typoscriptConfigurationPid, array $elementParts
) {
$parameters = BackendUtility::getSpecConfParametersFromArray($configuration['rte_transform']['parameters']);
return $elementParts[0] . ':' . $elementParts[1] . ':' . $elementParts[2] . ':' . (int) $pid . ':' .
$typeValue . ':' . (int) $typoscriptConfigurationPid . ':' . $parameters['imgpath'];
}
}
?>
\ No newline at end of file
<?php
namespace SGalinski\Tinymce4Rte;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
/*
* This file is part of the TYPO3 CMS project.
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Base extension class which generates the folder tree.
* Used directly by the RTE.
* RTE class which generates the