Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/Handlers
File: LocaleNumberFormatting.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class NF_Handlers_LocaleNumberFormatting
[2] Fix | Delete
{
[3] Fix | Delete
const NBSP = '&nbsp;';
[4] Fix | Delete
[5] Fix | Delete
protected $locale;
[6] Fix | Delete
[7] Fix | Delete
public function __construct($locale) {
[8] Fix | Delete
$this->locale = $locale;
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
public static function create() {
[12] Fix | Delete
global $wp_locale;
[13] Fix | Delete
return new self($wp_locale);
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
public function locale_decode_number( $number ) {
[17] Fix | Delete
// Be sure we have a string.
[18] Fix | Delete
$number = strval( $number );
[19] Fix | Delete
[20] Fix | Delete
$thousands_sep = $this->locale->number_format['thousands_sep'];
[21] Fix | Delete
[22] Fix | Delete
// Account for negative numbers.
[23] Fix | Delete
$negative = false;
[24] Fix | Delete
if ( '-' == substr( $number, 0, 1 ) ) {
[25] Fix | Delete
$negative = true;
[26] Fix | Delete
$number = str_replace( '-', '', $number );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
// Account for a space as the thousands separator.
[30] Fix | Delete
$thousands_sep = str_replace( self::NBSP, ' ', $thousands_sep );
[31] Fix | Delete
$number = str_replace( self::NBSP, ' ', $number );
[32] Fix | Delete
[33] Fix | Delete
// Determine what our existing separators are.
[34] Fix | Delete
$haystack = str_split( $number );
[35] Fix | Delete
$separators = preg_grep( '/[0-9]/', $haystack, PREG_GREP_INVERT );
[36] Fix | Delete
$final_separators = array_unique( $separators );
[37] Fix | Delete
$final_separators = array_values( $final_separators );
[38] Fix | Delete
switch( count( $final_separators ) ) {
[39] Fix | Delete
case 0:
[40] Fix | Delete
$formatted = $number;
[41] Fix | Delete
break;
[42] Fix | Delete
case 1:
[43] Fix | Delete
$replacer = '';
[44] Fix | Delete
if ( 1 == count( $separators ) ) {
[45] Fix | Delete
$separator = reset($separators);
[46] Fix | Delete
list($before, $after) = explode($separator, $number);
[47] Fix | Delete
[48] Fix | Delete
if(3 == strlen($after) && $separator == $thousands_sep) {
[49] Fix | Delete
$replacer = '';
[50] Fix | Delete
} else {
[51] Fix | Delete
$replacer = '.';
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
$formatted = str_replace( $final_separators[0], $replacer, $number );
[55] Fix | Delete
break;
[56] Fix | Delete
case 2:
[57] Fix | Delete
$formatted = str_replace( $final_separators[0], '', $number );
[58] Fix | Delete
$formatted = str_replace( $final_separators[1], '.', $formatted );
[59] Fix | Delete
break;
[60] Fix | Delete
default:
[61] Fix | Delete
return 'NaN';
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
if ( $negative ) {
[65] Fix | Delete
$formatted = '-' . $formatted;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return $formatted;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
public function locale_encode_number( $number, $decimal = null, $thousand = null ) {
[72] Fix | Delete
// Be sure we have a string.
[73] Fix | Delete
$number = strval( $number );
[74] Fix | Delete
// Decode our input value.
[75] Fix | Delete
$number = $this->locale_decode_number( $number );
[76] Fix | Delete
// Exit early if NaN.
[77] Fix | Delete
if ( 'NaN' == $number ) return 'NaN';
[78] Fix | Delete
[79] Fix | Delete
$thousands_sep = $this->locale->number_format['thousands_sep'];
[80] Fix | Delete
$decimal_point = $this->locale->number_format['decimal_point'];
[81] Fix | Delete
[82] Fix | Delete
$thousands_sep = ( !is_null($thousand) ) ? $thousand : $thousands_sep;
[83] Fix | Delete
$decimal_point = ( !is_null($decimal) ) ? $decimal : $decimal_point;
[84] Fix | Delete
[85] Fix | Delete
// Account for a space as the thousands separator.
[86] Fix | Delete
$thousands_sep = str_replace( ' ', self::NBSP, $thousands_sep );
[87] Fix | Delete
[88] Fix | Delete
$precision = 0;
[89] Fix | Delete
if ( false !== strpos( $number, '.' ) ) {
[90] Fix | Delete
$tmp = explode( '.', $number );
[91] Fix | Delete
$precision = strlen( array_pop( $tmp ) );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
$number = floatval( $number );
[95] Fix | Delete
[96] Fix | Delete
return number_format( $number, $precision, $decimal_point, $thousands_sep );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
public function locale_decode_equation( $eq ) {
[100] Fix | Delete
// Be sure we have a string.
[101] Fix | Delete
$eq = strval( $eq );
[102] Fix | Delete
$result = '';
[103] Fix | Delete
$expression = '';
[104] Fix | Delete
$pattern = '/[0-9.,]/';
[105] Fix | Delete
$eq = str_replace( array('&nbsp;', '&thinsp;', ' '), '', $eq );
[106] Fix | Delete
$characters = str_split( $eq );
[107] Fix | Delete
foreach ( $characters as $character ) {
[108] Fix | Delete
// If it matches the pattern...
[109] Fix | Delete
if ( preg_match( $pattern, $character ) ) {
[110] Fix | Delete
$expression .= $character;
[111] Fix | Delete
} else {
[112] Fix | Delete
// If we reach an operator char, append the expression to the result
[113] Fix | Delete
if ( 0 < strlen( $expression ) ) {
[114] Fix | Delete
$result .= $this->locale_decode_number( $expression );
[115] Fix | Delete
$expression = '';
[116] Fix | Delete
}
[117] Fix | Delete
$result .= $character;
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
// The following catches the case of the last character being a digit.
[121] Fix | Delete
if ( 0 < strlen( $expression ) ) {
[122] Fix | Delete
$result .= $this->locale_decode_number( $expression );
[123] Fix | Delete
}
[124] Fix | Delete
return $result;
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function