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.00 - Mar 31, 06 - Created
27
*/
28
 
29
 
30
class SearchEngine extends SearchEngineBase
31
{
32
    var $dateAdded = "";
33
 
34
    function SearchEngine($cfg)
35
    {
36
        $this->mainURL = "newnova.org";
37
        $this->altURL = "newnova.org";
38
        $this->mainTitle = "NewNova";
39
        $this->engineName = "NewNova";
40
 
41
        $this->author = "kboy";
42
        $this->version = "1.00";
43
        $this->updateURL = "http://www.torrentflux.com/forum/index.php?topic=1002.0.html";
44
 
45
        $this->Initialize($cfg);
46
    }
47
 
48
    //----------------------------------------------------------------
49
    // Function to Get Main Categories
50
    function populateMainCategories()
51
    {
52
        $this->mainCatalog["1"] = "Games";
53
        $this->mainCatalog["2"] = "Movies";
54
        $this->mainCatalog["3"] = "TV Shows";
55
        $this->mainCatalog["4"] = "Music";
56
        $this->mainCatalog["5"] = "Apps";
57
        $this->mainCatalog["6"] = "Miscellaneous";
58
        $this->mainCatalog["7"] = "Anime";
59
    }
60
 
61
    //----------------------------------------------------------------
62
    // Function to Get Sub Categories
63
    function getSubCategories($mainGenre)
64
    {
65
        $output = array();
66
 
67
        $mainGenreName = $this->GetMainCatName($mainGenre);
68
 
69
        if($mainGenre == "6")
70
        {
71
            $mainGenreName = "Misc";
72
        }
73
 
74
        $request = '/list_torrents/' . str_replace(" ","",strtolower($mainGenreName)) . '.html';
75
 
76
        if ($this->makeRequest($request))
77
        {
78
            $thing = $this->htmlPage;
79
 
80
            if (is_integer(strpos($thing,"seperator")))
81
            {
82
                $thing = substr($thing,strpos($thing,"seperator")+strlen("seperator"));
83
                $thing = substr($thing,strpos($thing,"<table"));
84
                $thing = substr($thing,0,strpos($thing,"</table>"));
85
 
86
                while (is_integer(strpos($thing,"href=\"JavaScript:showTbl2(")))
87
                {
88
 
89
                    $thing = substr($thing,strpos($thing,"href=\"JavaScript:showTbl2(")+strlen("href=\"JavaScript:showTbl2("));
90
                    $tmpStr = substr($thing,0,strpos($thing,')'));
91
                    $tmpArr = split(",",$tmpStr);
92
 
93
                    $subid = substr($tmpArr[0],strpos($tmpArr[0],'/')+1);
94
                    while(is_integer(strpos($subid,"/")))
95
                    {
96
                        $subid = substr($subid,strpos($subid,'/')+1);
97
                    }
98
                    $subid = str_replace(array("'"),"",$subid);
99
                    $subname = str_replace(array("'"),"",$tmpArr[1]);
100
 
101
                    if($subname != $mainGenreName)
102
                    {
103
                        $output[$subid] = $subname;
104
                    }
105
                }
106
            }
107
       }
108
 
109
        return $output;
110
    }
111
 
112
    //----------------------------------------------------------------
113
    // Function to get Latest..
114
    function getLatest()
115
    {
116
        //http://www.newnova.org/list_news.html
117
        $request = "/list_news.html";
118
 
119
        if (array_key_exists("mode",$_REQUEST))
120
        {
121
            if($_REQUEST["mode"] == "yesterday" )
122
            {
123
                $request = "/list_news_1.html";
124
            }
125
        }
126
 
127
        if (array_key_exists("subGenre",$_REQUEST))
128
        {
129
            $request = "/list_torrents/".$_REQUEST["subGenre"].".html";
130
        }
131
 
132
        if (array_key_exists("dteAdded",$_REQUEST))
133
        {
134
            $this->dateAdded = $_REQUEST["dteAdded"];
135
        }
136
 
137
        if ($this->makeRequest($request))
138
        {
139
          return $this->parseResponse();
140
        }
141
        else
142
        {
143
           return $this->msg;
144
        }
145
    }
146
 
147
    //----------------------------------------------------------------
148
    // Function to perform Search.
149
    function performSearch($searchTerm)
150
    {
151
 
152
        $request = "/search.foo?data[searchTerm]=".$searchTerm."&";
153
 
154
        if ($this->makeRequest($request))
155
        {
156
            return $this->parseResponse();
157
        }
158
        else
159
        {
160
            return $this->msg;
161
        }
162
}
163
 
164
    //----------------------------------------------------------------
165
    // Override the base to show custom table header.
166
    // Function to setup the table header
167
    function tableHeader()
168
    {
169
 
170
        $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
171
 
172
        $output .= "<br>\n";
173
 
174
        $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
175
        $output .= "<td colspan=7 align=center><strong>".$this->dateAdded."</strong></td>";
176
        $output .= "</tr>\n";
177
 
178
        $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
179
        $output .= "  <td>&nbsp;</td>";
180
        $output .= "  <td><strong>Torrent Name</strong> &nbsp;(";
181
 
182
        $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
183
 
184
        // Check to see if Question mark is there.
185
        if (strpos($tmpURI,'?'))
186
        {
187
            $tmpURI .= "&";
188
        }
189
        else
190
        {
191
            $tmpURI .= "?";
192
        }
193
 
194
        if($this->hideSeedless == "yes")
195
        {
196
            $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
197
        }
198
        else
199
        {
200
            $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
201
        }
202
 
203
        $output .= ")</td>";
204
        $output .= "  <td><strong>Category</strong></td>";
205
        $output .= "  <td align=center><strong>&nbsp;&nbsp;Size</strong></td>";
206
        $output .= "  <td><strong>Seeds</strong></td>";
207
        $output .= "  <td><strong>Peers</strong></td>";
208
        $output .= "  <td align=center><strong>Kind</strong></td>";
209
        $output .= "</tr>\n";
210
 
211
        return $output;
212
    }
213
 
214
    //----------------------------------------------------------------
215
    // Function to parse the response.
216
    function parseResponse()
217
    {
218
 
219
        if (is_integer(strpos($this->htmlPage,"seperator")))
220
        {
221
            $dteAdded = substr($this->htmlPage,strpos($this->htmlPage,"seperator",20)+strlen("seperator"));
222
            $dteAdded = substr($dteAdded,strpos($dteAdded,">")+1);
223
            $this->dateAdded = substr($dteAdded,0,strpos($dteAdded,"<"));
224
        }
225
        else
226
        {
227
            if (!strlen($this->dateAdded) > 0)
228
            {
229
                $this->dateAdded = date(' j. F Y',time());
230
            }
231
        }
232
 
233
        $output = $this->tableHeader();
234
 
235
        $thing = $this->htmlPage;
236
 
237
        if (is_integer(strpos($thing,"Loading...")))
238
        {
239
            $thing = substr($thing,strpos($thing,"Loading..."));
240
            $thing = substr($thing,strpos($thing,"<script>")+strlen("<script>"));
241
            $tmpList = substr($thing,0,strpos($thing,"</script>"));
242
        }
243
        else
244
        {
245
            $tmpList = $thing;
246
        }
247
 
248
        // We got a response so display it.
249
        // Chop the front end off.
250
        if (is_integer(strpos($tmpList,"at2_nws_hdr")))
251
        {
252
            $output .= $this->nwsTableRows($tmpList);
253
        }
254
        elseif (is_integer(strpos($tmpList,"at2_header")))
255
        {
256
            $output .= $this->at2TableRows($tmpList);
257
        }
258
        else
259
        {
260
            if(is_integer(strpos($thing,"search returned no results")))
261
            {
262
                $output .= "<center>Your search returned no results. Please refine your search</center><br>";
263
            }
264
        }
265
 
266
        if (is_integer(strpos($thing,"seperator")))
267
        {
268
            $dteAdd = substr($thing,strpos($thing,"seperator",20)+strlen("seperator"));
269
            $dteAdd = substr($dteAdd,strpos($dteAdd,">")+1);
270
            $dteAdd = substr($dteAdd,0,strpos($dteAdd,"<"));
271
        }
272
 
273
        $output .= "</table>";
274
 
275
        $pages = '';
276
 
277
        if(array_key_exists("LATEST",$_REQUEST))
278
        {
279
            if (array_key_exists("mode",$_REQUEST))
280
            {
281
                if (! $_REQUEST["mode"] == "yesterday")
282
                {
283
                    $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday&dteAdded=".$dteAdd."\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
284
                }
285
            }
286
            else
287
            {
288
                $pages .= "<br><a href=\"".$this->searchURL()."&LATEST=1&mode=yesterday&dteAdded=".$dteAdd."\" title=\"Yesterday's Latest\">Yesterday's Latest</a>";
289
            }
290
 
291
            $output .= "<br><div align=center>".$pages."</div><br>";
292
        }
293
 
294
        return $output;
295
    }
296
 
297
    function at2TableRows($tmpList)
298
    {
299
        $output = '';
300
        $bg = $this->cfg["bgLight"];
301
 
302
        while (is_integer(strpos($tmpList,"at2_header")))
303
        {
304
            $tmpList = substr($tmpList,strpos($tmpList,"at2_header(")+strlen("at2_header('"));
305
            $curCat = substr($tmpList,0,strpos($tmpList,"'"));
306
            $tmpList = substr($tmpList,strpos($tmpList,"at2("));
307
            if (is_int(array_search($curCat,$this->catFilter)))
308
            {
309
                // Skip this category.
310
            }
311
            else
312
            {
313
                // We have something to-do.
314
                if (is_integer(strpos($tmpList,"at2_header(")))
315
                {
316
                    $tmpList2 = substr($tmpList,0,strpos($tmpList,"at2_header("));
317
                }
318
                elseif (is_integer(strpos($tmpList,"str.push")))
319
                {
320
                    $tmpList2 = substr($tmpList,0,strpos($tmpList,"str.push"));
321
                }
322
 
323
                //prepare line
324
                $tmpList2 = str_replace("at2(","",$tmpList2);
325
 
326
                // ok so now we have the listing.
327
                $tmpListArr = split(");",$tmpList2);
328
 
329
                $output .= $this->buildTableRows($tmpListArr, $bg);
330
            }
331
 
332
            // set tmpList to end of this category.
333
            if (is_integer(strpos($tmpList,"at2_header(")))
334
            {
335
                $tmpList = substr($tmpList,strpos($tmpList,"at2_header("));
336
            }
337
            elseif (is_integer(strpos($tmpList,"str.push")))
338
            {
339
                $tmpList =  substr($tmpList,strpos($tmpList,"str.push"));
340
            }
341
 
342
            // ok switch colors.
343
            if ($bg == $this->cfg["bgLight"])
344
            {
345
                $bg = $this->cfg["bgDark"];
346
            }
347
            else
348
            {
349
                $bg = $this->cfg["bgLight"];
350
            }
351
 
352
        }
353
        return $output;
354
    }
355
 
356
    function nwsTableRows($tmpList)
357
    {
358
        $output = '';
359
        $bg = $this->cfg["bgLight"];
360
 
361
        while (is_integer(strpos($tmpList,"at2_nws_hdr")))
362
        {
363
            $tmpList = substr($tmpList,strpos($tmpList,"at2_nws_hdr(")+strlen("at2_nws_hdr('"));
364
            $curCat = substr($tmpList,0,strpos($tmpList,"'"));
365
            $tmpList = substr($tmpList,strpos($tmpList,"at2("));
366
 
367
            if (is_int(array_search($curCat,$this->catFilter)))
368
            {
369
                // Skip this category.
370
            }
371
            else
372
            {
373
                // We have something to-do.
374
                if (is_integer(strpos($tmpList,"at2_nws_hdr(")))
375
                {
376
                    $tmpList2 = substr($tmpList,0,strpos($tmpList,"at2_nws_hdr("));
377
                }
378
                elseif (is_integer(strpos($tmpList,"str.push")))
379
                {
380
                    $tmpList2 = substr($tmpList,0,strpos($tmpList,"str.push"));
381
                }
382
 
383
                //prepare line
384
                $tmpList2 = str_replace("at2(","",$tmpList2);
385
 
386
                // ok so now we have the listing.
387
                $tmpListArr = split(");",$tmpList2);
388
 
389
                $output .= $this->buildTableRows($tmpListArr, $bg);
390
            }
391
 
392
            // set tmpList to end of this category.
393
            if (is_integer(strpos($tmpList,"at2_nws_hdr(")))
394
            {
395
                $tmpList = substr($tmpList,strpos($tmpList,"at2_nws_hdr("));
396
            }
397
            elseif (is_integer(strpos($tmpList,"str.push")))
398
            {
399
                $tmpList =  substr($tmpList,strpos($tmpList,"str.push"));
400
            }
401
 
402
            // ok switch colors.
403
            if ($bg == $this->cfg["bgLight"])
404
            {
405
                $bg = $this->cfg["bgDark"];
406
            }
407
            else
408
            {
409
                $bg = $this->cfg["bgLight"];
410
            }
411
 
412
        }
413
        return $output;
414
    }
415
 
416
    function buildTableRows($tmpListArr, $bg)
417
    {
418
 
419
        $output = "";
420
 
421
        foreach($tmpListArr as $key =>$value)
422
        {
423
 
424
            $buildLine = true;
425
            $ts = new tNova($value);
426
 
427
            // Determine if we should build this output
428
            if (is_int(array_search($ts->MainCategory,$this->catFilter)))
429
            {
430
                $buildLine = false;
431
            }
432
 
433
            if ($this->hideSeedless == "yes")
434
            {
435
                if($ts->Seeds == "N/A" || $ts->Seeds == "0")
436
                {
437
                    $buildLine = false;
438
                }
439
            }
440
 
441
            if (!empty($ts->torrentFile) && $buildLine) {
442
 
443
                $output .= trim($ts->BuildOutput($bg, $this->searchURL()));
444
 
445
                // ok switch colors.
446
                if ($bg == $this->cfg["bgLight"])
447
                {
448
                    $bg = $this->cfg["bgDark"];
449
                }
450
                else
451
                {
452
                    $bg = $this->cfg["bgLight"];
453
                }
454
            }
455
        }
456
 
457
        return $output;
458
    }
459
}
460
 
