Exemplo n.º 1
0
function plugin_ls2_show_lists($prefix, &$params)
{
    //	global $_ls2_err_nopages;
    $pages = array();
    if ($prefix != '') {
        foreach (auth::get_existpages() as $_page) {
            if (strpos($_page, $prefix) === 0) {
                $pages[] = $_page;
            }
        }
    } else {
        $pages = auth::get_existpages();
    }
    natcasesort($pages);
    if ($params['reverse']) {
        $pages = array_reverse($pages);
    }
    foreach ($pages as $page) {
        $params['page_ ' . $page] = 0;
    }
    if (empty($pages)) {
        return str_replace('$1', htmlspecialchars($prefix), '<p>' . _("There is no child page in ' \$1'") . '</p>');
    } else {
        $params['result'] = $params['saved'] = array();
        foreach ($pages as $page) {
            plugin_ls2_get_headings($page, $params, 1);
        }
        return join("\n", $params['result']) . join("\n", $params['saved']);
    }
}
function build_directory_list($roots, $option = array())
{
    global $WikiName, $BracketName;
    $list = $warnings = array();
    $list['directory'] = $list['warning'] = array();
    $pages = auth::get_existpages();
    foreach ($roots as $root) {
        $matched = FALSE;
        foreach ($pages as $page) {
            // $page = strip_bracket($page);
            //			if (preg_match("/^$root.*$/", $page)){
            if (strpos($page, $root) === 0) {
                if (isset($option['directory only']) && $option['directory only'] && strrpos($page, '/') >= strlen($root)) {
                    $page = substr($page, 0, strrpos($page, '/'));
                }
                $list['directory'][] = $page;
                while (strrpos($page, '/') >= strlen($root)) {
                    $page = substr($page, 0, strrpos($page, '/'));
                    $list['directory'][] = $page;
                }
                $matched = TRUE;
            }
        }
        if (!$matched) {
            $list['directory'][] = $root;
            $warnings[] = '<font color="red">' . sprintf(_("#%s doesn't have the corresponding page. "), $root) . '</font>' . '(<a href="' . get_page_uri($root) . '">' . _('making') . "</a>)<br />\n";
        }
    }
    $list['directory'] = array_unique($list['directory']);
    natcasesort($list['directory']);
    if (isset($option['quiet']) && !$option['quiet']) {
        $list['warning'] = $warnings;
    }
    return $list;
}
Exemplo n.º 3
0
function plugin_tb_action()
{
    global $vars, $trackback;
    if (isset($vars['url'])) {
        // Receive and save a TrackBack Ping (both GET and POST)
        $url = $vars['url'];
        $tb_id = isset($vars['tb_id']) ? $vars['tb_id'] : '';
        plugin_tb_save($url, $tb_id);
        // Send a response (and exit)
    } else {
        if ($trackback && isset($vars['__mode']) && isset($vars['tb_id'])) {
            // Show TrackBacks received (and exit)
            switch ($vars['__mode']) {
                case 'rss':
                    plugin_tb_mode_rss($vars['tb_id']);
                    break;
                    // case 'view': plugin_tb_mode_view($vars['tb_id']); break;
                // case 'view': plugin_tb_mode_view($vars['tb_id']); break;
                case 'view':
                    return plugin_tb_mode_view($vars['tb_id']);
            }
        }
        // Show List of pages that TrackBacks reached
        $pages = auth::get_existpages(TRACKBACK_DIR, '.txt');
        if (!empty($pages)) {
            return array('msg' => 'Trackback list', 'body' => page_list($pages, 'read', FALSE));
        } else {
            return array('msg' => '', 'body' => '');
        }
    }
}
Exemplo n.º 4
0
function count_files($no = 0, $pref = '')
{
    // 0:DATA, 1:TB, 2:Referer, 3: DIFF, 4:BKUP, 5:CTR
    static $dir = array(DATA_DIR, TRACKBACK_DIR, REFERER_DIR, DIFF_DIR, BACKUP_DIR, COUNTER_DIR);
    static $ext = array('.txt', '.txt', '.ref', '.txt', BACKUP_EXT, '.count');
    // コンテンツ管理者以上は、全てのファイルを対象にする
    if (!auth::check_role('role_adm_contents')) {
        $pages = get_existpages($dir[$no], $ext[$no]);
    } else {
        // 自分が閲覧できるページ数のみ戻す
        $pages = auth::get_existpages($dir[$no], $ext[$no]);
    }
    // 条件なし
    if (empty($pref)) {
        return count($pages);
    }
    // 指定文書のカウント
    $i = 0;
    foreach ($pages as $page) {
        if (strpos($page, $pref) === 0) {
            $i++;
        }
    }
    return $i;
}
Exemplo n.º 5
0
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'] . '/';
    $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) {
            list($comment) = get_source($page);
            // 見出しの固有ID部を削除
            $comment = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/', '$1$2', $comment);
            $comment = '- ' . ereg_replace('^[-*]+', '', $comment);
        }
        $ls[] = "-[[{$page}]] {$comment}";
    }
    return convert_html($ls);
}
Exemplo n.º 6
0
function plugin_deleted_action()
{
    global $vars;
    $_deleted_plugin_title = _('The list of deleted pages');
    $_deleted_plugin_title_withfilename = _('The list of deleted pages (with filename)');
    $dir = isset($vars['dir']) ? $vars['dir'] : 'backup';
    $withfilename = isset($vars['file']);
    $_DIR['diff']['dir'] = DIFF_DIR;
    $_DIR['diff']['ext'] = '.txt';
    $_DIR['backup']['dir'] = BACKUP_DIR;
    $_DIR['backup']['ext'] = BACKUP_EXT;
    // .gz or .txt
    //$_DIR['cache' ]['dir'] = CACHE_DIR; // No way to delete them via web browser now
    //$_DIR['cache' ]['ext'] = '.ref';
    //$_DIR['cache' ]['ext'] = '.rel';
    if (!isset($_DIR[$dir])) {
        return array('msg' => 'Deleted plugin', 'body' => 'No such setting: Choose backup or diff');
    }
    $deleted_pages = array_diff(auth::get_existpages($_DIR[$dir]['dir'], $_DIR[$dir]['ext']), auth::get_existpages());
    if ($withfilename) {
        $retval['msg'] = $_deleted_plugin_title_withfilename;
    } else {
        $retval['msg'] = $_deleted_plugin_title;
    }
    $retval['body'] = page_list($deleted_pages, $dir, $withfilename);
    return $retval;
}
Exemplo n.º 7
0
function plugin_referer_action()
{
    global $vars, $referer;
    global $_referer_msg;
    // Setting: Off
    if (!$referer) {
        return array('msg' => '', 'body' => '');
    }
    if (isset($vars['page']) && $vars['page'] != '' && is_page($vars['page'])) {
        $sort = empty($vars['sort']) ? '0d' : $vars['sort'];
        return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => plugin_referer_body($vars['page'], $sort));
    }
    $pages = auth::get_existpages(TRACKBACK_DIR, '.ref');
    if (empty($pages)) {
        return array('msg' => '', 'body' => '');
    } else {
        $body = '';
        $sort = empty($vars['sort']) ? '0d' : $vars['sort'];
        foreach ($pages as $page) {
            $body .= '<h2>' . make_pagelink($page) . '</h2>';
            $body .= plugin_referer_body($page, $sort);
        }
        return array('msg' => 'referer list', 'body' => $body);
    }
}
Exemplo n.º 8
0
function plugin_yetlist_action()
{
    //	global $_title_yetlist, $_err_notexist, $_symbol_noexists, $non_list;
    global $_symbol_noexists, $non_list, $whatsdeleted;
    $retval = array('msg' => _('List of pages which have not yet been created.'), 'body' => '');
    // Diff
    $pages = array_diff(auth::get_existpages(CACHE_DIR, '.ref'), auth::get_existpages());
    if (empty($pages)) {
        $retval['body'] = _('All pages have been created.');
        return $retval;
    }
    $empty = TRUE;
    // Load .ref files and Output
    $refer_regex = '/' . $non_list . '|^' . preg_quote($whatsdeleted, '/') . '$/S';
    asort($pages, SORT_STRING);
    foreach ($pages as $file => $page) {
        $refer = array();
        foreach (file(CACHE_DIR . $file) as $line) {
            list($_page) = explode("\t", rtrim($line));
            $refer[] = $_page;
        }
        // Diff
        $refer = array_diff($refer, preg_grep($refer_regex, $refer));
        if (!empty($refer)) {
            $empty = FALSE;
            $refer = array_unique($refer);
            sort($refer, SORT_STRING);
            $r_refer = '';
            $link_refs = array();
            foreach ($refer as $_refer) {
                $r_refer = rawurlencode($_refer);
                $link_refs[] = '<a href="' . get_page_uri($_refer) . '">' . htmlspecialchars($_refer) . '</a>';
            }
            $link_ref = join(' ', $link_refs);
            unset($link_refs);
            $s_page = htmlspecialchars($page);
            //			if (PKWK_READONLY) {
            if (auth::check_role('readonly')) {
                $href = $s_page;
            } else {
                // Dangling link
                $href = '<span class="noexists">' . $s_page . '<a href="' . get_cmd_uri('edit', $page, '', 'refer=' . $r_refer) . '">' . $_symbol_noexists . '</a></span>';
            }
            $retval['body'] .= '<li>' . $href . ' <em>(' . $link_ref . ')</em></li>' . "\n";
        }
    }
    if ($empty) {
        $retval['body'] = $_err_notexist;
        return $retval;
    }
    if ($retval['body'] != '') {
        $retval['body'] = '<ul>' . "\n" . $retval['body'] . '</ul>' . "\n";
    }
    return $retval;
}
Exemplo n.º 9
0
function plugin_list_getlist($withfilename = FALSE, $listcmd = 'read')
{
    global $non_list, $whatsnew;
    $pages = array_diff(auth::get_existpages(), array($whatsnew));
    if (!$withfilename) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    if (empty($pages)) {
        return '';
    }
    $cmd = $listcmd == 'read' || $listcmd == 'edit' ? $listcmd : 'read';
    return page_list($pages, $cmd, $withfilename);
}
Exemplo n.º 10
0
function plugin_loglist_convert()
{
    global $script, $log;
    global $vars;
    global $_loglist_messages;
    @(list($kind) = func_get_args());
    $kind = empty($kind) ? 'update' : htmlspecialchars($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, create_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=';
    $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 convert_html($rc);
}
Exemplo n.º 11
0
function plugin_random_action()
{
    global $vars;
    $pattern = strip_bracket($vars['refer']) . '/';
    $pages = array();
    foreach (auth::get_existpages() as $_page) {
        if (strpos($_page, $pattern) === 0) {
            $pages[$_page] = strip_bracket($_page);
        }
    }
    srand((double) microtime() * 1000000);
    $page = array_rand($pages);
    if ($page != '') {
        $vars['refer'] = $page;
    }
    return array('body' => '', 'msg' => '');
}
Exemplo n.º 12
0
function plugin_referer_action()
{
    global $vars, $referer;
    global $_referer_msg;
    // Setting: Off
    if (!$referer) {
        return array('msg' => '', 'body' => '');
    }
    if (isset($vars['page']) && is_page($vars['page'])) {
        check_readable($vars['page'], false);
        $sort = empty($vars['sort']) ? '0d' : $vars['sort'];
        return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => plugin_referer_body($vars['page'], $sort));
    }
    $pages = auth::get_existpages(REFERER_DIR, '.ref');
    if (empty($pages)) {
        return array('msg' => '', 'body' => '');
    } else {
        return array('msg' => 'referer list', 'body' => page_list($pages, 'referer', FALSE));
    }
}
Exemplo n.º 13
0
function plugin_touchgraph_ref()
{
    foreach (auth::get_existpages() as $page) {
        if (check_non_list($page)) {
            continue;
        }
        $file = CACHE_DIR . encode($page) . '.ref';
        if (file_exists($file)) {
            echo $page;
            foreach (file($file) as $line) {
                list($name) = explode("\t", $line);
                if (check_non_list($name)) {
                    continue;
                }
                echo ' ', $name;
            }
            echo "\n";
        }
    }
}
Exemplo n.º 14
0
function plugin_nonlist_getlist($cmd = 0)
{
    global $non_list, $whatsnew;
    if ($cmd == 0) {
        $pages = array_diff(auth::get_existpages(), array($whatsnew));
        $pages = preg_grep('/' . $non_list . '/S', $pages);
        if (empty($pages)) {
            return '';
        }
        return page_list($pages, 'read', false);
    }
    $pages = array_diff(auth::get_existpages(), array($whatsnew));
    // : のみ抜粋
    $pages = preg_grep('/^\\:/S', $pages);
    if ($cmd == 2) {
        $pages = preg_grep('/^\\:config\\//S', $pages);
    }
    if (empty($pages)) {
        return '';
    }
    return page_list($pages, 'read', false);
}
Exemplo n.º 15
0
function replace_do($search, $replace, $notimestamp)
{
    global $cycle, $cantedit;
    global $_replace_msg;
    // パスワードが合ってたらいよいよ置換
    $pages = auth::get_existpages();
    $replaced_pages = array();
    foreach ($pages as $page) {
        if (REPLACE_IGNORE_FREEZE) {
            $editable = !in_array($page, $cantedit);
        } else {
            $editable = (!is_freeze($page) and !in_array($page, $cantedit));
        }
        if ($editable) {
            // パスワード一致
            $postdata = '';
            $postdata_old = get_source($page);
            foreach ($postdata_old as $line) {
                // キーワードの置換
                $line = str_replace($search, $replace, $line);
                $postdata .= $line;
            }
            if ($postdata != join('', $postdata_old)) {
                $cycle = 0;
                set_time_limit(30);
                page_write($page, $postdata, $notimestamp);
                $replaced_pages[] = htmlspecialchars($page);
            }
        }
    }
    $vars['cmd'] = 'read';
    if (count($replaced_pages) == 0) {
        return array('msg' => $_replace_msg['msg_H0_no_data'], 'body' => '<p>' . $_replace_msg['msg_no_replaced'] . '</p>');
    }
    return array('msg' => $_replace_msg['msg_H0_replaced'], 'body' => '<p>' . $_replace_msg['msg_replaced'] . "</p>\n<p>" . join("<br />\n", $replaced_pages) . '</p>');
}
Exemplo n.º 16
0
function plugin_navi_convert()
{
    global $vars, $head_tags;
    //	global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
    static $navi = array();
    $_navi_prev = _('Prev');
    $_navi_next = _('Next');
    $_navi_up = _('Up');
    $_navi_home = _('Home');
    $current = $vars['page'];
    $reverse = FALSE;
    if (func_num_args()) {
        list($home, $reverse) = array_pad(func_get_args(), 2, '');
        // strip_bracket() is not necessary but compatible
        $home = get_fullname(strip_bracket($home), $current);
        $is_home = $home == $current;
        if (!is_page($home)) {
            return '#navi(contents-page-name): No such page: ' . htmlspecialchars($home) . '<br />';
        } else {
            if (!$is_home && !preg_match('/^' . preg_quote($home, '/') . '/', $current)) {
                return '#navi(' . htmlspecialchars($home) . '): Not a child page like: ' . htmlspecialchars($home . '/' . basepagename($current)) . '<br />';
            }
        }
        $reverse = strtolower($reverse) == 'reverse';
    } else {
        $home = $vars['page'];
        $is_home = TRUE;
        // $home == $current
    }
    $pages = array();
    $footer = isset($navi[$home]);
    // The first time: FALSE, the second: TRUE
    if (!$footer) {
        $navi[$home] = array('up' => '', 'prev' => '', 'prev1' => '', 'next' => '', 'next1' => '', 'home' => '', 'home1' => '');
        $pages = preg_grep('/^' . preg_quote($home, '/') . '($|\\/)/', auth::get_existpages());
        if (PLUGIN_NAVI_EXCLUSIVE_REGEX != '') {
            // If old PHP could use preg_grep(,,PREG_GREP_INVERT)...
            $pages = array_diff($pages, preg_grep(PLUGIN_NAVI_EXCLUSIVE_REGEX, $pages));
        }
        $pages[] = $current;
        // Sentinel :)
        $pages = array_unique($pages);
        natcasesort($pages);
        if ($reverse) {
            $pages = array_reverse($pages);
        }
        $prev = $home;
        foreach ($pages as $page) {
            if ($page == $current) {
                break;
            }
            $prev = $page;
        }
        $next = current($pages);
        $pos = strrpos($current, '/');
        $up = '';
        if ($pos > 0) {
            $up = substr($current, 0, $pos);
            $navi[$home]['up'] = make_pagelink($up, $_navi_up);
        }
        if (!$is_home) {
            $navi[$home]['prev'] = make_pagelink($prev);
            $navi[$home]['prev1'] = make_pagelink($prev, $_navi_prev);
        }
        if ($next != '') {
            $navi[$home]['next'] = make_pagelink($next);
            $navi[$home]['next1'] = make_pagelink($next, $_navi_next);
        }
        $navi[$home]['home'] = make_pagelink($home);
        $navi[$home]['home1'] = make_pagelink($home, $_navi_home);
        // Generate <link> tag: start next prev(previous) parent(up)
        // Not implemented: contents(toc) search first(begin) last(end)
        if (PLUGIN_NAVI_LINK_TAGS) {
            foreach (array('start' => $home, 'next' => $next, 'prev' => $prev, 'up' => $up) as $rel => $_page) {
                if ($_page != '') {
                    $s_page = htmlspecialchars($_page);
                    $head_tags[] = ' <link rel="' . $rel . '" href="' . get_page_uri($_page) . '" title="' . $s_page . '" />';
                }
            }
        }
    }
    $ret = '';
    if ($is_home) {
        // Show contents
        $count = count($pages);
        if ($count == 0) {
            return '#navi(contents-page-name): You already view the result<br />';
        } else {
            if ($count == 1) {
                // Sentinel only: Show usage and warning
                $home = htmlspecialchars($home);
                $ret .= '#navi(' . $home . '): No child page like: ' . $home . '/Foo';
            } else {
                $ret .= '<ul>';
                foreach ($pages as $page) {
                    if ($page != $home) {
                        $ret .= ' <li>' . make_pagelink($page) . '</li>';
                    }
                }
                $ret .= '</ul>';
            }
        }
    } else {
        if (!$footer) {
            // Header
            $ret = <<<EOD
<ul class="navi">
 <li class="navi_left">{$navi[$home]['prev1']}</li>
 <li class="navi_right">{$navi[$home]['next1']}</li>
 <li class="navi_none">{$navi[$home]['home']}</li>
</ul>
<hr class="full_hr" />
EOD;
        } else {
            // Footer
            $ret = <<<EOD
<hr class="full_hr" />
<ul class="navi">
 <li class="navi_left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
 <li class="navi_right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
 <li class="navi_none">{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>
</ul>
EOD;
        }
    }
    return $ret;
}
Exemplo n.º 17
0
function todo_search($vars, $page, $mark)
{
    if ($page == "''") {
        $page = '';
    }
    // 検索対象を選択
    foreach (auth::get_existpages() as $file => $name) {
        if (strncmp($name, $page, strlen($page)) == 0) {
            $scan[$file] = $name;
        }
    }
    // 探索するマーク行のパターン
    // $expr = "/^[\*\-\s]*(\[".$mark."\].*)/i";
    $expr = "/^[\\*\\-\\+\\s]*(\\[" . $mark . "\\].*)/i";
    // [TODO] マークされているエントリを探す
    $link = array();
    foreach ($scan as $file => $name) {
        foreach (get_source($name) as $line) {
            $line = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/m', '$1$2', $line);
            if (preg_match($expr, $line, $match)) {
                $link[$name][] = $match[1];
            }
        }
    }
    ksort($link);
    return $link;
}
Exemplo n.º 18
0
function plugin_backup_get_list_all($withfilename = FALSE)
{
    global $cantedit;
    if (auth::check_role('safemode')) {
        die_message(_('PKWK_SAFE_MODE prohibits this'));
    }
    $pages = array_diff(auth::get_existpages(BACKUP_DIR, BACKUP_EXT), $cantedit);
    if (empty($pages)) {
        return '';
    } else {
        return page_list($pages, 'backup', $withfilename);
    }
}
Exemplo n.º 19
0
function plugin_rename_getselecttag($page)
{
    global $whatsnew;
    $pages = array();
    foreach (auth::get_existpages() as $_page) {
        if ($_page === $whatsnew) {
            continue;
        }
        $selected = $_page === $page ? ' selected' : '';
        $s_page = htmlspecialchars($_page);
        $pages[$_page] = '<option value="' . $s_page . '"' . $selected . '>' . $s_page . '</option>';
    }
    ksort($pages, SORT_STRING);
    $list = join("\n" . ' ', $pages);
    return <<<EOD
<select name="refer">
 <option value=""></option>
 {$list}
</select>
EOD;
}
Exemplo n.º 20
0
function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list;
    global $search_auth, $show_passage, $search_word_color, $ajax;
    //	global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
    global $_string;
    $retval = array();
    $b_type = $type == 'AND';
    // AND:TRUE OR:FALSE
    $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($keys as $key => $value) {
        $keys[$key] = '/' . $value . '/S';
    }
    $pages = auth::get_existpages();
    // Avoid
    if ($base != '') {
        $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages);
    }
    if (!$search_non_list) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    $pages = array_flip($pages);
    unset($pages[$whatsnew]);
    // SAFE_MODE の場合は、コンテンツ管理者以上のみ、カテゴリページ(:)も検索可能
    $role_adm_contents = auth::check_role('safemode') ? auth::check_role('role_adm_contents') : FALSE;
    $count = count($pages);
    foreach (array_keys($pages) as $page) {
        $b_match = FALSE;
        // Search hidden for page name
        if (substr($page, 0, 1) == ':' && $role_adm_contents) {
            unset($pages[$page]);
            --$count;
            continue;
        }
        // Search for page name
        if (!$non_format) {
            foreach ($keys as $key) {
                $b_match = preg_match($key, $page);
                if ($b_type xor $b_match) {
                    break;
                }
                // OR
            }
            if ($b_match) {
                continue;
            }
        }
        // Search auth for page contents
        if ($search_auth && !check_readable($page, false, false)) {
            unset($pages[$page]);
            --$count;
            continue;
        }
        // Search for page contents
        foreach ($keys as $key) {
            $b_match = preg_match($key, get_source($page, TRUE, TRUE));
            if ($b_match xor $b_type) {
                break;
            }
            // OR
        }
        if ($b_match) {
            continue;
        }
        unset($pages[$page]);
        // Miss
    }
    unset($role_adm_contents);
    if ($non_format) {
        return array_keys($pages);
    }
    $r_word = rawurlencode($word);
    $s_word = htmlspecialchars($word);
    if (empty($pages)) {
        return str_replace('$1', $s_word, $_string['notfoundresult']);
    }
    ksort($pages, SORT_STRING);
    $retval = '<ul>' . "\n";
    foreach (array_keys($pages) as $page) {
        $r_page = rawurlencode($page);
        $s_page = htmlspecialchars($page);
        $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : '';
        if ($search_word_color) {
            $uri = get_page_uri($page, '', 'word=' . $r_word);
            if ($ajax && UA_PROFILE == 'default') {
                $pre = $script . '?' . 'cmd=preview&amp;page=' . $r_page . '&amp;word=' . $r_word;
                $pre = ' onmouseover="showGlossaryPopup(' . "'" . $pre . "'" . ',event,0.2);" onmouseout="hideGlossaryPopup();"';
            } else {
                $pre = '';
            }
        } else {
            $uri = get_page_uri($page);
            $pre = '';
        }
        $retval .= ' <li><a href="' . $uri . '"' . $pre . '>' . $s_page . '</a>' . $passage . '</li>' . "\n";
    }
    $retval .= '</ul>' . "\n";
    $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', $count, $b_type ? $_string['andresult'] : $_string['orresult'])));
    return $retval;
}
Exemplo n.º 21
0
function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
{
    global $script, $vars, $rows, $cols, $hr, $function_freeze;
    global $load_template_func, $load_refer_related;
    global $notimeupdate;
    global $_button, $_string;
    global $ajax, $ctrl_unload;
    // Newly generate $digest or not
    if ($digest === FALSE) {
        $digest = md5(get_source($page, TRUE, TRUE));
    }
    $refer = $template = $addtag = $add_top = $add_ajax = '';
    $checked_top = isset($vars['add_top']) ? ' checked="checked"' : '';
    $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : '';
    if (isset($vars['add'])) {
        $addtag = '<input type="hidden" name="add" value="true" />';
        $add_top = '<input type="checkbox" name="add_top" value="true"' . $checked_top . ' /><span class="small">' . $_button['addtop'] . '</span>';
    }
    if ($load_template_func && $b_template) {
        $pages = array();
        foreach (auth::get_existpages() as $_page) {
            if (is_cantedit($_page) || check_non_list($_page)) {
                continue;
            }
            $s_page = htmlspecialchars($_page);
            $pages[$_page] = '   <option value="' . $s_page . '">' . $s_page . '</option>';
        }
        ksort($pages, SORT_STRING);
        $s_pages = join("\n", $pages);
        $template = <<<EOD
  <select name="template_page">
   <option value="">-- {$_button['template']} --</option>
{$s_pages}
  </select>
  <input type="submit" name="template" value="{$_button['load']}" accesskey="r" />
  <br />
EOD;
        if ($load_refer_related) {
            if (isset($vars['refer']) && $vars['refer'] != '') {
                $refer = '[[' . strip_bracket($vars['refer']) . ']]' . "\n\n";
            }
        }
    }
    $r_page = rawurlencode($page);
    $s_page = htmlspecialchars($page);
    $s_digest = htmlspecialchars($digest);
    $s_postdata = htmlspecialchars($refer . $postdata);
    $s_original = isset($vars['original']) ? htmlspecialchars($vars['original']) : $s_postdata;
    $s_id = isset($vars['id']) ? htmlspecialchars($vars['id']) : '';
    $b_preview = isset($vars['preview']);
    // TRUE when preview
    $btn_preview = $b_preview ? $_button['repreview'] : $_button['preview'];
    $s_ticket = md5(MUTIME);
    if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) {
        // BugTrack/95 fix Problem: browser RSS request with session
        $_SESSION[$s_ticket] = md5(get_ticket() . $digest);
        $_SESSION['origin' . $s_ticket] = md5(get_ticket() . str_replace("\r", '', $s_original));
    }
    if ($ajax && !is_mobile()) {
        $add_ajax = '<input type="button" name="add_ajax" value="' . $btn_preview . '" accesskey="p" onclick="pukiwiki_apx(this.form.page.value)" />';
    } else {
        $add_ajax = '<input type="submit" name="preview" value="' . $btn_preview . '" accesskey="p" />';
    }
    $add_notimestamp = '';
    if ($notimeupdate != 0 && is_page($page)) {
        // enable 'do not change timestamp'
        $add_notimestamp = <<<EOD
  <input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true"{$checked_time} />
  <label for="_edit_form_notimestamp"><span class="small">{$_button['notchangetimestamp']}</span></label>
EOD;
        if ($notimeupdate == 2 && auth::check_role('role_adm_contents')) {
            // enable only administrator
            $add_notimestamp .= <<<EOD
  <input type="password" name="pass" size="12" />
EOD;
        }
        $add_notimestamp .= '&nbsp;';
    }
    $refpage = isset($vars['refpage']) ? htmlspecialchars($vars['refpage']) : '';
    $add_assistant = edit_form_assistant();
    $body = <<<EOD
