smspilot.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class smspilot extends SendDogProto {
  3. /**
  4. * Returns set of inputs, required for SMSPILOT configuration
  5. *
  6. * @return string
  7. */
  8. public function renderSmsPilotConfigInputs() {
  9. $inputs = wf_tag('h2') . __('SMSPILOT') . ' ' . wf_Link(self::URL_ME . '&showmisc=smspilot', wf_img_sized('skins/icon_dollar.gif', __('Balance'), '10', '10'), true) . wf_tag('h2', true);
  10. $inputs .= wf_TextInput('editsmspilotapikey', __('User API key for access SMSPILOT API'), $this->settings['SMSPILOT_APIKEY'], true, 20);
  11. $inputs .= wf_TextInput('editsmspilotsign', __('SMSPILOT') . ' ' . __('Sign') . ' (' . __('Alphaname') . ')', $this->settings['SMSPILOT_SIGN'], true, 20);
  12. $smsServiceFlag = $this->settings['SMS_SERVICE'] === 'smspilot';
  13. $inputs .= wf_RadioInput('defaultsmsservice', __('Use SMSPILOT as default SMS service'), 'smspilot', true, $smsServiceFlag);
  14. return $inputs;
  15. }
  16. /**
  17. * Loads SMSPILOT.RU service config
  18. *
  19. * @return void
  20. */
  21. public function loadSmsPilotConfig() {
  22. $smsapikey = zb_StorageGet('SENDDOG_SMSPILOT_APIKEY');
  23. if (empty($smsapikey)) {
  24. $smsapikey = 'XXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZ';
  25. zb_StorageSet('SENDDOG_SMSPILOT_APIKEY', $smsapikey);
  26. }
  27. $smssign = zb_StorageGet('SENDDOG_SMSPILOT_SIGN');
  28. $this->settings['SMSPILOT_APIKEY'] = $smsapikey;
  29. $this->settings['SMSPILOT_SIGN'] = $smssign;
  30. }
  31. /**
  32. * Sends all sms storage via SMSPILOT.RU service
  33. *
  34. * @return void
  35. */
  36. public function smspilotPushMessages() {
  37. $apikey = $this->settings['SMSPILOT_APIKEY'];
  38. $sender = $this->settings['SMSPILOT_SIGN'];
  39. $allSmsQueue = $this->smsQueue->getQueueData();
  40. if (!empty($allSmsQueue)) {
  41. foreach ($allSmsQueue as $sms) {
  42. $url = 'http://smspilot.ru/api.php'
  43. . '?send=' . urlencode($sms['message'])
  44. . '&to=' . urlencode($sms['number'])
  45. . '&from=' . urlencode($sender)
  46. . '&apikey=' . urlencode($apikey)
  47. . '&format=json';
  48. $ch = curl_init($url);
  49. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  50. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  52. $json = curl_exec($ch);
  53. curl_close($ch);
  54. $j = json_decode($json);
  55. if ($j && isset($j->error)) {
  56. trigger_error($j->description_ru, E_USER_WARNING);
  57. }
  58. //remove old sent message
  59. $this->smsQueue->deleteSms($sms['filename']);
  60. }
  61. }
  62. }
  63. /**
  64. * Renders SMSPILOT user balance
  65. *
  66. * @return string
  67. */
  68. public function renderSMSPILOTBalance() {
  69. $balance = file_get_contents('http://smspilot.ru/api.php'
  70. . '?balance=rur'
  71. . '&apikey=' . $this->settings['SMSPILOT_APIKEY']
  72. );
  73. $result = wf_BackLink(self::URL_ME, '', true);
  74. $result .= $this->messages->getStyledMessage(__('Current account balance') . ': ' . $balance . ' RUR', 'info');
  75. return $result;
  76. }
  77. /**
  78. * Saves service settings to database
  79. *
  80. * @return void
  81. */
  82. public function saveSettings() {
  83. //SMSPILOT configuration
  84. if ($_POST['editsmspilotapikey'] != $this->settings['SMSPILOT_APIKEY']) {
  85. zb_StorageSet('SENDDOG_SMSPILOT_APIKEY', $_POST['editsmspilotapikey']);
  86. log_register('SENDDOG CONFIG SET SMSPILOT_APIKEY `' . $_POST['editsmspilotapikey'] . '`');
  87. }
  88. if ($_POST['editsmspilotsign'] != $this->settings['SMSPILOT_SIGN']) {
  89. zb_StorageSet('SENDDOG_SMSPILOT_SIGN', $_POST['editsmspilotsign']);
  90. log_register('SENDDOG CONFIG SET SMSPILOT_SIGN `' . $_POST['editsmspilotsign'] . '`');
  91. }
  92. }
  93. }