function test_convertFromBase() { $check_str = "12345678900987654321"; $base_16_chars = '0123456789abcdef'; $base_62_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $base_16_str = "ab54a98cdc6770b1"; $base_62_str = "eHZl6hFR4k1"; $result = FOX_math::convertFromBase($base_16_str, $base_16_chars); $this->assertEquals($result, $check_str); $result = FOX_math::convertFromBase($base_62_str, $base_62_chars); $this->assertEquals($result, $check_str); }
/** * Converts a size stored in an ini var in bytes * * @version 1.0 * @since 1.0 * * @param $varname ini var name * @return int size in bytes */ public static function ini_get_bytes($varname) { $val = ini_get($varname); $result = FOX_math::formattedSizeToBytes($val); return $result; }
function test_format_num() { $test_data = array(array('test' => 1000, 'result' => '1,000'), array('test' => 1000.1, 'result' => '1,000.1'), array('test' => 1000.12, 'result' => '1,000.12'), array('test' => 1000.123, 'result' => '1,000.123'), array('test' => 123456789.123, 'result' => '123,456,789.123')); foreach ($test_data as $test) { $this->assertEquals($test['result'], FOX_math::formatNum($test['test'])); } unset($test); }
/** * Renders the meta block within an media item * * @version 1.0 * @since 1.0 * * @param array $args | Control args * @param array $item | Item instance */ function renderMeta($args, $item) { $meta_width = $args["margin"]; $result = ""; foreach ($args["fields"] as $data) { if (array_key_exists($data["name"], $item["meta"]) && $meta_width < $item["mask_x"]) { $result .= '<img '; $result .= 'src="' . $this->meta[$data["name"]]["icon"] . '" '; $result .= 'alt="' . $this->meta[$data["name"]]["title"] . '"'; $result .= 'title="' . $this->meta[$data["name"]]["title"] . '" '; $result .= 'style="position:relative" '; $result .= '/>'; $result .= '<div class="text">'; $result .= FOX_math::siFormat($item["meta"][$data["name"]], $precision, true); $result .= '</div>'; } $meta_width += $args["block_width"]; } return $result; }
/** * Writes a multiple raw strings to the store * * @version 1.0 * @since 1.0 * * @param mixed $value | single value * @return bool | Exception on failure. Array of prefixed hash keys on success. */ public function setMulti($data) { $result = array(); foreach ($data as $value) { // Values MUST be serialized to prevent (int)0, (bool)false, and // NULL from all mapping to the same key $s_value = serialize($value); // Converting from base_16 to base_62 format reduces the key length // by almost 50%, saving memory $hash_16 = md5($s_value); $hash_10 = FOX_math::convertFromBase($hash_16, $this->base_16_chars); $hash_62 = FOX_math::convertToBase($hash_10, $this->base_62_chars); // We add $this-prefix to each key to guarantee the key is still // a string in the event we get something like "0000000000000005" // back from convertToBase(). If we passed the value straight // through, PHP would set the 6th key in the array instead of the // named key "0000000000000005". $prefixed = $this->prefix . $hash_62; $this->store[$prefixed] = $s_value; $result[] = $prefixed; } unset($value); // We can't return as an array of $value => $hash because // its entirely possible we'll get things like "foo text string" // which isn't a valid associative array key return $result; }