]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
eed1534639be7e774367cc49cb4218998ba64995
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
(defined $param -> {category
}?
$param->{category
}:''),
83 subject
=> plain
($param -> {subject
}),
84 time => plain
($param -> {time}),
89 my $forum = create_forum_xml_string
(
90 $param -> {parsedThreads
},
91 { dtd
=> $param -> {dtd
},
97 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
98 release_file
($param -> {messagePath
}.$tid.'.xml');
99 return (0, $thread, $mid);}
103 $tid = 't'.($param -> {thread
});
104 my $tfile = $param -> {messagePath
}.$tid.'.xml';
107 unless (write_lock_file
($tfile)) {
108 violent_unlock_file
($tfile);
109 return $error{threadFile
};
115 new XML
::DOM
::Parser
(KeepCDATA
=> 1) -> parsefile
($tfile);
119 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
120 return $error{threadFile
};
123 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
125 unless (defined $mnode) {
126 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
127 return $error{noParent
};
130 my $pheader = get_message_header
($mnode);
132 my $message = create_message
(
135 ip
=> $param -> {ip
},
136 name
=> $param -> {author
},
137 email
=> $param -> {email
},
138 home
=> $param -> {homepage
},
139 image
=> $param -> {image
},
140 category
=> length($param -> {category
})?
$param -> {category
}:$pheader -> {category
},
141 subject
=> length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
},
142 time => $param -> {time},
147 $mnode -> appendChild
($message);
149 my $mcontent = $xml -> createElement
('MessageContent');
150 $mcontent -> setAttribute
('mid', $mid);
151 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($param -> {body
}), $pars)}));
153 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
154 $content -> appendChild
($mcontent);
156 unless (save_file
($tfile, \
($xml -> toString
))) {
157 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
158 return $error{threadWrite
};
161 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
166 # ACHTUNG! danach kann der Threadbaum nicht mehr fuer die visuelle
167 # Ausgabe genutzt werden, da die answers nicht angepasst werden
168 # (und somit nicht mehr stimmen...)
171 my $cat = length($param -> {category
})?
$param -> {category
}:$pheader -> {category
};
172 my $subj = length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
};
174 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
175 if ($_ -> {mid
} == $param -> {parentMessage
}) {
176 splice @
{$param -> {parsedThreads
} -> {$param -> {thread
}}}, $i, 0,
177 { mid
=> $param -> {lastMessage
} + 1,
178 unid
=> $param -> {uniqueID
},
179 name
=> plain
($param -> {author
}),
180 cat
=> plain
(length($cat)?
$cat:''),
181 subject
=> plain
(length($subj)?
$subj:''),
182 level
=> $_ -> {level
} + 1,
183 time => plain
($param -> {time})
188 my $forum = create_forum_xml_string
(
189 $param -> {parsedThreads
},
190 { dtd
=> $param -> {dtd
},
192 lastThread
=> 't'.$param -> {lastThread
}
196 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
199 return (0, $thread, $mid);
203 # ====================================================
205 # ====================================================
207 sub create_message
($$) {
210 my $message = $xml -> createElement
('Message');
211 $message -> setAttribute
('id', $par -> {msg
});
212 $message -> setAttribute
('ip', $par -> {ip
});
215 my $header = $xml -> createElement
('Header');
217 # alles inside of 'Header'
218 my $author = $xml -> createElement
('Author');
219 my $name = $xml -> createElement
('Name');
220 $name -> addText
($par -> {name
});
221 $author -> appendChild
($name);
223 my $email = $xml -> createElement
('Email');
224 $email -> addText
($par -> {email
});
225 $author -> appendChild
($email);
227 if (length ($par -> {home
})) {
228 my $home = $xml -> createElement
('HomepageUrl');
229 $home -> addText
($par -> {home
});
230 $author -> appendChild
($home);}
232 if (length ($par -> {image
})) {
233 my $image = $xml -> createElement
('ImageUrl');
234 $image -> addText
($par -> {image
});
235 $author -> appendChild
($image);}
237 my $category = $xml -> createElement
('Category');
238 $category -> addText
($par -> {category
});
240 my $subject = $xml -> createElement
('Subject');
241 $subject -> addText
($par -> {subject
});
243 my $date = $xml -> createElement
('Date');
244 $date -> setAttribute
('longSec', $par -> {time});
246 $header -> appendChild
($author);
247 $header -> appendChild
($category);
248 $header -> appendChild
($subject);
249 $header -> appendChild
($date);
250 $message -> appendChild
($header);
255 sub create_new_thread
($) {
259 my $xml = new XML
::DOM
::Document
;
262 my $decl = new XML
::DOM
::XMLDecl
;
263 $decl -> setVersion
('1.0');
264 $decl -> setEncoding
('UTF-8');
265 $xml -> setXMLDecl
($decl);
268 my $dtd = $xml -> createDocumentType
('Forum', $par -> {dtd
}, undef, undef);
269 $xml -> setDoctype
($dtd);
272 my $forum = $xml -> createElement
('Forum');
275 my $thread = $xml -> createElement
('Thread');
276 $thread -> setAttribute
('id', $par -> {thread
});
279 my $message = create_message
($xml,$par);
282 my $content = $xml -> createElement
('ContentList');
283 my $mcontent = $xml -> createElement
('MessageContent');
284 $mcontent -> setAttribute
('mid', $par -> {msg
});
285 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($par -> {body
}), $par -> {pars
} )}));
287 # die ganzen Nodes verknuepfen
288 $thread -> appendChild
($message);
289 $forum -> appendChild
($thread);
291 $content -> appendChild
($mcontent);
292 $forum -> appendChild
($content);
294 $xml -> appendChild
($forum);
296 # und fertiges Dokument zurueckgeben
300 # ====================================================
301 # Modulinitialisierung
302 # ====================================================
304 # making require happy
307 # ====================================================
308 # end of Posting::Write
309 # ====================================================
patrick-canterino.de