OSDN Git Service

BugTrack/2478 Handle plus(+) char in URL as space for page name
[pukiwiki/pukiwiki.git] / lib / func.php
index 9536393..41bcd81 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // func.php
 // Copyright
-//   2002-2017 PukiWiki Development Team
+//   2002-2018 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -230,6 +230,13 @@ function auto_template($page)
        return $body;
 }
 
+function _mb_convert_kana__enable($str, $option) {
+       return mb_convert_kana($str, $option, SOURCE_ENCODING);
+}
+function _mb_convert_kana__none($str, $option) {
+       return $str;
+}
+
 // Expand all search-words to regexes and push them into an array
 function get_search_words($words = array(), $do_escape = FALSE)
 {
@@ -238,11 +245,9 @@ function get_search_words($words = array(), $do_escape = FALSE)
        if (! isset($init)) {
                // function: mb_convert_kana() is for Japanese code only
                if (LANG == 'ja' && function_exists('mb_convert_kana')) {
-                       $mb_convert_kana = create_function('$str, $option',
-                               'return mb_convert_kana($str, $option, SOURCE_ENCODING);');
+                       $mb_convert_kana = '_mb_convert_kana__enable';
                } else {
-                       $mb_convert_kana = create_function('$str, $option',
-                               'return $str;');
+                       $mb_convert_kana = '_mb_convert_kana__none';
                }
                if (SOURCE_ENCODING == 'EUC-JP') {
                        // Perl memo - Correct pattern-matching with EUC-JP
@@ -298,6 +303,74 @@ function get_search_words($words = array(), $do_escape = FALSE)
        return $regex; // For all words
 }
 
+function get_passage_date_html_span($date_atom)
+{
+       return '<span class="page_passage" data-mtime="' . $date_atom . '"></span>';
+}
+
+function get_passage_mtime_html_span($mtime)
+{
+       $date_atom = get_date_atom($mtime);
+       return get_passage_date_html_span($date_atom);
+}
+
+/**
+ * Get passage span html
+ *
+ * @param $page
+ */
+function get_passage_html_span($page)
+{
+       $date_atom = get_page_date_atom($page);
+       return get_passage_date_html_span($date_atom);
+}
+
+function get_link_passage_class() {
+       return 'link_page_passage';
+}
+
+/**
+ * Get page link general attributes
+ * @param $page
+ * @return array('data_mtime' => page mtime or null, 'class' => additinal classes)
+ */
+function get_page_link_a_attrs($page)
+{
+       global $show_passage;
+       if ($show_passage) {
+               $pagemtime = get_page_date_atom($page);
+               return array(
+                       'data_mtime' => $pagemtime,
+                       'class' => get_link_passage_class(),
+               );
+       }
+       return array(
+               'data_mtime' => '',
+               'class' => ''
+       );
+}
+
+/**
+ * Get page link general attributes from filetime
+ * @param $filetime
+ * @return array('data_mtime' => page mtime or null, 'class' => additinal classes)
+ */
+function get_filetime_a_attrs($filetime)
+{
+       global $show_passage;
+       if ($show_passage) {
+               $pagemtime = get_date_atom($filetime + LOCALZONE);
+               return array(
+                       'data_mtime' => $pagemtime,
+                       'class' => get_link_passage_class(),
+               );
+       }
+       return array(
+               'data_mtime' => '',
+               'class' => ''
+       );
+}
+
 // 'Search' main function
 function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
 {
@@ -359,7 +432,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
        $r_word = rawurlencode($word);
        $s_word = htmlsc($word);
        if (empty($pages))
-               return str_replace('$1', $s_word, $_msg_notfoundresult);
+               return str_replace('$1', $s_word, str_replace('$3', $count, $_msg_notfoundresult));
 
        ksort($pages, SORT_STRING);
 
@@ -367,7 +440,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
        foreach (array_keys($pages) as $page) {
                $r_page  = rawurlencode($page);
                $s_page  = htmlsc($page);
-               $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : '';
+               $passage = $show_passage ? ' ' . get_passage_html_span($page) : '';
                $retval .= ' <li><a href="' . get_base_uri() . '?cmd=read&amp;page=' .
                        $r_page . '&amp;word=' . $r_word . '">' . $s_page .
                        '</a>' . $passage . '</li>' . "\n";
@@ -389,7 +462,7 @@ function arg_check($str)
 
 function _pagename_urlencode_callback($matches)
 {
-       return rawurlencode($matches[0]);
+       return urlencode($matches[0]);
 }
 
 function pagename_urlencode($page)
@@ -460,15 +533,12 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
        } else {
                $href = $script . '?cmd=' . $cmd . '&amp;page=';
        }
-
+       uasort($pages, 'strnatcmp');
        foreach($pages as $file=>$page) {
                $r_page  = pagename_urlencode($page);
                $s_page  = htmlsc($page, ENT_QUOTES);
-               $passage = get_pg_passage($page);
-
                $str = '   <li><a href="' . $href . $r_page . '">' .
-                       $s_page . '</a>' . $passage;
-
+                       $s_page . '</a> ' . get_pg_passage($page);
                if ($withfilename) {
                        $s_file = htmlsc($file);
                        $str .= "\n" . '    <ul><li>' . $s_file . '</li></ul>' .
@@ -491,15 +561,14 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
                        $head = (preg_match('/^([A-Za-z])/', $page, $matches)) ? strtoupper($matches[1]) :
                                (preg_match('/^([ -~])/', $page) ? $symbol : $other);
                }
-
                $list[$head][$page] = $str;
        }
-       uksort($pages, 'strnatcmp');
+       uksort($list, 'strnatcmp');
 
        $cnt = 0;
        $arr_index = array();
        $retval .= '<ul>' . "\n";
-       foreach ($list as $head=>$pages) {
+       foreach ($list as $head=>$sub_pages) {
                if ($head === $symbol) {
                        $head = $_msg_symbol;
                } else if ($head === $other) {
@@ -515,8 +584,7 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
                                '"><strong>' . $head . '</strong></a>' . "\n" .
                                '  <ul>' . "\n";
                }
-               ksort($pages, SORT_STRING);
-               $retval .= join("\n", $pages);
+               $retval .= join("\n", $sub_pages);
                if ($list_index)
                        $retval .= "\n  </ul>\n </li>\n";
        }
@@ -619,6 +687,18 @@ function format_date($val, $paren = FALSE)
        return $paren ? '(' . $date . ')' : $date;
 }
 
+/**
+ * Format date in DATE_ATOM format.
+ */
+function get_date_atom($timestamp)
+{
+       // Compatible with DATE_ATOM format
+       // return date(DATE_ATOM, $timestamp);
+       $zmin = abs(LOCALZONE / 60);
+       return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
+               (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
+}
+
 // Get short string of the passage, 'N seconds/minutes/hours/days/years ago'
 function get_passage($time, $paren = TRUE)
 {
@@ -660,7 +740,7 @@ function get_autolink_pattern(& $pages)
                        $auto_pages[] = $page;
 
        if (empty($auto_pages)) {
-               $result = $result_a = $nowikiname ? '(?!)' : $WikiName;
+               $result = $result_a = '(?!)';
        } else {
                $auto_pages = array_unique($auto_pages);
                sort($auto_pages, SORT_STRING);
@@ -755,7 +835,7 @@ function get_script_uri()
  * @param $initialize true if you initialize URI
  * @param $uri_set URI set manually
  */
-function pkwk_script_uri_base($uri_type, $initialize, $uri_set)
+function pkwk_script_uri_base($uri_type, $initialize = null, $uri_set = null)
 {
        global $script_directory_index;
        static $initialized = false;
@@ -848,7 +928,7 @@ function pkwk_base_uri_type_stack_peek()
  * @param $uri_type uri_type on push and non-peeking
  * @return $uri_type uri_type for peeking
  */
-function _pkwk_base_uri_type_stack($peek, $push, $uri_type)
+function _pkwk_base_uri_type_stack($peek, $push, $uri_type = null)
 {
        static $uri_types = array();
        if ($peek) {