Changeset 51

Show
Ignore:
Timestamp:
03/05/08 10:32:31 (8 months ago)
Author:
royger
Message:

* New xmlrpc factory, 2 classes added:

  • torrent.cls.php
  • multicall.cls.php

Every torrent creates a torrent object, which contains the functions for calling all the necessary methods. Also a transparent cache was added.

* Cleaned most of the classes of unnecessary php code.
* Command interface finished, most actions are done through AJAX calls using the Commands.cls.php class. Fixes #16.
* This build is tested to work with Mozilla Firefox 2.0.0.14 and Safari 3.1.1 (5525.18) using Mac OS X. Same results expected (although not tested) under Windows.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wtorrent/cls/rtorrent.cls.php

    r49 r51  
    2121{ 
    2222        protected $client; 
     23        protected $multicall; 
     24        protected $torrents; 
     25        protected $data; 
     26         
    2327        private $menu = array('Main' => 'ListT', 
    2428                                                'Add Torrent' => 'AddT', 
     
    3640    /////////////////////////////////// C O N S T R U C T O R A S  Y  D E S T R U C T O R A /////////////////////////////////// 
    3741 
    38     public function __construct( ) 
    39     { 
    40         parent::__construct( ); 
    41         if(isset($this->_request['logout'])) $this->logout(); 
    42         if(isset($this->_request['user_login'])) $this->login($this->_request['userf'], $this->_request['passwdf']); 
    43     } 
    44  
    45     protected function construct( ){} 
    46  
    47          
     42        public function __construct( ) 
     43        { 
     44                parent::__construct( ); 
     45                if(isset($this->_request['logout'])) $this->logout(); 
     46                if(isset($this->_request['user_login'])) $this->login($this->_request['userf'], $this->_request['passwdf']); 
     47        } 
     48        private function checkError($result) 
     49        { 
     50                if($result->errno == '0') 
     51                        return true; 
     52                else 
     53                        return false; 
     54        } 
     55        protected function construct( ){} 
    4856 
    4957        public function registrado( ) 
    5058        { 
    51                 return !is_null( $this->_sesion->id_user ); 
     59                       return !is_null( $this->_sesion->id_user ); 
    5260        } 
    5361        public function compLogin($user, $passwd) 
    54    
     62       
    5563                $passwd = md5($passwd); 
    5664                $sql = "select id from tor_passwd where user = '$user' and passwd = '$passwd'"; 
     
    5967                { 
    6068                        $num = $result->numRows(); 
    61                  
     69 
    6270                        if($num > 0) 
    6371                                $return = $result->current(); 
    6472                        else 
    6573                                $return = false; 
    66                  
    67                 } else { 
    68                                 $return = false; 
    69                 } 
    70                 return $return; 
    71     } 
     74                } else { 
     75                        $return = false; 
     76                } 
     77                return $return; 
     78        } 
    7279        public function getUser( ) 
    7380        { 
    7481                return $this->_sesion->user; 
    7582        } 
    76  
    7783        public function getIdUser( ) 
    7884        { 
     
    108114                return $return; 
    109115        } 
    110          
    111  
    112116        public function login( $user, $password ) 
    113117        {        
     
    137141                } 
    138142        } 
     143        private function getPrivate() 
     144        { 
     145                $tt = array(); 
     146                $sql = "select hash, user from torrents"; 
     147                $result = $this->_db->query($sql); 
     148                $torr = $result->fetchAll(); 
     149                foreach($torr as $torrent) 
     150                        $tt[$torrent['hash']] = $torrent['user']; 
     151                         
     152                return $tt; 
     153        } 
    139154        public function setClient() 
    140155        { 
    141156                $this->client = new xmlrpc_client(RT_DIR, RT_HOST, RT_PORT); 
    142                 //$this->client->setDebug(2); 
     157                $this->multicall = new multicall($this->client, $this->data); 
     158 
    143159                if(RT_AUTH) 
    144160                        $this->client->setCredentials(RT_USER, RT_PASSWD); 
    145         $this->client->return_type = 'phpvals'; 
    146         $this->client->no_multicall = NO_MULTICALL; 
     161     
     162                $this->client->return_type = 'phpvals'; 
     163    $this->client->no_multicall = NO_MULTICALL; 
    147164         
    148        $message = new xmlrpcmsg("system.pid"); 
    149                 $result = $this->client->send($message); 
    150                 // print_r($result); 
     165    $message = new xmlrpcmsg("system.pid"); 
     166                $result = $this->client->send($message); 
     167 
    151168                if($result->errno != 0) 
    152169                { 
    153170                        $this->addMessage($this->_str['err_conn']); 
    154171                        return false; 
    155                 } else 
     172                } else { 
     173                        $this->setTorrents(); 
    156174                        return true; 
     175                } 
     176        } 
     177        /* Initializes torrent objects */ 
     178        protected function setTorrents() { 
     179                $message = new xmlrpcmsg("d.multicall", array(new xmlrpcval('default', 'string'),new xmlrpcval('d.get_hash=', 'string'))); 
     180                $result = $this->client->send($message); 
     181                if(is_array($result->val)) 
     182                { 
     183                        foreach($result->val as $hash) 
     184                        { 
     185                                $this->torrents[$hash[0]] = new torrent($hash[0], $this->client, $this->multicall, $this->data[$hash[0]]); 
     186                        } 
     187                        /* Mark torrents as public/private and assign owners */ 
     188                        $private_torrents = $this->getPrivate(); 
     189                        $hashes = $this->getHashes(); 
     190                        foreach($hashes as $hash) 
     191                        { 
     192                                if(array_key_exists($hash, $private_torrents)) 
     193                                { 
     194                                        $this->data[$hash]['private'] = true; 
     195                                        $this->data[$hash]['owner'] = $private_torrents[$hash]; 
     196                                } else { 
     197                                        $this->data[$hash]['private'] = false; 
     198                                        $this->data[$hash]['owner'] = 0; 
     199                                } 
     200                        } 
     201                } 
     202        } 
     203        protected function getHashes() 
     204        { 
     205                return array_keys($this->torrents); 
     206        } 
     207        protected function erase_db($hash) 
     208        { 
     209                $sql = "delete from torrents where hash = '" . $hash . "'"; 
     210                $this->_db->query($sql); 
    157211        } 
    158212        protected function setPerm() 
    159213        { 
    160214                $this->admin = false; 
     215        } 
     216        /* xmlrpc rtorrent admin functions (not torrent related ) */ 
     217        protected function set_download_rate($limit) 
     218        { 
     219                $message = new xmlrpcmsg("set_download_rate", array(new xmlrpcval($limit, 'int'))); 
     220                $result = $this->client->send($message); 
     221                 
     222                if($this->checkError($result)) 
     223                { 
     224                        $return = true; 
     225                } else { 
     226                        $return = false; 
     227                } 
     228                return $return; 
     229        } 
     230        protected function set_upload_rate($limit) 
     231        { 
     232                $message = new xmlrpcmsg("set_download_rate", array(new xmlrpcval($limit, 'int'))); 
     233                $result = $this->client->send($message); 
     234                 
     235                if($this->checkError($result)) 
     236                { 
     237                        $return = true; 
     238                } else { 
     239                        $return = false; 
     240                } 
     241                return $return; 
    161242        } 
    162243} 
  • trunk/wtorrent/home/cls/Commands.cls.php

    r36 r51  
    1818class Commands extends rtorrent 
    1919{ 
    20     /////////////////////////////////// C O N S T R U C T O R A S  Y  D E S T R U C T O R A /////////////////////////////////// 
     20        public function construct() 
     21        { 
     22                if(isset($this->_request['command']) && $this->_request['command'] != '' && isset($this->_request['param']) && $this->_request['param'] != '')  
     23                { 
     24                        if(!$this->setClient()) 
     25                                return false; 
    2126 
    22     public function construct() 
    23         { 
    24         if(isset($this->_request['command']) && $this->_request['command'] != '' && isset($this->_request['param']) && $this->_request['param'] != '')  
    25         { 
    26                 if(!$this->setClient()) 
    27                         return false; 
    28                          
    29                 switch($this->_request['command']) 
    30                 { 
    31                         case 'start': 
    32                                 $this->start($this->_request['param']); 
    33                                 break; 
    34                         case 'stop': 
    35                                 $this->stop($this->_request['param']); 
    36                                 break; 
    37                         case 'close': 
    38                                 $this->close($this->_request['param']); 
    39                                 break; 
    40                         case 'erase': 
    41                                 $this->erase($this->_request['param']); 
    42                                 break; 
    43                         case 'chash': 
    44                                 $this->chash($this->_request['param']); 
    45                                 break; 
    46                         case 'set_down_limit': 
    47                                 $this->setDownLimit($this->_request['param']); 
    48                                 break; 
    49                         case 'set_up_limit': 
    50                                 $this->setUploadLimit($this->_request['param']); 
    51                                 break; 
    52                         case 'files': 
    53                                 $this->changeFiles($this->_request['param'], $this->_request['param1'], $this->_request['param2']); 
    54                                 break; 
    55                         case 'info': 
    56                                 $this->changePriority($this->_request['param'], $this->_request['param1']); 
    57                                 break; 
    58                         case 'trackers': 
    59                                 $this->changeTrackers($this->_request['param'], $this->_request['param1'], $this->_request['param2']); 
    60                                 break; 
    61                         default: 
    62                                 $this->addMessage($this->_str['command_error']); 
    63                                 break; 
    64                                  
    65                 } 
    66         } else { 
    67                 $this->addMessage($this->_str['command_error']); 
    68         } 
     27                        switch($this->_request['command']) 
     28                        { 
     29                                case 'start': 
     30                                $this->start($this->_request['param']); 
     31                                break; 
     32                                case 'stop': 
     33                                $this->stop($this->_request['param']); 
     34                                break; 
     35                                case 'close': 
     36                                $this->close($this->_request['param']); 
     37                                break; 
     38                                case 'erase': 
     39                                $this->erase($this->_request['param']); 
     40                                break; 
     41                                case 'chash': 
     42                                $this->chash($this->_request['param']); 
     43                                break; 
     44                                case 'set_down_limit': 
     45                                $this->setDownLimit($this->_request['param']); 
     46                                break; 
     47                                case 'set_up_limit': 
     48                                $this->setUploadLimit($this->_request['param']); 
     49                                break; 
     50                                case 'files': 
     51                                $this->changeFiles($this->_request['param'], $this->_request['param1'], $this->_request['param2']); 
     52                                break; 
     53                                case 'info': 
     54                                $this->changePriority($this->_request['param'], $this->_request['param1']); 
     55                                break; 
     56                                case 'trackers': 
     57                                $this->changeTrackers($this->_request['param'], $this->_request['param1'], $this->_request['param2']); 
     58                                break; 
     59                                default: 
     60                                $this->addMessage($this->_str['command_error']); 
     61                                break; 
     62 
     63                        } 
     64                } else { 
     65                        $this->addMessage($this->_str['command_error']); 
     66                } 
    6967        } 
    7068        private function stop($hashes) 
     69        { 
     70                $hashes = explode('~', $hashes); 
     71                if(!is_array($hashes)) 
     72                        $hashes = array($hashes); 
     73 
     74                foreach($hashes as $hash) 
     75                { 
     76                        $this->torrents[$hash]->stop(true); 
     77                } 
     78                $this->multicall->call(); 
     79 
     80                $this->addMessage($this->_str['info_tor_stop']); 
     81        } 
     82        private function close($hashes) 
     83        { 
     84                $hashes = explode('~', $hashes); 
     85                if(!is_array($hashes)) 
     86                        $hashes = array($hashes); 
     87 
     88                foreach($hashes as $hash) 
     89                { 
     90                        $this->torrents[$hash]->close(true); 
     91                } 
     92                $this->multicall->call(); 
     93 
     94                $this->addMessage($this->_str['info_tor_close']); 
     95        } 
     96        private function chash($hashes) 
     97        { 
     98                $hashes = explode('~', $hashes); 
     99        if(!is_array($hashes)) 
     100                $hashes = array($hashes); 
     101         
     102        foreach($hashes as $hash) 
     103        { 
     104                $this->torrents[$hash]->check_hash(true); 
     105        } 
     106                $this->multicall->call(); 
     107         
     108        $this->addMessage($this->_str['info_tor_chash']); 
     109        } 
     110        private function start($hashes) 
     111        { 
     112                $hashes = explode('~', $hashes); 
     113        if(!is_array($hashes)) 
     114                $hashes = array($hashes); 
     115         
     116        foreach($hashes as $hash) 
     117        { 
     118                $this->torrents[$hash]->start(true); 
     119        } 
     120                $this->multicall->call(); 
     121         
     122        $this->addMessage($this->_str['info_tor_start']); 
     123        } 
     124  private function erase($hashes) 
     125        { 
     126        $hashes = explode('~', $hashes); 
     127    if(!is_array($hashes)) 
     128        $hashes = array($hashes); 
     129         
     130    foreach($hashes as $hash) 
    71131    { 
    72         $hashes = explode('~', $hashes); 
    73         if(!is_array($hashes)) 
    74                $hashes = array($hashes); 
     132        $this->torrents[$hash]->erase(); 
     133                        $this->erase_db($hash); 
     134    } 
    75135         
    76         foreach($hashes as $hash) 
    77         { 
    78                 $message = new xmlrpcmsg("d.stop", array(new xmlrpcval($hash, 'string'))); 
    79                 $result = $this->client->send($message); 
    80         } 
    81          
    82         $this->addMessage($this->_str['info_tor_stop']); 
    83     } 
    84     private function close($hashes) 
    85     { 
    86         $hashes = explode('~', $hashes); 
    87         if(!is_array($hashes)) 
    88                 $hashes = array($hashes); 
    89          
    90         foreach($hashes as $hash) 
    91         { 
    92                 $message = new xmlrpcmsg("d.close", array(new xmlrpcval($hash, 'string'))); 
    93                 $result = $this->client->send($message); 
    94         } 
    95          
    96         $this->addMessage($this->_str['info_tor_close']); 
    97     } 
    98     private function chash($hashes) 
    99     { 
    100         $hashes = explode('~', $hashes); 
    101         if(!is_array($hashes)) 
    102                 $hashes = array($hashes); 
    103          
    104         foreach($hashes as $hash) 
    105         { 
    106                 $message = new xmlrpcmsg("d.check_hash", array(new xmlrpcval($hash, 'string'))); 
    107                 $result = $this->client->send($message); 
    108         } 
    109          
    110         $this->addMessage($this->_str['info_tor_chash']); 
    111     } 
    112     private function start($hashes) 
    113     { 
    114         $hashes = explode('~', $hashes); 
    115         if(!is_array($hashes)) 
    116                 $hashes = array($hashes); 
    117          
    118         foreach($hashes as $hash) 
    119         { 
    120                 $message = new xmlrpcmsg("d.start", array(new xmlrpcval($hash, 'string'))); 
    121                         $result = $this->client->send($message); 
    122         } 
    123          
    124         $this->addMessage($this->_str['info_tor_start']); 
    125     } 
    126     private function erase($hashes) 
    127     { 
    128         $hashes = explode('~', $hashes); 
    129         if(!is_array($hashes)) 
    130                 $hashes = array($hashes); 
    131          
    132         foreach($hashes as $hash) 
    133         { 
    134                 $message = new xmlrpcmsg("d.erase", array(new xmlrpcval($hash, 'string'))); 
    135                         $result = $this->client->send($message); 
    136                         $sql = "delete from torrents where hash = '" . $hash . "'"; 
    137                         $this->_db->query($sql); 
    138         } 
    139          
    140         $this->addMessage($this->_str['info_tor_erase']); 
    141     } 
    142     private function setDownLimit($limit) 
    143     { 
    144         $message = new xmlrpcmsg("set_download_rate", array(new xmlrpcval($limit*1024, 'int'))); 
    145                 $result = $this->client->send($message); 
    146                 //print_r($result); 
    147                 if($result->errno == 0) 
     136    $this->addMessage($this->_str['info_tor_erase']); 
     137        } 
     138        private function setDownLimit($limit) 
     139        { 
     140        $result = $this->set_download_rate($limit*1024); 
     141                if($result) 
    148142                        $this->addMessage($this->_str['info_down_limit']); 
    149143                else 
    150144                        $this->addMessage($this->_str['err_down_limit']);        
    151     } 
    152     private function setUploadLimit($limit) 
    153     { 
    154         $message = new xmlrpcmsg("set_upload_rate", array(new xmlrpcval($limit*1024, 'int'))); 
    155                 $result = $this->client->send($message); 
    156                 if($result->errno == 0) 
    157                         $this->addMessage($this->_str['info_up_limit']); 
     145        } 
     146  private function setUploadLimit($limit) 
     147        { 
     148        $result = $this->set_upload_rate($limit*1024); 
     149                if($result) 
     150                        $this->addMessage($this->_str['info_down_limit']); 
    158151                else 
    159                         $this->addMessage($this->_str['err_up_limit']);         
    160    
    161     private function changeFiles($hash, $priority, $files) 
    162    
    163       $files = explode('~', $files); 
     152                        $this->addMessage($this->_str['err_down_limit']); 
     153       
     154  private function changeFiles($hash, $priority, $files) 
     155       
     156              $files = explode('~', $files); 
    164157         
    165       foreach($files as $param) 
    166                         $array_post[] = new xmlrpcmsg('f.set_priority', array(new xmlrpcval($hash, 'string'), new xmlrpcval($param, 'int'), new xmlrpcval($priority, 'int'))); 
     158              foreach($files as $param) 
     159                        $this->torrents[$hash]->f_set_priority($param, $priority, true); 
    167160                 
    168                 $result = $this->client->multicall($array_post); 
     161                $result = $this->multicall->call(); 
    169162                 
    170                 if($result->errno == 0
     163                if($result
    171164                        $this->addMessage($this->_str['info_ch_files']); 
    172165                else 
    173166                        $this->addMessage($this->_str['err_ch_files']); 
    174167                          
    175                 $mesage = new xmlrpcmsg('d.update_priorities', array(new xmlrpcval($hash, 'string'))); 
    176                 $this->client->send($mesage); 
    177     } 
    178     private function changePriority($hash, $priority) 
    179     { 
    180         $message = new xmlrpcmsg("d.set_priority", array(new xmlrpcval($hash, 'string'), new xmlrpcval($priority, 'int'))); 
    181                 $result = $this->client->send($message); 
    182                 if($result->errno == 0) 
     168                $this->torrents[$hash]->update_priorities(); 
     169        } 
     170  private function changePriority($hash, $priority) 
     171        { 
     172                $result = $this->torrents[$hash]->d_set_priority($priority); 
     173                 
     174                if($result) 
    183175                        $this->addMessage($this->_str['info_pr']); 
    184         else  
    185                 $this->addMessage($this->_str['err_pr']); 
    186     } 
    187     private function changeTrackers($hash, $enabled, $t_index) 
    188     { 
    189         $t_index = explode('~', $t_index); 
    190         //print_r($f_index); 
     176    else  
     177                        $this->addMessage($this->_str['err_pr']); 
     178        } 
     179  private function changeTrackers($hash, $enabled, $trackers) 
     180        { 
     181                $trackers = explode('~', $trackers); 
    191182         
    192        foreach($t_index as $param) 
    193                         $array_post[] = new xmlrpcmsg('t.set_enabled', array(new xmlrpcval($hash, 'string'), new xmlrpcval($param, 'int'), new xmlrpcval($enabled, 'int'))); 
     183               foreach($trackers as $param) 
     184                        $this->torrents[$hash]->t_set_enabled($param, $enabled, true); 
    194185                 
    195                 //print_r($array_post);         
    196                 $responses = $this->client->multicall($array_post); 
     186                $this->multicall->call(); 
     187                 
    197188                $this->addMessage($this->_str['info_ch_trackers']); 
    198    
     189       
    199190} 
    200191?> 
  • trunk/wtorrent/home/cls/Feeds.cls.php

    r4 r51  
    1818class Feeds extends rtorrent 
    1919{ 
    20         /*private  $torrents; 
    21     private  $info_dowload = array('default',  
    22                                                         'd.get_hash=',  
    23                                                         'd.get_name=', 
    24                                                                 'd.get_down_rate=', 
    25                                                                 'd.get_up_rate=', 
    26                                                                 'd.get_chunk_size=', 
    27                                                                 'd.get_completed_chunks=', 
    28                                                                 'd.get_size_chunks=', 
    29                                                                 'd.get_state=', 
    30                                                                 'd.get_peers_accounted=', 
    31                                                                 'd.get_peers_complete=', 
    32                                                                 'd.is_hash_checking=', 
    33                                                                 'd.get_ratio=', 
    34                                                                 'd.get_tracker_size='); 
    35         private $info_tracker = array('', 
    36                                                                 "", 
    37                                                                 't.get_scrape_complete=', 
    38                                                                 't.get_scrape_incomplete=');*/ 
    3920        private $info = array(); 
    4021        private $feeds = array(); 
    4122        private $view_feed = false; 
    4223 
    43     public function construct() 
     24       public function construct() 
    4425        { 
    4526                if(!$this->setClient()) 
     
    9172                        $this->feeds[$i]['feed'] = new SimplePie(); 
    9273                        $this->feeds[$i]['feed']->set_feed_url($result[$i]['url']); 
    93                         $this->feeds[$i]['feed']->set_cache_location(DIR_TPL_COMPILE); 
     74                        $this->feeds[$i]['feed']->set_cache_location(rtrim(DIR_TPL_COMPILE, '/')); 
    9475                        $this->feeds[$i]['feed']->init(); 
    9576                        $this->feeds[$i]['feed']->handle_content_type(); 
     
    141122                return $this->info[$index]['title']; 
    142123        } 
    143         public function getUpLimit() 
    144         { 
    145                 $message = new xmlrpcmsg("get_upload_rate"); 
    146                 $result = $this->client->send($message); 
    147                 return round($result->val/1024, 1); 
    148         } 
    149         public function getDownLimit() 
    150         { 
    151                 $message = new xmlrpcmsg("get_download_rate"); 
    152                 $result = $this->client->send($message); 
    153                 return round($result->val/1024, 1); 
    154         } 
    155         public function getName($hash) 
    156         { 
    157                 return $this->torrents[$hash]['name']; 
    158         } 
    159         public function getDownRate($hash) 
    160         { 
    161                 return $this->torrents[$hash]['down_rate']; 
    162         } 
    163         public function getUpRate($hash) 
    164         { 
    165                 return $this->torrents[$hash]['up_rate']; 
    166         } 
    167         public function getState($hash) 
    168         { 
    169                 return $this->torrents[$hash]['state']; 
    170         } 
    171         public function getConnPeers($hash) 
    172         { 
    173                 return $this->torrents[$hash]['peers']; 
    174         } 
    175         public function getConnSeeds($hash) 
    176         { 
    177                 return $this->torrents[$hash]['seeds']; 
    178         } 
    179         public function getTotalPeers($hash) 
    180         { 
    181                 return $this->torrents[$hash]['peers_scrape']; 
    182         } 
    183         public function getTotalSeeds($hash) 
    184         { 
    185                 return $this->torrents[$hash]['seeds_scrape']; 
    186         } 
    187         public function getPercent($hash) 
    188         { 
    189                 return $this->torrents[$hash]['percent']; 
    190         } 
    191         public function getRatio($hash) 
    192         { 
    193                 return $this->torrents[$hash]['ratio']; 
    194         } 
    195         public function isHashChecking($hash) 
    196         { 
    197                 return $this->torrents[$hash]['is_hash_checking']; 
    198         } 
    199         public function getETA($hash) 
    200         { 
    201                 return $this->torrents[$hash]['ETA']; 
    202         } 
    203         public function getSize($hash) 
    204         { 
    205                 return $this->getCorrectUnits($this->torrents[$hash]['size_in_chunks'] * $this->torrents[$hash]['chunk_size']); 
    206         } 
    207         public function getDone($hash) 
    208         { 
    209                 return $this->getCorrectUnits($this->torrents[$hash]['completed_chunks'] * $this->torrents[$hash]['chunk_size']); 
    210         } 
    211         private function getCorrectUnits($size) 
    212     { 
    213                 $size_units = 'bytes'; 
    214                 if($size >= 1024) 
    215                 { 
    216                 $size /= 1024; 
    217                 $size_units = 'Kb'; 
    218                 } 
    219                 if($size >= 1024) 
    220                 { 
    221             $size /= 1024; 
    222             $size_units = 'Mb'; 
    223         } 
    224                 if($size >= 1024) 
    225         { 
    226             $size /= 1024; 
    227             $size_units = 'Gb'; 
    228         } 
    229         return round($size, 2) .  $size_units; 
    230  
    231     } 
    232         private function getPrivate() 
    233         { 
    234                 $tt = array(); 
    235                 $sql = "select hash, user from torrents"; 
    236                 $result = $this->_db->query($sql); 
    237                 $torr = $result->fetchAll(); 
    238                 foreach($torr as $torrent) 
    239                         $tt[$torrent['hash']] = $torrent['user']; 
    240                          
    241                 return $tt; 
    242         } 
    243      
    244124        private function fetchFeeds() 
    245     { 
    246         $num_feeds = count($this->feeds); 
    247         for($i = 0; $i < $num_feeds;$i++) 
    248         { 
    249                 $this->info[$i]['title'] = $this->feeds[$i]['feed']->get_title(); 
    250                 $this->info[$i]['description'] = $this->feeds[$i]['feed']->get_description(); 
    251                 $this->info[$i]['id'] = $this->feeds[$i]['id']; 
    252                 /*foreach ($this->feeds[$i]->get_items() as $key => $item) 
    253                 { 
    254                         $this->info[$i]['items'][$key]['title'] = $item->get_title(); 
    255                         $this->info[$i]['items'][$key]['description'] = $item->get_description(); 
    256                         $this->info[$i]['items'][$key]['link'] = $item->get_link(); 
    257                         $this->info[$i]['items'][$key]['date'] = $item->get_date("U"); 
    258                 }*/ 
    259         } 
    260     } 
    261     /*private function formatETA($time) 
    262     { 
    263                 $time = $time/1000; 
    264                 $sec = sprintf("%02d",floor(($time/60 - floor($time/60))*60)); 
    265                 $min =  sprintf("%02d",floor(($time/3600 - floor($time/3600))*60)); 
    266                 $hour =  sprintf("%02d",floor(($time/216000 - floor($time/216000))*60)); 
    267          
    268                 if($hour > 23) 
    269                 { 
    270                         $days = floor($hour/24) . "d "; 
    271                         $hour = sprintf("%02d",floor(($hour/24 - floor($hour/24))*24)); 
    272                 } else { 
    273                         $days = ''; 
    274                 } 
    275  
    276                 return $days . $hour.':'.$min.':'.$sec; 
    277     } 
    278     private function stop($hashes) 
    279     { 
    280         if(is_array($hashes)) 
    281                 $hashes = array_keys($hashes); 
    282         else  
    283                 $hashes = array($hashes); 
    284          
    285         foreach($hashes as $hash) 
    286         { 
    287                 $message = new xmlrpcmsg("d.stop", array(new xmlrpcval($hash, 'string'))); 
    288                         $result = $this->client->send($message); 
    289         } 
    290          
    291         $this->addMessage($this->_str['info_tor_stop']); 
    292     } 
    293     private function start($hashes) 
    294     { 
    295         if(is_array($hashes)) 
    296                 $hashes = array_keys($hashes); 
    297         else  
    298                 $hashes = array($hashes); 
    299          
    300         foreach($hashes as $hash) 
    301         { 
    302                 $message = new xmlrpcmsg("d.start", array(new xmlrpcval($hash, 'string'))); 
    303                         $result = $this->client->send($message); 
    304         } 
    305          
    306         $this->addMessage($this->_str['info_tor_start']); 
    307     } 
    308     private function erase($hashes) 
    309     { 
    310         if(is_array($hashes)) 
    311                 $hashes = array_keys($hashes); 
    312         else  
    313                 $hashes = array($hashes); 
    314          
    315         foreach($hashes as $hash) 
    316         { 
    317                 $message = new xmlrpcmsg("d.erase", array(new xmlrpcval($hash, 'string'))); 
    318                         $result = $this->client->send($message); 
    319                         $sql = "delete from torrents where hash = '" . $hash . "'"; 
    320                         $this->_db->query($sql); 
    321         } 
    322          
    323         $this->addMessage($this->_str['info_tor_erase']); 
    324     } 
    325     private function setDownLimit($limit) 
    326     { 
    327         $message = new xmlrpcmsg("set_download_rate", array(new xmlrpcval($limit*1024, 'int'))); 
    328                 $result = $this->client->send($message); 
    329                 //print_r($result); 
    330                 if($result->errno == 0) 
    331                         $this->addMessage($this->_str['info_down_limit']); 
    332                 else 
    333                         $this->addMessage($this->_str['err_down_limit']);        
    334     } 
    335     private function setUploadLimit($limit) 
    336     { 
    337         $message = new xmlrpcmsg("set_upload_rate", array(new xmlrpcval($limit*1024, 'int'))); 
    338                 $result = $this->client->send($message); 
    339                 if($result->errno == 0) 
    340                         $this->addMessage($this->_str['info_up_limit']); 
    341                 else 
    342                         $this->addMessage($this->_str['err_up_limit']);  
    343     }*/ 
    344     private function AddFeed($feed_url) 
    345     { 
    346         $sql = "INSERT INTO feeds(url, user) VALUES('$feed_url' , '". $this->getIdUser() . "');"; 
    347         $this->_db->query($sql); 
    348         $this->addMessage($this->_str['info_add_feed']); 
    349     } 
    350     private function DeleteFeed($id) 
    351     { 
    352         $sql = "DELETE FROM feeds WHERE user = '". $this->getIdUser() . "' AND id = '$id';"; 
    353         $this->_db->query($sql); 
    354         $this->addMessage($this->_str['info_erase_feed']); 
    355     } 
     125        { 
     126        $num_feeds = count($this->feeds); 
     127        for($i = 0; $i < $num_feeds;$i++) 
     128        { 
     129                $this->info[$i]['title'] = $this->feeds[$i]['feed']->get_title(); 
     130                $this->info[$i]['description'] = $this->feeds[$i]['feed']->get_description(); 
     131                $this->info[$i]['id'] = $this->feeds[$i]['id']; 
     132                /*foreach ($this->feeds[$i]->get_items() as $key => $item) 
     133                { 
     134                        $this->info[$i]['items'][$key]['title'] = $item->get_title(); 
     135                        $this->info[$i]['items'][$key]['description'] = $item->get_description(); 
     136                        $this->info[$i]['items'][$key]['link'] = $item->get_link(); 
     137                        $this->info[$i]['items'][$key]['date'] = $item->get_date("U"); 
     138                }*/ 
     139        } 
     140  } 
     141  private function AddFeed($feed_url) 
     142  { 
     143        $sql = "INSERT INTO feeds(url, user) VALUES('$feed_url' , '". $this->getIdUser() . "');"; 
     144        $this->_db->query($sql); 
     145        $this->addMessage($this->_str['info_add_feed']); 
     146  } 
     147  private function DeleteFeed($id) 
     148  { 
     149        $sql = "DELETE FROM feeds WHERE user = '". $this->getIdUser() . "' AND id = '$id';"; 
     150        $this->_db->query($sql); 
     151        $this->addMessage($this->_str['info_erase_feed']); 
     152  } 
    356153} 
    357154?> 
  • trunk/wtorrent/home/cls/Files.cls.php

    r4 r51  
    1818class Files extends rtorrent 
    1919{ 
    20         private  $files; 
    21         private  $hash; 
    22         private  $info_files = array('', '', 
    23