OinkMeEngine.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. /* $Id: OinkMeEngine.php 2955 2007-04-30 15:21:07Z munk $ */
  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. include_once("SearchEngineBase.php");
  22. class SearchEngine extends SearchEngineBase
  23. {
  24. function SearchEngine($cfg)
  25. {
  26. $this->mainURL = "oink.me.uk";
  27. $this->altURL = "oink.me.uk";
  28. $this->mainTitle = "OinkMe";
  29. $this->engineName = "OinkMe";
  30. $this->author = "JimmyTheGrunt, and Anglachel";
  31. $this->version = "1.11-tfb";
  32. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,1096.0.html";
  33. //$this->updateURL = "http://www.torrentflux.com/forum/index.php";
  34. $this->Initialize($cfg);
  35. }
  36. //----------------------------------------------------------------
  37. // Function to Get Main Categories
  38. function populateMainCategories()
  39. {
  40. $this->mainCatalog["41"] = "Audio Books (Fiction)";
  41. $this->mainCatalog["89"] = "Audio Books (Non-Fiction)";
  42. $this->mainCatalog["44"] = "Comedy";
  43. $this->mainCatalog["88"] = "Comics";
  44. $this->mainCatalog["90"] = "Components";
  45. $this->mainCatalog["33"] = "eBooks (Fiction)";
  46. $this->mainCatalog["81"] = "eBooks (Non-Fiction)";
  47. $this->mainCatalog["82"] = "eLearning Videos";
  48. $this->mainCatalog["69"] = "Mac Apps";
  49. $this->mainCatalog["62"] = "Music Apps";
  50. $this->mainCatalog["35"] = "Phone";
  51. $this->mainCatalog["83"] = "Sheet Music";
  52. $this->mainCatalog["22"] = "Win Apps";
  53. $this->mainCatalog["47"] = "60s";
  54. $this->mainCatalog["48"] = "70s";
  55. $this->mainCatalog["49"] = "80s";
  56. $this->mainCatalog["50"] = "90s";
  57. $this->mainCatalog["39"] = "Alternative";
  58. $this->mainCatalog["56"] = "Ambient";
  59. $this->mainCatalog["73"] = "Asian";
  60. $this->mainCatalog["84"] = "Bluegrass";
  61. $this->mainCatalog["53"] = "Blues";
  62. $this->mainCatalog["78"] = "Breaks";
  63. $this->mainCatalog["43"] = "Classical";
  64. $this->mainCatalog["34"] = "Country";
  65. $this->mainCatalog["24"] = "Dance";
  66. $this->mainCatalog["55"] = "Drum 'n' Bass";
  67. $this->mainCatalog["6"] = "Electronic";
  68. $this->mainCatalog["58"] = "Emo";
  69. $this->mainCatalog["63"] = "Experimental";
  70. $this->mainCatalog["59"] = "Folk";
  71. $this->mainCatalog["75"] = "Funk";
  72. $this->mainCatalog["60"] = "Garage";
  73. $this->mainCatalog["76"] = "Hardcore";
  74. $this->mainCatalog["30"] = "Hip-Hop/Rap";
  75. $this->mainCatalog["40"] = "House";
  76. $this->mainCatalog["51"] = "IDM";
  77. $this->mainCatalog["38"] = "Indie";
  78. $this->mainCatalog["57"] = "Industrial";
  79. $this->mainCatalog["77"] = "J-Music";
  80. $this->mainCatalog["37"] = "Jazz";
  81. $this->mainCatalog["65"] = "Kids";
  82. $this->mainCatalog["85"] = "Latin";
  83. $this->mainCatalog["31"] = "Metal";
  84. $this->mainCatalog["25"] = "Misc";
  85. $this->mainCatalog["27"] = "OST";
  86. $this->mainCatalog["1"] = "Pop";
  87. $this->mainCatalog["86"] = "Post-Rock";
  88. $this->mainCatalog["46"] = "Pre 60s";
  89. $this->mainCatalog["80"] = "Psychedelic";
  90. $this->mainCatalog["42"] = "Punk";
  91. $this->mainCatalog["28"] = "R'n'B";
  92. $this->mainCatalog["32"] = "Reggae";
  93. $this->mainCatalog["23"] = "Rock";
  94. $this->mainCatalog["61"] = "Ska";
  95. $this->mainCatalog["45"] = "Soul";
  96. $this->mainCatalog["71"] = "Techno";
  97. $this->mainCatalog["66"] = "Trance";
  98. $this->mainCatalog["74"] = "Trip Hop";
  99. $this->mainCatalog["64"] = "UK Garage";
  100. $this->mainCatalog["54"] = "World/Ethnic";
  101. $this->mainCatalog["87"] = "Xmas";
  102. }
  103. //----------------------------------------------------------------
  104. // Function to get Latest..
  105. function getLatest()
  106. {
  107. $cat = tfb_getRequestVar('mainGenre');
  108. if (empty($cat)) $cat = tfb_getRequestVar('cat');
  109. $request = "/browse.php";
  110. if(!empty($cat))
  111. {
  112. if(strpos($request,"?"))
  113. {
  114. $request .= "&cat=".$cat;
  115. }
  116. else
  117. {
  118. $request .= "?cat=".$cat;
  119. }
  120. }
  121. if (!empty($this->pg))
  122. {
  123. if(strpos($request,"?"))
  124. {
  125. $request .= "&page=" . $this->pg;
  126. }
  127. else
  128. {
  129. $request .= "?page=" . $this->pg;
  130. }
  131. }
  132. if ($this->makeRequest($request,true))
  133. {
  134. if (strlen($this->htmlPage) > 0 )
  135. {
  136. return $this->parseResponse();
  137. }
  138. else
  139. {
  140. return 'Unable to Browse at this time.';
  141. }
  142. }
  143. else
  144. {
  145. return $this->msg;
  146. }
  147. }
  148. //----------------------------------------------------------------
  149. // Function to perform Search.
  150. function performSearch($searchTerm)
  151. {
  152. // create the request string.
  153. $searchTerm = str_replace(" ", "+", $searchTerm);
  154. $request = "/browse.php?search=".$searchTerm;
  155. if(!empty($cat))
  156. {
  157. $request .= "&cat=".$cat;
  158. }
  159. $incldead = tfb_getRequestVar('incldead');
  160. if (empty($incldead)) $incldead = "0";
  161. $request .= "&incldead=".$incldead;
  162. if (!empty($this->pg))
  163. {
  164. $request .= "&page=" . $this->pg;
  165. }
  166. if ($this->makeRequest($request,true))
  167. {
  168. return $this->parseResponse();
  169. }
  170. else
  171. {
  172. return $this->msg;
  173. }
  174. }
  175. //----------------------------------------------------------------
  176. // Override the base to show custom table header.
  177. // Function to setup the table header
  178. function tableHeader()
  179. {
  180. $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
  181. $output .= "<br>\n";
  182. $output .= "<tr bgcolor=\"".$this->cfg["bgLight"]."\">";
  183. if ($needWait)
  184. {
  185. $output .= " <td colspan=8 align=center>";
  186. }
  187. else
  188. {
  189. $output .= " <td colspan=7 align=center>";
  190. }
  191. if (is_integer(strpos($this->htmlPage,"Welcome back, ")))
  192. {
  193. $userinfo = substr($this->htmlPage,strpos($this->htmlPage,"Welcome back, ")+strlen("Welcome back, "));
  194. $userinfo = substr($userinfo,strpos($userinfo,"<br />")+strlen("<br />"));
  195. $userinfo = substr($userinfo,0,strpos($userinfo,"<br />"));
  196. //$userinfo = substr($userinfo,strpos($userinfo,"<br>")+strlen("<br>"));
  197. //$userinfo = str_replace("<font class=\"font_10px\">","",$userinfo);
  198. //$userinfo = str_replace("</font>","",$userinfo);
  199. //$userinfo = str_replace("<br>","",$userinfo);
  200. //$output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
  201. $output .= $userinfo;
  202. }
  203. $output .= "</td></tr>";
  204. $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
  205. $output .= " <td>&nbsp;</td>";
  206. $output .= " <td><strong>Torrent Name</strong> &nbsp;(";
  207. $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
  208. // Check to see if Question mark is there.
  209. if (strpos($tmpURI,'?'))
  210. {
  211. $tmpURI .= "&";
  212. }
  213. else
  214. {
  215. $tmpURI .= "?";
  216. }
  217. if($this->hideSeedless == "yes")
  218. {
  219. $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
  220. }
  221. else
  222. {
  223. $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
  224. }
  225. $output .= ")</td>";
  226. $output .= " <td><strong>Category</strong></td>";
  227. $output .= " <td align=center><strong>&nbsp;&nbsp;Size</strong></td>";
  228. $output .= " <td><strong>Seeds</strong></td>";
  229. $output .= " <td><strong>Peers</strong></td>";
  230. $output .= " <td><strong>Snatched</strong></td>";
  231. $output .= "</tr>\n";
  232. return $output;
  233. }
  234. //----------------------------------------------------------------
  235. // Function to parse the response.
  236. function parseResponse($latest = true)
  237. {
  238. $thing = $this->htmlPage;
  239. if(strpos($thing,"Not logged in!") > 0)
  240. {
  241. $tmpStr = substr($thing,strpos($thing,"takelogin"));
  242. $tmpStr = substr($tmpStr,strpos($tmpStr, ">")+1);
  243. $tmpStr2 = "<form method=\"post\" action=\"http://".$this->mainURL."/takelogin.php\">";
  244. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"</form>")+strlen("</form>"));
  245. $output = $tmpStr2.str_replace("src=\"","src=\"http://".$this->mainURL."/",$tmpStr)."</table>";
  246. }
  247. else
  248. {
  249. $output = $this->tableHeader();
  250. if(strpos($thing,"Error:") > 0)
  251. {
  252. $tmpStr = substr($thing,strpos($thing,"Error:")+strlen("Error:"));
  253. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"</p>"));
  254. $this->msg = strip_tags($tmpStr);
  255. return $output . "<center>".$this->msg."</center><br>";
  256. }
  257. // We got a response so display it.
  258. // Chop the front end off.
  259. $thing = substr($thing,strpos($thing,">Upped&nbsp;by<"));
  260. $thing = substr($thing,strpos($thing,"<tr>")+strlen("<tr>"));
  261. //$tmpList = substr($thing,0,strpos($thing,"</table>"));
  262. // ok so now we have the listing.
  263. $tmpListArr = explode("</tr>",$thing);
  264. $bg = $this->cfg["bgLight"];
  265. //var_export($tmpListArr);
  266. foreach($tmpListArr as $key =>$value)
  267. {
  268. $buildLine = true;
  269. if (strpos($value,"id="))
  270. {
  271. $ts = new OinkMe($value);
  272. // Determine if we should build this output
  273. /*if (is_int(array_search($ts->MainId,$this->catFilter)))
  274. {
  275. $buildLine = false;
  276. }
  277. if ($this->hideSeedless == "yes")
  278. {
  279. if($ts->Seeds == "N/A" || $ts->Seeds == "0")
  280. {
  281. $buildLine = false;
  282. }
  283. }*/
  284. if (!empty($ts->torrentFile) && $buildLine) {
  285. $output .= trim($ts->BuildOutput($bg,$this->searchURL()));
  286. // ok switch colors.
  287. if ($bg == $this->cfg["bgLight"])
  288. {
  289. $bg = $this->cfg["bgDark"];
  290. }
  291. else
  292. {
  293. $bg = $this->cfg["bgLight"];
  294. }
  295. }
  296. }
  297. }
  298. // set thing to end of this table.
  299. $thing = substr($thing,strpos($thing,"</table>"));
  300. $output .= "</table>";
  301. // is there paging at the bottom?
  302. if (strpos($thing, "page=") != false)
  303. {
  304. // Yes, then lets grab it and display it! ;)
  305. $pages = substr($thing,strpos($thing,"<p"));
  306. $pages = substr($pages,strpos($pages,">"));
  307. $pages = substr($pages,0,strpos($pages,"</p>"));
  308. $pages = str_replace("&nbsp; ",'',$pages);
  309. $tmpPageArr = explode("</a>",$pages);
  310. array_pop($tmpPageArr);
  311. $pagesout = '';
  312. foreach($tmpPageArr as $key => $value)
  313. {
  314. $value .= "</a> &nbsp;";
  315. $tmpVal = substr($value,strpos($value,"browse.php?"),strpos($value,">")-1);
  316. $pgNum = substr($tmpVal,strpos($tmpVal,"page=")+strlen("page="));
  317. $pagesout .= str_replace($tmpVal,"XXXURLXXX".$pgNum,$value);
  318. }
  319. $cat = tfb_getRequestVar('mainGenre');
  320. if(strpos($this->curRequest,"LATEST"))
  321. {
  322. if (!empty($cat))
  323. {
  324. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&cat=".$cat."&pg=",$pagesout);
  325. }
  326. else
  327. {
  328. $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&pg=",$pagesout);
  329. }
  330. }
  331. else
  332. {
  333. if(!empty($cat))
  334. {
  335. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&cat=".$cat."&pg=",$pagesout);
  336. }
  337. else
  338. {
  339. $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&pg=",$pagesout);
  340. }
  341. }
  342. // $pages = strip_tags($pages,"<a><b>");
  343. $output .= "<div align=center>".substr($pages,1)."</div>";
  344. }
  345. }
  346. return $output;
  347. }
  348. }
  349. // This is a worker class that takes in a row in a table and parses it.
  350. class OinkMe
  351. {
  352. var $torrentName = "";
  353. var $torrentDisplayName = "";
  354. var $torrentFile = "";
  355. var $torrentSize = "";
  356. var $torrentStatus = "";
  357. var $MainId = "";
  358. var $MainCategory = "";
  359. var $fileCount = "";
  360. var $Seeds = "";
  361. var $Peers = "";
  362. var $needsWait = false;
  363. var $waitTime = "";
  364. var $Data = "";
  365. var $torrentRating = "";
  366. function OinkMe( $htmlLine )
  367. {
  368. if (strlen($htmlLine) > 0)
  369. {
  370. $this->Data = $htmlLine;
  371. // Cleanup any bugs in the HTML
  372. $htmlLine = preg_replace("/</td>\n</td>/i",'</td>',$htmlLine);
  373. // Chunck up the row into columns.
  374. $tmpListArr = explode("<td ",$htmlLine);
  375. //if(count($tmpListArr) > 12)
  376. //{
  377. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"alt=\"")+strlen("alt=\"")); // MainCategory
  378. $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
  379. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"cat=")+strlen("cat=")); // Main Id
  380. $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
  381. //$this->torrentName = $this->cleanLine("<td ".$tmpListArr["2"]."</td>"); // TorrentName
  382. $tmpStr = substr($tmpListArr["2"], strpos($tmpListArr["2"],"<b>")+strlen("<b>"));
  383. $this->torrentName = substr($tmpStr, 0, strpos($tmpStr, "</b>"));
  384. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"href=\"downloadpk")+strlen("href=\""));
  385. $this->torrentFile = "http://oink.me.uk/".substr($tmpStr,0,strpos($tmpStr,"\""));
  386. //$tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"id=")+strlen("id=")); // File Id
  387. //$tmpStr = substr($tmpStr,0,strpos($tmpStr,"&"));
  388. //$this->torrentFile = "http://oink.me.uk/downloadpk/".$tmpStr."/".str_replace(" ","_",$this->torrentName).".torrent";
  389. $this->fileCount = $this->cleanLine("<td ".$tmpListArr["3"]."</td>"); // File Count
  390. $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["6"]."</td>"); // Size of File
  391. $this->torrentStatus = $this->cleanLine(str_replace("<br>"," ","<td ".$tmpListArr["4"]."</td>")); // Snatched
  392. $this->Seeds = $this->cleanLine("<td ".$tmpListArr["8"]."</td>"); // Seeds
  393. $this->Peers = $this->cleanLine("<td ".$tmpListArr["9"]."</td>"); // Leech
  394. /*if ($this->Peers == '')
  395. {
  396. $this->Peers = "N/A";
  397. if (empty($this->Seeds)) $this->Seeds = "N/A";
  398. }
  399. if ($this->Seeds == '') $this->Seeds = "N/A";*/
  400. $this->torrentDisplayName = $this->torrentName;
  401. if(strlen($this->torrentDisplayName) > 50)
  402. {
  403. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  404. }
  405. //}
  406. /*elseif (count($tmpListArr) > 11)
  407. {
  408. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"alt=\"")+strlen("alt=\"")); // MainCategory
  409. $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
  410. $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"cat=")+strlen("cat=")); // Main Id
  411. $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
  412. $this->torrentName = $this->cleanLine("<td ".$tmpListArr["2"]."</td>"); // TorrentName
  413. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"id=")+strlen("id=")); // File Id
  414. $tmpStr = substr($tmpStr,0,strpos($tmpStr,"&"));
  415. $this->torrentFile = "http://oink.me.uk/downloadpk/".$tmpStr."/".str_replace(" ","_",$this->torrentName).".torrent";
  416. $this->fileCount = $this->cleanLine("<td ".$tmpListArr["4"]."</td>"); // File Count
  417. $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["7"]."</td>"); // Size of File
  418. $this->torrentStatus = $this->cleanLine(str_replace("<br>"," ","<td ".$tmpListArr["8"]."</td>")); // Snatched
  419. $this->Seeds = $this->cleanLine("<td ".$tmpListArr["9"]."</td>"); // Seeds
  420. $this->Peers = $this->cleanLine("<td ".$tmpListArr["10"]."</td>"); // Leech
  421. if ($this->Peers == '')
  422. {
  423. $this->Peers = "N/A";
  424. if (empty($this->Seeds)) $this->Seeds = "N/A";
  425. }
  426. if ($this->Seeds == '') $this->Seeds = "N/A";
  427. $this->torrentDisplayName = $this->torrentName;
  428. if(strlen($this->torrentDisplayName) > 50)
  429. {
  430. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  431. }
  432. }*/
  433. }
  434. }
  435. function cleanLine($stringIn,$tags='')
  436. {
  437. if(empty($tags))
  438. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  439. else
  440. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  441. }
  442. //----------------------------------------------------------------
  443. // Function to build output for the table.
  444. function BuildOutput($bg, $searchURL = '')
  445. {
  446. $output = "<tr>\n";
  447. $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";
  448. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  449. if (strlen($this->MainCategory) > 1){
  450. $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
  451. }else{
  452. $genre = "";
  453. }
  454. $output .= " <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
  455. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  456. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  457. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  458. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
  459. $output .= "</tr>\n";
  460. return $output;
  461. }
  462. }
  463. ?>