Subversion Repositories svnkaklik

Rev

Go to most recent revision | 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
    v 1.01 - change in parsing routine
27
    v 1.02 - Mar 19, 06 - another change in the parsing. and updated paging
28
*/
29
 
30
class SearchEngine extends SearchEngineBase
31
{
32
    function SearchEngine($cfg)
33
    {
34
        $this->mainURL = "torrentportal.com";
35
        $this->altURL = "tp.searching.com";
36
        $this->mainTitle = "TorrentPortal";
37
        $this->engineName = "TorrentPortal";
38
 
39
        $this->author = "kboy";
40
        $this->version = "1.02";
41
        $this->updateURL = "http://www.torrentflux.com/forum/index.php?topic=875.0.html";
42
 
43
        $this->Initialize($cfg);
44
    }
45
 
46
    //----------------------------------------------------------------
47
    // Function to Get Main Categories
48
    function populateMainCategories()
49
    {
50
        $this->mainCatalog["0"] = "(all types)";
51
        $this->mainCatalog["1"] = "Games";
52
        $this->mainCatalog["2"] = "Movies";
53
        $this->mainCatalog["3"] = "TV";
54
        $this->mainCatalog["4"] = "Videos";
55
        $this->mainCatalog["5"] = "Apps";
56
        $this->mainCatalog["6"] = "Anime";
57
        $this->mainCatalog["7"] = "Audio";
58
        $this->mainCatalog["8"] = "Comics";
59
        $this->mainCatalog["9"] = "Unsorted";
60
        $this->mainCatalog["10"] = "Porn";
61
    }
62
 
63
    //----------------------------------------------------------------
64
    // Function to Make the Request (overriding base)
65
    function makeRequest($request)
66
    {
67
        return parent::makeRequest($request, false);
68
    }
69
 
70
    //----------------------------------------------------------------
71
    // Function to get Latest..
72
    function getLatest()
73
    {
74
        $cat = getRequestVar('subGenre');
75
        $count = getRequestVar('count');
76
 
77
        if (empty($cat)) $cat = getRequestVar('cat');
78
 
79
        if(empty($cat) && empty($this->pg))
80
        {
81
            $request = "/new-torrents.php";
82
        }
83
        else
84
        {
85
            $request = "/torrents.php";
86
        }
87
 
88
        if(!empty($cat))
89
        {
90
            if(strpos($request,"?"))
91
            {
92
                $request .= "&cat=".$cat;
93
            }
94
            else
95
            {
96
                $request .= "?cat=".$cat;
97
            }
98
        }
99
 
100
        if(!empty($count))
101
        {
102
            if(strpos($request,"?"))
103
            {
104
                $request .= "&count=".$count;
105
            }
106
            else
107
            {
108
                $request .= "?count=".$count;
109
            }
110
        }
111
 
112
        if (!empty($this->pg))
113
        {
114
            if(strpos($request,"?"))
115
            {
116
                $request .= "&page=" . $this->pg;
117
            }
118
            else
119
            {
120
                $request .= "?page=" . $this->pg;
121
            }
122
        }
123
 
124
        if ($this->makeRequest($request))
125
        {
126
          return $this->parseResponse();
127
        }
128
        else
129
        {
130
           return $this->msg;
131
        }
132
    }
133
 
134
    //----------------------------------------------------------------
135
    // Function to perform Search.
136
    function performSearch($searchTerm)
137
    {
138
 
139
        $searchTerm = str_replace(" ", "+", $searchTerm);
140
        $request = "/torrents-search.php?search=".$searchTerm;
141
 
142
        if(!empty($cat))
143
        {
144
            $request .= "&cat=".$cat;
145
        }
146
 
147
        $count = getRequestVar('count');
148
        if(!empty($count))
149
        {
150
            $request .= "&count=".$count;
151
        }
152
 
153
        $onlyname = getRequestVar('onlyname');
154
        if (empty($onlyname)) $onlyname = "no";
155
        $request .= "&onlyname=".$onlyname;
156
 
157
        $incldead = getRequestVar('incldead');
158
        if (empty($incldead)) $incldead = "0";
159
        $request .= "&incldead=".$incldead;
160
 
161
 
162
        $request .= "&submit=";
163
 
164
        if (!empty($this->pg))
165
        {
166
            $request .= "&page=" . $this->pg;
167
        }
168
 
169
        if ($this->makeRequest($request,true))
170
        {
171
            return $this->parseResponse();
172
        }
173
        else
174
        {
175
            return $this->msg;
176
        }
177
}
178
 
179
    //----------------------------------------------------------------
180
    // Override the base to show custom table header.
181
    // Function to setup the table header
182
    function tableHeader()
183
    {
184
        $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
185
 
186
        $output .= "<br>\n";
187
        $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
188
        $output .= "  <td>&nbsp;</td>";
189
        $output .= "  <td><strong>Torrent Name</strong> &nbsp;(";
190
 
191
        $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
192
 
193
        // Check to see if Question mark is there.
194
        if (strpos($tmpURI,'?'))
195
        {
196
            $tmpURI .= "&";
197
        }
198
        else
199
        {
200
            $tmpURI .= "?";
201
        }
202
 
203
        if($this->hideSeedless == "yes")
204
        {
205
            $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
206
        }
207
        else
208
        {
209
            $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
210
        }
211
 
212
        $output .= ")</td>";
213
        $output .= "  <td><strong>Category</strong></td>";
214
        $output .= "  <td align=center><strong>&nbsp;&nbsp;Size</strong></td>";
215
        $output .= "  <td><strong>Seeds</strong></td>";
216
        $output .= "  <td><strong>Peers</strong></td>";
217
        $output .= "  <td><strong>Health</strong></td>";
218
        $output .= "</tr>\n";
219
 
220
        return $output;
221
    }
222
 
223
    //----------------------------------------------------------------
224
    // Function to parse the response.
225
    function parseResponse()
226
    {
227
        $output = $this->tableHeader();
228
 
229
        $thing = $this->htmlPage;
230
 
231
        // We got a response so display it.
232
        // Chop the front end off.
233
        while (is_integer(strpos($thing,">Health")))
234
        {
235
            $thing = substr($thing,strpos($thing,">Health"));
236
            $thing = substr($thing,strpos($thing,"<tr"));
237
            $tmpList = substr($thing,0,strpos($thing,"</table>"));
238
 
239
            // ok so now we have the listing.
240
            $tmpListArr = split("<tr>",$tmpList);
241
 
242
            $bg = $this->cfg["bgLight"];
243
 
244
            foreach($tmpListArr as $key =>$value)
245
            {
246
                $buildLine = true;
247
                if (strpos($value,"/download/"))
248
                {
249
                    $ts = new tPort($value);
250
 
251
                    // Determine if we should build this output
252
                    if (is_int(array_search($ts->MainCategory,$this->catFilter)))
253
                    {
254
                        $buildLine = false;
255
                    }
256
 
257
                    if ($this->hideSeedless == "yes")
258
                    {
259
                        if($ts->Seeds == "N/A" || $ts->Seeds == "0")
260
                        {
261
                            $buildLine = false;
262
                        }
263
                    }
264
 
265
                    if (!empty($ts->torrentFile) && $buildLine) {
266
 
267
                        $output .= trim($ts->BuildOutput($bg, $this->searchURL()));
268
 
269
                        // ok switch colors.
270
                        if ($bg == $this->cfg["bgLight"])
271
                        {
272
                            $bg = $this->cfg["bgDark"];
273
                        }
274
                        else
275
                        {
276
                            $bg = $this->cfg["bgLight"];
277
                        }
278
                    }
279
 
280
                }
281
            }
282
            // set thing to end of this table.
283
            $thing = substr($thing,strpos($thing,"</table>"));
284
        }
285
 
286
        $output .= "</table>";
287
 
288
        // is there paging at the bottom?
289
        /*
290
        <p align="center"><b>1&nbsp;-&nbsp;25</b> | <a href="?search=test&amp;count=87&amp;page=1"><b>26&nbsp;-&nbsp;50</b></a> | <a href="?search=test&amp;count=87&amp;page=2"><b>51&nbsp;-&nbsp;75</b></a> | <a href="?search=test&amp;count=87&amp;page=3"><b>76&nbsp;-&nbsp;87</b></a><br /><b>&lt;&lt;&nbsp;Prev</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?search=test&amp;count=87&amp;page=1"><b>Next&nbsp;&gt;&gt;</b></a></p>
291
        */
292
        if (strpos($thing, "page=") != false)
293
        {
294
            // Yes, then lets grab it and display it!  ;)
295
            $thing = substr($thing,strpos($thing,"<p align=\"center\">")+strlen("<p align=\"center\">"));
296
            $pages = substr($thing,0,strpos($thing,"</p>"));
297
            //$output .= $pages;
298
 
299
            if(strpos($this->curRequest,"LATEST"))
300
            {
301
                if(strpos($pages,"cat="))
302
                {
303
                    $pages = str_replace("page=","pg=",str_replace("?",$this->searchURL()."&LATEST=1&",$pages));
304
                }
305
                else
306
                {
307
                    $pages = str_replace("?page=",$this->searchURL()."&LATEST=1&pg=",$pages);
308
                }
309
            }
310
            else
311
            {
312
               if(strpos($pages,"\"?"))
313
               {
314
                   $pages = str_replace("?",$this->searchURL()."&",$pages);
315
               }
316
 
317
               if(strpos($pages,"?search="))
318
               {
319
                   $pages = str_replace("?search=",$this->searchURL()."&searchterm=",$pages);
320
               }
321
               if(strpos($pages,"search="))
322
               {
323
                   $pages = str_replace("search=","searchterm=",$pages);
324
               }
325
            }
326
 
327
           if(strpos($pages,"torrents.php?"))
328
           {
329
               $pages = str_replace("torrents.php?",$this->searchURL()."&",$pages);
330
           }
331
 
332
           if(strpos($pages,"torrents-search.php?"))
333
           {
334
               $pages = str_replace("torrents-search.php?",$this->searchURL()."&",$pages);
335
           }
336
 
337
            $pages = str_replace("page=","pg=",$pages);
338
 
339
            $output .= "<div align=center>".$pages."</div>";
340
        }
341
 
342
        return $output;
343
    }
344
}
345
 
