Beispiel #1
0
function plugin_recent_convert()
{
    global $vars, $date_format, $_recent_plugin_frame, $show_passage;
    static $exec_count = 1;
    $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
    if (func_num_args()) {
        $args = func_get_args();
        if (!is_numeric($args[0]) || isset($args[1])) {
            return PLUGIN_RECENT_USAGE . '<br />';
        } else {
            $recent_lines = $args[0];
        }
    }
    // Show only N times
    if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
        return '#recent(): You called me too much' . '<br />' . "\n";
    } else {
        ++$exec_count;
    }
    if (!file_exists(PLUGIN_RECENT_CACHE)) {
        return '#recent(): Cache file of RecentChanges not found' . '<br />';
    }
    // Get latest N changes
    $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
    if ($lines == FALSE) {
        return '#recent(): File can not open' . '<br />' . "\n";
    }
    $script = get_script_uri();
    $date = $items = '';
    foreach ($lines as $line) {
        list($time, $page) = explode("\t", rtrim($line));
        $_date = get_date($date_format, $time);
        if ($date != $_date) {
            // End of the day
            if ($date != '') {
                $items .= '</ul>' . "\n";
            }
            // New day
            $date = $_date;
            $items .= '<strong>' . $date . '</strong>' . "\n" . '<ul class="recent_list">' . "\n";
        }
        $s_page = htmlsc($page);
        if ($page == $vars['page']) {
            // No need to link to the page you just read, or notify where you just read
            $items .= ' <li>' . $s_page . '</li>' . "\n";
        } else {
            $r_page = rawurlencode($page);
            $passage = $show_passage ? ' ' . get_passage($time) : '';
            $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
        }
    }
    // End of the day
    if ($date != '') {
        $items .= '</ul>' . "\n";
    }
    return sprintf($_recent_plugin_frame, count($lines), $items);
}
Beispiel #2
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);
}
function plugin_passage_inline()
{
    $argv = func_get_args();
    $argc = func_num_args();
    $field = array('time', 'paren');
    for ($i = 0; $i < $argc; $i++) {
        ${$field}[$i] = htmlspecialchars($argv[$i], ENT_QUOTES);
    }
    if (empty($time)) {
        return '';
    }
    $paren = empty($paren) ? FALSE : TRUE;
    return get_passage($time, $paren);
}
Beispiel #4
0
function plugin_related_action()
{
    global $vars, $script, $defaultpage, $whatsnew;
    $_page = isset($vars['page']) ? $vars['page'] : '';
    if ($_page == '') {
        $_page = $defaultpage;
    }
    // Get related from cache
    $data = links_get_related_db($_page);
    if (!empty($data)) {
        // Hide by array keys (not values)
        foreach (array_keys($data) as $page) {
            if ($page == $whatsnew || check_non_list($page)) {
                unset($data[$page]);
            }
        }
    }
    // Result
    // kazuwaya
    $r_word = rawurlencode($_page);
    $s_word = htmlspecialchars($_page);
    $msg = 'Backlinks for: ' . $s_word;
    $retval = '<p><a href="' . $script . '?' . $r_word . '">' . 'Return to ' . $s_word . '</a></p>' . "\n";
    if (empty($data)) {
        $retval .= '<ul><li>No related pages found.</li></ul>' . "\n";
    } else {
        // Show count($data)?
        ksort($data);
        $retval .= '<ul>' . "\n";
        foreach ($data as $page => $time) {
            $r_page = rawurlencode($page);
            $s_page = htmlspecialchars($page);
            $passage = get_passage($time);
            $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page . '</a> ' . $passage . '</li>' . "\n";
        }
        $retval .= '</ul>' . "\n";
    }
    return array('msg' => $msg, 'body' => $retval);
}
Beispiel #5
0
function plugin_related_action()
{
    global $vars, $script, $defaultpage, $whatsnew;
    $qm = get_qm();
    $_page = isset($vars['page']) ? $vars['page'] : '';
    if ($_page == '') {
        $_page = $defaultpage;
    }
    // Get related from cache
    $data = links_get_related_db($_page);
    if (!empty($data)) {
        // Hide by array keys (not values)
        foreach (array_keys($data) as $page) {
            if ($page == $whatsnew || check_non_list($page)) {
                unset($data[$page]);
            }
        }
    }
    // Result
    $r_word = rawurlencode($_page);
    $s_word = get_page_title($_page);
    $msg = $qm->replace('plg_related.title', $s_word);
    $retval = '<a href="' . $script . '?' . $r_word . '">' . $qm->replace('plg_related.link_back', $s_word) . '</a><br />' . "\n";
    if (empty($data)) {
        $retval .= '<ul><li>' . $qm->m['plg_related']['notfound'] . '</li></ul>' . "\n";
    } else {
        ksort($data);
        $retval .= '<ul>' . "\n";
        foreach ($data as $page => $time) {
            $r_page = rawurlencode($page);
            $s_page = get_page_title($page);
            $passage = get_passage($time);
            $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page . '</a> ' . $passage . '</li>' . "\n";
        }
        $retval .= '</ul>' . "\n";
    }
    return array('msg' => $msg, 'body' => $retval);
}
function plugin_related_action()
{
    global $vars, $defaultpage;
    $_page = isset($vars['page']) ? $vars['page'] : '';
    if ($_page == '') {
        $_page = $defaultpage;
    }
    // Get related from cache
    $data = links_get_related_db($_page);
    if (!empty($data)) {
        // Hide by array keys (not values)
        foreach (array_keys($data) as $page) {
            if (is_cantedit($page) || check_non_list($page)) {
                unset($data[$page]);
            }
        }
    }
    // Result
    $s_word = htmlspecialchars($_page);
    $msg = 'Backlinks for: ' . $s_word;
    $retval = '<a href="' . get_page_uri($_page) . '">' . 'Return to ' . $s_word . '</a><br />' . "\n";
    if (empty($data)) {
        $retval .= '<ul><li>No related pages found.</li></ul>' . "\n";
    } else {
        // Show count($data)?
        ksort($data, SORT_STRING);
        $retval .= '<ul>' . "\n";
        foreach ($data as $page => $time) {
            $s_page = htmlspecialchars($page);
            $passage = get_passage($time);
            $retval .= ' <li><a href="' . get_page_uri($page) . '">' . $s_page . '</a> ' . $passage . '</li>' . "\n";
        }
        $retval .= '</ul>' . "\n";
    }
    return array('msg' => $msg, 'body' => $retval);
}
Beispiel #7
0
 function format_line($line)
 {
     $desc = mb_strimwidth(preg_replace("/[\r\n]/", ' ', strip_tags($line['desc'])), 0, 255, '...');
     if (IS_MOBILE) {
         return '<li><a href="' . $line['link'] . '">' . $line['entry'] . '</a><span class="ui-count">' . get_passage($line['date']) . '</span></li>';
     } else {
         return '<li><a href="' . $line['link'] . '" title="' . $desc . ' ' . get_passage($line['date']) . '">' . $line['entry'] . '</a></li>';
     }
 }
