File: readrss.php

package info (click to toggle)
torrentflux 2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,028 kB
  • ctags: 13,559
  • sloc: php: 36,501; python: 12,563; sh: 1,139; sql: 340; makefile: 44; xml: 22
file content (215 lines) | stat: -rwxr-xr-x 7,434 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php

/*************************************************************
*  TorrentFlux - PHP Torrent Manager
*  www.torrentflux.com
**************************************************************/
/*
    This file is part of TorrentFlux.

    TorrentFlux is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    TorrentFlux is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with TorrentFlux; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include_once("config.php");
include_once("functions.php");
include_once("lastRSS.php");

// check http://varchars.com/rss/ for feeds

// The following is for PHP < 4.3
if (!function_exists('html_entity_decode'))
{
    function html_entity_decode($string, $opt = ENT_COMPAT)
    {
        $trans_tbl = get_html_translation_table (HTML_ENTITIES);
        $trans_tbl = array_flip ($trans_tbl);

        if ($opt & 1)
        {
            // Translating single quotes
            // Add single quote to translation table;
            // doesn't appear to be there by default
            $trans_tbl["&apos;"] = "'";
        }

        if (!($opt & 2))
        {
            // Not translating double quotes
            // Remove double quote from translation table
            unset($trans_tbl["&quot;"]);
        }

        return strtr ($string, $trans_tbl);
    }
}

// Just to be safe ;o)
if (!defined("ENT_COMPAT")) define("ENT_COMPAT", 2);
if (!defined("ENT_NOQUOTES")) define("ENT_NOQUOTES", 0);
if (!defined("ENT_QUOTES")) define("ENT_QUOTES", 3);

DisplayHead("RSS Torrents");

// Get RSS feeds from Database
$arURL = GetRSSLinks();

// create lastRSS object
$rss = new lastRSS();

// setup transparent cache
$rss->cache_dir = $cfg["torrent_file_path"];
$rss->cache_time = $cfg["rss_cache_min"] * 60; // 1200 = 20 min.  3600 = 1 hour
$rss->strip_html = false; // don't remove HTML from the description

echo "<a name=\"top\"></a><div align=\"center\">";
echo "<table border=1 cellspacing=0 width=\"760\" cellpadding=5><tr>";
echo "<td bgcolor=\"".$cfg["table_header_bg"]."\">RSS Feeds (jump list):";
echo "<ul>";

$jumpCount = 0;
$rssfeed = array();

if (is_array($arURL))
{
    // Loop through each RSS feed
    foreach( $arURL as $rid => $url )
    {
        if( $rs = $rss->get( $url ) )
        {
            if( !empty( $rs["items"] ) )
            {
                // Cache rss feed so we don't have to call it again
                $rssfeed[] = $rs;
                echo "<li><a href=\"#".$jumpCount."\">".$rs["title"]."</a></li>\n";
            }
            else
            {
                $rssfeed[] = "";
                echo "<li>* RSS timed out * (<a href=\"#".$rid."\">".$url."</a>)</li>\n";
            }
        }
        else
        {
            // Unable to grab RSS feed, must of timed out
            $rssfeed[] = "";
            echo "<li>* RSS timed out * (<a href=\"#".$jumpCount."\">".$url."</a>)</li>\n";
        }
        $jumpCount++;
    }
    echo "</ul>* Click on Torrent Links below to add them to the Torrent Download List</td>";
    echo "</tr></table>";
    echo "</div>";

    if(is_array($rssfeed))
    {
        // Parse through cache RSS feed
        foreach( $rssfeed as $rid => $rs )
        {
            $title = "";
            $content = "";
            $pageUrl = "";

            if( !empty( $rs["items"] ) )
            {
                // get Site title and Page Link
                $title = $rs["title"];
                $pageUrl = $rs["link"];

                $content = "";

                for ($i=0; $i < count($rs["items"]); $i++)
                {
                    $link = $rs["items"][$i]["link"];
                    $title2 = $rs["items"][$i]["title"];
                    $pubDate = (!empty($rs["items"][$i]["pubDate"])) ? $rs["items"][$i]["pubDate"] : "Unknown";

                    // RSS entry needs to have a link, otherwise pointless
                    if( empty( $link ) )
                        continue;

                    if($link != "" && $title2 !="")
                    {
                        $content .= "<tr><td><img src=\"images/download_owner.gif\" width=\"16\" height=\"16\" title=\"".$link."\"><a href=\"index.php?url_upload=".$link."\">".$title2."</a></td><td> ".$pubDate."</td></tr>\n";
                    }
                    else
                    {
                        $content .= "<tr><td  class=\"tiny\"><img src=\"images/download_owner.gif\" width=\"16\" height=\"16\">".ScrubDescription(str_replace("Torrent: <a href=\"", "Torrent: <a href=\"index.php?url_upload=", html_entity_decode($rs["items"][$i]["description"])), $title2)."</td><td valign=\"top\">".$pubDate."</td></tr>";
                    }
                }
            }
            else
            {
                // Request timed out, display timeout message
                echo "<br>**** RSS timed out: <a href=\"".$url."\" target=\"_blank\">".$url."</a>";
            }

            if ($content != "") { // Close the content and add a line break
                $content .= "<br>";
            }
            displayNews($title, $pageUrl, $content, $rid);
        }
    }
}

DisplayFoot();

function displayNews($title, $pageUrl, $content, $rid) {
    global $cfg;
    // Draw the Table
    echo "<a name=\"".$rid."\"></a><table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
    echo "<tr><td colspan=2 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<strong><a href=\"".$pageUrl."\" target=\"_blank\"><font class=\"adminlink\">".$title."</font></a>&nbsp;&nbsp;<font class=\"tinywhite\">[<a href=\"#\"><font class=\"tinywhite\">top</font></a>]</font></strong>";
    echo "</td></tr>";
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._TORRENTFILE."</div></td>";
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"33%\"><div align=center class=\"title\">"._TIMESTAMP."</div></td>";

    echo $content;

    echo "</table>";
}

// Scrub the description to take out the ugly long URLs
function ScrubDescription($desc, $title)
{
    $rtnValue = "";

    $parts = explode("</a>", $desc);

    $replace = ereg_replace('">.*$', '">'.$title."</a>", $parts[0]);

    if (strpos($parts[1], "Search:") !== false)
    {
        $parts[1] = $parts[1]."</a>\n";
    }

    for($inx = 2; $inx < count($parts); $inx++)
    {
        if (strpos($parts[$inx], "Info: <a ") !== false)
        {
            // We have an Info: and URL to clean
            $parts[$inx] = ereg_replace('">.*$', '" target="_blank">Read More...</a>', $parts[$inx]);
        }
    }

    $rtnValue = $replace;
    for ($inx = 1; $inx < count($parts); $inx++)
    {
        $rtnValue .= $parts[$inx];
    }

    return $rtnValue;
}

?>