示例#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));
}
示例#2
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));
}
示例#3
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));
}
示例#4
0
function kona3plugins_ls_execute($args)
{
    global $kona3conf;
    $page = $kona3conf['page'];
    $fname = kona3getWikiFile($page);
    $dir = dirname($fname);
    // get all files
    $files = glob($dir . "/*");
    sort($files);
    # filter
    $pat = array_shift($args);
    if ($pat != null) {
        $res = array();
        foreach ($files as $f) {
            if (fnmatch($pat, basename($f))) {
                $res[] = $f;
            }
        }
        $files = $res;
    }
    $code = "<ul>";
    foreach ($files as $f) {
        // directory --- check index
        if (is_dir($f)) {
            $f .= "/index.txt";
            if (!file_exists($f)) {
                continue;
            }
        }
        $name = kona3getWikiName($f);
        $url = kona3getPageURL($name);
        $name = htmlentities($name);
        $code .= "<li><a href='{$url}'>{$name}</a></li>\n";
    }
    $code .= "</ul>\n";
    return $code;
}
示例#5
0
function _at_all($pdo, $type)
{
    $page = kona3getPage();
    $q = $pdo->query('SELECT * FROM comment_bbsid');
    $allbbs = $q->fetchAll();
    $html = "<h3>Comments (type={$type})</h3>";
    foreach ($allbbs as $row) {
        $bbs_id = $row["bbs_id"];
        $bbs_name = htmlentities($row["name"]);
        $link = kona3getPageURL($row["name"]);
        $where = "";
        if ($type == "todo") {
            $where = " AND todo=1";
        }
        $stmt = $pdo->prepare("SELECT * FROM comment_list " . "  WHERE bbs_id=? {$where} " . "  ORDER BY comment_id DESC " . "  LIMIT 30");
        // 最新の30件
        $stmt->execute(array($bbs_id));
        $list = $stmt->fetchAll();
        if (count($list) == 0) {
            continue;
        }
        $html .= "<h4><a href='{$link}'>{$bbs_name}</a></h4>";
        $html .= "<ul>";
        $index = "index.php?" . urlencode($page) . "&plugin&name=comment";
        foreach ($list as $row) {
            $id = $row["comment_id"];
            $name = htmlentities($row["name"]);
            $body = htmlentities(mb_substr($row["body"], 0, 100));
            $mtime = date("m-d H:i", $row["mtime"]);
            $todo_v = $row["todo"];
            $todo_l = $todo_v == 0 ? "done" : "todo";
            $todo = "(<a class='{$todo_l}' onclick='chtodo(event,{$id},{$todo_v})'>{$todo_l}</a>)";
            $html .= "<li>{$name} - {$body} <span class='memo'>({$mtime}){$todo}</span></li>";
        }
        $html .= "</ul>";
    }
    $html .= _todo_script();
    return $html;
}
示例#6
0
<?php

/** frame template */
global $kona3conf;
// Parameters
if (empty($page_title)) {
    $page_title = "?";
}
if (empty($page_body)) {
    $page_body = "page_body is empty";
}
$wiki_title_ = kona3text2html($kona3conf['title']);
$page_title_ = Kona3text2html($page_title);
$logo_href = kona3getPageURL(KONA3_WIKI_FRONTPAGE);
$page_href = kona3getPageURL($page_title);
// Is FrontPage?
if ($page_title == KONA3_WIKI_FRONTPAGE) {
    // FrontPage
    $head_title = "{$wiki_title_}";
} else {
    // Normal page
    $head_title = "{$page_title}-{$wiki_title_}";
}
//
$logo_title_ = "<a href='{$logo_href}'>{$wiki_title_}</a>";
$page_name_ = "<a href='{$page_href}'>{$page_title_}</a>";
// js & css & header tags
$js = "";
if (isset($kona3conf['js'])) {
    $jslist = $kona3conf['js'];
    $jslist = array_unique($jslist);
示例#7
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));
}
示例#8
0
function kona3_trywrite(&$txt, &$a_hash, $i_mode)
{
    global $kona3conf, $page;
    $edit_txt = kona3param('edit_txt', '');
    $a_hash_frm = kona3param('a_hash', '');
    $fname = kona3getWikiFile($page);
    // check hash
    if ($a_hash_frm !== $a_hash) {
        // conflict
        return kona3_conflict($edit_txt, $txt, $i_mode);
    }
    // save
    if (file_exists($fname)) {
        if (!is_writable($fname)) {
            kona3_edit_err('Could not write file.', $i_mode);
            exit;
        }
    } else {
        $dirname = dirname($fname);
        if (file_exists($dirname)) {
            if (!is_writable(dirname($fname))) {
                kona3_edit_err('Could not write file. Permission denied.', $i_mode);
                exit;
            }
        } else {
            // auto mkdir ?
            $data_dir = $kona3conf['path.data'];
            $max_level = $kona3conf['path.max.mkdir'];
            if ($data_dir != substr($dirname, 0, strlen($data_dir))) {
                kona3_edit_err('Invalid File Path.', $i_mode);
                exit;
            }
            $dirname2 = substr($dirname, strlen($data_dir) + 1);
            $cnt = count(explode("/", $dirname2));
            if ($cnt <= $max_level) {
                // 3 level directories
                $b = mkdir($dirname, 0777, TRUE);
                if (!$b) {
                    kona3_edit_err('mkdir failed, could not use "/"', $i_mode);
                    exit;
                }
            } else {
                kona3_edit_err("Invalid Wiki Name (not allow use '/' over {$max_level} times)", $i_mode);
                exit;
            }
        }
    }
    file_put_contents($fname, $edit_txt);
    // result
    if ($i_mode == "ajax") {
        echo json_encode(array('result' => 'ok', 'a_hash' => hash('sha256', $edit_txt)));
        exit;
    }
    $jump = kona3getPageURL($page);
    header("location:{$jump}");
    echo "ok, saved.";
}
示例#9
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);
}
示例#10
0
function konawiki_parser_makeWikiLink($name)
{
    // check pattern
    // -[[wikiname]]
    // -[[name:url]]
    // -[[caption:wikiname]]
    // -[[caption:wikiname]]
    $caption = "";
    // display name
    $link = "";
    // link
    $wikiname = "";
    // wikiname
    $wikilink = TRUE;
    // [[xxx:xxxx]]
    if (strpos($name, ":") === FALSE) {
        // simple ?
        // [[wikiname]]
        $caption = $wikiname = $name;
        $link = kona3getPageURL($name);
    } else {
        // [[xxx:xxx]]
        preg_match('|^(.*?)\\:(.*)$|', $name, $e);
        $caption = $e[1];
        $link = $e[2];
        // protocol ?
        if ($caption == 'http' || $caption == 'https' || $caption == 'ftp') {
            $link = $caption = $name;
        }
        // check all url
        if (strpos($link, '://') !== FALSE) {
            // url
            $caption = konawiki_parser_disp_url($caption);
            $link = $link;
            $wikilink = FALSE;
        } else {
            // wiki link
            // [[caption:WikiPage]]
            $wikiname = $link;
            $link = kona3getPageURL($link);
            $wikilink = TRUE;
        }
    }
    // wikipage exists ?
    if ($wikilink === TRUE) {
        // TODO: check extra tag
    }
    return "<a href='{$link}'>{$caption}</a>";
}