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
class SearchEngine extends SearchEngineBase
26
{
27
 
28
    function SearchEngine($cfg)
29
    {
30
        $this->mainURL = "torrentbox.com";
31
        $this->altURL = "torrentbox.com";
32
        $this->mainTitle = "TorrentBox";
33
        $this->engineName = "TorrentBox";
34
 
35
        $this->author = "kboy";
36
        $this->version = "1.00";
37
        $this->updateURL = "http://www.torrentflux.com/forum/index.php/topic,876.0.html";
38
 
39
        $this->Initialize($cfg);
40
    }
41
 
42
    function populateMainCategories()
43
    {
44
        $this->mainCatalog["0"] = "(all types)";
45
        $this->mainCatalog["9"] = "Anime";
46
        $this->mainCatalog["90"] = "Apps";
47
        $this->mainCatalog["11"] = "Books";
48
        $this->mainCatalog["10"] = "Comics";
49
        $this->mainCatalog["91"] = "Games";
50
        $this->mainCatalog["6"] = "Misc";
51
        $this->mainCatalog["92"] = "Movies";
52
        $this->mainCatalog["93"] = "Music";
53
        $this->mainCatalog["8"] = "Pics";
54
        $this->mainCatalog["3"] = "TV";
55
        $this->mainCatalog["13"] = "Videos";
56
    }
57
 
58
    //----------------------------------------------------------------
59
    // Function to Get Sub Categories
60
    function getSubCategories($mainGenre)
61
    {
62
        $output = array();
63
 
64
        switch ($mainGenre)
65
        {
66
            case "90" :
67
                $output["51"] = "Linux";
68
                $output["52"] = "Mac";
69
                $output["50"] = "Windows";
70
                $output["5"] = "Misc";
71
                break;
72
            case "91" :
73
                $output["4"] = "Misc";
74
                $output["41"] = "PC";
75
                $output["42"] = "PS2";
76
                $output["43"] = "PSX";
77
                $output["44"] = "ROMS";
78
                $output["40"] = "Xbox";
79
                break;
80
            case "92" :
81
                $output["14"] = "DVD-R";
82
                $output["100"] = "Action";
83
                $output["101"] = "Adventure";
84
                $output["102"] = "Animation";
85
                $output["103"] = "Comedy";
86
                $output["104"] = "Drama";
87
                $output["105"] = "Documentary";
88
                $output["106"] = "Horror";
89
                $output["107"] = "Sci-Fi";
90
                $output["1"] = "Misc";
91
                break;
92
            case "93" :
93
                $output["15"] = "Alternative";
94
                $output["16"] = "Blues";
95
                $output["17"] = "Electronic";
96
                $output["18"] = "Pop";
97
                $output["19"] = "Rap";
98
                $output["20"] = "Rock";
99
                $output["21"] = "Reggae";
100
                $output["22"] = "Jazz";
101
                $output["23"] = "Dance";
102
                $output["24"] = "Christian";
103
                $output["25"] = "Spanish";
104
                $output["2"] = "Misc";
105
                break;
106
        }
107
 
108
        return $output;
109
 
110
    }
111
 
112
    //----------------------------------------------------------------
113
    // Function to Make the Request (overriding base)
114
    function makeRequest($request)
115
    {
116
        return parent::makeRequest($request, false);
117
    }
118
 
119
    //----------------------------------------------------------------
120
    // Function to get Latest..
121
    function getLatest()
122
    {
123
        $cat = getRequestVar('subGenre');
124
        if (empty($cat)) $cat = getRequestVar('cat');
125
 
126
        $request = "/torrents-browse.php";
127
 
128
        if(!empty($cat))
129
        {
130
            if(strpos($request,"?"))
131
            {
132
                $request .= "&cat=".$cat;
133
            }
134
            else
135
            {
136
                $request .= "?cat=".$cat;
137
            }
138
        }
139
 
140
        if (!empty($this->pg))
141
        {
142
            if(strpos($request,"?"))
143
            {
144
                $request .= "&page=" . $this->pg;
145
            }
146
            else
147
            {
148
                $request .= "?page=" . $this->pg;
149
            }
150
        }
151
 
152
        if ($this->makeRequest($request))
153
        {
154
          return $this->parseResponse();
155
        }
156
        else
157
        {
158
           return $this->msg;
159
        }
160
    }
161
 
162
    //----------------------------------------------------------------
163
    // Function to perform Search.
164
    function performSearch($searchTerm)
165
    {
166
 
167
        $searchTerm = str_replace(" ", "+", $searchTerm);
168
        $request = "/torrents-search.php?search=".$searchTerm;
169
 
170
        if(!empty($cat))
171
        {
172
            $request .= "&cat=".$cat;
173
        }
174
 
175
        $onlyname = getRequestVar('onlyname');
176
        if (empty($onlyname)) $onlyname = "no";
177
        $request .= "&onlyname=".$onlyname;
178
 
179
        $incldead = getRequestVar('incldead');
180
        if (empty($incldead)) $incldead = "0";
181
        $request .= "&incldead=".$incldead;
182
 
183
 
184
        $request .= "&submit=";
185
 
186
        if (!empty($this->pg))
187
        {
188
            $request .= "&page=" . $this->pg;
189
        }
190
 
191
        if ($this->makeRequest($request))
192
        {
193
            return $this->parseResponse();
194
        }
195
        else
196
        {
197
            return $this->msg;
198
        }
199
    }
200
 
201
    //----------------------------------------------------------------
202
    // Function to parse the response.
203
    function parseResponse()
204
    {
205
        $output = $this->tableHeader();
206
 
207
        $thing = $this->htmlPage;
208
 
209
        // We got a response so display it.
210
        // Chop the front end off.
211
        while (is_integer(strpos($thing,">Uploader<")))
212
        {
213
            $thing = substr($thing,strpos($thing,">Uploader<"));
214
            $thing = substr($thing,strpos($thing,"<tr"));
215
            $tmpList = substr($thing,0,strpos($thing,"</table>"));
216
            // ok so now we have the listing.
217
            $tmpListArr = split("</tr>",$tmpList);
218
 
219
            $bg = $this->cfg["bgLight"];
220
 
221
            foreach($tmpListArr as $key =>$value)
222
            {
223
                $buildLine = true;
224
                if (strpos($value,"download.php"))
225
                {
226
                    $ts = new tBox($value);
227
 
228
                    // Determine if we should build this output
229
                    if (is_int(array_search($ts->CatName,$this->catFilter)))
230
                    {
231
                        $buildLine = false;
232
                    }
233
 
234
                    if ($this->hideSeedless == "yes")
235
                    {
236
                        if($ts->Seeds == "N/A" || $ts->Seeds == "0")
237
                        {
238
                            $buildLine = false;
239
                        }
240
                    }
241
 
242
                    if (!empty($ts->torrentFile) && $buildLine) {
243
 
244
                        $output .= trim($ts->BuildOutput($bg));
245
 
246
                        // ok switch colors.
247
                        if ($bg == $this->cfg["bgLight"])
248
                        {
249
                            $bg = $this->cfg["bgDark"];
250
                        }
251
                        else
252
                        {
253
                            $bg = $this->cfg["bgLight"];
254
                        }
255
                    }
256
 
257
                }
258
            }
259
            // set thing to end of this table.
260
            $thing = substr($thing,strpos($thing,"</table>"));
261
        }
262
 
263
        $output .= "</table>";
264
 
265
        //http://www.torrentbox.com/torrents-browse.php?cat=4&page=2
266
        // is there paging at the bottom?
267
        if (strpos($thing, "<span class=\"pager\">") != false)
268
        {
269
            // Yes, then lets grab it and display it!  ;)
270
            $thing = substr($thing,strpos($thing,"<span class=\"pager\">")+strlen("<span class=\"pager\">"));
271
            $pages = substr($thing,0,strpos($thing,"</span>"));
272
            if(strpos($this->curRequest,"LATEST"))
273
            {
274
                if(strpos($pages,"cat="))
275
                {
276
                    $pages = str_replace("page=","pg=",str_replace("http://www.torrentbox.com/torrents-browse.php?",$this->searchURL()."&LATEST=1&",$pages));
277
                }
278
                else
279
                {
280
                    $pages = str_replace("http://www.torrentbox.com/torrents-browse.php?page=",$this->searchURL()."&LATEST=1&pg=",$pages);
281
                }
282
            }
283
            else
284
            {
285
                $pages = str_replace("page","pg",str_replace("http://www.torrentbox.com/torrents-browse.php?search=",$this->searchURL()."&searchterm=",$pages));
286
            }
287
            $output .= "<div align=center>".$pages."</div>";
288
        }
289
 
290
        return $output;
291
    }
292
}
293
 
