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
42
43
44
45
|
<?php
$db= new mysqli();
$db->connect('localhost','root','root','typecho');
$sql=<<<TEXT
select title,text,created,t2.category,t1.tags,slug from typecho_contents c
left join
(select cid,CONCAT('"',group_concat(m.name),'"') tags from typecho_metas m,typecho_relationships r where m.mid=r.mid and m.type='tag' group by cid ) t1
on c.cid=t1.cid
left join
(select cid,CONCAT('"',GROUP_CONCAT(m.name),'"') category from typecho_metas m,typecho_relationships r where m.mid=r.mid and m.type='category' group by cid) t2
on c.cid=t2.cid
TEXT;
$db->query("set character set 'utf8'");//读库
$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);
$_a = str_replace(array('C#'),'CSharp',$r->tags);
$_a = str_replace(array(','),'","',$r->$_a);
$_g = str_replace(array('C#'),'CSharp',$r->category);
$_g = str_replace(array(','),'-',$_g);
$_tmp = <<<TMP
+++
title= "$r->title"
categories= [$_g]
tags= [$_a]
date= "$_c"
+++
$_t
TMP;
$file_name=iconv("utf-8","gb2312",$r->slug);
//替换不合法文件名字符
file_put_contents(str_replace(array(" ","?","\\","/" ,":" ,"|", "*" ),'-',$file_name).".md",$_tmp);
}
}
$res->free();
}
$db->close();
|