Exemplo n.º 1
0
function kona3_action_new()
{
    global $kona3conf;
    $page = $kona3conf["page"];
    $action = kona3getPageURL($page, "new");
    $am = kona3param('a_mode', '');
    $key = kona3param('a_key', '');
    $res = "";
    if ($am == "new") {
        $url = kona3getPageURL($key, "edit");
        header("Location: {$url}");
        exit;
    }
    $key_ = kona3text2html($key);
    // show form
    $form = <<<EOS
<div>
  <form method="post" action="{$action}">
    <input type="hidden" name="a_mode" value="new">
    <input type="text" name="a_key" value="{$key_}">
    <input type="submit" value="New">
  </form>
</div>
<div>
{$res}
</div>
EOS;
    // show
    kona3template('message', array("page_title" => kona3text2html($page), "page_body" => $form));
}
Exemplo n.º 2
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));
}
Exemplo n.º 3
0
function kona3_action_login()
{
    global $kona3conf;
    $page = $kona3conf["page"];
    $action = kona3getPageURL($page, "login");
    $am = kona3param('a_mode', '');
    $user = kona3param('a_user', '');
    $pw = kona3param('a_pw', '');
    $msg = '';
    // check user
    if ($am == "trylogin") {
        $users = $kona3conf['users'];
        if (isset($users[$user]) && $users[$user] == $pw) {
            // ok
            $editLink = kona3getPageURL($page, 'edit');
            $msg = "<a href='{$editLink}'>Success to login.</a>";
            kona3login();
            kona3showMessage($page, $msg);
            exit;
        } else {
            // ng
            $msg = '<div class="error">Invalid User or Password.</div>';
        }
    }
    // show form
    $form = <<<EOS
<div id="loginform">
  {$msg}
  <form method="post" action="{$action}">
  <input type="hidden" name="a_mode" value="trylogin">
  <p>
    <label for="user">User:</label><br>
    <input id="user" type="text" name="a_user">
  </p>
  <p>
    <label for="pass">Password:</label><br>
    <input id="pass" type="password" name="a_pw">
  </p>
  <p><input type="submit" value="Login"></p>
  </form>
</div>
EOS;
    // show
    kona3template('message', array("page_title" => kona3text2html($page), "page_body" => $form));
}
Exemplo n.º 4
0
function kona3_action_search()
{
    global $kona3conf;
    $page = $kona3conf["page"];
    $action = kona3getPageURL($page, "search");
    $am = kona3param('a_mode', '');
    $key = kona3param('a_key', '');
    $res = '';
    if ($am == "search") {
        $result = array();
        $path_data = $kona3conf["path.data"];
        kona3search($key, $result, $path_data);
        foreach ($result as $f) {
            $path = str_replace("{$path_data}/", "", $f);
            $path = preg_replace('/\\.(txt|md)$/', '', $path);
            $enc = urlencode($path);
            $res .= "<li><a href='index.php?{$enc}'>{$path}</li>";
        }
    }
    if ($res != "") {
        $res = "<ul>{$res}</ul>\n";
    }
    $key_ = kona3text2html($key);
    // show form
    $form = <<<EOS
<div>
  <form method="post" action="{$action}">
    <input type="hidden" name="a_mode" value="search">
    <input type="text" name="a_key" value="{$key_}">
    <input type="submit" value="Search">
  </form>
</div>
<div>
{$res}
</div>
EOS;
    // show
    kona3template('message', array("page_title" => kona3text2html($page), "page_body" => $form));
}
Exemplo n.º 5
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));
}
Exemplo n.º 6
0
function kona3showMessage($title, $msg)
{
    $body = "<div class='message'>{$msg}</div>";
    kona3template("message", array('page_title' => kona3text2html($title), 'page_body' => $body));
    exit;
}