]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Write.pm
1 package Posting
::Write
;
3 ################################################################################
5 # File: shared/Posting/Write.pm #
7 # Authors: André Malo <nd@o3media.de> #
9 # Description: Save a posting #
11 ################################################################################
19 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 ################################################################################
50 sub VERSION
{(q
$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
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 new Lock
($param -> {messagePath
}.$tid.'.xml') -> release
;
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 = new Lock
($param -> {messagePath
}.$tid.'.xml');
150 unless ($tfile->lock(LH_EXCL
)) {
151 return $error{threadFile
};
155 my $xml = parse_xml_file
($tfile->filename);
159 return $error{threadFile
};
162 my $mnode = get_message_node
($xml, $tid, 'm'.$param -> {parentMessage
});
164 unless (defined $mnode) {
166 return $error{noParent
};
171 ip
=> $param -> {ip
},
172 name
=> defined $param -> {author
} ?
$param -> {author
} :'',
173 email
=> defined $param -> {email
} ?
$param -> {email
} :'',
174 home
=> defined $param -> {homepage
} ?
$param -> {homepage
} :'',
175 image
=> defined $param -> {image
} ?
$param -> {image
} :'',
176 category
=> defined $param -> {category
} ?
$param -> {category
} :'',
177 subject
=> defined $param -> {subject
} ?
$param -> {subject
} :'',
178 time => $param -> {time},
181 my $message = create_message
($xml, $pars);
183 $mnode -> appendChild
($message);
185 my $mcontent = $xml -> createElement
('MessageContent');
186 $mcontent -> setAttribute
('mid' => $mid);
187 $mcontent -> appendChild
(
188 $xml -> createCDATASection
(
191 { quoteChars
=> $param -> {quoteChars
},
192 messages
=> $param -> {messages
},
193 base_uri
=> $param -> {base_uri
}
199 my $content = $xml -> getElementsByTagName
('ContentList', 1) -> item
(0);
200 $content -> appendChild
($mcontent);
204 unless (save_file
($tfile->filename, \
($xml -> toString
))) {
206 return $error{threadWrite
};
213 # add message to thread tree
214 # ATTENTION: don't use the tree for visual output after this operation
217 for (@
{$param -> {parsedThreads
} -> {$param -> {thread
}}}) {
218 if ($_ -> {mid
} == $param -> {parentMessage
}) {
220 $param -> {parsedThreads
} -> {$param -> {thread
}}},$i, 0,
221 { mid
=> $param -> {lastMessage
} + 1,
222 unid
=> plain
($param -> {uniqueID
}),
223 name
=> plain
($pars -> {name
}),
224 cat
=> plain
($pars -> {category
}),
225 subject
=> plain
($pars -> {subject
}),
226 level
=> $_ -> {level
} + 1,
227 time => plain
($pars -> {time})
234 # create & save forum main file
236 my $forum = create_forum_xml_string
(
237 $param -> {parsedThreads
},
238 { dtd
=> $param -> {dtd
},
240 lastThread
=> 't'.$param -> {lastThread
}
244 save_file
($param -> {forumFile
}, $forum) or return $error{forumWrite
};
247 return (0, $thread, $mid, $tid);
250 # keep 'require' happy
256 ### end of Posting::Write ######################################################
patrick-canterino.de