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
/*
27
   This is the base search engine class that is inherited from to
28
   create specialized search engines.
29
 
30
   Each new Search must use the following nameing standards.
31
   ???Engine.php where ??? is the search engine name.
32
 
33
   !! All changes and customizations should be done in those files and not in this file. !!
34
 
35
*/
36
// Created By Kboy
37
class SearchEngineBase
38
{
39
    var $engineName = '';       // The Engine Name Must be the same as the File name
40
                                // minus Engine.
41
 
42
    var $mainTitle = '';        // The displayed Main Title for the engine.
43
    var $mainURL = '';          // The Primary URL used in searching or paging.
44
    var $altURL = '';           // The alternate URL used in searching or paging.
45
 
46
    var $author = '';           // the author of this engine
47
    var $version = '';
48
    var $updateURL = 'http://www.torrentflux.com/forum/index.php/board,14.0.html';
49
 
50
    // ------------------------------------------------------------------------------
51
    // You should only need to set the above variables in each of the custom classes.
52
    // ------------------------------------------------------------------------------
53
 
54
    var $cfg = array();         // The config array that holds the config settings of
55
                                // TorrentFlux at time of initialization
56
                                // This may contain the mainCatalog and catFilter
57
                                // as assigned by the admin tool.
58
                                // If it doesn't then we ask the individual engines for there
59
                                // mainCatalog and catFilter.
60
 
61
 
62
    var $mainCatalogName = '';  // The name of the Main Catalog
63
    var $mainCatalog = array(); // An array of Main Catalog entries.
64
    var $subCatalog = array();  // An array of Sub Catalog entries.
65
 
66
    var $catFilterName = '';    // Name of Filter used to retrieve from DB.
67
    var $catFilter = array();   // An array of categories to Filter out from DB.
68
 
69
    var $curRequest ='';        // The actual Request sent to the Search Engine
70
    var $hideSeedless = false;  // Boolean to determine if we should hide or show seedless torrents
71
    var $searchTerm = '';       // Search term passed into the engine
72
 
73
    var $htmlPage = '';         // HTML created by the engine for displaying
74
    var $msg = '';              // Message to be displayed
75
    var $pg = '';               // Page Variable used in Paging
76
 
77
    var $fp = '';               // Pointer to a socket connection
78
 
79
    var $initialized = false;   // Boolean to determine if the search engine initialized ok.
80
 
81
    /**
82
     * Constructor
83
     */
84
    function SearchEngineBase()
85
    {
86
        die('Virtual Class -- cannot instantiate');
87
    }
88
 
89
    //----------------------------------------------------------------
90
    // Initialize the Search Engine setting up the Catalog and Filters.
91
    // and Testing the connection.
92
    function Initialize($cfg)
93
    {
94
        $rtnValue = false;
95
 
96
        $this->cfg = unserialize($cfg);
97
        $this->pg = getRequestVar('pg');
98
 
99
        if (empty($this->altURL))
100
            $this->altURL = $this->mainURL;
101
 
102
        if (empty($this->cfg))
103
        {
104
            $this->msg = "Config not passed";
105
            $this->initialized = false;
106
            return;
107
        }
108
 
109
        $this->catFilterName = $this->engineName."GenreFilter";
110
        $this->mainCatalogName = $this->engineName."_catalog";
111
 
112
        if (array_key_exists('hideSeedless',$_SESSION))
113
            $this->hideSeedless = $_SESSION['hideSeedless'];
114
 
115
        if (array_key_exists($this->catFilterName,$this->cfg))
116
            $this->catFilter = $this->cfg[$this->catFilterName];
117
        else
118
            $this->catFilter = array();
119
 
120
        if (array_key_exists($this->mainCatalogName,$this->cfg))
121
            $this->mainCatalog = $this->cfg[$this->mainCatalogName];
122
        else
123
            $this->populateMainCategories();
124
 
125
        if ( $this->getConnection() )
126
            $rtnValue = true;
127
 
128
        $this->closeConnection();
129
 
130
        // in PHP 5 use
131
        //$this->curRequest = http_build_query($_REQUEST);
132
        $this->curRequest = $this->http_query_builder($_REQUEST);
133
 
134
        $this->initialized = $rtnValue;
135
    }
136
 
137
    //------------------------------------------------------------------
138
    // This is for backward compatibility.
139
    function http_query_builder( $formdata, $numeric_prefix = null, $key = null )
140
    {
141
       $res = array();
142
       foreach ((array)$formdata as $k=>$v) {
143
           $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);
144
           if ($key) $tmp_key = $key.'['.$tmp_key.']';
145
           if ( is_array($v) || is_object($v) ) {
146
               $res[] = http_query_builder($v, null, $tmp_key);
147
           } else {
148
               $res[] = $tmp_key."=".urlencode($v);
149
           }
150
       }
151
       $separator = ini_get('arg_separator.output');
152
       return implode($separator, $res);
153
    }
