1
0

TorrentBoxEngine.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?php
  2. /* $Id: TorrentBoxEngine.php 2833 2007-04-08 11:58:47Z b4rt $ */
  3. /*************************************************************
  4. * TorrentFlux PHP Torrent Manager
  5. * www.torrentflux.com
  6. **************************************************************/
  7. /*
  8. This file is part of TorrentFlux.
  9. TorrentFlux is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. TorrentFlux is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with TorrentFlux; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. v 1.04 - Oct 18, 06 - fix paging
  23. v 1.03 - updated by batmark
  24. v 1.02 - update to add torrentbox.com to download param.
  25. v 1.01 - TorrentBox changed the download.php to dl.php.
  26. */
  27. class SearchEngine extends SearchEngineBase
  28. {
  29. function SearchEngine($cfg)
  30. {
  31. $this->mainURL = "torrentbox.com";
  32. $this->altURL = "torrentbox.com";
  33. $this->mainTitle = "TorrentBox";
  34. $this->engineName = "TorrentBox";
  35. $this->author = "kboy";
  36. $this->version = "1.04-tfb";
  37. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,876.0.html";
  38. $this->Initialize($cfg);
  39. }
  40. function populateMainCategories()
  41. {
  42. $this->mainCatalog["0"] = "(all types)";
  43. $this->mainCatalog["9"] = "Anime";
  44. $this->mainCatalog["90"] = "Apps";
  45. $this->mainCatalog["11"] = "Books";
  46. $this->mainCatalog["10"] = "Comics";
  47. $this->mainCatalog["91"] = "Games";
  48. $this->mainCatalog["6"] = "Misc";
  49. $this->mainCatalog["92"] = "Movies";
  50. $this->mainCatalog["93"] = "Music";
  51. $this->mainCatalog["8"] = "Pics";
  52. $this->mainCatalog["3"] = "TV";
  53. $this->mainCatalog["13"] = "Videos";
  54. }
  55. //----------------------------------------------------------------
  56. // Function to Get Sub Categories
  57. function getSubCategories($mainGenre)
  58. {
  59. $output = array();
  60. switch ($mainGenre)
  61. {
  62. case "90" :
  63. $output["51"] = "Linux";
  64. $output["52"] = "Mac";
  65. $output["50"] = "Windows";
  66. $output["5"] = "Misc";
  67. break;
  68. case "91" :
  69. $output["4"] = "Misc";
  70. $output["41"] = "PC";
  71. $output["42"] = "PS2";
  72. $output["43"] = "PSX";
  73. $output["44"] = "ROMS";
  74. $output["40"] = "Xbox";
  75. break;
  76. case "92" :
  77. $output["14"] = "DVD-R";
  78. $output["100"] = "Action";
  79. $output["101"] = "Adventure";
  80. $output["102"] = "Animation";
  81. $output["103"] = "Comedy";
  82. $output["104"] = "Drama";
  83. $output["105"] = "Documentary";
  84. $output["106"] = "Horror";
  85. $output["107"] = "Sci-Fi";
  86. $output["1"] = "Misc";
  87. break;
  88. case "93" :
  89. $output["15"] = "Alternative";
  90. $output["16"] = "Blues";
  91. $output["17"] = "Electronic";
  92. $output["18"] = "Pop";
  93. $output["19"] = "Rap";
  94. $output["20"] = "Rock";
  95. $output["21"] = "Reggae";
  96. $output["22"] = "Jazz";
  97. $output["23"] = "Dance";
  98. $output["24"] = "Christian";
  99. $output["25"] = "Spanish";
  100. $output["2"] = "Misc";
  101. break;
  102. }
  103. return $output;
  104. }
  105. //----------------------------------------------------------------
  106. // Function to Make the Request (overriding base)
  107. function makeRequest($request)
  108. {
  109. return parent::makeRequest($request, false);
  110. }
  111. //----------------------------------------------------------------
  112. // Function to get Latest..
  113. function getLatest()
  114. {
  115. $cat = tfb_getRequestVar('subGenre');
  116. if (empty($cat)) $cat = tfb_getRequestVar('cat');
  117. $request = "/torrents-browse.php";
  118. if(!empty($cat))
  119. {
  120. if(strpos($request,"?"))
  121. {
  122. $request .= "&cat=".$cat;
  123. }
  124. else
  125. {
  126. $request .= "?cat=".$cat;
  127. }
  128. }
  129. if (!empty($this->pg))
  130. {
  131. if(strpos($request,"?"))
  132. {
  133. $request .= "&page=" . $this->pg;
  134. }
  135. else
  136. {
  137. $request .= "?page=" . $this->pg;
  138. }
  139. }
  140. if ($this->makeRequest($request))
  141. {
  142. return $this->parseResponse();
  143. }
  144. else
  145. {
  146. return $this->msg;
  147. }
  148. }
  149. //----------------------------------------------------------------
  150. // Function to perform Search.
  151. function performSearch($searchTerm)
  152. {
  153. $searchTerm = str_replace(" ", "+", $searchTerm);
  154. $request = "/torrents-search.php?search=".$searchTerm;
  155. if(!empty($cat))
  156. {
  157. $request .= "&cat=".$cat;
  158. }
  159. $onlyname = tfb_getRequestVar('onlyname');
  160. if (empty($onlyname)) $onlyname = "no";
  161. $request .= "&onlyname=".$onlyname;
  162. $incldead = tfb_getRequestVar('incldead');
  163. if (empty($incldead)) $incldead = "0";
  164. $request .= "&incldead=".$incldead;
  165. $request .= "&submit=";
  166. if (!empty($this->pg))
  167. {
  168. $request .= "&page=" . $this->pg;
  169. }
  170. if ($this->makeRequest($request))
  171. {
  172. return $this->parseResponse();
  173. }
  174. else
  175. {
  176. return $this->msg;
  177. }
  178. }
  179. //----------------------------------------------------------------
  180. // Function to parse the response.
  181. function parseResponse()
  182. {
  183. $output = $this->tableHeader();
  184. $thing = $this->htmlPage;
  185. // We got a response so display it.
  186. // Chop the front end off.
  187. while (is_integer(strpos($thing,">Uploader<")))
  188. {
  189. $thing = substr($thing,strpos($thing,">Uploader<"));
  190. $thing = substr($thing,strpos($thing,"<tr"));
  191. $tmpList = substr($thing,0,strpos($thing,"</table>"));
  192. // ok so now we have the listing.
  193. $tmpListArr = explode("</tr>",$tmpList);
  194. $bg = $this->cfg["bgLight"];
  195. foreach($tmpListArr as $key =>$value)
  196. {
  197. $buildLine = true;
  198. if (strpos($value,".torrent"))
  199. {
  200. $ts = new tBox($value);
  201. // Determine if we should build this output
  202. if (is_int(array_search($ts->CatName,$this->catFilter)))
  203. {
  204. $buildLine = false;
  205. }
  206. if ($this->hideSeedless == "yes")
  207. {
  208. if($ts->Seeds == "N/A" || $ts->Seeds == "0")
  209. {
  210. $buildLine = false;
  211. }
  212. }
  213. if (!empty($ts->torrentFile) && $buildLine) {
  214. $output .= trim($ts->BuildOutput($bg));
  215. // ok switch colors.
  216. if ($bg == $this->cfg["bgLight"])
  217. {
  218. $bg = $this->cfg["bgDark"];
  219. }
  220. else
  221. {
  222. $bg = $this->cfg["bgLight"];
  223. }
  224. }
  225. }
  226. }
  227. // set thing to end of this table.
  228. $thing = substr($thing,strpos($thing,"</table>"));
  229. }
  230. $output .= "</table>";
  231. //http://www.torrentbox.com/torrents-browse.php?cat=4&page=2
  232. // is there paging at the bottom?
  233. if (strpos($thing, "<span class=\"pager\">") != false)
  234. {
  235. // Yes, then lets grab it and display it! ;)
  236. $thing = substr($thing,strpos($thing,"<span class=\"pager\">")+strlen("<span class=\"pager\">"));
  237. $pages = substr($thing,0,strpos($thing,"</span>"));
  238. $pages = str_replace("http://www.torrentbox.com","",$pages);
  239. $pages = str_replace("page=","pg=",$pages);
  240. $pages = str_replace("search=","searchterm=",$pages);
  241. if(strpos($this->curRequest,"LATEST"))
  242. {
  243. $pages = str_replace("/torrents-browse.php?",$this->searchURL()."&LATEST=1&",$pages);
  244. }
  245. else
  246. {
  247. $pages = str_replace("/torrents-browse.php?",$this->searchURL()."&",$pages);
  248. }
  249. $output .= "<div align=center>".$pages."</div>";
  250. }
  251. return $output;
  252. }
  253. }
  254. // This is a worker class that takes in a row in a table and parses it.
  255. class tBox
  256. {
  257. var $torrentName = "";
  258. var $torrentDisplayName = "";
  259. var $torrentFile = "";
  260. var $torrentSize = "";
  261. var $torrentStatus = "";
  262. var $CatId = "";
  263. var $CatName = "";
  264. var $fileCount = "";
  265. var $Seeds = "";
  266. var $Peers = "";
  267. var $Data = "";
  268. var $dateAdded = "";
  269. var $dwnldCount = "";
  270. function tBox( $htmlLine )
  271. {
  272. if (strlen($htmlLine) > 0)
  273. {
  274. $this->Data = $htmlLine;
  275. // Fix messed up end td's once in a while.
  276. $htmlLine = preg_replace("/<(.)*1ff8(.)*/td>/i",'</td>',$htmlLine);
  277. $htmlLine = preg_replace("/1ff8/i",'',$htmlLine);
  278. // Chunck up the row into columns.
  279. $tmpListArr = explode("</td>",$htmlLine);
  280. if(count($tmpListArr) > 8)
  281. {
  282. $this->CatName = $this->cleanLine($tmpListArr["0"]); // Cat Name
  283. if (strpos($this->CatName,">"))
  284. {
  285. $this->CatName = trim(substr($this->CatName,strpos($this->CatName,">")+1));
  286. }
  287. $this->torrentName = $this->cleanLine($tmpListArr["1"]); // TorrentName
  288. $tmpStr = $tmpListArr["2"];
  289. $start = strpos($tmpStr, "href");
  290. $tmpStr = substr($tmpStr,$start + 6, strlen($tmpStr)-$start-6);
  291. $end = strpos($tmpStr, ".torrent");
  292. $tmpStr = substr($tmpStr, 0, $end + 8); //the DL link
  293. $this->torrentFile = "http://www.torrentbox.com".$tmpStr;
  294. $this->dateAdded = $this->cleanLine($tmpListArr["4"]); // Date Added
  295. $this->torrentSize = $this->cleanLine($tmpListArr["5"]); // Size of File
  296. $this->dwnldCount = $this->cleanLine($tmpListArr["6"]); // Download Count
  297. $this->Seeds = $this->cleanLine($tmpListArr["7"]); // Seeds
  298. $this->Peers = $this->cleanLine($tmpListArr["8"]); // Peers
  299. //$tmpListArr["9"] = $this->cleanLine($tmpListArr["9"]); // Person who Uploaded it.
  300. if ($this->Peers == '')
  301. {
  302. $this->Peers = "N/A";
  303. if (empty($this->Seeds)) $this->Seeds = "N/A";
  304. }
  305. if ($this->Seeds == '') $this->Seeds = "N/A";
  306. $this->torrentDisplayName = $this->torrentName;
  307. if(strlen($this->torrentDisplayName) > 50)
  308. {
  309. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  310. }
  311. }
  312. }
  313. }
  314. function cleanLine($stringIn,$tags='')
  315. {
  316. if(empty($tags))
  317. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  318. else
  319. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  320. }
  321. //----------------------------------------------------------------
  322. // Function to build output for the table.
  323. function BuildOutput($bg)
  324. {
  325. $output = "<tr>\n";
  326. $output .= " <td width=16 bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\"><img src=\"".getImagesPath()."download_owner.gif\" width=\"16\" height=\"16\" title=\"".$this->torrentName."\" border=0></a></td>\n";
  327. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  328. $output .= " <td bgcolor=\"".$bg."\">". $this->CatName ."</td>\n";
  329. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  330. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  331. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  332. $output .= "</tr>\n";
  333. return $output;
  334. }
  335. }
  336. ?>