Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
/** #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;
}
Exemplo n.º 3
0
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;
}