Issues (1839)

html/inc/rss.inc (2 issues)

1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2021 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
// functions for fetching and displaying RSS feeds
20
21
require_once("../inc/cache.inc");
22
23
// parse an RSS feed into objects
24
//
25
function get_rss_feed($url) {
26
    $x = @simplexml_load_file($url);
27
    if (!$x) return null;
28
    $x = $x->channel;
29
    $items = array();
30
    foreach ($x->item as $item) {
31
        $y = new StdClass;
32
        $y->title = (string)$item->title;
33
        $y->link = (string)$item->link;
34
        $y->description = (string)$item->description;
35
        $y->pubDate = (string)$item->pubDate;
36
        $items[] = $y;
37
    }
38
    return $items;
39
}
40
41
// same, but cache the results; $dur is the refresh period
42
//
43
function get_rss_feed_cached($url, $dur) {
44
    $d = get_cached_data($dur, $url);
45
    if ($d) {
46
        return unserialize($d);
47
    }
48
    $items = get_rss_feed($url);
0 ignored issues
show
Are you sure the assignment to $items is correct as get_rss_feed($url) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
    if (!$items) return null;
0 ignored issues
show
$items is of type null, thus it always evaluated to false.
Loading history...
50
    set_cached_data($dur, serialize($items), $url);
51
    return $items;
52
}
53
54
// Show up to $n items.
55
// You can pass a function $filter;
56
// if $filter(item) returns true, don't show it.
57
//
58
function show_rss_items($items, $n=0, $filter=null) {
59
    $i = 0;
60
    foreach ($items as $item) {
61
        if ($filter && $filter($item)) {
62
            continue;
63
        }
64
        echo sprintf(
65
            '<h4>%s</h4>
66
            <p>
67
            %s
68
            <p>
69
            <a href=%s>View article</a> &middot; %s
70
            <hr>
71
            ',
72
            $item->title,
73
            $item->description,
74
            $item->link,
75
            $item->pubDate
76
        );
77
        $i++;
78
        if ($i == $n) {
79
            break;
80
        }
81
    }
82
}
83
84
?>
85