Beispiel #8
0
function do_search_fuzzy($word, $type = 'AND', $non_format = FALSE, $non_fuzzy = FALSE)
{
    global $whatsnew, $non_list, $search_non_list;
    global $search_auth, $search_fuzzy;
    static $fuzzypattern = array('ヴァ' => 'バ', 'ヴィ' => 'ビ', 'ヴェ' => 'ベ', 'ヴォ' => 'ボ', 'ヴ' => 'ブ', 'ヰ' => 'イ', 'ヱ' => 'エ', 'ヵ' => 'カ', 'ァ' => 'ア', 'ィ' => 'イ', 'ゥ' => 'ウ', 'ェ' => 'エ', 'ォ' => 'オ', 'ャ' => 'ヤ', 'ュ' => 'ユ', 'ョ' => 'ヨ');
    $retval = array();
    $b_type = $type == 'AND';
    // AND:TRUE OR:FALSE
    $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
    $_pages = get_existpages();
    $pages = array();
    $non_list_pattern = '/' . $non_list . '/';
    foreach ($_pages as $page) {
        if ($page == $whatsnew || !$search_non_list && preg_match($non_list_pattern, $page)) {
            continue;
        }
        // 検索対象ページの制限をかけるかどうか (ページ名は制限外)
        if ($search_auth && !check_readable($page, false, false)) {
            $source = get_source();
            // 検索対象ページ内容を空に。
        } else {
            $source = get_source($page);
        }
        if (!$non_format) {
            array_unshift($source, $page);
        }
        // ページ名も検索対象に
        $b_match = FALSE;
        //miko modified
        if (!$search_fuzzy || $non_fuzzy) {
            foreach ($keys as $key) {
                $tmp = preg_grep('/' . $key . '/', $source);
                $b_match = !empty($tmp);
                if ($b_match xor $b_type) {
                    break;
                }
            }
            if ($b_match) {
                $pages[$page] = get_filetime($page);
            }
        } else {
            $fuzzy_from = array_keys($fuzzypattern);
            $fuzzy_to = array_values($fuzzypattern);
            $words = preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY);
            $_source = mb_strtolower(mb_convert_kana(join("\n", $source), 'KVCas'));
            for ($i = 0; $i < count($fuzzy_from); $i++) {
                $_source = mb_ereg_replace($fuzzy_from[$i], $fuzzy_to[$i], $_source);
            }
            $_source = mb_ereg_replace('[ッー・゛゜、。]', '', $_source);
            foreach ($keys as $key) {
                $_keyword = mb_strtolower(mb_convert_kana($word, 'KVCas'));
                for ($i = 0; $i < count($fuzzy_from); $i++) {
                    $_keyword = mb_ereg_replace($fuzzy_from[$i], $fuzzy_to[$i], $_keyword);
                }
                $_keyword = mb_ereg_replace('[ッー・゛゜、。]', '', $_keyword);
                $b_match = mb_ereg(mb_ereg_quote($_keyword), $_source);
            }
            if ($b_match) {
                $pages[$page] = get_filetime($page);
            }
        }
        //miko modified
    }
    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);
    $retval = '<ul>' . "\n";
    foreach ($pages as $page => $time) {
        $s_page = htmlspecialchars($page);
        $passage = get_passage($time);
        $retval .= ' <li><a href="' . get_page_uri($page, '', 'word=' . $r_word) . '">' . $s_page . '</a>' . $passage . '</li>' . "\n";
    }
    $retval .= '</ul>' . "\n";
    $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', count($_pages), $b_type ? $_string['andresult'] : $_string['orresult'])));
    return $retval;
}
Beispiel #9
0
function make_related($page, $tag = '')
{
    global $vars, $rule_related_str, $related_str;
    global $_ul_left_margin, $_ul_margin, $_list_pad_str;
    $links = links_get_related($page);
    if ($tag) {
        ksort($links, SORT_STRING);
        // Page name, alphabetical order
    } else {
        arsort($links, SORT_NUMERIC);
        // Last modified date, newer
    }
    $_links = array();
    foreach ($links as $page => $lastmod) {
        if (check_non_list($page)) {
            continue;
        }
        $s_page = htmlspecialchars($page);
        $passage = get_passage($lastmod);
        $_links[] = $tag ? '<a href="' . get_page_uri($page) . '" title="' . $s_page . ' ' . $passage . '">' . $s_page . '</a>' : '<a href="' . get_page_uri($page) . '">' . $s_page . '</a>' . $passage;
    }
    if (empty($_links)) {
        return '';
    }
    // Nothing
    if ($tag == 'p') {
        // From the line-head
        $margin = $_ul_left_margin + $_ul_margin;
        $style = sprintf($_list_pad_str, 1, $margin, $margin);
        $retval = "\n" . '<ul' . $style . '>' . "\n" . '<li>' . join($rule_related_str, $_links) . '</li>' . "\n" . '</ul>' . "\n";
    } else {
        if ($tag) {
            $retval = join($rule_related_str, $_links);
        } else {
            $retval = join($related_str, $_links);
        }
    }
    return $retval;
}
Beispiel #10
0
function plugin_referer_body($page, $sort)
{
    global $script;
    $qm = get_qm();
    $data = tb_get(tb_get_filename($page, '.ref'));
    if (empty($data)) {
        return '<p>no data.</p>';
    }
    $bg = plugin_referer_set_color();
    $arrow_last = $arrow_1st = $arrow_ctr = '';
    $color_last = $color_1st = $color_ctr = $color_ref = $bg['etc'];
    $sort_last = '0d';
    $sort_1st = '1d';
    $sort_ctr = '2d';
    switch ($sort) {
        case '0d':
            // 0d 最終更新日時(新着順)
            usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
            $color_last = $bg['cur'];
            $arrow_last = $qm->m['plg_referer']['down'];
            $sort_last = '0a';
            break;
        case '0a':
            // 0a 最終更新日時(日付順)
            usort($data, create_function('$a,$b', 'return $a[0] - $b[0];'));
            $color_last = $bg['cur'];
            $arrow_last = $qm->m['plg_referer']['up'];
            //		$sort_last = '0d';
            break;
        case '1d':
            // 1d 初回登録日時(新着順)
            usort($data, create_function('$a,$b', 'return $b[1] - $a[1];'));
            $color_1st = $bg['cur'];
            $arrow_1st = $qm->m['plg_referer']['down'];
            $sort_1st = '1a';
            break;
        case '1a':
            // 1a 初回登録日時(日付順)
            usort($data, create_function('$a,$b', 'return $a[1] - $b[1];'));
            $color_1st = $bg['cur'];
            $arrow_1st = $qm->m['plg_referer']['up'];
            //		$sort_1st = '1d';
            break;
        case '2d':
            // 2d カウンタ(大きい順)
            usort($data, create_function('$a,$b', 'return $b[2] - $a[2];'));
            $color_ctr = $bg['cur'];
            $arrow_ctr = $qm->m['plg_referer']['down'];
            $sort_ctr = '2a';
            break;
        case '2a':
            // 2a カウンタ(小さい順)
            usort($data, create_function('$a,$b', 'return $a[2] - $b[2];'));
            $color_ctr = $bg['cur'];
            $arrow_ctr = $qm->m['plg_referer']['up'];
            //		$sort_ctr = '2d';
            break;
        case '3':
            // 3 Referer
            usort($data, create_function('$a,$b', 'return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
            $color_ref = $bg['cur'];
            break;
    }
    $body = '';
    foreach ($data as $arr) {
        // 0:最終更新日時, 1:初回登録日時, 2:参照カウンタ, 3:Referer ヘッダ, 4:利用可否フラグ(1は有効)
        list($ltime, $stime, $count, $url, $enable) = $arr;
        // 非ASCIIキャラクタ(だけ)をURLエンコードしておく BugTrack/440
        $e_url = htmlspecialchars(preg_replace('/([" \\x80-\\xff]+)/e', 'rawurlencode("$1")', $url));
        $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url), SOURCE_ENCODING, 'auto'));
        $lpass = get_passage($ltime, FALSE);
        // 最終更新日時からの経過時間
        $spass = get_passage($stime, FALSE);
        // 初回登録日時からの経過時間
        $ldate = get_date($qm->m['plg_referer']['date_format'], $ltime);
        // 最終更新日時文字列
        $sdate = get_date($qm->m['plg_referer']['date_format'], $stime);
        // 初回登録日時文字列
        $body .= ' <tr>' . "\n" . '  <td>' . $ldate . '</td>' . "\n" . '  <td>' . $lpass . '</td>' . "\n";
        $body .= $count == 1 ? '  <td colspan="2">N/A</td>' . "\n" : '  <td>' . $sdate . '</td>' . "\n" . '  <td>' . $spass . '</td>' . "\n";
        $body .= '  <td style="text-align:right;">' . $count . '</td>' . "\n";
        // 適用不可データのときはアンカーをつけない
        $body .= plugin_referer_ignore_check($url) ? '  <td>' . $s_url . '</td>' . "\n" : '  <td><a href="' . $e_url . '" rel="nofollow">' . $s_url . '</a></td>' . "\n";
        $body .= ' </tr>' . "\n";
    }
    $href = $script . '?plugin=referer&amp;page=' . rawurlencode($page);
    return <<<EOD
