Пример #1
0
 /**
  * Get heading strings from a wiki source line
  *
  * *** Heading Strings ((footnotes)) [id]
  *   -> array("Heading Strings", "id")
  *
  * @param string $line a wiki source line
  * @param bool   $strip cut footnotes
  * @return array [0] heading string [1] a fixed-heading anchor
  * @uses lib/html.php#make_heading
  */
 function get_heading($line, $strip = TRUE)
 {
     global $NotePattern;
     $id = make_heading($line, FALSE);
     // $line is modified inside
     if ($strip) {
         $line = preg_replace($NotePattern, '', $line);
         // cut footnotes
     }
     return array($line, $id);
 }
Пример #2
0
 function format_cell($value)
 {
     make_heading($value);
     return $value;
 }
 function fixed_anchor()
 {
     $pages = $this->get_pages();
     $done = array();
     foreach ($pages as $page) {
         $do = false;
         $lines = get_source($page);
         foreach ($lines as $i => $line) {
             // multiline plugin. refer lib/convert_html
             if (defined('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK') && PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK === 0) {
                 $matches = array();
                 if ($multiline < 2) {
                     if (preg_match('/^#([^\\(\\{]+)(?:\\(([^\\r]*)\\))?(\\{*)/', $line, $matches)) {
                         $multiline = strlen($matches[3]);
                     }
                 } else {
                     if (preg_match('/^\\}{' . $multiline . '}$/', $line, $matches)) {
                         $multiline = 0;
                     }
                     continue;
                 }
             }
             if (preg_match($this->def_headline, $line, $matches)) {
                 $anchor = make_heading($line, FALSE);
                 if ($anchor === '') {
                     $do = true;
                     break;
                 }
             }
         }
         if ($do) {
             $source = join('', $lines);
             page_write($page, $source, true);
             // ->make_str_rules -> generate_fixed_heading_ancher_id
             // chown also
             $done[] = $page;
         }
     }
     $body = '<p>';
     $body .= '<b>Created fixed_heading anchors for followings:</b><br />';
     foreach ($done as $page) {
         $link = make_pagelink($page);
         $body .= $link . "<br />\n";
     }
     $body .= '</p>';
     return $body;
 }
