FALSE,
'nodate'=>FALSE,
'below' =>FALSE,
'above' =>FALSE,
'reply' =>FALSE,
'_args' =>array()
);
foreach (func_get_args() as $arg)
plugin_pcomment_check_arg($arg, $params);
$vars_page = isset($vars['page']) ? $vars['page'] : '';
if (isset($params['_args'][0]) && $params['_args'][0] != '') {
$page = $params['_args'][0];
} else {
$raw_vars_page = strip_bracket($vars_page);
$page = sprintf(PLUGIN_PCOMMENT_PAGE, $raw_vars_page);
$raw_page = strip_bracket($page);
if (!is_page($raw_page)) {
// If the page doesn't exist, search backward-compatible page
// If only compatible page exists, set the page as comment target
$page_compat = sprintf(PLUGIN_PCOMMENT_PAGE_COMPATIBLE, $raw_vars_page);
if (is_page(strip_bracket($page_compat))) {
$page = $page_compat;
}
}
}
$count = isset($params['_args'][1]) ? intval($params['_args'][1]) : 0;
if ($count == 0) $count = PLUGIN_PCOMMENT_NUM_COMMENTS;
$_page = get_fullname(strip_bracket($page), $vars_page);
if (!is_pagename($_page))
return sprintf($_pcmt_messages['err_pagename'], htmlsc($_page));
$dir = PLUGIN_CTRLCMT_DIRECTION_DEFAULT;
if ($params['below']) {
$dir = 0;
} elseif ($params['above']) {
$dir = 1;
}
list($comments, $digest) = plugin_pcomment_get_comments($_page, $count, $dir, $params['reply']);
if (PKWK_READONLY) {
$form_start = $form = $form_end = '';
} else {
// Show a form
if ($params['noname']) {
$title = $_pcmt_messages['msg_comment'];
$name = '';
} else {
$title = $_pcmt_messages['btn_name'];
$name = '';
}
$radio = $params['reply'] ?
'' : '';
$comment = PLUGIN_CTRLCMT_MULTILINE
? '
' . "\n" . '' . "\n" . '
' . "\n"
: '';
$s_page = htmlsc($page);
$s_refer = htmlsc($vars_page);
$s_nodate = htmlsc($params['nodate']);
$form_start = '
' . $recent . ' ' . $link . '
' . "\n" . $form_start . $comments . "\n" . $form . $form_end . '' . $recent . ' ' . $link . '
' . "\n" . '' . implode(" , ", $ngwords) . '');
}
}
if (PLUGIN_CTRLCMT_NGWORD_MODE == 'hide') {
$vars['msg'] = preg_replace('/' . $PLUGIN_CTRLCMT_NGWORD . '/u', PLUGIN_CTRLCMT_NGWORD_MASK, $vars['msg']);
}
}
$comment = str_replace('$msg', $vars['msg'], PLUGIN_CTRLCMT_FORMAT_MSG);
if (isset($vars['name']) || ($vars['nodate'] != '1')) {
$_name = (!isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
$_name2 = $_name;
if (PLUGIN_CTRLCMT_NONAME == "") {
$PLUGIN_CTRLCMT_NONAME = "";
} else {
$PLUGIN_CTRLCMT_NONAME = "[[" . PLUGIN_CTRLCMT_NONAME . "]]";
}
$_name = ($_name == '') ? $PLUGIN_CTRLCMT_NONAME : str_replace('$name', $_name, PLUGIN_CTRLCMT_FORMAT_NAME);
if (PLUGIN_CTRLCMT_IPCRY) {
$_cryedip = substr(base64_encode(hash_hmac("sha1", date("Ymd") . $_SERVER["REMOTE_ADDR"], PLUGIN_CTRLCMT_IPCRYPASS)) , 0, 8);
$_ipcry = " &size(10){[" . $_cryedip . "]};";
} else {
$_ipcry = "";
}
$_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_CTRLCMT_FORMAT_NOW);
if (PLUGIN_CTRLCMT_SAVEIP) {
$iplog_json = array();
$iplog_loadjson = array();
$iplogIsExist = false;
if (file_exists(PLUGIN_CTRLCMT_DIR . '/cmt/.htaccess') == false) {
mkdir(PLUGIN_CTRLCMT_DIR);
mkdir(PLUGIN_CTRLCMT_DIR . "/cmt");
$open_ht = fopen(PLUGIN_CTRLCMT_DIR . "/cmt/.htaccess", 'a');
@fwrite($open_ht, "Require all denied");
fclose($open_ht);
}
if (file_exists(PLUGIN_CTRLCMT_DIR . '/cmt/log.json')) {
$iplog_loadjson = json_decode(file_get_contents(PLUGIN_CTRLCMT_DIR . "/cmt/log.json") , true);
$iplogIsExist = true;
}
$iplog_json[] = array(
'name' => $_name2,
'comment' => $comment,
'ipcry' => $_cryedip,
'date' => $now,
'page' => $page,
'ip_address' => $_SERVER["REMOTE_ADDR"],
);
if ($iplogIsExist == true) {
$iplog_json = array_merge($iplog_json, $iplog_loadjson);
}
file_put_contents(PLUGIN_CTRLCMT_DIR . "/cmt/log.json", json_encode($iplog_json, JSON_PRETTY_PRINT));
}
$comment = str_replace("\$MSG\$", $comment, PLUGIN_CTRLCMT_FORMAT_STRING);
$comment = str_replace("\$NAME\$", $_name, $comment);
$comment = str_replace("\$IPCRY\$", $_ipcry, $comment);
$comment = str_replace("\$NOW\$", $_now, $comment);
}
$reply_hash = isset($vars['reply']) ? $vars['reply'] : '';
if ($reply_hash || ! is_page($page)) {
$comment = preg_replace('/^\-+/', '', $comment);
}
$comment = rtrim($comment);
if (! is_page($page)) {
$postdata = '[[' . htmlsc(strip_bracket($refer)) . ']]' . "\n\n" .
'-' . $comment . "\n";
} else {
$postdata = get_source($page);
$count = count($postdata);
$digest = isset($vars['digest']) ? $vars['digest'] : '';
if (md5(join('', $postdata)) !== $digest) {
$ret['msg'] = $_pcmt_messages['title_collided'];
$ret['body'] = $_pcmt_messages['msg_collided'];
}
$start_position = 0;
while ($start_position < $count) {
if (preg_match('/^\-/', $postdata[$start_position])) break;
++$start_position;
}
$end_position = $start_position;
$dir = isset($vars['dir']) ? $vars['dir'] : '';
// Find the comment to reply
$level = 1;
$b_reply = FALSE;
if ($reply_hash != '') {
while ($end_position < $count) {
$matches = array();
if (preg_match('/^(\-{1,2})(?!\-)(.*)$/', $postdata[$end_position++], $matches)
&& md5($matches[2]) === $reply_hash)
{
$b_reply = TRUE;
$level = strlen($matches[1]) + 1;
while ($end_position < $count) {
if (preg_match('/^(\-{1,3})(?!\-)/', $postdata[$end_position], $matches)
&& strlen($matches[1]) < $level) break;
++$end_position;
}
break;
}
}
}
if ($b_reply == FALSE)
$end_position = ($dir == '0') ? $start_position : $count;
// Insert new comment
array_splice($postdata, $end_position, 0, str_repeat('-', $level) . $comment . "\n");
if (PLUGIN_PCOMMENT_AUTO_LOG) {
$_count = isset($vars['count']) ? $vars['count'] : '';
plugin_pcomment_auto_log($page, $dir, $_count, $postdata);
}
$postdata = join('', $postdata);
}
page_write($page, $postdata, PLUGIN_PCOMMENT_TIMESTAMP);
if (PLUGIN_PCOMMENT_TIMESTAMP) {
if ($refer != '') pkwk_touch_file(get_filename($refer));
put_lastmodified();
}
return $ret;
}