btJunkieEngine.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?php
  2. /* $Id: btJunkieEngine.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.01 - Oct 06, 06 fix to search results.
  23. v 1.00 - Aug 23, 06
  24. */
  25. class SearchEngine extends SearchEngineBase
  26. {
  27. function SearchEngine($cfg)
  28. {
  29. $this->mainURL = "btjunkie.org";
  30. $this->altURL = "www.btjunkie.org";
  31. $this->mainTitle = "btjunkie";
  32. $this->engineName = "btJunkie";
  33. $this->author = "kboy";
  34. $this->version = "1.01-tfb";
  35. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,874.0.html";
  36. $this->Initialize($cfg);
  37. }
  38. function populateMainCategories()
  39. {
  40. $this->mainCatalog["1"] = "Audio";
  41. $this->mainCatalog["7"] = "Anime";
  42. $this->mainCatalog["2"] = "Games";
  43. $this->mainCatalog["3"] = "Software";
  44. $this->mainCatalog["4"] = "TV";
  45. $this->mainCatalog["5"] = "Unsorted";
  46. $this->mainCatalog["6"] = "Video";
  47. $this->mainCatalog["8"] = "XXX";
  48. }
  49. //----------------------------------------------------------------
  50. // Function to Make the Request (overriding base)
  51. function makeRequest($request)
  52. {
  53. return parent::makeRequest($request, false);
  54. }
  55. //----------------------------------------------------------------
  56. // Function to get Latest..
  57. function getLatest()
  58. {
  59. $cat = tfb_getRequestVar('mainGenre');
  60. if (empty($cat)) $cat = tfb_getRequestVar('c');
  61. if(!empty($cat))
  62. {
  63. $request = "/browse";
  64. if(strpos($request,"?"))
  65. {
  66. $request .= "&c=".$cat;
  67. }
  68. else
  69. {
  70. $request .= "?c=".$cat;
  71. }
  72. }
  73. else
  74. {
  75. $request = "/?do=latest";
  76. }
  77. if (!empty($this->pg))
  78. {
  79. if(strpos($request,"?"))
  80. {
  81. $request .= "&p=" . $this->pg;
  82. }
  83. else
  84. {
  85. $request .= "?p=" . $this->pg;
  86. }
  87. }
  88. $request .= "&o=72"; // Sort Newest to Oldest
  89. //$request .= "&o=52"; // Sort Most Seeded
  90. if ($this->makeRequest($request))
  91. {
  92. return $this->parseResponse();
  93. }
  94. else
  95. {
  96. return $this->msg;
  97. }
  98. }
  99. //----------------------------------------------------------------
  100. // Function to perform Search.
  101. function performSearch($searchTerm)
  102. {
  103. $searchTerm = str_replace(" ", "+", $searchTerm);
  104. $request = "/search?q=".$searchTerm;
  105. if(!empty($cat))
  106. {
  107. $request .= "&c=".$cat;
  108. }
  109. if (!empty($this->pg))
  110. {
  111. $request .= "&p=" . $this->pg;
  112. }
  113. //$request .= "&o=72"; // Sort Newest to Oldest
  114. $request .= "&o=52"; // Sort Most Seeded
  115. $request .= "&m=0"; // Search Exact
  116. //$request .= "&m=1"; // Search Contains
  117. if ($this->makeRequest($request))
  118. {
  119. return $this->parseResponse();
  120. }
  121. else
  122. {
  123. return $this->msg;
  124. }
  125. }
  126. //----------------------------------------------------------------
  127. // Function to parse the response.
  128. function parseResponse()
  129. {
  130. $output = $this->tableHeader();
  131. $thing = $this->htmlPage;
  132. // Chop the front end off.
  133. while (is_integer(strpos($thing,">Torrent Name<")))
  134. {
  135. $thing = substr($thing,strpos($thing,">Health<"));
  136. $thing = substr($thing,strpos($thing,"<tr"));
  137. if (is_integer(strpos($thing,"do=gear")))
  138. {
  139. $tmpList = substr($thing,0,strpos($thing,"do=gear"));
  140. }
  141. else
  142. {
  143. $tmpList = substr($thing,0,strpos($thing,"JavaScript"));
  144. }
  145. // ok so now we have the listing.
  146. $tmpListArr = explode("</tr>",$tmpList);
  147. $langFile = $this->cfg["_FILE"];
  148. $bg = $this->cfg["bgLight"];
  149. foreach($tmpListArr as $key =>$value)
  150. {
  151. $buildLine = true;
  152. if (strpos($value,"/torrent?do"))
  153. {
  154. $ts = new btJunk($value);
  155. // Determine if we should build this output
  156. if (is_int(array_search($ts->MainId,$this->catFilter)))
  157. {
  158. $buildLine = false;
  159. }
  160. if ($this->hideSeedless == "yes")
  161. {
  162. if($ts->Seeds == "N/A" || $ts->Seeds == "0")
  163. {
  164. $buildLine = false;
  165. }
  166. }
  167. if (!empty($ts->torrentFile) && $buildLine) {
  168. $output .= trim($ts->BuildOutput($bg,$langFile,$this->searchURL()));
  169. // ok switch colors.
  170. if ($bg == $this->cfg["bgLight"])
  171. {
  172. $bg = $this->cfg["bgDark"];
  173. }
  174. else
  175. {
  176. $bg = $this->cfg["bgLight"];
  177. }
  178. }
  179. }
  180. }
  181. // set thing to end of this table.
  182. $thing = substr($thing,strpos($thing,"do=gear"));
  183. }
  184. $output .= "</table>";
  185. // is there paging at the bottom?
  186. if (strpos($thing, "<p class=\"pagenav\">Pages (") !== false)
  187. {
  188. // Yes, then lets grab it and display it! ;)
  189. $thing = substr($thing,strpos($thing,"<p class=\"pagenav\">Pages (")+strlen("<p class=\"pagenav\">"));
  190. $pages = substr($thing,0,strpos($thing,"</p>"));
  191. $page1 = substr($pages,0,strpos($pages,"<img"));
  192. $page2 = substr($pages,strlen($page1));
  193. $page2 = substr($page2,strpos($page2,'>')+1);
  194. $pages = $page1.$page2;
  195. $output .= "<br><div align=center>".$pages."</div><br>";
  196. }
  197. return $output;
  198. }
  199. }
  200. // This is a worker class that takes in a row in a table and parses it.
  201. class btJunk
  202. {
  203. var $torrentName = "";
  204. var $torrentDisplayName = "";
  205. var $torrentFile = "";
  206. var $MainId = "";
  207. var $MainCategory = "";
  208. var $torrentSize = "";
  209. var $Seeds = "";
  210. var $Peers = "";
  211. var $Data = "";
  212. function btJunk( $htmlLine )
  213. {
  214. if (strlen($htmlLine) > 0)
  215. {
  216. $this->Data = $htmlLine;
  217. // Chunck up the row into columns.
  218. $tmpListArr = explode("</th>",$htmlLine);
  219. /*
  220. (
  221. [0] => <tr bgcolor="#FFFFFF"><th width="60%" align="left">
  222. <a href="/torrent?do=download&id=3780687290ec6d04d99417b85ef14bca45f030c90781"><img src="/images/down.gif" alt="Download Torrent" border="0"></a>
  223. <a href="/?do=listfiles&id=3780687290ec6d04d99417b85ef14bca45f030c90781" onclick="return listfiles(this,750,50,'2px solid',0,0,'img3780687290ec6d04d99417b85ef14bca45f030c90781');">
  224. <img name="img3780687290ec6d04d99417b85ef14bca45f030c90781" src="/images/expand.gif" alt="File Listing" border="0"></a>&nbsp;
  225. <a href="/torrent?do=stat&id=3780687290ec6d04d99417b85ef14bca45f030c90781" class="BlckUnd"><b>Paris Hilton - Paris (withcovers) a DHZ Inc Release</b></a>
  226. )
  227. */
  228. if(count($tmpListArr) > 5)
  229. {
  230. //$tmpListArr["0"]; // Torrent Name, Download Link, Status
  231. $this->torrentDisplayName = $this->cleanLine($tmpListArr["0"]); // TorrentName
  232. $tmpStr = substr($tmpListArr["0"],strpos($tmpListArr["0"],"torrent?"),strpos($tmpListArr["0"],"><img")-6);
  233. $this->torrentFile = "http://btjunkie.org/" . substr($tmpStr,0,strpos($tmpStr,"\""));
  234. if (strpos($this->torrentFile,"do=stat"))
  235. {
  236. $this->torrentFile = str_replace("do=stat","do=download",$this->torrentFile);
  237. }
  238. $this->torrentName = $this->torrentDisplayName;
  239. $this->MainCategory = $this->cleanLine($tmpListArr["1"]);
  240. $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
  241. $this->torrentSize = $this->cleanLine($tmpListArr["2"]); // Size of File
  242. $this->Seeds = $this->cleanLine($tmpListArr["4"]); // Seeds
  243. $this->Peers = $this->cleanLine($tmpListArr["5"]); // Peers
  244. if ($this->Seeds == '') $this->Seeds = "N/A";
  245. if ($this->Seeds == 'X') $this->Seeds = "N/A";
  246. if ($this->Peers == '') $this->Peers = "N/A";
  247. if ($this->Peers == 'X') $this->Peers = "N/A";
  248. if(strlen($this->torrentDisplayName) > 50)
  249. {
  250. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  251. }
  252. }
  253. }
  254. }
  255. function cleanLine($stringIn,$tags='')
  256. {
  257. if(empty($tags))
  258. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  259. else
  260. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  261. }
  262. //----------------------------------------------------------------
  263. // Function to build output for the table.
  264. function BuildOutput($bg,$langFILE, $searchURL = '')
  265. {
  266. $output = "<tr>\n";
  267. $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";
  268. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  269. $output .= "</td>\n";
  270. if (strlen($this->MainCategory) > 1){
  271. $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
  272. }
  273. $output .= " <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
  274. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  275. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  276. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  277. $output .= "</tr>\n";
  278. return $output;
  279. }
  280. }
  281. ?>