]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
1 package Posting
::Write
;
3 ################################################################################
5 # File: shared/Posting/Write.pm #
7 # Authors: André Malo <nd@o3media.de>, 2001-02-25 #
9 # Description: Save a posting #
11 ################################################################################
15 use base
qw(Exporter);
17 # ====================================================
19 # ====================================================
21 @Posting::Write
::EXPORT
= qw(write_posting);
23 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
25 use Lock
qw(:WRITE release_file);
26 use Posting
::_lib
qw(get_message_node get_message_header create_forum_xml_string save_file);
30 ################################
33 # Neues Posting speichern
34 ################################
36 sub write_posting
($) {
39 my $mid = 'm'.($param -> {lastMessage
} + 1);
42 quoteChars
=> $param -> {quoteChars
},
43 messages
=> $param -> {messages
}
47 threadWrite
=> '1 could not write thread file',
48 forumWrite
=> '2 could not write forum file',
49 threadFile
=> '3 could not load thread file',
50 noParent
=> '4 could not find parent message'
54 unless ($param -> {parentMessage
}) {
55 $tid = 't'.($param -> {lastThread
} + 1);
56 $thread = create_new_thread
(
59 name
=> $param -> {author
},
60 email
=> $param -> {email
},
61 home
=> $param -> {homepage
},
62 image
=> $param -> {image
},
63 category
=> $param -> {category
},
64 subject
=> $param -> {subject
},
65 time => $param -> {time},
66 dtd
=> $param -> {dtd
},
68 body
=> $param -> {body
},
73 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
78 -> {$param -> {lastThread
} + 1} = [
79 { mid
=> $param -> {lastMessage
} + 1,
80 unid
=> $param -> {uniqueID
},
81 name
=> plain
($param -> {author
}),
82 cat
=> plain
(length($param -> {category
})?
$param->{category
}:''),
83 subject
=> plain
($param -> {subject
}),
84 time => plain
($param -> {time})
88 my $forum = create_forum_xml_string
(
89 $param -> {parsedThreads
},
90 { dtd
=> $param -> {dtd
},
96 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
97 release_file
($param -> {messagePath
}.$tid.'.xml');
98 return (0, $thread, $mid);}
102 $tid = 't'.($param -> {thread
});
103 my $tfile = $param -> {messagePath
}.$tid.'.xml';
106 unless (write_lock_file
($tfile)) {
107 violent_unlock_file
($tfile);
108 return $error{threadFile
};
114 new XML
::DOM
::Parser
(KeepCDATA
=> 1) -> parsefile
($tfile);
118 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
119 return $error{threadFile
};
122 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
124 unless (defined $mnode) {
125 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
126 return $error{noParent
};
129 my $pheader = get_message_header
($mnode);
131 my $message = create_message
(
134 ip
=> $param -> {ip
},
135 name
=> $param -> {author
},
136 email
=> $param -> {email
},
137 home
=> $param -> {homepage
},
138 image
=> $param -> {image
},
139 category
=> length($param -> {category
})?
$param -> {category
}:$pheader -> {category
},
140 subject
=> length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
},
141 time => $param -> {time},
146 $mnode -> appendChild
($message);
148 my $mcontent = $xml -> createElement
('MessageContent');
149 $mcontent -> setAttribute
('mid', $mid);
150 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($param -> {body
}), $pars)}));
152 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
153 $content -> appendChild
($mcontent);
155 unless (save_file
($tfile, \
($xml -> toString
))) {
156 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
157 return $error{threadWrite
};
160 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
165 # ACHTUNG! danach kann der Threadbaum nicht mehr fuer die visuelle
166 # Ausgabe genutzt werden, da die answers nicht angepasst werden
167 # (und somit nicht mehr stimmen...)
170 my $cat = length($param -> {category
})?
$param -> {category
}:$pheader -> {category
};
171 my $subj = length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
};
173 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
174 if ($_ -> {mid
} == $param -> {parentMessage
}) {
175 splice @
{$param -> {parsedThreads
} -> {$param -> {thread
}}}, $i, 0,
176 { mid
=> $param -> {lastMessage
} + 1,
177 unid
=> $param -> {uniqueID
},
178 name
=> plain
($param -> {author
}),
179 cat
=> plain
(length($cat)?
$cat:''),
180 subject
=> plain
(length($subj)?
$subj:''),
181 level
=> $_ -> {level
} + 1,
182 time => plain
($param -> {time})
187 my $forum = create_forum_xml_string
(
188 $param -> {parsedThreads
},
189 { dtd
=> $param -> {dtd
},
191 lastThread
=> 't'.$param -> {lastThread
}
195 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
198 return (0, $thread, $mid);
202 # ====================================================
204 # ====================================================
206 sub create_message
($$) {
209 my $message = $xml -> createElement
('Message');
210 $message -> setAttribute
('id', $par -> {msg
});
211 $message -> setAttribute
('ip', $par -> {ip
});
214 my $header = $xml -> createElement
('Header');
216 # alles inside of 'Header'
217 my $author = $xml -> createElement
('Author');
218 my $name = $xml -> createElement
('Name');
219 $name -> addText
($par -> {name
});
220 $author -> appendChild
($name);
222 my $email = $xml -> createElement
('Email');
223 $email -> addText
($par -> {email
});
224 $author -> appendChild
($email);
226 if (length ($par -> {home
})) {
227 my $home = $xml -> createElement
('HomepageUrl');
228 $home -> addText
($par -> {home
});
229 $author -> appendChild
($home);}
231 if (length ($par -> {image
})) {
232 my $image = $xml -> createElement
('ImageUrl');
233 $image -> addText
($par -> {image
});
234 $author -> appendChild
($image);}
236 my $category = $xml -> createElement
('Category');
237 $category -> addText
($par -> {category
});
239 my $subject = $xml -> createElement
('Subject');
240 $subject -> addText
($par -> {subject
});
242 my $date = $xml -> createElement
('Date');
243 $date -> setAttribute
('longSec', $par -> {time});
245 $header -> appendChild
($author);
246 $header -> appendChild
($category);
247 $header -> appendChild
($subject);
248 $header -> appendChild
($date);
249 $message -> appendChild
($header);
254 sub create_new_thread
($) {
258 my $xml = new XML
::DOM
::Document
;
261 my $decl = new XML
::DOM
::XMLDecl
;
262 $decl -> setVersion
('1.0');
263 $decl -> setEncoding
('UTF-8');
264 $xml -> setXMLDecl
($decl);
267 my $dtd = $xml -> createDocumentType
('Forum', $par -> {dtd
}, undef, undef);
268 $xml -> setDoctype
($dtd);
271 my $forum = $xml -> createElement
('Forum');
274 my $thread = $xml -> createElement
('Thread');
275 $thread -> setAttribute
('id', $par -> {thread
});
278 my $message = create_message
($xml,$par);
281 my $content = $xml -> createElement
('ContentList');
282 my $mcontent = $xml -> createElement
('MessageContent');
283 $mcontent -> setAttribute
('mid', $par -> {msg
});
284 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($par -> {body
}), $par -> {pars
} )}));
286 # die ganzen Nodes verknuepfen
287 $thread -> appendChild
($message);
288 $forum -> appendChild
($thread);
290 $content -> appendChild
($mcontent);
291 $forum -> appendChild
($content);
293 $xml -> appendChild
($forum);
295 # und fertiges Dokument zurueckgeben
299 # ====================================================
300 # Modulinitialisierung
301 # ====================================================
303 # making require happy
306 # ====================================================
307 # end of Posting::Write
308 # ====================================================
patrick-canterino.de