1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Text parser - usubstr() method fix (always returned empty string), utf8 parser methods lowercased

This commit is contained in:
secretr
2010-01-12 13:11:48 +00:00
parent f91d47b456
commit 92d926279c
4 changed files with 74 additions and 71 deletions

View File

@@ -9,8 +9,8 @@
* Text processing and parsing functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.90 $
* $Date: 2010-01-09 13:17:45 $
* $Revision: 1.91 $
* $Date: 2010-01-12 13:11:48 $
* $Author: secretr $
*
*/
@@ -299,7 +299,7 @@ class e_parse
* @param string $str The UTF-8 encoded string being measured for length.
* @return integer The length (amount of UTF-8 characters) of the string on success, and 0 if the string is empty.
*/
public function uStrLen($str)
public function ustrlen($str)
{
switch($this->utfAction)
{
@@ -321,7 +321,7 @@ class e_parse
* @param string $str The UTF-8 encoded string to be lowercased.
* @return string Specified string with all alphabetic characters converted to lowercase.
*/
public function uStrToLower($str)
public function ustrtolower($str)
{
switch($this->utfAction)
{
@@ -342,7 +342,7 @@ class e_parse
* @param string $str The UTF-8 encoded string to be uppercased.
* @return string Specified string with all alphabetic characters converted to uppercase.
*/
public function uStrToUpper($str)
public function ustrtoupper($str)
{
switch($this->utfAction)
{
@@ -368,7 +368,7 @@ class e_parse
* The position returned is still relative to the beginning of haystack.
* @return integer|boolean Returns the position as an integer. If needle is not found, the function will return boolean FALSE.
*/
public function uStrPos($haystack, $needle, $offset = 0)
public function ustrpos($haystack, $needle, $offset = 0)
{
switch($this->utfAction)
{
@@ -393,7 +393,7 @@ class e_parse
* The position returned is still relative to the beginning of haystack.
* @return integer|boolean Returns the position as an integer. If needle is not found, the function will return boolean FALSE.
*/
public function uStrrPos($haystack, $needle, $offset = 0)
public function ustrrpos($haystack, $needle, $offset = 0)
{
switch($this->utfAction)
{
@@ -420,7 +420,7 @@ class e_parse
* (depending on the length of string). If length is omitted, the rest of string from start will be returned.
* @return string The extracted UTF-8 encoded part of input string.
*/
public function uSubStr($str, $start, $length = NULL)
public function usubstr($str, $start, $length = NULL)
{
switch($this->utfAction)
{
@@ -429,11 +429,11 @@ class e_parse
case 1:
if(is_null($length))
{
return mb_substr($haystack, $needle);
return mb_substr($str, $start);
}
else
{
return mb_substr($haystack, $needle, $offset);
return mb_substr($str, $start, $length);
}
}
return utf8_substr($str, $start, $length);
@@ -788,7 +788,7 @@ class e_parse
*/
function html_truncate($text, $length = 100, $ending = '...', $exact = true)
{
if($this->uStrLen(preg_replace('/<.*?>/', '', $text)) <= $length)
if($this->ustrlen(preg_replace('/<.*?>/', '', $text)) <= $length)
{
return $text;
}
@@ -796,9 +796,10 @@ class e_parse
$openTags = array();
$truncate = '';
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
foreach($tags as $tag)
{
if(!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/si', $tag[2]))
if(!$tag[2] || !preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/si', $tag[2]))
{
if(preg_match('/<[\w]+[^>]*>/s', $tag[0]))
{
@@ -814,7 +815,8 @@ class e_parse
}
}
$truncate .= $tag[1];
$contentLength = $this->uStrLen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3]));
$contentLength = $this->ustrlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3]));
if($contentLength + $totalLength > $length)
{
$left = $length - $totalLength;
@@ -826,7 +828,7 @@ class e_parse
if($entity[1] + 1 - $entitiesLength <= $left)
{
$left--;
$entitiesLength += $this->uStrLen($entity[0]);
$entitiesLength += $this->ustrlen($entity[0]);
}
else
{
@@ -834,7 +836,8 @@ class e_parse
}
}
}
$truncate .= $this->uSubStr($tag[3], 0, $left + $entitiesLength);
$truncate .= $this->usubstr($tag[3], 0, $left + $entitiesLength);
break;
}
else
@@ -849,10 +852,10 @@ class e_parse
}
if(!$exact)
{
$spacepos = $this->uStrrPos($truncate, ' ');
$spacepos = $this->ustrrpos($truncate, ' ');
if(isset($spacepos))
{
$bits = $this->uSubStr($truncate, $spacepos);
$bits = $this->usubstr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/i', $bits, $droppedTags, PREG_SET_ORDER);
if(!empty($droppedTags))
{
@@ -864,7 +867,7 @@ class e_parse
}
}
}
$truncate = $this->uSubStr($truncate, 0, $spacepos);
$truncate = $this->usubstr($truncate, 0, $spacepos);
}
}
$truncate .= $ending;

View File

@@ -9,9 +9,9 @@
* Handler - general purpose validation functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/validator_class.php,v $
* $Revision: 1.17 $
* $Date: 2009-11-18 01:04:43 $
* $Author: e107coders $
* $Revision: 1.18 $
* $Date: 2010-01-12 13:11:48 $
* $Author: secretr $
*
*/
@@ -508,7 +508,7 @@ class e_validator
case 'str':
case 'string':
$tmp = explode('-', $cond);
$length = e107::getParser()->uStrLen($value);
$length = e107::getParser()->ustrlen($value);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length)
{
$this->addValidateResult($name, self::ERR_TOO_SHORT);
@@ -843,7 +843,7 @@ class validatorClass
}
$value = $newValue;
}
if (!$errNum && isset($defs['minLength']) && ($tp->uStrLen($value) < $defs['minLength']))
if (!$errNum && isset($defs['minLength']) && ($tp->ustrlen($value) < $defs['minLength']))
{
if ($value == '')
{
@@ -857,7 +857,7 @@ class validatorClass
$errNum = ERR_TOO_SHORT;
}
}
if (!$errNum && isset($defs['maxLength']) && $tp->uStrLen($value) > $defs['maxLength'])
if (!$errNum && isset($defs['maxLength']) && $tp->ustrlen($value) > $defs['maxLength'])
{
if (varsettrue($defs['longtrim']))
{
@@ -878,11 +878,11 @@ class validatorClass
}
if (!$errNum && isset($defs['fixedBlock']))
{
$newValue = $tp->uStrToLower($value);
$newValue = $tp->ustrtolower($value);
$temp = explode(',',$defs['fixedBlock']);
foreach ($temp as $t)
{
if ($newValue == $tp->uStrToLower($t))
if ($newValue == $tp->ustrtolower($t))
{
$errNum = ERR_INVALID_WORD;
break;

View File

@@ -9,9 +9,9 @@
*
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/alt_auth/alt_auth_login_class.php,v $
* $Revision: 1.12 $
* $Date: 2009-11-18 01:05:22 $
* $Author: e107coders $
* $Revision: 1.13 $
* $Date: 2010-01-12 13:11:48 $
* $Author: secretr $
*/
define('AA_DEBUG',FALSE);
@@ -221,16 +221,16 @@ class alt_login
switch ($method)
{
case 'bool1' :
switch ($tp->uStrToUpper($word))
switch ($tp->ustrtoupper($word))
{
case 'TRUE' : return TRUE;
case 'FALSE' : return FALSE;
}
return $word;
case 'ucase' :
return $tp->uStrToUpper($word);
return $tp->ustrtoupper($word);
case 'lcase' :
return $tp->uStrToLower($word);
return $tp->ustrtolower($word);
case 'ucfirst' :
return ucfirst($word); // TODO: Needs changing to utf-8 function
case 'ucwords' :

View File

@@ -9,9 +9,9 @@
* Comment menu shortcodes
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/comment_menu/comment_menu_shortcodes.php,v $
* $Revision: 1.7 $
* $Date: 2009-11-18 01:05:28 $
* $Author: e107coders $
* $Revision: 1.8 $
* $Date: 2010-01-12 13:11:48 $
* $Author: secretr $
*/
if (!defined('e107_INIT')) { exit; }
@@ -72,7 +72,7 @@ $COMMENT = '';
if($menu_pref['comment_characters'] > 0)
{
$COMMENT = strip_tags($tp->toHTML($row['comment_comment'], TRUE, "emotes_off, no_make_clickable", "", e107::getPref('menu_wordwrap')));
if ($tp->uStrLen($COMMENT) > $menu_pref['comment_characters'])
if ($tp->ustrlen($COMMENT) > $menu_pref['comment_characters'])
{
$COMMENT = $tp->text_truncate($COMMENT, $menu_pref['comment_characters'],'').($row['comment_url'] ? " <a href='".$row['comment_url']."'>" : "").defset($menu_pref['comment_postfix'], $menu_pref['comment_postfix']).($row['comment_url'] ? "</a>" : "");
}