WJ_Utils

Wysija Premium Utils.

Defined (1)

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

/classes/WJ_Utils.php  
  1. class WJ_Utils { 
  2.  
  3. private function __construct() {} 
  4.  
  5. public static function to_int( $value ) { 
  6. $boolean = (bool) $value; 
  7. if ( $boolean ) { 
  8. $int = 1; 
  9. } else { 
  10. $int = 0; 
  11. return $int; 
  12.  
  13. public static function to_bool( $value ) { 
  14. $int = (int) $value; 
  15. if ( $int == 0 ) { 
  16. $boolean = false; 
  17. } else { 
  18. $boolean = true; 
  19. return $boolean; 
  20.  
  21. /** 
  22. * Retuns plain domain name. 
  23. * @return string $domain 
  24. */ 
  25. public static function get_domain() { 
  26. if ( isset($_SERVER['SERVER_NAME'] ) && strlen( trim( $_SERVER['SERVER_NAME'] ) ) > 0 ) { 
  27. $domain = strtolower( $_SERVER['SERVER_NAME'] ); 
  28. } else { 
  29. $domain = preg_replace( '@http[s]?:\/\/@', '', get_site_url() ); 
  30.  
  31. return preg_replace( '@^www\.@', '', $domain ); 
  32.  
  33. /** 
  34. * Reruns necessary data for tooltip. 
  35. * @return array $data 
  36. */ 
  37. public static function get_tip_data() { 
  38. $model_config = WYSIJA::get( 'config', 'model' ); 
  39. $is_gmail = 'false'; 
  40.  
  41. if ( 'gmail' === $model_config->getValue( 'sending_method' ) ) { 
  42. $is_gmail = 'true'; 
  43.  
  44. $data = array( 
  45. 'text' => sprintf( __( 'Use an email from your domain, like <strong>info@%s</strong> to avoid the spam folder, or even be blocked.', WYSIJA ), self::get_domain() ),  
  46. 'gmailText' => sprintf( __( 'If you want to use a Gmail address, you need to send with Gmail. Check <a id="tip-send-with" href="%s">sending settings</a>.', WYSIJA ), admin_url( 'admin.php?page=wysija_config#tab-sendingmethod' ) ),  
  47. 'domain' => self::get_domain(),  
  48. 'isGmail' => $is_gmail,  
  49. ); 
  50.  
  51. return $data; 
  52.  
  53. public static function esc_json_attr( $json ) { 
  54. $search = array( 
  55. '\"',  
  56. '\'',  
  57. '<',  
  58. '>',  
  59. '&',  
  60. ); 
  61. $replace = array( 
  62. '\\u0022',  
  63. '\\u0027',  
  64. '\\u003C',  
  65. '\\u003E',  
  66. '\\u0026',  
  67. ); 
  68.  
  69. return str_replace( $search, $replace, json_encode( $json ) ); 
  70.