-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp_trader_install.php
More file actions
333 lines (313 loc) · 14.3 KB
/
wp_trader_install.php
File metadata and controls
333 lines (313 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* @package WP-Trader
*/
/*
* Plugin Name: WP-Trader
* Plugin URI: http://wp-tracker.com/
* Description: Roughly based on Torrent Trader 2.07, WP-Trader is an easy solution for people to run a torrent site. Now it is easier for bands, software makers, authors and etc. to be able to get their work out to their users without the high cost of having servers for product download. We hope this plugin will be useful for people who do not want to distribute their works through the normal channel which like to act like a mafiaa and not pay the artists what they deserve (we will not mention the companies names but you should know who you are and should not fear us but embrace us). Users of this plugin should only use it to distribute work which they own the rights to. The author(s) of this plugin can not be held responsible for the use of this plugin.
* Version: .4.8 Beta
* Author: Andrew Walker & Lee Howarth
* Author URI: http://wp-tracker.com/
* Lisence: GPLv2
*/
require_once( dirname( __FILE__ ) . "/wp_trader_install_defines.php" );
require_once( WP_TRADER_ABSPATH . "/includes/required-includes.php" );
global $wp_trader_plugin_description, $wp_trader_plugin_version, $wp_trader_plugin_author;
if ( ! function_exists( "get_plugin_data" ) )
require_once( ABSPATH . "wp-admin/includes/plugin.php" );
$wp_trader_plugin_data = get_plugin_data( __FILE__, true, true );
$wp_trader_plugin_description = $wp_trader_plugin_data["Description"];
$wp_trader_plugin_version = $wp_trader_plugin_data["Version"];
$wp_trader_plugin_author = $wp_trader_plugin_data["Author"];
global $wp_trader_db_version;
$wp_trader_db_version = "1.1";
function wptrader_install(){
global $wpdb;
require_once( WP_TRADER_ABSPATH . "/includes/function-main.php" );
require_once( WP_TRADER_ABSPATH . "/wp_trader_install_functions.php" );
if ( function_exists( "wp_trader_install_db" ) )
wp_trader_install_db();
if ( function_exists( "wp_trader_install_db_values" ) )
wp_trader_install_db_values();
if ( function_exists( "wp_trader_install_options" ) )
wp_trader_install_options();
if ( function_exists( "wp_trader_install_categories" ) )
wp_trader_install_categories();
if ( function_exists( "wp_trader_install_pages" ) )
wp_trader_install_pages();
if ( function_exists( "wp_trader_install_system_user" ) )
wp_trader_install_system_user();
//need to remove in later version
update_option( 'cleanup_autoclean_interval', 'hourly' );
}
function wptrader_uninstall(){
require_once( WP_TRADER_ABSPATH . "/includes/function-main.php" );
if(get_option("wp_trader_keep_settings") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
global $wpdb;
if ( function_exists( "wp_trader_uninstall_options" ) )
wp_trader_uninstall_options(); //need to add an option to keep
delete_option("wp_trader_keep_settings");
}
if(get_option("wp_trader_keep_settings") == 0 || get_option("wp_trader_keep_posts") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
$query = "SELECT post_id, attachment_id FROM " . TRADER_TORRENTS . "";
$res = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
wp_delete_post( $row["post_id"], true );
wp_delete_post( $row["attachment_id"], true );
delete_post_meta($row["post_id"], "_thumbnail_id");
delete_post_meta($row["post_id"], "anon");
delete_post_meta($row["post_id"], "freeleech");
delete_post_meta($row["post_id"], "external");
delete_post_meta($row["post_id"], "views");
delete_post_meta($row["post_id"], "hits");
delete_post_meta($row["post_id"], "times_completed");
delete_post_meta($row["post_id"], "leechers");
delete_post_meta($row["post_id"], "seeders");
delete_post_meta($row["post_id"], "torrent_location");
delete_post_meta($row["post_id"], "last_action");
delete_post_meta($row["post_id"], "descr");
}
delete_option("wp_trader_keep_posts");
}
if(get_option("wp_trader_keep_settings") == 0 || get_option("wp_trader_keep_all_pages") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
if ( function_exists( "wp_trader_uninstall_pages" ) )
wp_trader_uninstall_pages();
delete_option("wp_trader_keep_all_pages");
}
if(get_option("wp_trader_keep_settings") == 0 || get_option("wp_trader_keep_all_user_info") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
if ( function_exists( "wp_trader_uninstall_user_meta" ) )
wp_trader_uninstall_user_meta();
delete_option("wp_trader_keep_all_user_info");
}
if(get_option("wp_trader_keep_settings") == 0 || get_option("wp_trader_keep_system_user") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
if ( function_exists( "wp_trader_uninstall_system_user" ) )
wp_trader_uninstall_system_user();
delete_option("wp_trader_keep_system_user");
}
if(get_option("wp_trader_keep_settings") == 0 || get_option("wp_trader_keep_databank_tables") == 0){
require_once( WP_TRADER_ABSPATH . "/wp_trader_uninstall_functions.php" );
if ( function_exists( "wp_trader_uninstall_db" ) )
wp_trader_uninstall_db();
delete_option("wp_trader_keep_databank_tables");
}
}
register_activation_hook(__FILE__, "wptrader_install");
register_deactivation_hook(__FILE__, "wptrader_uninstall");
add_action("wp_head", "wp_trader_head");
function wp_trader_head(){
if (!is_admin()){
?>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
<?php
}
}
if (get_option("members_only") == 1){
//credits and some part of the memebrs only redirect go to http://wordpress.org/extend/plugins/registered-users-only/
add_action( "wp", "members_only_redirect" );
function members_only_redirect() {
global $post;
// If the user is logged in, then abort
if ( current_user_can('read') ) return;
$members_only = get_option( "members_only" );
// Feeds
if ( 1 == $members_only["feeds"] && is_feed() ) return;
// This is a base array of pages that will be EXCLUDED from being blocked
$page_exclude = array_map("trim", @explode("|", get_option("members_only_page_exclude")));
// If the current script name is in the exclusion list, abort
if ( in_array( basename(get_permalink()), apply_filters( "wp_trader_memebers_only", $page_exclude ) ) ) return;
// Still here? Okay, then redirect to the login form
auth_redirect();
}
add_action( "init", "wp_trader_login_form_message" );
function wp_trader_login_form_message() {
// Don't show the error message if anything else is going on (registration, etc.)
if ( "wp-login.php" != basename($_SERVER["PHP_SELF"]) || !empty($_POST) || ( !empty($_GET) && empty($_GET["redirect_to"]) ) ) return;
global $error;
$error = __( "Only registered and logged in users are allowed to view this site. Please log in now.", "registered-users-only" );
}
// Tell bots to go away (they shouldn't index the login form)
add_action( "login_head", "wp_trader_no_index", 1 );
function wp_trader_no_index(){
return " <meta name='robots' content='noindex,nofollow' />\n";
}
}
function wptrader_custom_user_profile_fields( $user ) {
global $wpdb;
require_once( WP_TRADER_ABSPATH . "/includes/function-main.php" );
?>
<h3><?php _e('Torrent Site Info', 'your_textdomain'); ?></h3>
<table class="form-table">
<tr>
<th>
<label for="trader_upload"><?php _e('Upload', 'your_textdomain'); ?></label>
</th>
<td>
<?php
if ( !get_the_author_meta( 'trader_upload', $user->ID ) ){
$user_upload = '0';
}else{
$user_upload = ''.get_the_author_meta( 'trader_upload', $user->ID ).'';
}
?>
<?php if( !current_user_can('level_10') ){ ?>
<?php echo esc_attr( mksize( $user_upload ) ); ?><br />
<?php }else{ ?>
<input type="text" size="30" name="trader_upload" id="trader_upload" value="<?php echo esc_attr( $user_upload ); ?>" /> <?php echo esc_attr( mksize( $user_upload ) ); ?><br />
<span class="description">Value should be entered in bytes.</span><br />
<?php } ?>
</td>
</tr>
<tr>
<th>
<label for="trader_download"><?php _e('Download', 'your_textdomain'); ?></label>
</th>
<td>
<?php
if ( !get_the_author_meta( 'trader_download', $user->ID ) ){
$user_download = '0';
}else{
$user_download = ''.get_the_author_meta( 'trader_download', $user->ID ).'';
}
?>
<?php if( !current_user_can('level_10') ){ ?>
<?php echo esc_attr( mksize( $user_download ) ); ?><br />
<?php }else{ ?>
<input type="text" size="30" name="trader_download" id="trader_download" value="<?php echo esc_attr( $user_download ); ?>" /> <?php echo esc_attr( mksize( $user_download ) ); ?><br />
<span class="description">Value should be entered in bytes.</span><br />
<?php } ?>
</td>
</tr>
<tr>
<th>
<label for="trader_ratio"><?php _e('Ratio', 'your_textdomain'); ?></label>
</th>
<td>
<?php
if (get_the_author_meta("trader_upload", $user->ID) > 0 && get_the_author_meta("trader_download", $user->ID) == 0){
$user_ratio .= "Inf.";
}elseif (get_the_author_meta("trader_download", $user->ID) > 0){
$user_ratio .= number_format(get_the_author_meta("trader_upload", $user->ID) / get_the_author_meta("trader_download", $user->ID), 2);
}else{
$user_ratio .= "---";
}
?>
<?php echo esc_attr( $user_ratio ); ?><br />
</td>
</tr>
<?php if( get_option('members_only') == 1 && get_option('wptrader_seed_bonus') == 1 ){ ?>
<tr>
<th>
<label for="trader_ratio"><?php _e('Seed Bonus', 'your_textdomain'); ?></label>
</th>
<td>
<?php
if ( !get_the_author_meta( 'seed_bonus', $user->ID ) ){
$user_seed_bonus = '0';
}else{
$user_seed_bonus = ''.number_format(get_the_author_meta( 'seed_bonus', $user->ID ), 2).'';
}
?>
<?php if( !current_user_can('level_10') ){ ?>
<?php echo esc_attr( $user_seed_bonus ); ?><br />
<?php }else{ ?>
<input type="text" size="10" name="seed_bonus" id="seed_bonus" value="<?php echo esc_attr( $user_seed_bonus ); ?>" /><br />
<span class="description">Edit user's seed bonus amount.</span><br />
<?php } ?>
</td>
</tr>
<?php } ?>
<?php if( get_option('members_only') == 1 && get_option('ip_passkey_tracking') == 1 ){ ?>
<tr>
<th>
<label for="trader_ratio"><?php _e('Passkey', 'your_textdomain'); ?></label>
</th>
<td>
<?php
if(!get_the_author_meta("trader_passkey", $user->ID)){
echo 'No passkey has been assigned for this account. Please download a torrent to assign one.';
}else{
echo esc_attr( get_the_author_meta("trader_passkey", $user->ID) ).'<br />';
}
?>
</td>
</tr>
<?php if((current_user_can( 'edit_user', $user_id ) && get_option('user_generate_passkey') == 1) || current_user_can('level_10')){ ?>
<tr>
<th>
<label for="reset_passkey"><?php _e('Passkey Reset', 'your_textdomain'); ?></label>
</th>
<td>
<input name="reset_passkey" value="1" type="checkbox"> Yes<br />
<span class="description">Generate a new passkey for this account. (Any active torrents must be downloaded again to continue leeching or seeding.)</span><br />
</td>
</tr>
<?php } ?>
<?php } ?>
<?php if( get_option('members_only') == 1 && current_user_can('level_10')){
$download_banned_yes = (get_option('download_banned') == 1) ? 'checked="checked"' : '';
$download_banned_no = (get_option('download_banned') == 0) ? 'checked="checked"' : '';
?>
<tr>
<th>
<label for="download_banned"><?php _e('Download Banned', 'your_textdomain'); ?></label>
</th>
<td>
<input type="radio" name="download_banned" value="0" <?php echo $download_banned_no ?> /> No <input type="radio" name="download_banned" value="1" <?php echo $download_banned_yes ?> /> Yes<br />
<span class="description">Ban the user from downloading.</span><br />
</td>
</tr>
<?php } ?>
</table>
<?php
}
function wptrader_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
update_usermeta( $user_id, 'trader_upload', $_POST['trader_upload'] );
update_usermeta( $user_id, 'trader_download', $_POST['trader_download'] );
update_usermeta( $user_id, 'download_banned', $_POST['download_banned'] );
if($_POST['reset_passkey'] == "1"){
$trader_secret = get_user_meta($user_id, 'trader_secret', true);
$rand = array_sum(explode(" ", microtime()));
$trader_passkey = md5($current_user->user_login.$rand.$trader_secret.($rand*mt_rand()));
update_usermeta( $user_id, 'trader_passkey', $trader_passkey );
}
}
add_action( 'show_user_profile', 'wptrader_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'wptrader_custom_user_profile_fields' );
add_action( 'personal_options_update', 'wptrader_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'wptrader_save_custom_user_profile_fields' );
// Add cron job to run cleanup
/*function wptrader_cron_schedule( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800, // 1 week in seconds
'display' => __( 'Once Weekly' ),
);
return $schedules;
}*/
// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'wptrader_cron_action' ) ) {
wp_schedule_event( time(), 'hourly', 'wptrader_cron_action', wptrader_cron_schedule() );
}
// Hook into that action that'll fire weekly
add_action( 'wptrader_cron_action', 'wptrader_cron_do_cleanup' );
function wptrader_cron_do_cleanup() {
require_once( WP_TRADER_ABSPATH . "/admin/function-cleanup.php" );
do_cleanup();
}
add_filter( 'cron_schedules', 'wptrader_cron_schedule' );
function wptrader_cron_schedule() {
return array( 'wptrader_cleanup_time' => array(
'interval' => get_option('cleanup_autoclean_interval'), // seconds
'display' => __( 'WP-Trader Cleanup' )
) );
}
?>