Пример #1
0
/**
 * RSSをダウンロードし、パース結果を返す
 */
function p2GetRSS($remotefile, $atom = 0)
{
    global $_conf;
    $refresh = !empty($_GET['refresh']) || !empty($_POST['refresh']);
    $localpath = rss_get_save_path($remotefile);
    if (PEAR::isError($localpath)) {
        P2Util::pushInfoHtml('<p>' . $localpath->getMessage() . '</p>');
        return $localpath;
    }
    // 保存用ディレクトリがなければつくる
    if (!is_dir(dirname($localpath))) {
        FileCtl::mkdirFor($localpath);
    }
    // If-Modified-Sinceつきでダウンロード(ファイルが無いか、古いか、強制リロードのとき)
    if (!file_exists($localpath) || $refresh || filemtime($localpath) < time() - $_conf['expack.rss.check_interval'] * 60) {
        $dl = P2Util::fileDownload($remotefile, $localpath, true, 301);
        if ($dl->isSuccess()) {
            chmod($localpath, $_conf['expack.rss.setting_perm']);
        }
    }
    // キャッシュが更新されなかったか、ダウンロード成功ならRSSをパース
    if (file_exists($localpath) && (!isset($dl) || $dl->isSuccess())) {
        if ($atom) {
            $atom = isset($dl) && $dl->code == 200 ? 2 : 1;
        }
        $rss = p2ParseRSS($localpath, $atom);
        return $rss;
    } else {
        return $dl;
    }
}
Пример #2
0
/**
 * フィードリストを表示する
 *
 * @param string $title
 * @param int    $no
 * @return void
 */
function menu_iphone_show_feed_list($title, $no = null)
{
    global $_conf;
    require_once P2EX_LIB_DIR . '/rss/common.inc.php';
    echo "<ul id=\"rss{$no}\" title=\"{$title}\">";
    $errors = array();
    if ($rss_list = FileCtl::file_read_lines($_conf['expack.rss.setting_path'], FILE_IGNORE_NEW_LINES)) {
        foreach ($rss_list as $rss_info) {
            $p = explode("\t", $rss_info);
            if (count($p) > 1) {
                $site = $p[0];
                $xml = $p[1];
                if (!empty($p[2])) {
                    $atom = 1;
                    $atom_q = '&atom=1';
                } else {
                    $atom = 0;
                    $atom_q = '';
                }
                $localpath = rss_get_save_path($xml);
                if (PEAR::isError($localpath)) {
                    $errors[] = array($site, $localpath->getMessage());
                } else {
                    $mtime = file_exists($localpath) ? filemtime($localpath) : 0;
                    $site_en = UrlSafeBase64::encode($site);
                    $xml_en = rawurlencode($xml);
                    $rss_q = sprintf('?xml=%s&site_en=%s%s&mt=%d', $xml_en, $site_en, $atom_q, $mtime);
                    $rss_q_ht = p2h($rss_q);
                    echo "<li><a href=\"subject_rss.php{$rss_q_ht}\" target=\"_self\">{$site}</a></li>";
                }
            }
        }
    }
    if (count($errors)) {
        echo '<li class="group">エラー</li>';
        foreach ($errors as $error) {
            echo "<li>{$error[0]} - {$error[1]}</li>";
        }
    }
    //echo '<li class="group">&nbsp;</li>';
    echo '<li><a href="editrss.php';
    if ($_conf['expack.misc.multi_favs']) {
        echo '?m_rss_set=' . $no;
    }
    echo '" class="align-r" target="_self">編集</a></li>';
    echo "</ul>\n";
}
Пример #3
0
$items = array();
$num = trim($_REQUEST['num']);
$xml = trim($_REQUEST['xml']);
$atom = empty($_REQUEST['atom']) ? 0 : 1;
$site_en = trim($_REQUEST['site_en']);
$xml_en = rawurlencode($xml);
$xml_ht = htmlspecialchars($xml, ENT_QUOTES, 'Shift_JIS', false);
//============================================================
// RSS読み込み
//============================================================
if ($xml) {
    $rss = p2GetRSS($xml, $atom);
    if ($rss instanceof XML_RSS) {
        clearstatcache();
        $rss_parse_success = true;
        $xml_path = rss_get_save_path($xml);
        $mtime = filemtime($xml_path);
        $channel = $rss->getChannelInfo();
        $items = $rss->getItems();
        $fp = fopen($xml_path, 'rb');
        $xmldec = fgets($fp, 1024);
        fclose($fp);
        if (preg_match('/^<\\?xml version="1.0" encoding="((?i:iso)-8859-(?:[1-9]|1[0-5]))" ?\\?>/', $xmldec, $matches)) {
            $encoding = $matches[1];
        } else {
            $encoding = 'UTF-8,CP51932,CP932,JIS';
        }
        mb_convert_variables('CP932', $encoding, $channel, $items);
    } else {
        $rss_parse_success = false;
    }
Пример #4
0
/**
 * 登録されているRSS一覧を表示(携帯用)
 */
function print_rss_list_k()
{
    global $_conf;
    $pageTitle = $_conf['expack.misc.multi_favs'] ? FavSetManager::getFavSetPageTitleHt('m_rss_set', 'RSS') : 'RSS';
    echo $pageTitle;
    echo '<hr>';
    $i = 1;
    if ($rss_list = FileCtl::file_read_lines($_conf['expack.rss.setting_path'], FILE_IGNORE_NEW_LINES)) {
        foreach ($rss_list as $rss_info) {
            $p = explode("\t", $rss_info);
            if (count($p) > 1) {
                $site = $p[0];
                $xml = $p[1];
                if (!empty($p[2])) {
                    $atom = 1;
                    $atom_q = '&atom=1';
                } else {
                    $atom = 0;
                    $atom_q = '';
                }
                if ($i <= 9) {
                    $accesskey_at = $_conf['k_accesskey_at'][$i];
                    $accesskey_st = "{$i} ";
                } else {
                    $accesskey_at = '';
                    $accesskey_st = '';
                }
                $localpath = rss_get_save_path($xml);
                if (PEAR::isError($localpath)) {
                    echo $accesskey_st . $site . ' ' . $localpath->getMessage() . "<br>\n";
                } else {
                    $mtime = file_exists($localpath) ? filemtime($localpath) : 0;
                    $site_en = UrlSafeBase64::encode($site);
                    $xml_en = rawurlencode($xml);
                    $rss_q = sprintf('?xml=%s&site_en=%s%s&mt=%d', $xml_en, $site_en, $atom_q, $mtime);
                    $rss_q_ht = p2h($rss_q);
                    echo "{$accesskey_st}<a href=\"subject_rss.php{$rss_q_ht}\"{$accesskey_at}>{$site}</a><br>\n";
                }
                $i++;
            }
        }
    }
}