<table border="1" cellspacing="1" summary="Referer">
 <tr>
  <td style="background-color:{$color_last}" colspan="2">
   <a href="{$href}&amp;sort={$sort_last}">{$qm->m['plg_referer']['lastupdate']}{$arrow_last}</a>
  </td>
  <td style="background-color:{$color_1st}" colspan="2">
   <a href="{$href}&amp;sort={$sort_1st}">{$qm->m['plg_referer']['firstdate']}{$arrow_1st}</a>
  </td>
  <td style="background-color:{$color_ctr};text-align:right">
   <a href="{$href}&amp;sort={$sort_ctr}">{$qm->m['plg_referer']['counter']}{$arrow_ctr}</a>
  </td>
  <td style="background-color:{$color_ref}">
   <a href="{$href}&amp;sort=3">{$qm->m['plg_referer']['referer']}</a>
   </td>
 </tr>
 {$body}
</table>
EOD;
}
Beispiel #11
0
function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list;
    global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
    global $search_auth, $show_passage;
    $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 = 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]);
    $count = count($pages);
    foreach (array_keys($pages) as $page) {
        $b_match = FALSE;
        // 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;
        }
        // Search for page contents
        foreach ($keys as $key) {
            $b_match = preg_match($key, get_source($page, TRUE, TRUE));
            if ($b_type xor $b_match) {
                break;
            }
            // OR
        }
        if ($b_match) {
            continue;
        }
        unset($pages[$page]);
        // Miss
    }
    if ($non_format) {
        return array_keys($pages);
    }
    $r_word = rawurlencode($word);
    $s_word = htmlspecialchars($word);
    if (empty($pages)) {
        return str_replace('$1', $s_word, $_msg_notfoundresult);
    }
    ksort($pages);
    $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)) : '';
        $retval .= ' <li><a href="' . $script . '?cmd=read&amp;page=' . $r_page . '&amp;word=' . $r_word . '">' . $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 ? $_msg_andresult : $_msg_orresult)));
    return $retval;
}
function plugin_referer_body($page, $sort)
{
    global $script, $_referer_msg;
    global $referer;
    $data = tb_get(tb_get_filename($page, '.ref'));
    if (empty($data)) {
        return '<p>no data.</p>';
    }
    $bg = plugin_referer_set_color();
    $arrow_last = $arrow_1st = $arrow_ctr = '';
    $color_last = $color_1st = $color_ctr = $color_ref = $bg['etc'];
    $sort_last = '0d';
    $sort_1st = '1d';
    $sort_ctr = '2d';
    switch ($sort) {
        case '0d':
            // 0d 最終更新日時(新着順)
            usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
            $color_last = $bg['cur'];
            $arrow_last = $_referer_msg['msg_Chr_darr'];
            $sort_last = '0a';
            break;
        case '0a':
            // 0a 最終更新日時(日付順)
            usort($data, create_function('$a,$b', 'return $a[0] - $b[0];'));
            $color_last = $bg['cur'];
            $arrow_last = $_referer_msg['msg_Chr_uarr'];
            //		$sort_last = '0d';
            break;
        case '1d':
            // 1d 初回登録日時(新着順)
            usort($data, create_function('$a,$b', 'return $b[1] - $a[1];'));
            $color_1st = $bg['cur'];
            $arrow_1st = $_referer_msg['msg_Chr_darr'];
            $sort_1st = '1a';
            break;
        case '1a':
            // 1a 初回登録日時(日付順)
            usort($data, create_function('$a,$b', 'return $a[1] - $b[1];'));
            $color_1st = $bg['cur'];
            $arrow_1st = $_referer_msg['msg_Chr_uarr'];
            //		$sort_1st = '1d';
            break;
        case '2d':
            // 2d カウンタ(大きい順)
            usort($data, create_function('$a,$b', 'return $b[2] - $a[2];'));
            $color_ctr = $bg['cur'];
            $arrow_ctr = $_referer_msg['msg_Chr_darr'];
            $sort_ctr = '2a';
            break;
        case '2a':
            // 2a カウンタ(小さい順)
            usort($data, create_function('$a,$b', 'return $a[2] - $b[2];'));
            $color_ctr = $bg['cur'];
            $arrow_ctr = $_referer_msg['msg_Chr_uarr'];
            //		$sort_ctr = '2d';
            break;
        case '3':
            // 3 Referer
            usort($data, create_function('$a,$b', 'return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
            $color_ref = $bg['cur'];
            break;
    }
    $body = '';
    $ctr = 0;
    foreach ($data as $arr) {
        // 0:最終更新日時, 1:初回登録日時, 2:参照カウンタ, 3:Referer ヘッダ, 4:利用可否フラグ(1は有効)
        list($ltime, $stime, $count, $url, $enable) = $arr;
        // 項目不正の場合の対応
        // カウンタが数値ではない場合は、表示を抑止
        if (!is_numeric($count)) {
            continue;
        }
        $sw_ignore = plugin_referer_ignore_check($url);
        if ($sw_ignore && $referer > 1) {
            continue;
        }
        // 非ASCIIキャラクタ(だけ)をURLエンコードしておく BugTrack/440
        $e_url = htmlspecialchars(preg_replace('/([" \\x80-\\xff]+)/e', 'rawurlencode("$1")', $url));
        $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url), SOURCE_ENCODING, 'auto'));
        $s_url = mb_strimwidth($s_url, 0, REFERE_TITLE_LENGTH, '...');
        $lpass = get_passage($ltime, FALSE);
        // 最終更新日時からの経過時間
        $spass = get_passage($stime, FALSE);
        // 初回登録日時からの経過時間
        $ldate = get_date($_referer_msg['msg_Fmt_Date'], $ltime);
        // 最終更新日時文字列
        $sdate = get_date($_referer_msg['msg_Fmt_Date'], $stime);
        // 初回登録日時文字列
        $body .= ' <tr>' . "\n" . '  <td>' . $ldate . '</td>' . "\n" . '  <td>' . $lpass . '</td>' . "\n";
        $body .= $count == 1 ? '  <td colspan="2">N/A</td>' . "\n" : '  <td>' . $sdate . '</td>' . "\n" . '  <td>' . $spass . '</td>' . "\n";
        $body .= '  <td style="text-align:right;">' . $count . '</td>' . "\n";
        // 適用不可データのときはアンカーをつけない
        $body .= $sw_ignore ? '  <td>' . $s_url . '</td>' . "\n" : '  <td><a href="' . $e_url . '" rel="nofollow">' . $s_url . '</a></td>' . "\n";
        $body .= ' </tr>' . "\n";
        $ctr++;
    }
    if ($ctr === 0) {
        return '<p>no data.</p>';
    }
    $href = $script . '?plugin=referer&amp;page=' . rawurlencode($page);
    return <<<EOD
