6 * Copyright (c) 2008-2010 revulo
\r
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
9 * of this software and associated documentation files (the "Software"), to
\r
10 * deal in the Software without restriction, including without limitation the
\r
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
\r
12 * sell copies of the Software, and to permit persons to whom the Software is
\r
13 * furnished to do so, subject to the following conditions:
\r
15 * The above copyright notice and this permission notice shall be included in
\r
16 * all copies or substantial portions of the Software.
\r
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
\r
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
\r
27 * @author revulo <revulon@gmail.com>
\r
28 * @copyright 2008-2010 revulo
\r
29 * @license http://www.opensource.org/licenses/mit-license.php MIT License
\r
30 * @version Release: 0.4
\r
31 * @link http://www.revulo.com/SVG/SIE.html
\r
32 * @link http://sie.sourceforge.jp/
\r
35 // Filename of SIE JavaScript library.
\r
36 define('SIE_JS', 'sie.js');
\r
38 // Get the requested URL.
\r
39 $url = $_SERVER['REQUEST_URI'];
\r
41 // Trim the query string from the URL.
\r
42 $pos = strrpos($url, '?');
\r
43 if ($pos !== false) {
\r
44 $url = substr($url, 0, $pos);
\r
47 // Get the path to the requested file.
\r
48 $file = rawurldecode($_SERVER['DOCUMENT_ROOT'] . $url);
\r
50 // Check the file extension.
\r
51 $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
\r
52 if ($extension !== 'svg' && $extension !== 'svgz') {
\r
53 header('HTTP/1.1 403 Forbidden');
\r
57 // Return a 404 status code if the SVG file is not found.
\r
58 if (is_readable($file) === false) {
\r
59 header('HTTP/1.1 404 Not Found');
\r
63 // If the request is an Ajax request, output the raw contents.
\r
64 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
\r
65 header('Content-Disposition: inline');
\r
66 header('Content-Length: ' . filesize($file));
\r
67 header('Content-Type: image/svg+xml');
\r
72 // If the requested URL contains a question mark, download the file.
\r
73 if ($pos !== false) {
\r
74 header('Content-Type: application/octet-stream');
\r
75 header('Content-Disposition: attachment');
\r
76 header('Content-Length: ' . filesize($file));
\r
81 // Get the relative-path reference to the requested file.
\r
82 $url = basename($url);
\r
84 // Decode the file name.
\r
85 $name = rawurldecode($url);
\r
86 $name = mb_convert_encoding($name, 'UTF-8', 'auto');
\r
87 $name = htmlspecialchars($name);
\r
89 // Get uncompressed file contents.
\r
90 if ($extension === 'svgz') {
\r
91 $data = file_get_contents('compress.zlib://' . $file);
\r
93 $data = file_get_contents($file);
\r
96 // Strip <script> tags from the file contents.
\r
97 $data = preg_replace('/<script.*?\/script>/is', '', $data);
\r
99 // Get the absolute-path reference to the JavaScript file.
\r
100 $javascript = dirname($_SERVER['SCRIPT_NAME']) . '/' . SIE_JS;
\r
102 // Disable browser caching.
\r
103 header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');
\r
108 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\r
112 <div style="color: #777; margin-bottom: 1em;">
\r
113 This is an image converted by <a href="http://sie.sourceforge.jp/">SIE</a>.<br />
\r
114 Original file: <a href="<?php echo $url ?>?" title="Download <?php echo $name ?>"><?php echo $name ?></a>
\r
117 <script type="image/svg+xml" width="1000" height="1000">
\r
118 <?php echo $data ?>
\r
120 <script type="text/javascript" src="<?php echo $javascript ?>"></script>
\r