X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fhtml.php;h=41d53e9b158e3a13ebe4bec4ddc2d77ed7c59c07;hb=dcc6b19cb04618da87a41965a10db2f48b37c25e;hp=c5047d70c8d2e82fb03ac149d4b0b8a2abf10fd6;hpb=c459fd30e7be09e69c7a57d7bbf011502ec2cdc8;p=pukiwiki%2Fpukiwiki.git diff --git a/lib/html.php b/lib/html.php index c5047d7..41d53e9 100644 --- a/lib/html.php +++ b/lib/html.php @@ -1,8 +1,8 @@ ; rel=\"canonical\""); + } + // Search words if ($search_word_color && isset($vars['word'])) { - $body = '
' . $_msg_word . htmlspecialchars($vars['word']) . + $body = '
' . $_msg_word . htmlsc($vars['word']) . '
' . $hr . "\n" . $body; // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5 @@ -131,47 +166,128 @@ 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 = htmlspecialchars($key); - $pattern = '/' . + if (strlen($patterns) > 0) { + $patterns .= '|'; + } + $patterns .= '(' . $pattern . ')'; + } + if ($pattern) { + $whole_pattern = '/' . ']*>.*?<\/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])) ? ' . - '\'\' . $matches[1] . \'\' : ' . - '$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(); - $longtaketime = getmicrotime() - MUTIME; - $taketime = sprintf('%01.03f', $longtaketime); + // Compat: 'HTML convert time' without time about MenuBar and skin + $taketime = elapsedtime(); 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 '' . + $matches[0] . ''; + } + return $matches[0]; +} + +/** + * Get data used by JavaScript modules + */ +function get_html_scripting_data() +{ + 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+ + $json_enabled = defined('JSON_UNESCAPED_UNICODE'); + if (!$json_enabled) { + $empty_data = <<
+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; + $h_plugin = htmlsc($plugin); + $plugin_prop = << +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; + } + 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; + $data = <<