<table border="1" cellspacing="1" summary="Referer">
 <tr>
  <td style="background-color:{$color_last}" colspan="2">
   <a href="{$href}&amp;sort={$sort_last}">{$_referer_msg['msg_Hed_LastUpdate']}{$arrow_last}</a>
  </td>
  <td style="background-color:{$color_1st}" colspan="2">
   <a href="{$href}&amp;sort={$sort_1st}">{$_referer_msg['msg_Hed_1stDate']}{$arrow_1st}</a>
  </td>
  <td style="background-color:{$color_ctr};text-align:right">
   <a href="{$href}&amp;sort={$sort_ctr}">{$_referer_msg['msg_Hed_RefCounter']}{$arrow_ctr}</a>
  </td>
  <td style="background-color:{$color_ref}">
   <a href="{$href}&amp;sort=3">{$_referer_msg['msg_Hed_Referer']}</a>
   </td>
 </tr>
 {$body}
</table>
EOD;
}
function plugin_ls2_1_get_headings($page, &$params, $level = 1, $include = false, $prefix, $top_level = 1, &$pages)
{
    global $script;
    static $_ls2_anchor = 0;
    // すでにこのページの見出しを表示したかどうかのフラグ
    $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0;
    if (!$is_done) {
        $params["page_{$page}"] = ++$_ls2_anchor;
    }
    $s_page = htmlspecialchars($page);
    $title = $s_page . ' ' . get_pg_passage($page, false);
    $r_page = rawurlencode($page);
    $href = $script . '?' . $r_page;
    // relative オプション。リンク名制御。
    if ($params['relative']) {
        // パターンの最後の / 以下を取り除く。例) sample/test/d -> sample/test
        // $prefix_dir = preg_replace('/[^\/]+$/','',$prefix);
        if (($pos = strrpos($prefix, '/')) !== false) {
            $prefix_dir = substr($prefix, 0, $pos + 1);
        }
        // ページ名からそのパターンをとり除く。
        // $s_page = ereg_replace("^$prefix_dir",'',$s_page);
        $s_page = substr($s_page, strlen($prefix_dir));
        // relative オプションと hierarchy オプションが同時に指定された場合は
        // パターンを取り除くだけでなく、上位の存在しているページ名も取り除く。
        if ($params['display'] == 'hierarchy') {
            $tmp = $s_page;
            // depth オプションが指定されていた場合 $top_level が変わります。
            while (substr_count($tmp, "/") > $top_level - 1) {
                // 一階層ずつとりのぞく
                if (($pos = strrpos($tmp, '/')) !== false) {
                    $tmp = substr($tmp, 0, $pos);
                }
                // 上位のページが存在していれば、その文字列を取り除き、相対名にする。
                if (in_array($prefix_dir . $tmp, $pages)) {
                    // $s_page = ereg_replace("^$tmp/",'',$s_page);
                    $s_page = substr($s_page, strlen("{$tmp}/"));
                    break;
                }
            }
        }
    }
    // date オプション。更新日時の追加。
    $date = '';
    if ($params['date']) {
        $date = format_date(get_filetime($page));
    }
    // new オプション。New! 表示の追加。
    $new = '';
    if ($params['new']) {
        global $_plugin_new_elapses;
        $timestamp = get_filetime($page) - LOCALZONE;
        $erapse = UTIME - $timestamp;
        foreach ($_plugin_new_elapses as $limit => $tag) {
            if ($erapse <= $limit) {
                $new .= sprintf($tag, get_passage($timestamp));
                break;
            }
        }
    }
    plugin_ls2_1_list_push($params, $level);
    // LI TAG. display オプションに依る。plugin_ls2_1_list_push にも。
    if ($params['display'] == 'inline') {
        $litag = '';
    } else {
        $litag = '<li>';
    }
    array_push($params['result'], $litag);
    // include されたページの場合
    if ($include) {
        $ret = 'include ';
    } else {
        $ret = '';
    }
    // すでに表示済みなら必ずファイル内探索処理はせずに抜ける
    if ($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>';
    if ($date != '') {
        $ret .= " {$date}";
    }
    if ($new != '') {
        $ret .= " {$new}";
    }
    array_push($params['result'], $ret);
    // title オプション、include オプション時はファイル内探索もする
    if ($params['title'] || $params['include']) {
        $anchor = PLUGIN_LS2_1_ANCHOR_ORIGIN;
        $matches = array();
        // 全体で title_number 個ではなく各ファイル単位で title_number 個
        $title_counter = 0;
        foreach (get_source($page) as $line) {
            if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) {
                if ($params['title_number']) {
                    // ただの件数制限なので途中で抜けても $anchor には不整合はでないはず
                    if ($title_counter >= $params['title_number']) {
                        if (!$params['include']) {
                            break;
                        } else {
                            continue;
                        }
                    }
                    $title_counter++;
                }
                // $line は 'remove footnotes and HTML tags' される。見出し行のアンカーが返されるが正直いらない。
                $id = make_heading($line);
                $hlevel = strlen($matches[1]);
                $id = PLUGIN_LS2_1_ANCHOR_PREFIX . $anchor++;
                plugin_ls2_1_list_push($params, $level + $hlevel);
                array_push($params['result'], $litag);
                array_push($params['result'], '<a href="' . $href . $id . '">' . $line . '</a>');
            } else {
                if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) {
                    plugin_ls2_1_get_headings($matches[1], $params, $level + $hlevel + 1, true, $prefix, $top_level, $pages);
                }
            }
        }
    }
}
Beispiel #14
0
function plugin_tb_recent($page, $line)
{
    $body = '';
    $tb_id = tb_get_id($page);
    $data = tb_get(tb_get_filename($page));
    $ctr = count($data);
    if ($ctr == 0) {
        return '';
    }
    if ($ctr > 1) {
        // Sort: The first is the latest
        usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
    }
    $body .= '<h5>' . _("RECENT TRACKBACK") . "</h5>\n";
    $body .= "<div>\n<ul class=\"recent_list\">\n";
    $i = 0;
    foreach ($data as $x) {
        if (count($x) != 5) {
            continue;
        }
        // Ignore incorrect record
        list($time, $url, $title, $excerpt, $blog_name) = $x;
        if ($title == '') {
            $title = 'no title';
        }
        $body .= '<li><a href="' . $url . '" title="' . $blog_name . ' ' . get_passage($time) . '" rel="nofollow">' . $title . '</a></li>' . "\n";
        $i++;
        if ($line == 0) {
            continue;
        }
        if ($i >= $line) {
            break;
        }
    }
    if ($i == 0) {
        return '';
    }
    $body .= "</ul>\n</div>\n";
    return $body;
}
Beispiel #15
0
/**
 * アクションプラグイン処理
 */