346
// This is a worker class that takes in a row in a table and parses it.
347
class tPort
348
{
349
    var $torrentName = "";
350
    var $torrentDisplayName = "";
351
    var $torrentFile = "";
352
    var $torrentSize = "";
353
    var $torrentStatus = "";
354
    var $MainId = "";
355
    var $MainCategory = "";
356
    var $fileCount = "";
357
    var $Seeds = "";
358
    var $Peers = "";
359
    var $Data = "";
360
 
361
    var $torrentRating = "";
362
 
363
    function tPort( $htmlLine )
364
    {
365
        if (strlen($htmlLine) > 0)
366
        {
367
 
368
            $this->Data = $htmlLine;
369
 
370
            // Cleanup any bugs in the HTML
371
            $htmlLine = eregi_replace("</td>\n</td>",'</td>',$htmlLine);
372
 
373
            // Chunck up the row into columns.
374
            $tmpListArr = split("<td ",$htmlLine);
375
 
376
            if(count($tmpListArr) > 8)
377
            {
378
                $tmpStr = substr($tmpListArr["1"],strpos($tmpListArr["1"],"href=\"")+strlen("href=\"")); // Download Link
379
                $this->torrentFile = "http://www.torrentportal.com".substr($tmpStr,0,strpos($tmpStr,"\""));
380
 
381
                $this->MainCategory = $this->cleanLine("<td ".$tmpListArr["3"]."</td>");  // MainCategory
382
 
383
                $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"cat=")+strlen("cat=")); // Main Id
384
                $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
385
 
386
                $this->torrentName = $this->cleanLine("<td ".$tmpListArr["4"]."</td>");  // TorrentName
387
                $this->torrentRating = $this->cleanLine("<td ".$tmpListArr["5"]."</td>");  // Rating
388
 
389
                $this->torrentSize = $this->cleanLine("<td ".$tmpListArr["6"]."</td>");  // Size of File
390
                $this->Seeds = $this->cleanLine("<td ".$tmpListArr["7"]."</td>");  // Seeds
391
                $this->Peers = $this->cleanLine("<td ".$tmpListArr["8"]."</td>");  // Leech
392
 
393
                $tmpStr = substr($tmpListArr["9"],strpos($tmpListArr["9"],"Health ")+strlen("Health "));  // Health
394
                $tmpStr = substr($tmpStr,0,strpos($tmpStr,"\""));
395
                $tmpArr = split("/",$tmpStr);
396
                if ($tmpArr["1"] > 0 )
397
                {
398
                    $this->torrentStatus = ($tmpArr["0"] / $tmpArr["1"]) * 100 . "%";
399
                }
400
                else
401
                {
402
                    $this->torrentStatus = "0%";
403
                }
404
 
405
                if ($this->Peers == '')
406
                {
407
                    $this->Peers = "N/A";
408
                    if (empty($this->Seeds)) $this->Seeds = "N/A";
409
                }
410
                if ($this->Seeds == '') $this->Seeds = "N/A";
411
 
412
                $this->torrentDisplayName = $this->torrentName;
413
                if(strlen($this->torrentDisplayName) > 50)
414
                {
415
                    $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
416
                }
417
 
418
           }
419
        }
420
 
421
    }
422
 
423
    function cleanLine($stringIn,$tags='')
424
    {
425
        if(empty($tags))
426
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
427
        else
428
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
429
    }
430
 
431
    //----------------------------------------------------------------
432
    // Function to build output for the table.
433
    function BuildOutput($bg, $searchURL = '')
434
    {
435
        $output = "<tr>\n";
436
        $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";
437
        $output .= "    <td bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
438
 
439
        if (strlen($this->MainCategory) > 1){
440
            $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
441
        }else{
442
            $genre = "";
443
        }
444
 
445
        $output .= "    <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
446
 
447
        $output .= "    <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
448
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
449
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
450
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
451
        $output .= "</tr>\n";
452
 
453
        return $output;
454
 
455
    }
456
}
457
 
458
?>