]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
5670251bdb48ca8f047c929ba1892102d3dd9031
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;
26 create_forum_xml_string
37 threadWrite
=> '1 could not write thread file',
38 forumWrite
=> '2 could not write forum file',
39 threadFile
=> '3 could not load thread file',
40 noParent
=> '4 could not find parent message'
43 ################################################################################
47 $VERSION = do { my @r =(q
$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r };
49 ################################################################################
53 use base
qw(Exporter);
59 ### sub write_new_thread ($) ###################################################
61 # save a posting and update the forum main file
63 # Params: $param - hashreference
64 # (see doc for details)
66 # Return: (0 or error, thread-xml, new mid)
68 sub write_new_thread
($) {
71 my $mid = 'm'.($param -> {lastMessage
} + 1);
72 my $tid = 't'.($param -> {lastThread
} + 1);
74 # define the params needed for a new thread
79 name
=> defined $param -> {author
} ?
$param -> {author
} : '',
80 email
=> defined $param -> {email
} ?
$param -> {email
} : '',
81 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} : '',
82 image
=> defined $param -> {image
} ?
$param -> {image
} : '',
83 category
=> defined $param -> {category
} ?
$param -> {category
} : '',
84 subject
=> defined $param -> {subject
} ?
$param -> {subject
} : '',
87 { quoteChars
=> $param -> {quoteChars
},
88 messages
=> $param -> {messages
},
89 base_uri
=> $param -> {base_uri
}
92 time => $param -> {time},
93 dtd
=> $param -> {dtd
},
97 # create new thread and save it to disk
99 $thread = create_new_thread
($pars);
100 save_file
($param -> {messagePath
}.$tid.'.xml',\
($thread -> toString
)) or return $error{threadWrite
};
102 # update forum main file
106 -> {$param -> {lastThread
} + 1} = [
107 { mid
=> $param -> {lastMessage
} + 1,
108 unid
=> $param -> {uniqueID
},
109 name
=> plain
($pars -> {name
}),
110 cat
=> plain
($pars -> {category
}),
111 subject
=> plain
($pars -> {subject
}),
112 time => plain
($pars -> {time}),
117 my $forum = create_forum_xml_string
(
118 $param -> {parsedThreads
},
119 { dtd
=> $pars -> {dtd
},
125 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
126 new Lock
($param -> {messagePath
}.$tid.'.xml') -> release
;
127 return (0, $thread, $mid, $tid);
130 ### sub write_reply_posting ($) ################################################
132 # save a reply and update the forum main file
134 # Params: $param - hashreference
135 # (see doc for details)
137 # Return: (0 or error, thread-xml, new mid)
139 sub write_reply_posting
($) {
142 my $mid = 'm'.($param -> {lastMessage
} + 1);
143 my $tid = 't'.($param -> {thread
});
145 my $tfile = new Lock
($param -> {messagePath
}.$tid.'.xml');
147 unless ($tfile->lock(LH_EXCL
)) {
148 return $error{threadFile
};
152 my $xml = parse_xml_file
($tfile->filename);
156 return $error{threadFile
};
159 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
161 unless (defined $mnode) {
163 return $error{noParent
};
168 ip
=> $param -> {ip
},
169 name
=> defined $param -> {author
} ?
$param -> {author
} :'',
170 email
=> defined $param -> {email
} ?
$param -> {email
} :'',
171 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} :'',
172 image
=> defined $param -> {image
} ?
$param -> {image
} :'',
173 category
=> defined $param -> {category
} ?
$param -> {category
} :'',
174 subject
=> defined $param -> {subject
} ?
$param -> {subject
} :'',
175 time => $param -> {time},
178 my $message = create_message
($xml, $pars);
180 $mnode -> appendChild
($message);
182 my $mcontent = $xml -> createElement
('MessageContent');
183 $mcontent -> setAttribute
('mid' => $mid);
184 $mcontent -> appendChild
(
185 $xml -> createCDATASection
(
188 { quoteChars
=> $param -> {quoteChars
},
189 messages
=> $param -> {messages
},
190 base_uri
=> $param -> {base_uri
}
196 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
197 $content -> appendChild
($mcontent);
201 unless (save_file
($tfile->filename, \
($xml -> toString
))) {
203 return $error{threadWrite
};
210 # add message to thread tree
211 # ATTENTION: don't use the tree for visual output after this operation
214 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
215 if ($_ -> {mid
} == $param -> {parentMessage
}) {
217 $param -> {parsedThreads
} -> {$param -> {thread
}}},$i, 0,
218 { mid
=> $param -> {lastMessage
} + 1,
219 unid
=> plain
($param -> {uniqueID
}),
220 name
=> plain
($pars -> {name
}),
221 cat
=> plain
($pars -> {category
}),
222 subject
=> plain
($pars -> {subject
}),
223 level
=> $_ -> {level
} + 1,
224 time => plain
($pars -> {time})
231 # create & save forum main file
233 my $forum = create_forum_xml_string
(
234 $param -> {parsedThreads
},
235 { dtd
=> $param -> {dtd
},
237 lastThread
=> 't'.$param -> {lastThread
}
241 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
244 return (0, $thread, $mid, $tid);
247 # keep 'require' happy
253 ### end of Posting::Write ######################################################
patrick-canterino.de