/reg/smscoin_reg/smscoin_reg.php
PHP | 694 lines | 538 code | 57 blank | 99 comment | 81 complexity | 01f50201e8ad3c92ae090c76ebecda01 MD5 | raw file
- <?php
- /*
- Plugin Name: SMSCOIN R-REG
- Plugin URI: http://smscoin.com/software/engine/WordPress/
- Description: Плагин платной регистрации.
- Version: 1.2
- Author: SMSCOIN.COM
- Author URI: http://smscoin.com/
- */
- /* Copyright 2009 SMSCOIN */
- ###
- # Add events
- # Подключение событий
- ###
- add_action('activate_smscoin_reg/smscoin_reg.php', 'smscoin_reg_activation');
- add_action('deactivate_smscoin_reg/smscoin_reg.php', 'smscoin_reg_deactivation');
- add_action('smscoin_reg_cron', 'smscoin_reg_tariffs_cron');
- add_action('admin_menu', 'smscoin_reg_add_pages');
- add_action('register_form', 'smscoin_add_signup_fields',1);
- add_filter( 'registration_errors', 'smscoin_validate_signup_fields');
- add_filter( 'user_register', 'smscoin_on_activate_user');
- ###
- # Localization
- # Подключение локализации
- ###
- $currentLocale = get_locale();
- if(!empty($currentLocale)) {
- $moFile = dirname(__FILE__) . "/lang/smscoin_reg-" . $currentLocale . ".mo";
- if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('smscoin_reg', $moFile);
- }
- ###
- # Create paid form
- # Функция сборки инструкций по отправке смс
- ###
- function smscoin_add_signup_fields() {
- $key_id = get_option('smscoin_reg_key_id');
- $response .=
- __('<h3>If you have already received the password, enter it here:</h3>','smscoin_reg')
- .'<input name="s_pair" type="text" value="'.addslashes($_REQUEST['s_pair']).'" />'
- .__('<h3>To receive your password please send an sms</h3>','smscoin_reg'). smscoin_reg_add_script().''.smscoin_reg_instruction($key_id).'<br /><br />';
- echo $response;
- }
- ###
- # Check password
- # Функция проверки пароля
- ###
- function smscoin_validate_signup_fields( $result ) {
- if (isset($_REQUEST['s_pair']) && $_REQUEST['s_pair'] !='' && strlen($_REQUEST['s_pair'])<=10) {
- $key_id = get_option('smscoin_reg_key_id');
- $flag = do_reg_local_check ($key_id, addslashes($_REQUEST['s_pair']));
- }
- if ($flag != 1) {
- $result->errors['wrong_code'] = array("<b>ERROR:</b> Wrong code.");
- } else {
- $_SESSION['invite_code'] = $_REQUEST['s_pair'];
- }
- return $result;
- }
- ###
- # User activation
- # Функция активации пользователя
- ###
- function smscoin_on_activate_user( $user_id, $password='', $meta='') {
- global $wpdb, $table_prefix;
- $key_id = get_option('smscoin_reg_key_id');
- #delete pass
- $sql = 'UPDATE `'.$table_prefix.'rkeys` SET `k_status` = 0 WHERE `k_key`="'.$key_id.'" AND `k_pair` = "'.$_SESSION['invite_code'].'"';
- $wpdb->query($sql);
- echo mysql_error();
- }
- ###
- # Activate cron
- # Функция активации крона
- ###
- function smscoin_reg_activation() {
- wp_schedule_event(time(), 'hourly', 'smscoin_reg_cron');
- smscoin_reg_create_table();
- }
- ###
- # Deactivate cron
- # Функция деактивации крона
- ###
- function smscoin_reg_deactivation() {
- global $wpdb,$table_prefix;
- $table_name = $table_prefix . 'rkeys';
- wp_clear_scheduled_hook('smscoin_reg_cron');
- $wpdb->query("DROP TABLE `".$table_name."`");
- }
- ###
- # Add js
- # Функция создания скрипта
- ###
- function smscoin_reg_add_script() {
- $wpurl = get_bloginfo('wpurl');
- $key_id = intval(get_option('smscoin_reg_key_id'));
- $str = '
- <link rel="stylesheet" href="'.$wpurl.'/wp-content/plugins/smscoin_reg/viewer.css" type="text/css" />
- <script src="'.$wpurl.'/wp-content/plugins/smscoin_reg/dropdown.js" type="text/javascript"></script>
- <script type="text/javascript">
- var JSON_URL = "'.$wpurl.'/wp-content/plugins/smscoin_reg/data/local.js'.'"
- var SERVICE = "'.$key_id.'";
- var SELECT_PROVIDER = "'.__('Select Provider','smscoin_rkey').'";
- var INCLUDING_VAT = "'.__('including VAT','smscoin_rkey').'";
- var WITHOUT_VAT = "'.__('without VAT','smscoin_rkey').'";
- </script>
- <script type="text/javascript">
- //<![CDATA[
- function hideAll() {
- var allDivs = document.getElementsByTagName(\'div\');
- for (var div in allDivs) {
- if (belongsToClass(allDivs[div], \'div_sms\')) {
- allDivs[div].style.display = \'none\';
- }
- }
- }
- //]]>
- </script>';
- echo $str;
- }
- ###
- # Create table
- # Функция создания таблицы
- ###
- function smscoin_reg_create_table() {
- global $wpdb,$table_prefix;
- $table_name = $table_prefix . 'rkeys';
- if($wpdb->get_var(" SHOW TABLES LIKE `".$table_name."` ") != $table_name) {
- $sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
- `k_status` tinyint(1) unsigned NOT NULL default '0',
- `k_key` int(10) unsigned NOT NULL default '0',
- `k_pair` varchar(16) character set utf8 NOT NULL,
- `k_country` varchar(2) character set utf8 NOT NULL,
- `k_provider` varchar(64) character set utf8 NOT NULL,
- `k_text` varchar(255) character set utf8 NOT NULL,
- `k_cost_local` decimal(6,2) NOT NULL,
- `k_created` int(10) unsigned NOT NULL default '0',
- `k_timeout` int(10) unsigned NOT NULL default '0',
- `k_limit_start` int(10) unsigned NOT NULL default '0',
- `k_limit_current` int(10) unsigned NOT NULL default '0',
- `k_first_access` int(10) unsigned NOT NULL default '0',
- `k_first_ip` varchar(32) character set utf8 NOT NULL,
- `k_first_from` varchar(255) character set utf8 NOT NULL,
- UNIQUE KEY `k_key` (`k_key`,`k_pair`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
- $wpdb->query($sql);
- }
- }
- ###
- # Create Page
- # Функция создания страницы
- ###
- function smscoin_reg_add_pages() {
- if (function_exists('add_menu_page')) {
- add_menu_page('SmsCoin R-REG', 'SmsCoin R-REG', 8, __FILE__, 'smscoin_reg_list', plugins_url('smscoin_reg/images/dot.png'));
- }
- if (function_exists('add_submenu_page')) {
- add_submenu_page(__FILE__, 'List2', __('List','smscoin_reg'), 8, __FILE__, 'smscoin_reg_list');
- add_submenu_page(__FILE__, 'Tarifs2', __('Tarifs','smscoin_reg'), 8, 'Tarifs2', 'smscoin_reg_tariffs');
- add_submenu_page(__FILE__, 'Settings2', __('Settings','smscoin_reg'), 8, 'Settings2', 'smscoin_reg_settings_page');
- }
- }
- ###
- # Pagination
- # Функция создания номеров ссылок
- ###
- function smscoin_reg_paging($sms_num_row,$rpp) {
- $ii=0;
- if($sms_num_row == 0) return '';
- $ret_str = '<div>'.__('Pages : ','smscoin_reg').' ';
- while( $sms_num_row>0 ) {
- $GP = $_GET+$_POST;
- unset($GP['sms_page']);
- unset($GP['page']);
- unset($GP['del']);
- unset($GP['edit']);
- $ret_str .= '<a href="admin.php?page=smscoin_reg/smscoin_reg.php&sms_page='.($ii+1).'&'.http_build_query($GP).'">['.($ii+1).']</a> ';
- $sms_num_row -= $rpp;
- $ii++;
- }
- return $ret_str.'</div>';
- }
- ###
- # Statistics
- # Функция создания страницы статистики паролей
- ###
- function smscoin_reg_list($key_id) {
- global $wpdb, $table_prefix;
- $str = '';
- $table_name = $table_prefix . 'rkeys';
- $str .= '<h1>'.__('List received sms','smscoin_reg').'</h1>';
- $smscoin_keys = array();
- if($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'") == $table_name) {
- # Table created
- # Таблица создана
- if(isset($_POST['action']) && trim($_POST['action']) == 'add') {
- # Чтение параметров
- $key = intval($_POST["key"]);
- $pair = $_POST["pair"];
- $timeout = intval($_POST["timeout"]);
- $limit = intval($_POST["limit"]);
- $content = $_POST["content"];
- $country = $_POST["country"];
- $cost_local = $_POST["cost_local"];
- $provider = $_POST["provider"];
- # Store row
- # Запись строки в базу данных
- $fields = "1, ".addslashes($key).", '".addslashes($pair)."','".addslashes($country)."', '".addslashes($provider)."', '".addslashes($content)."', '".addslashes($cost_local)."',
- ".addslashes(time()).", ".intval($timeout).", ".intval($limit).", ".intval($limit);
- $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)
- VALUES (".$fields.");
- ");
- unset($_REQUEST['action']);
- }
- if( isset($_REQUEST['del']) ) {
- # Delete row
- # Удаление записи
- $wpdb->query("DELETE FROM ".$table_name." WHERE k_pair='".addslashes($_REQUEST['k_pair'])."';");
- $LastAction = '<h3>'. sprintf(__('Password %s was deleted!', 'smscoin_reg'), $_REQUEST['k_pair']).' .</h3> ';
- unset($_REQUEST['del']);
- }
- if( isset($_REQUEST['edit']) ) {
- # Change row
- # Изменение записи
- $wpdb->query("UPDATE ".$table_name." SET
- k_timeout='".intval($_REQUEST['k_timeout'])."' ,
- k_limit_start='".intval($_REQUEST['k_limit_start'])."' ,
- k_limit_current='".intval($_REQUEST['k_limit_current'])."'
- WHERE k_pair='".addslashes($_REQUEST['k_pair'])."';");
- $LastAction = '<h3>'. sprintf(__('Password %s parameters was changed!', 'smscoin_reg'), $_REQUEST['k_pair']) . '</h3> ';
- unset($_REQUEST['edit']);
- }
- if( !isset($_REQUEST['rpp']) ) {
- $rpp = 5;
- } else {
- $rpp = intval($_REQUEST['rpp']);
- }
- $str .= '
- <style type="text/css">
- p, li, th, td {
- font-size: 9pt;
- }
- .list_table {
- width: 100%;
- }
- .list_table tr {
- background: #ffffff;
- color: inherit;
- }
- .list_table tr.row_0 {
- background: #f9f9f9;
- color: inherit;
- }
- .list_table tr.row_1 {
- background: #efefff;
- color: inherit;
- }
- .list_table th {
- background: #f1f1f1;
- color: #033;
- padding: 2px;
- text-align: center;
- border-bottom: 1px #777 solid;
- }
- .list_table td {
- padding: 1px;
- text-align: center;
- }
- .list_table input {
- width: auto;
- }
- .list_table th input {
- width: 100%;
- }
- </style>
- <div><h3>'.__('Manually add a password:','smscoin_reg').'</h3></div>
- <table class="list_table">
- <tr>
- <th>'.__('Key','smscoin_reg').'</th>
- <th>'.__('Password','smscoin_reg').'</th>
- <th>'.__('Country','smscoin_reg').'</th>
- <th>'.__('Provider','smscoin_reg').'</th>
- <th>'.__('Text','smscoin_reg').'</th>
- <th>'.__('Cost','smscoin_reg').'</th>
- <th>'.__('Time','smscoin_reg').'</th>
- <th>'.__('Limit','smscoin_reg').'</th>
- <th></th>
- </tr>
- <tr>
- <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post">
- <th><input name="key" type="text" size="5" value="" /></th>
- <th><input name="pair" type="text" size="4" value="" /></th>
- <th><input name="country" type="text" size="5" value="" /></th>
- <th><input name="provider" type="text" size="5" value="" /></th>
- <th><input name="text" type="text" size="10" value="" /></th>
- <th><input name="cost_local" type="text" size="5" value="" /></th>
- <th><input name="timeout" type="text" size="5" value="" /></th>
- <th><input name="limit" type="text" size="5" value="" /></th>
- <th><input name="action" type="hidden" value="add" />
- <input class="btn" type="submit" name="add" value="'.__('Add Password','smscoin_reg').'" /></th>
- </form>
- </tr>
- </table>
- <hr />
- <div><h3>'.__('List recived sms','smscoin_reg').'</h3></div>
- <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post">
- <div>
- '.__('Items per page','smscoin_reg').'<input name="rpp" type="text" size="5" value="'.$rpp.'" />
- <input class="btn" type="submit" name="find" value="'.__('Show','smscoin_reg').'" />
- </div>';
- $where = array();
- $order = "k_created";
- # Create query
- # Создание запроса
- if (isset($_REQUEST['key']) && $_REQUEST['key']!='') {
- $where[] = "k_key='".intval($_REQUEST['key'])."'";
- }
- if (isset($_REQUEST['pair']) && $_REQUEST['pair']!='') {
- $where[] = "k_pair='".addslashes($_REQUEST['pair'])."'";
- }
- if (isset($_REQUEST['timeout']) && $_REQUEST['timeout']!='') {
- $where[] = "k_timeout='".intval($_REQUEST['timeout'])."'";
- }
- if (isset($_REQUEST['limit']) && $_REQUEST['limit']!='') {
- $where[] = "k_limit_start='".intval($_REQUEST['limit'])."'";
- }
- if (isset($_REQUEST['ip']) && $_REQUEST['ip']!='') {
- $where[] = "k_first_ip='".addslashes($_REQUEST['ip'])."'";
- }
- if (isset($_REQUEST['provider']) && $_REQUEST['provider']!='') {
- $where[] = "k_provider LIKE '%".addslashes($_REQUEST['provider'])."%'";
- }
- if (isset($_REQUEST['country']) && $_REQUEST['country']!='') {
- $where[] = "k_country='".addslashes($_REQUEST['country'])."'";
- }
- if (isset($_REQUEST['text']) && $_REQUEST['text']!='') {
- $where[] = "k_text LIKE '%".addslashes($_REQUEST['text'])."%'";
- }
- if(isset($_REQUEST['sms_page']) && $_REQUEST['sms_page']!='') {
- $page = intval($_REQUEST['sms_page']);
- } else {
- $page = 1;
- }
- $offset = ($page-1)*$rpp;
- $result = $wpdb->get_row("SELECT count(*) AS num_row FROM ".$table_name."
- ".(count($where) > 0 ? " WHERE ".implode(" AND ", $where) : "")."", ARRAY_A );
- $sms_num_row = intval($result['num_row']);
- $str .= smscoin_reg_paging($sms_num_row, $rpp);
- $str .= '<table class="list_table">
- <tr>
- <th>'.__('Key','smscoin_reg').'</th>
- <th>'.__('Password','smscoin_reg').'</th>
- <th>'.__('Country','smscoin_reg').'</th>
- <th>'.__('Provider','smscoin_reg').'</th>
- <th>'.__('Text','smscoin_reg').'</th>
- <th>'.__('Cost','smscoin_reg').'</th>
- <th>'.__('Added','smscoin_reg').'</th>
- <th>'.__('Time','smscoin_reg').'</th>
- <th>'.__('Limit','smscoin_reg').'</th>
- <th>'.__('Show','smscoin_reg').'</th>
- <th>'.__('First enter','smscoin_reg').'</th>
- <th>IP</th>
- <th>'.__('Options','smscoin_reg').'</th>
- </tr>
- <tr>
- <th><input name="key" type="text" size="5" value="'.$_REQUEST['key'].'" /></th>
- <th><input name="pair" type="text" size="7" value="'.$_REQUEST['pair'].'" /></th>
- <th><input name="country" type="text" size="5" value="'.$_REQUEST['country'].'" /></th>
- <th><input name="provider" type="text" size="5" value="'.$_REQUEST['provider'].'" /></th>
- <th><input name="text" type="text" size="10" value="'.$_REQUEST['text'].'" /></th>
- <th><input name="cost_local" type="text" size="5" value="'.$_REQUEST['cost_local'].'" /></th>
- <th> </th>
- <th><input name="timeout" type="text" size="3" value="'.$_REQUEST['timeout'].'" /></th>
- <th><input name="limit" type="text" size="3" value="'.$_REQUEST['limit'].'" /></th>
- <th> </th>
- <th> </th>
- <th><input name="ip" type="text" size="10" value="'.$_REQUEST['ip'].'" /></th>
- <th><input class="btn" type="submit" name="find" value="'.__('Find','smscoin_reg').'" /></th>
- </tr>';
- $smscoin_keys = $wpdb->get_results("SELECT * FROM ".$table_name."
- ".(count($where) > 0 ? " WHERE ".implode(" AND ", $where) : "")."
- ORDER BY ".addslashes($order)." DESC
- LIMIT ".intval($offset).",".intval($rpp));
- $i = 0;
- foreach($smscoin_keys as $skey) {
- $str .= '
- <form action="admin.php?page=smscoin_reg/smscoin_reg.php" method="post" >
- <tr class="row_'.$i.'">
- <td><input size="5" name="k_key" readonly="readonly" value="'.$skey->k_key.'" /></td>
- <td><input size="5" name="k_pair" readonly="readonly" value="'.$skey->k_pair.'" /></td>
- <td>'.$skey->k_country.'</td>
- <td>'.$skey->k_provider.'</td>
- <td>'.$skey->k_text.'</td>
- <td>'.$skey->k_cost_local.'</td>
- <td>'.date("d.m.Y H:i", $skey->k_created).'</td>
- <td><input size="5" name="k_timeout" value="'.$skey->k_timeout.'" /></td>
- <td><input size="5" name="k_limit_start" value="'.$skey->k_limit_start.'" /></td>
- <td><input size="5" name="k_limit_current" value="'.$skey->k_limit_current.'" /></td>
- <td>'.($skey->k_first_access>0 ? date("d.m.Y H:i", $skey->k_first_access) : '').'</td>
- <td>'.$skey->k_first_ip.'</td>
- <td>
- <input class="btn" type="submit" name="del" value="Del" />
- <input class="btn" type="submit" name="edit" value="Edit" />
- </td>
- </tr>
- </form>';
- $i = abs($i-1);
- }
- $str .= '</table></form>';
- $str .= smscoin_reg_paging($sms_num_row,$rpp);
- } else {
- $LastAction = '<h3>'.__('First you need to configure the module!','smscoin_reg').' </h3> ';
- $LastAction .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
- $page_mes .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
- }
- if(!empty($LastAction)) {
- $str .= '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
- }
- echo $page_mes.$str;
- }
- ###
- # Create paid form
- # Функция создает инструкции по отправке смс
- ###
- function smscoin_reg_instruction($key_id) {
- $wpurl = get_bloginfo('wpurl');
- $currentLocale = get_locale();
- if(!empty($currentLocale)) {
- $moFile = dirname(__FILE__) . "/lang/smscoin_reg-" . $currentLocale . ".mo";
- if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('smscoin_reg', $moFile);
- }
- $mess = '
- <div class="div_ui" style="display: none">
- <h3>'.__('Select Country','smscoin_reg').':</h3>
- <select class="select_country">
- <option value="-">'.__('Select Country','smscoin_reg').'</option>
- </select>
- <div class="div_provider" style="display: none">
- <h3>'.__('Select Provider','smscoin_reg').':</h3>
- <select class="select_provider">
- <option value="-">'.__('Select Provider','smscoin_reg').'</option>
- </select>
- </div>
- <div class="div_instructions" style="display: none">
- <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>
- <p>'.__('The message will cost you' , 'smscoin_reg').' — <span class="message_cost"></span>.</p>
- <p class="notes" style="display: none"></p>
- <p>'.__('You will receive your password in reply.' , 'smscoin_reg').'</p>
- <p>'.__('Caution!','smscoin_reg').'</p>
- <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>
- </div>
- </div>
- <div class="div_fail" style="display: none">
- <h1>'.__('Error connecting to server! Update you\'r tariffs','smscoin_reg').'</h1>
- </div>';
- return $mess;
- }
- ###
- # Upload tariffs
- # Функция обновления тарифной сетки
- ###
- function smscoin_reg_tariffs_cron() {
- @ini_set('user_agent', 'smscoin_key_cron');
- $wpurl = get_bloginfo('wpurl');
- $key_id = intval(get_option('smscoin_reg_key_id'));
- $language = get_option('smscoin_reg_language');
- $response = file_get_contents("http://service.smscoin.com/language/$language/json/key/".$key_id."/");
- if(preg_match('|(JSONResponse = \[.*\])|is', $response, $feed) > 0) {
- if ($response !== false) {
- $filename = dirname(__FILE__).'/data/local.js';
- if (($hnd = @fopen($filename, 'w')) !== false) {
- if (@fwrite($hnd, $response) !== false) {
- $LastAction .= ' - Success, file updated @ '.date("r");
- $last_update = date("r");
- update_option('smscoin_reg_last_update_net', trim($last_update) );
- }
- fclose($hnd);
- }
- }
- }
- }
- ###
- # Demo paid form in control panel
- # Функция отображения инструкции по отправке смс в админке сайта
- ###
- function smscoin_reg_tariffs() {
- smscoin_reg_add_script();
- $wpurl = get_bloginfo('wpurl');
- $key_id = intval(get_option('smscoin_reg_key_id'));
- $language = get_option('smscoin_reg_language');
- $last_update = get_option('smscoin_reg_last_update_net');
- if($key_id > 200000) {
- if ( isset($_POST['submit']) ) {
- if( isset($_POST['action']) && $_POST['action'] === 'up') {
- @ini_set('user_agent', 'smscoin_reg_cron');
- $response = file_get_contents("http://service.smscoin.com/language/$language/json/key/".$key_id."/");
- $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> ';
- # Update tariffs
- if ($response !== false) {
- $filename = dirname(__FILE__).'/data/local.js';
- if (($hnd = @fopen($filename, 'w')) !== false) {
- if (@fwrite($hnd, $response) !== false) {
- $LastAction .= ' - Success, file updated @ '.date("r");
- $last_update = date("r");
- update_option('smscoin_reg_last_update_net', trim($last_update) );
- } else {
- $LastAction = 'File "'.$filename.'" not writeable!';
- }
- fclose($hnd);
- } else {
- $LastAction = 'Could not open file';
- }
- } else {
- $LastAction = 'Unable to connect to remote server';
- }
- $page = '';
- }
- }
- $page .= '<h2>'.__('Your local tariff scale','smscoin_reg').'</h2>'.smscoin_reg_instruction($key_id);
- $page .= '<h2>'.__('Update your local tariff scale','smscoin_reg').'</h2>';
- $page .= '
- '.__('Last update: ','smscoin_reg').' '.$last_update.'
- <form action="admin.php?page=Tarifs2" method="post" id="smscoin_reg-conf" style="text-align: left ; margin: left; width: 50em; ">
- <input type="hidden" name="action" value="up" />
- <p class="submit"><input type="submit" name="submit" value="'.__('Update now: ','smscoin_reg').'" /></p>
- </form>';
- } else {
- $LastAction = '<h3>'.__('First you need to configure the module!','smscoin_reg').'</h3> ';
- $LastAction .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
- $page_mes .= '<a href="admin.php?page=Settings2">'.__('Settings','smscoin_reg').'</a>';
- }
- if(!empty($LastAction)) {
- echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
- }
- echo $page;
- }
- ###
- # Settings page
- # Функция основных настроек
- ###
- function smscoin_reg_settings_page() {
- $languages = array("russian", "belarusian", "english", "estonian", "french", "german", "hebrew", "latvian", "lithuanian", "romanian", "spanish", "ukrainian");
- $str = '<h2>'.__('Module Settings','smscoin_reg').' SmsCoin R-REG</h2>';
- if ( isset($_POST['submit']) ) {
- check_admin_referer();
- update_option('smscoin_reg_key_id', intval(trim($_POST['key_id'])));
- update_option('smscoin_reg_language', trim($_POST['language']));
- update_option('smscoin_reg_s_secret', trim($_POST['s_secret']));
- if (trim($_POST['key_id']) === "") {
- $mess='<h3>'.__('Wrong sms:key ID','smscoin_reg').'</h3>';
- } else {
- $mess='<h3>'.__('Settings saved','smscoin_reg').'</h3>';
- }
- $LastAction = $mess;
- }
- if(!empty($LastAction)) {
- $str .= '<!-- Last Action --><div id="message" class="updated fade"><p>'.$LastAction.'</p></div>';
- }
- echo $str;
- ?>
- <div class="wrap">
- <fieldset class="options">
- <legend><h2>SmsCoin - sms:key, <?php _e('Settings','smscoin_reg') ?></h2></legend>
- <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>
- <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>
- <p><hr /></p>
- <form action="admin.php?page=Settings2" method="post" id="smscoin_reg-conf" style="text-align: left ; margin: left; width: 50em; ">
- <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>
- <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'); ?>" />
- <?php
- $select_txt = '<p>'.__('Select default script language','smscoin_reg').'</p>
- <select id="language" name="language" type="text" style="font-family: \'Courier New\', monospace; font-size: 1.5em;">';
- $langs = $languages;
- foreach ($langs as $lang) {
- $select_txt .= '<option value="'.$lang.'"'.(($lang === get_option('smscoin_reg_language') )?' selected="selected"':'').'>'.$lang.'</option>';
- }
- echo $select_txt.'</select>';
- ?>
- <p><?php echo __('Enter Secret code from settings of sms:key:','smscoin_reg'); ?></p>
- <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') .'" ')?> />
- </p>
- <p class="submit"><input type="submit" name="submit" value="<?php echo __('Save Settings','smscoin_reg'); ?> »" /></p>
- </form>
- </fieldset>
- </div>
- <?php
- }
- ###
- # Validating password
- # Функция проверки пароля
- #
- # $pair string
- # $key int
- ###
- function do_reg_local_check ($key, $pair) {
- global $wpdb, $table_prefix;
- $table_name = $table_prefix . 'rkeys';
- $do_die = 0;
- if (isset($pair) && $pair !='' && strlen($pair)<=10) {
- # Validating
- # Проверка пароля
- $result = $wpdb->get_row("SELECT * FROM $table_name
- WHERE k_status='1'
- AND k_pair='".addslashes($pair)."'
- AND k_key='".intval($key)."'",ARRAY_A);
- $data = $result;
- if ($data && $data['k_first_access'] == '0') {
- # First access
- # Первая активация
- $wpdb->query("UPDATE $table_name
- SET k_first_access='".time()."', k_first_ip='".addslashes($_SERVER["REMOTE_ADDR"])."',
- k_first_from='".addslashes($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"])."'".($data['k_limit_current'] > 0 ? ", k_limit_current=k_limit_current-1" : "")."
- WHERE k_pair='".addslashes($pair)."' AND k_key='".intval($key)."'");
- $do_die = 1;
- } elseif ($data && ($data['k_timeout'] == 0 || ($data['k_first_access']+$data['k_timeout']*60)>time())) {
- if ($data['k_limit_start'] > 0) {
- if ($data['k_limit_current'] > 0) {
- # Other access
- # Другие активации
- $wpdb->query("UPDATE $table_name SET k_limit_current=k_limit_current-1
- WHERE k_pair='".addslashes($pair)."'
- AND k_key='".intval($key)."' AND k_limit_current>0");
- $do_die = 1;
- }
- } else {
- $do_die = 1;
- }
- }
- }
- return $do_die;
- }
- ?>