aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-18 12:14:55 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-18 12:14:55 +0000
commita50a1937ca193ca10553e93c609351a396fe4942 (patch)
tree8e363053afa6d94e12caa2dd0283067b7ed97788
parent961fc5a437c8d458884560485864d057aa807a25 (diff)
downloadelgg-a50a1937ca193ca10553e93c609351a396fe4942.tar.gz
elgg-a50a1937ca193ca10553e93c609351a396fe4942.tar.bz2
Added the autop function, replaced any references to nl2br
git-svn-id: https://code.elgg.org/elgg/trunk@1468 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/input.php46
-rw-r--r--mod/profile/views/default/profile/userdetails.php2
-rw-r--r--views/default/admin/main.php2
-rw-r--r--views/default/admin/plugins.php2
-rw-r--r--views/default/admin/site.php2
-rw-r--r--views/default/admin/statistics.php2
-rw-r--r--views/default/admin/user.php2
-rw-r--r--views/default/messages/errors/error.php2
-rw-r--r--views/default/messages/exceptions/exception.php4
-rw-r--r--views/default/messages/messages/message.php2
-rw-r--r--views/default/output/longtext.php2
-rw-r--r--views/default/settings/install.php2
-rw-r--r--views/default/usersettings/main.php2
-rw-r--r--views/default/usersettings/plugins.php2
-rw-r--r--views/default/usersettings/statistics.php2
-rw-r--r--views/failsafe/messages/exceptions/exception.php4
-rw-r--r--views/failsafe/messages/sanitisation/htaccess.php2
-rw-r--r--views/failsafe/messages/sanitisation/settings.php2
-rw-r--r--views/odd/messages/exceptions/exception.php2
-rw-r--r--views/rss/object/default.php2
-rw-r--r--views/rss/user/default.php4
-rw-r--r--views/xml/messages/exceptions/exception.php2
22 files changed, 66 insertions, 28 deletions
diff --git a/engine/lib/input.php b/engine/lib/input.php
index cd8e6ab3b..e6929f6c0 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -62,9 +62,10 @@
}
/**
- * This is a function to make url clickable
- * @param string text
- * @return string text
+ * Takes a string and turns any URLs into formatted links
+ *
+ * @param string $text The input string
+ * @return string The output stirng with formatted links
**/
function parse_urls($text) {
@@ -73,13 +74,50 @@
foreach (array_unique($urls[1]) AS $url){
$urltext = $url;
- $text = str_replace($url, '<a href="'. $url .'" style="text-decoration:underline;">view link</a>', $text);
+ $text = str_replace($url, '<a href="'. $url .'" style="text-decoration:underline;">'. elgg_echo("link:view") .'</a>', $text);
}
}
return $text;
}
+ function autop($pee, $br = 1) {
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
+ $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
+ // Space things out a little
+ $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
+ $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
+ $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '<object') !== false ) {
+ $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
+ $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
+ }
+ $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
+ $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
+ $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
+ $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
+ $pee = preg_replace( '|<p>|', "$1<p>", $pee );
+ $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
+ $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
+ $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
+ $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
+ $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
+ $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
+ if ($br) {
+ $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
+ $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
+ $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
+ }
+ $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
+ $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
+ if (strpos($pee, '<pre') !== false)
+ $pee = preg_replace_callback('!(<pre.*?>)(.*?)</pre>!is', 'clean_pre', $pee );
+ $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
+
+ return $pee;
+ }
+
function input_init() {
global $CONFIG;
$CONFIG->allowedtags = array ('address' => array (), 'a' => array ('href' => array (), 'title' => array (), 'rel' => array (), 'rev' => array (), 'name' => array ()), 'abbr' => array ('title' => array ()), 'acronym' => array ('title' => array ()), 'b' => array (), 'big' => array (), 'blockquote' => array ('cite' => array ()), 'br' => array (), 'button' => array ('disabled' => array (), 'name' => array (), 'type' => array (), 'value' => array ()), 'caption' => array ('align' => array ()), 'code' => array (), 'col' => array ('align' => array (), 'char' => array (), 'charoff' => array (), 'span' => array (), 'valign' => array (), 'width' => array ()), 'del' => array ('datetime' => array ()), 'dd' => array (), 'div' => array ('align' => array ()), 'dl' => array (), 'dt' => array (), 'em' => array (), 'fieldset' => array (), 'font' => array ('color' => array (), 'face' => array (), 'size' => array ()), 'form' => array ('action' => array (), 'accept' => array (), 'accept-charset' => array (), 'enctype' => array (), 'method' => array (), 'name' => array (), 'target' => array ()), 'h1' => array ('align' => array ()), 'h2' => array ('align' => array ()), 'h3' => array ('align' => array ()), 'h4' => array ('align' => array ()), 'h5' => array ('align' => array ()), 'h6' => array ('align' => array ()), 'hr' => array ('align' => array (), 'noshade' => array (), 'size' => array (), 'width' => array ()), 'i' => array (), 'img' => array ('alt' => array (), 'align' => array (), 'border' => array (), 'height' => array (), 'hspace' => array (), 'longdesc' => array (), 'vspace' => array (), 'src' => array (), 'width' => array ()), 'ins' => array ('datetime' => array (), 'cite' => array ()), 'kbd' => array (), 'label' => array ('for' => array ()), 'legend' => array ('align' => array ()), 'li' => array (), 'p' => array ('align' => array ()), 'pre' => array ('width' => array ()), 'q' => array ('cite' => array ()), 's' => array (), 'strike' => array (), 'strong' => array (), 'sub' => array (), 'sup' => array (), 'table' => array ('align' => array (), 'bgcolor' => array (), 'border' => array (), 'cellpadding' => array (), 'cellspacing' => array (), 'rules' => array (), 'summary' => array (), 'width' => array ()), 'tbody' => array ('align' => array (), 'char' => array (), 'charoff' => array (), 'valign' => array ()), 'td' => array ('abbr' => array (), 'align' => array (), 'axis' => array (), 'bgcolor' => array (), 'char' => array (), 'charoff' => array (), 'colspan' => array (), 'headers' => array (), 'height' => array (), 'nowrap' => array (), 'rowspan' => array (), 'scope' => array (), 'valign' => array (), 'width' => array ()), 'textarea' => array ('cols' => array (), 'rows' => array (), 'disabled' => array (), 'name' => array (), 'readonly' => array ()), 'tfoot' => array ('align' => array (), 'char' => array (), 'charoff' => array (), 'valign' => array ()), 'th' => array ('abbr' => array (), 'align' => array (), 'axis' => array (), 'bgcolor' => array (), 'char' => array (), 'charoff' => array (), 'colspan' => array (), 'headers' => array (), 'height' => array (), 'nowrap' => array (), 'rowspan' => array (), 'scope' => array (), 'valign' => array (), 'width' => array ()), 'thead' => array ('align' => array (), 'char' => array (), 'charoff' => array (), 'valign' => array ()), 'title' => array (), 'tr' => array ('align' => array (), 'bgcolor' => array (), 'char' => array (), 'charoff' => array (), 'valign' => array ()), 'tt' => array (), 'u' => array (), 'ul' => array (), 'ol' => array (), 'var' => array () );
diff --git a/mod/profile/views/default/profile/userdetails.php b/mod/profile/views/default/profile/userdetails.php
index de9169922..0a6427afa 100644
--- a/mod/profile/views/default/profile/userdetails.php
+++ b/mod/profile/views/default/profile/userdetails.php
@@ -121,7 +121,7 @@
</table>
<div id="profile_info_wide">
- <p><b><?php echo elgg_echo("profile:aboutme"); ?></b><br /><?php echo nl2br($vars['entity']->description); ?></p>
+ <p><b><?php echo elgg_echo("profile:aboutme"); ?></b><br /><?php echo autop($vars['entity']->description); ?></p>
</div><!-- /#profile_info_wide -->
diff --git a/views/default/admin/main.php b/views/default/admin/main.php
index 84be45780..b6040a5c9 100644
--- a/views/default/admin/main.php
+++ b/views/default/admin/main.php
@@ -12,7 +12,7 @@
*/
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("admin:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("admin:description")) . "</p>";
diff --git a/views/default/admin/plugins.php b/views/default/admin/plugins.php
index b4339f83a..b680bc039 100644
--- a/views/default/admin/plugins.php
+++ b/views/default/admin/plugins.php
@@ -12,7 +12,7 @@
*/
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("admin:plugins:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("admin:plugins:description")) . "</p>";
$limit = get_input('limit', 10);
$offset = get_input('offset', 0);
diff --git a/views/default/admin/site.php b/views/default/admin/site.php
index 8792431c2..202f493d5 100644
--- a/views/default/admin/site.php
+++ b/views/default/admin/site.php
@@ -14,7 +14,7 @@
global $CONFIG;
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("admin:site:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("admin:site:description")) . "</p>";
echo elgg_view("settings/system",array("action" => $CONFIG->wwwroot."action/admin/site/update_basic")); // Always want to do this first.
?> \ No newline at end of file
diff --git a/views/default/admin/statistics.php b/views/default/admin/statistics.php
index 4c2035f0d..f79812b51 100644
--- a/views/default/admin/statistics.php
+++ b/views/default/admin/statistics.php
@@ -12,6 +12,6 @@
global $CONFIG;
- echo "<p>" . nl2br(elgg_echo("admin:statistics:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("admin:statistics:description")) . "</p>";
?> \ No newline at end of file
diff --git a/views/default/admin/user.php b/views/default/admin/user.php
index 2e5445628..d3d80e6f7 100644
--- a/views/default/admin/user.php
+++ b/views/default/admin/user.php
@@ -12,7 +12,7 @@
*/
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("admin:user:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("admin:user:description")) . "</p>";
echo elgg_view("admin/user_opt/adduser");
diff --git a/views/default/messages/errors/error.php b/views/default/messages/errors/error.php
index 078e25949..ddcd0009c 100644
--- a/views/default/messages/errors/error.php
+++ b/views/default/messages/errors/error.php
@@ -16,5 +16,5 @@
?>
<p>
- <?php echo nl2br($vars['object']); ?>
+ <?php echo autop($vars['object']); ?>
</p> \ No newline at end of file
diff --git a/views/default/messages/exceptions/exception.php b/views/default/messages/exceptions/exception.php
index 8df557b48..f56927123 100644
--- a/views/default/messages/exceptions/exception.php
+++ b/views/default/messages/exceptions/exception.php
@@ -21,7 +21,7 @@
<span title="<?php echo get_class($vars['object']); ?>">
<?php
- echo nl2br($vars['object']->getMessage());
+ echo autop($vars['object']->getMessage());
?>
</span>
@@ -32,7 +32,7 @@
<p class="messages-exception-detail">
<?php
- echo nl2br(htmlentities(print_r($vars['object'], true)));
+ echo autop(htmlentities(print_r($vars['object'], true)));
?>
</p>
diff --git a/views/default/messages/messages/message.php b/views/default/messages/messages/message.php
index 1622c29e8..355afeb15 100644
--- a/views/default/messages/messages/message.php
+++ b/views/default/messages/messages/message.php
@@ -16,5 +16,5 @@
?>
<p>
- <?php echo nl2br($vars['object']); ?>
+ <?php echo autop($vars['object']); ?>
</p> \ No newline at end of file
diff --git a/views/default/output/longtext.php b/views/default/output/longtext.php
index 88c8a925c..85ab99fd4 100644
--- a/views/default/output/longtext.php
+++ b/views/default/output/longtext.php
@@ -15,5 +15,5 @@
*
*/
- echo nl2br($vars['value']);
+ echo autop($vars['value']);
?> \ No newline at end of file
diff --git a/views/default/settings/install.php b/views/default/settings/install.php
index 8de795da4..17d263349 100644
--- a/views/default/settings/install.php
+++ b/views/default/settings/install.php
@@ -12,7 +12,7 @@
*
*/
- echo "<p>" . nl2br(elgg_echo("installation:settings:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("installation:settings:description")) . "</p>";
echo elgg_view("settings/system",array("action" => "action/systemsettings/install"));
diff --git a/views/default/usersettings/main.php b/views/default/usersettings/main.php
index 1b0ed11e8..22bbc8e8f 100644
--- a/views/default/usersettings/main.php
+++ b/views/default/usersettings/main.php
@@ -12,5 +12,5 @@
*/
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("usersettings:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("usersettings:description")) . "</p>";
?> \ No newline at end of file
diff --git a/views/default/usersettings/plugins.php b/views/default/usersettings/plugins.php
index 730950178..70dfc5e14 100644
--- a/views/default/usersettings/plugins.php
+++ b/views/default/usersettings/plugins.php
@@ -11,7 +11,7 @@
*/
// Description of what's going on
- echo "<p>" . nl2br(elgg_echo("usersettings:plugins:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("usersettings:plugins:description")) . "</p>";
$limit = get_input('limit', 10);
$offset = get_input('offset', 0);
diff --git a/views/default/usersettings/statistics.php b/views/default/usersettings/statistics.php
index f01e48bc8..8ab6712c6 100644
--- a/views/default/usersettings/statistics.php
+++ b/views/default/usersettings/statistics.php
@@ -12,5 +12,5 @@
global $CONFIG;
- echo "<p>" . nl2br(elgg_echo("usersettings:statistics:description")) . "</p>";
+ echo "<p>" . autop(elgg_echo("usersettings:statistics:description")) . "</p>";
?> \ No newline at end of file
diff --git a/views/failsafe/messages/exceptions/exception.php b/views/failsafe/messages/exceptions/exception.php
index c8c630f3b..0b280107f 100644
--- a/views/failsafe/messages/exceptions/exception.php
+++ b/views/failsafe/messages/exceptions/exception.php
@@ -21,7 +21,7 @@
<span title="<?php echo get_class($vars['object']); ?>">
<?php
- echo nl2br($vars['object']->getMessage());
+ echo autop($vars['object']->getMessage());
?>
</span>
@@ -32,7 +32,7 @@
<p class="messages-exception-detail">
<?php
- echo nl2br(htmlentities(print_r($vars['object'], true)));
+ echo autop(htmlentities(print_r($vars['object'], true)));
?>
</p>
diff --git a/views/failsafe/messages/sanitisation/htaccess.php b/views/failsafe/messages/sanitisation/htaccess.php
index 99bfe4159..bca1b3243 100644
--- a/views/failsafe/messages/sanitisation/htaccess.php
+++ b/views/failsafe/messages/sanitisation/htaccess.php
@@ -12,6 +12,6 @@
* @link http://elgg.org/
*/
- echo nl2br(elgg_echo('installation:error:htaccess'));
+ echo autop(elgg_echo('installation:error:htaccess'));
?>
<textarea cols="120" rows="30"><?php echo $vars['.htaccess']; ?></textarea> \ No newline at end of file
diff --git a/views/failsafe/messages/sanitisation/settings.php b/views/failsafe/messages/sanitisation/settings.php
index 798bfbd91..e4ea720a8 100644
--- a/views/failsafe/messages/sanitisation/settings.php
+++ b/views/failsafe/messages/sanitisation/settings.php
@@ -24,7 +24,7 @@
else
{
- echo nl2br(elgg_echo('installation:error:settings'));
+ echo autop(elgg_echo('installation:error:settings'));
?>
<div>
<h2><?php echo elgg_echo('installation:settings:dbwizard:prompt'); ?></h2>
diff --git a/views/odd/messages/exceptions/exception.php b/views/odd/messages/exceptions/exception.php
index 86b5bba48..38afbee58 100644
--- a/views/odd/messages/exceptions/exception.php
+++ b/views/odd/messages/exceptions/exception.php
@@ -17,7 +17,7 @@
global $CONFIG;
?>
<!--
-<?php echo get_class($vars['object']); ?>: <?php echo nl2br($vars['object']->getMessage()); ?>
+<?php echo get_class($vars['object']); ?>: <?php echo autop($vars['object']->getMessage()); ?>
<?php if ($CONFIG->debug) { ?>
diff --git a/views/rss/object/default.php b/views/rss/object/default.php
index 7c5fc11d8..38732750a 100644
--- a/views/rss/object/default.php
+++ b/views/rss/object/default.php
@@ -25,5 +25,5 @@
<pubDate><?php echo date("r",$vars['entity']->time_created) ?></pubDate>
<link><?php echo $vars['entity']->getURL(); ?></link>
<title><![CDATA[<?php echo $title; ?>]]></title>
- <description><![CDATA[<?php echo (nl2br($vars['entity']->description)); ?>]]></description>
+ <description><![CDATA[<?php echo (autop($vars['entity']->description)); ?>]]></description>
</item>
diff --git a/views/rss/user/default.php b/views/rss/user/default.php
index 5d72b30df..edc8bcd17 100644
--- a/views/rss/user/default.php
+++ b/views/rss/user/default.php
@@ -17,6 +17,6 @@
<guid isPermaLink='true'><?php echo $vars['entity']->getURL(); ?></guid>
<pubDate><?php echo date("r",$vars['entity']->time_created) ?></pubDate>
<link><?php echo $vars['entity']->getURL(); ?></link>
- <title><![CDATA[<?php echo (nl2br($vars['entity']->name)); ?>]]></title>
- <description><![CDATA[<?php echo (nl2br($vars['entity']->description)); ?>]]></description>
+ <title><![CDATA[<?php echo (autop($vars['entity']->name)); ?>]]></title>
+ <description><![CDATA[<?php echo (autop($vars['entity']->description)); ?>]]></description>
</item>
diff --git a/views/xml/messages/exceptions/exception.php b/views/xml/messages/exceptions/exception.php
index 86b5bba48..38afbee58 100644
--- a/views/xml/messages/exceptions/exception.php
+++ b/views/xml/messages/exceptions/exception.php
@@ -17,7 +17,7 @@
global $CONFIG;
?>
<!--
-<?php echo get_class($vars['object']); ?>: <?php echo nl2br($vars['object']->getMessage()); ?>
+<?php echo get_class($vars['object']); ?>: <?php echo autop($vars['object']->getMessage()); ?>
<?php if ($CONFIG->debug) { ?>