<div id="realview_outer"><div id="realview"></div><br /></div>
<form action="{$script}" method="post" id="form">
 <div class="edit_form" onmouseup="pukiwiki_pos()" onkeyup="pukiwiki_pos()">
{$template}
  {$addtag}
  <input type="hidden" name="cmd"    value="edit" />
  <input type="hidden" name="page"   value="{$s_page}" />
  <input type="hidden" name="digest" value="{$s_digest}" />
  <input type="hidden" name="ticket" value="{$s_ticket}" />
  <input type="hidden" name="id"     value="{$s_id}" />
  <textarea id="msg" name="msg" rows="{$rows}" cols="{$cols}" onselect="pukiwiki_apv(this.form.page.value,this)" onfocus="pukiwiki_apv(this.form.page.value,this)" onkeyup="pukiwiki_apv(this.form.page.value,this)" onmouseup="pukiwiki_apv(this.form.page.value,this)">{$s_postdata}</textarea>
  <br />
  {$add_assistant}
  <br />
  <input type="submit" name="write"   value="{$_button['update']}" accesskey="s" />
  {$add_top}
  {$add_ajax}
  {$add_notimestamp}
  <input type="submit" id="cancel" name="cancel"  value="{$_button['cancel']}" accesskey="c" />
  <textarea id="original" name="original" rows="1" cols="1" style="display:none">{$s_original}</textarea>
 </div>
