コード例 #1
0
function plugin_pcomment_insert()
{
    global $vars, $now, $_no_name;
    //	global $vars, $now, $_title_updated, $_no_name, $_pcmt_messages;
    $refer = isset($vars['refer']) ? $vars['refer'] : '';
    $page = isset($vars['page']) ? $vars['page'] : '';
    $page = get_fullname($page, $refer);
    if (!is_pagename($page)) {
        return array('msg' => _('Invalid page name'), 'body' => _('Cannot add comment'), 'collided' => TRUE);
    }
    check_editable($page, true, true);
    $ret = array('msg' => _(' $1 was updated'), 'collided' => FALSE);
    $msg = str_replace('$msg', rtrim($vars['msg']), PLUGIN_PCOMMENT_FORMAT_MSG);
    $name = !isset($vars['name']) || $vars['name'] == '' ? $_no_name : $vars['name'];
    list($nick, $link) = plugin_pcomment_get_nick();
    if (!empty($link)) {
        $name = $link;
    }
    $name = $name == '' ? '' : str_replace('$name', $name, PLUGIN_PCOMMENT_FORMAT_NAME);
    $date = !isset($vars['nodate']) || $vars['nodate'] != '1' ? str_replace('$now', $now, PLUGIN_PCOMMENT_FORMAT_NOW) : '';
    if ($date != '' || $name != '') {
        $msg = str_replace("" . 'MSG' . "", $msg, PLUGIN_PCOMMENT_FORMAT_STRING);
        $msg = str_replace("" . 'NAME' . "", $name, $msg);
        $msg = str_replace("" . 'DATE' . "", $date, $msg);
    }
    $reply_hash = isset($vars['reply']) ? $vars['reply'] : '';
    if ($reply_hash || !is_page($page)) {
        $msg = preg_replace('/^\\-+/', '', $msg);
    }
    $msg = rtrim($msg);
    if (!is_page($page)) {
        $postdata = '[[' . htmlspecialchars(strip_bracket($refer)) . ']]' . "\n\n" . '-' . $msg . "\n";
    } else {
        $postdata = get_source($page);
        $count = count($postdata);
        $digest = isset($vars['digest']) ? $vars['digest'] : '';
        if (md5(join('', $postdata)) != $digest) {
            $ret['msg'] = _('On updating  $1, there was a collision.');
            $ret['body'] = _('It seems that someone has already updated this page while you were editing it.<br />' . 'The comment was added to the page, but there may be a problem.<br />');
        }
        $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) . $msg . "\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;
}
コード例 #2
0
ファイル: pcomment.inc.php プロジェクト: logue/pukiwiki_adv
function plugin_pcomment_insert()
{
    global $vars, $now, $_no_name, $_string;
    //	global $vars, $now, $_title_updated, $_no_name, $_pcmt_messages, $_string;
    $refer = isset($vars['refer']) ? $vars['refer'] : '';
    $page = isset($vars['page']) ? $vars['page'] : '';
    $page = get_fullname($page, $refer);
    $wiki = Factory::Wiki($page);
    if (!$wiki->isValied()) {
        return array('msg' => T_('Invalid page name'), 'body' => T_('Cannot add comment'), 'collided' => TRUE);
    }
    $wiki->checkEditable();
    $ret = array('msg' => $_string['updated'], 'collided' => FALSE);
    $msg = str_replace('$msg', rtrim($vars['msg']), PLUGIN_PCOMMENT_FORMAT_MSG);
    $name = !isset($vars['name']) || $vars['name'] == '' ? $_no_name : $vars['name'];
    $name = $name == '' ? '' : str_replace('$name', $name, PLUGIN_PCOMMENT_FORMAT_NAME);
    $date = !isset($vars['nodate']) || $vars['nodate'] != '1' ? str_replace('$now', $now, PLUGIN_PCOMMENT_FORMAT_NOW) : '';
    list($nick, $link) = plugin_pcomment_get_nick();
    if (!empty($link)) {
        $name = $link;
    }
    $name = $name == '' ? '' : str_replace('$name', $name, PLUGIN_PCOMMENT_FORMAT_NAME);
    $date = !isset($vars['nodate']) || $vars['nodate'] != '1' ? str_replace('$now', $now, PLUGIN_PCOMMENT_FORMAT_NOW) : '';
    if ($date != '' || $name != '') {
        $msg = str_replace("" . 'MSG' . "", $msg, PLUGIN_PCOMMENT_FORMAT_STRING);
        $msg = str_replace("" . 'NAME' . "", $name, $msg);
        $msg = str_replace("" . 'DATE' . "", $date, $msg);
    }
    $reply_hash = isset($vars['reply']) ? $vars['reply'] : '';
    if ($reply_hash || !is_page($page)) {
        $msg = preg_replace('/^\\-+/', '', $msg);
    }
    $msg = rtrim($msg);
    if (!is_page($page)) {
        $postdata = '[[' . Utility::htmlsc(strip_bracket($refer)) . ']]' . "\n\n" . '-' . $msg . "\n";
    } else {
        $postdata = get_source($page);
        $count = count($postdata);
        $digest = isset($vars['digest']) ? $vars['digest'] : '';
        if (md5(join('', $postdata)) !== $digest) {
            $ret['msg'] = $_string['title_collided'];
            $ret['body'] = $_string['comment_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) . $msg . "\n");
        if (PLUGIN_PCOMMENT_AUTO_LOG) {
            $_count = isset($vars['count']) ? $vars['count'] : '';
            plugin_pcomment_auto_log($page, $dir, $_count, $postdata);
        }
    }
    $wiki->set($postdata, PLUGIN_PCOMMENT_TIMESTAMP);
    return $ret;
}