function plugin_logview_action()
{
    global $vars, $_logview_msg, $_logview_logname;
    global $sortable_tracker, $_LANG, $vars;
    static $count = 0;
    $kind = isset($vars['kind']) ? $vars['kind'] : null;
    $title = $kind !== null ? sprintf($_logview_msg['msg_title'], $kind) : $_LANG['skin']['log'];
    // タイトルを設定
    $page = isset($vars['page']) ? $vars['page'] : null;
    $ajax = isset($vars['ajax']) ? $vars['ajax'] : null;
    $is_role_adm = Auth::check_role('role_adm');
    // 設定を読む
    $log = Utility::loadConfig('config-log.ini.php');
    // ゲスト表示ができない場合は、認証を要求する
    if ($kind !== null && empty($log[$kind]['guest'])) {
        $obj = new Auth();
        $user = $obj->check_auth();
        if (empty($user)) {
            PluginRenderer::executePluginAction('login');
            unset($obj);
            return array('msg' => $title, 'body' => '<p class="alert-warning">' . $_logview_msg['msg_not_auth'] . '</p>');
        }
    }
    unset($obj);
    if (empty($page)) {
        return array('msg' => 'Page name is missing', 'body' => '<p class="alert-warning">Page name is missing.</p>');
    }
    $wiki = Factory::Wiki($page);
    if (!$wiki->isReadable()) {
        return array('msg' => 'not readable', 'body' => '<p class="alert-warning">You have no permission to read this log.</p>');
    }
    if ($kind === null) {
        if (!IS_MOBILE) {
            $body = '<div class="tabs" role="application">' . "\n";
            $body .= '<ul role="tablist">';
            $cnt = 0;
            foreach ($log as $key => $val) {
                $link_text = isset($_logview_logname[$key]) ? $_logview_logname[$key] : $key;
                if ($val['use'] === 1) {
                    $body .= '<li role="tab"><a href="' . $wiki->uri('logview', array('kind' => $key)) . '">' . $link_text . '</a></li>';
                }
                /*
                				else
                				{
                					$body .= '<li><a href="'.get_cmd_uri('logview',$page,null,array('kind'=>$key)).'" data-ajax="raw" data-disabled="true">'.$link_text.'</a></li>';
                				}
                */
            }
            $body .= '</ul></div>' . "\n";
            if ($kind === null) {
                return array('msg' => $title, 'body' => $body);
            }
            $body .= '<div class="no-js" role="tabpanel">';
            $nodata = $body . '<p>' . $_logview_msg['msg_nodata'] . '</p></div></div>';
        } else {
            $body = '<div data-role="controlgroup" data-type="horizontal">' . "\n";
            $cnt = 0;
            foreach ($log as $key => $val) {
                $link_text = isset($_LANG['skin']['log_' . $key]) ? $_LANG['skin']['log_' . $key] : $key;
                if ($val['use'] === 1) {
                    $body .= '<a href="' . $wiki->uri('logview', array('kind' => $key)) . '" data-role="button">' . $link_text . '</a>';
                }
                /*
                				else
                				{
                					$body .= '<a href="'.get_cmd_uri('logview',$page,null,array('kind'=>$key)).'" data-ajax="raw" data-disabled="true">'.$link_text.'</a>';
                				}
                */
            }
            $body .= '</div>' . "\n" . '<div class="ui-body ui-body-c"></div>';
            if ($kind === null) {
                return array('msg' => $title, 'body' => $body);
            }
        }
    } else {
        $body = '';
    }
    // 保存データの項目名を取得
    $logfile = LogFactory::factory($kind, $page);
    $view = $logfile->get_view_field();
    // 表示したい項目設定
    $count++;
    $body[] = '<div class="table_wrapper">';
    $body[] = '<table class="table table-bordered table_logview" data-pagenate="true">';
    $body[] = '<thead>';
    $body[] = '<tr>';
    $cols = 0;
    // タイトルの処理
    foreach ($view as $_view) {
        if ($_view === 'local_id' && $is_role_adm) {
            continue;
        }
        $body[] = '<th>' . $_logview_msg[$_view] . '</th>';
        $cols++;
    }
    $body[] = '</tr>';
    $body[] = '</thead>';
    $body[] = '<tbody>';
    $nodata = '<p class="alert alert-warning">' . $_logview_msg['msg_nodata'] . '</p>';
    // USER-AGENT クラス
    $obj_ua = new UserAgent(USE_UA_OPTION);
    $guess = $log['guess_user']['use'] ? LogFactory::factory('guess_user')->get() : LogFactory::factory('update', $page)->getSigunature();
    $ctr = 0;
    // データの編集
    $lines = $logfile->get();
    if (!$lines) {
        return array('msg' => $title, 'body' => $nodata);
    }
    foreach ($lines as $data) {
        if (!VIEW_ROBOTS && $obj_ua->is_robots($data['ua'])) {
            continue;
        }
        // ロボットは対象外
        $body[] = '<tr>';
        foreach ($view as $field) {
            switch ($field) {
                case 'ts':
                    // タイムスタンプ (UTIME)
                    $body[] = '<td>' . get_date('Y-m-d H:i:s', $data['ts']) . ' ' . get_passage($data['ts']) . '</td>';
                    break;
                case '@guess_diff':
                case '@diff':
                    // 差分内容
                    $update = $field == '@diff' ? true : false;
                    // FIXME: バックアップ/差分 なしの新規の場合
                    // バックアップデータの確定
                    $body[] = '<td class="style_td">';
                    $age = $logfile->get_backup_age($data['ts'], $update);
                    switch ($age) {
                        case -1:
                            // データなし
                            $body[] = '<a href="' . $wiki->uri() . '" rel="nofollow">none</a>';
                            break;
                        case 0:
                            // diff
                            $body[] = '<a href="' . ($logfile->diff_exist() ? $wiki->uri('diff') : $wiki->uri()) . '" rel="nofollow">now</a>';
                            break;
                        default:
                            // あり
                            $body[] = '<a class="ext" href="' . $wiki->uri('backup', null, array('age' => $age, 'action' => 'visualdiff')) . '" rel="nofollow">' . $age . '</a>';
                            break;
                    }
                    $body[] = '</td>';
                    break;
                case 'host':
                    // ホスト名 (FQDN)
                    $body[] = ' <td>';
                    if ($data['ip'] != $data['host']) {
                        // 国名取得
                        list($flag_icon, $flag_name) = $obj_ua->get_icon_flag($data['host']);
                        if (!empty($flag_icon) && $flag_icon != 'jp') {
                            $body[] = '<span class="flag flag-' . $flag_icon . '" title="' . $flag_name . '" ></span>';
                        }
                        // ドメイン取得
                        $domain = $obj_ua->get_icon_domain($data['host']);
                        if (!empty($domain)) {
                            //						$body .= '<img src="'.$path_domain.$domain.'.png"'.
                            //								' alt="'.$data['host'].'" title="'.$data['host'].'" />';
                            $body[] = '<span class="flag flag-' . $domain . '" title="' . $data['host'] . '" ></span>';
                        }
                    }
                    if ($data['ip'] !== '::1') {
                        $body[] = '<a href="http://robtex.com/ip/' . $data['ip'] . '.html" rel="external nofollow">' . $data['host'] . '</a></td>';
                    } else {
                        $body[] = $data['host'] . '</td>';
                    }
                    break;
                case '@guess':
                    // 推測
                    $body[] = '<td>' . Utility::htmlsc(logview_guess_user($data, $guess), ENT_QUOTES) . '</td>';
                    break;
                case 'ua':
                    // ブラウザ情報 (USER-AGENT)
                    $body[] = ' <td>';
                    $os = $obj_ua->get_icon_os($data['ua']);
                    if (!empty($os)) {
                        $body[] = '<span class="os os-' . $os . '" title="' . $os . '"></span>';
                    }
                    $browser = $obj_ua->get_icon_broeswes($data['ua']);
                    if (!empty($browser)) {
                        $body[] = '<span class="browser browser-' . $browser . '" title="' . Utility::htmlsc($data['ua'], ENT_QUOTES) . '"></span>';
                    }
                    $body[] = '</td>';
                    break;
                case 'local_id':
                    if ($is_role_adm) {
                        continue;
                    }
                default:
                    $body[] = '<td>' . Utility::htmlsc($data[$field], ENT_QUOTES) . '</td>';
            }
        }
        $body[] = '</tr>';
        $ctr++;
    }
    unset($obj_ua);
    if ($ctr == 0) {
        return array('msg' => $title, 'body' => $nodata);
    }
    $body[] = '</tbody>';
    $body[] = '</table>';
    $body[] = '</div>';
    switch ($kind) {
        case 'login':
        case 'check':
            $body .= logview_user_list($fld, $page, $kind);
            break;
    }
    if ($ajax !== 'raw') {
        $body[] = '</div>';
        $body[] = '</div>';
    } else {
        echo join("\n", $body);
        exit;
    }
    return array('msg' => $title, 'body' => join("\n", $body));
}
Beispiel #16
0
function make_related($page,$tag='')
{
	global $script,$vars,$related,$rule_related_str,$related_str,$non_list;
	global $_ul_left_margin, $_ul_margin, $_list_pad_str;
	
	$links = links_get_related($page);
	
	if ($tag) {
		ksort($links);
	}
	else {
		arsort($links);
	}
	$_links = array();
	foreach ($links as $page=>$lastmod)
	{
		if (preg_match("/$non_list/",$page))
		{
			continue;
		}
		$r_page = rawurlencode($page);
		$s_page = htmlspecialchars($page);
		$passage = get_passage($lastmod);
		$_links[] = $tag ?
			"<a href=\"$script?$r_page\" title=\"$s_page $passage\">$s_page</a>" :
			"<a href=\"$script?$r_page\">$s_page</a>$passage";
	}
	
	if (count($_links) == 0)
	{
		return '';
	}
	
	if ($tag == 'p') // 行頭から
	{
		$margin = $_ul_left_margin + $_ul_margin;
		$style = sprintf($_list_pad_str,1,$margin,$margin);
		$retval =  "\n<ul$style>\n<li>".join($rule_related_str,$_links)."</li>\n</ul>\n";
	}
	else if ($tag)
	{
		$retval = join($rule_related_str,$_links);
	}
	else
	{
		$retval = join($related_str,$_links);
	}
	return $retval;
}
Beispiel #17
0
function get_pg_passage($page,$sw=TRUE)
{
	global $show_passage;
	static $pg_passage = array();
	
	if (!$show_passage)
	{
		return '';
	}
	
	if (!array_key_exists($page,$pg_passage))
	{
		$pg_passage[$page] = (is_page($page) and $time = get_filetime($page)) ?
			get_passage($time) : '';
	}
	
	return $sw ? "<small>{$pg_passage[$page]}</small>" : " {$pg_passage[$page]}";
}
Beispiel #18
0
function plugin_search_do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list;
    global $search_auth, $show_passage;
    $qm = get_qm();
    $retval = array();
    $b_type = $type == 'AND';
    // AND:TRUE OR:FALSE
    mb_language('Japanese');
    $word = mb_convert_encoding($word, SOURCE_ENCODING, "UTF-8,EUC-JP,SJIS,ASCII,JIS");
    $word = mb_ereg_replace(" ", " ", $word);
    $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($keys as $key => $value) {
        $keys[$key] = '/' . $value . '/S';
    }
    $pages = 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]);
    $count = count($pages);
    foreach (array_keys($pages) as $page) {
        $b_match = FALSE;
        // 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;
        }
        // Search for page contents
        foreach ($keys as $key) {
            $b_match = preg_match($key, get_source($page, TRUE, TRUE));
            if ($b_type xor $b_match) {
                break;
            }
            // OR
        }
        if ($b_match) {
            continue;
        }
        unset($pages[$page]);
        // Miss
    }
    if ($non_format) {
        return array_keys($pages);
    }
    $r_word = rawurlencode($word);
    $s_word = htmlspecialchars($word);
    if (empty($pages)) {
        return $qm->replace('fmt_msg_notfoundresult', $s_word);
    }
    ksort($pages);
    $retval = '<ul>' . "\n";
    foreach (array_keys($pages) as $page) {
        $s_page = get_page_title($page);
        $r_page = rawurlencode($page);
        $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : '';
        $tmp_li = ' <li><a href="' . $script . '?cmd=read&amp;page=' . $r_page . '&amp;word=' . $r_word . '">' . $s_page . '</a>' . $passage . '</li>' . "\n";
        $retval .= $tmp_li;
    }
    $retval .= '</ul>' . "\n";
    $retval .= $qm->replace($b_type ? 'fmt_msg_andresult' : 'fmt_msg_orresult', $s_word, count($pages), $count);
    return $retval;
}
Beispiel #19
0
function plugin_recent_convert()
{
    global $vars, $date_format, $show_passage;
    static $exec_count = 1;
    $qm = get_qm();
    $qt = get_qt();
    $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
    if (func_num_args()) {
        $args = func_get_args();
        if (!is_numeric($args[0]) || isset($args[1])) {
            return $qm->m['plg_recent']['err_usage'] . '<br />';
        } else {
            $recent_lines = $args[0];
        }
    }
    //---- キャッシュのための処理を登録 -----
    if ($qt->create_cache) {
        $args = func_get_args();
        return $qt->get_dynamic_plugin_mark(__FUNCTION__, $args);
    }
    //------------------------------------
    // Show only N times
    if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
        return $qm->m['plg_recent']['err_limit'] . '<br />' . "\n";
    } else {
        ++$exec_count;
    }
    if (!file_exists(PLUGIN_RECENT_CACHE)) {
        return $qm->m['plg_recent']['err_file_notfound'] . '<br />';
    }
    // Get latest N changes
    $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
    if ($lines == FALSE) {
        return $qm->m['plg_recent']['err_file_cannotopen'] . '<br />' . "\n";
    }
    $script = get_script_uri();
    $date = $items = '';
    foreach ($lines as $line) {
        list($time, $page) = explode("\t", rtrim($line));
        $_date = get_date($date_format, $time);
        if ($date != $_date) {
            // End of the day
            if ($date != '') {
                $items .= '</ul>' . "\n";
            }
            // New day
            $date = $_date;
            $items .= '<strong>' . $date . '</strong>' . "\n" . '<ul class="recent_list">' . "\n";
        }
        $s_page = htmlspecialchars($page);
        //customized by hokuken.com
        $s_page = get_page_title($page);
        if ($page == $vars['page']) {
            // No need to link to the page you just read, or notify where you just read
            $items .= ' <li>' . $s_page . '</li>' . "\n";
        } else {
            $r_page = rawurlencode($page);
            $passage = $show_passage ? ' ' . get_passage($time) : '';
            $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
        }
    }
    // End of the day
    if ($date != '') {
        $items .= '</ul>' . "\n";
    }
    $html = sprintf($qm->m['plg_recent']['frame'], count($lines), $items);
    return '<div class="qhm-plugin-recent">' . $html . '</div>';
}
Beispiel #20
0
 function ShowRSS_html($rss)
 {
     foreach ($rss as $date => $items) {
         foreach ($items as $item) {
             $link = $item['LINK'];
             $title = $item['TITLE'];
             $passage = get_passage($item['_TIMESTAMP']);
             $link = '<a href="' . $link . '" title="' . $title . ' ' . $passage . '" rel="nofollow">' . $title . '</a>';
             $this->items[$date][] = $this->format_link($link);
         }
     }
 }
