コード例 #1
0
ファイル: folding.php プロジェクト: ahastudio/moniwiki
function processor_folding($formatter, $value = "", $options = array())
{
    // unique id of the folding area
    $id = isset($GLOBALS['_folding_id_']) ? $GLOBALS['_folding_id_'] : 0;
    $id++;
    $GLOBALS['_folding_id_'] = $id;
    if ($value[0] == '#' and $value[1] == '!') {
        list($line, $value) = explode("\n", $value, 2);
    }
    $init_state = 'none';
    $title = _("More");
    $class = '';
    $opened = '';
    // parse args
    if (isset($line[0]) and ($p = strpos($line, ' ')) !== false) {
        $tag = substr($line, 0, $p);
        $args = substr($line, $p + 1);
        if (preg_match("/^(?:(open|\\+))?(?(1)[ ]*,[ ]*)?((?:(?:[a-zA-Z][a-z0-9_-]+)[ ]*)*)?(?(2)[ ]*,[ ]*)?/", $args, $matches)) {
            $class = isset($matches[2][0]) ? ' ' . $matches[2] : '';
            $tmp = substr($args, strlen($matches[0]));
            if (isset($tmp[0])) {
                $title = $tmp;
            }
            if ($matches[1] == 'open' or $matches[1] == '+') {
                $init_state = 'block';
                $opened = ' class="opened"';
            }
        }
    }
    // FIXME footnote prefix
    $fn_prefix = 'fn' . substr(md5(substr($value, 0, 32)), 0, 3);
    // allow wiki syntax in folding content
    ob_start();
    $params = array('notoc' => 1);
    $params['nosisters'] = 1;
    $f = new Formatter($formatter->page, $params);
    $f->foot_prefix = $fn_prefix;
    $f->get_javascripts();
    // trash default javascripts
    $f->pi['#linenum'] = 0;
    // do not use linenum
    $f->send_page($value, $params);
    $out = ob_get_contents();
    ob_end_clean();
    $onclick = " onclick=\"var f=document.getElementById('folding_{$id}');var s=f.style.display=='block';" . "f.style.display=s?'none':'block';this.className=s?'':'opened';\"";
    return <<<HERE
<div class="folding-area{$class}">
<dl class="folding">
<dt{$onclick}{$opened}>{$title}</dt>
<dd id="folding_{$id}" style="display:{$init_state};">{$out}</dd>
</dl>
</div>
HERE;
}
コード例 #2
0
ファイル: Include.php プロジェクト: NessunKim/MW_Skins
function macro_Include($formatter, $value = '')
{
    global $DBInfo;
    if (!isset($GLOBALS['_included_'])) {
        $GLOBALS['_included_'] = array();
    }
    $max_recursion = isset($DBInfo->include_max_recursion) ? $DBinfo->include_max_recursion : 2;
    $included =& $GLOBALS['_included_'];
    // <<Include("Page Name", arg="1", arg2="2", ...)>>
    // parse variables
    preg_match("/^(['\"])?(?(1)(?:[^'\"]|\\\\['\"])*(?1)|[^,]*)/", $value, $m);
    $vars = array();
    $pagename = '';
    $class = '';
    $style = '';
    $styles = array();
    $title = '';
    $debug = false;
    if ($m) {
        $pagename = $m[0];
        // first arg is page name
        // detect recursive include
        if (in_array($pagename, $included)) {
            if (isset($formatter->recursion) and $formatter->recursion > $max_recursion) {
                return '';
            }
        } else {
            $included[] = $pagename;
        }
        $last = substr($value, strlen($m[0]));
        $i = 1;
        while (isset($last[0])) {
            if (preg_match("/^(?:(?:\\s*,\\s*)(?:([a-zA-Z0-9_-]+)\\s*=\\s*)?(['\"])?((?(2)(?:[^'\"]|\\\\['\"])*(?2)|[^,]*)))/", $last, $m)) {
                $last = substr($last, strlen($m[0]));
                $key = strtolower($m[1]);
                $val = !empty($m[2]) ? substr($m[3], 0, -1) : $m[3];
                // check some built-in vars
                // set style or class
                if (in_array($key, array('style', 'class', 'debug'))) {
                    if (empty($val)) {
                        continue;
                    }
                    if ($key == 'style') {
                        $styles[] = $val;
                    } else {
                        if ($key == 'class') {
                            $class .= ' ' . $val;
                        } else {
                            $debug = true;
                        }
                    }
                    continue;
                }
                if (empty($key) and $i < 3) {
                    if ($i == 1) {
                        $title = $val;
                    } else {
                        $level = intval($val);
                    }
                    $i++;
                    continue;
                }
                if (!empty($key)) {
                    $vars[$key] = $val;
                } else {
                    $vars[$i] = $val;
                }
                $i++;
            } else {
                break;
            }
        }
    }
    if (!isset($pagename[0])) {
        return '';
    }
    // empty page
    // out debug msg;
    $msg = '';
    if ($debug) {
        ob_start();
        var_dump($vars);
        $msg = ob_get_contents();
        ob_end_clean();
    }
    // set title
    if (isset($title[0]) && $title[0] != '=') {
        if (empty($level) || $level > 5) {
            $level = 3;
        }
        $tag = str_repeat('=', $level);
        $title = $tag . ' ' . $title . ' ' . $tag;
    }
    if ($DBInfo->hasPage($pagename)) {
        // default class for template
        if (!empty($vars)) {
            $class .= ' template';
        }
        // add some default variables
        if (!isset($vars['pagename'])) {
            $vars['pagename'] = $formatter->page->name;
        }
        $repl = new _localDict($vars);
        $page = $DBInfo->getPage($pagename);
        $f = new Formatter($page);
        // for recursion detect
        $f->recursion = isset($formatter->recursion) ? $formatter->recursion + 1 : 1;
        $body = $page->_get_raw_body();
        // get raw body
        // mediawiki like replace variables
        // @foo@ or @foo[separator]default value@ are accepted
        // the separator can be space , and |
        $body = $repl->replace('/@([a-z0-9_-]+)(?:(?:,|\\|)((?!\\s)(?:[^@]|@@)*(?!\\s)))?@/', $body);
        if (isset($title[0])) {
            $body = $title . "\n" . $body;
        }
        $params['nosisters'] = 1;
        $f->get_javascripts();
        // trash default javascripts
        ob_start();
        $f->pi['#linenum'] = 0;
        // FIXME
        $f->send_page($body, $params);
        $out = ob_get_contents();
        ob_end_clean();
        if (!empty($class)) {
            $class = ' class="' . $class . '"';
        }
        if (!empty($styles)) {
            $style = ' style="' . implode(';', $styles) . '"';
        }
        return '<div' . $class . $style . '>' . $msg . $out . '</div>';
    } else {
        return $formatter->link_repl($pagename);
    }
}
コード例 #3
0
ファイル: render.php プロジェクト: sedrion/moniwiki
function render($pagename, $type, $params = array())
{
    global $DBInfo;
    $p = $DBInfo->getPage($pagename);
    $opts = array();
    // parameters for mdict
    if ($type == 'mdict') {
        $opts = array('prefix' => 'entry:/');
    }
    $formatter = new Formatter($p, $opts);
    if (isset($params['filters'])) {
        $formatter->filters = $params['filters'];
    }
    // trash javascripts
    $formatter->get_javascripts();
    // init wordrule
    if (empty($formatter->wordrule)) {
        $formatter->set_wordrule();
    }
    // render
    ob_start();
    $formatter->send_page();
    flush();
    $out = ob_get_contents();
    ob_end_clean();
    // filter for mdict
    if ($type == 'mdict') {
        return $formatter->postfilter_repl('mdict', $out);
    } else {
        return $out;
    }
}