Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
/*************************************************************
4
*  TorrentFlux PHP Torrent Manager
5
*  www.torrentflux.com
6
**************************************************************/
7
/*
8
    This file is part of TorrentFlux.
9
 
10
    TorrentFlux is free software; you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation; either version 2 of the License, or
13
    (at your option) any later version.
14
 
15
    TorrentFlux is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with TorrentFlux; if not, write to the Free Software
22
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
*/
24
 
25
 
26
class SearchEngine extends SearchEngineBase
27
{
28
 
29
    function SearchEngine($cfg)
30
    {
31
        $this->mainURL = "isohunt.com";
32
        $this->altURL = "isohunt.com";
33
        $this->mainTitle = "isoHunt";
34
        $this->engineName = "isoHunt";
35
 
36
        $this->author = "kboy";
37
        $this->version = "1.00";
38
        $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,878.0.html";
39
 
40
        $this->Initialize($cfg);
41
 
42
    }
43
 
44
    //----------------------------------------------------------------
45
    // Function to Make the Request (overriding base)
46
    function makeRequest($request)
47
    {
48
        return parent::makeRequest($request, true);
49
    }
50
 
51
    //----------------------------------------------------------------
52
    // Function to get Latest..
53
    function getLatest()
54
    {
55
        $request = "/latest.php?mode=bt";
56
 
57
        if (!empty($this->pg))
58
        {
59
            $request .= "&pg=" . $this->pg;
60
        }
61
 
62
        if ($this->makeRequest($request))
63
        {
64
          return $this->parseResponse(true);
65
        }
66
        else
67
        {
68
           return $this->msg;
69
        }
70
    }
71
 
72
    //----------------------------------------------------------------
73
    // Function to perform Search.
74
    function performSearch($searchTerm)
75
    {
76
        // This is what isohunt is looking for in a request.
77
        // http://isohunt.com/torrents.php?ihq=test&ext=&op=and
78
 
79
        // create the request string.
80
        $searchTerm = str_replace(" ", "+", $searchTerm);
81
        $request = "/torrents.php?ihq=".$searchTerm;
82
        $request .= "&ext=&op=and";
83
 
84
        if (!empty($this->pg))
85
        {
86
            $request .= "&ihs1=18&iho1=d&iht=-1&ihp=" . $this->pg;
87
        }
88
 
89
        $request .= "&submit=Torrents";
90
 
91
        // make the request if successful call the parse routine.
92
        if ($this->makeRequest($request))
93
        {
94
            return $this->parseResponse(false);
95
        }
96
        else
97
        {
98
            return $this->msg;
99
        }
100
 
101
    }
102
 
103
    //----------------------------------------------------------------
104
    // Function to parse the response.
105
    function parseResponse($latest = true)
106
    {
107
        $output = $this->tableHeader();
108
 
109
        $thing = $this->htmlPage;
110
 
111
        // Strip out those Nasty Iframes.
112
        $thing = eregi_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>",'',$thing);
113
 
114
        // We got a response so display it.
115
        // Chop the front end off.
116
        while (is_integer(strpos($thing,"<table")))
117
        {
118
            $thing = substr($thing,strpos($thing,"<table"));
119
            $thing = substr($thing,strpos($thing,"</tr>"));
120
            $tmpList = substr($thing,0,strpos($thing,"</table>"));
121
 
122
            // ok so now we have the listing.
123
            $tmpListArr = split("</tr>",$tmpList);
124
 
125
            $bg = $this->cfg["bgLight"];
126
 
127
            foreach($tmpListArr as $key =>$value)
128
            {
129
                //echo $value;
130
                $buildLine = true;
131
                if (strpos($value,"id="))
132
                {
133
                    $ts = new isoHunt($value,$latest);
134
 
135
                    // Determine if we should build this output
136
                    if (is_int(array_search($ts->CatName,$this->catFilter)))
137
                    {
138
                        $buildLine = false;
139
                    }
140
 
141
                    if ($this->hideSeedless == "yes")
142
                    {
143
                        if($ts->Seeds == "N/A" || $ts->Seeds == "0")
144
                        {
145
                            $buildLine = false;
146
                        }
147
                    }
148
 
149
                    if (!empty($ts->torrentFile) && $buildLine) {
150
 
151
                        $output .= trim($ts->BuildOutput($bg));
152
 
153
                        // ok switch colors.
154
                        if ($bg == $this->cfg["bgLight"])
155
                        {
156
                            $bg = $this->cfg["bgDark"];
157
                        }
158
                        else
159
                        {
160
                            $bg = $this->cfg["bgLight"];
161
                        }
162
                    }
163
 
164
                }
165
            }
166
 
167
            // set thing to end of this table.
168
            $thing = substr($thing,strpos($thing,"</table>"));
169
        }
170
 
171
        $output .= "</table>";
172
 
173
        // is there paging at the bottom?
174
        if (strpos($this->htmlPage, "<table class='pager'>") != false)
175
        {
176
            // Yes, then lets grab it and display it!  ;)
177
 
178
            $thing = substr($this->htmlPage,strpos($this->htmlPage,"<table class='pager'>")+strlen("<table class='pager'>"));
179
            $pages = substr($thing,0,strpos($thing,"</table>"));
180
 
181
            $pages = str_replace("&nbsp; ",'',strip_tags($pages,"<a><b>"));
182
 
183
            $tmpPageArr = split("</a>",$pages);
184
            array_pop($tmpPageArr);
185
 
186
            $pagesout = '';
187
            foreach($tmpPageArr as $key => $value)
188
            {
189
                $value .= "</a> &nbsp;";
190
                $tmpVal = substr($value,strpos($value,"/torrents.php"),strpos($value,"\>")-1);
191
                $pgNum = substr($tmpVal,strpos($tmpVal,"ihp=")+strlen("ihp="));
192
                $pagesout .= str_replace($tmpVal,"XXXURLXXX".$pgNum,$value);
193
            }
194
            if(strpos($this->curRequest,"LATEST"))
195
            {
196
                $pages = str_replace("XXXURLXXX",$this->searchURL()."&LATEST=1&pg=",$pagesout);
197
            }
198
            else
199
            {
200
                $pages = str_replace("XXXURLXXX",$this->searchURL()."&searchterm=".$_REQUEST["searchterm"]."&pg=",$pagesout);
201
            }
202
            $pages = strip_tags($pages,"<a><b>");
203
            $output .= "<div align=center>".$pages."</div>";
204
        }
205
 
206
        return $output;
207
    }
208
}
209
 
