From 32ca509d17335c9b080a210f7808ebe573c3b2c7 Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 8 Jun 2012 21:42:37 +0000 Subject: feature 2632: derivatives: search and replace hotlinks inside Piwigo (page_banner, covers also plugins Additional Pages and PWG Stuffs) git-svn-id: http://piwigo.org/svn/trunk@15608 68402e56-0260-453c-a942-63ccdbb3a9ee --- install/db/125-database.php | 197 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 install/db/125-database.php diff --git a/install/db/125-database.php b/install/db/125-database.php new file mode 100644 index 000000000..e26204cef --- /dev/null +++ b/install/db/125-database.php @@ -0,0 +1,197 @@ + pwg_db_real_escape_string($content_new)), + array('id' => $row['id']) + ); + } + } + + $upgrade_description.= ', Additional Pages'; +} + +// +// PWG Stuffs +// +$is_plugin_installed = false; +$plugin_table = $prefixeTable.'stuffs'; + +$query = 'SHOW TABLES LIKE \''.$plugin_table.'\';'; +$result = pwg_query($query); + +while ($row = pwg_db_fetch_row($result)) +{ + if ($plugin_table == $row[0]) + { + $is_plugin_installed = true; + } +} + +if ($is_plugin_installed) +{ + $query = ' +SELECT + id, + datas + FROM '.$plugin_table.' + WHERE path LIKE \'%plugins/PWG_Stuffs/modules/Personal%\' +;'; + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + $content_orig = $row['datas']; + $content_new = serialize(replace_hotlinks(unserialize($content_orig))); + if ($content_orig != $content_new) + { + single_update( + $plugin_table, + array('datas' => pwg_db_real_escape_string($content_new)), + array('id' => $row['id']) + ); + } + } + + $upgrade_description.= ', PWG Stuffs'; +} + +$upgrade_description.= ')'; + +echo "\n".$upgrade_description."\n"; + +// +-----------------------------------------------------------------------+ +// | Functions | +// +-----------------------------------------------------------------------+ + +function replace_hotlinks($string) +{ + global $conf; + + // websize 2.3 = medium 2.4 + $string = preg_replace( + '#(upload/\d{4}/\d{2}/\d{2}/\d{14}-\w{8})(\.(jpg|png))#', + 'i.php?/$1-me$2', + $string + ); + +// I've tried but I didn't find the way to do it correctly +// $string = preg_replace( +// '#(galleries/.*?/)(?!:(pwg_high|'.$conf['dir_thumbnail'].')/)([^/]*?)(\.[a-z0-9]{3,4})([\'"])#', +// 'i.php?/(1=$1)(2=$2)-me(3=$3)(4=$4)', // 'i.php?/$1$2-me$3', +// $string +// ); + + // thumbnail 2.3 = th size 2.4 + $string = preg_replace( + '#(upload/\d{4}/\d{2}/\d{2}/)'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].'(\d{14}-\w{8})(\.(jpg|png))#', + 'i.php?/$1$2-th$3', + $string + ); + + $string = preg_replace( + '#(galleries/.*?/)'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].'(.*?)(\.[a-z0-9]{3,4})([\'"])#', + 'i.php?/$1$2-th$3$4', + $string + ); + + // HD 2.3 = original 2.4 + $string = preg_replace( + '#(upload/\d{4}/\d{2}/\d{2}/)pwg_high/(\d{14}-\w{8}\.(jpg|png))#', + '$1$2', + $string + ); + + $string = preg_replace( + '#(galleries/.*?)/pwg_high(/.*?\.[a-z0-9]{3,4})#', + '$1$2', + $string + ); + + return $string; +} +?> \ No newline at end of file -- cgit v1.2.3