OSDN Git Service

Added pkwk_common_headers()
[pukiwiki/pukiwiki.git] / lib / html.php
index 42856c0..c01995c 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: html.php,v 1.11 2004/11/02 13:45:37 henoheno Exp $
+// $Id: html.php,v 1.20 2004/12/25 00:38:21 henoheno Exp $
 //
 
 // ËÜʸ¤ò½ÐÎÏ
@@ -43,12 +43,14 @@ function catbody($title,$page,$body)
        $_LINK['help']     = "$script?" . rawurlencode($help_page);
        $_LINK['list']     = "$script?cmd=list";
        $_LINK['new']      = "$script?plugin=newpage&refer=$r_page";
-       $_LINK['rdf']      = "$script?cmd=rss10";
+       $_LINK['rdf']      = "$script?cmd=rss&ver=1.0";
        $_LINK['recent']   = "$script?" . rawurlencode($whatsnew);
        $_LINK['refer']    = "$script?plugin=referer&page=$r_page";
        $_LINK['reload']   = "$script?$r_page";
        $_LINK['rename']   = "$script?plugin=rename&refer=$r_page";
        $_LINK['rss']      = "$script?cmd=rss";
+       $_LINK['rss10']    = "$script?cmd=rss&ver=1.0"; // Same as 'rdf'
+       $_LINK['rss20']    = "$script?cmd=rss&ver=2.0";
        $_LINK['search']   = "$script?cmd=search";
        $_LINK['top']      = "$script?" . rawurlencode($defaultpage);
        if ($trackback) {
@@ -73,6 +75,8 @@ function catbody($title,$page,$body)
        $link_trackback = & $_LINK['trackback'];        // New!
        $link_rdf       = & $_LINK['rdf'];              // New!
        $link_rss       = & $_LINK['rss'];
+       $link_rss10     = & $_LINK['rss10'];            // New!
+       $link_rss20     = & $_LINK['rss20'];            // New!
        $link_freeze    = & $_LINK['freeze'];
        $link_unfreeze  = & $_LINK['unfreeze'];
        $link_upload    = & $_LINK['upload'];
@@ -328,13 +332,14 @@ function make_search($page)
        return "<a href=\"$script?cmd=search&amp;word=$r_page\">$s_page</a> ";
 }
 
-// ¸«½Ð¤·¤òÀ¸À® (Ãí¼á¤äHTML¥¿¥°¤ò½üµî)
+// ¸«½Ð¤·¤òÀ¸À® (µÓÃí¤äHTML¥¿¥°¤ò½üµî)
 function make_heading(& $str, $strip = TRUE)
 {
        global $NotePattern;
 
-       // ¸«½Ð¤·¤Î¸ÇÍ­IDÉô¤òºï½ü
+       // Cut fixed-anchors
        $id = '';
+       $matches = array();
        if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m', $str, $matches)) {
                $str = $matches[2] . $matches[4];
                $id  = $matches[3];
@@ -342,9 +347,60 @@ function make_heading(& $str, $strip = TRUE)
                $str = preg_replace('/^\*{0,3}/', '', $str);
        }
 
+       // Cut footnotes and tags
        if ($strip === TRUE)
                $str = strip_htmltag(make_link(preg_replace($NotePattern, '', $str)));
 
        return $id;
 }
+
+// Separate a page-name(or URL or null string) and an anchor
+// (last one standing) without sharp
+function anchor_explode($page, $strict_editable = FALSE)
+{
+       $pos = strrpos($page, '#');
+       if ($pos === FALSE) return array($page, '', FALSE);
+
+       // Ignore the last sharp letter
+       if ($pos + 1 == strlen($page)) {
+               $pos = strpos(substr($page, $pos + 1), '#');
+               if ($pos === FALSE) return array($page, '', FALSE);
+       }
+
+       $s_page = substr($page, 0, $pos);
+       $anchor = substr($page, $pos + 1);
+
+       if($strict_editable === TRUE &&  preg_match('/^[a-z][a-f0-9]{7}$/', $anchor)) {
+               return array ($s_page, $anchor, TRUE); // Seems fixed-anchor
+       } else {
+               return array ($s_page, $anchor, FALSE);
+       }
+}
+
+// Check header()s were sent already, or
+// there're blank lines or something out of php blocks
+function pkwk_headers_sent()
+{
+       if (version_compare(PHP_VERSION, '4.3.0', '>=')) {
+               if (headers_sent($file, $line))
+                   die('Headers already sent at ' .
+                       htmlspecialchars($file) .
+                       ' line ' . $line . '.');
+       } else {
+               if (headers_sent())
+                       die('Headers already sent.');
+       }
+}
+
+function pkwk_common_headers()
+{
+       if (! PKWK_OPTIMISE) pkwk_headers_sent();
+
+       $matches = array();
+       if(ini_get('zlib.output_compression') &&
+           preg_match('/\b(gzip|deflate)\b/i', $_SERVER['HTTP_ACCEPT_ENCODING'], $matches)) {
+               header('Content-Encoding: ' . $matches[1]);
+               header('Vary: Accept-Encoding');
+       }
+}
 ?>