210
// This is a worker class that takes in a row in a table and parses it.
211
class isoHunt
212
{
213
    var $torrentName = "";
214
    var $torrentDisplayName = "";
215
    var $torrentFile = "";
216
    var $torrentSize = "";
217
    var $torrentStatus = "";
218
    var $CatId = "";
219
    var $CatName = "";
220
    var $fileCount = "";
221
    var $Seeds = "";
222
    var $Peers = "";
223
    var $Data = "";
224
 
225
    var $dateAdded = "";
226
    var $dwnldCount = "";
227
 
228
    function isoHunt( $htmlLine , $latest = true)
229
    {
230
        if (strlen($htmlLine) > 0)
231
        {
232
 
233
            $this->Data = $htmlLine;
234
 
235
            // Fix messed up end td's once in a while.
236
            $htmlLine = eregi_replace("<(.)*1ff8(.)*/td>",'</td>',$htmlLine);
237
 
238
            // Chunck up the row into columns.
239
            $tmpListArr = split("</td>",$htmlLine);
240
            array_pop($tmpListArr);
241
 
242
            //Age   Type    Torrent Names   MB  F   S   L   D
243
            if(count($tmpListArr) > 6)
244
            {
245
                if ($latest)
246
                {
247
                    // Latest Request //
248
                    if(strpos($tmpListArr["3"],"[DL]"))
249
                    {
250
 
251
                        //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]);  // Age
252
                        $this->CatName = $this->cleanLine($tmpListArr["2"]); // Type
253
 
254
                        $tmpStr = $tmpListArr["3"];  // TorrentName and Download Link
255
                        // move to the [DL] area. and remove [REL] line
256
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"[DL]")+strlen("[DL]"), strpos($tmpStr,"[REL]"));
257
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"href=\"")+strlen("href=\"")); // Download Link
258
                        $this->torrentFile = "http://isohunt.com".substr($tmpStr,0,strpos($tmpStr,"\""));
259
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
260
                        $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
261
                        $tmpStr = substr($tmpStr,strpos($tmpStr,'\''));
262
                        $this->torrentName = str_replace("'",'',$tmpStr);
263
 
264
                        $this->torrentSize = $this->cleanLine($tmpListArr["4"]); // MB
265
                        $this->fileCount = $this->cleanLine($tmpListArr["5"]); // Files
266
                        $this->Seeds = $this->cleanLine($tmpListArr["6"]); // Seeds
267
                        $this->Peers = $this->cleanLine($tmpListArr["7"]); // Peers / Leechers
268
                        $this->dwnldCount = $this->cleanLine($tmpListArr["8"]); // Download Count
269
                    }
270
                    else
271
                    {
272
                        $this->CatName = $this->cleanLine($tmpListArr["1"]); // Type
273
 
274
                        $tmpStr = $tmpListArr["0"];  // TorrentName and Download Link
275
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"id="));
276
                        $this->torrentFile = "http://isohunt.com/download.php?mode=bt&amp;".substr($tmpStr,0,strpos($tmpStr,"'"));
