index.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. function conversionError($err)
  23. {
  24. buffer::str('<p>'.__('Error(s)').' : '.$err.'</p>');
  25. }
  26. $dc_ini_file = dirname(__FILE__).'/../../../conf/dotclear.ini';
  27. $err = '';
  28. buffer::str(
  29. '<h2>'.__('UTF-8 conversion').'</h2>'
  30. );
  31. $step = (!empty($_GET['step'])) ? $_GET['step'] : 1;
  32. if (!is_writable($dc_ini_file))
  33. {
  34. buffer::str(
  35. '<p>'.sprintf(__('Config file %s, is not writable.'),'<strong>conf/dotclear.ini</strong>').'</p>'
  36. );
  37. }
  38. elseif (dc_encoding == 'UTF-8' && $step != 7)
  39. {
  40. buffer::str(
  41. '<p>'.__('Your blog is still in UTF-8.').'</p>'
  42. );
  43. }
  44. else
  45. {
  46. if ($step == 1)
  47. {
  48. buffer::str(
  49. '<h3>'.__('Please read carrefully').'</h3>'.
  50. '<p>'.__('If you still did the conversion, don\'t do it again.').'</p>'.
  51. '<p><strong>'.__('BACKUP YOUR DATABASE ! That\'s not an advise, that\'s an order ;-)').'</strong></p>'.
  52. '<p><a href="tools.php?p=utf8convert&amp;step=2">'.__('Next step').'</a></p>'
  53. );
  54. }
  55. elseif ($step == 2)
  56. {
  57. buffer::str(
  58. '<h3>'.__('Converting entries').'</h3>'
  59. );
  60. $strReq = 'SELECT post_id, user_id, post_titre, post_chapo, post_chapo_wiki, '.
  61. 'post_content, post_content_wiki, post_notes '.
  62. 'FROM '.DB_PREFIX.'post ';
  63. $rs = $con->select($strReq);
  64. while (!$rs->EOF())
  65. {
  66. $updReq = 'UPDATE '.DB_PREFIX.'post SET '.
  67. 'user_id = \''.$con->escapeStr(util::latin1utf8($rs->f('user_id'))).'\', '.
  68. 'post_titre = \''.$con->escapeStr(util::latin1utf8($rs->f('post_titre'))).'\', '.
  69. 'post_chapo = \''.$con->escapeStr(util::latin1utf8($rs->f('post_chapo'))).'\', '.
  70. 'post_chapo_wiki = \''.$con->escapeStr(util::latin1utf8($rs->f('post_chapo_wiki'))).'\', '.
  71. 'post_content = \''.$con->escapeStr(util::latin1utf8($rs->f('post_content'))).'\', '.
  72. 'post_content_wiki = \''.$con->escapeStr(util::latin1utf8($rs->f('post_content_wiki'))).'\', '.
  73. 'post_notes = \''.$con->escapeStr(util::latin1utf8($rs->f('post_notes'))).'\' '.
  74. 'WHERE post_id = '.$rs->f('post_id').' ';
  75. if ($con->execute($updReq) === false) {
  76. $err = $con->error();
  77. break(1);
  78. }
  79. $rs->moveNext();
  80. }
  81. if ($err != '') {
  82. conversionError($err);
  83. } else {
  84. buffer::str(
  85. '<p>'.__('Entries successfully converted.').'</p>'.
  86. '<p><a href="tools.php?p=utf8convert&amp;step=3">'.__('Next step').'</a></p>'
  87. );
  88. }
  89. }
  90. elseif ($step == 3)
  91. {
  92. buffer::str(
  93. '<h3>'.__('Converting categories').'</h3>'
  94. );
  95. $strReq = 'SELECT cat_id, cat_libelle, cat_desc '.
  96. 'FROM '.DB_PREFIX.'categorie ';
  97. $rs = $con->select($strReq);
  98. while (!$rs->EOF())
  99. {
  100. $updReq = 'UPDATE '.DB_PREFIX.'categorie SET '.
  101. 'cat_libelle = \''.$con->escapeStr(util::latin1utf8($rs->f('cat_libelle'))).'\', '.
  102. 'cat_desc = \''.$con->escapeStr(util::latin1utf8($rs->f('cat_desc'))).'\' '.
  103. 'WHERE cat_id = '.$rs->f('cat_id').' ';
  104. if ($con->execute($updReq) === false) {
  105. $err = $con->error();
  106. break(1);
  107. }
  108. $rs->moveNext();
  109. }
  110. if ($err != '') {
  111. conversionError($err);
  112. } else {
  113. buffer::str(
  114. '<p>'.__('Categories successfully converted.').'</p>'.
  115. '<p><a href="tools.php?p=utf8convert&amp;step=4">'.__('Next step').'</a></p>'
  116. );
  117. }
  118. }
  119. elseif ($step == 4)
  120. {
  121. buffer::str(
  122. '<h3>'.__('Converting comments').'</h3>'
  123. );
  124. $strReq = 'SELECT comment_id, comment_auteur, comment_email, comment_site, '.
  125. 'comment_content '.
  126. 'FROM '.DB_PREFIX.'comment';
  127. $rs = $con->select($strReq);
  128. while (!$rs->EOF())
  129. {
  130. $updReq = 'UPDATE '.DB_PREFIX.'comment SET '.
  131. 'comment_auteur = \''.$con->escapeStr(util::latin1utf8($rs->f('comment_auteur'))).'\', '.
  132. 'comment_email = \''.$con->escapeStr(util::latin1utf8($rs->f('comment_email'))).'\', '.
  133. 'comment_site = \''.$con->escapeStr(util::latin1utf8($rs->f('comment_site'))).'\', '.
  134. 'comment_content = \''.$con->escapeStr(util::latin1utf8($rs->f('comment_content'))).'\' '.
  135. 'WHERE comment_id = '.$rs->f('comment_id').' ';
  136. if ($con->execute($updReq) === false) {
  137. $err = $con->error();
  138. break(1);
  139. }
  140. $rs->moveNext();
  141. }
  142. if ($err != '') {
  143. conversionError($err);
  144. } else {
  145. buffer::str(
  146. '<p>'.__('Comments successfully converted.').'</p>'.
  147. '<p><a href="tools.php?p=utf8convert&amp;step=5">'.__('Next step').'</a></p>'
  148. );
  149. }
  150. }
  151. elseif ($step == 5)
  152. {
  153. buffer::str(
  154. '<h3>'.__('Converting users').'</h3>'
  155. );
  156. $strReq = 'SELECT user_id, user_nom, user_prenom, user_pseudo, '.
  157. 'user_email '.
  158. 'FROM '.DB_PREFIX.'user ';
  159. $rs = $con->select($strReq);
  160. while (!$rs->EOF())
  161. {
  162. $updReq = 'UPDATE '.DB_PREFIX.'user SET '.
  163. 'user_id = \''.$con->escapeStr(util::latin1utf8($rs->f('user_id'))).'\', '.
  164. 'user_nom = \''.$con->escapeStr(util::latin1utf8($rs->f('user_nom'))).'\', '.
  165. 'user_prenom = \''.$con->escapeStr(util::latin1utf8($rs->f('user_prenom'))).'\', '.
  166. 'user_pseudo = \''.$con->escapeStr(util::latin1utf8($rs->f('user_pseudo'))).'\', '.
  167. 'user_email = \''.$con->escapeStr(util::latin1utf8($rs->f('user_email'))).'\' '.
  168. 'WHERE user_id = \''.$con->escapeStr($rs->f('user_id')).'\' ';
  169. if ($con->execute($updReq) === false) {
  170. $err = $con->error();
  171. break(1);
  172. }
  173. $rs->moveNext();
  174. }
  175. if ($err != '') {
  176. conversionError($err);
  177. } else {
  178. buffer::str(
  179. '<p>'.__('Users successfully converted.').'</p>'.
  180. '<p><a href="tools.php?p=utf8convert&amp;step=6">'.__('Next step').'</a></p>'
  181. );
  182. }
  183. }
  184. elseif ($step == 6)
  185. {
  186. buffer::str(
  187. '<h3>'.__('Converting links').'</h3>'
  188. );
  189. $strReq = 'SELECT link_id, label, title '.
  190. 'FROM '.DB_PREFIX.'link ';
  191. $rs = $con->select($strReq);
  192. while (!$rs->EOF())
  193. {
  194. $updReq = 'UPDATE '.DB_PREFIX.'link SET '.
  195. 'label = \''.$con->escapeStr(util::latin1utf8($rs->f('label'))).'\', '.
  196. 'title = \''.$con->escapeStr(util::latin1utf8($rs->f('title'))).'\' '.
  197. 'WHERE link_id = '.$con->escapeStr($rs->f('link_id')).' ';
  198. if ($con->execute($updReq) === false) {
  199. $err = $con->error();
  200. break(1);
  201. }
  202. $rs->moveNext();
  203. }
  204. if ($err != '') {
  205. conversionError($err);
  206. } else {
  207. buffer::str(
  208. '<p>'.__('Links successfully converted.').'</p>'.
  209. '<p><a href="tools.php?p=utf8convert&amp;step=7">'.__('Next step').'</a></p>'
  210. );
  211. }
  212. }
  213. elseif ($step == 7)
  214. {
  215. # Ecriture du dotclear.ini
  216. $objIni = new iniFile($dc_ini_file);
  217. $objIni->editVar('dc_encoding','UTF-8');
  218. $objIni->saveFile();
  219. buffer::str(
  220. '<p>'.__('UTF-8 conversion of your blog is finished.').'</p>'
  221. );
  222. }
  223. }
  224. ?>