Пример #4
0
function plugin_bugtrack_list_pageinfo($page, $no = NULL, $recurse = TRUE)
{
    global $WikiName, $InterWikiName, $BracketName, $_plugin_bugtrack;
    if ($no === NULL) {
        $no = preg_match('/\\/([0-9]+)$/', $page, $matches) ? $matches[1] : 0;
    }
    $source = get_source($page);
    // Check 'moved' page _just once_
    $regex = "/move\\s*to\\s*({$WikiName}|{$InterWikiName}|\\[\\[{$BracketName}\\]\\])/";
    $match = array();
    if ($recurse && preg_match($regex, $source[0], $match)) {
        return plugin_bugtrack_list_pageinfo(strip_bracket($match[1]), $no, FALSE);
    }
    $body = join("\n", $source);
    foreach (array('summary', 'name', 'priority', 'state', 'category') as $item) {
        $regex = '/-\\s*' . preg_quote($_plugin_bugtrack[$item], '/') . '\\s*:(.*)/';
        if (preg_match($regex, $body, $matches)) {
            if ($item == 'name') {
                ${$item} = strip_bracket(trim($matches[1]));
            } else {
                ${$item} = trim($matches[1]);
            }
        } else {
            ${$item} = '';
            // Data not found
        }
    }
    if (preg_match("/\\*([^\n]*)/", $body, $matches)) {
        $summary = $matches[1];
        make_heading($summary);
    }
    return array($page, $no, $summary, $name, $priority, $state, $category);
}
function plugin_contents2_1_get_headings($page, &$params)
{
    static $_contents2_1_anchor = 0;
    // すでにこのページの見出しを表示したかどうかのフラグ
    $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0;
    if (!$is_done) {
        $params["page_{$page}"] = ++$_contents2_1_anchor;
    }
    // include ページの場合
    if ($params['page_anchor_counter'] > 1) {
        // 表示済み
        if ($is_done) {
            $params['page_anchor_counter']--;
            return;
        }
        // 標準 #include プラグインにはアンカーはつかないのでこのアンカーリンクは機能しない。
        // 自作プラグイン/include2.inc.php はこれに対応しています。
        $id = '#' . plugin_contents2_1_pageanchor($page);
        // include ページ名のレベルは0
        $level = 0;
        $link_string = htmlspecialchars($page);
        $title = $link_string . ' ' . get_pg_passage($page, false);
        plugin_contents2_1_push2result($page, &$params, $level, $page, $id, $title, $link_string);
    }
    $anchor_counter = PLUGIN_CONTENTS2_1_ANCHOR_ORIGIN;
    $matches = array();
    foreach (get_source($page) as $line) {
        // include ページにある #contents2_1 は呼び出しの #contents2_1 とは明らかに違うやつなので
        // include ページに対しては fromhere 検索すらしない(無論見出しも)。
        // ただ $params['page_anchor_counter'] のために #include を辿って #include の数は数えないといけない。
        // fixed_anchor=false だとしても fixed_anchor がまだ作られていないページである可能性があるのでやはり数えないといけない。
        if ($params['fromhere'] && !$params['fromhere_detected'] && $params['page_anchor_counter'] > 1) {
            if ($params['include'] && preg_match('/^#include.*\\((.+)\\)/', $line, $matches) && is_page($matches[1])) {
                $params['page_anchor_counter']++;
                plugin_contents2_1_get_headings($matches[1], $params);
            }
            continue;
        }
        // fromhere 判定。まだ見つかっていない場合は何もしない
        if ($params['fromhere'] && !$params['fromhere_detected'] && ($params['fromhere_detected'] = preg_match('/^#contents2\\_1/', $line, $matches))) {
            // do nothing
        } elseif (preg_match('/^(\\*{1,3})/', $line, $matches)) {
            // アンカー文字列をつくる。$anchor_counter++ が重要。
            $id = PLUGIN_CONTENTS2_1_ANCHOR_PREFIX . $params['page_anchor_counter'] . '_' . $anchor_counter++;
            // fromhere がまだ見つかっていなければ $anchor_counter++ だけして continue。
            if ($params['fromhere'] && !$params['fromhere_detected']) {
                continue;
            }
            // 見出しレベルは1以降
            $level = strlen($matches[1]);
            // $line は 'remove footnotes and HTML tags' される。見出し行の固定アンカーが返される。
            $fixed_id = make_heading($line);
            if ($params['fixed_anchor'] && $fixed_id !== '') {
                $id = '#' . $fixed_id;
            }
            // 自動アンカーがつく設定の場合の [#438239] の前に勝手に挿入される空白が make_heading ではまだ残るようなので。
            $title = $link_string = trim($line);
            plugin_contents2_1_push2result($line, &$params, $level, $page, $id, $title, $link_string);
            // number 判定。制限を越えていれば抜けて終了。
            if ($params['number'] != '' && $params['number_counter'] >= $params['number']) {
                break;
            }
        } elseif ($params['include'] && preg_match('/^#include.*\\((.+)\\)/', $line, $matches) && is_page($matches[1])) {
            $params['page_anchor_counter']++;
            plugin_contents2_1_get_headings($matches[1], $params);
        }
    }
}
Пример #6
0
 /**
  * Get heading strings from a wiki source line
  *
  * PukiWiki API Extension
  *
  * <code>
  * *** Heading Strings ((footnotes)) [id]
  *   -> array("Heading Strings", "id")
  * </code>
  *
  * @access public
  * @static
  * @param string $line a wiki source line
  * @param bool   $strip cut footnotes
  * @return array [0] heading string [1] a fixed-heading anchor
  * @uses lib/html.php#make_heading
  * @version $Id: v 1.1 2008-06-05 11:14:46 sonots $
  */
 function make_heading($line, $strip = true)
 {
     global $NotePattern;
     $id = make_heading($line, false);
     // $line is modified inside
     if ($strip) {
         $line = preg_replace($NotePattern, '', $line);
         // cut footnotes
     }
     $line = trim($line);
     return array($line, $id);
 }
Пример #7
0
 function format_cell($str)
 {
     make_heading($str);
     return $str;
 }
Пример #8
0
 function Contents_UList($text, $level, $id)
 {
     // Reformatting $text
     // A line started with "\n" means "preformatted" ... X(
     make_heading($text);
     $text = "\n" . '<a href="#' . $id . '">' . $text . '</a>' . "\n";
     parent::ListContainer('ul', 'li', '-', str_repeat('-', $level));
     $this->insert(Factory_Inline($text));
 }
