コード例 #1
0
ファイル: file.inc.php プロジェクト: kujirahand/konawiki3
function kona3plugins_file_execute($args)
{
    global $kona3conf;
    $name = array_shift($args);
    $fname = kona3getWikiFile($name, false);
    if (!file_exists($fname)) {
        return "<div class='error'>Not Exists:" . kona3text2html($name) . "</div>";
    }
    $txt = file_get_contents($fname);
    $htm = konawiki_parser_convert($txt);
    return "<div>" . $htm . "</div>";
}
コード例 #2
0
ファイル: ref.inc.php プロジェクト: kujirahand/konawiki3
function kona3plugins_ref_execute($args)
{
    global $kona3conf;
    // get args
    $size = "";
    $caption = "";
    $link = "";
    $url = array_shift($args);
    while ($args) {
        $arg = array_shift($args);
        $arg = trim($arg);
        $c = substr($arg, 0, 1);
        if ($c == "*") {
            $caption = substr($arg, 1);
            continue;
        }
        if ($c == "@") {
            $link = substr($arg, 1);
            continue;
        }
        if (preg_match("#(\\d+)x(\\d+)#", $arg, $m)) {
            $size = " width='{$m[1]}' height='{$m[2]}'";
            continue;
        }
    }
    // make link
    if (!preg_match("#^http#", $url)) {
        // attach
        $f = $kona3conf["path.attach"] . "/" . urlencode($url);
        if (file_exists($f)) {
            $url = $kona3conf["url.attach"] . "/" . urlencode($url);
        }
        // data
        $f = kona3getWikiFile($url, false);
        if (file_exists($f)) {
            $url = kona3getWikiUrl($url);
        }
    }
    // Is image?
    if (preg_match('/\\.(png|jpg|jpeg|gif|bmp|ico|svg)$/', $url)) {
        $caph = "<div class='memo'>" . kona3text2html($caption) . "</div>";
        $code = "<div>" . "<div><a href='{$url}'><img src='{$url}'{$size}></a></div>" . ($caption != "" ? $caph : "") . "</div>";
    } else {
        if ($caption == "") {
            $caption = $url;
        }
        $code = "<div><a href='{$url}'>{$caption}</a></div>";
    }
    return $code;
}
コード例 #3
0
ファイル: filelist.inc.php プロジェクト: kujirahand/konawiki3
/** #filelist enum files
 * - [args] #filelist(filter, option)
 * - [option] thumb ... show thumbnail(64px)
 * - [option] thumb128 ... show thumbnail(128px)
 */
function kona3plugins_filelist_execute($args)
{
    global $kona3conf;
    // check args
    $pat = array_shift($args);
    $opt = [];
    foreach ($args as $arg) {
        $arg = trim($arg);
        $opt[$arg] = true;
    }
    $page = $kona3conf['page'];
    $fname = kona3getWikiFile($page);
    $dir = dirname($fname);
    $files = glob($dir . '/*');
    sort($files);
    # filter
    if ($pat != null) {
        $res = array();
        foreach ($files as $f) {
            if (fnmatch($pat, basename($f))) {
                $res[] = $f;
            }
        }
        $files = $res;
    }
    $code = "<ul>";
    foreach ($files as $f) {
        if (is_dir($f)) {
            continue;
        }
        $file = "file:{$f}";
        $url = kona3getWikiUrl($file, false);
        $name = htmlentities(basename($f));
        $thumb = "";
        if (isset($opt['thumb']) || isset($opt['thumb128'])) {
            $width = 64;
            if (isset($opt['thumb128'])) {
                $width = 128;
            }
            if (preg_match('/\\.(png|gif|jpg|jpeg)$/i', $f)) {
                $thumb = "<img src='{$url}' width='{$width}'>";
            } else {
                $thumb = '(no thumb)';
            }
        }
        $code .= "<li><a href='{$url}'>{$thumb} {$name}</a></li>\n";
    }
    $code .= "</ul>\n";
    return $code;
}
コード例 #4
0
ファイル: filecode.inc.php プロジェクト: kujirahand/konawiki3
function kona3plugins_filecode_execute($args)
{
    global $kona3conf;
    $name = array_shift($args);
    $fname = kona3getWikiFile($name, false);
    if (!file_exists($fname)) {
        return "<div class='error'>Not Exists:" . kona3text2html($name) . "</div>";
    }
    $url = kona3getWikiUrl($name);
    $txt = @file_get_contents($fname);
    if (preg_match('#\\.php$#', $fname)) {
        $txt = trim($txt);
        $htm = highlight_string($txt, true);
        // <pre>するので不必要な改行を削除
        $htm = preg_replace('#[\\r\\n]#', '', $htm);
    } else {
        $htm = kona3text2html(trim($txt));
    }
    $name_ = htmlspecialchars($name, ENT_QUOTES);
    $code = "<div class='filecode'>" . "  <div class='filename'>" . "    <a href='{$url}'>file: {$name_}</a>" . "  </div>" . "  <pre class='code'>{$htm}</pre>" . "</div>";
    return $code;
}
コード例 #5
0
ファイル: ls.inc.php プロジェクト: kujirahand/konawiki3
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;
}
コード例 #6
0
ファイル: show.inc.php プロジェクト: kujirahand/konawiki3
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));
}
コード例 #7
0
ファイル: edit.inc.php プロジェクト: kujirahand/konawiki3
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.";
}