Changeset 51
- Timestamp:
- 05/03/08 10:32:31 (2 years ago)
- Files:
-
- trunk/wtorrent/cls/multicall.cls.php (added)
- trunk/wtorrent/cls/rtorrent.cls.php (modified) (5 diffs)
- trunk/wtorrent/cls/torrent.cls.php (added)
- trunk/wtorrent/home/cls/Commands.cls.php (modified) (1 diff)
- trunk/wtorrent/home/cls/Feeds.cls.php (modified) (3 diffs)
- trunk/wtorrent/home/cls/Files.cls.php (modified) (4 diffs)
- trunk/wtorrent/home/cls/General.cls.php (modified) (3 diffs)
- trunk/wtorrent/home/cls/ListT.cls.php (modified) (8 diffs)
- trunk/wtorrent/home/cls/Tracker.cls.php (modified) (3 diffs)
- trunk/wtorrent/home/css/estil.css (modified) (1 diff)
- trunk/wtorrent/home/js/javasc.js (modified) (1 diff)
- trunk/wtorrent/lib/inc/includes.inc.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wtorrent/cls/rtorrent.cls.php
r49 r51 21 21 { 22 22 protected $client; 23 protected $multicall; 24 protected $torrents; 25 protected $data; 26 23 27 private $menu = array('Main' => 'ListT', 24 28 'Add Torrent' => 'AddT', … … 36 40 /////////////////////////////////// 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 /////////////////////////////////// 37 41 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( ){} 48 56 49 57 public function registrado( ) 50 58 { 51 return !is_null( $this->_sesion->id_user );59 return !is_null( $this->_sesion->id_user ); 52 60 } 53 61 public function compLogin($user, $passwd) 54 {62 { 55 63 $passwd = md5($passwd); 56 64 $sql = "select id from tor_passwd where user = '$user' and passwd = '$passwd'"; … … 59 67 { 60 68 $num = $result->numRows(); 61 69 62 70 if($num > 0) 63 71 $return = $result->current(); 64 72 else 65 73 $return = false; 66 67 } else { 68 $return = false; 69 } 70 return $return; 71 } 74 } else { 75 $return = false; 76 } 77 return $return; 78 } 72 79 public function getUser( ) 73 80 { 74 81 return $this->_sesion->user; 75 82 } 76 77 83 public function getIdUser( ) 78 84 { … … 108 114 return $return; 109 115 } 110 111 112 116 public function login( $user, $password ) 113 117 { … … 137 141 } 138 142 } 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 } 139 154 public function setClient() 140 155 { 141 156 $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 143 159 if(RT_AUTH) 144 160 $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; 147 164 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 151 168 if($result->errno != 0) 152 169 { 153 170 $this->addMessage($this->_str['err_conn']); 154 171 return false; 155 } else 172 } else { 173 $this->setTorrents(); 156 174 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); 157 211 } 158 212 protected function setPerm() 159 213 { 160 214 $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; 161 242 } 162 243 } trunk/wtorrent/home/cls/Commands.cls.php
r36 r51 18 18 class Commands extends rtorrent 19 19 { 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; 21 26 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 } 69 67 } 70 68 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) 71 131 { 72 $ hashes = explode('~', $hashes);73 if(!is_array($hashes)) 74 $hashes = array($hashes);132 $this->torrents[$hash]->erase(); 133 $this->erase_db($hash); 134 } 75 135 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) 148 142 $this->addMessage($this->_str['info_down_limit']); 149 143 else 150 144 $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']); 158 151 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); 164 157 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); 167 160 168 $result = $this-> client->multicall($array_post);161 $result = $this->multicall->call(); 169 162 170 if($result ->errno == 0)163 if($result) 171 164 $this->addMessage($this->_str['info_ch_files']); 172 165 else 173 166 $this->addMessage($this->_str['err_ch_files']); 174 167 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) 183 175 $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); 191 182 192 foreach($t_indexas $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); 194 185 195 //print_r($array_post);196 $responses = $this->client->multicall($array_post);186 $this->multicall->call(); 187 197 188 $this->addMessage($this->_str['info_ch_trackers']); 198 }189 } 199 190 } 200 191 ?> trunk/wtorrent/home/cls/Feeds.cls.php
r4 r51 18 18 class Feeds extends rtorrent 19 19 { 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=');*/39 20 private $info = array(); 40 21 private $feeds = array(); 41 22 private $view_feed = false; 42 23 43 public function construct()24 public function construct() 44 25 { 45 26 if(!$this->setClient()) … … 91 72 $this->feeds[$i]['feed'] = new SimplePie(); 92 73 $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, '/')); 94 75 $this->feeds[$i]['feed']->init(); 95 76 $this->feeds[$i]['feed']->handle_content_type(); … … 141 122 return $this->info[$index]['title']; 142 123 } 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 244 124 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 } 356 153 } 357 154 ?> trunk/wtorrent/home/cls/Files.cls.php
r4 r51 18 18 class Files extends rtorrent 19 19 { 20 private $files; 21 private $hash; 22 private $info_files = array('', '', 23 'f.get_path=', 24 'f.get_completed_chunks=', 25 'f.get_size_chunks=', 26 'f.get_priority='); 27 private $position = 0; 20 private $hash; 28 21 29 public function construct()22 public function construct() 30 23 { 31 24 $this->hash = $this->_request['hash']; … … 34 27 return false; 35 28 36 if(isset($this->_request['ch_pr']) && count($this->_request['files']) > 0) $this->changePriorities($this->_request['files'], $this->_request['priority'], $this->hash);37 $this-> getTorrents($this->_request['hash']);29 $array_f = array('f.get_path', 'f.get_completed_chunks', 'f.get_size_chunks','f.get_priority'); 30 $this->multicall->f_multicall($this->hash, $array_f); 38 31 } 39 40 41 32 public function getHash() 42 33 { … … 45 36 public function getFiles() 46 37 { 47 return $this->files; 48 } 49 public function getName() 50 { 51 return $this->details['name']; 52 } 53 public function getTorrent() 54 { 55 return $this->details['torrent_file']; 56 } 57 public function getDataPath() 58 { 59 return $this->details['data_path']; 60 } 61 public function getPercent() 62 { 63 return $this->details['percent']; 64 } 65 public function getRatio() 66 { 67 return $this->details['ratio']; 38 $num = $this->torrents[$this->hash]->get_size_files(); 39 for($i = 0; $i < $num; $i++) 40 { 41 $files[$i]['name'] = $this->torrents[$this->hash]->f_get_path($i); 42 $files[$i]['size_in_chunks'] = $this->torrents[$this->hash]->f_get_size_chunks($i); 43 $files[$i]['completed_chunks'] = $this->torrents[$this->hash]->f_get_completed_chunks($i); 44 $files[$i]['priority'] = $this->torrents[$this->hash]->f_get_priority($i); 45 $files[$i]['percent'] = floor(($files[$i]['completed_chunks']/$files[$i]['size_in_chunks'])*100); 46 $files[$i]['size'] = $files[$i]['size_in_chunks'] * $this->torrents[$this->hash]->get_chunk_size(); 47 $files[$i]['size_done'] = $files[$i]['completed_chunks'] * $this->torrents[$this->hash]->get_chunk_size(); 48 } 49 return $files; 68 50 } 69 51 public function getSize($key) 70 52 { 71 return $this->getCorrectUnits($this-> files[$key]['size']);53 return $this->getCorrectUnits($this->torrents[$this->hash]->f_get_size_chunks($key) * $this->torrents[$this->hash]->get_chunk_size()); 72 54 } 73 55 public function getDone($key) 74 56 { 75 return $this->getCorrectUnits($this->files[$key]['size_done']); 76 } 77 public function getUp() 78 { 79 return $this->getCorrectUnits($this->details['bytes_up']); 57 return $this->getCorrectUnits($this->torrents[$this->hash]->f_get_completed_chunks($key) * $this->torrents[$this->hash]->get_chunk_size()); 80 58 } 81 59 public function getPriorityStr($key) 82 60 { 83 switch($this-> files[$key]['priority'])61 switch($this->torrents[$this->hash]->f_get_priority($key)) 84 62 { 85 63 case 0: … … 99 77 } 100 78 private function getCorrectUnits($size) 101 {79 { 102 80 $size_units = 'bytes'; 103 81 if($size >= 1024) 104 82 { 105 $size /= 1024;106 $size_units = 'Kb';83 $size /= 1024; 84 $size_units = 'Kb'; 107 85 } 108 86 if($size >= 1024) 109 87 { 110 $size /= 1024;111 $size_units = 'Mb';112 }88 $size /= 1024; 89 $size_units = 'Mb'; 90 } 113 91 if($size >= 1024) 114 {115 $size /= 1024;116 $size_units = 'Gb';117 }118 return round($size, 2) . $size_units;119 120 }121 122 private function getTorrents($hash)123 92 { 124 125 $this->info_files[0] = $hash; 126 127 foreach($this->info_files as $param) 128 $array_post[] = new xmlrpcval($param, 'string'); 129 130 // Get chunk size 131 $message = new xmlrpcmsg("d.get_chunk_size", array(new xmlrpcval($hash, 'string'))); 132 $result = $this->client->send($message); 133 $chunk_size = $result->val; 134 // Get file info 135 $message = new xmlrpcmsg("f.multicall", $array_post); 136 $result = $this->client->send($message); 137 //print_r($result); 138 foreach($result->val as $key => $file) 139 { 140 if(SCRAMBLE === true) 141 $file[0] = $this->scramble($file[0]); 142 143 $this->files[$key]['name'] = $file[0]; 144 $this->files[$key]['size_in_chunks'] = $file[2]; 145 $this->files[$key]['completed_chunks'] = $file[1]; 146 $this->files[$key]['priority'] = $file[3]; 147 $this->files[$key]['percent'] = floor(($this->files[$key]['completed_chunks']/$this->files[$key]['size_in_chunks'])*100); 148 $this->files[$key]['size'] = $this->files[$key]['size_in_chunks'] * $chunk_size; 149 $this->files[$key]['size_done'] = $this->files[$key]['completed_chunks'] * $chunk_size; 150 } 151 //print_r($this->files); 152 } 153 private function changePriorities($files, $priorities, $hash) 154 { 155 $f_index = array_keys($files); 156 //print_r($f_index); 157 158 foreach($f_index as $param) 159 $array_post[] = new xmlrpcmsg('f.set_priority', array(new xmlrpcval($hash, 'string'), new xmlrpcval($param, 'int'), new xmlrpcval($priorities, 'int'))); 160 161 //print_r($array_post); 162 $responses = $this->client->multicall($array_post); 163 164 $mesage = new xmlrpcmsg('d.update_priorities', array(new xmlrpcval($hash, 'string'))); 165 $this->client->send($mesage); 166 } 93 $size /= 1024; 94 $size_units = 'Gb'; 95 } 96 return round($size, 1) . $size_units; 97 } 167 98 } 168 99 ?> trunk/wtorrent/home/cls/General.cls.php
r4 r51 18 18 class General extends rtorrent 19 19 { 20 private $details;21 20 private $hash; 22 private $info_general = array('d.get_name', 23 'd.get_tied_to_file', 24 'd.get_base_path', 25 'd.get_down_rate', 26 'd.get_up_rate', 27 'd.get_chunk_size', 28 'd.get_completed_chunks', 29 'd.get_size_chunks', 30 'd.get_ratio', 31 'd.get_peers_max', 32 'd.get_peers_min', 33 'd.get_priority', 34 'd.get_message'); 35 /////////////////////////////////// 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 /////////////////////////////////// 36 37 public function construct() 38 { 21 22 public function construct() 23 { 39 24 $this->hash = $this->_request['hash']; 40 25 41 26 if(!$this->setClient()) 42 27 return false; 43 44 if(isset($this->_request['ch_pr'])) $this->changePriority($this->hash, $this->_request['priority']);45 46 $this->getTorrents($this->hash);47 28 } 48 49 29 ////////////////////////////////////////////////// C O N S U L T O R A S ////////////////////////////////////////////////// 50 30 public function getHash() … … 54 34 public function getName() 55 35 { 56 return $this-> details['name'];36 return $this->torrents[$hash]->get_name(); 57 37 } 58 38 public function getTorrent() 59 39 { 60 return $this->details['torrent_file'];40 return '/' . ltrim($this->torrents[$this->hash]->get_tied_to_file(), '/'); 61 41 } 62 42 public function getDataPath() 63 43 { 64 return $this-> details['data_path'];44 return $this->torrents[$this->hash]->get_base_path(); 65 45 } 66 46 public function getPercent() 67 47 { 68 return $this->details['percent'];48 return floor(($this->torrents[$this->hash]->get_completed_chunks() / $this->torrents[$this->hash]->get_size_chunks())*100); 69 49 } 70 50 public function getRatio() 71 51 { 72 return $this->details['ratio'];52 return round($this->torrents[$this->hash]->get_ratio()/1000,2); 73 53 } 74 54 public function getSize() 75 55 { 76 return $this->getCorrectUnits($this-> details['size_in_chunks'] * $this->details['chunk_size']);56 return $this->getCorrectUnits($this->torrents[$this->hash]->get_size_chunks() * $this->torrents[$this->hash]->get_chunk_size()); 77 57 } 78 58 public function getDone() 79 59 { 80 return $this->getCorrectUnits($this-> details['completed_chunks'] * $this->details['chunk_size']);60 return $this->getCorrectUnits($this->torrents[$this->hash]->get_completed_chunks() * $this->torrents[$this->hash]->get_chunk_size()); 81 61 } 82 62 public function getUp() 83 63 { 84 return $this->getCorrectUnits($this-> details['bytes_up']);64 return $this->getCorrectUnits($this->torrents[$this->hash]->get_completed_chunks() * $this->torrents[$this->hash]->get_chunk_size() * $this->getRatio()); 85 65 } 86 66 public function getMaxPeers() 87 67 { 88 return $this-> details['peers_max'];68 return $this->torrents[$this->hash]->get_peers_max(); 89 69 } 90 70 public function getMinPeers() 91 71 { 92 return $this-> details['peers_min'];72 return $this->torrents[$this->hash]->get_peers_min(); 93 73 } 94 74 public function getPriorityStr() 95 75 { 96 switch($this-> details['priority'])76 switch($this->torrents[$this->hash]->d_get_priority()) 97 77 { 98 78 case 1: … … 116 96 public function getPriority() 117 97 { 118 return $this-> details['priority'];98 return $this->torrents[$this->hash]->d_get_priority(); 119 99 } 120 100 public function getMessage() 121 101 { 122 return $this-> details['message'];102 return $this->torrents[$this->hash]->get_message(); 123 103 } 124 104 private function getCorrectUnits($size) 125 {105 { 126 106 $size_units = 'bytes'; 127 107 if($size >= 1024) 128 108 { 129 $size /= 1024;130 $size_units = 'Kb';109 $size /= 1024; 110 $size_units = 'Kb'; 131 111 } 132 112 if($size >= 1024) 133 113 { 134 $size /= 1024;135 $size_units = 'Mb';136 }114 $size /= 1024; 115 $size_units = 'Mb'; 116 } 137 117 if($size >= 1024) 138 {139 $size /= 1024;140 $size_units = 'Gb';141 }142 return round($size, 2) . $size_units;143 144 }145 //////////////////////////////////////////////// M O D I F I C A D O R A S ////////////////////////////////////////////////146 private function getTorrents($hash)147 118 { 148 foreach($this->info_general as $param) 149 $array_post[] = new xmlrpcmsg($param, array(new xmlrpcval($hash, 'string'))); 150 151 $responses = $this->client->multicall($array_post); 152 153 //print_r($responses); 154 155 if(SCRAMBLE === true) 156 { 157 $tor_name[1] = $this->scramble($tor_name[1]); 158 $tor_file[1] = $this->scramble($tor_file[1]); 159 $tor_base_path[1] = $this->scramble($tor_base_path[1]); 160 } 161 162 $this->details['id'] = $tor_id; 163 $this->details['name'] = $responses[0]->val; 164 $this->details['torrent_file'] = '/' . ltrim($responses[1]->val, '/'); 165 $this->details['data_path'] = $responses[2]->val; 166 $this->details['bytes_done'] = $responses[5]->val * $responses[6]->val; 167 $this->details['chunk_size'] = $responses[5]->val; 168 $this->details['completed_chunks'] = $responses[6]->val; 169 $this->details['size_in_chunks'] = $responses[7]->val; 170 $this->details['peers_max'] = $responses[9]->val; 171 $this->details['peers_min'] = $responses[10]->val; 172 $this->details['priority'] = $responses[11]->val; 173 $this->details['message'] = $responses[12]->val; 174 $this->details['missing_chunks'] = $this->details['size_in_chunks'] - $this->details['completed_chunks']; 175 $this->details['missing_bytes'] = $this->details['missing_chunks'] * $this->details['chunk_size']; 176 //$this->details['seeds'] = $tor_completed[1]; 177 //$this->details['peers'] = $tor_peers[1]; 178 $this->details['ratio'] = round($responses[8]->val/1000,2); 179 $this->details['bytes_up'] = $this->details['bytes_done'] * $this->details['ratio']; 180 $this->details['bytes_total'] = $this->details['chunk_size'] * $this->details['size_in_chunks']; 181 //$this->details['num_trackers'] = $tor_num_trackers[1]; 182 183 if($this->details['completed_chunks'] < $this->details['size_in_chunks']) 184 { 185 $this->details['percent'] = floor(($this->details['completed_chunks']/$this->details['size_in_chunks'])*100); 186 } else { 187 $this->details['percent'] = 100; 188 } 189 } 190 private function changePriority($hash, $priority) 191 { 192 if($hash != '' && $priority >= 0 && $priority <= 3) 193 { 194 $message = new xmlrpcmsg("d.set_priority", array(new xmlrpcval($hash, 'string'), new xmlrpcval($priority, 'int'))); 195 $result = $this->client->send($message); 196 $this->addMessage($this->_str['info_pr']); 197 } else { 198 $this->addMessage($this->_str['err_pr']); 199 } 200 } 119 $size /= 1024; 120 $size_units = 'Gb'; 121 } 122 return round($size, 1) . $size_units; 123 } 201 124 } 202 125 ?> trunk/wtorrent/home/cls/ListT.cls.php
r50 r51 19 19 { 20 20 private $view; 21 private $torrents = array();22 21 private $MAX_LENGTH_NAME = 55; 23 private $info_dowload = array('default', 24 'd.get_hash=', 25 'd.get_name=', 26 'd.get_down_rate=', 27 'd.get_up_rate=', 28 'd.get_chunk_size=', 29 'd.get_completed_chunks=', 30 'd.get_size_chunks=', 31 'd.get_state=', 32 'd.get_peers_accounted=', 33 'd.get_peers_complete=', 34 'd.is_hash_checking=', 35 'd.get_ratio=', 36 'd.get_tracker_size=', 37 'd.is_active=', 38 'd.is_open=', 39 'd.get_message=', 40 'd.get_creation_date=', 41 ); 42 private $info_tracker = array('', 43 "", 44 't.get_scrape_complete=', 45 't.get_scrape_incomplete='); 46 47 public function construct() 22 23 public function construct() 48 24 { 49 25 if($this->_request['view'] == 'public') $this->view = 'public'; … … 54 30 return false; 55 31 32 /* d multicall with all the necessary info to generate the torrent list */ 33 $array_d = array('d.get_name', 'd.get_down_rate', 'd.get_up_rate', 'd.get_chunk_size','d.get_completed_chunks','d.get_size_chunks','d.get_state','d.get_peers_accounted','d.get_peers_complete','d.is_hash_checking','d.get_ratio','d.get_tracker_size','d.is_active','d.is_open','d.get_message','d.get_creation_date'); 34 $this->multicall->d_multicall($array_d); 35 // t multicall 36 $array_t = array('t.get_scrape_complete', 't.get_scrape_incomplete'); 37 $hashes = $this->getHashes(); // Retrieve hashes 38 foreach($hashes as $hash) 39 $this->multicall->t_multicall($hash, $array_t); 40 56 41 if(isset($this->_request['start'])) $this->start($this->_request['start']); 57 42 if(isset($this->_request['stop'])) $this->stop($this->_request['stop']); 58 43 if(isset($this->_request['erase'])) $this->erase($this->_request['erase']); 59 60 $this->getTorrents();61 44 } 62 45 … … 67 50 public function getPublicHashes() 68 51 { 69 $ tor_hashes = array_keys($this->torrents);70 foreach($ tor_hashes as $hash)71 if($this->torrents[$hash] ['private']=== false)52 $hashes = $this->getHashes(); 53 foreach($hashes as $hash) 54 if($this->torrents[$hash]->get_private() === false) 72 55 $return[] = $hash; 73 56 … … 76 59 public function getPublicHashesNum() 77 60 { 78 $ tor_hashes = array_keys($this->torrents);61 $hashes = $this->getHashes(); 79 62 $i = 0; 80 foreach($ tor_hashes as $hash)81 if($this->torrents[$hash] ['private']=== false)63 foreach($hashes as $hash) 64 if($this->torrents[$hash]->get_private() === false) 82 65 $i++; 83 66 … … 86 69 public function getPrivateHashes() 87 70 { 88 $ tor_hashes = array_keys($this->torrents);89 foreach($ tor_hashes as $hash)90 if( $this->torrents[$hash]['private'] === true)71 $hashes = $this->getHashes(); 72 foreach($hashes as $hash) 73 if(($this->torrents[$hash]->get_private() === true) && ($this->torrents[$hash]->get_owner() == $this->getIdUser())) 91 74 $return[] = $hash; 92 75 … … 95 78 public function getPrivateHashesNum() 96 79 { 97 $ tor_hashes = array_keys($this->torrents);80 $hashes = $this->getHashes(); 98 81 $i = 0; 99 foreach($ tor_hashes as $hash)100 if($this->torrents[$hash]['private'] === true)101 $i++;82 foreach($hashes as $hash) 83 if(($this->torrents[$hash]->get_private() === false) && ($this->torrents[$hash]->get_owner() == $this->getIdUser())) 84 $i++; 102 85 103 86 return $i; … … 105 88 public function getName($hash) 106 89 { 107 // Just in case the torrent name is too long return a shortened version. 108 $name = $this->torrents[$hash] ['name'];90 // Just in case the torrent name is too long return a shortened version. (THIS SHOULD BE DONE IN THE TEMPLATE WITH SMARTY TRUNCATE) 91 $name = $this->torrents[$hash]->get_name(); 109 92 if(strlen($name) > $this->MAX_LENGTH_NAME){ 110 93 $name = substr($name, 0, $this->MAX_LENGTH_NAME) . ' ...'; … … 112 95 return $name; 113 96 } 114 // public function getTags($hash)115 // {116 // return $this->torrents[$hash]['tags'];117 // }118 97 public function getState($hash) 119 98 { 120 return $this->torrents[$hash] ['state'];99 return $this->torrents[$hash]->get_state(); 121 100 } 122 101 public function getOpen($hash) 123 102 { 124 return $this->torrents[$hash]['is_open']; 125 } 126 public function getActive($hash) 127 { 128 return $this->torrents[$hash]['is_active']; 103 return $this->torrents[$hash]->is_open(); 129 104 } 130 105 public function getConnPeers($hash) 131 106 { 132 return $this->torrents[$hash] ['peers'];107 return $this->torrents[$hash]->get_peers_accounted(); 133 108 } 134 109 public function getConnSeeds($hash) 135 110 { 136 return $this->torrents[$hash] ['seeds'];111 return $this->torrents[$hash]->get_peers_complete(); 137 112 } 138 113 public function getTotalPeers($hash) 139 114 { 140 return $this->torrents[$hash]['peers_scrape']; 115 $peers = 0; 116 $num = $this->torrents[$hash]->get_tracker_size(); 117 118 for($i = 0; $i < $num; $i++) 119 { 120 $t_peers = $this->torrents[$hash]->t_get_scrape_incomplete($i); 121 $peers += $t_peers; 122 } 123 124 return $peers; 141 125 } 142 126 public function getTotalSeeds($hash) 143 127 { 144 return $this->torrents[$hash]['seeds_scrape']; 128 $seeds = 0; 129 $num = $this->torrents[$hash]->get_tracker_size(); 130 131 for($i = 0; $i < $num; $i++) 132 { 133 $t_seeds = $this->torrents[$hash]->t_get_scrape_complete($i); 134 $seeds += $t_seeds; 135 } 136 137 return $seeds; 145 138 } 146 139 public function getDownRate($hash) 147 140 { 148 return $this->torrents[$hash]['down_rate'];141 return round($this->torrents[$hash]->get_down_rate()/1024,2); 149 142 } 150 143 public function getUpRate($hash) 151 144 { 152 return $this->torrents[$hash]['up_rate'];145 return round($this->torrents[$hash]->get_up_rate()/1024,2); 153 146 } 154 147 public function getPercent($hash) 155 148 { 156 return $this->torrents[$hash]['percent'];149 return floor(($this->torrents[$hash]->get_completed_chunks()/$this->torrents[$hash]->get_size_chunks())*100); 157 150 } 158 151 public function getRatio($hash) 159 152 { 160 return $this->torrents[$hash]['ratio'];153 return round($this->torrents[$hash]->get_ratio()/1000,2); 161 154 } 162 155 public function isHashChecking($hash) 163 156 { 164 return $this->torrents[$hash] ['is_hash_checking'];157 return $this->torrents[$hash]->is_hash_checking(); 165 158 } 166 159 public function getETA($hash) 167 160 { 168 return $this->torrents[$hash]['ETA']; 161 $return = '--'; 162 if(($this->getPercent($hash) != 100) && ($this->torrents[$hash]->get_down_rate() != 0)) 163 $return = $this->formatETA(ceil((($this->torrents[$hash]->get_size_chunks() - $this->torrents[$hash]->get_completed_chunks()) * $this->torrents[$hash]->get_chunk_size() / 1024) / $this->torrents[$hash]->get_down_rate())); 164 165 return $return; 169 166 } 170 167 public function getSize($hash) 171 168 { 172 return $this->getCorrectUnits($this->torrents[$hash] ['size_in_chunks'] * $this->torrents[$hash]['chunk_size']);169 return $this->getCorrectUnits($this->torrents[$hash]->get_size_chunks() * $this->torrents[$hash]->get_chunk_size()); 173 170 } 174 171 public function getDone($hash) 175 172 { 176 return $this->getCorrectUnits($this->torrents[$hash]['completed_chunks'] * $this->torrents[$hash]['chunk_size']); 177 } 178 public function getTstate($hash) 179 { 180 return $this->torrents[$hash]['tstate']; 181 } 182 public function getTstyle($hash) 183 { 184 switch($this->torrents[$hash]['tstate']) 185 { 186 case 'downloading': 187 $return = 'green'; 188 break; 189 case 'stopped': 190 $return = 'black'; 191 break; 192 case 'seeding': 193 $return = 'blue'; 194 break; 195 case 'closed': 196 $return = 'black'; 197 break; 198 case 'message': 199 $return = 'red'; 200 break; 201 case 'chash': 202 $return = 'yellow'; 203 break; 204 } 205 return $return; 206 } 207 public function getMessage($hash) 208 { 209 return $this->torrents[$hash]['message']; 210 } 211 public function getTooltipText($hash) 212 { 213 if($this->getTstate($hash) == 'message') 214 $return = $this->getMessage($hash); 215 else 216 $return = null; 217 return $return; 218 } 219 public function getCreationDate($hash) 220 { 221 return $this->torrents[$hash]['creation_date']; 222 } 173 return $this->getCorrectUnits($this->torrents[$hash]->get_completed_chunks() * $this->torrents[$hash]->get_chunk_size()); 174 } 175 public function getTstate($hash) 176 { 177 if($this->torrents[$hash]->get_state() == 0) 178 { 179 $return = 'stopped'; 180 } else { 181 if($this->getPercent($hash) != 100){ 182 $return = 'downloading'; 183 } else { 184 $return = 'seeding'; 185 } 186 } 187 if($this->torrents[$hash]->is_open() != 1) 188 $return = 'closed'; 189 190 if(($this->torrents[$hash]->get_message() != '') && ($this->torrents[$hash]->get_message() != 'Tracker: [Tried all trackers.]')) 191 $return = 'message'; 192 193 if($this->torrents[$hash]->is_hash_checking() == 1) 194 $return = 'chash'; 195 } 196 public function getTstyle($hash) 197 { 198 switch($this->getTstate($hash)) 199 { 200 case 'downloading': 201 $return = 'green'; 202 break; 203 case 'stopped': 204 $return = 'black'; 205 break; 206 case 'seeding': 207 $return = 'blue'; 208 break; 209 case 'closed': 210 $return = 'black'; 211 break; 212 case 'message': 213 $return = 'red'; 214 break; 215 case 'chash': 216 $return = 'yellow'; 217 break; 218 } 219 return $return; 220 } 221 public function getMessage($hash) 222 { 223 return $this->torrents[$hash]->get_message(); 224 } 225 public function getTooltipText($hash) 226 { 227 if($this->getTstate($hash) == 'message') 228 $return = $this->getMessage($hash); 229 else 230 $return = null; 231 return $return; 232 } 233 public function getCreationDate($hash) 234 { 235 return $this->torrents[$hash]->get_creation_date(); 236 } 223 237 private function getCorrectUnits($size) 224 {238 { 225 239 $size_units = 'bytes'; 226 240 if($size >= 1024) 227 241 { 228 $size /= 1024;229 $size_units = 'Kb';242 $size /= 1024; 243 $size_units = 'Kb'; 230 244 } 231 245 if($size >= 1024) 232 246 { 233 $size /= 1024;234 $size_units = 'Mb';235 }247 $size /= 1024; 248 $size_units = 'Mb'; 249 } 236 250 if($size >= 1024) 237 { 238 $size /= 1024; 239 $size_units = 'Gb'; 240 } 241 return round($size, 1) . $size_units; 242 251 { 252 $size /= 1024; 253 $size_units = 'Gb'; 254 } 255 return round($size, 1) . $size_units; 256 } 257 private function formatETA($time) 258 { 259 if (!is_array($periods)) { 260 $periods = array ( 261 'weeks' => 604800, 262 'days' => 86400, 263 'hours' => 3600, 264 'minutes' => 60, 265 ); 243 266 } 244 private function getPrivate() 245 { 246 $tt = array(); 247 $sql = "select hash, user from torrents"; 248 $result = $this->_db->query($sql); 249 $torr = $result->fetchAll(); 250 foreach($torr as $torrent) 251 $tt[$torrent['hash']] = $torrent['user']; 252 253 return $tt; 254 } 255 256 private function getTorrents() 257 { 258 //define("XMLRPC_DEBUG", 1); 259 //$this->client->setDebug(2); 260 foreach($this->info_dowload as $param) 261 $array_post[] = new xmlrpcval($param, 'string'); 262 263 //print_r(XMLRPC_prepare($array_post)); 264 //print_r(XMLRPC_prepare($array_multi)); 265 266 //$result = XMLRPC_request(RT_HOST , '/RPC2', 'd.multicall' ,$array_post); 267 $message = new xmlrpcmsg("d.multicall", $array_post); 268 $result = $this->client->send($message); 269 //print_r($result); 270 // Multicall for tracker info (reduces load time on big torrent list 271 $array_post = array(); 272 foreach($this->info_tracker as $param) 273 $array_post[] = new xmlrpcval($param, 'string'); 274 275 if(count($result->val)) { 276 foreach($result->val as $torrent) 277 { 278 $array_post[0] = new xmlrpcval($torrent[0], 'string'); 279 $messages[] = new xmlrpcmsg("t.multicall", $array_post); 280 } 281 if(count($messages) > 0) 282 $Tresponses = $this->client->multicall($messages); 283 //print_r($responses); 284 foreach($result->val as $key => $torrent) 285 { 286 // Check if the torrent is private and if the user can see it 287 $private = false; 288 $pr_torrent = $this->getPrivate(); 289 if(array_key_exists($torrent[0], $pr_torrent)) 290 { 291 $private = true; 292 if($pr_torrent[$torrent[0]] != $this->getIdUser()) 293 continue; 294 } 295 $this->torrents[$torrent[0]]['private'] = $private; 296 $this->torrents[$torrent[0]]['name'] = $torrent[1]; 297 $this->torrents[$torrent[0]]['down_rate'] = round($torrent[2]/1024,2); 298 $this->torrents[$torrent[0]]['up_rate'] = round($torrent[3]/1024,2); 299 $this->torrents[$torrent[0]]['chunk_size'] = $torrent[4]; 300 $this->torrents[$torrent[0]]['completed_chunks'] = $torrent[5]; 301 $this->torrents[$torrent[0]]['size_in_chunks'] = $torrent[6]; 302 $this->torrents[$torrent[0]]['state'] = $torrent[7]; 303 $this->torrents[$torrent[0]]['peers'] = $torrent[8]; 304 $this->torrents[$torrent[0]]['seeds'] = $torrent[9]; 305 $this->torrents[$torrent[0]]['is_hash_checking'] = $torrent[10]; 306 $this->torrents[$torrent[0]]['ratio'] = round($torrent[11]/1000,2); 307 $this->torrents[$torrent[0]]['num_trackers'] = $torrent[12]; 308 $this->torrents[$torrent[0]]['is_active'] = $torrent[13]; 309 $this->torrents[$torrent[0]]['is_open'] = $torrent[14]; 310 $this->torrents[$torrent[0]]['message'] = $torrent[15]; 311 $this->torrents[$torrent[0]]['creation_date'] = $torrent[16]; 312 313 $this->torrents[$torrent[0]]['percent'] = floor(($this->torrents[$torrent[0]]['completed_chunks']/$this->torrents[$torrent[0]]['size_in_chunks'])*100); 314 315 $this->torrents[$torrent[0]]['ETA'] = '--'; 316 if(($this->torrents[$torrent[0]]['percent'] != 100) && ($this->torrents[$torrent[0]]['down_rate'] != 0)) 317 $this->torrents[$torrent[0]]['ETA'] = $this->formatETA(ceil((($this->torrents[$torrent[0]]['size_in_chunks'] - $this->torrents[$torrent[0]]['completed_chunks']) * $this->torrents[$torrent[0]]['chunk_size'] / 1024) / $torrent[2])); 318 319 if($this->torrents[$torrent[0]]['state'] == 0) 320 { 321 $this->torrents[$torrent[0]]['tstate'] = 'stopped'; 322 } else { 323 if($this->torrents[$torrent[0]]['percent'] != 100){ 324 $this->torrents[$torrent[0]]['tstate'] = 'downloading'; 325 } else { 326 $this->torrents[$torrent[0]]['tstate'] = 'seeding'; 327 } 328 } 329 if($this->torrents[$torrent[0]]['is_open'] != 1) 330 $this->torrents[$torrent[0]]['tstate'] = 'closed'; 331 332 if(($this->torrents[$torrent[0]]['message'] != '') && ($this->torrents[$torrent[0]]['message'] != 'Tracker: [Tried all trackers.]')) 333 $this->torrents[$torrent[0]]['tstate'] = 'message'; 334 335 if($this->torrents[$torrent[0]]['is_hash_checking'] == 1) 336 $this->torrents[$torrent[0]]['tstate'] = 'chash'; 337 338 foreach($Tresponses[$key]->val as $tracker) 339 { 340 $this->torrents[$torrent[0]]['seeds_scrape'] += $tracker[0]; 341 $this->torrents[$torrent[0]]['peers_scrape'] += $tracker[1]; 342 } 343 // $this->torrents[$torrent[0]]['tags'] = Array(); 344 // $sql = "SELECT tagid FROM tags_torrents WHERE hash = '" . $torrent[0] . "';"; 345 // $res = $this->_db->query( $sql ); 346 // $result = $res->fetchAll(); 347 // foreach($result as $tag){ 348 // $sql = "SELECT value FROM tags WHERE id = '" . $tag['tagid'] . "';"; // Falta afegir lo del user 349 // $res = $this->_db->query( $sql ); 350 // $rslt = $res->fetch(); 351 // array_push($this->torrents[$torrent[0]]['tags'], $rslt['value']); 352 // } 353 354 } 355 356 } 357 //print_r($this->torrents); 358 //XMLRPC_debug_print();*/ 359 } 360 private function formatETA($time) 267 268 $seconds = (float) $time * 1000; 269 foreach ($periods as $period => $value) 361 270 { 362 if (!is_array($periods)) { 363 $periods = array ( 364 'weeks' => 604800, 365 'days' => 86400, 366 'hours' => 3600, 367 'minutes' => 60, 368 ); 369 } 370 371 $seconds = (float) $time * 1000; 372 foreach ($periods as $period => $value) 373 { 374 $count = floor($seconds / $value); 375 if ($count == 0) 376 continue; 377 378 $values[$period] = $count; 379 $seconds = $seconds % $value; 380 } 381 382 foreach ($values as $key => $value) 383 { 384 $segment_name = substr($key, 0, 1); 385 $segment = $value . $segment_name; 386 // If ETA is weeks away, don't display minutes: 387 if ($key == "minutes") 388 if ($values["weeks"] >= 1) 389 $segment = ""; 390 391 $array[] = $segment; 392 } 393 // If ETA is more then 30 weeks away, display "inf" instead of precise ETA: 394 if ($values["weeks"] > 30) 395 $str = "inf"; 396 else 397 $str = implode('', $array); 271 $count = floor($seconds / $value); 272 if ($count == 0) 273 continue; 274 275 $values[$period] = $count; 276 $seconds = $seconds % $value; 277 } 278 279 foreach ($values as $key => $value) 280 { 281 $segment_name = substr($key, 0, 1); 282 $segment = $value . $segment_name; 283 // If ETA is weeks away, don't display minutes: 284 if ($key == "minutes") 285 if ($values["weeks"] >= 1) 286 $segment = ""; 398 287 399 return $str;288 $array[] = $segment; 400 289 } 290 // If ETA is more then 30 weeks away, display "inf" instead of precise ETA: 291 if ($values["weeks"] > 30) 292 $str = "inf"; 293 else 294 $str = implode('', $array); 295 296 return $str; 297 } 401 298 } 402 299 ?> trunk/wtorrent/home/cls/Tracker.cls.php
r4 r51 18 18 class Tracker extends rtorrent 19 19 { 20 private $trackers; 21 private $info_trackers = array('', '', 22 't.get_url=', 23 't.get_normal_interval=', 24 't.get_scrape_time_last=', 25 't.get_scrape_complete=', 26 't.get_scrape_incomplete=', 27 't.is_enabled='); 28 20 private $hash; 29 21 30 public function construct()22 public function construct() 31 23 { 32 24 $this->hash = $this->_request['hash']; … … 35 27 return false; 36 28 37 if(isset($this->_request['ch_tr']) && count($this->_request['trackers']) > 0) $this->changeEnabled($this->_request['trackers'], $this->_request['active'], $this->hash); 38 $this->getTorrents($this->_request['hash']); 39 29 $array_t = array('t.get_url', 't.get_normal_interval','t.get_scrape_time_last', 't.get_scrape_complete','t.get_scrape_incomplete','t.is_enabled'); 30 $this->multicall->t_multicall($this->hash, $array_t); 40 31 } 41 42 32 public function getHash() 43 33 { … … 46 36 public function getTrackers() 47 37 { 48 return $this->trackers; 38 $num = $this->torrents[$this->hash]->get_tracker_size(); 39 for($i = 0; $i < $num; $i++) 40 { 41 $trackers[$i]['url'] = $this->torrents[$this->hash]->t_get_url($i); 42 $trackers[$i]['scrape_completed'] = $this->torrents[$this->hash]->t_get_scrape_complete($i); 43 $trackers[$i]['scrape_incomplete'] = $this->torrents[$this->hash]->t_get_scrape_incomplete($i); 44 $trackers[$i]['enabled'] = $this->torrents[$this->hash]->t_is_enabled($i); 45 } 46 return $trackers; 49 47 } 50 public function getName()51 {52 return $this->details['name'];53 }54 public function getTorrent()55 {56 return $this->details['torrent_file'];57 }58 public function getDataPath()59 {60 return $this->details['data_path'];61 }62 public function getPercent()63 {64 return $this->details['percent'];65 }66 public function getRatio()67 {68 return $this->details['ratio'];69 }70 public function getSize()71 {72 return $this->getCorrectUnits($this->details['size_in_chunks'] * $this->details['chunk_size']);73 }74 public function getDone()75 {76 return $this->getCorrectUnits($this->details['completed_chunks'] * $this->details['chunk_size']);77 }78 public function getUp()79 {80 return $this->getCorrectUnits($this->details['bytes_up']);81 }82 private function getCorrectUnits($size)83 {84 $size_units = 'bytes';85 if($size >= 1024)86 {87 $size /= 1024;88 $size_units = 'Kb';89 }90 if($size >= 1024)91 {92 $size /= 1024;93 $size_units = 'Mb';94 }95 if($size >= 1024)96 {97 $size /= 1024;98 $size_units = 'Gb';99 }100 return round($size, 2) . $size_units;101 102 }103 104 private function getTorrents($hash)105 {106 //define("XMLRPC_DEBUG", 1);107 108 $this->info_trackers[0] = $hash;109 110 foreach($this->info_trackers as $param)111 $array_post[] = new xmlrpcval($param, 'string');112 113 $message = new xmlrpcmsg("t.multicall", $array_post);114 $result = $this->client->send($message);115 //print_r($result);116 foreach($result->val as $key => $tracker)117 {118 if(SCRAMBLE === true)119 $tracker[0] = $this->scramble($tracker[0]);120 121 $sc_time = time() - $tracker[2];122 //echo $sc_time . " " . $tracker[1] . " " . time() . " " . $tracker[2];123 if($sc_time > $tracker[1])124 $enabled = 0;125 else126 $enabled = 1;127 128 $this->trackers[$key]['url'] = $tracker[0];129 $this->trackers[$key]['scrape_completed'] = $tracker[3];130 $this->trackers[$key]['scrape_incomplete'] = $tracker[4];131 $this->trackers[$key]['enabled'] = $tracker[5];132 }133 //print_r($this->files);134 //XMLRPC_debug_print();135 }136 private function changeEnabled($trackers, $enabled, $hash)137 {138 $t_index = array_keys($trackers);139 //print_r($f_index);140 141 foreach($t_index as $param)142 $array_post[] = new xmlrpcmsg('t.set_enabled', array(new xmlrpcval($hash, 'string'), new xmlrpcval($param, 'int'), new xmlrpcval($enabled, 'int')));143 144 //print_r($array_post);145 $responses = $this->client->multicall($array_post);146 }147 48 } 148 49 ?> trunk/wtorrent/home/css/estil.css
r39 r51 68 68 cursor: default; 69 69 display: none; 70 height: 12px; 70 71 } 71 72 .messages:hover { trunk/wtorrent/home/js/javasc.js
r49 r51 177 177 ajaxCall(frame, call[0]); 178 178 // Update the page (after 500ms to give rtorrent time to process the command (also set the frame to loading) 179 loadingContent(call[1]);180 window.setTimeout("load('" + call[1] + "', '" + call[2] + "')", 500);179 //loadingContent(call[1]); 180 window.setTimeout("load('" + call[1] + "', '" + call[2] + "')", 100); 181 181 } 182 182 trunk/wtorrent/lib/inc/includes.inc.php
r4 r51 22 22 require_once( 'lib/cls/Web.cls.php'); 23 23 require_once( 'cls/rtorrent.cls.php' ); 24 require_once( 'cls/torrent.cls.php' ); 25 require_once( 'cls/multicall.cls.php' ); 24 26 require_once( 'lib/xmlrpc/xmlrpc.inc.php' ); 25 27 require_once( 'lib/inc/utils.inc.php' );
