Bug #21143 » 12066-v5-div.diff
NEWS.txt (working copy) | ||
---|---|---|
Development
|
||
===========
|
||
* ...
|
||
* t3lib_div now provides the constants LF, CR, CRLF and TAB which can be used to improve code readability.
|
||
TypoScript changes
|
t3lib/class.t3lib_div.php (working copy) | ||
---|---|---|
* 499: function fixed_lgd($string,$origChars,$preStr='...')
|
||
* 524: function fixed_lgd_pre($string,$chars)
|
||
* 538: function fixed_lgd_cs($string,$chars)
|
||
* 555: function breakTextForEmail($str,$implChar="\n",$charWidth=76)
|
||
* 574: function breakLinesForEmail($str,$implChar="\n",$charWidth=76)
|
||
* 555: function breakTextForEmail($str,$implChar=LF,$charWidth=76)
|
||
* 574: function breakLinesForEmail($str,$implChar=LF,$charWidth=76)
|
||
* 610: function cmpIP($baseIP, $list)
|
||
* 626: function cmpIPv4($baseIP, $list)
|
||
* 668: function cmpIPv6($baseIP, $list)
|
||
... | ... | |
*
|
||
*/
|
||
// a tabulator
|
||
define('TAB', chr(9));
|
||
// a linefeed
|
||
define('LF', chr(10));
|
||
// a carriage return
|
||
define('CR', chr(13));
|
||
// a CR-LF combination
|
||
define('CRLF', CR . LF);
|
||
/**
|
||
* The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
|
||
... | ... | |
* @deprecated since TYPO3 4.1 - Use PHP function wordwrap()
|
||
* @return string
|
||
*/
|
||
public static function breakTextForEmail($str,$implChar="\n",$charWidth=76) {
|
||
public static function breakTextForEmail($str,$implChar=LF,$charWidth=76) {
|
||
self::logDeprecatedFunction();
|
||
$lines = explode(chr(10),$str);
|
||
$lines = explode(LF,$str);
|
||
$outArr=array();
|
||
foreach ($lines as $lStr) {
|
||
$outArr[] = self::breakLinesForEmail($lStr,$implChar,$charWidth);
|
||
}
|
||
return implode(chr(10),$outArr);
|
||
return implode(LF,$outArr);
|
||
}
|
||
/**
|
||
... | ... | |
* @return string
|
||
* @see breakTextForEmail()
|
||
*/
|
||
public static function breakLinesForEmail($str,$implChar="\n",$charWidth=76) {
|
||
public static function breakLinesForEmail($str,$implChar=LF,$charWidth=76) {
|
||
$lines=array();
|
||
$l=$charWidth;
|
||
$p=0;
|
||
... | ... | |
* @return string Formatted for <textarea>-tags
|
||
*/
|
||
public static function formatForTextarea($content) {
|
||
return chr(10).htmlspecialchars($content);
|
||
return LF.htmlspecialchars($content);
|
||
}
|
||
/**
|
||
... | ... | |
public static function wrapJS($string, $linebreak=TRUE) {
|
||
if(trim($string)) {
|
||
// <script wrapped in nl?
|
||
$cr = $linebreak? "\n" : '';
|
||
$cr = $linebreak? LF : '';
|
||
// remove nl from the beginning
|
||
$string = preg_replace ('/^\n+/', '', $string);
|
||
// re-ident to one tab using the first line as reference
|
||
$match = array();
|
||
if(preg_match('/^(\t+)/',$string,$match)) {
|
||
$string = str_replace($match[1],"\t", $string);
|
||
$string = str_replace($match[1],TAB, $string);
|
||
}
|
||
$string = $cr.'<script type="text/javascript">
|
||
/*<![CDATA[*/
|
||
... | ... | |
}
|
||
// Return XML:
|
||
return '<?xml version="1.0" encoding="'.htmlspecialchars($charset).'" standalone="yes" ?>'.chr(10).
|
||
return '<?xml version="1.0" encoding="'.htmlspecialchars($charset).'" standalone="yes" ?>'.LF.
|
||
self::array2xml($array,'',0,$docTag,0, $options);
|
||
}
|
||
... | ... | |
* @param string tag-prefix, eg. a namespace prefix like "T3:"
|
||
* @param integer Current recursion level. Don't change, stay at zero!
|
||
* @param string Alternative document tag. Default is "phparray".
|
||
* @param integer If greater than zero, then the number of spaces corresponding to this number is used for indenting, if less than zero - no indentation, if zero - a single chr(9) (TAB) is used
|
||
* @param integer If greater than zero, then the number of spaces corresponding to this number is used for indenting, if less than zero - no indentation, if zero - a single TAB is used
|
||
* @param array Options for the compilation. Key "useNindex" => 0/1 (boolean: whether to use "n0, n1, n2" for num. indexes); Key "useIndexTagForNum" => "[tag for numerical indexes]"; Key "useIndexTagForAssoc" => "[tag for associative indexes"; Key "parentTagMap" => array('parentTag' => 'thisLevelTag')
|
||
* @param string Stack data. Don't touch.
|
||
* @return string An XML string made from the input content in the array.
|
||
... | ... | |
chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29).
|
||
chr(30).chr(31);
|
||
// Set indenting mode:
|
||
$indentChar = $spaceInd ? ' ' : chr(9);
|
||
$indentChar = $spaceInd ? ' ' : TAB;
|
||
$indentN = $spaceInd>0 ? $spaceInd : 1;
|
||
$nl = ($spaceInd >= 0 ? chr(10) : '');
|
||
$nl = ($spaceInd >= 0 ? LF : '');
|
||
// Init output variable:
|
||
$output='';
|
||
... | ... | |
require_once(PATH_typo3 . 'contrib/jsmin/jsmin.php');
|
||
try {
|
||
$error = '';
|
||
$script = trim(JSMin::minify(str_replace(chr(13), '', $script)));
|
||
$script = trim(JSMin::minify(str_replace(CR, '', $script)));
|
||
}
|
||
catch(JSMinException $e) {
|
||
$error = 'Error while minifying JavaScript: ' . $e->getMessage();
|
||
... | ... | |
$method = ($includeHeader == 2) ? 'HEAD' : 'GET';
|
||
$msg = $method . ' ' . $parsedURL['path'] .
|
||
($parsedURL['query'] ? '?' . $parsedURL['query'] : '') .
|
||
' HTTP/1.0' . "\r\n" . 'Host: ' .
|
||
' HTTP/1.0' . CRLF . 'Host: ' .
|
||
$parsedURL['host'] . "\r\nConnection: close\r\n";
|
||
if (is_array($requestHeaders)) {
|
||
$msg .= implode("\r\n", $requestHeaders) . "\r\n";
|
||
$msg .= implode(CRLF, $requestHeaders) . CRLF;
|
||
}
|
||
$msg .= "\r\n";
|
||
$msg .= CRLF;
|
||
fputs($fp, $msg);
|
||
while (!feof($fp)) {
|
||
... | ... | |
}
|
||
$ctx = stream_context_create(array(
|
||
'http' => array(
|
||
'header' => implode("\r\n", $requestHeaders)
|
||
'header' => implode(CRLF, $requestHeaders)
|
||
)
|
||
)
|
||
);
|
||
... | ... | |
* @param string Email address to send to. (see PHP function mail())
|
||
* @param string Subject line, non-encoded. (see PHP function mail())
|
||
* @param string Message content, non-encoded. (see PHP function mail())
|
||
* @param string Headers, separated by chr(10)
|
||
* @param string Headers, separated by LF
|
||
* @param string Encoding type: "base64", "quoted-printable", "8bit". Default value is "quoted-printable".
|
||
* @param string Charset used in encoding-headers (only if $encoding is set to a valid value which produces such a header)
|
||
* @param boolean If set, the header content will not be encoded.
|
||
... | ... | |
if (!$dontEncodeHeader) {
|
||
// Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable
|
||
$newHeaders=array();
|
||
foreach (explode(chr(10),$headers) as $line) { // Split the header in lines and convert each line separately
|
||
foreach (explode(LF,$headers) as $line) { // Split the header in lines and convert each line separately
|
||
$parts = explode(': ',$line,2); // Field tags must not be encoded
|
||
if (count($parts)==2) {
|
||
if (0 == strcasecmp($parts[0], 'from')) {
|
||
... | ... | |
$newHeaders[] = $line; // Should never happen - is such a mail header valid? Anyway, just add the unchanged line...
|
||
}
|
||
}
|
||
$headers = implode(chr(10),$newHeaders);
|
||
$headers = implode(LF,$newHeaders);
|
||
unset($newHeaders);
|
||
$email = self::encodeHeader($email,$encoding,$charset); // Email address must not be encoded, but it could be appended by a name which should be so (e.g. "Kasper Sk�rh�j <kasperYYYY@typo3.com>")
|
||
... | ... | |
switch ((string)$encoding) {
|
||
case 'base64':
|
||
$headers=trim($headers).chr(10).
|
||
'Mime-Version: 1.0'.chr(10).
|
||
'Content-Type: text/plain; charset="'.$charset.'"'.chr(10).
|
||
$headers=trim($headers).LF.
|
||
'Mime-Version: 1.0'.LF.
|
||
'Content-Type: text/plain; charset="'.$charset.'"'.LF.
|
||
'Content-Transfer-Encoding: base64';
|
||
$message=trim(chunk_split(base64_encode($message.chr(10)))).chr(10); // Adding chr(10) because I think MS outlook 2002 wants it... may be removed later again.
|
||
$message=trim(chunk_split(base64_encode($message.LF))).LF; // Adding LF because I think MS outlook 2002 wants it... may be removed later again.
|
||
break;
|
||
case '8bit':
|
||
$headers=trim($headers).chr(10).
|
||
'Mime-Version: 1.0'.chr(10).
|
||
'Content-Type: text/plain; charset='.$charset.chr(10).
|
||
$headers=trim($headers).LF.
|
||
'Mime-Version: 1.0'.LF.
|
||
'Content-Type: text/plain; charset='.$charset.LF.
|
||
'Content-Transfer-Encoding: 8bit';
|
||
break;
|
||
case 'quoted-printable':
|
||
default:
|
||
$headers=trim($headers).chr(10).
|
||
'Mime-Version: 1.0'.chr(10).
|
||
'Content-Type: text/plain; charset='.$charset.chr(10).
|
||
$headers=trim($headers).LF.
|
||
'Mime-Version: 1.0'.LF.
|
||
'Content-Type: text/plain; charset='.$charset.LF.
|
||
'Content-Transfer-Encoding: quoted-printable';
|
||
$message=self::quoted_printable($message);
|
||
... | ... | |
// Headers must be separated by CRLF according to RFC 2822, not just LF.
|
||
// But many servers (Gmail, for example) behave incorectly and want only LF.
|
||
// So we stick to LF in all cases.
|
||
$headers = trim(implode(chr(10), self::trimExplode(chr(10), $headers, true))); // Make sure no empty lines are there.
|
||
$headers = trim(implode(LF, self::trimExplode(LF, $headers, true))); // Make sure no empty lines are there.
|
||
$ret = @mail($email, $subject, $message, $headers);
|
||
if (!$ret) {
|
||
... | ... | |
*/
|
||
public static function quoted_printable($string,$maxlen=76) {
|
||
// Make sure the string contains only Unix linebreaks
|
||
$string = str_replace(chr(13).chr(10), chr(10), $string); // Replace Windows breaks (\r\n)
|
||
$string = str_replace(chr(13), chr(10), $string); // Replace Mac breaks (\r)
|
||
$string = str_replace(CRLF, LF, $string); // Replace Windows breaks (\r\n)
|
||
$string = str_replace(CR, LF, $string); // Replace Mac breaks (\r)
|
||
$linebreak = chr(10); // Default line break for Unix systems.
|
||
$linebreak = LF; // Default line break for Unix systems.
|
||
if (TYPO3_OS=='WIN') {
|
||
$linebreak = chr(13).chr(10); // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the linebreak needs to be \r\n.
|
||
$linebreak = CRLF; // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the linebreak needs to be \r\n.
|
||
}
|
||
$newString = '';
|
||
$theLines = explode(chr(10),$string); // Split lines
|
||
$theLines = explode(LF,$string); // Split lines
|
||
foreach ($theLines as $val) {
|
||
$newVal = '';
|
||
$theValLen = strlen($val);
|
||
... | ... | |
}
|
||
}
|
||
$newVal = preg_replace('/'.chr(32).'$/','=20',$newVal); // Replaces a possible SPACE-character at the end of a line
|
||
$newVal = preg_replace('/'.chr(9).'$/','=09',$newVal); // Replaces a possible TAB-character at the end of a line
|
||
$newVal = preg_replace('/'.TAB.'$/','=09',$newVal); // Replaces a possible TAB-character at the end of a line
|
||
$newString.=$newVal.$linebreak;
|
||
}
|
||
return preg_replace('/'.$linebreak.'$/','',$newString); // Remove last newline
|
||
... | ... | |
$file = fopen($destination, 'a');
|
||
if ($file) {
|
||
flock($file, LOCK_EX); // try locking, but ignore if not available (eg. on NFS and FAT)
|
||
fwrite($file, date($dateFormat.' '.$timeFormat).$msgLine.chr(10));
|
||
fwrite($file, date($dateFormat.' '.$timeFormat).$msgLine.LF);
|
||
flock($file, LOCK_UN); // release the lock
|
||
fclose($file);
|
||
}
|
||
... | ... | |
elseif ($type == 'mail') {
|
||
list($to,$from) = explode('/',$destination);
|
||
mail($to, 'Warning - error in TYPO3 installation',
|
||
'Host: '.$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost']."\n".
|
||
'Extension: '.$extKey."\n".
|
||
'Severity: '.$severity."\n".
|
||
"\n".$msg,
|
||
'Host: '.$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'].LF.
|
||
'Extension: '.$extKey.LF.
|
||
'Severity: '.$severity.LF.
|
||
LF.$msg,
|
||
($from ? 'From: '.$from : '')
|
||
);
|
||
}
|
||
... | ... | |
if ($file) {
|
||
$date = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ': ');
|
||
flock($file, LOCK_EX); // try locking, but ignore if not available (eg. on NFS and FAT)
|
||
@fwrite($file, $date.$msg.chr(10));
|
||
@fwrite($file, $date.$msg.LF);
|
||
flock($file, LOCK_UN); // release the lock
|
||
@fclose($file);
|
||
}
|
||
... | ... | |
$valListCnt = count($valueList);
|
||
foreach ($arr as $key => $value) {
|
||
if (!$valListCnt || in_array($key, $valueList)) {
|
||
$str .= (string)$key.trim(': '.self::fixed_lgd_cs(str_replace("\n",'|',(string)$value), $valueLength)).'; ';
|
||
$str .= (string)$key.trim(': '.self::fixed_lgd_cs(str_replace(LF,'|',(string)$value), $valueLength)).'; ';
|
||
}
|
||
}
|
||
return $str;
|
||
... | ... | |
*/
|
||
static public function quoteJSvalue($value, $withinCData = false) {
|
||
$escapedValue = addcslashes(
|
||
$value, '\'' . '"' . '\\' . chr(9) . chr(10) . chr(13)
|
||
$value, '\'' . '"' . '\\' . TAB . LF . CR
|
||
);
|
||
if (!$withinCData) {
|
||
$escapedValue = htmlspecialchars($escapedValue);
|