function make_heading(&$str, $strip = TRUE) { return Rules::getHeading($str, $strip); }
function plugin_ls2_get_headings($page, &$params, $level, $include = FALSE) { static $_ls2_anchor = 0; // ページが未表示のとき $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0; if (!$is_done) { $params["page_{$page}"] = ++$_ls2_anchor; } $s_page = Utility::htmlsc($page); $wiki = Factory::Wiki($page); $title = $s_page . ' ' . $wiki->passage(false, true); $href = $wiki->uri(); 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>↑</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 ($wiki->get() as $line) { if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) { list($heading, $id) = Rules::getHeading($line); $level = strlen($matches[1]); plugin_ls2_list_push($params, $level + strlen($level)); array_push($params['result'], '<li><a href="' . $href . '#' . $id . '">' . $heading . '</a>'); } else { if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) { plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); } } } }
public function getAnchor($text, $level) { global $top; global $fixed_heading_edited; // Plus! // Heading id (auto-generated) $autoid = 'content_' . $this->id . '_' . $this->count; $this->count++; $anchor = ''; // Heading id (specified by users) list($_text, $id, $level) = Rules::getHeading($text, false); // Cut fixed-anchor from $text //var_dump(Rules::getHeading($text, false)); if (empty($id)) { // Not specified $id = $autoid; } else { if ($fixed_heading_edited) { //$anchor = ' &aname(' . $id . ',super,full){' . $_symbol_anchor . '};'; //if ($fixed_heading_edited) $anchor .= " &edit(,$id);"; $anchor = ' &edit(,' . $id . ');'; } } //var_dump($text, $id, $level); // Add 'page contents' link to its heading $contents = new ContentsList($_text, $level, $id); $this->contents_last = $this->contents_last->add($contents); // Add heding return array($_text . $anchor, $this->count > 1 ? "\n" . $top : '', $autoid); }
function plugin_edit_preview() { global $vars, $_edit_msg; $_msg_preview = T_('To confirm the changes, click the button at the bottom of the page'); $_msg_preview_delete = T_('(The contents of the page are empty. Updating deletes this page.)'); $page = isset($vars['page']) ? $vars['page'] : ''; // Loading template if (isset($vars['template_page']) && $wiki->isValied()) { $wiki = Factory::Wiki($vars['template_page']); $vars['msg'] = $wiki->get(true); // Cut fixed anchors $vars['msg'] = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z0-9][\\w-]+\\](.*)$/m', '$1$2', $vars['msg']); } else { $wiki = Factory::Wiki($page); } $vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']); $postdata = $vars['msg']; // Compat: add plugin and adding contents if (isset($vars['add']) && $vars['add']) { if (isset($vars['add_top']) && $vars['add_top']) { $postdata .= "\n\n" . $wiki->get(true); } else { $postdata = $wiki->get(true) . "\n\n" . $postdata; } } $body = '<p class="alert alert-info">' . $_edit_msg['msg_preview'] . '<br />' . "\n"; if ($postdata == '') { $body .= '<strong>' . $_edit_msg['msg_preview_delete'] . '</strong>'; } $body .= '</p>' . "\n"; if ($postdata) { $postdata = Rules::make_str_rules($postdata); $postdata = explode("\n", $postdata); $postdata = drop_submit(RendererFactory::factory($postdata)); $body .= '<div id="preview">' . $postdata . '</div>' . "\n"; } $body .= Utility::editForm($page, $vars['msg'], $vars['digest'], FALSE); return array('msg' => sprintf($_edit_msg['title_preview'], $page), 'body' => $body); }
/** * ソースからひな形を作成 */ public function auto_template() { global $auto_template_func, $auto_template_rules; if (!$auto_template_func) { return ''; } $source = ''; $matches = array(); foreach ($auto_template_rules as $rule => $template) { $rule_pattrn = '/' . $rule . '/'; if (!preg_match($rule_pattrn, $this->page, $matches)) { continue; } $template_page = preg_replace($rule_pattrn, $template, $this->page); if (!is_page($template_page)) { continue; } // ソースを取得 $source = Factory::Wiki($template_page)->source(); // Remove fixed-heading anchors $source = Rules::removeHeading($source); // Remove '#freeze' $source = preg_replace('/^#freeze\\s*$/m', '', $source); $count = count($matches); for ($i = 0; $i < $count; $i++) { $source = str_replace('$' . $i, $matches[$i], $source); } break; } return $source; }
function plugin_bugtrack_list_pageinfo($page, $no = NULL, $recurse = TRUE) { global $_plugin_bugtrack; if ($no === NULL) { $no = preg_match('/\\/([0-9]+)$/', $page, $matches) ? $matches[1] : 0; } $source = Factory::Wiki($page)->get(); // Check 'moved' page _just once_ $regex = '/move\\s*to\\s*(' . RendererDefines::WIKINAME_PATTERN . '|' . RendererDefines::INTERWIKINAME_PATTERN . '|\\[\\[' . RendererDefines::BRACKETNAME_PATTERN . '\\]\\])/'; $match = array(); if ($recurse && preg_match($regex, $source[0], $match)) { return plugin_bugtrack_list_pageinfo(Utility::stripBracket($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} = Utility::stripBracket(trim($matches[1])); } else { ${$item} = trim($matches[1]); } } else { ${$item} = ''; // Data not found } } if (preg_match("/\\*([^\n]*)/", $body, $matches)) { $summary = Rules::removeHeading($matches[0]); } return array($page, $no, $summary, $name, $priority, $state, $category); }
public static function setLineRules($str) { static $pattern, $replace; $line_rules = Rules::getLineRules(); if (!isset($pattern)) { $pattern = array_map(function ($a) { return '/' . $a . '/'; }, array_keys($line_rules)); $replace = array_values($line_rules); unset($line_rules); } return preg_replace($pattern, $replace, $str); }
public function toString() { list($this->text, $fixed_anchor) = Rules::getHeading($this->text, FALSE); $id = empty($fixed_anchor) ? $this->id : $fixed_anchor; return $this->msg_top . $this->wrap(parent::toString(), 'h' . $this->level, ' id="' . $id . '"'); }