<?php
	require("../__common__/__define_mobile.php");
	require("__define.php");
	require("magpierss/rss_fetch.inc");
	$login_id = mobile_login_check();
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<?php
	mobile_common_head('myHome RSS');
?>
<style>
ul.rss_item {
	margin: 0 0 0 18px;
	padding: 0;
	line-height: 2.4ex;
	list-style: none;
}
ul.rss_item li {
	margin: 1px 0 1px 0;
}
span.rss_time {
	font-size: 90%;
}
span.rss_description {
	font-size: 80%;
}
</style>
</head>
<body>
<div data-role="page" data-url="<?= $_SERVER['REQUEST_URI'] ?>" id="top">
	<div data-role="header">
		<a href="list.php?cat=<?= $_GET['cat'] ?>&id=<?= $_GET['id'] ?>" data-icon="back" rel="external">RSS一覧</a>
		<h1>RSS</h1>
		<a href="../index" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
	</div>
	<div data-role="content">
	<?php
		rss($login_id, $login_id);
	?>
	</div>
	<div data-role="footer">
		<h1>ok.2nd</h1>
	</div>
</div>
</body>
</html>
<?php
function rss($login_id, $user_id) {
	$con = my_mysql_connect(_DB_SCHEMA);
	$sql = "select * from m_rss where c_delete = 0 and id_account = '" . $login_id . "'";
	$sql .= " and id_rss = " . intval($_GET['id']);
	if ($login_id != $user_id) {
		$sql .= " and c_privacy = 0";
	}
	$rs = my_mysql_query($sql);
	if ($rec = mysql_fetch_array($rs)) {
		rss_view($rec);
	}
}
function rss_view($rec, $cntmax=100) {
	if ($rec['c_rss_url'].'' == '') return;
?>
	<h2><a href="<?= $rec['c_home_url'] ?>" target="_blank"><?= $rec['c_title'] ?></a></h2>
<?php
	if (!($rss = fetch_rss($rec['c_rss_url']))) {
?>
		<span class='error_msg'>RSS取得エラー</span>
<?php
		return;
	}
?>
	<ul class="rss_item">
	<?php
		$cnt = 0;
		foreach ($rss->items as $item) {
			if ($item['link'] <> '') {
	?>
			<li><a href="<?= $item['link'] ?>" target="_blank"><?= $item['title'] ?></a>
			<span class="rss_time">(<?= rss_pubdate($item) ?>)</span><br>
				<?php // if ($item['description'].'' <> '') { ?>
				<!--	<span class="rss_description">(<?= $item['description'] ?>)</span>	-->
				<?php // } ?>
			</li>
	<?php
				if (++$cnt >= $cntmax) break;
			}
		}
	?>
	</ul>
<?php
}
?>
<?php
function rss_pubdate($item) {
	if ($item['published'].'' <> '') {		// Atom 1.0
		return date("y/m/d H:i:s", strtotime((string)$item['published']));
	} elseif ($item['pubdate'].'' <> '') {		// RSS 2.0
		return date("y/m/d H:i:s", strtotime((string)$item['pubdate']));
	} elseif ($item['dc']['date'].'' <> '') {	// RSS 1.0
		return date("y/m/d H:i:s", strtotime(str_replace('T',' ',(string)$item['dc']['date'])));
	} elseif ($item['issued'].'' <> '') {		// ?????
		return date("y/m/d H:i:s", strtotime((string)$item['issued']));
	} else {
		return '';
	}
}
?>
