aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/adjust_bbcodes.php
blob: 5a7f065d7f53c0938dc38a21aed370d88bdec405 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* Only adjust bitfields, do not rewrite text...
* All new parsings have the img, flash and quote modes set to true
*
* You should make a backup from your users, posts and privmsgs table in case something goes wrong
* Forum descriptions and rules need to be re-submitted manually.
*/
die("Please read the first lines of this script for instructions on how to enable it");

set_time_limit(0);

define('IN_PHPBB', true);
$phpbb_root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$echos = 0;

// Adjust user signatures
$message_parser = new parse_message();
$message_parser->mode = 'sig';
$message_parser->bbcode_init();

$sql = 'SELECT user_id, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield
	FROM ' . USERS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['user_sig_bbcode_uid'] && $row['user_sig'])
	{
		decode_message($row['user_sig'], $row['user_sig_bbcode_uid']);

		$message_parser->message = $row['user_sig'];

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . USERS_TABLE . " SET user_sig_bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE user_id = " . $row['user_id'];
		$db->sql_query($sql);

		if ($echos > 200)
		{
			echo '<br />' . "\n";
			$echos = 0;
		}

		echo '.';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . USERS_TABLE . " SET user_sig_bbcode_bitfield = ''
			WHERE user_id = " . $row['user_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);


// Now adjust posts

$message_parser = new parse_message();
$message_parser->mode = 'post';
$message_parser->bbcode_init();

// Update posts
$sql = 'SELECT post_id, post_text, bbcode_uid, enable_bbcode, enable_smilies, enable_sig
	FROM ' . POSTS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['enable_bbcode'])
	{
		decode_message($row['post_text'], $row['bbcode_uid']);

		$message_parser->message = $row['post_text'];

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . POSTS_TABLE . " SET bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE post_id = " . $row['post_id'];
		$db->sql_query($sql);

		if ($echos > 200)
		{
			echo '<br />' . "\n";
			$echos = 0;
		}

		echo '.';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . POSTS_TABLE . " SET bbcode_bitfield = ''
			WHERE post_id = " . $row['post_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);

// Now to the private messages
$message_parser = new parse_message();
$message_parser->mode = 'post';
$message_parser->bbcode_init();

// Update pms
$sql = 'SELECT msg_id, message_text, bbcode_uid, enable_bbcode
	FROM ' . PRIVMSGS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['enable_bbcode'])
	{
		decode_message($row['message_text'], $row['bbcode_uid']);

		$message_parser->message = $row['message_text'];

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE msg_id = " . $row['msg_id'];
		$db->sql_query($sql);

		if ($echos > 200)
		{
			echo '<br />' . "\n";
			$echos = 0;
		}

		echo '.';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET bbcode_bitfield = ''
			WHERE msg_id = " . $row['msg_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);

// Done
$db->sql_close();