function plugin_ls_convert() { global $vars; $with_title = FALSE; if (func_num_args()) { $args = func_get_args(); $with_title = in_array('title', $args); } $prefix = $vars['page'] . '/'; $page = isset($vars['page']) ? $vars['page'] : ''; $pages = array(); foreach (Auth::get_existpages() as $page) { if (strpos($page, $prefix) === 0) { $pages[] = $page; } } natcasesort($pages); $ls = array(); foreach ($pages as $page) { $comment = ''; if ($with_title) { $array = file_head(get_filename($page), 1); if ($array) { $comment = ' - ' . preg_replace(array('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/S', '/^(?:-+|\\*+)/'), array('$1$2', null), current($array)); } } $ls[] = "-[[{$page}]] {$comment}"; } return RendererFactory::factory($ls); }
function plugin_region_convert() { static $first = 0; // at first call $usage = '<p class="alert alert-warning">#region usage: <code>#region(title){{ content }}</code> or <code>#region([[Pagename#hash]])</code></p>'; $title = $body = ''; $args = func_get_args(); $num = func_num_args(); $title = array_shift($args); if ($num === 1) { // BlacketNameだった場合、そのページをajaxで取得 if (preg_match('/^\\[\\[(.*)\\]\\]$/', $title, $match)) { $ret[] = '<div class="plugin-region clearfix">'; $ret[] = '<div class="plugin-region-title">' . RendererFactory::factory($title) . '</div>'; $ret[] = '<div class="plugin-region-body" data-page="' . $match[1] . '"></div>'; $ret[] = '</div>'; return join("\n", $ret); } } else { if ($num === 2) { $ret[] = '<div class="plugin-region clearfix">'; $ret[] = '<div class="plugin-region-title">' . Utility::htmlsc($title) . '</div>'; $ret[] = '<div class="plugin-region-body">' . RendererFactory::factory(array_pop($args)) . '</div>'; $ret[] = '</div>'; return join("\n", $ret); } } return $usage; }
function plugin_group_convert() { global $_group_msg; $auth_key = Auth::get_user_info(); if (empty($auth_key['group'])) { return ''; } $argv = func_get_args(); $i = count($argv); if ($i < 2) { return <<<EOD <div> \t<label>{$_group_msg['group']}</label>: \t{$auth_key['group']} </div> EOD; } $msg = $argv[$i - 1]; array_pop($argv); if (in_array($auth_key['group'], $argv)) { return RendererFactory::factory(str_replace("\r", "\n", $msg)); } return ''; }
function plugin_preview_action() { global $vars; $page = isset($vars['page']) ? $vars['page'] : ''; $modified = 0; $response = new Response(); if (!empty($page)) { $wiki = Factory::Wiki($page); if ($wiki->isReadable()) { $source = $wiki->get(); array_splice($source, 10); $response->setStatusCode(Response::STATUS_CODE_200); $response->setContent('<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n" . RendererFactory::factory($source)); $headers = Header::getHeaders('text/xml', $wiki->time()); } else { $response->setStatusCode(Response::STATUS_CODE_404); $headers = Header::getHeaders('text/xml'); } } else { $response->setStatusCode(Response::STATUS_CODE_404); $headers = Header::getHeaders('text/xml'); } $response->getHeaders()->addHeaders($headers); header($response->renderStatusLine()); foreach ($response->getHeaders() as $_header) { header($_header->toString()); } echo $response->getBody(); exit; }
function plugin_row_convert() { $argv = func_get_args(); $argc = func_num_args(); $data = array_pop($argv); $fluid = isset($argv) ? 'row' : 'row-fluid'; return '<div class="' . $fluid . '">' . "\n" . RendererFactory::factory($data) . "\n" . '</div>' . "\n"; }
function plugin_nolink_convert() { $argv = func_get_args(); $argc = func_num_args(); if ($argc < 1) { return ''; } $data = $argv[--$argc]; return strip_a(RendererFactory::factory(line2array($data))); }
function plugin_loglist_convert() { global $script, $log; global $vars; global $_loglist_messages; list($kind) = func_get_args(); $kind = empty($kind) ? 'update' : htmlsc($kind, ENT_QUOTES); if (!$log[$kind]['use']) { return $_loglist_messages['not_active']; } if (!empty($log[$kind]['file'])) { $vars['kind'] = $kind; $rc = do_plugin_action('logview'); return $rc['body']; } $dir = log::get_filename($kind, '', ''); $pages = Auth::get_existpages($dir); if (count($pages) == 0) { return $_loglist_messages['msg_not_found']; } $data = array(); foreach ($pages as $_real => $_page) { $data[] = array(filemtime($dir . '/' . $_real), $_page, log_count($kind, $_page)); } usort($data, function ($a, $b) { return $b[0] - $a[0]; }); // D // usort($data,create_function('$a,$b','return $a[0] - $b[0];')); // A //$str_view = $script.'?plugin=logview&kind='.$kind.'&page='; $str_view = get_cmd_uri('logview', $_page, null, array('kind' => $kind)); $rc = ''; $rc .= '|' . $_loglist_messages['fld_UTIME'] . '|' . $_loglist_messages['fld_PAGE'] . '|' . $_loglist_messages['fld_COUNT'] . "|h\n"; foreach ($data as $_line) { $i = 0; foreach ($_line as $_field) { $rc .= '|'; switch ($i) { case 0: $rc .= get_date('Y-m-d H:i:s', $_field) . ' ' . get_passage($_field); continue; case 1: $rc .= '[' . $str_view . rawurlencode($_field) . ' ' . $_field . ']'; continue; default: $rc .= $_field; } $i++; } $rc .= "|\n"; } return RendererFactory::factory($rc); }
/** * convert_html.php */ function convert_html($lines) { //trigger_error('convert_html($lines) is deprecated. Use RendererFactory::factory($lines)', E_USER_DEPRECATED); global $vars, $digest; static $contents_id = 0; // Set digest if (empty($digest) && !empty($vars['page'])) { $digest = Factory::Wiki($vars['page'])->digest(); } if (!is_array($lines)) { $lines = explode("\n", $lines); } return RendererFactory::factory($lines); }
function plugin_links_action() { global $post, $vars, $foot_explain; global $_links_messages, $_string; // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits this'); if (Auth::check_role('readonly')) { Utility::dieMessage($_string['error_prohibit']); } $msg = $_links_messages['title_update']; $admin_pass = empty($post['adminpass']) ? null : $post['adminpass']; if (isset($vars['execute']) && $vars['execute'] === 'true') { if (!Auth::check_role('role_contents_admin') || Auth::login($admin_pass)) { // $force = (isset($post['force']) && $post['force'] === 'on') ? true : false; $links = new Relational(''); $links->init(); return array('msg' => $msg, 'body' => $_links_messages['msg_done']); } else { $msg = $_links_messages['msg_error']; } } $body = RendererFactory::factory(sprintf($_links_messages['msg_usage1'])); $script = Router::get_script_uri(); if (Auth::check_role('role_contents_admin')) { $body .= RendererFactory::factory(sprintf($_links_messages['msg_usage2'])); } $body .= <<<EOD <form method="post" action="{$script}" class="form-inline plugin-links-form"> \t<input type="hidden" name="cmd" value="links" /> \t<input type="hidden" name="execute" value="true" /> EOD; if (Auth::check_role('role_contents_admin')) { $body .= <<<EOD \t<div class="form-group"> \t\t<label for="_p_links_adminpass" class="sr-only">{$_links_messages['msg_adminpass']}</label> \t\t<input type="password" name="adminpass" id="_p_links_adminpass" class="form-control" size="20" value="" placeholder="{$_links_messages['msg_adminpass']}" /> \t</div> EOD; } $body .= <<<EOD \t<!--div class="checkbox"> \t\t<input type="checkbox" name="force" id="_c_force" /> \t\t<label for="_c_force">{$_links_messages['btn_force']}</label> \t</div--> \t<input type="submit" class="btn btn-primary" value="{$_links_messages['btn_submit']}" /> </form> EOD; return array('msg' => $msg, 'body' => $body); }
function plugin_tooltip_action() { global $vars; $term = isset($vars['q']) ? trim($vars['q']) : null; if (empty($term)) { exit; } $glossary = Glossary::getGlossary($term); $glossary_lastmod = Glossary::getGlossaryTime(); // なんども通信するのを防ぐためlastmodを出力 if ($glossary == FALSE) { exit; } $s_glossary = RendererFactory::factory($glossary); Header::writeResponse(Header::getHeaders('text/xml', $glossary_lastmod), 200, '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $s_glossary); }
function plugin_headarea_convert() { global $vars, $headarea, $use_open_uri_in_new_window; static $head = NULL; static $headhtml = NULL; //miko patched // Cached MenuHTML if ($headhtml !== NULL) { return preg_replace('/<ul class="list[^>]*>/', '<ul class="head">', $headhtml); } //miko patched if (func_num_args()) { $args = func_get_args(); if (is_page($args[0])) { $head = $args[0]; } return ''; } $page = $head === NULL ? $headarea : $head; if (HEAD_ENABLE_SUBHEAD) { $path = explode('/', strip_bracket($vars['page'])); while (count($path)) { $_page = join('/', $path) . '/' . HEAD_SUBHEADBAR; if (is_page($_page)) { $page = $_page; break; } array_pop($path); } } if (!is_page($page)) { return ''; // } else if ($vars['page'] == $page) { // return '<!-- #headarea(): You already view ' . htmlsc($page) . ' -->'; } $headtext = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/m', '$1$2', get_source($page)); if (function_exists('convert_filter')) { $headtext = convert_filter($headtext); } $save_newwindow = $use_open_uri_in_new_window; $use_open_uri_in_new_window = 0; $headhtml = RendererFactory::factory($headtext); $use_open_uri_in_new_window = $save_newwindow; $headhtml = str_replace("\n", '', $headhtml); return preg_replace('/<ul class="list[^>]*>/', '<ul class="head">', $headhtml); }
function plugin_legend_convert() { $argv = func_get_args(); $argc = func_num_args(); if ($argc < 1) { return PLUGIN_CODE_USAGE; } $data = $argv[--$argc]; array_pop($argv); $parm = legend_set_parm($argv); if (strlen($data) == 0 || empty($parm['title'])) { return PLUGIN_CODE_USAGE; } // FIXME: // class, style で指定可能であったとしても、ブラウザで正しく処理できるのは、align しかなさそう $align = empty($parm['align']) ? '' : ' class="pull-' . $parm['align'] . '"'; return join("\n", array('<fieldset' . $align . '>', '<legend>' . $parm['title'] . '</legend>', RendererFactory::factory($data), '</fieldset>')); }
function plugin_role_convert() { global $_role_msg; $role = Auth::get_role_level(); if ($role == 0) { return ''; } $argv = func_get_args(); $i = count($argv); if ($i < 2) { return role_list($role); } $msg = $argv[$i - 1]; if (!Auth::is_check_role($argv[0])) { return RendererFactory::factory(str_replace("\r", "\n", $msg)); } return ''; }
function plugin_well_convert() { $title = $body = ''; $type = ''; $num_of_arg = func_num_args(); $args = func_get_args(); switch ($num_of_arg) { default: return '<p class="alert alert-warning">#well{{body}}</p>'; break; case 1: $body = $args[0]; break; } $ret[] = '<div class="well">' . "\n"; $ret[] = RendererFactory::factory($body); $ret[] = '</div>' . "\n"; return join("\n", $ret); }
function plugin_panel_convert() { $title = $body = ''; $type = ''; $num_of_arg = func_num_args(); $args = func_get_args(); switch ($num_of_arg) { default: return '<p class="alert alert-warning">#panel(title[,type]){{body}}</p>'; break; case 1: $body = $args[0]; break; case 2: $title = $args[0]; $body = $args[1]; break; case 3: $title = $args[0]; $type = $args[1]; $body = $args[2]; break; } if (preg_match('/^(primary|info|warning|danger)$/', $type) === 0) { $type = 'default'; } $ret[] = '<div class="panel panel-' . $type . '">'; if (!empty($title)) { $ret[] = '<div class="panel-heading">' . Utility::htmlsc($title) . '</div>'; } else { $body = str_replace(array(chr(0xd) . chr(0xa), chr(0xd), chr(0xa)), "\n", $body); } $ret[] = '<div class="panel-body">' . RendererFactory::factory($body) . '</div>'; $ret[] = '</div>'; return join("\n", $ret); }
function plugin_guiedit_preview() { global $vars; // global $_title_preview, $_msg_preview, $_msg_preview_delete; global $note_hr, $foot_explain; global $guiedit_use_fck; //FIXME $_msg_preview = _('To confirm the changes, click the button at the bottom of the page'); $_msg_preview_delete = _('(The contents of the page are empty. Updating deletes this page.)'); if ($guiedit_use_fck) { $postdata = Xhtml2WikiFactory::factory($vars['msg']); } if ($postdata) { $postdata = make_str_rules($postdata); $postdata = explode("\n", $postdata); $postdata = drop_submit(RendererFactory::factory($postdata, true)); } // テキスト編集の場合 if (!$guiedit_use_fck) { $body = $_msg_preview . '<br />' . "\n"; if ($postdata == '') { $body .= '<strong>' . $_msg_preview_delete . '</strong><br />' . "\n"; } else { $body .= '<br />' . "\n"; $body .= '<div id="preview">' . $postdata . '</div>' . "\n"; } $body .= plugin_guiedit_edit_form($vars['page'], $vars['msg'], $vars['digest'], FALSE); return array('msg' => $_title['preview'], 'body' => $body); } // 注釈 ksort($foot_explain, SORT_NUMERIC); $postdata .= !empty($foot_explain) ? $note_hr . join("\n", $foot_explain) : ''; // 通常の編集フォーム if (DEBUG) { $postdata .= '<hr />' . Utility::editForm($vars['page'], $vars['msg']); } plugin_guiedit_send_ajax($postdata); }
function plugin_csv2newpage_action() { global $vars, $num; $config_name = empty($vars['_config']) ? '' : $vars['_config']; $config = new Config('plugin/tracker/' . $config_name); if (!$config->read()) { return '<p>config file (' . htmlsc($config_name) . ') not found.</p>'; } $config->config_name = $config_name; $source = $config->page . '/page'; $refer = empty($vars['_refer']) ? '' : $vars['_refer']; if (!is_pagename($refer)) { return array('msg' => 'cannot write', 'body' => 'page name (' . htmlsc($refer) . ') is not valid.'); } if (!is_page($source)) { return array('msg' => 'cannot write', 'body' => 'page template (' . htmlsc($source) . ') is not exist.'); } $upload = empty($vars['_upload']) ? 0 : $vars['_upload']; $csvlines = $upload ? plugin_csv2newpage_upload($refer) : plugin_csv2newpage_from_page($refer); $csv_fields = plugin_csv2newpage_extract_fields($csvlines); // ページデータを生成 $postdata_template = join('', get_source($source)); $np = array('*Newpages under [[' . $refer . ']]'); foreach ($csv_fields as $csv_field) { $csv_ct = 1; $ary = array(); foreach ($csv_field as $csv_f) { $key = 'csv_field' . $csv_ct; if (!array_key_exists($key, $vars)) { $csv_ct++; continue; } $tracker_key = trim($vars[$key]); $ary[$tracker_key] = trim($csv_f); // array_push($np, '+' . $tracker_key . ' --- ' . $csv_f); $csv_ct++; } $np_name = plugin_csv2newpage_write($ary, $refer, $postdata_template, $config); $line = join(',', $csv_field); array_push($np, '+' . '[[' . $np_name . ']] ---' . $line); } return array('msg' => 'csv2newpage complete', 'body' => RendererFactory::factory($np)); }
/** * Returns the rendered HTML of a specific version of a Wiki page. * 版を指定してページのHTMLを返す。 * @param string $pagename ページ名 * @param int $version 版 * @return string */ public function getPageHTMLVersion($page, $version) { return RendererFactory::factory(Factory::Backup($page)->get($version)); }
function plugin_side_convert() { global $vars, $sidebar; static $side = NULL; static $sidehtml = NULL; //miko patched // Cached MenuHTML if ($sidehtml !== NULL) { return preg_replace('/<ul class="list[^>]*>/', '<ul class="menu">', $sidehtml); } //miko patched $num = func_num_args(); if ($num > 0) { // Try to change default 'sideBar' page name (only) if ($num > 1) { return '#side(): Zero or One argument needed'; } if ($side !== NULL) { return '#side(): Already set: ' . htmlsc($side); } $args = func_get_args(); if (!is_page($args[0])) { return '#side(): No such page: ' . htmlsc($args[0]); } else { $side = $args[0]; // Set return ''; } } else { // Output sidebar page data $page = $side === NULL ? $sidebar : $side; if (SIDE_ENABLE_SUBMENU) { $path = explode('/', strip_bracket($vars['page'])); while (count($path)) { $_page = join('/', $path) . '/' . SIDE_SUBMENUBAR; if (is_page($_page)) { $page = $_page; break; } array_pop($path); } } $wiki = Factory::Wiki($page); if (!$wiki->has()) { return ''; } else { if ($vars['page'] == $page) { return '<!-- #side(): You already view ' . htmlsc($page) . ' -->'; } else { // Cut fixed anchors $sidetext = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/m', '$1$2', $wiki->get(true)); //miko patched if (function_exists('convert_filter')) { $sidetext = convert_filter($sidetext); } global $top, $use_open_uri_in_new_window; $tmptop = $top; $top = ''; $save_newwindow = $use_open_uri_in_new_window; $use_open_uri_in_new_window = 0; $sidehtml = RendererFactory::factory($sidetext); $top = $tmptop; $use_open_uri_in_new_window = $save_newwindow; $sidehtml = str_replace("\n", '', $sidehtml); return preg_replace('/<ul class="list[^>]*>/', '<ul class="menu">', $sidehtml); //miko patched } } } }
function plugin_include_convert() { global $vars, $get, $post, $menubar, $sidebar; static $included = array(); static $count = 1; $_msg_include_restrict = T_('Due to the blocking, $1 cannot be include(d).'); if (func_num_args() == 0) { return '<p class="alert alert-warning">' . PLUGIN_INCLUDE_USAGE . '</p>' . "\n"; } // $menubar will already be shown via menu plugin if (!isset($included[$menubar])) { $included[$menubar] = TRUE; } // Loop yourself $root = isset($vars['page']) ? $vars['page'] : ''; $included[$root] = TRUE; // Get arguments $args = func_get_args(); // strip_bracket() is not necessary but compatible $page = isset($args[0]) ? array_shift($args) : null; $wiki = Factory::Wiki(Utility::getPageName($page, $root)); $with_title = PLUGIN_INCLUDE_WITH_TITLE; if (isset($args[0])) { switch (strtolower(array_shift($args))) { case 'title': $with_title = TRUE; break; case 'notitle': $with_title = FALSE; break; } } $s_page = Utility::htmlsc($page); $link = '<a href="' . $wiki->uri() . '">' . $s_page . '</a>'; // Read link // I'm stuffed if (isset($included[$page])) { return '<p class="alert alert-warning">#include(): Included already: ' . $link . '</p>' . "\n"; } else { if (!is_page($page)) { return '<p class="alert alert-warning">#include(): No such page: ' . $s_page . '</p>' . "\n"; } else { if ($count > PLUGIN_INCLUDE_MAX) { return '<p class="alert alert-warning">#include(): Limit exceeded: ' . $link . '</p>' . "\n"; } else { ++$count; } } } // One page, only one time, at a time $included[$page] = TRUE; // Include A page, that probably includes another pages $get['page'] = $post['page'] = $vars['page'] = $page; if ($wiki->isReadable()) { $source = $wiki->get($page); preg_replace('/^#navi/', '/\\/\\/#navi/', $source); $body = RendererFactory::factory($source); } else { $body = str_replace('$1', $page, $_msg_include_restrict); } $get['page'] = $post['page'] = $vars['page'] = $root; // Put a title-with-edit-link, before including document if ($with_title) { $link = '<a href="' . $wiki->uri('edit') . '">' . $s_page . '</a>'; if ($page == $menubar || $page == $sidebar) { $body = '<span align="center"><h5 class="side_label">' . $link . '</h5></span><small>' . $body . '</small>'; } else { $body = '<article>' . "\n" . '<h1>' . $link . '</h1>' . "\n" . $body . "\n" . '</article>' . "\n"; } } return $body; }
public function parse($lines) { $this->last =& $this; $matches = array(); while (!empty($lines)) { $line = array_shift($lines); // Escape comments if (substr($line, 0, 2) === '//') { if ($this->is_guiedit) { $this->comments[] = substr($line, 2); $line = '___COMMENT___'; } else { continue; } } // Extend TITLE by miko if (preg_match('/^(TITLE):(.*)$/', $line, $matches)) { global $newtitle; static $newbase; if (!isset($newbase)) { $newbase = trim(Utility::stripHtmlTags(RendererFactory::factory($matches[2]))); // For BugTrack/132. $newtitle = Utility::htmlsc($newbase); } continue; } if (preg_match('/^(LEFT|CENTER|RIGHT|JUSTIFY):(.*)$/', $line, $matches)) { // <div style="text-align:..."> $align = new Align(strtolower($matches[1])); $this->last = $this->last->add($align); if (empty($matches[2])) { continue; } $line = $matches[2]; } $line = rtrim($line, "\t\r\n\v"); // スペース以外の空白文字をトリム // Empty if (empty($line)) { $this->last =& $this; continue; } // Horizontal Rule if (substr($line, 0, 4) == '----') { $hrule = new HRule($this, $line); $this->insert($hrule); continue; } // Multiline-enabled block plugin #plugin{{ ... }} if (preg_match('/^#[^{]+(\\{\\{+)\\s*$/', $line, $matches)) { $len = strlen($matches[1]); $line .= self::MULTILINE_DELIMITER; while (!empty($lines)) { $next_line = preg_replace('/[' . self::MULTILINE_DELIMITER . '\\n]*$/', '', array_shift($lines)); if (preg_match('/\\}{' . $len . '}/', $next_line)) { $line .= $next_line; break; } else { $line .= $next_line .= self::MULTILINE_DELIMITER; } } } // The first character $head = $line[0]; // Heading if ($head === '*') { $heading = new Heading($this, $line); $this->insert($heading); continue; } // Pre if ($head === ' ' || $head === "\t") { $pre = new Pre($this, $line); $this->last = $this->last->add($pre); continue; } // CPre (Plus!) if (substr($line, 0, 2) === '# ' or substr($line, 0, 2) == "#\t") { $sharppre = new SharpPre($this, $line); $this->last = $this->last->add($sharppr); continue; } // Line Break if (substr($line, -1) === '~') { $line = substr($line, 0, -1) . "\r"; } // Other Character if (gettype($this->last) === 'object') { switch ($head) { case '-': $content = new UList($this, $line); break; case '+': $content = new OList($this, $line); break; case '>': case '<': $content = new Blockquote($this, $line); break; // ここからはファクトリークラスを通す // ここからはファクトリークラスを通す case ':': $content = ElementFactory::factory('DList', $this, $line); break; case '|': $content = ElementFactory::factory('Table', $this, $line); break; case ',': $content = ElementFactory::factory('YTable', $this, $line); break; case '#': if ($this->is_guiedit) { $content = ElementFactory::factory('PluginDummy', $this, $line); } else { $content = ElementFactory::factory('Plugin', $this, $line); } break; default: $content = ElementFactory::factory('InlineElement', null, $line); break; } // MathJax Expression if (PluginRenderer::hasPlugin('mathjax')) { $end_mark = ''; // 開始行によって終了行を判定する if (substr($line, 0, 2) === '\\[') { $end_mark = '\\]'; } else { if (substr($line, 0, 6) === '\\begin') { $end_mark = '\\end'; } } if ($end_mark) { while (!empty($lines)) { if (strpos($line, $end_mark) !== false) { break; } $next_line = preg_replace("/[\r\n]*\$/", '', array_shift($lines)); $line .= "\n" . ' ' . $next_line; } $mathjax = new BlockPlugin(array(null, 'mathjax', $line)); $this->last = $this->last->add($mathjax); continue; } } // Default $this->last = $this->last->add($content); unset($content); continue; } } }
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); }
function plugin_menu_convert() { global $vars, $menubar, $menuhtml; static $menu = NULL; //miko patched // Cached MenuHTML // if ($menuhtml !== NULL) // return preg_replace('/<ul class="list[^>]*>/','<ul class="menu">', $menuhtml); //miko patched $num = func_num_args(); if ($num > 0) { // Try to change default 'MenuBar' page name (only) if ($num > 1) { return '<p class="alert alert-warning">#menu(): Zero or One argument needed</p>'; } if ($menu !== NULL) { return '<p class="alert alert-warning">#menu(): Already set: ' . Utility::htmlsc($menu) . '</p>'; } $args = func_get_args(); if (!is_page($args[0])) { return '<p class="alert alert-warning">#menu(): No such page: ' . Utility::htmlsc($args[0]) . '</p>'; } else { $menu = $args[0]; // Set return ''; } } else { // Output menubar page data $page = $menu === NULL ? $menubar : $menu; if (MENU_ENABLE_SUBMENU) { $path = explode('/', strip_bracket($vars['page'])); while (!empty($path)) { $_page = join('/', $path) . '/' . MENU_SUBMENUBAR; if (is_page($_page)) { $page = $_page; break; } array_pop($path); } } $wiki = Factory::Wiki($page); if (!$wiki->has()) { return ''; } else { if ($vars['page'] === $page) { return '<!-- #menu(): You already view ' . htmlsc($page) . ' -->'; } else { // Cut fixed anchors $menutext = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/m', '$1$2', $wiki->get(true)); //miko patched if (function_exists('convert_filter')) { $menutext = convert_filter($menutext); } global $top; $tmptop = $top; $top = ''; $menuhtml = RendererFactory::factory($menutext); $top = $tmptop; $menuhtml = str_replace("\n", '', $menuhtml); return $menuhtml; //return preg_replace('/<ul class="list[^>]*>/','<ul class="menu">',$menuhtml); //miko patched } } } }
function plugin_backup_action() { global $vars, $do_backup, $_string, $_button; global $_backup_messages; if (!$do_backup) { return; } $page = isset($vars['page']) ? $vars['page'] : null; $action = isset($vars['action']) ? $vars['action'] : null; $s_age = isset($vars['age']) && is_numeric($vars['age']) ? $vars['age'] : 0; /** * if page is not set, show list of backup files */ if (!$page) { return array('msg' => $_backup_messages['title_backuplist'], 'body' => plugin_backup_get_list_all()); } $wiki = Factory::Wiki($page); $is_page = $wiki->has(); $s_page = Utility::htmlsc($page); $r_page = rawurlencode($page); $backups = Factory::Backup($page)->get(); $msg = $_backup_messages['msg_backup']; if ($s_age > count($backups)) { $s_age = count($backups); } $body = ''; $wiki->checkReadable(); if ($s_age <= 0) { return array('msg' => $_backup_messages['title_pagebackuplist'], 'body' => plugin_backup_get_list($page)); } $body .= '<div class="panel panel-default">'; $body .= plugin_backup_get_list($page); $body .= '</div>' . "\n"; if ($action) { $data = join("\n", $backups[$s_age]['data']); Auth::is_role_page($data); switch ($action) { case 'delete': /** * 指定された世代を確認。指定されていなければ、一覧のみ表示 */ // checkboxが選択されずにselectdeleteを実行された場合は、削除処理をしない if (!isset($vars['selectages']) && isset($vars['selectdelete'])) { // 選択削除ボタンが押された // 何もしない } else { if (!isset($vars['selectages'])) { // 世代引数がない場合は全削除 return plugin_backup_delete($page); } return plugin_backup_delete($page, $vars['selectages']); } case 'rollback': return plugin_backup_rollback($page, $s_age); break; case 'diff': if (Auth::check_role('safemode')) { Utility::dieMessage($_string['prohibit']); } $title =& $_backup_messages['title_backupdiff']; $past_data = $s_age > 1 ? join("\n", $backups[$s_age - 1]['data']) : ''; Auth::is_role_page($past_data); $body .= plugin_backup_diff($past_data, $data); break; case 'nowdiff': if (Auth::check_role('safemode')) { die_message($_string['prohibit']); } $title =& $_backup_messages['title_backupnowdiff']; $now_data = Factory::Wiki($page)->get(true); Auth::is_role_page($now_data); $body .= plugin_backup_diff($data, $now_data); break; case 'visualdiff': $old = join('', $backups[$s_age]['data']); $now_data = get_source($page, TRUE, TRUE); Auth::is_role_page($now_data); // <ins> <del>タグを使う形式に変更。 $diff = new Diff($data, $now_data); $source = plugin_backup_visualdiff($diff->getDiff()); $body .= drop_submit(RendererFactory::factory($source)); $body = preg_replace('#<p>\\#del(.*?)(</p>)#si', '<del class="remove_block">$1', $body); $body = preg_replace('#<p>\\#ins(.*?)(</p>)#si', '<ins class="add_block">$1', $body); $body = preg_replace('#<p>\\#delend(.*?)(</p>)#si', '$1</del>', $body); $body = preg_replace('#<p>\\#insend(.*?)(</p>)#si', '$1</ins>', $body); // ブロック型プラグインの処理が無いよ~! $body = preg_replace('#&del;#i', '<del class="remove_word">', $body); $body = preg_replace('#&ins;#i', '<ins class="add_word">', $body); $body = preg_replace('#&delend;#i', '</del>', $body); $body = preg_replace('#&insend;#i', '</ins>', $body); $title =& $_backup_messages['title_backupnowdiff']; break; case 'source': if (Auth::check_role('safemode')) { die_message($_string['prohibit']); } $title =& $_backup_messages['title_backupsource']; $body .= '<pre class="sh" data-blush="plain">' . htmlsc($data) . '</pre>' . "\n"; break; default: if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) { die_message(T_('This feature is prohibited')); } else { $title =& $_backup_messages['title_backup']; $body .= drop_submit(RendererFactory::factory($data)); } break; } $msg = str_replace('$2', $s_age, $title); } if (!Auth::check_role('readonly')) { $body .= '<a class="button" href="' . $wiki->uri('backup', $page, null, array('action' => 'delete')) . '">' . str_replace('$1', $s_page, $_backup_messages['title_backup_delete']) . '</a>'; } return array('msg' => $msg, 'body' => $body); }
function plugin_multilang_convert() { $lang = $lines = ''; $args = func_get_args(); $num = func_num_args(); $lines = array_pop($args); switch ($num) { case 1: $lang = DEFAULT_LANG; // pukiwiki.ini.php break; default: list($lang) = func_get_args(); } if (plugin_multilang_accept($lang)) { $lines = preg_replace(array("[\\r|\\n]", "[\\r]"), array("\n", "\n"), $lines); // return preg_replace(array("'<p>'si","'</p>'si"), array("",""), convert_html($lines) ); return '<div lang="' . $lang . '">' . RendererFactory::factory($lines) . '</div>'; } return ''; }
/** * ソース中のリンクを取得 * @param $source Wikiソース * @return array */ private static function getLinkList($source) { static $plugin_pattern, $replacement; // プラグインを無効化するためのマッチパターンを作成 if (empty($plugin_pattern) || empty($replacement)) { foreach (PluginRenderer::getPluginList() as $plugin => $plugin_value) { if ($plugin === 'ref' || $plugin === 'attach' || $plugin === 'attachref') { continue; } // ただしrefやattachは除外(あまりブロック型で使う人いないけどね) $plugin_pattern[] = '/^#' . $plugin . '\\(/i'; $replacement[] = '#null('; } } $ret = array(); // 1行づつ置き換え foreach ($source as $line) { $ret[] = preg_replace($plugin_pattern, $replacement, $line); } $links = array(); // プラグインを無効化したソースをレンダリング $html = RendererFactory::factory($ret); // レンダリングしたソースからリンクを取得 preg_match_all(self::HTML_URI_MATCH_PATTERN, $html, $links, PREG_PATTERN_ORDER); unset($html); return array_unique($links[1]); }
/** * 役割のあるページか * @global type $check_role * @param type $lines * @return boolean */ public static function is_role_page($lines) { global $check_role; if (!$check_role) { return FALSE; } $cmd = self::use_plugin('check_role', $lines); if ($cmd === FALSE) { return FALSE; } RendererFactory::factory($cmd); // die(); return TRUE; }
function plugin_pcomment_get_comments($page, $count, $dir, $reply) { // global $_msg_pcomment_restrict; $wiki = Factory::Wiki($page); if (!$wiki->has()) { return array('', 0); } if (!$wiki->isReadable()) { return array(str_replace('$1', $page, T_('Due to the blocking, no comments could be read from $1 at all.')), 0); } // $reply = (! PKWK_READONLY && $reply); // Suprress radio-buttons $reply = !Auth::check_role('readonly') && $reply; // Suprress radio-buttons $data = preg_replace('/^#pcomment\\(?.*/i', '', $wiki->get()); // Avoid eternal recurse if (!is_array($data)) { return array('', 0); } // Get latest N comments $num = $cnt = 0; $cmts = $matches = array(); if ($dir) { $data = array_reverse($data); } foreach ($data as $line) { if ($count > 0 && $dir && $cnt == $count) { break; } if (preg_match('/^(\\-{1,2})(?!\\-)(.+)$/', $line, $matches)) { if ($count > 0 && strlen($matches[1]) == 1 && ++$cnt > $count) { break; } // Ready for radio-buttons if ($reply) { ++$num; $cmts[] = $matches[1] . "" . $num . "" . md5($matches[2]) . "" . $matches[2] . "\n"; continue; } } $cmts[] = $line; } $data = $cmts; if ($dir) { $data = array_reverse($data); } unset($cmts, $matches); // Remove lines before comments while (!empty($data) && substr($data[0], 0, 1) != '-') { array_shift($data); } $comments = RendererFactory::factory($data); unset($data); // Add radio buttons if ($reply) { $comments = preg_replace('/<li>' . "" . '(\\d+)' . "" . '(.*)' . "" . '(.*)/', '<li class="pcomment_comment radio"><label><input type="radio" name="reply" value="$2" tabindex="$1" />$3</label>', $comments); } return array($comments, $wiki->digest()); }
function plugin_table_edit2_convert() { global $vars, $edit_auth, $edit_auth_pages; static $number = array(); $line_count = 1; $table_end = 0; $table_sub_num = 1; $column_sum_or_avg = 0; $page = isset($vars['page']) ? $vars['page'] : null; if (!isset($number[$page])) { $number[$page] = 1; } if (empty($page)) { return; } $wiki = Factory::Wiki($page); $count = $number[$page]++; $r_page = rawurlencode($page); // 初期設定 $opt = array('abs_m' => FALSE, 'add_show' => '0', 'comma' => null, 'column' => null, 'csv_select' => null, 'dot' => '0', 'edit' => 'on', 'pagenate' => false, 'row' => null, 'setting' => null, 'table_num' => null, 'table_mod' => 'off', 'td_edit' => 'on', 'tr_edit' => 'on'); $auth_chk = Auth::check_auth(); foreach ($edit_auth_pages as $key => $val) { $opt['edit'] = preg_match($key, $page) && $edit_auth && empty($auth_chk) ? 'off' : 'on'; } $head_button = ''; $body = ''; $body_table = ''; $args = func_get_args(); // データー $arg = substr(end($args), -1) == "\r" ? array_pop($args) : null; // 設定変数で上書き foreach ($args as $opt_key) { if (strpos($opt_key, "=") !== false) { list($key, $val) = explode('=', strtolower($opt_key)); $opt[$key] = Utility::htmlsc($val); } } // 読み込み専用の時やページが凍結されている場合は編集不可 if (Auth::check_role('readonly') || is_freeze($page)) { $opt['edit'] = 'off'; } // plugin setting if ((empty($arg) || $opt['setting'] === 'on') && $opt['edit'] !== 'off' && !isset($opt['csv'])) { $set = new TableEdit2Setting($page, $count); $set->table_data = empty($arg) ? 0 : 1; return $set->form($opt); } // csv if (($opt['csv_select'] === 'import' || $opt['csv_select'] === 'export' || array_search('import', $args) !== FALSE) && $opt['edit'] !== 'off') { $csv = new TableEdit2Csv(Utility::htmlsc($page), $count); return $csv->set_csv($opt['csv_select']); } // calc on off $opt['calc'] = isset($opt['calc']) ? PLUGIN_TABLE_EDIT2_CALC : 0; $calc_chk = ""; if ($opt['calc'] === 1) { $calc = new TableEdit2Calc(); $calc_chk = 'on'; } //td edit if (PLUGIN_TABLE_EDIT2_TD_SHOW === TRUE) { $td_edit = $opt['td_edit'] === 'off' ? 0 : 1; $td_edit_chk = $opt['td_edit'] === 'on' ? 1 : 0; } else { $td_edit = 0; } //tr edit if (PLUGIN_TABLE_EDIT2_TR_SHOW === TRUE) { $tr_edit = $opt['tr_edit'] === 'off' ? 0 : 1; $tr_edit_chk = $opt['tr_edit'] === 'on' ? 1 : 0; } else { $tr_edit = 0; } if ($opt['edit'] !== 'off') { // 編集モードが有効な場合 $tei = new TableEdit2Indicate($r_page, $count); // ロック/アンロックボタンを表示 if ($opt['table_mod'] !== 'off') { if (isset($opt['csv'])) { $tei->csv_button($opt['csv']); } $head_button = $tei->open_close($opt['table_mod'], $opt['edit'] === 'on' ? 'lock' : 'unlock'); if ($opt['table_mod'] === 'unlock') { $td_edit = $tr_edit = 0; } } } $arg = preg_replace(array("[\\r|\\n]", "[\\r]"), array("\n", "\n"), $arg); $args = explode("\n", $arg); if ($opt['edit'] !== 'off' || $calc_chk === 'on' || isset($opt['edit'])) { $editon_or_calcon = 1; //06.09.19 } $table_header = 0; foreach ($args as $args_line) { $table_f_chose = preg_match('/^\\|(.+)\\|([hHfFcC]?)$/', $args_line, $matches) ? 1 : 0; if (isset($args_line[0]) && $args_line[0] === ',') { $table_f_chose = 2; } if ($table_f_chose && $editon_or_calcon) { if ($table_f_chose === 1) { $match_cells = explode("|", $matches[1]); } elseif ($table_f_chose === 2) { $match_cells = csv_explode(',', substr($args_line, 1)); $matches = array(1 => join('|', $match_cells), 2 => ''); } if ($line_count === 1) { $r_cell_count = count($match_cells); } //06.11.17 sort $opt['row'] = isset($opt['row']) ? $opt['row'] : ''; $opt['column'] = isset($opt['column']) ? $opt['column'] : ''; if ($calc_chk == 'on') { if (strtolower($matches[2]) == "c") { $calc->cell_format = ''; } $calc->line_count = $line_count; $calc->comma = isset($opt['comma']) ? ',' : ''; $calc->dot = isset($opt['dot']) ? $opt['dot'] : ''; $calc->c_format = isset($opt['format_c']) ? $calc->opt_c($opt['format_c'], $r_cell_count) : array_fill(0, $r_cell_count + 1, TRUE); $calc->m_abs = isset($opt['abs_m']) ? $opt['abs_m'] : ''; $calc->c_abs = isset($opt['abs_c']) ? $calc->opt_c($opt['abs_c'], $r_cell_count) : array_fill(0, $r_cell_count + 1, FALSE); $calc->row = $opt['row']; $calc->column = $opt['column']; $calc->calc($match_cells); $calc->calc_row(); $cell_count_max = $calc->cell_count; $body_table .= $calc->body_table; } else { $body_table .= '|' . $matches[1] . '|'; } if ($opt['edit'] != 'off' && $tr_edit) { //edit if ($tr_edit_chk || $opt['tr_edit'] == 'edit') { $body_table .= $tei->inline('show', $count, $line_count); } if ($tr_edit_chk || $opt['tr_edit'] == 'add') { $body_table .= $tei->inline('tr', $count, $line_count); } $body_table .= '|'; } $body_table .= $matches[2] . "\n"; $line_count++; $table_end = 1; $table_header = 1; } elseif (substr($args_line, 0, 2) != '//') { if ($table_header === 1 && $opt['edit'] !== 'off' && $td_edit) { //td edit and add 06.09.16 $cell_count = 1; $table_line_count = $line_count - 1; $body .= '|'; foreach ($match_cells as $cell) { $body .= '~'; if ($td_edit_chk || $opt['td_edit'] == 'edit') { $body .= $tei->inline('tdshow', $count, $table_line_count, $table_sub_num, $cell_count); } if ($td_edit_chk || $opt['td_edit'] == 'add') { $body .= $tei->inline('td', $count, $table_line_count, $table_sub_num, $cell_count); } $body .= '|'; $cell_count++; } $table_sub_num++; if ($calc_chk == 'on' && ($opt['row'] === 'sum' || $opt['row'] === 'average')) { $body .= "|"; } $body .= $tr_edit ? '|' : ''; $body .= "h\n" . $body_table; $body_table = ''; $table_header = 0; } else { $body .= $body_table; $body_table = ''; } if ($calc_chk == 'on' && ($opt['column'] === 'sum' || $opt['column'] === 'average')) { $column_sum_or_avg = 1; } if ($table_end && $column_sum_or_avg) { //column $cell_calc = ''; $body .= '|'; $body .= $calc->calc_column($cell_count_max); $body .= $opt['edit'] == 'on' && $tr_edit ? '|' : ''; $body .= "\n"; $table_end = 0; } $body .= $args_line . "\n"; } } $body = RendererFactory::factory($body); if ($opt['pagenate'] !== false) { preg_replace('/data-pagenate="false"/', 'data-pagenate="true"', $body); } $sortable = 'true'; $sorter = ""; $filter = isset($opt['filter']) ? $opt['filter'] : ''; if (isset($opt['sort']) && !$td_edit) { $sort = new TableEdit2Sort(); $sort->sort($opt['sort'], $r_cell_count); $sorter = '[' . $sort->sortabletableso . ']'; $sortable = 'true'; } $body = $head_button . $body; return preg_replace('/<table class="table table-bordered"/', '<table class="table table-bordered table_edit" data-auto-width="false" data-sortable="' . $sortable . '" data-sort="' . $sorter . '" data-filter="' . $filter . '" ', $body); }
function adm_auth_wkgrp_check() { global $_adm_auth_wkgrp_msg; $msg = $_adm_auth_wkgrp_msg['msg_chk_1'] . adm_auth_wkgrp_file2page(); return RendererFactory::factory($msg) . adm_auth_wkgrp_add_btn(); }