Permalink
Browse files

BackwardsCompatibilityBreak - fHTML::checkForBlockLevelHTML() was ren…

…amed to fHTML::containsBlockLevelHTML() and fHTML::createLinks() was renamed to fHTML::makeLinks()
  • Loading branch information...
wbond committed Sep 14, 2008
1 parent a4c6fc1 commit 5b39138e3c2426d1930fbe7139aea44c0b2602ca
Showing with 32 additions and 33 deletions.
  1. +1 −1 classes/fActiveRecord.php
  2. +27 −27 classes/fHTML.php
  3. +4 −5 classes/fPrintableException.php
@@ -1045,7 +1045,7 @@ protected function prepare($column, $formatting=NULL)
// Turn like-breaks into breaks for text fields and add links
if ($formatting === TRUE && in_array($column_type, array('varchar', 'char', 'text'))) {
return fHTML::createLinks(fHTML::convertNewlines(fHTML::prepare($value)));
return fHTML::makeLinks(fHTML::convertNewlines(fHTML::prepare($value)));
}
// Anything that has gotten to here is a string value, or is not the
View
@@ -23,7 +23,7 @@ class fHTML
* @param string $content The HTML content to check
* @return boolean If the content contains a block level tag
*/
static public function checkForBlockLevelHTML($content)
static public function containsBlockLevelHTML($content)
{
static $inline_tags = '<a><abbr><acronym><b><big><br><button><cite><code><del><dfn><em><font><i><img><input><ins><kbd><label><q><s><samp><select><small><span><strike><strong><sub><sup><textarea><tt><u><var>';
return strip_tags($content, $inline_tags) != $content;
@@ -43,14 +43,38 @@ static public function convertNewlines($content)
}
/**
* Converts all html entities to normal characters, using UTF-8
*
* @param string $content The content to decode
* @return string The decoded content
*/
static public function decode($content)
{
return html_entity_decode($content, ENT_COMPAT, 'UTF-8');
}
/**
* Converts all special characters to entites, using UTF-8.
*
* @param string $content The content to encode
* @return string The encoded content
*/
static public function encode($content)
{
return htmlentities($content, ENT_COMPAT, 'UTF-8');
}
/**
* Takes a block of text and converts all URLs into HTML links
*
* @param string $content The content to parse for links
* @param integer $link_text_length If non-zero, all link text will be truncated to this many characters
* @return string The content with all URLs converted to HTML link
*/
static public function createLinks($content, $link_text_length=0)
static public function makeLinks($content, $link_text_length=0)
{
// Determine what replacement to perform
if ($link_text_length) {
@@ -108,30 +132,6 @@ static public function createLinks($content, $link_text_length=0)
}
/**
* Converts all html entities to normal characters, using UTF-8
*
* @param string $content The content to decode
* @return string The decoded content
*/
static public function decode($content)
{
return html_entity_decode($content, ENT_COMPAT, 'UTF-8');
}
/**
* Converts all special characters to entites, using UTF-8.
*
* @param string $content The content to encode
* @return string The encoded content
*/
static public function encode($content)
{
return htmlentities($content, ENT_COMPAT, 'UTF-8');
}
/**
* Prepares content for display in UTF-8 encoded HTML - allows HTML tags
*
@@ -186,7 +186,7 @@ static public function show($content, $css_class='')
}
$class = ($css_class) ? ' class="' . $css_class . '"' : '';
if (self::checkForBlockLevelHTML($content)) {
if (self::containsBlockLevelHTML($content)) {
echo '<div' . $class . '>' . self::prepare($content) . '</div>';
} else {
echo '<p' . $class . '>' . self::prepare($content) . '</p>';
@@ -41,8 +41,7 @@ public function formatTrace()
*/
protected function getCSSClass()
{
// underscorize the current exception class name, extracted from fGrammar::underscorize() to reduce dependencies
return strtolower(preg_replace('/(?:([a-z0-9A-Z])([A-Z])|([a-zA-Z])([0-9]))/', '\1\3_\2\4', preg_replace('#^f#', '', get_class($this))));
return fGrammar::underscorize(preg_replace('#^f#', '', get_class($this)));
}
@@ -53,17 +52,17 @@ protected function getCSSClass()
*/
protected function prepare($content)
{
// See if the message has newline characters but not br tags, extracted from fHTML::convertNewlines() to reduce dependencies
// See if the message has newline characters but not br tags, extracted from fHTML to reduce dependencies
static $inline_tags_minus_br = '<a><abbr><acronym><b><big><button><cite><code><del><dfn><em><font><i><img><input><ins><kbd><label><q><s><samp><select><small><span><strike><strong><sub><sup><textarea><tt><u><var>';
$content_with_newlines = (strip_tags($content, $inline_tags_minus_br)) ? $content : nl2br($content);
// Check to see if we have any block-level html, extracted from fHTML::checkForBlockLevelHtml() to reduce dependencies
// Check to see if we have any block-level html, extracted from fHTML to reduce dependencies
$inline_tags = $inline_tags_minus_br . '<br>';
$no_block_html = strip_tags($content, $inline_tags) == $content;
$content = html_entity_decode($content, ENT_COMPAT, 'UTF-8');
// This code ensures the output is properly encoded for display in (X)HTML, extracted from fHTML::prepare() to reduce dependencies
// This code ensures the output is properly encoded for display in (X)HTML, extracted from fHTML to reduce dependencies
$reg_exp = "/<\s*\/?\s*[\w:]+(?:\s+[\w:]+(?:\s*=\s*(?:\"[^\"]*?\"|'[^']*?'|[^'\">\s]+))?)*\s*\/?\s*>|&(?:#\d+|\w+);|<\!--.*?-->/";
preg_match_all($reg_exp, $content, $html_matches, PREG_SET_ORDER);
$text_matches = preg_split($reg_exp, $content_with_newlines);

0 comments on commit 5b39138

Please sign in to comment.