]>
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-02-25
6 # ====================================================
8 # Speicherung eines Postings
9 # ====================================================
13 package Posting
::Write
;
16 use base qw(Exporter);
18 # ====================================================
20 # ====================================================
22 @EXPORT = qw(write_posting);
24 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
26 use Lock
qw(:WRITE release_file);
27 use Posting
::_lib
qw(get_message_node get_message_header create_forum_xml_string save_file);
31 ################################
34 # Neues Posting speichern
35 ################################
37 sub write_posting
($) {
40 my $mid = 'm'.($param -> {lastMessage
} + 1);
42 my $pars = {quoteChars
=> $param -> {quoteChars
},
43 messages
=> $param -> {messages
}};
45 my %error = (threadWrite
=> '1 could not write thread file',
46 forumWrite
=> '2 could not write forum file',
47 threadFile
=> '3 could not load thread file',
48 noParent
=> '4 could not find parent message');
51 unless ($param -> {parentMessage
}) {
52 $tid = 't'.($param -> {lastThread
} + 1);
53 $thread = create_new_thread
({msg
=> $mid,
55 name
=> $param -> {author
},
56 email
=> $param -> {email
},
57 home
=> $param -> {homepage
},
58 image
=> $param -> {image
},
59 category
=> $param -> {category
},
60 subject
=> $param -> {subject
},
61 time => $param -> {time},
62 dtd
=> $param -> {dtd
},
64 body
=> $param -> {body
},
67 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
70 $param -> {parsedThreads
}
71 -> {$param -> {lastThread
} + 1} = [{mid
=> $param -> {lastMessage
} + 1,
72 unid
=> $param -> {uniqueID
},
73 name
=> plain
($param -> {author
}),
74 cat
=> plain
(length($param -> {category
})?
$param->{category
}:''),
75 subject
=> plain
($param -> {subject
}),
76 time => plain
($param -> {time})}];
78 my $forum = create_forum_xml_string
($param -> {parsedThreads
},
79 {dtd
=> $param -> {dtd
},
83 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
84 release_file
($param -> {messagePath
}.$tid.'.xml');
85 return (0, $thread, $mid);}
89 $tid = 't'.($param -> {thread
});
90 my $tfile = $param -> {messagePath
}.$tid.'.xml';
93 unless (write_lock_file
($tfile)) {
94 violent_unlock_file
($tfile);
95 return $error{threadFile
};}
98 $xml = eval {local $SIG{__DIE__
}; new XML
::DOM
::Parser
(KeepCDATA
=> 1) -> parsefile
($tfile);};
101 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
102 return $error{threadFile
};}
104 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
106 unless (defined $mnode) {
107 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
108 return $error{noParent
};}
110 my $pheader = get_message_header
($mnode);
112 my $message = create_message
($xml,
114 ip
=> $param -> {ip
},
115 name
=> $param -> {author
},
116 email
=> $param -> {email
},
117 home
=> $param -> {homepage
},
118 image
=> $param -> {image
},
119 category
=> length($param -> {category
})?
$param -> {category
}:$pheader -> {category
},
120 subject
=> length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
},
121 time => $param -> {time},
124 $mnode -> appendChild
($message);
126 my $mcontent = $xml -> createElement
('MessageContent');
127 $mcontent -> setAttribute
('mid', $mid);
128 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($param -> {body
}), $pars)}));
130 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
131 $content -> appendChild
($mcontent);
133 unless (save_file
($tfile, \
($xml -> toString
))) {
134 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
135 return $error{threadWrite
};}
137 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
142 # ACHTUNG! danach kann der Threadbaum nicht mehr fuer die visuelle
143 # Ausgabe genutzt werden, da die answers nicht angepasst werden
144 # (und somit nicht mehr stimmen...)
147 my $cat = length($param -> {category
})?
$param -> {category
}:$pheader -> {category
};
148 my $subj = length($param -> {subject
})?
$param -> {subject
}:$pheader -> {subject
};
150 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
151 if ($_ -> {mid
} == $param -> {parentMessage
}) {
152 splice @
{$param -> {parsedThreads
} -> {$param -> {thread
}}},$i,0,
153 {mid
=> $param -> {lastMessage
} + 1,
154 unid
=> $param -> {uniqueID
},
155 name
=> plain
($param -> {author
}),
156 cat
=> plain
(length($cat)?
$cat:''),
157 subject
=> plain
(length($subj)?
$subj:''),
158 level
=> $_ -> {level
} + 1,
159 time => plain
($param -> {time})};
163 my $forum = create_forum_xml_string
($param -> {parsedThreads
},
164 {dtd
=> $param -> {dtd
},
166 lastThread
=> 't'.$param -> {lastThread
}});
168 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};}
170 return (0, $thread, $mid);}
173 # ====================================================
175 # ====================================================
177 sub create_message
($$) {
180 my $message = $xml -> createElement
('Message');
181 $message -> setAttribute
('id', $par -> {msg
});
182 $message -> setAttribute
('ip', $par -> {ip
});
185 my $header = $xml -> createElement
('Header');
187 # alles inside of 'Header'
188 my $author = $xml -> createElement
('Author');
189 my $name = $xml -> createElement
('Name');
190 $name -> addText
($par -> {name
});
191 $author -> appendChild
($name);
193 my $email = $xml -> createElement
('Email');
194 $email -> addText
($par -> {email
});
195 $author -> appendChild
($email);
197 if (length ($par -> {home
})) {
198 my $home = $xml -> createElement
('HomepageUrl');
199 $home -> addText
($par -> {home
});
200 $author -> appendChild
($home);}
202 if (length ($par -> {image
})) {
203 my $image = $xml -> createElement
('ImageUrl');
204 $image -> addText
($par -> {image
});
205 $author -> appendChild
($image);}
207 my $category = $xml -> createElement
('Category');
208 $category -> addText
($par -> {category
});
210 my $subject = $xml -> createElement
('Subject');
211 $subject -> addText
($par -> {subject
});
213 my $date = $xml -> createElement
('Date');
214 $date -> setAttribute
('longSec', $par -> {time});
216 $header -> appendChild
($author);
217 $header -> appendChild
($category);
218 $header -> appendChild
($subject);
219 $header -> appendChild
($date);
220 $message -> appendChild
($header);
225 sub create_new_thread
($) {
229 my $xml = new XML
::DOM
::Document
;
232 my $decl = new XML
::DOM
::XMLDecl
;
233 $decl -> setVersion
('1.0');
234 $decl -> setEncoding
('UTF-8');
235 $xml -> setXMLDecl
($decl);
238 my $dtd = $xml -> createDocumentType
('Forum', $par -> {dtd
}, undef, undef);
239 $xml -> setDoctype
($dtd);
242 my $forum = $xml -> createElement
('Forum');
245 my $thread = $xml -> createElement
('Thread');
246 $thread -> setAttribute
('id', $par -> {thread
});
249 my $message = create_message
($xml,$par);
252 my $content = $xml -> createElement
('ContentList');
253 my $mcontent = $xml -> createElement
('MessageContent');
254 $mcontent -> setAttribute
('mid', $par -> {msg
});
255 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($par -> {body
}), $par -> {pars
} )}));
257 # die ganzen Nodes verknuepfen
258 $thread -> appendChild
($message);
259 $forum -> appendChild
($thread);
261 $content -> appendChild
($mcontent);
262 $forum -> appendChild
($content);
264 $xml -> appendChild
($forum);
266 # und fertiges Dokument zurueckgeben
270 # ====================================================
271 # Modulinitialisierung
272 # ====================================================
274 # making require happy
277 # ====================================================
278 # end of Posting::Write
279 # ====================================================
patrick-canterino.de