PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/reg/smscoin_reg/smscoin_reg.php

https://bitbucket.org/smscoin/wordpress
PHP | 694 lines | 538 code | 57 blank | 99 comment | 81 complexity | 01f50201e8ad3c92ae090c76ebecda01 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: SMSCOIN R-REG
  4. Plugin URI: http://smscoin.com/software/engine/WordPress/
  5. Description: Плагин платной регистрации.
  6. Version: 1.2
  7. Author: SMSCOIN.COM
  8. Author URI: http://smscoin.com/
  9. */
  10. /* Copyright 2009 SMSCOIN */
  11. ###
  12. # Add events
  13. # Подключение событий
  14. ###
  15. add_action('activate_smscoin_reg/smscoin_reg.php', 'smscoin_reg_activation');
  16. add_action('deactivate_smscoin_reg/smscoin_reg.php', 'smscoin_reg_deactivation');
  17. add_action('smscoin_reg_cron', 'smscoin_reg_tariffs_cron');
  18. add_action('admin_menu', 'smscoin_reg_add_pages');
  19. add_action('register_form', 'smscoin_add_signup_fields',1);
  20. add_filter( 'registration_errors', 'smscoin_validate_signup_fields');
  21. add_filter( 'user_register', 'smscoin_on_activate_user');
  22. ###
  23. # Localization
  24. # Подключение локализации
  25. ###
  26. $currentLocale = get_locale();
  27. if(!empty($currentLocale)) {
  28. $moFile = dirname(__FILE__) . "/lang/smscoin_reg-" . $currentLocale . ".mo";
  29. if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('smscoin_reg', $moFile);
  30. }
  31. ###
  32. # Create paid form
  33. # Функция сборки инструкций по отправке смс
  34. ###
  35. function smscoin_add_signup_fields() {
  36. $key_id = get_option('smscoin_reg_key_id');
  37. $response .=
  38. __('<h3>If you have already received the password, enter it here:</h3>','smscoin_reg')
  39. .'<input name="s_pair" type="text" value="'.addslashes($_REQUEST['s_pair']).'" />'
  40. .__('<h3>To receive your password please send an sms</h3>','smscoin_reg'). smscoin_reg_add_script().''.smscoin_reg_instruction($key_id).'<br /><br />';
  41. echo $response;
  42. }
  43. ###
  44. # Check password
  45. # Функция проверки пароля
  46. ###
  47. function smscoin_validate_signup_fields( $result ) {
  48. if (isset($_REQUEST['s_pair']) && $_REQUEST['s_pair'] !='' && strlen($_REQUEST['s_pair'])<=10) {
  49. $key_id = get_option('smscoin_reg_key_id');
  50. $flag = do_reg_local_check ($key_id, addslashes($_REQUEST['s_pair']));
  51. }
  52. if ($flag != 1) {
  53. $result->errors['wrong_code'] = array("<b>ERROR:</b> Wrong code.");
  54. } else {
  55. $_SESSION['invite_code'] = $_REQUEST['s_pair'];
  56. }
  57. return $result;
  58. }
  59. ###
  60. # User activation
  61. # Функция активации пользователя
  62. ###
  63. function smscoin_on_activate_user( $user_id, $password='', $meta='') {
  64. global $wpdb, $table_prefix;
  65. $key_id = get_option('smscoin_reg_key_id');
  66. #delete pass
  67. $sql = 'UPDATE `'.$table_prefix.'rkeys` SET `k_status` = 0 WHERE `k_key`="'.$key_id.'" AND `k_pair` = "'.$_SESSION['invite_code'].'"';
  68. $wpdb->query($sql);
  69. echo mysql_error();
  70. }
  71. ###
  72. # Activate cron
  73. # Функция активации крона
  74. ###
  75. function smscoin_reg_activation() {
  76. wp_schedule_event(time(), 'hourly', 'smscoin_reg_cron');
  77. smscoin_reg_create_table();
  78. }
  79. ###
  80. # Deactivate cron
  81. # Функция деактивации крона
  82. ###
  83. function smscoin_reg_deactivation() {
  84. global $wpdb,$table_prefix;
  85. $table_name = $table_prefix . 'rkeys';
  86. wp_clear_scheduled_hook('smscoin_reg_cron');
  87. $wpdb->query("DROP TABLE `".$table_name."`");
  88. }
  89. ###
  90. # Add js
  91. # Функция создания скрипта
  92. ###
  93. function smscoin_reg_add_script() {
  94. $wpurl = get_bloginfo('wpurl');
  95. $key_id = intval(get_option('smscoin_reg_key_id'));
  96. $str = '
  97. <link rel="stylesheet" href="'.$wpurl.'/wp-content/plugins/smscoin_reg/viewer.css" type="text/css" />
  98. <script src="'.$wpurl.'/wp-content/plugins/smscoin_reg/dropdown.js" type="text/javascript"></script>
  99. <script type="text/javascript">
  100. var JSON_URL = "'.$wpurl.'/wp-content/plugins/smscoin_reg/data/local.js'.'"
  101. var SERVICE = "'.$key_id.'";
  102. var SELECT_PROVIDER = "'.__('Select Provider','smscoin_rkey').'";
  103. var INCLUDING_VAT = "'.__('including VAT','smscoin_rkey').'";
  104. var WITHOUT_VAT = "'.__('without VAT','smscoin_rkey').'";
  105. </script>
  106. <script type="text/javascript">
  107. //<![CDATA[
  108. function hideAll() {
  109. var allDivs = document.getElementsByTagName(\'div\');
  110. for (var div in allDivs) {
  111. if (belongsToClass(allDivs[div], \'div_sms\')) {
  112. allDivs[div].style.display = \'none\';
  113. }
  114. }
  115. }
  116. //]]>
  117. </script>';
  118. echo $str;
  119. }
  120. ###
  121. # Create table
  122. # Функция создания таблицы
  123. ###
  124. function smscoin_reg_create_table() {
  125. global $wpdb,$table_prefix;
  126. $table_name = $table_prefix . 'rkeys';
  127. if($wpdb->get_var(" SHOW TABLES LIKE `".$table_name."` ") != $table_name) {
  128. $sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
  129. `k_status` tinyint(1) unsigned NOT NULL default '0',
  130. `k_key` int(10) unsigned NOT NULL default '0',
  131. `k_pair` varchar(16) character set utf8 NOT NULL,
  132. `k_country` varchar(2) character set utf8 NOT NULL,
  133. `k_provider` varchar(64) character set utf8 NOT NULL,
  134. `k_text` varchar(255) character set utf8 NOT NULL,
  135. `k_cost_local` decimal(6,2) NOT NULL,
  136. `k_created` int(10) unsigned NOT NULL default '0',
  137. `k_timeout` int(10) unsigned NOT NULL default '0',
  138. `k_limit_start` int(10) unsigned NOT NULL default '0',
  139. `k_limit_current` int(10) unsigned NOT NULL default '0',
  140. `k_first_access` int(10) unsigned NOT NULL default '0',
  141. `k_first_ip` varchar(32) character set utf8 NOT NULL,
  142. `k_first_from` varchar(255) character set utf8 NOT NULL,
  143. UNIQUE KEY `k_key` (`k_key`,`k_pair`)
  144. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
  145. $wpdb->query($sql);
  146. }
  147. }
  148. ###
  149. # Create Page
  150. # Функция создания страницы
  151. ###
  152. function smscoin_reg_add_pages() {
  153. if (function_exists('add_menu_page')) {
  154. add_menu_page('SmsCoin R-REG', 'SmsCoin R-REG', 8, __FILE__, 'smscoin_reg_list', plugins_url('smscoin_reg/images/dot.png'));
  155. }
  156. if (function_exists('add_submenu_page')) {
  157. add_submenu_page(__FILE__, 'List2', __('List','smscoin_reg'), 8, __FILE__, 'smscoin_reg_list');
  158. add_submenu_page(__FILE__, 'Tarifs2', __('Tarifs','smscoin_reg'), 8, 'Tarifs2', 'smscoin_reg_tariffs');
  159. add_submenu_page(__FILE__, 'Settings2', __('Settings','smscoin_reg'), 8, 'Settings2', 'smscoin_reg_settings_page');
  160. }
  161. }
  162. ###
  163. # Pagination
  164. # Функция создания номеров ссылок
  165. ###
  166. function smscoin_reg_paging($sms_num_row,$rpp) {
  167. $ii=0;
  168. if($sms_num_row == 0) return '';
  169. $ret_str = '<div>'.__('Pages : ','smscoin_reg').' ';
  170. while( $sms_num_row>0 ) {
  171. $GP = $_GET+$_POST;
  172. unset($GP['sms_page']);
  173. unset($GP['page']);
  174. unset($GP['del']);
  175. unset($GP['edit']);
  176. $ret_str .= '<a href="admin.php?page=smscoin_reg/smscoin_reg.php&amp;sms_page='.($ii+1).'&amp;'.http_build_query($GP).'">['.($ii+1).']</a> ';
  177. $sms_num_row -= $rpp;
  178. $ii++;
  179. }
  180. return $ret_str.'</div>';
  181. }
  182. ###
  183. # Statistics
  184. # Функция создания страницы статистики паролей
  185. ###
  186. function smscoin_reg_list($key_id) {
  187. global $wpdb, $table_prefix;
  188. $str = '';
  189. $table_name = $table_prefix . 'rkeys';
  190. $str .= '<h1>'.__('List received sms','smscoin_reg').'</h1>';
  191. $smscoin_keys = array();
  192. if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'") == $table_name) {
  193. # Table created
  194. # Таблица создана
  195. if(isset($_POST['action']) && trim($_POST['action']) == 'add') {
  196. # Чтение параметров
  197. $key = intval($_POST["key"]);
  198. $pair = $_POST["pair"];
  199. $timeout = intval($_POST["timeout"]);
  200. $limit = intval($_POST["limit"]);
  201. $content = $_POST["content"];
  202. $country = $_POST["country"];
  203. $cost_local = $_POST["cost_local"];
  204. $provider = $_POST["provider"];
  205. # Store row
  206. # Запись строки в базу данных
  207. $fields = "1, ".addslashes($key).", '".addslashes($pair)."','".addslashes($country)."', '".addslashes($provider)."', '".addslashes($content)."', '".addslashes($cost_local)."',
  208. ".addslashes(time()).", ".intval($timeout).", ".intval($limit).", ".intval($limit);
  209. $wpdb->query("INSERT INTO ".$table_name." (k_status, k_key, k_pair, k_country, k_provider, k_text, k_cost_local, k_created, k_timeout, k_limit_start, k_limit_current)
  210. VALUES (".$fields.");
  211. ");
  212. unset($_REQUEST['action']);
  213. }
  214. if( isset($_REQUEST['del']) ) {
  215. # Delete row
  216. # Удаление записи
  217. $wpdb->query("DELETE FROM ".$table_name." WHERE k_pair='".addslashes($_REQUEST['k_pair'])."';");
  218. $LastAction = '<h3>'. sprintf(__('Password %s was deleted!', 'smscoin_reg'), $_REQUEST['k_pair']).' .</h3> ';
  219. unset($_REQUEST['del']);
  220. }
  221. if( isset($_REQUEST['edit']) ) {
  222. # Change row
  223. # Изменение записи
  224. $wpdb->query("UPDATE ".$table_name." SET
  225. k_timeout='".intval($_REQUEST['k_timeout'])."' ,
  226. k_limit_start='".intval($_REQUEST['k_limit_start'])."' ,
  227. k_limit_current='".intval($_REQUEST['k_limit_current'])."'
  228. WHERE k_pair='".addslashes($_REQUEST['k_pair'])."';");
  229. $LastAction = '<h3>'. sprintf(__('Password %s parameters was changed!', 'smscoin_reg'), $_REQUEST['k_pair']) . '</h3> ';
  230. unset($_REQUEST['edit']);
  231. }
  232. if( !isset($_REQUEST['rpp']) ) {
  233. $rpp = 5;
  234. } else {
  235. $rpp = intval($_REQUEST['rpp']);
  236. }
  237. $str .= '
  238. <style type="text/css">
  239. p, li, th, td {
  240. font-size: 9pt;
  241. }
  242. .list_table {
  243. width: 100%;
  244. }
  245. .list_table tr {
  246. background: #ffffff;
  247. color: inherit;
  248. }
  249. .list_table tr.row_0 {
  250. background: #f9f9f9;
  251. color: inherit;
  252. }
  253. .list_table tr.row_1 {
  254. background: #efefff;
  255. color: inherit;
  256. }
  257. .list_table th {
  258. background: #f1f1f1;
  259. color: #033;
  260. padding: 2px;
  261. text-align: center;
  262. border-bottom: 1px #777 solid;
  263. }
  264. .list_table td {
  265. padding: 1px;
  266. text-align: center;
  267. }
  268. .list_table input {
  269. width: auto;
  270. }
  271. .list_table th input {
  272. width: 100%;
  273. }
  274. </style>
  275. <div><h3>'.__('Manually add a password:','smscoin_reg').'</h3></div>
  276. <table class="list_table">
  277. <tr>
  278. <th>'.__('Key','smscoin_reg').'</th>
  279. <th>'.__('Password','smscoin_reg').'</th>
  280. <th>'.__('Country','smscoin_reg').'</th>
  281. <th>'.__('Provider','smscoin_reg').'</th>
  282. <th>'.__('Text','smscoin_reg').'</th>
  283. <th>'.__('Cost','smscoin_reg').'</th>
  284. <th>'.__('Time','smscoin_reg').'</th>
  285. <th>'.__('Limit','smscoin_reg').'</th>
  286. <th></th>
  287. </tr>
  288. <tr>
  289. <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post">
  290. <th><input name="key" type="text" size="5" value="" /></th>
  291. <th><input name="pair" type="text" size="4" value="" /></th>
  292. <th><input name="country" type="text" size="5" value="" /></th>
  293. <th><input name="provider" type="text" size="5" value="" /></th>
  294. <th><input name="text" type="text" size="10" value="" /></th>
  295. <th><input name="cost_local" type="text" size="5" value="" /></th>
  296. <th><input name="timeout" type="text" size="5" value="" /></th>
  297. <th><input name="limit" type="text" size="5" value="" /></th>
  298. <th><input name="action" type="hidden" value="add" />
  299. <input class="btn" type="submit" name="add" value="'.__('Add Password','smscoin_reg').'" /></th>
  300. </form>
  301. </tr>
  302. </table>
  303. <hr />
  304. <div><h3>'.__('List recived sms','smscoin_reg').'</h3></div>
  305. <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post">
  306. <div>
  307. '.__('Items per page','smscoin_reg').'<input name="rpp" type="text" size="5" value="'.$rpp.'" />
  308. <input class="btn" type="submit" name="find" value="'.__('Show','smscoin_reg').'" />
  309. </div>';
  310. $where = array();
  311. $order = "k_created";
  312. # Create query
  313. # Создание запроса
  314. if (isset($_REQUEST['key']) && $_REQUEST['key']!='') {
  315. $where[] = "k_key='".intval($_REQUEST['key'])."'";
  316. }
  317. if (isset($_REQUEST['pair']) && $_REQUEST['pair']!='') {
  318. $where[] = "k_pair='".addslashes($_REQUEST['pair'])."'";
  319. }
  320. if (isset($_REQUEST['timeout']) && $_REQUEST['timeout']!='') {
  321. $where[] = "k_timeout='".intval($_REQUEST['timeout'])."'";
  322. }
  323. if (isset($_REQUEST['limit']) && $_REQUEST['limit']!='') {
  324. $where[] = "k_limit_start='".intval($_REQUEST['limit'])."'";
  325. }
  326. if (isset($_REQUEST['ip']) && $_REQUEST['ip']!='') {
  327. $where[] = "k_first_ip='".addslashes($_REQUEST['ip'])."'";
  328. }
  329. if (isset($_REQUEST['provider']) && $_REQUEST['provider']!='') {
  330. $where[] = "k_provider LIKE '%".addslashes($_REQUEST['provider'])."%'";
  331. }
  332. if (isset($_REQUEST['country']) && $_REQUEST['country']!='') {
  333. $where[] = "k_country='".addslashes($_REQUEST['country'])."'";
  334. }
  335. if (isset($_REQUEST['text']) && $_REQUEST['text']!='') {
  336. $where[] = "k_text LIKE '%".addslashes($_REQUEST['text'])."%'";
  337. }
  338. if(isset($_REQUEST['sms_page']) && $_REQUEST['sms_page']!='') {
  339. $page = intval($_REQUEST['sms_page']);
  340. } else {
  341. $page = 1;
  342. }
  343. $offset = ($page-1)*$rpp;
  344. $result = $wpdb->get_row("SELECT count(*) AS num_row FROM ".$table_name."
  345. ".(count($where) > 0 ? " WHERE ".implode(" AND ", $where) : "")."", ARRAY_A );
  346. $sms_num_row = intval($result['num_row']);
  347. $str .= smscoin_reg_paging($sms_num_row, $rpp);
  348. $str .= '<table class="list_table">
  349. <tr>
  350. <th>'.__('Key','smscoin_reg').'</th>
  351. <th>'.__('Password','smscoin_reg').'</th>
  352. <th>'.__('Country','smscoin_reg').'</th>
  353. <th>'.__('Provider','smscoin_reg').'</th>
  354. <th>'.__('Text','smscoin_reg').'</th>
  355. <th>'.__('Cost','smscoin_reg').'</th>
  356. <th>'.__('Added','smscoin_reg').'</th>
  357. <th>'.__('Time','smscoin_reg').'</th>
  358. <th>'.__('Limit','smscoin_reg').'</th>
  359. <th>'.__('Show','smscoin_reg').'</th>
  360. <th>'.__('First enter','smscoin_reg').'</th>
  361. <th>IP</th>
  362. <th>'.__('Options','smscoin_reg').'</th>
  363. </tr>
  364. <tr>
  365. <th><input name="key" type="text" size="5" value="'.$_REQUEST['key'].'" /></th>
  366. <th><input name="pair" type="text" size="7" value="'.$_REQUEST['pair'].'" /></th>
  367. <th><input name="country" type="text" size="5" value="'.$_REQUEST['country'].'" /></th>
  368. <th><input name="provider" type="text" size="5" value="'.$_REQUEST['provider'].'" /></th>
  369. <th><input name="text" type="text" size="10" value="'.$_REQUEST['text'].'" /></th>
  370. <th><input name="cost_local" type="text" size="5" value="'.$_REQUEST['cost_local'].'" /></th>
  371. <th>&nbsp;</th>
  372. <th><input name="timeout" type="text" size="3" value="'.$_REQUEST['timeout'].'" /></th>
  373. <th><input name="limit" type="text" size="3" value="'.$_REQUEST['limit'].'" /></th>
  374. <th>&nbsp;</th>
  375. <th>&nbsp;</th>
  376. <th><input name="ip" type="text" size="10" value="'.$_REQUEST['ip'].'" /></th>
  377. <th><input class="btn" type="submit" name="find" value="'.__('Find','smscoin_reg').'" /></th>
  378. </tr>';
  379. $smscoin_keys = $wpdb->get_results("SELECT * FROM ".$table_name."
  380. ".(count($where) > 0 ? " WHERE ".implode(" AND ", $where) : "")."
  381. ORDER BY ".addslashes($order)." DESC
  382. LIMIT ".intval($offset).",".intval($rpp));
  383. $i = 0;
  384. foreach($smscoin_keys as $skey) {
  385. $str .= '
  386. <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post" >
  387. <tr class="row_'.$i.'">
  388. <td><input size="5" name="k_key" readonly="readonly" value="'.$skey->k_key.'" /></td>
  389. <td><input size="5" name="k_pair" readonly="readonly" value="'.$skey->k_pair.'" /></td>
  390. <td>'.$skey->k_country.'</td>
  391. <td>'.$skey->k_provider.'</td>
  392. <td>'.$skey->k_text.'</td>
  393. <td>'.$skey->k_cost_local.'</td>
  394. <td>'.date("d.m.Y H:i", $skey->k_created).'</td>
  395. <td><input size="5" name="k_timeout" value="'.$skey->k_timeout.'" /></td>
  396. <td><input size="5" name="k_limit_start" value="'.$skey->k_limit_start.'" /></td>
  397. <td><input size="5" name="k_limit_current" value="'.$skey->k_limit_current.'" /></td>
  398. <td>'.($skey->k_first_access>0 ? date("d.m.Y H:i", $skey->k_first_access) : '').'</td>
  399. <td>'.$skey->k_first_ip.'</td>
  400. <td>
  401. <input class="btn" type="submit" name="del" value="Del" />
  402. <input class="btn" type="submit" name="edit" value="Edit" />
  403. </td>
  404. </tr>
  405. </form>';
  406. $i = abs($i-1);
  407. }
  408. $str .= '</table></form>';
  409. $str .= smscoin_reg_paging($sms_num_row,$rpp);
  410. } else {
  411. $LastAction = '<h3>'.__('First you need to configure the module!','smscoin_reg').' </h3> ';
  412. $LastAction .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
  413. $page_mes .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
  414. }
  415. if(!empty($LastAction)) {
  416. $str .= '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
  417. }
  418. echo $page_mes.$str;
  419. }
  420. ###
  421. # Create paid form
  422. # Функция создает инструкции по отправке смс
  423. ###
  424. function smscoin_reg_instruction($key_id) {
  425. $wpurl = get_bloginfo('wpurl');
  426. $currentLocale = get_locale();
  427. if(!empty($currentLocale)) {
  428. $moFile = dirname(__FILE__) . "/lang/smscoin_reg-" . $currentLocale . ".mo";
  429. if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('smscoin_reg', $moFile);
  430. }
  431. $mess = '
  432. <div class="div_ui" style="display: none">
  433. <h3>'.__('Select Country','smscoin_reg').':</h3>
  434. <select class="select_country">
  435. <option value="-">'.__('Select Country','smscoin_reg').'</option>
  436. </select>
  437. <div class="div_provider" style="display: none">
  438. <h3>'.__('Select Provider','smscoin_reg').':</h3>
  439. <select class="select_provider">
  440. <option value="-">'.__('Select Provider','smscoin_reg').'</option>
  441. </select>
  442. </div>
  443. <div class="div_instructions" style="display: none">
  444. <p>'.__('In order to receive a password, please send a message saying' ,'smscoin_reg' ).' <span class="message_text"></span> '.__('to the phone number','smscoin_reg').' <span class="shortcode"></span>.</p>
  445. <p>'.__('The message will cost you' , 'smscoin_reg').' <span class="message_cost"></span>.</p>
  446. <p class="notes" style="display: none"></p>
  447. <p>'.__('You will receive your password in reply.' , 'smscoin_reg').'</p>
  448. <p>'.__('Caution!','smscoin_reg').'</p>
  449. <p>'.__('Pay attention to the message text and especially spaces.All the letters are latin.You\'ll be charged the full price, even in case of an error.','smscoin_reg').'</p>
  450. </div>
  451. </div>
  452. <div class="div_fail" style="display: none">
  453. <h1>'.__('Error connecting to server! Update you\'r tariffs','smscoin_reg').'</h1>
  454. </div>';
  455. return $mess;
  456. }
  457. ###
  458. # Upload tariffs
  459. # Функция обновления тарифной сетки
  460. ###
  461. function smscoin_reg_tariffs_cron() {
  462. @ini_set('user_agent', 'smscoin_key_cron');
  463. $wpurl = get_bloginfo('wpurl');
  464. $key_id = intval(get_option('smscoin_reg_key_id'));
  465. $language = get_option('smscoin_reg_language');
  466. $response = file_get_contents("http://service.smscoin.com/language/$language/json/key/".$key_id."/");
  467. if(preg_match('|(JSONResponse = \[.*\])|is', $response, $feed) > 0) {
  468. if ($response !== false) {
  469. $filename = dirname(__FILE__).'/data/local.js';
  470. if (($hnd = @fopen($filename, 'w')) !== false) {
  471. if (@fwrite($hnd, $response) !== false) {
  472. $LastAction .= ' - Success, file updated @ '.date("r");
  473. $last_update = date("r");
  474. update_option('smscoin_reg_last_update_net', trim($last_update) );
  475. }
  476. fclose($hnd);
  477. }
  478. }
  479. }
  480. }
  481. ###
  482. # Demo paid form in control panel
  483. # Функция отображения инструкции по отправке смс в админке сайта
  484. ###
  485. function smscoin_reg_tariffs() {
  486. smscoin_reg_add_script();
  487. $wpurl = get_bloginfo('wpurl');
  488. $key_id = intval(get_option('smscoin_reg_key_id'));
  489. $language = get_option('smscoin_reg_language');
  490. $last_update = get_option('smscoin_reg_last_update_net');
  491. if($key_id > 200000) {
  492. if ( isset($_POST['submit']) ) {
  493. if( isset($_POST['action']) && $_POST['action'] === 'up') {
  494. @ini_set('user_agent', 'smscoin_reg_cron');
  495. $response = file_get_contents("http://service.smscoin.com/language/$language/json/key/".$key_id."/");
  496. $LastAction .= 'From : <a onclick="window.open(this.href); return false;" href="http://service.smscoin.com/language/'.$language.'/json/key/'.$key_id.'/">http://service.smscoin.com/language/'.$language.'/json/key/'.$key_id.'/</a> ';
  497. # Update tariffs
  498. if ($response !== false) {
  499. $filename = dirname(__FILE__).'/data/local.js';
  500. if (($hnd = @fopen($filename, 'w')) !== false) {
  501. if (@fwrite($hnd, $response) !== false) {
  502. $LastAction .= ' - Success, file updated @ '.date("r");
  503. $last_update = date("r");
  504. update_option('smscoin_reg_last_update_net', trim($last_update) );
  505. } else {
  506. $LastAction = 'File "'.$filename.'" not writeable!';
  507. }
  508. fclose($hnd);
  509. } else {
  510. $LastAction = 'Could not open file';
  511. }
  512. } else {
  513. $LastAction = 'Unable to connect to remote server';
  514. }
  515. $page = '';
  516. }
  517. }
  518. $page .= '<h2>'.__('Your local tariff scale','smscoin_reg').'</h2>'.smscoin_reg_instruction($key_id);
  519. $page .= '<h2>'.__('Update your local tariff scale','smscoin_reg').'</h2>';
  520. $page .= '
  521. '.__('Last update: ','smscoin_reg').' '.$last_update.'
  522. <form action="admin.php?page=Tarifs2" method="post" id="smscoin_reg-conf" style="text-align: left ; margin: left; width: 50em; ">
  523. <input type="hidden" name="action" value="up" />
  524. <p class="submit"><input type="submit" name="submit" value="'.__('Update now: ','smscoin_reg').'" /></p>
  525. </form>';
  526. } else {
  527. $LastAction = '<h3>'.__('First you need to configure the module!','smscoin_reg').'</h3> ';
  528. $LastAction .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
  529. $page_mes .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
  530. }
  531. if(!empty($LastAction)) {
  532. echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
  533. }
  534. echo $page;
  535. }
  536. ###
  537. # Settings page
  538. # Функция основных настроек
  539. ###
  540. function smscoin_reg_settings_page() {
  541. $languages = array("russian", "belarusian", "english", "estonian", "french", "german", "hebrew", "latvian", "lithuanian", "romanian", "spanish", "ukrainian");
  542. $str = '<h2>'.__('Module Settings','smscoin_reg').' SmsCoin R-REG</h2>';
  543. if ( isset($_POST['submit']) ) {
  544. check_admin_referer();
  545. update_option('smscoin_reg_key_id', intval(trim($_POST['key_id'])));
  546. update_option('smscoin_reg_language', trim($_POST['language']));
  547. update_option('smscoin_reg_s_secret', trim($_POST['s_secret']));
  548. if (trim($_POST['key_id']) === "") {
  549. $mess='<h3>'.__('Wrong sms:key ID','smscoin_reg').'</h3>';
  550. } else {
  551. $mess='<h3>'.__('Settings saved','smscoin_reg').'</h3>';
  552. }
  553. $LastAction = $mess;
  554. }
  555. if(!empty($LastAction)) {
  556. $str .= '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
  557. }
  558. echo $str;
  559. ?>
  560. <div class="wrap">
  561. <fieldset class="options">
  562. <legend><h2>SmsCoin - sms:key, <?php _e('Settings','smscoin_reg') ?></h2></legend>
  563. <p><?php _e('For using this module you have to be' ,'smscoin_reg') ?> <a href="http://smscoin.com/account/register/" onclick="this.target = '_blank';"><b><?php _e('registered' ,'smscoin_reg') ?></b></a><?php _e(' at smscoin.net .' ,'smscoin_reg') ?></p>
  564. <p><?php _e('For more information about this service:') ?> <a href="http://smscoin.com/info/smskey-tech/" onclick="this.target = '_blank';" >SmsCoin - sms:key.</a></p>
  565. <p><hr /></p>
  566. <form action="admin.php?page=Settings2" method="post" id="smscoin_reg-conf" style="text-align: left ; margin: left; width: 50em; ">
  567. <p><?php _e('Enter ID of you\'r sms:key:' , 'smscoin_reg')?> <a href="http://smscoin.com/keys/add/" onclick="this.target = '_blank';"><?php _e('get sms:key','smscoin_reg') ?></a></p>
  568. <p><input id="key_id" name="key_id" type="text" size="12" maxlength="6" style="font-family: 'Courier New', monospace; font-size: 1.5em;" value="<?php echo get_option('smscoin_reg_key_id'); ?>" />
  569. <?php
  570. $select_txt = '<p>'.__('Select default script language','smscoin_reg').'</p>
  571. <select id="language" name="language" type="text" style="font-family: \'Courier New\', monospace; font-size: 1.5em;">';
  572. $langs = $languages;
  573. foreach ($langs as $lang) {
  574. $select_txt .= '<option value="'.$lang.'"'.(($lang === get_option('smscoin_reg_language') )?' selected="selected"':'').'>'.$lang.'</option>';
  575. }
  576. echo $select_txt.'</select>';
  577. ?>
  578. <p><?php echo __('Enter Secret code from settings of sms:key:','smscoin_reg'); ?></p>
  579. <p><input id="s_secret" name="s_secret" type="text" size="12" style="font-family: 'Courier New', monospace; font-size: 1.5em;" <?php echo (get_option('smscoin_reg_s_secret') == "" ? ' value="" ' : ' value="'. get_option('smscoin_reg_s_secret') .'" ')?> />
  580. </p>
  581. <p class="submit"><input type="submit" name="submit" value="<?php echo __('Save Settings','smscoin_reg'); ?> &raquo;" /></p>
  582. </form>
  583. </fieldset>
  584. </div>
  585. <?php
  586. }
  587. ###
  588. # Validating password
  589. # Функция проверки пароля
  590. #
  591. # $pair string
  592. # $key int
  593. ###
  594. function do_reg_local_check ($key, $pair) {
  595. global $wpdb, $table_prefix;
  596. $table_name = $table_prefix . 'rkeys';
  597. $do_die = 0;
  598. if (isset($pair) && $pair !='' && strlen($pair)<=10) {
  599. # Validating
  600. # Проверка пароля
  601. $result = $wpdb->get_row("SELECT * FROM $table_name
  602. WHERE k_status='1'
  603. AND k_pair='".addslashes($pair)."'
  604. AND k_key='".intval($key)."'",ARRAY_A);
  605. $data = $result;
  606. if ($data && $data['k_first_access'] == '0') {
  607. # First access
  608. # Первая активация
  609. $wpdb->query("UPDATE $table_name
  610. SET k_first_access='".time()."', k_first_ip='".addslashes($_SERVER["REMOTE_ADDR"])."',
  611. k_first_from='".addslashes($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"])."'".($data['k_limit_current'] > 0 ? ", k_limit_current=k_limit_current-1" : "")."
  612. WHERE k_pair='".addslashes($pair)."' AND k_key='".intval($key)."'");
  613. $do_die = 1;
  614. } elseif ($data && ($data['k_timeout'] == 0 || ($data['k_first_access']+$data['k_timeout']*60)>time())) {
  615. if ($data['k_limit_start'] > 0) {
  616. if ($data['k_limit_current'] > 0) {
  617. # Other access
  618. # Другие активации
  619. $wpdb->query("UPDATE $table_name SET k_limit_current=k_limit_current-1
  620. WHERE k_pair='".addslashes($pair)."'
  621. AND k_key='".intval($key)."' AND k_limit_current>0");
  622. $do_die = 1;
  623. }
  624. } else {
  625. $do_die = 1;
  626. }
  627. }
  628. }
  629. return $do_die;
  630. }
  631. ?>