function fetch_items($channel)
{
    $opts = array();
    if (ENABLE_PROXY) {
        $opts = array("http" => array("proxy" => "tcp://" . PROXY_SERVER . ":" . PROXY_PORT, "request_fulluri" => true));
    }
    $context = stream_context_create($opts);
    $data = file_get_contents($channel->get_url(), false, $context);
    $items = parse_rss($data);
    return $items;
}
Пример #2
0
/**
 * Pull notifications from remotes
 * @return array Notifications
 */
function get_notifications()
{
    global $config;
    $obj = array();
    foreach ($config['notifications'] as $name => $url) {
        echo '[ ' . date('r') . ' ] ' . $url . ' ';
        $feed = json_decode(json_encode(simplexml_load_string(file_get_contents($url))), true);
        if (isset($feed['channel'])) {
            $feed = parse_rss($feed);
        } else {
            $feed = parse_atom($feed);
        }
        array_walk($feed, function (&$items, $key, $url) {
            $items['source'] = $url;
        }, $url);
        $obj = array_reverse(array_merge($obj, $feed));
        echo '(' . sizeof($obj) . ')' . PHP_EOL;
    }
    return $obj;
}
Пример #3
0
}
function output_rss($pattern, $rss_data, $count_latest)
{
    $temp = null;
    for ($i = 0; $i < $count_latest; $i++) {
        $temp .= sprintf($pattern, $rss_data['link'][$i], html_entity_decode($rss_data['title'][$i]), html_entity_decode($rss_data['desc'][$i]));
    }
    return $temp;
}
$url = 'http://censor.net.ua/includes/news_ru.xml';
$reg_exp = '#<item>.*?<title>(.*?)<\\/title>.*?';
$reg_exp .= '<link>(.*?)<\\/link>.*?<description>';
$reg_exp .= '(.*?)<\\/description>.*?<\\/item>#si';
$pattern = '<a href="%s">%s</a><br>%s<hr>';
if ($xml_data = file_get_contents($url)) {
    $rss_data = parse_rss($reg_exp, $xml_data);
    echo output_rss($pattern, $rss_data, 20);
}
?>

            </div>


            <?php 
echo $content;
?>
        </div>


        <footer class="footer">
            <div class="container">
Пример #4
0
    if ($data !== False) {
        $feed_history = explode(PHP_EOL, $data);
    }
}
$results = array();
$new_history = array();
for ($i = 0; $i < count($feed_list); $i++) {
    $feed = $feed_list[$i];
    term_echo("processing " . $feed["name"] . " " . $feed["type"] . " feed @ \"" . $feed["url"] . "\"");
    $response = wget($feed["host"], $feed["uri"], $feed["port"]);
    $html = strip_headers($response);
    $items = array();
    if ($feed["type"] == "atom") {
        $items = parse_atom($html);
    } elseif ($feed["type"] == "rss") {
        $items = parse_rss($html);
    }
    if ($items === False) {
        term_echo("feed parse error");
        continue;
    }
    term_echo("feed items for " . $feed["name"] . ": " . count($items));
    for ($j = 0; $j < count($items); $j++) {
        $item = $items[$j];
        if (in_array($item["url"], $feed_history) == False) {
            $new_history[] = $item["url"];
            $delim1 = "<![CDATA[";
            $delim2 = "]]>";
            if (strtoupper(substr($item["title"], 0, strlen($delim1))) == $delim1) {
                $item["title"] = substr($item["title"], strlen($delim1), strlen($item["title"]) - strlen($delim1) - strlen($delim2));
            }
Пример #5
0
        }
        return $ret;
    }
}
if (0) {
    /**
     * 该文件应该定期使用 PHP-CLI 运行,建议添加到 CRON 任务中
     * 
     * 建议每隔 30 分钟运行一次
     * 
     * 该脚本会自动访问 $RSS_FEED,并将 RSS 内存保存到数据库中
     */
    require_once 'header.php';
    /// 3. 解析资源
    LOGI("正在解析资源\n");
    $resources = parse_rss($content);
    if (!$resources) {
        LOGE('无法解析 RSS 资源:' . $content);
        die('');
    }
    LOGI(sprintf("共 %d 个资源", count($resources)));
    /// 4. 将资源丢进数据库
    foreach ($resources as $res) {
        $title = $mysqli->real_escape_string($res['title']);
        $guid = $mysqli->real_escape_string($res['guid']);
        $link = $mysqli->real_escape_string($res['link']);
        $description = $mysqli->real_escape_string($res['description']);
        $pubDate = strtotime($res['pubDate']);
        $btih = '';
        $match = array();
        preg_match('([0-9a-f]{40})', $res['link'], $match);