Пример #9
0
function plugin_ls2_get_headings($page, &$params, $level, $include = FALSE)
{
    global $script;
    static $_ls2_anchor = 0;
    // ページが未表示のとき
    $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0;
    if (!$is_done) {
        $params["page_{$page}"] = ++$_ls2_anchor;
    }
    $r_page = rawurlencode($page);
    $s_page = htmlsc($page);
    $title = $s_page . ' ' . get_pg_passage($page, FALSE);
    $href = $script . '?cmd=read&amp;page=' . $r_page;
    plugin_ls2_list_push($params, $level);
    $ret = $include ? '<li>include ' : '<li>';
    if ($params['title'] && $is_done) {
        $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> ';
        $ret .= '<a href="#list_' . $params["page_{$page}"] . '"><sup>&uarr;</sup></a>';
        array_push($params['result'], $ret);
        return;
    }
    $ret .= '<a id="list_' . $params["page_{$page}"] . '" href="' . $href . '" title="' . $title . '">' . $s_page . '</a>';
    array_push($params['result'], $ret);
    $anchor = PLUGIN_LS2_ANCHOR_ORIGIN;
    $matches = array();
    foreach (get_source($page) as $line) {
        if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) {
            $id = make_heading($line);
            $level = strlen($matches[1]);
            $id = PLUGIN_LS2_ANCHOR_PREFIX . $anchor++;
            plugin_ls2_list_push($params, $level + strlen($level));
            array_push($params['result'], '<li><a href="' . $href . $id . '">' . $line . '</a>');
        } else {
            if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) {
                plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE);
            }
        }
    }
}
Пример #10
0
function plugin_ls2_1_get_headings($page, &$params, $level = 1, $include = false, $prefix, $top_level = 1, &$pages)
{
    global $script;
    static $_ls2_anchor = 0;
    // すでにこのページの見出しを表示したかどうかのフラグ
    $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0;
    if (!$is_done) {
        $params["page_{$page}"] = ++$_ls2_anchor;
    }
    $s_page = htmlspecialchars($page);
    $title = $s_page . ' ' . get_pg_passage($page, false);
    $r_page = rawurlencode($page);
    $href = $script . '?' . $r_page;
    // relative オプション。リンク名制御。
    if ($params['relative']) {
        // パターンの最後の / 以下を取り除く。例) sample/test/d -> sample/test
        // $prefix_dir = preg_replace('/[^\/]+$/','',$prefix);
        if (($pos = strrpos($prefix, '/')) !== false) {
            $prefix_dir = substr($prefix, 0, $pos + 1);
        }
        // ページ名からそのパターンをとり除く。
        // $s_page = ereg_replace("^$prefix_dir",'',$s_page);
        $s_page = substr($s_page, strlen($prefix_dir));
        // relative オプションと hierarchy オプションが同時に指定された場合は
        // パターンを取り除くだけでなく、上位の存在しているページ名も取り除く。
        if ($params['display'] == 'hierarchy') {
            $tmp = $s_page;
            // depth オプションが指定されていた場合 $top_level が変わります。
            while (substr_count($tmp, "/") > $top_level - 1) {
                // 一階層ずつとりのぞく
                if (($pos = strrpos($tmp, '/')) !== false) {
                    $tmp = substr($tmp, 0, $pos);
                }
                // 上位のページが存在していれば、その文字列を取り除き、相対名にする。
                if (in_array($prefix_dir . $tmp, $pages)) {
                    // $s_page = ereg_replace("^$tmp/",'',$s_page);
                    $s_page = substr($s_page, strlen("{$tmp}/"));
                    break;
                }
            }
        }
    }
    // date オプション。更新日時の追加。
    $date = '';
    if ($params['date']) {
        $date = format_date(get_filetime($page));
    }
    // new オプション。New! 表示の追加。
    $new = '';
    if ($params['new']) {
        global $_plugin_new_elapses;
        $timestamp = get_filetime($page) - LOCALZONE;
        $erapse = UTIME - $timestamp;
        foreach ($_plugin_new_elapses as $limit => $tag) {
            if ($erapse <= $limit) {
                $new .= sprintf($tag, get_passage($timestamp));
                break;
            }
        }
    }
    plugin_ls2_1_list_push($params, $level);
    // LI TAG. display オプションに依る。plugin_ls2_1_list_push にも。
    if ($params['display'] == 'inline') {
        $litag = '';
    } else {
        $litag = '<li>';
    }
    array_push($params['result'], $litag);
    // include されたページの場合
    if ($include) {
        $ret = 'include ';
    } else {
        $ret = '';
    }
    // すでに表示済みなら必ずファイル内探索処理はせずに抜ける
    if ($is_done) {
        $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> ';
        $ret .= '<a href="#list_' . $params["page_{$page}"] . '"><sup>&uarr;</sup></a>';
        array_push($params['result'], $ret);
        return;
    }
    $ret .= '<a id="list_' . $params["page_{$page}"] . '" href="' . $href . '" title="' . $title . '">' . $s_page . '</a>';
    if ($date != '') {
        $ret .= " {$date}";
    }
    if ($new != '') {
        $ret .= " {$new}";
    }
    array_push($params['result'], $ret);
    // title オプション、include オプション時はファイル内探索もする
    if ($params['title'] || $params['include']) {
        $anchor = PLUGIN_LS2_1_ANCHOR_ORIGIN;
        $matches = array();
        // 全体で title_number 個ではなく各ファイル単位で title_number 個
        $title_counter = 0;
        foreach (get_source($page) as $line) {
            if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) {
                if ($params['title_number']) {
                    // ただの件数制限なので途中で抜けても $anchor には不整合はでないはず
                    if ($title_counter >= $params['title_number']) {
                        if (!$params['include']) {
                            break;
                        } else {
                            continue;
                        }
                    }
                    $title_counter++;
                }
                // $line は 'remove footnotes and HTML tags' される。見出し行のアンカーが返されるが正直いらない。
                $id = make_heading($line);
                $hlevel = strlen($matches[1]);
                $id = PLUGIN_LS2_1_ANCHOR_PREFIX . $anchor++;
                plugin_ls2_1_list_push($params, $level + $hlevel);
                array_push($params['result'], $litag);
                array_push($params['result'], '<a href="' . $href . $id . '">' . $line . '</a>');
            } else {
                if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) {
                    plugin_ls2_1_get_headings($matches[1], $params, $level + $hlevel + 1, true, $prefix, $top_level, $pages);
                }
            }
        }
    }
}