| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- <?php
- /* $Id: TorrentPortalEngine.php 2833 2007-04-08 11:58:47Z b4rt $ */
- /*************************************************************
- * TorrentFlux PHP Torrent Manager
- * www.torrentflux.com
- **************************************************************/
- /*
- This file is part of TorrentFlux.
- TorrentFlux is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- TorrentFlux is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with TorrentFlux; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /*
- v 1.01 - change in parsing routine
- v 1.02 - Mar 19, 06 - another change in the parsing. and updated paging
- v 1.03 - Updated to check for a count on the array
- */
- class SearchEngine extends SearchEngineBase
- {
- function SearchEngine($cfg)
- {
- $this->mainURL = "torrentportal.com";
- $this->altURL = "tp.searching.com";
- $this->mainTitle = "TorrentPortal";
- $this->engineName = "TorrentPortal";
- $this->author = "kboy";
- $this->version = "1.03-tfb";
- $this->updateURL = "http://www.torrentflux.com/forum/index.php?topic=875.0.html";
- $this->Initialize($cfg);
- }
- //----------------------------------------------------------------
- // Function to Get Main Categories
- function populateMainCategories()
- {
- $this->mainCatalog["0"] = "(all types)";
- $this->mainCatalog["1"] = "Games";
- $this->mainCatalog["2"] = "Movies";
- $this->mainCatalog["3"] = "TV";
- $this->mainCatalog["4"] = "Videos";
- $this->mainCatalog["5"] = "Apps";
- $this->mainCatalog["6"] = "Anime";
- $this->mainCatalog["7"] = "Audio";
- $this->mainCatalog["8"] = "Comics";
- $this->mainCatalog["9"] = "Unsorted";
- $this->mainCatalog["10"] = "Porn";
- }
- //----------------------------------------------------------------
- // Function to Make the Request (overriding base)
- function makeRequest($request)
- {
- return parent::makeRequest($request, false);
- }
- //----------------------------------------------------------------
- // Function to get Latest..
- function getLatest()
- {
- $cat = tfb_getRequestVar('subGenre');
- $count = tfb_getRequestVar('count');
- if (empty($cat)) $cat = tfb_getRequestVar('cat');
- if(empty($cat) && empty($this->pg))
- {
- $request = "/new-torrents.php";
- }
- else
- {
- $request = "/torrents.php";
- }
- if(!empty($cat))
- {
- if(strpos($request,"?"))
- {
- $request .= "&cat=".$cat;
- }
- else
- {
- $request .= "?cat=".$cat;
- }
- }
- if(!empty($count))
- {
- if(strpos($request,"?"))
- {
- $request .= "&count=".$count;
- }
- else
- {
- $request .= "?count=".$count;
- }
- }
- if (!empty($this->pg))
- {
- if(strpos($request,"?"))
- {
- $request .= "&page=" . $this->pg;
- }
- else
- {
- $request .= "?page=" . $this->pg;
- }
- }
- if ($this->makeRequest($request))
- {
- return $this->parseResponse();
- }
- else
- {
- return $this->msg;
- }
- }
- //----------------------------------------------------------------
- // Function to perform Search.
- function performSearch($searchTerm)
- {
- $searchTerm = str_replace(" ", "+", $searchTerm);
- $request = "/torrents-search.php?search=".$searchTerm;
- if(!empty($cat))
- {
- $request .= "&cat=".$cat;
- }
- $count = tfb_getRequestVar('count');
- if(!empty($count))
- {
- $request .= "&count=".$count;
- }
- $onlyname = tfb_getRequestVar('onlyname');
- if (empty($onlyname)) $onlyname = "no";
- $request .= "&onlyname=".$onlyname;
- $incldead = tfb_getRequestVar('incldead');
- if (empty($incldead)) $incldead = "0";
- $request .= "&incldead=".$incldead;
- $request .= "&submit=";
- if (!empty($this->pg))
- {
- $request .= "&page=" . $this->pg;
- }
- if ($this->makeRequest($request,true))
- {
- return $this->parseResponse();
- }
- else
- {
- return $this->msg;
- }
- }
- //----------------------------------------------------------------
- // Override the base to show custom table header.
- // Function to setup the table header
- function tableHeader()
- {
- $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
- $output .= "<br>\n";
- $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
- $output .= " <td> </td>";
- $output .= " <td><strong>Torrent Name</strong> (";
- $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
- // Check to see if Question mark is there.
- if (strpos($tmpURI,'?'))
- {
- $tmpURI .= "&";
- }
- else
- {
- $tmpURI .= "?";
- }
- if($this->hideSeedless == "yes")
- {
- $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
- }
- else
- {
- $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
- }
- $output .= ")</td>";
- $output .= " <td><strong>Category</strong></td>";
- $output .= " <td align=center><strong> Size</strong></td>";
- $output .= " <td><strong>Seeds</strong></td>";
- $output .= " <td><strong>Peers</strong></td>";
- $output .= " <td><strong>Health</strong></td>";
- $output .= "</tr>\n";
- return $output;
- }
- //----------------------------------------------------------------
- // Function to parse the response.
- function parseResponse()
- {
- $output = $this->tableHeader();
- $thing = $this->htmlPage;
- // We got a response so display it.
- // Chop the front end off.
- while (is_integer(strpos($thing,">Health")))
- {
- $thing = substr($thing,strpos($thing,">Health"));
- $thing = substr($thing,strpos($thing,"<tr"));
- $tmpList = substr($thing,0,strpos($thing,"</table>"));
- // ok so now we have the listing.
- $tmpListArr = explode("<tr>",$tmpList);
- $bg = $this->cfg["bgLight"];
- foreach($tmpListArr as $key =>$value)
- {
- $buildLine = true;
- if (strpos($value,"/download/"))
- {
- $ts = new tPort($value);
- // Determine if we should build this output
- if (is_int(array_search($ts->MainCategory,$this->catFilter)))
- {
- $buildLine = false;
- }
- if ($this->hideSeedless == "yes")
- {
- if($ts->Seeds == "N/A" || $ts->Seeds == "0")
- {
- $buildLine = false;
- }
- }
- if (!empty($ts->torrentFile) && $buildLine) {
- $output .= trim($ts->BuildOutput($bg, $this->searchURL()));
- // ok switch colors.
- if ($bg == $this->cfg["bgLight"])
- {
- $bg = $this->cfg["bgDark"];
- }
- else
- {
- $bg = $this->cfg["bgLight"];
- }
- }
- }
- }
- // set thing to end of this table.
- $thing = substr($thing,strpos($thing,"</table>"));
- }
- $output .= "</table>";
- // is there paging at the bottom?
- /*
- <p align="center"><b>1 - 25</b> | <a href="?search=test&count=87&page=1"><b>26 - 50</b></a> | <a href="?search=test&count=87&page=2"><b>51 - 75</b></a> | <a href="?search=test&count=87&page=3"><b>76 - 87</b></a><br /><b><< Prev</b> <a href="?search=test&count=87&page=1"><b>Next >></b></a></p>
- */
- if (strpos($thing, "page=") != false)
- {
- // Yes, then lets grab it and display it! ;)
- $thing = substr($thing,strpos($thing,"<p align=\"center\">")+strlen("<p align=\"center\">"));
- $pages = substr($thing,0,strpos($thing,"</p>"));
- //$output .= $pages;
- if(strpos($this->curRequest,"LATEST"))
- {
- if(strpos($pages,"cat="))
- {
- $pages = str_replace("page=","pg=",str_replace("?",$this->searchURL()."&LATEST=1&",$pages));
- }
- else
- {
- $pages = str_replace("?page=",$this->searchURL()."&LATEST=1&pg=",$pages);
- }
- }
- else
- {
- if(strpos($pages,"\"?"))
- {
- $pages = str_replace("?",$this->searchURL()."&",$pages);
- }
- if(strpos($pages,"?search="))
- {
- $pages = str_replace("?search=",$this->searchURL()."&searchterm=",$pages);
- }
- if(strpos($pages,"search="))
- {
- $pages = str_replace("search=","searchterm=",$pages);
- }
- }
- if(strpos($pages,"torrents.php?"))
- {
- $pages = str_replace("torrents.php?",$this->searchURL()."&",$pages);
- }
- if(strpos($pages,"torrents-search.php?"))
- {
- $pages = str_replace("torrents-search.php?",$this->searchURL()."&",$pages);
- }
- $pages = str_replace("page=","pg=",$pages);
- $output .= "<div align=center>".$pages."</div>";
- }
- return $output;
- }
- }
- // This is a worker class that takes in a row in a table and parses it.
- class tPort
- {
- var $torrentName = "";
- var $torrentDisplayName = "";
- var $torrentFile = "";
- var $torrentSize = "";
- var $torrentStatus = "";
- var $MainId = "";
- var $MainCategory = "";
- var $fileCount = "";
- var $Seeds = "";
- var $Peers = "";
- var $Data = "";
- var $torrentRating = "";
- function tPort( $htmlLine )
- {
- if (strlen($htmlLine) > 0)
- {
- $this->Data = $htmlLine;
- // Cleanup any bugs in the HTML
- $htmlLine = preg_replace("/</td>\n</td>/i",'</td>',$htmlLine);
- // Chunck up the row into columns.
- $tmpListArr = explode("<td ",$htmlLine);
- if(count($tmpListArr) > 8)
- {
- $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"href=\"")+strlen("href=\"")); // Download Link
- $this->torrentFile = "http://www.torrentportal.com".substr($tmpStr,0,strpos($tmpStr,"\""));
- $this->MainCategory = $this->cleanLine("<td ".$tmpListArr["3"]."</td>"); // MainCategory
- $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"cat=")+strlen("cat=")); // Main Id
- $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
- $this->torrentName = $this->cleanLine("<td ".$tmpListArr["4"]."</td>"); // TorrentName
- $this->torrentRating = $this->cleanLine("<td ".$tmpListArr["5"]."</td>"); // Rating
- $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["6"]."</td>"); // Size of File
- $this->Seeds = $this->cleanLine("<td ".$tmpListArr["7"]."</td>"); // Seeds
- $this->Peers = $this->cleanLine("<td ".$tmpListArr["8"]."</td>"); // Leech
- $tmpStr = substr($tmpListArr["9"],strpos($tmpListArr["9"],"Health ")+strlen("Health ")); // Health
- $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
- $tmpArr = explode("/",$tmpStr);
- if (count($tmpArr) > 1 && $tmpArr["1"] > 0 )
- {
- $this->torrentStatus = ($tmpArr["0"] / $tmpArr["1"]) * 100 . "%";
- }
- else
- {
- $this->torrentStatus = "0%";
- }
- if ($this->Peers == '')
- {
- $this->Peers = "N/A";
- if (empty($this->Seeds)) $this->Seeds = "N/A";
- }
- if ($this->Seeds == '') $this->Seeds = "N/A";
- $this->torrentDisplayName = $this->torrentName;
- if(strlen($this->torrentDisplayName) > 50)
- {
- $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
- }
- }
- }
- }
- function cleanLine($stringIn,$tags='')
- {
- if(empty($tags))
- return trim(str_replace(array(" "," ")," ",strip_tags($stringIn)));
- else
- return trim(str_replace(array(" "," ")," ",strip_tags($stringIn,$tags)));
- }
- //----------------------------------------------------------------
- // Function to build output for the table.
- function BuildOutput($bg, $searchURL = '')
- {
- $output = "<tr>\n";
- $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";
- $output .= " <td bgcolor=\"".$bg."\"><a href=\"dispatcher.php?action=urlUpload&type=torrent&url=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
- if (strlen($this->MainCategory) > 1){
- $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
- }else{
- $genre = "";
- }
- $output .= " <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
- $output .= " <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
- $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
- $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
- $output .= " <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
- $output .= "</tr>\n";
- return $output;
- }
- }
- ?>
|