]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
b7d78935aa677cc2edf60a8abcef039647c616e6
1 package Posting
::Write
;
3 ################################################################################
5 # File: shared/Posting/Write.pm #
7 # Authors: André Malo <nd@o3media.de>, 2001-04-08 #
9 # Description: Save a posting #
11 ################################################################################
14 use vars
qw(%error @EXPORT);
16 use Encode::Plain; $Encode::Plain::utf8 = 1;
25 create_forum_xml_string
36 threadWrite
=> '1 could not write thread file',
37 forumWrite
=> '2 could not write forum file',
38 threadFile
=> '3 could not load thread file',
39 noParent
=> '4 could not find parent message'
42 ################################################################################
46 use base
qw(Exporter);
52 ### sub write_new_thread ($) ###################################################
54 # save a posting and update the forum main file
56 # Params: $param - hashreference
57 # (see doc for details)
59 # Return: (0 or error, thread-xml, new mid)
61 sub write_new_thread
($) {
64 my $mid = 'm'.($param -> {lastMessage
} + 1);
65 my $tid = 't'.($param -> {lastThread
} + 1);
67 # define the params needed for a new thread
72 name
=> defined $param -> {author
} ?
$param -> {author
} : '',
73 email
=> defined $param -> {email
} ?
$param -> {email
} : '',
74 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} : '',
75 image
=> defined $param -> {image
} ?
$param -> {image
} : '',
76 category
=> defined $param -> {category
} ?
$param -> {category
} : '',
77 subject
=> defined $param -> {subject
} ?
$param -> {subject
} : '',
80 { quoteChars
=> $param -> {quoteChars
},
81 messages
=> $param -> {messages
}
84 time => $param -> {time},
85 dtd
=> $param -> {dtd
},
89 # create new thread and save it to disk
91 $thread = create_new_thread
($pars);
92 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
94 # update forum main file
98 -> {$param -> {lastThread
} + 1} = [
99 { mid
=> $param -> {lastMessage
} + 1,
100 unid
=> $param -> {uniqueID
},
101 name
=> plain
($pars -> {name
}),
102 cat
=> plain
($pars -> {category
}),
103 subject
=> plain
($pars -> {subject
}),
104 time => plain
($pars -> {time}),
109 my $forum = create_forum_xml_string
(
110 $param -> {parsedThreads
},
111 { dtd
=> $pars -> {dtd
},
117 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
118 release_file
($param -> {messagePath
}.$tid.'.xml');
119 return (0, $thread, $mid);
122 ### sub write_reply_posting ($) ################################################
124 # save a reply and update the forum main file
126 # Params: $param - hashreference
127 # (see doc for details)
129 # Return: (0 or error, thread-xml, new mid)
131 sub write_reply_posting
($) {
134 my $mid = 'm'.($param -> {lastMessage
} + 1);
135 my $tid = 't'.($param -> {thread
});
137 my $tfile = $param -> {messagePath
}.$tid.'.xml';
139 unless (write_lock_file
($tfile)) {
140 violent_unlock_file
($tfile);
141 return $error{threadFile
};
145 my $xml = parse_xml_file
($tfile);
148 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
149 return $error{threadFile
};
152 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
154 unless (defined $mnode) {
155 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
156 return $error{noParent
};
161 ip
=> $param -> {ip
},
162 name
=> defined $param -> {author
} ?
$param -> {author
} :'',
163 email
=> defined $param -> {email
} ?
$param -> {email
} :'',
164 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} :'',
165 image
=> defined $param -> {image
} ?
$param -> {image
} :'',
166 category
=> defined $param -> {category
} ?
$param -> {category
} :'',
167 subject
=> defined $param -> {subject
} ?
$param -> {subject
} :'',
168 time => $param -> {time},
171 my $message = create_message
($xml, $pars);
173 $mnode -> appendChild
($message);
175 my $mcontent = $xml -> createElement
('MessageContent');
176 $mcontent -> setAttribute
('mid' => $mid);
177 $mcontent -> appendChild
(
178 $xml -> createCDATASection
(
181 { quoteChars
=> $param -> {quoteChars
},
182 messages
=> $param -> {messages
}
188 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
189 $content -> appendChild
($mcontent);
193 unless (save_file
($tfile, \
($xml -> toString
))) {
194 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
195 return $error{threadWrite
};
198 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
202 # add message to thread tree
203 # ATTENTION: don't use the tree for visual output after this operation
206 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
207 if ($_ -> {mid
} == $param -> {parentMessage
}) {
209 $param -> {parsedThreads
} -> {$param -> {thread
}}},$i, 0,
210 { mid
=> $param -> {lastMessage
} + 1,
211 unid
=> plain
($param -> {uniqueID
}),
212 name
=> plain
($pars -> {name
}),
213 cat
=> plain
($pars -> {category
}),
214 subject
=> plain
($pars -> {subject
}),
215 level
=> $_ -> {level
} + 1,
216 time => plain
($pars -> {time})
223 # create & save forum main file
225 my $forum = create_forum_xml_string
(
226 $param -> {parsedThreads
},
227 { dtd
=> $param -> {dtd
},
233 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
236 return (0, $thread, $mid);
239 # keeping 'require' happy
245 ### end of Posting::Write ######################################################
patrick-canterino.de