461
 
462
// This is a worker class that takes in a row in a table and parses it.
463
class tNova
464
{
465
    var $torrentName = "";
466
    var $torrentDisplayName = "";
467
    var $torrentFile = "";
468
    var $torrentSize = "";
469
    var $torrentStatus = "";
470
    var $MainId = "";
471
    var $MainCategory = "";
472
    var $SubCategory = "";
473
 
474
    var $fileCount = "";
475
    var $torrentAdded = "";
476
    var $Seeds = "";
477
    var $Peers = "";
478
    var $Data = "";
479
 
480
/*
481
   function at2 (
482
 
483
 1   torrent_additiondate_day,
484
 2   torrent_server_id,
485
 3   torrent_viewserver_id,
486
 4   torrent_view_link,
487
 5   torrent_link_desc,
488
 6   torrent_name,
489
 7   torrent_link,
490
 8   torrent_filesize_mb,
491
 9   torrent_lastnrseeds,
492
10   torrent_lastnrleeches,
493
11   torrent_quality,
494
12   torrent_submitter_id,
495
13   torrent_submitter_nickname,
496
14   torrent_submitter_status,
497
15   torrent_infolink,
498
16   torrent_type_id,
499
17   torrent_tracker_has_nostats,
500
18   torrent_tracker_has_unknownstats,
501
19   torrent_lastcheck_nr_invalid,
502
20   torrent_is_moderated,
503
21   torrent_is_deleted,
504
22   torrent_is_softdeleted,
505
23   torrent_has_rights,
506
24   torrent_tracker_registered
507
)
508
*/
509
 
510
    function tNova( $htmlLine , $dteAdded = "")
511
    {
512
        if (strlen($htmlLine) > 0)
513
        {
514
 
515
            $this->Data = $htmlLine;
516
 
517
            // Chunck up the row into columns.
518
            $tmpListArr = split(",",str_replace(array("'"),"",$htmlLine));
519
 
520
            if(count($tmpListArr) >= 24)
521
            {
522
                $this->torrentAdded = " | Added" . $dteAdded . " " . $tmpListArr[1];
523
                if(strlen($tmpListArr[13])>0)
524
                {
525
                    $this->torrentAdded .= " By ". $tmpListArr[13];
526
                }
527
 
528
                if( $tmpListArr[2])
529
                {
530
                    $this->torrentFile = "http://www.newnova.org/site/torrents/" . trim($tmpListArr[7]);
531
                }else{
532
                    $this->torrentFile = "http://www.newnova.org/get/" . trim($tmpListArr[7]);
533
                }
534
 
535
                $tmpArr = split(" - ",$tmpListArr[5]);
536
                if(count($tmpArr) == 2)
537
                {
538
                    $this->MainCategory = trim($tmpArr[0]);
539
                    $this->SubCategory = trim($tmpArr[1]);
540
                }
541
                else
542
                {
543
                    $this->MainCategory = trim($tmpListArr[5]);
544
                }
545
 
546
                $this->torrentName = $tmpListArr[6];
547
                $this->torrentSize = $tmpListArr[8];
548
                $this->Seeds = $tmpListArr[9];
549
                $this->Peers = $tmpListArr[10];
550
                $this->torrentStatus = $tmpListArr[11];
551
 
552
                if ($this->Peers == '')
553
                {
554
                    $this->Peers = "N/A";
555
                    if (empty($this->Seeds)) $this->Seeds = "N/A";
556
                }
557
                if ($this->Seeds == '') $this->Seeds = "N/A";
558
 
559
                $this->torrentDisplayName = $this->torrentName;
560
                if(strlen($this->torrentDisplayName) > 50)
561
                {
562
                    $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
563
                }
564
           }
565
        }
566
    }
567
 
568
    //----------------------------------------------------------------
569
    // Function to build output for the table.
570
    function BuildOutput($bg, $searchURL = '')
571
    {
572
        $output = "<tr>\n";
573
        $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->torrentAdded."\" border=0></a></td>\n";
574
        $output .= "    <td bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
575
 
576
        if (strlen($this->SubCategory) > 1){
577
            $genre = $this->MainCategory . " - " . $this->SubCategory;
578
        }else{
579
            $genre = $this->MainCategory;
580
        }
581
 
582
        $output .= "    <td bgcolor=\"".$bg."\">". $genre ."</td>\n";
583
 
584
        $output .= "    <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
585
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
586
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
587
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->torrentStatus."</td>\n";
588
        $output .= "</tr>\n";
589
 
590
        return $output;
591
 
592
    }
593
}
594
 
595
?>