[15124] | 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 | |
---|
[15127] | 31 | if (!isset($page['warnings'])) $page['warnings'] = array(); |
---|
[15126] | 32 | |
---|
[15124] | 33 | $upgrade_description = 'add/append htaccess for hotlinks'; |
---|
| 34 | $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>'; |
---|
| 35 | |
---|
| 36 | $htaccess = PHPWG_ROOT_PATH.'/.htaccess'; |
---|
| 37 | $writable = true; |
---|
| 38 | if (file_exists($htaccess)) |
---|
| 39 | { |
---|
| 40 | if (!is_readable($htaccess) || !is_writable($htaccess)) |
---|
| 41 | { |
---|
| 42 | $writable = false; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | else |
---|
| 46 | { |
---|
| 47 | $writable = is_writable(PHPWG_ROOT_PATH); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if (!$writable) |
---|
| 51 | { |
---|
| 52 | array_push($page['warnings'], $warning_message); |
---|
[15127] | 53 | $upgrade_description.= ': failed'; |
---|
[15124] | 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | $content = file_exists($htaccess) ? file_get_contents($htaccess) : null; |
---|
| 58 | if (strpos($content, 'RewriteEngine off') !== false) |
---|
| 59 | { |
---|
| 60 | array_push($page['warnings'], $warning_message); |
---|
[15127] | 61 | $upgrade_description.= ': failed'; |
---|
[15124] | 62 | } |
---|
| 63 | else |
---|
| 64 | { |
---|
[15178] | 65 | $content.= ' |
---|
| 66 | <IfModule mod_rewrite.c>'; |
---|
| 67 | |
---|
[15124] | 68 | if (strpos($content, 'RewriteEngine on') === false) |
---|
| 69 | { |
---|
| 70 | $content.=' |
---|
| 71 | RewriteEngine on'; |
---|
| 72 | } |
---|
| 73 | |
---|
[15128] | 74 | if (!isset($conf['prefix_thumbnail'])) |
---|
| 75 | { |
---|
| 76 | $conf['prefix_thumbnail'] = 'TN-'; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if (!isset($conf['dir_thumbnail'])) |
---|
| 80 | { |
---|
| 81 | $conf['dir_thumbnail'] = 'thumbnail'; |
---|
| 82 | } |
---|
| 83 | |
---|
[15124] | 84 | $content.= ' |
---|
| 85 | ## redirect <2.4 thumbnails hotlinks to i.php |
---|
| 86 | 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] |
---|
| 87 | 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] |
---|
| 88 | |
---|
| 89 | ## redirect <2.4 high-def hotlinks to original file |
---|
| 90 | RewriteRule ^upload/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ upload/$1/$2.$3 [L] |
---|
| 91 | RewriteRule ^galleries/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ galleries/$1/$2.$3 [L] |
---|
| 92 | |
---|
| 93 | ## redirect <2.4 low-def hotlinks to i.php |
---|
| 94 | RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC] |
---|
| 95 | RewriteRule ^upload/(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-me.$3 [L] |
---|
| 96 | RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC] |
---|
[15178] | 97 | RewriteRule ^galleries(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-me.$3 [L] |
---|
| 98 | </IfModule>'; |
---|
[15124] | 99 | |
---|
| 100 | file_put_contents($htaccess, $content); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | echo |
---|
| 106 | "\n" |
---|
| 107 | . $upgrade_description |
---|
| 108 | ."\n" |
---|
| 109 | ; |
---|
| 110 | ?> |
---|