</form>
EOD;
    if ($ajax) {
        global $head_tags;
        $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/msxml.js"></script>';
        $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/realedit.js"></script>';
    }
    if ($ctrl_unload) {
        global $head_tags;
        $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/ctrl_unload.js"></script>';
    }
    return $body;
}
Exemplo n.º 22
0
function plugin_dav_maketree0()
{
    global $whatsnew, $attach_link;
    $root = array();
    $pagelist = auth::get_existpages();
    foreach ($pagelist as $page) {
        if (check_non_list($page)) {
            continue;
        }
        if ($page == $whatsnew) {
            continue;
        }
        if (PLUGIN_DAV_SHOWONLYEDITABLE && !is_editable($page)) {
            continue;
        }
        $root[$page] = array();
    }
    // FIXME
    // 認証時は、この制限を回避するようにする。
    // 現状は、添付ファイル非表示の場合は抑止
    if (!$attach_link) {
        return $root;
    }
    $attaches =& new AttachPages('');
    foreach ($attaches->pages as $key => $val) {
        if (check_non_list($key)) {
            continue;
        }
        if (!check_readable($key, false, false)) {
            continue;
        }
        if (PLUGIN_DAV_SHOWONLYEDITABLE && !is_editable($key)) {
            continue;
        }
        if (!isset($root[$key])) {
            $root[$key] = array();
        }
        if (is_array($root[$key])) {
            foreach ($val->files as $file => $arr) {
                if (isset($arr[0])) {
                    $root[$key][$file] = $arr[0];
                }
            }
        }
    }
    return $root;
}
Exemplo n.º 23
0
function plugin_map_action()
{
    global $vars, $whatsnew, $defaultpage, $non_list;
    $reverse = isset($vars['reverse']);
    $refer = isset($vars['refer']) ? $vars['refer'] : '';
    if ($refer == '' || !is_page($refer)) {
        $vars['refer'] = $refer = $defaultpage;
    }
    $retval['msg'] = $reverse ? _('Relation map (link from)') : sprintf(_('Relation map, from %s'), $refer);
    // Get pages
    $pages = array_values(array_diff(auth::get_existpages(), array($whatsnew)));
    if (!PLUGIN_MAP_SHOW_HIDDEN) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/', $pages));
    }
    if (empty($pages)) {
        $retval['body'] = _('No pages.');
        return $retval;
    }
    $body = array();
    // Generate a tree
    $nodes = array();
    foreach ($pages as $page) {
        $nodes[$page] =& new MapNode($page, $reverse);
    }
    // Node not found: Because of filtererd by $non_list
    if (!isset($nodes[$refer])) {
        $vars['refer'] = $refer = $defaultpage;
        $nodes[$refer] =& new MapNode($page, $reverse);
    }
    if ($reverse) {
        $keys = array_keys($nodes);
        sort($keys, SORT_STRING);
        $alone = array();
        $body[] = '<ul>';
        foreach ($keys as $page) {
            if (!empty($nodes[$page]->rels)) {
                $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id);
            } else {
                $alone[] = $page;
            }
        }
        $body[] = '</ul>';
        if (!empty($alone)) {
            $body[] = '<hr />';
            $body[] = _('<p>No link from anywhere in this site.</p>');
            $body[] = '<ul>';
            foreach ($alone as $page) {
                $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id);
            }
            $body[] = '</ul>';
        }
    } else {
        $nodes[$refer]->chain($nodes);
        $body[] = '<ul>';
        $body[] = $nodes[$refer]->toString($nodes) . '</ul>';
        $body[] = '<hr />';
        $body[] = sprintf(_('<p>Not related from %s.</p>'), htmlspecialchars($refer));
        $keys = array_keys($nodes);
        sort($keys, SORT_STRING);
        $body[] = '<ul>';
        foreach ($keys as $page) {
            if (!$nodes[$page]->done) {
                $nodes[$page]->chain($nodes);
                $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id);
            }
        }
        $body[] = '</ul>';
    }
    $body[] = '<hr />';
    $body[] = sprintf(_('<p>Total: %d page(s) on this site.</p>'), count($pages));
    $retval['body'] = implode("\n", $body) . "\n";
    return $retval;
}
Exemplo n.º 24
0
 function get_data_prefix($pref)
 {
     static $pages;
     if (!isset($pages)) {
         $pages = auth::get_existpages();
     }
     $rc = array();
     foreach ($pages as $_page) {
         if (strpos($_page, $pref) === 0) {
             $rc[] = $_page;
         }
     }
     natcasesort($rc);
     return $rc;
 }
