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

Revision 15126, 3.8 KB checked in by mistic100, 8 years ago (diff)

remove Warning when called from upgrade_feed.php, no consequence for upgrade.php

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['errors'])) $page['errors'] = 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}
54else
55{
56  $content = file_exists($htaccess) ? file_get_contents($htaccess) : null;
57  if (strpos($content, 'RewriteEngine off') !== false)
58  {
59    array_push($page['warnings'], $warning_message);
60  }
61  else
62  {
63    if (strpos($content, 'RewriteEngine on') === false)
64    {
65      $content.='
66RewriteEngine on';
67    }
68   
69    $content.= '
70## redirect <2.4 thumbnails hotlinks to i.php
71RewriteRule ^upload/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-th.$3 [L]
72RewriteRule ^galleries/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-th.$3 [L]
73
74## redirect <2.4 high-def hotlinks to original file
75RewriteRule ^upload/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ upload/$1/$2.$3 [L]
76RewriteRule ^galleries/(.*)/pwg_high/(.*)\.([a-z0-9]{3,4})$ galleries/$1/$2.$3 [L]
77
78## redirect <2.4 low-def hotlinks to i.php
79RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
80RewriteRule ^upload/(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/upload/$1/$2-me.$3 [L]
81RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
82RewriteRule ^galleries(.*)/(.*)\.([a-z0-9]{3,4})$ i.php?/galleries/$1/$2-me.$3 [L]';
83   
84    file_put_contents($htaccess, $content);
85  }
86}
87
88
89echo
90"\n"
91. $upgrade_description
92."\n"
93;
94?>
Note: See TracBrowser for help on using the repository browser.