Browse Source

Version 1.1

new:
    - option: list or table view
    - option: show seeders
    - option: show leechers
    - translation: all translated to english
    - translation: bug fixes
master
Vladimir Smagin 4 years ago
parent
commit
8ff033314e
2 changed files with 124 additions and 22 deletions
  1. 83
    20
      torrent_tracker.php
  2. 41
    2
      torrent_tracker_adm.php

+ 83
- 20
torrent_tracker.php View File

@@ -4,11 +4,11 @@
Plugin Name: 21h Torrent Tracker
Text Domain: blindage.org
Domain Path: /
Plugin URI: http://blindage.org
Plugin URI: http://blindage.org/?p=7686
Description: Torrent tracker
Author: Vladimir Smagin
Author URI: http://blindage.org/
Version: 1.0
Version: 1.1
License: GPL
Donate URI: http://blindage.org
*/
@@ -60,10 +60,13 @@ function ttdb_install() {
add_option("21h_torrent_tracker_db_version", "1.0");
add_option('21h_torrent_tracker', array(
"torrents_per_page" => 0,
"viewas" => 'checked',
"showseed" => 'checked',
"showleech" => 'checked',
"cachetime" => 600,
"html_before" => "<div id='torrent_list'>",
"html_after" => "</div>",
"html_tracker_title" => "<h3>Torrents on this site</h3>",
"html_tracker_title" => "<h3>All torrent files</h3>",
"html_in_post_tracker_title" => "<h3>All torrent files in this post</h3>"
));
}
@@ -71,13 +74,13 @@ function ttdb_install() {
function ttdb_select_all() {
global $wpdb;
$table_name = $wpdb->prefix . 'torrent_tracker';
return $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A);
return $wpdb->get_results("SELECT * FROM $table_name order by title asc", ARRAY_A);
}

function ttdb_select_id($id) {
global $wpdb;
$table_name = $wpdb->prefix . 'torrent_tracker';
return $wpdb->get_results("SELECT * FROM $table_name where file_id=$id", ARRAY_A);
return $wpdb->get_results("SELECT * FROM $table_name where file_id=$id order by title asc", ARRAY_A);
}