Exemplo n.º 25
0
 /**
  * Get filtered pages (not all existpages)
  *
  * @param string $filter regexp filter
  * @param string $except regexp except filter
  * @param string $onepage one exact page name
  */
 function get_pages($filter = '', $except = '', $onepage = '')
 {
     if (!empty($onepage)) {
         return (array) $onepage;
     }
     if (method_exists('auth', 'get_existpages')) {
         // plus!
         $pages = auth::get_existpages();
     } else {
         $pages = get_existpages();
     }
     if (!empty($filter)) {
         $pregfilter = '/' . str_replace('/', '\\/', $filter) . '/';
         foreach ($pages as $file => $page) {
             if (!preg_match($pregfilter, $page)) {
                 unset($pages[$file]);
             }
         }
     }
     if (!empty($except)) {
         $pregexcept = '/' . str_replace('/', '\\/', $except) . '/';
         foreach ($pages as $file => $page) {
             if (preg_match($pregexcept, $page)) {
                 unset($pages[$file]);
             }
         }
     }
     return $pages;
 }
Exemplo n.º 26
0
function plugin_bugtrack_list_convert()
{
    global $vars, $_plugin_bugtrack;
    $page = $vars['page'];
    if (func_num_args()) {
        list($_page) = func_get_args();
        $_page = get_fullname(strip_bracket($_page), $page);
        if (is_pagename($_page)) {
            $page = $_page;
        }
    }
    $data = array();
    $pattern = $page . '/';
    $pattern_len = strlen($pattern);
    foreach (auth::get_existpages() as $page) {
        if (strpos($page, $pattern) === 0 && is_numeric(substr($page, $pattern_len))) {
            array_push($data, plugin_bugtrack_list_pageinfo($page));
        }
    }
    $count_list = count($_plugin_bugtrack['state_list']);
    $table = array();
    for ($i = 0; $i <= $count_list + 1; ++$i) {
        $table[$i] = array();
    }
    foreach ($data as $line) {
        list($page, $no, $summary, $name, $priority, $state, $category) = $line;
        foreach (array('summary', 'name', 'priority', 'state', 'category') as $item) {
            ${$item} = htmlspecialchars(${$item});
        }
        $page_link = make_pagelink($page);
        $state_no = array_search($state, $_plugin_bugtrack['state_sort']);
        if ($state_no === NULL || $state_no === FALSE) {
            $state_no = $count_list;
        }
        $bgcolor = htmlspecialchars($_plugin_bugtrack['state_bgcolor'][$state_no]);
        $row = <<<EOD
 <tr>
  <td style="background-color:{$bgcolor}">{$page_link}</td>
  <td style="background-color:{$bgcolor}">{$state}</td>
  <td style="background-color:{$bgcolor}">{$priority}</td>
  <td style="background-color:{$bgcolor}">{$category}</td>
  <td style="background-color:{$bgcolor}">{$name}</td>
  <td style="background-color:{$bgcolor}">{$summary}</td>
 </tr>
EOD;
        $table[$state_no][$no] = $row;
    }
    $table_html = ' <tr>' . "\n";
    $bgcolor = htmlspecialchars($_plugin_bugtrack['header_bgcolor']);
    foreach (array('pagename', 'state', 'priority', 'category', 'name', 'summary') as $item) {
        $table_html .= '  <th style="background-color:' . $bgcolor . '">' . htmlspecialchars($_plugin_bugtrack[$item]) . '</th>' . "\n";
    }
    $table_html .= ' </tr>' . "\n";
    for ($i = 0; $i <= $count_list; ++$i) {
        ksort($table[$i], SORT_NUMERIC);
        $table_html .= join("\n", $table[$i]);
    }
    return '<table border="1" width="100%">' . "\n" . $table_html . "\n" . '</table>';
}
Exemplo n.º 27
0
function plugin_new_inline()
{
    global $vars, $_plugin_new_elapses;
    $retval = '';
    $args = func_get_args();
    $date = strip_autolink(array_pop($args));
    // {date} always exists
    if ($date !== '') {
        // Show 'New!' message by the time of the $date string
        if (func_num_args() > 2) {
            return '&new([nodate]){date};';
        }
        // dev:BugTrack2/120
        //$timestamp = strtotime($date);
        //if ($timestamp === -1) return '&new([nodate]){date}: Invalid date string;';
        //$timestamp = strtotime(preg_replace('/\([^\x00-\x7F]+\)/','',$date));
        // plus:BugTrack/102
        $timestamp = strtotime(preg_replace('/\\(.*?\\)/', '', $date));
        if ($timestamp === -1 || $timestamp === FALSE) {
            return '&new([nodate]){date}: Invalid date string;';
        }
        // $timestamp -= ZONETIME;
        $retval = in_array('nodate', $args) ? '' : htmlspecialchars($date);
    } else {
        // Show 'New!' message by the timestamp of the page
        if (func_num_args() > 3) {
            return '&new(pagename[,nolink]);';
        }
        $name = strip_bracket(!empty($args) ? array_shift($args) : $vars['page']);
        $page = get_fullname($name, $vars['page']);
        $nolink = in_array('nolink', $args);
        if (substr($page, -1) == '/') {
            // Check multiple pages started with "$page"
            $timestamp = 0;
            $regex = '/^' . preg_quote($page, '/') . '/';
            foreach (preg_grep($regex, auth::get_existpages()) as $page) {
                // Get the latest pagename and its timestamp
                $_timestamp = get_filetime($page);
                if ($timestamp < $_timestamp) {
                    $timestamp = $_timestamp;
                    $retval = $nolink ? '' : make_pagelink($page);
                }
            }
            if ($timestamp == 0) {
                return '&new(pagename/[,nolink]): No such pages;';
            }
        } else {
            // Check a page
            if (is_page($page)) {
                $timestamp = get_filetime($page);
                $retval = $nolink ? '' : make_pagelink($page, $name);
            } else {
                return '&new(pagename[,nolink]): No such page;';
            }
        }
    }
    // Add 'New!' string by the elapsed time
    $erapse = UTIME - $timestamp;
    foreach ($_plugin_new_elapses as $limit => $tag) {
        if ($erapse <= $limit) {
            $retval .= sprintf($tag, get_passage($timestamp));
            break;
        }
    }
    if ($date !== '') {
        // Show a date string
        return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);
    } else {
        // Show a page name
        return $retval;
    }
}
Exemplo n.º 28
0
 function loadRows()
 {
     $base = $this->form->base . '/';
     $len = strlen($base);
     $regex = '#^' . preg_quote($base, '#') . '#';
     foreach (preg_grep($regex, array_values(auth::get_existpages())) as $pagename) {
         if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, substr($pagename, $len))) {
             continue;
         }
         if ($this->addRow($pagename) === FALSE) {
             return FALSE;
         }
     }
     if (empty($this->rows)) {
         $this->error = 'Pages not found under: ' . $base;
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 29
0
function plugin_popular_convert()
{
    global $vars;
    //	global $_popular_plugin_frame, $_popular_plugin_today_frame;
    static $localtime;
    $_popular_plugin_frame_s = _('popular(%d)');
    $_popular_plugin_today_frame_s = _('today\'s(%d)');
    $_popular_plugin_yesterday_frame_s = _('yesterday\'s(%d)');
    $_popular_plugin_recent_frame_s = _('recent\'s(%d)');
    $_popular_plugin_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_frame_s);
    $_popular_plugin_today_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_today_frame_s);
    $_popular_plugin_yesterday_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_yesterday_frame_s);
    $_popular_plugin_recent_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_recent_frame_s);
    $view = 'total';
    $max = PLUGIN_POPULAR_DEFAULT;
    $except = '';
    if (!isset($localtime)) {
        list($zone, $zonetime) = set_timezone(DEFAULT_LANG);
        $localtime = UTIME + $zonetime;
    }
    $today = gmdate('Y/m/d', $localtime);
    // $yesterday = gmdate('Y/m/d', strtotime('yesterday', $localtime));
    $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
    $array = func_get_args();
    switch (func_num_args()) {
        case 3:
            switch ($array[2]) {
                case 'today':
                case 'true':
                    $view = 'today';
                    break;
                case 'yesterday':
                    $view = 'yesterday';
                    break;
                case 'recent':
                    $view = 'recent';
                    break;
                case 'total':
                case 'false':
                default:
                    $view = 'total';
                    break;
            }
        case 2:
            $except = $array[1];
        case 1:
            $max = $array[0];
    }
    $counters = array();
    foreach (auth::get_existpages(COUNTER_DIR, '.count') as $file => $page) {
        if ($except != '' && ereg($except, $page) || is_cantedit($page) || check_non_list($page) || !is_page($page)) {
            continue;
        }
        $array = file(COUNTER_DIR . $file);
        $count = rtrim($array[0]);
        $date = rtrim($array[1]);
        $today_count = rtrim($array[2]);
        $yesterday_count = rtrim($array[3]);
        $counters['_' . $page] = 0;
        if ($view == 'today' or $view == 'recent') {
            // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
            // array_splice()によってキー値が変更されてしまうのを防ぐ
            // ため、キーに '_' を連結する
            if ($today == $date) {
                $counters['_' . $page] = $today_count;
            }
        }
        if ($view == 'yesterday' or $view == 'recent') {
            if ($today == $date) {
                $counters['_' . $page] += $yesterday_count;
            } elseif ($yesterday == $date) {
                $counters['_' . $page] += $today_count;
            }
        }
        if ($view == 'total') {
            $counters['_' . $page] = $count;
        }
        if ($counters['_' . $page] == 0) {
            unset($counters['_' . $page]);
        }
    }
    asort($counters, SORT_NUMERIC);
    // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
    $counters = array_reverse($counters, TRUE);
    // with array_splice()
    $counters = array_splice($counters, 0, $max);
    $items = '';
    if (!empty($counters)) {
        $items = '<ul class="popular_list">' . "\n";
        foreach ($counters as $page => $count) {
            $page = substr($page, 1);
            $s_page = htmlspecialchars($page);
            if ($page == $vars['page']) {
                // No need to link itself, notifies where you just read
                $pg_passage = get_pg_passage($page, FALSE);
                $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' . $s_page . '<span class="counter">(' . $count . ')</span></span></li>' . "\n";
            } else {
                $items .= ' <li>' . make_pagelink($page, $s_page . '<span class="counter">(' . $count . ')</span>') . '</li>' . "\n";
            }
        }
        $items .= '</ul>' . "\n";
    }
    switch ($view) {
        case 'today':
            $frame = $_popular_plugin_today_frame;
            break;
        case 'yesterday':
            $frame = $_popular_plugin_yesterday_frame;
            break;
        case 'recent':
            $frame = $_popular_plugin_recent_frame;
            break;
        case 'total':
        default:
            $frame = $_popular_plugin_frame;
            break;
    }
    return sprintf($frame, count($counters), $items);
}