]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
3 # ====================================================
4 # Autor: n.d.p. / 2001-01-29
5 # lm : n.d.p. / 2001-01-29
6 # ====================================================
8 # Speicherung eines Postings
9 # ====================================================
13 package Posting
::Write
;
15 use vars
qw(@ISA @EXPORT);
17 # ====================================================
19 # ====================================================
23 @EXPORT = qw(write_posting);
25 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
27 use Lock
qw(:WRITE release_file);
28 use Posting
::_lib
qw(get_message_node get_message_header create_forum_xml_string save_file);
32 ################################
35 # Neues Posting speichern
36 ################################
38 sub write_posting
($) {
41 my $mid = 'm'.($param -> {lastMessage
} + 1);
43 my $pars = {quoteChars
=> $param -> {quoteChars
},
44 messages
=> $param -> {messages
}};
46 my %error = (threadWrite
=> '1 could not write thread file',
47 forumWrite
=> '2 could not write forum file',
48 threadFile
=> '3 could not load thread file',
49 noParent
=> '4 could not find parent message');
52 unless ($param -> {parentMessage
}) {
53 $tid = 't'.($param -> {lastThread
} + 1);
54 $thread = create_new_thread
({msg
=> $mid,
56 name
=> $param -> {author
},
57 email
=> $param -> {email
},
58 home
=> $param -> {homepage
},
59 image
=> $param -> {image
},
60 category
=> $param -> {category
},
61 subject
=> $param -> {subject
},
62 time => $param -> {time},
63 dtd
=> $param -> {dtd
},
65 body
=> $param -> {body
},
68 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
71 $param -> {parsedThreads
}
72 -> {$param -> {lastThread
} + 1} = [{mid
=> $param -> {lastMessage
} + 1,
73 unid
=> $param -> {uniqueID
},
74 name
=> plain
($param -> {author
}),
75 cat
=> plain
(length($param -> {category
})?
$param->{category
}:''),
76 subject
=> plain
($param -> {subject
}),
77 time => plain
($param -> {time})}];
79 my $forum = create_forum_xml_string
($param -> {parsedThreads
},
80 {dtd
=> $param -> {dtd
},
84 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
85 release_file
($param -> {messagePath
}.$tid.'.xml');
86 return (0, $thread, $mid);}
90 $tid = 't'.($param -> {thread
});
91 my $tfile = $param -> {messagePath
}.$tid.'.xml';
94 unless (write_lock_file
($tfile)) {
95 violent_unlock_file
($tfile);
96 return $error{threadFile
};}
99 $xml = eval {local $SIG{__DIE__
}; new XML
::DOM
::Parser
(KeepCDATA
=> 1) -> parsefile
($tfile);};
102 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
103 return $error{threadFile
};}
105 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
107 unless (defined $mnode) {
108 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
109 return $error{noParent
};}
111 my $pheader = get_message_header
($mnode);
113 my $message = create_message
($xml,
115 ip
=> $param -> {ip
},
116 name
=> $param -> {author
},
117 email
=> $param -> {email
},
118 home
=> $param -> {homepage
},
119 image
=> $param -> {image
},
120 category
=> length($param -> {category
})?
$param -> {category
}:$pheader -> {category
},
121 subject
=> length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
},
122 time => $param -> {time},
125 $mnode -> appendChild
($message);
127 my $mcontent = $xml -> createElement
('MessageContent');
128 $mcontent -> setAttribute
('mid', $mid);
129 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($param -> {body
}), $pars)}));
131 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
132 $content -> appendChild
($mcontent);
134 unless (save_file
($tfile, \
($xml -> toString
))) {
135 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
136 return $error{threadWrite
};}
138 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
143 # ACHTUNG! danach kann der Threadbaum nicht mehr fuer die visuelle
144 # Ausgabe genutzt werden, da die answers nicht angepasst werden
145 # (und somit nicht mehr stimmen...)
148 my $cat = length($param -> {category
})?
$param -> {category
}:$pheader -> {category
};
149 my $subj = length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
};
151 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
152 if ($_ -> {mid
} == $param -> {parentMessage
}) {
153 splice @
{$param -> {parsedThreads
} -> {$param -> {thread
}}},$i,0,
154 {mid
=> $param -> {lastMessage
} + 1,
155 unid
=> $param -> {uniqueID
},
156 name
=> plain
($param -> {author
}),
157 cat
=> plain
(length($cat)?
$cat:''),
158 subject
=> plain
(length($subj)?
$subj:''),
159 level
=> $_ -> {level
} + 1,
160 time => plain
($param -> {time})};
164 my $forum = create_forum_xml_string
($param -> {parsedThreads
},
165 {dtd
=> $param -> {dtd
},
167 lastThread
=> 't'.$param -> {lastThread
}});
169 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};}
171 return (0, $thread, $mid);}
174 # ====================================================
176 # ====================================================
178 sub create_message
($$) {
181 my $message = $xml -> createElement
('Message');
182 $message -> setAttribute
('id', $par -> {msg
});
183 $message -> setAttribute
('ip', $par -> {ip
});
186 my $header = $xml -> createElement
('Header');
188 # alles inside of 'Header'
189 my $author = $xml -> createElement
('Author');
190 my $name = $xml -> createElement
('Name');
191 $name -> addText
($par -> {name
});
192 $author -> appendChild
($name);
194 my $email = $xml -> createElement
('Email');
195 $email -> addText
($par -> {email
});
196 $author -> appendChild
($email);
198 if (length ($par -> {home
})) {
199 my $home = $xml -> createElement
('HomepageUrl');
200 $home -> addText
($par -> {home
});
201 $author -> appendChild
($home);}
203 if (length ($par -> {image
})) {
204 my $image = $xml -> createElement
('ImageUrl');
205 $image -> addText
($par -> {image
});
206 $author -> appendChild
($image);}
208 my $category = $xml -> createElement
('Category');
209 $category -> addText
($par -> {category
});
211 my $subject = $xml -> createElement
('Subject');
212 $subject -> addText
($par -> {subject
});
214 my $date = $xml -> createElement
('Date');
215 $date -> setAttribute
('longSec', $par -> {time});
217 $header -> appendChild
($author);
218 $header -> appendChild
($category);
219 $header -> appendChild
($subject);
220 $header -> appendChild
($date);
221 $message -> appendChild
($header);
226 sub create_new_thread
($) {
230 my $xml = new XML
::DOM
::Document
;
233 my $decl = new XML
::DOM
::XMLDecl
;
234 $decl -> setVersion
('1.0');
235 $decl -> setEncoding
('UTF-8');
236 $xml -> setXMLDecl
($decl);
239 my $dtd = $xml -> createDocumentType
('Forum', $par -> {dtd
}, undef, undef);
240 $xml -> setDoctype
($dtd);
243 my $forum = $xml -> createElement
('Forum');
246 my $thread = $xml -> createElement
('Thread');
247 $thread -> setAttribute
('id', $par -> {thread
});
250 my $message = create_message
($xml,$par);
253 my $content = $xml -> createElement
('ContentList');
254 my $mcontent = $xml -> createElement
('MessageContent');
255 $mcontent -> setAttribute
('mid', $par -> {msg
});
256 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($par -> {body
}), $par -> {pars
} )}));
258 # die ganzen Nodes verknuepfen
259 $thread -> appendChild
($message);
260 $forum -> appendChild
($thread);
262 $content -> appendChild
($mcontent);
263 $forum -> appendChild
($content);
265 $xml -> appendChild
($forum);
267 # und fertiges Dokument zurueckgeben
271 # ====================================================
272 # Modulinitialisierung
273 # ====================================================
275 # making require happy
278 # ====================================================
279 # end of Posting::Write
280 # ====================================================
patrick-canterino.de