]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
7e6ba975b9d9fe31162be01290f9ffde2157383b
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 ################################################################################
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
};
171 return (0, $thread, $mid);
175 # ====================================================
177 # ====================================================
179 sub create_message
($$) {
182 my $message = $xml -> createElement
('Message');
183 $message -> setAttribute
('id', $par -> {msg
});
184 $message -> setAttribute
('ip', $par -> {ip
});
187 my $header = $xml -> createElement
('Header');
189 # alles inside of 'Header'
190 my $author = $xml -> createElement
('Author');
191 my $name = $xml -> createElement
('Name');
192 $name -> addText
($par -> {name
});
193 $author -> appendChild
($name);
195 my $email = $xml -> createElement
('Email');
196 $email -> addText
($par -> {email
});
197 $author -> appendChild
($email);
199 if (length ($par -> {home
})) {
200 my $home = $xml -> createElement
('HomepageUrl');
201 $home -> addText
($par -> {home
});
202 $author -> appendChild
($home);}
204 if (length ($par -> {image
})) {
205 my $image = $xml -> createElement
('ImageUrl');
206 $image -> addText
($par -> {image
});
207 $author -> appendChild
($image);}
209 my $category = $xml -> createElement
('Category');
210 $category -> addText
($par -> {category
});
212 my $subject = $xml -> createElement
('Subject');
213 $subject -> addText
($par -> {subject
});
215 my $date = $xml -> createElement
('Date');
216 $date -> setAttribute
('longSec', $par -> {time});
218 $header -> appendChild
($author);
219 $header -> appendChild
($category);
220 $header -> appendChild
($subject);
221 $header -> appendChild
($date);
222 $message -> appendChild
($header);
227 sub create_new_thread
($) {
231 my $xml = new XML
::DOM
::Document
;
234 my $decl = new XML
::DOM
::XMLDecl
;
235 $decl -> setVersion
('1.0');
236 $decl -> setEncoding
('UTF-8');
237 $xml -> setXMLDecl
($decl);
240 my $dtd = $xml -> createDocumentType
('Forum', $par -> {dtd
}, undef, undef);
241 $xml -> setDoctype
($dtd);
244 my $forum = $xml -> createElement
('Forum');
247 my $thread = $xml -> createElement
('Thread');
248 $thread -> setAttribute
('id', $par -> {thread
});
251 my $message = create_message
($xml,$par);
254 my $content = $xml -> createElement
('ContentList');
255 my $mcontent = $xml -> createElement
('MessageContent');
256 $mcontent -> setAttribute
('mid', $par -> {msg
});
257 $mcontent -> appendChild
($xml -> createCDATASection
(${encoded_body
(\
($par -> {body
}), $par -> {pars
} )}));
259 # die ganzen Nodes verknuepfen
260 $thread -> appendChild
($message);
261 $forum -> appendChild
($thread);
263 $content -> appendChild
($mcontent);
264 $forum -> appendChild
($content);
266 $xml -> appendChild
($forum);
268 # und fertiges Dokument zurueckgeben
272 # ====================================================
273 # Modulinitialisierung
274 # ====================================================
276 # making require happy
279 # ====================================================
280 # end of Posting::Write
281 # ====================================================
patrick-canterino.de