Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_parsehtml_proc.patch

Administrator Admin, 2010-11-24 14:03

View differences:

t3lib/class.t3lib_parsehtml_proc.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* 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 2 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* 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 2 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Functions for parsing HTML, specially for TYPO3 processing in relation to TCEmain and Rich Text Editor (RTE)
*
......
*
*
* 103: class t3lib_parsehtml_proc extends t3lib_parsehtml
* 138: function init($elRef='',$recPid=0)
* 138: function init($elRef='',$recPid=0)
* 150: function setRelPath($path)
* 150: function setRelPath($path)
* 174: function evalWriteFile($pArr,$currentRecord)
* 174: function evalWriteFile($pArr,$currentRecord)
*
* SECTION: Main function
* SECTION: Main function
* 232: function RTE_transform($value,$specConf,$direction='rte',$thisConfig=array())
* 232: function RTE_transform($value,$specConf,$direction='rte',$thisConfig=array())
*
* SECTION: Specific RTE TRANSFORMATION functions
* SECTION: Specific RTE TRANSFORMATION functions
* 398: function TS_images_db($value)
* 398: function TS_images_db($value)
* 550: function TS_images_rte($value)
* 550: function TS_images_rte($value)
* 589: function TS_reglinks($value,$direction)
* 589: function TS_reglinks($value,$direction)
* 626: function TS_links_db($value)
* 626: function TS_links_db($value)
* 675: function TS_links_rte($value)
* 675: function TS_links_rte($value)
* 760: function TS_preserve_db($value)
* 760: function TS_preserve_db($value)
* 784: function TS_preserve_rte($value)
* 784: function TS_preserve_rte($value)
* 805: function TS_transform_db($value,$css=FALSE)
* 805: function TS_transform_db($value,$css=FALSE)
* 922: function transformStyledATags($value)
* 922: function transformStyledATags($value)
* 948: function TS_transform_rte($value,$css=0)
* 948: function TS_transform_rte($value,$css=0)
* 1019: function TS_strip_db($value)
* 1019: function TS_strip_db($value)
*
* SECTION: Generic RTE transformation, analysis and helper functions
* SECTION: Generic RTE transformation, analysis and helper functions
* 1050: function getURL($url)
* 1050: function getURL($url)
* 1064: function HTMLcleaner_db($content,$tagList='')
* 1064: function HTMLcleaner_db($content,$tagList='')
* 1091: function getKeepTags($direction='rte',$tagList='')
* 1091: function getKeepTags($direction='rte',$tagList='')
* 1200: function divideIntoLines($value,$count=5,$returnArray=FALSE)
* 1200: function divideIntoLines($value,$count=5,$returnArray=FALSE)
* 1304: function setDivTags($value,$dT='p')
* 1304: function setDivTags($value,$dT='p')
* 1349: function internalizeFontTags($value)
* 1349: function internalizeFontTags($value)
* 1385: function siteUrl()
* 1385: function siteUrl()
* 1395: function rteImageStorageDir()
* 1395: function rteImageStorageDir()
* 1407: function removeTables($value,$breakChar='<br />')
* 1407: function removeTables($value,$breakChar='<br />')
* 1439: function defaultTStagMapping($code,$direction='rte')
* 1439: function defaultTStagMapping($code,$direction='rte')
* 1462: function getWHFromAttribs($attribArray)
* 1462: function getWHFromAttribs($attribArray)
* 1489: function urlInfoForLinkTags($url)
* 1489: function urlInfoForLinkTags($url)
* 1548: function TS_AtagToAbs($value,$dontSetRTEKEEP=FALSE)
* 1548: function TS_AtagToAbs($value,$dontSetRTEKEEP=FALSE)
*
* TOTAL FUNCTIONS: 28
* (This index is automatically created/updated by the extension "extdeveval")
......
*/
/**
* Class for parsing HTML for the Rich Text Editor. (also called transformations)
*
......
class t3lib_parsehtml_proc extends t3lib_parsehtml {
// Static:
var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,HR,ADDRESS,DL,DD'; // List of tags for these elements
var $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,HR,ADDRESS,DL,DD'; // List of tags for these elements
// Internal, static:
var $recPid = 0; // Set this to the pid of the record manipulated by the class.
var $recPid = 0; // Set this to the pid of the record manipulated by the class.
var $elRef = ''; // Element reference [table]:[field], eg. "tt_content:bodytext"
var $elRef = ''; // Element reference [table]:[field], eg. "tt_content:bodytext"
var $relPath=''; // Relative path
var $relPath = ''; // Relative path
var $relBackPath=''; // Relative back-path
var $relBackPath = ''; // Relative back-path
public $tsConfig = array(); // Current Page TSConfig
public $tsConfig = array(); // Current Page TSConfig
var $procOptions = ''; // Set to the TSconfig options coming from Page TSconfig
var $procOptions = ''; // Set to the TSconfig options coming from Page TSconfig
// Internal, dynamic
var $TS_transform_db_safecounter=100; // Run-away brake for recursive calls.
var $TS_transform_db_safecounter = 100; // Run-away brake for recursive calls.
var $rte_p=''; // Parameters from TCA types configuration related to the RTE
var $rte_p = ''; // Parameters from TCA types configuration related to the RTE
var $getKeepTags_cache=array(); // Data caching for processing function
var $getKeepTags_cache = array(); // Data caching for processing function
var $allowedClasses=array(); // Storage of the allowed CSS class names in the RTE
var $allowedClasses = array(); // Storage of the allowed CSS class names in the RTE
var $preserveTags = ''; // Set to tags to preserve from Page TSconfig configuration
var $preserveTags = ''; // Set to tags to preserve from Page TSconfig configuration
/**
* Initialize, setting element reference and record PID
*
......
* @param integer PID of the record (page id)
* @return void
*/
function init($elRef='',$recPid=0) {
function init($elRef = '', $recPid = 0) {
$this->recPid = $recPid;
$this->elRef = $elRef;
}
......
* @param string The relative path from PATH_site to the place where the file being edited is. Eg. "fileadmin/static".
* @return void There is no output, it is set in internal variables. With the above example of "fileadmin/static" as input this will yield ->relPath to be "fileadmin/static/" and ->relBackPath to be "../../"
*/
function setRelPath($path) {
function setRelPath($path) {
$path = trim($path);
$path = preg_replace('/^\//','',$path);
$path = preg_replace('/^\//', '', $path);
$path = preg_replace('/\/$/','',$path);
$path = preg_replace('/\/$/', '', $path);
if ($path) {
if ($path) {
$this->relPath = $path;
$this->relBackPath = '';
$partsC=count(explode('/',$this->relPath));
$partsC = count(explode('/', $this->relPath));
for ($a=0;$a<$partsC;$a++) {
for ($a = 0; $a < $partsC; $a++) {
$this->relBackPath.='../';
$this->relBackPath .= '../';
}
$this->relPath.='/';
$this->relPath .= '/';
}
}
......
* @return mixed On success an array with various information is returned, otherwise a string with an error message
* @see t3lib_TCEmain, t3lib_transferData
*/
function evalWriteFile($pArr,$currentRecord) {
function evalWriteFile($pArr, $currentRecord) {
// Write file configuration:
if (is_array($pArr)) {
if (is_array($pArr)) {
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath']
&& substr($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'],-1)=='/'
&& substr($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'], -1) == '/'
&& @is_dir(PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'])) {
&& @is_dir(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'])) {
$SW_p = $pArr['parameters'];
$SW_editFileField = trim($SW_p[0]);
$SW_editFile = $currentRecord[$SW_editFileField];
if ($SW_editFileField && $SW_editFile && t3lib_div::validPathStr($SW_editFile)) {
if ($SW_editFileField && $SW_editFile && t3lib_div::validPathStr($SW_editFile)) {
$SW_relpath = $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'].$SW_editFile;
$SW_relpath = $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'] . $SW_editFile;
$SW_editFile = PATH_site.$SW_relpath;
$SW_editFile = PATH_site . $SW_relpath;
if (@is_file($SW_editFile)) {
if (@is_file($SW_editFile)) {
return array(
'editFile' => $SW_editFile,
'relEditFile' => $SW_relpath,
......
'loadFromFileField' => trim($SW_p[3]),
'statusField' => trim($SW_p[4])
);
} else return "ERROR: Editfile '".$SW_relpath."' did not exist";
} else return "ERROR: Edit file name could not be found or was bad.";
} else return "ERROR: staticFileEditPath was not set, not set correctly or did not exist!";
} else {
return "ERROR: Editfile '" . $SW_relpath . "' did not exist";
}
}
} else {
return "ERROR: Edit file name could not be found or was bad.";
}
}
} else {
return "ERROR: staticFileEditPath was not set, not set correctly or did not exist!";
}
}
}
/**********************************************
*
* Main function
......
* @return string Output value
* @see t3lib_TCEmain::fillInFieldArray(), t3lib_transferData::renderRecord_typesProc()
*/
function RTE_transform($value,$specConf,$direction='rte',$thisConfig=array()) {
function RTE_transform($value, $specConf, $direction = 'rte', $thisConfig = array()) {
// Init:
$this->tsConfig = $thisConfig;
$this->procOptions = $thisConfig['proc.'];
$this->preserveTags = strtoupper(implode(',',t3lib_div::trimExplode(',',$this->procOptions['preserveTags'])));
$this->preserveTags = strtoupper(implode(',', t3lib_div::trimExplode(',', $this->procOptions['preserveTags'])));
// dynamic configuration of blockElementList
if ($this->procOptions['blockElementList']) {
......
$p = $this->rte_p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
// Setting modes:
if (strcmp($this->procOptions['overruleMode'],'')) {
if (strcmp($this->procOptions['overruleMode'], '')) {
$modes = array_unique(t3lib_div::trimExplode(',',$this->procOptions['overruleMode']));
$modes = array_unique(t3lib_div::trimExplode(',', $this->procOptions['overruleMode']));
} else {
$modes = array_unique(t3lib_div::trimExplode('-',$p['mode']));
$modes = array_unique(t3lib_div::trimExplode('-', $p['mode']));
}
$revmodes = array_flip($modes);
// Find special modes and extract them:
if (isset($revmodes['ts'])) {
if (isset($revmodes['ts'])) {
$modes[$revmodes['ts']] = 'ts_transform,ts_preserve,ts_images,ts_links';
}
// Find special modes and extract them:
if (isset($revmodes['ts_css'])) {
if (isset($revmodes['ts_css'])) {
$modes[$revmodes['ts_css']] = 'css_transform,ts_images,ts_links';
}
// Make list unique
$modes = array_unique(t3lib_div::trimExplode(',',implode(',',$modes),1));
$modes = array_unique(t3lib_div::trimExplode(',', implode(',', $modes), 1));
// Reverse order if direction is "rte"
if ($direction=='rte') {
if ($direction == 'rte') {
$modes = array_reverse($modes);
}
// Getting additional HTML cleaner configuration. These are applied either before or after the main transformation is done and is thus totally independant processing options you can set up:
$entry_HTMLparser = $this->procOptions['entryHTMLparser_'.$direction] ? $this->HTMLparserConfig($this->procOptions['entryHTMLparser_'.$direction.'.']) : '';
$entry_HTMLparser = $this->procOptions['entryHTMLparser_' . $direction] ? $this->HTMLparserConfig($this->procOptions['entryHTMLparser_' . $direction . '.']) : '';
$exit_HTMLparser = $this->procOptions['exitHTMLparser_'.$direction] ? $this->HTMLparserConfig($this->procOptions['exitHTMLparser_'.$direction.'.']) : '';
$exit_HTMLparser = $this->procOptions['exitHTMLparser_' . $direction] ? $this->HTMLparserConfig($this->procOptions['exitHTMLparser_' . $direction . '.']) : '';
// Line breaks of content is unified into char-10 only (removing char 13)
if (!$this->procOptions['disableUnifyLineBreaks']) {
if (!$this->procOptions['disableUnifyLineBreaks']) {
$value = str_replace(CRLF,LF,$value);
$value = str_replace(CRLF, LF, $value);
}
// In an entry-cleaner was configured, pass value through the HTMLcleaner with that:
if (is_array($entry_HTMLparser)) {
if (is_array($entry_HTMLparser)) {
$value = $this->HTMLcleaner($value,$entry_HTMLparser[0],$entry_HTMLparser[1],$entry_HTMLparser[2],$entry_HTMLparser[3]);
$value = $this->HTMLcleaner($value, $entry_HTMLparser[0], $entry_HTMLparser[1], $entry_HTMLparser[2], $entry_HTMLparser[3]);
}
// Traverse modes:
foreach($modes as $cmd) {
foreach ($modes as $cmd) {
// ->DB
if ($direction=='db') {
if ($direction == 'db') {
// Checking for user defined transformation:
if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
$_procObj = t3lib_div::getUserObj($_classRef);
$_procObj->pObj = $this;
$_procObj->transformationKey = $cmd;
$value = $_procObj->transform_db($value,$this);
$value = $_procObj->transform_db($value, $this);
} else { // ... else use defaults:
} else { // ... else use defaults:
switch($cmd) {
switch ($cmd) {
case 'ts_images':
$value = $this->TS_images_db($value);
break;
case 'ts_reglinks':
$value = $this->TS_reglinks($value,'db');
$value = $this->TS_reglinks($value, 'db');
break;
case 'ts_links':
$value = $this->TS_links_db($value);
......
break;
case 'ts_transform':
case 'css_transform':
$value = str_replace(CR,'',$value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
$value = str_replace(CR, '', $value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
$this->allowedClasses = t3lib_div::trimExplode(',', $this->procOptions['allowedClasses'], 1);
$value = $this->TS_transform_db($value,$cmd=='css_transform');
$value = $this->TS_transform_db($value, $cmd == 'css_transform');
break;
case 'ts_strip':
$value = $this->TS_strip_db($value);
......
}
}
// ->RTE
if ($direction=='rte') {
if ($direction == 'rte') {
// Checking for user defined transformation:
if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
if ($_classRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
$_procObj = t3lib_div::getUserObj($_classRef);
$_procObj->pObj = $this;
$value = $_procObj->transform_rte($value,$this);
$value = $_procObj->transform_rte($value, $this);
} else { // ... else use defaults:
} else { // ... else use defaults:
switch($cmd) {
switch ($cmd) {
case 'ts_images':
$value = $this->TS_images_rte($value);
break;
case 'ts_reglinks':
$value = $this->TS_reglinks($value,'rte');
$value = $this->TS_reglinks($value, 'rte');
break;
case 'ts_links':
$value = $this->TS_links_rte($value);
......
break;
case 'ts_transform':
case 'css_transform':
$value = str_replace(CR,'',$value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
$value = str_replace(CR, '', $value); // Has a very disturbing effect, so just remove all '13' - depend on '10'
$value = $this->TS_transform_rte($value,$cmd=='css_transform');
$value = $this->TS_transform_rte($value, $cmd == 'css_transform');
break;
default:
break;
......
}
// In an exit-cleaner was configured, pass value through the HTMLcleaner with that:
if (is_array($exit_HTMLparser)) {
if (is_array($exit_HTMLparser)) {
$value = $this->HTMLcleaner($value,$exit_HTMLparser[0],$exit_HTMLparser[1],$exit_HTMLparser[2],$exit_HTMLparser[3]);
$value = $this->HTMLcleaner($value, $exit_HTMLparser[0], $exit_HTMLparser[1], $exit_HTMLparser[2], $exit_HTMLparser[3]);
}
// Final clean up of linebreaks:
if (!$this->procOptions['disableUnifyLineBreaks']) {
if (!$this->procOptions['disableUnifyLineBreaks']) {
$value = str_replace(CRLF,LF,$value); // Make sure no \r\n sequences has entered in the meantime...
$value = str_replace(CRLF, LF, $value); // Make sure no \r\n sequences has entered in the meantime...
$value = str_replace(LF,CRLF,$value); // ... and then change all \n into \r\n
$value = str_replace(LF, CRLF, $value); // ... and then change all \n into \r\n
}
// Return value:
......
}
/************************************
*
* Specific RTE TRANSFORMATION functions
......
* @param string The content from RTE going to Database
* @return string Processed content
*/
function TS_images_db($value) {
function TS_images_db($value) {
// Split content by <img> tags and traverse the resulting array for processing:
$imgSplit = $this->splitTags('img',$value);
$imgSplit = $this->splitTags('img', $value);
foreach($imgSplit as $k => $v) {
foreach ($imgSplit as $k => $v) {
if ($k%2) { // image found, do processing:
if ($k % 2) { // image found, do processing:
// Init
$attribArray = $this->get_tag_attributes_classic($v,1);
$attribArray = $this->get_tag_attributes_classic($v, 1);
$siteUrl = $this->siteUrl();
$sitePath = str_replace (t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
$sitePath = str_replace(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
$absRef = trim($attribArray['src']); // It's always a absolute URL coming from the RTE into the Database.
$absRef = trim($attribArray['src']); // It's always a absolute URL coming from the RTE into the Database.
// make path absolute if it is relative and we have a site path wich is not '/'
$pI=pathinfo($absRef);
$pI = pathinfo($absRef);
if($sitePath AND !$pI['scheme'] && t3lib_div::isFirstPartOfStr($absRef,$sitePath)) {
if ($sitePath AND !$pI['scheme'] && t3lib_div::isFirstPartOfStr($absRef, $sitePath)) {
// if site is in a subpath (eg. /~user_jim/) this path needs to be removed because it will be added with $siteUrl
$absRef = substr($absRef,strlen($sitePath));
$absRef = substr($absRef, strlen($sitePath));
$absRef = $siteUrl.$absRef;
$absRef = $siteUrl . $absRef;
}
// External image from another URL? In that case, fetch image (unless disabled feature).
if (!t3lib_div::isFirstPartOfStr($absRef,$siteUrl) && !$this->procOptions['dontFetchExtPictures']) {
if (!t3lib_div::isFirstPartOfStr($absRef, $siteUrl) && !$this->procOptions['dontFetchExtPictures']) {
$externalFile = $this->getUrl($absRef); // Get it
$externalFile = $this->getUrl($absRef); // Get it
if ($externalFile) {
if ($externalFile) {
$pU = parse_url($absRef);
$pI=pathinfo($pU['path']);
$pI = pathinfo($pU['path']);
if (t3lib_div::inList('gif,png,jpeg,jpg',strtolower($pI['extension']))) {
if (t3lib_div::inList('gif,png,jpeg,jpg', strtolower($pI['extension']))) {
$filename = t3lib_div::shortMD5($absRef).'.'.$pI['extension'];
$filename = t3lib_div::shortMD5($absRef) . '.' . $pI['extension'];
$origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicP_'.$filename;
$origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
$C_origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicC_'.$filename.'.'.$pI['extension'];
$C_origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
if (!@is_file($origFilePath)) {
if (!@is_file($origFilePath)) {
t3lib_div::writeFile($origFilePath,$externalFile);
t3lib_div::writeFile($origFilePath, $externalFile);
t3lib_div::writeFile($C_origFilePath,$externalFile);
t3lib_div::writeFile($C_origFilePath, $externalFile);
}
$absRef = $siteUrl.$this->rteImageStorageDir().'RTEmagicC_'.$filename.'.'.$pI['extension'];
$absRef = $siteUrl . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
$attribArray['src']=$absRef;
$attribArray['src'] = $absRef;
$params = t3lib_div::implodeAttributes($attribArray,1);
$params = t3lib_div::implodeAttributes($attribArray, 1);
$imgSplit[$k] = '<img '.$params.' />';
$imgSplit[$k] = '<img ' . $params . ' />';
}
}
}
// Check image as local file (siteURL equals the one of the image)
if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl)) {
if (t3lib_div::isFirstPartOfStr($absRef, $siteUrl)) {
$path = rawurldecode(substr($absRef,strlen($siteUrl))); // Rel-path, rawurldecoded for special characters.
$path = rawurldecode(substr($absRef, strlen($siteUrl))); // Rel-path, rawurldecoded for special characters.
$filepath = t3lib_div::getFileAbsFileName($path); // Abs filepath, locked to relative path of this project.
$filepath = t3lib_div::getFileAbsFileName($path); // Abs filepath, locked to relative path of this project.
// Check file existence (in relative dir to this installation!)
if ($filepath && @is_file($filepath)) {
if ($filepath && @is_file($filepath)) {
// If "magic image":
$pathPre=$this->rteImageStorageDir().'RTEmagicC_';
$pathPre = $this->rteImageStorageDir() . 'RTEmagicC_';
if (t3lib_div::isFirstPartOfStr($path,$pathPre)) {
if (t3lib_div::isFirstPartOfStr($path, $pathPre)) {
// Find original file:
// Find original file:
$pI=pathinfo(substr($path,strlen($pathPre)));
$pI = pathinfo(substr($path, strlen($pathPre)));
$filename = substr($pI['basename'],0,-strlen('.'.$pI['extension']));
$filename = substr($pI['basename'], 0, -strlen('.' . $pI['extension']));
$origFilePath = PATH_site.$this->rteImageStorageDir().'RTEmagicP_'.$filename;
$origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
if (@is_file($origFilePath)) {
if (@is_file($origFilePath)) {
$imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
$imgObj->init();
$imgObj->mayScaleUp=0;
$imgObj->mayScaleUp = 0;
$imgObj->tempPath=PATH_site.$imgObj->tempPath;
$imgObj->tempPath = PATH_site . $imgObj->tempPath;
$curInfo = $imgObj->getImageDimensions($filepath); // Image dimensions of the current image
$curInfo = $imgObj->getImageDimensions($filepath); // Image dimensions of the current image
$curWH = $this->getWHFromAttribs($attribArray); // Image dimensions as set in the image tag
$curWH = $this->getWHFromAttribs($attribArray); // Image dimensions as set in the image tag
// Compare dimensions:
if ($curWH[0]!=$curInfo[0] || $curWH[1]!=$curInfo[1]) {
if ($curWH[0] != $curInfo[0] || $curWH[1] != $curInfo[1]) {
$origImgInfo = $imgObj->getImageDimensions($origFilePath); // Image dimensions of the current image
$origImgInfo = $imgObj->getImageDimensions($origFilePath); // Image dimensions of the current image
$cW = $curWH[0];
$cH = $curWH[1];
$cH = 1000; // Make the image based on the width solely...
$cH = 1000; // Make the image based on the width solely...
$imgI = $imgObj->imageMagickConvert($origFilePath,$pI['extension'],$cW.'m',$cH.'m');
$imgI = $imgObj->imageMagickConvert($origFilePath, $pI['extension'], $cW . 'm', $cH . 'm');
if ($imgI[3]) {
if ($imgI[3]) {
$fI=pathinfo($imgI[3]);
$fI = pathinfo($imgI[3]);
@copy($imgI[3],$filepath); // Override the child file
@copy($imgI[3], $filepath); // Override the child file
// Removing width and heigth form style attribute
$attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
$attribArray['width']=$imgI[0];
$attribArray['width'] = $imgI[0];
$attribArray['height']=$imgI[1];
$attribArray['height'] = $imgI[1];
$params = t3lib_div::implodeAttributes($attribArray,1);
$params = t3lib_div::implodeAttributes($attribArray, 1);
$imgSplit[$k]='<img '.$params.' />';
$imgSplit[$k] = '<img ' . $params . ' />';
}
}
}
} elseif ($this->procOptions['plainImageMode']) { // If "plain image" has been configured:
} elseif ($this->procOptions['plainImageMode']) { // If "plain image" has been configured:
// Image dimensions as set in the image tag, if any
$curWH = $this->getWHFromAttribs($attribArray);
if ($curWH[0]) $attribArray['width'] = $curWH[0];
if ($curWH[1]) $attribArray['height'] = $curWH[1];
if ($curWH[0]) {
$attribArray['width'] = $curWH[0];
}
if ($curWH[1]) {
$attribArray['height'] = $curWH[1];
}
// Removing width and heigth form style attribute
$attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
......
$fI = @getimagesize($filepath);
// Perform corrections to aspect ratio based on configuration:
switch((string)$this->procOptions['plainImageMode']) {
switch ((string) $this->procOptions['plainImageMode']) {
case 'lockDimensions':
$attribArray['width']=$fI[0];
$attribArray['width'] = $fI[0];
$attribArray['height']=$fI[1];
$attribArray['height'] = $fI[1];
break;
case 'lockRatioWhenSmaller': // If the ratio has to be smaller, then first set the width...:
case 'lockRatioWhenSmaller': // If the ratio has to be smaller, then first set the width...:
if ($attribArray['width']>$fI[0]) $attribArray['width'] = $fI[0];
if ($attribArray['width'] > $fI[0]) {
$attribArray['width'] = $fI[0];
}
case 'lockRatio':
if ($fI[0]>0) {
if ($fI[0] > 0) {
$attribArray['height']=round($attribArray['width']*($fI[1]/$fI[0]));
$attribArray['height'] = round($attribArray['width'] * ($fI[1] / $fI[0]));
}
break;
}
// Compile the image tag again:
$params = t3lib_div::implodeAttributes($attribArray,1);
$params = t3lib_div::implodeAttributes($attribArray, 1);
$imgSplit[$k]='<img '.$params.' />';
$imgSplit[$k] = '<img ' . $params . ' />';
}
} else { // Remove image if it was not found in a proper position on the server!
} else { // Remove image if it was not found in a proper position on the server!
// Commented out; removing the image tag might not be that logical...
// Commented out; removing the image tag might not be that logical...
#$imgSplit[$k]='';
// $imgSplit[$k]='';
}
}
// Convert abs to rel url
if ($imgSplit[$k]) {
if ($imgSplit[$k]) {
$attribArray=$this->get_tag_attributes_classic($imgSplit[$k],1);
$attribArray = $this->get_tag_attributes_classic($imgSplit[$k], 1);
$absRef = trim($attribArray['src']);
if (t3lib_div::isFirstPartOfStr($absRef,$siteUrl)) {
if (t3lib_div::isFirstPartOfStr($absRef, $siteUrl)) {
$attribArray['src'] = $this->relBackPath.substr($absRef,strlen($siteUrl));
$attribArray['src'] = $this->relBackPath . substr($absRef, strlen($siteUrl));
if (!isset($attribArray['alt'])) $attribArray['alt']=''; // Must have alt-attribute for XHTML compliance.
if (!isset($attribArray['alt'])) {
$attribArray['alt'] = '';
} // Must have alt-attribute for XHTML compliance.
$imgSplit[$k]='<img '.t3lib_div::implodeAttributes($attribArray,1,1).' />';
$imgSplit[$k] = '<img ' . t3lib_div::implodeAttributes($attribArray, 1, 1) . ' />';
}
}
}
}
return implode('',$imgSplit);
return implode('', $imgSplit);
}
/**
......
* @param string Content input
* @return string Content output
*/
function TS_images_rte($value) {
function TS_images_rte($value) {
$siteUrl = $this->siteUrl();
$sitePath = str_replace (t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
$sitePath = str_replace(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '', $siteUrl);
// Split content by <img> tags and traverse the resulting array for processing:
$imgSplit = $this->splitTags('img',$value);
$imgSplit = $this->splitTags('img', $value);
foreach($imgSplit as $k => $v) {
foreach ($imgSplit as $k => $v) {
if ($k%2) { // image found:
if ($k % 2) { // image found:
// Init
$attribArray=$this->get_tag_attributes_classic($v,1);
$attribArray = $this->get_tag_attributes_classic($v, 1);
$absRef = trim($attribArray['src']);
// Unless the src attribute is already pointing to an external URL:
if (strtolower(substr($absRef,0,4))!='http') {
if (strtolower(substr($absRef, 0, 4)) != 'http') {
$attribArray['src'] = substr($attribArray['src'],strlen($this->relBackPath));
$attribArray['src'] = substr($attribArray['src'], strlen($this->relBackPath));
// if site is in a subpath (eg. /~user_jim/) this path needs to be removed because it will be added with $siteUrl
$attribArray['src'] = preg_replace('#^'.preg_quote($sitePath,'#').'#','',$attribArray['src']);
$attribArray['src'] = preg_replace('#^' . preg_quote($sitePath, '#') . '#', '', $attribArray['src']);
$attribArray['src'] = $siteUrl.$attribArray['src'];
$attribArray['src'] = $siteUrl . $attribArray['src'];
if (!isset($attribArray['alt'])) $attribArray['alt']='';
if (!isset($attribArray['alt'])) {
$attribArray['alt'] = '';
}
$params = t3lib_div::implodeAttributes($attribArray);
$imgSplit[$k]='<img '.$params.' />';
$imgSplit[$k] = '<img ' . $params . ' />';
}
}
}
// return processed content:
return implode('',$imgSplit);
return implode('', $imgSplit);
}
/**
......
* @param string Direction of conversion; "rte" (from database to RTE) or "db" (from RTE to database)
* @return string Content output
*/
function TS_reglinks($value,$direction) {
function TS_reglinks($value, $direction) {
$retVal = '';
switch($direction) {
switch ($direction) {
case 'rte':
$retVal = $this->TS_AtagToAbs($value,1);
$retVal = $this->TS_AtagToAbs($value, 1);
break;
case 'db':
$siteURL = $this->siteUrl();
$blockSplit = $this->splitIntoBlock('A',$value);
$blockSplit = $this->splitIntoBlock('A', $value);
foreach ($blockSplit as $k => $v) {
if ($k%2) { // block:
if ($k % 2) { // block:
$attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v),1);
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
// If the url is local, remove url-prefix
if ($siteURL && substr($attribArray['href'],0,strlen($siteURL))==$siteURL) {
if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) {
$attribArray['href']=$this->relBackPath.substr($attribArray['href'],strlen($siteURL));
$attribArray['href'] = $this->relBackPath . substr($attribArray['href'], strlen($siteURL));
}
$bTag='<a '.t3lib_div::implodeAttributes($attribArray,1).'>';
$bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
$eTag='</a>';
$eTag = '</a>';
$blockSplit[$k] = $bTag.$this->TS_reglinks($this->removeFirstAndLastTag($blockSplit[$k]),$direction).$eTag;
$blockSplit[$k] = $bTag . $this->TS_reglinks($this->removeFirstAndLastTag($blockSplit[$k]), $direction) . $eTag;
}
}
$retVal = implode('',$blockSplit);
$retVal = implode('', $blockSplit);
break;
}
return $retVal;
......
* @return string Content output
* @see TS_links_rte()
*/
function TS_links_db($value) {
function TS_links_db($value) {
// Split content into <a> tag blocks and process:
$blockSplit = $this->splitIntoBlock('A',$value);
$blockSplit = $this->splitIntoBlock('A', $value);
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
if ($k%2) { // If an A-tag was found:
if ($k % 2) { // If an A-tag was found:
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v),1);
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
$info = $this->urlInfoForLinkTags($attribArray['href']);
// Check options:
......
unset($attribArray_copy['class']);
unset($attribArray_copy['title']);
unset($attribArray_copy['external']);
if ($attribArray_copy['rteerror']) { // Unset "rteerror" and "style" attributes if "rteerror" is set!
if ($attribArray_copy['rteerror']) { // Unset "rteerror" and "style" attributes if "rteerror" is set!
unset($attribArray_copy['style']);
unset($attribArray_copy['rteerror']);
}
if (!count($attribArray_copy)) { // Only if href, target and class are the only attributes, we can alter the link!
if (!count($attribArray_copy)) { // Only if href, target and class are the only attributes, we can alter the link!
// Quoting class and title attributes if they contain spaces
$attribArray['class'] = preg_match('/ /', $attribArray['class']) ? '"' . $attribArray['class'] . '"' : $attribArray['class'];
$attribArray['title'] = preg_match('/ /', $attribArray['title']) ? '"' . $attribArray['title'] . '"' : $attribArray['title'];
// Creating the TYPO3 pseudo-tag "<LINK>" for the link (includes href/url, target and class attributes):
// If external attribute is set, keep the href unchanged
$href = $attribArray['external'] ? $attribArray['href'] : $info['url'].($info['query']?',0,'.$info['query']:'');
$href = $attribArray['external'] ? $attribArray['href'] : $info['url'] . ($info['query'] ? ',0,' . $info['query'] : '');
$bTag='<link '. $href . ($attribArray['target']?' '.$attribArray['target']:(($attribArray['class'] || $attribArray['title'])?' -':'')).($attribArray['class']?' '.$attribArray['class']:($attribArray['title']?' -':'')).($attribArray['title']?' '.$attribArray['title']:'').'>';
$bTag = '<link ' . $href . ($attribArray['target'] ? ' ' . $attribArray['target'] : (($attribArray['class'] || $attribArray['title']) ? ' -' : '')) . ($attribArray['class'] ? ' ' . $attribArray['class'] : ($attribArray['title'] ? ' -' : '')) . ($attribArray['title'] ? ' ' . $attribArray['title'] : '') . '>';
$eTag='</link>';
$eTag = '</link>';
$blockSplit[$k] = $bTag.$this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
$blockSplit[$k] = $bTag . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
} else { // ... otherwise store the link as a-tag.
} else { // ... otherwise store the link as a-tag.
// Unsetting 'rtekeep' attribute if that had been set.
unset($attribArray['rtekeep']);
if (!$attribArray['external']) {
// If the url is local, remove url-prefix
$siteURL = $this->siteUrl();
if ($siteURL && substr($attribArray['href'],0,strlen($siteURL))==$siteURL) {
if ($siteURL && substr($attribArray['href'], 0, strlen($siteURL)) == $siteURL) {
$attribArray['href']=$this->relBackPath.substr($attribArray['href'],strlen($siteURL));
$attribArray['href'] = $this->relBackPath . substr($attribArray['href'], strlen($siteURL));
}
}
unset($attribArray['external']);
$bTag='<a '.t3lib_div::implodeAttributes($attribArray,1).'>';
$bTag = '<a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
$eTag='</a>';
$eTag = '</a>';
$blockSplit[$k] = $bTag.$this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
$blockSplit[$k] = $bTag . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
}
}
}
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @return string Content output
* @see TS_links_rte()
*/
function TS_links_rte($value) {
function TS_links_rte($value) {
$value = $this->TS_AtagToAbs($value);
// Split content by the TYPO3 pseudo tag "<link>":
$blockSplit = $this->splitIntoBlock('link',$value,1);
$blockSplit = $this->splitIntoBlock('link', $value, 1);
$siteUrl = $this->siteUrl();
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
$error = '';
if ($k%2) { // block:
if ($k % 2) { // block:
$tagCode = t3lib_div::unQuoteFilenames(trim(substr($this->getFirstTag($v),0,-1)),true);
$tagCode = t3lib_div::unQuoteFilenames(trim(substr($this->getFirstTag($v), 0, -1)), true);
$link_param = $tagCode[1];
$href = '';
// Parsing the typolink data. This parsing is roughly done like in tslib_content->typolink()
if (strstr($link_param,'@')) { // mailadr
if (strstr($link_param, '@')) { // mailadr
$href = 'mailto:'.preg_replace('/^mailto:/i','',$link_param);
$href = 'mailto:' . preg_replace('/^mailto:/i', '', $link_param);
} elseif (substr($link_param,0,1)=='#') { // check if anchor
} elseif (substr($link_param, 0, 1) == '#') { // check if anchor
$href = $siteUrl.$link_param;
$href = $siteUrl . $link_param;
} else {
$fileChar=intval(strpos($link_param, '/'));
$fileChar = intval(strpos($link_param, '/'));
$urlChar=intval(strpos($link_param, '.'));
$urlChar = intval(strpos($link_param, '.'));
$external = FALSE;
// Parse URL:
$pU = parse_url($link_param);
// Detects if a file is found in site-root OR is a simulateStaticDocument.
list($rootFileDat) = explode('?',$link_param);
list($rootFileDat) = explode('?', $link_param);
$rFD_fI = pathinfo($rootFileDat);
if (trim($rootFileDat) && !strstr($link_param,'/') && (@is_file(PATH_site.$rootFileDat) || t3lib_div::inList('php,html,htm',strtolower($rFD_fI['extension'])))) {
if (trim($rootFileDat) && !strstr($link_param, '/') && (@is_file(PATH_site . $rootFileDat) || t3lib_div::inList('php,html,htm', strtolower($rFD_fI['extension'])))) {
$href = $siteUrl.$link_param;
$href = $siteUrl . $link_param;
} elseif ($pU['scheme'] || ($urlChar && (!$fileChar || $urlChar < $fileChar))) {
// url (external): if has scheme or if a '.' comes before a '/'.
$href = $link_param;
......
$href = 'http://' . $href;
}
$external = TRUE;
} elseif($fileChar) { // file (internal)
} elseif ($fileChar) { // file (internal)
$href = $siteUrl.$link_param;
$href = $siteUrl . $link_param;
} else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
} else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
// Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/parameters triplet
$pairParts = t3lib_div::trimExplode(',', $link_param, TRUE);
$idPart = $pairParts[0];
$link_params_parts = explode('#', $idPart);
$idPart = trim($link_params_parts[0]);
$sectionMark = trim($link_params_parts[1]);
if (!strcmp($idPart,'')) { $idPart=$this->recPid; } // If no id or alias is given, set it to class record pid
if (!strcmp($idPart, '')) {
$idPart = $this->recPid;
} // If no id or alias is given, set it to class record pid
// Checking if the id-parameter is an alias.
if (!t3lib_div::testInt($idPart)) {
if (!t3lib_div::testInt($idPart)) {
list($idPartR) = t3lib_BEfunc::getRecordsByField('pages','alias',$idPart);
list($idPartR) = t3lib_BEfunc::getRecordsByField('pages', 'alias', $idPart);
$idPart = intval($idPartR['uid']);
}
$page = t3lib_BEfunc::getRecord('pages', $idPart);
if (is_array($page)) { // Page must exist...
if (is_array($page)) { // Page must exist...
$href = $siteUrl .'?id=' . $idPart . ($pairParts[2] ? $pairParts[2] : '') . ($sectionMark ? '#' . $sectionMark : '');
$href = $siteUrl . '?id=' . $idPart . ($pairParts[2] ? $pairParts[2] : '') . ($sectionMark ? '#' . $sectionMark : '');
// linkHandler - allowing links to start with registerd linkHandler e.g.. "record:"
// linkHandler - allowing links to start with registerd linkHandler e.g.. "record:"
} elseif (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][array_shift(explode(':', $link_param))])) {
$href = $link_param;
} else {
#$href = '';
$href = $siteUrl.'?id='.$link_param;
$href = $siteUrl . '?id=' . $link_param;
$error = 'No page found: '.$idPart;
$error = 'No page found: ' . $idPart;
}
}
}
// Setting the A-tag:
// Setting the A-tag:
$bTag = '<a href="'.htmlspecialchars($href).'"'.
$bTag = '<a href="' . htmlspecialchars($href) . '"' .
($tagCode[2]&&$tagCode[2]!='-' ? ' target="'.htmlspecialchars($tagCode[2]).'"' : '').
($tagCode[2] && $tagCode[2] != '-' ? ' target="' . htmlspecialchars($tagCode[2]) . '"' : '') .
($tagCode[3]&&$tagCode[3]!='-' ? ' class="'.htmlspecialchars($tagCode[3]).'"' : '').
($tagCode[3] && $tagCode[3] != '-' ? ' class="' . htmlspecialchars($tagCode[3]) . '"' : '') .
($tagCode[4] ? ' title="'.htmlspecialchars($tagCode[4]).'"' : '').
($tagCode[4] ? ' title="' . htmlspecialchars($tagCode[4]) . '"' : '') .
($external ? ' external="1"' : '').
($external ? ' external="1"' : '') .
($error ? ' rteerror="'.htmlspecialchars($error).'" style="background-color: yellow; border:2px red solid; color: black;"' : ''). // Should be OK to add the style; the transformation back to databsae will remove it...
($error ? ' rteerror="' . htmlspecialchars($error) . '" style="background-color: yellow; border:2px red solid; color: black;"' : '') . // Should be OK to add the style; the transformation back to databsae will remove it...
'>';
'>';
$eTag = '</a>';
$blockSplit[$k] = $bTag.$this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k])).$eTag;
$blockSplit[$k] = $bTag . $this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k])) . $eTag;
}
}
// Return content:
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @param string Content input
* @return string Content output
*/
function TS_preserve_db($value) {
function TS_preserve_db($value) {
if (!$this->preserveTags) return $value;
if (!$this->preserveTags) {
return $value;
}
// Splitting into blocks for processing (span-tags are used for special tags)
$blockSplit = $this->splitIntoBlock('span',$value);
$blockSplit = $this->splitIntoBlock('span', $value);
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
if ($k%2) { // block:
if ($k % 2) { // block:
$attribArray=$this->get_tag_attributes_classic($this->getFirstTag($v));
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v));
if ($attribArray['specialtag']) {
if ($attribArray['specialtag']) {
$theTag = rawurldecode($attribArray['specialtag']);
$theTagName = $this->getFirstTagName($theTag);
$blockSplit[$k] = $theTag.$this->removeFirstAndLastTag($blockSplit[$k]).'</'.$theTagName.'>';
$blockSplit[$k] = $theTag . $this->removeFirstAndLastTag($blockSplit[$k]) . '</' . $theTagName . '>';
}
}
}
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @param string Content input
* @return string Content output
*/
function TS_preserve_rte($value) {
function TS_preserve_rte($value) {
if (!$this->preserveTags) return $value;
if (!$this->preserveTags) {
return $value;
}
$blockSplit = $this->splitIntoBlock($this->preserveTags,$value);
$blockSplit = $this->splitIntoBlock($this->preserveTags, $value);
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
if ($k%2) { // block:
if ($k % 2) { // block:
$blockSplit[$k] = '<span specialtag="'.rawurlencode($this->getFirstTag($v)).'">'.$this->removeFirstAndLastTag($blockSplit[$k]).'</span>';
$blockSplit[$k] = '<span specialtag="' . rawurlencode($this->getFirstTag($v)) . '">' . $this->removeFirstAndLastTag($blockSplit[$k]) . '</span>';
}
}
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @return string Content output
* @see TS_transform_rte()
*/
function TS_transform_db($value,$css=FALSE) {
function TS_transform_db($value, $css = FALSE) {
// safety... so forever loops are avoided (they should not occur, but an error would potentially do this...)
$this->TS_transform_db_safecounter--;
if ($this->TS_transform_db_safecounter<0) return $value;
if ($this->TS_transform_db_safecounter < 0) {
return $value;
}
// Split the content from RTE by the occurence of these blocks:
$blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$value);
$blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value);
$cc=0;
$cc = 0;
$aC = count($blockSplit);
// Avoid superfluous linebreaks by transform_db after ending headListTag
while($aC && !strcmp(trim($blockSplit[$aC-1]),'')) {
while ($aC && !strcmp(trim($blockSplit[$aC - 1]), '')) {
unset($blockSplit[$aC-1]);
unset($blockSplit[$aC - 1]);
$aC = count($blockSplit);
}
// Traverse the blocks
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
$cc++;
$lastBR = $cc==$aC ? '' : LF;
$lastBR = $cc == $aC ? '' : LF;
if ($k%2) { // Inside block:
if ($k % 2) { // Inside block:
// Init:
$tag=$this->getFirstTag($v);
$tag = $this->getFirstTag($v);
$tagName=strtolower($this->getFirstTagName($v));
$tagName = strtolower($this->getFirstTagName($v));
// Process based on the tag:
switch($tagName) {
switch ($tagName) {
case 'blockquote': // Keep blockquotes, but clean the inside recursively in the same manner as the main code
case 'blockquote': // Keep blockquotes, but clean the inside recursively in the same manner as the main code
case 'dd' : // Do the same on dd elements
case 'dd' : // Do the same on dd elements
case 'div': // Do the same on div sections, if they were splitted
case 'div': // Do the same on div sections, if they were splitted
$blockSplit[$k]=$tag.$this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]),$css).'</'.$tagName.'>'.$lastBR;
$blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k]), $css) . '</' . $tagName . '>' . $lastBR;
break;
case 'ol':
case 'ul': // Transform lists into <typolist>-tags:
case 'ul': // Transform lists into <typolist>-tags:
if (!$css) {
if (!$css) {
if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
$parts = $this->getAllParts($this->splitIntoBlock('LI',$this->removeFirstAndLastTag($blockSplit[$k])),1,0);
$parts = $this->getAllParts($this->splitIntoBlock('LI', $this->removeFirstAndLastTag($blockSplit[$k])), 1, 0);
foreach ($parts as $k2 => $value) {
$parts[$k2]=preg_replace('/['.preg_quote(LF.CR).']+/','',$parts[$k2]); // remove all linesbreaks!
$parts[$k2] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', '', $parts[$k2]); // remove all linesbreaks!
$parts[$k2]=$this->defaultTStagMapping($parts[$k2],'db');
$parts[$k2] = $this->defaultTStagMapping($parts[$k2], 'db');
$parts[$k2]=$this->cleanFontTags($parts[$k2],0,0,0);
$parts[$k2] = $this->cleanFontTags($parts[$k2], 0, 0, 0);
$parts[$k2] = $this->HTMLcleaner_db($parts[$k2],strtolower($this->procOptions['allowTagsInTypolists']?$this->procOptions['allowTagsInTypolists']:'br,font,b,i,u,a,img,span,strong,em'));
$parts[$k2] = $this->HTMLcleaner_db($parts[$k2], strtolower($this->procOptions['allowTagsInTypolists'] ? $this->procOptions['allowTagsInTypolists'] : 'br,font,b,i,u,a,img,span,strong,em'));
}
if ($tagName=='ol') { $params=' type="1"'; } else { $params=''; }
if ($tagName == 'ol') {
$params = ' type="1"';
} else {
$params = '';
}
$blockSplit[$k]='<typolist'.$params.'>'.LF.implode(LF,$parts).LF.'</typolist>'.$lastBR;
$blockSplit[$k] = '<typolist' . $params . '>' . LF . implode(LF, $parts) . LF . '</typolist>' . $lastBR;
}
} else {
$blockSplit[$k]=preg_replace('/['.preg_quote(LF.CR).']+/',' ',$this->transformStyledATags($blockSplit[$k])).$lastBR;
$blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
}
break;
case 'table': // Tables are NOT allowed in any form (unless preserveTables is set or CSS is the mode)
case 'table': // Tables are NOT allowed in any form (unless preserveTables is set or CSS is the mode)
if (!$this->procOptions['preserveTables'] && !$css) {
if (!$this->procOptions['preserveTables'] && !$css) {
$blockSplit[$k]=$this->TS_transform_db($this->removeTables($blockSplit[$k]));
$blockSplit[$k] = $this->TS_transform_db($this->removeTables($blockSplit[$k]));
} else {
$blockSplit[$k]=preg_replace('/['.preg_quote(LF.CR).']+/',' ',$this->transformStyledATags($blockSplit[$k])).$lastBR;
$blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
}
break;
case 'h1':
......
case 'h4':
case 'h5':
case 'h6':
if (!$css) {
if (!$css) {
$attribArray=$this->get_tag_attributes_classic($tag);
$attribArray = $this->get_tag_attributes_classic($tag);
// Processing inner content here:
$innerContent = $this->HTMLcleaner_db($this->removeFirstAndLastTag($blockSplit[$k]));
if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
$type = intval(substr($tagName,1));
$type = intval(substr($tagName, 1));
$blockSplit[$k]='<typohead'.
$blockSplit[$k] = '<typohead' .
($type!=6?' type="'.$type.'"':'').
($type != 6 ? ' type="' . $type . '"' : '') .
($attribArray['align']?' align="'.$attribArray['align'].'"':'').
($attribArray['align'] ? ' align="' . $attribArray['align'] . '"' : '') .
($attribArray['class']?' class="'.$attribArray['class'].'"':'').
($attribArray['class'] ? ' class="' . $attribArray['class'] . '"' : '') .
'>'.
'>' .
$innerContent.
$innerContent .
'</typohead>'.
'</typohead>' .
$lastBR;
$lastBR;
} else {
$blockSplit[$k]='<'.$tagName.
$blockSplit[$k] = '<' . $tagName .
($attribArray['align']?' align="'.htmlspecialchars($attribArray['align']).'"':'').
($attribArray['align'] ? ' align="' . htmlspecialchars($attribArray['align']) . '"' : '') .
($attribArray['class']?' class="'.htmlspecialchars($attribArray['class']).'"':'').
($attribArray['class'] ? ' class="' . htmlspecialchars($attribArray['class']) . '"' : '') .
'>'.
'>' .
$innerContent.
$innerContent .
'</'.$tagName.'>'.
'</' . $tagName . '>' .
$lastBR;
$lastBR;
}
} else {
// Eliminate true linebreaks inside Hx tags
$blockSplit[$k]=preg_replace('/['.preg_quote(LF.CR).']+/',' ',$this->transformStyledATags($blockSplit[$k])).$lastBR;
$blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
}
break;
default:
// Eliminate true linebreaks inside other headlist tags and after hr tag
$blockSplit[$k]=preg_replace('/['.preg_quote(LF.CR).']+/',' ',$this->transformStyledATags($blockSplit[$k])).$lastBR;
$blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
break;
}
} else { // NON-block:
} else { // NON-block:
if (strcmp(trim($blockSplit[$k]),'')) {
if (strcmp(trim($blockSplit[$k]), '')) {
$blockSplit[$k]=$this->divideIntoLines(preg_replace('/['.preg_quote(LF.CR).']+/',' ',$blockSplit[$k])).$lastBR;
$blockSplit[$k] = $this->divideIntoLines(preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $blockSplit[$k])) . $lastBR;
$blockSplit[$k]=$this->transformStyledATags($blockSplit[$k]);
$blockSplit[$k] = $this->transformStyledATags($blockSplit[$k]);
} else unset($blockSplit[$k]);
} else {
unset($blockSplit[$k]);
}
}
}
}
}
$this->TS_transform_db_safecounter++;
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @param string Content input
* @return string Content output
*/
function transformStyledATags($value) {
function transformStyledATags($value) {
$blockSplit = $this->splitIntoBlock('A',$value);
$blockSplit = $this->splitIntoBlock('A', $value);
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
if ($k%2) { // If an A-tag was found:
if ($k % 2) { // If an A-tag was found:
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v),1);
$attribArray = $this->get_tag_attributes_classic($this->getFirstTag($v), 1);
if ($attribArray['style']) { // If "style" attribute is set!
if ($attribArray['style']) { // If "style" attribute is set!
$attribArray_copy['style'] = $attribArray['style'];
unset($attribArray['style']);
$bTag='<span '.t3lib_div::implodeAttributes($attribArray_copy,1).'><a '.t3lib_div::implodeAttributes($attribArray,1).'>';
$bTag = '<span ' . t3lib_div::implodeAttributes($attribArray_copy, 1) . '><a ' . t3lib_div::implodeAttributes($attribArray, 1) . '>';
$eTag='</a></span>';
$eTag = '</a></span>';
$blockSplit[$k] = $bTag.$this->removeFirstAndLastTag($blockSplit[$k]).$eTag;
$blockSplit[$k] = $bTag . $this->removeFirstAndLastTag($blockSplit[$k]) . $eTag;
}
}
}
return implode('',$blockSplit);
return implode('', $blockSplit);
}
/**
......
* @return string Content output
* @see TS_transform_db()
*/
function TS_transform_rte($value,$css=0) {
function TS_transform_rte($value, $css = 0) {
// Split the content from Database by the occurence of these blocks:
$blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$value);
$blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value);
// Traverse the blocks
foreach($blockSplit as $k => $v) {
foreach ($blockSplit as $k => $v) {
if ($k%2) { // Inside one of the blocks:
if ($k % 2) { // Inside one of the blocks:
// Init:
$tag = $this->getFirstTag($v);
......
$attribArray = $this->get_tag_attributes_classic($tag);
// Based on tagname, we do transformations:
switch($tagName) {
switch ($tagName) {
case 'blockquote': // Keep blockquotes
case 'blockquote': // Keep blockquotes
case 'dd': // Keep definitions
case 'dd': // Keep definitions
case 'div': // Keep div sections, if they were splitted
case 'div': // Keep div sections, if they were splitted
$blockSplit[$k] = $tag.
$blockSplit[$k] = $tag .
$this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]),$css).
$this->TS_transform_rte($this->removeFirstAndLastTag($blockSplit[$k]), $css) .
'</'.$tagName.'>';
'</' . $tagName . '>';
break;
case 'typolist': // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
case 'typolist': // Transform typolist blocks into OL/UL lists. Type 1 is expected to be numerical block
if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
$tListContent = $this->removeFirstAndLastTag($blockSplit[$k]);
$tListContent = preg_replace('/^[ ]*'.LF.'/','',$tListContent);
$tListContent = preg_replace('/^[ ]*' . LF . '/', '', $tListContent);
$tListContent = preg_replace('/'.LF.'[ ]*$/','',$tListContent);
$tListContent = preg_replace('/' . LF . '[ ]*$/', '', $tListContent);
$lines = explode(LF,$tListContent);
$lines = explode(LF, $tListContent);
$typ = $attribArray['type']==1 ? 'ol' : 'ul';
$typ = $attribArray['type'] == 1 ? 'ol' : 'ul';
$blockSplit[$k] = '<'.$typ.'>'.LF.
$blockSplit[$k] = '<' . $typ . '>' . LF .
'<li>'.implode('</li>'.LF.'<li>',$lines).'</li>'.
'<li>' . implode('</li>' . LF . '<li>', $lines) . '</li>' .
'</'.$typ.'>';
'</' . $typ . '>';
}
break;
case 'typohead': // Transform typohead into Hx tags.
case 'typohead': // Transform typohead into Hx tags.
if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
if (!isset($this->procOptions['typohead']) || $this->procOptions['typohead']) {
$tC = $this->removeFirstAndLastTag($blockSplit[$k]);
$typ = t3lib_div::intInRange($attribArray['type'],0,6);
$typ = t3lib_div::intInRange($attribArray['type'], 0, 6);
if (!$typ) $typ=6;
if (!$typ) {
$typ = 6;
}
$align = $attribArray['align']?' align="'.$attribArray['align'].'"': '';
$align = $attribArray['align'] ? ' align="' . $attribArray['align'] . '"' : '';
$class = $attribArray['class']?' class="'.$attribArray['class'].'"': '';
$class = $attribArray['class'] ? ' class="' . $attribArray['class'] . '"' : '';
$blockSplit[$k] = '<h'.$typ.$align.$class.'>'.
$blockSplit[$k] = '<h' . $typ . $align . $class . '>' .
$tC.
$tC .
'</h'.$typ.'>';
'</h' . $typ . '>';
}
break;
}
$blockSplit[$k+1] = preg_replace('/^[ ]*'.LF.'/','',$blockSplit[$k+1]); // Removing linebreak if typohead
$blockSplit[$k + 1] = preg_replace('/^[ ]*' . LF . '/', '', $blockSplit[$k + 1]); // Removing linebreak if typohead
} else { // NON-block:
} else { // NON-block:
$nextFTN = $this->getFirstTagName($blockSplit[$k+1]);
$nextFTN = $this->getFirstTagName($blockSplit[$k + 1]);
$singleLineBreak = $blockSplit[$k]==LF;
$singleLineBreak = $blockSplit[$k] == LF;
if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,'.($this->procOptions['preserveDIVSections']?'DIV,':'').$this->blockElementList,$nextFTN)) { // Removing linebreak if typolist/typohead
if (t3lib_div::inList('TABLE,BLOCKQUOTE,TYPOLIST,TYPOHEAD,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $nextFTN)) { // Removing linebreak if typolist/typohead
$blockSplit[$k] = preg_replace('/'.LF.'[ ]*$/','',$blockSplit[$k]);
$blockSplit[$k] = preg_replace('/' . LF . '[ ]*$/', '', $blockSplit[$k]);
}
// If $blockSplit[$k] is blank then unset the line. UNLESS the line happend to be a single line break.
if (!strcmp($blockSplit[$k],'') && !$singleLineBreak) {
if (!strcmp($blockSplit[$k], '') && !$singleLineBreak) {
unset($blockSplit[$k]);
} else {
$blockSplit[$k] = $this->setDivTags($blockSplit[$k],($this->procOptions['useDIVasParagraphTagForRTE']?'div':'p'));
$blockSplit[$k] = $this->setDivTags($blockSplit[$k], ($this->procOptions['useDIVasParagraphTagForRTE'] ? 'div' : 'p'));
}
}
}
return implode(LF,$blockSplit);
return implode(LF, $blockSplit);
}
/**
......
* @param string Content input
* @return string Content output
*/
function TS_strip_db($value) {
function TS_strip_db($value) {
$value = strip_tags($value,'<'.implode('><',explode(',','b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote')).'>');
$value = strip_tags($value, '<' . implode('><', explode(',', 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote')) . '>');
return $value;
}
/***************************************************************
*
* Generic RTE transformation, analysis and helper functions
......
* @return string The content from the resource given as input.
* @see t3lib_div::getURL()
*/
function getURL($url) {
function getURL($url) {
return t3lib_div::getURL($url);
}
......
* @return string Clean content
* @see getKeepTags()
*/
function HTMLcleaner_db($content,$tagList='') {
function HTMLcleaner_db($content, $tagList = '') {
if (!$tagList) {
if (!$tagList) {
$keepTags = $this->getKeepTags('db');
} else {
$keepTags = $this->getKeepTags('db',$tagList);
$keepTags = $this->getKeepTags('db', $tagList);
}
$kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; // Default: remove unknown tags.
$kUknown = $this->procOptions['dontRemoveUnknownTags_db'] ? 1 : 0; // Default: remove unknown tags.
$hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; // Default: re-convert literals to characters (that is &lt; to <)
$hSC = $this->procOptions['dontUndoHSC_db'] ? 0 : -1; // Default: re-convert literals to characters (that is &lt; to <)
// Create additional configuration in order to honor the setting RTE.default.proc.HTMLparser_db.xhtml_cleaning=1
$addConfig=array();
$addConfig = array();
if ((is_array($this->procOptions['HTMLparser_db.']) && $this->procOptions['HTMLparser_db.']['xhtml_cleaning']) || (is_array($this->procOptions['entryHTMLparser_db.']) && $this->procOptions['entryHTMLparser_db.']['xhtml_cleaning']) || (is_array($this->procOptions['exitHTMLparser_db.']) && $this->procOptions['exitHTMLparser_db.']['xhtml_cleaning'])) {
if ((is_array($this->procOptions['HTMLparser_db.']) && $this->procOptions['HTMLparser_db.']['xhtml_cleaning']) || (is_array($this->procOptions['entryHTMLparser_db.']) && $this->procOptions['entryHTMLparser_db.']['xhtml_cleaning']) || (is_array($this->procOptions['exitHTMLparser_db.']) && $this->procOptions['exitHTMLparser_db.']['xhtml_cleaning'])) {
$addConfig['xhtml']=1;
$addConfig['xhtml'] = 1;
}
return $this->HTMLcleaner($content,$keepTags,$kUknown,$hSC,$addConfig);
return $this->HTMLcleaner($content, $keepTags, $kUknown, $hSC, $addConfig);
}
}
/**
* Creates an array of configuration for the HTMLcleaner function based on whether content go TO or FROM the Rich Text Editor ($direction)
......
* @return array Configuration array
* @see HTMLcleaner_db()
*/
function getKeepTags($direction='rte',$tagList='') {
function getKeepTags($direction = 'rte', $tagList = '') {
if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
if (!is_array($this->getKeepTags_cache[$direction]) || $tagList) {
// Setting up allowed tags:
if (strcmp($tagList,'')) { // If the $tagList input var is set, this will take precedence
if (strcmp($tagList, '')) { // If the $tagList input var is set, this will take precedence
$keepTags = array_flip(t3lib_div::trimExplode(',',$tagList,1));
$keepTags = array_flip(t3lib_div::trimExplode(',', $tagList, 1));
} else { // Default is to get allowed/denied tags from internal array of processing options:
} else { // Default is to get allowed/denied tags from internal array of processing options:
// Construct default list of tags to keep:
$typoScript_list = 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span';
$keepTags = array_flip(t3lib_div::trimExplode(',',$typoScript_list.','.strtolower($this->procOptions['allowTags']),1));
$keepTags = array_flip(t3lib_div::trimExplode(',', $typoScript_list . ',' . strtolower($this->procOptions['allowTags']), 1));
// For tags to deny, remove them from $keepTags array:
$denyTags = t3lib_div::trimExplode(',',$this->procOptions['denyTags'],1);
$denyTags = t3lib_div::trimExplode(',', $this->procOptions['denyTags'], 1);
foreach($denyTags as $dKe) {
foreach ($denyTags as $dKe) {
unset($keepTags[$dKe]);
}
}
// Based on the direction of content, set further options:
switch ($direction) {
switch ($direction) {
// GOING from database to Rich Text Editor:
case 'rte':
if (!isset($this->procOptions['transformBoldAndItalicTags']) || $this->procOptions['transformBoldAndItalicTags']) {
// Transform bold/italics tags to strong/em
if (isset($keepTags['b'])) {$keepTags['b']=array('remap'=>'STRONG');}
if (isset($keepTags['i'])) {$keepTags['i']=array('remap'=>'EM');}
if (isset($keepTags['b'])) {
$keepTags['b'] = array('remap' => 'STRONG');
}
}
... This diff was truncated because it exceeds the maximum size that can be displayed.
(43-43/93)