phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / develop / adjust_sizes.php

History | View | Annotate | Download (3.3 kB)

1
<?php
2
/**
3
* Only adjust the [size] bbcode tag from pc to percent.
4
*
5
* You should make a backup from your users, posts and privmsgs table in case something goes wrong
6
* Forum descriptions and rules need to be re-submitted manually if they use the [size] tag.
7
*
8
* Since we limit the match to the sizes from 0 to 29 no newly applied sizes should be affected...
9
*/
10
die("Please read the first lines of this script for instructions on how to enable it");
11
12
set_time_limit(0);
13
@ini_set('memory_limit', '128M');
14
15
define('IN_PHPBB', true);
16
$phpbb_root_path = './../';
17
$phpEx = substr(strrchr(__FILE__, '.'), 1);
18
include($phpbb_root_path . 'common.'.$phpEx);
19
20
// Start session management
21
$user->session_begin();
22
$auth->acl($user->data);
23
$user->setup();
24
25
$echos = 0;
26
27
function replace_size($matches)
28
{
29
        return '[size=' . ceil(100.0 * (((double) $matches[1])/12.0)) . ':' . $matches[2] . ']';
30
}
31
32
// Adjust user signatures
33
$sql = 'SELECT user_id, user_sig, user_sig_bbcode_uid
34
        FROM ' . USERS_TABLE;
35
$result = $db->sql_query($sql);
36
37
while ($row = $db->sql_fetchrow($result))
38
{
39
        $bbcode_uid = $row['user_sig_bbcode_uid'];
40
41
        // Only if a bbcode uid is present, the signature present and a size tag used...
42
        if ($bbcode_uid && $row['user_sig'] && strpos($row['user_sig'], '[size=') !== false)
43
        {
44
                $row['user_sig'] = preg_replace_callback('/\[size=(\d*):(' . $bbcode_uid . ')\]/', 'replace_size', $row['user_sig']);
45
46
                $sql = 'UPDATE ' . USERS_TABLE . " SET user_sig = '" . $db->sql_escape($row['user_sig']) . "'
47
                        WHERE user_id = " . $row['user_id'];
48
                $db->sql_query($sql);
49
50
                if ($echos > 200)
51
                {
52
                        echo '<br />' . "\n";
53
                        $echos = 0;
54
                }
55
56
                echo '.';
57
                $echos++;
58
59
                flush();
60
        }
61
}
62
$db->sql_freeresult($result);
63
64
65
// Now adjust posts
66
$sql = 'SELECT post_id, post_text, bbcode_uid, enable_bbcode
67
        FROM ' . POSTS_TABLE;
68
$result = $db->sql_query($sql);
69
70
while ($row = $db->sql_fetchrow($result))
71
{
72
        $bbcode_uid = $row['bbcode_uid'];
73
74
        // Only if a bbcode uid is present, bbcode enabled and a size tag used...
75
        if ($row['enable_bbcode'] && $bbcode_uid && strpos($row['post_text'], '[size=') !== false)
76
        {
77
                $row['post_text'] = preg_replace_callback('/\[size=(\d*):' . $bbcode_uid . '\]/', 'replace_size', $row['post_text']);
78
79
                $sql = 'UPDATE ' . POSTS_TABLE . " SET post_text = '" . $db->sql_escape($row['post_text']) . "'
80
                        WHERE post_id = " . $row['post_id'];
81
                $db->sql_query($sql);
82
83
                if ($echos > 200)
84
                {
85
                        echo '<br />' . "\n";
86
                        $echos = 0;
87
                }
88
89
                echo '.';
90
                $echos++;
91
92
                flush();
93
        }
94
}
95
$db->sql_freeresult($result);
96
97
// Now to the private messages
98
$sql = 'SELECT msg_id, message_text, bbcode_uid, enable_bbcode
99
        FROM ' . PRIVMSGS_TABLE;
100
$result = $db->sql_query($sql);
101
102
while ($row = $db->sql_fetchrow($result))
103
{
104
        $bbcode_uid = $row['bbcode_uid'];
105
106
        // Only if a bbcode uid is present, bbcode enabled and a size tag used...
107
        if ($row['enable_bbcode'] && $bbcode_uid && strpos($row['message_text'], '[size=') !== false)
108
        {
109
                $row['message_text'] = preg_replace_callback('/\[size=(\d*):' . $bbcode_uid . '\]/', 'replace_size', $row['message_text']);
110
111
                $sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET message_text = '" . $db->sql_escape($row['message_text']) . "'
112
                        WHERE msg_id = " . $row['msg_id'];
113
                $db->sql_query($sql);
114
115
                if ($echos > 200)
116
                {
117
                        echo '<br />' . "\n";
118
                        $echos = 0;
119
                }
120
121
                echo '.';
122
                $echos++;
123
124
                flush();
125
        }
126
}
127
$db->sql_freeresult($result);
128
129
// Done
130
$db->sql_close();
131
132
?>