Example #1
0
function kona3_edit_err($msg, $method = "web")
{
    global $page;
    if ($method == "ajax") {
        echo json_encode(array('result' => 'ng', 'reason' => $msg));
    } else {
        kona3error($page, $msg);
    }
}
Example #2
0
function kona3execute()
{
    global $kona3conf;
    $action = $kona3conf["action"];
    $actionFile = kona3getEngineFName("action", $action);
    $actionFunc = "kona3_action_{$action}";
    $page = $kona3conf['page'];
    if (!file_exists($actionFile)) {
        kona3error($page, "Invalid Action `{$action}`");
        exit;
    }
    include_once $actionFile;
    if (!function_exists($actionFunc)) {
        kona3error($page, "[System Error] Action not found.");
        exit;
    }
    call_user_func($actionFunc);
}
Example #3
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;
}
Example #4
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));
}