]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
b7338f657a940b61ea0942612054a7d1c346361e
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 ################################################################################
20 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
29 create_forum_xml_string
40 threadWrite
=> '1 could not write thread file',
41 forumWrite
=> '2 could not write forum file',
42 threadFile
=> '3 could not load thread file',
43 noParent
=> '4 could not find parent message'
46 ################################################################################
50 $VERSION = do { my @r =(q
$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r };
52 ################################################################################
56 use base
qw(Exporter);
62 ### sub write_new_thread ($) ###################################################
64 # save a posting and update the forum main file
66 # Params: $param - hashreference
67 # (see doc for details)
69 # Return: (0 or error, thread-xml, new mid)
71 sub write_new_thread
($) {
74 my $mid = 'm'.($param -> {lastMessage
} + 1);
75 my $tid = 't'.($param -> {lastThread
} + 1);
77 # define the params needed for a new thread
82 name
=> defined $param -> {author
} ?
$param -> {author
} : '',
83 email
=> defined $param -> {email
} ?
$param -> {email
} : '',
84 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} : '',
85 image
=> defined $param -> {image
} ?
$param -> {image
} : '',
86 category
=> defined $param -> {category
} ?
$param -> {category
} : '',
87 subject
=> defined $param -> {subject
} ?
$param -> {subject
} : '',
90 { quoteChars
=> $param -> {quoteChars
},
91 messages
=> $param -> {messages
},
92 base_uri
=> $param -> {base_uri
}
95 time => $param -> {time},
96 dtd
=> $param -> {dtd
},
100 # create new thread and save it to disk
102 $thread = create_new_thread
($pars);
103 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
105 # update forum main file
109 -> {$param -> {lastThread
} + 1} = [
110 { mid
=> $param -> {lastMessage
} + 1,
111 unid
=> $param -> {uniqueID
},
112 name
=> plain
($pars -> {name
}),
113 cat
=> plain
($pars -> {category
}),
114 subject
=> plain
($pars -> {subject
}),
115 time => plain
($pars -> {time}),
120 my $forum = create_forum_xml_string
(
121 $param -> {parsedThreads
},
122 { dtd
=> $pars -> {dtd
},
128 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
129 release_file
($param -> {messagePath
}.$tid.'.xml');
130 return (0, $thread, $mid, $tid);
133 ### sub write_reply_posting ($) ################################################
135 # save a reply and update the forum main file
137 # Params: $param - hashreference
138 # (see doc for details)
140 # Return: (0 or error, thread-xml, new mid)
142 sub write_reply_posting
($) {
145 my $mid = 'm'.($param -> {lastMessage
} + 1);
146 my $tid = 't'.($param -> {thread
});
148 my $tfile = $param -> {messagePath
}.$tid.'.xml';
150 unless (write_lock_file
($tfile)) {
151 violent_unlock_file
($tfile);
152 return $error{threadFile
};
156 my $xml = parse_xml_file
($tfile);
159 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
160 return $error{threadFile
};
163 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
165 unless (defined $mnode) {
166 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
167 return $error{noParent
};
172 ip
=> $param -> {ip
},
173 name
=> defined $param -> {author
} ?
$param -> {author
} :'',
174 email
=> defined $param -> {email
} ?
$param -> {email
} :'',
175 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} :'',
176 image
=> defined $param -> {image
} ?
$param -> {image
} :'',
177 category
=> defined $param -> {category
} ?
$param -> {category
} :'',
178 subject
=> defined $param -> {subject
} ?
$param -> {subject
} :'',
179 time => $param -> {time},
182 my $message = create_message
($xml, $pars);
184 $mnode -> appendChild
($message);
186 my $mcontent = $xml -> createElement
('MessageContent');
187 $mcontent -> setAttribute
('mid' => $mid);
188 $mcontent -> appendChild
(
189 $xml -> createCDATASection
(
192 { quoteChars
=> $param -> {quoteChars
},
193 messages
=> $param -> {messages
},
194 base_uri
=> $param -> {base_uri
}
200 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
201 $content -> appendChild
($mcontent);
205 unless (save_file
($tfile, \
($xml -> toString
))) {
206 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
207 return $error{threadWrite
};
210 violent_unlock_file
($tfile) unless (write_unlock_file
($tfile));
214 # add message to thread tree
215 # ATTENTION: don't use the tree for visual output after this operation
218 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
219 if ($_ -> {mid
} == $param -> {parentMessage
}) {
221 $param -> {parsedThreads
} -> {$param -> {thread
}}},$i, 0,
222 { mid
=> $param -> {lastMessage
} + 1,
223 unid
=> plain
($param -> {uniqueID
}),
224 name
=> plain
($pars -> {name
}),
225 cat
=> plain
($pars -> {category
}),
226 subject
=> plain
($pars -> {subject
}),
227 level
=> $_ -> {level
} + 1,
228 time => plain
($pars -> {time})
235 # create & save forum main file
237 my $forum = create_forum_xml_string
(
238 $param -> {parsedThreads
},
239 { dtd
=> $param -> {dtd
},
241 lastThread
=> 't'.$param -> {lastThread
}
245 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
248 return (0, $thread, $mid, $tid);
251 # keep 'require' happy
257 ### end of Posting::Write ######################################################
patrick-canterino.de