Exemplo n.º 1
0
 public function setPattern($arr, $page)
 {
     global $foot_explain, $vars;
     list(, $body) = $this->splice($arr);
     // Recover of notes(miko)
     if (count($foot_explain) === 0) {
         self::$note_id = 0;
     }
     $script = !self::ALLOW_RELATIVE_FOOTNOTE_ANCHOR ? Factory::Wiki($page)->uri() : '';
     $id = ++self::$note_id;
     $note = InlineFactory::factory($body);
     $page = isset($vars['page']) ? rawurlencode($vars['page']) : null;
     // Footnote
     $foot_explain[$id] = '<li id="notefoot_' . $id . '">' . '<a href="' . $script . '#notetext_' . $id . '" class="note_super">' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</a>' . $note . '</li>';
     if (!IS_MOBILE) {
         // A hyperlink, content-body to footnote
         if (!is_numeric(self::FOOTNOTE_TITLE_MAX) || self::FOOTNOTE_TITLE_MAX <= 0) {
             $title = '';
         } else {
             $title = strip_tags($note);
             $count = mb_strlen($title, SOURCE_ENCODING);
             $title = mb_substr($title, 0, self::FOOTNOTE_TITLE_MAX, SOURCE_ENCODING);
             $abbr = mb_strlen($title) < $count ? '...' : '';
             $title = ' title="' . $title . $abbr . '"';
         }
         $name = '<a id="notetext_' . $id . '" href="' . $script . '#notefoot_' . $id . '" class="note_super"' . $title . '>' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</a>';
     } else {
         // モバイルは、ツールチップで代用
         $name = '<span class="note_super" aria-describedby="tooltip" data-msgtext="' . strip_tags($note) . '">' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</span>';
     }
     return parent::setParam($page, $name, $body);
 }
