-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailbox-functions.php
211 lines (200 loc) · 7.13 KB
/
mailbox-functions.php
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
//
// TorrentTrader v2.x
// $LastChangedDate: 2011-11-17 10:28:48 +0000 (Thu, 17 Nov 2011) $
// $LastChangedBy: dj-howarth1 $
//
// http://www.torrenttrader.org
//
//
function begin_form($action='', $extra='', $method='post')
{
//if (!$action) $action = substr($_SERVER['REQUEST_URI'], 1);
print("<form method=\"$method\" action=\"$action\" $extra>\n");
}
function end_form()
{
print("</form>\n");
}
function submenu($pages, $default, $prefix='', $class='submenu', $space=false)
{
if ($space) $menu = "<p style=\"text-align:center;\">";
else $menu = "<table class=\"$class\"><tr>";
$arr = explode(',', $pages);
if ($prefix)
{
if (!isset($_GET[$prefix])) $_GET[$prefix] = $default;
elseif (!preg_match('/(^|,)'.$_GET[$prefix].'(,|$)/i', $pages)) $_GET[$prefix] = $default;
else $_GET[$prefix] = $_GET[$prefix];
} else {
foreach ($arr as $page) if (isset($_GET[$page])) break;
if (!isset($_GET[$page])) $_GET[$default] = '';
}
foreach ($arr as $page)
{
$name = ucwords(str_replace("_"," ",$page));
if (!$space)
{
if ((!$prefix && isset($_GET[$page])) || ($prefix && $_GET[$prefix] == $page)) $menu .= '<td style="width:'.floor(100/count($arr)).'%"><b>'.$name.'</b></td>';
else $menu .= '<td style="width:'.floor(100/count($arr)).'%"><a href="mailbox.php?'.$prefix.($prefix ? '=' : '').$page.'">'.$name.'</a></td>';
} else {
if ((!$prefix && isset($_GET[$page])) || ($prefix && $_GET[$prefix] == $page)) $menu .= " <b>$name</b>";
else $menu .= ' <a href="mailbox.php?'.$prefix.($prefix ? '=' : '').$page.'">'.$name.'</a>';
}
}
return $menu.($space ? "</p>" : "</tr></table>");
}
function order($fields, $default, $reverse=false)
{
if (isset($_GET['sort']))
{
$sort = trim($_GET['sort']);
if (!preg_match('/(^|,)'.$sort.'(,|$)/i', $fields)) unset($sort);
}
elseif ($reverse) $_GET['reverse'] = '';
if (!isset($sort)) $sort = $default;
$_GET['sort'] = $sort;
if (strpos($sort,'.')) $sort = implode('`.`', explode('.', $sort));
return "ORDER BY `$sort`".(isset($_GET['reverse']) ? " DESC" : "");
}
function tr2($x, $y='', $noesc=0, $style='')
{
print('<tr>');
if ($y !== '')
{
if (!$style) $style = 'text-align:left;';
print(th_right($x, 1));
print(td($y, $noesc, $style));
}
else
{
if (!$style) $style = 'text-align:center;';
print(td($x, 1, $style.'border:0;', 2));
}
print('</tr>');
}
function tr_left($x, $y='', $noesc=0, $style='', $col=1) { return tr($x, $y, $noesc, 'text-align:left;'.$style, $col); }
function tr_center($x, $y='', $noesc=0, $style='', $col=1) { return tr($x, $y, $noesc, 'text-align:center;'.$style, $col); }
function tr_right($x, $y='', $noesc=0, $style='', $col=1) { return tr($x, $y, $noesc, 'text-align:right;'.$style, $col); }
function td($x, $noesc=0, $style='', $col=1)
{
$col = ($col > 1 ? " colspan=\"$col\"" : '');
if (!$noesc) $x = str_replace("\n", "<br />\n", htmlspecialchars($x));
if ($style)return "<td style=\"$style\"$col>$x</td>";
return "<td$col>$x</td>";
}
function td_left($x, $noesc=0, $style='', $col=1) { return td($x, $noesc, 'text-align:left;'.$style, $col); }
function td_center($x, $noesc=0, $style='', $col=1) { return td($x, $noesc, 'text-align:center;'.$style, $col); }
function td_right($x, $noesc=0, $style='', $col=1) { return td($x, $noesc, 'text-align:right;'.$style, $col); }
// If field is a string, then it's a sort field, otherwise if a number/true it's don't escape the string, if empty then escape
function th($x, $field=0, $style='', $col=1)
{
if (is_string($field))
{
if (isset($_GET['sort']) && $field != $_GET['sort']) $x = "<a href=\"".add_get('sort',$field)."\">$x</a>";
elseif (!isset($_GET['reverse'])) $x = "<a href=\"".add_get('reverse')."\">$x</a> ↓";
else $x = "<a href=\"".rem_get('reverse')."\">$x</a> ↑";
}
$col = ($col > 1 ? " colspan=\"$col\"" : '');
if (!empty($noesc)) $x = str_replace("\n", "<br />\n", htmlspecialchars($x));
if ($style)return "<th style=\"$style\"$col>$x</th>";
return "<th>$x</th>";
}
function th_left($x, $noesc=0, $style='', $col=1, $field='') { return th($x, $noesc, 'text-align:left;'.$style, $col, $field); }
function th_center($x, $noesc=0, $style='', $col=1, $field='') { return th($x, $noesc, 'text-align:center;'.$style, $col, $field); }
function th_right($x, $noesc=0, $style='', $col=1, $field='') { return th($x, $noesc, 'text-align:right;'.$style, $col, $field); }
function table($arr, $format='', $extratr='')
{
if ($extratr) print("<tr $extratr>\n");
else print("<tr>\n");
if (is_array($arr))
{
if (!$format) foreach($arr as $td) print($td."\n");
else
{
$list = explode(',' ,$format);
foreach($list as $id)
{
if (isset($arr[$id])) print($arr[$id]."\n");
else print("<td> </td>\n");
}
}
}
else print(substr($arr,0,3).' colspan="'.(substr_count($format, ',') + 1).'"'.substr($arr,3));
print("</tr>\n");
}
function add_get($key, $value='')
{
$get = $_GET;
unset($get[$key]); $get[$key] = ''; // force it to be last!!
foreach($get as $k => $v)$get2[] = $k . ($v ? '='.urlencode($v) : '');
return $_SERVER["SCRIPT_NAME"].'?'.implode('&',$get2).($value ? '='.urlencode($value) : '');
}
function rem_get($key)
{
$get = $_GET;
unset($get[$key]);
if (!count($get)) return $_SERVER["SCRIPT_NAME"];
foreach($get as $k => $v)$get2[] = $k . ($v ? '='.urlencode($v) : '');
return $_SERVER["SCRIPT_NAME"].'?'.implode('&',$get2);
}
function pager2($rpp, $count, $opts = array())
{
$href = add_get('page').'=';
$pages = ceil($count / $rpp);
if (!@$opts["lastpagedefault"]) $pagedefault = 0;
else
{
$pagedefault = floor(($count - 1) / $rpp);
if ($pagedefault < 0) $pagedefault = 0;
}
if (isset($_GET["page"]))
{
$page = (int) $_GET["page"];
if ($page < 0) $page = $pagedefault;
}
else $page = $pagedefault;
$pager = "";
$mp = $pages - 1;
$as = "<b><< Prev</b>";
if ($page >= 1) $pager .= '<a href="'.$href.($page - 1).'">'.$as.'</a>';
else $pager .= $as;
$pager .= " ";
$as = "<b>".T_("NEXT")." >></b>";
if ($page < $mp && $mp >= 0) $pager .= '<a href="'.$href.($page + 1).'">'.$as.'</a>';
else $pager .= $as;
if ($count)
{
$pagerarr = array();
$dotted = 0;
$dotspace = 3;
$dotend = $pages - $dotspace;
$curdotend = $page - $dotspace;
$curdotstart = $page + $dotspace;
for ($i = 0; $i < $pages; $i++)
{
if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend))
{
if (!$dotted) $pagerarr[] = "...";
$dotted = 1;
continue;
}
$dotted = 0;
$start = $i * $rpp + 1;
$end = $start + $rpp - 1;
if ($end > $count) $end = $count;
$text = "$start - $end";
if ($i != $page) $pagerarr[] = '<a href="'.$href.$i.'"><b>'.$text.'</b></a>';
else $pagerarr[] = '<b>'.$text.'</b>';
}
$pagerstr = join(" | ", $pagerarr);
$pagertop = "<p align=\"center\">$pager<br />$pagerstr</p>\n";
$pagerbottom = "<p align=\"center\">$pagerstr<br />$pager</p>\n";
} else {
$pagertop = "<p align=\"center\">$pager</p>\n";
$pagerbottom = $pagertop;
}
$start = $page * $rpp;
return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
}
?>