Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - fHTML::checkForBlockLevelHTML() was ren…
Browse files Browse the repository at this point in the history
…amed to fHTML::containsBlockLevelHTML() and fHTML::createLinks() was renamed to fHTML::makeLinks()
  • Loading branch information
wbond committed Apr 12, 2012
1 parent a4c6fc1 commit 5b39138
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion classes/fActiveRecord.php
Expand Up @@ -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
Expand Down
54 changes: 27 additions & 27 deletions classes/fHTML.php
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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>';
Expand Down
9 changes: 4 additions & 5 deletions classes/fPrintableException.php
Expand Up @@ -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)));
}


Expand All @@ -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);
Expand Down

0 comments on commit 5b39138

Please sign in to comment.