277
 
278
                        $this->torrentName = $this->cleanLine($tmpListArr["2"]);
279
 
280
                        $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
281
                        $this->fileCount = $this->cleanLine($tmpListArr["4"]); // Files
282
                        $this->Seeds = $this->cleanLine($tmpListArr["5"]); // Seeds
283
                        $this->Peers = $this->cleanLine($tmpListArr["6"]); // Peers / Leechers
284
                        $this->dwnldCount = $this->cleanLine($tmpListArr["7"]); // Download Count
285
                    }
286
                }
287
                else
288
                {
289
                    // Search Request //
290
 
291
                    if(strpos($tmpListArr["2"],"[DL]"))
292
                    {
293
                        $this->CatName = $this->cleanLine($tmpListArr["0"]); // Type
294
 
295
                        //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]);  // Age
296
 
297
                        $tmpStr = $tmpListArr["2"];  // TorrentName and Download Link
298
                        // move to the [DL] area. and remove [REL] line
299
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"[DL]")+strlen("[DL]"), strpos($tmpStr,"[REL]"));
300
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"href=\"")+strlen("href=\"")); // Download Link
301
                        $this->torrentFile = "http://isohunt.com".substr($tmpStr,0,strpos($tmpStr,"\""));
302
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
303
                        $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
304
                        $tmpStr = substr($tmpStr,strpos($tmpStr,'\''));
305
                        $this->torrentName = str_replace(array("'","Download .torrent here: "),'',$tmpStr);
306
 
307
                    }
308
                    else
309
                    {
310
                        $tmpStr = $tmpListArr["0"];  // Download ID and Type
311
                        $this->CatName = $this->cleanLine($tmpStr); // Download ID and Type
312
                        $tmpStr = substr($tmpStr,strpos($tmpStr,"&id=")+strlen("&id="));
313
 
314
                        $this->torrentFile = "http://isohunt.com/download.php?mode=bt&amp;id=".substr($tmpStr,0,strpos($tmpStr,",")-1);
315
 
316
                        //$tmpListArr["1"] = $this->cleanLine($tmpListArr["1"]);  // Age
317
 
318
                        $this->torrentName = $this->cleanLine($tmpListArr["2"]);
319
 
320
                    }
321
 
322
                    $this->torrentSize = $this->cleanLine($tmpListArr["3"]); // MB
323
                    $this->fileCount = $this->cleanLine($tmpListArr["4"]); // Files
324
                    $this->Seeds = $this->cleanLine($tmpListArr["5"]); // Seeds
325
                    $this->Peers = $this->cleanLine($tmpListArr["6"]); // Peers / Leechers
326
                    $this->dwnldCount = $this->cleanLine($tmpListArr["7"]); // Download Count
327
 
328
                    $this->torrentDisplayName = $this->torrentName;
329
 
330
                }
331
 
332
                if ($this->Peers == '')
333
                {
334
                    $this->Peers = "N/A";
335
                    if (empty($this->Seeds)) $this->Seeds = "N/A";
336
                }
337
 
338
                if ($this->Seeds == '') $this->Seeds = "N/A";
339
 
340
                $this->torrentDisplayName = str_replace(".torrent",'',$this->torrentName);
341
                if(strlen($this->torrentDisplayName) > 50)
342
                {
343
                    $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
344
                }
345
 
346
           }
347
        }
348
    }
349
 
350
    function cleanLine($stringIn,$tags='')
351
    {
352
        if(empty($tags))
353
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
354
        else
355
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
356
    }
357
 
358
    function dumpArray($arrIn)
359
    {
360
        foreach($arrIn as $key => $value)
361
        {
362
            echo "\nkey(".$key.")"."value(".$value.")";
363
        }
364
    }
365
    //----------------------------------------------------------------
366
    // Function to build output for the table.
367
    function BuildOutput($bg)
368
    {
369
        $output = "<tr>\n";
370
        $output .= "    <td width=16 bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\"><img src=\"images/download_owner.gif\" width=\"16\" height=\"16\" title=\"".$this->torrentName."\" border=0></a></td>\n";
371
        $output .= "    <td bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
372
        $output .= "    <td bgcolor=\"".$bg."\">". $this->CatName ."</td>\n";
373
        $output .= "    <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
374
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
375
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
376
        $output .= "</tr>\n";
377
 
378
        return $output;
379
 
380
    }
381
}
382
 
383
?>