class_torrent.php TS 7.2
I have this error :
[13-Jan-2013 22:38:00 UTC] PHP Fatal error: Call to a member function get_type() on a non-object in C:\web\include\class_torrent.php on line 22
line 22 : if ($this->torrent->get_type() == 'error') {
PHP Code:
<?php
/**
*
* @ iDezender 7.0
* @ Developed by Qarizma
*
* @ Visit our website:
* @ www.iRadikal.com
* @ For cheap decoding service :)
* @ And for the ionCube Decoder!
*
*/
class Torrent {
protected $torrent = null;
protected $info = null;
var $error = null;
function load($data) {
$this->torrent = BEncode::decode( $data );
if ($this->torrent->get_type() == 'error') {
$this->error = $this->torrent->get_plain( );
return false;
}
if ($this->torrent->get_type() != 'dictionary') {
$this->error = 'The file was not a valid torrent file.';
return false;
}
$this->info = $this->torrent->get_value( 'info' );
if (!$this->info) {
$this->error = 'Could not find info dictionary.';
return false;
}
return true;
}
function getWhatever($Whatever) {
return ($this->torrent->get_value( $Whatever ) ? $this->torrent->get_value( $Whatever )->get_plain( ) : null);
}
function getComment() {
return ($this->torrent->get_value( 'comment' ) ? $this->torrent->get_value( 'comment' )->get_plain( ) : null);
}
function getCreationDate() {
return ($this->torrent->get_value( 'creation date' ) ? $this->torrent->get_value( 'creation date' )->get_plain( ) : null);
}
function getCreatedBy() {
return ($this->torrent->get_value( 'created by' ) ? $this->torrent->get_value( 'created by' )->get_plain( ) : null);
}
function getName() {
return $this->info->get_value( 'name' )->get_plain( );
}
function getPieceLength() {
return $this->info->get_value( 'piece length' )->get_plain( );
}
function getPieces() {
return $this->info->get_value( 'pieces' )->get_plain( );
}
function getPrivate() {
if ($this->info->get_value( 'private' )) {
return $this->info->get_value( 'private' )->get_plain( );
}
return 0 - 1;
}
function getFiles() {
$filelist = array( );
$length = $this->info->get_value( 'length' );
if ($length) {
//Torrent_File;
$file = new Torrent_File( );
$file->name = $this->info->get_value( 'name' )->get_plain( );
$file->length = $this->info->get_value( 'length' )->get_plain( );
array_push( $filelist, $file );
}
else {
if ($this->info->get_value( 'files' )) {
$files = $this->info->get_value( 'files' )->get_plain( );
while (list( $key, $value ) = each( $files )) {
//Torrent_File;
$file = new Torrent_File( );
$path = $value->get_value( 'path' )->get_plain( );
while (list( $key, $value2 ) = each( $path )) {
$file->name .= '/' . $value2->get_plain( );
}
$file->name = ltrim( $file->name, '/' );
$file->length = $value->get_value( 'length' )->get_plain( );
array_push( $filelist, $file );
}
}
}
return $filelist;
}
function getTrackers() {
$trackerlist = array( );
if ($this->torrent->get_value( 'announce-list' )) {
$trackers = $this->torrent->get_value( 'announce-list' )->get_plain( );
while (list( $key, $value ) = each( $trackers )) {
if (is_array( $value->get_plain( ) )) {
while (list( $key, $value2 ) = each( $value )) {
while (list( $key, $value3 ) = each( $value2 )) {
array_push( $trackerlist, $value3->get_plain( ) );
}
}
continue;
}
array_push( $trackerlist, $value->get_plain( ) );
}
}
else {
if ($this->torrent->get_value( 'announce' )) {
array_push( $trackerlist, $this->torrent->get_value( 'announce' )->get_plain( ) );
}
}
return $trackerlist;
}
function addTracker($tracker_url) {
$trackers = $this->getTrackers( );
$trackers[] = $tracker_url;
$this->setTrackers( $trackers );
}
function removeWhatever($Whatever) {
if ($this->torrent->get_value( $Whatever )) {
$this->torrent->remove( $Whatever );
}
}
function setTrackers($trackerlist) {
if (1 <= count( $trackerlist )) {
$this->torrent->remove( 'announce-list' );
//BEncode_String;
$string = new BEncode_String( $trackerlist[0] );
$this->torrent->set( 'announce', $string );
}
if (1 < count( $trackerlist )) {
//BEncode_List;
$list = new BEncode_List( );
while (list( $key, $value ) = each( $trackerlist )) {
//BEncode_List;
$list2 = new BEncode_List( );
//BEncode_String;
$string = new BEncode_String( $value );
$list2->add( $string );
$list->add( $list2 );
}
$this->torrent->set( 'announce-list', $list );
}
}
function setFiles( $filelist )
{
$length = $this->info->get_value( "length" );
if ( $length )
{
$filelist[0] = str_replace( "\\", "/", $filelist[0] );
$string = new BEncode_String( $filelist[0] );
$this->info->set( "name", $string );
return null;
}
else if ( $this->info->get_value( "files" ) )
{
$files = $this->info->get_value( "files" )->get_plain( );
$i = 0;
while ( $i < count( $files ) )
{
$file_parts = split( "/", $filelist[$i] );
$path = new BEncode_List( );
foreach ( $file_parts as $part )
{
$string = new BEncode_String( $part );
$path->add( $string );
}
$files[$i]->set( "path", $path );
++$i;
}
}
}
function setComment($value) {
$type = 'comment';
$key = $this->torrent->get_value( $type );
if ($value == '') {
$this->torrent->remove( $type );
return null;
}
if ($key) {
$key->set( $value );
return null;
}
//BEncode_String;
$string = new BEncode_String( $value );
$this->torrent->set( $type, $string );
}
function setCreatedBy($value) {
$type = 'created by';
$key = $this->torrent->get_value( $type );
if ($value == '') {
$this->torrent->remove( $type );
return null;
}
if ($key) {
$key->set( $value );
return null;
}
//BEncode_String;
$string = new BEncode_String( $value );
$this->torrent->set( $type, $string );
}
function setSource($value) {
$type = 'source';
$key = $this->torrent->get_value( $type );
if ($value == '') {
$this->torrent->remove( $type );
return null;
}
if ($key) {
$key->set( $value );
return null;
}
//BEncode_String;
$string = new BEncode_String( $value );
$this->torrent->set( $type, $string );
}
function setCreationDate($value) {
$type = 'creation date';
$key = $this->torrent->get_value( $type );
if ($value == '') {
$this->torrent->remove( $type );
return null;
}
if ($key) {
$key->set( $value );
return null;
}
//BEncode_Int;
$int = new BEncode_Int( $value );
$this->torrent->set( $type, $int );
}
function setPrivate($value) {
if ($value == 0 - 1) {
$this->info->remove( 'private' );
return null;
}
//BEncode_Int;
$int = new BEncode_Int( $value );
$this->info->set( 'private', $int );
}
function bencode() {
return $this->torrent->encode( );
}
function getHash() {
return pack( 'H*', sha1( $this->info->encode( ) ) );
}
}
class Torrent_File {
var $name = null;
var $length = null;
}
class BEncode {
function decode(&$raw, $offset = 0) {
if (strlen( $raw ) <= $offset) {
//BEncode_Error;
return new BEncode_Error( 'Decoder exceeded max length.' );
}
$char = $raw[$offset];
switch ($char) {
case 'i': {
//BEncode_Int;
$int = new BEncode_Int( );
$int->decode( $raw, $offset );
$int;
}
}
return ;
}
}
class BEncode_End {
function get_type() {
return 'end';
}
}
class BEncode_Error {
protected $error = null;
function BEncode_Error($error) {
$this->error = $error;
}
function get_plain() {
return $this->error;
}
function get_type() {
return 'error';
}
}
class BEncode_Int {
protected $value = null;
function BEncode_Int($value = null) {
$this->value = $value;
}
function decode(&$raw, $offset) {
$end = strpos( $raw, 'e', $offset );
$this->value = substr( $raw, ++$offset, $end - $offset );
$offset += $end - $offset;
}
function get_plain() {
return $this->value;
}
function get_type() {
return 'int';
}
function encode() {
return '' . 'i' . $this->value . 'e';
}
function set($value) {
$this->value = $value;
}
}
class BEncode_Dictionary {
var $value = array( );
function decode(&$raw, $offset) {
$dictionary = array( );
while (true) {
$name = BEncode::decode( $raw, ++$offset );
if ($name->get_type( ) == 'end') {
break;
}
if ($name->get_type( ) == 'error') {
return $name;
}
if ($name->get_type( ) != 'string') {
//BEncode_Error;
return new BEncode_Error( 'Key name in dictionary was not a string.' );
}
$value = BEncode::decode( $raw, ++$offset );
if ($value->get_type( ) == 'error') {
return $value;
}
$dictionary[$name->get_plain( )] = $value;
}
$this->value = $dictionary;
}
function get_value($key) {
if (isset( $this->value[$key] )) {
return $this->value[$key];
}
return null;
}
function encode() {
$this->sort( );
$encoded = 'd';
while (list( $key, $value ) = each( $this->value )) {
//BEncode_String;
$bstr = new BEncode_String( );
$bstr->set( $key );
$encoded .= $bstr->encode( );
$encoded .= $value->encode( );
}
$encoded .= 'e';
return $encoded;
}
function get_type() {
return 'dictionary';
}
function remove($key) {
unset( $this->value[$key] );
}
function set($key, $value) {
$this->value[$key] = $value;
}
function sort() {
ksort( $this->value );
}
function count() {
return count( $this->value );
}
}
class BEncode_List {
protected $value = array( );
function add($bval) {
array_push( $this->value, $bval );
}
function decode(&$raw, $offset) {
$list = array( );
while (true) {
$value = BEncode::decode( $raw, ++$offset );
if ($value->get_type( ) == 'end') {
break;
}
if ($value->get_type( ) == 'error') {
return $value;
}
array_push( $list, $value );
}
$this->value = $list;
}
function encode() {
$encoded = 'l';
$i = 0;
while ($i < count( $this->value )) {
$encoded .= $this->value[$i]->encode( );
++$i;
}
$encoded .= 'e';
return $encoded;
}
function get_plain() {
return $this->value;
}
function get_type() {
return 'list';
}
}
class BEncode_String {
protected $value = null;
function BEncode_String($value = null) {
$this->value = $value;
}
function decode(&$raw, $offset) {
$end = strpos( $raw, ':', $offset );
$len = substr( $raw, $offset, $end - $offset );
$offset += $len + ( $end - $offset );
++$end;
$this->value = substr( $raw, $end, $len );
}
function get_plain() {
return $this->value;
}
function get_type() {
return 'string';
}
function encode() {
$len = strlen( $this->value );
return '' . $len . ':' . $this->value;
}
function set($value) {
$this->value = $value;
}
}
if (!defined( 'IN_TRACKER' )) {
exit( '<font face=\'verdana\' size=\'2\' color=\'darkred\'><b>Error!</b> Direct initialization of this file is not allowed.</font>' );
}
?>
Bump: pls help !