[Sie-announce] SIEコード [2069] sie. phpをrevulo氏の作った0 . 4にアップデート

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2010年 10月 20日 (水) 19:29:03 JST


Revision: 2069
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2069
Author:   dhrname
Date:     2010-10-20 19:29:03 +0900 (Wed, 20 Oct 2010)

Log Message:
-----------
sie.phpをrevulo氏の作った0.4にアップデート

Modified Paths:
--------------
    trunk/sie_php/.htaccess
    trunk/sie_php/sie.php

Modified: trunk/sie_php/.htaccess
===================================================================
--- trunk/sie_php/.htaccess	2010-10-20 10:26:44 UTC (rev 2068)
+++ trunk/sie_php/.htaccess	2010-10-20 10:29:03 UTC (rev 2069)
@@ -1,5 +1,6 @@
+AddEncoding gzip svgz
+
 RewriteEngine on
-RewriteCond %{REQUEST_URI} \.svg$ [NC]
-RewriteCond %{HTTP_USER_AGENT} MSIE
-RewriteCond %{THE_REQUEST} !\?
-RewriteRule ^(.*)$ ./sie.php [L]
+RewriteCond %{REQUEST_URI} \.svgz?$ [NC]
+RewriteCond %{HTTP_USER_AGENT} MSIE\ [5-8]
+RewriteRule .* sie.php [L]

Modified: trunk/sie_php/sie.php
===================================================================
--- trunk/sie_php/sie.php	2010-10-20 10:26:44 UTC (rev 2068)
+++ trunk/sie_php/sie.php	2010-10-20 10:29:03 UTC (rev 2069)
@@ -3,13 +3,13 @@
 /**
  * sie.php
  *
- * Copyright (c) 2008 revulo
+ * Copyright (c) 2008-2010 revulo
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in
@@ -19,15 +19,15 @@
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
  *
  * @package     sie
  * @author      revulo <revul****@gmail*****>
- * @copyright   2008 revulo
+ * @copyright   2008-2010 revulo
  * @license     http://www.opensource.org/licenses/mit-license.php  MIT License
- * @version     Release: 0.3
+ * @version     Release: 0.4
  * @link        http://www.revulo.com/SVG/SIE.html
  * @link        http://sie.sourceforge.jp/
  */
@@ -35,12 +35,21 @@
 // Filename of SIE JavaScript library.
 define('SIE_JS', 'sie.js');
 
-// Get the path of the requested file.
-$file = rawurldecode($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI']);
+// Get the requested URL.
+$url = $_SERVER['REQUEST_URI'];
 
+// Trim the query string from the URL.
+$pos = strrpos($url, '?');
+if ($pos !== false) {
+    $url = substr($url, 0, $pos);
+}
+
+// Get the path to the requested file.
+$file = rawurldecode($_SERVER['DOCUMENT_ROOT'] . $url);
+
 // Check the file extension.
 $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
-if ($extension !== 'svg') {
+if ($extension !== 'svg' && $extension !== 'svgz') {
     header('HTTP/1.1 403 Forbidden');
     exit;
 }
@@ -60,16 +69,31 @@
     exit;
 }
 
+// If the requested URL contains a question mark, download the file.
+if ($pos !== false) {
+    header('Content-Type: application/octet-stream');
+    header('Content-Disposition: attachment');
+    header('Content-Length: ' . filesize($file));
+    readfile($file);
+    exit;
+}
+
 // Get the relative-path reference to the requested file.
-$url = basename($_SERVER['REQUEST_URI']);
+$url = basename($url);
 
 // Decode the file name.
 $name = rawurldecode($url);
 $name = mb_convert_encoding($name, 'UTF-8', 'auto');
 $name = htmlspecialchars($name);
 
+// Get uncompressed file contents.
+if ($extension === 'svgz') {
+    $data = file_get_contents('compress.zlib://' . $file); 
+} else {
+    $data = file_get_contents($file);
+}
+
 // Strip <script> tags from the file contents.
-$data = file_get_contents($file);
 $data = preg_replace('/<script.*?\/script>/is', '', $data);
 
 // Get the absolute-path reference to the JavaScript file.
@@ -84,6 +108,7 @@
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 </head>
 <body>
+
 <div style="color: #777; margin-bottom: 1em;">
 This is an image converted by <a href="http://sie.sourceforge.jp/">SIE</a>.<br />
 Original file: <a href="<?php echo $url ?>?" title="Download <?php echo $name ?>"><?php echo $name ?></a>
@@ -93,5 +118,6 @@
 <?php echo $data ?>
 </script>
 <script type="text/javascript" src="<?php echo $javascript ?>"></script>
+
 </body>
 </html>




Sie-announce メーリングリストの案内
アーカイブの一覧に戻る