OSDN Git Service

BugTrack/560 Get timestamps of tracker_list pages from cache
[pukiwiki/pukiwiki.git] / lib / html.php
index 5ffcd20..e77baf3 100644 (file)
@@ -117,7 +117,7 @@ function catbody($title, $page, $body)
 
        // Last modification date (string) of the page
        $lastmodified = $is_read ?  format_date(get_filetime($_page)) .
-               ' ' . get_pg_passage($_page, FALSE) : '';
+               get_passage_html_span($_page) : '';
 
        // List of attached files to the page
        $show_attaches = $is_read || arg_check('edit');
@@ -166,28 +166,24 @@ function catbody($title, $page, $body)
                arsort($keys, SORT_NUMERIC);
                $keys = get_search_words(array_keys($keys), TRUE);
                $id = 0;
+               $patterns = '';
                foreach ($keys as $key=>$pattern) {
-                       $s_key    = htmlsc($key);
-                       $pattern  = '/' .
+                       if (strlen($patterns) > 0) {
+                               $patterns .= '|';
+                       }
+                       $patterns .= '(' . $pattern . ')';
+               }
+               if ($pattern) {
+                       $whole_pattern  = '/' .
                                '<textarea[^>]*>.*?<\/textarea>' .      // Ignore textareas
                                '|' . '<[^>]*>' .                       // Ignore tags
                                '|' . '&[^;]+;' .                       // Ignore entities
-                               '|' . '(' . $pattern . ')' .            // $matches[1]: Regex for a search word
+                               '|' . '(' . $patterns . ')' .           // $matches[1]: Regex for a search word
                                '/sS';
-                       $decorate_Nth_word = create_function(
-                               '$matches',
-                               'return (isset($matches[1])) ? ' .
-                                       '\'<strong class="word' .
-                                               $id .
-                                       '">\' . $matches[1] . \'</strong>\' : ' .
-                                       '$matches[0];'
-                       );
-                       $body  = preg_replace_callback($pattern, $decorate_Nth_word, $body);
-                       $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes);
-                       ++$id;
+                       $body  = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $body);
+                       $notes = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $notes);
                }
        }
-
        // Embed Scripting data
        $html_scripting_data = get_html_scripting_data();
 
@@ -197,33 +193,79 @@ function catbody($title, $page, $body)
        require(SKIN_FILE);
 }
 
+function _decorate_Nth_word($matches)
+{
+       // $matches[0]: including both words to skip and to decorate
+       // $matches[1]: word to decorate
+       // $matches[2+]: indicates which keyword to decorate
+       $index = -1;
+       for ($i = 2; $i < count($matches); $i++) {
+               if (isset($matches[$i]) && $matches[$i]) {
+                       $index = $i - 2;
+                       break;
+               }
+       }
+       if (isset($matches[1])) {
+               // wordN highlight class: N=0...n
+               return '<strong class="word' . $index . '">' .
+                       $matches[0] . '</strong>';
+       }
+       return $matches[0];
+}
+
 /**
  * Get data used by JavaScript modules
  */
 function get_html_scripting_data()
 {
-       global $ticket_link_sites;
+       global $ticket_link_sites, $plugin;
        if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
                return '';
        }
+       $is_utf8 = (bool)defined('PKWK_UTF8_ENABLE');
        // Require: PHP 5.4+