Beispiel #21
0
function get_pg_passage($page, $sw = TRUE)
{
    global $show_passage;
    if (!$show_passage) {
        return '';
    }
    $time = get_filetime($page);
    $pg_passage = $time != 0 ? get_passage($time) : '';
    return $sw ? '<small>' . $pg_passage . '</small>' : ' ' . $pg_passage;
}
Beispiel #22
0
/**
 * 'Search' main function
 *
 * @param string $word search word
 * @param enum $type 'AND' or 'OR'
 * @param boolean $non_format get the matched pages in array, not html
 * @param string $base search only pages whose prefixes are $base . '/' 
 * @return string|array the search result in html or the matched pages
 * @uses get_search_words
 * @uses get_existpages
 * @uses auth::check_role
 * @see search.inc.php
 * @global string script. PukiWiki Script URI. @see get_script_uri()
 * @global string whatsnew. RecentChanges
 * @global string non_list. ignore pages
 * @global string search_non_list. non_list for searching
 * @global boolean search_auth. search authorized pages, too
 * @global boolean show_passage. show time passage in the html result
 * @global boolean search_word_color. link pages which highlight search words
 * @global boolean ajax. use ajax to show search results in pages on mouse
 * @global array _string. messages
 */
function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list, $search_auth, $show_passage, $search_word_color, $ajax, $_string;
    //	       $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
    $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 = 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);
    $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 = $script . '?' . 'cmd=read&amp;page=' . $r_page . '&amp;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 = $script . '?' . $r_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;
}
Beispiel #23
0
function make_related($page, $tag = '')
{
    global $script, $vars, $rule_related_str, $related_str;
    global $_ul_left_margin, $_ul_margin, $_list_pad_str;
    $links = links_get_related($page);
    if ($tag) {
        ksort($links);
    } else {
        arsort($links);
    }
    $_links = array();
    foreach ($links as $page => $lastmod) {
        if (check_non_list($page)) {
            continue;
        }
        $r_page = rawurlencode($page);
        $s_page = htmlsc($page);
        $passage = get_passage($lastmod);
        $_links[] = $tag ? '<a href="' . $script . '?' . $r_page . '" title="' . $s_page . ' ' . $passage . '">' . $s_page . '</a>' : '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>' . $passage;
    }
    if (empty($_links)) {
        return '';
    }
    // Nothing
    if ($tag == 'p') {
        // From the line-head
        $margin = $_ul_left_margin + $_ul_margin;
        $style = sprintf($_list_pad_str, 1, $margin, $margin);
        $retval = "\n" . '<ul' . $style . '>' . "\n" . '<li>' . join($rule_related_str, $_links) . '</li>' . "\n" . '</ul>' . "\n";
    } else {
        if ($tag) {
            $retval = join($rule_related_str, $_links);
        } else {
            $retval = join($related_str, $_links);
        }
    }
    return $retval;
}
Beispiel #24
0
function do_search($word,$type='AND',$non_format=FALSE)
{
	global $script,$vars,$whatsnew,$non_list,$search_non_list;
	global $_msg_andresult,$_msg_orresult,$_msg_notfoundresult;
	global $search_auth;
	
	$database = array();
	$retval = array();

	$b_type = ($type == 'AND'); // AND:TRUE OR:FALSE
	$keys = get_search_words(preg_split('/\s+/',$word,-1,PREG_SPLIT_NO_EMPTY));
	
	$_pages = get_existpages();
	$pages = array();
	
	foreach ($_pages as $page)
	{
		if ($page == $whatsnew
			or (!$search_non_list and preg_match("/$non_list/",$page)))
		{
			continue;
		}
		
		// 検索対象ページの制限をかけるかどうか (ページ名は制限外)
		if ($search_auth and !check_readable($page,false,false)) {
			$source = get_source(); // 検索対象ページ内容を空に。
		} else {
			$source = get_source($page);
		}
		if (!$non_format)
		{
			array_unshift($source,$page); // ページ名も検索対象に
		}
		
		$b_match = FALSE;
		foreach ($keys as $key)
		{
			$tmp = preg_grep("/$key/",$source);
			$b_match = (count($tmp) > 0);
			if ($b_match xor $b_type)
			{
				break;
			}
		}
		if ($b_match)
		{
			$pages[$page] = get_filetime($page);
		}
	}
	if ($non_format)
	{
		return array_keys($pages);
	}
	$r_word = rawurlencode($word);
	$s_word = htmlspecialchars($word);
	if (count($pages) == 0)
	{
		return str_replace('$1',$s_word,$_msg_notfoundresult);
	}
	ksort($pages);
	$retval = "<ul>\n";
	foreach ($pages as $page=>$time)
	{
		$r_page = rawurlencode($page);
		$s_page = htmlspecialchars($page);
		$passage = get_passage($time);
		$retval .= " <li><a href=\"$script?cmd=read&amp;page=$r_page&amp;word=$r_word\">$s_page</a>$passage</li>\n";
	}
	$retval .= "</ul>\n";
	
	$retval .= str_replace('$1',$s_word,str_replace('$2',count($pages),
		str_replace('$3',count($_pages),$b_type ? $_msg_andresult : $_msg_orresult)));
	
	return $retval;
}
Beispiel #25
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};';
        }
        $timestamp = strtotime($date);
        if ($timestamp === -1) {
            return '&new([nodate]){date}: Invalid date string;';
        }
        $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 '&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, 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;
    }
}
Beispiel #26
0
 function ShowRSS_html($rss, $showlines)
 {
     foreach ($rss as $date => $items) {
         foreach ($items as $item) {
             if ($showlines and $showlines <= $this->i) {
                 break;
             }
             $link = $item['LINK'];
             $title = $item['TITLE'];
             $passage = get_passage($item['_TIMESTAMP']);
             $link = "<a href=\"{$link}\" title=\"{$title} {$passage}\">{$title}</a>";
             $this->items[$date][] = $this->format_link($link);
             $this->i++;
         }
     }
 }
 function format_cell($timestamp)
 {
     return get_passage($timestamp, FALSE);
 }