154
 
155
    //----------------------------------------------------------------
156
    // Function to populate the mainCatalog
157
    function populateMainCategories()
158
    {
159
        return;
160
    }
161
 
162
    //----------------------------------------------------------------
163
    // Function to Get Sub Categories
164
    function getSubCategories($mainGenre)
165
    {
166
        return array();
167
    }
168
 
169
    //----------------------------------------------------------------
170
    // Function to test Connection.
171
    function getConnection()
172
    {
173
        // Try to connect
174
        if (!$this->fp = @fsockopen ($this->mainURL, 80, $errno, $errstr, 30))
175
        {
176
            // Error Connecting
177
            $this->msg = "Error connecting to ".$this->mainURL."!";
178
            return false;
179
        }
180
        return true;
181
    }
182
 
183
    //----------------------------------------------------------------
184
    // Function to Close Connection.
185
    function closeConnection()
186
    {
187
        if($this->fp)
188
        {
189
            fclose($this->fp);
190
        }
191
    }
192
 
193
    //----------------------------------------------------------------
194
    // Function to return the URL needed by tf
195
    function searchURL()
196
    {
197
        return "torrentSearch.php?searchEngine=".$this->engineName;
198
    }
199
 
200
    //----------------------------------------------------------------
201
    // Function to Make the GetRequest
202
    function makeRequest($request, $useAlt = false)
203
    {
204
        $rtnVal = false;
205
 
206
        if (isset($_SESSION['lastOutBoundURI']))
207
        {
208
            $refererURI = $_SESSION['lastOutBoundURI'];
209
        }
210
        else
211
        {
212
            $refererURI = "http://".$this->mainURL;
213
        }
214
 
215
        if ($useAlt)
216
        {
217
            $request =  "http://".$this->altURL. $request;
218
        }
219
        else
220
        {
221
            $request =  "http://".$this->mainURL. $request;
222
        }
223
 
224
        $this->htmlPage = FetchHTML( $request, $refererURI );
225
        $rtnVal = true;
226
 
227
        return $rtnVal;
228
    }
229
 
230
    //----------------------------------------------------------------
231
    // Function to Get Main Categories
232
    function getMainCategories($filtered = true)
233
    {
234
        $output = array();
235
 
236
        foreach ($this->mainCatalog as $mainId => $mainName)
237
        {
238
            if ($filtered)
239
            {
240
                // see if this is filtered out.
241
                if (!(@in_array($mainId, $this->catFilter)))
242
                {
243
                    $output[$mainId] = $mainName;
244
                }
245
            }
246
            else
247
            {
248
                $output[$mainId] = $mainName;
249
            }
250
        }
251
 
252
        return $output;
253
    }
254
 
255
    //----------------------------------------------------------------
256
    // Function to Get Main Category Name
257
    function GetMainCatName($mainGenre)
258
    {
259
        $mainGenreName = '';
260
        foreach ($this->getMainCategories() as $mainId => $mainName)
261
        {
262
            if ($mainId == $mainGenre)
263
            {
264
                $mainGenreName = $mainName;
265
            }
266
        }
267
        return $mainGenreName;
268
    }
269
 
270
    //----------------------------------------------------------------
271
    // Function to setup the table header
272
    function tableHeader()
273
    {
274
        $output = "<table width=\"100%\" cellpadding=3 cellspacing=0 border=0>";
275
 
276
        $output .= "<br>\n";
277
        $output .= "<tr bgcolor=\"".$this->cfg["table_header_bg"]."\">";
278
        $output .= "  <td>&nbsp;</td>";
279
        $output .= "  <td><strong>Torrent Name</strong> &nbsp;(";
280
 
281
        $tmpURI = str_replace(array("?hideSeedless=yes","&hideSeedless=yes","?hideSeedless=no","&hideSeedless=no"),"",$_SERVER["REQUEST_URI"]);
282
 
283
        // Check to see if Question mark is there.
284
        if (strpos($tmpURI,'?'))
285
        {
286
            $tmpURI .= "&";
287
        }
288
        else
289
        {
290
            $tmpURI .= "?";
291
        }
292
 
293
        if($this->hideSeedless == "yes")
294
        {
295
            $output .= "<a href=\"". $tmpURI . "hideSeedless=no\">Show Seedless</a>";
296
        }
297
        else
298
        {
299
            $output .= "<a href=\"". $tmpURI . "hideSeedless=yes\">Hide Seedless</a>";
300
        }
301
 
302
        $output .= ")</td>";
303
        $output .= "  <td><strong>Category</strong></td>";
304
        $output .= "  <td align=center><strong>&nbsp;&nbsp;Size</strong></td>";
305
        $output .= "  <td><strong>Seeds</strong></td>";
306
        $output .= "  <td><strong>Peers</strong></td>";
307
        $output .= "</tr>\n";
308
 
309
        return $output;
310
    }
311
 
312
}
313
 
314
?>
315