1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
25 | { |
---|
26 | die('Hacking attempt!'); |
---|
27 | } |
---|
28 | |
---|
29 | // see http://piwigo.org/doc/doku.php?id=user_documentation:htaccess_and_hotlink_in_2.4 |
---|
30 | |
---|
31 | $upgrade_description = 'add/append htaccess for hotlinks'; |
---|
32 | $warning_message = 'Failed to modify <b>.htaccess</b> file, a manual intervention is needed, <a href="http://piwigo.org/doc/doku.php?id=user_documentation:htaccess_and_hotlink_in_2.4" target="_blank">click here for more information</a>'; |
---|
33 | |
---|
34 | $htaccess = PHPWG_ROOT_PATH.'/.htaccess'; |
---|
35 | $writable = true; |
---|
36 | if (file_exists($htaccess)) |
---|
37 | { |
---|
38 | if (!is_readable($htaccess) || !is_writable($htaccess)) |
---|
39 | { |
---|
40 | $writable = false; |
---|
41 | } |
---|
42 | } |
---|
43 | else |
---|
44 | { |
---|
45 | $writable = is_writable(PHPWG_ROOT_PATH); |
---|
46 | } |
---|
47 | |
---|
48 | if (!$writable) |
---|
49 | { |
---|
50 | array_push($page['warnings'], $warning_message); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | $content = file_exists($htaccess) ? file_get_contents($htaccess) : null; |
---|
55 | if (strpos($content, 'RewriteEngine off') !== false) |
---|
56 | { |
---|
57 | array_push($page['warnings'], $warning_message); |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | if (strpos($content, 'RewriteEngine on') === false) |
---|
62 | { |
---|
63 | $content.=' |
---|
64 | RewriteEngine on'; |
---|
65 | } |
---|
66 | |
---|
67 | $content.= ' |
---|
68 | ## redirect <2.4 thumbnails hotlinks to i.php |
---|
69 | RewriteRule ^upload/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-th.$3 [L] |
---|
70 | RewriteRule ^galleries/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-th.$3 [L] |
---|
71 | |
---|
72 | ## redirect <2.4 high-def hotlinks to original file |
---|
73 | RewriteRule ^upload/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ upload/$1/$2.$3 [L] |
---|
74 | RewriteRule ^galleries/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ galleries/$1/$2.$3 [L] |
---|
75 | |
---|
76 | ## redirect <2.4 low-def hotlinks to i.php |
---|
77 | RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC] |
---|
78 | RewriteRule ^upload/(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-me.$3 [L] |
---|
79 | RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC] |
---|
80 | RewriteRule ^galleries(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-me.$3 [L]'; |
---|
81 | |
---|
82 | file_put_contents($htaccess, $content); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | echo |
---|
88 | "\n" |
---|
89 | . $upgrade_description |
---|
90 | ."\n" |
---|
91 | ; |
---|
92 | ?> |
---|