-       if (!defined('JSON_UNESCAPED_UNICODE')) {
-               return '';
-       };
-       $text = '';
+       $json_enabled = defined('JSON_UNESCAPED_UNICODE');
+       if (!$json_enabled) {
+               $empty_data = <<<EOS
+<div id="pukiwiki-site-properties" style="display:none;">
+</div>
+EOS;
+               return $empty_data;
+       }
+       // Site basic Properties
+       $props = array(
+               'is_utf8' => $is_utf8,
+               'json_enabled' => $json_enabled,
+               'base_uri_pathname' => get_base_uri(PKWK_URI_ROOT),
+               'base_uri_absolute' => get_base_uri(PKWK_URI_ABSOLUTE)
+       );
+       $props_json = htmlsc(json_encode($props, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+       $site_props = <<<EOS
+<div data-key="site-props" data-value="$props_json"></div>
+EOS;
+       $h_plugin = htmlsc($plugin);
+       $plugin_prop = <<<EOS
+<input type="hidden" class="plugin-name" value="$h_plugin" />
+EOS;
+
+       // AutoTicketLink
+       $filtered_ticket_link_sites = array();
        foreach ($ticket_link_sites as $s) {
                if (!preg_match('/^([a-zA-Z0-9]+)([\.\-][a-zA-Z0-9]+)*$/', $s['key'])) {
                        continue;
                }
-               $site_info_json = htmlsc(json_encode($s, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
-               $text .= <<<EOS
-  <span class="pukiwiki-ticketlink-site" data-site="$site_info_json"></span>
-EOS;
-               $text .= "\n";
+               array_push($filtered_ticket_link_sites, $s);
        }
+       $h_ticket_link_sites = htmlsc(json_encode($filtered_ticket_link_sites,
+               JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+       $ticketlink_data = <<<EOS
+<input type="hidden" class="ticketlink-def" value="$h_ticket_link_sites" />
+EOS;
        $data = <<<EOS
-<div class="pukiwiki-ticketlink-def" style="display:none;">
-$text
+<div id="pukiwiki-site-properties" style="display:none;">
+$site_props
+$plugin_prop
+$ticketlink_data
 </div>
 EOS;
        return $data;
@@ -237,6 +279,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
        global $whatsnew, $_btn_template, $_btn_load, $load_template_func;
        global $notimeupdate;
        global $_title_list, $_label_template_pages;
+       global $_msg_edit_cancel_confirm, $_msg_edit_unloadbefore_message;
        global $rule_page;
 
        $script = get_base_uri();
@@ -244,7 +287,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
        if ($digest === FALSE) $digest = md5(join('', get_source($page)));
 
        $refer = $template = '';
+
        // Add plugin
        $addtag = $add_top = '';
        if(isset($vars['add'])) {
@@ -345,14 +388,18 @@ EOD;
 
        // 'margin-bottom', 'float:left', and 'margin-top'
        // are for layout of 'cancel button'
+       $h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
+       $h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
        $body = <<<EOD
 <div class="edit_form">
- <form action="$script" method="post" style="margin-bottom:0px;">
+ <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0px;">
 $template
   $addtag
   <input type="hidden" name="cmd"    value="edit" />
   <input type="hidden" name="page"   value="$s_page" />
   <input type="hidden" name="digest" value="$s_digest" />
+  <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
+  <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
   <textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
   <br />
   <div style="float:left;">
@@ -363,7 +410,7 @@ $template
   </div>
   <textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
  </form>
- <form action="$script" method="post" style="margin-top:0px;">
+ <form action="$script" method="post" class="_plugin_edit_cancel" style="margin-top:0px;">
   <input type="hidden" name="cmd"    value="edit" />
   <input type="hidden" name="page"   value="$s_page" />
   <input type="submit" name="cancel" value="$_btn_cancel" accesskey="c" />
@@ -395,15 +442,18 @@ function make_related($page, $tag = '')
        $_links = array();
        foreach ($links as $page=>$lastmod) {
                if (check_non_list($page)) continue;
-
                $page_uri = get_page_uri($page);
                $s_page   = htmlsc($page);
-               $passage  = get_passage($lastmod);
-               $_links[] = $tag ?
-                       '<a href="' . $page_uri . '" title="' .
-                       $s_page . ' ' . $passage . '">' . $s_page . '</a>' :
-                       '<a href="' . $page_uri . '">' .
-                       $s_page . '</a>' . $passage;
+               if ($tag) {
+                       $attrs = get_page_link_a_attrs($page);
+                       $_links[] = '<a href="' . $page_uri . '" class="' .
+                               $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                               '">' . $s_page . '</a>';
+               } else {
+                       $mtime_span = get_passage_mtime_html_span($lastmod + LOCALZONE);
+                       $_links[] = '<a href="' . $page_uri . '">' .
+                       $s_page . '</a>' . $mtime_span;
+               }
        }
        if (empty($_links)) return ''; // Nothing
 
@@ -421,6 +471,11 @@ function make_related($page, $tag = '')
        return $retval;
 }
 
+function _convert_line_rule_to_regex($a)
+{
+       return '/' . $a . '/';
+}
+
 // User-defined rules (convert without replacing source)
 function make_line_rules($str)
 {
@@ -428,8 +483,7 @@ function make_line_rules($str)
        static $pattern, $replace;
 
        if (! isset($pattern)) {
-               $pattern = array_map(create_function('$a',
-                       'return \'/\' . $a . \'/\';'), array_keys($line_rules));
+               $pattern = array_map('_convert_line_rule_to_regex', array_keys($line_rules));
                $replace = array_values($line_rules);
                unset($line_rules);
        }