예제 #1
0
function plugin_guiedit_edit_data($page)
{
    global $vars;
    $source = Factory::Wiki($vars['page'])->get(true);
    $postdata = $vars['original'] = $source;
    if (!empty($vars['id'])) {
        exist_plugin('edit');
        $postdata = plugin_edit_parts($vars['id'], $source);
        if ($postdata === FALSE) {
            unset($vars['id']);
            $postdata = $vars['original'];
        }
    }
    if ($postdata == '') {
        $postdata = Factory::Wiki($page)->auto_template();
    }
    //	構文の変換
    $ret = RendererFactory::factory($postdata, true);
    plugin_guiedit_send_ajax($ret);
}
예제 #2
0
function plugin_edit_write()
{
    global $post, $vars, $trackback;
    global $notimeupdate, $do_update_diff_table;
    global $use_trans_sid_address;
    //	global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
    //	global $_msg_invalidpass;
    $_title_deleted = _(' $1 was deleted');
    $_msg_invalidpass = _('Invalid password.');
    $page = isset($vars['page']) ? $vars['page'] : '';
    $add = isset($vars['add']) ? $vars['add'] : '';
    $digest = isset($vars['digest']) ? $vars['digest'] : '';
    $partid = isset($vars['id']) ? $vars['id'] : '';
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    // Check Validate and Ticket
    if ($notimestamp && !is_page($page)) {
        return plugin_edit_honeypot();
    }
    // SPAM Check (Client(Browser)-Server Ticket Check)
    if (isset($post['encode_hint']) && $post['encode_hint'] != PKWK_ENCODING_HINT) {
        return plugin_edit_honeypot();
    }
    if (!isset($post['encode_hint']) && PKWK_ENCODING_HINT != '') {
        return plugin_edit_honeypot();
    }
    // Validate
    if (is_spampost(array('msg'))) {
        return plugin_edit_honeypot();
    }
    // Paragraph edit mode
    if ($partid) {
        $source = preg_split('/([^\\n]*\\n)/', $vars['original'], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        if (plugin_edit_parts($partid, $source, $vars['msg']) !== FALSE) {
            $vars['msg'] = join('', $source);
        } else {
            $vars['msg'] = rtrim($vars['original']) . "\n\n" . $vars['msg'];
        }
    }
    // Delete "#freeze" command for form edit.
    $vars['msg'] = preg_replace('/^#freeze\\s*$/im', '', $vars['msg']);
    $msg =& $vars['msg'];
    // Reference
    $retvars = array();
    // Collision Detection
    $oldpagesrc = get_source($page, TRUE, TRUE);
    $oldpagemd5 = md5($oldpagesrc);
    if ($digest != $oldpagemd5) {
        $vars['digest'] = $oldpagemd5;
        // Reset
        $original = isset($vars['original']) ? $vars['original'] : '';
        list($postdata_input, $auto) = do_update_diff($oldpagesrc, $msg, $original);
        $_msg_collided_auto = _('It seems that someone has already updated this page while you were editing it.<br />') . _('The collision has been corrected automatically, but there may still be some problems with the page.<br />') . _('To confirm the changes to the page, press [Update].<br />');
        $_msg_collided = _('It seems that someone has already updated this page while you were editing it.<br />') . _(' + is placed at the beginning of a line that was newly added.<br />') . _(' ! is placed at the beginning of a line that has possibly been updated.<br />') . _(' Edit those lines, and submit again.');
        $retvars['msg'] = _('On updating  $1, a collision has occurred.');
        $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
        $retvars['body'] .= $do_update_diff_table;
        unset($vars['id']);
        // Change edit all-text of pages(from para-edit)
        $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
        return $retvars;
    }
    // Action?
    if ($add) {
        // Add
        if (isset($vars['add_top']) && $vars['add_top']) {
            $postdata = $msg . "\n\n" . @join('', get_source($page));
        } else {
            $postdata = @join('', get_source($page)) . "\n\n" . $msg;
        }
    } else {
        // Edit or Remove
        $postdata =& $msg;
        // Reference
    }
    // NULL POSTING, OR removing existing page
    if ($postdata == '') {
        page_write($page, $postdata);
        $retvars['msg'] = $_title_deleted;
        $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
        if ($trackback) {
            tb_delete($page);
        }
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    //	$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    //	if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
    if ($notimeupdate > 1 && $notimestamp && auth::check_role('role_adm_contents') && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
        $retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
        return $retvars;
    }
    page_write($page, $postdata, $notimestamp);
    pkwk_headers_sent();
    if (isset($vars['refpage']) && $vars['refpage'] != '') {
        if ($partid) {
            header('Location: ' . get_page_location_uri($vars['refpage'], '', rawurlencode($partid)));
        } else {
            header('Location: ' . get_page_location_uri($vars['refpage']));
        }
    } else {
        if ($partid) {
            header('Location: ' . get_page_location_uri($page, '', rawurlencode($partid)));
        } else {
            header('Location: ' . get_page_location_uri($page));
        }
    }
    exit;
}
예제 #3
0
function plugin_edit_write()
{
    global $vars, $trackback, $_string, $_msg_edit;
    global $notimeupdate;
    $page = isset($vars['page']) ? $vars['page'] : null;
    $add = isset($vars['add']) ? $vars['add'] : null;
    $digest = isset($vars['digest']) ? $vars['digest'] : null;
    $partid = isset($vars['id']) ? $vars['id'] : null;
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] !== null;
    if (empty($page)) {
        return array('mgs' => 'Error', 'body' => $_msg_edit['err_empty_page']);
    }
    $wiki = Factory::Wiki($page);
    // Check Validate and Ticket
    if ($notimestamp && !$wiki->isValied()) {
        return plugin_edit_honeypot();
    }
    // Validate
    if (is_spampost(array('msg'))) {
        return plugin_edit_honeypot();
    }
    // Paragraph edit mode
    if ($partid) {
        $source = preg_split('/([^\\n]*\\n)/', $vars['original'], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $vars['msg'] = plugin_edit_parts($partid, $source, $vars['msg']) !== FALSE ? join('', $source) : rtrim($vars['original']) . "\n\n" . $vars['msg'];
    }
    $retvars = array();
    if (isset($vars['msg']) && !empty($vars['msg'])) {
        // Delete "#freeze" command for form edit.
        $vars['msg'] = preg_replace('/^#freeze\\s*$/im', '', $vars['msg']);
        $msg = $vars['msg'];
        // Reference
        // Action?
        if ($add) {
            // Compat: add plugin and adding contents
            $postdata = isset($vars['add_top']) && $vars['add_top'] ? $msg . "\n\n" . $oldpagesrc : $oldpagesrc . "\n\n" . $msg;
        } else {
            // Edit or Remove
            $postdata =& $msg;
        }
    } else {
        // CAPTCHAが有効なときで、ページを削除しようとした時、$vars['msg']は空になる。
        $wiki->set('');
        $retvars['msg'] = sprintf($_msg_edit['title_deleted'], Utility::htmlsc($page));
        $retvars['body'] = '<p class="alert alert-success">' . sprintf($_msg_edit['title_deleted'], Utility::htmlsc($page)) . '</p>';
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    //	$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    //	if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
    if ($notimeupdate > 1 && $notimestamp && Auth::check_role('role_contents_admin') && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p class="alert alert-danger">' . $_msg_edit['msg_invalidpass'] . '</p>' . "\n";
        $retvars['body'] .= Utility::editForm($page, $msg, FALSE);
        return $retvars;
    }
    $wiki->set($postdata, $notimeupdate !== 0 && $notimestamp);
    if (isset($vars['refpage']) && $vars['refpage'] !== '') {
        $refwiki = Factory::Wiki($vars['refpage']);
        $url = $partid ? $refwiki->uri('read', null, rawurlencode($partid)) : $refwiki->uri();
    } else {
        $url = $partid ? $wiki->uri('read', null, rawurlencode($partid)) : $wiki->uri();
    }
    if (isset($vars['ajax'])) {
        $headers = Header::getHeaders('application/json');
        Header::writeResponse($headers, 200, Json::encode(array('msg' => 'Your post has been saved.', 'posted' => true, 'taketime' => Time::getTakeTime())));
    } else {
        Utility::redirect($url);
    }
    exit;
}
예제 #4
0
function plugin_guiedit_edit_data($page)
{
    global $vars;
    $source = get_source($vars['page']);
    $postdata = $vars['original'] = join('', $source);
    if (!empty($vars['id'])) {
        exist_plugin('edit');
        $postdata = plugin_edit_parts($vars['id'], $source);
        if ($postdata === FALSE) {
            unset($vars['id']);
            $postdata = $vars['original'];
        }
    }
    if ($postdata == '') {
        $postdata = auto_template($page);
    }
    //	構文の変換
    require_once GUIEDIT_LIB_PATH . 'wiki2xhtml.php';
    $postdata = guiedit_convert_html($postdata);
    plugin_guiedit_send_xml($postdata);
}