Example #1
0
function plugin_deleted_action()
{
    global $vars, $_deleted_msg;
    $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' => $_deleted_msg['no_such_setting']);
    }
    $deleted_pages = array_diff(Auth::get_existpages($_DIR[$dir]['dir'], $_DIR[$dir]['ext']), Auth::get_existpages());
    if ($withfilename) {
        $retval['msg'] = $_deleted_msg['title_withfilename'];
    } else {
        $retval['msg'] = $_deleted_msg['title_collision'];
    }
    $retval['body'] = page_list($deleted_pages, $dir, $withfilename);
    return $retval;
}
Example #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>');
}
Example #3
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'] . '/';
    $page = isset($vars['page']) ? $vars['page'] : '';
    $pages = array();
    foreach (Auth::get_existpages() as $page) {
        if (strpos($page, $prefix) === 0) {
            $pages[] = $page;
        }
    }
    natcasesort($pages);
    $ls = array();
    foreach ($pages as $page) {
        $comment = '';
        if ($with_title) {
            $array = file_head(get_filename($page), 1);
            if ($array) {
                $comment = ' - ' . preg_replace(array('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/S', '/^(?:-+|\\*+)/'), array('$1$2', null), current($array));
            }
        }
        $ls[] = "-[[{$page}]] {$comment}";
    }
    return RendererFactory::factory($ls);
}
Example #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_contents_admin')) {
        $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;
}
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[] = '<p><span class="text-danger">' . sprintf(T_("#%s doesn't have the corresponding page. "), $root) . '</span>' . '(<a href="' . get_page_uri($root) . '">' . T_('making') . "</a>)</p>\n";
        }
    }
    $list['directory'] = array_unique($list['directory']);
    natcasesort($list['directory']);
    if (isset($option['quiet']) && !$option['quiet']) {
        $list['warning'] = $warnings;
    }
    return $list;
}
Example #6
0
function plugin_yetlist_action()
{
    //	global $_title_yetlist, $_err_notexist, $_symbol_noexists, $non_list;
    global $_symbol_noexists, $non_list, $whatsdeleted;
    $retval = array('msg' => 'yetlist', 'body' => T_('List of pages which have not yet been created.'));
    // Diff
    $pages = array_diff(Auth::get_existpages(CACHE_DIR, '.ref'), Auth::get_existpages());
    if (empty($pages)) {
        $retval['body'] = T_('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) . '">' . htmlsc($_refer) . '</a>';
            }
            $link_ref = join(' ', $link_refs);
            unset($link_refs);
            $s_page = htmlsc($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;
}
Example #7
0
function plugin_loglist_convert()
{
    global $script, $log;
    global $vars;
    global $_loglist_messages;
    list($kind) = func_get_args();
    $kind = empty($kind) ? 'update' : htmlsc($kind, ENT_QUOTES);
    if (!$log[$kind]['use']) {
        return $_loglist_messages['not_active'];
    }
    if (!empty($log[$kind]['file'])) {
        $vars['kind'] = $kind;
        $rc = do_plugin_action('logview');
        return $rc['body'];
    }
    $dir = log::get_filename($kind, '', '');
    $pages = Auth::get_existpages($dir);
    if (count($pages) == 0) {
        return $_loglist_messages['msg_not_found'];
    }
    $data = array();
    foreach ($pages as $_real => $_page) {
        $data[] = array(filemtime($dir . '/' . $_real), $_page, log_count($kind, $_page));
    }
    usort($data, function ($a, $b) {
        return $b[0] - $a[0];
    });
    // D
    // usort($data,create_function('$a,$b','return $a[0] - $b[0];')); // A
    //$str_view = $script.'?plugin=logview&kind='.$kind.'&page=';
    $str_view = get_cmd_uri('logview', $_page, null, array('kind' => $kind));
    $rc = '';
    $rc .= '|' . $_loglist_messages['fld_UTIME'] . '|' . $_loglist_messages['fld_PAGE'] . '|' . $_loglist_messages['fld_COUNT'] . "|h\n";
    foreach ($data as $_line) {
        $i = 0;
        foreach ($_line as $_field) {
            $rc .= '|';
            switch ($i) {
                case 0:
                    $rc .= get_date('Y-m-d H:i:s', $_field) . ' ' . get_passage($_field);
                    continue;
                case 1:
                    $rc .= '[' . $str_view . rawurlencode($_field) . ' ' . $_field . ']';
                    continue;
                default:
                    $rc .= $_field;
            }
            $i++;
        }
        $rc .= "|\n";
    }
    return RendererFactory::factory($rc);
}
Example #8
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' => '');
}
Example #9
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";
        }
    }
}
Example #10
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);
}
Example #11
0
function plugin_rename_getselecttag($page)
{
    global $whatsnew;
    $pages = array();
    foreach (Auth::get_existpages() as $_page) {
        if (is_cantedit($_page)) {
            continue;
        }
        $selected = $_page === $page ? ' selected' : '';
        $s_page = htmlsc($_page);
        $pages[$_page] = '<option value="' . $s_page . '"' . $selected . '>' . $s_page . '</option>';
    }
    ksort($pages, SORT_STRING);
    $list = join("\n" . ' ', $pages);
    return <<<EOD
<select name="refer" class="form-control">
\t<option value="" disabled="disabled" selected="selected">--------------------</option>
\t{$list}
</select>
EOD;
}
Example #12
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;
}
Example #13
0
function plugin_navi_convert()
{
    global $vars, $link_tags;
    //	global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
    static $navi = array();
    $_navi_prev = T_('Prev');
    $_navi_next = T_('Next');
    $_navi_up = T_('Up');
    $_navi_home = T_('Home');
    $current = isset($vars['page']) ? $vars['page'] : '';
    $reverse = FALSE;
    if (func_num_args()) {
        list($home, $reverse) = array_pad(func_get_args(), 2, null);
        // 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: ' . htmlsc($home) . '<br />';
        } else {
            if (!$is_home && !preg_match('/^' . preg_quote($home, '/') . '/', $current)) {
                return '#navi(' . htmlsc($home) . '): Not a child page like: ' . htmlsc($home . '/' . basename($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' => null, 'prev' => null, 'prev1' => null, 'next' => null, 'next1' => null, 'home' => null, 'home1' => null);
        $pages = preg_grep('/^' . preg_quote($home, '/') . '($|\\/)/', Auth::get_existpages());
        if (PLUGIN_NAVI_EXCLUSIVE_REGEX != null) {
            // 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 = null;
        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 != null) {
            $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) as $rel => $_page) {
                if ($_page != null) {
                    $s_page = htmlsc($_page);
                    $link_tags[] = array('rel' => $rel, 'href' => get_page_uri($_page), 'title' => $s_page);
                    /*
                    	$head_tags[] = ' <link rel="' .
                    		$rel . '" href="' .
                    		get_page_uri($_page) . '" title="' .
                    		$s_page . '" />';
                    */
                }
            }
        }
    }
    $ret = null;
    if ($is_home) {
        // Show contents
        $count = count($pages);
        if ($count == 0) {
            return '<p class="alert alert-warning">#navi(contents-page-name): You already view the result</p>';
        } else {
            if ($count == 1) {
                // Sentinel only: Show usage and warning
                $home = htmlsc($home);
                $ret .= '<p class="alert alert-warning">#navi(' . $home . '): No child page like: ' . $home . '/Foo</p>';
            } 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="list-inline text-center">
\t<li class="pull-left">{$navi[$home]['prev1']}</li>
\t<li class="pull-right">{$navi[$home]['next1']}</li>
\t<li>{$navi[$home]['home']}</li>
</ul>
<hr />
EOD;
        } else {
            // Footer
            $ret = <<<EOD
<hr />
<ul class="list-inline text-center">
\t<li class="pull-left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
\t<li class="pull-right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
\t<li>{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>
</ul>
EOD;
        }
    }
    return '<nav>' . $ret . '</nav>' . "\n";
}
Example #14
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 ? T_('Relation map (link from)') : sprintf(T_('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'] = T_('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[] = T_('<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(T_('<p>Not related from %s.</p>'), htmlsc($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(T_('<p>Total: %d page(s) on this site.</p>'), count($pages));
    $retval['body'] = implode("\n", $body) . "\n";
    return $retval;
}
Example #15
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} = htmlsc(${$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 = htmlsc($_plugin_bugtrack['state_bgcolor'][$state_no]);
        $row = <<<EOD
\t<tr>
\t\t<td style="background-color:{$bgcolor}">{$page_link}</td>
\t\t<td style="background-color:{$bgcolor}">{$state}</td>
\t\t<td style="background-color:{$bgcolor}">{$priority}</td>
\t\t<td style="background-color:{$bgcolor}">{$category}</td>
\t\t<td style="background-color:{$bgcolor}">{$name}</td>
\t\t<td style="background-color:{$bgcolor}">{$summary}</td>
\t</tr>
EOD;
        $table[$state_no][$no] = $row;
    }
    $table_html = '<thead>' . "\n" . '	<tr>' . "\n";
    $bgcolor = htmlsc($_plugin_bugtrack['header_bgcolor']);
    foreach (array('pagename', 'state', 'priority', 'category', 'name', 'summary') as $item) {
        $table_html .= '  <th style="background-color:' . $bgcolor . '">' . htmlsc($_plugin_bugtrack[$item]) . '</th>' . "\n";
    }
    $table_html .= '	</tr>' . "\n" . '</thead>' . "\n" . '<tbody>' . "\n";
    for ($i = 0; $i <= $count_list; ++$i) {
        ksort($table[$i], SORT_NUMERIC);
        $table_html .= join("\n", $table[$i]);
    }
    $table_html .= '</tbody>' . "\n";
    return '<table class="table">' . "\n" . $table_html . "\n" . '</table>';
}
Example #16
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));
    }
}
Example #17
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 '&amp;new([nodate]){date};';
        }
        // dev:BugTrack2/120
        //$timestamp = strtotime($date);
        //if ($timestamp === -1) return '&amp;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 '<span class="text-warning">&amp;new([nodate]){date}: Invalid date string;</span>';
        }
        // $timestamp -= ZONETIME;
        $retval = in_array('nodate', $args) ? '' : htmlsc($date);
    } else {
        // Show 'New!' message by the timestamp of the page
        if (func_num_args() > 3) {
            return '<span class="text-muted">&new(pagename[,nolink]);</span>';
        }
        $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 '<span class="text-warning">&amp;new(pagename/[,nolink]): No such pages;</span>';
            }
        } else {
            // Check a page
            if (is_page($page)) {
                $timestamp = get_filetime($page);
                $retval = $nolink ? '' : make_pagelink($page, $name);
            } else {
                return '<span class="text-warning">&amp;new(pagename[,nolink]): No such page;</span>';
            }
        }
    }
    // 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;
    }
}