| 1 |
sysadm |
1.1 |
<?php
|
| 2 |
|
|
if (!isset($_SERVER["argc"]))
|
| 3 |
|
|
{
|
| 4 |
|
|
echo ("Invalid usage");
|
| 5 |
|
|
exit();
|
| 6 |
|
|
}
|
| 7 |
|
|
|
| 8 |
|
|
chdir(dirname($_SERVER["argv"][0]));
|
| 9 |
|
|
|
| 10 |
|
|
require_once "../lib/db_open.inc.php";
|
| 11 |
|
|
require_once "../lib/str_process.inc.php";
|
| 12 |
|
|
require_once "../lib/section_list.inc.php";
|
| 13 |
|
|
|
| 14 |
|
|
$menu_input_path = "../../conf/menu.conf";
|
| 15 |
|
|
$menu_output_path = "../../var/menu_merged.conf";
|
| 16 |
|
|
|
| 17 |
|
|
$buffer = file_get_contents($menu_input_path);
|
| 18 |
|
|
if ($buffer == false)
|
| 19 |
|
|
{
|
| 20 |
|
|
echo "Unable to load menu config file " . $menu_input_path . "\n";
|
| 21 |
|
|
exit();
|
| 22 |
|
|
}
|
| 23 |
|
|
|
| 24 |
|
|
// Load section list
|
| 25 |
|
|
$section_hierachy = array();
|
| 26 |
|
|
|
| 27 |
|
|
$ret = load_section_list($section_hierachy,
|
| 28 |
|
|
function (array $section, array $filter_param) : bool
|
| 29 |
|
|
{
|
| 30 |
|
|
return true;
|
| 31 |
|
|
},
|
| 32 |
|
|
function (array $section, array $filter_param) : mixed
|
| 33 |
|
|
{
|
| 34 |
sysadm |
1.4 |
$db_conn = $filter_param["db"];
|
| 35 |
|
|
$result = array(
|
| 36 |
|
|
"article_count" => 0,
|
| 37 |
|
|
"section_master" => "",
|
| 38 |
|
|
);
|
| 39 |
|
|
|
| 40 |
|
|
// Query article count
|
| 41 |
|
|
$sql = "SELECT COUNT(*) AS article_count FROM bbs WHERE SID = " .
|
| 42 |
|
|
$section["SID"] . " AND visible";
|
| 43 |
|
|
|
| 44 |
|
|
$rs = mysqli_query($db_conn, $sql);
|
| 45 |
|
|
if ($rs == false)
|
| 46 |
|
|
{
|
| 47 |
|
|
echo mysqli_error($db_conn);
|
| 48 |
|
|
return $result;
|
| 49 |
|
|
}
|
| 50 |
|
|
|
| 51 |
|
|
if ($row = mysqli_fetch_array($rs))
|
| 52 |
|
|
{
|
| 53 |
|
|
$result["article_count"] = $row["article_count"];
|
| 54 |
|
|
}
|
| 55 |
|
|
mysqli_free_result($rs);
|
| 56 |
|
|
|
| 57 |
|
|
// Query section master
|
| 58 |
|
|
$sql = "SELECT user_list.UID, user_list.username, section_master.major FROM section_master
|
| 59 |
|
|
INNER JOIN user_list ON section_master.UID = user_list.UID WHERE SID = " .
|
| 60 |
|
|
$section["SID"] . " AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt)
|
| 61 |
|
|
ORDER BY major DESC LIMIT 1";
|
| 62 |
|
|
|
| 63 |
|
|
$rs = mysqli_query($db_conn, $sql);
|
| 64 |
|
|
if ($rs == false)
|
| 65 |
|
|
{
|
| 66 |
|
|
echo mysqli_error($db_conn);
|
| 67 |
|
|
return $result;
|
| 68 |
|
|
}
|
| 69 |
|
|
|
| 70 |
|
|
if ($row = mysqli_fetch_array($rs))
|
| 71 |
|
|
{
|
| 72 |
|
|
$result["section_master"] = $row["username"];
|
| 73 |
|
|
}
|
| 74 |
|
|
mysqli_free_result($rs);
|
| 75 |
|
|
|
| 76 |
|
|
return $result;
|
| 77 |
sysadm |
1.1 |
},
|
| 78 |
sysadm |
1.4 |
$db_conn,
|
| 79 |
|
|
array(
|
| 80 |
|
|
"db" => $db_conn
|
| 81 |
|
|
)
|
| 82 |
|
|
);
|
| 83 |
sysadm |
1.1 |
|
| 84 |
|
|
if ($ret == false)
|
| 85 |
|
|
{
|
| 86 |
|
|
echo "Query section list error: " . mysqli_error($db_conn);
|
| 87 |
|
|
exit();
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
sysadm |
1.2 |
// Generate menu of section class
|
| 91 |
sysadm |
1.1 |
$buffer .= <<<MENU
|
| 92 |
|
|
#---------------------------------------------------------------------
|
| 93 |
|
|
%menu M_EGROUP
|
| 94 |
sysadm |
1.10 |
title 0, 0, "[栏目列表]"
|
| 95 |
sysadm |
1.1 |
screen 2, 0, S_EGROUP
|
| 96 |
|
|
|
| 97 |
|
|
MENU;
|
| 98 |
|
|
|
| 99 |
|
|
foreach ($section_hierachy as $c_index => $section_class)
|
| 100 |
|
|
{
|
| 101 |
|
|
$display_row = ($c_index == 0 ? 4 : 0);
|
| 102 |
|
|
|
| 103 |
|
|
$section_count = count($section_class["sections"]);
|
| 104 |
|
|
|
| 105 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($section_count))) . $section_count . " + " .
|
| 106 |
sysadm |
1.4 |
$section_class['name'] . str_repeat(" ", 32 - strlen($section_class['name'])) .
|
| 107 |
sysadm |
1.1 |
"[" . addslashes($section_class['title']) . "]";
|
| 108 |
|
|
|
| 109 |
|
|
$buffer .= <<<MENU
|
| 110 |
|
|
!M__{$section_class['name']} {$display_row}, 4, 1, 0, "{$section_class['name']}", "{$title_f}"
|
| 111 |
|
|
|
| 112 |
|
|
MENU;
|
| 113 |
|
|
}
|
| 114 |
|
|
|
| 115 |
|
|
$buffer .= <<<MENU
|
| 116 |
|
|
%
|
| 117 |
|
|
|
| 118 |
|
|
MENU;
|
| 119 |
|
|
|
| 120 |
|
|
foreach ($section_hierachy as $c_index => $section_class)
|
| 121 |
|
|
{
|
| 122 |
sysadm |
1.2 |
// Generate menu of sections in section_class[$c_index]
|
| 123 |
sysadm |
1.1 |
$buffer .= <<<MENU
|
| 124 |
|
|
#---------------------------------------------------------------------
|
| 125 |
|
|
%menu M__{$section_class["name"]}
|
| 126 |
|
|
title 0, 0, "[{$section_class["title"]}]"
|
| 127 |
sysadm |
1.6 |
screen 2, 0, S_BOARD
|
| 128 |
sysadm |
1.1 |
|
| 129 |
|
|
MENU;
|
| 130 |
|
|
|
| 131 |
sysadm |
1.4 |
$class_title_f = "[" . addslashes($section_class['title']) . "]" . str_repeat(" ", 10 - str_length($section_class['title']));
|
| 132 |
sysadm |
1.1 |
|
| 133 |
|
|
foreach ($section_class["sections"] as $s_index => $section)
|
| 134 |
|
|
{
|
| 135 |
|
|
$display_row = ($s_index == 0 ? 4 : 0);
|
| 136 |
|
|
|
| 137 |
sysadm |
1.4 |
$article_count = $section['udf_values']['article_count'];
|
| 138 |
sysadm |
1.1 |
|
| 139 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($article_count))) . $article_count . " + " .
|
| 140 |
sysadm |
1.4 |
$section['name'] . str_repeat(" ", 20 - strlen($section['name'])) .
|
| 141 |
sysadm |
1.5 |
$class_title_f . addslashes($section['title']) . str_repeat(" ", 22 - str_length($section['title'])) .
|
| 142 |
sysadm |
1.10 |
($section['udf_values']['section_master'] == "" ? "诚征版主中" : $section['udf_values']['section_master']);
|
| 143 |
sysadm |
1.1 |
|
| 144 |
|
|
$buffer .= <<<MENU
|
| 145 |
|
|
@LIST_SECTION {$display_row}, 4, 1, {$section['read_user_level']}, "{$section['name']}", "{$title_f}"
|
| 146 |
|
|
|
| 147 |
|
|
MENU;
|
| 148 |
|
|
}
|
| 149 |
|
|
|
| 150 |
|
|
$buffer .= <<<MENU
|
| 151 |
|
|
%
|
| 152 |
|
|
|
| 153 |
|
|
MENU;
|
| 154 |
|
|
|
| 155 |
|
|
}
|
| 156 |
|
|
|
| 157 |
sysadm |
1.9 |
// Load excerptional section list
|
| 158 |
|
|
$ex_section_hierachy = array();
|
| 159 |
|
|
|
| 160 |
|
|
$ret = load_section_list($ex_section_hierachy,
|
| 161 |
|
|
function (array $section, array $filter_param) : bool
|
| 162 |
|
|
{
|
| 163 |
|
|
$db_conn = $filter_param["db"];
|
| 164 |
|
|
|
| 165 |
|
|
// Query excerptional article count
|
| 166 |
|
|
$sql = "SELECT AID AS ex_article_count FROM bbs WHERE SID = " .
|
| 167 |
|
|
$section["SID"] . " AND visible AND gen_ex LIMIT 1";
|
| 168 |
|
|
|
| 169 |
|
|
$rs = mysqli_query($db_conn, $sql);
|
| 170 |
|
|
if ($rs == false)
|
| 171 |
|
|
{
|
| 172 |
|
|
echo mysqli_error($db_conn);
|
| 173 |
|
|
return false;
|
| 174 |
|
|
}
|
| 175 |
|
|
|
| 176 |
|
|
$have_ex_article = (mysqli_num_rows($rs) > 0);
|
| 177 |
|
|
mysqli_free_result($rs);
|
| 178 |
|
|
|
| 179 |
|
|
return $have_ex_article;
|
| 180 |
|
|
},
|
| 181 |
|
|
function (array $section, array $filter_param) : mixed
|
| 182 |
|
|
{
|
| 183 |
|
|
$db_conn = $filter_param["db"];
|
| 184 |
|
|
$result = array(
|
| 185 |
|
|
"ex_menu_tm" => 0,
|
| 186 |
|
|
"ex_article_count" => 0,
|
| 187 |
|
|
);
|
| 188 |
|
|
|
| 189 |
|
|
// Query ex_menu_tm
|
| 190 |
|
|
$sql = "SELECT ex_menu_tm FROM section_config WHERE SID = " . $section["SID"];
|
| 191 |
|
|
$rs = mysqli_query($db_conn, $sql);
|
| 192 |
|
|
if ($rs == false)
|
| 193 |
|
|
{
|
| 194 |
|
|
echo mysqli_error($db_conn);
|
| 195 |
|
|
return $result;
|
| 196 |
|
|
}
|
| 197 |
|
|
|
| 198 |
|
|
if ($row = mysqli_fetch_array($rs))
|
| 199 |
|
|
{
|
| 200 |
|
|
$result["ex_menu_tm"] = $row["ex_menu_tm"];
|
| 201 |
|
|
}
|
| 202 |
|
|
mysqli_free_result($rs);
|
| 203 |
|
|
|
| 204 |
|
|
// Query excerptional article count
|
| 205 |
|
|
$sql = "SELECT COUNT(*) AS ex_article_count FROM bbs WHERE SID = " .
|
| 206 |
|
|
$section["SID"] . " AND visible AND gen_ex";
|
| 207 |
|
|
|
| 208 |
|
|
$rs = mysqli_query($db_conn, $sql);
|
| 209 |
|
|
if ($rs == false)
|
| 210 |
|
|
{
|
| 211 |
|
|
echo mysqli_error($db_conn);
|
| 212 |
|
|
return $result;
|
| 213 |
|
|
}
|
| 214 |
|
|
|
| 215 |
|
|
if ($row = mysqli_fetch_array($rs))
|
| 216 |
|
|
{
|
| 217 |
|
|
$result["ex_article_count"] = $row["ex_article_count"];
|
| 218 |
|
|
}
|
| 219 |
|
|
mysqli_free_result($rs);
|
| 220 |
|
|
|
| 221 |
|
|
return $result;
|
| 222 |
|
|
},
|
| 223 |
|
|
$db_conn,
|
| 224 |
|
|
array(
|
| 225 |
|
|
"db" => $db_conn
|
| 226 |
|
|
)
|
| 227 |
|
|
);
|
| 228 |
|
|
|
| 229 |
|
|
if ($ret == false)
|
| 230 |
|
|
{
|
| 231 |
|
|
echo "Query excerptional section list error: " . mysqli_error($db_conn);
|
| 232 |
|
|
exit();
|
| 233 |
|
|
}
|
| 234 |
|
|
|
| 235 |
|
|
// Generate menu of excerptional section class
|
| 236 |
|
|
$buffer .= <<<MENU
|
| 237 |
|
|
#---------------------------------------------------------------------
|
| 238 |
|
|
%menu M_ANNOUNCE
|
| 239 |
sysadm |
1.10 |
title 0, 0, "精华公布栏"
|
| 240 |
sysadm |
1.9 |
screen 2, 0, S_EGROUP
|
| 241 |
|
|
|
| 242 |
|
|
MENU;
|
| 243 |
|
|
|
| 244 |
|
|
foreach ($ex_section_hierachy as $c_index => $section_class)
|
| 245 |
|
|
{
|
| 246 |
|
|
$display_row = ($c_index == 0 ? 4 : 0);
|
| 247 |
|
|
|
| 248 |
|
|
$section_count = count($section_class["sections"]);
|
| 249 |
|
|
|
| 250 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($section_count))) . $section_count . " + " .
|
| 251 |
sysadm |
1.9 |
$section_class['name'] . str_repeat(" ", 32 - strlen($section_class['name'])) .
|
| 252 |
|
|
"[" . addslashes($section_class['title']) . "]";
|
| 253 |
|
|
|
| 254 |
|
|
$buffer .= <<<MENU
|
| 255 |
|
|
!M_EX_{$section_class['name']} {$display_row}, 4, 1, 0, "{$section_class['name']}", "{$title_f}"
|
| 256 |
|
|
|
| 257 |
|
|
MENU;
|
| 258 |
|
|
}
|
| 259 |
|
|
|
| 260 |
|
|
$buffer .= <<<MENU
|
| 261 |
|
|
%
|
| 262 |
|
|
|
| 263 |
|
|
MENU;
|
| 264 |
|
|
|
| 265 |
|
|
foreach ($ex_section_hierachy as $c_index => $section_class)
|
| 266 |
|
|
{
|
| 267 |
|
|
// Generate menu of excerptional sections in section_class[$c_index]
|
| 268 |
|
|
$buffer .= <<<MENU
|
| 269 |
|
|
#---------------------------------------------------------------------
|
| 270 |
|
|
%menu M_EX_{$section_class["name"]}
|
| 271 |
sysadm |
1.10 |
title 0, 0, "精华区 > {$section_class["title"]}"
|
| 272 |
sysadm |
1.9 |
screen 2, 0, S_EX_DIR
|
| 273 |
|
|
|
| 274 |
|
|
MENU;
|
| 275 |
|
|
|
| 276 |
|
|
$display_row = 4;
|
| 277 |
|
|
$class_title_f = "[" . addslashes($section_class['title']) . "]" . str_repeat(" ", 10 - str_length($section_class['title']));
|
| 278 |
|
|
|
| 279 |
|
|
foreach ($section_class["sections"] as $s_index => $section)
|
| 280 |
|
|
{
|
| 281 |
|
|
$article_count = $section['udf_values']['ex_article_count'];
|
| 282 |
|
|
if ($article_count == 0)
|
| 283 |
|
|
{
|
| 284 |
|
|
continue;
|
| 285 |
|
|
}
|
| 286 |
|
|
|
| 287 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($article_count))) . $article_count . " + " .
|
| 288 |
sysadm |
1.9 |
$section['name'] . str_repeat(" ", 20 - strlen($section['name'])) .
|
| 289 |
|
|
$class_title_f . addslashes($section['title']) . str_repeat(" ", 22 - str_length($section['title'])) .
|
| 290 |
|
|
(new DateTimeImmutable($section['udf_values']['ex_menu_tm']))->format("Y.m.d");
|
| 291 |
|
|
|
| 292 |
|
|
$buffer .= <<<MENU
|
| 293 |
|
|
@LIST_EX_SECTION {$display_row}, 4, 1, 0, "{$section['name']}", "{$title_f}"
|
| 294 |
|
|
|
| 295 |
|
|
MENU;
|
| 296 |
|
|
|
| 297 |
|
|
$display_row = 0;
|
| 298 |
|
|
}
|
| 299 |
|
|
|
| 300 |
|
|
$buffer .= <<<MENU
|
| 301 |
|
|
%
|
| 302 |
|
|
|
| 303 |
|
|
MENU;
|
| 304 |
|
|
|
| 305 |
|
|
}
|
| 306 |
|
|
|
| 307 |
sysadm |
1.2 |
// Generate menu of all sections
|
| 308 |
|
|
$buffer .= <<<MENU
|
| 309 |
|
|
#---------------------------------------------------------------------
|
| 310 |
|
|
%menu M_BOARD
|
| 311 |
sysadm |
1.10 |
title 0, 0, "[版块列表]"
|
| 312 |
sysadm |
1.2 |
screen 2, 0, S_BOARD
|
| 313 |
|
|
page 4, 1, 20
|
| 314 |
|
|
|
| 315 |
|
|
MENU;
|
| 316 |
|
|
|
| 317 |
|
|
$display_row = 4;
|
| 318 |
|
|
|
| 319 |
|
|
foreach ($section_hierachy as $c_index => $section_class)
|
| 320 |
|
|
{
|
| 321 |
sysadm |
1.4 |
$class_title_f = "[" . addslashes($section_class['title']) . "]" . str_repeat(" ", 10 - str_length($section_class['title']));
|
| 322 |
sysadm |
1.2 |
|
| 323 |
|
|
foreach ($section_class["sections"] as $s_index => $section)
|
| 324 |
|
|
{
|
| 325 |
sysadm |
1.4 |
$article_count = $section['udf_values']['article_count'];
|
| 326 |
sysadm |
1.2 |
|
| 327 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($article_count))) . $article_count . " + " .
|
| 328 |
sysadm |
1.4 |
$section['name'] . str_repeat(" ", 20 - strlen($section['name'])) .
|
| 329 |
sysadm |
1.5 |
$class_title_f . addslashes($section['title']) . str_repeat(" ", 22 - str_length($section['title'])) .
|
| 330 |
sysadm |
1.10 |
($section['udf_values']['section_master'] == "" ? "诚征版主中" : $section['udf_values']['section_master']);
|
| 331 |
sysadm |
1.2 |
|
| 332 |
|
|
$buffer .= <<<MENU
|
| 333 |
|
|
@LIST_SECTION {$display_row}, 4, 1, {$section['read_user_level']}, "{$section['name']}", "{$title_f}"
|
| 334 |
|
|
|
| 335 |
|
|
MENU;
|
| 336 |
|
|
|
| 337 |
|
|
$display_row = 0;
|
| 338 |
|
|
}
|
| 339 |
|
|
}
|
| 340 |
|
|
|
| 341 |
|
|
$buffer .= <<<MENU
|
| 342 |
|
|
%
|
| 343 |
|
|
|
| 344 |
|
|
MENU;
|
| 345 |
|
|
|
| 346 |
sysadm |
1.7 |
// Generate menu of favourite sections
|
| 347 |
|
|
$buffer .= <<<MENU
|
| 348 |
|
|
#---------------------------------------------------------------------
|
| 349 |
|
|
%menu M_FAVOUR
|
| 350 |
sysadm |
1.10 |
title 0, 0, "[版块收藏]"
|
| 351 |
sysadm |
1.7 |
screen 2, 0, S_BOARD
|
| 352 |
|
|
use_filter
|
| 353 |
|
|
page 4, 1, 20
|
| 354 |
|
|
|
| 355 |
|
|
MENU;
|
| 356 |
|
|
|
| 357 |
|
|
$display_row = 4;
|
| 358 |
|
|
|
| 359 |
|
|
foreach ($section_hierachy as $c_index => $section_class)
|
| 360 |
|
|
{
|
| 361 |
|
|
$class_title_f = "[" . addslashes($section_class['title']) . "]" . str_repeat(" ", 10 - str_length($section_class['title']));
|
| 362 |
|
|
|
| 363 |
|
|
foreach ($section_class["sections"] as $s_index => $section)
|
| 364 |
|
|
{
|
| 365 |
|
|
$article_count = $section['udf_values']['article_count'];
|
| 366 |
|
|
|
| 367 |
sysadm |
1.10 |
$title_f = str_repeat(" ", 5 - intval(log10($article_count))) . $article_count . " + " .
|
| 368 |
sysadm |
1.7 |
$section['name'] . str_repeat(" ", 20 - strlen($section['name'])) .
|
| 369 |
|
|
$class_title_f . addslashes($section['title']) . str_repeat(" ", 22 - str_length($section['title'])) .
|
| 370 |
sysadm |
1.10 |
($section['udf_values']['section_master'] == "" ? "诚征版主中" : $section['udf_values']['section_master']);
|
| 371 |
sysadm |
1.7 |
|
| 372 |
|
|
$buffer .= <<<MENU
|
| 373 |
|
|
@LIST_SECTION {$display_row}, 4, {$section['sid']}, {$section['read_user_level']}, "{$section['name']}", "{$title_f}"
|
| 374 |
|
|
|
| 375 |
|
|
MENU;
|
| 376 |
|
|
|
| 377 |
|
|
$display_row = 0;
|
| 378 |
|
|
}
|
| 379 |
|
|
}
|
| 380 |
|
|
|
| 381 |
|
|
$buffer .= <<<MENU
|
| 382 |
|
|
%
|
| 383 |
|
|
|
| 384 |
|
|
MENU;
|
| 385 |
|
|
|
| 386 |
sysadm |
1.1 |
unset($section_hierachy);
|
| 387 |
|
|
|
| 388 |
|
|
mysqli_close($db_conn);
|
| 389 |
|
|
|
| 390 |
|
|
file_put_contents($menu_output_path, $buffer);
|