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
    v 1.01 - Changed Main Categories. (removed TV, changed Movies to Video)
27
    v 1.02 - Mar 19, 06 - Updated pageing.
28
*/
29
 
30
class SearchEngine extends SearchEngineBase
31
{
32
 
33
    function SearchEngine($cfg)
34
    {
35
        $this->mainURL = "torrentspy.com";
36
        $this->altURL = "ts.searching.com";
37
        $this->mainTitle = "TorrentSpy";
38
        $this->engineName = "TorrentSpy";
39
 
40
        $this->author = "kboy";
41
        $this->version = "1.02";
42
        $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,874.0.html";
43
        $this->Initialize($cfg);
44
    }
45
 
46
    function populateMainCategories()
47
    {
48
 
49
        $this->mainCatalog["11"] = "Adult";
50
        $this->mainCatalog["6"] = "Anime";
51
        $this->mainCatalog["1"] = "Applications";
52
        $this->mainCatalog["2"] = "Games";
53
        $this->mainCatalog["13"] = "Handheld";
54
        $this->mainCatalog["7"] = "Hentai";
55
        $this->mainCatalog["8"] = "Linux";
56
        $this->mainCatalog["9"] = "Macintosh";
57
        $this->mainCatalog["10"] = "Misc";
58
        $this->mainCatalog["3"] = "Music";
59
        $this->mainCatalog["14"] = "Non-English";
60
        $this->mainCatalog["12"] = "Unsorted/Other";
61
        $this->mainCatalog["4"] = "Videos";
62
 
63
    }
64
 
65
    //----------------------------------------------------------------
66
    // Function to Get Sub Categories
67
    function getSubCategories($mainGenre)
68
    {
69
        $output = array();
70
 
71
        if (strpos($mainGenre,'/'))
72
        {
73
            $request = '/directory/' . $mainGenre;
74
        }
75
        else
76
        {
77
            $request = '/directory.asp?mode=main&id=' . $mainGenre;
78
        }
79
 
80
        $mainGenreName = $this->GetMainCatName($mainGenre);
81
 
82
        if ($this->makeRequest($request))
83
        {
84
            $thing = $this->htmlPage;
85
 
86
            while (is_integer(strpos($thing,"href=\"/directory/")))
87
            {
88
 
89
                $thing = substr($thing,strpos($thing,"href=\"/directory/")+strlen("href=\"/directory/"));
90
                $tmpStr = str_replace(array("%2f","+")," ",substr($thing,0,strpos($thing,"\"")));
91
                $tmpStr = str_replace("%2d","-",$tmpStr);
92
                $subid = $tmpStr;
93
                $thing = substr($thing,strpos($thing,">")+strlen(">"));
94
                $subname = trim(substr($thing,0,strpos($thing,"<")));
95
 
96
                if($subname != $mainGenreName)
97
                {
98
                    $output[$subid] = $subname;
99
                }
100
 
101
            }
102
       }
103
 
104
        return $output;
105
    }
106
 
107
    //----------------------------------------------------------------
108
    // Function to Make the Request (overriding base)
109
    function makeRequest($request)
110
    {
111
        if (strpos($request,"search.asp"))
112
        {
113
            return parent::makeRequest($request, true);
114
        }
115
        else
116
        {
117
            return parent::makeRequest($request, false);
118
        }
119
    }
120
 
121
    //----------------------------------------------------------------
122
    // Function to get Latest..
123
    function getLatest()
124
    {
125
        $request = '/latest.asp';
126
 
127
        // Added mode to support yesterday request.
128
        if (array_key_exists("mode",$_REQUEST))
129
        {
130
            $request .='?mode='.$_REQUEST["mode"];
131
            if (array_key_exists("id",$_REQUEST))
132
            {
133
                $request .= '&id=' . $_REQUEST["id"];
134
            }
135
            if (!empty($this->pg))
136
            {
137
                $request .= '&pg=' . $this->pg;
138
            }
139
        }
140
        elseif (array_key_exists("subGenre",$_REQUEST))
141
        {
142
            if (strpos($_REQUEST["subGenre"],"/")>0)
143
            {
144
                $request ='/directory.asp?mode=sub&id=' . substr($_REQUEST["subGenre"],0,strpos($_REQUEST["subGenre"],"/"));
145
            }
146
            else
147
            {
148
                $request ='/directory.asp?mode=sub&id=' . $_REQUEST["subGenre"];
149
            }
150
 
151
            if (!empty($this->pg))
152
            {
153
                $request .= '&pg=' . $this->pg;
154
            }
155
        }
156
        elseif (!empty($this->pg))
157
        {
158
            $request .= '?pg=' . $this->pg;
159
        }
160
 
161
        if ($this->makeRequest($request))
162
        {
163
          return $this->parseResponse();
164
        }
165
        else
166
        {
167
           return $this->msg;
168
        }
169
    }
170
 
171
    //----------------------------------------------------------------
172
    // Function to perform Search.
173
    function performSearch($searchTerm)
174
    {
175
        if (array_key_exists("directory",$_REQUEST))
176
        {
177
            $request = "/directory/" . str_replace("%2F","/",urlencode($_REQUEST["directory"]));
178
            if (!empty($this->pg))
179
            {
180
                $request .= "?pg=" . $this->pg;
181
            }
182
        }
183
        elseif (array_key_exists("getMain",$_REQUEST))
184
        {
185
            $request = '/directory';
186
        }
187
        elseif (array_key_exists("mainGenre",$_REQUEST))
188
        {
189
            if (strpos($_REQUEST["mainGenre"],'/'))
190
            {
191
                $request .= '/' . $_REQUEST["mainGenre"];
192
            }
193
            else
194
            {
195
                if (!empty($this->pg))
196
                {
197
                    $request = '/directory.asp?mode=main&id=' . $_REQUEST["mainGenre"] . '&pg=' . $this->pg;
198
                }
199
                else
200
                {
201
                    $request = '/directory.asp?mode=main&id=' . $_REQUEST["mainGenre"];
202
                }
203
            }
204
        }
205
        elseif (array_key_exists("subGenre",$_REQUEST))
206
        {
207
            if (strpos($_REQUEST["subGenre"],'/'))
208
            {
209
                $request = "/directory/" . $_REQUEST["subGenre"];
210
            }
211
            else
212
            {
213
                if ($_REQUEST["subGenre"] != "")
214
                {
215
                    if (!empty($this->pg))
216
                    {
217
                        $request = '/directory.asp?mode=sub&id=' . $_REQUEST["subGenre"] . '&pg=' . $this->pg;
218
                    }
219
                    else
220
                    {
221
                        $request = '/directory.asp?mode=sub&id=' . $_REQUEST["subGenre"];
222
                    }
223
                }
224
            }
225
        }
226
        else
227
        {
228
            $searchTerm = str_replace(" ", "+", $searchTerm);
229
 
230
            if ( $this->pg != '' && array_key_exists("db",$_REQUEST))
231
            {
232
                $request = '/search.asp?query=' . $searchTerm . '&pg=' . $this->pg . '&db=' . $_REQUEST["db"] . '&submit.x=24&submit.y=10';
233
            }
234
            else
235
            {
236
                $request = '/search.asp?query=' . $searchTerm . '&submit.x=24&submit.y=10';
237
            }
238
        }
239
 
240
       if ($this->makeRequest($request))
241
       {
242
            return $this->parseResponse();
243
       }
244
        else
245
       {
246
            return $this->msg;
247
       }
248
    }
249
 
250
    //----------------------------------------------------------------
251
    // Function to parse the response.
252
    function parseResponse()
253
    {
254
        $output = $this->tableHeader();
255
 
256
        $thing = $this->htmlPage;
257
 
258
        if (strpos($thing, "experiencing high load") > 0)
259
        {
260
            $output .= "<b>We're experiencing high load at this time. Please use the directory until further notice.</b>";
261
        }else{
262
            // We got a response so display it.
263
            // Chop the front end off.
264
            while (is_integer(strpos($thing,">Health<")))
265
            {
266
                $thing = substr($thing,strpos($thing,">Health<"));
267
                $thing = substr($thing,strpos($thing,"<tr"));
268
                $tmpList = substr($thing,0,strpos($thing,"</table>"));
269
                // ok so now we have the listing.
270
                $tmpListArr = split("</tr>",$tmpList);
271
 
272
                $langFile = _FILE;
273
 
274
                $bg = $this->cfg["bgLight"];
275
 
276
                foreach($tmpListArr as $key =>$value)
277
                {
278
                    $buildLine = true;
279
                    if (strpos($value,"/torrent/"))
280
                    {
281
                        $ts = new tSpy($value);
282
 
283
                        // Determine if we should build this output
284
                        if (is_int(array_search($ts->MainId,$this->catFilter)))
285
                        {
286
                            $buildLine = false;
287
                        }
288
 
289
                        if ($this->hideSeedless == "yes")
290
                        {
291
                            if($ts->Seeds == "N/A" || $ts->Seeds == "0")
292
                            {
293
                                $buildLine = false;
294
                            }
295
                        }
296
 
297
                        if (!empty($ts->torrentFile) && $buildLine) {
298
 
299
                            $output .= trim($ts->BuildOutput($bg,$langFile,$this->searchURL()));
300
 
301
                            // ok switch colors.
302
                            if ($bg == $this->cfg["bgLight"])
303
                            {
304
                                $bg = $this->cfg["bgDark"];
305
                            }
306
                            else
307
                            {
308
                                $bg = $this->cfg["bgLight"];
309
                            }
310
                        }
311
 
312
                    }
313
                }
314
                // set thing to end of this table.
315
                $thing = substr($thing,strpos($thing,"</table>"));
316
            }
317
        }
318
 
319
        $output .= "</table>";
320
 
321
        // is there paging at the bottom?
322
        if (strpos($thing, "<p class=\"pagenav\">Pages (") !== false)
323
        {
324
            // Yes, then lets grab it and display it!  ;)
325
            $thing = substr($thing,strpos($thing,"<p class=\"pagenav\">Pages (")+strlen("<p class=\"pagenav\">"));
326
            $pages = substr($thing,0,strpos($thing,"</p>"));
327
            $page1 = substr($pages,0,strpos($pages,"<img"));
328
            $page2 = substr($pages,strlen($page1));
329
            $page2 = substr($page2,strpos($page2,'>')+1);
330
            $pages = $page1.$page2;
331
 
332
            if (strpos($pages,"directory"))
333
            {
334
                $pages = str_replace("?","&",$pages);
335
                $pages = str_replace("/directory/", $this->searchURL()."&directory=", $pages);
336
            }
337
            elseif (strpos($pages, "search.asp?"))
338
            {
339
                $pages = str_replace("search.asp?", $this->searchURL()."&", $pages);
340
            }
341
            elseif  (strpos($pages, "/search/"))
342
            {
343
                $pages = str_replace("&amp;","&",$pages);
344
                $pages = str_replace("?","&",$pages);
345
                $pages = str_replace("/search/", $this->searchURL()."&searchterm=", $pages);
346
            }
347
            elseif (strpos($pages,"latest.asp?"))
348
            {
349
                $pages = str_replace("latest.asp?mode=", $this->searchURL()."&LATEST=1&mode=", $pages);
350
                if (!array_key_exists("mode",$_REQUEST))
351
                {
352
                    $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
353
                }
354
                elseif (! $_REQUEST["mode"] == "yesterday")
355
                {
356
                    $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
357
                }
358
                else
359
                {
360
                    $pages .= "<br><b>Yesterday's Latest</b>";
361
                }
362
            }
363
 
364
            $output .= "<br><div align=center>".$pages."</div><br>";
365
        }
366
        elseif(array_key_exists("LATEST",$_REQUEST))
367
        {
368
            $pages = '';
369
            if (!array_key_exists("mode",$_REQUEST))
370
            {
371
                $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
372
            }
373
            elseif (! $_REQUEST["mode"] == "yesterday")
374
            {
375
                $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
376
            }
377
            else
378
            {
379
                $pages .= "<br><b>Yesterday's Latest</b>";
380
            }
381
 
382
            $output .= "<br><div align=center>".$pages."</div><br>";
383
        }
384
 
385
        return $output;
386
    }
387
}
388
 
