Exemple #1
0
// This file is part of Pipecode.
//
// Pipecode 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 3 of the License, or
// (at your option) any later version.
//
// Pipecode 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 Pipecode.  If not, see <http://www.gnu.org/licenses/>.
//
include "feed.php";
header("Content-Type: text/plain");
header_expires();
$row = run_sql("select fid, uri, time from feed");
for ($i = 0; $i < count($row); $i++) {
    $fid = $row[$i]["fid"];
    $uri = $row[$i]["uri"];
    $time = $row[$i]["time"];
    if (time() > $time + 60 * 5) {
        print "downloading fid [{$fid}] uri [{$uri}] ";
        $data = download_feed($uri);
        print "len [" . strlen($data) . "]\n";
        save_feed($fid, $data);
    }
}
print "done";
Exemple #2
0
function add_feed($uri)
{
    if (db_has_rec("feed", array("uri" => $uri))) {
        //die("feed already exists [$uri]");
        $feed = db_get_rec("feed", array("uri" => $uri));
        return $feed["fid"];
    }
    $data = download_feed($uri);
    $sp = new SimplePie();
    $sp->set_raw_data($data);
    $sp->init();
    $title = $sp->get_title();
    $link = get_feed_link($sp, $uri);
    $count = $sp->get_item_quantity();
    if (strlen($title) == 0 || $count == 0) {
        die("unable to parse feed [{$uri}]");
        //die("unable to parse feed [$uri] data [$data]");
    }
    $feed = array();
    $feed["fid"] = 0;
    $feed["time"] = time();
    $feed["uri"] = $uri;
    $feed["title"] = $title;
    $feed["link"] = $link;
    db_set_rec("feed", $feed);
    $feed = db_get_rec("feed", array("uri" => $uri));
    save_feed($feed["fid"], $data);
    return $feed["fid"];
}