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
|
<?php
function convertquote($body, $reply)
{
// Convert Quotes
$arrbody = explode("\n", trim($body));
$arrlevel = array();
for ($i = 0; $i < count($arrbody); $i++) {
$quotelevel = 0;
$quoteline = $arrbody[$i];
while ((strlen($quoteline)>0) and ((substr($quoteline, 0, 1) == '>')
or (substr($quoteline, 0, 1) == ' '))) {
if (substr($quoteline, 0, 1) == '>')
$quotelevel++;
$quoteline = ltrim(substr($quoteline, 1));
}
//echo $quotelevel.'*'.$quoteline."\r\n";
$arrlevel[$i] = $quotelevel;
$arrbody[$i] = $quoteline;
}
$quotelevel = 0;
$previousquote = 0;
$arrbodyquoted = array();
for ($i = 0; $i < count($arrbody); $i++) {
$previousquote = $quotelevel;
$quotelevel = $arrlevel[$i];
$currline = $arrbody[$i];
while ($previousquote < $quotelevel) {
if ($sender != '') {
$quote = "[quote title=$sender]";
$sender = '';
} else
$quote = "[quote]";
$arrbody[$i] = $quote.$arrbody[$i];
$previousquote++;
}
while ($previousquote > $quotelevel) {
$arrbody[$i] = '[/quote]'.$arrbody[$i];
$previousquote--;
}
$arrbodyquoted[] = $arrbody[$i];
}
while ($quotelevel > 0) {
$arrbodyquoted[] = '[/quote]';
$quotelevel--;
}
$body = implode("\n", $arrbodyquoted);
if (strlen($body) > 0)
$body = $body."\n\n";
if ($reply)
$body = removetofu($body);
return($body);
}
function removetofu($message)
{
$message = trim($message);
do {
$oldmessage = $message;
$message = preg_replace('=\[/quote\][\s](.*?)\[quote\]=i', '$1', $message);
$message = str_replace("[/quote][quote]", "", $message);
} while ($message != $oldmessage);
$quotes = array();
$startquotes = 0;
$start = 0;
while(($pos = strpos($message, '[quote', $start)) > 0) {
$quotes[$pos] = -1;
$start = $pos + 7;
$startquotes++;
}
$endquotes = 0;
$start = 0;
while(($pos = strpos($message, '[/quote]', $start)) > 0) {
$start = $pos + 7;
$endquotes++;
}
while ($endquotes < $startquotes) {
$message .= '[/quote]';
++$endquotes;
}
$start = 0;
while(($pos = strpos($message, '[/quote]', $start)) > 0) {
$quotes[$pos] = 1;
$start = $pos + 7;
}
if (strtolower(substr($message, -8)) != '[/quote]')
return($message);
krsort($quotes);
$quotelevel = 0;
$quotestart = 0;
foreach ($quotes as $index => $quote) {
$quotelevel += $quote;
if (($quotelevel == 0) and ($quotestart == 0))
$quotestart = $index;
}
if ($quotestart != 0) {
$message = trim(substr($message, 0, $quotestart))."\n[spoiler]".substr($message, $quotestart+7, -8).'[/spoiler]';
}
return($message);
}
?>
|