From a50a1937ca193ca10553e93c609351a396fe4942 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 18 Jul 2008 12:14:55 +0000 Subject: Added the autop function, replaced any references to nl2br git-svn-id: https://code.elgg.org/elgg/trunk@1468 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/input.php | 46 +++++++++++++++++++++-- mod/profile/views/default/profile/userdetails.php | 2 +- views/default/admin/main.php | 2 +- views/default/admin/plugins.php | 2 +- views/default/admin/site.php | 2 +- views/default/admin/statistics.php | 2 +- views/default/admin/user.php | 2 +- views/default/messages/errors/error.php | 2 +- views/default/messages/exceptions/exception.php | 4 +- views/default/messages/messages/message.php | 2 +- views/default/output/longtext.php | 2 +- views/default/settings/install.php | 2 +- views/default/usersettings/main.php | 2 +- views/default/usersettings/plugins.php | 2 +- views/default/usersettings/statistics.php | 2 +- views/failsafe/messages/exceptions/exception.php | 4 +- views/failsafe/messages/sanitisation/htaccess.php | 2 +- views/failsafe/messages/sanitisation/settings.php | 2 +- views/odd/messages/exceptions/exception.php | 2 +- views/rss/object/default.php | 2 +- views/rss/user/default.php | 4 +- views/xml/messages/exceptions/exception.php | 2 +- 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, 'view link', $text); + $text = str_replace($url, ''. elgg_echo("link:view") .'', $text); } } return $text; } + function autop($pee, $br = 1) { + $pee = $pee . "\n"; // just to make things a little easier, pad the end + $pee = preg_replace('|
\s*
|', "\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('!()!', "$1\n\n", $pee); + $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines + if ( strpos($pee, ']*)>\s*|', "", $pee); // no pee inside object/embed + $pee = preg_replace('|\s*\s*|', '', $pee); + } + $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates + $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "

$1

\n", $pee); // make paragraphs, including one at the end + $pee = preg_replace('|

\s*?

|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace + $pee = preg_replace('!

([^<]+)\s*?(]*>)!', "

$1

$2", $pee); + $pee = preg_replace( '|

|', "$1

", $pee ); + $pee = preg_replace('!

\s*(]*>)\s*

!', "$1", $pee); // don't pee all over a tag + $pee = preg_replace("|

(|", "$1", $pee); // problem with nested lists + $pee = preg_replace('|

]*)>|i', "

", $pee); + $pee = str_replace('

', '

', $pee); + $pee = preg_replace('!

\s*(]*>)!', "$1", $pee); + $pee = preg_replace('!(]*>)\s*

!', "$1", $pee); + if ($br) { + $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee); + $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks + $pee = str_replace('', "\n", $pee); + } + $pee = preg_replace('!(]*>)\s*
!', "$1", $pee); + $pee = preg_replace('!
(\s*]*>)!', '$1', $pee); + if (strpos($pee, ')(.*?)!is', 'clean_pre', $pee ); + $pee = preg_replace( "|\n

$|", '

', $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 @@
-


description); ?>

+


description); ?>

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 "

" . nl2br(elgg_echo("admin:description")) . "

"; + echo "

" . autop(elgg_echo("admin:description")) . "

"; 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 "

" . nl2br(elgg_echo("admin:plugins:description")) . "

"; + echo "

" . autop(elgg_echo("admin:plugins:description")) . "

"; $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 "

" . nl2br(elgg_echo("admin:site:description")) . "

"; + echo "

" . autop(elgg_echo("admin:site:description")) . "

"; 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 "

" . nl2br(elgg_echo("admin:statistics:description")) . "

"; + echo "

" . autop(elgg_echo("admin:statistics:description")) . "

"; ?> \ 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 "

" . nl2br(elgg_echo("admin:user:description")) . "

"; + echo "

" . autop(elgg_echo("admin:user:description")) . "

"; 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 @@ ?>

- +

\ 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 @@ getMessage()); + echo autop($vars['object']->getMessage()); ?> @@ -32,7 +32,7 @@

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 @@ ?>

- +

\ 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 "

" . nl2br(elgg_echo("installation:settings:description")) . "

"; + echo "

" . autop(elgg_echo("installation:settings:description")) . "

"; 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 "

" . nl2br(elgg_echo("usersettings:description")) . "

"; + echo "

" . autop(elgg_echo("usersettings:description")) . "

"; ?> \ 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 "

" . nl2br(elgg_echo("usersettings:plugins:description")) . "

"; + echo "

" . autop(elgg_echo("usersettings:plugins:description")) . "

"; $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 "

" . nl2br(elgg_echo("usersettings:statistics:description")) . "

"; + echo "

" . autop(elgg_echo("usersettings:statistics:description")) . "

"; ?> \ 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 @@ getMessage()); + echo autop($vars['object']->getMessage()); ?> @@ -32,7 +32,7 @@

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')); ?> \ 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')); ?>

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; ?>