api.senddogproto.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * SendDog classic SMS services prototype class
  4. */
  5. class SendDogProto {
  6. /**
  7. * Contains SMS service settings
  8. *
  9. * @var array
  10. */
  11. protected $settings = array();
  12. /**
  13. * System SMS queue object placeholder
  14. *
  15. * @var object
  16. */
  17. protected $smsQueue = '';
  18. /**
  19. * Placeholder for UbillingConfig object
  20. *
  21. * @var null
  22. */
  23. protected $ubConfig = '';
  24. /**
  25. * System message helper object placeholder
  26. *
  27. * @var object
  28. */
  29. protected $messages = '';
  30. const URL_ME = '?module=senddog';
  31. public function __construct($settingsBase) {
  32. $this->initUbConfig();
  33. $this->initMessages();
  34. $this->initSmsQueue();
  35. $this->setBaseSettings($settingsBase);
  36. }
  37. /**
  38. * Clones ubillingConfig object for future usage
  39. *
  40. * @global object $ubillingConfig
  41. *
  42. * @return void
  43. */
  44. protected function initUbConfig() {
  45. global $ubillingConfig;
  46. $this->ubConfig = $ubillingConfig;
  47. }
  48. /**
  49. * Basic settings setter
  50. *
  51. * @param array $settingsBase
  52. *
  53. * @return void
  54. */
  55. protected function setBaseSettings($settingsBase) {
  56. $this->settings = $settingsBase;
  57. }
  58. /**
  59. * Inits system SMS queue object
  60. *
  61. * @return void
  62. */
  63. protected function initSmsQueue() {
  64. $this->smsQueue = new UbillingSMS();
  65. }
  66. /**
  67. * Inits message helper object for further usage
  68. *
  69. * @return void
  70. */
  71. protected function initMessages() {
  72. $this->messages = new UbillingMessageHelper();
  73. }
  74. /**
  75. * Dirty input data filtering
  76. *
  77. * @param $string - string to filter
  78. *
  79. * @return string
  80. */
  81. protected function safeEscapeString($string) {
  82. @$result = preg_replace("#[~@\?\%\/\;=\*\>\<\"\']#Uis", '', $string);
  83. return ($result);
  84. }
  85. /**
  86. * Cuts international codes like "+38", "+7" from phone number
  87. * This function might be supplemented with new country codes and refactored
  88. *
  89. * @param $PhoneNumber
  90. *
  91. * @return bool|mixed|string
  92. */
  93. public static function cutInternationalsFromPhoneNum($PhoneNumber) {
  94. // if we have users phones in DB like "0991234567" and some function/module
  95. // appended "+38" or "+7" to the beginning of it and if we need to remove that prefix
  96. // for MYSQL "LIKE" to search properly
  97. $PhoneNumber = str_replace(array('+7', '+38', '+'), '', $PhoneNumber);
  98. // sometimes phone number may be stored without leading "+"
  99. // and we still need to remove international codes
  100. $Prefix = '38';
  101. if (substr($PhoneNumber, 0, strlen($Prefix)) == $Prefix) {
  102. $PhoneNumber = substr($PhoneNumber, strlen($Prefix));
  103. }
  104. $Prefix = '7';
  105. if (substr($PhoneNumber, 0, strlen($Prefix)) == $Prefix) {
  106. $PhoneNumber = substr($PhoneNumber, strlen($Prefix));
  107. }
  108. return $PhoneNumber;
  109. }
  110. }