X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fhtml.php;h=3ba8c3fc4c1486aa2d277eb27399464dc1be5557;hb=83a95d80e0fc3d8bdccf79fb1106a04903685090;hp=e54c2b1e14cf799858e40d75e744f4af584d47c4;hpb=ff810438e1d70b83ee8e341798b70f563747d4ff;p=pukiwiki%2Fpukiwiki.git diff --git a/lib/html.php b/lib/html.php index e54c2b1..3ba8c3f 100644 --- a/lib/html.php +++ b/lib/html.php @@ -1,17 +1,23 @@ ; 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; - $words = array_flip(array_splice( - preg_split('/\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY), - 0, 10)); + + // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5 + // with array_splice(), array_flip() + $words = preg_split('/\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY); + $words = array_splice($words, 0, 10); // Max: 10 words + $words = array_flip($words); + $keys = array(); foreach ($words as $word=>$id) $keys[$word] = strlen($word); 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 = '/<[^>]*>|(' . $pattern . ')|&[^;]+;/'; - $callback = create_function( - '$arr', - 'return (count($arr) > 1) ? \'\' . $arr[1] . \'\' : $arr[0];' - ); - $body = preg_replace_callback($pattern, $callback, $body); - $notes = preg_replace_callback($pattern, $callback, $notes); + if (strlen($patterns) > 0) { + $patterns .= '|'; + } + $patterns .= '(' . $pattern . ')'; + } + if ($pattern) { + $whole_pattern = '/' . + ']*>.*?<\/textarea>' . // Ignore textareas + '|' . '<[^>]*>' . // Ignore tags + '|' . '&[^;]+;' . // Ignore entities + '|' . '(' . $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); } -// Show 'edit' form -function edit_form($page, $postdata, $digest = 0, $b_template = TRUE) +function _decorate_Nth_word($matches) { - global $script, $vars, $rows, $cols, $hr, $function_freeze; - global $_btn_addtop, $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, - $_msg_help, $_btn_notchangetimestamp; - global $whatsnew, $_btn_template, $_btn_load, $non_list, $load_template_func; - - $refer = $template = $addtag = $add_top = ''; - - if ($digest == 0) $digest = md5(join('', get_source($page))); + // $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]; +} - $checked_top = isset($vars['add_top']) ? ' checked="checked"' : ''; - $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : ''; +/** + * 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 = <<