-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb_rss.dao
140 lines (129 loc) · 4.47 KB
/
web_rss.dao
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
load web_text
routine MakeRSS( space : User, tid = 0, label = '' )
{
rssname = %label ? 'rss_' + label : 'rss';
format = "%W,%D-%M-%Y %H:%I:%S GMT";
temps = io.read( '::templates/rss.xml' ).split( '<!--splitter-->' );
header = temps[0];
channel = temps[1];
item = temps[2];
channels = { '', '', '' };
user = User.{};
txt = Text.{};
lab = Label.{};
sptext = SpaceText.{};
labeling = TextLabeling.{};
time = time_now - month_in_seconds;
hd : any = none;
if( %label )
hd = web_database.Select( SpaceText, 1, Text, Label, 1, TextLabeling );
else
hd = web_database.Select( SpaceText, 1, Text );
hd.Where().EQ( Text, 'uid_space', space.uid ).GT( Text, 'time_create', time )
.Match( SpaceText, Text, 'tid' ).EQ( SpaceText, 'stid_reply', 0 )
.EQ( SpaceText, 'blog', 1 )
if( %label ){
hd.Match( Text, TextLabeling, 'tid' ).Match( TextLabeling, Label, 'lid' );
hd.EQ( Label, 'name', label );
}
hd.Sort( Text, 'time_create', 1 );
link = 'http://' + HTTP_ENV[ 'HTTP_HOST' ] + '/space/' + space.username;
count = 0;
while(1){
if( %label ){
if( hd.QueryOnce( sptext, txt, lab, labeling ) == 0 ) break;
}else{
if( hd.QueryOnce( sptext, txt ) ==0 ) break;
}
count += 1;
link2 = link + '/thread/' + (string)txt.tid;
kv = { 'title' => txt.title, 'link' => link2, 'guid' => link2 };
desc = CompleteText( txt.stid, txt.content, space.username, 0 );
desc.change( '&', '&' );
desc.change( '%<', '<' );
desc.change( '%>', '>' );
desc.change( '"', '"' );
kv[ 'description' ] = desc;
kv[ 'pubDate' ] = GMTime( txt.time_create );
it = item.expand( kv, '@' );
if( txt.language == 'english' ){
channels[0] += it;
}else if( txt.language == 'chinese' ){
channels[1] += it;
}else{
channels[2] += it;
}
}
body = '';
link += '&' + rssname;
pubdate = GMTime( time_now - 2*month_in_seconds );
gmtime = GMTime( sys::time() );
kv = { 'pubDate' => (string)pubdate, 'lastBuildDate' => (string)gmtime, 'link' => (string)link };
if( label == 'chinese' ){
kv[ 'language' ] = 'zh-cn';
}else{
kv[ 'language' ] = 'en-us';
}
kv[ 'title' ] = 'Dao Language';
kv[ 'description' ] = 'Dao Language';
kv[ 'link' ] = link + '&lang=en_uk';
body += channel.expand( kv, '@' );
if( %channels[0] ) body += channels[0];
kv[ 'title' ] = '道语言';
kv[ 'description' ] = '道语言';
kv[ 'link' ] = link + '&lang=zh_cn';
if( %channels[1] ) body += channels[1];
if( %channels[2] ) body += channels[2];
body += '\n</channel>';
rss = header + body + '</rss>';
if( tid ){
web_database.Update( Text ).Set( 'time_edit', time_now ).Set('source').Set( 'content' )
.Where().EQ( 'tid', tid ).Bind( rss ).Bind( rss, 1 ).QueryOnce();
}else if( count ){
date = ctime_now.year * 10000 + ctime_now.month * 100 + ctime_now.day;
spacetext = SpaceText.{ blog = 0, forum = 0, uid_space = space.uid,
uid_author = space.uid, date_create = date, time_create = time_now,
name = rssname, stid_reply = 0 };
web_database.Insert( spacetext );
atext = Text.{ stid = spacetext.stid, uid_space = space.uid, uid_author = space.uid,
time_create = time_now, preface = 0, name = rssname,
title = 'RSS', brief = '', source = '', content = rss };
web_database.Insert( atext );
web_database.Update( SpaceText ).Set( 'stid_first', spacetext.stid )
.Set( 'tid', atext.tid ).Where().EQ( 'stid', spacetext.stid ).QueryOnce();
tid = atext.tid;
}
#{
debug = io.open( '/winux/projects/Cybego/debug.txt', 'w' );
debug.println( header + body + '\n</rss>' );
debug.close();
#}
return rss, tid;
}
routine GetRSS( space : User, label = '' )
{
rssname = %label ? 'rss_' + label : 'rss';
rss_time = 0;
blog_time = 0;
hd = web_database.Select( Text ).Where().EQ( 'uid_space', space.uid ).EQ( 'name' );
txt = Text.{};
sptxt = SpaceText.{};
if( hd.Bind( rssname ).QueryOnce( txt ) ){
rss_time = txt.time_edit ? txt.time_edit : txt.time_create;
}
rss = txt.content;
hd = web_database.Select( SpaceText ).Where().EQ( 'stid_reply', 0 ).EQ( 'blog', 1 )
.Sort( 'time_create', 1 ).Range( 1 );
if( hd.QueryOnce( sptxt ) ) blog_time = sptxt.time_edit ? sptxt.time_edit : sptxt.time_create;
if( txt.tid ==0 || rss == '' || (blog_time >= rss_time && blog_time + 600 < time_now) ){
( rss, tid ) = MakeRSS( space, txt.tid, label );
if( tid ) TextHit::Update( tid );
}else{
TextHit::Update( txt.tid );
}
return rss;
}
io.writeln( 'content-type: text/plain\n\n' );
label = '';
if( HTTP_GET.find( 'label' ) != none ) label = HTTP_GET[ 'label' ];
io.writeln( GetRSS( space_owner, label ) );