[geeklog-hg] geeklog: Introduce COM_nl2br() to fix nl2br which breaks HTML co...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Tue Nov 20 11:41:35 EST 2012
changeset 8873:b8263e6b5535
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/b8263e6b5535
user: Tom <websitemaster at cogeco.net>
date: Tue Nov 20 11:40:48 2012 -0500
description:
Introduce COM_nl2br() to fix nl2br which breaks HTML compliance. Original patch by Erisco and Rouslan Placella. (bug #0001141)
diffstat:
public_html/admin/install/bigdump.php | 2 +-
public_html/admin/install/configinfo.php | 2 +-
public_html/calendar/event.php | 6 +++---
public_html/lib-common.php | 24 +++++++++++++++++++-----
public_html/links/index.php | 2 +-
system/classes/story.class.php | 6 +++---
system/lib-comment.php | 7 +++----
system/lib-syndication.php | 8 ++++----
system/lib-user.php | 4 ++--
9 files changed, 37 insertions(+), 24 deletions(-)
diffs (236 lines):
diff -r f32de78ba49c -r b8263e6b5535 public_html/admin/install/bigdump.php
--- a/public_html/admin/install/bigdump.php Sun Oct 28 10:10:42 2012 -0400
+++ b/public_html/admin/install/bigdump.php Tue Nov 20 11:40:48 2012 -0500
@@ -268,7 +268,7 @@
// Execute query if end of query detected (; as last character) AND NOT in parents
if (preg_match("/;$/",trim($dumpline)) && !$inparents) {
if (!TESTMODE && !mysql_query(trim($query), $dbconnection)) {
- echo INST_getAlertMsg($LANG_BIGDUMP[17] . $linenumber . ': ' . trim($dumpline) . '.<br ' . XHTML . '>' . $LANG_BIGDUMP[18] . trim(nl2br(htmlentities($query))) . '<br ' . XHTML . '>' . $LANG_BIGDUMP[19] . mysql_error());
+ echo INST_getAlertMsg($LANG_BIGDUMP[17] . $linenumber . ': ' . trim($dumpline) . '.<br ' . XHTML . '>' . $LANG_BIGDUMP[18] . trim(COM_nl2br(htmlentities($query))) . '<br ' . XHTML . '>' . $LANG_BIGDUMP[19] . mysql_error());
$error=true;
break;
}
diff -r f32de78ba49c -r b8263e6b5535 public_html/admin/install/configinfo.php
--- a/public_html/admin/install/configinfo.php Sun Oct 28 10:10:42 2012 -0400
+++ b/public_html/admin/install/configinfo.php Tue Nov 20 11:40:48 2012 -0500
@@ -75,7 +75,7 @@
if (is_array($value)) {
ob_start();
print_r($value);
- $value=nl2br(ob_get_contents());
+ $value = COM_nl2br(ob_get_contents());
ob_end_clean();
} elseif (is_bool($value)) {
$value = ($value === false) ? 'false' : 'true';
diff -r f32de78ba49c -r b8263e6b5535 public_html/calendar/event.php
--- a/public_html/calendar/event.php Sun Oct 28 10:10:42 2012 -0400
+++ b/public_html/calendar/event.php Tue Nov 20 11:40:48 2012 -0500
@@ -108,7 +108,7 @@
$cal_template->set_var('lang_description', $LANG_CAL_1[5]);
$description = stripslashes ($A['description']);
if (empty($A['postmode']) || ($A['postmode'] == 'plaintext')) {
- $description = nl2br ($description);
+ $description = COM_nl2br($description);
}
$cal_template->set_var ('event_description',
PLG_replaceTags ($description));
@@ -290,7 +290,7 @@
$cal_templates->set_var('lang_description', $LANG_CAL_1[5]);
$cal_templates->set_var('event_description',
- nl2br (stripslashes ($A['description'])));
+ COM_nl2br(stripslashes($A['description'])));
$cal_templates->set_var('lang_htmlnotallowed', $LANG_CAL_1[44]);
$cal_templates->set_var('lang_submit', $LANG_CAL_1[45]);
@@ -656,7 +656,7 @@
$cal_templates->set_var('lang_description', $LANG_CAL_1[5]);
$description = stripslashes($A['description']);
if (empty($A['postmode']) || ($A['postmode'] == 'plaintext')) {
- $description = nl2br($description);
+ $description = COM_nl2br($description);
}
$description = PLG_replaceTags($description);
if (!empty($query)) {
diff -r f32de78ba49c -r b8263e6b5535 public_html/lib-common.php
--- a/public_html/lib-common.php Sun Oct 28 10:10:42 2012 -0400
+++ b/public_html/lib-common.php Tue Nov 20 11:40:48 2012 -0500
@@ -2807,13 +2807,13 @@
case 2:
$retval .= COM_startBlock( $LANG01[55] . ' ' . $timestamp, '',
COM_getBlockTemplate( '_msg_block', 'header' ))
- . nl2br( $logentry )
+ . COM_nl2br($logentry)
. COM_endBlock( COM_getBlockTemplate( '_msg_block',
'footer' ));
break;
case 3:
- $retval = nl2br($logentry);
+ $retval = COM_nl2br($logentry);
break;
default:
@@ -2829,7 +2829,7 @@
$retval .= COM_startBlock( $LANG01[34] . ' - ' . $timestamp,
'', COM_getBlockTemplate( '_msg_block',
'header' ))
- . nl2br( $logentry )
+ . COM_nl2br($logentry)
. COM_endBlock( COM_getBlockTemplate( '_msg_block',
'footer' ));
}
@@ -4511,11 +4511,11 @@
$blockcontent = stripslashes($A['content']);
// Hack: If the block content starts with a '<' assume it
- // contains HTML and do not call nl2br() which would only add
+ // contains HTML and do not call COM_nl2br() which would only add
// unwanted <br> tags.
if (substr(trim($blockcontent), 0, 1) != '<') {
- $blockcontent = nl2br($blockcontent);
+ $blockcontent = COM_nl2br($blockcontent);
}
// autotags are only(!) allowed in normal blocks
@@ -8414,6 +8414,20 @@
}
/**
+ * Replaces all newlines in a string with <br> or <br />,
+ * depending on the detected setting.
+ *
+ * @param string $string The string to modify
+ * @return string The modified string
+ */
+function COM_nl2br($string) {
+ $tag = '<br' . XHTML . '>';
+ $find = array("\r\n", "\n\r", "\r", "\n");
+ $replace = array($tag."\r\n", $tag."\n\r", $tag."\r", $tag."\n");
+ return str_replace($find, $replace, $string);
+}
+
+/**
* Now include all plugin functions
*/
foreach ($_PLUGINS as $pi_name) {
diff -r f32de78ba49c -r b8263e6b5535 public_html/links/index.php
--- a/public_html/links/index.php Sun Oct 28 10:10:42 2012 -0400
+++ b/public_html/links/index.php Tue Nov 20 11:40:48 2012 -0500
@@ -365,7 +365,7 @@
$template->set_var('link_name_encoded', rawurlencode($title));
$template->set_var('link_hits', COM_numberFormat($A['hits']));
$template->set_var('link_description',
- PLG_replaceTags( nl2br(stripslashes($A['description'])) ));
+ PLG_replaceTags( COM_nl2br(stripslashes($A['description'])) ));
$attr = array('title' => $actualUrl);
if (substr($actualUrl, 0, strlen($_CONF['site_url'])) != $_CONF['site_url']) {
diff -r f32de78ba49c -r b8263e6b5535 system/classes/story.class.php
--- a/system/classes/story.class.php Sun Oct 28 10:10:42 2012 -0400
+++ b/system/classes/story.class.php Tue Nov 20 11:40:48 2012 -0500
@@ -1674,7 +1674,7 @@
{
case 'introtext':
if ($this->_postmode == 'plaintext') {
- $return = nl2br($this->_introtext);
+ $return = COM_nl2br($this->_introtext);
} elseif ($this->_postmode == 'wikitext') {
$return = COM_renderWikiText($this->_editUnescape($this->_introtext));
} else {
@@ -1686,7 +1686,7 @@
case 'bodytext':
if (($this->_postmode == 'plaintext') && !(empty($this->_bodytext))) {
- $return = nl2br($this->_bodytext);
+ $return = COM_nl2br($this->_bodytext);
} elseif (($this->_postmode == 'wikitext') && !(empty($this->_bodytext))) {
$return = COM_renderWikiText($this->_editUnescape($this->_bodytext));
} elseif (!empty($this->_bodytext)) {
@@ -2160,7 +2160,7 @@
* title, page title, intro and body of the article from the post array, removing all
* HTML mode content into the nice safe form that geeklog can then (simply)
* spit back out into the page on render. After doing a magic tags
- * replacement. And nl2br.
+ * replacement. And COM_nl2br.
*
* This DOES NOT ADDSLASHES! We do that on DB store, because we want to
* keep our internal variables in "display mode", not in db mode or anything.
diff -r f32de78ba49c -r b8263e6b5535 system/lib-comment.php
--- a/system/lib-comment.php Sun Oct 28 10:10:42 2012 -0400
+++ b/system/lib-comment.php Tue Nov 20 11:40:48 2012 -0500
@@ -557,8 +557,7 @@
$text = str_replace('<div class="comment-edit">', '', $text);
$text = str_replace('</div><!-- /COMMENTEDIT -->', '', $text);
if (preg_match('/<.*>/', $text) == 0) {
-// $A['comment'] = '<p>' . nl2br($A['comment']) . '</p>';
- $A['comment'] = '<div class="commentbody">' . nl2br($A['comment']) . '</div>';
+ $A['comment'] = '<div class="commentbody">' . COM_nl2br($A['comment']) . '</div>';
}
// highlight search terms if specified
@@ -1829,7 +1828,7 @@
$comment = htmlspecialchars(COM_checkWords(COM_stripslashes($comment)));
$newcomment = COM_makeClickableLinks ($comment);
if (strcmp ($comment, $newcomment) != 0) {
- $comment = nl2br ($newcomment);
+ $comment = COM_nl2br($newcomment);
}
}
@@ -1856,7 +1855,7 @@
if (!empty ($sig)) {
$comment .= '<!-- COMMENTSIG --><div class="comment-sig">';
if ( $postmode == 'html') {
- $comment .= '---<br' . XHTML . '>' . nl2br($sig);
+ $comment .= '---<br' . XHTML . '>' . COM_nl2br($sig);
} else {
$comment .= '---' . LB . $sig;
}
diff -r f32de78ba49c -r b8263e6b5535 system/lib-syndication.php
--- a/system/lib-syndication.php Sun Oct 28 10:10:42 2012 -0400
+++ b/system/lib-syndication.php Tue Nov 20 11:40:48 2012 -0500
@@ -299,11 +299,11 @@
{
if( !empty($storytext) )
{
- $storytext = nl2br($storytext);
+ $storytext = COM_nl2br($storytext);
}
if( !empty($fulltext) )
{
- $fulltext = nl2br($fulltext);
+ $fulltext = COM_nl2br($fulltext);
}
}
@@ -439,11 +439,11 @@
{
if( !empty($storytext) )
{
- $storytext = nl2br($storytext);
+ $storytext = COM_nl2br($storytext);
}
if( !empty($fulltext) )
{
- $fulltext = nl2br($fulltext);
+ $fulltext = COM_nl2br($fulltext);
}
}
diff -r f32de78ba49c -r b8263e6b5535 system/lib-user.php
--- a/system/lib-user.php Sun Oct 28 10:10:42 2012 -0400
+++ b/system/lib-user.php Tue Nov 20 11:40:48 2012 -0500
@@ -965,9 +965,9 @@
$user_templates->set_var('lang_location', $LANG04[106]);
$user_templates->set_var('user_location', strip_tags($A['location']));
$user_templates->set_var('lang_bio', $LANG04[7]);
- $user_templates->set_var('user_bio', nl2br(stripslashes ($A['about'])));
+ $user_templates->set_var('user_bio', COM_nl2br(stripslashes($A['about'])));
$user_templates->set_var('lang_pgpkey', $LANG04[8]);
- $user_templates->set_var('user_pgp', nl2br ($A['pgpkey']));
+ $user_templates->set_var('user_pgp', COM_nl2br($A['pgpkey']));
$user_templates->set_var('start_block_last10stories',
COM_startBlock($LANG04[82] . ' ' . $display_name));
$user_templates->set_var('start_block_last10comments',
More information about the geeklog-cvs
mailing list