source: trunk/install/db/121-database.php @ 15127

Last change on this file since 15127 was 15127, checked in by mistic100, 12 years ago

confusion in previous commit

File size: 3.8 KB
Line 
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
24if (!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
31if (!isset($page['warnings'])) $page['warnings'] = array();
32
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;
38if (file_exists($htaccess))
39{
40  if (!is_readable($htaccess) || !is_writable($htaccess))
41  {
42    $writable = false;
43  }
44}
45else
46{
47  $writable = is_writable(PHPWG_ROOT_PATH);
48}
49
50if (!$writable)
51{
52  array_push($page['warnings'], $warning_message);
53  $upgrade_description.= ': failed';
54}
55else
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);
61    $upgrade_description.= ': failed';
62  }
63  else
64  {
65    if (strpos($content, 'RewriteEngine on') === false)
66    {
67      $content.='
68RewriteEngine on';
69    }
70   
71    $content.= '
72## redirect <2.4 thumbnails hotlinks to i.php
73RewriteRule ^upload/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-th.$3 [L]
74RewriteRule ^galleries/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-th.$3 [L]
75
76## redirect <2.4 high-def hotlinks to original file
77RewriteRule ^upload/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ upload/$1/$2.$3 [L]
78RewriteRule ^galleries/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ galleries/$1/$2.$3 [L]
79
80## redirect <2.4 low-def hotlinks to i.php
81RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
82RewriteRule ^upload/(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-me.$3 [L]
83RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
84RewriteRule ^galleries(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-me.$3 [L]';
85   
86    file_put_contents($htaccess, $content);
87  }
88}
89
90
91echo
92"\n"
93. $upgrade_description
94."\n"
95;
96?>
Note: See TracBrowser for help on using the repository browser.