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