Commit 5e0fd8e9 authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

Initial Commit

parents
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!
***************************************************************/
/**
* Script class for the Element Browser window.
*/
class BrowseLinksController {
public $mode = 'rte';
public $button = 'link';
protected $content = '';
/**
* Initialize language files
*/
public function __construct() {
$GLOBALS['LANG']->includeLLFile('EXT:tinymce4_rte/mod3/locallang.xlf');
}
/**
* Main function, rendering the element browser in RTE mode.
*
* @return void
* @todo Define visibility
*/
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();
}
}
/**
* Print module content
*
* @return void
* @todo Define visibility
*/
public function printContent() {
echo $this->content;
}
}
<?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
* 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\Resource;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Render the image attributes and reconstruct magic images, if necessary (and possible)
*/
class ImageRenderingController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
/**
* Same as class name
*
* @var string
*/
public $prefixId = 'ImageRenderingController';
/**
* Path to this script relative to the extension dir
*
* @var string
*/
public $scriptRelPath = 'Classes/Controller/ImageRenderingController.php';
/**
* The extension key
*
* @var string
*/
public $extKey = 'tinymce4_rte';
/**
* Configuration
*
* @var array
*/
public $conf = array();
/**
* cObj object
*
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $cObj;
/**
* Returns a processed image to be displayed on the Frontend.
*
* @param string $content Content input (not used).
* @param array $conf TypoScript configuration
* @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'];
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']
);
$processedFile = $this->getMagicImageService()->createMagicImage($file, $imageConfiguration);
$additionalAttributes = array(
'src' => $processedFile->getPublicUrl(),
'title' => $imageAttributes['title'] ? : $file->getProperty('title'),
'alt' => $imageAttributes['alt'] ? : $file->getProperty('alternative'),
'width' => $processedFile->getProperty('width'),
'height' => $processedFile->getProperty('height'),
);
$imageAttributes = array_merge($imageAttributes, $additionalAttributes);
}
} catch (Resource\Exception\FileDoesNotExistException $fileDoesNotExistException) {
// Log the fact the file could not be retrieved.
$message = sprintf('I could not find file with uid "%s"', $fileUid);
$this->getLogger()->error($message);
}
}
}
return '<img ' . GeneralUtility::implodeAttributes($imageAttributes, TRUE, TRUE) . ' />';
}
/**
* Returns a sanitizes array of attributes out of $this->cObj
*
* @return array
*/
protected function getImageAttributes() {
return $this->cObj->parameters;
}
/**
* Instantiates and prepares the Magic Image service.
*
* @return \TYPO3\CMS\Core\Resource\Service\MagicImageService
*/
protected function getMagicImageService() {
/** @var $magicImageService Resource\Service\MagicImageService */
$magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
// Get RTE configuration
$pageTSConfig = $this->getFrontendObject()->getPagesTSconfig();
if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
$magicImageService->setMagicImageMaximumDimensions($pageTSConfig['RTE.']);
}
return $magicImageService;
}
/**
* Tells whether the image URL is found to be "external".
*
* @return bool
*/
protected function isExternalImage() {
$srcAbsoluteUrl = $this->cObj->parameters['src'];
return strtolower(substr($srcAbsoluteUrl, 0, 4)) === 'http' || substr($srcAbsoluteUrl, 0, 2) === '//';
}
/**
* @return \TYPO3\CMS\Core\Log\Logger
*/
protected function getLogger() {
/** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
$logManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
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!
***************************************************************/
/**
* Script class for the Element Browser window.
*/
class SelectImageController {
public $mode = 'rte';
public $button = 'image';
protected $content = '';
/**
* Initialize language files
*/
public function __construct() {
$GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser.xlf');
$GLOBALS['LANG']->includeLLFile('EXT:tinymce4_rte/mod4/locallang.xlf');
}
/**
* Main function, rendering the element browser in RTE mode.
*
* @return void
* @todo Define visibility
*/
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();
}
}
/**
* Print module content
*
* @return void
* @todo Define visibility
*/
public function printContent() {
echo $this->content;
}
}
<?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 TYPO3\CMS\Backend\Form\FormEngine;
use TYPO3\CMS\Backend\Rte\AbstractRte;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* 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
) {
// render the tinymce textarea
$value = $this->transformContent(
'rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue
);
// render RTE field
$editorId = uniqid();
$code = $this->triggerField($PA['itemFormElName']);
$code .= '<textarea id="editor' . $editorId . '" class="tinymce4_rte"
name="' . htmlspecialchars($PA['itemFormElName']) . '"
rows="20" cols="100">' . GeneralUtility::formatForTextarea($value) . '</textarea>';
// add 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)
);
$languageId = max($row['sys_language_uid'], 0);
$language = ($GLOBALS['LANG']->lang === '' ? 'default' : $GLOBALS['LANG']->lang);
$code .= '
<script type = "text/javascript" >
var RTE = RTE || {};
RTE["editor' . $editorId . '"] = {};
RTE["editor' . $editorId . '"].rteConfiguration = "' . $rteConfiguration . '";
RTE["editor' . $editorId . '"].typo3ContentLanguage = "' . $language . '";
RTE["editor' . $editorId . '"].sys_language_content = parseInt(' . $languageId . ');
</script>';
// load the tinymce code and it's configuration
if (!self::$coreLoaded) {
self::$coreLoaded = TRUE;
$userOrPageProperties = BackendUtility::getModTSconfig($thePidValue, 'RTE');
/** @var \tinyMCE $tinyMCE */
require_once(ExtensionManagementUtility::extPath('tinymce') . 'class.tinymce.php');
$tinyMCE = GeneralUtility::makeInstance('tinyMCE');
$tinyMCE->loadConfiguration($userOrPageProperties['properties']['default.']['tinymceConfiguration']);
if ($userOrPageProperties['properties']['default.']['contentCSS'] !== '') {
$tinyMCE->addConfigurationOption(
'content_css',
'/' . $userOrPageProperties['properties']['default.']['contentCSS']
);
}
$code .= $tinyMCE->getJS();
$imageModule = BackendUtility::getModuleUrl('rtehtmlarea_wizard_select_image');
$linkModule = BackendUtility::getModuleUrl('rtehtmlarea_wizard_element_browser');
$code .= '
<script type = "text/javascript" >
var RTE = RTE || {};
RTE.linkToImageModule = ' . GeneralUtility::quoteJSvalue($imageModule) . ';
RTE.linkToLinkModule = ' . GeneralUtility::quoteJSvalue($linkModule) . ';
</script>';
}
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 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 TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Base extension class which generates the folder tree.
* Used directly by the RTE.
*/
class FolderTree extends \localFolderTree {
/**
* Constructor function of the class
*/
public function __construct() {
// The backpath is set here to fix problems with relatives path when used in ajax scope
$GLOBALS['BACK_PATH'] = isset($GLOBALS['ajaxID']) ? '../../../' : $GLOBALS['BACK_PATH'];
parent::__construct();
}
/**
* Wrapping the title in a link, if applicable.
*
* @param string $title Title, ready for output.
* @param \TYPO3\CMS\Core\Resource\Folder $folderObject The "record"
* @return string Wrapping title string.
* @todo Define visibility
*/
public function wrapTitle($title, \TYPO3\CMS\Core\Resource\Folder $folderObject) {
if ($this->ext_isLinkable($folderObject)) {
$aOnClick = 'return jumpToUrl(\'' . $this->getThisScript(
) . 'act=' . $GLOBALS['SOBE']->browser->act . '&mode=' . $GLOBALS['SOBE']->browser->mode . '&editorNo=' . $GLOBALS['SOBE']->browser->editorNo . '&contentTypo3Language=' . $GLOBALS['SOBE']->browser->contentTypo3Language . '&contentTypo3Charset=' . $GLOBALS['SOBE']->browser->contentTypo3Charset . '&expandFolder=' . rawurlencode(
$folderObject->getCombinedIdentifier()
) . '\');';
return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
} else {
return '<span class="typo3-dimmed">' . $title . '</span>';
}
}
/**
* Wrap the plus/minus icon in a link
*
* @param string $icon HTML string to wrap, probably an image tag.