2 // PukiWiki - Yet another WikiWikiWeb clone.
5 // 2002-2022 PukiWiki Development Team
6 // 2001-2002 Originally written by yu-ji
7 // License: GPL v2 or (at your option) any later version
9 // HTML-publishing related functions
12 function catbody($title, $page, $body)
14 global $vars, $arg, $defaultpage, $whatsnew, $help_page, $hr;
15 global $attach_link, $related_link, $cantedit, $function_freeze;
16 global $search_word_color, $_msg_word, $foot_explain, $note_hr, $head_tags;
17 global $javascript, $nofollow;
18 global $_LANG, $_LINK, $_IMAGE;
19 global $auth_type, $auth_user;
20 global $html_meta_referrer_policy;
22 global $pkwk_dtd; // XHTML 1.1, XHTML1.0, HTML 4.01 Transitional...
23 global $page_title; // Title of this site
24 global $do_backup; // Do backup or not
25 global $modifier; // Site administrator's web page
26 global $modifierlink; // Site administrator's name
28 $script = get_base_uri();
29 $enable_login = false;
30 $enable_logout = false;
31 if (AUTH_TYPE_FORM === $auth_type || AUTH_TYPE_EXTERNAL === $auth_type ||
32 AUTH_TYPE_SAML === $auth_type) {
34 $enable_logout = true;
38 } else if (AUTH_TYPE_BASIC === $auth_type) {
40 $enable_logout = true;
43 if (! file_exists(SKIN_FILE) || ! is_readable(SKIN_FILE))
44 die_message('SKIN_FILE is not found');
46 $_LINK = $_IMAGE = array();
48 $_page = isset($vars['page']) ? $vars['page'] : '';
49 $r_page = pagename_urlencode($_page);
50 $is_edit_preview = isset($vars['preview']);
52 $canonical_url = get_page_uri($_page, PKWK_URI_ABSOLUTE);
54 // Set $_LINK for skin
55 $_LINK['add'] = "$script?cmd=add&page=$r_page";
56 $_LINK['backup'] = "$script?cmd=backup&page=$r_page";
57 $_LINK['copy'] = "$script?plugin=template&refer=$r_page";
58 $_LINK['diff'] = "$script?cmd=diff&page=$r_page";
59 $_LINK['edit'] = "$script?cmd=edit&page=$r_page";
60 $_LINK['filelist'] = "$script?cmd=filelist";
61 $_LINK['freeze'] = "$script?cmd=freeze&page=$r_page";
62 $_LINK['help'] = get_page_uri($help_page);
63 $_LINK['list'] = "$script?cmd=list";
64 $_LINK['new'] = "$script?plugin=newpage&refer=$r_page";
65 $_LINK['rdf'] = "$script?cmd=rss&ver=1.0";
66 $_LINK['recent'] = get_page_uri($whatsnew);
67 $_LINK['reload'] = get_page_uri($_page);
68 $_LINK['rename'] = "$script?plugin=rename&refer=$r_page";
69 $_LINK['rss'] = "$script?cmd=rss";
70 $_LINK['rss10'] = "$script?cmd=rss&ver=1.0"; // Same as 'rdf'
71 $_LINK['rss20'] = "$script?cmd=rss&ver=2.0";
72 $_LINK['search'] = "$script?cmd=search";
73 $_LINK['top'] = get_base_uri();
74 $_LINK['unfreeze'] = "$script?cmd=unfreeze&page=$r_page";
75 $_LINK['upload'] = "$script?plugin=attach&pcmd=upload&page=$r_page";
76 $_LINK['canonical_url'] = $canonical_url;
77 $login_link = "#LOGIN_ERROR"; // dummy link that is not used
80 $login_link = "$script?plugin=loginform&pcmd=login&page=$r_page";
82 case AUTH_TYPE_EXTERNAL:
84 $login_link = get_auth_external_login_url($_page,
85 get_page_uri($_page, PKWK_URI_ROOT));
88 $_LINK['login'] = htmlsc($login_link);
89 $_LINK['logout'] = "$script?plugin=loginform&pcmd=logout&page=$r_page";
91 // Compat: Skins for 1.4.4 and before
92 $link_add = & $_LINK['add'];
93 $link_new = & $_LINK['new']; // New!
94 $link_edit = & $_LINK['edit'];
95 $link_diff = & $_LINK['diff'];
96 $link_top = & $_LINK['top'];
97 $link_list = & $_LINK['list'];
98 $link_filelist = & $_LINK['filelist'];
99 $link_search = & $_LINK['search'];
100 $link_whatsnew = & $_LINK['recent'];
101 $link_backup = & $_LINK['backup'];
102 $link_help = & $_LINK['help'];
103 $link_trackback = ''; // Removed (compat)
104 $link_rdf = & $_LINK['rdf']; // New!
105 $link_rss = & $_LINK['rss'];
106 $link_rss10 = & $_LINK['rss10']; // New!
107 $link_rss20 = & $_LINK['rss20']; // New!
108 $link_freeze = & $_LINK['freeze'];
109 $link_unfreeze = & $_LINK['unfreeze'];
110 $link_upload = & $_LINK['upload'];
111 $link_template = & $_LINK['copy'];
112 $link_refer = ''; // Removed (compat)
113 $link_rename = & $_LINK['rename'];
116 $is_page = (is_pagename($_page) && ! arg_check('backup') && $_page != $whatsnew);
117 $is_read = (arg_check('read') && is_page($_page));
118 $is_freeze = is_freeze($_page);
120 // Last modification date (string) of the page
121 $lastmodified = $is_read ? format_date(get_filetime($_page)) .
122 get_passage_html_span($_page) : '';
124 // List of attached files to the page
125 $show_attaches = $is_read || arg_check('edit');
126 $attaches = ($attach_link && $show_attaches && exist_plugin_action('attach')) ?
127 attach_filelist() : '';
129 // List of related pages
130 $related = ($related_link && $is_read) ? make_related($_page) : '';
133 ksort($foot_explain, SORT_NUMERIC);
134 $notes = ! empty($foot_explain) ? $note_hr . join("\n", $foot_explain) : '';
136 // Tags will be inserted into <head></head>
137 $head_tag = ! empty($head_tags) ? join("\n", $head_tags) ."\n" : '';
140 // Last modification date (UNIX timestamp) of the page
141 $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
143 // Output nofollow / noindex regardless os skin file
144 if (!$is_read || $nofollow) {
145 if (!headers_sent()) {
146 header("X-Robots-Tag: noindex,nofollow");
150 // Send Canonical URL for Search Engine Optimization
151 if ($is_read && !headers_sent()) {
152 header("Link: <$canonical_url>; rel=\"canonical\"");
156 if ($search_word_color && isset($vars['word'])) {
157 $body = '<div class="small">' . $_msg_word . htmlsc($vars['word']) .
158 '</div>' . $hr . "\n" . $body;
160 // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
161 // with array_splice(), array_flip()
162 $words = preg_split('/\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY);
163 $words = array_splice($words, 0, 10); // Max: 10 words
164 $words = array_flip($words);
167 foreach ($words as $word=>$id) $keys[$word] = strlen($word);
168 arsort($keys, SORT_NUMERIC);
169 $keys = get_search_words(array_keys($keys), TRUE);
172 foreach ($keys as $key=>$pattern) {
173 if (strlen($patterns) > 0) {
176 $patterns .= '(' . $pattern . ')';
179 $whole_pattern = '/' .
180 '<textarea[^>]*>.*?<\/textarea>' . // Ignore textareas
181 '|' . '<[^>]*>' . // Ignore tags
182 '|' . '&[^;]+;' . // Ignore entities
183 '|' . '(' . $patterns . ')' . // $matches[1]: Regex for a search word
185 $body = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $body);
186 $notes = preg_replace_callback($whole_pattern, '_decorate_Nth_word', $notes);
189 // Embed Scripting data
190 $html_scripting_data = get_html_scripting_data($_page, $is_edit_preview);
192 // Compat: 'HTML convert time' without time about MenuBar and skin
193 $taketime = elapsedtime();
198 function _decorate_Nth_word($matches)
200 // $matches[0]: including both words to skip and to decorate
201 // $matches[1]: word to decorate
202 // $matches[2+]: indicates which keyword to decorate
204 for ($i = 2; $i < count($matches); $i++) {
205 if (isset($matches[$i]) && $matches[$i]) {
210 if (isset($matches[1])) {
211 // wordN highlight class: N=0...n
212 return '<strong class="word' . $index . '">' .
213 $matches[0] . '</strong>';
219 * Get data used by JavaScript modules
221 * @param $page page name
222 * @param $in_editing true if preview in editing
224 function get_html_scripting_data($page, $in_editing)
226 global $ticket_link_sites, $plugin;
227 global $external_link_cushion_page, $external_link_cushion;
228 global $topicpath_title;
229 global $ticket_jira_default_site;
230 global $show_passage;
231 if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
234 $is_utf8 = (bool)defined('PKWK_UTF8_ENABLE');
236 $json_enabled = defined('JSON_UNESCAPED_UNICODE');
237 if (!$json_enabled) {
239 <div id="pukiwiki-site-properties" style="display:none;">
244 $is_show_passage = (bool)($show_passage !== 0);
245 // Site basic Properties
247 'is_utf8' => $is_utf8,
248 'json_enabled' => $json_enabled,
249 'show_passage' => $is_show_passage,
250 'base_uri_pathname' => get_base_uri(PKWK_URI_ROOT),
251 'base_uri_absolute' => get_base_uri(PKWK_URI_ABSOLUTE)
253 $h_props = htmlsc_json($props);
255 <input type="hidden" class="site-props" value="$h_props" />
257 $h_plugin = htmlsc($plugin);
258 $plugin_prop = <<<EOS
259 <input type="hidden" class="plugin-name" value="$h_plugin" />
262 $h_page_name = htmlsc($page);
263 $page_name_data = <<<EOS
264 <input type="hidden" class="page-name" value="$h_page_name" />
266 // Page is editing (preview)
267 $in_editing_value = ($plugin === 'edit' && $in_editing) ? 'true' : 'false';
268 $page_edit_data = <<<EOS
269 <input type="hidden" class="page-in-edit" value="$in_editing_value" />
272 $filtered_ticket_link_sites = array();
273 foreach ($ticket_link_sites as $s) {
274 if (!preg_match('/^([a-zA-Z0-9]+)([\.\-][a-zA-Z0-9]+)*$/', $s['key'])) {
277 array_push($filtered_ticket_link_sites, $s);
279 $h_ticket_link_sites = htmlsc_json($filtered_ticket_link_sites);
280 $ticketlink_data = <<<EOS
281 <input type="hidden" class="ticketlink-def" value="$h_ticket_link_sites" />
283 // AutoTicketLink - JIRA
284 $ticket_jira_projects = get_ticketlink_jira_projects();
285 $ticketlink_jira_data = '';
286 if (count($ticket_jira_projects) > 0) {
287 $h_ticket_jira_projects = htmlsc_json($ticket_jira_projects);
288 $ticketlink_jira_data = <<<EOS
289 <input type="hidden" class="ticketlink-jira-def" value="$h_ticket_jira_projects" />
292 $ticketlink_jira_default_data = '';
293 if (isset($ticket_jira_default_site) && is_array($ticket_jira_default_site)) {
294 $h_ticket_jira_default_site = htmlsc_json($ticket_jira_default_site);
295 $ticketlink_jira_default_data = <<<EOS
296 <input type="hidden" class="ticketlink-jira-default-def" value="$h_ticket_jira_default_site" />
299 // External link cushion page
300 $external_link_cushion_data = '';
301 if ($external_link_cushion_page) {
302 $h_cushion = htmlsc_json($external_link_cushion);
303 $external_link_cushion_data = <<<EOS
304 <input type="hidden" class="external-link-cushion" value="$h_cushion" />
308 $topicpath_data = '';
309 if ($topicpath_title && exist_plugin('topicpath') &&
310 function_exists('plugin_topicpath_parent_links')) {
311 $parents = plugin_topicpath_parent_links($page);
312 $h_topicpath = htmlsc_json($parents);
313 $topicpath_data = <<<EOS
314 <input type="hidden" class="topicpath-links" value="$h_topicpath" />
318 <div id="pukiwiki-site-properties" style="display:none;">
324 $ticketlink_jira_data
325 $ticketlink_jira_default_data
326 $external_link_cushion_data
334 function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
336 global $vars, $rows, $cols;
337 global $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, $_msg_help;
338 global $_btn_template, $_btn_load, $load_template_func;
339 global $notimeupdate;
340 global $_msg_edit_cancel_confirm, $_msg_edit_unloadbefore_message;
343 $script = get_base_uri();
344 // Newly generate $digest or not
345 if ($digest === FALSE) $digest = md5(join('', get_source($page)));
346 $refer = $template = '';
348 $addtag = $add_top = '';
349 if(isset($vars['add'])) {
351 $addtag = '<input type="hidden" name="add" value="true" />';
352 $add_top = isset($vars['add_top']) ? ' checked="checked"' : '';
353 $add_top = '<input type="checkbox" name="add_top" ' .
354 'id="_edit_form_add_top" value="true"' . $add_top . ' />' . "\n" .
355 ' <label for="_edit_form_add_top">' .
356 '<span class="small">' . $_btn_addtop . '</span>' .
359 if($load_template_func && $b_template) {
360 $template_page_list = get_template_page_list();
361 $tpages = array(); // Template pages
362 foreach($template_page_list as $p) {
364 $tpages[] = ' <option value="' . $ps . '">' . $ps . '</option>';
366 if (count($template_page_list) > 0) {
367 $s_tpages = join("\n", $tpages);
369 $s_tpages = ' <option value="">(no template pages)</option>';
372 <select name="template_page">
373 <option value="">-- $_btn_template --</option>
376 <input type="submit" name="template" value="$_btn_load" accesskey="r" />
380 if (isset($vars['refer']) && $vars['refer'] != '')
381 $refer = '[[' . strip_bracket($vars['refer']) . ']]' . "\n\n";
384 $r_page = rawurlencode($page);
385 $s_page = htmlsc($page);
386 $s_digest = htmlsc($digest);
387 $s_postdata = htmlsc($refer . $postdata);
388 $s_original = isset($vars['original']) ? htmlsc($vars['original']) : $s_postdata;
389 $b_preview = isset($vars['preview']); // TRUE when preview
390 $btn_preview = $b_preview ? $_btn_repreview : $_btn_preview;
392 // Checkbox 'do not change timestamp'
393 $add_notimestamp = '';
394 if ($notimeupdate != 0) {
395 global $_btn_notchangetimestamp;
396 $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : '';
397 // Only for administrator
398 if ($notimeupdate == 2) {
399 $add_notimestamp = ' ' .
400 '<input type="password" name="pass" size="12" />' . "\n";
402 $add_notimestamp = '<input type="checkbox" name="notimestamp" ' .
403 'id="_edit_form_notimestamp" value="true"' . $checked_time . ' />' . "\n" .
404 ' ' . '<label for="_edit_form_notimestamp"><span class="small">' .
405 $_btn_notchangetimestamp . '</span></label>' . "\n" .
410 // 'margin-bottom', 'float:left', and 'margin-top'
411 // are for layout of 'cancel button'
412 $h_msg_edit_cancel_confirm = htmlsc($_msg_edit_cancel_confirm);
413 $h_msg_edit_unloadbefore_message = htmlsc($_msg_edit_unloadbefore_message);
415 <div class="edit_form">
416 <form action="$script" method="post" class="_plugin_edit_edit_form" style="margin-bottom:0;">
419 <input type="hidden" name="cmd" value="edit" />
420 <input type="hidden" name="page" value="$s_page" />
421 <input type="hidden" name="digest" value="$s_digest" />
422 <input type="hidden" id="_msg_edit_cancel_confirm" value="$h_msg_edit_cancel_confirm" />
423 <input type="hidden" id="_msg_edit_unloadbefore_message" value="$h_msg_edit_unloadbefore_message" />
424 <textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
426 <div style="float:left;">
427 <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
428 <input type="submit" name="write" value="$_btn_update" accesskey="s" />
432 <textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
434 <form action="$script" method="post" class="_plugin_edit_cancel" style="margin-top:0;">
435 <input type="hidden" name="cmd" value="edit" />
436 <input type="hidden" name="page" value="$s_page" />
437 <input type="submit" name="cancel" value="$_btn_cancel" accesskey="c" />
442 $body .= '<ul><li><a href="' .
443 get_page_uri($rule_page) .
444 '" target="_blank">' . $_msg_help . '</a></li></ul>';
449 * Get template page list.
451 function get_template_page_list()
454 $tpage_names = array(); // Pages marked as template
455 $template_page = ':config/Templates';
457 foreach(get_source($template_page) as $_templates) {
459 if (! preg_match('#\-\s*\[\[([^\[\]]+)\]\]#', $_templates, $m)) continue;
460 $tpage = preg_replace('#^./#', "$template_page/", $m[1]);
461 if (! is_page($tpage)) continue;
462 $tpage_names[] = $tpage;
464 $page_names = array();
465 $page_list = get_existpages();
466 if (count($page_list) > $page_max) {
467 // Extract only template name pages
468 $target_pages = array();
469 foreach ($page_list as $_page) {
470 if (preg_match('/template/i', $_page)) {
471 $target_pages[] = $_page;
475 $target_pages = $page_list;
477 foreach ($target_pages as $_page) {
478 if ($_page == $whatsnew || check_non_list($_page) ||
479 !is_page_readable($_page)) {
482 $tpage_names[] = $_page;
484 $tempalte_page_list = array_values(array_unique($tpage_names));
485 natcasesort($tempalte_page_list);
486 return $tempalte_page_list;
490 function make_related($page, $tag = '')
492 global $vars, $rule_related_str, $related_str;
494 $script = get_base_uri();
495 prepare_links_related($page);
496 $links = links_get_related($page);
499 ksort($links, SORT_STRING); // Page name, alphabetical order
501 arsort($links, SORT_NUMERIC); // Last modified date, newer
505 foreach ($links as $page=>$lastmod) {
506 if (check_non_list($page)) continue;
507 $page_uri = get_page_uri($page);
508 $s_page = htmlsc($page);
510 $attrs = get_page_link_a_attrs($page);
511 $_links[] = '<a href="' . $page_uri . '" class="' .
512 $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
513 '">' . $s_page . '</a>';
515 $mtime_span = get_passage_mtime_html_span($lastmod + LOCALZONE);
516 $_links[] = '<a href="' . $page_uri . '">' .
517 $s_page . '</a>' . $mtime_span;
520 if (empty($_links)) return ''; // Nothing
522 if ($tag == 'p') { // From the line-head
523 $style = sprintf(pkwk_list_attrs_template(), 1, 1);
524 $retval = "\n" . '<ul' . $style . '>' . "\n" .
525 '<li>' . join($rule_related_str, $_links) . '</li>' . "\n" .
528 $retval = join($rule_related_str, $_links);
530 $retval = join($related_str, $_links);
536 function _convert_line_rule_to_regex($a)
538 return '/' . $a . '/' . get_preg_u();
541 // User-defined rules (convert without replacing source)
542 function make_line_rules($str)
545 static $pattern, $replace;
547 if (! isset($pattern)) {
548 $pattern = array_map('_convert_line_rule_to_regex', array_keys($line_rules));
549 $replace = array_values($line_rules);
553 return preg_replace($pattern, $replace, $str);
556 // Remove all HTML tags(or just anchor tags), and WikiName-speific decorations
557 function strip_htmltag($str, $all = TRUE)
559 global $_symbol_noexists;
560 static $noexists_pattern;
562 if (! isset($noexists_pattern)) {
563 if ($_symbol_noexists != '') {
564 $noexists_pattern = '#<span class="noexists">([^<]*)<a[^>]+>' .
565 preg_quote($_symbol_noexists, '#') . '</a></span>#';
567 $noexists_pattern = '';
570 if ($noexists_pattern != '') {
571 // Strip Dagnling-Link decoration (Tags and "$_symbol_noexists")
572 $str = preg_replace($noexists_pattern, '$1', $str);
575 // All other HTML tags
576 return preg_replace('#<[^>]+>#', '', $str);
578 // All other anchor-tags only
579 return preg_replace('#<a[^>]+>|</a>#i', '', $str);
583 // Remove AutoLink marker with AutLink itself
584 function strip_autolink($str)
586 return preg_replace('#<!--autolink--><a [^>]+>|</a><!--/autolink-->#', '', $str);
589 // Make a backlink. searching-link of the page name, by the page name, for the page name
590 function make_search($page)
592 $s_page = htmlsc($page);
593 $r_page = rawurlencode($page);
594 return '<a href="' . get_base_uri() . '?plugin=related&page=' . $r_page .
595 '">' . $s_page . '</a> ';
598 // Make heading string (remove heading-related decorations from Wiki text)
599 function make_heading(& $str, $strip = TRUE)
603 // Cut fixed-heading anchors
606 if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m', $str, $matches)) {
607 $str = $matches[2] . $matches[4];
610 $str = preg_replace('/^\*{0,3}/', '', $str);
613 // Cut footnotes and tags
615 $str = strip_htmltag(make_link(preg_replace($NotePattern, '', $str)));
620 // Separate a page-name(or URL or null string) and an anchor
621 // (last one standing) without sharp
622 function anchor_explode($page, $strict_editable = FALSE)
624 $pos = strrpos($page, '#');
625 if ($pos === FALSE) return array($page, '', FALSE);
627 // Ignore the last sharp letter
628 if ($pos + 1 == strlen($page)) {
629 $pos = strpos(substr($page, $pos + 1), '#');
630 if ($pos === FALSE) return array($page, '', FALSE);
633 $s_page = substr($page, 0, $pos);
634 $anchor = substr($page, $pos + 1);
636 if($strict_editable === TRUE && preg_match('/^[a-z][a-f0-9]{7}$/', $anchor)) {
637 return array ($s_page, $anchor, TRUE); // Seems fixed-anchor
639 return array ($s_page, $anchor, FALSE);
643 // Check HTTP header()s were sent already, or
644 // there're blank lines or something out of php blocks
645 function pkwk_headers_sent()
647 if (PKWK_OPTIMISE) return;
650 if (version_compare(PHP_VERSION, '4.3.0', '>=')) {
651 if (headers_sent($file, $line))
652 die('Headers already sent at ' .
654 ' line ' . $line . '.');
657 die('Headers already sent.');
661 // Output common HTTP headers
662 function pkwk_common_headers()
664 global $http_response_custom_headers;
665 if (! PKWK_OPTIMISE) pkwk_headers_sent();
666 foreach ($http_response_custom_headers as $header) {
669 if(defined('PKWK_ZLIB_LOADABLE_MODULE')) {
671 if(ini_get('zlib.output_compression') &&
672 preg_match('/\b(gzip|deflate)\b/i', $_SERVER['HTTP_ACCEPT_ENCODING'], $matches)) {
673 // Bug #29350 output_compression compresses everything _without header_ as loadable module
674 // http://bugs.php.net/bug.php?id=29350
675 header('Content-Encoding: ' . $matches[1]);
676 header('Vary: Accept-Encoding');
682 define('PKWK_DTD_XHTML_1_1', 17); // Strict only
683 define('PKWK_DTD_XHTML_1_0', 16); // Strict
684 define('PKWK_DTD_XHTML_1_0_STRICT', 16);
685 define('PKWK_DTD_XHTML_1_0_TRANSITIONAL', 15);
686 define('PKWK_DTD_XHTML_1_0_FRAMESET', 14);
687 define('PKWK_DTD_HTML_4_01', 3); // Strict
688 define('PKWK_DTD_HTML_4_01_STRICT', 3);
689 define('PKWK_DTD_HTML_4_01_TRANSITIONAL', 2);
690 define('PKWK_DTD_HTML_4_01_FRAMESET', 1);
692 define('PKWK_DTD_TYPE_XHTML', 1);
693 define('PKWK_DTD_TYPE_HTML', 0);
695 // Output HTML DTD, <html> start tag. Return content-type.
696 function pkwk_output_dtd($pkwk_dtd = PKWK_DTD_XHTML_1_1, $charset = CONTENT_CHARSET)
699 if (isset($called)) die('pkwk_output_dtd() already called. Why?');
702 $type = PKWK_DTD_TYPE_XHTML;
705 case PKWK_DTD_XHTML_1_1 :
707 $dtd = 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd';
709 case PKWK_DTD_XHTML_1_0_STRICT :
712 $dtd = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd';
714 case PKWK_DTD_XHTML_1_0_TRANSITIONAL:
716 $option = 'Transitional';
717 $dtd = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd';
720 case PKWK_DTD_HTML_4_01_STRICT :
721 $type = PKWK_DTD_TYPE_HTML;
723 $dtd = 'http://www.w3.org/TR/html4/strict.dtd';
725 case PKWK_DTD_HTML_4_01_TRANSITIONAL:
726 $type = PKWK_DTD_TYPE_HTML;
728 $option = 'Transitional';
729 $dtd = 'http://www.w3.org/TR/html4/loose.dtd';
732 default: die('DTD not specified or invalid DTD');
736 $charset = htmlsc($charset);
739 if ($type == PKWK_DTD_TYPE_XHTML) echo '<?xml version="1.0" encoding="' . $charset . '" ?>' . "\n";
742 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD ' .
743 ($type == PKWK_DTD_TYPE_XHTML ? 'XHTML' : 'HTML') . ' ' .
745 ($option != '' ? ' ' . $option : '') .
750 // Output <html> start tag
752 if ($type == PKWK_DTD_TYPE_XHTML) {
753 echo ' xmlns="http://www.w3.org/1999/xhtml"'; // dir="ltr" /* LeftToRight */
754 echo ' xml:lang="' . LANG . '"';
755 if ($version == '1.0') echo ' lang="' . LANG . '"'; // Only XHTML 1.0
757 echo ' lang="' . LANG . '"'; // HTML
759 echo '>' . "\n"; // <html>
761 // Return content-type (with MIME type)
762 if ($type == PKWK_DTD_TYPE_XHTML) {
763 // NOTE: XHTML 1.1 browser will ignore http-equiv
764 return '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . $charset . '" />' . "\n";
766 return '<meta http-equiv="content-type" content="text/html; charset=' . $charset . '" />' . "\n";
771 * Get template of List (ul, ol, dl) attributes
773 function pkwk_list_attrs_template() {
774 return ' class="list%d list-indent%d"';