X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fhtml.php;h=3ba8c3fc4c1486aa2d277eb27399464dc1be5557;hb=83a95d80e0fc3d8bdccf79fb1106a04903685090;hp=d07ca9c1ceaa19698969d3824626a04202ee8d06;hpb=694d5a8d60cd0cfe5b892e19a1bca7bb55797700;p=pukiwiki%2Fpukiwiki.git diff --git a/lib/html.php b/lib/html.php index d07ca9c..3ba8c3f 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,49 +168,179 @@ 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 - '/s'; - $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; + '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word + '/sS'; + $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($_page, $is_edit_preview); - $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 + * + * @param $page page name + * @param $in_editing true if preview in editing + */ +function get_html_scripting_data($page, $in_editing) +{ + global $ticket_link_sites, $plugin; + global $external_link_cushion_page, $external_link_cushion; + global $topicpath_title; + global $ticket_jira_default_site; + 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) + ); + $h_props = htmlsc_json($props); + $site_props = << +EOS; + $h_plugin = htmlsc($plugin); + $plugin_prop = << +EOS; + // Page name + $h_page_name = htmlsc($page); + $page_name_data = << +EOS; + // Page is editing (preview) + $in_editing_value = ($plugin === 'edit' && $in_editing) ? 'true' : 'false'; + $page_edit_data = << +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($filtered_ticket_link_sites); + $ticketlink_data = << +EOS; + // AutoTicketLink - JIRA + $ticket_jira_projects = get_ticketlink_jira_projects(); + $ticketlink_jira_data = ''; + if (count($ticket_jira_projects) > 0) { + $h_ticket_jira_projects = htmlsc_json($ticket_jira_projects); + $ticketlink_jira_data = << +EOS; + } + $ticketlink_jira_default_data = ''; + if (isset($ticket_jira_default_site) && is_array($ticket_jira_default_site)) { + $h_ticket_jira_default_site = htmlsc_json($ticket_jira_default_site); + $ticketlink_jira_default_data = << +EOS; + } + // External link cushion page + $external_link_cushion_data = ''; + if ($external_link_cushion_page) { + $h_cushion = htmlsc_json($external_link_cushion); + $external_link_cushion_data = << +EOS; + } + // Topicpath title + $topicpath_data = ''; + if ($topicpath_title && exist_plugin('topicpath')) { + $parents = plugin_topicpath_parent_links($page); + $h_topicpath = htmlsc(json_encode($parents, + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + $topicpath_data = << +EOS; + } + $data = <<