WYSIJA_help_numbers

The MailPoet Newsletters WYSIJA help numbers class.

Defined (1)

The class is defined in the following location(s).

/helpers/numbers.php  
  1. class WYSIJA_help_numbers extends WYSIJA_object{ 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. function format_number($int) { 
  7. // strip any commas 
  8. $int = (int)(0 + str_replace(', ', '', $int)); 
  9.  
  10. // make sure it's a number... 
  11. if(!is_numeric($int)) { return false;} 
  12.  
  13. // filter and format it 
  14. if($int>1000000000000) { 
  15. return round(($int/1000000000000), 2).' trillion'; 
  16. }elseif($int>1000000000) { 
  17. return round(($int/1000000000), 2).' billion'; 
  18. }elseif($int>1000000) { 
  19. return round(($int/1000000), 2).' million'; 
  20. }elseif($int>1000) { 
  21. return round(($int/1000), 2).' thousand'; 
  22.  
  23. return number_format($int); 
  24.  
  25. /** 
  26. * Calculate percetage of $a, based $b; and round down 
  27. * @param mixed $a 
  28. * @param mixed $b 
  29. * @param type $decimal_number 
  30. * @return real 
  31. */ 
  32. function calculate_percetage($a, $b, $decimal_number = 2) { 
  33. // cast values to float 
  34. $a = (float)$a; 
  35. $b = (float)$b; 
  36.  
  37. if($b === 0.0) { 
  38. return 0; 
  39. } else { 
  40. return round(($a / $b) * 100, $decimal_number); 
  41.  
  42. function get_max_file_upload() { 
  43. if(defined('HHVM_VERSION')) { 
  44. $u_bytes = ini_get('hhvm.server.upload.upload_max_file_size'); 
  45. $p_bytes = ini_get('hhvm.server.max_post_size'); 
  46. } else { 
  47. $u_bytes = ini_get('upload_max_filesize'); 
  48. $p_bytes = ini_get('post_max_size'); 
  49. // uniform bytes 
  50. $u_bytes = $this->return_bytes($u_bytes); 
  51. $p_bytes = $this->return_bytes($p_bytes); 
  52.  
  53. $data=array(); 
  54.  
  55. $data['maxbytes'] = min($u_bytes, $p_bytes); 
  56. $data['maxmegas'] = $this->return_megas(apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes )); 
  57. $data['maxchars'] = (int)floor(($p_bytes*1024*1024)/200); 
  58. return $data; 
  59.  
  60. function return_megas($size_bytes) { 
  61. return ($size_bytes / 1024 / 1024) . 'M'; 
  62.  
  63. function return_bytes($size_str) 
  64. switch (substr ($size_str, -1)) 
  65. case 'M': case 'm': return (int)$size_str * 1048576; 
  66. case 'K': case 'k': return (int)$size_str * 1024; 
  67. case 'G': case 'g': return (int)$size_str * 1073741824; 
  68. default: return $size_str; 
  69.