389
// This is a worker class that takes in a row in a table and parses it.
390
class tSpy
391
{
392
    var $torrentName = "";
393
    var $torrentDisplayName = "";
394
    var $torrentFile = "";
395
    var $torrentStatus = "";
396
    var $MainId = "";
397
    var $MainCategory = "";
398
    var $SubId = "";
399
    var $SubCategory = "";
400
    var $torrentSize = "";
401
    var $fileCount = "";
402
    var $Seeds = "";
403
    var $Peers = "";
404
    var $Data = "";
405
 
406
    function tSpy( $htmlLine )
407
    {
408
        if (strlen($htmlLine) > 0)
409
        {
410
 
411
            $this->Data = $htmlLine;
412
 
413
            // Chunck up the row into columns.
414
            $tmpListArr = split("</td>",$htmlLine);
415
 
416
            if(count($tmpListArr) > 5)
417
            {
418
                $tmpListArr["0"];  // Torrent Name, Download Link, Status
419
 
420
                $this->torrentDisplayName = $this->cleanLine($tmpListArr["0"]);  // TorrentName
421
 
422
                $tmpStr = substr($tmpListArr["0"],strpos($tmpListArr["0"],"/torrent/")+strlen("/torrent/")); // Download Link
423
                $this->torrentFile = "http://www.torrentspy.com/download.asp?id=" . substr($tmpStr,0,strpos($tmpStr,"/"));
424
 
425
                $tmpStatus = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
426
                $tmpStatus = substr($tmpStatus,0,strpos($tmpStatus,">"));
427
 
428
                if (strpos($tmpStatus,"password"))
429
                {
430
                    $this->torrentStatus = "P";
431
                }elseif (strpos($tmpStatus,"register"))
432
                {
433
                    $this->torrentStatus = "R";
434
                }
435
 
436
                $tmpStr = substr($tmpStr,strpos($tmpStr,">")+strlen(">"));
437
 
438
                if(strpos($tmpStr,"/torrent/") > 0)
439
                {
440
                    $tmpStr = substr($tmpStr,strpos($tmpStr,"/torrent/")+strlen("/torrent/"));
441
                }
442
 
443
                $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
444
                $this->torrentName = substr($tmpStr,0,strpos($tmpStr,"\""));
445
 
446
                $tmpStr = $tmpListArr["1"]; // Categories
447
                if(strpos($tmpStr,"mode=")){
448
                    $tmpStr = substr($tmpStr,strpos($tmpStr,"mode=main&id=")+strlen("mode=main&id="));
449
                    $this->MainId = substr($tmpStr,0,strpos($tmpStr,"\""));
450
                }else{
451
                    $tmpStr = substr($tmpStr,strpos($tmpStr,"/directory/")+strlen("/directory/"));
452
                    $this->MainId = substr($tmpStr,0,strpos($tmpStr,"/"));
453
                }
454
                $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
455
                $this->MainCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
456
 
457
                if(strpos($tmpStr,"mode=")){
458
                    $tmpStr = substr($tmpStr,strpos($tmpStr,"mode=sub&id=")+strlen("mode=sub&id="));
459
                    $this->SubId = substr($tmpStr,0,strpos($tmpStr,"\""));
460
                }else{
461
                    $tmpStr = substr($tmpStr,strpos($tmpStr,"/directory/")+strlen("/directory/"));
462
                    $this->SubId = substr($tmpStr,0,strpos($tmpStr,"/"));
463
                }
464
                $tmpStr = substr($tmpStr,strpos($tmpStr,"title=\"")+strlen("title=\""));
465
                $this->SubCategory = substr($tmpStr,0,strpos($tmpStr,"\""));
466
 
467
                $this->torrentSize = $this->cleanLine($tmpListArr["2"]);  // Size of File
468
                $this->fileCount = $this->cleanLine($tmpListArr["3"]);  // File Count
469
                $this->Seeds = $this->cleanLine($tmpListArr["4"]);  // Seeds
470
                $this->Peers = $this->cleanLine($tmpListArr["5"]);  // Peers
471
                //$tmpListArr["6"] = $this->cleanLine($tmpListArr["6"]);  // Health
472
 
473
                if ($this->Peers == '')
474
                {
475
                    $this->Peers = "N/A";
476
                    if (empty($this->Seeds)) $this->Seeds = "N/A";
477
                }
478
                if ($this->Seeds == '') $this->Seeds = "N/A";
479
 
480
                if(strlen($this->torrentDisplayName) > 50)
481
                {
482
                    $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
483
                }
484
 
485
           }
486
        }
487
 
488
    }
489
 
490
    function cleanLine($stringIn,$tags='')
491
    {
492
        if(empty($tags))
493
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
494
        else
495
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
496
    }
497
 
498
    //----------------------------------------------------------------
499
    // Function to build output for the table.
500
    function BuildOutput($bg,$langFILE, $searchURL = '')
501
    {
502
        $output = "<tr>\n";
503
        $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." - ".$this->fileCount." ".$langFILE."\" border=0></a></td>\n";
504
        $output .= "    <td bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a>";
505
        switch ($this->torrentStatus)
506
        {
507
            case "R":
508
                $output .= " <span title=Registration_Needed><b>R</b></span>";
509
                break;
510
            case "P":
511
                $output .= " <span title=Password_Needed><b>P</b></span>";
512
                break;
513
        }
514
        $output .= "</td>\n";
515
 
516
        if (strlen($this->MainCategory) > 1){
517
            if (strlen($this->SubCategory) > 1){
518
                $mainGenre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
519
                $subGenre = "<a href=\"".$searchURL."&subGenre=".$this->SubId."\">".$this->SubCategory."</a>";
520
                $genre = $mainGenre."-".$subGenre;
521
            }else{
522
                $genre = "<a href=\"".$searchURL."&mainGenre=".$this->MainId."\">".$this->MainCategory."</a>";
523
            }
524
        }else{
525
            $genre = "<a href=\"".$searchURL."&subGenre=".$this->SubId."\">".$this->SubCategory."</a>";
526
        }
527
 
528
        $output .= "    <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
529
        $output .= "    <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
530
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
531
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
532
        $output .= "</tr>\n";
533
 
534
        return $output;
535
 
536
    }
537
}
538
 
539
?>