Exemplo n.º 2
0
function replace_do($search, $replace, $notimestamp)
{
    global $cycle, $cantedit;
    global $_replace_msg;
    // パスワードが合ってたらいよいよ置換
    $pages = Auth::get_existpages();
    $replaced_pages = array();
    foreach ($pages as $page) {
        $wiki = Factory::Wiki($page);
        if ($wiki->isEditable(false, REPLACE_IGNORE_FREEZE)) {
            // パスワード一致
            $postdata = array();
            foreach ($wiki->get() as $line) {
                // キーワードの置換
                $postdata[] = str_replace($search, $replace, $line);
            }
            if (md5(join("\n", $postdata)) !== $wiki->digest()) {
                $cycle = 0;
                set_time_limit(30);
                $wiki->set($postdata, $notimestamp);
                $replaced_pages[] = '<li><a href="' . $wiki->uri() . '">' . Utility::htmlsc($page) . '</a></li>';
            }
        }
    }
    $vars['cmd'] = 'read';
    if (count($replaced_pages) == 0) {
        return array('msg' => $_replace_msg['msg_H0_no_data'], 'body' => '<p class="alert alert-danger">' . $_replace_msg['msg_no_replaced'] . '</p>');
    }
    return array('msg' => $_replace_msg['msg_H0_replaced'], 'body' => '<p class="alert alert-success">' . $_replace_msg['msg_replaced'] . '</p>' . "\n" . '<ul>' . join("\n", $replaced_pages) . '</ul>');
}
Exemplo n.º 3
0
function plugin_splitinclude_convert()
{
    global $vars, $get, $post;
    global $_msg_splitinclude_restrict;
    static $splitinclude_list = array();
    //処理済ページ名の配列
    if (func_num_args() == 0) {
        return;
    }
    $splitinclude_list[$vars['page']] = TRUE;
    $func_vars_num = func_num_args();
    $func_vars_array = func_get_args();
    $incbody = "";
    foreach ($func_vars_array as $page) {
        $page = strip_bracket($page);
        if (!is_page($page) or isset($splitinclude_list[$page])) {
            return '';
        }
        $splitinclude_list[$page] = TRUE;
        $_page = $vars['page'];
        $get['page'] = $post['page'] = $vars['page'] = $page;
        $wiki = Factory::Wiki($page);
        // splitincludeのときは、認証画面をいちいち出さず、後始末もこちらでつける
        if ($wiki->isReadable()) {
            $body = $wiki->render();
        } else {
            $body = str_replace('$1', $page, $_msg_splitinclude_restrict);
        }
        $get['page'] = $post['page'] = $vars['page'] = $_page;
        $incbody .= "<div style=\"width:" . intval(96 / $func_vars_num) . "%;margin:0px 2px;vartical-align:top;float:left;\">{$body}</div>\n";
    }
    $incbody = "<div style=\"width:100%\">\n{$incbody}</div>\n<div style=\"display:block;\"></div>\n";
    return $incbody;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
function plugin_memo_action()
{
    global $vars, $cols, $rows, $_string;
    //	global $_title_collided, $_msg_collided, $_title_updated;
    $_title_collided = $_string['title_collided'];
    $_title_updated = $_string['updated'];
    $_msg_collided = $_string['msg_collided'];
    // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    if (Auth::check_role('readonly')) {
        die_message('PKWK_READONLY prohibits editing');
    }
    if (!isset($vars['msg']) || $vars['msg'] == '') {
        return;
    }
    $memo_body = preg_replace('/' . "\r" . '/', '', $vars['msg']);
    $memo_body = str_replace("\n", '\\n', $memo_body);
    $memo_body = str_replace('"', '&#x22;', $memo_body);
    // Escape double quotes
    $memo_body = str_replace(',', '&#x2c;', $memo_body);
    // Escape commas
    $wiki = Factory::Wiki($vars['refer']);
    $postdata = array();
    $memo_no = 0;
    foreach ($wiki->get() as $line) {
        if (preg_match('/^#memo\\(?.*\\)?$/i', $line)) {
            if ($memo_no == $vars['memo_no']) {
                $postdata[] = '#memo(' . $memo_body . ')' . "\n";
                $line = '';
            }
            ++$memo_no;
        }
        $postdata[] = $line;
    }
    $postdata_input = $memo_body . "\n";
    $body = '';
    if ($wiki->digest() !== $vars['digest']) {
        $title = $_title_collided;
        $body = $_msg_collided . "\n";
        $s_refer = Utility::htmlsc($vars['refer']);
        $s_digest = Utility::htmlsc($vars['digest']);
        $s_postdata_input = Utility::htmlsc($postdata_input);
        $script = get_script_uri();
        $body .= <<<EOD
<form action="{$script}" method="post" class="plugin-memo-form">
\t<input type="hidden" name="cmd" value="preview" />
\t<input type="hidden" name="refer"  value="{$s_refer}" />
\t<input type="hidden" name="digest" value="{$s_digest}" />
\t<textarea name="msg" rows="{$rows}" cols="{$cols}" class="form-control">{$s_postdata_input}</textarea>
</form>
EOD;
    } else {
        $wiki->set($postdata);
        $title = $_title_updated;
    }
    $retvars['msg'] =& $title;
    $retvars['body'] =& $body;
    $vars['page'] = $vars['refer'];
    return $retvars;
}
Exemplo n.º 6
0
function plugin_read_action()
{
    global $vars, $_read_msg;
    $page = isset($vars['page']) ? Utility::stripBracket($vars['page']) : null;
    $ret = array('msg' => null, 'body' => null);
    $id = isset($vars['id']) ? $vars['id'] : null;
    if (!$page) {
        return $ret;
    }
    // 読み込むことができるページか
    $wiki = Factory::Wiki($page);
    if ($wiki->isReadable(true)) {
        return array('msg' => Utility::htmlsc($page), 'body' => $wiki->render($id));
        //return $ret;
    }
    global $referer;
    $referer = 0;
    // InterWikiNameに含まれるページか?
    // ?adv:FrontPageみたいな感じでアクセス
    if (preg_match('/^' . RendererDefines::INTERWIKINAME_PATTERN . '$/', $page, $match)) {
        $url = InterWikiName::getInterWikiUrl($match[2], $match[3]);
        if ($url == false) {
            return array('msg' => $_read_msg['title_invalied'], 'body' => sprintf($_read_msg['msg_ibvaliediw'], $match[2]));
        }
        Utility::redirect($url);
        return;
    }
    // AutoAliasに含まれるページか?
    $realpage = AutoAlias::getAutoAlias($page);
    if (count($realpage) === 1) {
        // AutoAliasの指定先のページを指定
        $a_wiki = Factory::Wiki($realpage);
        if ($a_wiki->isValied()) {
            Utility::redirect($a_wiki->link());
            return;
        } else {
            if (Utility::isUri($realpage)) {
                Utility::redirect($realpage);
                return;
            }
        }
    } else {
        if (count($realpage) >= 2) {
            $body = '<p>';
            $body .= $_read_msg['msg_invalidwn'] . '<br />';
            foreach ($realpage as $entry) {
                $link[] = '[[' . $entry . '>' . $entry . ']]&br;';
            }
            $body .= InlineFactory::Wiki(join("\n", $link));
            $body .= '</p>';
            return array('msg' => $_read_msg['title_invalied'], 'body' => $body);
        }
    }
    Utility::notfound();
    exit;
}
Exemplo n.º 7
0
function plugin_suckerfish_makehtml($page)
{
    if (empty($page)) {
        return false;
    }
    $wiki = Factory::Wiki($page);
    if (!$wiki->has()) {
        return false;
    }
    $output = '';
    $before_level = 1;
    $loop = 0;
    foreach ($wiki->get(false) as $line) {
        if ($line == '') {
            continue;
        }
        $head = $line[0];
        $level = strspn($line, $head);
        $line = substr($line, $level);
        /*
        		foreach (0 as $level) {
        			$output .= '	';
        		}
        */
        if ($head == '-') {
            $item = plugin_suckerfish_to_item($line);
            if ($item == '') {
                continue;
            } else {
                $item = '<li>' . $item;
                if ($before_level < $level) {
                    /* 直前のレベルよりも現在のレベルが高いときは、そのまま<ul>タグを開く */
                    $item = "\n<ul>\n" . $item;
                } else {
                    if ($before_level > $level) {
                        /* 直前のレベルと現在のレベルの差の分だけ<ul>タグを閉じる */
                        $item = "</li>\n</ul></li>\n" . $item;
                    } else {
                        if ($loop != 0) {
                            $item = '</li>' . "\n" . $item;
                        }
                    }
                }
                $output .= $item;
            }
            $before_level = $level;
            $loop++;
        }
    }
    if ($level != 1) {
        $output .= "</li></ul>\n</li>\n";
    }
    $output = '<ul class="sf-menu">' . "\n" . $output . '</ul>';
    return '<nav id="navigator">' . $output . '</nav>' . "\n";
}
Exemplo n.º 8
0
function plugin_unfreeze_action()
{
    global $vars, $function_freeze, $_unfreeze_msg;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $wiki = Factory::Wiki($page);
    if (!$function_freeze || !$wiki->isEditable(false, true) || !$wiki->isValied($page)) {
        return array('msg' => $_unfreeze_msg['title_disabled'], 'body' => '<p class="alert alert-danger">You have no permission to unfreeze this page.</p>');
    }
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $msg = '';
    $body = array();
    if (!$wiki->isFreezed()) {
        // Unfreezed already
        $msg = str_replace('$1', Utility::htmlsc(Utility::stripBracket($page)), $_unfreeze_msg['title_isunfreezed']);
        $body[] = '<p class="alert alert-info">' . $msg . '</p>';
    } else {
        if (!Auth::check_role('role_contents_admin') || $pass !== NULL && Auth::login($pass)) {
            // BugTrack2/255
            $wiki->checkReadable();
            // Unfreeze
            $postdata = $wiki->get();
            array_shift($postdata);
            $wiki->set($postdata);
            // Update
            if (PLUGIN_UNFREEZE_EDIT) {
                // BugTrack2/255
                $wiki->checkEditable(true);
                //			$vars['cmd'] = 'read'; // To show 'Freeze' link
                $vars['cmd'] = 'edit';
            } else {
                $vars['cmd'] = 'read';
            }
            $msg = str_replace('$1', Utility::htmlsc(Utility::stripBracket($page)), $_unfreeze_msg['title_unfreezed']);
            $body[] = !IS_AJAX ? '' : '<p class="alert alert-success">' . $msg . '</p>';
            $body[] = '<div class="pull-right"><a href="' . $wiki->uri() . '" class="btn btn-primary">OK</a></div>';
            Utility::redirect($wiki->uri());
            exit;
        } else {
            // Show unfreeze form
            $msg = $_unfreeze_msg['title_unfreeze'];
            $body[] = $pass === NULL ? '' : '<p class="alert alert-danger">' . $_unfreeze_msg['msg_invalidpass'] . '</p>' . "\n";
            $body[] = '<fieldset>';
            $body[] = '<legend>' . $_unfreeze_msg['msg_unfreezing'] . '</legend>';
            $body[] = '<form action="' . Router::get_script_uri() . '" method="post" class="form-inline plugin-freeze-form">';
            $body[] = '<input type="hidden"   name="cmd"  value="unfreeze" />';
            $body[] = '<input type="hidden"   name="page" value="' . Utility::htmlsc($page) . '" />';
            $body[] = '<input type="password" name="pass" size="12" class="form-control" />';
            $body[] = '<button type="submit" class="btn btn-primary" name="ok"><span class="fa fa-lock"></span>' . $_unfreeze_msg['btn_unfreeze'] . '</button>';
            $body[] = '</form>';
            $body[] = '</fieldset>';
        }
    }
    return array('msg' => $msg, 'body' => join("\n", $body));
}
Exemplo n.º 9
0
function plugin_referer_action()
{
    global $vars, $referer, $use_pingback;
    global $_referer_msg;
    // Setting: Off
    if (!$referer) {
        return array('msg' => $_referer_msg['msg_referer'], 'body' => $_referer_msg['msg_disabled']);
    }
    $page = isset($vars['page']) ? $vars['page'] : null;
    $kind = isset($vars['kind']) ? $vars['kind'] : null;
    $max = isset($vars['max']) ? (int) $vars['max'] : -1;
    if (empty($page)) {
        return array('msg' => $_referer_msg['msg_referer'], 'body' => $_referer_msg['msg_notfound']);
    }
    if (empty($kind)) {
        return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => join("\n", array('<div class="tabs" role="application">' . "\n" . '<ul role="tablist">' . "\n" . '<li role="tab"><a href="' . get_cmd_uri('referer', $page, null, array('kind' => 'referer')) . '">' . $_referer_msg['msg_referer'] . '</a></li>', '<li role="tab"><a href="' . get_cmd_uri('referer', $page, null, array('kind' => 'searchkey')) . '">' . $_referer_msg['msg_searchkey'] . '</a></li>', '<li role="tab"><a href="' . get_cmd_uri('referer', $page, null, array('kind' => 'mutual')) . '">' . $_referer_msg['msg_mutual'] . '</a></li>', $use_pingback ? '<li role="tab"><a href="' . get_cmd_uri('referer', $page, null, array('kind' => 'pingback')) . '">' . $_referer_msg['msg_pingback'] . '</a></li>' : null, '</ul>', '</div>')));
    }
    $wiki = Factory::Wiki($page);
    if ($wiki->isValied() && $wiki->isReadable()) {
        if ($kind === 'pingback') {
            return array('msg' => sprintf($_referer_msg['msg_pingback_title'], $page), 'body' => plugin_referer_pingback($page));
        }
        $data = Factory::Referer($page)->get();
        if (!isset($data)) {
            return '<p class="alert alert-warning">' . $_referer_msg['msg_no_data'] . '</p>';
        }
        switch ($kind) {
            case 'skeylist':
                // searchkeylist.inc.phpのなごり
            // searchkeylist.inc.phpのなごり
            case 'searchkey':
                return array('msg' => sprintf($_referer_msg['msg_searchkey_title'], $page), 'body' => plugin_referer_searchkeylist($data, $max));
                break;
            case 'linklist':
                // linklist.inc.phpのなごり
            // linklist.inc.phpのなごり
            case 'mutual':
                return array('msg' => sprintf($_referer_msg['msg_mutual_title'], $page), 'body' => plugin_referer_mutual($data, $max));
                break;
            case 'referer':
                return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => plugin_referer_body($data));
                break;
            default:
                return array('msg' => $_referer_msg['msg_referer'], 'body' => plugin_referer_body($data));
                break;
        }
    }
    $pages = Auth::get_existpages(REFERER_DIR, '.ref');
    if (empty($pages)) {
        return array('msg' => $_referer_msg['msg_referer'], 'body' => $_referer_msg['msg_notfound']);
    } else {
        return array('msg' => $_referer_msg['msg_referer_list'], 'body' => page_list($pages, 'referer', FALSE));
    }
}
Exemplo n.º 10
0
function plugin_back_convert()
{
    $_msg_back_word = T_('Back');
    if (func_num_args() > 4) {
        return PLUGIN_BACK_USAGE;
    }
    list($word, $align, $hr, $href) = array_pad(func_get_args(), 4, '');
    $word = trim($word);
    $word = $word == '' ? $_msg_back_word : htmlsc($word);
    $align = strtolower(trim($align));
    switch ($align) {
        case '':
            $align = 'center';
            /*FALLTHROUGH*/
        /*FALLTHROUGH*/
        case 'center':
            /*FALLTHROUGH*/
        /*FALLTHROUGH*/
        case 'left':
            /*FALLTHROUGH*/
        /*FALLTHROUGH*/
        case 'right':
            break;
        default:
            return PLUGIN_BACK_USAGE;
    }
    $hr = trim($hr) != '0' ? '<hr class="full_hr" />' . "\n" : '';
    $link = TRUE;
    $href = trim($href);
    if (!empty($href)) {
        if (Auth::check_role('safemode')) {
            if (is_url($href)) {
                $href = rawurlencode($href);
            } else {
                $wiki = Factory::Wiki($array[0]);
                $array = Utility::explodeAnchor($href);
                $array[1] = !empty($array[1]) ? '#' . rawurlencode($array[1]) : '';
                $href = $wiki->uri() . $array[1];
                $link = $wiki->has();
            }
        } else {
            $href = rawurlencode($href);
        }
    } else {
        $href = 'javascript:history.go(-1)';
    }
    if ($link) {
        // Normal link
        return $hr . '<div style="text-align:' . $align . '">' . '[ <a href="' . $href . '">' . $word . '</a> ]</div>' . "\n";
    } else {
        // Dangling link
        return $hr . '<div style="text-align:' . $align . '">' . '[ <span class="noexists">' . $word . '<a href="' . $href . '">?</a></span> ]</div>' . "\n";
    }
}
Exemplo n.º 11
0
function plugin_add_action()
{
    global $get, $post, $vars, $_string;
    // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    if (Auth::check_role('readonly')) {
        Utility::dieMessage($_string['prohibit']);
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    $wiki = Factory::Wiki($page);
    $wiki->checkEditable();
    $get['add'] = $post['add'] = $vars['add'] = TRUE;
    return array('msg' => _("Add to \$1"), 'body' => '<ul>' . "\n" . '	<li>' . T_('Two and the contents of an input are added for a new-line to the contents of a page of present addition.') . '</li>' . "\n" . '</ul>' . "\n" . edit_form($page, ''));
}
Exemplo n.º 12
0
function plugin_nofollow_convert()
{
    global $vars, $nofollow;
    $page = isset($vars['page']) ? $vars['page'] : null;
    if (empty($page)) {
        // ページ名が無い
        return '<p class="alert alert-warning">#nofollow: Page name is missing.</p>';
    }
    if (!Factory::Wiki($page)->isFreezed()) {
        // フリーズされてない
        return '<p class="alert alert-warning">#nofollow: Page not freezed.</p>';
    }
    $nofollow = 1;
}
Exemplo n.º 13
0
function plugin_freeze_action()
{
    global $vars, $function_freeze, $_freeze_msg;
    $page = isset($vars['page']) ? $vars['page'] : null;
    if (is_null($page)) {
        return array('msg' => 'Not Found', 'body' => 'Page not found');
    }
    $wiki = Factory::Wiki($page);
    if (!$function_freeze || !$wiki->isEditable(true) || !$wiki->has()) {
        return array('msg' => $_freeze_msg['title_disabled'], 'body' => '<p class="alert alert-danger">You have no permission to freeze this page.</p>');
    }
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $msg = '';
    $body = array();
    if ($wiki->isFreezed()) {
        // Freezed already
        $msg = str_replace('$1', Utility::htmlsc(Utility::stripBracket($page)), $_freeze_msg['title_isfreezed']);
        $body[] = '<p class="alert alert-info">' . $msg . '</p>';
    } else {
        if (!Auth::check_role('role_contents_admin') || $pass !== NULL && Auth::login($pass)) {
            // Freeze
            $postdata = $wiki->get();
            array_unshift($postdata, "#freeze");
            //凍結をページに付加
            $wiki->set($postdata, true);
            // Update
            //$wiki->is_freezed();
            $vars['cmd'] = 'read';
            $msg = str_replace('$1', Utility::htmlsc(Utility::stripBracket($page)), $_freeze_msg['title_freezed']);
            $body[] = !IS_AJAX ? '' : '<p class="alert alert-success">' . $msg . '</p><div class="pull-right"><a href="' . $wiki->uri() . '" class="btn btn-primary">OK</a></div>';
        } else {
            // Show a freeze form
            $msg = $_freeze_msg['title_freeze'];
            $body[] = $pass === NULL ? '' : '<p class="alert alert-warning">' . $_freeze_msg['msg_invalidpass'] . '</p>';
            $body[] = '<fieldset>';
            $body[] = '<legend>' . $_freeze_msg['msg_freezing'] . '</legend>';
            $body[] = '<form action="' . Router::get_script_uri() . '" method="post" class="form-inline plugin-freeze-form">';
            $body[] = '<input type="hidden"   name="cmd"  value="freeze" />';
            $body[] = '<input type="hidden"   name="page" value="' . Utility::htmlsc($page) . '" />';
            $body[] = '<input type="password" name="pass" size="12" class="form-control" />';
            $body[] = '<button type="submit" class="btn btn-primary" name="ok"><span class="fa fa-lock"></span>' . $_freeze_msg['btn_freeze'] . '</button>';
            $body[] = '</form>';
            $body[] = '</fieldset>';
        }
    }
    return array('msg' => $msg, 'body' => join("\n", $body));
}
Exemplo n.º 14
0
function plugin_source_action()
{
    global $vars;
    //, $_source_messages;
    // if (PKWK_SAFE_MODE) die_message('PKWK_SAFE_MODE prohibits this');
    if (Auth::check_role('safemode')) {
        Utility::dieMessage('PKWK_SAFE_MODE prohibits this');
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    $vars['refer'] = $page;
    $wiki = Factory::Wiki($page);
    if (!$wiki->isValied() || !$wiki->isReadable()) {
        return array('msg' => T_(' $1 was not found.'), 'body' => T_('cannot display the page source.'));
    }
    $source = $wiki->get(true);
    Auth::is_role_page($source);
    return array('msg' => T_('Source of  $1'), 'body' => '<pre class="sh sunlight-highlight-plain">' . Utility::htmlsc($source) . '</pre>');
}
Exemplo n.º 15
0
function plugin_diff_view($page)
{
    global $hr, $_string;
    //	global $_msg_notfound, $_msg_goto, $_msg_deleted, $_msg_addline, $_msg_delline;
    //	global $_title_diff, $_title_diff_delete;
    if (Auth::check_role('safemode')) {
        die_message('PKWK_SAFE_MODE prohibits this');
    }
    $_msg_notfound = T_('The page was not found.');
    $_msg_addline = T_('The added line is <span class="diff_added">THIS COLOR</span>.');
    $_msg_delline = T_('The deleted line is <span class="diff_removed">THIS COLOR</span>.');
    $_msg_goto = T_('Go to $1.');
    $_msg_deleted = T_(' $1 has been deleted.');
    $_title_diff = T_('Diff of $1');
    $_title_diff_delete = T_('Deleting diff of $1');
    $r_page = rawurlencode($page);
    $s_page = htmlsc($page);
    $menu = array('<li class="no-js">' . $_msg_addline . '</li>', '<li class="no-js">' . $_msg_delline . '</li>');
    $is_page = Factory::Wiki($page)->isValied();
    if ($is_page) {
        $menu[] = ' <li>' . str_replace('$1', '<a href="' . get_page_uri($page) . '">' . $s_page . '</a>', $_msg_goto) . '</li>';
    } else {
        $menu[] = ' <li>' . str_replace('$1', $s_page, $_msg_deleted) . '</li>';
    }
    $diff = FileFactory::Diff($page);
    if ($diff->has() && ($is_page || Auth::is_role_page($diff))) {
        // if (! PKWK_READONLY) {
        if (!Auth::check_role('readonly')) {
            $menu[] = '<li><a href="' . get_cmd_uri('diff', $page, null, array('action' => 'delete')) . '">' . str_replace('$1', $s_page, $_title_diff_delete) . '</a></li>';
        }
        Auth::is_role_page($diff);
        $msg = $diff->render();
    } else {
        return array('msg' => $_title_diff, 'body' => $_msg_notfound);
    }
    $menu = join("\n", $menu);
    $body = <<<EOD
<ul>
{$menu}
</ul>
{$hr}
EOD;
    return array('msg' => $_title_diff, 'body' => $body . $msg);
}
Exemplo n.º 16
0
 public function setPattern($arr, $page)
 {
     list(, $alias, , $name, $this->anchor) = $this->splice($arr);
     if (empty($name) && empty($this->anchor)) {
         return FALSE;
     }
     if (empty($name) || !Utility::isWikiName($name)) {
         if (empty($alias)) {
             $alias = $name . $this->anchor;
         }
         if (!empty($name)) {
             $name = self::getFullname($name, $page);
             if (!empty($name) && !Factory::Wiki($name)->isValied()) {
                 return FALSE;
             }
         }
     }
     return parent::setParam($page, $name, null, 'pagename', $alias);
 }
Exemplo n.º 17
0
function plugin_tooltip_get_page_title($term)
{
    $page = strip_bracket($term);
    $wiki = Factory::Wiki($page);
    if (!$wiki->has($page)) {
        return FALSE;
    }
    $ct = 0;
    foreach ($wiki->get() as $line) {
        if ($ct++ > 99) {
            break;
        }
        if (preg_match('/^\\*{1,3}(.*)\\[#[A-Za-z0-9][\\w\\-]+\\].*$/', $line, $match)) {
            return trim($match[1]);
        } else {
            if (preg_match('/^\\*{1,3}(.*)$/', $line, $match)) {
                return trim($match[1]);
            }
        }
    }
    return FALSE;
}
Exemplo n.º 18
0
 /**
  * インデックスファイルを生成
  */
 public static function updateIndex()
 {
     if (empty(self::$igo)) {
         self::$igo = new Tagger(array('dict_dir' => LIB_DIR . 'ipadic', 'reduce_mode' => true));
     }
     Analyzer::setDefault(new Utf8());
     // 索引の作成
     $index = Lucene::create(CACHE_DIR . self::INDEX_NAME);
     foreach (Listing::pages() as $page) {
         if (empty($page)) {
             continue;
         }
         $wiki = Factory::Wiki($page);
         // 読む権限がない場合スキップ
         if (!$wiki->isReadable() || $wiki->isHidden()) {
             continue;
         }
         /*
         			// HTML出力
         			$html[] = '<html><head>';
         			$html[] = '<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>';
         			$html[] = '<title>' . $wiki->title() . '</title>';
         			$html[] = '</head>';
         			$html[] = '<body>' . $wiki->render() . '</body>';
         			$html[] = '</html>';
         */
         $doc = new LuceneDoc();
         $doc->addField(Field::Text('title', $wiki->title()));
         // Store document URL to identify it in the search results
         $doc->addField(Field::Text('url', $wiki->uri()));
         // Index document contents
         //$contents = join(" ", self::$igo->wakati(strip_tags($wiki->render())));
         $contents = strip_tags($wiki->render());
         $doc->addField(Field::UnStored('contents', $contents));
         // 索引へ文書の登録
         $index->addDocument($doc);
     }
     $index->optimize();
 }
Exemplo n.º 19
0
 /**
  * 編集画面を表示
  * @param string $page 編集しようとしているページ名
  * @param string $data 入力データー
  * @param boolean $show_template テンプレートを表示するか
  */
 public static function editForm($page, $data, $show_template = TRUE)
 {
     global $vars, $session;
     global $_button, $_string;
     global $notimeupdate, $load_template_func, $load_refer_related;
     if (empty($page)) {
         return self::dieMessage('Page name was not defined.');
     }
     $postdata = is_array($data) ? join("\n", $data) : $data;
     $original = isset($vars['original']) ? $vars['original'] : $postdata;
     // ticketは、PliginRenderer::addHiddenField()で自動挿入されるので、同じアルゴリズムでチケット名を生成
     $ticket_name = md5(Utility::getTicket() . REMOTE_ADDR);
     // BugTrack/95 fix Problem: browser RSS request with session
     $session->offsetSet('origin-' . $ticket_name, md5(self::getTicket() . str_replace("\r", '', $original)));
     $ret[] = '<form action="' . Router::get_script_uri() . '" role="form" method="post" class="form-edit" data-collision-check-strict="true">';
     $ret[] = '<input type="hidden" name="cmd" value="edit" />';
     $ret[] = '<input type="hidden" name="page" value="' . self::htmlsc($page) . '" />';
     $ret[] = isset($vars['id']) ? '<input type="hidden" name="id" value="' . self::htmlsc($vars['id']) . '" />' : null;
     if ($load_template_func && $show_template) {
         // ひな形を読み込む
         foreach (Listing::pages() as $_page) {
             $_w = Factory::Wiki($_page);
             if (!$_w->isEditable() || $_w->isHidden()) {
                 continue;
             }
             $_s_page = self::htmlsc($_page);
             $_pages[$_page] = '<option value="' . $_s_page . '">' . $_s_page . '</option>' . "\n";
         }
         // ナチュラルソート
         ksort($_pages, SORT_NATURAL);
         $ret[] = '<div class="form-inline">';
         $ret[] = '<div class="form-group">';
         $ret[] = '<select class="form-control" name="template_page" class="template">';
         $ret[] = '<option value="" disabled="disabled" selected="selected">-- ' . $_button['template'] . ' --</option>';
         $ret[] = join("\n", $_pages);
         $ret[] = '</select>';
         $ret[] = '</div>';
         $ret[] = '<button type="submit" class="btn btn-secondary" name="template" accesskey="l">' . $_button['load'] . '</button>';
         $ret[] = '</div>';
         unset($_s_page, $_w, $_pages);
     }
     // 編集フォーム
     $ret[] = '<textarea name="msg" id="msg" rows="15" class="form-control">' . self::htmlsc(($load_refer_related && isset($vars['refer']) && !empty($vars['refer']) ? '[[' . self::stripBracket($vars['refer']) . ']]' . "\n\n" : '') . $postdata) . '</textarea>';
     $ret[] = '<div class="form-inline">';
     if (IS_MOBILE) {
         // モバイル用
         $ret[] = '<input type="submit" id="btn_submit" name="write" value="' . $_button['update'] . '" data-icon="check" data-inline="true" data-theme="b" />';
         $ret[] = '<input type="submit" id="btn_preview" name="preview" value="' . $_button['preview'] . '" accesskey="p" data-icon="gear" data-inline="true" data-theme="e" />';
         $ret[] = '<input type="submit" id="btn_cancel" name="cancel" value="' . $_button['cancel'] . '" accesskey="c" data-icon="delete" data-inline="true" />';
         $ret[] = $notimeupdate === 2 && Auth::check_role('role_contents_admin') ? '<div data-role="fieldcontain">' : null;
         if ($notimeupdate !== 0 && Factory::Wiki($page)->isValied()) {
             // タイムスタンプを更新しないのチェックボックス
             $ret[] = '<input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true" ' . (isset($vars['notimestamp']) ? ' checked="checked"' : null) . ' />';
             $ret[] = '<label for="_edit_form_notimestamp" data-inline="true">' . $_button['notchangetimestamp'] . '</label>';
         }
         // 管理人のパス入力
         $ret[] = $notimeupdate == 2 && Auth::check_role('role_contents_admin') ? '<input type="password" name="pass" size="12"  data-inline="true" />' . "\n" . '</div>' : null;
         $ret[] = isset($vars['add']) ? '<input type="checkbox" name="add_top" value="true"' . (isset($vars['add']) ? ' checked="checked"' : '') . ' /><label for="add_top">' . $_button['addtop'] . '</label>' : null;
     } else {
         // 通常用
         $ret[] = '<button type="submit" class="btn btn-primary" name="write" accesskey="s"><span class="fa fa-check"></span>' . $_button['update'] . '</button>';
         $ret[] = isset($vars['add']) ? '<input type="checkbox" name="add_top" value="true"' . (isset($vars['add']) ? ' checked="checked"' : '') . ' /><label for="add_top">' . $_button['addtop'] . '</label>' : null;
         $ret[] = '<button type="submit" class="btn btn-secondary" name="preview" accesskey="p"><span class="fa fa-eye"></span>' . $_button['preview'] . '</button>';
         if ($notimeupdate !== 0 && Factory::Wiki($page)->isValied()) {
             // タイムスタンプを更新しないのチェックボックス
             $ret[] = '<div class="checkbox">';
             $ret[] = '<input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true"' . (isset($vars['notimestamp']) ? ' checked="checked"' : null) . ' />';
             $ret[] = '<label for="_edit_form_notimestamp">' . $_button['notchangetimestamp'] . '</label>';
             $ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="ping" id="_edit_form_ping" value="true"' . (isset($vars['ping']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_ping">' . $_button['send_ping'] . '</label>';
             //	$ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="tweet" id="_edit_form_tweet" value="true"' . (isset($vars['tweet']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_tweet"><span class="fa  fa-twitter"></span></label>';
             //	$ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="ping" id="_edit_form_fb" value="true"' . (isset($vars['facebook']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_tweet"><span class="fa  fa-facebook"></span></label>';
             //	$ret[] = '</div>';
         }
         // 管理人のパス入力
         if ($notimeupdate === 2 && Auth::check_role('role_contents_admin')) {
             $ret[] = '<div class="form-group">';
             $ret[] = '<div class="input-group">';
             $ret[] = '<span class="input-group-addon"><span class="fa fa-key"></span></span>';
             $ret[] = '<input type="password" name="pass" class="form-control" size="12" placeholder="Password" />';
             $ret[] = '</div>';
             $ret[] = '</div>';
         }
         $ret[] = '<button type="submit" class="btn btn-warning" name="cancel" accesskey="c"><span class="fa fa-ban"></span>' . $_button['cancel'] . '</button>';
     }
     $ret[] = '</div>';
     $ret[] = '</form>';
     if (isset($vars['help'])) {
         // テキストの整形ルールを表示
         $rule_wiki = Factory::Wiki(self::RULE_PAGENAME);
         $ret[] = '<hr />';
         $ret[] = $rule_wiki->has() ? $rule_wiki->render() : '<p class="alert alert-warning">Sorry, page \'' . Utility::htmlsc(self::RULE_PAGENAME) . '\' unavailable.</p>';
     } else {
         $ret[] = '<ul><li><a href="' . Factory::Wiki($page)->uri('edit', array('help' => 'true')) . '" id="FormatRule">' . $_string['help'] . '</a></li></ul>';
     }
     return join("\n", $ret);
 }
Exemplo n.º 20
0
function plugin_recent_convert()
{
    global $vars, $date_format, $link_compact, $page_title;
    // , $_recent_plugin_frame;
    static $exec_count = 1;
    global $cache;
    if (empty($vars['page'])) {
        return null;
    }
    $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
    $args = func_get_args();
    if (!empty($args)) {
        if (isset($args[1]) || !is_numeric($args[0])) {
            return PLUGIN_RECENT_USAGE . '<br />';
        }
        $recent_lines =& $args[0];
    }
    if ($exec_count++ > PLUGIN_RECENT_EXEC_LIMIT) {
        return '<div class="alert alert-warning">#recent(): You called me too much.</div>' . "\n";
    }
    $date = '';
    $items = array();
    $lines = Recent::get();
    if ($lines !== null) {
        $count = count($lines) < $recent_lines ? count($lines) : $recent_lines;
        $i = 0;
        foreach ($lines as $page => $time) {
            $wiki = Factory::Wiki($page);
            if (!$wiki->isReadable()) {
                continue;
            }
            //if (! $wiki->isHidden()) continue;
            if ($i > $count) {
                break;
            }
            $s_page = Utility::htmlsc($page);
            $_date = get_date($date_format, $time);
            if (!IS_MOBILE) {
                if ($page === $vars['page']) {
                    // No need to link to the page you just read, or notify where you just read
                    $items[$_date][] = ' <li>' . $s_page . '</li>';
                } else {
                    $passage = !$link_compact ? ' ' . $wiki->passage(false, true) : '';
                    $items[$_date][] = ' <li><a href="' . $wiki->uri() . '" title="' . $s_page . $passage . '">' . $s_page . '</a></li>';
                }
            } else {
                if ($date !== $_date) {
                    // New day
                    $date = $_date;
                    $items[] = '<li data-role="list-divider">' . $date . '</li>';
                }
                if ($page === $vars['page']) {
                    // No need to link to the page you just read, or notify where you just read
                    $items[] = ' <li data-theme="e">' . $s_page . '</li>';
                } else {
                    $passage = !$link_compact ? ' ' . '<span class="ui-li-count">' . $wiki->passage(false, false) . '</span>' : '';
                    $items[] = ' <li><a href="' . $wiki->uri() . '" data-transition="slide">' . $s_page . $passage . '</a></li>';
                }
            }
            $i++;
        }
        unset($lines, $i);
    }
    $_recent_title = sprintf(T_('recent(%d)'), $count);
    if (!IS_MOBILE) {
        // End of the day
        $ret[] = '<div class="plugin-recent">';
        $ret[] = '<h5>' . $_recent_title . '</h5>';
        $ret[] = '<div class="hslice" id="webslice">';
        $ret[] = '<span class="entry-title" style="display:none;">' . $page_title . '</span>';
        $ret[] = '<div class="entry-content">';
        $ret[] = '<ul class="list-unstyled">';
        foreach ($items as $date => $entries) {
            $ret[] = '<li><strong>' . $date . '</strong><ul>';
            foreach ($entries as $entry) {
                $ret[] = $entry;
            }
            $ret[] = '</ul></li>';
        }
        $ret[] = '</ul>';
        $ret[] = '</div>';
        $ret[] = '</div>';
        $ret[] = '</div>';
        return join("\n", $ret);
    } else {
        return '<ul data-role="listview" data-dividertheme="b">' . "\n" . '<li data-theme="a">' . $_recent_title . '</li>' . "\n" . join("\n", $items) . '</ul>' . "\n";
    }
}
Exemplo n.º 21
0
function plugin_help_action()
{
    global $help_page;
    Utility::redirect(Factory::Wiki('Help')->uri());
}
Exemplo n.º 22
0
function check_non_list($page = '')
{
    if (empty($page)) {
        return false;
    }
    return Factory::Wiki($page)->isHidden();
}
Exemplo n.º 23
0
function plugin_guiedit_cancel()
{
    global $vars, $defaultpage;
    $page = isset($vars['page']) ? $vars['page'] : $defaultpage;
    $location = Factory::Wiki($page)->uri();
    if (!empty($vars['id'])) {
        $location .= '#' . $vars['id'];
    }
    Utility::redirect($location);
    exit;
}
Exemplo n.º 24
0
 /**
  * 署名の特定
  */
 private function log_set_signature($utime)
 {
     // $utime は、今後、閲覧者の特定などの際にバックアップファイルから
     // 特定することを想定し、含めている。
     if ($this->kind !== 'update') {
         return null;
     }
     $diff = new DiffFile($this->page);
     // 差分ファイル名
     $lines = array();
     if ($diff->has()) {
         // 今回更新行のみ抽出
         foreach ($diff->get() as $_src) {
             if (substr($_src, 0, 1) === '+') {
                 $lines[] = substr($_src, 1);
             }
         }
     } else {
         // 新規ページの全てが対象
         $lines = Factory::Wiki($this->page)->get();
     }
     return Auth::get_signature($lines);
 }
Exemplo n.º 25
0
 /**
  *  Mail to administrator(s)
  */
 private static function pkwk_spamnotify($action, $page, $target = array('title' => ''), $progress = array(), $method = array())
 {
     global $notify, $notify_subject;
     if (!$notify) {
         return;
     }
     $asap = isset($method['asap']);
     $summary['ACTION'] = 'Blocked by: ' . self::summarize_spam_progress($progress, TRUE);
     if (!$asap) {
         $summary['METRICS'] = self::summarize_spam_progress($progress);
     }
     $tmp = self::summarize_detail_badhost($progress);
     if ($tmp != '') {
         $summary['DETAIL_BADHOST'] = $tmp;
     }
     $tmp = self::summarize_detail_newtral($progress);
     if (!$asap && $tmp != '') {
         $summary['DETAIL_NEUTRAL_HOST'] = $tmp;
     }
     $wiki = Factory::Wiki($page);
     $summary['COMMENT'] = $action;
     $summary['PAGE'] = '[blocked] ' . ($wiki->isValied() ? $page : '');
     $summary['URI'] = $wiki->uri();
     $summary['USER_AGENT'] = TRUE;
     $summary['REMOTE_ADDR'] = TRUE;
     pkwk_mail_notify($notify_subject, var_export($target, TRUE), $summary, TRUE);
 }
Exemplo n.º 26
0
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>&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 ($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);
            }
        }
    }
}
Exemplo n.º 27
0
 /**
  * Atom/rssを出力
  * string $page ページ名(ページ名が入っている場合はキャッシュは無効)
  * string $type rssかatomか。
  * boolean $force キャッシュ生成しない
  * return void
  */
 public static function getFeed($page = '', $type = 'rss', $force = false)
 {
     global $vars, $site_name, $site_logo, $modifier, $modifierlink, $_string, $cache;
     static $feed;
     // rss, atom以外はエラー
     if (!($type === 'rss' || $type === 'atom')) {
         throw new Exception('Recent::getFeed(): Unknown feed type.');
     }
     $content_type = $type === 'rss' ? 'application/rss+xml' : 'application/atom+xml';
     $body = '';
     if (empty($page)) {
         // recentキャッシュの更新チェック
         if ($cache['wiki']->getMetadata(self::RECENT_CACHE_NAME)['mtime'] > $cache['wiki']->getMetadata(self::FEED_CACHE_NAME)['mtime']) {
             $force = true;
         }
         if ($force) {
             // キャッシュ再生成
             unset($feed);
             $cache['wiki']->removeItem(self::FEED_CACHE_NAME);
         } else {
             if (!empty($feed)) {
                 // メモリにキャッシュがある場合
             } else {
                 if ($cache['wiki']->hasItem(self::FEED_CACHE_NAME)) {
                     // キャッシュから最終更新を読み込む
                     $feed = $cache['wiki']->getItem(self::FEED_CACHE_NAME);
                 }
             }
         }
     }
     if (empty($feed)) {
         // Feedを作る
         $feed = new Feed();
         // Wiki名
         $feed->setTitle($site_name);
         // Wikiのアドレス
         $feed->setLink(Router::get_script_absuri());
         // サイトのロゴ
         //$feed->setImage(array(
         //	'title'=>$site_name,
         //	'uri'=>$site_logo,
         //	'link'=>Router::get_script_absuri()
         //));
         // Feedの解説
         $feed->setDescription(sprintf($_string['feed_description'], $site_name));
         // Feedの発行者など
         $feed->addAuthor(array('name' => $modifier, 'uri' => $modifierlink));
         // feedの更新日時(生成された時間なので、この実装で問題ない)
         $feed->setDateModified(time());
         $feed->setDateCreated(time());
         // Feedの生成
         $feed->setGenerator(S_APPNAME, S_VERSION, 'http://pukiwiki.logue.be/');
         if (empty($page)) {
             // feedのアドレス
             // ※Zend\Feedの仕様上、&が自動的に&amp;に変更されてしまう
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom', 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed'), 'rss');
             // PubSubHubbubの送信
             foreach (Ping::$pubsubhubbub_server as $uri) {
                 $feed->addHub($uri);
             }
         } else {
             $r_page = rawurlencode($page);
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom&refer=' . $r_page, 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&refer=' . $r_page, 'rss');
         }
         $i = 0;
         // エントリを取得
         foreach (self::get() as $_page => $time) {
             // ページ名が指定されていた場合、そのページより下位の更新履歴のみ出力
             if (!empty($page) && strpos($_page, $page . '/') === false) {
                 continue;
             }
             $wiki = Factory::Wiki($_page);
             if ($wiki->isHidden()) {
                 continue;
             }
             $entry = $feed->createEntry();
             // ページのタイトル
             $entry->setTitle($wiki->title());
             // ページのアドレス
             $entry->setLink($wiki->uri());
             // ページの更新日時
             $entry->setDateModified($wiki->time());
             // ページの要約
             $entry->setDescription($wiki->description(self::FEED_ENTRY_DESCRIPTION_LENGTH));
             // 項目を追加
             $feed->addEntry($entry);
             $i++;
             if ($i >= self::RECENT_MAX_SHOW_PAGES) {
                 break;
             }
         }
         if (empty($page)) {
             // キャッシュに保存
             $cache['wiki']->setItem(self::FEED_CACHE_NAME, $feed);
         }
     }
     flush();
     $headers = Header::getHeaders($content_type);
     Header::writeResponse($headers, 200, $feed->export($type));
     //header('Content-Type: ' . $content_type);
     //echo $body;
     exit;
 }
