1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <?php
$db = new mysqli();
$db->connect('localhost','username','password','database'); $prefix = 'typecho_'; $sql = <<<TEXT select title,text,created,category,tags from {$prefix}contents c, (select cid,group_concat(m.name) tags from {$prefix}metas m,{$prefix}relationships r where m.mid=r.mid and m.type='tag' group by cid ) t1, (select cid,m.name category from {$prefix}metas m,{$prefix}relationships r where m.mid=r.mid and m.type='category') t2 where t1.cid=t2.cid and c.cid=t1.cid TEXT; $res = $db->query($sql); if ($res) { if ($res->num_rows > 0) { while ($r = $res->fetch_object()) { $_c = @date('Y-m-d H:i:s', $r->created); $_t = str_replace('<!--markdown-->', '', $r->text); $_tmp = <<<TMP title: {$r->title} categories: {$r->category} tags: [{$r->tags}] date: {$_c} --- {$_t} TMP; if (strpos(PHP_OS, "WIN") !== false) { $name = iconv("UTF-8", "GBK//IGNORE", $r->title); echo $name.'<br>'; } else { $name = $r->title; echo $name.'<br>'; } file_put_contents(str_replace(array(" ", "?", "\\", "/", ":", "|", "*"), '-', $name) . ".md", $_tmp); } } $res->free(); } $db->close();
|