/**
 * アクションプラグイン処理
 */
function plugin_logview_action()
{
    global $vars, $_logview_msg;
    global $log, $sortable_tracker;
    static $count = 0;
    $kind = isset($vars['kind']) ? $vars['kind'] : 'update';
    $title = sprintf($_logview_msg['msg_title'], $kind);
    // タイトルを設定
    $page = isset($vars['page']) ? $vars['page'] : '';
    // ゲスト表示ができない場合は、認証を要求する
    if ($log[$kind]['guest'] == '') {
        $obj = new auth();
        $user = $obj->check_auth();
        if (empty($user)) {
            if (exist_plugin('login')) {
                do_plugin_action('login');
            }
            unset($obj);
            return array('msg' => $title, 'body' => $_logview_msg['msg_not_auth']);
        }
    }
    unset($obj);
    check_readable($page, false);
    // 保存データの項目名を取得
    $name = log::get_log_field($kind);
    $view = log::get_view_field($kind);
    // 表示したい項目設定
    if ($sortable_tracker && $count == 0) {
        global $head_tags;
        $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'sortabletable.js"></script>';
    }
    $count++;
    $body = <<<EOD
<table id="logview{$count}" class="style_table" cellspacing="1" border="0">
<thead>
<tr>

EOD;
    $cols = 0;
    $is_role_adm = auth::check_role('role_adm');
    // タイトルの処理
    foreach ($view as $_view) {
        if ($_view === 'local_id' && $is_role_adm) {
            continue;
        }
        $body .= '<td class="style_td">' . $_logview_msg[$_view] . '</td>' . "\n";
        $cols++;
    }
    $body .= <<<EOD
</tr>
</thead>
<tbody>

EOD;
    // データを取得
    $fld = logview_get_data(log::set_filename($kind, $page), $name);
    if (empty($fld)) {
        return array('msg' => $title, 'body' => 'no data');
    }
    // USER-AGENT クラス
    $obj_ua = new user_agent(USE_UA_OPTION);
    $path_flag = IMAGE_URI . 'icon/flags/';
    $path_browser = IMAGE_URI . 'icon/browser/';
    $path_os = IMAGE_URI . 'icon/os/';
    $path_domain = IMAGE_URI . 'icon/option/domain/';
    $guess = $log['guess_user']['use'] ? log::read_guess() : log::summary_signature();
    $ctr = 0;
    // データの編集
    foreach ($fld as $data) {
        if (!VIEW_ROBOTS && $obj_ua->is_robots($data['ua'])) {
            continue;
        }
        // ロボットは対象外
        $body .= "<tr>\n";
        foreach ($view as $field) {
            switch ($field) {
                case 'ts':
                    // タイムスタンプ (UTIME)
                    $body .= ' <td class="style_td">' . get_date('Y-m-d H:i:s', $data['ts']) . ' ' . get_passage($data['ts']) . "</td>\n";
                    break;
                case '@guess_diff':
                case '@diff':
                    // 差分内容
                    $update = $field == '@diff' ? true : false;
                    // FIXME: バックアップ/差分 なしの新規の場合
                    // バックアップデータの確定
                    $body .= ' <td class="style_td">';
                    $age = log::get_backup_age($page, $data['ts'], $update);
                    switch ($age) {
                        case -1:
                            // データなし
                            $body .= '<a class="ext" href="' . get_page_uri($page) . '" rel="nofollow">none</a>';
                            break;
                        case 0:
                            // diff
                            $body .= '<a class="ext" href="';
                            $body .= log::diff_exist($page) ? get_cmd_uri('diff', $page) : get_page_uri($page);
                            $body .= '" rel="nofollow">now</a>';
                            break;
                        default:
                            // あり
                            $body .= '<a class="ext" href="' . get_cmd_uri('backup', $page, '', array('age' => $age, 'action' => 'visualdiff')) . '"' . ' rel="nofollow">' . $age . '</a>';
                            break;
                    }
                    $body .= "</td>\n";
                    break;
                case 'host':
                    // ホスト名 (FQDN)
                    $body .= ' <td class="style_td">';
                    if ($data['ip'] != $data['host']) {
                        // 国名取得
                        list($flag_icon, $flag_name) = $obj_ua->get_icon_flag($data['host']);
                        if (!empty($flag_icon) && $flag_icon != 'jp') {
                            $body .= '<img src="' . $path_flag . $flag_icon . '.png"' . ' alt="' . $flag_name . '" title="' . $flag_name . '" />';
                        }
                        // ドメイン取得
                        $domain = $obj_ua->get_icon_domain($data['host']);
                        if (!empty($domain)) {
                            $body .= '<img src="' . $path_domain . $domain . '.png"' . ' alt="' . $data['host'] . '" title="' . $data['host'] . '" />';
                        }
                    }
                    $body .= $data['host'] . "</td>\n";
                    break;
                case '@guess':
                    // 推測
                    $body .= ' <td class="style_td">' . htmlspecialchars(logview_guess_user($data, $guess), ENT_QUOTES) . "</td>\n";
                    break;
                case 'ua':
                    // ブラウザ情報 (USER-AGENT)
                    $body .= ' <td class="style_td">';
                    $os = $obj_ua->get_icon_os($data['ua']);
                    if (!empty($os)) {
                        $body .= '<img src="' . $path_os . $os . '.png"' . ' alt="' . $os . '" title="' . $os . '" />';
                    }
                    $browser = $obj_ua->get_icon_broeswes($data['ua']);
                    if (!empty($browser)) {
                        $body .= '<img src="' . $path_browser . $browser . '.png"' . ' alt="' . htmlspecialchars($data['ua'], ENT_QUOTES) . '" title="' . htmlspecialchars($data['ua'], ENT_QUOTES) . '" />';
                    }
                    $body .= "</td>\n";
                    break;
                case 'local_id':
                    if ($is_role_adm) {
                        continue;
                    }
                default:
                    $body .= ' <td class="style_td">' . htmlspecialchars($data[$field], ENT_QUOTES) . "</td>\n";
            }
        }
        $body .= "</tr>\n";
        $ctr++;
    }
    unset($obj_ua);
    if ($ctr == 0) {
        return array('msg' => $title, 'body' => 'no data');
    }
    $body .= <<<EOD
</tbody>
</table>

EOD;
    switch ($kind) {
        case 'login':
        case 'check':
            $body .= logview_user_list($fld, $page, $kind);
            break;
    }
    if ($sortable_tracker) {
        $logviewso = join(',', array_fill(0, $cols, '"String"'));
        $body .= <<<EOD
<script type="text/javascript">
<!-- <![CDATA[
var st = new SortableTable(document.getElementById('logview{$count}'),[{$logviewso}]);
//]]>-->
</script>
EOD;
    }
    return array('msg' => $title, 'body' => $body);
}