Exemplo n.º 28
0
function plugin_edit_write()
{
    global $vars, $trackback, $_string, $_msg_edit;
    global $notimeupdate;
    $page = isset($vars['page']) ? $vars['page'] : null;
    $add = isset($vars['add']) ? $vars['add'] : null;
    $digest = isset($vars['digest']) ? $vars['digest'] : null;
    $partid = isset($vars['id']) ? $vars['id'] : null;
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] !== null;
    if (empty($page)) {
        return array('mgs' => 'Error', 'body' => $_msg_edit['err_empty_page']);
    }
    $wiki = Factory::Wiki($page);
    // Check Validate and Ticket
    if ($notimestamp && !$wiki->isValied()) {
        return plugin_edit_honeypot();
    }
    // Validate
    if (is_spampost(array('msg'))) {
        return plugin_edit_honeypot();
    }
    // Paragraph edit mode
    if ($partid) {
        $source = preg_split('/([^\\n]*\\n)/', $vars['original'], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $vars['msg'] = plugin_edit_parts($partid, $source, $vars['msg']) !== FALSE ? join('', $source) : rtrim($vars['original']) . "\n\n" . $vars['msg'];
    }
    $retvars = array();
    if (isset($vars['msg']) && !empty($vars['msg'])) {
        // Delete "#freeze" command for form edit.
        $vars['msg'] = preg_replace('/^#freeze\\s*$/im', '', $vars['msg']);
        $msg = $vars['msg'];
        // Reference
        // Action?
        if ($add) {
            // Compat: add plugin and adding contents
            $postdata = isset($vars['add_top']) && $vars['add_top'] ? $msg . "\n\n" . $oldpagesrc : $oldpagesrc . "\n\n" . $msg;
        } else {
            // Edit or Remove
            $postdata =& $msg;
        }
    } else {
        // CAPTCHAが有効なときで、ページを削除しようとした時、$vars['msg']は空になる。
        $wiki->set('');
        $retvars['msg'] = sprintf($_msg_edit['title_deleted'], Utility::htmlsc($page));
        $retvars['body'] = '<p class="alert alert-success">' . sprintf($_msg_edit['title_deleted'], Utility::htmlsc($page)) . '</p>';
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    //	$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    //	if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
    if ($notimeupdate > 1 && $notimestamp && Auth::check_role('role_contents_admin') && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p class="alert alert-danger">' . $_msg_edit['msg_invalidpass'] . '</p>' . "\n";
        $retvars['body'] .= Utility::editForm($page, $msg, FALSE);
        return $retvars;
    }
    $wiki->set($postdata, $notimeupdate !== 0 && $notimestamp);
    if (isset($vars['refpage']) && $vars['refpage'] !== '') {
        $refwiki = Factory::Wiki($vars['refpage']);
        $url = $partid ? $refwiki->uri('read', null, rawurlencode($partid)) : $refwiki->uri();
    } else {
        $url = $partid ? $wiki->uri('read', null, rawurlencode($partid)) : $wiki->uri();
    }
    if (isset($vars['ajax'])) {
        $headers = Header::getHeaders('application/json');
        Header::writeResponse($headers, 200, Json::encode(array('msg' => 'Your post has been saved.', 'posted' => true, 'taketime' => Time::getTakeTime())));
    } else {
        Utility::redirect($url);
    }
    exit;
}
Exemplo n.º 29
0
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;
}
Exemplo n.º 30
0
function plugin_article_action()
{
    global $vars, $cols, $rows, $now;
    global $_plugin_article_mailto, $_no_subject, $_no_name;
    global $_article_msg, $_string;
    // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    if (Auth::check_role('readonly')) {
        die_message($_string['error_prohibit']);
    }
    if (!isset($vars['msg']) || !isset($vars['refer'])) {
        return array('msg' => null, 'body' => null);
    }
    $name = !isset($vars['name']) ? $_no_name : $vars['name'];
    $name = empty($name) ? '' : str_replace('$name', $name, PLUGIN_ARTICLE_NAME_FORMAT);
    $subject = !isset($vars['subject']) ? $_no_subject : $vars['subject'];
    $subject = empty($subject) ? '' : str_replace('$subject', $subject, PLUGIN_ARTICLE_SUBJECT_FORMAT);
    $ret[] = $subject;
    $ret[] = '>' . $name . ' (&epoch(' . UTIME . ');)~';
    $ret[] = '~';
    $msg = rtrim($vars['msg']);
    if (PLUGIN_ARTICLE_AUTO_BR) {
        //改行の取り扱いはけっこう厄介。特にURLが絡んだときは…
        //コメント行、整形済み行には~をつけないように arino
        $msg = join("\n", preg_replace('/^(?!\\/\\/)(?!\\s)(.*)$/', '$1~', explode("\n", $msg)));
    }
    $ret[] = $msg . "\n\n" . '//';
    if (PLUGIN_ARTICLE_COMMENT) {
        $ret[] = '';
        $ret[] = '#comment';
    }
    $postdata = array();
    $wiki = Factory::Wiki($vars['refer']);
    $vars['page'] = $vars['refer'];
    $article_no = 0;
    foreach ($wiki->get() as $line) {
        if (!PLUGIN_ARTICLE_INS) {
            $postdata[] = $line;
        }
        if (preg_match('/^#article/i', $line)) {
            if ($article_no === $vars['article_no'] && !empty($vars['msg'])) {
                $postdata[] = join("\n", $ret);
            }
            ++$article_no;
        }
        if (PLUGIN_ARTICLE_INS) {
            $postdata[] = $line;
        }
    }
    $postdata[] = join("\n", $ret);
    $body = '';
    $wiki->set($postdata);
    // 投稿内容のメール自動送信
    if (PLUGIN_ARTICLE_MAIL_AUTO_SEND) {
        $mailaddress = implode(',', $_plugin_article_mailto);
        $mailsubject = PLUGIN_ARTICLE_MAIL_SUBJECT_PREFIX . ' ' . str_replace('**', '', $subject);
        if ($post['name']) {
            $mailsubject .= '/' . $post['name'];
        }
        $mailsubject = mb_encode_mimeheader($mailsubject);
        $mailbody = array();
        $mailbody[] = $post['msg'];
        $mailbody[] = "\n" . '---';
        $mailbody[] = $_article_msg['msg_article_mail_sender'] . $post['name'] . ' (' . $now . ')';
        $mailbody[] = $_article_msg['msg_article_mail_page'] . $post['refer'];
        $mailbody[] = 'URL: ' . get_page_absuri($post['refer']);
        $output = mb_convert_encoding(join("\n", $mailbody), 'JIS');
        $mailaddheader = 'From: ' . PLUGIN_ARTICLE_MAIL_FROM;
        mail($mailaddress, $mailsubject, $mailbody, $mailaddheader);
    }
    $retvars['msg'] = $_article_msg['title_updated'];
    $retvars['body'] = $body;
    return $retvars;
}