示例#1
0
function plugin_newpage_action()
{
    global $vars, $_string, $_newpage_messages;
    // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    if (Auth::check_role('readonly')) {
        Utility::dieMessage(sprintf($_string['error_prohibit'], 'PKWK_READONLY'), '', 403);
    }
    if (Auth::is_check_role(PKWK_CREATE_PAGE)) {
        Utility::dieMessage(sprintf($_string['error_prohibit'], 'PKWK_CREATE_PAGE'), '', 403);
    }
    if (!isset($vars['page'])) {
        $retvars['msg'] = $_newpage_messages['title'];
        $retvars['body'] = plugin_newpage_convert();
        return $retvars;
    } else {
        $page = Utility::stripNullBytes($vars['page']);
        if (isset($vars['refer'])) {
            $r_page = Utility::getPageName($page, $vars['refer']);
            $r_refer = 'refer=' . $vars['refer'];
        } else {
            $r_page = $page;
            $r_refer = '';
        }
        Utility::redirect(get_page_location_uri($r_page, $r_refer));
        exit;
    }
}
示例#2
0
function get_fullname($name, $refer)
{
    return Utility::getPageName($name, $refer);
}
示例#3
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;
}
示例#4
0
function plugin_bugtrack_write($base, $pagename, $summary, $name, $priority, $state, $category, $version, $body)
{
    global $vars;
    $base = strip_bracket($base);
    $pagename = strip_bracket($pagename);
    $postdata = plugin_bugtrack_template($base, $summary, $name, $priority, $state, $category, $version, $body);
    $id = $jump = 1;
    $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
    while (is_page($page)) {
        $id = $jump;
        $jump += 50;
        $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $jump);
    }
    $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
    while (is_page($page)) {
        $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, ++$id);
    }
    if (empty($pagename)) {
        Factory::Wiki($page)->set($postdata);
    } else {
        $pagename = Utility::getPageName($pagename, $base);
        $wiki = Factory::Wiki($page);
        if ($wiki->isValied()) {
            $pagename = $page;
            // Set default
        } else {
            $wiki->set('move to [[' . $pagename . ']]');
        }
        Factory::Wiki($pagename)->set($postdata);
    }
    return $page;
}
示例#5
0
function plugin_ref_body($args)
{
    global $vars;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'justify' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'noimg' => FALSE, 'nolink' => FALSE, 'zoom' => FALSE, 'rounded' => FALSE, 'circle' => FALSE, 'thumbnail' => FALSE, 'novideo' => FALSE, 'noaudio' => FALSE, 'autoplay' => FALSE, '_align' => PLUGIN_REF_DEFAULT_ALIGN, '_size' => True, '_w' => 0, '_h' => 0, '_%' => 0, '_title' => null, '_body' => null, '_error' => null, '_class' => '');
    // [Page_name/maybe-separated-with/slashes/]AttachedFileName.sfx or URI
    $name = array_shift($args);
    // ファイル名
    // 第一引数が InterWiki か
    if (Utility::isInterWiki($name)) {
        preg_match('/^' . RendererDefines::INTERWIKINAME_PATTERN . '$/', $name, $intermatch);
        $intername = $intermatch[2];
        $interparam = $intermatch[3];
        $interurl = InterWikiName::getInterWikiUrl($intername, $interparam);
        if ($interurl !== FALSE) {
            $name = $interurl;
        }
    }
    $is_url = Utility::isUri($name);
    // アドレスか?
    // 画像
    $seems_image = !$params['noimg'] && preg_match(RendererDefines::IMAGE_EXTENTION_PATTERN, $name);
    // ビデオ
    $seems_video = !$params['novideo'] && preg_match(RendererDefines::VIDEO_EXTENTION_PATTERN, $name);
    // 音声
    $seems_audio = !$params['noaudio'] && preg_match(RendererDefines::AUDIO_EXTENTION_PATTERN, $name);
    $file = '';
    // Path to the attached file
    $is_file = FALSE;
    if (!$is_url) {
        if (!is_dir(UPLOAD_DIR)) {
            $params['_error'] = 'UPLOAD_DIR is not found.';
            return $params;
        }
        // ページ名が空の時は処理しない
        if (empty($page)) {
            return '';
        }
        $matches = array();
        if (preg_match('#^(.+)/([^/]+)$#', $name, $matches)) {
            // Page_name/maybe-separated-with/slashes and AttachedFileName.sfx
            // #ref(ページ名/ファイル名) 新形式の表記
            if ($matches[1] === '.' || $matches[1] === '..') {
                // 相対パスでの指定
                $matches[1] .= '/';
                // Restore relative paths
            }
            // ファイル名を取得
            $name = $matches[2];
            // AttachedFileName.sfx
            $page = Utility::getPageName($matches[1], $page);
            // strip is a compat
        } else {
            if (isset($args[0]) && !empty($args[0]) && !isset($params[$args[0]])) {
                // Is the second argument a page-name or a path-name? (compat)
                // #ref(ファイル名,ページ名) 古い形式の表記
                $_page = array_shift($args);
                // 引用元のページ名
                // Looks like WikiName, or double-bracket-inserted pagename? (compat)
                $is_bracket_bracket = preg_match('/^(' . RendererDefines::WIKINAME_PATTERN . '|\\[\\[' . RendererDefines::BRACKETNAME_PATTERN . '\\]\\])$/', $_page);
                $page = Utility::getPageName(Utility::stripBracket($_page), $page);
                // strip is a compat
                $a = new Attach($_page, $name);
                if (!$is_bracket_bracket || !$a->has()) {
                    // Promote new design
                    if ($is_file && is_file(UPLOAD_DIR . encode($page) . '_' . encode($name))) {
                        // Because of race condition NOW
                        $params['_error'] = 'The same file name "' . $name . '" at both page: "' . $page . '" and "' . $_page . '". Try ref(pagename/filename) to specify one of them';
                    } else {
                        // Because of possibility of race condition, in the future
                        $params['_error'] = 'The style &amp;ref(filename,pagename) is ambiguous ' . 'and become obsolete. ' . 'Please try ref(pagename/filename)';
                    }
                    return $params;
                }
                $page = $_page;
                // Suppose it
            }
        }
        // Attachオブジェクトを生成
        $a = new Attach($page, $name);
        if (!$a->has()) {
            $params['_error'] = 'File not found: "' . Utility::htmlsc($name) . '" at page "' . Utility::htmlsc($page) . '"';
            return $params;
        }
    }
    // 残りの引数の処理
    if (!empty($args)) {
        $keys = array_keys($params);
        $params['_done'] = false;
        foreach ($args as $val) {
            list($_key, $_val) = array_pad(explode(':', $val, 2), 2, TRUE);
            $_key = trim(strtolower($_key));
            if (is_string($_val)) {
                $_val = trim($_val);
            }
            if (in_array($_key, $keys) && $params['_done'] !== TRUE) {
                $params[$_key] = $_val;
                // Exist keys
            } elseif ($val != '') {
                $params['_args'][] = $val;
                // Not exist keys, in '_args'
            }
        }
    }
    $width = $height = 0;
    $url = $url2 = '';
    if ($is_url) {
        // 外部リンクの場合
        $url = $name;
        $url2 = $name;
        if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) {
            //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this';
            //return $params;
            $params['_body'] = '<a href="' . $url . '" rel="external">' . $s_url . '</a>';
            return $params;
        }
        $matches = array();
        $params['_title'] = preg_match('#([^/]+)$#', $url, $matches) ? $matches[1] : $url;
    } else {
        // Wikiの添付ファイルの場合
        // Count downloads with attach plugin
        $url = Router::get_cmd_uri('attach', null, null, array('refer' => $page, 'openfile' => $name));
        $url2 = '';
        $params['_title'] = $name;
        if ($seems_image || $seems_video || $seems_audio) {
            // URI for in-line image output
            $url2 = $url;
            // With ref plugin (faster than attach)
            $url = Router::get_cmd_uri('ref', $page, null, array('src' => $name));
            if ($seems_image) {
                // 画像の場合は、getimagesizeでサイズを読み取る
                $size = getimagesize($a->basename);
                if (is_array($size)) {
                    $params['_w'] = $size[0];
                    $params['_h'] = $size[1];
                }
            }
        }
    }
    // 拡張パラメータをチェック
    if (!empty($params['_args'])) {
        $_title = array();
        foreach ($params['_args'] as $arg) {
            if (preg_match('/^([0-9]+)x([0-9]+)$/', $arg, $matches)) {
                $params['_size'] = TRUE;
                $params['_w'] = $matches[1];
                $params['_h'] = $matches[2];
            } else {
                if (preg_match('/^([0-9.]+)%$/', $arg, $matches) && $matches[1] > 0) {
                    $params['_%'] = $matches[1];
                } else {
                    $_title[] = $arg;
                }
            }
        }
    }
    foreach (array('right', 'left', 'center', 'justify') as $align) {
        if (isset($params[$align])) {
            $params['_align'] = $align;
            unset($params[$align]);
            break;
        }
    }
    $s_title = isset($params['_title']) ? Inline::setLineRules(Utility::htmlsc($params['_title'])) : '';
    $s_info = '';
    if ($seems_image || $seems_video) {
        // 指定されたサイズを使用する
        $info = '';
        if ($width === 0 && $height === 0) {
            $width = $params['_w'];
            $height = $params['_h'];
        }
        if ($params['_size']) {
            if ($params['zoom']) {
                $_w = $params['_w'] ? $width / $params['_w'] : 0;
                $_h = $params['_h'] ? $height / $params['_h'] : 0;
                $zoom = max($_w, $_h);
                if ($zoom) {
                    $width = (int) ($width / $zoom);
                    $height = (int) ($height / $zoom);
                }
            } else {
                $width = $params['_w'] ? $params['_w'] : $width;
                $height = $params['_h'] ? $params['_h'] : $height;
            }
        }
        if ($params['_%']) {
            $width = (int) ($width * $params['_%'] / 100);
            $height = (int) ($height * $params['_%'] / 100);
        }
        $info = $width && $height ? 'width="' . $width . '" height="' . $height . '" ' : '';
        if ($seems_image) {
            $body = '<img src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" ' . $info . '/>';
        } else {
            if ($seems_video) {
                $body = '<video src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" ' . $s_info . ' controls="controls" preload="auto">';
            }
        }
        if (!isset($params['nolink']) && $url2) {
            $params['_body'] = '<a href="' . $url2 . '" title="' . $s_title . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . "\n" . $body . "\n" . '</a>';
        } else {
            $params['_body'] = $body;
        }
    } else {
        if ($seems_audio) {
            // 音声
            $body = '<audio src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" controls="controls" preload="auto" />';
            if (!isset($params['nolink']) && $url2) {
                $params['_body'] = '<a href="' . $url2 . '" title="' . $s_title . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . "\n" . (isset($params['noicon']) ? '' : '<span class="fa fa-music"></span>') . $body . "\n" . '</a>';
            } else {
                $params['_body'] = $body;
            }
        } else {
            // リンクを貼り付ける
            if (!$is_url && $is_file) {
                $s_info = Utility::htmlsc(get_date('Y/m/d H:i:s', filemtime($file)) . ' ' . sprintf('%01.1f', round(filesize($file) / 1024, 1)) . 'KB');
            }
            $params['_body'] = '<a href="' . $url . '" title="' . $s_info . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . (isset($params['noicon']) ? '' : '<span class="fa fa-paperclip"></span>') . $s_title . '</a>';
        }
    }
    return $params;
}