]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - view.php
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / view.php
1 <?php
2 /*
3  * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
4  *
5  * This file is part of PhpWiki.
6  *
7  * PhpWiki is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * PhpWiki is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 /*
23  * Standard Alcatel-Lucent disclaimer for contributing to open source
24  *
25  * "The Configuration File ("Contribution") has not been tested and/or
26  * validated for release as or in products, combinations with products or
27  * other commercial use. Any use of the Contribution is entirely made at
28  * the user's own responsibility and the user can not rely on any features,
29  * functionalities or performances Alcatel-Lucent has attributed to the
30  * Contribution.
31  *
32  * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
33  * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
34  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
35  * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
36  * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
37  * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
38  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39  * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
40  * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
41  * ALONE BASIS."
42  */
43
44 $no_gz_buffer = true;
45
46 require_once '../../env.inc.php';
47 require_once $gfcommon . 'include/pre.php';
48
49 $sysdebug_enable = false;
50
51 if (isset($group_id) && $group_id) {
52     if (!isset($project) || !$project) {
53         $project = group_get_object($group_id);
54     }
55 } elseif (isset($project) && is_object($project)) {
56     $group_id = $project->getID();
57 }
58
59 if (!isset($group_id) || !isset($project)) {
60     exit_no_group();
61 } elseif (!($project->usesPlugin("wiki"))) {
62     exit_disabled('home');
63 }
64
65 // If project is private, check membership.
66 if (!$project->isPublic()) {
67     session_require_perm('project_read', $project->getID());
68 }
69
70 $arr = explode('/', urldecode(getStringFromServer('REQUEST_URI')));
71 array_shift($arr);
72 array_shift($arr);
73 array_shift($arr);
74 array_shift($arr);
75 array_shift($arr);
76 $path = join('/', $arr);
77
78 $basepath = realpath(forge_get_config('groupdir_prefix') .'/'. $project->getUnixName() . '/www/uploads/');
79 $filepath = realpath($basepath . '/' . $path);
80 $filename = basename($filepath);
81
82 if (strncmp($basepath, $filepath, strlen($basepath)) !== 0) {
83     error_log("DEBUG: basepath=$basepath, filepath=$filepath");
84     exit_error('Invalid path: No access');
85 }
86
87 if ($filepath && is_file($filepath)) {
88     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
89         # workaround for IE filename bug with multiple periods/ multiple dots in filename
90         # that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
91         $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
92     }
93     $filename = str_replace('"', '', $filename);
94     header('Content-disposition: filename="' . $filename . '"');
95
96     if (function_exists('finfo_open')) {
97         $finfo = finfo_open(FILEINFO_MIME_TYPE);
98         $mimetype = finfo_file($finfo, $filepath);
99     } else {
100         $mimetype = 'application/octet-stream';
101     }
102     header("Content-type: $mimetype");
103
104     $length = filesize($filepath);
105     header("Content-length: $length");
106
107     readfile_chunked($filepath);
108
109 } else {
110     header("HTTP/1.0 404 Not Found");
111     require_once $gfwww . '404.php';
112 }
113
114 // Local Variables:
115 // mode: php
116 // c-file-style: "bsd"
117 // End: