source: branches/2.4/install/db/125-database.php @ 15934

Last change on this file since 15934 was 15608, checked in by plg, 12 years ago

feature 2632: derivatives: search and replace hotlinks inside Piwigo
(page_banner, covers also plugins Additional Pages and PWG Stuffs)

File size: 5.4 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$upgrade_description = 'derivatives: search and replace hotlinks inside Piwigo (page_banner';
30
31include_once(PHPWG_ROOT_PATH.'include/constants.php');
32
33if (!isset($conf['prefix_thumbnail']))
34{
35  $conf['prefix_thumbnail'] = 'TN-';
36}
37
38if (!isset($conf['dir_thumbnail']))
39{
40  $conf['dir_thumbnail'] = 'thumbnail';
41}
42
43$dbconf = array();
44$conf_orig = $conf;
45load_conf_from_db();
46$dbconf = $conf;
47$conf = $conf_orig;
48
49$banner_orig = $dbconf['page_banner'];
50$banner_new = replace_hotlinks($dbconf['page_banner']);
51if ($banner_orig != $banner_new)
52{
53  conf_update_param('page_banner', pwg_db_real_escape_string($banner_new));
54}
55
56//
57// Additional Pages
58//
59$is_plugin_installed = false;
60$plugin_table = $prefixeTable.'additionalpages';
61
62$query = 'SHOW TABLES LIKE \''.$plugin_table.'\';';
63$result = pwg_query($query);
64
65while ($row = pwg_db_fetch_row($result))
66{
67  if ($plugin_table == $row[0])
68  {
69    $is_plugin_installed = true;
70  }
71}
72
73if ($is_plugin_installed)
74{
75  $query = '
76SELECT
77    id,
78    content
79  FROM '.$plugin_table.'
80;';
81  $result = pwg_query($query);
82  while ($row = pwg_db_fetch_assoc($result))
83  {
84    $content_orig = $row['content'];
85    $content_new = replace_hotlinks($content_orig);
86    if ($content_orig != $content_new)
87    {
88      single_update(
89        $plugin_table,
90        array('content' => pwg_db_real_escape_string($content_new)),
91        array('id' => $row['id'])
92        );
93    }
94  }
95
96  $upgrade_description.= ', Additional Pages';
97}
98
99//
100// PWG Stuffs
101//
102$is_plugin_installed = false;
103$plugin_table = $prefixeTable.'stuffs';
104
105$query = 'SHOW TABLES LIKE \''.$plugin_table.'\';';
106$result = pwg_query($query);
107
108while ($row = pwg_db_fetch_row($result))
109{
110  if ($plugin_table == $row[0])
111  {
112    $is_plugin_installed = true;
113  }
114}
115
116if ($is_plugin_installed)
117{
118  $query = '
119SELECT
120    id,
121    datas
122  FROM '.$plugin_table.'
123  WHERE path LIKE \'%plugins/PWG_Stuffs/modules/Personal%\'
124;';
125  $result = pwg_query($query);
126  while ($row = pwg_db_fetch_assoc($result))
127  {
128    $content_orig = $row['datas'];
129    $content_new = serialize(replace_hotlinks(unserialize($content_orig)));
130    if ($content_orig != $content_new)
131    {
132      single_update(
133        $plugin_table,
134        array('datas' => pwg_db_real_escape_string($content_new)),
135        array('id' => $row['id'])
136        );
137    }
138  }
139 
140  $upgrade_description.= ', PWG Stuffs';
141}
142
143$upgrade_description.= ')';
144
145echo "\n".$upgrade_description."\n";
146
147// +-----------------------------------------------------------------------+
148// | Functions                                                             |
149// +-----------------------------------------------------------------------+
150
151function replace_hotlinks($string)
152{
153  global $conf;
154 
155  // websize 2.3 = medium 2.4
156  $string = preg_replace(
157    '#(upload/\d{4}/\d{2}/\d{2}/\d{14}-\w{8})(\.(jpg|png))#',
158    'i.php?/$1-me$2',
159    $string
160    );
161
162// I've tried but I didn't find the way to do it correctly
163// $string = preg_replace(
164//   '#(galleries/.*?/)(?!:(pwg_high|'.$conf['dir_thumbnail'].')/)([^/]*?)(\.[a-z0-9]{3,4})([\'"])#',
165//   'i.php?/(1=$1)(2=$2)-me(3=$3)(4=$4)', // 'i.php?/$1$2-me$3',
166//   $string
167//   );
168
169  // thumbnail 2.3 = th size 2.4
170  $string = preg_replace(
171    '#(upload/\d{4}/\d{2}/\d{2}/)'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].'(\d{14}-\w{8})(\.(jpg|png))#',
172    'i.php?/$1$2-th$3',
173    $string
174    );
175 
176  $string = preg_replace(
177    '#(galleries/.*?/)'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].'(.*?)(\.[a-z0-9]{3,4})([\'"])#',
178    'i.php?/$1$2-th$3$4',
179    $string
180    );
181 
182  // HD 2.3 = original 2.4
183  $string = preg_replace(
184    '#(upload/\d{4}/\d{2}/\d{2}/)pwg_high/(\d{14}-\w{8}\.(jpg|png))#',
185    '$1$2',
186    $string
187    );
188
189  $string = preg_replace(
190    '#(galleries/.*?)/pwg_high(/.*?\.[a-z0-9]{3,4})#',
191    '$1$2',
192    $string
193    );
194 
195  return $string;
196}
197?>
Note: See TracBrowser for help on using the repository browser.