1
0

BitMeEngine.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <?php
  2. /* $Id: BitMeEngine.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 17, 06. Fixed a bug on the tooltip display name of the torrent search results
  23. v 1.00 - Oct 17, 06. Ripped all of Anglachel's code on BitMeTV.org search module to create this for BitMe.org. Thanks anglachel!
  24. */
  25. class SearchEngine extends SearchEngineBase
  26. {
  27. function SearchEngine($cfg)
  28. {
  29. $this->mainURL = "www.bitme.org";
  30. $this->altURL = "www.bitme.org";
  31. $this->mainTitle = "BitMe";
  32. $this->engineName = "BitMe";
  33. $this->author = "Kalep";
  34. $this->version = "1.01-tfb";
  35. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,2085.0.html";
  36. $this->Initialize($cfg);
  37. }
  38. function populateMainCategories()
  39. {
  40. $this->mainCatalog["1"] = "AppDev";
  41. $this->mainCatalog["2"] = "Audio";
  42. $this->mainCatalog["3"] = "CBT";
  43. $this->mainCatalog["4"] = "College Lectures";
  44. $this->mainCatalog["5"] = "Documentaries";
  45. $this->mainCatalog["6"] = "e-Books";
  46. $this->mainCatalog["7"] = "Keystone";
  47. $this->mainCatalog["8"] = "Languages";
  48. $this->mainCatalog["9"] = "LearnKey";
  49. $this->mainCatalog["10"] = "Lynda.com";
  50. $this->mainCatalog["11"] = "Misc";
  51. $this->mainCatalog["12"] = "Misc E-Learning";
  52. $this->mainCatalog["13"] = "Total Training";
  53. $this->mainCatalog["14"] = "ART";
  54. $this->mainCatalog["15"] = "3D Buzz";
  55. $this->mainCatalog["16"] = "SFX";
  56. $this->mainCatalog["17"] = "Stock Photography";
  57. $this->mainCatalog["18"] = "Medical";
  58. $this->mainCatalog["19"] = "Magic";
  59. $this->mainCatalog["20"] = "3D";
  60. $this->mainCatalog["21"] = "Dating";
  61. $this->mainCatalog["22"] = "Music Learning";
  62. $this->mainCatalog["23"] = "Political";
  63. $this->mainCatalog["24"] = "Religion";
  64. $this->mainCatalog["25"] = "Self Improvement";
  65. $this->mainCatalog["26"] = "Sports";
  66. $this->mainCatalog["27"] = "Video Stock";
  67. }
  68. //----------------------------------------------------------------
  69. // Function to Get Sub Categories
  70. /* function getSubCategories($mainGenre)
  71. {
  72. return $output;
  73. }*/
  74. //----------------------------------------------------------------
  75. // Function to Make the Request (overriding base)
  76. function makeRequest($request)
  77. {
  78. return parent::makeRequest($request, false);
  79. }
  80. //----------------------------------------------------------------
  81. // Function to get Latest..
  82. function getLatest()
  83. {
  84. $cat = tfb_getRequestVar('mainGenre');
  85. if (empty($cat)) $cat = tfb_getRequestVar('cat');
  86. $request = "/browse.php";
  87. if(!empty($cat))
  88. {
  89. if(strpos($request,"?"))
  90. {
  91. $request .= "&cat=".$cat;
  92. }
  93. else
  94. {
  95. $request .= "?cat=".$cat;
  96. }
  97. }
  98. if (!empty($this->pg))
  99. {
  100. if(strpos($request,"?"))
  101. {
  102. $request .= "&page=" . $this->pg;
  103. }
  104. else
  105. {
  106. $request .= "?page=" . $this->pg;
  107. }
  108. }
  109. if ($this->makeRequest($request,true))
  110. {
  111. if (strlen($this->htmlPage) > 0 )
  112. {
  113. return $this->parseResponse();
  114. }
  115. else
  116. {
  117. return 'Unable to Browse at this time.';
  118. }
  119. }
  120. else
  121. {
  122. return $this->msg;
  123. }
  124. }
  125. //----------------------------------------------------------------
  126. // Function to perform Search.
  127. function performSearch($searchTerm)
  128. {
  129. // create the request string.
  130. $searchTerm = str_replace(" ", "+", $searchTerm);
  131. $request = "/browse.php?search=".$searchTerm;
  132. if(!empty($cat))
  133. {
  134. $request .= "&cat=".$cat;
  135. }
  136. $incldead = tfb_getRequestVar('incldead');
  137. if (empty($incldead)) $incldead = "0";
  138. $request .= "&incldead=".$incldead;
  139. if (!empty($this->pg))
  140. {
  141. $request .= "&page=" . $this->pg;
  142. }
  143. if ($this->makeRequest($request,true))
  144. {
  145. return $this->parseResponse();
  146. }
  147. else
  148. {
  149. return $this->msg;
  150. }
  151. }
  152. //----------------------------------------------------------------
  153. // Override the base to show custom table header.
  154. // Function to setup the table header
  155. function tableHeader()
  156. {
  157. $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
  158. $output .= "<br>\n";
  159. $output .= "<tr bgcolor=\"".$this->cfg["bgLight"]."\">";
  160. if ($needWait)
  161. {
  162. $output .= " <td colspan=9 align=center>";
  163. }
  164. else
  165. {
  166. $output .= " <td colspan=8 align=center>";
  167. }
  168. if (is_integer(strpos($this->htmlPage,"Welcome back, ")))
  169. {
  170. $userinfo = substr($this->htmlPage,strpos($this->htmlPage,"Welcome back, ")+strlen("Welcome back, "));
  171. $userinfo = substr($userinfo,strpos($userinfo,"<br/>")+strlen("<br/>"));
  172. // Comment the following line and uncomment the next two if you would like to have the arrows for active torrents. Remember to download the arrow files and put them in your images directory
  173. $userinfo = substr($userinfo,0,strpos($userinfo,"Active:"));
  174. //$userinfo = substr($userinfo,0,strpos($userinfo,"</td>"));
  175. //$userinfo = str_replace("../pic/", "images/", $userinfo);
  176. $output .= $userinfo;
  177. }
  178. $output .= "</td></tr>";
  179. $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
  180. $output .= " <td>&nbsp;</td>";
  181. $output .= " <td><strong>Torrent Name</strong> &nbsp;(";
  182. $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
  183. // Check to see if Question mark is there.
  184. if (strpos($tmpURI,'?'))
  185. {
  186. $tmpURI .= "&";
  187. }
  188. else
  189. {
  190. $tmpURI .= "?";
  191. }
  192. if($this->hideSeedless == "yes")
  193. {
  194. $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
  195. }
  196. else
  197. {
  198. $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
  199. }
  200. $output .= ")</td>";
  201. $output .= " <td><strong>Category</strong></td>";
  202. $output .= " <td align=center><strong>Life</strong></td>";
  203. $output .= " <td align=center><strong>Size</strong></td>";
  204. $output .= " <td><strong>Seeds</strong></td>";
  205. $output .= " <td><strong>Peers</strong></td>";
  206. $output .= " <td><strong>Snatched</strong></td>";
  207. $output .= "</tr>\n";
  208. return $output;
  209. }
  210. //----------------------------------------------------------------
  211. // Function to parse the response.
  212. function parseResponse($latest = true)
  213. {
  214. $thing = $this->htmlPage;
  215. if(strpos($thing,"Not logged in!") > 0)
  216. {
  217. $tmpStr = substr($thing,strpos($thing,"takelogin"));
  218. $tmpStr = substr($tmpStr,strpos($tmpStr, ">")+1);
  219. $tmpStr2 = "<form method=\"post\" action=\"http://".$this->mainURL."/takelogin.php\">";
  220. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"</form>")+strlen("</form>"));
  221. $output = $tmpStr2.str_replace("src=\"","src=\"http://".$this->mainURL."/",$tmpStr)."</table>";
  222. }
  223. else
  224. {
  225. $output = $this->tableHeader();
  226. if(strpos($thing,"Error:") > 0)
  227. {
  228. $tmpStr = substr($thing,strpos($thing,"Error:")+strlen("Error:"));
  229. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"</p>"));
  230. $this->msg = strip_tags($tmpStr);
  231. return $output . "<center>".$this->msg."</center><br>";
  232. }
  233. // We got a response so display it.
  234. // Chop the front end off.
  235. $thing = substr($thing,strpos($thing,"leechers.gif></a></td>"));
  236. $thing = substr($thing,strpos($thing,"<tr>")+strlen("<tr>"));
  237. //$tmpList = substr($thing,0,strpos($thing,"</table>"));
  238. // ok so now we have the listing.
  239. $tmpListArr = explode("</tr>",$thing);
  240. $bg = $this->cfg["bgLight"];
  241. //var_export($tmpListArr);
  242. foreach($tmpListArr as $key =>$value)
  243. {
  244. $buildLine = true;
  245. if (strpos($value,"id="))
  246. {
  247. $ts = new BitMe($value);
  248. if (!empty($ts->torrentFile) && $buildLine) {
  249. $output .= trim($ts->BuildOutput($bg,$this->searchURL()));
  250. // ok switch colors.
  251. if ($bg == $this->cfg["bgLight"])
  252. {
  253. $bg = $this->cfg["bgDark"];
  254. }
  255. else
  256. {
  257. $bg = $this->cfg["bgLight"];
  258. }
  259. }
  260. }
  261. }
  262. // set thing to end of this table.
  263. $thing = substr($thing,strpos($thing,"</table>"));
  264. $output .= "</table>";
  265. // is there paging at the bottom?
  266. if (strpos($thing, "page=") != false)
  267. {
  268. // Yes, then lets grab it and display it! ;)
  269. $pages = substr($thing,strpos($thing,"<p"));
  270. $pages = substr($pages,strpos($pages,">"));
  271. $pages = substr($pages,0,strpos($pages,"</p>"));
  272. $pages = str_replace("&nbsp; ",'',$pages);
  273. $tmpPageArr = explode("</a>",$pages);
  274. array_pop($tmpPageArr);
  275. $pagesout = '';
  276. foreach($tmpPageArr as $key => $value)
  277. {
  278. $value .= "</a> &nbsp;";
  279. $tmpVal = substr($value,strpos($value,"browse.php?"),strpos($value,">")-1);
  280. $pgNum = substr($tmpVal,strpos($tmpVal,"page=")+strlen("page="));
  281. $pagesout .= str_replace($tmpVal,"XXXURLXXX".$pgNum,$value);
  282. }
  283. $cat = tfb_getRequestVar('mainGenre');
  284. if(strpos($this->curRequest,"LATEST"))
  285. {
  286. if (!empty($cat))
  287. {
  288. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&cat=".$cat."&pg=",$pagesout);
  289. }
  290. else
  291. {
  292. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&pg=",$pagesout);
  293. }
  294. }
  295. else
  296. {
  297. if(!empty($cat))
  298. {
  299. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&cat=".$cat."&pg=",$pagesout);
  300. }
  301. else
  302. {
  303. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&pg=",$pagesout);
  304. }
  305. }
  306. // $pages = strip_tags($pages,"<a><b>");
  307. $output .= "<div align=center>".substr($pages,1)."</div>";
  308. }
  309. }
  310. return $output;
  311. }
  312. }
  313. // This is a worker class that takes in a row in a table and parses it.
  314. class BitMe
  315. {
  316. var $torrentName = "";
  317. var $torrentDisplayName = "";
  318. var $torrentFile = "";
  319. var $torrentSize = "";
  320. var $torrentLife = "";
  321. var $torrentStatus = "";
  322. var $MainId = "";
  323. var $MainCategory = "";
  324. var $fileCount = "";
  325. var $Seeds = "";
  326. var $Peers = "";
  327. var $needsWait = false;
  328. var $waitTime = "";
  329. var $Data = "";
  330. var $torrentRating = "";
  331. function BitMe( $htmlLine )
  332. {
  333. if (strlen($htmlLine) > 0)
  334. {
  335. $this->Data = $htmlLine;
  336. // Cleanup any bugs in the HTML
  337. $htmlLine = preg_replace("/</td>\n</td>/i",'</td>',$htmlLine);
  338. // Chunck up the row into columns.
  339. $tmpListArr = explode("<td ",$htmlLine);
  340. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"alt=\"")+strlen("alt=\"")); // MainCategory
  341. $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
  342. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"cat=")+strlen("cat=")); // Main Id
  343. $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
  344. $this->torrentName = substr($tmpListArr["2"],strpos($tmpListArr["2"],"title=")+strlen("title="));
  345. $this->torrentName = substr($this->torrentName,0,strpos($this->torrentName,"><b>"));
  346. $tmpStr = substr($tmpListArr["3"],strpos($tmpListArr["3"],"href=\"download.php")+strlen("href=\""));
  347. $this->torrentFile = "http://www.bitme.org/".substr($tmpStr,0,strpos($tmpStr,"\""));
  348. $this->fileCount = $this->cleanLine("<td ".$tmpListArr["4"]."</td>"); // File Count
  349. $this->torrentLife = "&nbsp;&nbsp;".$this->cleanLine("<td ".$tmpListArr["8"]."</td>");
  350. $this->torrentLife = str_replace("hours", " hr", $this->torrentLife);
  351. $this->torrentLife = str_replace("hour", " hr", $this->torrentLife); // Life of File
  352. $this->torrentSize = "&nbsp;&nbsp;".$this->cleanLine("<td ".$tmpListArr["9"]."</td>"); // Size of File
  353. $this->torrentStatus = $this->cleanLine(str_replace("<br>"," ","<td ".$tmpListArr["10"]."</td>")); // Snatched
  354. $this->Seeds = $this->cleanLine("<td ".$tmpListArr["11"]."</td>"); // Seeds
  355. $this->Peers = $this->cleanLine("<td ".$tmpListArr["12"]."</td>"); // Leech
  356. $this->torrentDisplayName = $this->torrentName;
  357. if(strlen($this->torrentDisplayName) > 50)
  358. {
  359. $this->torrentDisplayName = substr(str_replace("&nbsp;", " ", $this->torrentDisplayName),0,50)."...";
  360. }
  361. }
  362. }
  363. function cleanLine($stringIn,$tags='')
  364. {
  365. if(empty($tags))
  366. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  367. else
  368. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  369. }
  370. //----------------------------------------------------------------
  371. // Function to build output for the table.
  372. function BuildOutput($bg, $searchURL = '')
  373. {
  374. $output = "<tr>\n";
  375. $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";
  376. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  377. if (strlen($this->MainCategory) > 1){
  378. $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
  379. }else{
  380. $genre = "";
  381. }
  382. $output .= " <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
  383. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentLife."</td>\n";
  384. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  385. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  386. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  387. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
  388. $output .= "</tr>\n";
  389. return $output;
  390. }
  391. }
  392. ?>