function ttdb_insert($data) {
@@ -166,7 +169,12 @@ function torrent_edit_attachment($post_ID) {
ttdb_update($post_ID, $data);
}

function generateTrackerHTML() {
function selectFormOfView() {
$options = get_option('21h_torrent_tracker');
if (isset($options['viewas'])) { return generateTrackerHTMLasTable(); } else { return generateTrackerHTMLasList(); }
}

function generateTrackerHTMLasList() {
$options = get_option('21h_torrent_tracker');
$torrents = ttdb_select_all();
$htmlcode = $options['html_before'];
@@ -196,12 +204,10 @@ function generateTrackerHTML() {
);
ttdb_update($torrent['file_id'], $data);
$htmlcode.="<li>";
//$htmlcode.=var_export($torrent, true);
//$htmlcode.=var_export($scrape_data, true);
$htmlcode.="<a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a>: ";
$htmlcode.="(" . $torrent['size_mb'] . " Мб) ";
$htmlcode.="Раздают: " . $seeders;
$htmlcode.=" <span style = 'color:silver'>Неполностью: " . $leechers . "</span>";
$htmlcode.="<a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a> ";
$htmlcode.=" (" . $torrent['size_mb'] . " Mb) ";
if (isset($options['showseed'])) $htmlcode.="<span class='tt_seeds'>Seeders: $seeders</span> ";
if (isset($options['showleech'])) $htmlcode.="<span class='tt_leech'>Leechers: $leechers</span> ";
$htmlcode.="</li>";
}
} else {
@@ -209,13 +215,12 @@ function generateTrackerHTML() {
$scrape_data = bdecode($torrent_file_contents);
$seeders = $torrent['seeders'];
$leechers = $torrent['leechers'];
$htmlcode.="<li>";
//$htmlcode.=var_export($torrent, true);
$htmlcode.="<a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a>: ";
$htmlcode.="(" . $torrent['size_mb'] . " Мб) ";
$htmlcode.="Раздают: " . $seeders;
$htmlcode.=" <span style = 'color:silver'>Неполностью: " . $leechers . "</span>";
$htmlcode.="</li>";
$htmlcode.="<li>";
$htmlcode.="<a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a> ";
$htmlcode.=" (" . $torrent['size_mb'] . " Mb) ";
if (isset($options['showseed'])) $htmlcode.="<span class='tt_seeds'>Seeders: $seeders</span> ";
if (isset($options['showleech'])) $htmlcode.="<span class='tt_leech'>Leechers: $leechers</span> ";
$htmlcode.="</li>";
}
}
$htmlcode.="</ol>";
@@ -223,6 +228,64 @@ function generateTrackerHTML() {
return $htmlcode;
}

function generateTrackerHTMLasTable() {
$options = get_option('21h_torrent_tracker');
$torrents = ttdb_select_all();
$htmlcode = $options['html_before'];
$htmlcode.= $options['html_tracker_title'];
$htmlcode.="<table border='1' cellspacing='1'>";
$htmlcode.="<tr><th>Title</th><th>Size (Mb)</th>";
if (isset($options['showseed'])) $htmlcode.="<th>Seeders</th>";
if (isset($options['showleech'])) $htmlcode.="<th>Leechers</th>";
$htmlcode.="</tr>";
foreach ($torrents as $torrent) {
if (time() - strtotime($torrent['cached']) > $options['cachetime']) {
$scrape_url = $torrent['scrape'] . '?info_hash=' . urlencode(base64_decode($torrent['sha1']));

if (($torrent_file_contents = @file_get_contents($scrape_url)) === FALSE) {
//tracker not available
} else {
$sha1 = base64_decode($torrent['sha1']);
$scrape_data = bdecode($torrent_file_contents);

if (isset($scrape_data['files'][$sha1]['complete'])) {
$seeders = $scrape_data['files'][$sha1]['complete'];
$leechers = $scrape_data['files'][$sha1]['incomplete'];
} else {
$seeders = $scrape_data['complete'];
$leechers = $scrape_data['incomplete'];
}
$data = array(
'seeders' => $seeders,
'leechers' => $leechers,
'cached' => date('Y-m-d H:i:s')
);
ttdb_update($torrent['file_id'], $data);
$htmlcode.="<tr>";
$htmlcode.="<td><a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a></td>";
$htmlcode.="<td>" . $torrent['size_mb'] . "</td>";
if (isset($options['showseed'])) $htmlcode.="<td>$seeders</td>";
if (isset($options['showleech'])) $htmlcode.="<td>$leechers</td>";
$htmlcode.="</tr>";
}
} else {
$sha1 = base64_decode($torrent['sha1']);
$scrape_data = bdecode($torrent_file_contents);
$seeders = $torrent['seeders'];
$leechers = $torrent['leechers'];
$htmlcode.="<tr>";
$htmlcode.="<td><a href = '" . $torrent['url'] . "' > " . $torrent['title'] . "</a></td>";
$htmlcode.="<td>" . $torrent['size_mb'] . "</td>";
if (isset($options['showseed'])) $htmlcode.="<td>$seeders</td>";
if (isset($options['showleech'])) $htmlcode.="<td>$leechers</td>";
$htmlcode.="</tr>";
}
}
$htmlcode.="</table>";
$htmlcode.=$options['html_after'];
return $htmlcode;
}

function generateTrackerPostHTML() {
$post_ID = $GLOBALS['post']->ID;
$options = get_option('21h_torrent_tracker');
@@ -287,7 +350,7 @@ function generateTrackerPostHTML() {

function replace_content(
$content) {
$content = str_replace('<!-- TorrentTracker -->', generateTrackerHTML(), $content);
$content = str_replace('<!-- TorrentTracker -->', selectFormOfView(), $content);
$content = str_replace('<!-- TorrentTrackerPost -->', generateTrackerPostHTML(), $content);
return $content;
}

+ 41
- 2
torrent_tracker_adm.php View File

@@ -40,6 +40,17 @@ class TTSettingsPage {
'setting_section_id', 'View settings', array($this, 'print_section_info1'), 'tt-setting-admin'
);

add_settings_field(
'viewas', 'View list as table', array($this, 'viewas_callback'), 'tt-setting-admin', 'setting_section_id'
);

add_settings_field(
'showseed', 'Show seeders', array($this, 'showseed_callback'), 'tt-setting-admin', 'setting_section_id'
);

add_settings_field(
'showleech', 'Show leechers', array($this, 'showleech_callback'), 'tt-setting-admin', 'setting_section_id'
);

add_settings_field(
'torrents_per_page', 'Torrents per page (0 for all in one page)', array($this, 'torrents_per_page_callback'), 'tt-setting-admin', 'setting_section_id'
@@ -58,7 +69,7 @@ class TTSettingsPage {
'html_tracker_title', 'Tracker title', array($this, 'html_tracker_title_callback'), 'tt-setting-admin', 'setting_section_id'
);
add_settings_field(
'html_in_post_tracker_title', 'In post tracker title', array($this, 'html_in_post_tracker_title_callback'), 'tt-setting-admin', 'setting_section_id'
'html_in_post_tracker_title', 'In-post tracker title', array($this, 'html_in_post_tracker_title_callback'), 'tt-setting-admin', 'setting_section_id'
);
}

@@ -67,6 +78,15 @@ class TTSettingsPage {
if (isset($input['torrents_per_page']))
$new_input['torrents_per_page'] = absint($input['torrents_per_page']);

if (isset($input['viewas']))
$new_input['viewas'] = 'checked';

if (isset($input['showseed']))
$new_input['showseed'] = 'checked';

if (isset($input['showleech']))
$new_input['showleech'] = 'checked';

if (isset($input['cachetime']))
$new_input['cachetime'] = absint($input['cachetime']);

@@ -86,7 +106,7 @@ class TTSettingsPage {
}

public function print_section_info1() {
print 'Check write permissions to plugin directory if something goes wrong. Updates and support only <a href="http://blindage.org/?p=7686">here</a>.';
print 'Check write permissions to plugin directory if something goes wrong. Updates and support only <a href="http://blindage.org/?p=7686">here</a>.';//.esc_attr(print_r($this->options,true));
}

public function torrents_per_page_callback() {
@@ -94,6 +114,25 @@ class TTSettingsPage {
'<input type="text" id="torrents_per_page" name="21h_torrent_tracker[torrents_per_page]" value="%s" style="width:50px" />', isset($this->options['torrents_per_page']) ? esc_attr($this->options['torrents_per_page']) : ''
);
}

public function viewas_callback() {
printf(
'<input type="checkbox" id="viewas" name="21h_torrent_tracker[viewas]" %s />', isset($this->options['viewas']) ? esc_attr($this->options['viewas']) : ''
);
}

public function showseed_callback() {
printf(
'<input type="checkbox" id="showseed" name="21h_torrent_tracker[showseed]" %s />', isset($this->options['showseed']) ? esc_attr($this->options['showseed']) : ''
);
}

public function showleech_callback() {
printf(
'<input type="checkbox" id="showleech" name="21h_torrent_tracker[showleech]" %s />', isset($this->options['showleech']) ? esc_attr($this->options['showleech']) : ''
);
}

public function cachetime_callback() {
printf(
'<input type="text" id="cachetime" name="21h_torrent_tracker[cachetime]" value="%s" style="width:50px" />', isset($this->options['cachetime']) ? esc_attr($this->options['cachetime']) : ''

Loading…
Cancel
Save