Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

migrate-sigs.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. function phorum_htmlpurifier_migrate_sigs_check()
  3. {
  4. global $PHORUM;
  5. $offset = 0;
  6. if (!empty($_POST['migrate-sigs'])) {
  7. if (!isset($_POST['confirmation']) || strtolower($_POST['confirmation']) !== 'yes') {
  8. echo 'Invalid confirmation code.';
  9. exit;
  10. }
  11. $PHORUM['mod_htmlpurifier']['migrate-sigs'] = true;
  12. phorum_db_update_settings(array("mod_htmlpurifier"=>$PHORUM["mod_htmlpurifier"]));
  13. $offset = 1;
  14. } elseif (!empty($_GET['migrate-sigs']) && $PHORUM['mod_htmlpurifier']['migrate-sigs']) {
  15. $offset = (int) $_GET['migrate-sigs'];
  16. }
  17. return $offset;
  18. }
  19. function phorum_htmlpurifier_migrate_sigs($offset)
  20. {
  21. global $PHORUM;
  22. if(!$offset) return; // bail out quick if $offset == 0
  23. // theoretically, we could get rid of this multi-request
  24. // doo-hickery if safe mode is off
  25. @set_time_limit(0); // attempt to let this run
  26. $increment = $PHORUM['mod_htmlpurifier']['migrate-sigs-increment'];
  27. require_once(dirname(__FILE__) . '/../migrate.php');
  28. // migrate signatures
  29. // do this in batches so we don't run out of time/space
  30. $end = $offset + $increment;
  31. $user_ids = array();
  32. for ($i = $offset; $i < $end; $i++) {
  33. $user_ids[] = $i;
  34. }
  35. $userinfos = phorum_db_user_get_fields($user_ids, 'signature');
  36. foreach ($userinfos as $i => $user) {
  37. if (empty($user['signature'])) continue;
  38. $sig = $user['signature'];
  39. // perform standard Phorum processing on the sig
  40. $sig = str_replace(array("&","<",">"), array("&amp;","&lt;","&gt;"), $sig);
  41. $sig = preg_replace("/<((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%]+?)>/i", "$1", $sig);
  42. // prepare fake data to pass to migration function
  43. $fake_data = array(array("author"=>"", "email"=>"", "subject"=>"", 'body' => $sig));
  44. list($fake_message) = phorum_htmlpurifier_migrate($fake_data);
  45. $user['signature'] = $fake_message['body'];
  46. if (!phorum_api_user_save($user)) {
  47. exit('Error while saving user data');
  48. }
  49. }
  50. unset($userinfos); // free up memory
  51. // query for highest ID in database
  52. $type = $PHORUM['DBCONFIG']['type'];
  53. $sql = "select MAX(user_id) from {$PHORUM['user_table']}";
  54. $row = phorum_db_interact(DB_RETURN_ROW, $sql);
  55. $top_id = (int) $row[0];
  56. $offset += $increment;
  57. if ($offset > $top_id) { // test for end condition
  58. echo 'Migration finished';
  59. $PHORUM['mod_htmlpurifier']['migrate-sigs'] = false;
  60. phorum_htmlpurifier_commit_settings();
  61. return true;
  62. }
  63. $host = $_SERVER['HTTP_HOST'];
  64. $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
  65. $extra = 'admin.php?module=modsettings&mod=htmlpurifier&migrate-sigs=' . $offset;
  66. // relies on output buffering to work
  67. header("Location: http://$host$uri/$extra");
  68. exit;
  69. }
  70. // vim: et sw=4 sts=4