-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb_commit.dao
162 lines (153 loc) · 5.83 KB
/
web_commit.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
load web_user
load web_text
load sdml_html;
routine AddLabeling( space : int, stid : int, labels :list<string> ={}, blog=0, post=0 )
{
stext = SpaceText.{};
label = Label.{};
web_database.Select( SpaceText ).Where().EQ( 'uid_space', space )
.EQ( 'stid', stid ).QueryOnce( stext );
hd1 = web_database.Select( Label ).Where().EQ( 'uid', space ).EQ( 'name' );
hd2 = web_database.Select( TextLabeling ).Where().EQ( 'tid', stext.tid ).EQ( 'lid' );
hd3 = web_database.Update( Label ).Add( 'blog_count', blog )
.Add( 'post_count', blog ).Where().EQ( 'uid', space ).EQ( 'lid' );
labeling = TextLabeling.{ tid = stext.tid };
for( lab in labels ){
if( hd1.Bind( lab ).QueryOnce( label ) ){
if( hd2.Bind( label.lid ).QueryOnce( labeling ) ==0 ){
labeling.lid = label.lid;
web_database.Insert( labeling );
hd3.Bind( label.lid ).QueryOnce();
}
}
if( lab == 'chinse' || lab == 'english' ){
web_database.Update( Text ).Set( 'language', lab ).Where()
.EQ( 'uid_space', space ).EQ( 'stid', stid ).QueryOnce();
}
}
}
routine RemoveLabeling( space : int, stid : int, labels :list<string>={}, blog=0, post=0 )
{
stext = SpaceText.{};
label = Label.{};
web_database.Select( SpaceText ).Where().EQ( 'uid_space', space )
.EQ( 'stid', stid ).QueryOnce( stext );
hd1 = web_database.Select( Label ).Where().EQ( 'uid', space ).EQ( 'name' );
hd2 = web_database.Select( TextLabeling ).Where().EQ( 'tid', stext.tid ).EQ( 'lid' );
hd3 = web_database.Update( Label ).Add( 'blog_count', - blog )
.Add( 'post_count', - blog ).Where().EQ( 'uid', space ).EQ( 'lid' );
labeling = TextLabeling.{ tid = stext.tid };
for( lab in labels ){
if( hd1.Bind( lab ).QueryOnce( label ) ){
if( hd2.Bind( label.lid ).QueryOnce( labeling ) ){
hd3.Bind( label.lid ).QueryOnce();
web_database.Delete( TextLabeling ).Where().EQ( 'tid', stext.tid ).EQ( 'lid', label.lid ).QueryOnce();
}
}
}
}
#===========
# Text
#===========
#{
Commit source:
if( tid=0 )
add as new text item;
}else{
add as revised text;
}
#}
static routine Text::Commit( title : string, source : string, section='', log='', name='',
labels='', stid=0, blog=0, forum=0, space=0, author=0, reply=0 )
{
if( author <=1 ) std::error( Exception::Error( 'not logged in' ) );
parser = Sdml2Html();
time = sys::time();
var content = parser.Parse( source );
var brief = parser.brief;
spacetext = SpaceText.{};
tokens = labels.split( ";" );
labeling :list<string> = {};
nolabeling :list<string> = {};
langlab = 0;
for( tok in tokens ){
tks = tok.split( ":" );
if( tks.size() >=2 ){
if( tks[1] == 'true' ){
labeling.append( tks[0] );
langlab |= web_languages.find( tks[0] ) != none
}else{
nolabeling.append( tks[0] );
}
}
}
if( langlab == 0 ) labeling.append( language2 )
#{
The 'blog' and 'forum' tag should not be mutatable,
otherwise, if these tags are set in a time different from
the time for creation, it will need more fields to display
the text in proper time order, which will add much complexity.
The 'name' field should not be mutatable as well.
In case they should be mutated, create new thread!
#}
hd = web_database.Select( SpaceText ).Where().EQ( 'uid_space', space )
.EQ( 'stid', stid ).EQ( 'name' ).EQ( 'blog', blog ).EQ( 'forum', forum ).Bind( name );
if( hd.QueryOnce( spacetext ) ){ # modifying a text
txt = Text.{};
web_database.Select( Text ).Where().EQ( 'tid', spacetext.tid ).QueryOnce( txt );
if( %section ){
parser2 = Sdml2Html();
parser2.sectindex = section;
parser2.Parse( txt.source );
source2 = txt.source;
source2.replace( parser2.section, source );
source = source2;
content = parser.Parse( source );
brief = parser.brief;
}
web_database.Update( SpaceText ) .Set( 'time_edit', time )
.Where().EQ( 'stid', stid ).QueryOnce();
hd = web_database.Update( Text ).Set( 'time_edit', time ).Set( 'title' )
.Set( 'preface', parser.preface.size() )
.Set( 'brief' ).Set( 'source' ).Set( 'content' )
.Where().EQ( 'tid', spacetext.tid );
hd.Bind( title,0 ).Bind( brief,1 ).Bind( source,2 ).Bind( content,3 );
hd.QueryOnce();
AddLabeling( space, spacetext.stid, labeling, spacetext.blog, spacetext.forum );
RemoveLabeling( space, spacetext.stid, nolabeling, spacetext.blog, spacetext.forum );
#XXX revision
}else{ # adding a new text
ctime = sys::ctime( time );
date = ctime.year * 10000 + ctime.month * 100 + ctime.day;
spacetext = SpaceText.{ blog = blog, forum = forum, uid_space = space,
uid_author = author, date_create = date, time_create = time, time_order = time,
name = name, stid_reply = reply };
web_database.Insert( spacetext );
atext = Text.{ stid = spacetext.stid, uid_space = space, uid_author = author,
time_create = time, preface = parser.preface.size(), name = name,
title = title, brief = brief, source = source, content = content };
web_database.Insert( atext );
web_database.Update( SpaceText ).Set( 'stid_first', spacetext.stid )
.Set( 'tid', atext.tid ).Where()
.EQ( 'stid', spacetext.stid ).QueryOnce();
stid = spacetext.stid;
if( reply ){
web_database.Update( SpaceText ).Set( 'uid_commenter', author )
.Set( 'stid_last', spacetext.stid ).Set( 'time_comment', time )
.Where().EQ( 'stid', reply ).QueryOnce();
web_database.Select( SpaceText ).Where().EQ( 'stid', reply )
.QueryOnce( spacetext );
web_database.Update( SpaceText ).Set( 'stid_first', spacetext.stid_first )
.Where().EQ( 'stid', stid ).QueryOnce();
web_database.Update( SpaceText ).Set( 'stid_last', stid )
.Set( 'uid_commenter', author ).Set( 'time_comment', time )
.Set( 'time_order', time ).Add( 'count_reply', 1 )
.Where().EQ( 'stid', spacetext.stid_first ).QueryOnce();
stid = spacetext.stid_first;
}else{
AddLabeling( space, spacetext.stid, labeling, spacetext.blog, spacetext.forum );
TextStat::Update( space, time, blog, forum );
}
}
return stid, content;
}