示例#1
0
function kona3_action_edit()
{
    global $kona3conf, $page;
    $page = $kona3conf["page"];
    $action = kona3getPageURL($page, "edit");
    $a_mode = kona3param('a_mode', '');
    $i_mode = kona3param('i_mode', 'form');
    // or ajax
    // check permission
    if (!kona3isLogin()) {
        $url = kona3getPageURL($page, 'login');
        kona3_edit_err("<a href='{$url}'>Please login</a>", $i_mode);
        exit;
    }
    // load body
    $txt = "";
    $fname = kona3getWikiFile($page);
    if (file_exists($fname)) {
        $txt = @file_get_contents($fname);
    }
    $a_hash = hash('sha256', $txt);
    if ($a_mode == "trywrite") {
        $msg = kona3_trywrite($txt, $a_hash, $i_mode);
    } else {
        $msg = "";
    }
    // show
    kona3template('edit', array("action" => $action, "a_hash" => $a_hash, "page_title" => kona3text2html($page), "page_body" => kona3text2html($txt), "msg" => $msg));
}
示例#2
0
function kona3plugins_comment_action()
{
    global $kona3conf, $output_format;
    $page = kona3getPage();
    $m = kona3param("m", "");
    $output_format = kona3param("fmt", "");
    $is_login = kona3isLogin();
    if ($m == "") {
        _err($page, 'No Mode in Comment');
    }
    // write comment
    if ($m == "write") {
        kona3plugins_comment_action_write($page);
        return;
    }
    // delete comment (1/2)
    if ($m == "del") {
        $id = intval(@$_REQUEST['id']);
        if ($id <= 0) {
            kona3error($page, 'no id');
        }
        $key = $_SESSION['password'];
        $del = "<form method='post'>" . "<input type='hidden' name='m' value='del2'>" . "<input type='hidden' name='id' value='{$id}'>" . "<p>Really delete (id={$id})?</p>" . "<p>password: <input type='password' name='pw' value='{$key}'>" . " <input type='submit' value='Delete'></p>" . "</form>";
        _err($page, $del);
        exit;
    }
    // delete comment (2/2)
    if ($m == "del2") {
        $id = intval(@$_REQUEST['id']);
        $pw = isset($_REQUEST['pw']) ? $_REQUEST['pw'] : '';
        if ($id <= 0) {
            kona3error($page, "no id");
        }
        $pdo = kona3getDB();
        $stmt = $pdo->prepare('SELECT * FROM comment_list WHERE comment_id=?');
        $stmt->execute(array($id));
        $row = $stmt->fetch();
        if ($row['delkey'] === $pw || $is_login) {
            $pdo->exec("DELETE FROM comment_list WHERE comment_id={$id}");
            if ($output_format == "json") {
                _ok($page, "deleted");
            }
            header('location: index.php?' . urlencode($page));
            exit;
        }
    }
    // set todo
    if ($m == "todo") {
        $id = intval(@$_REQUEST['id']);
        if ($id < 0) {
            kona3error($page, "no id");
        }
        $v = isset($_REQUEST['v']) ? intval($_REQUEST['v']) : -1;
        if ($v < 0) {
            kona3error($page, "no v param");
        }
        $pdo = kona3getDB();
        $stmt = $pdo->prepare('UPDATE comment_list SET todo=? ' . '  WHERE comment_id=?');
        $stmt->execute(array($v, $id));
        $v = $v == 1 ? "todo" : "done";
        _ok($page, "ok comment_id={$id} change to {$v}");
        exit;
    }
    // else
    _err($page, 'Invalid mode');
    exit;
}
示例#3
0
function kona3_action_show()
{
    global $kona3conf;
    $page = $kona3conf["page"];
    $page_h = htmlspecialchars($page);
    // check login
    if ($kona3conf["wiki.private"]) {
        if (!kona3isLogin()) {
            $url = kona3getPageURL($page, "login");
            kona3error($page, "Private mode. <a href='{$url}'>Please login.</a>");
            exit;
        }
    }
    // wiki file (text)
    $fname = kona3getWikiFile($page);
    // wiki file eixsits?
    $ext = "txt";
    $wiki_live = file_exists($fname);
    if (!$wiki_live) {
        // mark down
        $fname = kona3getWikiFile($page, TRUE, '.md');
        $wiki_live = file_exists($fname);
        if ($wiki_live) {
            $ext = "md";
        } else {
            $fname = kona3getWikiFile($page, FALSE);
            $wiki_live = file_exists($fname);
            if (preg_match('#\\.([a-z]+)$#', $fname, $m)) {
                $ext = $m[1];
            }
        }
    }
    // body
    if ($wiki_live) {
        $txt = @file_get_contents($fname);
    } else {
        $updir = dirname($page);
        $txt = "*** {$page}\n\n" . "Not Found\n\n" . "#ls()\n";
    }
    // convert
    $cnt_txt = mb_strlen($txt);
    if ($ext == "txt") {
        $page_body = konawiki_parser_convert($txt);
    } else {
        if ($ext == "md") {
            $page_body = _markdown_convert($txt);
        } else {
            kona3error($page, "Sorry, System Error.");
            exit;
        }
    }
    // every page
    if (!empty($kona3conf['allpage.footer'])) {
        $footer = konawiki_parser_convert($kona3conf['allpage.footer']);
        $page_body .= "<hr>" . $footer;
    }
    // menu
    $menufile = kona3getWikiFile("MenuBar");
    if (file_exists($menufile)) {
        $menu = @file_get_contents($menufile);
        $menuhtml = konawiki_parser_convert($menu);
    } else {
        $menuhtml = "";
    }
    // show
    kona3template('show', array("page_title" => kona3text2html($page), "page_body" => $page_body, "cnt_txt" => $cnt_txt, "wiki_menu" => $menuhtml));
}
示例#4
0
function kona3getMenu()
{
    global $kona3conf;
    $page = $kona3conf['page'];
    //
    $new_uri = kona3getPageURL($page, 'new');
    $edit_uri = kona3getPageURL($page, 'edit');
    $login_uri = kona3getPageURL($page, 'login');
    $logout_uri = kona3getPageURL($page, 'logout');
    $search_uri = kona3getPageURL($page, 'search');
    //
    $list = array();
    //
    if (!kona3isLogin()) {
        $list[] = array('login', $login_uri);
        $list[] = array('-', '-');
    } else {
        $list[] = array('logout', $logout_uri);
        $list[] = array('-', '-');
        $list[] = array('new', $new_uri);
        $list[] = array('edit', $edit_uri);
    }
    $list[] = array('search', $search_uri);
    // make link
    $ha = array();
    foreach ($list as $it) {
        $label = $it[0];
        $href = $it[1];
        if ($href != "-") {
            $ha[] = "[<a href=\"{$href}\">{$label}</a>]";
        } else {
            $ha[] = " - ";
        }
    }
    return implode(" ", $ha);
}