周四. 4月 25th, 2024

离 Google Reader 逝去两个来月了,此文仅作个纪念

下载 user@gmail.com-takeout 文件并解压后,得到的是 json 文件,用 json_decode() 函数做一下解码 json 的操作

date_default_timezone_set('Asia/Chongqing');
$handle = fopen("GR/starred.json", "rb");
$content = stream_get_contents($handle);
fclose($handle);
$content = json_decode($content);

输出操作

“starred.json” 是你加星标的内容,这里代码同样可以读取“liked.json, notes.json, shared.json” 等,更改要读取文件名即可。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Test Page</title>
		<style type="text/css">
			img {max-width:920px;}
			pre,blockquote {
				background-color:#E2D8FF;
				font-family:Monaco,"Courier New",Courier;
				font-size:13px;
				border:1px dashed #EEF8FF;
				padding:10px 12px 10px 25px;
				margin:12px 0;
				white-space:pre-wrap;	/* css-3 */
				white-space:-moz-pre-wrap;	/* Mozilla,since 1999 */
				white-space:-pre-wrap;	/* Opera 4-6 */
				white-space:-o-pre-wrap;	/* Opera 7 */
				word-wrap:break-word; /* IE 5.5+ */
			}
			#wrapper {width:950px; margin:30px auto;}
		</style>
    </head>
<body>
	<div id="wrapper">
<?php
foreach ($content->items as $item) {
	echo '<div class="header">',"\n";
	echo '<h2><a href="',$item->alternate[0]->href,'" target="_blank">',$item->title,'</a></h2>',"\n";
	echo 'Published: ',date("Y-m-d H:i:s", $item->published),'<br />';
	echo 'Updated: ',date("Y-m-d H:i:s", $item->updated),'<br />';
	echo '</div>',"\n";
	echo '<div class="content">',"\n";	
	echo (isset($item->content->content) ? $item->content->content : '<p>No content here.</p>');
	echo '</div>',"\n";
}
?>
	</div>
</body>
</html>

CSS & PHP Code 要点

  • 定义 img 的 max-width 是由于外链图片可能很大,超出了 #wapper 宽度
  • 定义 pre,blockquote 让代码块和引用更便于浏览,同时让长字符断行。
  • 某些 RSS 订阅在 GR 里面是没有内容的,所以 $item->content->content 要判断是否有内容

作者 Chris

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据