mininovaEngine.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /* $Id: mininovaEngine.php 3231 2007-10-01 22:44:15Z 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. class SearchEngine extends SearchEngineBase
  22. {
  23. function SearchEngine($cfg)
  24. {
  25. $this->mainURL = "www.mininova.org";
  26. $this->altURL = "www.mininova.org";
  27. $this->mainTitle = "mininova";
  28. $this->engineName = "mininova";
  29. $this->author = "sloan";
  30. $this->version = "1.01-tfb";
  31. $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,1501.0.html";
  32. $this->Initialize($cfg);
  33. }
  34. function populateMainCategories()
  35. {
  36. $this->mainCatalog[0] = "(all types)";
  37. $this->mainCatalog[1] = "Anime";
  38. $this->mainCatalog[2] = "Books";
  39. $this->mainCatalog[3] = "Games";
  40. $this->mainCatalog[4] = "Movies";
  41. $this->mainCatalog[5] = "Music";
  42. $this->mainCatalog[6] = "Other";
  43. $this->mainCatalog[7] = "Pictures";
  44. $this->mainCatalog[8] = "Software";
  45. $this->mainCatalog[9] = "TV Shows";
  46. }
  47. //----------------------------------------------------------------
  48. // Function to Make the Request (overriding base)
  49. function makeRequest($request)
  50. {
  51. return parent::makeRequest($request, true);
  52. }
  53. //----------------------------------------------------------------
  54. // Function to get Latest..
  55. function getLatest()
  56. {
  57. $request = "/latest.php?mode=bt";
  58. if (!empty($this->pg))
  59. {
  60. $request .= "&pg=" . $this->pg;
  61. }
  62. if ($this->makeRequest($request))
  63. {
  64. return $this->parseResponse(true);
  65. }
  66. else
  67. {
  68. return $this->msg;
  69. }
  70. }
  71. //----------------------------------------------------------------
  72. // Function to perform Search.
  73. function performSearch($searchTerm)
  74. {
  75. // This is what mininova is looking for in a request.
  76. // http://www.mininova.org/search/?search=test
  77. // create the request string.
  78. $searchTerm = str_replace(" ", "+", $searchTerm);
  79. $request = "/search/$searchTerm/seeds";
  80. if (!empty($this->pg))
  81. {
  82. $request .= "&ihs1=18&iho1=d&iht=-1&ihp=" . $this->pg;
  83. }
  84. // make the request if successful call the parse routine.
  85. if ($this->makeRequest($request))
  86. {
  87. return $this->parseResponse(false);
  88. }
  89. else
  90. {
  91. return $this->msg;
  92. }
  93. }
  94. //----------------------------------------------------------------
  95. // Function to parse the response.
  96. function parseResponse($latest = true)
  97. {
  98. $output = $this->tableHeader();
  99. $thing = $this->htmlPage;
  100. // Strip out those Nasty Iframes.
  101. $thing = preg_replace("/<table[[:space:]]width=[[:punct:]]100%[[:punct:]][[:space:]]cellspacing=[[:punct:]]0[[:punct:]][[:space:]]cellpadding=[[:punct:]]0[[:punct:]][[:space:]]border=[[:punct:]]0[[:punct:]]><tr><td[[:space:]]width=[[:punct:]]10[[:punct:]]></td><td[[:space:]]style=[[:punct:]]border[[:punct:]]3px[[:space:]]solid[[:space:]]#003366[[:punct:]]><iframe[[:space:]]frameborder=[[:punct:]]0[[:punct:]][[:space:]]width=[[:punct:]]100%[[:punct:]][[:space:]]id=[[:punct:]]([a-zA-Z0-9])*[[:punct:]]></iframe></td></tr></table>/i",'',$thing);
  102. // We got a response so display it.
  103. // Chop the front end off.
  104. $thing = substr($thing,strpos($thing,">Leechers<"));
  105. $thing = substr($thing,strpos($thing,"<tr"));
  106. $tmpList = substr($thing,0,strpos($thing,"</table>"));
  107. // ok so now we have the listing.
  108. $tmpListArr = explode("</tr>",$tmpList);
  109. $bg = $this->cfg["bgLight"];
  110. foreach($tmpListArr as $key =>$value)
  111. {
  112. //echo $value;
  113. $buildLine = true;
  114. if (strpos($value,'<a href="/get'))
  115. {
  116. $ts = new mininova($value,$latest);
  117. // Determine if we should build this output
  118. if (is_int(array_search($ts->CatName,$this->catFilter)))
  119. {
  120. $buildLine = false;
  121. }
  122. print_r("<!--");
  123. print_r($this->catFilter);
  124. print_r($ts->CatName);
  125. print_r("-->");
  126. if ($this->hideSeedless == "yes")
  127. {
  128. if($ts->Seeds == "---")
  129. {
  130. $buildLine = false;
  131. }
  132. }
  133. if (!empty($ts->torrentFile) && $buildLine) {
  134. $output .= trim($ts->BuildOutput($bg));
  135. // ok switch colors.
  136. if ($bg == $this->cfg["bgLight"])
  137. {
  138. $bg = $this->cfg["bgDark"];
  139. }
  140. else
  141. {
  142. $bg = $this->cfg["bgLight"];
  143. }
  144. }
  145. }
  146. }
  147. // set thing to end of this table.
  148. $thing = substr($thing,strpos($thing,"</table>"));
  149. $output .= "</table>";
  150. return $output;
  151. }
  152. }
  153. // This is a worker class that takes in a row in a table and parses it.
  154. class mininova
  155. {
  156. var $torrentName = "";
  157. var $torrentDisplayName = "";
  158. var $torrentFile = "";
  159. var $torrentSize = "";
  160. var $torrentStatus = "";
  161. var $CatId = "";
  162. var $CatName = "";
  163. var $fileCount = "";
  164. var $Seeds = "";
  165. var $Peers = "";
  166. var $Data = "";
  167. var $dateAdded = "";
  168. var $dwnldCount = "";
  169. function mininova( $htmlLine , $latest = true)
  170. {
  171. if (strlen($htmlLine) > 0)
  172. {
  173. $this->Data = $htmlLine;
  174. // Chunck up the row into columns.
  175. $tmpListArr = explode("</td>",$htmlLine);
  176. array_pop($tmpListArr);
  177. //print_r($tmpListArr);
  178. //Age Type Torrent Names MB S L
  179. if(count($tmpListArr) > 4)
  180. {
  181. if ($latest)
  182. {
  183. // Latest Request //
  184. $this->CatName = $this->cleanLine($tmpListArr["1"]); // Type
  185. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"/tor/")+5);
  186. $this->torrentFile = "http://www.mininova.org/get/".substr($tmpStr,0,strpos($tmpStr,'">'));
  187. $this->torrentName = $this->cleanLine($tmpListArr["2"]); // Name
  188. $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
  189. $this->Seeds = $this->cleanLine($tmpListArr["4"]); // Seeds
  190. $this->Peers = $this->cleanLine($tmpListArr["5"]); // Leechers
  191. }
  192. else
  193. {
  194. // Search Request //
  195. $this->CatName = $this->cleanLine($tmpListArr["1"]); // Type
  196. $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"/tor/")+5);
  197. $this->torrentFile = "http://www.mininova.org/get/".substr($tmpStr,0,strpos($tmpStr,'">'));
  198. $this->torrentName = $this->cleanLine( substr($tmpListArr[2], strpos($tmpListArr["2"], "<a href=\"/tor")) ); // Name
  199. $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
  200. $this->Seeds = $this->cleanLine($tmpListArr["4"]); // Seeds
  201. $this->Peers = $this->cleanLine($tmpListArr["5"]); // Leechers
  202. $this->torrentDisplayName = $this->torrentName;
  203. }
  204. if ($this->Peers == '')
  205. {
  206. $this->Peers = "N/A";
  207. if (empty($this->Seeds)) $this->Seeds = "N/A";
  208. }
  209. if ($this->Seeds == '') $this->Seeds = "N/A";
  210. $this->torrentDisplayName = str_replace(".torrent",'',$this->torrentName);
  211. if(strlen($this->torrentDisplayName) > 50)
  212. {
  213. $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
  214. }
  215. }
  216. }
  217. }
  218. function cleanLine($stringIn,$tags='')
  219. {
  220. if(empty($tags))
  221. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
  222. else
  223. return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
  224. }
  225. function dumpArray($arrIn)
  226. {
  227. foreach($arrIn as $key => $value)
  228. {
  229. echo "\nkey(".$key.")"."value(".$value.")";
  230. }
  231. }
  232. //----------------------------------------------------------------
  233. // Function to build output for the table.
  234. function BuildOutput($bg)
  235. {
  236. $output = "<tr>\n";
  237. $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";
  238. $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
  239. $output .= " <td bgcolor=\"".$bg."\">". $this->CatName ."</td>\n";
  240. $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
  241. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
  242. $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
  243. $output .= "</tr>\n";
  244. return $output;
  245. }
  246. }
  247. ?>