294
// This is a worker class that takes in a row in a table and parses it.
295
class tBox
296
{
297
    var $torrentName = "";
298
    var $torrentDisplayName = "";
299
    var $torrentFile = "";
300
    var $torrentSize = "";
301
    var $torrentStatus = "";
302
    var $CatId = "";
303
    var $CatName = "";
304
    var $fileCount = "";
305
    var $Seeds = "";
306
    var $Peers = "";
307
    var $Data = "";
308
 
309
    var $dateAdded = "";
310
    var $dwnldCount = "";
311
 
312
    function tBox( $htmlLine )
313
    {
314
        if (strlen($htmlLine) > 0)
315
        {
316
 
317
            $this->Data = $htmlLine;
318
 
319
            // Fix messed up end td's once in a while.
320
            $htmlLine = eregi_replace("<(.)*1ff8(.)*/td>",'</td>',$htmlLine);
321
            $htmlLine = eregi_replace("1ff8",'',$htmlLine);
322
 
323
            // Chunck up the row into columns.
324
            $tmpListArr = split("</td>",$htmlLine);
325
 
326
            if(count($tmpListArr) > 8)
327
            {
328
                $this->CatName = $this->cleanLine($tmpListArr["0"]);  // Cat Name
329
                if (strpos($this->CatName,">"))
330
                {
331
                    $this->CatName = trim(substr($this->CatName,strpos($this->CatName,">")+1));
332
                }
333
                $this->torrentName = $this->cleanLine($tmpListArr["1"]);  // TorrentName
334
 
335
                $tmpStr = substr($tmpListArr["2"],strpos($tmpListArr["2"],"href=\"")+strlen("href=\"")); // Download Link
336
 
337
                $this->torrentFile = substr($tmpStr,0,strpos($tmpStr,"\""));
338
 
339
                $this->dateAdded = $this->cleanLine($tmpListArr["4"]);  // Date Added
340
                $this->torrentSize = $this->cleanLine($tmpListArr["5"]);  // Size of File
341
                $this->dwnldCount = $this->cleanLine($tmpListArr["6"]);  // Download Count
342
                $this->Seeds = $this->cleanLine($tmpListArr["7"]);  // Seeds
343
                $this->Peers = $this->cleanLine($tmpListArr["8"]);  // Peers
344
                //$tmpListArr["9"] = $this->cleanLine($tmpListArr["9"]);  // Person who Uploaded it.
345
 
346
                if ($this->Peers == '')
347
                {
348
                    $this->Peers = "N/A";
349
                    if (empty($this->Seeds)) $this->Seeds = "N/A";
350
                }
351
                if ($this->Seeds == '') $this->Seeds = "N/A";
352
 
353
                $this->torrentDisplayName = $this->torrentName;
354
                if(strlen($this->torrentDisplayName) > 50)
355
                {
356
                    $this->torrentDisplayName = substr($this->torrentDisplayName,0,50)."...";
357
                }
358
 
359
           }
360
        }
361
 
362
    }
363
 
364
    function cleanLine($stringIn,$tags='')
365
    {
366
        if(empty($tags))
367
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn)));
368
        else
369
            return trim(str_replace(array("&nbsp;","&nbsp")," ",strip_tags($stringIn,$tags)));
370
    }
371
 
372
    //----------------------------------------------------------------
373
    // Function to build output for the table.
374
    function BuildOutput($bg)
375
    {
376
        $output = "<tr>\n";
377
        $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";
378
        $output .= "    <td bgcolor=\"".$bg."\"><a href=\"index.php?url_upload=".$this->torrentFile."\" title=\"".$this->torrentName."\">".$this->torrentDisplayName."</a></td>\n";
379
        $output .= "    <td bgcolor=\"".$bg."\">". $this->CatName ."</td>\n";
380
        $output .= "    <td bgcolor=\"".$bg."\" align=right>".$this->torrentSize."</td>\n";
381
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Seeds."</td>\n";
382
        $output .= "    <td bgcolor=\"".$bg."\" align=center>".$this->Peers."</td>\n";
383
        $output .= "</tr>\n";
384
 
385
        return $output;
386
 
387
    }
388
}
389
 
390
?>