'€', // the Euro sign
'' => '',
'' => '‚', // these are Windows CP1252 specific characters
'' => 'ƒ', // they would look weird on non-Windows browsers
'' => '„',
'
' => '…',
'' => '†',
'' => '‡',
'' => 'ˆ',
'' => '‰',
'' => 'Š',
'' => '‹',
'' => 'Œ',
'' => '',
'' => 'ž',
'' => '',
'' => '',
'' => '‘',
'' => '’',
'' => '“',
'' => '”',
'' => '•',
'' => '–',
'' => '—',
'' => '˜',
'' => '™',
'' => 'š',
'' => '›',
'' => 'œ',
'' => '',
'' => '',
'' => 'Ÿ');
function PostComment(&$frontend, $args, $dummy_run=false) {
$this->PostGenericAction($frontend, $args, $dummy_run);
}
function run($hook, &$post) {
$this->_post =& $post;
$this->_comment_id = null;
$tpl =& $this->_frontend->tpl;
$messages =& $this->_frontend->messages;
$options =& $this->_frontend->options;
$action =& $this->_action;
// a trackback?
$trackback = ($action == 'trackback') ? true : false;
$now = time();
if ($trackback) {
if ($post['ping_status'] != 'open')
$this->trackback_error("Trackbacks closed for this post");
$tb_fields = array('title', 'excerpt', 'url', 'blog_name', 'charset');
$this->_bootstrap($post, '', true, false, $tb_fields);
// check trackback
$user_data =& $this->_user_data;
if (empty($user_data['ud_url']))
$this->trackback_error("No URL in request vars");
if (!preg_match('/^[a-zA-Z]+:\/\//', $user_data['ud_url']))
$this->trackback_error("Incorrect URL format.");
if (empty($user_data['ud_blog_name']))
$user_data['ud_blog_name'] = 'Anonymous Trackback';
$tb_charset = strtoupper(trim($user_data['ud_charset']));
if (!empty($tb_charset) && function_exists('mb_convert_encoding') && $tb_charset != $options['charset']) {
foreach ($tb_fields as $tb_var)
$user_data[$tb_var] = mb_convert_encoding($user_data[$tb_var], $options['charset'], $tb_charset);
}
if (!empty($user_data['ud_title'])) {
$comment = '' .
$user_data['ud_title'] . " " . $user_data['ud_excerpt'];
} else {
$comment = $user_data['ud_excerpt'];
}
$comment = $this->wp_formatting($comment);
// TODO: check query result
$this->_comment_id = $this->_frontend->insertComment($this->_post['post_id'], $now, $user_data['ud_blog_name'], '', $user_data['ud_url'], $comment, 'trackback', true);
$this->sendNotification($now, $user_data['ud_blog_name'], '', $user_data['ud_url'], $comment);
$this->trackback_success();
} else {
$comment_add_block = $tpl->setBlock('index', 'comment_add', 'BLOCK_COMMENT_ADD', false);
if ($post['skip_form']) {
// we can't display the form as something else is happening
// (eg the "send post to a friend" form)
$tpl->setVar('PLUGIN_POSTCOMMENT', ' ');
if ($comment_add_block)
$tpl->setVar('BLOCK_COMMENT_ADD', $messages['comments_closed']);
return;
}
if ($post['comment_status'] != 'open') {
// comments are closed, let's hide the plugin's template tag
$tpl->setVar('PLUGIN_POSTCOMMENT', ' ');
// and change the link above the comennts list
if ($comment_add_block)
$tpl->setVar('BLOCK_COMMENT_ADD', $messages['comments_closed']);
return;
}
if ($comment_add_block)
$tpl->parse('BLOCK_COMMENT_ADD', 'comment_add');
$this->_bootstrap($post, $messages['comment_form_message']);
// too lazy to add $this->_ to every variable
$message =& $this->_message;
$message_class =& $this->_message_class;
$user_data =& $this->_user_data;
$labels =& $this->_labels;
// handle comment submission
if ($action == 'post_comment') {
// check comment fields
$empty_fields = array();
foreach (array('name', 'email', 'text') as $key) {
if (empty($user_data["ud_$key"]))
$empty_fields[] = $key;
}
if (count($empty_fields) == 0) {
$comment = $this->wp_formatting($user_data['ud_text']);
$this->_comment_id = $this->_frontend->insertComment($this->_post['post_id'], $now, $user_data['ud_name'], $user_data['ud_email'],
$user_data['ud_url'], $comment);
$this->sendNotification($now, $user_data['ud_name'], $user_data['ud_email'],
$user_data['ud_url'], $user_data['ud_text']);
// check if we have to remove the user cookie
if (!isset($_REQUEST['remember']) || $_REQUEST['remember'] != '1')
$this->_frontend->removeUserCookie();
// redirect user so that he does not insert the comment twice
$this->_frontend->redirectToPost(
$post['post_permalink'],
$messages['comment_accepted']);
} else {
// we have errors, let's set warnings
foreach ($empty_fields as $empty_field)
$user_data["ud_label_$empty_field"] = "warning";
$message = $messages['comment_required_fields']; // . implode(", ", $empty_fields);
$message_class = 'comment_form_warning';
}
}
// no action, let's set user data and display the form
$tpl->setVar($user_data);
$tpl->setVar(array(
'comment_form_message' => $message,
'comment_form_message_class' => $message_class));
$tpl->setFile('plugin_postcomment', 'plugins/post_comment.xml');
$tpl->parse('PLUGIN_POSTCOMMENT', 'plugin_postcomment');
}
}
function sendNotification($now, $author, $email, $url, $comment) {
$options =& $this->_frontend->options;
if (!$options['mail_on_comment'] || is_null($this->_comment_id))
return;
$messages =& $this->_frontend->messages;
$tpl =& $this->_frontend->tpl;
$tables =& $this->_frontend->tables;
$db =& $this->_frontend->db;
$q = "select distinct u.user_email from " . $tables['users'] . " u " .
"left join " . $tables['posts'] . " p on p.post_author=u.id " .
"where (u.user_level >= 3 or p.id=" . $this->_post['post_id'] .
") and u.user_email is not null and u.user_email != ''";
$db->query($q);
$users = array();
foreach ($db->all() as $row)
$users[] = $row['user_email'];
$to = implode(', ', $users);
$tpl->setFile('notify_email', 'plugins/post_comment_notification.txt');
$mh =& $this->_frontend->getMailHelper();
$shortname = $mh->htent2qp($options['shortname']);
$shortname_hdr = $mh->encoded2hdr($options['shortname']);
$tpl->setVar(array(
'notify_shortname' => $shortname,
'notify_useremails' => $to,
'notify_post_title' => $mh->htent2qp($this->_post['post_title']),
'notify_post_name' => $mh->htent2qp($this->_post['post_name']),
'notify_post_permalink' => $mh->htent2qp($this->_post['post_permalink']),
'notify_comment_date' => $mh->htent2qp(strftime($options['date_format'], $now)),
'notify_comment_time' => $mh->htent2qp(strftime($options['time_format'], $now)),
'notify_comment_user' => $mh->htent2qp($author),
'notify_comment_email' => $mh->htent2qp($email),
'notify_comment_ip' => $_SERVER['REMOTE_ADDR'],
'notify_comment_agent' => $_SERVER['HTTP_USER_AGENT'],
'notify_comment_url' => $mh->htent2qp($url),
'notify_comment_id' => $this->_comment_id,
'notify_comment_text' => strip_tags($comment)
));
$headers = array(
'Content-Type: text/plain; charset="' . $options['charset'] . '"',
'MIME-Version: 1.0',
'Content-Transfer-Encoding: quoted-printable',
'From: "'. $shortname_hdr . '" <' . $options['mail_from'] . '>');
return $mh->send_mail(
$to,
"[$shortname_hdr] " . $mh->encoded2hdr($messages['comment_mail_subject']),
$tpl->parse('NOTIFY_EMAIL', 'notify_email'),
implode("\r\n", $headers));
}
function trackback_success() {
header('Content-Type: text/xml');
echo '_frontend->options['charset'] . '"?>' .
"\n0\n";
exit;
}
function trackback_error($error="Error inserting trackback") {
header('Content-Type: text/xml');
echo '_frontend->options['charset'] . '"?>' .
"\n1" .
"" . htmlspecialchars($error, ENT_QUOTES) . "" .
"\n";
exit;
}
function wp_formatting(&$text) {
// stripped down version of WP's wp_formatting
// will have to code this properly sooner or later...
$output = '';
// Capture tags and everything inside them
$textarr = preg_split("/(<[^>]+>)/s", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$next = true;
foreach ($textarr as $curl) {
if (empty($curl))
continue;
if ($curl[0] == '<') {
if (strstr($curl, '_wp_htmltranswinuni);
// Just a little XHTML help
$output = str_replace('
', '
', $output);
$output = str_replace('
', '
', $output);
return $output;
}
}
?>