OSDN Git Service

Merge branch 'master' into develop
[sie/sie.git] / tool / sie_php / sie.php
index b3f628c..3661dfa 100644 (file)
-<?php
-
-/**
- * sie.php
- *
- * 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
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * 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.
- *
- * @package     sie
- * @author      revulo <revulon@gmail.com>
- * @copyright   2008-2010 revulo
- * @license     http://www.opensource.org/licenses/mit-license.php  MIT License
- * @version     Release: 0.4
- * @link        http://www.revulo.com/SVG/SIE.html
- * @link        http://sie.sourceforge.jp/
- */
-
-// Filename of SIE JavaScript library.
-define('SIE_JS', 'sie.js');
-
-// 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' && $extension !== 'svgz') {
-    header('HTTP/1.1 403 Forbidden');
-    exit;
-}
-
-// Return a 404 status code if the SVG file is not found.
-if (is_readable($file) === false) {
-    header('HTTP/1.1 404 Not Found');
-    exit;
-}
-
-// If the request is an Ajax request, output the raw contents.
-if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
-    header('Content-Disposition: inline');
-    header('Content-Length: ' . filesize($file));
-    header('Content-Type: image/svg+xml');
-    readfile($file);
-    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($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 = preg_replace('/<script.*?\/script>/is', '', $data);
-
-// Get the absolute-path reference to the JavaScript file.
-$javascript = dirname($_SERVER['SCRIPT_NAME']) . '/' . SIE_JS;
-
-// Disable browser caching.
-header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');
-
-?>
-<html>
-<head>
-<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>
-</div>
-
-<script type="image/svg+xml" width="1000" height="1000">
-<?php echo $data ?>
-</script>
-<script type="text/javascript" src="<?php echo $javascript ?>"></script>
-
-</body>
-</html>
+<?php\r
+\r
+/**\r
+ * sie.php\r
+ *\r
+ * Copyright (c) 2008-2010 revulo\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\r
+ * IN THE SOFTWARE.\r
+ *\r
+ * @package     sie\r
+ * @author      revulo <revulon@gmail.com>\r
+ * @copyright   2008-2010 revulo\r
+ * @license     http://www.opensource.org/licenses/mit-license.php  MIT License\r
+ * @version     Release: 0.4\r
+ * @link        http://www.revulo.com/SVG/SIE.html\r
+ * @link        http://sie.sourceforge.jp/\r
+ */\r
+\r
+// Filename of SIE JavaScript library.\r
+define('SIE_JS', 'sie.js');\r
+\r
+// Get the requested URL.\r
+$url = $_SERVER['REQUEST_URI'];\r
+\r
+// Trim the query string from the URL.\r
+$pos = strrpos($url, '?');\r
+if ($pos !== false) {\r
+    $url = substr($url, 0, $pos);\r
+}\r
+\r
+// Get the path to the requested file.\r
+$file = rawurldecode($_SERVER['DOCUMENT_ROOT'] . $url);\r
+\r
+// Check the file extension.\r
+$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));\r
+if ($extension !== 'svg' && $extension !== 'svgz') {\r
+    header('HTTP/1.1 403 Forbidden');\r
+    exit;\r
+}\r
+\r
+// Return a 404 status code if the SVG file is not found.\r
+if (is_readable($file) === false) {\r
+    header('HTTP/1.1 404 Not Found');\r
+    exit;\r
+}\r
+\r
+// If the request is an Ajax request, output the raw contents.\r
+if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {\r
+    header('Content-Disposition: inline');\r
+    header('Content-Length: ' . filesize($file));\r
+    header('Content-Type: image/svg+xml');\r
+    readfile($file);\r
+    exit;\r
+}\r
+\r
+// If the requested URL contains a question mark, download the file.\r
+if ($pos !== false) {\r
+    header('Content-Type: application/octet-stream');\r
+    header('Content-Disposition: attachment');\r
+    header('Content-Length: ' . filesize($file));\r
+    readfile($file);\r
+    exit;\r
+}\r
+\r
+// Get the relative-path reference to the requested file.\r
+$url = basename($url);\r
+\r
+// Decode the file name.\r
+$name = rawurldecode($url);\r
+$name = mb_convert_encoding($name, 'UTF-8', 'auto');\r
+$name = htmlspecialchars($name);\r
+\r
+// Get uncompressed file contents.\r
+if ($extension === 'svgz') {\r
+    $data = file_get_contents('compress.zlib://' . $file); \r
+} else {\r
+    $data = file_get_contents($file);\r
+}\r
+\r
+// Strip <script> tags from the file contents.\r
+$data = preg_replace('/<script.*?\/script>/is', '', $data);\r
+\r
+// Get the absolute-path reference to the JavaScript file.\r
+$javascript = dirname($_SERVER['SCRIPT_NAME']) . '/' . SIE_JS;\r
+\r
+// Disable browser caching.\r
+header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');\r
+\r
+?>\r
+<html>\r
+<head>\r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
+</head>\r
+<body>\r
+\r
+<div style="color: #777; margin-bottom: 1em;">\r
+This is an image converted by <a href="http://sie.sourceforge.jp/">SIE</a>.<br />\r
+Original file: <a href="<?php echo $url ?>?" title="Download <?php echo $name ?>"><?php echo $name ?></a>\r
+</div>\r
+\r
+<script type="image/svg+xml" width="1000" height="1000">\r
+<?php echo $data ?>\r
+</script>\r
+<script type="text/javascript" src="<?php echo $javascript ?>"></script>\r
+\r
+</body>\r
+</html>\r